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.
MLBase.h
Go to the documentation of this file.
1 
31 #ifndef GRT_MLBASE_HEADER
32 #define GRT_MLBASE_HEADER
33 
34 #include "GRTBase.h"
35 #include "../DataStructures/UnlabelledData.h"
36 #include "../DataStructures/ClassificationData.h"
37 #include "../DataStructures/ClassificationDataStream.h"
38 #include "../DataStructures/RegressionData.h"
39 #include "../DataStructures/TimeSeriesClassificationData.h"
40 
41 GRT_BEGIN_NAMESPACE
42 
43 #define DEFAULT_NULL_LIKELIHOOD_VALUE 0
44 #define DEFAULT_NULL_DISTANCE_VALUE 0
45 
49 class TrainingResultsObserverManager : public ObserverManager< TrainingResult >
50 {
51 public:
53  }
55 
56 };
57 
61 class TestResultsObserverManager : public ObserverManager< TestInstanceResult >
62 {
63 public:
65  }
66  virtual ~TestResultsObserverManager(){}
67 
68 };
69 
70 class MLBase : public GRTBase, public Observer< TrainingResult >, public Observer< TestInstanceResult >
71 {
72 public:
76  MLBase(void);
77 
81  virtual ~MLBase(void);
82 
89  bool copyMLBaseVariables(const MLBase *mlBase);
90 
98  virtual bool train(ClassificationData trainingData);
99 
106  virtual bool train_(ClassificationData &trainingData);
107 
115  virtual bool train(RegressionData trainingData);
116 
123  virtual bool train_(RegressionData &trainingData);
124 
132  virtual bool train(TimeSeriesClassificationData trainingData);
133 
140  virtual bool train_(TimeSeriesClassificationData &trainingData);
141 
149  virtual bool train(ClassificationDataStream trainingData);
150 
157  virtual bool train_(ClassificationDataStream &trainingData);
158 
166  virtual bool train(UnlabelledData trainingData);
167 
174  virtual bool train_(UnlabelledData &trainingData);
175 
183  virtual bool train(MatrixFloat data);
184 
191  virtual bool train_(MatrixFloat &data);
192 
200  virtual bool predict(VectorFloat inputVector);
201 
208  virtual bool predict_(VectorFloat &inputVector);
209 
217  virtual bool predict(MatrixFloat inputMatrix);
218 
225  virtual bool predict_(MatrixFloat &inputMatrix);
226 
234  virtual bool map(VectorFloat inputVector);
235 
242  virtual bool map_(VectorFloat &inputVector);
243 
251  virtual bool reset();
252 
259  virtual bool clear();
260 
267  virtual bool print() const;
268 
275  virtual bool save(const std::string filename) const;
276 
283  virtual bool load(const std::string filename);
284 
291  virtual bool saveModelToFile(std::string filename) const;
292 
300  virtual bool saveModelToFile(std::fstream &file) const;
301 
308  virtual bool loadModelFromFile(std::string filename);
309 
317  virtual bool loadModelFromFile(std::fstream &file);
318 
326  virtual bool getModel(std::ostream &stream) const;
327 
339  Float inline scale(const Float &x,const Float &minSource,const Float &maxSource,const Float &minTarget,const Float &maxTarget,const bool constrain=false){
340  if( constrain ){
341  if( x <= minSource ) return minTarget;
342  if( x >= maxSource ) return maxTarget;
343  }
344  if( minSource == maxSource ) return minTarget;
345  return (((x-minSource)*(maxTarget-minTarget))/(maxSource-minSource))+minTarget;
346  }
347 
353  virtual std::string getModelAsString() const;
354 
360  DataType getInputType() const;
361 
367  DataType getOutputType() const;
368 
374  UINT getBaseType() const;
375 
382  UINT getNumInputFeatures() const;
383 
389  UINT getNumInputDimensions() const;
390 
396  UINT getNumOutputDimensions() const;
397 
404  UINT getMinNumEpochs() const;
405 
412  UINT getMaxNumEpochs() const;
413 
421  UINT getValidationSetSize() const;
422 
429 
435  Float getMinChange() const;
436 
442  Float getLearningRate() const;
443 
449  Float getRootMeanSquaredTrainingError() const;
450 
456  Float getTotalSquaredTrainingError() const;
457 
463  Float getValidationSetAccuracy() const;
464 
471 
478 
488  bool getUseValidationSet() const;
489 
496  bool getRandomiseTrainingOrder() const;
497 
503  bool getTrained() const;
504 
510  bool getModelTrained() const;
511 
517  bool getScalingEnabled() const;
518 
524  bool getIsBaseTypeClassifier() const;
525 
531  bool getIsBaseTypeRegressifier() const;
532 
538  bool getIsBaseTypeClusterer() const;
539 
545  bool enableScaling(const bool useScaling);
546 
554  bool setMaxNumEpochs(const UINT maxNumEpochs);
555 
562  bool setMinNumEpochs(const UINT minNumEpochs);
563 
571  bool setMinChange(const Float minChange);
572 
580  bool setLearningRate(const Float learningRate);
581 
590  bool setUseValidationSet(const bool useValidationSet);
591 
600  bool setValidationSetSize(const UINT validationSetSize);
601 
609  bool setRandomiseTrainingOrder(const bool randomiseTrainingOrder);
610 
618  bool setTrainingLoggingEnabled(const bool loggingEnabled);
619 
627 
635 
643 
651 
658 
664  bool removeAllTestObservers();
665 
672  bool notifyTrainingResultsObservers( const TrainingResult &data );
673 
680  bool notifyTestResultsObservers( const TestInstanceResult &data );
681 
688 
694  const MLBase* getMLBasePointer() const;
695 
702 
703 protected:
704 
710  bool saveBaseSettingsToFile( std::fstream &file ) const;
711 
717  bool loadBaseSettingsFromFile( std::fstream &file );
718 
719  bool trained;
720  bool useScaling;
721  DataType inputType;
722  DataType outputType;
723  UINT baseType;
724  UINT numInputDimensions;
725  UINT numOutputDimensions;
726  UINT numTrainingIterationsToConverge;
727  UINT minNumEpochs;
728  UINT maxNumEpochs;
729  UINT validationSetSize;
730  Float learningRate;
731  Float minChange;
732  Float rootMeanSquaredTrainingError;
733  Float totalSquaredTrainingError;
734  Float validationSetAccuracy;
735  bool useValidationSet;
736  bool randomiseTrainingOrder;
737  VectorFloat validationSetPrecision;
738  VectorFloat validationSetRecall;
739  Random random;
740  std::vector< TrainingResult > trainingResults;
741  TrainingResultsObserverManager trainingResultsObserverManager;
742  TestResultsObserverManager testResultsObserverManager;
743 
744 public:
745 
746  enum BaseTypes{BASE_TYPE_NOT_SET=0,CLASSIFIER,REGRESSIFIER,CLUSTERER};
747 };
748 
749 GRT_END_NAMESPACE
750 
751 #endif //GRT_MLBASE_HEADER
bool saveBaseSettingsToFile(std::fstream &file) const
Definition: MLBase.cpp:370
bool setLearningRate(const Float learningRate)
Definition: MLBase.cpp:291
virtual bool predict(VectorFloat inputVector)
Definition: MLBase.cpp:112
bool setRandomiseTrainingOrder(const bool randomiseTrainingOrder)
Definition: MLBase.cpp:316
bool notifyTrainingResultsObservers(const TrainingResult &data)
Definition: MLBase.cpp:350
bool registerTrainingResultsObserver(Observer< TrainingResult > &observer)
Definition: MLBase.cpp:326
Float scale(const Float &x, const Float &minSource, const Float &maxSource, const Float &minTarget, const Float &maxTarget, const bool constrain=false)
Definition: MLBase.h:339
virtual bool predict_(VectorFloat &inputVector)
Definition: MLBase.cpp:114
virtual bool reset()
Definition: MLBase.cpp:124
bool setTrainingLoggingEnabled(const bool loggingEnabled)
Definition: MLBase.cpp:321
Float getLearningRate() const
Definition: MLBase.cpp:230
bool removeAllTestObservers()
Definition: MLBase.cpp:346
bool enableScaling(const bool useScaling)
Definition: MLBase.cpp:266
Definition: Random.h:40
DataType getOutputType() const
Definition: MLBase.cpp:199
virtual bool getModel(std::ostream &stream) const
Definition: MLBase.cpp:185
virtual bool train(ClassificationData trainingData)
Definition: MLBase.cpp:88
bool getTrained() const
Definition: MLBase.cpp:254
Float getRootMeanSquaredTrainingError() const
Definition: MLBase.cpp:234
UINT getMinNumEpochs() const
Definition: MLBase.cpp:218
UINT getNumOutputDimensions() const
Definition: MLBase.cpp:209
bool getScalingEnabled() const
Definition: MLBase.cpp:258
bool registerTestResultsObserver(Observer< TestInstanceResult > &observer)
Definition: MLBase.cpp:330
bool setMinChange(const Float minChange)
Definition: MLBase.cpp:282
UINT getValidationSetSize() const
Definition: MLBase.cpp:226
bool getRandomiseTrainingOrder() const
bool getUseValidationSet() const
virtual bool save(const std::string filename) const
Definition: MLBase.cpp:142
virtual bool load(const std::string filename)
Definition: MLBase.cpp:164
Float getMinChange() const
UINT getMaxNumEpochs() const
Definition: MLBase.cpp:222
bool getModelTrained() const
Definition: MLBase.cpp:256
Float getTotalSquaredTrainingError() const
Definition: MLBase.cpp:238
bool setValidationSetSize(const UINT validationSetSize)
Definition: MLBase.cpp:299
virtual bool saveModelToFile(std::string filename) const
Definition: MLBase.cpp:146
bool copyMLBaseVariables(const MLBase *mlBase)
Definition: MLBase.cpp:49
virtual bool print() const
Definition: MLBase.cpp:140
UINT getBaseType() const
Definition: MLBase.cpp:203
Float getValidationSetAccuracy() const
Definition: MLBase.cpp:242
bool getIsBaseTypeClusterer() const
Definition: MLBase.cpp:264
virtual std::string getModelAsString() const
Definition: MLBase.cpp:187
virtual bool loadModelFromFile(std::string filename)
Definition: MLBase.cpp:168
bool setMinNumEpochs(const UINT minNumEpochs)
Definition: MLBase.cpp:277
This file contains the GRTBase class. This is the core base class for all the GRT modules...
MLBase(void)
Definition: MLBase.cpp:25
bool loadBaseSettingsFromFile(std::fstream &file)
Definition: MLBase.cpp:393
MLBase * getMLBasePointer()
Definition: MLBase.cpp:358
bool removeAllTrainingObservers()
Definition: MLBase.cpp:342
UINT getNumInputFeatures() const
Definition: MLBase.cpp:205
virtual bool clear()
Definition: MLBase.cpp:126
virtual ~MLBase(void)
Definition: MLBase.cpp:45
virtual bool train_(ClassificationData &trainingData)
Definition: MLBase.cpp:90
bool notifyTestResultsObservers(const TestInstanceResult &data)
Definition: MLBase.cpp:354
bool getIsBaseTypeClassifier() const
Definition: MLBase.cpp:260
VectorFloat getValidationSetPrecision() const
Definition: MLBase.cpp:246
DataType getInputType() const
Definition: MLBase.cpp:195
bool removeTrainingResultsObserver(const Observer< TrainingResult > &observer)
Definition: MLBase.cpp:334
Definition: Vector.h:41
UINT getNumInputDimensions() const
Definition: MLBase.cpp:207
bool removeTestResultsObserver(const Observer< TestInstanceResult > &observer)
Definition: MLBase.cpp:338
virtual bool map_(VectorFloat &inputVector)
Definition: MLBase.cpp:122
UINT getNumTrainingIterationsToConverge() const
Definition: MLBase.cpp:211
bool setUseValidationSet(const bool useValidationSet)
Definition: MLBase.cpp:311
bool setMaxNumEpochs(const UINT maxNumEpochs)
Definition: MLBase.cpp:268
Vector< TrainingResult > getTrainingResults() const
Definition: MLBase.cpp:366
virtual bool map(VectorFloat inputVector)
Definition: MLBase.cpp:120
VectorFloat getValidationSetRecall() const
Definition: MLBase.cpp:250
Definition: MLBase.h:70
bool getIsBaseTypeRegressifier() const
Definition: MLBase.cpp:262