GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
ClassificationData.h
Go to the documentation of this file.
1 
31 #ifndef GRT_CLASSIFICATION_DATA_HEADER
32 #define GRT_CLASSIFICATION_DATA_HEADER
33 
34 #include "../Util/GRTCommon.h"
35 #include "../CoreModules/GRTBase.h"
36 #include "ClassificationSample.h"
37 #include "RegressionData.h"
38 #include "UnlabelledData.h"
39 
40 namespace GRT{
41 
42 class ClassificationData : public GRTBase{
43 public:
44 
53  ClassificationData(UINT numDimensions = 0,string datasetName = "NOT_SET",string infoText = "");
54 
61 
65  virtual ~ClassificationData();
66 
74 
82  inline ClassificationSample& operator[] (const UINT &i){
83  return data[i];
84  }
85 
93  inline const ClassificationSample& operator[] (const UINT &i) const{
94  return data[i];
95  }
96 
100  void clear();
101 
112  bool setNumDimensions(UINT numDimensions);
113 
121  bool setDatasetName(string datasetName);
122 
130  bool setInfoText(string infoText);
131 
139  bool setClassNameForCorrespondingClassLabel(string className,UINT classLabel);
140 
149  bool setAllowNullGestureClass(bool allowNullGestureClass);
150 
160  bool addSample(UINT classLabel,const VectorDouble &sample);
161 
167  bool removeSample( const UINT index );
168 
174  bool removeLastSample();
175 
184  bool reserve(const UINT N);
185 
194  bool addClass(const UINT classLabel,const std::string className = "NOT_SET");
195 
202  UINT removeClass(const UINT classLabel);
203 
213  UINT eraseAllSamplesWithClassLabel(const UINT classLabel);
214 
222  bool relabelAllSamplesWithClassLabel(const UINT oldClassLabel,const UINT newClassLabel);
223 
232  bool setExternalRanges(const vector< MinMax > &externalRanges,const bool useExternalRanges = false);
233 
241  bool enableExternalRangeScaling(const bool useExternalRanges);
242 
248  bool scale(const double minTarget,const double maxTarget);
249 
255  bool scale(const vector<MinMax> &ranges,const double minTarget,const double maxTarget);
256 
265  bool save(const string &filename) const;
266 
275  bool load(const string &filename);
276 
283  bool saveDatasetToFile(const string &filename) const;
284 
291  bool loadDatasetFromFile(const string &filename);
292 
300  bool saveDatasetToCSVFile(const string &filename) const;
301 
312  bool loadDatasetFromCSVFile(const string &filename,const UINT classLabelColumnIndex = 0);
313 
320  bool printStats() const;
321 
327  bool sortClassLabels();
328 
337  bool merge(const ClassificationData &labelledData);
338 
347  ClassificationData partition(const UINT partitionPercentage,const bool useStratifiedSampling = false);
348 
356  bool spiltDataIntoKFolds(const UINT K,const bool useStratifiedSampling = false);
357 
365  ClassificationData getTrainingFoldData(const UINT foldIndex) const;
366 
374  ClassificationData getTestFoldData(const UINT foldIndex) const;
375 
383  ClassificationData getClassData(const UINT classLabel) const;
384 
393  ClassificationData getBootstrappedDataset(UINT numSamples=0) const;
394 
404 
411 
417  string getDatasetName() const{ return datasetName; }
418 
424  string getInfoText() const{ return infoText; }
425 
431  string getStatsAsString() const;
432 
438  UINT inline getNumDimensions() const{ return numDimensions; }
439 
445  UINT inline getNumSamples() const{ return totalNumSamples; }
446 
452  UINT inline getNumClasses() const{ return (UINT)classTracker.size(); }
453 
459  UINT getMinimumClassLabel() const;
460 
466  UINT getMaximumClassLabel() const;
467 
473  UINT getClassLabelIndexValue(const UINT classLabel) const;
474 
480  string getClassNameForCorrespondingClassLabel(const UINT classLabel) const;
481 
487  vector<MinMax> getRanges() const;
488 
494  vector< UINT > getClassLabels() const;
495 
501  vector< UINT > getNumSamplesPerClass() const;
502 
508  vector< ClassTracker > getClassTracker() const{ return classTracker; }
509 
517  MatrixDouble getClassHistogramData(const UINT classLabel,const UINT numBins) const;
518 
526  vector< MatrixDouble > getHistogramData(const UINT numBins) const;
527 
533  vector< ClassificationSample > getClassificationData() const{ return data; }
534 
535  VectorDouble getClassProbabilities() const;
536 
537  VectorDouble getClassProbabilities( const vector< UINT > &classLabels ) const;
538 
544  VectorDouble getMean() const;
545 
551  VectorDouble getStdDev() const;
552 
559  MatrixDouble getClassMean() const;
560 
568 
575 
582  vector< UINT > getClassDataIndexes(const UINT classLabel) const;
583 
591 
609  static bool generateGaussDataset( const std::string filename, const UINT numSamples = 10000, const UINT numClasses = 10, const UINT numDimensions = 3, const double range = 10, const double sigma = 1 );
610 
611 private:
612 
613  string datasetName;
614  string infoText;
615  UINT numDimensions;
616  UINT totalNumSamples;
617  UINT kFoldValue;
618  bool crossValidationSetup;
619  bool useExternalRanges;
620  bool allowNullGestureClass;
621  vector< MinMax > externalRanges;
622  vector< ClassTracker > classTracker;
623  vector< ClassificationSample > data;
624  vector< vector< UINT > > crossValidationIndexs;
625 };
626 
627 } //End of namespace GRT
628 
629 #endif //GRT_CLASSIFICATION_DATA_HEADER
VectorDouble getStdDev() const
bool save(const string &filename) const
bool removeSample(const UINT index)
bool setAllowNullGestureClass(bool allowNullGestureClass)
VectorDouble getMean() const
vector< UINT > getClassLabels() const
bool loadDatasetFromFile(const string &filename)
Definition: AdaBoost.cpp:25
ClassificationData getTrainingFoldData(const UINT foldIndex) const
string getDatasetName() const
bool setNumDimensions(UINT numDimensions)
vector< ClassificationSample > getClassificationData() const
ClassificationData & operator=(const ClassificationData &rhs)
UINT removeClass(const UINT classLabel)
MatrixDouble getClassStdDev() const
bool merge(const ClassificationData &labelledData)
vector< ClassTracker > getClassTracker() const
The UnlabelledData class is the main data container for supporting unsupervised learning.
UINT getClassLabelIndexValue(const UINT classLabel) const
bool scale(const double minTarget, const double maxTarget)
static bool generateGaussDataset(const std::string filename, const UINT numSamples=10000, const UINT numClasses=10, const UINT numDimensions=3, const double range=10, const double sigma=1)
ClassificationSample & operator[](const UINT &i)
RegressionData reformatAsRegressionData() const
vector< UINT > getClassDataIndexes(const UINT classLabel) const
vector< UINT > getNumSamplesPerClass() const
ClassificationData(UINT numDimensions=0, string datasetName="NOT_SET", string infoText="")
bool saveDatasetToCSVFile(const string &filename) const
MatrixDouble getDataAsMatrixDouble() const
The RegressionData is the main data structure for recording, labeling, managing, saving, and loading datasets that can be used to train and test the GRT supervised regression algorithms.
UnlabelledData reformatAsUnlabelledData() const
MatrixDouble getCovarianceMatrix() const
bool setExternalRanges(const vector< MinMax > &externalRanges, const bool useExternalRanges=false)
vector< MinMax > getRanges() const
UINT eraseAllSamplesWithClassLabel(const UINT classLabel)
bool enableExternalRangeScaling(const bool useExternalRanges)
vector< MatrixDouble > getHistogramData(const UINT numBins) const
bool setInfoText(string infoText)
bool loadDatasetFromCSVFile(const string &filename, const UINT classLabelColumnIndex=0)
ClassificationData getTestFoldData(const UINT foldIndex) const
string getClassNameForCorrespondingClassLabel(const UINT classLabel) const
ClassificationData partition(const UINT partitionPercentage, const bool useStratifiedSampling=false)
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
MatrixDouble getClassMean() const
bool addSample(UINT classLabel, const VectorDouble &sample)
ClassificationData getBootstrappedDataset(UINT numSamples=0) const
bool load(const string &filename)
bool saveDatasetToFile(const string &filename) const
This class stores the class label and raw data for a single labelled classification sample...
bool relabelAllSamplesWithClassLabel(const UINT oldClassLabel, const UINT newClassLabel)
bool setClassNameForCorrespondingClassLabel(string className, UINT classLabel)
bool addClass(const UINT classLabel, const std::string className="NOT_SET")
MatrixDouble getClassHistogramData(const UINT classLabel, const UINT numBins) const
bool setDatasetName(string datasetName)
ClassificationData getClassData(const UINT classLabel) const