Gaussian.h
Go to the documentation of this file.
1 // *****************************************************************
2 // Filename: Gaussian.h
3 // Copyright: Kai Welke, Chair Prof. Dillmann (IAIM),
4 // Institute for Computer Science and Engineering (CSE),
6 // Author: Kai Welke
7 // Date: 27.05.2012
8 // *****************************************************************
9 #pragma once
10
11 // *****************************************************************
12 // includes
13 // *****************************************************************
14 #include <math.h>
15 #include <vector>
16
17 #include <Eigen/Eigen>
18
19 class InvalidDimensionException : public std::exception
20 {
21  const char* what() const noexcept override
22  {
23  return "Invalid dimension";
24  }
25 };
26
27 class GaussianNotInitializedException : public std::exception
28 {
29  const char* what() const noexcept override
30  {
31  return "Gaussian not initialized";
32  }
33 };
34
35 class CovarianceNotSymmetricException : public std::exception
36 {
37  const char* what() const noexcept override
38  {
39  return "Covariance not symmetric";
40  }
41 };
42
43 // *****************************************************************
44 // declaration of Gaussian
45 // *****************************************************************
46 class Gaussian
47 {
48 public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50
51  // required types
52  using value_type = Eigen::VectorXd;
53  using covariance_type = Eigen::MatrixXd;
54  using samples_type = Eigen::MatrixXd;
55
56  // construction
57  Gaussian();
58  Gaussian(int dimension);
59  Gaussian(const Gaussian& prototype);
60  Gaussian(const value_type& mean, const covariance_type& covariance);
61
63  double mahalanobis(const value_type& point);
64  double evaluate(const value_type& point);
67
68  // content manipulation
69  void generateFromSamples(const samples_type& samples);
70
71  void set(const Gaussian& prototype);
72  void set(const value_type& mean, const covariance_type& cov);
73  void setMean(const value_type& mean);
74  void setCovariance(const covariance_type& cov);
75
76  // getters
78  {
79  return cov;
80  }
81  const value_type& getMean() const
82  {
83  return mean;
84  }
85  int getDimensions() const
86  {
87  return dimension;
88  }
89
90  // opertor
91  Gaussian& operator= (const Gaussian& prototype)
92  {
93  if (this != &prototype)
94  {
95  this->dimension = prototype.dimension;
96
97  this->cov = prototype.cov;
98  this->mean = prototype.mean;
99  }
100
101  return *this;
102  }
103
104  friend std::ostream& operator<<(std::ostream& stream, const Gaussian& rhs)
105  {
106  stream << "mean: " << std::endl << rhs.mean << std::endl;
107  stream << "cov: " << std::endl << rhs.cov << std::endl;
108  return stream;
109  }
110
111 private:
112  void isSymmetric(const covariance_type& matrix);
113
114  // direct access
115  value_type mean;
116  covariance_type cov;
117
118  int dimension;
119 };
120
Gaussian::getCovariance
const covariance_type & getCovariance() const
Definition: Gaussian.h:77
Gaussian::operator=
Gaussian & operator=(const Gaussian &prototype)
Definition: Gaussian.h:91
Gaussian::covariance_type
Eigen::MatrixXd covariance_type
Definition: Gaussian.h:53
Gaussian::mahalanobis
double mahalanobis(const value_type &point)
Definition: Gaussian.cpp:74
CovarianceNotSymmetricException
Definition: Gaussian.h:35
Gaussian::evaluate
double evaluate(const value_type &point)
Definition: Gaussian.cpp:55
Gaussian::getDimensions
int getDimensions() const
Definition: Gaussian.h:85
InvalidDimensionException
Definition: Gaussian.h:19
Gaussian::operator<<
friend std::ostream & operator<<(std::ostream &stream, const Gaussian &rhs)
Definition: Gaussian.h:104
Gaussian::samples_type
Eigen::MatrixXd samples_type
Definition: Gaussian.h:54
Gaussian::setMean
void setMean(const value_type &mean)
Definition: Gaussian.cpp:245
Gaussian::drawSample
value_type drawSample()
Definition: Gaussian.cpp:93
Gaussian::setCovariance
void setCovariance(const covariance_type &cov)
Definition: Gaussian.cpp:261
Gaussian::value_type
Eigen::VectorXd value_type
Definition: Gaussian.h:52
Gaussian::drawSampleDiagonalCovariance
value_type drawSampleDiagonalCovariance()
Definition: Gaussian.cpp:130
GaussianNotInitializedException
Definition: Gaussian.h:27
Gaussian::getMean
const value_type & getMean() const
Definition: Gaussian.h:81
Gaussian
Definition: Gaussian.h:46
Gaussian::generateFromSamples
void generateFromSamples(const samples_type &samples)
Definition: Gaussian.cpp:175
Gaussian::Gaussian
Gaussian()
Definition: Gaussian.cpp:20
Gaussian::set
void set(const Gaussian &prototype)
Definition: Gaussian.cpp:211