Changeset 60 for bdm/stat

Show
Ignore:
Timestamp:
03/31/08 13:53:36 (16 years ago)
Author:
smidl
Message:

nove rozlozeni Q

Location:
bdm/stat
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libEF.cpp

    r32 r60  
    6060 
    6161vec mgamma::samplecond ( vec &cond, double &ll ) { 
    62         *_beta=k / cond ; 
     62        this->condition(cond ); 
    6363        vec smp = epdf.sample(); 
    6464        ll = epdf.evalpdflog ( smp ); 
  • bdm/stat/libEF.h

    r51 r60  
    9696        double eval ( const vec &val ) const ; 
    9797        double evalpdflog ( const vec &val ) const; 
    98         vec mean()const {return mu;} 
     98        vec mean() const {return mu;} 
    9999 
    100100//Access methods 
     
    140140        //! Returns poiter to alpha and beta. Potentially dengerous: use with care! 
    141141        void _param ( vec* &a, vec* &b ) {a=αb=β}; 
    142         vec mean()const {vec pom(alpha); pom/=beta; return pom;} 
     142        vec mean() const {vec pom ( alpha ); pom/=beta; return pom;} 
    143143}; 
    144144/* 
     
    228228*/ 
    229229class mgamma : public mEF { 
     230protected: 
    230231        //! Internal epdf that arise by conditioning on \c rvc 
    231232        egamma epdf; 
     
    247248}; 
    248249 
     250/*! 
     251\brief  Gamma random walk around a fixed point 
     252 
     253Mean value, \f$\mu\f$, of this density is given by a geometric combination of \c rvc and given fixed point, $p$. $k$ is the coefficient of the geometric combimation 
     254\f[ \mu = \mu_{t-1} ^{l} p^{1-l}\f] 
     255 
     256Standard deviation of the random walk is proportional to one $k$-th the mean. 
     257This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$. 
     258 
     259The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 
     260*/ 
     261class mgamma_fix : public mgamma { 
     262protected: 
     263        double l; 
     264        vec refl; 
     265public: 
     266        //! Constructor 
     267        mgamma_fix ( const RV &rv,const RV &rvc ) : mgamma ( rv,rvc ),refl ( rv.count() ) {}; 
     268        //! Set value of \c k 
     269        void set_parameters ( double k0 , vec ref0, double l0 ) { 
     270                mgamma::set_parameters ( k0 ); 
     271                refl=pow ( ref0,1.0-l0 );l=l0; 
     272        }; 
     273 
     274        void condition ( const vec &val ) {vec mean=elem_mult ( refl,pow ( val,l ) ); *_beta=k/mean;}; 
     275}; 
     276 
    249277//! Switch between various resampling methods. 
    250278enum RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; 
     
    264292public: 
    265293        //! Default constructor 
    266         eEmp ( const RV &rv0 ,int n0) :epdf ( rv0 ),n(n0),w(n),samples(n) {}; 
     294        eEmp ( const RV &rv0 ,int n0 ) :epdf ( rv0 ),n ( n0 ),w ( n ),samples ( n ) {}; 
    267295        //! Set sample 
    268296        void set_parameters ( const vec &w0, epdf* pdf0 ); 
     
    276304        vec sample() const {it_error ( "Not implemented" );return 0;} 
    277305        //! inherited operation : NOT implemneted 
    278         double evalpdflog(const vec &val) const {it_error ( "Not implemented" );return 0.0;} 
    279         vec mean()const {vec pom=zeros(rv.count());  
    280                 for (int i=0;i<n;i++){pom+=samples(i)*w(i);} 
     306        double evalpdflog ( const vec &val ) const {it_error ( "Not implemented" );return 0.0;} 
     307        vec mean() const { 
     308                vec pom=zeros ( rv.count() ); 
     309                for ( int i=0;i<n;i++ ) {pom+=samples ( i ) *w ( i );} 
    281310                return pom; 
    282311        } 
     
    287316 
    288317template<class sq_T> 
    289 enorm<sq_T>::enorm ( RV &rv ) :eEF(rv), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 
     318enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 
    290319 
    291320template<class sq_T> 
     
    320349 
    321350template<class sq_T> 
    322 mat enorm<sq_T>::sample ( int N )const { 
     351mat enorm<sq_T>::sample ( int N ) const { 
    323352        mat X ( dim,N ); 
    324353        vec x ( dim ); 
     
    346375template<class sq_T> 
    347376double enorm<sq_T>::evalpdflog ( const vec &val ) const { 
    348         if ( !cached ) {it_error("this should not happen, see cached");} 
     377        if ( !cached ) {it_error ( "this should not happen, see cached" );} 
    349378 
    350379        // 1.83787706640935 = log(2pi)