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.
HMM.h
Go to the documentation of this file.
1 
31 #ifndef GRT_HMM_HEADER
32 #define GRT_HMM_HEADER
33 
34 #include "HMMEnums.h"
37 #include "../../CoreModules/Classifier.h"
38 
39 GRT_BEGIN_NAMESPACE
40 
41 class HMM : public Classifier
42 {
43 public:
55  HMM(const UINT hmmType=HMM_CONTINUOUS,const UINT modelType=HMM_LEFTRIGHT,const UINT delta=1,const bool useScaling = false,const bool useNullRejection = false);
56 
64  HMM(const HMM &rhs);
65 
69  virtual ~HMM(void);
70 
79  HMM& operator=(const HMM &rhs);
80 
88  virtual bool deepCopyFrom(const Classifier *classifier);
89 
97  virtual bool train(ClassificationData trainingData);
98 
107  virtual bool train_(TimeSeriesClassificationData &trainingData);
108 
116  virtual bool predict_(VectorFloat &inputVector);
117 
125  virtual bool predict_(MatrixFloat &timeseries);
126 
132  virtual bool reset();
133 
140  virtual bool clear();
141 
142  virtual bool print() const;
143 
151  virtual bool saveModelToFile( std::fstream &file ) const;
152 
160  virtual bool loadModelFromFile( std::fstream &file );
161 
167  UINT getHMMType() const;
168 
174  UINT getModelType() const;
175 
182  UINT getDelta() const;
183 
189  UINT getNumStates() const;
190 
196  UINT getNumSymbols() const;
197 
208  UINT getNumRandomTrainingIterations() const;
209 
217 
225 
234  bool setHMMType(const UINT hmmType);
235 
244  bool setModelType(const UINT modelType);
245 
258  bool setDelta(const UINT delta);
259 
271  bool setDownsampleFactor(const UINT downsampleFactor);
272 
282  bool setCommitteeSize(const UINT committeeSize);
283 
292  bool setNumStates(const UINT numStates);
293 
300  bool setNumSymbols(const UINT numStates);
301 
314  bool setNumRandomTrainingIterations(const UINT numRandomTrainingIterations);
315 
328  bool setSigma(const Float sigma);
329 
330  bool setAutoEstimateSigma(const bool autoEstimateSigma);
331 
332  //Tell the compiler we are using the base class train method to stop hidden virtual function warnings
335  using MLBase::train;
336  using MLBase::predict;
337 
338 protected:
339  bool train_discrete(TimeSeriesClassificationData &trainingData);
340  bool train_continuous(TimeSeriesClassificationData &trainingData);
341  bool predict_discrete( VectorFloat &inputVector );
342  bool predict_continuous( VectorFloat &inputVector );
343  bool predict_discrete(MatrixFloat &timeseries);
344  bool predict_continuous(MatrixFloat &timeseries);
345  bool convertDataToObservationSequence( TimeSeriesClassificationData &classData, Vector< Vector< UINT > > &observationSequences );
346  bool loadLegacyModelFromFile( std::fstream &file );
347 
348  UINT hmmType;
349  UINT modelType; //Set if the model is ERGODIC or LEFTRIGHT
350  UINT delta; //The number of states a model can move to in a LeftRight model
351 
352  //Discrete HMM variables
353  UINT numStates; //The number of states for each model
354  UINT numSymbols; //The number of symbols for each model
355  UINT numRandomTrainingIterations;
357 
358  //Continuous HMM variables
359  UINT downsampleFactor;
360  UINT committeeSize;
361  Float sigma;
362  bool autoEstimateSigma;
363  Vector< ContinuousHiddenMarkovModel > continuousModels;
364 
365  static RegisterClassifierModule< HMM > registerModule;
366 };
367 
368 GRT_END_NAMESPACE
369 
370 #endif //GRT_HMM_HEADER
virtual bool saveModelToFile(std::fstream &file) const
Definition: HMM.cpp:702
virtual bool predict(VectorFloat inputVector)
Definition: MLBase.cpp:112
virtual bool loadModelFromFile(std::fstream &file)
Definition: HMM.cpp:757
bool setHMMType(const UINT hmmType)
Definition: HMM.cpp:957
bool setDownsampleFactor(const UINT downsampleFactor)
Definition: HMM.cpp:996
virtual bool predict_(VectorFloat &inputVector)
Definition: HMM.cpp:282
This class acts as the main interface for using a Hidden Markov Model.
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:88
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: HMM.cpp:91
bool setNumRandomTrainingIterations(const UINT numRandomTrainingIterations)
Definition: HMM.cpp:1042
virtual bool reset()
Definition: HMM.cpp:627
bool setNumSymbols(const UINT numStates)
Definition: HMM.cpp:1029
virtual ~HMM(void)
Definition: HMM.cpp:67
virtual bool train(ClassificationData trainingData)
Definition: HMM.cpp:119
Vector< DiscreteHiddenMarkovModel > getDiscreteModels() const
Definition: HMM.cpp:949
virtual bool clear()
Definition: HMM.cpp:648
bool setModelType(const UINT modelType)
Definition: HMM.cpp:970
UINT getModelType() const
Definition: HMM.cpp:929
virtual bool print() const
Definition: HMM.cpp:659
HMM & operator=(const HMM &rhs)
Definition: HMM.cpp:71
UINT hmmType
Controls if this is a HMM_DISCRETE or a HMM_CONTINUOUS.
Definition: HMM.h:348
UINT getNumStates() const
Definition: HMM.cpp:937
bool setSigma(const Float sigma)
Definition: HMM.cpp:1055
virtual bool train_(TimeSeriesClassificationData &trainingData)
Definition: HMM.cpp:125
HMM(const UINT hmmType=HMM_CONTINUOUS, const UINT modelType=HMM_LEFTRIGHT, const UINT delta=1, const bool useScaling=false, const bool useNullRejection=false)
Definition: HMM.cpp:28
virtual bool saveModelToFile(std::string filename) const
Definition: MLBase.cpp:146
UINT getDelta() const
Definition: HMM.cpp:933
UINT getHMMType() const
Definition: HMM.cpp:925
This class implements a continuous Hidden Markov Model.
UINT getNumSymbols() const
Definition: HMM.cpp:941
virtual bool loadModelFromFile(std::string filename)
Definition: MLBase.cpp:168
bool setDelta(const UINT delta)
Definition: HMM.cpp:983
bool setCommitteeSize(const UINT committeeSize)
Definition: HMM.cpp:1006
Definition: HMM.h:41
This class implements a discrete Hidden Markov Model.
UINT getNumRandomTrainingIterations() const
Definition: HMM.cpp:945
bool setNumStates(const UINT numStates)
Definition: HMM.cpp:1016
Vector< ContinuousHiddenMarkovModel > getContinuousModels() const
Definition: HMM.cpp:953