Direct Graphical Models  v.1.7.0
TrainNodeGMM.h
1 // Gaussian Mixture Model training class interface
2 // Written by Sergey G. Kosov in 2012 - 2014 for Project X
3 // Refactored by Sergey G. Kosov in 2017 for Project X
4 #pragma once
5 
6 #include "TrainNode.h"
7 #include "KDGauss.h"
8 
9 namespace DirectGraphicalModels
10 {
12  typedef struct TrainNodeGMMParams {
13  word maxGausses;
14  size_t minSamples;
15  double dist_Etreshold;
16  double dist_Mtreshold;
17  double div_KLtreshold;
18 
20  TrainNodeGMMParams(word _maxGausses, size_t _minSamples, double _dist_Etreshold, double _dist_Mtreshold, double _div_KLtreshold) : maxGausses(_maxGausses), minSamples(_minSamples), dist_Etreshold(_dist_Etreshold), dist_Mtreshold(_dist_Mtreshold), div_KLtreshold(_div_KLtreshold) {}
22 
24  64, // maxGausses
25  64, // min_samples
26  64, // dist_Etreshold
27  -16, // dist_Mtreshold
28  -16 // div_KLtreshold
29  );
30 
31  // ==================== Gaussian Mixture Model Train Class =====================
40  class CTrainNodeGMM : public CTrainNode
41  {
42  public:
49  DllExport CTrainNodeGMM(byte nStates, word nFeatures, TrainNodeGMMParams params = TRAIN_NODE_GMM_PARAMS_DEFAULT);
56  DllExport CTrainNodeGMM(byte nStates, word nFeatures, byte maxGausses);
57  DllExport virtual ~CTrainNodeGMM(void);
58 
59  DllExport void reset(void);
60 
61  DllExport void addFeatureVec(const Mat &featureVector, byte gt);
62  DllExport void train(bool doClean = false);
63 
64 
65  protected:
66  DllExport void saveFile(FILE *pFile) const;
67  DllExport void loadFile(FILE *pFile);
77  DllExport void calculateNodePotentials(const Mat &featureVector, Mat &potential, Mat &mask) const;
78 
79 
80  private:
81  static const size_t MIN_SAMPLES;
82  static const long double MAX_COEFFICIENT;
83 
84 
85  private:
87  std::vector<GaussianMixture> m_vGaussianMixtures; // block of n-dimensional Gauss function
88  long double m_minAlpha = 1; // auxilary coefficient for scaling gaussian coefficients
89  };
90 }
91 
92 
void saveFile(FILE *pFile) const
Saves the random model into the file.
double dist_Etreshold
Minimum Euclidean distance between Gauss functions.
Definition: TrainNodeGMM.h:15
double div_KLtreshold
Minimum Kullback-Leiber divergence between Gauss functions. If this parameter is negative, the merging of Gaussians in addFeatureVec() function will be disabled.
Definition: TrainNodeGMM.h:17
void reset(void)
Resets class variables.
void train(bool doClean=false)
Random model training.
struct DirectGraphicalModels::TrainNodeGMMParams TrainNodeGMMParams
Gaussian Mixture Model parameters.
Gaussian Mixture Model parameters.
Definition: TrainNodeGMM.h:12
CTrainNodeGMM(byte nStates, word nFeatures, TrainNodeGMMParams params=TRAIN_NODE_GMM_PARAMS_DEFAULT)
Constructor.
static const long double MAX_COEFFICIENT
Definition: TrainNodeGMM.h:82
word maxGausses
The maximal number of Gauss functions for approximation.
Definition: TrainNodeGMM.h:13
void calculateNodePotentials(const Mat &featureVector, Mat &potential, Mat &mask) const
Calculates the node potential, based on the feature vector.
const TrainNodeGMMParams TRAIN_NODE_GMM_PARAMS_DEFAULT
Definition: TrainNodeGMM.h:23
Gaussian Mixture Model training class.
Definition: TrainNodeGMM.h:40
Base abstract class for node potentials training.
Definition: TrainNode.h:47
double dist_Mtreshold
Minimum Mahalanobis distance between Gauss functions. If this parameter is negative, the Euclidean distance is used.
Definition: TrainNodeGMM.h:16
TrainNodeGMMParams(word _maxGausses, size_t _minSamples, double _dist_Etreshold, double _dist_Mtreshold, double _div_KLtreshold)
Definition: TrainNodeGMM.h:20
std::vector< GaussianMixture > m_vGaussianMixtures
Definition: TrainNodeGMM.h:87
size_t minSamples
Minimum number of sapmles to approximate a Gauss function.
Definition: TrainNodeGMM.h:14
void addFeatureVec(const Mat &featureVector, byte gt)
Adds new feature vector.
void loadFile(FILE *pFile)
Loads the random model from the file.