Changeset 695 for library/bdm/base/datasources.h
- Timestamp:
- 11/03/09 00:03:19 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/datasources.h
r693 r695 304 304 305 305 //! State-space data source simulating two densities 306 class stateDS : public DS {307 pr ivate:306 class StateDS : public DS { 307 protected: 308 308 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$ 309 shared_ptr< pdf> IM;309 shared_ptr<mpdf> IM; 310 310 311 311 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$ 312 shared_ptr<pdf> OM; 313 314 protected: 312 shared_ptr<mpdf> OM; 313 315 314 //! result storage 316 315 vec dt; … … 319 318 //! input storage 320 319 vec ut; 321 //! Logger 322 int L_xt; 323 324 public: 325 void getdata ( vec &dt0 ) { 320 321 //! datalink from ut to IM.rvc 322 datalink_part u2imc; 323 //! datalink from ut to OM.rvc 324 datalink_part u2omc; 325 public: 326 void getdata ( vec &dt0 ) const { 326 327 dt0 = dt; 327 328 } 328 329 void write (const vec &ut0 ) { 330 ut = ut0; 331 } 332 329 333 void getdata ( vec &dt0, const ivec &indices ) { 330 334 dt0 = dt ( indices ); 331 335 } 332 //! convenience constructor333 stateDS ( const shared_ptr<pdf> &IM0, const shared_ptr<pdf> &OM0, int usize ) : IM ( IM0 ), OM ( OM0 ),334 dt ( OM0->dimension() ), xt ( IM0->dimension() ),335 ut ( usize ), L_xt ( 0 ) { }336 337 stateDS() : L_xt ( 0 ) { }338 336 339 337 virtual void step() { 340 xt = IM->samplecond ( concat ( xt, ut ) ); 341 dt = OM->samplecond ( concat ( xt, ut ) ); 342 } 343 344 virtual void log_register(logger &L, const string &prefix){ 345 DS::log_register ( L, prefix ); //ids 0 and 1 338 vec imc(IM->dimensionc()); 339 imc.set_subvector(0,xt); 340 u2imc.filldown(ut,imc); 341 xt = IM->samplecond ( imc ); 346 342 347 logrec->ids.set_size(3,true);//copy 348 logrec->ids(2)=logrec->L.add ( IM->_rv(), "true" ); 349 } 350 virtual void log_write () { 351 DS::log_write ( ); 352 logrec->L.logit ( logrec->ids(2), xt ); 353 } 343 vec omc(OM->dimensionc()); 344 omc.set_subvector(0,xt); 345 u2omc.filldown(ut,omc); 346 vec yt; 347 yt = OM->samplecond ( omc ); 348 //fill all data 349 dt.set_subvector(0,yt); 350 dt.set_subvector(yt.length(),xt); 351 dt.set_subvector(ytsize,ut); 352 } 353 354 //! set parameters 355 void set_parameters(shared_ptr<mpdf> IM0, shared_ptr<mpdf> OM0){ 356 IM=IM0; 357 OM = OM0; 358 } 359 void set_initx(const vec &x0){xt=x0;} 354 360 355 361 /*! UI for stateDS … … 357 363 The DS is constructed from a structure with fields: 358 364 \code 359 system = { 360 type = "stateDS"; 361 //Internal model 362 IM = { type = "pdf"; //<-- valid offspring! e.g. "mlnorm" 363 rv = { //description of x_t 364 names=["name1",...]; 365 sizes=[2,1]; // optional default=[1,1...]; 366 times=[0,0]; // optional default=[0,0...]; 367 } 368 rvu= { //description of u_t 369 //optional default=empty 370 } 371 372 // remaining fields depending on the chosen type 373 }; 374 //Observation model 375 OM = { type = "pdf-offspring"; 376 rv = {}; //description of d_t 377 rvu = {type="internal", path="system.IM.rvu"}; //description of u_t 378 379 //remaining fields 380 } 381 }; 382 \endcode 365 class = "stateDS"; 366 //Internal model 367 IM = { type = "mpdf-offspring"; }; 368 //Observation model 369 OM = { type = "mpdf-offspring"; } 370 //initial state 371 x0 = [...]; //vector of data 372 \endcode 373 Both models must have defined \c rv. and \c rvc 374 Random variables not found in any rv are considered to be inputs. 383 375 */ 384 376 void from_setting ( const Setting &set ); … … 386 378 // TODO dodelat void to_setting( Setting &set ) const; 387 379 388 }; 389 390 UIREGISTER ( stateDS ); 391 SHAREDPTR ( stateDS ); 380 void validate(); 381 }; 382 383 UIREGISTER ( StateDS ); 384 SHAREDPTR ( StateDS ); 392 385 393 386 }; //namespace