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::Classifier Class Reference
Inheritance diagram for GRT::Classifier:
GRT::MLBase GRT::GRTBase GRT::Observer< TrainingResult > GRT::Observer< TestInstanceResult > GRT::AdaBoost GRT::ANBC GRT::BAG GRT::DecisionTree GRT::DTW GRT::FiniteStateMachine GRT::GMM GRT::HMM GRT::KNN GRT::LDA GRT::MinDist GRT::ParticleClassifier GRT::RandomForests GRT::RegisterClassifierModule< T > GRT::Softmax GRT::SVM GRT::SwipeDetector GRT::RegisterClassifierModule< GRT::AdaBoost > GRT::RegisterClassifierModule< GRT::ANBC > GRT::RegisterClassifierModule< GRT::BAG > GRT::RegisterClassifierModule< GRT::DecisionTree > GRT::RegisterClassifierModule< GRT::DTW > GRT::RegisterClassifierModule< GRT::FiniteStateMachine > GRT::RegisterClassifierModule< GRT::GMM > GRT::RegisterClassifierModule< GRT::HMM > GRT::RegisterClassifierModule< GRT::KNN > GRT::RegisterClassifierModule< GRT::MinDist > GRT::RegisterClassifierModule< GRT::ParticleClassifier > GRT::RegisterClassifierModule< GRT::RandomForests > GRT::RegisterClassifierModule< GRT::Softmax > GRT::RegisterClassifierModule< GRT::SVM > GRT::RegisterClassifierModule< GRT::SwipeDetector >

Public Types

typedef std::map< string, Classifier *(*)() > StringClassifierMap
 
- Public Types inherited from GRT::MLBase
enum  BaseTypes { BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER }
 

Public Member Functions

 Classifier (void)
 
virtual ~Classifier (void)
 
virtual bool deepCopyFrom (const Classifier *classifier)
 
bool copyBaseVariables (const Classifier *classifier)
 
virtual bool reset ()
 
virtual bool clear ()
 
string getClassifierType () const
 
bool getSupportsNullRejection () const
 
bool getNullRejectionEnabled () const
 
double getNullRejectionCoeff () const
 
double getMaximumLikelihood () const
 
double getBestDistance () const
 
double getPhase () const
 
virtual UINT getNumClasses () const
 
UINT getClassLabelIndexValue (UINT classLabel) const
 
UINT getPredictedClassLabel () const
 
VectorDouble getClassLikelihoods () const
 
VectorDouble getClassDistances () const
 
VectorDouble getNullRejectionThresholds () const
 
vector< UINT > getClassLabels () const
 
vector< MinMaxgetRanges () const
 
bool enableNullRejection (bool useNullRejection)
 
virtual bool setNullRejectionCoeff (double nullRejectionCoeff)
 
virtual bool setNullRejectionThresholds (VectorDouble newRejectionThresholds)
 
virtual bool recomputeNullRejectionThresholds ()
 
bool getTimeseriesCompatible () const
 
ClassifiercreateNewInstance () const
 
ClassifierdeepCopy () const
 
const ClassifiergetClassifierPointer () const
 
const ClassifiergetBaseClassifier () const
 
- Public Member Functions inherited from GRT::MLBase
 MLBase (void)
 
virtual ~MLBase (void)
 
bool copyMLBaseVariables (const MLBase *mlBase)
 
virtual bool train (ClassificationData trainingData)
 
virtual bool train_ (ClassificationData &trainingData)
 
virtual bool train (RegressionData trainingData)
 
virtual bool train_ (RegressionData &trainingData)
 
virtual bool train (TimeSeriesClassificationData trainingData)
 
virtual bool train_ (TimeSeriesClassificationData &trainingData)
 
virtual bool train (TimeSeriesClassificationDataStream trainingData)
 
virtual bool train_ (TimeSeriesClassificationDataStream &trainingData)
 
virtual bool train (UnlabelledData trainingData)
 
virtual bool train_ (UnlabelledData &trainingData)
 
virtual bool train (MatrixDouble data)
 
virtual bool train_ (MatrixDouble &data)
 
virtual bool predict (VectorDouble inputVector)
 
virtual bool predict_ (VectorDouble &inputVector)
 
virtual bool predict (MatrixDouble inputMatrix)
 
virtual bool predict_ (MatrixDouble &inputMatrix)
 
virtual bool map (VectorDouble inputVector)
 
virtual bool map_ (VectorDouble &inputVector)
 
virtual bool print () const
 
