![]() |
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.
|
Public Types | |
enum | TrainingModes { ONLINE_GRADIENT_DESCENT } |
![]() | |
typedef std::map< string, Regressifier *(*)() > | StringRegressifierMap |
![]() | |
enum | BaseTypes { BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER } |
Public Member Functions | |
MLP () | |
MLP (const MLP &rhs) | |
virtual | ~MLP () |
MLP & | operator= (const MLP &rhs) |
virtual bool | deepCopyFrom (const Regressifier *regressifier) |
virtual bool | train_ (ClassificationData &trainingData) |
virtual bool | train_ (RegressionData &trainingData) |
virtual bool | predict_ (VectorDouble &inputVector) |
virtual bool | clear () |
virtual bool | print () const |
virtual bool | saveModelToFile (fstream &file) const |
virtual bool | loadModelFromFile (fstream &file) |
UINT | getNumClasses () const |
bool | init (const UINT numInputNeurons, const UINT numHiddenNeurons, const UINT numOutputNeurons) |
bool | init (const UINT numInputNeurons, const UINT numHiddenNeurons, const UINT numOutputNeurons, const UINT inputLayerActivationFunction, const UINT hiddenLayerActivationFunction, const UINT outputLayerActivationFunction) |
void | printNetwork () const |
bool | checkForNAN () const |
string | activationFunctionToString (const UINT activationFunction) const |
UINT | activationFunctionFromString (const string activationName) const |
bool | validateActivationFunction (const UINT avactivationFunction) const |
UINT | getNumInputNeurons () const |
UINT | getNumHiddenNeurons () const |
UINT | getNumOutputNeurons () const |
UINT | getInputLayerActivationFunction () const |
UINT | getHiddenLayerActivationFunction () const |
UINT | getOutputLayerActivationFunction () const |
UINT | getNumRandomTrainingIterations () const |
double | getTrainingRate () const |
double | getMomentum () const |
double | getGamma () const |
double | getTrainingError () const |
bool | getClassificationModeActive () const |
bool | getRegressionModeActive () const |
vector< Neuron > | getInputLayer () const |
vector< Neuron > | getHiddenLayer () const |
vector< Neuron > | getOutputLayer () const |
vector< VectorDouble > | getTrainingLog () const |
bool | getNullRejectionEnabled () const |
double | getNullRejectionCoeff () const |
double | getNullRejectionThreshold () const |
double | getMaximumLikelihood () const |
VectorDouble | getClassLikelihoods () const |
VectorDouble | getClassDistances () const |
UINT | getPredictedClassLabel () const |
bool | setInputLayerActivationFunction (const UINT activationFunction) |
bool | setHiddenLayerActivationFunction (const UINT activationFunction) |
bool | setOutputLayerActivationFunction (const UINT activationFunction) |
bool | setTrainingRate (const double trainingRate) |
bool | setMomentum (const double momentum) |
bool | setGamma (const double gamma) |
bool | setNumRandomTrainingIterations (const UINT numRandomTrainingIterations) |
bool | setNullRejection (const bool useNullRejection) |
bool | setNullRejectionCoeff (const double nullRejectionCoeff) |
![]() | |
Regressifier (void) | |
virtual | ~Regressifier (void) |
bool | copyBaseVariables (const Regressifier *regressifier) |
virtual bool | reset () |
string | getRegressifierType () const |
VectorDouble | getRegressionData () const |
vector< MinMax > | getInputRanges () const |
vector< MinMax > | getOutputRanges () const |
Regressifier * | createNewInstance () const |
Regressifier * | deepCopy () const |
const Regressifier & | getBaseRegressifier () const |
![]() | |
MLBase (void) | |
virtual | ~MLBase (void) |
bool | copyMLBaseVariables (const MLBase *mlBase) |
virtual bool | train (ClassificationData 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 (MatrixDouble inputMatrix) |
virtual bool | predict_ (MatrixDouble &inputMatrix) |
virtual bool | map (VectorDouble inputVector) |
virtual bool | map_ (VectorDouble &inputVector) |
virtual bool | save (const string filename) const |
virtual bool | load (const string filename) |
virtual bool | saveModelToFile (string filename) const |
virtual bool | loadModelFromFile (string filename) |
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) |
MLBase * | getMLBasePointer () |
const MLBase * | getMLBasePointer () const |
vector< TrainingResult > | getTrainingResults () const |
![]() | |
GRTBase (void) | |
virtual | ~GRTBase (void) |
bool | copyGRTBaseVariables (const GRTBase *GRTBase) |
string | getClassType () const |
string | getLastWarningMessage () const |
string | getLastErrorMessage () const |
string | getLastInfoMessage () const |
GRTBase * | getGRTBasePointer () |
const GRTBase * | getGRTBasePointer () const |
![]() | |
virtual void | notify (const TrainingResult &data) |
![]() | |
virtual void | notify (const TestInstanceResult &data) |
Protected Member Functions | |
bool | isNAN (const double v) const |
bool | trainModel (RegressionData &trainingData) |
bool | trainOnlineGradientDescentClassification (const RegressionData &trainingData, const RegressionData &validationData) |
bool | trainOnlineGradientDescentRegression (const RegressionData &trainingData, const RegressionData &validationData) |
bool | loadLegacyModelFromFile (fstream &file) |
double | back_prop (const VectorDouble &trainingExample, const VectorDouble &targetVector, const double alpha, const double beta) |
VectorDouble | feedforward (VectorDouble trainingExample) |
void | feedforward (const VectorDouble &trainingExample, VectorDouble &inputNeuronsOuput, VectorDouble &hiddenNeuronsOutput, VectorDouble &outputNeuronsOutput) |
![]() | |
bool | saveBaseSettingsToFile (fstream &file) const |
bool | loadBaseSettingsFromFile (fstream &file) |
![]() | |
bool | saveBaseSettingsToFile (fstream &file) const |
bool | loadBaseSettingsFromFile (fstream &file) |
![]() | |
double | SQR (const double &x) const |
Protected Attributes | |
UINT | numInputNeurons |
UINT | numHiddenNeurons |
UINT | numOutputNeurons |
UINT | inputLayerActivationFunction |
UINT | hiddenLayerActivationFunction |
UINT | outputLayerActivationFunction |
UINT | numRandomTrainingIterations |
UINT | trainingMode |
double | momentum |
double | gamma |
double | trainingError |
bool | initialized |
Random | random |
vector< Neuron > | inputLayer |
vector< Neuron > | hiddenLayer |
vector< Neuron > | outputLayer |
vector< VectorDouble > | trainingErrorLog |
bool | classificationModeActive |
bool | useNullRejection |
UINT | predictedClassLabel |
double | nullRejectionThreshold |
double | nullRejectionCoeff |
double | maxLikelihood |
VectorDouble | classLikelihoods |
VectorDouble | inputNeuronsOuput |
VectorDouble | hiddenNeuronsOutput |
VectorDouble | outputNeuronsOutput |
VectorDouble | deltaO |
VectorDouble | deltaH |
![]() | |
string | regressifierType |
VectorDouble | regressionData |
vector< MinMax > | inputVectorRanges |
vector< MinMax > | targetVectorRanges |
![]() | |
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< TrainingResult > | trainingResults |
TrainingResultsObserverManager | trainingResultsObserverManager |
TestResultsObserverManager | testResultsObserverManager |
![]() | |
string | classType |
DebugLog | debugLog |
ErrorLog | errorLog |
InfoLog | infoLog |
TrainingLog | trainingLog |
TestingLog | testingLog |
WarningLog | warningLog |
Static Protected Attributes | |
static RegisterRegressifierModule< MLP > | registerModule |
Additional Inherited Members | |
![]() | |
static Regressifier * | createInstanceFromString (string const ®ressifierType) |
static vector< string > | getRegisteredRegressifiers () |
![]() | |
static string | getGRTVersion (bool returnRevision=true) |
static string | getGRTRevison () |
![]() | |
static StringRegressifierMap * | getMap () |
UINT GRT::MLP::activationFunctionFromString | ( | const string | activationName | ) | const |
string GRT::MLP::activationFunctionToString | ( | const UINT | activationFunction | ) | const |
Gets a string representation of the activation function
UINT | activationFunction: the activation function you want to convert to a string |
|
protected |
Performs one round of back propagation, using the training example and target vector
const | VectorDouble &trainingExample: the input vector to use for back propagation |
const | VectorDouble &targetVector: the target vector to use for back propagation |
const | double alpha: the training rate |
const | double beta: the momentum |
bool GRT::MLP::checkForNAN | ( | ) | const |
|
virtual |
Clears any previous model or settings.
Reimplemented from GRT::Regressifier.
|
virtual |
This is required for the Gesture Recognition Pipeline for when the pipeline.setRegressifier(...) method is called. It clones the data from the Base Class Regressifier pointer (which should be pointing to an MLP instance) into this instance
Regressifier | *regressifier: a pointer to the Regressifier Base Class, this should be pointing to another MLP instance |
Reimplemented from GRT::Regressifier.
|
protected |
|
protected |
Performs the feedforward step for back propagation, using the input data
const | VectorDouble &trainingExample: the input vector to use for the feedforward |
VectorDouble | &inputNeuronsOuput: the results of the input layer |
VectorDouble | &hiddenNeuronsOutput: the results of the hidden layer |
VectorDouble | &outputNeuronsOutput: the results of the output layer |
VectorDouble GRT::MLP::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.
bool GRT::MLP::getClassificationModeActive | ( | ) | const |
VectorDouble GRT::MLP::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.
double GRT::MLP::getGamma | ( | ) | const |
vector< Neuron > GRT::MLP::getHiddenLayer | ( | ) | const |
UINT GRT::MLP::getHiddenLayerActivationFunction | ( | ) | const |
vector< Neuron > GRT::MLP::getInputLayer | ( | ) | const |
UINT GRT::MLP::getInputLayerActivationFunction | ( | ) | const |
double GRT::MLP::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 is only relevant if the MLP is in classification mode. This value will return 0 if a prediction has not been made.
double GRT::MLP::getMomentum | ( | ) | const |
double GRT::MLP::getNullRejectionCoeff | ( | ) | const |
Returns the current null rejection coefficient value. The null rejection coefficient is a multipler controlling the null rejection threshold for each class. This is only relevant if the MLP is in classification mode.
bool GRT::MLP::getNullRejectionEnabled | ( | ) | const |
double GRT::MLP::getNullRejectionThreshold | ( | ) | const |
Returns the current null rejection threshold value. The null rejection threshold is value controlling if a classification result should be rejected or accepted. This is only relevant if the MLP is in classification mode.
UINT GRT::MLP::getNumClasses | ( | ) | const |
UINT GRT::MLP::getNumHiddenNeurons | ( | ) | const |
UINT GRT::MLP::getNumInputNeurons | ( | ) | const |
UINT GRT::MLP::getNumOutputNeurons | ( | ) | const |
UINT GRT::MLP::getNumRandomTrainingIterations | ( | ) | const |
Gets the number of random training iterations that should be performed during the training phase. The MLP back propagation algorithm starts with random values, and the accuracy of a trained model can depend on which random values the algorithm started with. The GRT MLP algorithm therefore trains a number of models and picks the best one. This value therefore represents the number of random training iterations that should be used.
vector< Neuron > GRT::MLP::getOutputLayer | ( | ) | const |
UINT GRT::MLP::getOutputLayerActivationFunction | ( | ) | const |
UINT GRT::MLP::getPredictedClassLabel | ( | ) | const |
bool GRT::MLP::getRegressionModeActive | ( | ) | const |
double GRT::MLP::getTrainingError | ( | ) | const |
vector< vector< double > > GRT::MLP::getTrainingLog | ( | ) | const |
Returns a vector of VectorDouble representing the training log for each random round of training. The outer vector represents each round and the inner vector represents each epoch in that round.
double GRT::MLP::getTrainingRate | ( | ) | const |
bool GRT::MLP::init | ( | const UINT | numInputNeurons, |
const UINT | numHiddenNeurons, | ||
const UINT | numOutputNeurons | ||
) |
Initializes the MLP for training. This should be called before the MLP is trained. The number of input neurons should match the number of input dimensions in your training data. The number of output neurons should match the number of target dimensions in your training data. The number of hidden units should be chosen by the user, a common rule of thumb is to set this as a value somewhere between the number of input neurons and the number of output neurons. Initializaling the MLP will clear any previous model or settings.
This function calls the other init function below, passing in the layer activation functions.
const | UINT numInputNeurons: the number of input neurons (should match the number of input dimensions in your training data) |
const | UINT numHiddenNeurons: the number of hidden neurons |
const | UINT numOutputNeurons: the number of output neurons (should match the number of target dimensions in your training data) |
bool GRT::MLP::init | ( | const UINT | numInputNeurons, |
const UINT | numHiddenNeurons, | ||
const UINT | numOutputNeurons, | ||
const UINT | inputLayerActivationFunction, | ||
const UINT | hiddenLayerActivationFunction, | ||
const UINT | outputLayerActivationFunction | ||
) |
Initializes the MLP for training. This should be called before the MLP is trained. The number of input neurons should match the number of input dimensions in your training data. The number of output neurons should match the number of target dimensions in your training data. The number of hidden units should be chosen by the user, a common rule of thumb is to set this as a value somewhere between the number of input neurons and the number of output neurons. The activation functions should be one of the Neuron ActivationFunctions enums. Initializaling the MLP will clear any previous model or settings.
const | UINT numInputNeurons: the number of input neurons (should match the number of input dimensions in your training data) |
const | UINT numHiddenNeurons: the number of hidden neurons |
const | UINT numOutputNeurons: the number of output neurons (should match the number of target dimensions in your training data) |
const | UINT inputLayerActivationFunction: the activation function to use for the input layer |
const | UINT hiddenLayerActivationFunction: the activation function to use for the input layer |
const | UINT outputLayerActivationFunction: the activation function to use for the input layer |
|
virtual |
This loads a trained MLP model from a file. This overrides the loadModelFromFile function in the ML base class.
fstream | &file: a reference to the file the MLP model will be loaded from |
Reimplemented from GRT::MLBase.
|
virtual |
This function either predicts the class of the input vector (if the MLP is in Classification Mode), or it performs regression using the MLP model.
VectorDouble | &inputVector: the input vector to classify or perform regression on |
Reimplemented from GRT::MLBase.
|
virtual |
This function will print the model and settings to the display log.
Reimplemented from GRT::MLBase.
void GRT::MLP::printNetwork | ( | ) | const |
|
virtual |
This saves the trained MLP model to a file. This overrides the saveModelToFile function in the ML base class.
fstream | &file: a reference to the file the MLP model will be saved to |
Reimplemented from GRT::MLBase.
bool GRT::MLP::setGamma | ( | const double | gamma | ) |
Sets the gamma parameter for the Neurons. Gamma must be greater than zero. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
const | double gamma: the gamma value for each Neuron, gamma must be greater than zero |
bool GRT::MLP::setHiddenLayerActivationFunction | ( | const UINT | activationFunction | ) |
This function sets the activation function for all the Neurons in the hidden layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
const | UINT activationFunction: the activation function for the hidden layer, this should be one of the Neuron ActivationFunctions enums |
bool GRT::MLP::setInputLayerActivationFunction | ( | const UINT | activationFunction | ) |
This function sets the activation function for all the Neurons in the input layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
const | UINT activationFunction: the activation function for the input layer, this should be one of the Neuron ActivationFunctions enums |
bool GRT::MLP::setMomentum | ( | const double | momentum | ) |
Sets the momentum parameter. This is used to update the weights at each step of the stochastic gradient descent. The momentum parameter is normally set between [0.1 0.9], with 0.5 being a common value.
const | double momentum: the momentum value used during the training phase, must be greater than zero |
bool GRT::MLP::setNullRejection | ( | const bool | useNullRejection | ) |
Sets if null rejection should be used for the real-time prediction. This is only used if the MLP is in classificationMode.
const | bool useNullRejection: if true then null rejection will be used |
bool GRT::MLP::setNullRejectionCoeff | ( | const double | nullRejectionCoeff | ) |
This function lets you manually control the null rejection threshold. Any class with a prediction value less than the null rejection threshold will be rejected, setting the predicted class label to 0.
This is only used if the MLP is in classificationMode.
const | double nullRejectionCoeff: the new null rejection threshold |
bool GRT::MLP::setNumRandomTrainingIterations | ( | const UINT | numRandomTrainingIterations | ) |
Sets number of times the MLP model should be trained to find the best model. This value must be greater than zero.
Setting this value to a high number (i.e. 100) will most likely give you a better model, however it will take much longer to train the overall model. Setting this value to a low number (i.e. 5) will make the training process much faster, but you might not get the best model.
const | UINT numRandomTrainingIterations: the number of times you want to randomly train the MLP model to search for the best results |
bool GRT::MLP::setOutputLayerActivationFunction | ( | const UINT | activationFunction | ) |
This function sets the activation function for all the Neurons in the output layer. If the MLP instance has been initialized then this function will also call the init function to reinitialize the instance.
const | UINT activationFunction: the activation function for the output layer, this should be one of the Neuron ActivationFunctions enums |
bool GRT::MLP::setTrainingRate | ( | const double | trainingRate | ) |
Sets the training rate, which controls the learning rate parameter. This is used to update the weights at each step of the stochastic gradient descent. The learningRate value must be greater than zero, a value of 0.1 normally works well. If you find the MLP fails to train with this value then try setting the learning rate to a smaller value (for example 0.01).
const | double trainingRate: the learningRate value used during the training phase, must be greater than zero |
|
virtual |
This trains the MLP model, using the labelled classification data. Calling this function sets the MLP into Classification Model.
ClassificationData | &trainingData: the training data that will be used to train the classification model |
Reimplemented from GRT::MLBase.
|
virtual |
This trains the MLP model, using the labelled regression data. Calling this function sets the MLP into Regression Model.
RegressionData | trainingData: the training data that will be used to train the regression model |
Reimplemented from GRT::MLBase.
bool GRT::MLP::validateActivationFunction | ( | const UINT | avactivationFunction | ) | const |