Changeset 214
- Timestamp:
- 11/27/08 23:31:48 (16 years ago)
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/emix.h
r211 r214 61 61 }; 62 62 double evallogcond ( const vec &val, const vec &cond ) { 63 double tmp; 63 64 vec nom_val ( rv.count() +rvc.count() ); 64 65 dl.fill_val_cond ( nom_val,val,cond ); 65 return exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 66 tmp = exp ( nom->evallog ( nom_val ) - den->evallog ( cond ) ); 67 it_assert_debug(std::isfinite(tmp),"Infinite value"); 68 return tmp; 66 69 } 67 70 //! Object takes ownership of nom and will destroy it … … 106 109 double sum = 0.0; 107 110 for ( i = 0;i < w.length();i++ ) {sum += w ( i ) * exp ( Coms ( i )->evallog ( val ) );} 108 return log ( sum ); 111 if (sum==0.0){sum=std::numeric_limits<double>::epsilon();} 112 double tmp=log ( sum ); 113 it_assert_debug(std::isfinite(tmp),"Infinite"); 114 return tmp; 109 115 }; 110 116 vec evallog_m ( const mat &Val ) const { … … 115 121 return log ( x ); 116 122 }; 123 //! Auxiliary function that returns pdflog for each component 117 124 mat evallog_M ( const mat &Val ) const { 118 125 mat X ( w.length(), Val.cols() ); … … 249 256 tmp+=epdfs ( i )->evallog ( dls ( i )->get_val ( val ) ); 250 257 } 258 it_assert_debug(std::isfinite(tmp),"Infinite"); 251 259 return tmp; 252 260 } -
bdm/stat/libBM.h
r211 r214 232 232 233 233 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. 234 virtual double evallogcond ( const vec &dt, const vec &cond ) {this->condition ( cond );return ep->evallog ( dt );}; 234 virtual double evallogcond ( const vec &dt, const vec &cond ) {double tmp; this->condition ( cond );tmp = ep->evallog ( dt ); it_assert_debug(std::isfinite(tmp),"Infinite value"); return tmp; 235 }; 235 236 236 237 //! Matrix version of evallogcond -
bdm/stat/libEF.cpp
r211 r214 135 135 res += ( alpha ( i ) - 1 ) *std::log ( val ( i ) ) - beta ( i ) *val ( i ); 136 136 } 137 138 return res-lognc(); 137 double tmp=res-lognc();; 138 it_assert_debug(std::isfinite(tmp),"Infinite value"); 139 return tmp; 139 140 } 140 141 -
bdm/stat/libEF.h
r211 r214 48 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 evallog ( const vec &val ) const {double tmp;tmp= evallog_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),"Infinite value"); return tmp;} 51 51 //!Evaluate normalized log-probability for many samples 52 52 virtual vec evallog ( const mat &Val ) const { … … 128 128 //! TODO is it used? 129 129 mat sample ( int N ) const; 130 double eval ( const vec &val ) const ;130 // double eval ( const vec &val ) const ; 131 131 double evallog_nn ( const vec &val ) const; 132 132 double lognc () const; … … 227 227 vec mean() const {return beta/sum ( beta );}; 228 228 //! In this instance, val is ... 229 double evallog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );}; 229 double evallog_nn ( const vec &val ) const {double tmp; tmp=( beta-1 ) *log ( val ); it_assert_debug(std::isfinite(tmp),"Infinite value"); 230 return tmp;}; 230 231 double lognc () const { 232 double tmp; 231 233 double gam=sum ( beta ); 232 234 double lgb=0.0; 233 235 for ( int i=0;i<beta.length();i++ ) {lgb+=lgamma ( beta ( i ) );} 234 return lgb-lgamma ( gam ); 236 tmp= lgb-lgamma ( gam ); 237 it_assert_debug(std::isfinite(tmp),"Infinite value"); 238 return tmp; 235 239 }; 236 240 //!access function … … 255 259 public: 256 260 //!Default constructor 257 multiBM ( const RV &rv, const vec beta0 ) : BMEF ( rv ),est ( rv,beta0 ),beta ( est._beta() ) { last_lognc=est.lognc();}261 multiBM ( const RV &rv, const vec beta0 ) : BMEF ( rv ),est ( rv,beta0 ),beta ( est._beta() ) {if(beta.length()>0){last_lognc=est.lognc();}else{last_lognc=0.0;}} 258 262 //!Copy constructor 259 263 multiBM ( const multiBM &B ) : BMEF ( B ),est ( rv,B.beta ),beta ( est._beta() ) {} … … 596 600 }; 597 601 598 template<class sq_T>599 double enorm<sq_T>::eval ( const vec &val ) const {600 double pdfl,e;601 pdfl = evallog ( val );602 e = exp ( pdfl );603 return e;604 };602 // template<class sq_T> 603 // double enorm<sq_T>::eval ( const vec &val ) const { 604 // double pdfl,e; 605 // pdfl = evallog ( val ); 606 // e = exp ( pdfl ); 607 // return e; 608 // }; 605 609 606 610 template<class sq_T> -
tests/testEpdf.cpp
r162 r214 31 31 pom ( 0 ) = x ( i ); 32 32 pom ( 1 ) = y ( j ); 33 suma+= e N.eval ( pom);33 suma+= exp(eN.evallog ( pom )); 34 34 } 35 35 }