virtual bool save (const string filename) const
 
virtual bool load (const string filename)
 
virtual bool saveModelToFile (string filename) const
 
virtual bool saveModelToFile (fstream &file) const
 
virtual bool loadModelFromFile (string filename)
 
virtual bool loadModelFromFile (fstream &file)
 
virtual bool getModel (ostream &stream) const
 
double scale (const double &x, const double &minSource, const double &maxSource, const double &minTarget, const double &maxTarget, const bool constrain=false)
 
virtual string getModelAsString () const
 
UINT getBaseType () const
 
UINT getNumInputFeatures () const
 
UINT getNumInputDimensions () const
 
UINT getNumOutputDimensions () const
 
UINT getMinNumEpochs () const
 
UINT getMaxNumEpochs () const
 
UINT getValidationSetSize () const
 
UINT getNumTrainingIterationsToConverge () const
 
double getMinChange () const
 
double getLearningRate () const
 
double getRootMeanSquaredTrainingError () const
 
double getTotalSquaredTrainingError () const
 
bool getUseValidationSet () const
 
bool getRandomiseTrainingOrder () const
 
bool getTrained () const
 
bool getModelTrained () const
 
bool getScalingEnabled () const
 
bool getIsBaseTypeClassifier () const
 
bool getIsBaseTypeRegressifier () const
 
bool getIsBaseTypeClusterer () const
 
bool enableScaling (bool useScaling)
 
bool setMaxNumEpochs (const UINT maxNumEpochs)
 
bool setMinNumEpochs (const UINT minNumEpochs)
 
bool setMinChange (const double minChange)
 
bool setLearningRate (double learningRate)
 
bool setUseValidationSet (const bool useValidationSet)
 
bool setValidationSetSize (const UINT validationSetSize)
 
bool setRandomiseTrainingOrder (const bool randomiseTrainingOrder)
 
bool registerTrainingResultsObserver (Observer< TrainingResult > &observer)
 
bool registerTestResultsObserver (Observer< TestInstanceResult > &observer)
 
bool removeTrainingResultsObserver (const Observer< TrainingResult > &observer)
 
bool removeTestResultsObserver (const Observer< TestInstanceResult > &observer)
 
bool removeAllTrainingObservers ()
 
bool removeAllTestObservers ()
 
bool notifyTrainingResultsObservers (const TrainingResult &data)
 
bool notifyTestResultsObservers (const TestInstanceResult &data)
 
MLBasegetMLBasePointer ()
 
const MLBasegetMLBasePointer () const
 
vector< TrainingResultgetTrainingResults () const
 
- Public Member Functions inherited from GRT::GRTBase
 GRTBase (void)
 
virtual ~GRTBase (void)
 
bool copyGRTBaseVariables (const GRTBase *GRTBase)
 
string getClassType () const
 
string getLastWarningMessage () const
 
string getLastErrorMessage () const
 
string getLastInfoMessage () const
 
GRTBasegetGRTBasePointer ()
 
const GRTBasegetGRTBasePointer () const
 
- Public Member Functions inherited from GRT::Observer< TrainingResult >
virtual void notify (const TrainingResult &data)
 
- Public Member Functions inherited from GRT::Observer< TestInstanceResult >
virtual void notify (const TestInstanceResult &data)
 

Static Public Member Functions

static ClassifiercreateInstanceFromString (string const &classifierType)
 
static vector< string > getRegisteredClassifiers ()
 
- Static Public Member Functions inherited from GRT::GRTBase
static string getGRTVersion (bool returnRevision=true)
 
static string getGRTRevison ()
 

Protected Types

enum  ClassifierModes { STANDARD_CLASSIFIER_MODE =0, TIMESERIES_CLASSIFIER_MODE }
 

Protected Member Functions

bool saveBaseSettingsToFile (fstream &file) const
 
bool loadBaseSettingsFromFile (fstream &file)
 
- Protected Member Functions inherited from GRT::MLBase
bool saveBaseSettingsToFile (fstream &file) const
 
bool loadBaseSettingsFromFile (fstream &file)
 
- Protected Member Functions inherited from GRT::GRTBase
double SQR (const double &x) const
 

Static Protected Member Functions

static StringClassifierMapgetMap ()
 

Protected Attributes

string classifierType
 
bool supportsNullRejection
 
bool useNullRejection
 
UINT numClasses
 
UINT predictedClassLabel
 
UINT classifierMode
 
double nullRejectionCoeff
 
double maxLikelihood
 
