Changeset 33 for bdm/stat/libEF.h

Show
Ignore:
Timestamp:
03/05/08 16:01:56 (16 years ago)
Author:
smidl
Message:

Oprava PF a MPF + jejich implementace pro pmsm system

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libEF.h

    r32 r33  
    2525//! Global Uniform_RNG 
    2626extern Uniform_RNG UniRNG; 
     27//! Global Normal_RNG 
    2728extern Normal_RNG NorRNG; 
     29//! Global Gamma_RNG 
    2830extern Gamma_RNG GamRNG; 
    29  
    3031 
    3132/*! 
     
    4142        //! default constructor 
    4243        eEF ( const RV &rv ) :epdf ( rv ) {}; 
    43  
     44        //!TODO decide if it is really needed 
    4445        virtual void tupdate ( double phi, mat &vbar, double nubar ) {}; 
    45  
     46        //!TODO decide if it is really needed 
    4647        virtual void dupdate ( mat &v,double nu=1.0 ) {}; 
    4748}; 
    4849 
     50/*! 
     51* \brief Exponential family model. 
     52 
     53* More?... 
     54*/ 
     55 
    4956class mEF : public mpdf { 
    5057 
    5158public: 
     59        //! Default constructor 
    5260        mEF ( const RV &rv0, const RV &rvc0 ) :mpdf ( rv0,rvc0 ) {}; 
    5361}; 
     
    7482public: 
    7583//      enorm() :eEF() {}; 
    76  
     84        //!Default constructor 
    7785        enorm ( RV &rv ); 
     86        //! Set mean value \c mu and covariance \c R 
    7887        void set_parameters ( const vec &mu,const sq_T &R ); 
    7988        //! tupdate in exponential form (not really handy) 
    8089        void tupdate ( double phi, mat &vbar, double nubar ); 
     90        //! dupdate in exponential form (not really handy) 
    8191        void dupdate ( mat &v,double nu=1.0 ); 
    8292 
    8393        vec sample() const; 
     94        //! TODO is it used? 
    8495        mat sample ( int N ) const; 
    8596        double eval ( const vec &val ) const ; 
     
    106117 Multvariate Gamma density as product of independent univariate densities. 
    107118 \f[ 
    108  f(x|a,b) = \prod f(x_i|a_i,b_i) 
     119 f(x|\alpha,\beta) = \prod f(x_i|\alpha_i,\beta_i) 
    109120 \f] 
    110121*/ 
     
    112123class egamma : public eEF { 
    113124protected: 
     125        //! Vector \f$\alpha\f$ 
    114126        vec alpha; 
     127        //! Vector \f$\beta\f$ 
    115128        vec beta; 
    116129public : 
     
    120133        void set_parameters ( const vec &a, const vec &b ) {alpha=a,beta=b;}; 
    121134        vec sample() const; 
     135        //! TODO: is it used anywhere? 
    122136        mat sample ( int N ) const; 
    123137        double evalpdflog ( const vec &val ) const; 
     
    126140        vec mean()const {vec pom(alpha); pom/=beta; return pom;} 
    127141}; 
    128  
     142/* 
    129143//! Weighted mixture of epdfs with external owned components. 
    130144class emix : public epdf { 
     
    140154        vec sample() {it_error ( "Not implemented" );return 0;} 
    141155}; 
     156*/ 
    142157 
    143158//!  Uniform distributed density on a rectangular support 
     
    152167        vec distance; 
    153168//! normalizing coefficients 
    154         double nk,lnk; 
    155 public: 
     169        double nk; 
     170//! cache of log( \c nk ) 
     171        double lnk; 
     172public: 
     173        //! Defualt constructor 
    156174        euni ( const RV rv ) :epdf ( rv ) {} 
    157175        double eval ( const vec &val ) const  {return nk;} 
     
    161179                return low+distance*smp; 
    162180        } 
     181        //! set values of \c low and \c high 
    163182        void set_parameters ( const vec &low0, const vec &high0 ) { 
    164183                distance = high0-low0; 
     
    180199template<class sq_T> 
    181200class mlnorm : public mEF { 
     201        //! Internal epdf that arise by conditioning on \c rvc 
    182202        enorm<sq_T> epdf; 
    183203        vec* _mu; //cached epdf.mu; 
     
    186206        //! Constructor 
    187207        mlnorm ( RV &rv,RV &rvc ); 
     208        //! Set \c A and \c R 
    188209        void set_parameters ( const  mat &A, const sq_T &R ); 
    189210        //!Generate one sample of the posterior 
     
    191212        //!Generate matrix of samples of the posterior 
    192213        mat samplecond ( vec &cond, vec &lik, int n ); 
     214        //! Set value of \c rvc . Result of this operation is stored in \c epdf use function \c _ep to access it. 
    193215        void condition ( vec &cond ); 
    194216}; 
     
    197219\brief  Gamma random walk 
    198220 
    199 Mean value, $\mu$, of this density is given by \c rvc . 
     221Mean value, \f$\mu\f$, of this density is given by \c rvc . 
    200222Standard deviation of the random walk is proportional to one $k$-th the mean. 
    201 This is achieved by setting $\alpha=k$ and $\beta=k/\mu$. 
    202  
    203 The standard deviation of the walk is then: $\mu/\sqrt(k)$. 
     223This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$. 
     224 
     225The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 
    204226*/ 
    205227class mgamma : public mEF { 
     228        //! Internal epdf that arise by conditioning on \c rvc 
    206229        egamma epdf; 
     230        //! Constant $k$ 
    207231        double k; 
     232        //! cache of epdf.beta 
    208233        vec* _beta; 
    209234 
     
    211236        //! Constructor 
    212237        mgamma ( const RV &rv,const RV &rvc ); 
     238        //! Set value of \c k 
    213239        void set_parameters ( double k ); 
    214240        //!Generate one sample of the posterior 
     
    230256        //! Number of particles 
    231257        int n; 
     258        //! Sample weights $w$ 
    232259        vec w; 
     260        //! Samples \f$x^{(i)}, i=1..n\f$ 
    233261        Array<vec> samples; 
    234262public: 
     263        //! Default constructor 
    235264        eEmp ( const RV &rv0 ,int n0) :epdf ( rv0 ),n(n0),w(n),samples(n) {}; 
     265        //! Set sample 
    236266        void set_parameters ( const vec &w0, epdf* pdf0 ); 
    237267        //! Potentially dangerous, use with care. 
    238268        vec& _w()  {return w;}; 
     269        //! access function 
    239270        Array<vec>& _samples() {return samples;}; 
    240271        //! Function performs resampling, i.e. removal of low-weight samples and duplication of high-weight samples such that the new samples represent the same density. 
    241272        ivec resample ( RESAMPLING_METHOD method = SYSTEMATIC ); 
     273        //! inherited operation : NOT implemneted 
    242274        vec sample() const {it_error ( "Not implemented" );return 0;} 
     275        //! inherited operation : NOT implemneted 
    243276        double evalpdflog(const vec &val) const {it_error ( "Not implemented" );return 0.0;} 
    244277        vec mean()const {vec pom=zeros(rv.count());