Changeset 77
- Timestamp:
- 04/18/08 14:02:01 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libEF.h
r67 r77 74 74 //! Covariance matrix in decomposed form 75 75 sq_T R; 76 //! Cache: _iR = inv(R);77 sq_T _iR;78 //! indicator if \c _iR is chached79 bool cached;80 76 //! dimension (redundant from rv.count() for easier coding ) 81 77 int dim; … … 100 96 //Access methods 101 97 //! returns a pointer to the internal mean value. Use with Care! 102 vec * _mu() {return μ}98 vec& _mu() {return mu;} 103 99 104 100 //! access function … … 106 102 107 103 //! 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 116 107 mat getR () {return R.to_mat();} 117 108 }; … … 206 197 //! Internal epdf that arise by conditioning on \c rvc 207 198 enorm<sq_T> epdf; 208 vec *_mu; //cached epdf.mu;199 vec& _mu; //cached epdf.mu; 209 200 mat A; 210 201 public: … … 319 310 320 311 template<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() ) {};312 enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),dim ( rv.count() ) {}; 322 313 323 314 template<class sq_T> … … 326 317 mu = mu0; 327 318 R = R0; 328 if ( _iR.rows() !=R.rows() ) _iR=R; // memory allocation!329 R.inv ( _iR ); //update cache330 cached=true;331 319 }; 332 320 … … 378 366 template<class sq_T> 379 367 double enorm<sq_T>::evalpdflog ( const vec &val ) const { 380 if ( !cached ) {it_error ( "this should not happen, see cached" );}381 382 368 // 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 373 template<class sq_T> 374 mlnorm<sq_T>::mlnorm ( RV &rv0,RV &rvc0 ) :mEF ( rv0,rvc0 ),epdf ( rv ),A ( rv0.count(),rv0.count() ),_mu(epdf._mu()) { 390 375 } 391 376 … … 423 408 template<class sq_T> 424 409 void mlnorm<sq_T>::condition ( vec &cond ) { 425 *_mu = A*cond;410 _mu = A*cond; 426 411 //R is already assigned; 427 412 }