mlpack
Public Member Functions | List of all members
mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy, Distribution > Class Template Reference

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

#include <em_fit.hpp>

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). More...
 
void Estimate (const arma::mat &observations, std::vector< Distribution > &dists, arma::vec &weights, const bool useInitialModel=false)
 Fit the observations to a Gaussian mixture model (GMM) using the EM algorithm. More...
 
void Estimate (const arma::mat &observations, const arma::vec &probabilities, std::vector< Distribution > &dists, 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. More...
 
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.
 
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.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t version)
 Serialize the fitter.
 

Detailed Description

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

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:

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

Constructor & Destructor Documentation

◆ EMFit()

template<typename InitialClusteringType , typename CovarianceConstraintPolicy , typename Distribution >
mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy, Distribution >::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).

Constructor.

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
maxIterationsMaximum number of iterations for EM.
toleranceLog-likelihood tolerance required for convergence.
clustererObject which will perform the initial clustering.
constraintConstraint policy of covariance.

Member Function Documentation

◆ Estimate() [1/2]

template<typename InitialClusteringType , typename CovarianceConstraintPolicy , typename Distribution >
void mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy, Distribution >::Estimate ( const arma::mat &  observations,
std::vector< Distribution > &  dists,
arma::vec &  weights,
const bool  useInitialModel = false 
)

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
observationsList of observations to train on.
distsDistributions to store model in.
weightsVector to store a priori weights in.
useInitialModelIf true, the given model is used for the initial clustering.

◆ Estimate() [2/2]

template<typename InitialClusteringType , typename CovarianceConstraintPolicy , typename Distribution >
void mlpack::gmm::EMFit< InitialClusteringType, CovarianceConstraintPolicy, Distribution >::Estimate ( const arma::mat &  observations,
const arma::vec &  probabilities,
std::vector< Distribution > &  dists,
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.

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
observationsList of observations to train on.
probabilitiesProbability of each point being from this model.
distsDistributions to store model in.
weightsVector to store a priori weights in.
useInitialModelIf true, the given model is used for the initial clustering.

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