Changeset 974
- Timestamp:
- 05/23/10 11:40:48 (15 years ago)
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/sandbox/mpf_arx_3.m
r971 r974 8 8 g.function = 'test_function'; 9 9 10 g.class = 'linfn';11 g.A = eye(2);12 g.B = [1;0];10 % g.class = 'linfn'; 11 % g.A = eye(2); 12 % g.B = [1;0]; 13 13 14 14 h.class = 'linfn'; … … 17 17 18 18 fx.class = 'mgnorm<chmat>'; 19 fx.R = [0. 3 -0.2; -0.2 0.5];19 fx.R = [0.03 -0.02; -0.02 0.05]; 20 20 fx.g = g; 21 21 fx.rv = x; … … 23 23 24 24 fy.class = 'mgnorm<chmat>'; 25 fy.R = 0. 1*eye(2);25 fy.R = 0.01*eye(2); 26 26 fy.g = h; 27 27 fy.rv = y; … … 39 39 A.class = 'ARX'; 40 40 A.yrv = RV('vw',4); 41 A.rv = RV('R',16); 41 42 A.rgr = RV({}); 42 43 A.dimx=4; 43 44 A.constant = 0; 44 A.frg=0.99; 45 A.frg=1.0; 46 A.prior.class='egiw'; 47 A.prior.dimx=4; 48 A.prior.V =1e-3*eye(4); 49 45 50 46 51 M.class = 'NoiseParticle'; 47 52 M.g = g; 48 53 M.h = h; 54 M.yrv = y; 49 55 M.rvx = x; 50 56 M.rvxc = RVtimes(x,-1); … … 54 60 PF.class='PF'; 55 61 PF.particle = M; 56 PF.n = 100 ;57 PF.res_threshold = 1.0;62 PF.n = 1000; 63 PF.res_threshold = 0.9; 58 64 PF.prior.class = 'enorm<ldmat>'; 59 65 PF.prior.mu = [0.2;0.3]; … … 61 67 62 68 63 exper.ndat = 200 0;69 exper.ndat = 200; 64 70 O = estimator(DS,{PF},exper); 65 71 %%%%%% ARX estimator conditioned on frg … … 69 75 figure(1); 70 76 hold off 71 plot(M.Est0_Q_Q); 72 hold on 73 plot(ones(size(M.Est0_Q_Q,1),1)* DS.pdf.pdfs{2}.R(:)','--'); 77 plot(O.Est0_apost_mean_R); 74 78 75 79 figure(2) 76 80 hold off 77 plot( M.Est0_apost_mean_);81 plot(O.Est0_apost_mean_x); 78 82 hold on 79 plot( M.DS_x,'--');83 plot(O.DS_dt_x,'--'); 80 84 -
library/bdm/estim/particles.h
r971 r974 43 43 bm = m2.bm->_copy(); 44 44 est_emp = m2.est_emp; 45 est.validate();; 45 46 validate(); 46 47 }; … … 66 67 void validate() { 67 68 BM::validate(); 69 //est.validate(); --pdfs not known 68 70 bdm_assert(bm,"Internal BM is not given"); 69 71 } … … 118 120 } 119 121 void validate(){ 122 MarginalizedParticleBase::validate(); 123 est_emp.set_rv(par->_rv()); 120 124 if (est_emp.point.length()!=par->dimension()) 121 125 est_emp.set_point(zeros(par->dimension())); … … 324 328 shared_ptr<BM> bm0 = UI::build<BM>(set, "particle",UI::compulsory); 325 329 326 shared_ptr<epdf> pri = UI::build<epdf> ( set, "prior", UI::compulsory );327 330 n =0; 328 331 UI::get(n,set,"n",UI::optional);; … … 332 335 w = ones(n)/n; 333 336 } 334 set_prior(pri.get());335 337 // set resampling method 336 338 resmethod_from_set ( set ); … … 435 437 436 438 if ( particles(0)->_rv()._dsize() > 0 ) { 437 bdm_assert ( particles(0)->_rv()._dsize() == est.dimension(), "Mismatch of RV and dimension of posterior" ); 439 bdm_assert ( particles(0)->_rv()._dsize() == est.dimension(), "Mismatch of RV " +particles(0)->_rv().to_string() + 440 " of size (" +num2str(particles(0)->_rv()._dsize())+"and dimension of posterior ("+num2str(est.dimension()) + ")" ); 438 441 } 439 442 } … … 445 448 for (int i = 0; i < n; i++ ) { 446 449 if ( ind ( i ) != i ) { 450 delete particles(i); 447 451 particles( i ) = particles( ind ( i ) )->_copy(); 448 452 } … … 453 457 Array<BM*>& _particles() { 454 458 return particles; 459 } 460 ~PF(){ 461 for (int i=0; i<particles.length(); i++){delete particles(i);} 455 462 } 456 463 … … 476 483 //! function transforming xt,ut -> yt 477 484 shared_ptr<fnc> h; // pdf for non-linear part 478 479 RV rvv;480 485 481 486 RV rvx; … … 493 498 494 499 public: 495 BM* _copy() const{return new NoiseParticle( );};500 BM* _copy() const{return new NoiseParticle(*this);}; 496 501 void bayes(const vec &dt, const vec &cond){ 497 epdf*pred_vw=bm->epredictor();498 shared_ptr<epdf> pred_v = pred_vw->marginal(rv v);502 shared_ptr<epdf> pred_vw=bm->epredictor(); 503 shared_ptr<epdf> pred_v = pred_vw->marginal(rvx); 499 504 500 505 vec vt=pred_v->sample(); … … 506 511 cond2g.filldown(cond,g_args); 507 512 vec xt = g->eval(g_args) + vt; 513 est_emp.point=xt; 508 514 509 515 // residue of observation … … 521 527 UI::get(g,set,"g",UI::compulsory); 522 528 UI::get(h,set,"h",UI::compulsory); 523 RV rvx;524 529 UI::get(rvx,set,"rvx",UI::compulsory); 525 530 est_emp.set_rv(rvx); 526 531 527 RV rvxc;528 532 UI::get(rvxc,set,"rvxc",UI::compulsory); 529 RV rvyc;530 533 UI::get(rvyc,set,"rvyc",UI::compulsory); 531 534 } 532 535 void validate(){ 533 536 MarginalizedParticleBase::validate(); 537 538 dimy = h->dimension(); 539 bm->set_yrv(concat(rvx,yrv)); 540 541 est_emp.set_rv(rvx); 542 est_emp.set_dim(rvx._dsize()); 543 est.validate(); 544 // 534 545 //check dimensions 535 rvc = rvxc ;546 rvc = rvxc.subt(rvx.copy_t(-1)); 536 547 rvc.add( rvyc); 537 rvc.subt(rvx); 538 548 rvc=rvc.subt(rvx); 549 550 bdm_assert(g->dimension()==rvx._dsize(),"rvx is not described"); 551 bdm_assert(g->dimensionc()==rvxc._dsize(),"rvxc is not described"); 552 bdm_assert(h->dimension()==rvyc._dsize(),"rvyc is not described"); 553 554 bdm_assert(bm->dimensiony()==g->dimension()+h->dimension(), 555 "Incompatible noise estimator of dimension " + 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 539 561 //establish datalinks 540 562 x2g.set_connection(rvxc, rvx.copy_t(-1));