- Timestamp:
- 05/23/10 11:40:48 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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));