Gaussian Mixture Model
Public Member Functions | List of all members
GaussianMixtureModel Class Reference

Public Member Functions

 GaussianMixtureModel (Eigen::MatrixXd samples, int num_components)
 Use this method to initialize a GMM fitting given data samples with the desired number of components. Training is done with Expectation-Maximization algorithm. More...
 
 GaussianMixtureModel (std::vector< Eigen::VectorXd > means, std::vector< Eigen::MatrixXd > covariances, std::vector< double > weights)
 Use this method to initialize a GMM starting from mean points and covariance matrices already known. Faster than fitting a GMM from a dataset. The number of component is equal to the number of elements in the input vectors. More...
 
 GaussianMixtureModel (int num_components)
 Use this method to initialize a GMM from random mean points and covariance matrices. DEPRECATED! The fitting procedure is very slow. It's better to initialize an empty GMM and then set the parameters with the setter methods. More...
 
 GaussianMixtureModel ()
 Use this method to initialize an empty GMM. Parameters must be set with the setter methods.
 
 ~GaussianMixtureModel ()
 Destructor.
 
void fitgmm (Eigen::MatrixXd samples, int num_components, int max_iterations, double tolerance, bool verbose)
 Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized. More...
 
void fitgmm2 (Eigen::MatrixXd samples, int num_components, int max_iterations, double tolerance, bool verbose)
 Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized. More...
 
void fitgmm (std::vector< Eigen::VectorXd > samples, int num_components, int max_iterations, double tolerance, bool verbose)
 Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized. Result is the same as above, but convergence should be faster. More...
 
std::vector< Eigen::VectorXd > getMeans ()
 Mean getter. More...
 
std::vector< Eigen::MatrixXd > getCovariances ()
 Covariances getter. More...
 
std::vector< double > getWeights ()
 Weights getter. More...
 
double getLogLikelihood ()
 Log-likelihood getter. More...
 
void setMeans (std::vector< Eigen::VectorXd > means)
 Mean points setter method. More...
 
void setCovariances (std::vector< Eigen::MatrixXd > covariances)
 Covariance matrices setter method. More...
 
void setWeights (std::vector< double > weights)
 Weights setter method. More...
 
bool check ()
 Check dimensions consistency of the GMM parameters. More...
 
double gauss_pdf_2d (Eigen::VectorXd q, Eigen::VectorXd mean, Eigen::MatrixXd cov)
 Use this method to calculate the probability of a given 2D point from a Bivariate Gaussian Distribution (single component). More...
 

Constructor & Destructor Documentation

◆ GaussianMixtureModel() [1/3]

GaussianMixtureModel::GaussianMixtureModel ( Eigen::MatrixXd  samples,
int  num_components 
)

Use this method to initialize a GMM fitting given data samples with the desired number of components. Training is done with Expectation-Maximization algorithm.

Parameters
[in]samplestraining set
[in]num_componentsdesired number of clusters

◆ GaussianMixtureModel() [2/3]

GaussianMixtureModel::GaussianMixtureModel ( std::vector< Eigen::VectorXd >  means,
std::vector< Eigen::MatrixXd >  covariances,
std::vector< double >  weights 
)

Use this method to initialize a GMM starting from mean points and covariance matrices already known. Faster than fitting a GMM from a dataset. The number of component is equal to the number of elements in the input vectors.

Parameters
[in]meansvector of mean points, one for each cluster
[in]covariancesvector of covariance matrices, one for each cluster
[in]weightsmixture proportion of each cluster
Exceptions
returnerror if size of input vectors is not consistent

◆ GaussianMixtureModel() [3/3]

GaussianMixtureModel::GaussianMixtureModel ( int  num_components)

Use this method to initialize a GMM from random mean points and covariance matrices. DEPRECATED! The fitting procedure is very slow. It's better to initialize an empty GMM and then set the parameters with the setter methods.

Parameters
[in]num_componentsnumber of clusters

Member Function Documentation

◆ check()

bool GaussianMixtureModel::check ( )

