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.
GRT::RegressionData Class Reference

Public Member Functions

 RegressionData (const UINT numInputDimensions=0, const UINT numTargetDimensions=0, const string datasetName="NOT_SET", const string infoText="")
 
 RegressionData (const RegressionData &rhs)
 
 ~RegressionData ()
 
RegressionDataoperator= (const RegressionData &rhs)
 
RegressionSampleoperator[] (const UINT &i)
 
const RegressionSampleoperator[] (const UINT &i) const
 
void clear ()
 
bool setInputAndTargetDimensions (const UINT numInputDimensions, const UINT numTargetDimensions)
 
bool setDatasetName (const string &datasetName)
 
bool setInfoText (const string &infoText)
 
bool addSample (const VectorDouble &inputVector, const VectorDouble &targetVector)
 
bool removeLastSample ()
 
bool reserve (const UINT N)
 
bool setExternalRanges (const vector< MinMax > &externalInputRanges, const vector< MinMax > &externalTargetRanges, const bool useExternalRanges)
 
bool enableExternalRangeScaling (const bool useExternalRanges)
 
bool scale (const double minTarget, const double maxTarget)
 
bool scale (const vector< MinMax > &inputVectorRanges, const vector< MinMax > &targetVectorRanges, const double minTarget, const double maxTarget)
 
bool save (const string &filename) const
 
bool load (const string &filename)
 
bool saveDatasetToFile (const string &filename) const
 
bool loadDatasetFromFile (const string &filename)
 
bool saveDatasetToCSVFile (const string &filename) const
 
bool loadDatasetFromCSVFile (const string &filename, const UINT numInputDimensions, const UINT numTargetDimensions)
 
bool printStats () const
 
bool merge (const RegressionData &regressionData)
 
RegressionData partition (const UINT trainingSizePercentage)
 
bool spiltDataIntoKFolds (const UINT K)
 
RegressionData getTrainingFoldData (const UINT foldIndex) const
 
RegressionData getTestFoldData (const UINT foldIndex) const
 
UINT removeDuplicateSamples ()
 
string getDatasetName () const
 
string getInfoText () const
 
string getStatsAsString () const
 
UINT getNumInputDimensions () const
 
UINT getNumTargetDimensions () const
 
UINT getNumSamples () const
 
vector< MinMaxgetInputRanges () const
 
vector< MinMaxgetTargetRanges () const
 
vector< RegressionSamplegetData () const
 

Detailed Description

Definition at line 40 of file RegressionData.h.

Constructor & Destructor Documentation

GRT::RegressionData::RegressionData ( const UINT  numInputDimensions = 0,
const UINT  numTargetDimensions = 0,
const string  datasetName = "NOT_SET",
const string  infoText = "" 
)

Constructor, set the number of input dimensions, number of target dimensions, dataset name and the infotext for the dataset. The name of the dataset should not contain any spaces.

Parameters
constUINT numInputDimensions: the number of input dimensions of the training data, should be an unsigned integer greater than 0
constUINT numTargetDimensions: the number of target dimensions of the training data, should be an unsigned integer greater than 0
conststring datasetName: the name of the dataset, should not contain any spaces
conststring infoText: some info about the data in this dataset, this can contain spaces

Definition at line 25 of file RegressionData.cpp.

GRT::RegressionData::RegressionData ( const RegressionData rhs)

Copy Constructor, copies the RegressionData from the rhs instance to this instance

Parameters
constRegressionData &rhs: another instance of the RegressionData class from which the data will be copied to this instance

Definition at line 38 of file RegressionData.cpp.

GRT::RegressionData::~RegressionData ( )

Default Destructor

Definition at line 42 of file RegressionData.cpp.

Member Function Documentation

bool GRT::RegressionData::addSample ( const VectorDouble &  inputVector,
const VectorDouble &  targetVector 
)

Adds a new labelled sample to the dataset. The input and target dimensionality of the sample should match that of the dataset.

Parameters
vector<double>inputVector: the new input vector you want to add to the dataset. The dimensionality of this sample should match the number of input dimensions in the dataset
vector<double>targetVector: the new target vector you want to add to the dataset. The dimensionality of this sample should match the number of target dimensions in the dataset
Returns
true if the sample was correctly added to the dataset, false otherwise