double bestDistance
 
double phase
 
VectorDouble classLikelihoods
 
VectorDouble classDistances
 
VectorDouble nullRejectionThresholds
 
vector< UINT > classLabels
 
vector< MinMaxranges
 
- Protected Attributes inherited from GRT::MLBase
bool trained
 
bool useScaling
 
UINT baseType
 
UINT numInputDimensions
 
UINT numOutputDimensions
 
UINT numTrainingIterationsToConverge
 
UINT minNumEpochs
 
UINT maxNumEpochs
 
UINT validationSetSize
 
double learningRate
 
double minChange
 
double rootMeanSquaredTrainingError
 
double totalSquaredTrainingError
 
bool useValidationSet
 
bool randomiseTrainingOrder
 
Random random
 
vector< TrainingResulttrainingResults
 
TrainingResultsObserverManager trainingResultsObserverManager
 
TestResultsObserverManager testResultsObserverManager
 
- Protected Attributes inherited from GRT::GRTBase
string classType
 
DebugLog debugLog
 
ErrorLog errorLog
 
InfoLog infoLog
 
TrainingLog trainingLog
 
TestingLog testingLog
 
WarningLog warningLog
 

Detailed Description

Definition at line 41 of file Classifier.h.

Member Typedef Documentation

typedef std::map< string, Classifier*(*)() > GRT::Classifier::StringClassifierMap

Defines a map between a string (which will contain the name of the classifier, such as ANBC) and a function returns a new instance of that classifier

Definition at line 248 of file Classifier.h.

Constructor & Destructor Documentation

GRT::Classifier::Classifier ( void  )

Default Classifier Constructor

Definition at line 67 of file Classifier.cpp.

GRT::Classifier::~Classifier ( void  )
virtual

Default Classifier Destructor

Definition at line 84 of file Classifier.cpp.

Member Function Documentation

bool GRT::Classifier::clear ( )
virtual

This function clears the classifier module, removing any trained model and setting all the base variables to their default values.

Returns
returns true if the derived class was cleared succesfully, false otherwise

Reimplemented from GRT::MLBase.

Reimplemented in GRT::DTW, GRT::HMM, GRT::FiniteStateMachine, GRT::AdaBoost, GRT::ANBC, GRT::SVM, GRT::KNN, GRT::DecisionTree, GRT::BAG, GRT::GMM, GRT::RandomForests, GRT::ParticleClassifier, GRT::MinDist, GRT::Softmax, and GRT::SwipeDetector.

Definition at line 140 of file Classifier.cpp.

bool GRT::Classifier::copyBaseVariables ( const Classifier classifier)

This copies the Classifier base class variables from the classifier pointer to this instance.

Parameters
constClassifier *classifier: a pointer to a classifier from which the values will be copied to this instance
Returns
returns true if the copy was successfull, false otherwise

Definition at line 91 of file Classifier.cpp.

Classifier * GRT::Classifier::createInstanceFromString ( string const &  classifierType)
static

Creates a new classifier instance based on the input string (which should contain the name of a valid classifier such as ANBC).

Parameters
stringconst &classifierType: the name of the classifier
Returns
Classifier*: a pointer to the new instance of the classifier

Definition at line 27 of file Classifier.cpp.

Classifier * GRT::Classifier::createNewInstance ( ) const

Creates a new classifier instance based on the current classifierType string value.

Returns
Classifier*: a pointer to the new instance of the classifier

Definition at line 35 of file Classifier.cpp.

Classifier * GRT::Classifier::deepCopy ( ) const

This creates a new Classifier instance and deep copies the variables and models from this instance into the deep copy. The function will then return a pointer to the new instance. It is up to the user who calls this function to delete the dynamic instance when they are finished using it.

Returns
returns a pointer to a new Classifier instance which is a deep copy of this instance

Definition at line 39 of file Classifier.cpp.

virtual bool GRT::Classifier::deepCopyFrom ( const Classifier classifier)
inlinevirtual

This is the base deep copy function for the Classifier modules. This function should be overwritten by the derived class. This deep copies the variables and models from the classifier pointer to this classifier instance.

Parameters
constClassifier *classifier: a pointer to the Classifier base class, this should be pointing to another instance of a matching derived class
Returns
returns true if the clone was successfull, false otherwise (the Classifier base class will always return flase)

