GVF Class Reference

Public Types

enum  GVFState { STATE_CLEAR = 0, STATE_LEARNING, STATE_FOLLOWING, STATE_BYPASS }
 

Public Member Functions

 GVF ()
 
 ~GVF ()
 
void startGesture ()
 
void addObservation (vector< float > data)
 
void addGestureTemplate (GVFGesture &gestureTemplate)
 
void replaceGestureTemplate (GVFGesture &gestureTemplate, int index)
 
void removeGestureTemplate (int index)
 
void removeAllGestureTemplates ()
 
GVFGesturegetGestureTemplate (int index)
 
vector< GVFGesture > & getAllGestureTemplates ()
 
int getNumberOfGestureTemplates ()
 
vector< int > getGestureClasses ()
 
GVFState setState (GVFState _state, vector< int > indexes=vector< int >())
 
GVFState getState ()
 
GVFOutcomesupdate (vector< float > &observation)
 
void setActiveGestures (vector< int > activeGestureIds)
 
void restart ()
 
void clear ()
 
void translate (bool translateFlag)
 
void segmentation (bool segmentationFlag)
 
void setTolerance (float tolerance)
 
float getTolerance ()
 
void setNumberOfParticles (int numberOfParticles)
 
int getNumberOfParticles ()
 
void setPredictionSteps (int predictionSteps)
 
int getPredictionSteps ()
 
void setResamplingThreshold (int resamplingThreshold)
 
int getResamplingThreshold ()
 
void setDynamicsVariance (float dynVariance, int dim=-1)
 
void setDynamicsVariance (vector< float > dynVariance)
 
vector< float > getDynamicsVariance ()
 
void setScalingsVariance (float scaleVariance, int dim=-1)
 
void setScalingsVariance (vector< float > scaleVariance)
 
vector< float > getScalingsVariance ()
 
void setRotationsVariance (float rotationsVariance, int dim=-1)
 
void setRotationsVariance (vector< float > rotationsVariance)
 
vector< float > getRotationsVariance ()
 
const vector< vector< float > > & getParticlesPositions ()
 
void setSpreadDynamics (float min, float max, int dim=-1)
 
void setSpreadScalings (float min, float max, int dim=-1)
 
void setSpreadRotations (float min, float max, int dim=-1)
 
void saveTemplates (string filename)
 
void loadTemplates (string filename)
 

Protected Member Functions

void initPrior ()
 
void initNoiseParameters ()
 
void updateLikelihood (vector< float > obs, int n)
 
void updatePrior (int n)
 
void updatePosterior (int n)
 
void resampleAccordingToWeights (vector< float > obs)
 
void estimates ()
 
void train ()
 

Protected Attributes

GVFConfig config
 
GVFParameters parameters
 
GVFOutcomes outcomes
 
GVFState state
 
GVFGesture theGesture
 
vector< float > dimWeights
 
vector< float > maxRange
 
vector< float > minRange
 
int dynamicsDim
 
int scalingsDim
 
int rotationsDim
 
float globalNormalizationFactor
 
int mostProbableIndex
 
int learningGesture
 
vector< int > classes
 
vector< float > alignment
 
vector< vector< float > > dynamics
 
vector< vector< float > > scalings
 
vector< vector< float > > rotations
 
vector< float > weights
 
vector< float > prior
 
vector< float > posterior
 
vector< float > likelihood
 
vector< float > estimatedGesture
 
vector< float > estimatedAlignment
 
vector< vector< float > > estimatedDynamics
 
vector< vector< float > > estimatedScalings
 
vector< vector< float > > estimatedRotations
 
vector< float > estimatedProbabilities
 
vector< float > estimatedLikelihoods
 
vector< float > absoluteLikelihoods
 
vector< float > currentVelAcc
 
vector< vector< float > > kalmanDynMatrix
 
vector< vector< float > > kalmanMapMatrix
 
bool tolerancesetmanually
 
vector< GVFGesturegestureTemplates
 
vector< vector< float > > offsets
 
vector< int > activeGestures
 
std::random_device rd
 
std::mt19937 normgen
 
std::normal_distribution< float > * rndnorm
 
std::default_random_engine unifgen
 
std::uniform_real_distribution< float > * rndunif
 
vector< float > gestureProbabilities
 
vector< vector< float > > particles
 

Member Enumeration Documentation

GVF possible states

Enumerator
STATE_CLEAR 

STATE_CLEAR: clear the GVF and be in standby

STATE_LEARNING 

STATE_LEARNING: recording mode, input gestures are added to the templates

STATE_FOLLOWING 

STATE_FOLLOWING: tracking mode, input gestures are classifed and their variations tracked (need the GVF to be trained)

STATE_BYPASS 

STATE_BYPASS: by pass GVF but does not erase templates or training

Constructor & Destructor Documentation

GVF::GVF ( )

GVF default constructor

use default configuration and parameters, can be changed using accessors

GVF::~GVF ( )

GVF default constructor

