Changeset 267

Show
Ignore:
Timestamp:
02/11/09 14:15:05 (15 years ago)
Author:
smidl
Message:

samplecond modification

Files:
6 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/libPF.cpp

    r254 r267  
    1313        for ( i=0;i<n;i++ ) { 
    1414                //generate new samples from paramater evolution model; 
    15                 _samples ( i ) = par.samplecond ( _samples ( i ), lls ( i ) ); 
     15                _samples ( i ) = par.samplecond ( _samples ( i )); 
     16                lls(i )= par._e()->evallog(_samples(i)); 
    1617                lls ( i ) *= obs.evallogcond ( dt,_samples ( i ) ); 
    1718 
  • bdm/estim/libPF.h

    r262 r267  
    151151        for ( i=0;i<n;i++ ) {    
    152152                //generate new samples from paramater evolution model; 
    153                 _samples ( i ) = par.samplecond ( _samples ( i ), llsP ( i ) ); 
     153                _samples ( i ) = par.samplecond ( _samples ( i ) ); 
     154                llsP ( i ) = par._e()->evallog(_samples(i)); 
    154155                Bms[i]->condition ( _samples ( i ) ); 
    155156                Bms[i]->bayes ( dt ); 
  • bdm/stat/libBM.h

    r265 r267  
    234234        public: 
    235235 
    236                 //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv \param ll is a return value of log-likelihood of the sample. 
    237                 virtual vec samplecond ( const vec &cond, double &ll ) { 
     236                //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv  
     237                virtual vec samplecond ( const vec &cond) { 
    238238                        this->condition ( cond ); 
    239239                        vec temp= ep->sample(); 
    240                         ll=ep->evallog ( temp );return temp; 
     240                        return temp; 
    241241                }; 
    242242                //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv \param ll is a return value of log-likelihood of the sample. 
     
    298298 
    299299        */ 
    300  
    301         /*! 
    302         @brief Class for storing results (and semi-results) of an experiment 
    303  
    304         This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed. 
    305         */ 
    306         class logger : public bdmroot { 
    307         protected: 
    308                 //! RVs of all logged variables. 
    309                 Array<RV> entries; 
    310                 //! Names of logged quantities, e.g. names of algorithm variants 
    311                 Array<string> names; 
    312         public: 
    313                 //!Default constructor 
    314                 logger ( ) : entries ( 0 ),names ( 0 ) {} 
    315  
    316                 //! returns an identifier which will be later needed for calling the log() function 
    317                 virtual int add ( const RV &rv, string name="" ) { 
    318                         int id=entries.length(); 
    319                         names=concat ( names, name ); // diff 
    320                         entries.set_length ( id+1,true ); 
    321                         entries ( id ) = rv; 
    322                         return id; // identifier of the last entry 
    323                 } 
    324  
    325                 //! log this vector 
    326                 virtual void logit ( int id, const vec &v ) =0; 
    327  
    328                 //! Shifts storage position for another time step. 
    329                 virtual void step() =0; 
    330  
    331                 //! Finalize storing information 
    332                 virtual void finalize() {}; 
    333  
    334                 //! Initialize the storage 
    335                 virtual void init() {}; 
    336  
    337                 //! for future use 
    338                 virtual ~logger() {}; 
    339         }; 
    340  
    341300        class datalink_e2e { 
    342301        protected: 
     
    418377                //! Fill 
    419378 
     379        }; 
     380 
     381        /*! 
     382        @brief Class for storing results (and semi-results) of an experiment 
     383 
     384        This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed. 
     385         */ 
     386        class logger : public bdmroot { 
     387                protected: 
     388                //! RVs of all logged variables. 
     389                        Array<RV> entries; 
     390                //! Names of logged quantities, e.g. names of algorithm variants 
     391                        Array<string> names; 
     392                public: 
     393                //!Default constructor 
     394                        logger ( ) : entries ( 0 ),names ( 0 ) {} 
     395 
     396                //! returns an identifier which will be later needed for calling the log() function 
     397                        virtual int add ( const RV &rv, string name="" ) { 
     398                                int id=entries.length(); 
     399                                names=concat ( names, name ); // diff 
     400                                entries.set_length ( id+1,true ); 
     401                                entries ( id ) = rv; 
     402                                return id; // identifier of the last entry 
     403                        } 
     404 
     405                //! log this vector 
     406                        virtual void logit ( int id, const vec &v ) =0; 
     407 
     408                //! Shifts storage position for another time step. 
     409                        virtual void step() =0; 
     410 
     411                //! Finalize storing information 
     412                        virtual void finalize() {}; 
     413 
     414                //! Initialize the storage 
     415                        virtual void init() {}; 
     416 
     417                //! for future use 
     418                        virtual ~logger() {}; 
    420419        }; 
    421420 
  • bdm/stat/libDS.cpp

    r265 r267  
    4343 
    4444void ArxDS::step() { 
    45         double tmp; 
    4645        //shift history 
    4746        H.shift_right ( 0, Drv.count() +Urv.count() ); 
     
    5251        rgr = rgrlnk.get_val ( H ); 
    5352        // Eval Y 
    54         H.set_subvector ( 0, model.samplecond ( rgr,tmp ) ); 
     53        H.set_subvector ( 0, model.samplecond ( rgr ) ); 
    5554 
    5655} 
  • bdm/stat/libDS.h

    r265 r267  
    7373                int L_theta; 
    7474                int L_R; 
    75                 public: 
     75        public: 
    7676                void getdata ( vec &dt ) { 
    7777                        it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" ); 
     
    104104                        mat &A =model._A(); 
    105105                        mat R =model._R(); 
    106                         if ( opt_L_theta ) {L_theta=L.add ( RV("{theta }", vec_1(A.rows() *A.cols())),"t" );} 
    107                         if ( opt_L_theta ) {L_R=L.add ( RV("{R }", vec_1(R.rows() *R.cols())),"r" );} 
     106                        if ( opt_L_theta ) {L_theta=L.add ( RV ( "{theta }", vec_1 ( A.rows() *A.cols() ) ),"t" );} 
     107                        if ( opt_L_theta ) {L_R=L.add ( RV ( "{R }", vec_1 ( R.rows() *R.cols() ) ),"r" );} 
    108108                } 
    109109                virtual void logit ( logger &L ) { 
     
    126126 
    127127        }; 
     128 
     129        class stateDS : public DS { 
     130        protected: 
     131                //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$ 
     132                mpdf* IM; 
     133                //!conditional pdf of the observations \f$ f(d_t|x_t) \f$ 
     134                mpdf* OM; 
     135                //! result storage 
     136                vec dt; 
     137                //! state storage 
     138                vec xt; 
     139                //! input storage 
     140                vec ut; 
     141                //! Logger 
     142                int L_xt; 
     143        public: 
     144                void getdata ( vec &dt0 ) {dt0=dt;} 
     145                void getdata ( vec &dt0, const ivec &indeces ) {dt0=dt ( indeces );} 
     146 
     147                stateDS ( mpdf* IM0, mpdf* OM0, RV &Urv0 ) :DS ( OM0->_rv(),Urv0 ),IM ( IM0 ),OM ( OM0 ), 
     148                                dt ( OM0->_rv().count() ), xt ( IM0->_rv().count() ), ut ( Urv0.count() ) {} 
     149                ~stateDS() {delete IM; delete OM;} 
     150                virtual void step() { 
     151                        double tmp; 
     152                        xt=IM->samplecond(concat ( xt,ut )); 
     153                        dt=OM->samplecond(concat ( xt,ut )); 
     154                }; 
     155                 
     156                virtual void log_add ( logger &L ) { 
     157                        DS::log_add ( L ); 
     158                        L_xt=L.add(IM->_rv(),"true"); 
     159                } 
     160                virtual void logit ( logger &L ) { 
     161                        DS::logit ( L ); 
     162                        L.logit ( L_xt,xt); 
     163                } 
     164 
     165        }; 
     166 
    128167}; //namespace 
    129168 
  • pmsm/pmsm_mix.cpp

    r262 r267  
    9494        L.init(); 
    9595 
    96 double dum=0.0; 
    9796vec dumvec = vec_1(1.0); 
    98 vec z=  evolQR.samplecond(dumvec,dum) ; 
     97vec z=  evolQR.samplecond(dumvec) ; 
    9998cout << z << endl; 
    10099