GestureRecognitionToolkit  Version: 0.1.0
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 GRT_BEGIN_NAMESPACE
39 
40 //This class is used for the HMM batch training
42 public:
44  pk = 0.0;
45  }
47  MatrixFloat alpha; //The forward estimate matrix
48  MatrixFloat beta; //The backward estimate matrix
49  VectorFloat c; //The scaling coefficient Vector
50  Float 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 MatrixFloat &a,const MatrixFloat &b,const VectorFloat &pi,const UINT modelType,const UINT delta);
61 
63 
64  virtual ~DiscreteHiddenMarkovModel();
65 
66  Float predict(const UINT newSample);
67  Float 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( std::fstream &file ) const;
81 
88  virtual bool loadModelFromFile( std::fstream &file );
89 
90  bool randomizeMatrices(const UINT numStates,const UINT numSymbols);
91  Float 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,Float &newLoglikelihood);
94  virtual bool print() const;
95 
96  VectorFloat getTrainingIterationLog() const;
97 
98  UINT numStates; //The number of states for this model
99  UINT numSymbols; //The number of symbols for this model
100  MatrixFloat a; //The transitions probability matrix
101  MatrixFloat b; //The emissions probability matrix
102  VectorFloat pi; //The state start probability Vector
103  VectorFloat 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  Float logLikelihood; //The log likelihood of an observation sequence given the modal, calculated by the forward method
109  Float cThreshold; //The classification threshold for this model
110  CircularBuffer<UINT> observationSequence;
111  Vector< UINT > estimatedStates;
112 };
113 
114 GRT_END_NAMESPACE
115 
116 #endif //GRT_HIDDEN_MARKOV_MODEL_HEADER
virtual bool saveModelToFile(std::fstream &file) const
This class acts as the main interface for using a Hidden Markov Model.
virtual bool loadModelFromFile(std::fstream &file)
Definition: MLBase.h:70