Changeset 693 for library/bdm/base
- Timestamp:
- 11/02/09 17:27:29 (15 years ago)
- Location:
- library/bdm/base
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r690 r693 146 146 } 147 147 148 shared_ptr< mpdf> epdf::condition ( const RV &rv ) const {148 shared_ptr<pdf> epdf::condition ( const RV &rv ) const { 149 149 bdm_warning ( "Not implemented" ); 150 return shared_ptr< mpdf>();150 return shared_ptr<pdf>(); 151 151 } 152 152 … … 180 180 } 181 181 182 mat mpdf::samplecond_m ( const vec &cond, int N ) {182 mat pdf::samplecond_m ( const vec &cond, int N ) { 183 183 mat M ( dimension(), N ); 184 184 for ( int i = 0; i < N; i++ ) { … … 189 189 } 190 190 191 void mpdf::from_setting ( const Setting &set ) {191 void pdf::from_setting ( const Setting &set ) { 192 192 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 193 193 if ( r ) { … … 373 373 } 374 374 375 RV get_composite_rv ( const Array<shared_ptr< mpdf> > &mpdfs,375 RV get_composite_rv ( const Array<shared_ptr<pdf> > &pdfs, 376 376 bool checkoverlap ) { 377 377 RV rv; //empty rv 378 378 bool rvaddok; 379 for ( int i = 0; i < mpdfs.length(); i++ ) {380 rvaddok = rv.add ( mpdfs ( i )->_rv() ); //add rv to common rvs.381 // If rvaddok==false, mpdfs overlap => assert error.382 bdm_assert_debug ( rvaddok || !checkoverlap, "mprod::mprod() input mpdfs overlap in rv!" );379 for ( int i = 0; i < pdfs.length(); i++ ) { 380 rvaddok = rv.add ( pdfs ( i )->_rv() ); //add rv to common rvs. 381 // If rvaddok==false, pdfs overlap => assert error. 382 bdm_assert_debug ( rvaddok || !checkoverlap, "mprod::mprod() input pdfs overlap in rv!" ); 383 383 } 384 384 -
library/bdm/base/bdmbase.h
r690 r693 386 386 387 387 //! Conditional probability density, e.g. modeling \f$ f( x | y) \f$, where \f$ x \f$ is random variable, \c rv, and \f$ y \f$ is conditioning variable, \c rvc. 388 class mpdf : public root {388 class pdf : public root { 389 389 protected: 390 390 //!dimension of the condition … … 403 403 //! @{ 404 404 405 mpdf() : dimc ( 0 ), rvc(), dim(0), rv() { }406 407 mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim( m.dim), rv( m.rv ) { }405 pdf() : dimc ( 0 ), rvc(), dim(0), rv() { } 406 407 pdf ( const pdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim( m.dim), rv( m.rv ) { } 408 408 409 409 //! copy of the current object - make sure to implement 410 virtual mpdf* _copy_() const {return new mpdf(*this);}410 virtual pdf* _copy_() const {return new pdf(*this);} 411 411 //!@} 412 412 … … 467 467 //! Load from structure with elements: 468 468 //! \code 469 //! { class = " mpdf_offspring",469 //! { class = "pdf_offspring", 470 470 //! rv = {class="RV", names=(...),}; // RV describing meaning of random variable 471 471 //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition … … 491 491 //!@} 492 492 }; 493 SHAREDPTR ( mpdf );493 SHAREDPTR ( pdf ); 494 494 495 495 //! Probability density function with numerical statistics, e.g. posterior density. 496 class epdf : public mpdf {496 class epdf : public pdf { 497 497 498 498 public: … … 509 509 @{*/ 510 510 epdf() {}; 511 epdf ( const epdf &e ) : mpdf(e) {};511 epdf ( const epdf &e ) : pdf(e) {}; 512 512 void set_parameters ( int dim0 ) { 513 513 dim = dim0; … … 542 542 543 543 //! Return conditional density on the given RV, the remaining rvs will be in conditioning 544 virtual shared_ptr< mpdf> condition ( const RV &rv ) const;544 virtual shared_ptr<pdf> condition ( const RV &rv ) const; 545 545 546 546 //! Return marginal density on the given RV, the remainig rvs are intergrated out … … 633 633 SHAREDPTR ( epdf ); 634 634 635 //! Mpdf with internal epdf that is modified by function \c condition635 //! pdf with internal epdf that is modified by function \c condition 636 636 template <class EPDF> 637 class mpdf_internal: public mpdf {637 class pdf_internal: public pdf { 638 638 protected : 639 639 //! Internal epdf used for sampling … … 641 641 public: 642 642 //! constructor 643 mpdf_internal() : mpdf(), iepdf() {643 pdf_internal() : pdf(), iepdf() { 644 644 // set_ep ( iepdf ); TODO! 645 645 } 646 646 647 //! Update \c iepdf so that it represents this mpdf conditioned on \c rvc = cond647 //! Update \c iepdf so that it represents this pdf conditioned on \c rvc = cond 648 648 //! This function provides convenient reimplementation in offsprings 649 649 virtual void condition ( const vec &cond ) { … … 896 896 }; 897 897 898 //!DataLink is a connection between mpdf and its superordinate (Up)898 //!DataLink is a connection between pdf and its superordinate (Up) 899 899 //! This class links 900 900 class datalink_m2m: public datalink_m2e { … … 928 928 929 929 930 //! \brief Combines RVs from a list of mpdfs to a single one.931 RV get_composite_rv ( const Array<shared_ptr< mpdf> > &mpdfs, bool checkoverlap = false );930 //! \brief Combines RVs from a list of pdfs to a single one. 931 RV get_composite_rv ( const Array<shared_ptr<pdf> > &pdfs, bool checkoverlap = false ); 932 932 933 933 /*! \brief Abstract class for discrete-time sources of data. … … 1118 1118 }; 1119 1119 //!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$ 1120 virtual mpdf* predictor() const {1120 virtual pdf* predictor() const { 1121 1121 bdm_error ( "Not implemented" ); 1122 1122 return NULL; … … 1229 1229 //! array of pointers to epdf 1230 1230 typedef Array<shared_ptr<epdf> > epdf_array; 1231 //! array of pointers to mpdf1232 typedef Array<shared_ptr< mpdf> > mpdf_array;1231 //! array of pointers to pdf 1232 typedef Array<shared_ptr<pdf> > pdf_array; 1233 1233 1234 1234 template<class EPDF> 1235 vec mpdf_internal<EPDF>::samplecond ( const vec &cond ) {1235 vec pdf_internal<EPDF>::samplecond ( const vec &cond ) { 1236 1236 condition ( cond ); 1237 1237 vec temp = iepdf.sample(); … … 1240 1240 1241 1241 template<class EPDF> 1242 mat mpdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) {1242 mat pdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) { 1243 1243 condition ( cond ); 1244 1244 mat temp ( dimension(), N ); … … 1253 1253 1254 1254 template<class EPDF> 1255 double mpdf_internal<EPDF>::evallogcond ( const vec &yt, const vec &cond ) {1255 double pdf_internal<EPDF>::evallogcond ( const vec &yt, const vec &cond ) { 1256 1256 double tmp; 1257 1257 condition ( cond ); … … 1261 1261 1262 1262 template<class EPDF> 1263 vec mpdf_internal<EPDF>::evallogcond_m ( const mat &Yt, const vec &cond ) {1263 vec pdf_internal<EPDF>::evallogcond_m ( const mat &Yt, const vec &cond ) { 1264 1264 condition ( cond ); 1265 1265 return iepdf.evallog_m ( Yt ); … … 1267 1267 1268 1268 template<class EPDF> 1269 vec mpdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Yt, const vec &cond ) {1269 vec pdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Yt, const vec &cond ) { 1270 1270 condition ( cond ); 1271 1271 return iepdf.evallog_m ( Yt ); -
library/bdm/base/datasources.cpp
r676 r693 123 123 124 124 void stateDS::from_setting ( const Setting &set ) { 125 IM = UI::build< mpdf> ( set, "IM", UI::compulsory );126 OM = UI::build< mpdf> ( set, "OM", UI::compulsory );125 IM = UI::build<pdf> ( set, "IM", UI::compulsory ); 126 OM = UI::build<pdf> ( set, "OM", UI::compulsory ); 127 127 128 128 dt.set_length ( OM->dimension() ); -
library/bdm/base/datasources.h
r676 r693 145 145 Still having only one density but allowing conditioning on either input or delayed values. 146 146 */ 147 class MpdfDS :public DS {147 class PdfDS :public DS { 148 148 protected: 149 149 //! internal pointer to epdf from which we samplecond 150 shared_ptr< mpdf> impdf;150 shared_ptr<pdf> ipdf; 151 151 //! internal storage of data sample 152 152 vec yt; … … 165 165 ut2rgr.filldown ( ut,rgr ); 166 166 yt2rgr.filldown ( yt,rgr ); 167 yt=i mpdf->samplecond ( rgr );167 yt=ipdf->samplecond ( rgr ); 168 168 ut2rgr.step(ut); //u is now history 169 169 } … … 177 177 /*! 178 178 \code 179 class = " MpdfDS";180 mpdf = {class="mpdf_offspring", ...}; // mpdf to simulate179 class = "PdfDS"; 180 pdf = {class="pdf_offspring", ...}; // pdf to simulate 181 181 --- optional --- 182 182 init_rv = {class="RV",names=...}; // define what rv to initialize - typically delayed values! … … 187 187 */ 188 188 void from_setting ( const Setting &set ) { 189 i mpdf=UI::build<mpdf> ( set,"mpdf",UI::compulsory );189 ipdf=UI::build<pdf> ( set,"pdf",UI::compulsory ); 190 190 191 Yrv = i mpdf->_rv();191 Yrv = ipdf->_rv(); 192 192 // get unique rvs form rvc 193 RV rgrv0=i mpdf->_rvc().remove_time();193 RV rgrv0=ipdf->_rvc().remove_time(); 194 194 // input is what in not in Yrv 195 195 Urv=rgrv0.subt(Yrv); 196 196 set_drv(Yrv, Urv); 197 197 // connect input and output to rvc 198 ut2rgr.set_connection(i mpdf->_rvc(), Urv);199 yt2rgr.set_connection(i mpdf->_rvc(), Yrv);198 ut2rgr.set_connection(ipdf->_rvc(), Urv); 199 yt2rgr.set_connection(ipdf->_rvc(), Yrv); 200 200 201 201 //set history - if given … … 212 212 } 213 213 214 yt = zeros ( i mpdf->dimension() );215 rgr = zeros ( i mpdf->dimensionc() );214 yt = zeros ( ipdf->dimension() ); 215 rgr = zeros ( ipdf->dimensionc() ); 216 216 ut = zeros(Urv._dsize()); 217 217 … … 225 225 ut2rgr.filldown ( ut,rgr ); 226 226 yt2rgr.filldown ( yt,rgr ); 227 yt=i mpdf->samplecond ( rgr );228 } 229 }; 230 UIREGISTER ( MpdfDS );227 yt=ipdf->samplecond ( rgr ); 228 } 229 }; 230 UIREGISTER ( PdfDS ); 231 231 232 232 /*! Pseudovirtual class for reading data from files … … 307 307 private: 308 308 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$ 309 shared_ptr< mpdf> IM;309 shared_ptr<pdf> IM; 310 310 311 311 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$ 312 shared_ptr< mpdf> OM;312 shared_ptr<pdf> OM; 313 313 314 314 protected: … … 331 331 } 332 332 //! convenience constructor 333 stateDS ( const shared_ptr< mpdf> &IM0, const shared_ptr<mpdf> &OM0, int usize ) : IM ( IM0 ), OM ( OM0 ),333 stateDS ( const shared_ptr<pdf> &IM0, const shared_ptr<pdf> &OM0, int usize ) : IM ( IM0 ), OM ( OM0 ), 334 334 dt ( OM0->dimension() ), xt ( IM0->dimension() ), 335 335 ut ( usize ), L_xt ( 0 ) { } … … 360 360 type = "stateDS"; 361 361 //Internal model 362 IM = { type = " mpdf"; //<-- valid offspring! e.g. "mlnorm"362 IM = { type = "pdf"; //<-- valid offspring! e.g. "mlnorm" 363 363 rv = { //description of x_t 364 364 names=["name1",...]; … … 373 373 }; 374 374 //Observation model 375 OM = { type = " mpdf-offspring";375 OM = { type = "pdf-offspring"; 376 376 rv = {}; //description of d_t 377 377 rvu = {type="internal", path="system.IM.rvu"}; //description of u_t