SYNOPSIS

Public Member Functions

EMFit (const size_t maxIterations=300, const double tolerance=1e-10, InitialClusteringType clusterer=InitialClusteringType(), CovarianceConstraintPolicy constraint=CovarianceConstraintPolicy())

Construct the EMFit object, optionally passing an InitialClusteringType object (just in case it needs to store state). const InitialClusteringType & Clusterer () const

Get the clusterer. InitialClusteringType & Clusterer ()

Modify the clusterer. const CovarianceConstraintPolicy & Constraint () const

Get the covariance constraint policy class. CovarianceConstraintPolicy & Constraint ()

Modify the covariance constraint policy class. void Estimate (const arma::mat &observations, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights, const bool useInitialModel=false)

Fit the observations to a Gaussian mixture model (GMM) using the EM algorithm. void Estimate (const arma::mat &observations, const arma::vec &probabilities, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights, const bool useInitialModel=false)

Fit the observations to a Gaussian mixture model (GMM) using the EM algorithm, taking into account the probabilities of each point being from this mixture. size_t MaxIterations () const

Get the maximum number of iterations of the EM algorithm. size_t & MaxIterations ()

Modify the maximum number of iterations of the EM algorithm. double Tolerance () const

Get the tolerance for the convergence of the EM algorithm. double & Tolerance ()

Modify the tolerance for the convergence of the EM algorithm.

Private Member Functions

void InitialClustering (const arma::mat &observations, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights)

Run the clusterer, and then turn the cluster assignments into Gaussians. double LogLikelihood (const arma::mat &data, const std::vector< arma::vec > &means, const std::vector< arma::mat > &covariances, const arma::vec &weights) const

Calculate the log-likelihood of a model.

Private Attributes

InitialClusteringType clusterer

Object which will perform the clustering. CovarianceConstraintPolicy constraint

Object which applies constraints to the covariance matrix. size_t maxIterations

Maximum iterations of EM algorithm. double tolerance

Tolerance for convergence of EM.

Detailed Description

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint>class mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >

This class contains methods which can fit a GMM to observations using the EM algorithm.

It requires an initial clustering mechanism, which is by default the KMeans algorithm. The clustering mechanism must implement the following method:

  • void Cluster(const arma::mat& observations, const size_t clusters, arma::Col<size_t>& assignments);

This method should create 'clusters' clusters, and return the assignment of each point to a cluster.

Definition at line 51 of file em_fit.hpp.

Constructor & Destructor Documentation

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::\fBEMFit\fP (const size_tmaxIterations = \fC300\fP, const doubletolerance = \fC1e-10\fP, InitialClusteringTypeclusterer = \fCInitialClusteringType()\fP, CovarianceConstraintPolicyconstraint = \fCCovarianceConstraintPolicy()\fP)

Construct the EMFit object, optionally passing an InitialClusteringType object (just in case it needs to store state). Setting the maximum number of iterations to 0 means that the EM algorithm will iterate until convergence (with the given tolerance).

The parameter forcePositive controls whether or not the covariance matrices are checked for positive definiteness at each iteration. This could be a time-consuming task, so, if you know your data is well-behaved, you can set it to false and save some runtime.

Parameters:

maxIterations Maximum number of iterations for EM.

tolerance Log-likelihood tolerance required for convergence.

forcePositive Check for positive-definiteness of each covariance matrix at each iteration.

clusterer Object which will perform the initial clustering.

Member Function Documentation

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> const InitialClusteringType& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Clusterer () const\fC [inline]\fP

Get the clusterer.

Definition at line 122 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::clusterer.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> InitialClusteringType& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Clusterer ()\fC [inline]\fP

Modify the clusterer.

Definition at line 124 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::clusterer.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> const CovarianceConstraintPolicy& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Constraint () const\fC [inline]\fP

Get the covariance constraint policy class.

Definition at line 127 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::constraint.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> CovarianceConstraintPolicy& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Constraint ()\fC [inline]\fP

Modify the covariance constraint policy class.

