Changeset 181 for bdm/stat/emix.h
- Timestamp:
- 10/15/08 19:11:17 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/emix.h
r178 r181 40 40 public: 41 41 //!Default constructor 42 emix ( const RV &rv ) : epdf ( rv ) {};42 emix ( const RV &rv ) : epdf ( rv ) {}; 43 43 //! Set weights \c w and components \c Coms , Coms are not copied! 44 44 void set_parameters ( const vec &w, const Array<epdf*> &Coms, bool copy=true ); … … 60 60 //! returns a pointer to the internal mean value. Use with Care! 61 61 vec& _w() {return w;} 62 virtual ~emix() {if (destroyComs){for(int i=0;i<Coms.length();i++){delete Coms(i);}}}62 virtual ~emix() {if ( destroyComs ) {for ( int i=0;i<Coms.length();i++ ) {delete Coms ( i );}}} 63 63 //! Auxiliary function for taking ownership of the Coms() 64 void ownComs() {destroyComs=true;}64 void ownComs() {destroyComs=true;} 65 65 }; 66 66 … … 75 75 class mprod: public compositepdf, public mpdf { 76 76 protected: 77 // pointers to epdfs77 //! pointers to epdfs - shortcut to mpdfs()._epdf() 78 78 Array<epdf*> epdfs; 79 79 //! Indeces of rvc in common rvc 80 Array<ivec> rvcinds; 80 Array<ivec> rvcsinrvc; 81 //! Indeces of common rvc in rvcs 82 Array<ivec> rvcinrvcs; 81 83 public: 82 84 /*!\brief Constructor from list of mFacs, 83 Additional parameter overlap is left for future use. Do not set to true for mprod.84 85 */ 85 mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), epdfs(n), rvcinds(n) 86 { setrvc(rv,rvc); 87 setrvcinrv(rvc,rvcinds); 88 setindices(rv); 89 for(int i=0;i<n;i++){epdfs(i)=&(mpdfs(i)->_epdf());} 90 }; 91 92 double evalpdflog ( const vec &val ) const { 86 mprod ( Array<mpdf*> mFacs ) : compositepdf ( mFacs ), mpdf ( getrv ( true ),RV() ), epdfs ( n ), rvcsinrvc ( n ) { 87 setrvc ( rv,rvc ); 88 setindices ( rv ); 89 for ( int i = 0;i < n;i++ ) { 90 // find ith rvc in common rv 91 rvcsinrvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 92 //and vice-versa 93 rvcinrvcs ( i ) = rvc.dataind ( mpdfs ( i )->_rvc() ); 94 } 95 96 for ( int i=0;i<n;i++ ) { 97 epdfs ( i ) =& ( mpdfs ( i )->_epdf() ); 98 } 99 }; 100 101 double evalcond ( const vec &val, const vec &cond ) const { 93 102 int i; 94 103 double res = 0.0; 104 vec condi; 95 105 for ( i = n - 1;i > 0;i++ ) { 96 if ( rvcinds ( i ).length() > 0 ) 97 {mpdfs ( i )->condition ( val ( rvcinds ( i ) ) );} 106 if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 107 condi = zeros ( rvcsinrvc ( i ).length() +rvcsinrv ( i ).length() ); 108 //copy part of the rvc into condi 109 set_subvector ( condi, rvcinrvcs ( i ), get_vec ( cond,rvcsinrvc ( i ) ) ); 110 //copy part of the rv into condi 111 set_subvector ( condi, rvinrvcs ( i ), get_vec ( val,rvcsinrv ( i ) ) ); 112 mpdfs ( i )->condition ( condi ); 113 } 98 114 // add logarithms 99 115 res += epdfs ( i )->evalpdflog ( val ( rvsinrv ( i ) ) ); … … 107 123 ll = 0; 108 124 for ( int i = ( n - 1 );i >= 0;i-- ) { 109 if ( ( rvcinds ( i ).length() > 0 )||( rvcsinrv ( i ).length() > 0 )) {110 condi = zeros ( rvcsinrv (i).length() + rvcinds(i).length() );125 if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 126 condi = zeros ( rvcsinrv ( i ).length() + rvcsinrvc ( i ).length() ); 111 127 // copy data in condition 112 set_subvector ( condi,rvc inds( i ), cond );128 set_subvector ( condi,rvcsinrvc ( i ), cond ); 113 129 // copy data in already generated sample 114 set_subvector ( condi,rvinrvcs ( i ), get_vec (smp,rvcsinrv(i)) );130 set_subvector ( condi,rvinrvcs ( i ), get_vec ( smp,rvcsinrv ( i ) ) ); 115 131 116 132 mpdfs ( i )->condition ( condi ); … … 169 185 double tmp=0; 170 186 for ( int i=0;i<epdfs.length();i++ ) { 171 tmp+=epdfs (i)->evalpdflog(val(rvinds(i)));187 tmp+=epdfs ( i )->evalpdflog ( val ( rvinds ( i ) ) ); 172 188 } 173 189 return tmp; 174 190 } 175 191 //!access function 176 const epdf* operator () ( int i) const {it_assert_debug(i<epdfs.length(),"wrong index");return epdfs(i);}192 const epdf* operator () ( int i ) const {it_assert_debug ( i<epdfs.length(),"wrong index" );return epdfs ( i );} 177 193 }; 178 194