7 #ifndef SSMPACK_FILTER_PARTICLE_HPP
8 #define SSMPACK_FILTER_PARTICLE_HPP
22 using process::Hierarchical;
23 using process::Markov;
24 using process::Memoryless;
25 using distribution::Conditional;
29 template <
class Process,
class Resampler>
52 void normalizeWeights(
void) { w_ = w_ / arma::sum(w_); }
63 Particle(Process process, Resampler resampler,
unsigned long particles_num)
64 : process_{process}, resampler_{resampler}, num_{particles_num} {
68 auto tmp = process_.template getProcess<0>().getInitialPDF().random();
69 state_par_.resize(tmp.size(), num_);
79 template <
class... Args>
81 state_par_.each_col([
this, &args...](arma::vec &v,
const Args &... args) {
82 v = process_.template getProcess<0>().getCPDF().random(v, args...);
98 template <
class Measurement,
class... TArgs>
100 const TArgs &... args) {
101 unsigned long cnt = 0;
102 w_.for_each([
this, &cnt, &measurement, &args...](
double &e) {
103 e *= process_.template getProcess<1>().getCPDF().likelihood(
104 measurement, state_par_.col(cnt++), args...);
109 resampler_(state_par_, w_);
111 return std::make_tuple(state_par_, w_);
118 state_par_.each_col([
this](arma::vec &v) {
119 v = process_.template getProcess<0>().getInitialPDF().random();
122 unsigned long cnt = 0;
123 w_.for_each([
this, &cnt](
double &e) {
124 e = process_.template getProcess<0>().getInitialPDF().likelihood(
125 state_par_.col(cnt++));
130 return std::make_tuple(state_par_, w_);
140 template <
class StatePDF,
class StateParamMap,
class InitialPDF,
141 class MeasurementPDF,
class MeasurementParamMap,
class Resampler>
143 Hierarchical<Markov<StatePDF, StateParamMap, InitialPDF>,
144 Memoryless<MeasurementPDF, MeasurementParamMap>> process,
145 Resampler resampler,
unsigned long particle_num) {
147 Memoryless<MeasurementPDF, MeasurementParamMap>>,
148 Resampler>(process, resampler, particle_num);
154 #endif // SSMPACK_FILTER_PARTICLE_HPP
const arma::vec & getWeights(void) const
std::tuple< arma::mat, arma::vec > CompeleteState
Type of the state posterior.
CompeleteState correct(const Measurement &measurement, const TArgs &...args)
Correction.
void predict(const Args &...args)
Prediction.
Particle(Process process, Resampler resampler, unsigned long particles_num)
Constructor.
const arma::mat & getStateParticles(void) const
CompeleteState initialize()
Initialization.
auto makeParticle(Hierarchical< Markov< StatePDF, StateParamMap, InitialPDF >, Memoryless< MeasurementPDF, MeasurementParamMap >> process, Resampler resampler, unsigned long particle_num)