Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
drwnGaussianMixture Class Reference

Implements a multi-variant Gaussian mixture model. More...

Inheritance diagram for drwnGaussianMixture:
drwnStdObjIface drwnWriteable drwnCloneable drwnTypeable

Public Member Functions

 drwnGaussianMixture (unsigned n=1, unsigned k=1)
 construct a gaussian mixture model over n dimensional features with k mixture components
 
void initialize (unsigned n, unsigned k)
 initialize the gaussian mixture model to be over n dimensional features with k mixture components
 
const char * type () const
 returns object type as a string (e.g., Foo::type() { return "Foo"; })
 
drwnGaussianMixtureclone () const
 returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); }
 
bool save (drwnXMLNode &xml) const
 write object to XML node (see also write)
 
bool load (drwnXMLNode &xml)
 read object from XML node (see also read)
 
void evaluate (const MatrixXd &x, VectorXd &p) const
 compute the log-likelihood of each row of x and put the results in p
 
void evaluate (const vector< vector< double > > &x, vector< double > &p) const
 compute the log-likelihood of each vector in x and put the results in p
 
double evaluateSingle (const VectorXd &x) const
 compute the log-likelihood of a given vector
 
double evaluateSingle (const vector< double > &x) const
 compute the log-likelihood of a given vector
 
void sample (VectorXd &x) const
 generate a random sample from the mixture of gaussian distribution
 
void sample (vector< double > &x) const
 generate a random sample from the mixture of gaussian distribution
 
void train (const MatrixXd &x, double lambda=1.0e-3)
 Estimate the parameters of the mixture of gaussians from a matrix of training examples using the EM algorithm. The parameter lambda regularizes the component covariance matrices towards the global covariance matrix.
 
void train (const vector< vector< double > > &x, double lambda=1.0e-3)
 See above.
 
unsigned mixtures () const
 returns the number of mixture components
 
unsigned dimension () const
 returns the dimensionality of the features space
 
double weight (int k) const
 returns the mixture weight of the k-th component
 
const VectorXd & mean (int k) const
 returns the mean of the k-th component
 
const MatrixXd & covariance (int k) const
 returns the covariance matrix for the k-th component
 
const drwnGaussiancomponent (int k) const
 returns the k-th component as a gaussian distribution
 
drwnGaussianMixtureoperator= (const drwnGaussianMixture &model)
 assignment operator
 
- Public Member Functions inherited from drwnWriteable
bool write (const char *filename) const
 write object to file (calls save)
 
bool read (const char *filename)
 read object from file (calls load)
 
void dump () const
 print object's current state to standard output (for debugging)
 

Static Public Attributes

static int MAX_ITERATIONS = 100
 

Protected Attributes

unsigned _n
 feature dimension
 
vector< drwnGaussian_g
 gaussian components
 
VectorXd _logLambda
 mixture weights (log space)
 

Detailed Description

Implements a multi-variant Gaussian mixture model.

\[ p(x; \left\{\lambda_k, \mu_k, \Sigma\right\}_k) = \sum_k \lambda_k \frac{1}{\sqrt{|2 \pi \Sigma_k|}} \exp\{-\frac{1}{2} (x - \mu_k)^T \Sigma_k^{-1} (x - \mu_k)\}\]

The following code snippet shows example usage:

// load dataset
vector<vector<double> > features;
... // code to load the dataset
// estimate parameters for a 5-component mixture model
drwnGaussianMixture gmm(features[0].size(), 5);
gmm.train(features);
// save the learned model
gmm.write("gmm.xml");
// generate 10 samples from the model
vector<double> s;
for (int i = 0; i < 10; i++) {
gmm.sample(s);
DRWN_LOG_MESSAGE("sample " << (i + 1) << " is " << toString(s));
}

The documentation for this class was generated from the following files: