This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/distribution/NormalN.h
2017-03-10 14:43:46 +01:00

51 lines
1.1 KiB
C++

#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