- Timestamp:
- 11/13/08 20:00:53 (16 years ago)
- Location:
- bdm
- Files:
-
- 11 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/estim/libKF.cpp
r141 r211 158 158 159 159 if ( evalll==true ) { //likelihood of observation y 160 ll=fy.eval pdflog ( y );160 ll=fy.evallog ( y ); 161 161 } 162 162 } … … 232 232 233 233 if ( evalll==true ) { //likelihood of observation y 234 ll=fy.eval pdflog ( y );234 ll=fy.evallog ( y ); 235 235 } 236 236 } -
bdm/estim/libKF.h
r200 r211 332 332 333 333 if ( evalll==true ) { //likelihood of observation y 334 ll=fy.eval pdflog ( y );334 ll=fy.evallog ( y ); 335 335 } 336 336 … … 395 395 ( _mu ) += _K* ( y-_yp ); 396 396 397 if ( evalll==true ) {ll+=fy.eval pdflog ( y );}397 if ( evalll==true ) {ll+=fy.evallog ( y );} 398 398 }; 399 399 -
bdm/estim/libPF.cpp
r60 r211 14 14 //generate new samples from paramater evolution model; 15 15 _samples ( i ) = par.samplecond ( _samples ( i ), lls ( i ) ); 16 lls ( i ) *= obs.eval cond ( dt,_samples ( i ) );16 lls ( i ) *= obs.evallogcond ( dt,_samples ( i ) ); 17 17 18 18 if ( lls ( i ) >mlls ) mlls=lls ( i ); //find maximum -
bdm/estim/libPF.h
r200 r211 94 94 vec sample() const {it_error ( "Not implemented" );return 0;} 95 95 96 double eval pdflog ( 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;} 97 97 }; 98 98 -
bdm/estim/merger.cpp
r205 r211 102 102 // no need for conditioning or marginalization 103 103 for ( int j=0;j<Ns; j++ ) { // Smp is Array<> => for cycle 104 lw_src ( j ) =mpdfs ( i )->_epdf().eval pdflog ( Smp ( j ) );104 lw_src ( j ) =mpdfs ( i )->_epdf().evallog ( Smp ( j ) ); 105 105 } 106 106 } … … 113 113 for ( int k=0;k<Ns;k++ ) { 114 114 // Here val of tmp_marg = cond of mpdfs(i) ==> calling dls->get_cond 115 lw_src ( k ) += tmp_marg->eval pdflog ( dls ( i )->get_cond ( Smp ( k ) ) );115 lw_src ( k ) += tmp_marg->evallog ( dls ( i )->get_cond ( Smp ( k ) ) ); 116 116 } 117 117 delete tmp_marg; … … 130 130 for ( int k= 0; k<Ns; k++ ) { 131 131 lw_src ( k ) += log ( 132 tmp_cond->eval cond (132 tmp_cond->evallogcond ( 133 133 zdls ( i )->get_val ( Smp ( k ) ), 134 134 zdls ( i )->get_cond ( Smp ( k ) ) ) ); … … 142 142 for ( int k= 0; k<Ns; k++ ) { 143 143 mpdfs ( i )->condition ( dls ( i )->get_cond ( Smp ( k ) ) ); 144 lw_src ( k ) += mpdfs ( i )->_epdf().eval pdflog ( dls ( i )->get_val ( Smp ( k ) ) );144 lw_src ( k ) += mpdfs ( i )->_epdf().evallog ( dls ( i )->get_val ( Smp ( k ) ) ); 145 145 } 146 146 -
bdm/estim/merger.h
r205 r211 88 88 //! weight w is a 89 89 vec sample ( ) const { return Mix._epdf().sample();} 90 double eval pdflog ( const vec &dt ) const {90 double evallog ( const vec &dt ) const { 91 91 vec dtf=ones ( dt.length() +1 ); 92 92 dtf.set_subvector ( 0,dt ); -
bdm/stat/emix.h
r204 r211 32 32 In particular this type of arise by conditioning of a mixture model. 33 33 34 At present the only supported operation is eval cond().34 At present the only supported operation is evallogcond(). 35 35 */ 36 36 class mratio: public mpdf { … … 60 60 den = nom->marginal ( rvc ); 61 61 }; 62 double eval cond ( const vec &val, const vec &cond ) {62 double evallogcond ( const vec &val, const vec &cond ) { 63 63 vec nom_val ( rv.count() +rvc.count() ); 64 64 dl.fill_val_cond ( nom_val,val,cond ); 65 return exp ( nom->eval pdflog ( nom_val ) - den->evalpdflog ( cond ) );65 return exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 66 66 } 67 67 //! Object takes ownership of nom and will destroy it … … 102 102 return mu; 103 103 } 104 double eval pdflog ( const vec &val ) const {104 double evallog ( const vec &val ) const { 105 105 int i; 106 106 double sum = 0.0; 107 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->eval pdflog ( val ) );}107 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->evallog ( val ) );} 108 108 return log ( sum ); 109 109 }; 110 vec eval pdflog_m ( const mat &Val ) const {110 vec evallog_m ( const mat &Val ) const { 111 111 vec x=zeros ( Val.cols() ); 112 112 for ( int i = 0; i < w.length(); i++ ) { 113 x+= w ( i ) *exp ( Coms ( i )->eval pdflog_m ( Val ) );113 x+= w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ); 114 114 } 115 115 return log ( x ); 116 116 }; 117 mat eval pdflog_M ( const mat &Val ) const {117 mat evallog_M ( const mat &Val ) const { 118 118 mat X ( w.length(), Val.cols() ); 119 119 for ( int i = 0; i < w.length(); i++ ) { 120 X.set_row ( i, w ( i ) *exp ( Coms ( i )->eval pdflog_m ( Val ) ) );120 X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ) ); 121 121 } 122 122 return X; … … 166 166 }; 167 167 168 double eval cond ( const vec &val, const vec &cond ) {168 double evallogcond ( const vec &val, const vec &cond ) { 169 169 int i; 170 170 double res = 1.0; … … 174 174 } 175 175 // add logarithms 176 res += epdfs ( i )->eval pdflog ( dls ( i )->get_val ( val ) );*/177 res *= mpdfs ( i )->eval cond (176 res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/ 177 res *= mpdfs ( i )->evallogcond ( 178 178 dls ( i )->get_val ( val ), 179 179 dls ( i )->get_cond ( val, cond ) … … 196 196 dls ( i )->fill_val ( smp, smpi ); 197 197 // add ith likelihood contribution 198 ll+=epdfs ( i )->eval pdflog ( smpi );198 ll+=epdfs ( i )->evallog ( smpi ); 199 199 } 200 200 return smp; … … 244 244 return tmp; 245 245 } 246 double eval pdflog ( const vec &val ) const {246 double evallog ( const vec &val ) const { 247 247 double tmp=0; 248 248 for ( int i=0;i<epdfs.length();i++ ) { 249 tmp+=epdfs ( i )->eval pdflog ( dls ( i )->get_val ( val ) );249 tmp+=epdfs ( i )->evallog ( dls ( i )->get_val ( val ) ); 250 250 } 251 251 return tmp; -
bdm/stat/libBM.cpp
r201 r211 8 8 9 9 static int RVcounter=0; 10 11 RV RV0=RV(); 10 12 11 13 void RV::init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ) { -
bdm/stat/libBM.h
r203 r211 126 126 RV concat ( const RV &rv1, const RV &rv2 ); 127 127 128 //!Default empty RV that can be used as default argument 129 extern RV RV0; 128 130 129 131 //! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv … … 172 174 173 175 //! Compute log-probability of argument \c val 174 virtual double eval pdflog ( const vec &val ) const =0;176 virtual double evallog ( const vec &val ) const =0; 175 177 176 178 //! Compute log-probability of multiple values argument \c val 177 virtual vec eval pdflog_m ( const mat &Val ) const {179 virtual vec evallog_m ( const mat &Val ) const { 178 180 vec x ( Val.cols() ); 179 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =eval pdflog ( Val.get_col ( i ) ) ;}181 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evallog ( Val.get_col ( i ) ) ;} 180 182 return x; 181 183 } … … 217 219 this->condition ( cond ); 218 220 vec temp= ep->sample(); 219 ll=ep->eval pdflog ( temp );return temp;221 ll=ep->evallog ( temp );return temp; 220 222 }; 221 223 //! 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 ) { 223 225 this->condition ( cond ); 224 226 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->eval pdflog ( smp );}227 for ( int i=0;i<N;i++ ) {smp=ep->sample() ;temp.set_col ( i, smp );ll ( i ) =ep->evallog ( smp );} 226 228 return temp; 227 229 }; … … 230 232 231 233 //! 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 );}; 235 238 236 239 //! Destructor for future use; -
bdm/stat/libEF.cpp
r198 r211 19 19 } 20 20 21 double egiw::eval pdflog_nn ( const vec &val ) const {21 double egiw::evallog_nn ( const vec &val ) const { 22 22 int vend = val.length()-1; 23 23 … … 128 128 // } 129 129 130 double egamma::eval pdflog ( const vec &val ) const {130 double egamma::evallog ( const vec &val ) const { 131 131 double res = 0.0; //the rest will be added 132 132 int i; -
bdm/stat/libEF.h
r205 r211 46 46 virtual void dupdate ( mat &v ) {it_error ( "Not implemented" );}; 47 47 //!Evaluate normalized log-probability 48 virtual double eval pdflog_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;}; 49 49 //!Evaluate normalized log-probability 50 virtual double eval pdflog ( 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;} 51 51 //!Evaluate normalized log-probability for many samples 52 virtual vec eval pdflog ( const mat &Val ) const {52 virtual vec evallog ( const mat &Val ) const { 53 53 vec x ( Val.cols() ); 54 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =eval pdflog_nn ( Val.get_col ( i ) ) ;}54 for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evallog_nn ( Val.get_col ( i ) ) ;} 55 55 return x-lognc(); 56 56 } … … 129 129 mat sample ( int N ) const; 130 130 double eval ( const vec &val ) const ; 131 double eval pdflog_nn ( const vec &val ) const;131 double evallog_nn ( const vec &val ) const; 132 132 double lognc () const; 133 133 vec mean() const {return mu;} … … 193 193 void mean_mat ( mat &M, mat&R ) const; 194 194 //! In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise val = [theta_1 theta_2 ... r_1 r_2 ] 195 double eval pdflog_nn ( const vec &val ) const;195 double evallog_nn ( const vec &val ) const; 196 196 double lognc () const; 197 197 … … 227 227 vec mean() const {return beta/sum ( beta );}; 228 228 //! In this instance, val is ... 229 double eval pdflog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );};229 double evallog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );}; 230 230 double lognc () const { 231 231 double gam=sum ( beta ); … … 318 318 //! TODO: is it used anywhere? 319 319 // mat sample ( int N ) const; 320 double eval pdflog ( const vec &val ) const;320 double evallog ( const vec &val ) const; 321 321 double lognc () const; 322 322 //! Returns poiter to alpha and beta. Potentially dengerous: use with care! … … 358 358 euni ( const RV rv ) :epdf ( rv ) {} 359 359 double eval ( const vec &val ) const {return nk;} 360 double eval pdflog ( const vec &val ) const {return lnk;}360 double evallog ( const vec &val ) const {return lnk;} 361 361 vec sample() const { 362 362 vec smp ( rv.count() ); … … 538 538 vec sample() const {it_error ( "Not implemented" );return 0;} 539 539 //! inherited operation : NOT implemneted 540 double eval pdflog ( 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;} 541 541 vec mean() const { 542 542 vec pom=zeros ( rv.count() ); … … 599 599 double enorm<sq_T>::eval ( const vec &val ) const { 600 600 double pdfl,e; 601 pdfl = eval pdflog ( val );601 pdfl = evallog ( val ); 602 602 e = exp ( pdfl ); 603 603 return e; … … 605 605 606 606 template<class sq_T> 607 double enorm<sq_T>::eval pdflog_nn ( const vec &val ) const {607 double enorm<sq_T>::evallog_nn ( const vec &val ) const { 608 608 // 1.83787706640935 = log(2pi) 609 609 double tmp=-0.5* ( R.invqform ( mu-val ) );// - lognc();