21 #ifndef GRT_PARTICLE_CLASSIFIER_PARTICLE_FILTER_HEADER
22 #define GRT_PARTICLE_CLASSIFIER_PARTICLE_FILTER_HEADER
24 #include "../../CoreAlgorithms/ParticleFilter/ParticleFilter.h"
38 unsigned int getLength()
const {
42 unsigned int classLabel;
61 unsigned int numRandomFlipParticles = 0;
63 for(
unsigned int i=0; i<numRandomFlipParticles; i++){
65 unsigned int randomParticleIndex = i;
69 particles[ randomParticleIndex ].x[2] = 0;
83 const Float phase = p.x[1];
84 const Float velocity = p.x[2];
90 p.x[2] += phase-p.x[1];
104 const unsigned int templateIndex = (
unsigned int)p.x[0];
106 if( templateIndex >= numTemplates ){
107 errorLog <<
"update( Particle &p, VectorFloat &data ) - Template index out of bounds! templateIndex: " << templateIndex << std::endl;
112 const unsigned int templateLength = gestureTemplates[templateIndex].timeseries.getNumRows();
113 const unsigned int templatePos = (
unsigned int)(p.x[1] * Float(templateLength-1));
115 if( templatePos >= templateLength ){
116 errorLog <<
"update( Particle &p, VectorFloat &data ) - Template position out of bounds! templatePos: " << templatePos <<
" templateLength: " << templateLength << std::endl;
120 for(
unsigned int j=0; j<numInputDimensions; j++){
121 p.w *=
gauss( data[j], gestureTemplates[templateIndex].timeseries[templatePos][j],
measurementNoise[j] );
132 numInputDimensions = 0;
136 gestureTemplates.clear();
151 gestureTemplates.
resize( numTemplates );
152 for(
unsigned int i=0; i<numTemplates; i++){
153 gestureTemplates[i].classLabel = trainingData[i].getClassLabel();
154 gestureTemplates[i].timeseries = trainingData[i].getData();
178 for(
unsigned int i=0; i<numInputDimensions; i++){
191 errorLog <<
"ERROR: Failed to init particles!" << std::endl;
209 unsigned int numInputDimensions;
210 unsigned int numTemplates;
211 unsigned int numClasses;
212 unsigned int resampleCounter;
219 #endif //GRT_PARTICLE_CLASSIFIER_PARTICLE_FILTER_HEADER
virtual bool initParticles(const UINT numParticles)
bool setEstimationMode(const unsigned int estimationMode)
bool initialized
A flag that indicates if the filter has been initialized.
VectorFloat x
The state estimation.
virtual bool predict(Particle &p)
virtual bool resize(const unsigned int size)
virtual bool preFilterUpdate(VectorFloat &data)
Float getRandomNumberGauss(Float mu=0.0, Float sigma=1.0)
virtual bool update(Particle &p, VectorFloat &data)
Vector< VectorFloat > initModel
The noise model for the initial starting guess.
VectorFloat processNoise
The noise covariance in the system.
unsigned int getNumRows() const
VectorFloat measurementNoise
The noise covariance in the measurement.
unsigned int numParticles
The number of particles in the filter.
Random rand
A random number generator.
Float gauss(Float x, Float mu, Float sigma)
Float getRandomNumberUniform(Float minRange=0.0, Float maxRange=1.0)
UINT getNumDimensions() const
static Float limit(const Float value, const Float minValue, const Float maxValue)
Vector< Particle > & particles
A reference to the current active particle Vector.
int getRandomNumberInt(int minRange, int maxRange)
unsigned int stateVectorSize
The size of the state Vector (x)
UINT getNumClasses() const
UINT getNumSamples() const
virtual bool postFilterUpdate(VectorFloat &data)