Changeset 281 for bdm/estim/libPF.h

Show
Ignore:
Timestamp:
02/24/09 14:13:23 (15 years ago)
Author:
smidl
Message:

new version of mpf_test for TR2245

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/libPF.h

    r279 r281  
    3939        //! Observation model 
    4040        mpdf *obs; 
     41 
     42        //! \name Options 
     43        //!@{ 
     44 
     45        //! Log resampling times 
     46        bool opt_L_res; 
     47        //! Log all samples 
     48        bool opt_L_smp; 
     49        //!@} 
     50 
    4151public: 
    4252        //! \name Constructors 
    4353        //!@{ 
    4454        PF ( ) :est(), _w ( est._w() ),_samples ( est._samples() ) {}; 
    45         PF( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) : 
    46                         est ( ),_w ( est._w() ),_samples ( est._samples() )  
    47                         { par = par0; obs=obs0; est.set_parameters ( ones(n0),epdf0 ); }; 
    48         void set_parameters ( mpdf *par0, mpdf *obs0, int n0 )  
    49                         { par = par0; obs=obs0; n=n0; est.set_n(n);}; 
    50         void set_statistics (const vec w0, epdf *epdf0){est.set_parameters ( w0,epdf0 );}; 
     55        PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) : 
     56                        est ( ),_w ( est._w() ),_samples ( est._samples() ) 
     57        { set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); }; 
     58        void set_parameters ( mpdf *par0, mpdf *obs0, int n0 ) 
     59        { par = par0; obs=obs0; n=n0; est.set_n ( n );}; 
     60        void set_statistics ( const vec w0, epdf *epdf0 ) {est.set_parameters ( w0,epdf0 );}; 
    5161        //!@} 
    5262        //! Set posterior density by sampling from epdf0 
    5363        void set_est ( const epdf &epdf0 ); 
     64        void set_options(const string &opt){ 
     65                opt_L_res= ( s.find ( "logres" ) !=string::npos ); 
     66                opt_L_smp= ( s.find ( "logsmp" ) !=string::npos );               
     67        } 
    5468        void bayes ( const vec &dt ); 
    5569        //!access function 
     
    7690                Array<const epdf*> Coms; 
    7791        public: 
    78                 mpfepdf ( eEmp &E0) : 
     92                mpfepdf ( eEmp &E0 ) : 
    7993                                epdf ( ), E ( E0 ),  _w ( E._w() ), 
    8094                                Coms ( _w.length() ) { 
     
    8397                {_w ( i ) =wi; Coms ( i ) =ep;}; 
    8498 
    85                 void set_n(int n){E.set_n(n); Coms.set_length(n);} 
     99                void set_n ( int n ) {E.set_n ( n ); Coms.set_length ( n );} 
    86100                vec mean() const { 
    87101                        // ugly 
    88                         vec pom=zeros ( Coms(0)->dimension() ); 
     102                        vec pom=zeros ( Coms ( 0 )->dimension() ); 
    89103                        for ( int i=0; i<_w.length(); i++ ) {pom += Coms ( i )->mean() * _w ( i );} 
    90104                        return concat ( E.mean(),pom ); 
     
    93107                        // ugly 
    94108                        vec pom=zeros ( Coms ( 0 )->dimension() ); 
    95                         vec pom2=zeros (  Coms ( 0 )->dimension() ); 
     109                        vec pom2=zeros ( Coms ( 0 )->dimension() ); 
    96110                        for ( int i=0; i<_w.length(); i++ ) { 
    97111                                pom += Coms ( i )->mean() * _w ( i ); 
     
    106120        }; 
    107121 
    108         //! estimate joining PF.est with conditional 
     122        //! Density joining PF.est with conditional parts 
    109123        mpfepdf jest; 
    110124 
     125        //! Log means of BMs 
     126        bool opt_L_mea; 
     127         
    111128public: 
    112129        //! Default constructor. 
    113130        MPF ( mpdf *par0, mpdf *obs0, int n, const BM_T &BMcond0 ) : PF (), jest ( est ) { 
    114                 PF::set_parameters(par0,obs0,n); 
    115                 jest.set_n(n); 
     131                PF::set_parameters ( par0,obs0,n ); 
     132                jest.set_n ( n ); 
    116133                // 
    117134                //TODO test if rv and BMcond.rv are compatible. 
     
    141158                for ( int i=0;i<n;i++ ) {Bms[i]->condition ( _samples ( i ) );} 
    142159        } 
    143  
     160        void set_options(const string &opt){ 
     161                PF:set_options(opt); 
     162                opt_L_mea = ( s.find ( "logmeans" ) !=string::npos ); 
     163        } 
     164         
    144165        //!Access function 
    145166        BM* _BM ( int i ) {return Bms[i];}