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),
5// University of Karlsruhe. All rights reserved.
6// Author: Kai Welke
7// Date: 27.05.2012
8// *****************************************************************
9#pragma once
10
11// *****************************************************************
12// includes
13// *****************************************************************
14#include <math.h>
15
16#include <vector>
17
18#include <Eigen/Eigen>
19
20class InvalidDimensionException : public std::exception
21{
22 const char*
23 what() const noexcept override
24 {
25 return "Invalid dimension";
26 }
27};
28
29class GaussianNotInitializedException : public std::exception
30{
31 const char*
32 what() const noexcept override
33 {
34 return "Gaussian not initialized";
35 }
36};
37
38class CovarianceNotSymmetricException : public std::exception
39{
40 const char*
41 what() const noexcept override
42 {
43 return "Covariance not symmetric";
44 }
45};
46
47// *****************************************************************
48// declaration of Gaussian
49// *****************************************************************
51{
52public:
53 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
54
55 // required types
56 using value_type = Eigen::VectorXd;
57 using covariance_type = Eigen::MatrixXd;
58 using samples_type = Eigen::MatrixXd;
59
60 // construction
61 Gaussian();
62 Gaussian(int dimension);
63 Gaussian(const Gaussian& prototype);
64 Gaussian(const value_type& mean, const covariance_type& covariance);
65
66 // readouts
67 double mahalanobis(const value_type& point);
68 double evaluate(const value_type& point);
71
72 // content manipulation
73 void generateFromSamples(const samples_type& samples);
74
75 void set(const Gaussian& prototype);
76 void set(const value_type& mean, const covariance_type& cov);
77 void setMean(const value_type& mean);
78 void setCovariance(const covariance_type& cov);
79
80 // getters
81 const covariance_type&
83 {
84 return cov;
85 }
86
87 const value_type&
88 getMean() const
89 {
90 return mean;
91 }
92
93 int
95 {
96 return dimension;
97 }
98
99 // opertor
100 Gaussian&
101 operator=(const Gaussian& prototype)
102 {
103 if (this != &prototype)
104 {
105 this->dimension = prototype.dimension;
106
107 this->cov = prototype.cov;
108 this->mean = prototype.mean;
109 }
110
111 return *this;
112 }
113
114 friend std::ostream&
115 operator<<(std::ostream& stream, const Gaussian& rhs)
116 {
117 stream << "mean: " << std::endl << rhs.mean << std::endl;
118 stream << "cov: " << std::endl << rhs.cov << std::endl;
119 return stream;
120 }
121
122private:
123 void isSymmetric(const covariance_type& matrix);
124
125 // direct access
126 value_type mean;
127 covariance_type cov;
128
129 int dimension;
130};
friend std::ostream & operator<<(std::ostream &stream, const Gaussian &rhs)
Definition Gaussian.h:115
const covariance_type & getCovariance() const
Definition Gaussian.h:82
Eigen::VectorXd value_type
Definition Gaussian.h:56
double evaluate(const value_type &point)
Definition Gaussian.cpp:57
value_type drawSample()
Definition Gaussian.cpp:98
int getDimensions() const
Definition Gaussian.h:94
Eigen::MatrixXd samples_type
Definition Gaussian.h:58
void set(const Gaussian &prototype)
Definition Gaussian.cpp:219
Gaussian & operator=(const Gaussian &prototype)
Definition Gaussian.h:101
Eigen::MatrixXd covariance_type
Definition Gaussian.h:57
void setCovariance(const covariance_type &cov)
Definition Gaussian.cpp:272
void setMean(const value_type &mean)
Definition Gaussian.cpp:255
value_type drawSampleDiagonalCovariance()
Definition Gaussian.cpp:136
const value_type & getMean() const
Definition Gaussian.h:88
void generateFromSamples(const samples_type &samples)
Definition Gaussian.cpp:182
double mahalanobis(const value_type &point)
Definition Gaussian.cpp:78