Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libEF.cpp
r32 r60 60 60 61 61 vec mgamma::samplecond ( vec &cond, double &ll ) { 62 *_beta=k / cond;62 this->condition(cond ); 63 63 vec smp = epdf.sample(); 64 64 ll = epdf.evalpdflog ( smp ); -
bdm/stat/libEF.h
r51 r60 96 96 double eval ( const vec &val ) const ; 97 97 double evalpdflog ( const vec &val ) const; 98 vec mean() const {return mu;}98 vec mean() const {return mu;} 99 99 100 100 //Access methods … … 140 140 //! Returns poiter to alpha and beta. Potentially dengerous: use with care! 141 141 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;} 143 143 }; 144 144 /* … … 228 228 */ 229 229 class mgamma : public mEF { 230 protected: 230 231 //! Internal epdf that arise by conditioning on \c rvc 231 232 egamma epdf; … … 247 248 }; 248 249 250 /*! 251 \brief Gamma random walk around a fixed point 252 253 Mean 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 256 Standard deviation of the random walk is proportional to one $k$-th the mean. 257 This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$. 258 259 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 260 */ 261 class mgamma_fix : public mgamma { 262 protected: 263 double l; 264 vec refl; 265 public: 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 249 277 //! Switch between various resampling methods. 250 278 enum RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; … … 264 292 public: 265 293 //! 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 ) {}; 267 295 //! Set sample 268 296 void set_parameters ( const vec &w0, epdf* pdf0 ); … … 276 304 vec sample() const {it_error ( "Not implemented" );return 0;} 277 305 //! 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 );} 281 310 return pom; 282 311 } … … 287 316 288 317 template<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() ) {};318 enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 290 319 291 320 template<class sq_T> … … 320 349 321 350 template<class sq_T> 322 mat enorm<sq_T>::sample ( int N ) const {351 mat enorm<sq_T>::sample ( int N ) const { 323 352 mat X ( dim,N ); 324 353 vec x ( dim ); … … 346 375 template<class sq_T> 347 376 double 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" );} 349 378 350 379 // 1.83787706640935 = log(2pi)