Definition at line 129 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::constraint.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> void \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Estimate (const arma::mat &observations, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights, const booluseInitialModel = \fCfalse\fP)

Fit the observations to a Gaussian mixture model (GMM) using the EM algorithm. The size of the vectors (indicating the number of components) must already be set. Optionally, if useInitialModel is set to true, then the model given in the means, covariances, and weights parameters is used as the initial model, instead of using the InitialClusteringType::Cluster() option.

Parameters:

observations List of observations to train on.

means Vector to store trained means in.

covariances Vector to store trained covariances in.

weights Vector to store a priori weights in.

useInitialModel If true, the given model is used for the initial clustering.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> void \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Estimate (const arma::mat &observations, const arma::vec &probabilities, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights, const booluseInitialModel = \fCfalse\fP)

Fit the observations to a Gaussian mixture model (GMM) using the EM algorithm, taking into account the probabilities of each point being from this mixture. The size of the vectors (indicating the number of components) must already be set. Optionally, if useInitialModel is set to true, then the model given in the means, covariances, and weights parameters is used as the initial model, instead of using the InitialClusteringType::Cluster() option.

Parameters:

observations List of observations to train on.

probabilities Probability of each point being from this model.

means Vector to store trained means in.

covariances Vector to store trained covariances in.

weights Vector to store a priori weights in.

useInitialModel If true, the given model is used for the initial clustering.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> void \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::InitialClustering (const arma::mat &observations, std::vector< arma::vec > &means, std::vector< arma::mat > &covariances, arma::vec &weights)\fC [private]\fP

Run the clusterer, and then turn the cluster assignments into Gaussians. This is a helper function for both overloads of Estimate(). The vectors must be already set to the number of clusters.

Parameters:

observations List of observations.

means Vector to store means in.

covariances Vector to store covariances in.

weights Vector to store a priori weights in.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> double \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::LogLikelihood (const arma::mat &data, const std::vector< arma::vec > &means, const std::vector< arma::mat > &covariances, const arma::vec &weights) const\fC [private]\fP

Calculate the log-likelihood of a model. Yes, this is reimplemented in the GMM code. Intuition suggests that the log-likelihood is not the best way to determine if the EM algorithm has converged.

Parameters:

data Data matrix.

means Vector of means.

covariances Vector of covariance matrices.

weights Vector of a priori weights.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> size_t \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::MaxIterations () const\fC [inline]\fP

Get the maximum number of iterations of the EM algorithm.

Definition at line 132 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::maxIterations.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> size_t& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::MaxIterations ()\fC [inline]\fP

Modify the maximum number of iterations of the EM algorithm.

Definition at line 134 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::maxIterations.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> double \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Tolerance () const\fC [inline]\fP

Get the tolerance for the convergence of the EM algorithm.

Definition at line 137 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::tolerance.

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> double& \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::Tolerance ()\fC [inline]\fP

Modify the tolerance for the convergence of the EM algorithm.

Definition at line 139 of file em_fit.hpp.

References mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::tolerance.

Member Data Documentation

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> InitialClusteringType \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::clusterer\fC [private]\fP

Object which will perform the clustering.

Definition at line 177 of file em_fit.hpp.

Referenced by mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::Clusterer().

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> CovarianceConstraintPolicy \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::constraint\fC [private]\fP

Object which applies constraints to the covariance matrix.

Definition at line 179 of file em_fit.hpp.

Referenced by mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::Constraint().

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> size_t \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::maxIterations\fC [private]\fP

Maximum iterations of EM algorithm.

Definition at line 173 of file em_fit.hpp.

Referenced by mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::MaxIterations().

template<typename InitialClusteringType = kmeans::KMeans<>, typename CovarianceConstraintPolicy = PositiveDefiniteConstraint> double \fBmlpack::gmm::EMFit\fP< InitialClusteringType, CovarianceConstraintPolicy >::tolerance\fC [private]\fP

Tolerance for convergence of EM.

Definition at line 175 of file em_fit.hpp.

Referenced by mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy >::Tolerance().

Author

Generated automatically by Doxygen for MLPACK from the source code.