Changeset 124
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/emix.cpp
r107 r124 3 3 using namespace itpp; 4 4 5 void emix::set_parameters ( const vec &w0, const Array<epdf*> &Coms0 ) {5 void emix::set_parameters ( const vec &w0, const Array<epdf*> &Coms0 ) { 6 6 w = w0; 7 7 int i; 8 for(i=0;i<w.length();i++){it_assert_debug(rv.equal(Coms0(i)->_rv()),"RVs do not match!"); } 8 for ( i=0;i<w.length();i++ ) { 9 epdf* Mp=Coms0 ( i ); 10 it_assert_debug ( rv.equal ( Coms0 ( i )->_rv() ),"RVs do not match!" ); 11 } 9 12 Coms = Coms0; 10 13 } 11 14 12 vec emix::sample() const {13 //Sample which component 15 vec emix::sample() const { 16 //Sample which component 14 17 vec cumDist = cumsum ( w ); 15 18 double u0 = UniRNG.sample(); 16 19 17 20 int i=0; 18 while ( (w(i)<u0) && (i<(w.length()-1))){i++;}19 20 return Coms (i)->sample();21 while ( ( w ( i ) <u0 ) && ( i< ( w.length()-1 ) ) ) {i++;} 22 23 return Coms ( i )->sample(); 21 24 } -
bdm/stat/emix.h
r115 r124 69 69 Array<mpdf*> mpdfs; 70 70 public: 71 72 71 72 73 73 }; 74 74 75 /*! \brief Mixture of mpdfs with constant weights 76 77 */ 78 class mmix : public mpdf { 79 protected: 80 //! Component (epdfs) 81 Array<mpdf*> Coms; 82 //!Internal epdf 83 emix Epdf; 84 public: 85 //!Default constructor 86 mmix ( RV &rv, RV &rvc ) : mpdf ( rv, rvc ), Epdf ( rv ) {ep=&Epdf;}; 87 //! Set weights \c w and components \c R 88 void set_parameters ( const vec &w, const Array<mpdf*> &Coms ) { 89 Array<epdf*> Eps ( Coms.length()); 90 91 for ( int i=0;i<Coms.length();i++ ) {mpdf* Ci=Coms(i); 92 Eps ( i ) =& ( Coms ( i )->_epdf() );} 93 Epdf.set_parameters ( w,Eps ); 94 }; 95 96 void condition ( const vec &cond ) { 97 for ( int i=0;i<Coms.length();i++ ) {Coms ( i )->condition ( cond );} 98 }; 99 }; 75 100 #endif //MX_H -
bdm/stat/libEF.h
r102 r124 412 412 413 413 template<class sq_T> 414 mlnorm<sq_T>::mlnorm ( RV &rv0,RV &rvc0 ) :mEF ( rv0,rvc0 ),epdf ( rv ),A ( rv0.count(),rv0.count() ),_mu(epdf._mu()) {414 mlnorm<sq_T>::mlnorm ( RV &rv0,RV &rvc0 ) :mEF ( rv0,rvc0 ),epdf ( rv0 ),A ( rv0.count(),rv0.count() ),_mu(epdf._mu()) { ep =&epdf; 415 415 } 416 416