Show
Ignore:
Timestamp:
05/23/10 11:40:48 (14 years ago)
Author:
smidl
Message:

Noise Particle

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/estim/particles.h

    r971 r974  
    4343                        bm = m2.bm->_copy(); 
    4444                        est_emp = m2.est_emp; 
     45                        est.validate();; 
    4546                        validate(); 
    4647                }; 
     
    6667                void validate() { 
    6768                        BM::validate(); 
     69                        //est.validate(); --pdfs not known 
    6870                        bdm_assert(bm,"Internal BM is not given"); 
    6971                } 
     
    118120                } 
    119121                void validate(){ 
     122                        MarginalizedParticleBase::validate(); 
     123                        est_emp.set_rv(par->_rv()); 
    120124                        if (est_emp.point.length()!=par->dimension()) 
    121125                                est_emp.set_point(zeros(par->dimension())); 
     
    324328                shared_ptr<BM> bm0 = UI::build<BM>(set, "particle",UI::compulsory); 
    325329                 
    326                 shared_ptr<epdf> pri = UI::build<epdf> ( set, "prior", UI::compulsory ); 
    327330                n =0; 
    328331                UI::get(n,set,"n",UI::optional);; 
     
    332335                        w = ones(n)/n; 
    333336                } 
    334                 set_prior(pri.get()); 
    335337                // set resampling method 
    336338                resmethod_from_set ( set ); 
     
    435437 
    436438                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()) + ")" ); 
    438441                } 
    439442        } 
     
    445448                for (int i = 0; i < n; i++ ) { 
    446449                        if ( ind ( i ) != i ) { 
     450                                delete particles(i); 
    447451                                particles( i ) = particles( ind ( i ) )->_copy(); 
    448452                        } 
     
    453457        Array<BM*>& _particles() { 
    454458                return particles; 
     459        } 
     460        ~PF(){ 
     461                for (int i=0; i<particles.length(); i++){delete particles(i);} 
    455462        } 
    456463 
     
    476483                //! function transforming xt,ut -> yt 
    477484                shared_ptr<fnc> h; // pdf for non-linear part 
    478  
    479                 RV rvv; 
    480485                 
    481486                RV rvx; 
     
    493498                 
    494499        public: 
    495                 BM* _copy() const{return new NoiseParticle();}; 
     500                BM* _copy() const{return new NoiseParticle(*this);}; 
    496501                void bayes(const vec &dt, const vec &cond){ 
    497                         epdf* pred_vw=bm->epredictor(); 
    498                         shared_ptr<epdf> pred_v = pred_vw->marginal(rvv); 
     502                        shared_ptr<epdf> pred_vw=bm->epredictor(); 
     503                        shared_ptr<epdf> pred_v = pred_vw->marginal(rvx); 
    499504                         
    500505                        vec vt=pred_v->sample(); 
     
    506511                        cond2g.filldown(cond,g_args); 
    507512                        vec xt = g->eval(g_args) + vt; 
     513                        est_emp.point=xt; 
    508514                         
    509515                        // residue of observation 
     
    521527                        UI::get(g,set,"g",UI::compulsory); 
    522528                        UI::get(h,set,"h",UI::compulsory); 
    523                         RV rvx; 
    524529                        UI::get(rvx,set,"rvx",UI::compulsory); 
    525530                        est_emp.set_rv(rvx); 
    526531                         
    527                         RV rvxc; 
    528532                        UI::get(rvxc,set,"rvxc",UI::compulsory); 
    529                         RV rvyc; 
    530533                        UI::get(rvyc,set,"rvyc",UI::compulsory); 
    531534                } 
    532535                void validate(){ 
    533536                        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                        //  
    534545                        //check dimensions 
    535                         rvc = rvxc; 
     546                        rvc = rvxc.subt(rvx.copy_t(-1)); 
    536547                        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                                         
    539561                        //establish datalinks 
    540562                        x2g.set_connection(rvxc, rvx.copy_t(-1));