DiagonalGMM Class Reference

A Diagonal Gaussian Mixture Model. More...

Public Member Functions

 DiagonalGMM ()
 Create an empty Diagonal Gaussian Mixture Model, with zero gaussians. More...

 
 DiagonalGMM (const size_t gaussians, const size_t dimensionality)
 Create a GMM with the given number of Gaussians, each of which have the specified dimensionality. More...

 
 DiagonalGMM (const std::vector< distribution::DiagonalGaussianDistribution > &dists, const arma::vec &weights)
 Create a DiagonalGMM with the given dists and weights. More...

 
 DiagonalGMM (const DiagonalGMM &other)
 Copy constructor for DiagonalGMMs. More...

 
void Classify (const arma::mat &observations, arma::Row< size_t > &labels) const
 Classify the given observations as being from an individual component in this DiagonalGMM. More...

 
const distribution::DiagonalGaussianDistributionComponent (size_t i) const
 Return a const reference to a component distribution. More...

 
distribution::DiagonalGaussianDistributionComponent (size_t i)
 Return a reference to a component distribution. More...

 
size_t Dimensionality () const
 Return the dimensionality of the model. More...

 
size_t Gaussians () const
 Return the number of Gaussians in the model. More...

 
double LogProbability (const arma::vec &observation) const
 Return the log probability that the given observation came from this distribution. More...

 
void LogProbability (const arma::mat &observation, arma::vec &logProbs) const
 Return the log probability that the given observation matrix. More...

 
double LogProbability (const arma::vec &observation, const size_t component) const
 Return the log probability that the given observation came from the given Gaussian component in this distribution. More...

 
DiagonalGMMoperator= (const DiagonalGMM &other)
 Copy operator for DiagonalGMMs. More...

 
double Probability (const arma::vec &observation) const
 Return the probability that the given observation came from this distribution. More...

 
void Probability (const arma::mat &observation, arma::vec &probs) const
 Return the probability that the given observation matrix. More...

 
double Probability (const arma::vec &observation, const size_t component) const
 Return the probability that the given observation came from the given Gaussian component in this distribution. More...

 
arma::vec Random () const
 Return a randomly generated observation according to the probability distribution defined by this object. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the DiagonalGMM. More...

 
template<typename FittingType = EMFit<kmeans::KMeans<>, DiagonalConstraint, distribution::DiagonalGaussianDistribution>>
double Train (const arma::mat &observations, const size_t trials=1, const bool useExistingModel=false, FittingType fitter=FittingType())
 Estimate the probability distribution directly from the given observations, using the given algorithm in the FittingType class to fit the data. More...

 
template<typename FittingType = EMFit<kmeans::KMeans<>, DiagonalConstraint, distribution::DiagonalGaussianDistribution>>
double Train (const arma::mat &observations, const arma::vec &probabilities, const size_t trials=1, const bool useExistingModel=false, FittingType fitter=FittingType())
 Estimate the probability distribution directly from the given observations, taking into account the probability of each observation actually being from this distribution, and using the given algorithm in the FittingType class to fit the data. More...

 
const arma::vec & Weights () const
 Return a const reference to the a priori weights of each Gaussian. More...

 
arma::vec & Weights ()
 Return a reference to the a priori weights of each Gaussian. More...

 

Detailed Description

A Diagonal Gaussian Mixture Model.

This class uses maximum likelihood loss functions to estimate the parameters of the DiagonalGMM on a given dataset via the given fitting mechanism, defined by the FittingType template parameter. The DiagonalGMM can be trained using normal data, or data with probabilities of being from this GMM (see DiagonalGMM::Train() for more information). The DiagonalGMM is the same as GMM except for wrapping gmm_diag class.

The Train() method uses a template type 'FittingType'. The FittingType template class must provide a way for the DiagonalGMM to train on data. It must provide the following two functions:

void Estimate(
const arma::mat& observations,
std::vector<distribution::DiagonalGaussianDistribution>& dists,
arma::vec& weights);
void Estimate(
const arma::mat& observations,
const arma::vec& probabilities,
std::vector<distribution::DiagonalGaussianDistribution>& dists,
arma::vec& weights);

