GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
GaussianMixtureModels.h
Go to the documentation of this file.
1 
30 #ifndef GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
31 #define GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
32 
33 #include "../../CoreModules/Clusterer.h"
34 
35 namespace GRT {
36 
38 {
39 public:
43  GaussianMixtureModels(const UINT numClusters=10,const UINT minNumEpochs=5,const UINT maxNumEpochs=1000,const double minChange=1.0e-5);
44 
51 
55  virtual ~GaussianMixtureModels();
56 
64 
72  virtual bool deepCopyFrom(const Clusterer *clusterer);
73 
80  virtual bool reset();
81 
87  virtual bool clear();
88 
95  virtual bool train_(MatrixDouble &data);
96 
103  virtual bool train_(ClassificationData &trainingData);
104 
111  virtual bool train_(UnlabelledData &trainingData);
112 
113 
114  virtual bool predict_(VectorDouble &inputVector);
115 
123  virtual bool saveModelToFile(fstream &file) const;
124 
132  virtual bool loadModelFromFile(fstream &file);
133 
141  MatrixDouble getMu() const { if( trained ){ return mu; } return MatrixDouble(); }
142 
151  vector< MatrixDouble > getSigma() const { if( trained ){ return sigma; } return vector< MatrixDouble >(); }
152 
160  MatrixDouble getSigma(const UINT k) const{
161  if( k < numClusters && trained ){
162  return sigma[k];
163  }
164  return MatrixDouble();
165  }
166 
167  //Tell the compiler we are using the base class train method to stop hidden virtual function warnings
170 
171 protected:
172  bool estep( const MatrixDouble &data, VectorDouble &u, VectorDouble &v, double &change );
173  bool mstep( const MatrixDouble &data );
174  bool computeInvAndDet();
175  inline void SWAP(UINT &a,UINT &b);
176  inline double SQR(const double v){ return v*v; }
177 
178  double gauss(const VectorDouble &x,const UINT clusterIndex,const VectorDouble &det,const MatrixDouble &mu,const vector< MatrixDouble > &invSigma){
179 
180  double y = 0;
181  double sum = 0;
182  UINT i,j = 0;
183  const UINT N = (UINT)x.size();
184  VectorDouble temp(N,0);
185 
186  //Compute the first part of the equation
187  y = (1.0/pow(TWO_PI,N/2.0)) * (1.0/pow(det[clusterIndex],0.5));
188 
189  //Compute the later half
190  for(i=0; i<N; i++){
191  for(j=0; j<N; j++){
192  temp[i] += (x[j]-mu[clusterIndex][j]) * invSigma[clusterIndex][j][i];
193  }
194  sum += (x[i]-mu[clusterIndex][i]) * temp[i];
195  }
196 
197  return ( y*exp( -0.5*sum ) );
198  }
199 
201  double loglike;
204  VectorDouble frac;
205  VectorDouble lndets;
206  VectorDouble det;
207  vector< MatrixDouble > sigma;
208  vector< MatrixDouble > invSigma;
209 
210 private:
212 };
213 
214 }//End of namespace GRT
215 
216 #endif //GRT_GAUSSIAN_MIXTURE_MODELS_HEADER
217 
virtual bool saveModelToFile(string filename) const
Definition: MLBase.cpp:135
double loglike
The current loglikelihood value of the models given the data.
GaussianMixtureModels & operator=(const GaussianMixtureModels &rhs)
virtual bool loadModelFromFile(string filename)
Definition: MLBase.cpp:157
Definition: AdaBoost.cpp:25
UINT numClusters
Number of clusters in the model.
Definition: Clusterer.h:249
virtual bool deepCopyFrom(const Clusterer *clusterer)
UINT numTrainingSamples
The number of samples in the training data.
virtual bool loadModelFromFile(fstream &file)
virtual bool train_(MatrixDouble &data)
virtual bool predict_(VectorDouble &inputVector)
VectorDouble lndets
A vector holding the log detminants of SIGMA'k.
virtual bool saveModelToFile(fstream &file) const
GaussianMixtureModels(const UINT numClusters=10, const UINT minNumEpochs=5, const UINT maxNumEpochs=1000, const double minChange=1.0e-5)
MatrixDouble getSigma(const UINT k) const
MatrixDouble mu
A matrix holding the estimated mean values of each Gaussian.
vector< MatrixDouble > getSigma() const
MatrixDouble resp
The responsibility matrix.
VectorDouble frac
A vector holding the P(k)'s.