CluE  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pointgauss.h
Go to the documentation of this file.
1 #ifndef CLUEPOINTGAUSS_H
2 #define CLUEPOINTGAUSS_H
3 
4 #include "../distribution/distribution.h"
5 #include "../point/point.h"
6 #include "../point/matrix.h"
7 
8 #include <random>
9 
10 #ifndef M_PI
11 #define M_PI 3.14159265358979323846
12 #endif
13 
14 namespace CluE
15 {
16 
22 class PointGauss : public Distribution<Point>
23 {
24 public:
25 
26  PointGauss(Point const& m, Matrix const& cov);
27 
31  virtual double density(Point const& x) const;
32 
36  virtual double nll(Point const& x) const;
37 
38  virtual double squaredMahalanobis(Point const& x) const;
39 
40  template<typename RndEngine> Point draw(RndEngine&) const;
41 
42 private:
45  double logSqrt; // log of sqrt of (2*pi)^d * det
46 };
47 
48 template<typename RndEngine>
49 Point PointGauss::draw(RndEngine& re) const
50 {
51  size_t d = this->mean.dimension();
52  std::normal_distribution<> nd(0,1);
53 
54  std::vector<double> coord;
55  for (size_t i=0; i<d; ++i)
56  coord.push_back(nd(re));
57  Matrix m = this->cholesky*Point(coord);
58 
59  coord.clear();
60  for (size_t i=0; i<d; ++i)
61  coord.push_back(m(i,0));
62  return Point(coord)+this->mean;
63 }
64 
65 }
66 
67 #endif
virtual double density(Point const &x) const
Evaluates the density of the multivariate normal distribution at the given point x.
Definition: pointgauss.cpp:23
virtual double squaredMahalanobis(Point const &x) const
Definition: pointgauss.cpp:53
PointGauss(Point const &m, Matrix const &cov)
Definition: pointgauss.cpp:10
Point draw(RndEngine &) const
Definition: pointgauss.h:49
Matrix covariance
Definition: pointgauss.h:44
Matrix inverseCholesky
Definition: pointgauss.h:44
size_t dimension() const
Definition: point.h:87
Weighted matrix of arbitrary dimension.
Definition: matrix.h:17
Univariate normal distribution.
Definition: pointgauss.h:22
Weighted point of arbitrary dimension.
Definition: point.h:17
Abstract base class for probability distributions.
Definition: distribution.h:16
virtual double nll(Point const &x) const
Computes the negative log-likelihood of the density at the given point x.
Definition: pointgauss.cpp:38