Changeset 675
- Timestamp:
- 10/21/09 20:19:40 (15 years ago)
- Location:
- library
- Files:
-
- 15 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r624 r675 373 373 } 374 374 375 void mepdf::from_setting ( const Setting &set ) {376 shared_ptr<epdf> e ( UI::build<epdf> ( set, "epdf", UI::compulsory ) );377 iepdf = e;378 set_ep ( iepdf.get() );379 }380 381 375 RV get_composite_rv ( const Array<shared_ptr<mpdf> > &mpdfs, 382 376 bool checkoverlap ) { -
library/bdm/base/bdmbase.h
r665 r675 326 326 }; 327 327 328 class mpdf; 328 class epdf; 329 330 //! 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. 331 class mpdf : public root { 332 protected: 333 //!dimension of the condition 334 int dimc; 335 //! random variable in condition 336 RV rvc; 337 338 //! TODO 339 int dim; 340 341 //! TODO 342 RV rv; 343 344 public: 345 //! \name Constructors 346 //! @{ 347 348 mpdf() : dimc ( 0 ), rvc(), dim(0), rv() { } 349 350 mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), rv( m.rv ), dim( m.dim) { } 351 //!@} 352 353 //! \name Matematical operations 354 //!@{ 355 356 //! 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 357 virtual vec samplecond ( const vec &cond ) { 358 bdm_error ( "Not implemented" ); 359 return vec(); 360 } 361 362 //! 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 363 virtual mat samplecond_m ( const vec &cond, int N ); 364 365 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. 366 virtual double evallogcond ( const vec &dt, const vec &cond ) { 367 bdm_error ( "Not implemented" ); 368 return 0.0; 369 } 370 371 //! Matrix version of evallogcond 372 virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) { 373 vec v ( Dt.cols() ); 374 for ( int i = 0; i < Dt.cols(); i++ ) { 375 v ( i ) = evallogcond ( Dt.get_col ( i ), cond ); 376 } 377 return v; 378 } 379 380 //! Array<vec> version of evallogcond 381 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) { 382 bdm_error ( "Not implemented" ); 383 return vec(); 384 } 385 386 //! \name Access to attributes 387 //! @{ 388 389 const RV& _rv() const { 390 return rv; 391 } 392 const RV& _rvc() const { 393 return rvc; 394 } 395 396 int dimension() const { 397 return dim; 398 } 399 int dimensionc() { 400 return dimc; 401 } 402 403 //! Load from structure with elements: 404 //! \code 405 //! { class = "mpdf_offspring", 406 //! rv = {class="RV", names=(...),}; // RV describing meaning of random variable 407 //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition 408 //! // elements of offsprings 409 //! } 410 //! \endcode 411 //!@} 412 void from_setting ( const Setting &set ); 413 //!@} 414 415 //! \name Connection to other objects 416 //!@{ 417 void set_rvc ( const RV &rvc0 ) { 418 rvc = rvc0; 419 } 420 void set_rv ( const RV &rv0 ) { 421 rv = rv0; 422 } 423 424 bool isnamed() { 425 return ( dim == rv._dsize() ) && ( dimc == rvc._dsize() ); 426 } 427 //!@} 428 }; 429 SHAREDPTR ( mpdf ); 329 430 330 431 //! Probability density function with numerical statistics, e.g. posterior density. 331 332 class epdf : public root { 432 class epdf : public mpdf { 333 433 protected: 334 434 //! dimension of the random variable … … 456 556 } 457 557 558 559 /*! \brief Unconditional mpdf, allows using epdf in the role of mpdf. 560 561 */ 562 563 564 /// MEPDF BEGINS HERE TODO 565 //! empty 566 vec samplecond ( const vec &cond ) { 567 return sample(); 568 } 569 double evallogcond ( const vec &val, const vec &cond ) { 570 return evallog ( val ); 571 } 458 572 }; 459 573 SHAREDPTR ( epdf ); 460 461 //! 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.462 class mpdf : public root {463 protected:464 //!dimension of the condition465 int dimc;466 //! random variable in condition467 RV rvc;468 private:469 //! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension()470 epdf* ep;471 472 protected:473 //! set internal pointer \c ep to point to given \c iepdf474 void set_ep ( epdf &iepdf ) {475 ep = &iepdf;476 }477 //! set internal pointer \c ep to point to given \c iepdf478 void set_ep ( epdf *iepdfp ) {479 ep = iepdfp;480 }481 482 public:483 //! \name Constructors484 //! @{485 486 mpdf() : dimc ( 0 ), rvc(), ep ( NULL ) { }487 488 mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), ep ( m.ep ) { }489 //!@}490 491 //! \name Matematical operations492 //!@{493 494 //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv495 virtual vec samplecond ( const vec &cond ) {496 bdm_error ( "Not implemented" );497 return vec();498 }499 500 //! 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 rv501 virtual mat samplecond_m ( const vec &cond, int N );502 503 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently.504 virtual double evallogcond ( const vec &dt, const vec &cond ) {505 bdm_error ( "Not implemented" );506 return 0.0;507 }508 509 //! Matrix version of evallogcond510 virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {511 vec v ( Dt.cols() );512 for ( int i = 0; i < Dt.cols(); i++ ) {513 v ( i ) = evallogcond ( Dt.get_col ( i ), cond );514 }515 return v;516 }517 518 //! Array<vec> version of evallogcond519 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {520 bdm_error ( "Not implemented" );521 return vec();522 }523 524 //! \name Access to attributes525 //! @{526 527 const RV& _rv() const {528 return ep->_rv();529 }530 const RV& _rvc() const {531 return rvc;532 }533 534 int dimension() const {535 return ep->dimension();536 }537 int dimensionc() {538 return dimc;539 }540 541 //! Load from structure with elements:542 //! \code543 //! { class = "mpdf_offspring",544 //! rv = {class="RV", names=(...),}; // RV describing meaning of random variable545 //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition546 //! // elements of offsprings547 //! }548 //! \endcode549 //!@}550 void from_setting ( const Setting &set );551 //!@}552 553 //! \name Connection to other objects554 //!@{555 void set_rvc ( const RV &rvc0 ) {556 rvc = rvc0;557 }558 void set_rv ( const RV &rv0 ) {559 ep->set_rv ( rv0 );560 }561 bool isnamed() {562 return ( ep->isnamed() ) && ( dimc == rvc._dsize() );563 }564 //!@}565 };566 SHAREDPTR ( mpdf );567 574 568 575 //! Mpdf with internal epdf that is modified by function \c condition … … 575 582 //! constructor 576 583 mpdf_internal() : mpdf(), iepdf() { 577 set_ep ( iepdf ); 584 // set_ep ( iepdf ); TODO! 578 585 } 579 586 … … 906 913 }; 907 914 908 /*! \brief Unconditional mpdf, allows using epdf in the role of mpdf.909 910 */911 class mepdf : public mpdf {912 //! Internal shared pointer to epdf913 shared_ptr<epdf> iepdf;914 public:915 //!Default constructor916 mepdf() { }917 //! Set internal shared pointer918 mepdf ( shared_ptr<epdf> em ) {919 iepdf = em;920 set_ep ( *iepdf.get() );921 dimc = 0;922 }923 924 //! empty925 vec samplecond ( const vec &cond ) {926 return iepdf->sample();927 }928 double evallogcond ( const vec &val, const vec &cond ) {929 return iepdf->evallog ( val );930 }931 932 //! Load from structure with elements:933 //! \code934 //! { class = "mepdf",935 //! epdf = {class="epdf_offspring",...}936 //! }937 //! \endcode938 //!@}939 void from_setting ( const Setting &set );940 };941 UIREGISTER ( mepdf );942 SHAREDPTR ( mepdf );943 915 944 916 //! \brief Combines RVs from a list of mpdfs to a single one. … … 1209 1181 if ( LFlags ( 3 ) ) LIDs ( 3 ) = L.add ( RV ( "ll", 1 ), name ); //TODO: "local" RV 1210 1182 } 1211 //! Save results to the given logger, details of what is stored is configured by \c LIDs and \c options1212 1183 virtual void logit ( logger &L ) { 1213 1184 L.logit ( LIDs ( 0 ), posterior().mean() ); -
library/bdm/estim/kalman.h
r660 r675 214 214 */ 215 215 void bayes (const vec &dt); 216 216 217 217 void from_setting(const Setting &set){ 218 218 Kalman<chmat>::from_setting(set); -
library/bdm/estim/particles.h
r665 r675 389 389 } 390 390 } 391 391 392 392 }; 393 393 UIREGISTER(MPF); -
library/bdm/stat/emix.cpp
r620 r675 207 207 dls.set_size ( mFacs.length() ); 208 208 209 set_ep ( iepdf); 210 RV rv = get_composite_rv ( mpdfs, true ); 211 set_rv ( rv ); 212 iepdf.set_parameters ( rv._dsize() ); 209 rv = get_composite_rv ( mpdfs, true ); 210 dim = rv._dsize(); 213 211 214 212 for ( int i = 0; i < mpdfs.length(); i++ ) { -
library/bdm/stat/emix.h
r660 r675 47 47 //!datalink between conditional and nom 48 48 datalink_m2e dl; 49 //! dummy epdf that stores only rv and dim50 epdf iepdf;51 49 public: 52 50 //!Default constructor. By default, the given epdf is not copied! 53 51 //! It is assumed that this function will be used only temporarily. 54 mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ) ,iepdf(){52 mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ) { 55 53 // adjust rv and rvc 54 55 set_rv( rv ); // TODO co kdyby tohle samo uz nastavovalo dimension?!?! 56 dim = rv._dsize(); 57 56 58 rvc = nom0->_rv().subt ( rv ); 57 59 dimc = rvc._dsize(); 58 set_ep ( iepdf ); 59 iepdf.set_parameters ( rv._dsize() ); 60 iepdf.set_rv ( rv ); 61 60 62 61 //prepare data structures 63 62 if ( copy ) { … … 74 73 dl.set_connection ( rv, rvc, nom0->_rv() ); 75 74 }; 75 76 76 double evallogcond ( const vec &val, const vec &cond ) { 77 77 double tmp; … … 469 469 //!weights of the components 470 470 vec w; 471 //! dummy epdfs472 epdf dummy_epdf;473 471 public: 474 472 //!Default constructor 475 mmix() : Coms(0) , dummy_epdf() { set_ep(dummy_epdf);}473 mmix() : Coms(0) { } 476 474 477 475 //! Set weights \c w and components \c R … … 483 481 if (Coms0.length()>0){ 484 482 set_rv(Coms(0)->_rv()); 485 d ummy_epdf.set_parameters(Coms(0)->_rv()._dsize());483 dim = rv._dsize(); 486 484 set_rvc(Coms(0)->_rvc()); 487 485 dimc = rvc._dsize(); -
library/tests/epdf_harness.cpp
r598 r675 71 71 mpdf_array aa ( 2 ); 72 72 aa ( 0 ) = c; 73 aa ( 1 ) = new mepdf ( m );73 aa ( 1 ) = m; 74 74 mprod mEp ( aa ); 75 75 -
library/tests/mepdf.cfg
r489 r675 3 3 class = "mpdf_harness"; 4 4 mpdf = { 5 class = "mepdf";6 epdf = {7 5 class = "enorm<ldmat>"; 8 6 mu = [ 1.1, -1.0 ]; … … 13 11 names = ( "x", "y" ); 14 12 }; 15 };16 13 }; 17 14 cond = [ 1.5, 1.7 ]; -
library/tests/merger.cfg
r562 r675 1 1 Sources = ( 2 2 { 3 class = "mepdf";4 epdf :5 {6 3 class = "enorm<ldmat>"; 7 4 mu = ( "matrix", 1, 2, [ 0.0, 2.0 ] ); … … 12 9 names = ( "a", "b" ); 13 10 }; 14 };15 11 }, 16 12 { 17 class = "mepdf";18 epdf :19 {20 13 class = "egiw"; 21 14 V = ( "matrix", 2, 2, [ 20.0, 8.0, 8.0, 4.0 ] ); … … 27 20 names = ( "a", "b" ); 28 21 }; 29 };30 22 } ); 31 23 Support : -
library/tests/merger_2d_test.cpp
r529 r675 32 32 33 33 mpdf_array A ( 2 ); 34 mepdf_ptr A1 = new mepdf ( f1 ); 35 mepdf_ptr A2 = new mepdf ( f2 ); 36 A ( 0 ) = A1; 37 A ( 1 ) = A2; 34 A ( 0 ) = f1; 35 A ( 1 ) = f2; 38 36 39 37 int Npoints = 100; -
library/tests/merger_error.cfg
r562 r675 1 1 Sources = ( 2 2 { 3 class = "mepdf";4 epdf :5 {6 3 class = "enorm<ldmat>"; 7 4 mu = ( "matrix", 1, 2, [ 0.0, 2.0 ] ); … … 12 9 names = ( "a", "b" ); 13 10 }; 14 };15 11 }, 16 12 { 17 class = "mepdf";18 epdf :19 {20 13 class = "egiw"; 21 14 V = ( "matrix", 2, 2, [ 20.0, 8.0, 8.0, 4.0 ] ); … … 27 20 names = ( "a", "b" ); 28 21 }; 29 };30 22 } ); 31 23 Support : -
library/tests/merger_iter_test.cpp
r529 r675 33 33 34 34 mpdf_array A ( 3 ); 35 A ( 0 ) = new mepdf ( f1 );36 A ( 1 ) = new mepdf ( f2 );37 A ( 2 ) = new mepdf ( f3 );35 A ( 0 ) = f1; 36 A ( 1 ) = f2; 37 A ( 2 ) = f3; 38 38 39 39 int Npoints = 100; -
library/tests/merger_test.cpp
r562 r675 22 22 23 23 mpdf_array A ( 2 ); 24 A ( 0 ) = new mepdf ( f1 );25 A ( 1 ) = new mepdf ( f2 );24 A ( 0 ) = f1; 25 A ( 1 ) = f2; 26 26 27 27 int Npoints = 100; -
library/tests/mpdf_test.cpp
r529 r675 54 54 55 55 eN->set_mu ( vec_2 ( 0.0, 0.0 ) ); 56 mepdf_ptr mEnorm = new mepdf ( eN ); 57 mComs ( 1 ) = mEnorm; 56 mComs ( 1 ) = eN; 58 57 59 58 mMix.set_parameters ( vec_2 ( 0.5, 0.5 ), mComs ); … … 87 86 88 87 eMix->set_parameters ( vec_2 ( 0.5, 0.5 ), Coms ); 89 mepdf meMix ( eMix ); 90 check_mean ( meMix, mu0, N, eMix->mean(), 0.1 ); 88 check_mean ( *eMix, mu0, N, eMix->mean(), 0.1 ); 91 89 } 92 90 -
library/tests/mprod.cfg
r531 r675 21 21 }, 22 22 { 23 class = "mepdf";24 epdf :25 {26 23 class = "egamma"; 27 24 alpha = 2.0; … … 32 29 names = ( "a" ); 33 30 }; 34 };35 31 }); 36 32 }; … … 46 42 mpdfs = ( 47 43 { 48 class = "mepdf";49 epdf :50 {51 44 class = "enorm<ldmat>"; 52 45 mu = [ 1.5, 1.7 ]; … … 58 51 sizes = [ 2 ]; 59 52 }; 60 };61 53 }, 62 54 { 63 class = "mepdf";64 epdf :65 {66 55 class = "egamma"; 67 56 alpha = [ 100000, 10000 ]; … … 72 61 sizes = [ 2 ]; 73 62 }; 74 };75 63 }); 76 64 };