mlpack
|
A Diagonal Gaussian Mixture Model. More...
#include <diagonal_gmm.hpp>
Public Member Functions | |
DiagonalGMM () | |
Create an empty Diagonal Gaussian Mixture Model, with zero gaussians. | |
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. | |
DiagonalGMM & | operator= (const DiagonalGMM &other) |
Copy operator for DiagonalGMMs. | |
size_t | Gaussians () const |
Return the number of Gaussians in the model. | |
size_t | Dimensionality () const |
Return the dimensionality of the model. | |
const distribution::DiagonalGaussianDistribution & | Component (size_t i) const |
Return a const reference to a component distribution. More... | |
distribution::DiagonalGaussianDistribution & | Component (size_t i) |
Return a reference to a component distribution. More... | |
const arma::vec & | Weights () const |
Return a const reference to the a priori weights of each Gaussian. | |
arma::vec & | Weights () |
Return a reference to the a priori weights of each Gaussian. | |
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 | 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 | 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... | |
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... | |
arma::vec | Random () const |
Return a randomly generated observation according to the probability distribution defined by this object. 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... | |
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... | |
template<typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the DiagonalGMM. More... | |
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:
Example use:
mlpack::gmm::DiagonalGMM::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.
Create a DiagonalGMM with the given number of Gaussians, each of which have the specified dimensionality.
The means and covariances will be set to 0.
gaussians | Number of Gaussians in this DiagonalGMM. |
dimensionality | Dimensionality of each Gaussian. |
The means and covariances will be set to 0.
gaussians | Number of Gaussians in this GMM. |
dimensionality | Dimensionality of each Gaussian. |
|
inline |
Create a DiagonalGMM with the given dists and weights.
dists | Distributions of the model. |
weights | Weights of the model. |
void mlpack::gmm::DiagonalGMM::Classify | ( | const arma::mat & | observations, |
arma::Row< size_t > & | labels | ||
) | const |
Classify the given observations as being from an individual component in this DiagonalGMM.
Classify the given observations as being from an individual component in this GMM.
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:
observations | Matrix of observations to classify. |
labels | Object which will be filled with labels. |
|
inline |
Return a const reference to a component distribution.
i | Index of component. |
|
inline |
Return a reference to a component distribution.
i | Index of component. |
double mlpack::gmm::DiagonalGMM::LogProbability | ( | const arma::vec & | observation | ) | const |
Return the log probability that the given observation came from this distribution.
Return the log probability of the given observation being from this GMM.
observation | Observation to evaluate the log-probability of. |
void mlpack::gmm::DiagonalGMM::LogProbability | ( | const arma::mat & | observation, |
arma::vec & | logProbs | ||
) | const |
Return the log probability that the given observation matrix.
Return the log probability of the given observation GMM matrix.
observation | Observation to evaluate the log-probability of. |
logProbs | Stores the value of log-probability for observation. |
observation | Observation matrix to compute log-probabilty. |
logProbs | Stores the value of log-probability for input. |
double mlpack::gmm::DiagonalGMM::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.
Return the log probability of the given observation being from the given component in the mixture.
observation | Observation to evaluate the probability of. |
component | Index of the component of the DiagonalGMM. |
double mlpack::gmm::DiagonalGMM::Probability | ( | const arma::vec & | observation | ) | const |
Return the probability that the given observation came from this distribution.
Return the probability of the given observation being from this GMM.
observation | Observation to evaluate the probability of. |
void mlpack::gmm::DiagonalGMM::Probability | ( | const arma::mat & | observation, |
arma::vec & | probs | ||
) | const |
Return the probability that the given observation matrix.
Return the probability of the given observation GMM matrix.
observation | Observation to evaluate the probability of. |
probs | Stores the value of probability for observation. |
observation | Observation matrix to compute probabilty. |
probs | Stores the value of probability for observation. |
double mlpack::gmm::DiagonalGMM::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.
Return the probability of the given observation being from the given component in the mixture.
observation | Observation to evaluate the probability of. |
component | Index of the component of the DiagonalGMM. |
arma::vec mlpack::gmm::DiagonalGMM::Random | ( | ) | const |
Return a randomly generated observation according to the probability distribution defined by this object.
void mlpack::gmm::DiagonalGMM::serialize | ( | Archive & | ar, |
const uint32_t | |||
) |
Serialize the DiagonalGMM.
Serialize the object.
double mlpack::gmm::DiagonalGMM::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.
Fit the DiagonalGMM to the given observations.
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.
observations | Observations of the model. |
trials | Number of trials to perform; the model in these trials with the greatest log-likelihood will be selected. |
useExistingModel | If true, the existing model is used as an initial model for the estimation. |
fitter | Fitting type that estimates observations. |
double mlpack::gmm::DiagonalGMM::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.
Fit the DiagonalGMM to the given observations, each of which has a certain probability of being from this distribution.
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.
observations | Observations of the model. |
probabilities | Probability of each observation being from this distribution. |
trials | Number of trials to perform; the model in these trials with the greatest log-likelihood will be selected. |
useExistingModel | If true, the existing model is used as an initial model for the estimation. |
fitter | Fitting type that estimates observations. |