Example use:

// Set up a mixture of 5 gaussians in a 4-dimensional space.
DiagonalGMM g(5, 4);
// Train the DiagonalGMM given the data observations, using the default
// EM fitting mechanism.
g.Train(data);
// Get the probability of 'observation' being observed from this
// DiagoanlGMM.
double probability = g.Probability(observation);
// Get a random observation from the DiagonalGMM.
arma::vec observation = g.Random();

Definition at line 74 of file diagonal_gmm.hpp.

Constructor & Destructor Documentation

◆ DiagonalGMM() [1/4]

DiagonalGMM ( )
inline

Create an empty Diagonal Gaussian Mixture Model, with zero gaussians.

Definition at line 92 of file diagonal_gmm.hpp.

References Log::Debug.

Referenced by DiagonalGMM::DiagonalGMM().

◆ DiagonalGMM() [2/4]

DiagonalGMM ( const size_t  gaussians,
const size_t  dimensionality 
)

Create a GMM with the given number of Gaussians, each of which have the specified dimensionality.

The means and covariances will be set to 0.

Parameters
gaussiansNumber of Gaussians in this DiagonalGMM.
dimensionalityDimensionality of each Gaussian.

◆ DiagonalGMM() [3/4]

DiagonalGMM ( const std::vector< distribution::DiagonalGaussianDistribution > &  dists,
const arma::vec &  weights 
)
inline

Create a DiagonalGMM with the given dists and weights.

Parameters
distsDistributions of the model.
weightsWeights of the model.

Definition at line 118 of file diagonal_gmm.hpp.

References DiagonalGMM::DiagonalGMM(), and DiagonalGMM::operator=().

◆ DiagonalGMM() [4/4]

DiagonalGMM ( const DiagonalGMM other)

Copy constructor for DiagonalGMMs.

Member Function Documentation

◆ Classify()

void Classify ( const arma::mat &  observations,
arma::Row< size_t > &  labels 
) const

Classify the given observations as being from an individual component in this DiagonalGMM.

The resultant classifications are stored in the 'labels' object, and each label will be between 0 and (Gaussians() - 1). Supposing that a point was classified with label 2, and that our DiagonalGMM object was called 'dgmm', one could access the relevant Gaussian distribution as follows:

arma::vec mean = dgmm.Means()[2];
arma::mat covariance = dgmm.Covariances()[2];
double priorWeight = dgmm.Weights()[2];
Parameters
observationsMatrix of observations to classify.
labelsObject which will be filled with labels.

Referenced by DiagonalGMM::Weights().

◆ Component() [1/2]

const distribution::DiagonalGaussianDistribution& Component ( size_t  i) const
inline

Return a const reference to a component distribution.

Parameters
iIndex of component.

Definition at line 141 of file diagonal_gmm.hpp.

◆ Component() [2/2]

distribution::DiagonalGaussianDistribution& Component ( size_t  i)
inline

Return a reference to a component distribution.

Parameters
iIndex of component.

Definition at line 151 of file diagonal_gmm.hpp.

◆ Dimensionality()

size_t Dimensionality ( ) const
inline

Return the dimensionality of the model.

Definition at line 134 of file diagonal_gmm.hpp.

◆ Gaussians()

size_t Gaussians ( ) const
inline

Return the number of Gaussians in the model.

Definition at line 132 of file diagonal_gmm.hpp.

◆ LogProbability() [1/3]

double LogProbability ( const arma::vec &  observation) const

Return the log probability that the given observation came from this distribution.

Parameters
observationObservation to evaluate the log-probability of.

Referenced by DiagonalGMM::Weights().

◆ LogProbability() [2/3]

void LogProbability ( const arma::mat &  observation,
arma::vec &  logProbs 
) const

Return the log probability that the given observation matrix.

Parameters
observationObservation to evaluate the log-probability of.
logProbsStores the value of log-probability for observation.

◆ LogProbability() [3/3]

double LogProbability ( const arma::vec &  observation,
const size_t  component 
) const

