28 #ifndef PARTICLEFILTER_H_ 29 #define PARTICLEFILTER_H_ 38 #define TWOPI (6.2831853071795864769252867665590057683943387987502) 44 #define RAND (rand())/((double) RAND_MAX) 51 #define RANDN (sqrt(-2.0*log(RAND))*cos(TWOPI*RAND)) 53 std::vector<double>
cumSum(
const std::vector<double> & v)
55 std::vector<double> cum(v.size());
57 for(
unsigned int i=0; i<v.size(); ++i)
65 std::vector<double>
resample(
const std::vector<double> & p,
66 const std::vector<double> & w,
67 bool normalizeWeights =
false)
69 std::vector<double> np;
70 if(p.size() != w.size() || p.size() == 0)
72 UERROR(
"particles (%d) and weights (%d) are not the same size", p.size(), w.size());
76 std::vector<double> cs;
79 double wSum =
uSum(w);
80 std::vector<double> wNorm(w.size());
81 for(
unsigned int i=0; i<w.size(); ++i)
91 for(
unsigned int j=0; j<cs.size(); ++j)
97 for(
unsigned int i=0; i<np.size(); ++i)
99 unsigned int index = 0;
100 double randnum =
RAND;
101 for(
unsigned int j=0; j<cs.size(); ++j)
120 double lambda = 10.0,
121 double initValue = 0.0) :
128 void init(
double initValue = 0.0f)
135 std::vector<double> weights(
particles_.size(), 1);
136 double sumWeights = 0;
137 for(
unsigned int i=0; i<
particles_.size(); ++i)
150 sumWeights += weights[i];
156 for(
unsigned int i=0; i<weights.size(); ++i)
158 weights[i] /= sumWeights;
void init(double initValue=0.0f)
double filter(double val)
Basic mathematics functions.
bool uIsFinite(const T &value)
std::vector< double > resample(const std::vector< double > &p, const std::vector< double > &w, bool normalizeWeights=false)
ParticleFilter(unsigned int nParticles=200, double noise=0.1, double lambda=10.0, double initValue=0.0)
std::vector< double > cumSum(const std::vector< double > &v)
GLM_FUNC_DECL genType exp(genType const &x)
ULogger class and convenient macros.
T uSum(const std::list< T > &list)
std::vector< double > particles_