Changeset 189 for bdm/estim/mixef.cpp
- Timestamp:
- 10/22/08 10:46:36 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/estim/mixef.cpp
r180 r189 21 21 Coms ( 0 )->flatten ( Com0 ); 22 22 23 //Copy it to the rest 23 //Copy it to the rest 24 24 for ( i=1;i<n;i++ ) { 25 25 //copy Com0 and create new rvs for them … … 38 38 39 39 } 40 void MixEF::bayesB ( const mat &Data ) {41 this->bayes ( Data );42 }43 40 44 void MixEF::bayes ( const vec &data ) { 45 46 }; 47 48 void MixEF::bayes ( const mat &data ) { 41 void MixEF::bayesB ( const mat &data , const vec &wData ) { 49 42 int ndat=data.cols(); 50 43 int t,i,niter; … … 63 56 // tmp for weights 64 57 vec wtmp = zeros ( n ); 58 int maxi; 59 double maxll; 65 60 //Estim 66 61 while ( !converged ) { … … 75 70 ll ( i ) += weights.logpred ( wtmp ); 76 71 } 77 w = exp ( ll-max ( ll ) ); 78 W.set_col ( t, w/sum ( w ) ); 72 73 maxll = max(ll,maxi); 74 switch (method) { 75 case QB: 76 w = exp ( ll-maxll ); 77 w/=sum(w); 78 break; 79 case EM: 80 w = 0.0; 81 w(maxi) = 1.0; 82 break; 83 } 84 85 W.set_col ( t, w ); 79 86 } 80 87 88 // copy initial statistics 81 89 for ( i=0;i<n;i++ ) { 82 90 Coms ( i )-> set_statistics ( Coms0 ( i ) ); … … 84 92 weights.set_statistics ( &weights0 ); 85 93 94 // Update statistics 95 // !!!! note wData ==> this is extra weight of the data record 96 // !!!! For typical cases wData=1. 86 97 for ( t=0;t<ndat;t++ ) { 87 98 for ( i=0;i<n;i++ ) { 88 Coms ( i )-> bayes ( data.get_col ( t ),W ( i,t ) );99 Coms ( i )-> bayes ( data.get_col ( t ),W ( i,t ) * wData ( t ) ); 89 100 } 90 weights.bayes ( W.get_col ( t ) );101 weights.bayes ( W.get_col ( t ) * wData ( t ) ); 91 102 } 92 103 … … 98 109 //Clean Coms0 99 110 for ( i=0;i<n;i++ ) {delete Coms0 ( i );} 111 } 112 113 void MixEF::bayes ( const vec &data ) { 114 115 }; 116 117 void MixEF::bayes ( const mat &data ) { 118 this->bayesB ( data, ones ( data.cols() ) ); 100 119 }; 101 120 … … 111 130 } 112 131 113 emix* MixEF::predictor (const RV &rv){114 Array<epdf*> pC (n);115 for (int i=0;i<n;i++){pC(i)=Coms(i)->predictor(rv);}132 emix* MixEF::predictor ( const RV &rv ) { 133 Array<epdf*> pC ( n ); 134 for ( int i=0;i<n;i++ ) {pC ( i ) =Coms ( i )->predictor ( rv );} 116 135 emix* tmp; 117 tmp = new emix (rv);118 tmp->set_parameters (weights._epdf().mean(), pC, false);136 tmp = new emix ( rv ); 137 tmp->set_parameters ( weights._epdf().mean(), pC, false ); 119 138 tmp->ownComs(); 120 139 return tmp;