Return the log probability that the given observation came from the given Gaussian component in this distribution.

Parameters
observationObservation to evaluate the probability of.
componentIndex of the component of the DiagonalGMM.

◆ operator=()

DiagonalGMM& operator= ( const DiagonalGMM other)

Copy operator for DiagonalGMMs.

Referenced by DiagonalGMM::DiagonalGMM().

◆ Probability() [1/3]

double Probability ( const arma::vec &  observation) const

Return the probability that the given observation came from this distribution.

Parameters
observationObservation to evaluate the probability of.

Referenced by DiagonalGMM::Weights().

◆ Probability() [2/3]

void Probability ( const arma::mat &  observation,
arma::vec &  probs 
) const

Return the probability that the given observation matrix.

Parameters
observationObservation to evaluate the probability of.
probsStores the value of probability for observation.

◆ Probability() [3/3]

double Probability ( const arma::vec &  observation,
const size_t  component 
) const

Return the probability that the given observation came from the given Gaussian component in this distribution.

Parameters
observationObservation to evaluate the probability of.
componentIndex of the component of the DiagonalGMM.

◆ Random()

arma::vec Random ( ) const

Return a randomly generated observation according to the probability distribution defined by this object.

Returns
Random observation from this DiagonalGMM.

Referenced by DiagonalGMM::Weights().

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

Serialize the DiagonalGMM.

Referenced by DiagonalGMM::Weights().

◆ Train() [1/2]

double Train ( const arma::mat &  observations,
const size_t  trials = 1,
const bool  useExistingModel = false,
FittingType  fitter = FittingType() 
)

Estimate the probability distribution directly from the given observations, using the given algorithm in the FittingType class to fit the data.

The fitting will be performed 'trials' times; from these trials, the model with the greatest log-likelihood will be selected. By default, only one trial is performed. The log-likelihood of the best fitting is returned.

Optionally, the existing model can be used as an initial model for the estimation by setting 'useExistingModel' to true. If the fitting procedure is deterministic after the initial position is given, then 'trials' should be set to 1.

Parameters
observationsObservations of the model.
trialsNumber of trials to perform; the model in these trials with the greatest log-likelihood will be selected.
useExistingModelIf true, the existing model is used as an initial model for the estimation.
fitterFitting type that estimates observations.
Returns
The log-likelihood of the best fit.

Referenced by DiagonalGMM::Weights().

◆ Train() [2/2]

double Train ( const arma::mat &  observations,
const arma::vec &  probabilities,
const size_t  trials = 1,
const bool  useExistingModel = false,
FittingType  fitter = FittingType() 
)

Estimate the probability distribution directly from the given observations, taking into account the probability of each observation actually being from this distribution, and using the given algorithm in the FittingType class to fit the data.

The fitting will be performed 'trials' times; from these trials, the model with the greatest log-likelihood will be selected. By default, only one trial is performed. The log-likelihood of the best fitting is returned.

Optionally, the existing model can be used as an initial model for the estimation by setting 'useExistingModel' to true. If the fitting procedure is deterministic after the initial position is given, then 'trials' should be set to 1.

Parameters
observationsObservations of the model.
probabilitiesProbability of each observation being from this distribution.
trialsNumber of trials to perform; the model in these trials with the greatest log-likelihood will be selected.
useExistingModelIf true, the existing model is used as an initial model for the estimation.
fitterFitting type that estimates observations.
Returns
The log-likelihood of the best fit.

◆ Weights() [1/2]

const arma::vec& Weights ( ) const
inline

Return a const reference to the a priori weights of each Gaussian.

Definition at line 157 of file diagonal_gmm.hpp.

◆ Weights() [2/2]

arma::vec& Weights ( )
inline

Return a reference to the a priori weights of each Gaussian.

Definition at line 159 of file diagonal_gmm.hpp.

References DiagonalGMM::Classify(), DiagonalGMM::LogProbability(), DiagonalGMM::Probability(), DiagonalGMM::Random(), DiagonalGMM::serialize(), and DiagonalGMM::Train().


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/methods/gmm/diagonal_gmm.hpp