Changeset 1013 for library/bdm/estim

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

Flatten has an extra argument

Location:
library/bdm/estim
Files:
4 modified

Legend:

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

    r1009 r1013  
    7272} 
    7373 
    74 void ARX::flatten ( const BMEF* B ) { 
     74void ARX::flatten ( const BMEF* B , double weight =1.0) { 
    7575        const ARX* A = dynamic_cast<const ARX*> ( B ); 
    7676        // nu should be equal to B.nu 
    77         est.pow ( A->posterior()._nu() / posterior()._nu() ); 
     77        est.pow ( A->posterior()._nu() / posterior()._nu() *weight); 
    7878        if ( evalll ) { 
    7979                last_lognc = est.lognc(); 
  • library/bdm/estim/arx.h

    r1009 r1013  
    8989        }; 
    9090        double logpred ( const vec &yt, const vec &cond ) const; 
    91         void flatten ( const BMEF* B ); 
     91        void flatten ( const BMEF* B , double weight ); 
    9292        //! Conditioned version of the predictor 
    9393        enorm<ldmat>* epredictor ( const vec &rgr ) const; 
  • 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!! 
  • library/bdm/estim/mixtures.h

    r1009 r1013  
    9898        //! Recursive EM-like algorithm (QB-variant), see Karny et. al, 2006 
    9999        void bayes ( const vec &yt, const vec &cond ); 
    100         //! EM algorithm 
    101         void bayes ( const mat &yt, const vec &cond ); 
    102100        //! batch weighted Bayes rule 
    103         double bayes_batch ( const mat &yt, const mat &cond, const vec &wData ); 
     101        double bayes_batch_weighted ( const mat &yt, const mat &cond, const vec &wData ); 
     102        double bayes_batch ( const mat &yt, const mat &cond){ 
     103                return bayes_batch_weighted(yt,cond,ones(yt.cols())); 
     104        }; 
    104105        double logpred ( const vec &yt, const vec &cond ) const; 
    105106        //! return correctly typed posterior (covariant return) 
     
    110111        emix* epredictor(const vec &cond=vec()) const; 
    111112        //! Flatten the density as if it was not estimated from the data 
    112         void flatten ( const BMEF* M2 ); 
     113        void flatten ( const BMEF* M2, double weight ); 
    113114        //! Access function 
    114115        BMEF* _Coms ( int i ) {