7 #ifndef SSMPACK_DISTRIBUTION_GAUSSIAN_HPP
8 #define SSMPACK_DISTRIBUTION_GAUSSIAN_HPP
17 namespace distribution {
34 arma::mat covariance_;
36 std::normal_distribution<double> normal_;
38 static constexpr
double pi = 3.1415926535897;
53 void calcDistConstants() {
55 inv_cov_ = arma::inv(covariance_);
57 double det_cov = arma::det(covariance_);
58 double den_pi = 1 / std::sqrt(std::pow(2 * pi, dim_));
59 part_ = den_pi * (1 / std::sqrt(det_cov));
61 chol_dec_ = arma::chol(covariance_,
"lower");
80 : mean_(std::move(mean)), covariance_(std::move(covariance)) {
92 return mean_ + chol_dec_ * rnd;
102 const auto diff = rv - mean_;
103 const arma::vec tmp = diff.t() * inv_cov_ * diff;
104 const double expt = -tmp(0) / 2;
105 return part_ * std::exp(expt);
114 return parameterize(std::get<0>(parameters), std::get<1>(parameters));
123 const arma::mat &covariance) {
125 covariance_ = covariance;
130 const arma::vec&
getMean()
const {
return mean_; }
138 #endif // SSMPACK_DISTRIBUTION_GAUSSIAN_HPP
const arma::mat & getCovariance() const
Returns the covariance matrix.
arma::vec random()
Returns a random variable from the distribution.
static Generator & get()
Returns a reference to singleton instance.
double likelihood(const arma::vec &rv) const
Returns the likelihood of a given random variable.
Gaussian & parameterize(const arma::vec &mean, const arma::mat &covariance)
Changes the mean and covariance of the distribution with the given values.
std::tuple< arma::vec, arma::mat > TParameterVAR
Data type of the parameter variable .
const arma::vec & getMean() const
Returns the mean vector.
A D-dimensional multivariate Gaussian distribution.
Gaussian(int dim)
Default constructor.
Gaussian(arma::vec mean, arma::mat covariance)
Returns D dimensional Gaussian with given mean and covariance.
Gaussian & parameterize(const TParameterVAR ¶meters)
Changes the mean and covariance of the distribution with the given parameters.