| 365 | /*! ARXg for estimation of state-space variances |
| 366 | */ |
| 367 | class MPF_ARXg :public BM{ |
| 368 | protected: |
| 369 | shared_ptr<PF> pf; |
| 370 | //! pointer to Array of BMs |
| 371 | Array<ARX*> BMso; |
| 372 | //! pointer to Array of BMs |
| 373 | Array<ARX*> BMsp; |
| 374 | //!parameter evolution |
| 375 | shared_ptr<fnc> g; |
| 376 | //!observation function |
| 377 | shared_ptr<fnc> h; |
| 378 | |
| 379 | public: |
| 380 | void bayes(const vec &yt, const vec &cond ); |
| 381 | void from_setting(const Setting &set) ; |
| 382 | void validate() { |
| 383 | bdm_assert(g->dimensionc()==g->dimension(),"not supported yet"); |
| 384 | bdm_assert(h->dimensionc()==g->dimension(),"not supported yet"); |
| 385 | } |
| 386 | |
| 387 | double logpred(const vec &cond) const NOT_IMPLEMENTED(0.0); |
| 388 | epdf* epredictor() const NOT_IMPLEMENTED(NULL); |
| 389 | pdf* predictor() const NOT_IMPLEMENTED(NULL); |
| 390 | const epdf& posterior() const {return pf->posterior();}; |
| 391 | |
| 392 | void log_register( logger &L, const string &prefix ){ |
| 393 | BM::log_register(L,prefix); |
| 394 | logrec->ids.set_size ( 3 ); |
| 395 | logrec->ids(1)= L.add_vector(RV("Q",dimension()*dimension()), prefix+L.prefix_sep()+"Q"); |
| 396 | logrec->ids(2)= L.add_vector(RV("R",dimensiony()*dimensiony()), prefix+L.prefix_sep()+"R"); |
| 397 | |
| 398 | }; |
| 399 | void log_write() const { |
| 400 | BM::log_write(); |
| 401 | mat mQ=zeros(dimension(),dimension()); |
| 402 | mat pom=zeros(dimension(),dimension()); |
| 403 | mat mR=zeros(dimensiony(),dimensiony()); |
| 404 | mat pom2=zeros(dimensiony(),dimensiony()); |
| 405 | mat dum; |
| 406 | const vec w=pf->posterior()._w(); |
| 407 | for (int i=0; i<w.length(); i++){ |
| 408 | BMsp(i)->posterior().mean_mat(dum,pom); |
| 409 | mQ += w(i) * pom; |
| 410 | BMso(i)->posterior().mean_mat(dum,pom2); |
| 411 | mR += w(i) * pom2; |
| 412 | |
| 413 | } |
| 414 | logrec->L.log_vector ( logrec->ids ( 1 ), cvectorize(mQ) ); |
| 415 | logrec->L.log_vector ( logrec->ids ( 2 ), cvectorize(mR) ); |
| 416 | |
| 417 | } |
| 418 | }; |
| 419 | UIREGISTER(MPF_ARXg); |
| 420 | |
| 421 | |