models

package
v0.0.0-...-31ab637 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2019 License: BSD-3-Clause Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accuracy

func Accuracy(S spn.SPN, T spn.Dataset, U []int, Sc map[int]*learn.Variable)

Accuracy tests classification accuracy of the SPN given test dataset.

Types

type DVModel

type DVModel struct {
	S []spn.SPN       // Each sub-SPN S[i] is restricted to label i.
	Y *learn.Variable // Y is the query variable. Namely the direction variable.
	// contains filtered or unexported fields
}

DVModel is an SPN based on the Dennis-Ventura algorithm (gospn/learn/dennis), but optimized for parallel programming. We assume that we have at least 4 CPU cores (e.g. Raspberry Pi B+).

func LoadDVModel

func LoadDVModel(filename string) (*DVModel, error)

func NewDVModel

func NewDVModel(Y *learn.Variable) *DVModel

NewDVModel creates a new DVModel.

func (*DVModel) Infer

func (M *DVModel) Infer(I spn.VarSet) (int, []float64)

Infer takes an instance X and returns argmax_y P(Y=y|X), where Y is the query variable set on construction. Returns the most probable label and its probability.

func (*DVModel) LearnDiscriminative

func (M *DVModel) LearnDiscriminative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

LearnDiscriminative fits the DVModel to the dataset (D, L) and scope Sc.

func (*DVModel) LearnGenerative

func (M *DVModel) LearnGenerative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

LearnGenerative fits the DVModel to the dataset (D, L) and scope Sc.

func (*DVModel) LearnStructure

func (M *DVModel) LearnStructure(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

LearnStructure learns only the DV structure.

func (*DVModel) Save

func (M *DVModel) Save(filename string) error

func (*DVModel) TestAccuracy

func (M *DVModel) TestAccuracy(D spn.Dataset, L []int)

type GensModel

type GensModel struct {
	S spn.SPN
	Y *learn.Variable
	// contains filtered or unexported fields
}

func LoadGensModel

func LoadGensModel(filename string) (*GensModel, error)

func NewGensModel

func NewGensModel(Y *learn.Variable) *GensModel

func (*GensModel) Infer

func (M *GensModel) Infer(I spn.VarSet) (int, []float64)

func (*GensModel) LearnDiscriminative

func (M *GensModel) LearnDiscriminative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

func (*GensModel) LearnGenerative

func (M *GensModel) LearnGenerative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

func (*GensModel) LearnStructure

func (M *GensModel) LearnStructure(D spn.Dataset, L []int, Sc map[int]*learn.Variable)

func (*GensModel) Save

func (M *GensModel) Save(filename string) error

func (*GensModel) TestAccuracy

func (M *GensModel) TestAccuracy(D spn.Dataset, L []int)

type Model

type Model interface {
	// LearnStructure generates only the structure.
	LearnStructure(D spn.Dataset, L []int, Sc map[int]*learn.Variable)
	// LearnGenerative generates the structure and then applies generative gradient descent learning
	// on the model.
	LearnGenerative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)
	// LearnDiscriminative generates the structure and then applies discriminative gradient descent
	// learning on the model.
	LearnDiscriminative(D spn.Dataset, L []int, Sc map[int]*learn.Variable)
	// Infer takes an instance spn.VarSet and returns the prediction and its probabilities.
	Infer(I spn.VarSet) (int, []float64)
	// TestAccuracy runs an accuracy test with a test dataset (D, L).
	TestAccuracy(D spn.Dataset, L []int)
	// Save saves this model to a file.
	Save(filename string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL