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::TimeSeriesClassificationDataStream Class Reference

Public Member Functions

 TimeSeriesClassificationDataStream (const UINT numDimensions=0, const string datasetName="NOT_SET", const string infoText="")
 
 TimeSeriesClassificationDataStream (const TimeSeriesClassificationDataStream &rhs)
 
virtual ~TimeSeriesClassificationDataStream ()
 
TimeSeriesClassificationDataStreamoperator= (const TimeSeriesClassificationDataStream &rhs)
 
ClassificationSampleoperator[] (const UINT i)
 
void clear ()
 
bool setNumDimensions (const UINT numDimensions)
 
bool setDatasetName (const string datasetName)
 
bool setInfoText (const string infoText)
 
bool setClassNameForCorrespondingClassLabel (const string className, const UINT classLabel)
 
bool addSample (const UINT classLabel, const VectorDouble &trainingSample)
 
bool removeLastSample ()
 
UINT eraseAllSamplesWithClassLabel (const UINT classLabel)
 
bool relabelAllSamplesWithClassLabel (const UINT oldClassLabel, const UINT newClassLabel)
 
bool setExternalRanges (const vector< MinMax > &externalRanges, const bool useExternalRanges=false)
 
bool enableExternalRangeScaling (const bool useExternalRanges)
 
bool scale (const double minTarget, const double maxTarget)
 
bool scale (const vector< MinMax > &ranges, const double minTarget, const double maxTarget)
 
bool resetPlaybackIndex (const UINT playbackIndex)
 
ClassificationSample getNextSample ()
 
TimeSeriesClassificationData getAllTrainingExamplesWithClassLabel (const UINT classLabel) const
 
bool save (const string &filename)
 
bool load (const string &filename)
 
bool saveDatasetToFile (const string &filename)
 
bool saveDatasetToCSVFile (const string &filename)
 
bool loadDatasetFromFile (const string &filename)
 
bool loadDatasetFromCSVFile (const string &filename, const UINT classLabelColumnIndex=0)
 
bool printStats () const
 
string getDatasetName () const
 
string getInfoText () const
 
UINT getNumDimensions () const
 
UINT getNumSamples () const
 
UINT getNumClasses () const
 
UINT getMinimumClassLabel () const
 
UINT getMaximumClassLabel () const
 
UINT getClassLabelIndexValue (const UINT classLabel) const
 
string getClassNameForCorrespondingClassLabel (const UINT classLabel)
 
vector< MinMaxgetRanges () const
 
vector< ClassTrackergetClassTracker () const
 
vector< TimeSeriesPositionTrackergetTimeSeriesPositionTracker () const
 
vector< ClassificationSamplegetClassificationSamples () const
 
TimeSeriesClassificationDataStream getSubset (const UINT startIndex, const UINT endIndex) const
 
TimeSeriesClassificationData getTimeSeriesClassificationData (const bool includeNullGestures=false) const
 
ClassificationData getClassificationData (const bool includeNullGestures=false) const
 
MatrixDouble getTimeSeriesData (const TimeSeriesPositionTracker &trackerInfo) const
 
MatrixDouble getDataAsMatrixDouble () const
 
vector< UINT > getClassLabels () const
 

Protected Attributes

string datasetName
 The name of the dataset.
 
string infoText
 Some infoText about the dataset.
 
UINT numDimensions
 The number of dimensions in the dataset.
 
UINT totalNumSamples
 
UINT lastClassID
 
UINT playbackIndex
 
bool trackingClass
 
bool useExternalRanges
 A flag to show if the dataset should be scaled using the externalRanges values.
 
vector< MinMaxexternalRanges
 A vector containing a set of externalRanges set by the user.
 
vector< ClassTrackerclassTracker
 
vector< ClassificationSampledata
 
vector< TimeSeriesPositionTrackertimeSeriesPositionTracker
 
DebugLog debugLog
 Default debugging log.
 
ErrorLog errorLog
 Default error log.
 
WarningLog warningLog
 Default warning log.
 

Detailed Description

Definition at line 41 of file TimeSeriesClassificationDataStream.h.

Constructor & Destructor Documentation

GRT::TimeSeriesClassificationDataStream::TimeSeriesClassificationDataStream ( const UINT  numDimensions = 0,
const string  datasetName = "NOT_SET",
const string  infoText = "" 
)

Constructor, sets the name of the dataset and the number of dimensions of the training data. The name of the dataset should not contain any spaces.

Parameters
UINTnumDimensions: the number of dimensions of the training data, should be an unsigned integer greater than 0
stringdatasetName: the name of the dataset, should not contain any spaces
stringinfoText: some info about the data in this dataset, this can contain spaces

Definition at line 26 of file TimeSeriesClassificationDataStream.cpp.

GRT::TimeSeriesClassificationDataStream::TimeSeriesClassificationDataStream ( const TimeSeriesClassificationDataStream rhs)

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

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

Definition at line 44 of file TimeSeriesClassificationDataStream.cpp.

GRT::TimeSeriesClassificationDataStream::~TimeSeriesClassificationDataStream ( )
virtual

Default Destructor

Definition at line 48 of file TimeSeriesClassificationDataStream.cpp.

Member Function Documentation

bool GRT::TimeSeriesClassificationDataStream::addSample ( const UINT  classLabel,
const VectorDouble &  trainingSample 
)

Adds a new labelled sample to the dataset. The dimensionality of the sample should match the number of dimensions in the TimeSeriesClassificationDataStream. The class label can be zero (this should represent a null class).

Parameters
constUINT classLabel: the class label of the corresponding sample
constVectorDouble &sample: the new sample you want to add to the dataset. The dimensionality of this sample should match the number of dimensions in the TimeSeriesClassificationDataStream
Returns
true if the sample was correctly added to the dataset, false otherwise

Definition at line 127 of file TimeSeriesClassificationDataStream.cpp.

void GRT::TimeSeriesClassificationDataStream::clear ( )

Clears any previous training data and counters

Definition at line 72 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::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
booluseExternalRanges: 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 312 of file TimeSeriesClassificationDataStream.cpp.

UINT GRT::TimeSeriesClassificationDataStream::eraseAllSamplesWithClassLabel ( const UINT  classLabel)

Deletes from the dataset all the samples with a specific class label.

Parameters
constUINT classLabel: the class label of the samples you wish to delete from the dataset
Returns
the number of samples deleted from the dataset

Definition at line 201 of file TimeSeriesClassificationDataStream.cpp.

TimeSeriesClassificationData GRT::TimeSeriesClassificationDataStream::getAllTrainingExamplesWithClassLabel ( const UINT  classLabel) const

Gets all the timeseries that have a specific class label.

Parameters
constUINT classLabel: the class label of the timeseries you want to find
Returns
a TimeSeriesClassificationData dataset containing any timeseries that have the matching classlabel

Definition at line 352 of file TimeSeriesClassificationDataStream.cpp.

ClassificationData GRT::TimeSeriesClassificationDataStream::getClassificationData ( const bool  includeNullGestures = false) const

This function segments the continuous time series data into individual samples and then adds these samples into a new ClassificationData dataset. This new dataset is then returned. By default, the new dataset will not contain any samples with the class label of GRT_DEFAULT_NULL_CLASS_LABEL (as this is assumed to be a NULL gesture) unless you set the includeNullGestures parameter to true.

Returns
returns a new ClassificationData built from the samples in this dataset.

Definition at line 828 of file TimeSeriesClassificationDataStream.cpp.

vector< ClassificationSample > GRT::TimeSeriesClassificationDataStream::getClassificationSamples ( ) const
inline

Gets the classification data as a vector of ClassificationSample.

Returns
a vector of ClassificationSamples

Definition at line 380 of file TimeSeriesClassificationDataStream.h.

UINT GRT::TimeSeriesClassificationDataStream::getClassLabelIndexValue ( const UINT  classLabel) const

Gets the index of the class label from the class tracker.

Returns
an unsigned int representing the index of the class label in the class tracker

Definition at line 391 of file TimeSeriesClassificationDataStream.cpp.

vector< UINT > GRT::TimeSeriesClassificationDataStream::getClassLabels ( ) const

Gets the class labels in the current dataset.

Returns
a vector containing the class labels from the current dataset.

Definition at line 882 of file TimeSeriesClassificationDataStream.cpp.

string GRT::TimeSeriesClassificationDataStream::getClassNameForCorrespondingClassLabel ( const UINT  classLabel)

Gets the name of the class with a given class label. If the class label does not exist then the string "CLASS_LABEL_NOT_FOUND" will be returned.

Returns
a string containing the name of the given class label or the string "CLASS_LABEL_NOT_FOUND" if the class label does not exist

Definition at line 401 of file TimeSeriesClassificationDataStream.cpp.

vector< ClassTracker > GRT::TimeSeriesClassificationDataStream::getClassTracker ( ) const
inline

Gets the class tracker for each class in the dataset.

Returns
a vector of ClassTracker, one for each class in the dataset

Definition at line 366 of file TimeSeriesClassificationDataStream.h.

MatrixDouble GRT::TimeSeriesClassificationDataStream::getDataAsMatrixDouble ( ) const

Gets all the data as a MatrixDouble. This returns just the data, not the labels. This will be an M by N MatrixDouble, where M is the number of samples and N is the number of dimensions.

Returns
a MatrixDouble containing the data from the current dataset.

Definition at line 870 of file TimeSeriesClassificationDataStream.cpp.

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

Gets the name of the dataset.

Returns
returns the name of the dataset

Definition at line 296 of file TimeSeriesClassificationDataStream.h.

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

Gets the infotext for the dataset

Returns
returns the infotext of the dataset

Definition at line 303 of file TimeSeriesClassificationDataStream.h.

UINT GRT::TimeSeriesClassificationDataStream::getMaximumClassLabel ( ) const

Gets the maximum class label in the dataset. If there are no values in the dataset then the value 0 will be returned.

Returns
an unsigned int representing the maximum class label in the dataset

Definition at line 379 of file TimeSeriesClassificationDataStream.cpp.

UINT GRT::TimeSeriesClassificationDataStream::getMinimumClassLabel ( ) const

Gets the minimum class label in the dataset. If there are no values in the dataset then the value 99999 will be returned.

Returns
an unsigned int representing the minimum class label in the dataset

Definition at line 366 of file TimeSeriesClassificationDataStream.cpp.

ClassificationSample GRT::TimeSeriesClassificationDataStream::getNextSample ( )

Gets the next sample, this will also increment the playback index. If the playback index reaches the last data sample then it will be reset to 0.

Returns
the ClassificationSample at the current playback index

Definition at line 345 of file TimeSeriesClassificationDataStream.cpp.

UINT GRT::TimeSeriesClassificationDataStream::getNumClasses ( ) const
inline

Gets the number of classes.

Returns
an unsigned int representing the number of classes

Definition at line 324 of file TimeSeriesClassificationDataStream.h.

UINT GRT::TimeSeriesClassificationDataStream::getNumDimensions ( ) const
inline

Gets the number of dimensions of the labelled classification data.

Returns
an unsigned int representing the number of dimensions in the classification data

Definition at line 310 of file TimeSeriesClassificationDataStream.h.

UINT GRT::TimeSeriesClassificationDataStream::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 317 of file TimeSeriesClassificationDataStream.h.

vector< MinMax > GRT::TimeSeriesClassificationDataStream::getRanges ( ) const

Gets the ranges of the classification data.

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

Definition at line 411 of file TimeSeriesClassificationDataStream.cpp.

TimeSeriesClassificationDataStream GRT::TimeSeriesClassificationDataStream::getSubset ( const UINT  startIndex,
const UINT  endIndex 
) const

Gets a new TimeSeriesClassificationDataStream dataset drawn from the startIndex and endIndex values. The startIndex and endIndex values must be valid (i.e. if the current dataset has 1000 samples then you can not have a startIndex or endIndex value that is greater or equal to 1000).

Parameters
UINTstartIndex: the index of the first value from the current dataset that you want to start the new subset from
UINTendIndex: the index of the last value from the current dataset that you want to end the new dataset at (inclusive)
Returns
returns a new TimeSeriesClassificationDataStream subset of the current dataset drawn from the startIndex and endIndex values

Definition at line 782 of file TimeSeriesClassificationDataStream.cpp.

TimeSeriesClassificationData GRT::TimeSeriesClassificationDataStream::getTimeSeriesClassificationData ( const bool  includeNullGestures = false) const

This function segments the continuous time series data into individual time series and then adds these time series into a new TimeSeriesClassificationData dataset. This new dataset is then returned. By default, the new dataset will not contain any time series with the class label of GRT_DEFAULT_NULL_CLASS_LABEL (as this is assumed to be a NULL gesture) unless you set the includeNullGestures parameter to true.

Returns
returns a new TimeSeriesClassificationData built from the time series data in this dataset.

Definition at line 809 of file TimeSeriesClassificationDataStream.cpp.

MatrixDouble GRT::TimeSeriesClassificationDataStream::getTimeSeriesData ( const TimeSeriesPositionTracker trackerInfo) const

This function segments a specific time series from the main data set and returns this as a MatrixDouble. You should use one of the TimeSeriesPositionTracker elements from the timeSeriesPositionTracker vector to indicate to the function which time series you want to retrieve. You can get the TimeSeriesPositionTracker elements using the getTimeSeriesPositionTracker() function.

The MatrixDouble will be empty if the trackerInfo indexs (the startIndex and the endIndex) are not valid.

Returns
returns a new LabelledClassificationData built from the samples in this dataset.

Definition at line 849 of file TimeSeriesClassificationDataStream.cpp.

vector< TimeSeriesPositionTracker > GRT::TimeSeriesClassificationDataStream::getTimeSeriesPositionTracker ( ) const
inline

Gets the timeseries position tracker, a vector of TimeSeriesPositionTracker which indicate the start and end position of each time series in the dataset.

Returns
a vector of TimeSeriesPositionTracker, one for each timeseries in the dataset

