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.
Classifier.h
Go to the documentation of this file.
1 
31 #ifndef GRT_CLASSIFIER_HEADER
32 #define GRT_CLASSIFIER_HEADER
33 
34 #include "MLBase.h"
35 
36 namespace GRT{
37 
38 #define DEFAULT_NULL_LIKELIHOOD_VALUE 0
39 #define DEFAULT_NULL_DISTANCE_VALUE 0
40 
41 class Classifier : public MLBase
42 {
43 public:
47  Classifier(void);
48 
52  virtual ~Classifier(void);
53 
61  virtual bool deepCopyFrom(const Classifier *classifier){ return false; }
62 
69  bool copyBaseVariables(const Classifier *classifier);
70 
77  virtual bool reset();
78 
84  virtual bool clear();
85 
91  string getClassifierType() const;
92 
98  bool getSupportsNullRejection() const;
99 
105  bool getNullRejectionEnabled() const;
106 
113  double getNullRejectionCoeff() const;
114 
122  double getMaximumLikelihood() const;
123 
131  double getBestDistance() const;
132 
138  double getPhase() const;
139 
145  virtual UINT getNumClasses() const;
146 
154  UINT getClassLabelIndexValue(UINT classLabel) const;
155 
161  UINT getPredictedClassLabel() const;
162 
169  VectorDouble getClassLikelihoods() const;
170 
177  VectorDouble getClassDistances() const;
178 
184  VectorDouble getNullRejectionThresholds() const;
185 
192  vector< UINT > getClassLabels() const;
193 
200  vector<MinMax> getRanges() const;
201 
211  bool enableNullRejection(bool useNullRejection);
212 
218  virtual bool setNullRejectionCoeff(double nullRejectionCoeff);
219 
228  virtual bool setNullRejectionThresholds(VectorDouble newRejectionThresholds);
229 
235  virtual bool recomputeNullRejectionThresholds(){ return false; }
236 
243  bool getTimeseriesCompatible() const{ return classifierMode==TIMESERIES_CLASSIFIER_MODE; }
244 
248  typedef std::map< string, Classifier*(*)() > StringClassifierMap;
249 
256  static Classifier* createInstanceFromString(string const &classifierType);
257 
263  Classifier* createNewInstance() const;
264 
272  Classifier* deepCopy() const;
273 
279  const Classifier* getClassifierPointer() const;
280 
286  const Classifier& getBaseClassifier() const;
287 
293  static vector< string > getRegisteredClassifiers();
294 
295 protected:
301  bool saveBaseSettingsToFile(fstream &file) const;
302 
308  bool loadBaseSettingsFromFile(fstream &file);
309 
310  string classifierType;
311  bool supportsNullRejection;
312  bool useNullRejection;
313  UINT numClasses;
314  UINT predictedClassLabel;
315  UINT classifierMode;
316  double nullRejectionCoeff;
317  double maxLikelihood;
318  double bestDistance;
319  double phase;
320  VectorDouble classLikelihoods;
321  VectorDouble classDistances;
322  VectorDouble nullRejectionThresholds;
323  vector< UINT > classLabels;
324  vector<MinMax> ranges;
325 
326  static StringClassifierMap *getMap() {
327  if( !stringClassifierMap ){ stringClassifierMap = new StringClassifierMap; }
328  return stringClassifierMap;
329  }
330 
331  enum ClassifierModes{STANDARD_CLASSIFIER_MODE=0,TIMESERIES_CLASSIFIER_MODE};
332 
333 private:
334  static StringClassifierMap *stringClassifierMap;
335  static UINT numClassifierInstances;
336 
337 };
338 
339 //These two functions/classes are used to register any new Classification Module with the Classifier base class
340 template< typename T > Classifier* getNewClassificationModuleInstance() { return new T; }
341 
342 template< typename T >
344 public:
345  RegisterClassifierModule(string const &newClassificationModuleName) {
346  getMap()->insert( std::pair<string, Classifier*(*)()>(newClassificationModuleName, &getNewClassificationModuleInstance< T > ) );
347  }
348 };
349 
350 } //End of namespace GRT
351 
352 #endif //GRT_CLASSIFIER_HEADER
353 
const Classifier & getBaseClassifier() const
Definition: Classifier.cpp:250
static Classifier * createInstanceFromString(string const &classifierType)
Definition: Classifier.cpp:27
virtual bool recomputeNullRejectionThresholds()
Definition: Classifier.h:235
virtual bool setNullRejectionThresholds(VectorDouble newRejectionThresholds)
Definition: Classifier.cpp:242
bool getTimeseriesCompatible() const
Definition: Classifier.h:243
const Classifier * getClassifierPointer() const
Definition: Classifier.cpp:52
double getPhase() const
Definition: Classifier.cpp:180
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: Classifier.h:61
bool copyBaseVariables(const Classifier *classifier)
Definition: Classifier.cpp:91
std::map< string, Classifier *(*)() > StringClassifierMap
Definition: Classifier.h:248
Definition: AdaBoost.cpp:25
bool loadBaseSettingsFromFile(fstream &file)
Definition: Classifier.cpp:301
virtual UINT getNumClasses() const
Definition: Classifier.cpp:189
VectorDouble getClassLikelihoods() const
Definition: Classifier.cpp:206
Classifier * deepCopy() const
Definition: Classifier.cpp:39
VectorDouble getClassDistances() const
Definition: Classifier.cpp:211
static vector< string > getRegisteredClassifiers()
Definition: Classifier.cpp:56
double getMaximumLikelihood() const
Definition: Classifier.cpp:175
bool saveBaseSettingsToFile(fstream &file) const
Definition: Classifier.cpp:254
This is the main base class that all GRT machine learning algorithms should inherit from...
UINT getClassLabelIndexValue(UINT classLabel) const
Definition: Classifier.cpp:193
virtual bool reset()
Definition: Classifier.cpp:121
double getNullRejectionCoeff() const
Definition: Classifier.cpp:171
virtual ~Classifier(void)
Definition: Classifier.cpp:84
virtual bool clear()
Definition: Classifier.cpp:140
VectorDouble getNullRejectionThresholds() const
Definition: Classifier.cpp:216
bool getNullRejectionEnabled() const
Definition: Classifier.cpp:167
double getBestDistance() const
Definition: Classifier.cpp:184
UINT getPredictedClassLabel() const
Definition: Classifier.cpp:201
Classifier * createNewInstance() const
Definition: Classifier.cpp:35
vector< MinMax > getRanges() const
Definition: Classifier.cpp:225
string getClassifierType() const
Definition: Classifier.cpp:159
bool enableNullRejection(bool useNullRejection)
Definition: Classifier.cpp:229
vector< UINT > getClassLabels() const
Definition: Classifier.cpp:221
virtual bool setNullRejectionCoeff(double nullRejectionCoeff)
Definition: Classifier.cpp:234
bool getSupportsNullRejection() const
Definition: Classifier.cpp:163