Changeset 60 for bdm/estim/libPF.h

Show
Ignore:
Timestamp:
03/31/08 13:53:36 (16 years ago)
Author:
smidl
Message:

nove rozlozeni Q

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/libPF.h

    r33 r60  
    1919 
    2020using namespace itpp; 
     21 
     22//UGLY HACK 
     23extern double PF_SSAT;//used for StrSim:06 test... if length>0 the value is written. 
    2124 
    2225/*! 
     
    6063 
    6164class MPF : public PF { 
    62         BM_T* Bms[1000]; 
     65        BM_T* Bms[10000]; 
    6366 
    6467        //! internal class for MPDF providing composition of eEmp with external components 
     
    105108                // 
    106109 
    107                 if ( n>1000 ) it_error ( "increase 1000 here!" ); 
     110                if ( n>10000 ) it_error ( "increase 10000 here!" ); 
    108111 
    109112                for ( int i=0;i<n;i++ ) { 
     
    126129                for ( int i=0;i<n;i++ ) {Bms[i]->condition ( _samples ( i ) );} 
    127130        } 
     131 
     132//SimStr: 
     133        double SSAT;     
    128134}; 
    129135 
     
    132138        int i; 
    133139        vec lls ( n ); 
     140        vec llsP ( n ); 
    134141        ivec ind; 
    135142        double mlls=-std::numeric_limits<double>::infinity(); 
    136143 
     144        // StrSim:06 
     145        double sumLWL=0.0; 
     146        double sumL2WL=0.0; 
     147        double WL = 0.0; 
     148 
    137149        for ( i=0;i<n;i++ ) { 
    138150                //generate new samples from paramater evolution model; 
    139                 _samples ( i ) = par.samplecond ( _samples ( i ), lls ( i ) ); 
     151                _samples ( i ) = par.samplecond ( _samples ( i ), llsP ( i ) ); 
    140152                Bms[i]->condition ( _samples ( i ) ); 
    141153                Bms[i]->bayes ( dt ); 
     
    144156                if ( lls ( i ) >mlls ) mlls=lls ( i ); //find maximum likelihood (for numerical stability) 
    145157        } 
     158         
     159        if ( true ) { 
     160                for ( i=0;i<n;i++ ) { 
     161                        WL = _w ( i ) *exp ( llsP ( i ) ); //using old weights! 
     162                        sumLWL += exp ( lls ( i ) ) *WL; 
     163                        sumL2WL += exp ( 2*lls ( i ) ) *WL; 
     164                } 
     165                SSAT  = sumL2WL/(sumLWL*sumLWL); 
     166        } 
    146167 
    147168        // compute weights 
     
    150171        } 
    151172 
    152         _w /=sum(_w); //? 
    153  
    154         double eff = 1.0/( _w*_w ); 
     173        _w /=sum ( _w ); //? 
     174 
     175 
     176 
     177        double eff = 1.0/ ( _w*_w ); 
    155178        if ( eff < ( 0.1*n ) ) { 
    156179                ind = est.resample(); 
     
    161184                                //fixme this would require new assignment operator 
    162185                                // *Bms[i] = *Bms[ind ( i ) ]; 
    163                                  
     186 
    164187                                // poor-man's solution: replicate constructor here 
    165188                                // copied from MPF::MPF 
     
    170193                        } 
    171194                }; 
    172                 cout << '.';  
     195                cout << '.'; 
    173196        } 
    174197}