Changeset 33 for bdm/stat/libEF.h
- Timestamp:
- 03/05/08 16:01:56 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libEF.h
r32 r33 25 25 //! Global Uniform_RNG 26 26 extern Uniform_RNG UniRNG; 27 //! Global Normal_RNG 27 28 extern Normal_RNG NorRNG; 29 //! Global Gamma_RNG 28 30 extern Gamma_RNG GamRNG; 29 30 31 31 32 /*! … … 41 42 //! default constructor 42 43 eEF ( const RV &rv ) :epdf ( rv ) {}; 43 44 //!TODO decide if it is really needed 44 45 virtual void tupdate ( double phi, mat &vbar, double nubar ) {}; 45 46 //!TODO decide if it is really needed 46 47 virtual void dupdate ( mat &v,double nu=1.0 ) {}; 47 48 }; 48 49 50 /*! 51 * \brief Exponential family model. 52 53 * More?... 54 */ 55 49 56 class mEF : public mpdf { 50 57 51 58 public: 59 //! Default constructor 52 60 mEF ( const RV &rv0, const RV &rvc0 ) :mpdf ( rv0,rvc0 ) {}; 53 61 }; … … 74 82 public: 75 83 // enorm() :eEF() {}; 76 84 //!Default constructor 77 85 enorm ( RV &rv ); 86 //! Set mean value \c mu and covariance \c R 78 87 void set_parameters ( const vec &mu,const sq_T &R ); 79 88 //! tupdate in exponential form (not really handy) 80 89 void tupdate ( double phi, mat &vbar, double nubar ); 90 //! dupdate in exponential form (not really handy) 81 91 void dupdate ( mat &v,double nu=1.0 ); 82 92 83 93 vec sample() const; 94 //! TODO is it used? 84 95 mat sample ( int N ) const; 85 96 double eval ( const vec &val ) const ; … … 106 117 Multvariate Gamma density as product of independent univariate densities. 107 118 \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) 109 120 \f] 110 121 */ … … 112 123 class egamma : public eEF { 113 124 protected: 125 //! Vector \f$\alpha\f$ 114 126 vec alpha; 127 //! Vector \f$\beta\f$ 115 128 vec beta; 116 129 public : … … 120 133 void set_parameters ( const vec &a, const vec &b ) {alpha=a,beta=b;}; 121 134 vec sample() const; 135 //! TODO: is it used anywhere? 122 136 mat sample ( int N ) const; 123 137 double evalpdflog ( const vec &val ) const; … … 126 140 vec mean()const {vec pom(alpha); pom/=beta; return pom;} 127 141 }; 128 142 /* 129 143 //! Weighted mixture of epdfs with external owned components. 130 144 class emix : public epdf { … … 140 154 vec sample() {it_error ( "Not implemented" );return 0;} 141 155 }; 156 */ 142 157 143 158 //! Uniform distributed density on a rectangular support … … 152 167 vec distance; 153 168 //! normalizing coefficients 154 double nk,lnk; 155 public: 169 double nk; 170 //! cache of log( \c nk ) 171 double lnk; 172 public: 173 //! Defualt constructor 156 174 euni ( const RV rv ) :epdf ( rv ) {} 157 175 double eval ( const vec &val ) const {return nk;} … … 161 179 return low+distance*smp; 162 180 } 181 //! set values of \c low and \c high 163 182 void set_parameters ( const vec &low0, const vec &high0 ) { 164 183 distance = high0-low0; … … 180 199 template<class sq_T> 181 200 class mlnorm : public mEF { 201 //! Internal epdf that arise by conditioning on \c rvc 182 202 enorm<sq_T> epdf; 183 203 vec* _mu; //cached epdf.mu; … … 186 206 //! Constructor 187 207 mlnorm ( RV &rv,RV &rvc ); 208 //! Set \c A and \c R 188 209 void set_parameters ( const mat &A, const sq_T &R ); 189 210 //!Generate one sample of the posterior … … 191 212 //!Generate matrix of samples of the posterior 192 213 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. 193 215 void condition ( vec &cond ); 194 216 }; … … 197 219 \brief Gamma random walk 198 220 199 Mean value, $\mu$, of this density is given by \c rvc .221 Mean value, \f$\mu\f$, of this density is given by \c rvc . 200 222 Standard 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)$.223 This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$. 224 225 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 204 226 */ 205 227 class mgamma : public mEF { 228 //! Internal epdf that arise by conditioning on \c rvc 206 229 egamma epdf; 230 //! Constant $k$ 207 231 double k; 232 //! cache of epdf.beta 208 233 vec* _beta; 209 234 … … 211 236 //! Constructor 212 237 mgamma ( const RV &rv,const RV &rvc ); 238 //! Set value of \c k 213 239 void set_parameters ( double k ); 214 240 //!Generate one sample of the posterior … … 230 256 //! Number of particles 231 257 int n; 258 //! Sample weights $w$ 232 259 vec w; 260 //! Samples \f$x^{(i)}, i=1..n\f$ 233 261 Array<vec> samples; 234 262 public: 263 //! Default constructor 235 264 eEmp ( const RV &rv0 ,int n0) :epdf ( rv0 ),n(n0),w(n),samples(n) {}; 265 //! Set sample 236 266 void set_parameters ( const vec &w0, epdf* pdf0 ); 237 267 //! Potentially dangerous, use with care. 238 268 vec& _w() {return w;}; 269 //! access function 239 270 Array<vec>& _samples() {return samples;}; 240 271 //! 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. 241 272 ivec resample ( RESAMPLING_METHOD method = SYSTEMATIC ); 273 //! inherited operation : NOT implemneted 242 274 vec sample() const {it_error ( "Not implemented" );return 0;} 275 //! inherited operation : NOT implemneted 243 276 double evalpdflog(const vec &val) const {it_error ( "Not implemented" );return 0.0;} 244 277 vec mean()const {vec pom=zeros(rv.count());