Definition at line 106 of file RegressionData.cpp.

void GRT::RegressionData::clear ( )

Clears any previous training data and counters

Definition at line 65 of file RegressionData.cpp.

bool GRT::RegressionData::enableExternalRangeScaling ( const bool  useExternalRanges)

Sets if the dataset should be scaled using an external range (if useExternalRanges == true) or the ranges of the dataset (if false). The external ranges need to be set FIRST before calling this function, otherwise it will return false.

Parameters
constbool useExternalRanges: sets if these ranges should be used to scale the dataset
Returns
returns true if the useExternalRanges variable was set, false otherwise

Definition at line 156 of file RegressionData.cpp.

vector< RegressionSample > GRT::RegressionData::getData ( ) const
inline

Gets the regression data.

Returns
a vector of RegressionSample

Definition at line 357 of file RegressionData.h.

string GRT::RegressionData::getDatasetName ( ) const
inline

Gets the name of the dataset.

Returns
returns the name of the dataset

Definition at line 306 of file RegressionData.h.

string GRT::RegressionData::getInfoText ( ) const
inline

Gets the infotext for the dataset

Returns
returns the infotext of the dataset

Definition at line 313 of file RegressionData.h.

vector< MinMax > GRT::RegressionData::getInputRanges ( ) const

Gets the input ranges of the dataset.

Returns
a vector of minimum and maximum values for each input dimension of the data

Definition at line 194 of file RegressionData.cpp.

UINT GRT::RegressionData::getNumInputDimensions ( ) const
inline

Gets the number of input dimensions of the labelled regression data.

Returns
an unsigned int representing the number of input dimensions in the dataset

Definition at line 322 of file RegressionData.h.

UINT GRT::RegressionData::getNumSamples ( ) const
inline

Gets the number of samples in the classification data across all the classes.

Returns
an unsigned int representing the total number of samples in the classification data

Definition at line 336 of file RegressionData.h.

UINT GRT::RegressionData::getNumTargetDimensions ( ) const
inline

Gets the number of target dimensions of the labelled regression data.

Returns
an unsigned int representing the number of target dimensions in the dataset

Definition at line 329 of file RegressionData.h.

vector< MinMax > GRT::RegressionData::getTargetRanges ( ) const

Gets the target ranges of the dataset.

Returns
a vector of minimum and maximum values for each target dimension of the data

Definition at line 213 of file RegressionData.cpp.

RegressionData GRT::RegressionData::getTestFoldData ( const UINT  foldIndex) const

Returns the test dataset for the k-th fold for cross validation. The spiltDataIntoKFolds(UINT K) function should have been called once before using this function. The foldIndex should be in the range [0 K-1], where K is the number of folds the data was spilt into.

Parameters
UINTfoldIndex: the index of the fold you want the test data for, this should be in the range [0 K-1], where K is the number of folds the data was spilt into
Returns
returns a test dataset

Definition at line 413 of file RegressionData.cpp.

RegressionData GRT::RegressionData::getTrainingFoldData ( const UINT  foldIndex) const

Returns the training dataset for the k-th fold for cross validation. The spiltDataIntoKFolds(UINT K) function should have been called once before using this function. The foldIndex should be in the range [0 K-1], where K is the number of folds the data was spilt into.

Parameters
UINTfoldIndex: the index of the fold you want the training data for, this should be in the range [0 K-1], where K is the number of folds the data was spilt into
Returns
returns a training dataset

Definition at line 386 of file RegressionData.cpp.

bool GRT::RegressionData::load ( const string &  filename)

Load the data from a file. If the file format ends in '.csv' then the function will try and load the data from a csv format. If this fails then it will try and load the data as a custom GRT file.

Parameters
conststring &filename: the name of the file the data will be loaded from
Returns
true if the data was loaded successfully, false otherwise

Definition at line 489 of file RegressionData.cpp.

bool GRT::RegressionData::loadDatasetFromCSVFile ( const string &  filename,
const UINT  numInputDimensions,
const UINT  numTargetDimensions 
)

