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.
|
#include <FFT.h>
Public Types | |
enum | FFTWindowFunctionOptions { RECTANGULAR_WINDOW =0, BARTLETT_WINDOW, HAMMING_WINDOW, HANNING_WINDOW } |
Public Types inherited from FeatureExtraction | |
typedef std::map< std::string, FeatureExtraction *(*)() > | StringFeatureExtractionMap |
Public Types inherited from MLBase | |
enum | BaseTypes { BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER } |
Public Member Functions | |
FFT (UINT fftWindowSize=512, UINT hopSize=1, UINT numDimensions=1, UINT fftWindowFunction=RECTANGULAR_WINDOW, bool computeMagnitude=true, bool computePhase=true) | |
FFT (const FFT &rhs) | |
virtual | ~FFT (void) |
FFT & | operator= (const FFT &rhs) |
virtual bool | deepCopyFrom (const FeatureExtraction *featureExtraction) |
virtual bool | computeFeatures (const VectorFloat &inputVector) |
virtual bool | computeFeatures (const MatrixFloat &inputMatrix) |
virtual bool | clear () |
virtual bool | reset () |
virtual bool | saveModelToFile (std::fstream &file) const |
virtual bool | loadModelFromFile (std::fstream &file) |
bool | init (UINT fftWindowSize, UINT hopSize, UINT numDimensions, UINT windowFunction, bool computeMagnitude, bool computePhase, DataType inputType=DATA_TYPE_VECTOR, DataType outputType=DATA_TYPE_VECTOR) |
bool | update (const Float x) |
bool | update (const VectorFloat &x) |
bool | update (const MatrixFloat &x) |
UINT | getHopSize () |
UINT | getDataBufferSize () |
UINT | getFFTWindowSize () |
UINT | getFFTWindowFunction () |
UINT | getHopCounter () |
bool | getComputeMagnitude () |
bool | getComputePhase () |
Vector< FastFourierTransform > | getFFTResults () |
Vector< FastFourierTransform > & | getFFTResultsPtr () |
VectorFloat | getFrequencyBins (const unsigned int sampleRate) |
bool | setHopSize (UINT hopSize) |
bool | setFFTWindowSize (UINT fftWindowSize) |
bool | setFFTWindowFunction (UINT fftWindowFunction) |
bool | setComputeMagnitude (bool computeMagnitude) |
bool | setComputePhase (bool computePhase) |
Public Member Functions inherited from FeatureExtraction | |
FeatureExtraction () | |
virtual | ~FeatureExtraction () |
bool | copyBaseVariables (const FeatureExtraction *featureExtractionModule) |
std::string | getFeatureExtractionType () const |
UINT | getNumInputDimensions () const |
UINT | getNumOutputDimensions () const |
bool | getInitialized () const |
bool | getFeatureDataReady () const |
const VectorFloat & | getFeatureVector () const |
const MatrixFloat & | getFeatureMatrix () const |
FeatureExtraction * | createNewInstance () const |
Public Member Functions inherited from 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 (ClassificationDataStream trainingData) |
virtual bool | train_ (ClassificationDataStream &trainingData) |
virtual bool | train (UnlabelledData trainingData) |
virtual bool | train_ (UnlabelledData &trainingData) |
virtual bool | train (MatrixFloat data) |
virtual bool | train_ (MatrixFloat &data) |
virtual bool | predict (VectorFloat inputVector) |
virtual bool | predict_ (VectorFloat &inputVector) |
virtual bool | predict (MatrixFloat inputMatrix) |
virtual bool | predict_ (MatrixFloat &inputMatrix) |
virtual bool | map (VectorFloat inputVector) |
virtual bool | map_ (VectorFloat &inputVector) |
virtual bool | print () const |
virtual bool | save (const std::string filename) const |
virtual bool | load (const std::string filename) |
virtual bool | saveModelToFile (std::string filename) const |
virtual bool | loadModelFromFile (std::string filename) |
virtual bool | getModel (std::ostream &stream) const |
Float | scale (const Float &x, const Float &minSource, const Float &maxSource, const Float &minTarget, const Float &maxTarget, const bool constrain=false) |
virtual std::string | getModelAsString () const |
DataType | getInputType () const |
DataType | getOutputType () 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 |
Float | getMinChange () const |
Float | getLearningRate () const |
Float | getRootMeanSquaredTrainingError () const |
Float | getTotalSquaredTrainingError () const |
Float | getValidationSetAccuracy () const |
VectorFloat | getValidationSetPrecision () const |
VectorFloat | getValidationSetRecall () 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 (const bool useScaling) |
bool | setMaxNumEpochs (const UINT maxNumEpochs) |
bool | setMinNumEpochs (const UINT minNumEpochs) |
bool | setMinChange (const Float minChange) |
bool | setLearningRate (const Float learningRate) |
bool | setUseValidationSet (const bool useValidationSet) |
bool | setValidationSetSize (const UINT validationSetSize) |
bool | setRandomiseTrainingOrder (const bool randomiseTrainingOrder) |
bool | setTrainingLoggingEnabled (const bool loggingEnabled) |
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 |
Public Member Functions inherited from GRTBase | |
GRTBase (void) | |
virtual | ~GRTBase (void) |
bool | copyGRTBaseVariables (const GRTBase *GRTBase) |
std::string | getClassType () const |
std::string | getLastWarningMessage () const |
std::string | getLastErrorMessage () const |
std::string | getLastInfoMessage () const |
bool | setInfoLoggingEnabled (const bool loggingEnabled) |
bool | setWarningLoggingEnabled (const bool loggingEnabled) |
bool | setErrorLoggingEnabled (const bool loggingEnabled) |
GRTBase * | getGRTBasePointer () |
const GRTBase * | getGRTBasePointer () const |
Public Member Functions inherited from Observer< TrainingResult > | |
virtual void | notify (const TrainingResult &data) |
Public Member Functions inherited from Observer< TestInstanceResult > | |
virtual void | notify (const TestInstanceResult &data) |
Protected Member Functions | |
bool | isPowerOfTwo (UINT x) |
A helper function to compute if the input is a power of two. | |
bool | validateFFTWindowFunction (UINT fftWindowFunction) |
Protected Member Functions inherited from FeatureExtraction | |
bool | init () |
bool | saveFeatureExtractionSettingsToFile (std::fstream &file) const |
bool | loadFeatureExtractionSettingsFromFile (std::fstream &file) |
Protected Member Functions inherited from MLBase | |
bool | saveBaseSettingsToFile (std::fstream &file) const |
bool | loadBaseSettingsFromFile (std::fstream &file) |
Protected Member Functions inherited from GRTBase | |
Float | SQR (const Float &x) const |
Protected Attributes | |
UINT | hopSize |
The current hopSize, this sets how often the fft should be computed. | |
UINT | dataBufferSize |
Stores how much previous input data is stored in the dataBuffer. | |
UINT | fftWindowSize |
Stores the size of the fft (and also the dataBuffer) | |
UINT | fftWindowFunction |
The current windowFunction used for the FFT. | |
UINT | hopCounter |
Keeps track of how many input samples the FFT has seen. | |
bool | computeMagnitude |
Tracks if the magnitude (and power) of the FFT need to be computed. | |
bool | computePhase |
Tracks if the phase of the FFT needs to be computed. | |
VectorFloat | tempBuffer |
A temporary buffer used to store the input data for the FFT. | |
CircularBuffer< VectorFloat > | dataBuffer |
A circular buffer used to store the previous M inputs. | |
Vector< FastFourierTransform > | fft |
A buffer used to store the FFT results. | |
std::map< unsigned int, unsigned int > | windowSizeMap |
A map to relate the FFTWindowSize enumerations to actual values. | |
Protected Attributes inherited from FeatureExtraction | |
std::string | featureExtractionType |
bool | initialized |
bool | featureDataReady |
VectorFloat | featureVector |
MatrixFloat | featureMatrix |
Protected Attributes inherited from MLBase | |
bool | trained |
bool | useScaling |
DataType | inputType |
DataType | outputType |
UINT | baseType |
UINT | numInputDimensions |
UINT | numOutputDimensions |
UINT | numTrainingIterationsToConverge |
UINT | minNumEpochs |
UINT | maxNumEpochs |
UINT | validationSetSize |
Float | learningRate |
Float | minChange |
Float | rootMeanSquaredTrainingError |
Float | totalSquaredTrainingError |
Float | validationSetAccuracy |
bool | useValidationSet |
bool | randomiseTrainingOrder |
VectorFloat | validationSetPrecision |
VectorFloat | validationSetRecall |
Random | random |
std::vector< TrainingResult > | trainingResults |
TrainingResultsObserverManager | trainingResultsObserverManager |
TestResultsObserverManager | testResultsObserverManager |
Protected Attributes inherited from GRTBase | |
std::string | classType |
DebugLog | debugLog |
ErrorLog | errorLog |
InfoLog | infoLog |
TrainingLog | trainingLog |
TestingLog | testingLog |
WarningLog | warningLog |
Static Protected Attributes | |
static RegisterFeatureExtractionModule< FFT > | registerModule |
Additional Inherited Members | |
Static Public Member Functions inherited from FeatureExtraction | |
static FeatureExtraction * | createInstanceFromString (const std::string &featureExtractionType) |
Static Public Member Functions inherited from GRTBase | |
static std::string | getGRTVersion (bool returnRevision=true) |
static std::string | getGRTRevison () |
Static Protected Member Functions inherited from FeatureExtraction | |
static StringFeatureExtractionMap * | getMap () |
GRT MIT License Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FFT::FFT | ( | UINT | fftWindowSize = 512 , |
UINT | hopSize = 1 , |
||
UINT | numDimensions = 1 , |
||
UINT | fftWindowFunction = RECTANGULAR_WINDOW , |
||
bool | computeMagnitude = true , |
||
bool | computePhase = true |
||
) |
Constructor, sets the fftWindowSize, hopSize, fftWindowFunction, if the magnitude and phase should be computed during the FFT and the number of dimensions in the input signal.
fftWindowSize | sets the size of the fft, this should be a power of two. Default fftWindowSize=512 |
hopSize | sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize. Default hopSize=1 |
numDimensions | the dimensionality of the input data to the FFT. Default numDimensions = 1 |
fftWindowFunction | sets the window function of the FFT. This should be one of the FFTWindowFunctionOptions enumeration values. Default windowFunction=RECTANGULAR_WINDOW |
computeMagnitude | sets if the magnitude (and power) of the spectrum should be computed on the results of the FFT. Default computeMagnitude=true |
computePhase | sets if the phase of the spectrum should be computed on the results of the FFT. Default computePhase=true |
FFT::FFT | ( | const FFT & | rhs | ) |
|
virtual |
Sets the FeatureExtraction clear function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when the pipelines main clear() function is called. This function completely clears the FFT setup, you will need to initialize the instance again before you can use it.
Reimplemented from FeatureExtraction.
|
virtual |
Sets the FeatureExtraction computeFeatures function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when any new input data needs to be processed (during the prediction phase for example). This function calls the FFT's computeFFT(...) function.
inputVector | the inputVector that should be processed. Must have the same dimensionality as the FeatureExtraction module |
Reimplemented from FeatureExtraction.
|
virtual |
Sets the FeatureExtraction computeFeatures function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when any new input data needs to be processed (during the prediction phase for example). This function calls the FFT's computeFFT(...) function.
inputMatrix | the inputMatrix that should be processed. Must have the same dimensionality as the FeatureExtraction module |
Reimplemented from FeatureExtraction.
|
virtual |
Sets the FeatureExtraction deepCopyFrom function, overwriting the base FeatureExtraction function. This function is used to deep copy the values from the input pointer to this instance of the FeatureExtraction module. This function is called by the GestureRecognitionPipeline when the user adds a new FeatureExtraction module to the pipeline.
featureExtraction | a pointer to another instance of an FFT, the values of that instance will be cloned to this instance |
Reimplemented from FeatureExtraction.
|
inline |
|
inline |
UINT FFT::getDataBufferSize | ( | ) |
|
inline |
Returns the FFT results computed from the last FFT of the input signal.
|
inline |
Returns a pointer to the FFT results computed from the last FFT of the input signal.
UINT FFT::getFFTWindowFunction | ( | ) |
UINT FFT::getFFTWindowSize | ( | ) |
UINT FFT::getHopCounter | ( | ) |
UINT FFT::getHopSize | ( | ) |
bool FFT::init | ( | UINT | fftWindowSize, |
UINT | hopSize, | ||
UINT | numDimensions, | ||
UINT | windowFunction, | ||
bool | computeMagnitude, | ||
bool | computePhase, | ||
DataType | inputType = DATA_TYPE_VECTOR , |
||
DataType | outputType = DATA_TYPE_VECTOR |
||
) |
Initializes the FFT. Should be called before calling the computeFFT(...) or computeFeatures(...) methods. This function is automatically called by the constructor.
fftWindowSize | sets the size of the fft, this must be a power of two |
hopSize | sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize |
numDimensions | the dimensionality of the input data to the FFT |
windowFunction | sets the window function of the FFT. This should be one of the WindowFunctionOptions enumeration values |
computeMagnitude | sets if the magnitude (and power) of the spectrum should be computed on the results of the FFT |
computePhase | sets if the phase of the spectrum should be computed on the results of the FFT |
inputType | the input type expected, defaults to DATA_TYPE_VECTOR |
outputType | the output type that can be accessed by users of the module, defaults to DATA_TYPE_VECTOR |
|
virtual |
This loads the feature extraction settings from a file. This overrides the loadSettingsFromFile function in the FeatureExtraction base class.
file | a reference to the file to load the settings from |
Reimplemented from FeatureExtraction.
|
virtual |
Sets the FeatureExtraction reset function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when the pipelines main reset() function is called. This function resets the FFT by re-initiliazing the instance.
Reimplemented from FeatureExtraction.
|
virtual |
This saves the feature extraction settings to a file. This overrides the saveSettingsToFile function in the FeatureExtraction base class.
file | a reference to the file to save the settings to |
Reimplemented from FeatureExtraction.
bool FFT::setComputeMagnitude | ( | bool | computeMagnitude | ) |
bool FFT::setComputePhase | ( | bool | computePhase | ) |
bool FFT::setFFTWindowFunction | ( | UINT | fftWindowFunction | ) |
Sets the fftWindowFunction parameter, this should be one of the FFTWindowFunctionOptions enumeration values.
fftWindowFunction | the new fftWindowFunction parameter, must be one of the FFTWindowFunctionOptions enumeration values |
bool FFT::setFFTWindowSize | ( | UINT | fftWindowSize | ) |
Sets the fftWindowSize parameter, this sets the size of the fft, this must be a power of two. Setting this value will also re-initialize the FFT.
fftWindowSize | the new fftWindowSize parameter, this must be a power of two. |
bool FFT::setHopSize | ( | UINT | hopSize | ) |
Sets the hopSize parameter, this sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes' computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize. The hopSize must be greater than zero. Setting the hopSize will also reset the hop counter.
hopSize | the new hopSize parameter, must be greater than zero |
bool FFT::update | ( | const Float | x | ) |
Computes the FFT of the previous M input samples, where M is the size of the fft window set by the constructor. The FFT of the input will only be computed if the current hop counter value matches the hopSize. This function should only be used if the dimensionality of the FFT has been set to 1.
x | the new sample, this will be added to a buffer and the FFT will be computed for the data in the buffer |
bool FFT::update | ( | const VectorFloat & | x | ) |
Computes the FFT of the previous M input samples, where M is the size of the fft window set by the constructor. The FFT of the input will only be computed if the current hop counter value matches the hopSize. The dimensionality of the input vector must match the number of dimensions for the FFT.
x | the new N-dimensional sample, this will be added to a buffer and the FFT will be computed for the data in the buffer |
bool FFT::update | ( | const MatrixFloat & | x | ) |
Computes the FFT of the previous M input samples, where M is the size of the fft window set by the constructor. The FFT of the input will only be computed if the current hop counter value matches the hopSize. The number of columns in the input matrix must match the number of dimensions for the FFT.
x | a [M N] matrix, this will be added to a buffer and the FFT will be computed for the data in the buffer |