Changeset 487
- Timestamp:
- 08/08/09 13:42:18 (15 years ago)
- Location:
- library/bdm
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r479 r487 140 140 } 141 141 142 vec mpdf::samplecond ( const vec &cond ) { 143 condition ( cond ); 144 vec temp = shep->sample(); 142 template<class EPDF> 143 vec mpdf_internal<EPDF>::samplecond ( const vec &cond ) { 144 condition ( cond ); 145 vec temp = iepdf.sample(); 145 146 return temp; 146 147 } 147 148 148 mat mpdf::samplecond_m ( const vec &cond, int N ) { 149 condition ( cond ); 150 mat temp ( shep->dimension(), N ); 151 vec smp ( shep->dimension() ); 149 template<class EPDF> 150 mat mpdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) { 151 condition ( cond ); 152 mat temp ( dimension(), N ); 153 vec smp ( dimension() ); 152 154 for ( int i = 0; i < N; i++ ) { 153 smp = shep->sample();155 smp = iepdf.sample(); 154 156 temp.set_col ( i, smp ); 155 157 } … … 158 160 } 159 161 160 double mpdf::evallogcond ( const vec &dt, const vec &cond ) { 162 template<class EPDF> 163 double mpdf_internal<EPDF>::evallogcond ( const vec &dt, const vec &cond ) { 161 164 double tmp; 162 165 condition ( cond ); 163 tmp = shep->evallog ( dt );166 tmp = iepdf.evallog ( dt ); 164 167 // it_assert_debug(std::isfinite(tmp), "Infinite value"); 165 168 return tmp; 166 169 } 167 170 168 vec mpdf::evallogcond_m ( const mat &Dt, const vec &cond ) { 169 condition ( cond ); 170 return shep->evallog_m ( Dt ); 171 } 172 173 vec mpdf::evallogcond_m ( const Array<vec> &Dt, const vec &cond ) { 174 condition ( cond ); 175 return shep->evallog_m ( Dt ); 171 template<class EPDF> 172 vec mpdf_internal<EPDF>::evallogcond_m ( const mat &Dt, const vec &cond ) { 173 condition ( cond ); 174 return iepdf.evallog_m ( Dt ); 175 } 176 177 template<class EPDF> 178 vec mpdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Dt, const vec &cond ) { 179 condition ( cond ); 180 return iepdf.evallog_m ( Dt ); 176 181 } 177 182 … … 313 318 void mepdf::from_setting ( const Setting &set ) { 314 319 shared_ptr<epdf> e ( UI::build<epdf> ( set, "epdf", UI::compulsory ) ); 315 set_ep ( e );320 ipdf = e; 316 321 } 317 322 -
library/bdm/base/bdmbase.h
r477 r487 399 399 //! Conditional probability density, e.g. modeling some dependencies. 400 400 //TODO Samplecond can be generalized 401 402 401 class mpdf : public root { 403 402 protected: … … 406 405 //! random variable in condition 407 406 RV rvc; 408 409 407 private: 410 //! pointer to internal epdf 411 shared_ptr<epdf> shep; 408 //! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension() 409 epdf* ep; 410 411 protected: 412 void set_ep(epdf &iepdf) { 413 ep = &iepdf; 414 } 412 415 413 416 public: … … 415 418 //! @{ 416 419 417 mpdf() : dimc ( 0 ), rvc() { }418 419 mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), shep ( m.shep ) { }420 mpdf() : dimc ( 0 ), rvc(), ep(NULL) { } 421 422 mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), ep ( m.ep ) { } 420 423 //!@} 421 424 … … 424 427 425 428 //! 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 426 virtual vec samplecond ( const vec &cond ) ;429 virtual vec samplecond ( const vec &cond ){it_error("Not implemented");return vec(0);}; 427 430 428 431 //! 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 429 virtual mat samplecond_m ( const vec &cond, int N ); 430 431 //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond 432 virtual void condition ( const vec &cond ) { 433 it_error ( "Not implemented" ); 434 }; 432 virtual mat samplecond_m ( const vec &cond, int N ){it_error("Not implemented");return mat();} 433 435 434 436 435 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. 437 virtual double evallogcond ( const vec &dt, const vec &cond ) ;436 virtual double evallogcond ( const vec &dt, const vec &cond ){it_error("Not implemented");return 0.0;} 438 437 439 438 //! Matrix version of evallogcond 440 virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) ;439 virtual vec evallogcond_m ( const mat &Dt, const vec &cond ){it_error("Not implemented");return vec(0);} 441 440 442 441 //! Array<vec> version of evallogcond 443 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) ;442 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ){it_error("Not implemented");return vec(0);} 444 443 445 444 //! \name Access to attributes … … 447 446 448 447 RV _rv() { 449 return shep->_rv();448 return ep->_rv(); 450 449 } 451 450 RV _rvc() { … … 454 453 } 455 454 int dimension() { 456 return shep->dimension();455 return ep->dimension(); 457 456 } 458 457 int dimensionc() { … … 460 459 } 461 460 462 epdf *e() {463 return shep.get();464 }465 466 void set_ep ( shared_ptr<epdf> ep ) {467 shep = ep;468 }469 470 461 //! Load from structure with elements: 471 462 //! \code 472 //! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable 463 //! { class = "mpdf_offspring", 464 //! rv = {class="RV", names=(...),}; // RV describing meaning of random variable 473 465 //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition 474 466 //! // elements of offsprings … … 485 477 } 486 478 void set_rv ( const RV &rv0 ) { 487 shep->set_rv ( rv0 );479 ep->set_rv ( rv0 ); 488 480 } 489 481 bool isnamed() { 490 return ( shep->isnamed() ) && ( dimc == rvc._dsize() ); 491 } 492 //!@} 482 return ( ep->isnamed() ) && ( dimc == rvc._dsize() ); 483 } 484 //!@} 485 }; 486 487 template <class EPDF> 488 class mpdf_internal: public mpdf{ 489 protected : 490 EPDF iepdf; 491 public: 492 //! constructor 493 mpdf_internal(): mpdf(),iepdf(){set_ep(iepdf);} 494 //! Update \c iepdf so that it represents this mpdf conditioned on \c rvc = cond 495 //! This function provides convenient reimplementation in offsprings 496 virtual void condition ( const vec &cond ) { 497 it_error ( "Not implemented" ); 498 }; 499 //!access function to iepdf 500 EPDF& e(){return iepdf;} 501 502 //! Reimplements samplecond using \c condition() 503 vec samplecond ( const vec &cond ); 504 //! Reimplements evallogcond using \c condition() 505 double evallogcond ( const vec &val, const vec &cond ); 506 //! Efficient version of evallogcond for matrices 507 virtual vec evallogcond_m ( const mat &Dt, const vec &cond ); 508 //! Efficient version of evallogcond for Array<vec> 509 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ); 510 //! Efficient version of samplecond 511 virtual mat samplecond_m ( const vec &cond, int N ); 493 512 }; 494 513 … … 686 705 */ 687 706 class mepdf : public mpdf { 707 708 shared_ptr<epdf> ipdf; 688 709 public: 689 710 //!Default constructor … … 691 712 692 713 mepdf ( shared_ptr<epdf> em ) { 693 set_ep ( em ); 714 ipdf = em; 715 set_ep(*ipdf.get()); 694 716 dimc = 0; 695 717 } … … 701 723 //! \code 702 724 //! { class = "mepdf", 703 //! epdf s = {class="epdfs",...}725 //! epdf = {class="epdf_offspring",...} 704 726 //! } 705 727 //! \endcode -
library/bdm/estim/particles.cpp
r477 r487 13 13 for ( i = 0; i < n; i++ ) { 14 14 //generate new samples from paramater evolution model; 15 _samples ( i ) = par->samplecond ( _samples ( i ) ); 16 lls ( i ) = par->e()->evallog ( _samples ( i ) ); 15 vec old_smp=_samples ( i ); 16 _samples ( i ) = par->samplecond ( old_smp ); 17 lls ( i ) = par->evallogcond ( _samples ( i ), old_smp ); 17 18 lls ( i ) *= obs->evallogcond ( dt, _samples ( i ) ); 18 19 -
library/bdm/estim/particles.h
r477 r487 250 250 for ( i = 0; i < n; i++ ) { 251 251 //generate new samples from paramater evolution model; 252 _samples ( i ) = par->samplecond ( _samples ( i ) ); 253 llsP ( i ) = par->e()->evallog ( _samples ( i ) ); 252 vec old_smp=_samples ( i ); 253 _samples ( i ) = par->samplecond ( old_smp ); 254 llsP ( i ) = par->evallogcond ( _samples ( i ), old_smp ); 254 255 BMs ( i )->condition ( _samples ( i ) ); 255 256 BMs ( i )->bayes ( dt ); -
library/bdm/stat/emix.h
r477 r487 45 45 //!datalink between conditional and nom 46 46 datalink_m2e dl; 47 //! dummy epdf that stores only rv and dim 48 epdf iepdf; 47 49 public: 48 50 //!Default constructor. By default, the given epdf is not copied! 49 51 //! It is assumed that this function will be used only temporarily. 50 mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ) {52 mratio ( const epdf* nom0, const RV &rv, bool copy = false ) : mpdf ( ), dl ( ),iepdf() { 51 53 // adjust rv and rvc 52 54 rvc = nom0->_rv().subt ( rv ); 53 55 dimc = rvc._dsize(); 54 set_ep ( shared_ptr<epdf> ( new epdf ));55 e()->set_parameters ( rv._dsize() );56 e()->set_rv ( rv );56 set_ep ( iepdf ); 57 iepdf.set_parameters ( rv._dsize() ); 58 iepdf.set_rv ( rv ); 57 59 58 60 //prepare data structures … … 72 74 double evallogcond ( const vec &val, const vec &cond ) { 73 75 double tmp; 74 vec nom_val ( e()->dimension() + dimc );76 vec nom_val ( dimension() + dimc ); 75 77 dl.pushup_cond ( nom_val, val, cond ); 76 78 tmp = exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 77 it_assert_debug ( std::isfinite ( tmp ), "Infinite value" );78 79 return tmp; 79 80 } … … 278 279 class mprod: public compositepdf, public mpdf { 279 280 protected: 280 //! pointers to epdfs - shortcut to mpdfs().posterior()281 Array<epdf*> epdfs;282 281 //! Data link for each mpdfs 283 282 Array<datalink_m2m*> dls; 284 283 285 //! dummy ep 286 shared_ptr<epdf> dummy;284 //! dummy epdf used only as storage for RV and dim 285 epdf iepdf; 287 286 288 287 public: 289 288 /*!\brief Constructor from list of mFacs, 290 289 */ 291 mprod() : dummy ( new epdf()) { }290 mprod() : iepdf( ) { } 292 291 mprod ( Array<mpdf*> mFacs ) : 293 dummy ( new epdf()) {292 iepdf ( ) { 294 293 set_elements ( mFacs ); 295 294 } … … 299 298 compositepdf::set_elements ( mFacs, own ); 300 299 dls.set_size ( mFacs.length() ); 301 epdfs.set_size ( mFacs.length() ); 302 303 set_ep ( dummy ); 300 301 set_ep ( iepdf); 304 302 RV rv = getrv ( true ); 305 303 set_rv ( rv ); 306 dummy->set_parameters ( rv._dsize() );307 setrvc ( e()->_rv(), rvc );304 iepdf.set_parameters ( rv._dsize() ); 305 setrvc (_rv(), rvc ); 308 306 // rv and rvc established = > we can link them with mpdfs 309 307 for ( int i = 0; i < mpdfs.length(); i++ ) { … … 312 310 } 313 311 314 for ( int i = 0; i < mpdfs.length(); i++ ) {315 epdfs ( i ) = mpdfs ( i )->e();316 }317 312 }; 318 313 … … 352 347 vec samplecond ( const vec &cond ) { 353 348 //! Ugly hack to help to discover if mpfs are not in proper order. Correct solution = check that explicitely. 354 vec smp = std::numeric_limits<double>::infinity() * ones ( e()->dimension() );349 vec smp = std::numeric_limits<double>::infinity() * ones ( dimension() ); 355 350 vec smpi; 356 351 // Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated! 357 352 for ( int i = ( mpdfs.length() - 1 ); i >= 0; i-- ) { 358 if ( mpdfs ( i )->dimensionc() ) { 359 mpdfs ( i )->condition ( dls ( i )->get_cond ( smp , cond ) ); // smp is val here!! 360 } 361 smpi = epdfs ( i )->sample(); 353 // generate contribution of this mpdf 354 smpi = mpdfs(i)->samplecond(dls ( i )->get_cond ( smp , cond )); 362 355 // copy contribution of this pdf into smp 363 356 dls ( i )->pushup ( smp, smpi ); 364 // add ith likelihood contribution365 357 } 366 358 return smp; … … 483 475 484 476 */ 485 class mmix : public mpdf {486 protected:487 //! Component (epdfs)488 Array<mpdf*> Coms;489 490 //!Internal epdf491 shared_ptr<emix>iepdf;492 493 public:494 //!Default constructor495 mmix() : iepdf ( new emix()) {496 set_ep ( iepdf );497 }498 499 //! Set weights \c w and components \c R500 void set_parameters ( const vec &w, const Array<mpdf*> &Coms ) {501 Array<epdf*> Eps ( Coms.length() );502 503 for ( int i = 0; i < Coms.length(); i++ ) {504 Eps ( i ) = Coms ( i )->e();505 }506 507 iepdf->set_parameters ( w, Eps );508 }509 510 void condition ( const vec &cond ) {511 for ( int i = 0; i < Coms.length(); i++ ) {512 Coms ( i )->condition ( cond );513 }514 };515 };477 // class mmix : public mpdf { 478 // protected: 479 // //! Component (epdfs) 480 // Array<mpdf*> Coms; 481 // 482 // //!Internal epdf 483 // emix iepdf; 484 // 485 // public: 486 // //!Default constructor 487 // mmix() : iepdf ( ) { 488 // set_ep ( iepdf ); 489 // } 490 // 491 // //! Set weights \c w and components \c R 492 // void set_parameters ( const vec &w, const Array<mpdf*> &Coms ) { 493 // Array<epdf*> Eps ( Coms.length() ); 494 // 495 // for ( int i = 0; i < Coms.length(); i++ ) { 496 // Eps ( i ) = Coms ( i )->e(); 497 // } 498 // 499 // iepdf->set_parameters ( w, Eps ); 500 // } 501 // 502 // void condition ( const vec &cond ) { 503 // for ( int i = 0; i < Coms.length(); i++ ) { 504 // Coms ( i )->condition ( cond ); 505 // } 506 // }; 507 // }; 516 508 517 509 } -
library/bdm/stat/exp_family.cpp
r477 r487 11 11 12 12 using std::cout; 13 14 /////////// 13 15 14 16 void BMEF::bayes ( const vec &dt ) { … … 214 216 void mgamma::set_parameters ( double k0, const vec &beta0 ) { 215 217 k = k0; 216 iepdf ->set_parameters ( k * ones ( beta0.length() ), beta0 );217 dimc = e()->dimension();218 iepdf.set_parameters ( k * ones ( beta0.length() ), beta0 ); 219 dimc = iepdf.dimension(); 218 220 } 219 221 -
library/bdm/stat/exp_family.h
r476 r487 55 55 return tmp;} 56 56 //!Evaluate normalized log-probability for many samples 57 virtual vec evallog ( const mat &Val ) const57 virtual vec evallog_m ( const mat &Val ) const 58 58 { 59 59 vec x ( Val.cols() ); … … 65 65 }; 66 66 67 /*!68 * \brief Exponential family model.69 70 * More?...71 */72 73 class mEF : public mpdf74 {75 76 public:77 //! Default constructor78 mEF ( ) :mpdf ( ) {};79 };80 67 81 68 //! Estimator for Exponential family … … 106 93 }; 107 94 108 template<class sq_T >95 template<class sq_T, template <typename> class TEpdf > 109 96 class mlnorm; 110 97 … … 527 514 Mean value \f$mu=A*rvc+mu_0\f$. 528 515 */ 529 template<class sq_T >530 class mlnorm : public m EF516 template<class sq_T, template <typename> class TEpdf =enorm> 517 class mlnorm : public mpdf_internal< TEpdf<sq_T> > 531 518 { 532 519 protected: 533 520 //! Internal epdf that arise by conditioning on \c rvc 534 shared_ptr<enorm<sq_T> > iepdf;535 521 mat A; 536 522 vec mu_const; 537 vec& _mu; //cached epdf.mu; 523 // vec& _mu; //cached epdf.mu; !!!!!! WHY NOT? 538 524 public: 539 525 //! \name Constructors 540 526 //!@{ 541 mlnorm(): iepdf(new enorm<sq_T>()), _mu(iepdf->_mu()) { set_ep(iepdf);};542 mlnorm (const mat &A, const vec &mu0, const sq_T &R ) : iepdf(new enorm<sq_T>()), _mu(iepdf->_mu())543 { 544 set_ ep(iepdf); set_parameters ( A,mu0,R );527 mlnorm():mpdf_internal< TEpdf<sq_T> >() {}; 528 mlnorm (const mat &A, const vec &mu0, const sq_T &R ) : mpdf_internal< TEpdf<sq_T> >() 529 { 530 set_parameters ( A,mu0,R ); 545 531 } 546 532 547 533 //! Set \c A and \c R 548 void set_parameters ( const mat &A, const vec &mu0, const sq_T &R ); 534 void set_parameters ( const mat &A0, const vec &mu0, const sq_T &R0 ){ 535 it_assert_debug ( A0.rows() ==mu0.length(),"" ); 536 it_assert_debug ( A0.rows() ==R0.rows(),"" ); 537 538 this->iepdf.set_parameters(zeros(A0.rows()), R0); 539 A = A0; 540 mu_const = mu0; 541 this->dimc = A0.cols(); 542 } 549 543 //!@} 550 544 //! Set value of \c rvc . Result of this operation is stored in \c epdf use function \c _ep to access it. 551 void condition ( const vec &cond ); 545 void condition ( const vec &cond ){ 546 this->iepdf._mu()= A*cond + mu_const; 547 //R is already assigned; 548 } 552 549 553 550 //!access function … … 556 553 mat& _A() {return A;} 557 554 //!access function 558 mat _R() { return iepdf->_R().to_mat(); }559 560 template< classsq_M>561 friend std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M > &ml );555 mat _R(){ return this->iepdf._R().to_mat(); } 556 557 template<typename sq_M> 558 friend std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M,enorm> &ml ); 562 559 563 560 void from_setting(const Setting &set){ … … 577 574 //! Mpdf with general function for mean value 578 575 template<class sq_T> 579 class mgnorm : public mEF 580 { 581 protected: 582 //! Internal epdf that arise by conditioning on \c rvc 583 shared_ptr<enorm<sq_T> > iepdf; 584 vec μ 576 class mgnorm : public mpdf_internal< enorm< sq_T > > 577 { 578 protected: 579 // vec μ WHY NOT? 585 580 fnc* g; 586 581 public: 587 582 //!default constructor 588 mgnorm(): iepdf(new enorm<sq_T>()), mu(iepdf->_mu()) { set_ep(iepdf);}583 mgnorm():mpdf_internal<enorm<sq_T> >() { } 589 584 //!set mean function 590 void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; iepdf->set_parameters ( zeros ( g->dimension() ), R0 );}591 void condition ( const vec &cond ) {mu=g->eval ( cond );};585 inline void set_parameters ( fnc* g0, const sq_T &R0 ); 586 inline void condition ( const vec &cond ); 592 587 593 588 … … 644 639 Perhaps a moment-matching technique? 645 640 */ 646 class mlstudent : public mlnorm<ldmat >641 class mlstudent : public mlnorm<ldmat,enorm> 647 642 { 648 643 protected: … … 651 646 ldmat Re; 652 647 public: 653 mlstudent ( ) :mlnorm<ldmat > (),654 Lambda (), _R ( iepdf ->_R() ) {}648 mlstudent ( ) :mlnorm<ldmat,enorm> (), 649 Lambda (), _R ( iepdf._R() ) {} 655 650 void set_parameters ( const mat &A0, const vec &mu0, const ldmat &R0, const ldmat& Lambda0 ) 656 651 { … … 658 653 it_assert_debug ( R0.rows() ==A0.rows(),"" ); 659 654 660 iepdf ->set_parameters ( mu0,Lambda ); //655 iepdf.set_parameters ( mu0,Lambda ); // 661 656 A = A0; 662 657 mu_const = mu0; … … 666 661 void condition ( const vec &cond ) 667 662 { 668 _mu= A*cond + mu_const;663 iepdf._mu() = A*cond + mu_const; 669 664 double zeta; 670 665 //ugly hack! … … 691 686 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 692 687 */ 693 class mgamma : public mEF 694 { 695 protected: 696 //! Internal epdf that arise by conditioning on \c rvc 697 shared_ptr<egamma> iepdf; 688 class mgamma : public mpdf_internal<egamma> 689 { 690 protected: 698 691 699 692 //! Constant \f$k\f$ … … 705 698 public: 706 699 //! Constructor 707 mgamma():iepdf(new egamma()), k(0), 708 _beta(iepdf->_beta()) { 709 set_ep(iepdf); 700 mgamma():mpdf_internal<egamma>(), k(0), 701 _beta(iepdf._beta()) { 710 702 } 711 703 … … 742 734 The standard deviation of the walk is then: \f$ \mu/\sqrt(k)\f$. 743 735 */ 744 class migamma : public mEF 745 { 746 protected: 747 //! Internal epdf that arise by conditioning on \c rvc 748 shared_ptr<eigamma> iepdf; 749 736 class migamma : public mpdf_internal<eigamma> 737 { 738 protected: 750 739 //! Constant \f$k\f$ 751 740 double k; … … 760 749 //! \name Constructors 761 750 //!@{ 762 migamma(): iepdf(new eigamma()),751 migamma():mpdf_internal<eigamma>(), 763 752 k(0), 764 _alpha(iepdf->_alpha()), 765 _beta(iepdf->_beta()) { 766 set_ep(iepdf); 767 } 768 769 migamma(const migamma &m):iepdf(m.iepdf), 753 _alpha(iepdf._alpha()), 754 _beta(iepdf._beta()) { 755 } 756 757 migamma(const migamma &m):mpdf_internal<eigamma>(), 770 758 k(0), 771 _alpha(iepdf->_alpha()), 772 _beta(iepdf->_beta()) { 773 set_ep(iepdf); 759 _alpha(iepdf._alpha()), 760 _beta(iepdf._beta()) { 774 761 } 775 762 //!@} … … 779 766 { 780 767 k=k0; 781 iepdf ->set_parameters ( ( 1.0/ ( k*k ) +2.0 ) *ones ( len ) /*alpha*/, ones ( len ) /*beta*/ );768 iepdf.set_parameters ( ( 1.0/ ( k*k ) +2.0 ) *ones ( len ) /*alpha*/, ones ( len ) /*beta*/ ); 782 769 dimc = dimension(); 783 770 }; … … 915 902 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 916 903 */ 917 class mlognorm : public mpdf 918 { 919 protected: 920 shared_ptr<elognorm> eno; 921 904 class mlognorm : public mpdf_internal<elognorm> 905 { 906 protected: 922 907 //! parameter 1/2*sigma^2 923 908 double sig2; … … 927 912 public: 928 913 //! Constructor 929 mlognorm(): eno(new elognorm()),914 mlognorm():mpdf_internal<elognorm>(), 930 915 sig2(0), 931 mu(eno->_mu()) { 932 set_ep(eno); 916 mu(iepdf._mu()) { 933 917 } 934 918 … … 937 921 { 938 922 sig2 = 0.5*log ( k*k+1 ); 939 eno->set_parameters ( zeros ( size ),2*sig2*eye ( size ) );923 iepdf.set_parameters ( zeros ( size ),2*sig2*eye ( size ) ); 940 924 941 925 dimc = size; … … 1071 1055 { 1072 1056 protected: 1073 shared_ptr<eiWishartCh>eiW;1057 eiWishartCh eiW; 1074 1058 //!square root of \f$ \nu-p-1 \f$ - needed for computation of \f$ \Psi \f$ from conditions 1075 1059 double sqd; … … 1080 1064 1081 1065 public: 1082 rwiWishartCh():eiW( new eiWishartCh()),1066 rwiWishartCh():eiW(), 1083 1067 sqd(0), l(0), p(0) { 1084 1068 set_ep(eiW); … … 1093 1077 refl=pow(ref0,1-l); 1094 1078 1095 eiW ->set_parameters ( eye ( p ),delta );1096 dimc=eiW ->dimension();1079 eiW.set_parameters ( eye ( p ),delta ); 1080 dimc=eiW.dimension(); 1097 1081 } 1098 1082 void condition ( const vec &c ) { … … 1104 1088 } 1105 1089 1106 eiW ->_setY ( sqd*z );1090 eiW._setY ( sqd*z ); 1107 1091 } 1108 1092 }; … … 1256 1240 }; 1257 1241 1258 template<class sq_T>1259 void mlnorm<sq_T>::set_parameters ( const mat &A0, const vec &mu0, const sq_T &R0 )1260 {1261 it_assert_debug ( A0.rows() ==mu0.length(),"" );1262 it_assert_debug ( A0.rows() ==R0.rows(),"" );1263 1264 iepdf->set_parameters(zeros(A0.rows()), R0);1265 A = A0;1266 mu_const = mu0;1267 dimc = A0.cols();1268 }1269 1242 1270 1243 // template<class sq_T> … … 1293 1266 // } 1294 1267 1295 template<class sq_T>1296 void mlnorm<sq_T>::condition ( const vec &cond )1297 {1298 _mu = A*cond + mu_const;1299 //R is already assigned;1300 }1301 1268 1302 1269 template<class sq_T> … … 1348 1315 } 1349 1316 1350 /////////// 1317 //// 1318 /////// 1319 template<class sq_T> 1320 void mgnorm<sq_T >::set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; this->iepdf.set_parameters ( zeros ( g->dimension() ), R0 );} 1321 template<class sq_T> 1322 void mgnorm<sq_T >::condition ( const vec &cond ) {this->iepdf._mu()=g->eval ( cond );}; 1351 1323 1352 1324 template<class sq_T> -
library/bdm/stat/merger.cpp
r477 r487 152 152 if ( mpdfs ( i )->dimension() == dim ) { 153 153 // no need for conditioning or marginalization 154 lw_src = mpdfs ( i )->e ()->evallog_m ( Smp);154 lw_src = mpdfs ( i )->evallogcond_m ( Smp , vec(0)); 155 155 } else { 156 156 // compute likelihood of marginal on the conditional variable … … 190 190 // Compute likelihood of the partial source 191 191 for ( int k = 0; k < Npoints; k++ ) { 192 mpdfs ( i )->condition ( dls ( i )->get_cond ( Smp ( k ) ) );193 lw_src ( k ) += mpdfs ( i )->e()->evallog ( dls ( i )->pushdown ( Smp ( k ) ));192 lw_src ( k ) += mpdfs ( i )->evallogcond ( dls ( i )->pushdown ( Smp ( k ) ), 193 dls ( i )->get_cond ( Smp ( k ) )); 194 194 } 195 195