Loads the labelled regression data from a CSV file. Each row represents a sample, the first N columns should represent the input vector data with the remaining T columns representing the target sample. The user must specify the length of the input vector (N) and the length of the target vector (T).

Parameters
conststring &filename: the name of the file the data will be saved to
constUINT numInputDimensions: the length of an input vector
constUINT numTargetDimensions: the length of a target vector
Returns
true if the data was saved successfully, false otherwise

Definition at line 692 of file RegressionData.cpp.

bool GRT::RegressionData::loadDatasetFromFile ( const string &  filename)

Loads the labelled regression data from a custom file format.

Parameters
conststring &filename: the name of the file the data will be loaded from
Returns
true if the data was loaded successfully, false otherwise

Definition at line 544 of file RegressionData.cpp.

bool GRT::RegressionData::merge ( const RegressionData regressionData)

Adds the data in the regressionData set to the current instance of the RegressionData. The number of dimensions in both datasets must match.

Parameters
constRegressionData &regressionData: the dataset to add to this dataset
Returns
returns true if the datasets were merged, false otherwise

Definition at line 303 of file RegressionData.cpp.

RegressionData & GRT::RegressionData::operator= ( const RegressionData rhs)

Sets the equals operator, copies the data from the rhs instance to this instance

Parameters
constRegressionData &rhs: another instance of the RegressionData class from which the data will be copied to this instance
Returns
a reference to this instance of RegressionData

Definition at line 44 of file RegressionData.cpp.

RegressionSample& GRT::RegressionData::operator[] ( const UINT &  i)
inline

Array Subscript Operator, returns the LabelledRegressionSample at index i. It is up to the user to ensure that i is within the range of [0 totalNumSamples-1]

Parameters
constUINT &i: the index of the training sample you want to access. Must be within the range of [0 totalNumSamples-1]
Returns
a reference to the i'th RegressionSample

Definition at line 81 of file RegressionData.h.

const RegressionSample& GRT::RegressionData::operator[] ( const UINT &  i) const
inline

Const Array Subscript Operator, returns the LabelledRegressionSample at index i. It is up to the user to ensure that i is within the range of [0 totalNumSamples-1]

Parameters
constUINT &i: the index of the training sample you want to access. Must be within the range of [0 totalNumSamples-1]
Returns
a reference to the i'th RegressionSample

Definition at line 92 of file RegressionData.h.

RegressionData GRT::RegressionData::partition ( const UINT  trainingSizePercentage)

Partitions the dataset into a training dataset (which is kept by this instance of the RegressionData) and a testing/validation dataset (which is returned as a new instance of a RegressionData).

Parameters
constUINT partitionPercentage: sets the percentage of data which remains in this instance, the remaining percentage of data is then returned as the testing/validation dataset
Returns
a new RegressionData instance, containing the remaining data not kept but this instance

Definition at line 262 of file RegressionData.cpp.

bool GRT::RegressionData::removeLastSample ( )

Removes the last training sample added to the dataset.

Returns
true if the last sample was removed, false otherwise

Definition at line 120 of file RegressionData.cpp.

bool GRT::RegressionData::reserve ( const UINT  N)

Reserves that the vector capacity be at least enough to contain N elements.

If N is greater than the current vector capacity, the function causes the container to reallocate its storage increasing its capacity to N (or greater).

Parameters
constUINT N: the new memory size
Returns
true if the memory was reserved successfully, false otherwise

Definition at line 135 of file RegressionData.cpp.

bool GRT::RegressionData::save ( const string &  filename) const

Saves the data to a file. If the file format ends in '.csv' then the data will be saved as comma-seperated-values, otherwise it will be saved to a custom GRT file (which contains the csv data with an additional header).

Parameters
conststring &filename: the name of the file the data will be saved to
Returns
true if the data was saved successfully, false otherwise

Definition at line 478 of file RegressionData.cpp.

bool GRT::RegressionData::saveDatasetToCSVFile ( const string &  filename) const

Saves the labelled regression data to a CSV file. This will save the input vector as the first N columns and the target data as the following T columns. Each row will represent a sample.

