Changeset 211 for bdm/stat/emix.h
- Timestamp:
- 11/13/08 20:00:53 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/emix.h
r204 r211 32 32 In particular this type of arise by conditioning of a mixture model. 33 33 34 At present the only supported operation is eval cond().34 At present the only supported operation is evallogcond(). 35 35 */ 36 36 class mratio: public mpdf { … … 60 60 den = nom->marginal ( rvc ); 61 61 }; 62 double eval cond ( const vec &val, const vec &cond ) {62 double evallogcond ( const vec &val, const vec &cond ) { 63 63 vec nom_val ( rv.count() +rvc.count() ); 64 64 dl.fill_val_cond ( nom_val,val,cond ); 65 return exp ( nom->eval pdflog ( nom_val ) - den->evalpdflog ( cond ) );65 return exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 66 66 } 67 67 //! Object takes ownership of nom and will destroy it … … 102 102 return mu; 103 103 } 104 double eval pdflog ( const vec &val ) const {104 double evallog ( const vec &val ) const { 105 105 int i; 106 106 double sum = 0.0; 107 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->eval pdflog ( val ) );}107 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->evallog ( val ) );} 108 108 return log ( sum ); 109 109 }; 110 vec eval pdflog_m ( const mat &Val ) const {110 vec evallog_m ( const mat &Val ) const { 111 111 vec x=zeros ( Val.cols() ); 112 112 for ( int i = 0; i < w.length(); i++ ) { 113 x+= w ( i ) *exp ( Coms ( i )->eval pdflog_m ( Val ) );113 x+= w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ); 114 114 } 115 115 return log ( x ); 116 116 }; 117 mat eval pdflog_M ( const mat &Val ) const {117 mat evallog_M ( const mat &Val ) const { 118 118 mat X ( w.length(), Val.cols() ); 119 119 for ( int i = 0; i < w.length(); i++ ) { 120 X.set_row ( i, w ( i ) *exp ( Coms ( i )->eval pdflog_m ( Val ) ) );120 X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ) ); 121 121 } 122 122 return X; … … 166 166 }; 167 167 168 double eval cond ( const vec &val, const vec &cond ) {168 double evallogcond ( const vec &val, const vec &cond ) { 169 169 int i; 170 170 double res = 1.0; … … 174 174 } 175 175 // add logarithms 176 res += epdfs ( i )->eval pdflog ( dls ( i )->get_val ( val ) );*/177 res *= mpdfs ( i )->eval cond (176 res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/ 177 res *= mpdfs ( i )->evallogcond ( 178 178 dls ( i )->get_val ( val ), 179 179 dls ( i )->get_cond ( val, cond ) … … 196 196 dls ( i )->fill_val ( smp, smpi ); 197 197 // add ith likelihood contribution 198 ll+=epdfs ( i )->eval pdflog ( smpi );198 ll+=epdfs ( i )->evallog ( smpi ); 199 199 } 200 200 return smp; … … 244 244 return tmp; 245 245 } 246 double eval pdflog ( const vec &val ) const {246 double evallog ( const vec &val ) const { 247 247 double tmp=0; 248 248 for ( int i=0;i<epdfs.length();i++ ) { 249 tmp+=epdfs ( i )->eval pdflog ( dls ( i )->get_val ( val ) );249 tmp+=epdfs ( i )->evallog ( dls ( i )->get_val ( val ) ); 250 250 } 251 251 return tmp;