added kullback leibler for gaussian cases

This commit is contained in:
toni
2017-03-09 18:57:47 +01:00
parent f7d0d88448
commit d5bc1111f5
9 changed files with 374 additions and 8 deletions

View File

@@ -0,0 +1,50 @@
#ifndef NORMALN_H
#define NORMALN_H
#include <eigen3/Eigen/Dense>
namespace Distribution {
class NormalDistributionN {
private:
const Eigen::VectorXd mu;
const Eigen::MatrixXd sigma;
const double _a;
const Eigen::MatrixXd _sigmaInv;
public:
/** ctor */
NormalDistributionN(const Eigen::VectorXd mu, const Eigen::MatrixXd sigma) :
mu(mu), sigma(sigma), _a( 1.0 / std::sqrt( (sigma * 2.0 * M_PI).determinant() ) ), _sigmaInv(sigma.inverse()) {
}
/** get probability for the given value */
double getProbability(const Eigen::VectorXd val) const {
const double b = ((val-mu).transpose() * _sigmaInv * (val-mu));
return _a * std::exp(-b/2.0);
}
/** get the mean vector */
const Eigen::VectorXd getMu(){
return this->mu;
}
/** get covariance matrix */
const Eigen::MatrixXd getSigma(){
return this->sigma;
}
const Eigen::MatrixXd getSigmaInv(){
return this->_sigmaInv;
}
};
}
#endif // NORMALN_H