Show
Ignore:
Timestamp:
06/09/10 14:00:40 (14 years ago)
Author:
mido
Message:

astyle applied all over the library

Files:
1 modified

Legend:

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

    r887 r1064  
    88void PF::bayes_weights() { 
    99// 
    10         double mlls = max ( lls ); 
    11         // compute weights 
    12         for ( int  i = 0; i < n; i++ ) { 
    13                 w ( i ) *= exp ( lls ( i ) - mlls ); // multiply w by likelihood 
    14         } 
    15  
    16         //renormalize 
    17         double sw = sum ( w ); 
    18         if ( !std::isfinite ( sw ) ) { 
    19                 for ( int i = 0; i < n; i++ ) { 
    20                         if ( !std::isfinite ( w ( i ) ) ) { 
    21                                 w ( i ) = 0; 
    22                         } 
    23                 } 
    24                 sw = sum ( w ); 
    25                 if ( !std::isfinite ( sw ) || sw == 0.0 ) { 
    26                         bdm_error ( "Particle filter is lost; no particle is good enough." ); 
    27                 } 
    28         } 
    29         w /= sw; 
     10    double mlls = max ( lls ); 
     11    // compute weights 
     12    for ( int  i = 0; i < n; i++ ) { 
     13        w ( i ) *= exp ( lls ( i ) - mlls ); // multiply w by likelihood 
     14    } 
     15 
     16    //renormalize 
     17    double sw = sum ( w ); 
     18    if ( !std::isfinite ( sw ) ) { 
     19        for ( int i = 0; i < n; i++ ) { 
     20            if ( !std::isfinite ( w ( i ) ) ) { 
     21                w ( i ) = 0; 
     22            } 
     23        } 
     24        sw = sum ( w ); 
     25        if ( !std::isfinite ( sw ) || sw == 0.0 ) { 
     26            bdm_error ( "Particle filter is lost; no particle is good enough." ); 
     27        } 
     28    } 
     29    w /= sw; 
    3030} 
    3131 
    3232void PF::bayes ( const vec &yt, const vec &cond ) { 
    3333 
    34 /*      if (auxiliary){ 
    35                 ... 
    36         }*/ 
    37         // weight them - data step 
    38         for (int i = 0; i < n; i++ ) { 
    39                 particles(i)->bayes(yt,cond); 
    40                 lls ( i ) = particles(i)->_ll(); //+= because lls may have something from gensmp! 
    41         } 
    42  
    43         bayes_weights(); 
    44  
    45         if ( do_resampling() ) { resample ( ); } 
     34    /*  if (auxiliary){ 
     35                ... 
     36        }*/ 
     37    // weight them - data step 
     38    for (int i = 0; i < n; i++ ) { 
     39        particles(i)->bayes(yt,cond); 
     40        lls ( i ) = particles(i)->_ll(); //+= because lls may have something from gensmp! 
     41    } 
     42 
     43    bayes_weights(); 
     44 
     45    if ( do_resampling() ) { 
     46        resample ( ); 
     47    } 
    4648 
    4749} 
     
    6466//      return concat ( pf->posterior().mean(), pom ); 
    6567// } 
    66 //  
     68// 
    6769// vec MPF::mpfepdf::variance() const { 
    6870//      const vec &w = pf->posterior()._w(); 
    69 //  
     71// 
    7072//      vec pom = zeros ( BMs ( 0 )->posterior ().dimension() ); 
    7173//      vec pom2 = zeros ( BMs ( 0 )->posterior ().dimension() ); 
    7274//      vec mea; 
    73 //  
     75// 
    7476//      for ( int i = 0; i < w.length(); i++ ) { 
    7577//              // save current mean 
     
    8183//      return concat ( pf->posterior().variance(), pom2 - pow ( pom, 2 ) ); 
    8284// } 
    83 //  
     85// 
    8486// void MPF::mpfepdf::qbounds ( vec &lb, vec &ub, double perc ) const { 
    8587//      //bounds on particles 
     
    8789//      vec ubp; 
    8890//      pf->posterior().qbounds ( lbp, ubp ); 
    89 //  
     91// 
    9092//      //bounds on Components 
    9193//      int dimC = BMs ( 0 )->posterior().dimension(); 
     
    99101//      Lbc = std::numeric_limits<double>::infinity(); 
    100102//      Ubc = -std::numeric_limits<double>::infinity(); 
    101 //  
     103// 
    102104//      for ( int i = 0; i < BMs.length(); i++ ) { 
    103105//              // check Coms 
     
    116118//      ub = concat ( ubp, Ubc ); 
    117119// } 
    118 //  
    119 //  
    120 //  
     120// 
     121// 
     122// 
    121123// void MPF::bayes ( const vec &yt, const vec &cond ) { 
    122124//      // follows PF::bayes in most places!!! 
     
    125127//      vec &lls = pf->_lls(); 
    126128//      Array<vec> &samples = pf->__samples(); 
    127 //  
     129// 
    128130//      // generate samples - time step 
    129131//      pf->bayes_gensmp ( vec ( 0 ) ); 
     
    137139//              lls ( i ) += BMs ( i )->_ll(); 
    138140//      } 
    139 //  
     141// 
    140142//      pf->bayes_weights(); 
    141 //  
     143// 
    142144//      ivec ind; 
    143145//      if ( pf->do_resampling() ) { 
    144146//              pf->resample ( ind ); 
    145 //  
     147// 
    146148// #pragma omp parallel for 
    147149//              for ( i = 0; i < n; i++ ) { 
     
    153155//      } 
    154156// }; 
    155 //  
    156 //  
     157// 
     158// 
    157159// void MPF_ARXg::bayes ( const vec &yt, const vec &cond ) { 
    158160//      // follows PF::bayes in most places!!! 
     
    161163//      vec &lls = pf->_lls(); 
    162164//      Array<vec> &samples = pf->__samples(); 
    163 //       
     165// 
    164166//      // generate samples - time step 
    165167//      for (int i =0;i<n; i++){ 
     
    177179//      ooo.set_parameters(zeros(2),0.1*eye(2)); 
    178180//      ooo.validate(); 
    179 //       
     181// 
    180182//      #pragma parallel for 
    181183//      for ( i = 0; i < n; i++ ) { 
     
    187189//              lls(i) = ooo.evallog_nn(yt); 
    188190//      } 
    189 //       
     191// 
    190192//      pf->bayes_weights(); 
    191 //       
     193// 
    192194//      ivec ind; 
    193195//      if ( pf->do_resampling() ) { 
    194196//              pf->resample ( ind ); 
    195 //               
     197// 
    196198//              #pragma omp parallel for 
    197199//              for ( i = 0; i < n; i++ ) { 
     
    205207//      } 
    206208// }; 
    207 //  
     209// 
    208210// void MPF_ARXg::from_setting(const libconfig::Setting& set) { 
    209211//      BM::from_setting(set); 
    210 //       
     212// 
    211213//      pf = new PF; 
    212214//      // prior must be set before BM 
    213215//      pf->prior_from_set ( set ); 
    214216//      pf->resmethod_from_set ( set ); 
    215 //               
     217// 
    216218//      // read functions g and h 
    217219//      g=UI::build<fnc>(set,"g"); 
    218220//      h=UI::build<fnc>(set,"h"); 
    219 //       
     221// 
    220222//      set_dim( g->dimension()); 
    221223//      dimy = h->dimension(); 
    222 //       
     224// 
    223225//      shared_ptr<ARX> arxo=UI::build<ARX>(set,"arxo"); 
    224226//      shared_ptr<ARX> arxp=UI::build<ARX>(set,"arxp"); 
     
    230232//              BMsp(i)=arxp->_copy(); 
    231233//      } 
    232 //       
     234// 
    233235//      yrv = arxo->_yrv(); 
    234236//      //rvc = arxo->_rvc(); 
    235 //       
     237// 
    236238//      validate(); 
    237 //       
     239// 
    238240// } 
    239241