Parameters
conststring &filename: the name of the file the data will be saved to
Returns
true if the data was saved successfully, false otherwise

Definition at line 665 of file RegressionData.cpp.

bool GRT::RegressionData::saveDatasetToFile ( const string &  filename) const

Saves the labelled regression data to a custom file format.

Parameters
conststring &filename: the name of the file the data will be saved to
Returns
true if the data was saved successfully, false otherwise

Definition at line 500 of file RegressionData.cpp.

bool GRT::RegressionData::scale ( const double  minTarget,
const double  maxTarget 
)

Scales the dataset to the new target range.

Parameters
constdouble minTarget: the minimum target the dataset will be scaled to
constdouble maxTarget: the maximum target the dataset will be scaled to
Returns
true if the data was scaled correctly, false otherwise

Definition at line 164 of file RegressionData.cpp.

bool GRT::RegressionData::scale ( const vector< MinMax > &  inputVectorRanges,
const vector< MinMax > &  targetVectorRanges,
const double  minTarget,
const double  maxTarget 
)

Scales the dataset to the new target range, using the vector of ranges as the min and max source ranges.

Returns
true if the data was scaled correctly, false otherwise

Definition at line 170 of file RegressionData.cpp.

bool GRT::RegressionData::setDatasetName ( const string &  datasetName)

Sets the name of the dataset. There should not be any spaces in the name. Will return true if the name is set, or false otherwise.

Parameters
conststring &datasetName: the new dataset name (must not include any spaces)
Returns
returns true if the name is set, or false otherwise

Definition at line 89 of file RegressionData.cpp.

bool GRT::RegressionData::setExternalRanges ( const vector< MinMax > &  externalInputRanges,
const vector< MinMax > &  externalTargetRanges,
const bool  useExternalRanges 
)

Sets the external input and target ranges of the dataset, also sets if the dataset should be scaled using these values. The dimensionality of the externalRanges vector should match the numInputDimensions and numTargetDimensions of this dataset.

Parameters
constvector< MinMax > &externalInputRanges: an N dimensional vector containing the min and max values of the expected input ranges of the dataset
constvector< MinMax > &externalTargetRanges: an N dimensional vector containing the min and max values of the expected target ranges of the dataset
constbool useExternalRanges: sets if these ranges should be used to scale the dataset, default value is false
Returns
returns true if the external ranges were set, false otherwise

Definition at line 144 of file RegressionData.cpp.

bool GRT::RegressionData::setInfoText ( const string &  infoText)

Sets the info string. This can be any string with information about how the training data was recorded for example.

Parameters
conststring &infoText: the infoText
Returns
true if the infoText was correctly updated, false otherwise

Definition at line 101 of file RegressionData.cpp.

bool GRT::RegressionData::setInputAndTargetDimensions ( const UINT  numInputDimensions,
const UINT  numTargetDimensions 
)

Sets the number of input and target dimensions in the training data. These should be unsigned integers greater than zero. This will clear any previous training data and counters. This function needs to be called before any new samples can be added to the dataset, unless the numInputDimensions and numTargetDimensions variables was set in the constructor or some data was already loaded from a file

Parameters
constUINT numInputDimensions: the number of input dimensions of the training data. Must be an unsigned integer greater than zero
constUINT numTargetDimensions: the number of target dimensions of the training data. Must be an unsigned integer greater than zero
Returns
true if the number of input and target dimensions was correctly updated, false otherwise

Definition at line 73 of file RegressionData.cpp.

bool GRT::RegressionData::spiltDataIntoKFolds ( const UINT  K)

This function prepares the dataset for k-fold cross validation and should be called prior to calling the getTrainingFold(UINT foldIndex) or getTestingFold(UINT foldIndex) functions. It will spilt the dataset into K-folds, as long as K < M, where M is the number of samples in the dataset.

Parameters
constUINT K: the number of folds the dataset will be split into, K should be less than the number of samples in the dataset
Returns
returns true if the dataset was split correctly, false otherwise

Definition at line 327 of file RegressionData.cpp.


The documentation for this class was generated from the following files: