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.
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 
41 public:
46 
50  virtual ~WeakClassifier();
51 
58  *this = rhs;
59  }
60 
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 
169  typedef std::map< std::string, WeakClassifier*(*)() > StringWeakClassifierMap;
170 
177  static WeakClassifier* createInstanceFromString( std::string const &weakClassifierType );
178 
185 
186 protected:
187  std::string weakClassifierType;
188  bool trained;
190  TrainingLog trainingLog;
191  ErrorLog errorLog;
192  WarningLog warningLog;
193 
194  static StringWeakClassifierMap *getMap() {
195  if( !stringWeakClassifierMap ){ stringWeakClassifierMap = new StringWeakClassifierMap; }
196  return stringWeakClassifierMap;
197  }
198 
199 private:
200  static StringWeakClassifierMap *stringWeakClassifierMap;
201  static UINT numWeakClassifierInstances;
202 };
203 
204 //These two functions/classes are used to register any new WeakClassification Module with the WeakClassifier base class
205 template< typename T > WeakClassifier *newWeakClassificationModuleInstance() { return new T; }
206 
207 template< typename T >
209 public:
210  RegisterWeakClassifierModule( std::string const &newWeakClassificationModuleName ) {
211  getMap()->insert( std::pair< std::string, WeakClassifier*(*)() >(newWeakClassificationModuleName, &newWeakClassificationModuleInstance< T > ) );
212  }
213 };
214 
215 GRT_END_NAMESPACE
216 
217 #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)
WeakClassifier * createNewInstance() const
WeakClassifier & operator=(const WeakClassifier &rhs)
bool copyBaseVariables(const WeakClassifier *weakClassifer)
std::map< std::string, WeakClassifier *(*)() > StringWeakClassifierMap
bool trained
A flag to show if the weak classifier model has been trained.
static WeakClassifier * createInstanceFromString(std::string const &weakClassifierType)
virtual ~WeakClassifier()
virtual void print() const