Parameters
configconfiguration structure of type GVFConfig used to set number of dimensions etc. Here the parameters used are the default ones GVF default constructor
configurationstructure (nb. dimensions etc)
parametersstructure GVF default destructor

Member Function Documentation

void GVF::addGestureTemplate ( GVFGesture gestureTemplate)

Add gesture template to the vocabulary

a gesture template is a GVFGesture object

Parameters
thegesture template to be recorded
void GVF::addObservation ( vector< float >  data)

Add an observation to a gesture template

Parameters
vectorof features
void GVF::clear ( )

Clear GVF

delete templates

vector< GVFGesture > & GVF::getAllGestureTemplates ( )

Get every recorded gesture template

Returns
the vecotr of gesture templates
vector< float > GVF::getDynamicsVariance ( )

Get dynamics variances

Returns
the vector of variances (the returned vector is 2-dimensional)
vector< int > GVF::getGestureClasses ( )

Get gesture classes

GVFGesture & GVF::getGestureTemplate ( int  index)

Get a specific gesture template a gesture template by another

Parameters
indexof the template to be returned
Returns
the template
int GVF::getNumberOfGestureTemplates ( )

Get number of gesture templates in the vocabulary

Returns
the number of templates
int GVF::getNumberOfParticles ( )

Get the current number of particles

Returns
the current number of particles
const vector< vector< float > > & GVF::getParticlesPositions ( )

Get particle values

Returns
vector of list of estimated particles
int GVF::getPredictionSteps ( )

Get the current number of prediction steps

Returns
current number of prediciton steps
int GVF::getResamplingThreshold ( )

Get the current resampling threshold

Returns
resampling threshold
vector< float > GVF::getRotationsVariance ( )

Get rotation variances

Returns
the vector of variances
vector< float > GVF::getScalingsVariance ( )

Get scalings variances

Returns
the vector of variances
float GVF::getTolerance ( )

Get the obervation tolerance value

see setTolerance(float tolerance)

Returns
the current toleranc value
void GVF::loadTemplates ( string  filename)

Import template data in a filename

needs to respect a given format provided by saveTemplates()

Parameters
filename as a string
void GVF::removeAllGestureTemplates ( )

Remove every recorded gesture template

void GVF::removeGestureTemplate ( int  index)

Remove a specific template

Parameters
thegesture index (as integer) to be removed
void GVF::replaceGestureTemplate ( GVFGesture gestureTemplate,
int  index 
)

Replace a specific gesture template by another

Parameters
thegesture template to be used
thegesture index (as integer) to be replaced
void GVF::restart ( )

Restart GVF

re-sample particles at the origin (i.e. initial prior)

void GVF::saveTemplates ( string  filename)

Export template data in a filename

Parameters
filenamefile name as a string
void GVF::segmentation ( bool  segmentationFlag)

Segment gestures within a continuous gesture stream

if segmentation is true, the method will segment a continuous gesture into a sequence of gestures. In other words no need to call the method startGesture(), it is done automatically

Parameters
booleanto activate or deactivate segmentation
void GVF::setActiveGestures ( vector< int >  activeGestureIds)

Define a subset of gesture templates on which to perform the recognition and variation tracking

By default every recorded gesture template is considered

Parameters
setof gesture template index to consider
void GVF::setDynamicsVariance ( float  dynVariance,
int  dim = -1 
)

Change variance of alignment adaptation

if alignment variance is high the method will adapt faster to high variations Change variance of adaptation in dynamics

if dynamics adaptation variance is high the method will adapt faster to fast changes in dynamics. Dynamics is 2-dimensional: the first dimension is the speed The second dimension is the acceleration.

Typically the variance is the average amount the speed or acceleration can change from one sample to another. As an example, if the relative estimated speed can change from 1.1 to 1.2 from one sample to another, the variance should allow a change of 0.1 in speed. So the variance should be set to 0.1*0.1 = 0.01

Parameters
dynVariancedynamics variance value
dimoptional dimension of the dynamics for which the change of variance is applied (default value is 1)
void GVF::setDynamicsVariance ( vector< float >  dynVariance)

Change variance of adaptation in dynamics

See setDynamicsVariance(float dynVariance, int dim) for more details

Parameters
dynVariancevector of dynamics variances, each vector index is the variance to be applied to each dynamics dimension (consequently the vector should be 2-dimensional).
void GVF::setNumberOfParticles ( int  numberOfParticles)

Set number of particles used in estimation

default valye is 1000, note that the computational cost directly depends on the number of particles

Parameters
newnumber of particles
void GVF::setPredictionSteps ( int  predictionSteps)

Number of prediciton steps

it is possible to leave GVF to perform few steps of prediction ahead which can be useful to estimate more fastly the variations. Default value is 1 which means no prediction ahead

Parameters
thenumber of prediction steps
void GVF::setResamplingThreshold ( int  resamplingThreshold)

Set resampling threshold

resampling threshold is the minimum number of active particles before resampling all the particles by the estimated posterior distribution. in other words, it re-targets particles around the best current estimates

