13 #ifndef MLPACK_CORE_DISTRIBUTIONS_GAUSSIAN_DISTRIBUTION_HPP 14 #define MLPACK_CORE_DISTRIBUTIONS_GAUSSIAN_DISTRIBUTION_HPP 19 namespace distribution {
39 static const constexpr
double log2pi = 1.83787706640934533908193770912475883;
52 mean(arma::zeros<arma::vec>(dimension)),
53 covariance(arma::eye<arma::mat>(dimension, dimension)),
54 covLower(arma::eye<arma::mat>(dimension, dimension)),
55 invCov(arma::eye<arma::mat>(dimension, dimension)),
91 void Probability(
const arma::mat& x, arma::vec& probabilities)
const 97 probabilities = arma::exp(logProbs);
112 diffs.each_col() -= mean;
116 logProbabilities = -0.5 * x.n_rows * log2pi - 0.5 * logDetCov +
117 sum(diffs % (-0.5 * invCov * diffs), 0).t();
133 void Train(
const arma::mat& observations);
140 void Train(
const arma::mat& observations,
141 const arma::vec& probabilities);
146 const arma::vec&
Mean()
const {
return mean; }
151 arma::vec&
Mean() {
return mean; }
166 const arma::mat&
InvCov()
const {
return invCov; }
174 template<
typename Archive>
178 ar(CEREAL_NVP(mean));
179 ar(CEREAL_NVP(covariance));
180 ar(CEREAL_NVP(covLower));
181 ar(CEREAL_NVP(invCov));
182 ar(CEREAL_NVP(logDetCov));
191 void FactorCovariance();
void LogProbability(const arma::mat &x, arma::vec &logProbabilities) const
Returns the Log probability of the given matrix.
A single multivariate Gaussian distribution.
double LogProbability(const arma::vec &observation) const
Return the log probability of the given observation.
const arma::mat & InvCov() const
Return the invCov.
Linear algebra utility functions, generally performed on matrices or vectors.
GaussianDistribution(const size_t dimension)
Create a Gaussian distribution with zero mean and identity covariance with the given dimensionality...
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Probability(const arma::vec &observation) const
Return the probability of the given observation.
GaussianDistribution()
Default constructor, which creates a Gaussian with zero dimension.
arma::vec Random() const
Return a randomly generated observation according to the probability distribution defined by this obj...
void serialize(Archive &ar, const uint32_t)
Serialize the distribution.
double LogDetCov() const
Return the logDetCov.
size_t Dimensionality() const
Return the dimensionality of this distribution.
void Probability(const arma::mat &x, arma::vec &probabilities) const
Calculates the multivariate Gaussian probability density function for each data point (column) in the...
void Train(const arma::mat &observations)
Estimate the Gaussian distribution directly from the given observations.
const arma::mat & Covariance() const
Return the covariance matrix.
arma::vec & Mean()
Return a modifiable copy of the mean.
const arma::vec & Mean() const
Return the mean.