Check dimensions consistency of the GMM parameters.

Returns
true if dimensions are consistent, false otherwise

◆ fitgmm() [1/2]

void GaussianMixtureModel::fitgmm ( Eigen::MatrixXd  samples,
int  num_components,
int  max_iterations = 1000,
double  tolerance = 1e-3,
bool  verbose = false 
)

Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized.

Parameters
[in]samplesmatrix of data samples. Each column is a sample.
[in]num_componentsnumber of clusters
[in]max_iterationsmaximum number of iterations (default: 1000)
[in]toleranceconvergence threshold (default: 1e-3)
[in]verboseprint number of iterations, final log_likelihood and time required for computation (default: false)

◆ fitgmm() [2/2]

void GaussianMixtureModel::fitgmm ( std::vector< Eigen::VectorXd >  samples,
int  num_components,
int  max_iterations = 1000,
double  tolerance = 1e-3,
bool  verbose = false 
)

Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized. Result is the same as above, but convergence should be faster.

Parameters
[in]samplesvector of samples. Each element of the std::vector contains coordinates of a sample.
[in]num_componentsnumber of clusters
[in]max_iterationsmaximum number of iterations (default: 1000)
[in]toleranceconvergence threshold (default: 1e-3)
[in]verboseprint number of iterations, final log_likelihood and time required for computation (default: false)

◆ fitgmm2()

void GaussianMixtureModel::fitgmm2 ( Eigen::MatrixXd  samples,
int  num_components,
int  max_iterations = 1000,
double  tolerance = 1e-3,
bool  verbose = false 
)

Expectation-Maximization algorithm. Fits a GMM to a dataset recursively iterating between E-step and M-step. Iterations stop when the log likelihood of the data does not change more than a specified tolerance or when the maximum number of iterations is reached. The GMM must be already initialized.

Parameters
[in]samplesmatrix of data samples. Each column is a sample.
[in]num_componentsnumber of clusters
[in]max_iterationsmaximum number of iterations (default: 1000)
[in]toleranceconvergence threshold (default: 1e-3)
[in]verboseprint number of iterations, final log_likelihood and time required for computation (default: false)

◆ gauss_pdf_2d()

double GaussianMixtureModel::gauss_pdf_2d ( Eigen::VectorXd  q,
Eigen::VectorXd  mean,
Eigen::MatrixXd  cov 
)

Use this method to calculate the probability of a given 2D point from a Bivariate Gaussian Distribution (single component).

Parameters
[in]qconsidered point coordinates
[in]meanmean point of the Bivariate Gaussian Distribution
[in]covcovariance matrix of the Bivariate Gaussian Distribution

◆ getCovariances()

std::vector< Eigen::MatrixXd > GaussianMixtureModel::getCovariances ( )

Covariances getter.

Returns
covariances vector of covariance matrices, one for each cluster

◆ getLogLikelihood()

double GaussianMixtureModel::getLogLikelihood ( )

Log-likelihood getter.

Returns
logLikelihood log-likelihood value of the data

◆ getMeans()

std::vector< Eigen::VectorXd > GaussianMixtureModel::getMeans ( )

Mean getter.

Returns
means vector of mean points, one for each cluster

◆ getWeights()

std::vector< double > GaussianMixtureModel::getWeights ( )

Weights getter.

Returns
weights vector of weights, one for each cluster

◆ setCovariances()

void GaussianMixtureModel::setCovariances ( std::vector< Eigen::MatrixXd >  covariances)

Covariance matrices setter method.

Parameters
[in]covariancesvector of covariance matrices of each Gaussian component

◆ setMeans()

void GaussianMixtureModel::setMeans ( std::vector< Eigen::VectorXd >  means)

Mean points setter method.

Parameters
[in]meansvector of mean points of each Gaussian component

◆ setWeights()

void GaussianMixtureModel::setWeights ( std::vector< double >  weights)

Weights setter method.

Parameters
[in]weightsvector of weights of each Gaussian component

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