Changeset 267
- Timestamp:
- 02/11/09 14:15:05 (16 years ago)
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/estim/libPF.cpp
r254 r267 13 13 for ( i=0;i<n;i++ ) { 14 14 //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)); 16 17 lls ( i ) *= obs.evallogcond ( dt,_samples ( i ) ); 17 18 -
bdm/estim/libPF.h
r262 r267 151 151 for ( i=0;i<n;i++ ) { 152 152 //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)); 154 155 Bms[i]->condition ( _samples ( i ) ); 155 156 Bms[i]->bayes ( dt ); -
bdm/stat/libBM.h
r265 r267 234 234 public: 235 235 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) { 238 238 this->condition ( cond ); 239 239 vec temp= ep->sample(); 240 ll=ep->evallog ( temp );return temp;240 return temp; 241 241 }; 242 242 //! 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. … … 298 298 299 299 */ 300 301 /*!302 @brief Class for storing results (and semi-results) of an experiment303 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 variants311 Array<string> names;312 public:313 //!Default constructor314 logger ( ) : entries ( 0 ),names ( 0 ) {}315 316 //! returns an identifier which will be later needed for calling the log() function317 virtual int add ( const RV &rv, string name="" ) {318 int id=entries.length();319 names=concat ( names, name ); // diff320 entries.set_length ( id+1,true );321 entries ( id ) = rv;322 return id; // identifier of the last entry323 }324 325 //! log this vector326 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 information332 virtual void finalize() {};333 334 //! Initialize the storage335 virtual void init() {};336 337 //! for future use338 virtual ~logger() {};339 };340 341 300 class datalink_e2e { 342 301 protected: … … 418 377 //! Fill 419 378 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() {}; 420 419 }; 421 420 -
bdm/stat/libDS.cpp
r265 r267 43 43 44 44 void ArxDS::step() { 45 double tmp;46 45 //shift history 47 46 H.shift_right ( 0, Drv.count() +Urv.count() ); … … 52 51 rgr = rgrlnk.get_val ( H ); 53 52 // Eval Y 54 H.set_subvector ( 0, model.samplecond ( rgr ,tmp) );53 H.set_subvector ( 0, model.samplecond ( rgr ) ); 55 54 56 55 } -
bdm/stat/libDS.h
r265 r267 73 73 int L_theta; 74 74 int L_R; 75 75 public: 76 76 void getdata ( vec &dt ) { 77 77 it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" ); … … 104 104 mat &A =model._A(); 105 105 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" );} 108 108 } 109 109 virtual void logit ( logger &L ) { … … 126 126 127 127 }; 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 128 167 }; //namespace 129 168 -
pmsm/pmsm_mix.cpp
r262 r267 94 94 L.init(); 95 95 96 double dum=0.0;97 96 vec dumvec = vec_1(1.0); 98 vec z= evolQR.samplecond(dumvec ,dum) ;97 vec z= evolQR.samplecond(dumvec) ; 99 98 cout << z << endl; 100 99