41 #include <eigen3/Eigen/Cholesky>
42 #include <eigen3/Eigen/Core>
52 template <
typename Derived1,
typename Derived2>
53 MultivariateGaussian(
const Eigen::MatrixBase<Derived1>& mean,
const Eigen::MatrixBase<Derived2>& covariance);
55 template <
typename Derived>
56 void sample(Eigen::MatrixBase<Derived>& output);
59 Eigen::VectorXd mean_;
60 Eigen::MatrixXd covariance_;
61 Eigen::MatrixXd covariance_cholesky_;
65 std::normal_distribution<double> gaussian_;
70 template <
typename Derived1,
typename Derived2>
72 const Eigen::MatrixBase<Derived2>& covariance)
73 : mean_(mean), covariance_(covariance), covariance_cholesky_(covariance_.llt().matrixL()), gaussian_(0.0, 1.0)
75 rng_ = std::mt19937(std::random_device{}());
79 template <
typename Derived>
82 for (
int i = 0; i < size_; ++i)
83 output(i) = gaussian_(rng_);
84 output = mean_ + covariance_cholesky_ * output;
Generates samples from a multivariate gaussian distribution.
void sample(Eigen::MatrixBase< Derived > &output)
MultivariateGaussian(const Eigen::MatrixBase< Derived1 > &mean, const Eigen::MatrixBase< Derived2 > &covariance)