Go to the documentation of this file. 1 #ifndef BOOTSTRAP_FILTER_WC_H
2 #define BOOTSTRAP_FILTER_WC_H
8 #ifdef DROPPINGTHISINRPACKAGE
12 #include <Eigen/Dense>
36 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov,
typename resamp_t,
typename float_t,
bool debug=false>
42 using ssv = Eigen::Matrix<float_t, dimx, 1>;
44 using osv = Eigen::Matrix<float_t, dimy, 1>;
46 using cvsv = Eigen::Matrix<float_t,dimcov,1>;
48 using Mat = Eigen::Matrix<float_t,Eigen::Dynamic,Eigen::Dynamic>;
84 const std::vector<std::function<
const Mat(
const ssv&,
const cvsv&)>>& fs = std::vector<std::function<
const Mat(
const ssv&,
const cvsv&)>>());
170 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov, typename resamp_t, typename float_t,
bool debug>
181 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov,
typename resamp_t,
typename float_t,
bool debug>
185 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov,
typename resamp_t,
typename float_t,
bool debug>
193 float_t maxOldLogUnNormWts(-std::numeric_limits<float_t>::infinity());
195 for(
size_t ii = 0; ii < nparts; ++ii)
208 #ifndef DROPPINGTHISINRPACKAGE
216 float_t sumExp1(0.0);
217 float_t sumExp2(0.0);
218 for(
size_t i = 0; i < nparts; ++i){
220 sumExp2 += std::exp(oldLogUnNormWts[i] - maxOldLogUnNormWts);
222 m_logLastCondLike = maxNumer + std::log(sumExp1) - maxOldLogUnNormWts - std::log(sumExp2);
229 unsigned int rows = testOutput.rows();
230 unsigned int cols = testOutput.cols();
231 Mat numer = Mat::Zero(rows,cols);
232 float_t weightNormConst (0.0);
233 for(
size_t prtcl = 0; prtcl < nparts; ++prtcl){
239 #ifndef DROPPINGTHISINRPACKAGE
241 std::cout <<
"transposed expectation " << fId <<
": " <<
m_expectations[fId].transpose() <<
"\n";
257 for(
size_t ii = 0; ii < nparts; ++ii)
265 #ifndef DROPPINGTHISINRPACKAGE
275 for(
size_t i = 0; i < nparts; ++i){
287 unsigned int rows = testOutput.rows();
288 unsigned int cols = testOutput.cols();
289 Mat numer = Mat::Zero(rows,cols);
290 float_t weightNormConst (0.0);
291 for(
size_t prtcl = 0; prtcl < nparts; ++prtcl){
310 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov,
typename resamp_t,
typename float_t,
bool debug>
317 template<
size_t nparts,
size_t dimx,
size_t dimy,
size_t dimcov,
typename resamp_t,
typename float_t,
bool debug>
326 #endif // BOOTSTRAP_FILTER_WC_H
virtual float_t logMuEv(const ssv &x1, const cvsv &z1)=0
Calculate muEv or logmuEv.
virtual float_t logQ1Ev(const ssv &x1, const osv &y1, const cvsv &z1)=0
Calculate q1Ev or log q1Ev.
std::array< float_t, nparts > arrayfloat_t
Definition: bootstrap_filter_with_covariates.h:52
Eigen::Matrix< float_t, dimcov, 1 > cvsv
Definition: bootstrap_filter_with_covariates.h:46
Eigen::Matrix< float_t, Eigen::Dynamic, Eigen::Dynamic > Mat
Definition: bootstrap_filter_with_covariates.h:48
void filter(const osv &ydata, const cvsv &covdata, const std::vector< std::function< const Mat(const ssv &, const cvsv &)>> &fs=std::vector< std::function< const Mat(const ssv &, const cvsv &)>>())
updates filtering distribution on a new datapoint. Optionally stores expectations of functionals.
Definition: bootstrap_filter_with_covariates.h:186
BSFilterWC(const unsigned int &rs=1)
The constructor.
Definition: bootstrap_filter_with_covariates.h:171
unsigned int m_now
time point
Definition: bootstrap_filter_with_covariates.h:149
All non Rao-Blackwellized particle filters without covariates inherit from this.
arrayfloat_t m_logUnNormWeights
particle unnormalized weights
Definition: bootstrap_filter_with_covariates.h:146
virtual ssv fSamp(const ssv &xtm1, const cvsv &zt)=0
Sample from the state transition distribution.
virtual ssv q1Samp(const osv &y1, const cvsv &z1)=0
Samples from time 1 proposal.
virtual float_t logGEv(const osv &yt, const ssv &xt, const cvsv &zt)=0
Calculate gEv or logGEv.
auto getExpectations() const -> std::vector< Mat >
return all stored expectations (taken with respect to $p(x_t|y_{1:t})$
Definition: bootstrap_filter_with_covariates.h:318
resamp_t m_resampler
resampler object
Definition: bootstrap_filter_with_covariates.h:155
std::array< ssv, nparts > arrayStates
Definition: bootstrap_filter_with_covariates.h:50
Eigen::Matrix< float_t, dimx, 1 > ssv
Definition: bootstrap_filter_with_covariates.h:42
float_t getLogCondLike() const
Returns the most recent (log-) conditiona likelihood.
Definition: bootstrap_filter_with_covariates.h:311
std::vector< Mat > m_expectations
expectations E[h(x_t) | y_{1:t}] for user defined "h"s
Definition: bootstrap_filter_with_covariates.h:158
A base class for the bootstrap particle filter with covariates.
Definition: bootstrap_filter_with_covariates.h:37
Eigen::Matrix< float_t, dimy, 1 > osv
Definition: bootstrap_filter_with_covariates.h:44
unsigned int m_resampSched
resampling schedule (e.g. resample every __ time points)
Definition: bootstrap_filter_with_covariates.h:161
virtual ~BSFilterWC()
The (virtual) destructor.
Definition: bootstrap_filter_with_covariates.h:182
arrayStates m_particles
particle samples
Definition: bootstrap_filter_with_covariates.h:143
float_t m_logLastCondLike
log p(y_t|y_{1:t-1}) or log p(y1)
Definition: bootstrap_filter_with_covariates.h:152