-
Notifications
You must be signed in to change notification settings - Fork 18
/
helper.h
33 lines (24 loc) · 969 Bytes
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef HELPER_H
#define HELPER_H
#include <eigen/Eigen/Core>
template<size_t Dimension>
const double normalDistributionDensity(const Eigen::Matrix<double, Dimension, Dimension> & cov,
const Eigen::Matrix<double, Dimension, 1> & mu, const Eigen::Matrix<double, Dimension, 1> & x )
{
const Eigen::Matrix<double, Dimension, 1> d = mu - x;
// calculate exponent
const double e = -0.5 * d.transpose() * cov.inverse() * d;
// get normal distribution value
return (1. / (std::pow(2 * M_PI, (double) Dimension * .5)
* std::sqrt(cov.determinant()))) * std::exp(e);
}
template<size_t Dimension = 1>
const double normalDistributionDensity(const double & var, const double & mu, const double & x )
{
const double d = mu - x;
// calculate exponent
const double e = -0.5 * std::pow(d, 2.) / var;
// get normal distribution value
return (1. / std::sqrt(2 * M_PI * var)) * std::exp(e);
}
#endif // HELPER_H