mlpack  master
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
mlpack::distribution::GaussianDistribution Class Reference

A single multivariate Gaussian distribution. More...

Public Member Functions

 GaussianDistribution ()
 Default constructor, which creates a Gaussian with zero dimension. More...
 
 GaussianDistribution (const size_t dimension)
 Create a Gaussian distribution with zero mean and identity covariance with the given dimensionality. More...
 
 GaussianDistribution (const arma::vec &mean, const arma::mat &covariance)
 Create a Gaussian distribution with the given mean and covariance. More...
 
const arma::mat & Covariance () const
 Return the covariance matrix. More...
 
void Covariance (const arma::mat &covariance)
 Set the covariance. More...
 
void Covariance (arma::mat &&covariance)
 
size_t Dimensionality () const
 Return the dimensionality of this distribution. More...
 
double LogProbability (const arma::vec &observation) const
 Return the log probability of the given observation. More...
 
void LogProbability (const arma::mat &x, arma::vec &logProbabilities) const
 Calculates the multivariate Gaussian log probability density function for each data point (column) in the given matrix. More...
 
const arma::vec & Mean () const
 Return the mean. More...
 
arma::vec & Mean ()
 Return a modifiable copy of the mean. More...
 
double Probability (const arma::vec &observation) const
 Return the probability of the given observation. More...
 
void Probability (const arma::mat &x, arma::vec &probabilities) const
 Calculates the multivariate Gaussian probability density function for each data point (column) in the given matrix. 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 unsigned int)
 Serialize the distribution. More...
 
void Train (const arma::mat &observations)
 Estimate the Gaussian distribution directly from the given observations. More...
 
void Train (const arma::mat &observations, const arma::vec &probabilities)
 Estimate the Gaussian distribution from the given observations, taking into account the probability of each observation actually being from this distribution. More...
 

Private Member Functions

void FactorCovariance ()
 This factors the covariance using arma::chol(). More...
 

Private Attributes

arma::mat covariance
 Positive definite covariance of the distribution. More...
 
arma::mat covLower
 Lower triangular factor of cov (e.g. cov = LL^T). More...
 
arma::mat invCov
 Cached inverse of covariance. More...
 
double logDetCov
 Cached logdet(cov). More...
 
arma::vec mean
 Mean of the distribution. More...
 

Static Private Attributes

static const constexpr double log2pi = 1.83787706640934533908193770912475883
 log(2pi) More...
 

Detailed Description

A single multivariate Gaussian distribution.

Definition at line 24 of file gaussian_distribution.hpp.

Constructor & Destructor Documentation

mlpack::distribution::GaussianDistribution::GaussianDistribution ( )
inline

Default constructor, which creates a Gaussian with zero dimension.

Definition at line 45 of file gaussian_distribution.hpp.

Referenced by GaussianDistribution().

mlpack::distribution::GaussianDistribution::GaussianDistribution ( const size_t  dimension)
inline

Create a Gaussian distribution with zero mean and identity covariance with the given dimensionality.

Definition at line 51 of file gaussian_distribution.hpp.

References GaussianDistribution().

mlpack::distribution::GaussianDistribution::GaussianDistribution ( const arma::vec &  mean,
const arma::mat &  covariance 
)

Create a Gaussian distribution with the given mean and covariance.

covariance is expected to be positive definite.

Member Function Documentation

const arma::mat& mlpack::distribution::GaussianDistribution::Covariance ( ) const
inline

Return the covariance matrix.

Definition at line 136 of file gaussian_distribution.hpp.

References covariance.

Referenced by mlpack::distribution::RegressionDistribution::RegressionDistribution().

void mlpack::distribution::GaussianDistribution::Covariance ( const arma::mat &  covariance)

Set the covariance.

void mlpack::distribution::GaussianDistribution::Covariance ( arma::mat &&  covariance)
size_t mlpack::distribution::GaussianDistribution::Dimensionality ( ) const
inline

Return the dimensionality of this distribution.

Definition at line 69 of file gaussian_distribution.hpp.

