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.
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 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  std::string getClassifierType() const;
92 
98  bool getSupportsNullRejection() const;
99 
105  bool getNullRejectionEnabled() const;
106 
113  Float getNullRejectionCoeff() const;
114 
122  Float getMaximumLikelihood() const;
123 
131  Float getBestDistance() const;
132 
138  Float getPhase() const;
139 
145  virtual UINT getNumClasses() const;
146 
154  UINT getClassLabelIndexValue(UINT classLabel) const;
155 
161  UINT getPredictedClassLabel() const;
162 
170 
178 
185 
193 
200  Vector<MinMax> getRanges() const;
201 
211  bool enableNullRejection(bool useNullRejection);
212 
218  virtual bool setNullRejectionCoeff(Float nullRejectionCoeff);
219 
228  virtual bool setNullRejectionThresholds(VectorFloat newRejectionThresholds);
229 
235  virtual bool recomputeNullRejectionThresholds(){ return false; }
236 
243  bool getTimeseriesCompatible() const{ return classifierMode==TIMESERIES_CLASSIFIER_MODE; }
244 
248  typedef std::map< std::string, Classifier*(*)() > StringClassifierMap;
249 
256  static Classifier* createInstanceFromString( std::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 
294 
295 protected:
301  bool saveBaseSettingsToFile( std::fstream &file ) const;
302 
308  bool loadBaseSettingsFromFile( std::fstream &file );
309 
310  std::string classifierType;
311  bool supportsNullRejection;
312  bool useNullRejection;
313  UINT numClasses;
314  UINT predictedClassLabel;
315  UINT classifierMode;
316  Float nullRejectionCoeff;
317  Float maxLikelihood;
318  Float bestDistance;
319  Float phase;
320  VectorFloat classLikelihoods;
321  VectorFloat classDistances;
322  VectorFloat 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( std::string const &newClassificationModuleName ) {
346  getMap()->insert( std::pair< std::string, Classifier*(*)() >(newClassificationModuleName, &getNewClassificationModuleInstance< T > ) );
347  }
348 };
349 
350 GRT_END_NAMESPACE
351 
352 #endif //GRT_CLASSIFIER_HEADER
353 
bool saveBaseSettingsToFile(std::fstream &file) const
Definition: Classifier.cpp:255
virtual bool recomputeNullRejectionThresholds()
Definition: Classifier.h:235
Classifier * deepCopy() const
Definition: Classifier.cpp:40
Vector< UINT > getClassLabels() const
Definition: Classifier.cpp:222
Vector< MinMax > getRanges() const
Definition: Classifier.cpp:226
VectorFloat getNullRejectionThresholds() const
Definition: Classifier.cpp:217
std::string getClassifierType() const
Definition: Classifier.cpp:160
virtual UINT getNumClasses() const
Definition: Classifier.cpp:190
bool getTimeseriesCompatible() const
Definition: Classifier.h:243
const Classifier * getClassifierPointer() const
Definition: Classifier.cpp:53
Classifier(void)
Definition: Classifier.cpp:68
UINT getClassLabelIndexValue(UINT classLabel) const
Definition: Classifier.cpp:194
Float getNullRejectionCoeff() const
Definition: Classifier.cpp:172
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: Classifier.h:61
bool getSupportsNullRejection() const
Definition: Classifier.cpp:164
This is the main base class that all GRT machine learning algorithms should inherit from...
virtual bool setNullRejectionThresholds(VectorFloat newRejectionThresholds)
Definition: Classifier.cpp:243
bool getNullRejectionEnabled() const
Definition: Classifier.cpp:168
Float getPhase() const
Definition: Classifier.cpp:181
UINT getPredictedClassLabel() const
Definition: Classifier.cpp:202
Float getBestDistance() const
Definition: Classifier.cpp:185
static Classifier * createInstanceFromString(std::string const &classifierType)
Definition: Classifier.cpp:28
bool copyBaseVariables(const Classifier *classifier)
Definition: Classifier.cpp:92
virtual ~Classifier(void)
Definition: Classifier.cpp:85
bool loadBaseSettingsFromFile(std::fstream &file)
Definition: Classifier.cpp:302
Float getMaximumLikelihood() const
Definition: Classifier.cpp:176
virtual bool setNullRejectionCoeff(Float nullRejectionCoeff)
Definition: Classifier.cpp:235
virtual bool reset()
Definition: Classifier.cpp:122
VectorFloat getClassDistances() const
Definition: Classifier.cpp:212
static Vector< std::string > getRegisteredClassifiers()
Definition: Classifier.cpp:57
VectorFloat getClassLikelihoods() const
Definition: Classifier.cpp:207
std::map< std::string, Classifier *(*)() > StringClassifierMap
Definition: Classifier.h:248
bool enableNullRejection(bool useNullRejection)
Definition: Classifier.cpp:230
virtual bool clear()
Definition: Classifier.cpp:141
Definition: MLBase.h:70
Classifier * createNewInstance() const
Definition: Classifier.cpp:36
const Classifier & getBaseClassifier() const
Definition: Classifier.cpp:251