GestureRecognitionToolkit  Version: 0.2.0
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 GRT_BEGIN_NAMESPACE
37 
38 #define DEFAULT_NULL_LIKELIHOOD_VALUE 0
39 #define DEFAULT_NULL_DISTANCE_VALUE 0
40 
41 class GRT_API Classifier : public MLBase
42 {
43 public:
44  enum ClassifierModes{STANDARD_CLASSIFIER_MODE=0,TIMESERIES_CLASSIFIER_MODE};
45 
49  Classifier(void);
50 
54  virtual ~Classifier(void);
55 
63  virtual bool deepCopyFrom(const Classifier *classifier){ return false; }
64 
71  bool copyBaseVariables(const Classifier *classifier);
72 
79  virtual bool reset();
80 
86  virtual bool clear();
87 
93  std::string getClassifierType() const;
94 
100  bool getSupportsNullRejection() const;
101 
107  bool getNullRejectionEnabled() const;
108 
115  Float getNullRejectionCoeff() const;
116 
124  Float getMaximumLikelihood() const;
125 
133  Float getBestDistance() const;
134 
140  Float getPhase() const;
141 
147  virtual UINT getNumClasses() const;
148 
156  UINT getClassLabelIndexValue(UINT classLabel) const;
157 
163  UINT getPredictedClassLabel() const;
164 
171  VectorFloat getClassLikelihoods() const;
172 
179  VectorFloat getClassDistances() const;
180 
186  VectorFloat getNullRejectionThresholds() const;
187 
194  Vector< UINT > getClassLabels() const;
195 
202  Vector<MinMax> getRanges() const;
203 
213  bool enableNullRejection(bool useNullRejection);
214 
220  virtual bool setNullRejectionCoeff(Float nullRejectionCoeff);
221 
230  virtual bool setNullRejectionThresholds(VectorFloat newRejectionThresholds);
231 
237  virtual bool recomputeNullRejectionThresholds(){ return false; }
238 
245  bool getTimeseriesCompatible() const{ return classifierMode==TIMESERIES_CLASSIFIER_MODE; }
246 
250  typedef std::map< std::string, Classifier*(*)() > StringClassifierMap;
251 
258  static Classifier* createInstanceFromString( std::string const &classifierType );
259 
265  Classifier* createNewInstance() const;
266 
274  Classifier* deepCopy() const;
275 
281  const Classifier* getClassifierPointer() const;
282 
288  const Classifier& getBaseClassifier() const;
289 
295  static Vector< std::string > getRegisteredClassifiers();
296 
297 protected:
303  bool saveBaseSettingsToFile( std::fstream &file ) const;
304 
310  bool loadBaseSettingsFromFile( std::fstream &file );
311 
312  std::string classifierType;
313  bool supportsNullRejection;
314  bool useNullRejection;
315  UINT numClasses;
316  UINT predictedClassLabel;
317  UINT classifierMode;
318  Float nullRejectionCoeff;
319  Float maxLikelihood;
320  Float bestDistance;
321  Float phase;
322  VectorFloat classLikelihoods;
323  VectorFloat classDistances;
324  VectorFloat nullRejectionThresholds;
325  Vector< UINT > classLabels;
326  Vector< MinMax > ranges;
327 
333  static StringClassifierMap *getMap() {
334  if( !stringClassifierMap ){ stringClassifierMap = new StringClassifierMap; }
335  return stringClassifierMap;
336  }
337 
338 private:
339  static StringClassifierMap *stringClassifierMap;
340  static UINT numClassifierInstances;
341 
342 };
343 
344 //These two functions/classes are used to register any new Classification Module with the Classifier base class
345 template< typename T > Classifier* getNewClassificationModuleInstance() { return new T; }
346 
347 template< typename T >
349 public:
350  RegisterClassifierModule( std::string const &newClassificationModuleName ) {
351  getMap()->insert( std::pair< std::string, Classifier*(*)() >(newClassificationModuleName, &getNewClassificationModuleInstance< T > ) );
352  }
353 };
354 
355 GRT_END_NAMESPACE
356 
357 #endif //GRT_CLASSIFIER_HEADER
358 
bool saveBaseSettingsToFile(std::fstream &file) const
Definition: MLBase.cpp:375
virtual bool recomputeNullRejectionThresholds()
Definition: Classifier.h:237
virtual bool reset()
Definition: MLBase.cpp:125
bool getTimeseriesCompatible() const
Definition: Classifier.h:245
static StringClassifierMap * getMap()
Definition: Classifier.h:333
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: Classifier.h:63
This is the main base class that all GRT machine learning algorithms should inherit from...
bool loadBaseSettingsFromFile(std::fstream &file)
Definition: MLBase.cpp:398
virtual bool clear()
Definition: MLBase.cpp:127
std::map< std::string, Classifier *(*)() > StringClassifierMap
Definition: Classifier.h:250
Definition: MLBase.h:70