ESP  0.1
The Example-based Sensor Predictions (ESP) system tries to bring machine learning to the maker community.
GRT::Filter Class Referenceabstract

#include <Filter.h>

Inheritance diagram for GRT::Filter:
LogEnergy

Public Member Functions

 Filter (const char *classType, UINT filterSize=5, UINT numDimensions=1)
 
 Filter (const Filter &rhs)
 
virtual ~Filter ()
 
Filteroperator= (const Filter &rhs)
 
virtual bool deepCopyFrom (const PreProcessing *preProcessing)
 
virtual bool process (const VectorDouble &inputVector)
 
virtual bool reset ()
 
virtual bool saveModelToFile (string filename) const
 
virtual bool saveModelToFile (fstream &file) const
 
virtual bool loadModelFromFile (string filename)
 
virtual bool loadModelFromFile (fstream &file)
 
bool init (UINT filterSize, UINT numDimensions)
 
double filter (const double x)
 
VectorDouble filter (const VectorDouble &x)
 
virtual double computeFilter (const VectorDouble &buf)=0
 
UINT getFilterSize () const
 
VectorDouble getFilteredData () const
 
vector< VectorDouble > getDataBuffer () const
 

Protected Attributes

UINT filterSize
 The size of the filter. More...
 
UINT inputSampleCounter
 A counter to keep track of the number of input samples. More...
 
CircularBuffer< VectorDouble > dataBuffer
 A buffer to store the previous N values, N = filterSize. More...
 

Constructor & Destructor Documentation

GRT::Filter::Filter ( const char *  classType,
UINT  filterSize = 5,
UINT  numDimensions = 1 
)

Constructor, sets the size of the median filter and the dimensionality of the data it will filter.

Parameters
char*classType: the name of the sub-class being instantiated.
UINTfilterSize: the size of the median filter, should be a value greater than zero. Default filterSize = 5
UINTnumDimensions: the dimensionality of the data to filter. Default numDimensions = 1
GRT::Filter::Filter ( const Filter rhs)

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

Parameters
constFilter &rhs: another instance of the Filter class from which the data will be copied to this instance
GRT::Filter::~Filter ( )
virtual

Default Destructor

Member Function Documentation

virtual double GRT::Filter::computeFilter ( const VectorDouble &  buf)
pure virtual

Compute the filter. This is implemented by the derived class and called separately on each dimension of the input data.

Parameters
constVectorDouble buf: the values to filter, i.e. the last filterSize (or fewer) values read within a particular dimension
Returns
the filtered value

Implemented in LogEnergy.

bool GRT::Filter::deepCopyFrom ( const PreProcessing *  preProcessing)
virtual

Sets the PreProcessing deepCopyFrom function, overwriting the base PreProcessing function. This function is used to deep copy the values from the input pointer to this instance of the PreProcessing module. This function is called by the GestureRecognitionPipeline when the user adds a new PreProcessing module to the pipeline.

Parameters
constPreProcessing *preProcessing: a pointer to another instance of a Filter, the values of that instance will be cloned to this instance
Returns
true if the deep copy was successful, false otherwise
double GRT::Filter::filter ( const double  x)

Filters the input, this should only be called if the dimensionality of the filter was set to 1.

Parameters
doublex: the value to filter, this should only be called if the dimensionality of the filter was set to 1
Returns
the filtered value. Zero will be returned if the value was not filtered
VectorDouble GRT::Filter::filter ( const VectorDouble &  x)

Filters the input, the dimensionality of the input vector should match that of the filter.

Parameters
constVectorDouble &x: the values to filter, the dimensionality of the input vector should match that of the filter
Returns
the filtered values. An empty vector will be returned if the values were not filtered
vector< VectorDouble > GRT::Filter::getDataBuffer ( ) const

Returns the current data in the dataBuffer. This will be a [N M] vector of VectorDoubles, where N is the number of dimensions in the filter and M is the size of the buffer. If the filter has not been initialized then an empty vector will be returned.

Returns
the current data in the dataBuffer
VectorDouble GRT::Filter::getFilteredData ( ) const
inline

Returns the last value(s) that were filtered.

Returns
the filtered values. An empty vector will be returned if the values were not filtered
UINT GRT::Filter::getFilterSize ( ) const
inline

Gets the current filter size.

Returns
returns the filter size
bool GRT::Filter::init ( UINT  filterSize,
UINT  numDimensions 
)

Initializes the filter, setting the filter size and dimensionality of the data it will filter. Sets all the filter values to zero.

Parameters
UINTfilterSize: the size of the moving average filter, should be a value greater than zero
Returns
true if the filter was initiliazed, false otherwise
bool GRT::Filter::loadModelFromFile ( string  filename)
virtual

This loads the Filter settings from a file. This overrides the loadModelFromFile function in the PreProcessing base class.

Parameters
stringfilename: the name of the file to load the settings from
Returns
returns true if the settings were loaded successfully, false otherwise
bool GRT::Filter::loadModelFromFile ( fstream &  file)
virtual

This loads the Filter settings from a file. This overrides the loadModelFromFile function in the PreProcessing base class.

Parameters
fstream&file: a reference to the file to load the settings from
Returns
returns true if the model was loaded successfully, false otherwise
Filter & GRT::Filter::operator= ( const Filter rhs)

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

Parameters
constFilter &rhs: another instance of the Filter class from which the data will be copied to this instance
Returns
a reference to this instance of Filter
bool GRT::Filter::process ( const VectorDouble &  inputVector)
virtual

Sets the PreProcessing process function, overwriting the base PreProcessing 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 Filter's filter function.

Parameters
constVectorDouble &inputVector: the inputVector that should be processed. Must have the same dimensionality as the PreProcessing module
Returns
true if the data was processed, false otherwise
bool GRT::Filter::reset ( )
virtual

Sets the PreProcessing reset function, overwriting the base PreProcessing function. This function is called by the GestureRecognitionPipeline when the pipelines main reset() function is called. This function resets the filter values by re-initiliazing the filter.

Returns
true if the filter was reset, false otherwise
bool GRT::Filter::saveModelToFile ( string  filename) const
virtual

This saves the current settings of the Filter to a file. This overrides the saveModelToFile function in the PreProcessing base class.

Parameters
stringfilename: the name of the file to save the settings to
Returns
returns true if the model was saved successfully, false otherwise
bool GRT::Filter::saveModelToFile ( fstream &  file) const
virtual

This saves the current settings of the Filter to a file. This overrides the saveModelToFile function in the PreProcessing base class.

Parameters
fstream&file: a reference to the file the settings will be saved to
Returns
returns true if the settings were saved successfully, false otherwise

Member Data Documentation

CircularBuffer< VectorDouble > GRT::Filter::dataBuffer
protected

A buffer to store the previous N values, N = filterSize.

UINT GRT::Filter::filterSize
protected

The size of the filter.

UINT GRT::Filter::inputSampleCounter
protected

A counter to keep track of the number of input samples.


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