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.
GestureRecognitionPipeline.h
Go to the documentation of this file.
1 
35 #ifndef GRT_GESTURE_RECOGNITION_PIPELINE_HEADER
36 #define GRT_GESTURE_RECOGNITION_PIPELINE_HEADER
37 
38 #include "PreProcessing.h"
39 #include "FeatureExtraction.h"
40 #include "Classifier.h"
41 #include "Regressifier.h"
42 #include "Clusterer.h"
43 #include "PostProcessing.h"
44 #include "Context.h"
45 #include "../DataStructures/TimeSeriesClassificationDataStream.h"
46 #include "../Util/ClassificationResult.h"
47 #include "../Util/TestResult.h"
48 
49 namespace GRT{
50 
51 #define INSERT_AT_END_INDEX 99999
52 
54 {
55 public:
60 
65 
69  virtual ~GestureRecognitionPipeline(void);
70 
75 
85  bool train(const ClassificationData &trainingData);
86 
98  bool train(const ClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling = false );
99 
109  bool train(const TimeSeriesClassificationData &trainingData);
110 
121  bool train(const TimeSeriesClassificationData &trainingData,const UINT kFoldValue,const bool useStratifiedSampling = false);
122 
132  bool train(const RegressionData &trainingData);
133 
144  bool train(const RegressionData &trainingData,const UINT kFoldValue);
145 
155  bool train(const UnlabelledData &trainingData);
156 
166  bool test(const ClassificationData &testData);
167 
177  bool test(const TimeSeriesClassificationData &testData);
178 
188  bool test(const TimeSeriesClassificationDataStream &testData);
189 
199  bool test(const RegressionData &testData);
200 
208  bool predict(const VectorDouble &inputVector);
209 
217  bool predict(const MatrixDouble &inputMatrix);
218 
228  bool map(const VectorDouble &inputVector);
229 
236  bool reset();
237 
245  bool save(const string &filename) const;
246 
253  bool savePipelineToFile(const string &filename) const;
254 
262  bool load(const string &filename);
263 
270  bool loadPipelineFromFile(const string &filename);
271 
286  bool preProcessData(VectorDouble inputVector,bool computeFeatures = true);
287 
293  bool getIsInitialized() const;
294 
300  bool getTrained() const;
301 
307  bool getIsPreProcessingSet() const;
308 
314  bool getIsFeatureExtractionSet() const;
315 
321  bool getIsClassifierSet() const;
322 
328  bool getIsRegressifierSet() const;
329 
335  bool getIsClustererSet() const;
336 
342  bool getIsPostProcessingSet() const;
343 
349  bool getIsContextSet() const;
350 
356  bool getIsPipelineModeSet() const;
357 
364 
370  bool getIsPipelineInRegressionMode() const;
371 
377  UINT getInputVectorDimensionsSize() const;
378 
385  UINT getOutputVectorDimensionsSize() const;
386 
392  UINT getNumClassesInModel() const;
393 
400  UINT getNumClasses() const;
401 
407  UINT getNumPreProcessingModules() const;
408 
414  UINT getNumFeatureExtractionModules() const;
415 
421  UINT getNumPostProcessingModules() const;
422 
432 
438  UINT getPredictedClassLabel() const;
439 
447 
453  UINT getNumTrainingSamples() const;
454 
460  UINT getNumTestSamples() const;
461 
467  double getMaximumLikelihood() const;
468 
474  double getPhase() const;
475 
483  double getCrossValidationAccuracy() const;
484 
490  double getTestAccuracy() const;
491 
497  double getTestRMSError() const;
498 
504  double getTestSSError() const;
505 
513  double getTestFMeasure(const UINT classLabel) const;
514 
522  double getTestPrecision(const UINT classLabel) const;
523 
531  double getTestRecall(const UINT classLabel) const;
532 
539  double getTestRejectionPrecision() const;
540 
547  double getTestRejectionRecall() const;
548 
554  double getTestTime() const;
555 
561  double getTrainingTime() const;
562 
568  double getTrainingRMSError() const;
569 
575  double getTrainingSSError() const;
576 
584 
592  TestResult getTestResults() const;
593 
600  VectorDouble getTestPrecision() const;
601 
608  VectorDouble getTestRecall() const;
609 
616  VectorDouble getTestFMeasure() const;
617 
624  VectorDouble getClassLikelihoods() const;
625 
632  VectorDouble getClassDistances() const;
633 
639  VectorDouble getNullRejectionThresholds() const;
640 
646  VectorDouble getRegressionData() const;
647 
653  VectorDouble getUnProcessedRegressionData() const;
654 
660  VectorDouble getPreProcessedData() const;
661 
668  VectorDouble getPreProcessedData(UINT moduleIndex) const;
669 
675  VectorDouble getFeatureExtractionData() const;
676 
683  VectorDouble getFeatureExtractionData(const UINT moduleIndex) const;
684 
691  vector< UINT > getClassLabels() const;
692 
698  vector< TestInstanceResult > getTestInstanceResults() const;
699 
705  vector< TestResult > getCrossValidationResults() const;
706 
713  PreProcessing* getPreProcessingModule(const UINT moduleIndex) const;
714 
721  FeatureExtraction* getFeatureExtractionModule(const UINT moduleIndex) const;
722 
728  Classifier* getClassifier() const;
729 
735  Regressifier* getRegressifier() const;
736 
742  Clusterer* getClusterer() const;
743 
750  PostProcessing* getPostProcessingModule(UINT moduleIndex) const;
751 
759  Context* getContextModule(const UINT contextLevel,const UINT moduleIndex) const;
760 
767  template <class T> T* getPreProcessingModule(const UINT moduleIndex) const{
768  if( moduleIndex < preProcessingModules.size() ){
769  return (T*)preProcessingModules[ moduleIndex ];
770  }
771  return NULL;
772  }
773 
780  template <class T> T* getFeatureExtractionModule(const UINT moduleIndex) const{
781  if( moduleIndex < featureExtractionModules.size() ){
782  return (T*)featureExtractionModules[ moduleIndex ];
783  }
784  return NULL;
785  }
786 
793  template <class T> T* getClassifier() const{
794 
795  if( classifier == NULL ) return NULL;
796 
797  T temp;
798 
799  if( temp.getClassifierType() == classifier->getClassifierType() ){
800  return dynamic_cast<T*>(classifier);
801  }
802 
803  return NULL;
804  }
805 
812  template <class T> T* getRegressifier() const{
813 
814  if( regressifier == NULL ) return NULL;
815 
816  T temp;
817 
818  if( temp.getRegressifierType() == regressifier->getRegressifierType() ){
819  return (T*)regressifier;
820  }
821 
822  return NULL;
823  }
824 
831  template <class T> T* getCluster() const{
832 
833  if( clusterer == NULL ) return NULL;
834 
835  T temp;
836 
837  if( temp.getClassifierType() == clusterer->getClustererType() ){
838  return (T*)clusterer;
839  }
840 
841  return NULL;
842  }
843 
850  template <class T> T* getPostProcessingModule(const UINT moduleIndex) const{
851  if( moduleIndex < postProcessingModules.size() ){
852  return (T*)postProcessingModules[ moduleIndex ];
853  }
854  return NULL;
855  }
856 
864  template <class T> T* getContextModule(const UINT contextLevel,const UINT moduleIndex) const{
865  if( contextLevel < contextModules.size() ){
866  if( moduleIndex < contextModules[ contextLevel ].size() ){
867  return (T*)contextModules[ contextLevel ][ moduleIndex ];
868  }
869  }
870  return NULL;
871  }
872 
878  string getModelAsString() const;
879 
885  string getPipelineModeAsString() const;
886 
887  /*
888  Gets the pipeline info text as a string.
889 
890  @return returns the pipeline info as a string
891  */
892  string getInfo() const;
893 
900  UINT getPipelineModeFromString(string pipelineMode) const;
901 
910  bool addPreProcessingModule(const PreProcessing &preProcessingModule,UINT insertIndex = INSERT_AT_END_INDEX);
911 
918  bool setPreProcessingModule(const PreProcessing &preProcessingModule);
919 
928  bool addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule,UINT insertIndex = INSERT_AT_END_INDEX);
929 
936  bool setFeatureExtractionModule(const FeatureExtraction &featureExtractionModule);
937 
944  bool setClassifier(const Classifier &classifier);
945 
952  bool setRegressifier(const Regressifier &regressifier);
953 
960  bool setClusterer(const Clusterer &clusterer);
961 
970  bool addPostProcessingModule(const PostProcessing &postProcessingModule,UINT insertIndex = INSERT_AT_END_INDEX);
971 
978  bool setPostProcessingModule(const PostProcessing &postProcessingModule);
979 
989  bool addContextModule(const Context &contextModule,UINT contextLevel,UINT insertIndex = INSERT_AT_END_INDEX);
990 
1000  bool updateContextModule(bool value,UINT contextLevel = 0,UINT moduleIndex = 0);
1001 
1008 
1015  bool removePreProcessingModule(UINT moduleIndex);
1016 
1023 
1030  bool removeFeatureExtractionModule(UINT moduleIndex);
1031 
1037  bool removeClassifier(){ deleteClassifier(); return true; }
1038 
1044  bool removeRegressifier(){ deleteRegressifier(); return true; }
1045 
1051  bool removeClusterer(){ deleteClusterer(); return true; }
1052 
1059 
1066  bool removePostProcessingModule(const UINT moduleIndex);
1067 
1073  bool removeAllContextModules();
1074 
1082  bool removeContextModule(const UINT contextLevel,const UINT moduleIndex);
1083 
1089  bool clearAll();
1090 
1096  bool clearTestResults();
1097 
1102  bool setInfo(const string info);
1103 
1104 protected:
1105  bool predict_classifier(const VectorDouble &inputVector);
1106  bool predict_regressifier(const VectorDouble &inputVector);
1107  bool predict_clusterer(const VectorDouble &inputVector);
1108  void deleteAllPreProcessingModules();
1109  void deleteAllFeatureExtractionModules();
1110  void deleteClassifier();
1111  void deleteRegressifier();
1112  void deleteClusterer();
1113  void deleteAllPostProcessingModules();
1114  void deleteAllContextModules();
1115  bool updateTestMetrics(const UINT classLabel,const UINT predictedClassLabel,VectorDouble &precisionCounter,VectorDouble &recallCounter,double &rejectionPrecisionCounter,double &rejectionRecallCounter,VectorDouble &confusionMatrixCounter);
1116  bool computeTestMetrics(VectorDouble &precisionCounter,VectorDouble &recallCounter,double &rejectionPrecisionCounter,double &rejectionRecallCounter,VectorDouble &confusionMatrixCounter,const UINT numTestSamples);
1117 
1118  bool initialized;
1119  bool trained;
1120  string info;
1121  UINT inputVectorDimensions;
1122  UINT outputVectorDimensions;
1123  UINT predictedClassLabel;
1124  UINT predictedClusterLabel;
1125  UINT pipelineMode;
1126  UINT predictionModuleIndex;
1127  UINT numTrainingSamples;
1128  UINT numTestSamples;
1129  double testAccuracy;
1130  double testRMSError;
1131  double testSquaredError;
1132  double testTime;
1133  double trainingTime;
1134  VectorDouble testFMeasure;
1135  VectorDouble testPrecision;
1136  VectorDouble testRecall;
1137  VectorDouble regressionData;
1138  double testRejectionPrecision;
1139  double testRejectionRecall;
1140  MatrixDouble testConfusionMatrix;
1141  vector< TestResult > crossValidationResults;
1142  vector< TestInstanceResult > testResults;
1143 
1144  vector< PreProcessing* > preProcessingModules;
1145  vector< FeatureExtraction* > featureExtractionModules;
1146  Classifier *classifier;
1147  Regressifier *regressifier;
1148  Clusterer *clusterer;
1149  vector< PostProcessing* > postProcessingModules;
1150  vector< vector< Context* > > contextModules;
1151 
1152  enum PipelineModes{PIPELINE_MODE_NOT_SET=0,CLASSIFICATION_MODE,REGRESSION_MODE,CLUSTER_MODE};
1153 
1154 public:
1155  enum ContextLevels{START_OF_PIPELINE=0,AFTER_PREPROCESSING,AFTER_FEATURE_EXTRACTION,AFTER_CLASSIFIER,END_OF_PIPELINE,NUM_CONTEXT_LEVELS};
1156 
1157 };
1158 
1159 } //End of namespace GRT
1160 
1161 #endif //GRT_GESTURE_RECOGNITION_PIPELINE_HEADER
1162 
1163 
This is the main base class that all GRT Feature Extraction algorithms should inherit from...
This is the main base class that all GRT Clustering algorithms should inherit from.
bool map(const VectorDouble &inputVector)
bool setRegressifier(const Regressifier &regressifier)
Context * getContextModule(const UINT contextLevel, const UINT moduleIndex) const
Definition: AdaBoost.cpp:25
bool test(const ClassificationData &testData)
bool setPostProcessingModule(const PostProcessing &postProcessingModule)
bool addPostProcessingModule(const PostProcessing &postProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
T * getPreProcessingModule(const UINT moduleIndex) const
bool save(const string &filename) const
bool addContextModule(const Context &contextModule, UINT contextLevel, UINT insertIndex=INSERT_AT_END_INDEX)
bool loadPipelineFromFile(const string &filename)
vector< TestResult > getCrossValidationResults() const
bool setFeatureExtractionModule(const FeatureExtraction &featureExtractionModule)
bool removePostProcessingModule(const UINT moduleIndex)
string getRegressifierType() const
string getClustererType() const
Definition: Clusterer.cpp:257
bool addPreProcessingModule(const PreProcessing &preProcessingModule, UINT insertIndex=INSERT_AT_END_INDEX)
bool setClusterer(const Clusterer &clusterer)
bool savePipelineToFile(const string &filename) const
T * getPostProcessingModule(const UINT moduleIndex) const
This is the main base class that all GRT Classification algorithms should inherit from...
bool train(const ClassificationData &trainingData)
bool predict(const VectorDouble &inputVector)
This is the main base class that all GRT PostProcessing algorithms should inherit from...
bool addFeatureExtractionModule(const FeatureExtraction &featureExtractionModule, UINT insertIndex=INSERT_AT_END_INDEX)
T * getContextModule(const UINT contextLevel, const UINT moduleIndex) const
bool setPreProcessingModule(const PreProcessing &preProcessingModule)
T * getFeatureExtractionModule(const UINT moduleIndex) const
string getClassifierType() const
Definition: Classifier.cpp:159
bool setClassifier(const Classifier &classifier)
This is the main base class that all GRT PreProcessing algorithms should inherit from.
bool preProcessData(VectorDouble inputVector, bool computeFeatures=true)
UINT getPipelineModeFromString(string pipelineMode) const
GestureRecognitionPipeline & operator=(const GestureRecognitionPipeline &rhs)
FeatureExtraction * getFeatureExtractionModule(const UINT moduleIndex) const
vector< TestInstanceResult > getTestInstanceResults() const
PreProcessing * getPreProcessingModule(const UINT moduleIndex) const
bool removeContextModule(const UINT contextLevel, const UINT moduleIndex)
PostProcessing * getPostProcessingModule(UINT moduleIndex) const
This is the main base class that all GRT Feature Extraction algorithms should inherit from...
This is the main base class that all GRT Regression algorithms should inherit from.
bool updateContextModule(bool value, UINT contextLevel=0, UINT moduleIndex=0)