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 double phase = p.x[1];
84 const double 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, VectorDouble &data ) - Template index out of bounds! templateIndex: " << templateIndex << endl;
112 const unsigned int templateLength = gestureTemplates[templateIndex].timeseries.getNumRows();
113 const unsigned int templatePos = (
unsigned int)(p.x[1] *
double(templateLength-1));
115 if( templatePos >= templateLength ){
116 errorLog <<
"update( Particle &p, VectorDouble &data ) - Template position out of bounds! templatePos: " << templatePos <<
" templateLength: " << templateLength << 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!" << endl;
209 unsigned int numInputDimensions;
210 unsigned int numTemplates;
211 unsigned int numClasses;
212 unsigned int resampleCounter;
213 vector< ParticleClassifierGestureTemplate > gestureTemplates;
219 #endif //GRT_PARTICLE_CLASSIFIER_PARTICLE_FILTER_HEADER
double getRandomNumberGauss(double mu=0.0, double sigma=1.0)
unsigned int numParticles
The number of particles in the filter.
virtual bool postFilterUpdate(VectorDouble &data)
UINT getNumSamples() const
std::vector< VectorDouble > initModel
The noise model for the initial starting guess.
VectorDouble x
The state estimation.
unsigned int stateVectorSize
The size of the state vector (x)
UINT getNumDimensions() const
VectorDouble measurementNoise
The noise covariance in the measurement.
bool initialized
A flag that indicates if the filter has been initialized.
double gauss(double x, double mu, double sigma)
std::vector< Particle > & particles
A reference to the current active particle vector.
virtual bool initParticles(const UINT numParticles)
virtual bool preFilterUpdate(VectorDouble &data)
VectorDouble processNoise
The noise covariance in the system.
UINT getNumClasses() const
int getRandomNumberInt(int minRange, int maxRange)
double getRandomNumberUniform(double minRange=0.0, double maxRange=1.0)
virtual bool update(Particle &p, VectorDouble &data)
virtual bool predict(Particle &p)
unsigned int getNumRows() const
Random rand
A random number generator.
static double limit(const double value, const double minValue, const double maxValue)
bool setEstimationMode(const unsigned int estimationMode)