Show
Ignore:
Timestamp:
11/25/09 18:02:21 (14 years ago)
Author:
mido
Message:

the rest of h to cpp movements, with exception of from_setting and validate to avoid conflicts with Sarka

Files:
1 modified

Legend:

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

    r737 r739  
    7575// } 
    7676 
     77vec MPF::mpfepdf::mean() const { 
     78        const vec &w = pf->posterior()._w(); 
     79        vec pom = zeros ( BMs ( 0 )->posterior ().dimension() ); 
     80        //compute mean of BMs 
     81        for ( int i = 0; i < w.length(); i++ ) { 
     82                pom += BMs ( i )->posterior().mean() * w ( i ); 
     83        } 
     84        return concat ( pf->posterior().mean(), pom ); 
     85} 
     86 
     87vec MPF::mpfepdf::variance() const { 
     88        const vec &w = pf->posterior()._w(); 
     89 
     90        vec pom = zeros ( BMs ( 0 )->posterior ().dimension() ); 
     91        vec pom2 = zeros ( BMs ( 0 )->posterior ().dimension() ); 
     92        vec mea; 
     93 
     94        for ( int i = 0; i < w.length(); i++ ) { 
     95                // save current mean 
     96                mea = BMs ( i )->posterior().mean(); 
     97                pom += mea * w ( i ); 
     98                //compute variance 
     99                pom2 += ( BMs ( i )->posterior().variance() + pow ( mea, 2 ) ) * w ( i ); 
     100        } 
     101        return concat ( pf->posterior().variance(), pom2 - pow ( pom, 2 ) ); 
     102} 
     103 
     104void MPF::mpfepdf::qbounds ( vec &lb, vec &ub, double perc ) const { 
     105        //bounds on particles 
     106        vec lbp; 
     107        vec ubp; 
     108        pf->posterior().qbounds ( lbp, ubp ); 
     109 
     110        //bounds on Components 
     111        int dimC = BMs ( 0 )->posterior().dimension(); 
     112        int j; 
     113        // temporary 
     114        vec lbc ( dimC ); 
     115        vec ubc ( dimC ); 
     116        // minima and maxima 
     117        vec Lbc ( dimC ); 
     118        vec Ubc ( dimC ); 
     119        Lbc = std::numeric_limits<double>::infinity(); 
     120        Ubc = -std::numeric_limits<double>::infinity(); 
     121 
     122        for ( int i = 0; i < BMs.length(); i++ ) { 
     123                // check Coms 
     124                BMs ( i )->posterior().qbounds ( lbc, ubc ); 
     125                //save either minima or maxima 
     126                for ( j = 0; j < dimC; j++ ) { 
     127                        if ( lbc ( j ) < Lbc ( j ) ) { 
     128                                Lbc ( j ) = lbc ( j ); 
     129                        } 
     130                        if ( ubc ( j ) > Ubc ( j ) ) { 
     131                                Ubc ( j ) = ubc ( j ); 
     132                        } 
     133                } 
     134        } 
     135        lb = concat ( lbp, Lbc ); 
     136        ub = concat ( ubp, Ubc ); 
     137} 
     138 
     139 
     140 
    77141void MPF::bayes ( const vec &yt, const vec &cond ) { 
    78142        // follows PF::bayes in most places!!!