added kullback leibler for gaussian cases
This commit is contained in:
50
math/distribution/NormalN.h
Normal file
50
math/distribution/NormalN.h
Normal 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
|
||||
Reference in New Issue
Block a user