Definition at line 373 of file TimeSeriesClassificationDataStream.h.

bool GRT::TimeSeriesClassificationDataStream::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 443 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::loadDatasetFromCSVFile ( const string &  filename,
const UINT  classLabelColumnIndex = 0 
)

Loads the labelled timeseries classification data from a CSV file. This assumes the data is formatted with each row representing a sample. The class label should be the first column followed by the sample data as the following N columns, where N is the number of dimensions in the data. If the class label is not the first column, you should set the 2nd argument (UINT classLabelColumnIndex) to the column index that contains the class label.

Parameters
conststring filename: the name of the file the data will be loaded from
constUINT classLabelColumnIndex: the index of the column containing the class label. Default value = 0
Returns
true if the data was loaded successfully, false otherwise

Definition at line 694 of file TimeSeriesClassificationDataStream.cpp.

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

Loads the data from a custom file format.

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

Definition at line 508 of file TimeSeriesClassificationDataStream.cpp.

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

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

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

Definition at line 50 of file TimeSeriesClassificationDataStream.cpp.

ClassificationSample& GRT::TimeSeriesClassificationDataStream::operator[] ( const UINT  i)
inline

Array Subscript Operator, returns the ClassificationSample 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 ClassificationSample

Definition at line 81 of file TimeSeriesClassificationDataStream.h.

bool GRT::TimeSeriesClassificationDataStream::printStats ( ) const

Prints the dataset info (such as its name and infoText) and the stats (such as the number of examples, number of dimensions, number of classes, etc.) to the std out.

Returns
returns true if the dataset info and stats were printed successfully, false otherwise

Definition at line 749 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::relabelAllSamplesWithClassLabel ( const UINT  oldClassLabel,
const UINT  newClassLabel 
)

Relabels all the samples with the class label A with the new class label B.

Parameters
constUINT oldClassLabel: the class label of the samples you want to relabel
constUINT newClassLabel: the class label the samples will be relabelled with
Returns
returns true if the samples were correctly relablled, false otherwise

Definition at line 250 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::removeLastSample ( )

Removes the last training sample added to the dataset.

Returns
true if the last sample was removed, false otherwise

Definition at line 169 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::resetPlaybackIndex ( const UINT  playbackIndex)

Sets the playback index to a specific index. The index should be within the range [0 totalNumSamples-1].

Parameters
constUINT playbackIndex: the value you want to set the playback index to
Returns
true if the playback index was set correctly, false otherwise

Definition at line 337 of file TimeSeriesClassificationDataStream.cpp.

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

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 432 of file TimeSeriesClassificationDataStream.cpp.

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

Saves the data to a CSV file. This will save the timeseries counter as the first column, the class label as the second column, and the sample data as the following N columns, where N is the number of dimensions in the data. 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 671 of file TimeSeriesClassificationDataStream.cpp.

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

Saves the labelled timeseries classification data to a custom file format.

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

Definition at line 454 of file TimeSeriesClassificationDataStream.cpp.

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

Scales the dataset to the new target range. This function uses the minimum and maximum values of the current dataset as the source range.

Parameters
constdouble minTarget: the minimum value of the target range
constdouble maxTarget: the maximum value of the target range
Returns
true if the data was scaled correctly, false otherwise

Definition at line 320 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::scale ( const vector< MinMax > &  ranges,
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.

Parameters
constvector<MinMax> &ranges: the minimum and maximum values for the source range
constdouble minTarget: the minimum value of the target range
constdouble maxTarget: the maximum value of the target range
Returns
true if the data was scaled correctly, false otherwise

Definition at line 325 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::setClassNameForCorrespondingClassLabel ( const string  className,
const UINT  classLabel 
)

Sets the name of the class with the given class label. There should not be any spaces in the className. Will return true if the name is set, or false if the class label does not exist.

Returns
returns true if the name is set, or false if the class label does not exist

Definition at line 114 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::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.

Returns
returns true if the name is set, or false otherwise

Definition at line 97 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::setExternalRanges ( const vector< MinMax > &  externalRanges,
const bool  useExternalRanges = false 
)

Sets the external ranges of the dataset, also sets if the dataset should be scaled using these values. The dimensionality of the externalRanges vector should match the number of dimensions of this dataset.

Parameters
constvector< MinMax > &externalRanges: an N dimensional vector containing the min and max values of the expected 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 302 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::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 109 of file TimeSeriesClassificationDataStream.cpp.

bool GRT::TimeSeriesClassificationDataStream::setNumDimensions ( const UINT  numDimensions)

Sets the number of dimensions in the training data. This should be an unsigned integer 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 numDimensions variable was set in the constructor or some data was already loaded from a file

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

Definition at line 81 of file TimeSeriesClassificationDataStream.cpp.


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