Changeset 211 for bdm

Show
Ignore:
Timestamp:
11/13/08 20:00:53 (16 years ago)
Author:
smidl
Message:

prejmenovani evalpdflog a evalcond

Location:
bdm
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/libKF.cpp

    r141 r211  
    158158         
    159159        if ( evalll==true ) { //likelihood of observation y 
    160                 ll=fy.evalpdflog ( y ); 
     160                ll=fy.evallog ( y ); 
    161161        } 
    162162} 
     
    232232 
    233233        if ( evalll==true ) { //likelihood of observation y 
    234                 ll=fy.evalpdflog ( y ); 
     234                ll=fy.evallog ( y ); 
    235235        } 
    236236} 
  • bdm/estim/libKF.h

    r200 r211  
    332332 
    333333        if ( evalll==true ) { //likelihood of observation y 
    334                 ll=fy.evalpdflog ( y ); 
     334                ll=fy.evallog ( y ); 
    335335        } 
    336336 
     
    395395        ( _mu ) += _K* ( y-_yp ); 
    396396 
    397         if ( evalll==true ) {ll+=fy.evalpdflog ( y );} 
     397        if ( evalll==true ) {ll+=fy.evallog ( y );} 
    398398}; 
    399399 
  • bdm/estim/libPF.cpp

    r60 r211  
    1414                //generate new samples from paramater evolution model; 
    1515                _samples ( i ) = par.samplecond ( _samples ( i ), lls ( i ) ); 
    16                 lls ( i ) *= obs.evalcond ( dt,_samples ( i ) ); 
     16                lls ( i ) *= obs.evallogcond ( dt,_samples ( i ) ); 
    1717 
    1818                if ( lls ( i ) >mlls ) mlls=lls ( i ); //find maximum 
  • bdm/estim/libPF.h

    r200 r211  
    9494                vec sample() const {it_error ( "Not implemented" );return 0;} 
    9595 
    96                 double evalpdflog ( const vec &val ) const {it_error ( "not implemented" ); return 0.0;} 
     96                double evallog ( const vec &val ) const {it_error ( "not implemented" ); return 0.0;} 
    9797        }; 
    9898 
  • bdm/estim/merger.cpp

    r205 r211  
    102102                                // no need for conditioning or marginalization 
    103103                                for ( int j=0;j<Ns; j++ ) { // Smp is Array<> => for cycle 
    104                                         lw_src ( j ) =mpdfs ( i )->_epdf().evalpdflog ( Smp ( j ) ); 
     104                                        lw_src ( j ) =mpdfs ( i )->_epdf().evallog ( Smp ( j ) ); 
    105105                                } 
    106106                        } 
     
    113113                                        for ( int k=0;k<Ns;k++ ) { 
    114114                                                // Here val of tmp_marg = cond of mpdfs(i) ==> calling dls->get_cond 
    115                                                 lw_src ( k ) += tmp_marg->evalpdflog ( dls ( i )->get_cond ( Smp ( k ) ) ); 
     115                                                lw_src ( k ) += tmp_marg->evallog ( dls ( i )->get_cond ( Smp ( k ) ) ); 
    116116                                        } 
    117117                                        delete tmp_marg; 
     
    130130                                        for ( int k= 0; k<Ns; k++ ) { 
    131131                                                lw_src ( k ) += log ( 
    132                                                                     tmp_cond->evalcond ( 
     132                                                                    tmp_cond->evallogcond ( 
    133133                                                                        zdls ( i )->get_val ( Smp ( k ) ), 
    134134                                                                        zdls ( i )->get_cond ( Smp ( k ) ) ) ); 
     
    142142                                for ( int k= 0; k<Ns; k++ ) { 
    143143                                        mpdfs ( i )->condition ( dls ( i )->get_cond ( Smp ( k ) ) ); 
    144                                         lw_src ( k ) += mpdfs ( i )->_epdf().evalpdflog ( dls ( i )->get_val ( Smp ( k ) ) ); 
     144                                        lw_src ( k ) += mpdfs ( i )->_epdf().evallog ( dls ( i )->get_val ( Smp ( k ) ) ); 
    145145                                } 
    146146 
  • bdm/estim/merger.h

    r205 r211  
    8888//! weight w is a 
    8989        vec sample ( ) const { return Mix._epdf().sample();} 
    90         double evalpdflog ( const vec &dt ) const { 
     90        double evallog ( const vec &dt ) const { 
    9191                vec dtf=ones ( dt.length() +1 ); 
    9292                dtf.set_subvector ( 0,dt ); 
  • bdm/stat/emix.h

    r204 r211  
    3232In particular this type of arise by conditioning of a mixture model. 
    3333 
    34 At present the only supported operation is evalcond(). 
     34At present the only supported operation is evallogcond(). 
    3535 */ 
    3636class mratio: public mpdf { 
     
    6060                den = nom->marginal ( rvc ); 
    6161        }; 
    62         double evalcond ( const vec &val, const vec &cond ) { 
     62        double evallogcond ( const vec &val, const vec &cond ) { 
    6363                vec nom_val ( rv.count() +rvc.count() ); 
    6464                dl.fill_val_cond ( nom_val,val,cond ); 
    65                 return exp ( nom->evalpdflog ( nom_val ) - den->evalpdflog ( cond ) ); 
     65                return exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 
    6666        } 
    6767        //! Object takes ownership of nom and will destroy it 
     
    102102                return mu; 
    103103        } 
    104         double evalpdflog ( const vec &val ) const { 
     104        double evallog ( const vec &val ) const { 
    105105                int i; 
    106106                double sum = 0.0; 
    107                 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->evalpdflog ( val ) );} 
     107                for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->evallog ( val ) );} 
    108108                return log ( sum ); 
    109109        }; 
    110         vec evalpdflog_m ( const mat &Val ) const { 
     110        vec evallog_m ( const mat &Val ) const { 
    111111                vec x=zeros ( Val.cols() ); 
    112112                for ( int i = 0; i < w.length(); i++ ) { 
    113                         x+= w ( i ) *exp ( Coms ( i )->evalpdflog_m ( Val ) ); 
     113                        x+= w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ); 
    114114                } 
    115115                return log ( x ); 
    116116        }; 
    117         mat evalpdflog_M ( const mat &Val ) const { 
     117        mat evallog_M ( const mat &Val ) const { 
    118118                mat X ( w.length(), Val.cols() ); 
    119119                for ( int i = 0; i < w.length(); i++ ) { 
    120                         X.set_row ( i, w ( i ) *exp ( Coms ( i )->evalpdflog_m ( Val ) ) ); 
     120                        X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ) ); 
    121121                } 
    122122                return X; 
     
    166166        }; 
    167167 
    168         double evalcond ( const vec &val, const vec &cond ) { 
     168        double evallogcond ( const vec &val, const vec &cond ) { 
    169169                int i; 
    170170                double res = 1.0; 
     
    174174                                                } 
    175175                                                // add logarithms 
    176                                                 res += epdfs ( i )->evalpdflog ( dls ( i )->get_val ( val ) );*/ 
    177                         res *= mpdfs ( i )->evalcond ( 
     176                                                res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/ 
     177                        res *= mpdfs ( i )->evallogcond ( 
    178178                                   dls ( i )->get_val ( val ), 
    179179                                   dls ( i )->get_cond ( val, cond ) 
     
    196196                        dls ( i )->fill_val ( smp, smpi ); 
    197197                        // add ith likelihood contribution 
    198                         ll+=epdfs ( i )->evalpdflog ( smpi ); 
     198                        ll+=epdfs ( i )->evallog ( smpi ); 
    199199                } 
    200200                return smp; 
     
    244244                return tmp; 
    245245        } 
    246         double evalpdflog ( const vec &val ) const { 
     246        double evallog ( const vec &val ) const { 
    247247                double tmp=0; 
    248248                for ( int i=0;i<epdfs.length();i++ ) { 
    249                         tmp+=epdfs ( i )->evalpdflog ( dls ( i )->get_val ( val ) ); 
     249                        tmp+=epdfs ( i )->evallog ( dls ( i )->get_val ( val ) ); 
    250250                } 
    251251                return tmp; 
  • bdm/stat/libBM.cpp

    r201 r211  
    88 
    99static int RVcounter=0; 
     10 
     11RV RV0=RV(); 
    1012 
    1113void RV::init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ) { 
  • bdm/stat/libBM.h

    r203 r211  
    126126RV concat ( const RV &rv1, const RV &rv2 ); 
    127127 
     128//!Default empty RV that can be used as default argument 
     129extern RV RV0; 
    128130 
    129131//! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv 
     
    172174         
    173175        //! Compute log-probability of argument \c val 
    174         virtual double evalpdflog ( const vec &val ) const =0; 
     176        virtual double evallog ( const vec &val ) const =0; 
    175177 
    176178        //! Compute log-probability of multiple values argument \c val 
    177         virtual vec evalpdflog_m ( const mat &Val ) const { 
     179        virtual vec evallog_m ( const mat &Val ) const { 
    178180                vec x ( Val.cols() ); 
    179                 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evalpdflog ( Val.get_col ( i ) ) ;} 
     181                for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evallog ( Val.get_col ( i ) ) ;} 
    180182                return x; 
    181183        } 
     
    217219                this->condition ( cond ); 
    218220                vec temp= ep->sample(); 
    219                 ll=ep->evalpdflog ( temp );return temp; 
     221                ll=ep->evallog ( temp );return temp; 
    220222        }; 
    221223        //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv \param ll is a return value of log-likelihood of the sample. 
    222         virtual mat samplecond ( const vec &cond, vec &ll, int N ) { 
     224        virtual mat samplecond_m ( const vec &cond, vec &ll, int N ) { 
    223225                this->condition ( cond ); 
    224226                mat temp ( rv.count(),N ); vec smp ( rv.count() ); 
    225                 for ( int i=0;i<N;i++ ) {smp=ep->sample() ;temp.set_col ( i, smp );ll ( i ) =ep->evalpdflog ( smp );} 
     227                for ( int i=0;i<N;i++ ) {smp=ep->sample() ;temp.set_col ( i, smp );ll ( i ) =ep->evallog ( smp );} 
    226228                return temp; 
    227229        }; 
     
    230232 
    231233        //! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently. 
    232         virtual double evalcond ( const vec &dt, const vec &cond ) {this->condition ( cond );return exp(ep->evalpdflog ( dt ));}; 
    233  
    234         virtual vec evalcond_m ( const mat &Dt, const vec &cond ) {this->condition ( cond );return exp(ep->evalpdflog_m ( Dt ));}; 
     234        virtual double evallogcond ( const vec &dt, const vec &cond ) {this->condition ( cond );return ep->evallog ( dt );}; 
     235 
     236        //! Matrix version of evallogcond 
     237        virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {this->condition ( cond );return ep->evallog_m ( Dt );}; 
    235238 
    236239        //! Destructor for future use; 
  • bdm/stat/libEF.cpp

    r198 r211  
    1919} 
    2020 
    21 double egiw::evalpdflog_nn ( const vec &val ) const { 
     21double egiw::evallog_nn ( const vec &val ) const { 
    2222        int vend = val.length()-1; 
    2323 
     
    128128// } 
    129129 
    130 double egamma::evalpdflog ( const vec &val ) const { 
     130double egamma::evallog ( const vec &val ) const { 
    131131        double res = 0.0; //the rest will be added 
    132132        int i; 
  • bdm/stat/libEF.h

    r205 r211  
    4646        virtual void dupdate ( mat &v ) {it_error ( "Not implemented" );}; 
    4747        //!Evaluate normalized log-probability 
    48         virtual double evalpdflog_nn ( const vec &val ) const{it_error ( "Not implemented" );return 0.0;}; 
     48        virtual double evallog_nn ( const vec &val ) const{it_error ( "Not implemented" );return 0.0;}; 
    4949        //!Evaluate normalized log-probability 
    50         virtual double evalpdflog ( const vec &val ) const {double tmp;tmp= evalpdflog_nn ( val )-lognc();it_assert_debug(std::isfinite(tmp),"why?"); return tmp;} 
     50        virtual double evallog ( const vec &val ) const {double tmp;tmp= evallog_nn ( val )-lognc();it_assert_debug(std::isfinite(tmp),"why?"); return tmp;} 
    5151        //!Evaluate normalized log-probability for many samples 
    52         virtual vec evalpdflog ( const mat &Val ) const { 
     52        virtual vec evallog ( const mat &Val ) const { 
    5353                vec x ( Val.cols() ); 
    54                 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evalpdflog_nn ( Val.get_col ( i ) ) ;} 
     54                for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evallog_nn ( Val.get_col ( i ) ) ;} 
    5555                return x-lognc(); 
    5656        } 
     
    129129        mat sample ( int N ) const; 
    130130        double eval ( const vec &val ) const ; 
    131         double evalpdflog_nn ( const vec &val ) const; 
     131        double evallog_nn ( const vec &val ) const; 
    132132        double lognc () const; 
    133133        vec mean() const {return mu;} 
     
    193193        void mean_mat ( mat &M, mat&R ) const; 
    194194        //! In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise val = [theta_1 theta_2 ... r_1 r_2 ] 
    195         double evalpdflog_nn ( const vec &val ) const; 
     195        double evallog_nn ( const vec &val ) const; 
    196196        double lognc () const; 
    197197 
     
    227227        vec mean() const {return beta/sum ( beta );}; 
    228228        //! In this instance, val is ... 
    229         double evalpdflog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );}; 
     229        double evallog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );}; 
    230230        double lognc () const { 
    231231                double gam=sum ( beta ); 
     
    318318        //! TODO: is it used anywhere? 
    319319//      mat sample ( int N ) const; 
    320         double evalpdflog ( const vec &val ) const; 
     320        double evallog ( const vec &val ) const; 
    321321        double lognc () const; 
    322322        //! Returns poiter to alpha and beta. Potentially dengerous: use with care! 
     
    358358        euni ( const RV rv ) :epdf ( rv ) {} 
    359359        double eval ( const vec &val ) const  {return nk;} 
    360         double evalpdflog ( const vec &val ) const  {return lnk;} 
     360        double evallog ( const vec &val ) const  {return lnk;} 
    361361        vec sample() const { 
    362362                vec smp ( rv.count() ); 
     
    538538        vec sample() const {it_error ( "Not implemented" );return 0;} 
    539539        //! inherited operation : NOT implemneted 
    540         double evalpdflog ( const vec &val ) const {it_error ( "Not implemented" );return 0.0;} 
     540        double evallog ( const vec &val ) const {it_error ( "Not implemented" );return 0.0;} 
    541541        vec mean() const { 
    542542                vec pom=zeros ( rv.count() ); 
     
    599599double enorm<sq_T>::eval ( const vec &val ) const { 
    600600        double pdfl,e; 
    601         pdfl = evalpdflog ( val ); 
     601        pdfl = evallog ( val ); 
    602602        e = exp ( pdfl ); 
    603603        return e; 
     
    605605 
    606606template<class sq_T> 
    607 double enorm<sq_T>::evalpdflog_nn ( const vec &val ) const { 
     607double enorm<sq_T>::evallog_nn ( const vec &val ) const { 
    608608        // 1.83787706640935 = log(2pi) 
    609609        double tmp=-0.5* ( R.invqform ( mu-val ) );// - lognc();