| 467 | /*! Marginalized particle for state-space models with unknown parameters of distribuution of residues on \f$v_t\f$. |
| 468 | |
| 469 | \f{eqnarray*}{ |
| 470 | x_t &=& g(x_{t-1}) + v_t,\\ |
| 471 | y_t &\sim &fy(x_t), |
| 472 | \f} |
| 473 | |
| 474 | This particle is a only a shell creating the residues calling internal estimator of their parameters. The internal estimator can be of any compatible type, e.g. ARX for Gaussian residues with unknown mean and variance. |
| 475 | |
| 476 | */ |
| 477 | class NoiseParticleX : public MarginalizedParticleBase{ |
| 478 | protected: |
| 479 | //! function transforming xt, ut -> x_t+1 |
| 480 | shared_ptr<fnc> g; // pdf for non-linear part |
| 481 | //! function transforming xt,ut -> yt |
| 482 | shared_ptr<pdf> fy; // pdf for non-linear part |
| 483 | |
| 484 | RV rvx; |
| 485 | RV rvxc; |
| 486 | RV rvyc; |
| 487 | |
| 488 | //!link from condition to f |
| 489 | datalink_part cond2g; |
| 490 | //!link from condition to h |
| 491 | datalink_part cond2fy; |
| 492 | //!link from xt to f |
| 493 | datalink_part x2g; |
| 494 | //!link from xt to h |
| 495 | datalink_part x2fy; |
| 496 | |
| 497 | public: |
| 498 | BM* _copy() const{return new NoiseParticleX(*this);}; |
| 499 | void bayes(const vec &dt, const vec &cond){ |
| 500 | shared_ptr<epdf> pred_v=bm->epredictor(); |
| 501 | |
| 502 | vec vt=pred_v->sample(); |
| 503 | |
| 504 | //new sample |
| 505 | vec &xtm=est_emp.point; |
| 506 | vec g_args(g->dimensionc()); |
| 507 | x2g.filldown(xtm,g_args); |
| 508 | cond2g.filldown(cond,g_args); |
| 509 | vec xt = g->eval(g_args) + vt; |
| 510 | est_emp.point=xt; |
| 511 | |
| 512 | // the vector [v_t] updates bm, |
| 513 | bm->bayes(vt); |
| 514 | |
| 515 | // residue of observation |
| 516 | vec fy_args(fy->dimensionc()); |
| 517 | x2fy.filldown(xt,fy_args); |
| 518 | cond2fy.filldown(cond,fy_args); |
| 519 | |
| 520 | ll=bm->_ll() + fy->evallogcond(dt,fy_args); |
| 521 | } |
| 522 | void from_setting(const Setting &set){ |
| 523 | MarginalizedParticleBase::from_setting(set); //reads bm, yrv,rvc, bm_rv, etc... |
| 524 | |
| 525 | g=UI::build<fnc>(set,"g",UI::compulsory); |
| 526 | fy=UI::build<pdf>(set,"fy",UI::compulsory); |
| 527 | UI::get(rvx,set,"rvx",UI::compulsory); |
| 528 | est_emp.set_rv(rvx); |
| 529 | |
| 530 | UI::get(rvxc,set,"rvxc",UI::compulsory); |
| 531 | UI::get(rvyc,set,"rvyc",UI::compulsory); |
| 532 | |
| 533 | } |
| 534 | void validate(){ |
| 535 | MarginalizedParticleBase::validate(); |
| 536 | |
| 537 | dimy = fy->dimension(); |
| 538 | bm->set_yrv(rvx); |
| 539 | |
| 540 | est_emp.set_rv(rvx); |
| 541 | est_emp.set_dim(rvx._dsize()); |
| 542 | est.validate(); |
| 543 | // |
| 544 | //check dimensions |
| 545 | rvc = rvxc.subt(rvx.copy_t(-1)); |
| 546 | rvc.add( rvyc); |
| 547 | rvc=rvc.subt(rvx); |
| 548 | |
| 549 | bdm_assert(g->dimension()==rvx._dsize(),"rvx is not described"); |
| 550 | bdm_assert(g->dimensionc()==rvxc._dsize(),"rvxc is not described"); |
| 551 | bdm_assert(fy->dimensionc()==rvyc._dsize(),"rvyc is not described"); |
| 552 | |
| 553 | bdm_assert(bm->dimensiony()==g->dimension(), |
| 554 | "Incompatible noise estimator of dimension " + |
| 555 | num2str(bm->dimensiony()) + " does not match dimension of g , " + |
| 556 | num2str(g->dimension())); |
| 557 | |
| 558 | dimc = rvc._dsize(); |
| 559 | |
| 560 | //establish datalinks |
| 561 | x2g.set_connection(rvxc, rvx.copy_t(-1)); |
| 562 | cond2g.set_connection(rvxc, rvc); |
| 563 | |
| 564 | x2fy.set_connection(rvyc, rvx); |
| 565 | cond2fy.set_connection(rvyc, rvc); |
| 566 | } |
| 567 | }; |
| 568 | UIREGISTER(NoiseParticleX); |
| 569 | |
556 | | num2str(bm->dimensiony()) + " does not match dimension of g and h, " + |
557 | | num2str(g->dimension())+" and "+ num2str(h->dimension()) ); |
558 | | |
559 | | dimc = rvc._dsize(); |
560 | | |
561 | | //establish datalinks |
562 | | x2g.set_connection(rvxc, rvx.copy_t(-1)); |
563 | | cond2g.set_connection(rvxc, rvc); |
564 | | |
565 | | x2h.set_connection(rvyc, rvx); |
566 | | cond2h.set_connection(rvyc, rvc); |
| 658 | num2str(bm->dimensiony()) + " does not match dimension of g and h, " + |
| 659 | num2str(g->dimension())+" and "+ num2str(h->dimension()) ); |
| 660 | |
| 661 | dimc = rvc._dsize(); |
| 662 | |
| 663 | //establish datalinks |
| 664 | x2g.set_connection(rvxc, rvx.copy_t(-1)); |
| 665 | cond2g.set_connection(rvxc, rvc); |
| 666 | |
| 667 | x2h.set_connection(rvyc, rvx); |
| 668 | cond2h.set_connection(rvyc, rvc); |