gmm

package
v0.0.0-...-0953495 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2015 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomVector

func RandomVector(mean, sd []float64, r *rand.Rand) []float64

Returns a random vector using the mean and sd vectors.

Types

type Model

type Model struct {
	Type         string            `json:"type"`
	ModelName    string            `json:"name"`
	ModelDim     int               `json:"dim"`
	NSamples     float64           `json:"nsamples"`
	Diag         bool              `json:"diag"`
	NComponents  int               `json:"num_components"`
	PosteriorSum []float64         `json:"posterior_sum,omitempty"`
	Weights      []float64         `json:"-"`
	LogWeights   []float64         `json:"weights,omitempty"`
	Likelihood   float64           `json:"likelihood"`
	Components   []*gaussian.Model `json:"components,omitempty"`
	Iteration    int               `json:"iteration"`
	// contains filtered or unexported fields
}

Model is a mixture of Gaussian distributions.

func NewModel

func NewModel(dim, numComponents int, options ...Option) *Model

NewModel creates a new Gaussian mixture model.

func RandomModel

func RandomModel(mean, sd []float64, numComponents int,
	name string, seed int64) *Model

RandomModel generates a random Gaussian mixture model using mean and variance vectors as seed. Use this function to initialize the GMM before training. The mean and sd vector can be estimated from the data set using a Gaussian model.

func Read

func Read(r io.Reader) (*Model, error)

Read unmarshals json data from an io.Reader into a model struct.

func ReadFile

func ReadFile(fn string) (*Model, error)

ReadFile unmarshals json data from a file into a model struct.

func (*Model) Clear

func (gmm *Model) Clear()

Clear resets sufficient statistics.

func (*Model) Dim

func (gmm *Model) Dim() int

Dim is the dimensionality of the observation vector.

func (*Model) Estimate

func (gmm *Model) Estimate() error

Estimate computes model parameters using sufficient statistics.

func (*Model) LogProb

func (gmm *Model) LogProb(obs model.Obs) float64

LogProb returns log probability for observation.

func (*Model) Name

func (gmm *Model) Name() string

Name returns the name of the model.

func (*Model) Predict

func (gmm *Model) Predict(x model.Observer) ([]model.Labeler, error)

Predict returns a hypothesis given the observation.

func (*Model) Sample

func (gmm *Model) Sample(r *rand.Rand) model.Obs

Sample returns a GMM sample.

func (*Model) SampleChan

func (gmm *Model) SampleChan(r *rand.Rand, size int) <-chan model.Obs

SampleChan returns a channel with samples generated by the GMM model.

func (*Model) Update

func (gmm *Model) Update(x model.Observer, w func(model.Obs) float64) error

Update updates sufficient statistics using observations.

func (*Model) UpdateOne

func (gmm *Model) UpdateOne(o model.Obs, w float64)

Estimate computes model parameters using sufficient statistics.

func (*Model) Write

func (gmm *Model) Write(w io.Writer) error

Write writes the model to an io.Writer.

func (*Model) WriteFile

func (gmm *Model) WriteFile(fn string) error

WriteFile writes the model to file.

type Option

type Option func(*Model)

Option type is used to pass options to NewModel().

func Clone

func Clone(src *Model) Option

Clone create a clone of src.

func Components

func Components(cs []*gaussian.Model) Option

Components sets the mixture components for the model.

func LogWeights

func LogWeights(logw []float64) Option

LogWeights sets the mixture weights for the model using log(w) as the argument.

func Name

func Name(name string) Option

Name is an option to set the model name.

func Weights

func Weights(w []float64) Option

Weights sets the mixture weights for the model.

Jump to

Keyboard shortcuts

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