Changeset 77

Show
Ignore:
Timestamp:
04/18/08 14:02:01 (16 years ago)
Author:
smidl
Message:

odstraneni inverze z enorm

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libEF.h

    r67 r77  
    7474        //! Covariance matrix in decomposed form 
    7575        sq_T R; 
    76         //! Cache:  _iR = inv(R); 
    77         sq_T _iR; 
    78         //! indicator if \c _iR is chached 
    79         bool cached; 
    8076        //! dimension (redundant from rv.count() for easier coding ) 
    8177        int dim; 
     
    10096//Access methods 
    10197        //! returns a pointer to the internal mean value. Use with Care! 
    102         vec* _mu() {return μ} 
     98        vec& _mu() {return mu;} 
    10399         
    104100        //! access function 
     
    106102 
    107103        //! returns pointers to the internal variance and its inverse. Use with Care! 
    108         void _R ( sq_T* &pR, sq_T* &piR ) { 
    109                 pR=&R; 
    110                 piR=&_iR; 
    111         } 
    112  
    113         //! set cache as inconsistent 
    114         void _cached ( bool what ) {cached=what;} 
    115         //! access mthod 
     104        sq_T& _R() {return R;} 
     105 
     106        //! access method 
    116107        mat getR () {return R.to_mat();} 
    117108}; 
     
    206197        //! Internal epdf that arise by conditioning on \c rvc 
    207198        enorm<sq_T> epdf; 
    208         vec* _mu; //cached epdf.mu; 
     199        vec& _mu; //cached epdf.mu; 
    209200        mat A; 
    210201public: 
     
    319310 
    320311template<class sq_T> 
    321 enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 
     312enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),dim ( rv.count() ) {}; 
    322313 
    323314template<class sq_T> 
     
    326317        mu = mu0; 
    327318        R = R0; 
    328         if ( _iR.rows() !=R.rows() ) _iR=R; // memory allocation! 
    329         R.inv ( _iR ); //update cache 
    330         cached=true; 
    331319}; 
    332320 
     
    378366template<class sq_T> 
    379367double enorm<sq_T>::evalpdflog ( const vec &val ) const { 
    380         if ( !cached ) {it_error ( "this should not happen, see cached" );} 
    381  
    382368        // 1.83787706640935 = log(2pi) 
    383         return -0.5* ( R.cols() * 1.83787706640935 +R.logdet() +_iR.qform ( mu-val ) ); 
    384 }; 
    385  
    386  
    387 template<class sq_T> 
    388 mlnorm<sq_T>::mlnorm ( RV &rv0,RV &rvc0 ) :mEF ( rv0,rvc0 ),epdf ( rv ),A ( rv0.count(),rv0.count() ) { 
    389         _mu = epdf._mu(); 
     369        return -0.5* ( R.cols() * 1.83787706640935 +R.logdet() +R.invqform ( mu-val ) ); 
     370}; 
     371 
     372 
     373template<class sq_T> 
     374mlnorm<sq_T>::mlnorm ( RV &rv0,RV &rvc0 ) :mEF ( rv0,rvc0 ),epdf ( rv ),A ( rv0.count(),rv0.count() ),_mu(epdf._mu()) { 
    390375} 
    391376 
     
    423408template<class sq_T> 
    424409void mlnorm<sq_T>::condition ( vec &cond ) { 
    425         *_mu = A*cond; 
     410        _mu = A*cond; 
    426411//R is already assigned; 
    427412}