Direct Graphical Models  v.1.7.0
KDGauss.h
1 // K-Dimensional Gauss function
2 // Written by Sergey G. Kosov in 2012 - 2014 for Project X
3 #pragma once
4 
5 #include "types.h"
6 
7 namespace DirectGraphicalModels
8 {
9  // ================================ KDGauss Class ==============================
28  class CKDGauss
29  {
30  public:
35  DllExport CKDGauss(dword k);
41  DllExport CKDGauss(const Mat &mu);
45  DllExport CKDGauss(const CKDGauss &rhs);
46 
50  DllExport CKDGauss & operator= (const CKDGauss & rhs);
64  DllExport CKDGauss & operator+= (const CKDGauss &rhs);
74  DllExport CKDGauss & operator+= (const Mat &point);
75 
80  DllExport void clear(void);
86  DllExport bool empty(void) const { return (m_nPoints == 0); }
87 
90 
94  DllExport void setNumPoints(long nPoints) { m_nPoints = nPoints; }
99  DllExport size_t getNumPoints(void) const { return m_nPoints; }
104  DllExport void setMu(Mat &mu);
109  DllExport Mat getMu(void) const { return m_mu.clone(); }
114  DllExport void setSigma(Mat &sigma);
119  DllExport Mat getSigma(void) const { return m_sigma.clone(); }
121 
124 
140  DllExport void addPoint(const Mat &point, bool approximate = false);
145  DllExport long double getAlpha(void) const;
167  DllExport double getValue(Mat &x, Mat &aux1 = EmptyMat, Mat &aux2 = EmptyMat, Mat &aux3 = EmptyMat) const;
173  DllExport Mat getSample(void) const;
175 
178 
184  DllExport double getEuclidianDistance(const Mat &x) const;
191  DllExport double getMahalanobisDistance(const Mat &x) const;
202  DllExport double getKullbackLeiberDivergence(const CKDGauss &x) const;
204 
205 
206  private:
207  static const bool USE_SAFE_SIGMA;
208 
209 
210  private:
211  size_t m_nPoints; // number of samples
212  Mat m_mu; // The mathematical expectation \f$mu\f$: (size: k x 1; type: CV_64FC1)
213  Mat m_sigma; // The covariance matrix \f$\Sigma\f$: (size: k x k; type: CV_64FC1)
214  mutable Mat m_sigmaInv = Mat(); // the inverse to the <sigma> matrix
215  mutable Mat m_Q = Mat(); // aux Mat for getSample()
216  mutable long double m_alpha = -1; // gaussian coefficient
217 
218 
219  private:
225  Mat getSigmaInv(void) const;
226  inline void reset_SigmaInv_Q_Alpha(void);
227  Mat calculateQ(void) const;
228  };
229 
230  using GaussianMixture = std::vector<CKDGauss>;
231 }
void setNumPoints(long nPoints)
Sets the number of approximation points.
Definition: KDGauss.h:94
void clear(void)
Clears class variables.
Definition: KDGauss.cpp:81
void addPoint(const Mat &point, bool approximate=false)
Adds new k-dimensional point (sample) for Gaussian distribution approximation.
Definition: KDGauss.cpp:90
Mat getSigmaInv(void) const
Returns .
Definition: KDGauss.cpp:156
double getMahalanobisDistance(const Mat &x) const
Returns the Mahalanobis distance between argument point x and the center of multivariate normal distr...
Definition: KDGauss.cpp:198
void setSigma(Mat &sigma)
Sets .
Definition: KDGauss.cpp:145
Mat getSample(void) const
Returns a random vector (sample) from multivariate normal distribution.
Definition: KDGauss.cpp:229
double getValue(Mat &x, Mat &aux1=EmptyMat, Mat &aux2=EmptyMat, Mat &aux3=EmptyMat) const
Returns unscaled value of the Gaussian function.
Definition: KDGauss.cpp:175
size_t getNumPoints(void) const
Returns the number of approximation points.
Definition: KDGauss.h:99
CKDGauss & operator+=(const CKDGauss &rhs)
Compound merge operator.
Definition: KDGauss.cpp:50
long double getAlpha(void) const
Returns .
Definition: KDGauss.cpp:163
CKDGauss(dword k)
Constructor.
Definition: KDGauss.cpp:12
double getKullbackLeiberDivergence(const CKDGauss &x) const
Returns the Kullback-Leiber divergence from the multivariate normal distribution to argument multiva...
Definition: KDGauss.cpp:207
double getEuclidianDistance(const Mat &x) const
Returns the Euclidian distance between argument point x and the center of multivariate normal distrib...
Definition: KDGauss.cpp:189
Mat getSigma(void) const
Returns .
Definition: KDGauss.h:119
void setMu(Mat &mu)
Sets .
Definition: KDGauss.cpp:134
std::vector< CKDGauss > GaussianMixture
Definition: KDGauss.h:230
bool empty(void) const
Checks weather the Gaussian function is approximated.
Definition: KDGauss.h:86
CKDGauss & operator=(const CKDGauss &rhs)
Copy operator.
Definition: KDGauss.cpp:37
Multivariate Gaussian distribution class.
Definition: KDGauss.h:28
Mat getMu(void) const
Returns .
Definition: KDGauss.h:109
static const bool USE_SAFE_SIGMA
Definition: KDGauss.h:207