Changeset 96 for bdm/stat/libEF.h

Show
Ignore:
Timestamp:
05/09/08 17:25:10 (16 years ago)
Author:
smidl
Message:

changes in EF - introduction of the lognc() function

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libEF.h

    r85 r96  
    3737 
    3838class eEF : public epdf { 
    39  
    4039public: 
    4140//      eEF() :epdf() {}; 
    4241        //! default constructor 
    4342        eEF ( const RV &rv ) :epdf ( rv ) {}; 
     43        //! logarithm of the normalizing constant, \f$\mathcal{I}\f$  
     44        virtual double lognc()const =0; 
    4445        //!TODO decide if it is really needed 
    4546        virtual void tupdate ( double phi, mat &vbar, double nubar ) {}; 
     
    9293        double eval ( const vec &val ) const ; 
    9394        double evalpdflog ( const vec &val ) const; 
     95        double lognc () const; 
    9496        vec mean() const {return mu;} 
    9597 
     
    106108        //! access method 
    107109        mat getR () {return R.to_mat();} 
     110}; 
     111 
     112/*! 
     113* \brief Gauss-inverse-Wishart density stored in LD form 
     114 
     115* More?... 
     116*/ 
     117class egiw : public eEF { 
     118protected: 
     119        //! Extended information matrix of sufficient statistics 
     120        ldmat V; 
     121        //! Number of data records (degrees of freedom) of sufficient statistics 
     122        double nu; 
     123public: 
     124        //!Default constructor 
     125        egiw(RV rv, mat V0, double nu0): eEF(rv), V(V0), nu(nu0) { 
     126                it_assert_debug(rv.count()==V.rows(),"Incompatible V0."); 
     127        } 
     128 
     129        vec sample() const; 
     130        vec mean() const; 
     131        double evalpdflog ( const vec &val ) const; 
     132        double lognc () const; 
     133 
     134        //Access 
     135        //! returns a pointer to the internal statistics. Use with Care! 
     136        ldmat& _V() {return V;} 
     137        //! returns a pointer to the internal statistics. Use with Care! 
     138        double& _nu() {return nu;} 
     139 
    108140}; 
    109141 
     
    132164        mat sample ( int N ) const; 
    133165        double evalpdflog ( const vec &val ) const; 
     166        double lognc () const; 
    134167        //! Returns poiter to alpha and beta. Potentially dengerous: use with care! 
    135168        void _param ( vec* &a, vec* &b ) {a=αb=β}; 
     
    255288class mgamma_fix : public mgamma { 
    256289protected: 
     290        //! parameter l 
    257291        double l; 
     292        //! reference vector 
    258293        vec refl; 
    259294public: 
     
    367402double enorm<sq_T>::evalpdflog ( const vec &val ) const { 
    368403        // 1.83787706640935 = log(2pi) 
    369         return -0.5* ( R.cols() * 1.83787706640935 +R.logdet() +R.invqform ( mu-val ) ); 
    370 }; 
    371  
     404        return  -0.5* (  +R.invqform ( mu-val ) ) - lognc(); 
     405}; 
     406 
     407template<class sq_T> 
     408inline double enorm<sq_T>::lognc () const { 
     409        // 1.83787706640935 = log(2pi) 
     410        return -0.5* ( R.cols() * 1.83787706640935 +R.logdet()); 
     411}; 
    372412 
    373413template<class sq_T>