Reimplemented in GRT::DTW, GRT::AdaBoost, GRT::SVM, GRT::LDA, GRT::KNN, GRT::DecisionTree, GRT::ANBC, GRT::HMM, GRT::RandomForests, GRT::GMM, GRT::BAG, GRT::MinDist, GRT::Softmax, GRT::SwipeDetector, GRT::FiniteStateMachine, and GRT::ParticleClassifier.

Definition at line 61 of file Classifier.h.

bool GRT::Classifier::enableNullRejection ( bool  useNullRejection)

Sets if the classifier should use nullRejection.

If set to true then the classifier will reject a predicted class label if the likelihood of the prediction is below (or above depending on the algorithm) the models rejectionThreshold. If a prediction is rejected then the default null class label of 0 will be returned. If set to false then the classifier will simply return the most likely predicted class.

Returns
returns true if nullRejection was updated successfully, false otherwise

Definition at line 229 of file Classifier.cpp.

const Classifier & GRT::Classifier::getBaseClassifier ( ) const

Returns a pointer to this classifier. This is useful for a derived class so it can get easy access to this base classifier.

Returns
Classifier&: a reference to this classifier

Definition at line 250 of file Classifier.cpp.

double GRT::Classifier::getBestDistance ( ) const

Returns the current bestDistance value. The bestDistance value is computed during the prediction phase and is either the minimum or maximum distance, depending on the algorithm. This value will return 0 if a prediction has not been made.

Returns
returns the current bestDistance value

Definition at line 184 of file Classifier.cpp.

VectorDouble GRT::Classifier::getClassDistances ( ) const

Gets a vector of the class distances from the last prediction, this will be an N-dimensional vector, where N is the number of classes in the model. The exact form of these distances depends on the classification algorithm.

Returns
returns a vector of the class distances from the last prediction, an empty vector will be returned if the model has not been trained

Definition at line 211 of file Classifier.cpp.

const Classifier * GRT::Classifier::getClassifierPointer ( ) const

Returns a pointer to the classifier.

Returns
returns a pointer the current classifier

Definition at line 52 of file Classifier.cpp.

string GRT::Classifier::getClassifierType ( ) const

Returns the classifier type as a string.

Returns
returns the classifier type as a string

Definition at line 159 of file Classifier.cpp.

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

Gets the index of the query classLabel in the classLabels vector. If the query classLabel does not exist in the classLabels vector then the function will return zero.

Parameters
UINTclassLabel: the query classLabel
Returns
returns index of the query classLabel in the classLabels vector

Definition at line 193 of file Classifier.cpp.

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

Gets a vector containing the label each class represents, this will be an N-dimensional vector, where N is the number of classes in the model. This is useful if the model was trained with non-monotonically class labels (i.e. class labels such as [1, 3, 6, 9, 12] instead of [1, 2, 3, 4, 5]).

Returns
returns a vector containing the class labels for each class, an empty vector will be returned if the model has not been trained

Definition at line 221 of file Classifier.cpp.

VectorDouble GRT::Classifier::getClassLikelihoods ( ) const

Gets a vector of the class likelihoods from the last prediction, this will be an N-dimensional vector, where N is the number of classes in the model. The exact form of these likelihoods depends on the classification algorithm.

Returns
returns a vector of the class likelihoods from the last prediction, an empty vector will be returned if the model has not been trained

Definition at line 206 of file Classifier.cpp.

double GRT::Classifier::getMaximumLikelihood ( ) const

Returns the current maximumLikelihood value. The maximumLikelihood value is computed during the prediction phase and is the likelihood of the most likely model. This value will return 0 if a prediction has not been made.

Returns
returns the current maximumLikelihood value

Definition at line 175 of file Classifier.cpp.

double GRT::Classifier::getNullRejectionCoeff ( ) const

Returns the current nullRejectionCoeff value. The nullRejectionCoeff parameter is a multipler controlling the null rejection threshold for each class.

Returns
returns the current nullRejectionCoeff value

Definition at line 171 of file Classifier.cpp.

bool GRT::Classifier::getNullRejectionEnabled ( ) const

Returns true if nullRejection is enabled.

Returns
returns true if nullRejection is enabled, false otherwise

Definition at line 167 of file Classifier.cpp.

VectorDouble GRT::Classifier::getNullRejectionThresholds ( ) const

Gets a vector containing the null rejection thresholds for each class, this will be an N-dimensional vector, where N is the number of classes in the model.

Returns
returns a vector containing the null rejection thresholds for each class, an empty vector will be returned if the model has not been trained

Definition at line 216 of file Classifier.cpp.

