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.
DiscreteHiddenMarkovModel.h
Go to the documentation of this file.
1 
31 #ifndef GRT_DISCRETE_HIDDEN_MARKOV_MODEL_HEADER
32 #define GRT_DISCRETE_HIDDEN_MARKOV_MODEL_HEADER
33 
34 #include "HMMEnums.h"
35 #include "../../Util/GRTCommon.h"
36 #include "../../CoreModules/MLBase.h"
37 
38 namespace GRT {
39 
40 //This class is used for the HMM batch training
42 public:
44  pk = 0.0;
45  }
47  MatrixDouble alpha; //The forward estimate matrix
48  MatrixDouble beta; //The backward estimate matrix
49  VectorDouble c; //The scaling coefficient vector
50  double pk; //P( O | Model )
51 };
52 
54 
55 public:
57 
58  DiscreteHiddenMarkovModel(const UINT numStates,const UINT numSymbols,const UINT modelType,const UINT delta);
59 
60  DiscreteHiddenMarkovModel(const MatrixDouble &a,const MatrixDouble &b,const VectorDouble &pi,const UINT modelType,const UINT delta);
61 
63 
64  virtual ~DiscreteHiddenMarkovModel();
65 
66  double predict(const UINT newSample);
67  double predict(const vector<UINT> &obs);
68 
69  bool resetModel(const UINT numStates,const UINT numSymbols,const UINT modelType,const UINT delta);
70  bool train(const vector< vector<UINT> > &trainingData);
71 
72  virtual bool reset();
73 
80  virtual bool saveModelToFile(fstream &file) const;
81 
88  virtual bool loadModelFromFile(fstream &file);
89 
90  bool randomizeMatrices(const UINT numStates,const UINT numSymbols);
91  double predictLogLikelihood(const vector<UINT> &obs);
92  bool forwardBackward(HMMTrainingObject &trainingObject,const vector<UINT> &obs);
93  bool train_(const vector< vector<UINT> > &obs,const UINT maxIter, UINT &currentIter,double &newLoglikelihood);
94  virtual bool print() const;
95 
96  VectorDouble getTrainingIterationLog() const;
97 
98  UINT numStates; //The number of states for this model
99  UINT numSymbols; //The number of symbols for this model
100  MatrixDouble a; //The transitions probability matrix
101  MatrixDouble b; //The emissions probability matrix
102  VectorDouble pi; //The state start probability vector
103  VectorDouble trainingIterationLog; //Stores the loglikelihood at each iteration the BaumWelch algorithm
104 
105  UINT modelType;
106  UINT delta; //The number of states a model can move to in a LeftRight model
107  UINT numRandomTrainingIterations; //The number of training loops to find the best starting values
108  double logLikelihood; //The log likelihood of an observation sequence given the modal, calculated by the forward method
109  double cThreshold; //The classification threshold for this model
110  CircularBuffer<UINT> observationSequence;
111  vector< UINT > estimatedStates;
112 };
113 
114 }//end of namespace GRT
115 
116 #endif //GRT_HIDDEN_MARKOV_MODEL_HEADER
This class acts as the main interface for using a Hidden Markov Model.
Definition: AdaBoost.cpp:25
virtual bool saveModelToFile(fstream &file) const
virtual bool loadModelFromFile(fstream &file)