GestureRecognitionToolkit  Version: 0.2.5
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 
26 #ifndef GRT_CLASSIFIER_HEADER
27 #define GRT_CLASSIFIER_HEADER
28 
29 #include "MLBase.h"
30 
31 GRT_BEGIN_NAMESPACE
32 
33 #define DEFAULT_NULL_LIKELIHOOD_VALUE 0
34 #define DEFAULT_NULL_DISTANCE_VALUE 0
35 
41 class GRT_API Classifier : public MLBase
42 {
43 public:
44  enum ClassifierModes{STANDARD_CLASSIFIER_MODE=0,TIMESERIES_CLASSIFIER_MODE};
45 
50  Classifier( const std::string &classifierId = "" );
51 
55  virtual ~Classifier(void);
56 
64  virtual bool deepCopyFrom(const Classifier *classifier){ return false; }
65 
72  bool copyBaseVariables(const Classifier *classifier);
73 
80  virtual bool reset();
81 
87  virtual bool clear();
88 
95  virtual bool computeAccuracy( const ClassificationData &data, Float &accuracy );
96 
102  std::string getClassifierType() const;
103 
109  bool getSupportsNullRejection() const;
110 
116  bool getNullRejectionEnabled() const;
117 
124  Float getNullRejectionCoeff() const;
125 
133  Float getMaximumLikelihood() const;
134 
142  Float getBestDistance() const;
143 
149  Float getPhase() const;
150 
156  Float getTrainingSetAccuracy() const;
157 
163  virtual UINT getNumClasses() const;
164 
172  UINT getClassLabelIndexValue(const UINT classLabel) const;
173 
179  UINT getPredictedClassLabel() const;
180 
187  VectorFloat getClassLikelihoods() const;
188 
195  VectorFloat getClassDistances() const;
196 
202  VectorFloat getNullRejectionThresholds() const;
203 
210  Vector< UINT > getClassLabels() const;
211 
218  Vector<MinMax> getRanges() const;
219 
230  bool enableNullRejection(const bool useNullRejection);
231 
238  virtual bool setNullRejectionCoeff(const Float nullRejectionCoeff);
239 
248  virtual bool setNullRejectionThresholds(const VectorFloat &newRejectionThresholds);
249 
255  virtual bool recomputeNullRejectionThresholds(){ return false; }
256 
263  bool getTimeseriesCompatible() const{ return classifierMode==TIMESERIES_CLASSIFIER_MODE; }
264 
268  typedef std::map< std::string, Classifier*(*)() > StringClassifierMap;
269 
276  static Classifier* create( const std::string &id );
277 
283  Classifier* create() const;
284 
285  GRT_DEPRECATED_MSG( "createNewInstance is deprecated, use create instead.", Classifier* createNewInstance() const );
286  GRT_DEPRECATED_MSG( "createInstanceFromString is deprecated, use create instead.", static Classifier* createInstanceFromString( const std::string &id ) );
287 
295  Classifier* deepCopy() const;
296 
302  const Classifier* getClassifierPointer() const;
303 
309  const Classifier& getBaseClassifier() const;
310 
316  static Vector< std::string > getRegisteredClassifiers();
317 
318 protected:
324  bool saveBaseSettingsToFile( std::fstream &file ) const;
325 
331  bool loadBaseSettingsFromFile( std::fstream &file );
332 
333  bool supportsNullRejection;
334  bool useNullRejection;
335  UINT numClasses;
336  UINT predictedClassLabel;
337  UINT classifierMode;
338  Float nullRejectionCoeff;
339  Float maxLikelihood;
340  Float bestDistance;
341  Float phase;
342  Float trainingSetAccuracy;
343  VectorFloat classLikelihoods;
344  VectorFloat classDistances;
345  VectorFloat nullRejectionThresholds;
346  Vector< UINT > classLabels;
347  Vector< MinMax > ranges;
348 
354  static StringClassifierMap *getMap() {
355  if( !stringClassifierMap ){ stringClassifierMap = new StringClassifierMap; }
356  return stringClassifierMap;
357  }
358 
359 private:
360  static StringClassifierMap *stringClassifierMap;
361  static UINT numClassifierInstances;
362 
363 };
364 
365 template< typename T >
367 
372 template< typename T >
374 public:
375  RegisterClassifierModule( std::string const &newModuleId ) {
376  getMap()->insert( std::pair< std::string, Classifier*(*)() >(newModuleId, &createNewClassifierInstance<T> ) );
377  }
378 };
379 
380 GRT_END_NAMESPACE
381 
382 #endif //GRT_CLASSIFIER_HEADER
383 
bool saveBaseSettingsToFile(std::fstream &file) const
Definition: MLBase.cpp:435
virtual bool recomputeNullRejectionThresholds()
Definition: Classifier.h:255
virtual bool reset()
Definition: MLBase.cpp:147
bool getTimeseriesCompatible() const
Definition: Classifier.h:263
static StringClassifierMap * getMap()
Definition: Classifier.h:354
virtual bool deepCopyFrom(const Classifier *classifier)
Definition: Classifier.h:64
bool loadBaseSettingsFromFile(std::fstream &file)
Definition: MLBase.cpp:458
virtual bool clear()
Definition: MLBase.cpp:149
std::map< std::string, Classifier *(*)() > StringClassifierMap
Definition: Classifier.h:268
GRT_DEPRECATED_MSG("saveModelToFile(std::string filename) is deprecated, use save(const std::string &filename) instead", virtual bool saveModelToFile(const std::string &filename) const )
Classifier * createNewClassifierInstance()
Returns a pointer to a new instance of the template class, the caller is responsible for deleting the...
Definition: Classifier.h:366
This class provides an interface for classes to register themselves with the classifier base class...
Definition: Classifier.h:373
This is the main base class that all GRT machine learning algorithms should inherit from...
Definition: MLBase.h:72
This is the main base class that all GRT Classification algorithms should inherit from...
Definition: Classifier.h:41