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.
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 "VectorFloat.h"
35 #include "../Util/GRTCommon.h"
36 #include "../CoreModules/GRTBase.h"
37 #include "ClassificationSample.h"
38 #include "RegressionData.h"
39 #include "UnlabelledData.h"
40 
41 GRT_BEGIN_NAMESPACE
42 
43 class ClassificationData : public GRTBase{
44 public:
45 
54  ClassificationData(UINT numDimensions = 0,std::string datasetName = "NOT_SET",std::string infoText = "");
55 
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(std::string datasetName);
122 
130  bool setInfoText(std::string infoText);
131 
139  bool setClassNameForCorrespondingClassLabel(std::string className,UINT classLabel);
140 
149  bool setAllowNullGestureClass(bool allowNullGestureClass);
150 
160  bool addSample(UINT classLabel,const VectorFloat &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 Float minTarget,const Float maxTarget);
249 
255  bool scale(const Vector<MinMax> &ranges,const Float minTarget,const Float maxTarget);
256 
265  bool save(const std::string &filename) const;
266 
275  bool load(const std::string &filename);
276 
283  bool saveDatasetToFile(const std::string &filename) const;
284 
291  bool loadDatasetFromFile(const std::string &filename);
292 
300  bool saveDatasetToCSVFile(const std::string &filename) const;
301 
312  bool loadDatasetFromCSVFile(const std::string &filename,const UINT classLabelColumnIndex = 0);
313 
320  bool printStats() const;
321 
327  bool sortClassLabels();
328 
337  bool merge(const ClassificationData &data);
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 
394  ClassificationData getBootstrappedDataset(UINT numSamples=0, bool balanceDataset=false ) const;
395 
405 
412 
418  std::string getDatasetName() const{ return datasetName; }
419 
425  std::string getInfoText() const{ return infoText; }
426 
432  std::string getStatsAsString() const;
433 
439  UINT inline getNumDimensions() const{ return numDimensions; }
440 
446  UINT inline getNumSamples() const{ return totalNumSamples; }
447 
453  UINT inline getNumClasses() const{ return classTracker.getSize(); }
454 
460  UINT getMinimumClassLabel() const;
461 
467  UINT getMaximumClassLabel() const;
468 
474  UINT getClassLabelIndexValue(const UINT classLabel) const;
475 
481  std::string getClassNameForCorrespondingClassLabel(const UINT classLabel) const;
482 
488  Vector<MinMax> getRanges() const;
489 
496 
503 
509  Vector< ClassTracker > getClassTracker() const{ return classTracker; }
510 
518  MatrixFloat getClassHistogramData(const UINT classLabel,const UINT numBins) const;
519 
527  Vector< MatrixFloat > getHistogramData(const UINT numBins) const;
528 
535 
536  VectorFloat getClassProbabilities() const;
537 
538  VectorFloat getClassProbabilities( const Vector< UINT > &classLabels ) const;
539 
545  VectorFloat getMean() const;
546 
552  VectorFloat getStdDev() const;
553 
560  MatrixFloat getClassMean() const;
561 
568  MatrixFloat getClassStdDev() const;
569 
576 
583  Vector< UINT > getClassDataIndexes(const UINT classLabel) const;
584 
592 
600 
618  static bool generateGaussDataset( const std::string filename, const UINT numSamples = 10000, const UINT numClasses = 10, const UINT numDimensions = 3, const Float range = 10, const Float sigma = 1 );
619 
620 private:
621 
622  std::string datasetName;
623  std::string infoText;
624  UINT numDimensions;
625  UINT totalNumSamples;
626  UINT kFoldValue;
627  bool crossValidationSetup;
628  bool useExternalRanges;
629  bool allowNullGestureClass;
630  Vector< MinMax > externalRanges;
631  Vector< ClassTracker > classTracker;
633  Vector< Vector< UINT > > crossValidationIndexs;
634 };
635 
636 GRT_END_NAMESPACE
637 
638 #endif //GRT_CLASSIFICATION_DATA_HEADER
bool saveDatasetToFile(const std::string &filename) const
bool setDatasetName(std::string datasetName)
bool loadDatasetFromFile(const std::string &filename)
RegressionData reformatAsRegressionData() const
ClassificationData & operator=(const ClassificationData &rhs)
static bool generateGaussDataset(const std::string filename, const UINT numSamples=10000, const UINT numClasses=10, const UINT numDimensions=3, const Float range=10, const Float sigma=1)
bool relabelAllSamplesWithClassLabel(const UINT oldClassLabel, const UINT newClassLabel)
bool addSample(UINT classLabel, const VectorFloat &sample)
ClassificationData getTestFoldData(const UINT foldIndex) const
bool addClass(const UINT classLabel, const std::string className="NOT_SET")
Vector< ClassTracker > getClassTracker() const
Vector< ClassificationSample > getClassificationData() const
ClassificationData getClassData(const UINT classLabel) const
bool setNumDimensions(UINT numDimensions)
UINT eraseAllSamplesWithClassLabel(const UINT classLabel)
MatrixDouble getDataAsMatrixDouble() const
MatrixFloat getClassMean() const
std::string getClassNameForCorrespondingClassLabel(const UINT classLabel) const
std::string getDatasetName() const
bool setClassNameForCorrespondingClassLabel(std::string className, UINT classLabel)
Vector< UINT > getClassLabels() const
bool loadDatasetFromCSVFile(const std::string &filename, const UINT classLabelColumnIndex=0)
bool setAllowNullGestureClass(bool allowNullGestureClass)
UINT getMinimumClassLabel() const
Vector< MatrixFloat > getHistogramData(const UINT numBins) const
unsigned int getSize() const
Definition: Vector.h:193
UINT removeClass(const UINT classLabel)
The UnlabelledData class is the main data container for supporting unsupervised learning.
ClassificationData(UINT numDimensions=0, std::string datasetName="NOT_SET", std::string infoText="")
bool setInfoText(std::string infoText)
Vector< UINT > getNumSamplesPerClass() const
MatrixFloat getCovarianceMatrix() const
UnlabelledData reformatAsUnlabelledData() const
bool removeSample(const UINT index)
UINT getNumSamples() const
bool spiltDataIntoKFolds(const UINT K, const bool useStratifiedSampling=false)
bool save(const std::string &filename) const
bool enableExternalRangeScaling(const bool useExternalRanges)
bool setExternalRanges(const Vector< MinMax > &externalRanges, const bool useExternalRanges=false)
bool reserve(const UINT N)
bool saveDatasetToCSVFile(const std::string &filename) const
ClassificationData partition(const UINT partitionPercentage, const bool useStratifiedSampling=false)
UINT getNumDimensions() const
UINT getNumClasses() 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.
Vector< MinMax > getRanges() const
bool merge(const ClassificationData &data)
VectorFloat getStdDev() const
Vector< UINT > getClassDataIndexes(const UINT classLabel) const
std::string getInfoText() const
MatrixFloat getDataAsMatrixFloat() const
ClassificationSample & operator[](const UINT &i)
UINT getClassLabelIndexValue(const UINT classLabel) const
ClassificationData getBootstrappedDataset(UINT numSamples=0, bool balanceDataset=false) const
MatrixFloat getClassHistogramData(const UINT classLabel, const UINT numBins) const
ClassificationData getTrainingFoldData(const UINT foldIndex) const
UINT getMaximumClassLabel() const
bool scale(const Float minTarget, const Float maxTarget)
bool load(const std::string &filename)
This class stores the class label and raw data for a single labelled classification sample...
MatrixFloat getClassStdDev() const
std::string getStatsAsString() const
VectorFloat getMean() const