Show
Ignore:
Timestamp:
05/27/10 23:07:49 (14 years ago)
Author:
smidl
Message:

Flatten has an extra argument

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/estim/mixtures.cpp

    r1009 r1013  
    99        Coms.set_size ( c ); 
    1010        weights.set_parameters ( ones ( c ) ); //assume at least one observation in each comp. 
     11        multiBM weights0(weights); 
    1112        //est will be done at the end 
    1213        // 
     
    1819        Coms ( 0 )->bayes_batch ( Data ); 
    1920        // Flatten it to its original shape 
    20         Coms ( 0 )->flatten ( Com0 ); 
     21        shared_ptr<BMEF> SharpCom((BMEF*)Coms(0)->_copy()); 
     22        Coms ( 0 )->flatten ( Com0 );  
    2123 
    2224        //Copy it to the rest 
     
    3234                } else { // pick at random 
    3335                        int ind = (int) floor ( ndat * UniRNG.sample() ); 
    34                         Coms ( i )->bayes ( Data.get_col ( ind ), empty_vec ); 
     36                        Coms ( i )->bayes_weighted ( Data.get_col ( ind ), empty_vec, ndat/Coms.length() ); 
    3537                } 
    36                 //flatten back to oringinal 
    37                 Coms ( i )->flatten ( Com0 ); 
     38                //sharpen to the sharp component 
     39                //Coms ( i )->flatten ( SharpCom.get(), 1.0/Coms.length() ); 
    3840        } 
    39  
    4041} 
    4142 
    42 double MixEF::bayes_batch ( const mat &data , const mat &cond, const vec &wData ) { 
     43double MixEF::bayes_batch_weighted ( const mat &data , const mat &cond, const vec &wData ) { 
    4344        int ndat = data.cols(); 
    4445        int t, i, niter; 
     
    133134}; 
    134135 
    135 void MixEF::bayes ( const mat &data, const vec &cond = empty_vec ) { 
    136         this->bayes_batch ( data, cond, ones ( data.cols() ) ); 
    137 }; 
    138  
    139  
    140136double MixEF::logpred ( const vec &yt, const vec &cond =empty_vec) const { 
    141137 
     
    162158} 
    163159 
    164 void MixEF::flatten ( const BMEF* M2 ) { 
     160void MixEF::flatten ( const BMEF* M2, double weight=1.0 ) { 
    165161        const MixEF* Mix2 = dynamic_cast<const MixEF*> ( M2 ); 
    166162        bdm_assert_debug ( Mix2->Coms.length() == Coms.length(), "Different no of coms" ); 
    167163        //Flatten each component 
    168164        for ( int i = 0; i < Coms.length(); i++ ) { 
    169                 Coms ( i )->flatten ( Mix2->Coms ( i ) ); 
     165                Coms ( i )->flatten ( Mix2->Coms ( i ) , weight); 
    170166        } 
    171167        //Flatten weights = make them equal!!