15 #ifndef __MLPACK_CORE_DISTRIBUTIONS_GAUSSIAN_DISTRIBUTION_HPP 16 #define __MLPACK_CORE_DISTRIBUTIONS_GAUSSIAN_DISTRIBUTION_HPP 21 namespace distribution {
41 static const constexpr
double log2pi = 1.83787706640934533908193770912475883;
54 mean(arma::zeros<arma::vec>(dimension)),
55 covariance(arma::eye<arma::mat>(dimension, dimension)),
56 covLower(arma::eye<arma::mat>(dimension, dimension)),
57 invCov(arma::eye<arma::mat>(dimension, dimension)),
93 void Probability(
const arma::mat& x, arma::vec& probabilities)
const 95 arma::vec logProbabilities;
97 probabilities = arma::exp(logProbabilities);
100 void LogProbability(
const arma::mat& x, arma::vec& logProbabilities)
const;
115 void Train(
const arma::mat& observations);
122 void Train(
const arma::mat& observations,
123 const arma::vec& probabilities);
150 template<
typename Archive>
157 ar &
CreateNVP(covariance,
"covariance");
180 arma::vec& logProbabilities)
const 183 arma::mat diffs = x - (
mean * arma::ones<arma::rowvec>(x.n_cols));
189 const arma::mat rhs = -0.5 *
invCov * diffs;
190 arma::vec logExponents(diffs.n_cols);
191 for (
size_t i = 0; i < diffs.n_cols; i++)
192 logExponents(i) = accu(diffs.unsafe_col(i) % rhs.unsafe_col(i));
194 const size_t k = x.n_rows;
A single multivariate Gaussian distribution.
arma::vec mean
Mean of the distribution.
Linear algebra utility functions, generally performed on matrices or vectors.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
void Probability(const arma::mat &x, arma::vec &probabilities) const
Calculates the multivariate Gaussian probability density function for each data point (column) in the...
arma::vec Random() const
Return a randomly generated observation according to the probability distribution defined by this obj...
void Train(const arma::mat &observations)
Estimate the Gaussian distribution directly from the given observations.
static const constexpr double log2pi
log(2pi)
void FactorCovariance()
This factors the covariance using arma::chol().
double logDetCov
Cached logdet(cov).
arma::mat covariance
Positive definite covariance of the distribution.
double LogProbability(const arma::vec &observation) const
Return the log probability of the given observation.
void Serialize(Archive &ar, const unsigned int)
Serialize the distribution.
arma::mat covLower
Lower triangular factor of cov (e.g. cov = LL^T).
double Probability(const arma::vec &observation) const
Return the probability of the given observation.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
GaussianDistribution(const size_t dimension)
Create a Gaussian distribution with zero mean and identity covariance with the given dimensionality...
arma::mat invCov
Cached inverse of covariance.
GaussianDistribution()
Default constructor, which creates a Gaussian with zero dimension.
size_t Dimensionality() const
Return the dimensionality of this distribution.
arma::vec & Mean()
Return a modifiable copy of the mean.
const arma::vec & Mean() const
Return the mean.
const arma::mat & Covariance() const
Return the covariance matrix.