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.
WeakClassifier.h
Go to the documentation of this file.
1 
29 #ifndef GRT_WEAK_CLASSIFIER_HEADER
30 #define GRT_WEAK_CLASSIFIER_HEADER
31 
32 #include "../../../Util/GRTCommon.h"
33 #include "../../../DataStructures/ClassificationData.h"
34 
35 GRT_BEGIN_NAMESPACE
36 
37 #define WEAK_CLASSIFIER_POSITIVE_CLASS_LABEL 1
38 #define WEAK_CLASSIFIER_NEGATIVE_CLASS_LABEL 2
39 
40 class GRT_API WeakClassifier{
41 public:
46 
50  virtual ~WeakClassifier();
51 
58  *this = rhs;
59  }
60 
67  WeakClassifier& operator=(const WeakClassifier &rhs);
68 
75  bool copyBaseVariables(const WeakClassifier *weakClassifer);
76 
84  virtual bool deepCopyFrom(const WeakClassifier *weakClassifer){
85  return false;
86  }
87 
96  virtual bool train(ClassificationData &trainingData, VectorFloat &weights){
97  return false;
98  }
99 
107  virtual Float predict(const VectorFloat &x){
108  return 0;
109  }
110 
118  virtual bool saveModelToFile( std::fstream &file ) const{ return false; }
119 
127  virtual bool loadModelFromFile( std::fstream &file ){ return false; }
128 
133  virtual void print() const{}
134 
138  virtual Float getPositiveClassLabel() const{ return 1; }
139 
143  virtual Float getNegativeClassLabel() const{ return -1; }
144 
148  std::string getWeakClassifierType() const{
149  return weakClassifierType;
150  }
151 
155  bool getTrained() const{
156  return trained;
157  }
158 
162  UINT getNumInputDimensions() const{
163  return numInputDimensions;
164  }
165 
166  bool getTrainingLoggingEnabled() const{
167  return trainingLog.getLoggingEnabled();
168  }
169 
170  bool setTrainingLoggingEnabled(const bool enabled){
171  return trainingLog.setLoggingEnabled(enabled);
172  }
173 
177  typedef std::map< std::string, WeakClassifier*(*)() > StringWeakClassifierMap;
178 
185  static WeakClassifier* createInstanceFromString( std::string const &weakClassifierType );
186 
192  WeakClassifier* createNewInstance() const;
193 
194 protected:
195  std::string weakClassifierType;
196  bool trained;
198  TrainingLog trainingLog;
199  ErrorLog errorLog;
200  WarningLog warningLog;
201 
202  static StringWeakClassifierMap *getMap() {
203  if( !stringWeakClassifierMap ){ stringWeakClassifierMap = new StringWeakClassifierMap; }
204  return stringWeakClassifierMap;
205  }
206 
207 private:
208  static StringWeakClassifierMap *stringWeakClassifierMap;
209  static UINT numWeakClassifierInstances;
210 };
211 
212 //These two functions/classes are used to register any new WeakClassification Module with the WeakClassifier base class
213 template< typename T > WeakClassifier *newWeakClassificationModuleInstance() { return new T; }
214 
215 template< typename T >
217 public:
218  RegisterWeakClassifierModule( std::string const &newWeakClassificationModuleName ) {
219  getMap()->insert( std::pair< std::string, WeakClassifier*(*)() >(newWeakClassificationModuleName, &newWeakClassificationModuleInstance< T > ) );
220  }
221 };
222 
223 GRT_END_NAMESPACE
224 
225 #endif //GRT_WEAK_CLASSIFIER_HEADER
virtual Float predict(const VectorFloat &x)
std::string weakClassifierType
A string that represents the weak classifier type, e.g. DecisionStump.
virtual bool deepCopyFrom(const WeakClassifier *weakClassifer)
UINT numInputDimensions
The number of input dimensions to the weak classifier.
virtual bool saveModelToFile(std::fstream &file) const
std::string getWeakClassifierType() const
virtual Float getNegativeClassLabel() const
WeakClassifier(const WeakClassifier &rhs)
bool getTrained() const
virtual bool train(ClassificationData &trainingData, VectorFloat &weights)
UINT getNumInputDimensions() const
virtual Float getPositiveClassLabel() const
virtual bool loadModelFromFile(std::fstream &file)
std::map< std::string, WeakClassifier *(*)() > StringWeakClassifierMap
bool trained
A flag to show if the weak classifier model has been trained.
virtual void print() const