Changeset 214

Show
Ignore:
Timestamp:
11/27/08 23:31:48 (15 years ago)
Author:
smidl
Message:

debug asserts for infinite likelihoods

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/emix.h

    r211 r214  
    6161        }; 
    6262        double evallogcond ( const vec &val, const vec &cond ) { 
     63                double tmp; 
    6364                vec nom_val ( rv.count() +rvc.count() ); 
    6465                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; 
    6669        } 
    6770        //! Object takes ownership of nom and will destroy it 
     
    106109                double sum = 0.0; 
    107110                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; 
    109115        }; 
    110116        vec evallog_m ( const mat &Val ) const { 
     
    115121                return log ( x ); 
    116122        }; 
     123        //! Auxiliary function that returns pdflog for each component 
    117124        mat evallog_M ( const mat &Val ) const { 
    118125                mat X ( w.length(), Val.cols() ); 
     
    249256                        tmp+=epdfs ( i )->evallog ( dls ( i )->get_val ( val ) ); 
    250257                } 
     258                it_assert_debug(std::isfinite(tmp),"Infinite"); 
    251259                return tmp; 
    252260        } 
  • bdm/stat/libBM.h

    r211 r214  
    232232 
    233233        //! 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        }; 
    235236 
    236237        //! Matrix version of evallogcond 
  • bdm/stat/libEF.cpp

    r211 r214  
    135135                res += ( alpha ( i ) - 1 ) *std::log ( val ( i ) ) - beta ( i ) *val ( i ); 
    136136        } 
    137  
    138         return res-lognc(); 
     137        double tmp=res-lognc();; 
     138        it_assert_debug(std::isfinite(tmp),"Infinite value"); 
     139        return tmp; 
    139140} 
    140141 
  • bdm/stat/libEF.h

    r211 r214  
    4848        virtual double evallog_nn ( const vec &val ) const{it_error ( "Not implemented" );return 0.0;}; 
    4949        //!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;} 
    5151        //!Evaluate normalized log-probability for many samples 
    5252        virtual vec evallog ( const mat &Val ) const { 
     
    128128        //! TODO is it used? 
    129129        mat sample ( int N ) const; 
    130         double eval ( const vec &val ) const ; 
     130//      double eval ( const vec &val ) const ; 
    131131        double evallog_nn ( const vec &val ) const; 
    132132        double lognc () const; 
     
    227227        vec mean() const {return beta/sum ( beta );}; 
    228228        //! 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;}; 
    230231        double lognc () const { 
     232                double tmp; 
    231233                double gam=sum ( beta ); 
    232234                double lgb=0.0; 
    233235                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; 
    235239        }; 
    236240        //!access function 
     
    255259public: 
    256260        //!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;}} 
    258262        //!Copy constructor 
    259263        multiBM ( const multiBM &B ) : BMEF ( B ),est ( rv,B.beta ),beta ( est._beta() ) {} 
     
    596600}; 
    597601 
    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// }; 
    605609 
    606610template<class sq_T> 
  • tests/testEpdf.cpp

    r162 r214  
    3131                        pom ( 0 ) = x ( i ); 
    3232                        pom ( 1 ) = y ( j ); 
    33                         suma+= eN.eval ( pom ); 
     33                        suma+= exp(eN.evallog ( pom )); 
    3434                } 
    3535        }