Changeset 700 for library/bdm/estim

Show
Ignore:
Timestamp:
11/04/09 22:54:58 (15 years ago)
Author:
smidl
Message:

Making tutorial/userguide example work again (changes of mpdf and bayes)

Location:
library/bdm/estim
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/estim/arx.cpp

    r679 r700  
    22namespace bdm { 
    33 
    4         void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 
     4void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 
     5                 
     6        bdm_assert_debug(yt.length()>=dimy,"ARX::bayes yt is smaller then dimc");        
     7        bdm_assert_debug(cond.length()>=dimc,"ARX::bayes cond is smaller then dimc");    
    58        double lnc; 
    69        //cache 
  • library/bdm/estim/arx.h

    r679 r700  
    5454        //! \name Constructors 
    5555        //!@{ 
    56         ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ),  have_constant(true), dyad(), est() {}; 
    57         ARX ( const ARX &A0 ) : BMEF (A0.frg),  have_constant(A0.have_constant), dyad(A0.dyad),est(est) { }; 
     56        ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ),  have_constant(true), dyad(), est(), alter_est() {}; 
     57        ARX ( const ARX &A0 ) : BMEF (A0),  have_constant(A0.have_constant), dyad(A0.dyad),est(A0.est),alter_est(A0.alter_est) { }; 
    5858        ARX* _copy_() const; 
    5959        void set_parameters ( double frg0 ) { 
     
    167167/*! ARX model conditined by knowledge of the forgetting factor 
    168168\f[ f(\theta| d_1 \ldots d_t , \phi_t) \f] 
     169 
     170The symbol \f$ \phi \f$ is assumed to be the last of the conditioning variables. 
    169171*/ 
    170172class ARXfrg : public ARX{ 
     
    174176                ARXfrg(const ARXfrg &A0):ARX(A0){}; 
    175177                ARXfrg* _copy_() const {ARXfrg *A = new ARXfrg(*this); return A;} 
    176         void condition(const vec &val){ 
    177                 frg = val(0); 
     178 
     179        void bayes(const vec &val, const vec &cond){ 
     180                frg = cond(dimc-1); //  last in cond is phi 
     181                ARX::bayes(val,cond); 
     182        } 
     183        void validate() { 
     184                ARX::validate(); 
     185                rvc.add(RV("{phi }",vec_1(1))); 
     186                dimc +=1; 
    178187        } 
    179188}; 
  • library/bdm/estim/particles.cpp

    r679 r700  
    7878        int n=pf->__w().length(); 
    7979        vec &lls = pf->_lls(); 
     80        Array<vec> &samples=pf->__samples(); 
    8081         
    8182        // generate samples - time step 
     
    8485        #pragma parallel for 
    8586        for ( i = 0; i < n; i++ ) { 
    86                 BMs(i) -> bayes(this2bm.pushdown(yt), this2bm.get_cond(yt,cond)); 
     87                vec bm_cond(BMs(i)->dimensionc()); 
     88                this2bm.fill_cond(yt,cond, bm_cond); 
     89                pf2bm.filldown(samples(i), bm_cond); 
     90                BMs(i) -> bayes(this2bm.pushdown(yt), bm_cond); 
    8791                lls ( i ) += BMs(i)->_ll(); 
    8892        } 
  • library/bdm/estim/particles.h

    r693 r700  
    157157                        res_threshold=0.5; 
    158158                } 
    159                 validate(); 
     159                //validate(); 
    160160        } 
    161161        //! load prior information from set and set internal structures accordingly 
     
    177177         
    178178        void validate(){ 
     179                bdm_assert(par,"PF::parameter_pdf not specified."); 
    179180                n=_w.length(); 
    180181                lls=zeros(n); 
     182                 
    181183                if (par->_rv()._dsize()>0) { 
    182184                        bdm_assert(par->_rv()._dsize()==est.dimension(),"Mismatch of RV and dimension of posterior" ); 
     
    301303        //! datalink from global yt and cond (Up) to PFs yt and cond (Down) 
    302304        datalink_m2m this2pf; 
     305        //!datalink from PF part to BM 
     306        datalink_part pf2bm; 
    303307         
    304308public: 
     
    367371                } 
    368372                //set drv 
     373                //??set_yrv(concat(BM0->_yrv(),u) ); 
     374                set_yrv(BM0->_yrv() ); 
     375                rvc = BM0->_rvc().subt(par->_rv()); 
    369376                //find potential input - what remains in rvc when we subtract rv 
    370                 RV u = par->_rvc().remove_time().subt( par->_rv() );             
    371                 set_yrv(concat(BM0->_yrv(),u) ); 
     377                RV u = par->_rvc().subt( par->_rv().copy_t(-1) );                
     378                rvc.add(u); 
     379                dimc = rvc._dsize(); 
    372380                validate(); 
    373381        } 
    374382        void validate(){ 
    375383                try{ 
    376                 pf->validate(); 
     384                        pf->validate(); 
    377385                } catch (std::exception &e){ 
    378386                        throw UIException("Error in PF part of MPF:"); 
     
    380388                jest.read_parameters(); 
    381389                this2bm.set_connection(BMs(0)->_yrv(), BMs(0)->_rvc(), yrv, rvc); 
    382                 this2bm.set_connection(pf->_yrv(), pf->_rvc(), yrv, rvc); 
     390                this2pf.set_connection(pf->_yrv(), pf->_rvc(), yrv, rvc); 
     391                pf2bm.set_connection(BMs(0)->_rvc(), pf->posterior()._rv()); 
    383392        } 
    384393