Parameters
theminimum number of particles (default is (number of particles)/2)
void GVF::setRotationsVariance ( float  rotationsVariance,
int  dim = -1 
)

Change variance of adaptation in orientation

if rotation adaptation variance is high the method will adapt faster to fast changes in relative orientation. If the gesture is 2-dimensional, there is one variance value since the rotation can be defined by only one angle of rotation. If the gesture is 3-dimensional, there are 3 variance values since the rotation in 3-d is defined by 3 rotation angles. For any other dimension, the rotation is not defined.

The variance is the average amount the orientation can change from one sample to another. As an example, if the relative orientation in rad changes from 0.1 to 0.2 from one observation to another, the variance should allow a change of 0.1 in rotation angle. So the variance should be set to 0.1*0.1 = 0.01

Parameters
rotationsVariancerotation variance value
dimoptional dimension of the rotation for which the change of variance is applied
void GVF::setRotationsVariance ( vector< float >  rotationsVariance)

Change variance of adaptation in orientation

See setRotationsVariance(float rotationsVariance, int dim) for more details

Parameters
vectorof rotation variances, each vector index is the variance to be applied to each rotation angle (1 or 3)
vectorof variances (should be 1 if the the template gestures are 2-dim or 3 if they are 3-dim)
void GVF::setScalingsVariance ( float  scaleVariance,
int  dim = -1 
)

Change variance of adaptation in scalings

if scalings adaptation variance is high the method will adapt faster to fast changes in relative sizes. There is one scaling variance for each dimension of the input gesture. If the gesture is 2-dimensional, the scalings variances will also be 2-dimensional.

Typically the variance is the average amount the size can change from one sample to another. As an example, if the relative estimated size changes from 1.1 to 1.15 from one sample to another, the variance should allow a change of 0.05 in size. So the variance should be set to 0.05*0.05 = 0.0025

Parameters
scalingsvariance value
dimensionof the scalings for which the change of variance is applied
void GVF::setScalingsVariance ( vector< float >  scaleVariance)

Change variance of adaptation in dynamics

See setScalingsVariance(float scaleVariance, int dim) for more details

Parameters
vectorof scalings variances, each vector index is the variance to be applied to each scaling dimension.
vectorof variances (should be the size of the template gestures dimension)
void GVF::setSpreadDynamics ( float  min,
float  max,
int  dim = -1 
)

Set the interval on which the dynamics values should be spread at the beginning (before adaptation)

this interval can be used to concentrate the potential dynamics value on a narrow interval, typically around 1 (the default value), for instance between -0.05 and 0.05, or to allow at the very beginning, high changes in dynamics by spreading, for instance between 0.0 and 2.0

Parameters
minlower value of the inital values for dynamics
maxhigher value of the inital values for dynamics
dimthe dimension on which the change of initial interval should be applied (optional)
void GVF::setSpreadRotations ( float  min,
float  max,
int  dim = -1 
)

Set the interval on which the angle of rotation values should be spread at the beginning (before adaptation)

this interval can be used to concentrate the potential angle values on a narrow interval, typically around 0.0 (the default value), for instance between -0.05 and 0.05, or to allow at the very beginning, high changes in orientation by spreading, for instance, between -0.5 and 0.5

Parameters
minlower value of the inital values for angle of rotation
maxhigher value of the inital values for angle of rotation
dimthe dimension on which the change of initial interval should be applied (optional)
void GVF::setSpreadScalings ( float  min,
float  max,
int  dim = -1 
)

Set the interval on which the scalings values should be spread at the beginning (before adaptation)

this interval can be used to concentrate the potential scalings value on a narrow interval, typically around 1.0 (the default value), for instance between 0.95 and 1.05, or to allow at the very beginning high changes in dynamics by spreading, for instance, between 0.0 and 2.0

Parameters
minlower value of the inital values for scalings
maxhigher value of the inital values for scalings
dimthe dimension on which the change of initial interval should be applied (optional)
void GVF::setTolerance ( float  tolerance)

Get gesture probabilities

Returns
vector of probabilities Set tolerance between observation and estimation

tolerance depends on the range of the data typially tolerance = (data range)/3.0;

Parameters
tolerancevalue
void GVF::startGesture ( )

Start a gesture either to be recorded or followed

void GVF::translate ( bool  translateFlag)

Translate data according to the first point

substract each gesture feature by the first point of the gesture

Parameters
booleanto activate or deactivate translation
GVFOutcomes & GVF::update ( vector< float > &  observation)

Compute the estimated gesture and its potential variations

infers the probability that the current observation belongs to one of the recorded gesture template and track the variations of this gesture according to each template

Parameters
observationvector of the observation data at current time
Returns
the estimated probabilities and variaitons relative to each template

Member Data Documentation

GVFConfig GVF::config
protected

Similar to constructor GVF() - for openFrameworks Similar to constructor GVF(GVFConfig _config) - for openFrameworks Similar to constructor GVF(GVFConfig _config, GVFParameters _parameters) - for openFrameworks