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.
Main Page
Related Pages
Classes
Files
Examples
File List
File Members
FSMParticleFilter.h
Go to the documentation of this file.
1
27
#ifndef GRT_FSM_PARTICLE_FILTER_HEADER
28
#define GRT_FSM_PARTICLE_FILTER_HEADER
29
30
#include "../../CoreAlgorithms/ParticleFilter/ParticleFilter.h"
31
#include "
FSMParticle.h
"
32
33
GRT_BEGIN_NAMESPACE
34
35
class
FSMParticleFilter
:
public
ParticleFilter
< FSMParticle, VectorFloat >{
36
public
:
37
FSMParticleFilter
():errorLog(
"[ERROR FSMParticleFilter]"
){
38
pt = NULL;
39
pe = NULL;
40
}
41
42
FSMParticleFilter
(
const
FSMParticleFilter
&rhs ):errorLog(
"[ERROR FSMParticleFilter]"
){
43
pt = NULL;
44
pe = NULL;
45
//TODO: Need to handle copy better
46
}
47
48
virtual
~
FSMParticleFilter
(){
49
50
}
51
52
virtual
bool
predict
(
FSMParticle
&p ){
53
54
if
( !
initialized
){
55
errorLog <<
"predict( FSMParticle &p ) - Particle Filter has not been initialized!"
<< std::endl;
56
return
false
;
57
}
58
59
if
( pt == NULL || pe == NULL ){
60
errorLog <<
"predict( FSMParticle &p ) - pt or pe are NULL!"
<< std::endl;
61
return
false
;
62
}
63
64
//Update the particles current state
65
p.currentState = random.
getRandomNumberWeighted
( pt->at( p.currentState ) );
66
67
//Get the model for the current state
68
const
Vector< VectorDouble >
&model = pe->at( p.currentState );
69
70
//Pick a random sample from the model and set this as the particles state vector
71
const
unsigned
int
K = model.
getSize
();
72
if
( K > 0 )
73
p.x = model[ random.
getRandomNumberInt
(0, K) ];
74
75
return
true
;
76
}
77
78
virtual
bool
update
(
FSMParticle
&p,
VectorDouble
&data ){
79
80
if
( !
initialized
){
81
errorLog <<
"update( FSMParticle &p, VectorDouble &data ) - Particle Filter has not been initialized!"
<< std::endl;
82
return
false
;
83
}
84
85
if
( p.x.size() != data.size() ){
86
errorLog <<
"update( FSMParticle &p, VectorDouble &data ) - x does not match data.size()!"
<< std::endl;
87
return
false
;
88
}
89
90
//Estimate the particles weight, given its current state and the sensor data
91
p.w = 1;
92
const
size_t
N = p.x.size();
93
for
(
size_t
i=0; i<N; i++){
94
p.w *=
gauss
(p.x[i], data[i],
measurementNoise
[i]);
95
}
96
97
/*
98
std::cout << "w: " << p.w << " p.x: ";
99
for(size_t i=0; i<N; i++){
100
std::cout << p.x[i] << " ";
101
}
102
std::cout << " data: ";
103
for(size_t i=0; i<N; i++){
104
std::cout << data[i] << " ";
105
}
106
std::cout << std::endl;
107
*/
108
109
return
true
;
110
}
111
112
bool
setLookupTables(
Vector
<
Vector< IndexedDouble >
> &pt,
Vector
<
Vector< VectorDouble >
> &pe ){
113
114
this->pt = &pt;
115
this->pe = &pe;
116
117
return
true
;
118
}
119
120
Random
random;
121
ErrorLog
errorLog;
122
Vector< Vector< IndexedDouble >
> *pt;
123
Vector< Vector< VectorDouble >
> *pe;
124
};
125
126
GRT_END_NAMESPACE
127
128
#endif
ParticleFilter< FSMParticle, VectorFloat >::initialized
bool initialized
A flag that indicates if the filter has been initialized.
Definition:
ParticleFilter.h:902
FSMParticleFilter::update
virtual bool update(FSMParticle &p, VectorDouble &data)
Definition:
FSMParticleFilter.h:78
Random
Definition:
Random.h:40
FSMParticle.h
ParticleFilter
Definition:
ParticleFilter.h:41
Vector::getSize
unsigned int getSize() const
Definition:
Vector.h:193
FSMParticleFilter
Definition:
FSMParticleFilter.h:35
Random::getRandomNumberWeighted
int getRandomNumberWeighted(const Vector< int > &values, const VectorFloat &weights)
Definition:
Random.h:105
ParticleFilter< FSMParticle, VectorFloat >::measurementNoise
VectorFloat measurementNoise
The noise covariance in the measurement.
Definition:
ParticleFilter.h:919
VectorFloat
Definition:
VectorFloat.h:33
ParticleFilter< FSMParticle, VectorFloat >::gauss
Float gauss(Float x, Float mu, Float sigma)
Definition:
ParticleFilter.h:855
Random::getRandomNumberInt
int getRandomNumberInt(int minRange, int maxRange)
Definition:
Random.h:88
FSMParticle
Definition:
FSMParticle.h:34
Vector
Definition:
Vector.h:41
FSMParticleFilter::predict
virtual bool predict(FSMParticle &p)
Definition:
FSMParticleFilter.h:52
ErrorLog
Definition:
ErrorLog.h:51
GRT
ClassificationModules
FiniteStateMachine
FSMParticleFilter.h
Generated on Sun Feb 21 2016 20:06:25 for GestureRecognitionToolkit by
1.8.11