UINT GRT::Classifier::getNumClasses ( ) const
virtual

Gets the number of classes in trained model.

Returns
returns the number of classes in the trained model, a value of 0 will be returned if the model has not been trained

Reimplemented in GRT::SVM.

Definition at line 189 of file Classifier.cpp.

double GRT::Classifier::getPhase ( ) const

This function returns the estimated gesture phase from the most recent prediction. This value is only relevant if the classifier supports timeseries classification.

Returns
double representing the gesture phase value from the most likely class from the most recent prediction

Definition at line 180 of file Classifier.cpp.

UINT GRT::Classifier::getPredictedClassLabel ( ) const

Gets the predicted class label from the last prediction.

Returns
returns the label of the last predicted class, a value of 0 will be returned if the model has not been trained

Definition at line 201 of file Classifier.cpp.

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

Gets a vector of the ranges used to scale the data for training and prediction, these ranges are only used if the classifier has been trained with the #useScaling flag set to true. This should be an N-dimensional vector, where N is the number of features in your data.

Returns
returns a vector containing the ranges used to scale the data for classification, an empty vector will be returned if the model has not been trained

Definition at line 225 of file Classifier.cpp.

vector< string > GRT::Classifier::getRegisteredClassifiers ( )
static

Returns a vector of the names of all classifiers that have been registered with the base classifier.

Returns
vector< string >: a vector containing the names of the classifiers that have been registered with the base classifier

Definition at line 56 of file Classifier.cpp.

bool GRT::Classifier::getSupportsNullRejection ( ) const

Returns true if the classifier instance supports null rejection, false otherwise.

Returns
returns true if the classifier instance supports null rejection, false otherwise

Definition at line 163 of file Classifier.cpp.

bool GRT::Classifier::getTimeseriesCompatible ( ) const
inline

Indicates if the classifier can be used to classify timeseries data. If true then the classifier can accept training data in the LabelledTimeSeriesClassificationData format.

return returns true if the classifier can be used to classify timeseries data, false otherwise

Definition at line 243 of file Classifier.h.

bool GRT::Classifier::loadBaseSettingsFromFile ( fstream &  file)
protected

Loads the core base settings from a file.

Returns
returns true if the base settings were loaded, false otherwise

Definition at line 301 of file Classifier.cpp.

virtual bool GRT::Classifier::recomputeNullRejectionThresholds ( )
inlinevirtual

Recomputes the null rejection thresholds for each model.

Returns
returns true if the nullRejectionThresholds were updated successfully, false otherwise

Reimplemented in GRT::DTW, GRT::AdaBoost, GRT::ANBC, GRT::KNN, GRT::GMM, GRT::MinDist, and GRT::DecisionTree.

Definition at line 235 of file Classifier.h.

bool GRT::Classifier::reset ( )
virtual

This resets the classifier. This overrides the reset function in the MLBase base class.

Returns
returns true if the classifier was reset, false otherwise

Reimplemented from GRT::MLBase.

Reimplemented in GRT::DTW, GRT::HMM, GRT::FiniteStateMachine, GRT::ParticleClassifier, GRT::ANBC, GRT::SwipeDetector, and GRT::BAG.

Definition at line 121 of file Classifier.cpp.

bool GRT::Classifier::saveBaseSettingsToFile ( fstream &  file) const
protected

Saves the core base settings to a file.

Returns
returns true if the base settings were saved, false otherwise

Definition at line 254 of file Classifier.cpp.

bool GRT::Classifier::setNullRejectionCoeff ( double  nullRejectionCoeff)
virtual

Sets the nullRejectionCoeff, this is a multipler controlling the null rejection threshold for each class.

Returns
returns true if nullRejectionCoeff was updated successfully, false otherwise

Reimplemented in GRT::KNN, GRT::ANBC, GRT::AdaBoost, and GRT::MinDist.

Definition at line 234 of file Classifier.cpp.

bool GRT::Classifier::setNullRejectionThresholds ( VectorDouble  newRejectionThresholds)
virtual

Manually sets the nullRejectionThresholds, these are the thresholds used for null rejection for each class. This needs to be called after the model has been trained. Calling the setNullRejectionCoeff or recomputeNullRejectionThresholds functions will override these values. The size of the newRejectionThresholds vector must match the number of classes in the model.

Parameters
VectorDoublenewRejectionThresholds: the new rejection thresholds
Returns
returns true if nullRejectionThresholds were updated successfully, false otherwise

Definition at line 242 of file Classifier.cpp.


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