void mlpack::distribution::GaussianDistribution::FactorCovariance ( )
private

This factors the covariance using arma::chol().

The function assumes that the given matrix is factorizable via the Cholesky decomposition. If not, a std::runtime_error will be thrown.

Referenced by Serialize().

double mlpack::distribution::GaussianDistribution::LogProbability ( const arma::vec &  observation) const

Return the log probability of the given observation.

Referenced by Probability().

void mlpack::distribution::GaussianDistribution::LogProbability ( const arma::mat &  x,
arma::vec &  logProbabilities 
) const
inline

Calculates the multivariate Gaussian log probability density function for each data point (column) in the given matrix.

Parameters
xList of observations.
probabilitiesOutput log probabilities for each input observation.

Definition at line 177 of file gaussian_distribution.hpp.

References invCov, log2pi, logDetCov, and mean.

const arma::vec& mlpack::distribution::GaussianDistribution::Mean ( ) const
inline

Return the mean.

Definition at line 126 of file gaussian_distribution.hpp.

References mean.

arma::vec& mlpack::distribution::GaussianDistribution::Mean ( )
inline

Return a modifiable copy of the mean.

Definition at line 131 of file gaussian_distribution.hpp.

References mean.

double mlpack::distribution::GaussianDistribution::Probability ( const arma::vec &  observation) const
inline

Return the probability of the given observation.

Definition at line 74 of file gaussian_distribution.hpp.

References LogProbability().

void mlpack::distribution::GaussianDistribution::Probability ( const arma::mat &  x,
arma::vec &  probabilities 
) const
inline

Calculates the multivariate Gaussian probability density function for each data point (column) in the given matrix.

Parameters
xList of observations.
probabilitiesOutput probabilities for each input observation.

Definition at line 91 of file gaussian_distribution.hpp.

References LogProbability(), Random(), and Train().

arma::vec mlpack::distribution::GaussianDistribution::Random ( ) const

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

Returns
Random observation from this Gaussian distribution.

Referenced by Probability().

template<typename Archive >
void mlpack::distribution::GaussianDistribution::Serialize ( Archive &  ar,
const unsigned  int 
)
inline

Serialize the distribution.

Definition at line 149 of file gaussian_distribution.hpp.

References mlpack::data::CreateNVP(), and FactorCovariance().

void mlpack::distribution::GaussianDistribution::Train ( const arma::mat &  observations)

Estimate the Gaussian distribution directly from the given observations.

Parameters
observationsList of observations.

Referenced by Probability().

void mlpack::distribution::GaussianDistribution::Train ( const arma::mat &  observations,
const arma::vec &  probabilities 
)

Estimate the Gaussian distribution from the given observations, taking into account the probability of each observation actually being from this distribution.

Member Data Documentation

arma::mat mlpack::distribution::GaussianDistribution::covariance
private

Positive definite covariance of the distribution.

Definition at line 30 of file gaussian_distribution.hpp.

Referenced by Covariance().

arma::mat mlpack::distribution::GaussianDistribution::covLower
private

Lower triangular factor of cov (e.g. cov = LL^T).

Definition at line 32 of file gaussian_distribution.hpp.

arma::mat mlpack::distribution::GaussianDistribution::invCov
private

Cached inverse of covariance.

Definition at line 34 of file gaussian_distribution.hpp.

Referenced by LogProbability().

const constexpr double mlpack::distribution::GaussianDistribution::log2pi = 1.83787706640934533908193770912475883
staticprivate

log(2pi)

Definition at line 39 of file gaussian_distribution.hpp.

Referenced by LogProbability().

double mlpack::distribution::GaussianDistribution::logDetCov
private

Cached logdet(cov).

Definition at line 36 of file gaussian_distribution.hpp.

Referenced by LogProbability().

arma::vec mlpack::distribution::GaussianDistribution::mean
private

Mean of the distribution.

Definition at line 28 of file gaussian_distribution.hpp.

Referenced by LogProbability(), and Mean().


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