Changeset 283 for bdm/stat/libEF.h
- Timestamp:
- 02/24/09 14:14:01 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libEF.h
r281 r283 94 94 // virtual void flatten ( double nu0 ) {it_error ( "Not implemented" );} 95 95 96 BMEF* _copy_ ( bool changerv=false ) {it_error ( "function _copy_ not implemented for this BM" ); return NULL;};96 BMEF* _copy_ ( bool changerv=false ) const {it_error ( "function _copy_ not implemented for this BM" ); return NULL;}; 97 97 }; 98 98 … … 348 348 \f] 349 349 350 Vector \f$\beta\f$ has different meaning (in fact it is 1/beta as used in definition of iG) 351 350 352 Inverse Gamma can be converted to Gamma using \f[ 351 353 x\sim iG(a,b) => 1/x\sim G(a,1/b) … … 354 356 */ 355 357 356 class eigamma : public eEF { 357 protected: 358 //!internal egamma 359 egamma eg; 360 //! Vector \f$\alpha\f$ 361 vec α 362 //! Vector \f$\beta\f$ (in fact it is 1/beta as used in definition of iG) 363 vec β 358 class eigamma : public egamma { 359 protected: 364 360 public : 365 361 //! \name Constructors 366 //!@{ 367 eigamma ( ) :eEF ( ), eg(),alpha ( eg._alpha() ), beta ( eg._beta() ) {}; 368 eigamma ( const vec &a, const vec &b ) :eEF ( ), eg(),alpha ( eg._alpha() ), beta ( eg._beta() ) {eg.set_parameters ( a,b );}; 369 void set_parameters ( const vec &a, const vec &b ) {eg.set_parameters ( a,b );}; 370 //!@} 371 372 vec sample() const {return 1.0/eg.sample();}; 373 //! TODO: is it used anywhere? 374 // mat sample ( int N ) const; 375 double evallog ( const vec &val ) const {return eg.evallog ( val );}; 376 double lognc () const {return eg.lognc();}; 362 //! All constructors are inherited 363 //!@{ 364 //!@} 365 366 vec sample() const {return 1.0/egamma::sample();}; 377 367 //! Returns poiter to alpha and beta. Potentially dangerous: use with care! 378 368 vec mean() const {return elem_div ( beta,alpha-1 );} 379 369 vec variance() const {vec mea=mean(); return elem_div ( elem_mult ( mea,mea ),alpha-2 );} 380 vec& _alpha() {return alpha;}381 vec& _beta() {return beta;}382 370 }; 383 371 /* … … 490 478 mgnorm() :mu ( epdf._mu() ) {ep=&epdf;} 491 479 //!set mean function 492 void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g-> _dimy() ), R0 );}480 void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g->dimension() ), R0 );} 493 481 void condition ( const vec &cond ) {mu=g->eval ( cond );}; 494 482 }; … … 686 674 687 675 //! Set samples and weights 688 void set_parameters ( const vec &w0, const epdf* pdf0 ); 676 void set_statistics ( const vec &w0, const epdf* pdf0 ); 677 //! Set samples and weights 678 void set_statistics ( const epdf* pdf0 , int n ) {set_statistics ( ones ( n ) /n,pdf0 );}; 689 679 //! Set sample 690 680 void set_samples ( const epdf* pdf0 ); 691 681 //! Set sample 692 void set_ n( int n0, bool copy=true ) {n=n0; w.set_size ( n0,copy );samples.set_size ( n0,copy );};682 void set_parameters ( int n0, bool copy=true ) {n=n0; w.set_size ( n0,copy );samples.set_size ( n0,copy );}; 693 683 //! Potentially dangerous, use with care. 694 684 vec& _w() {return w;}; … … 700 690 const Array<vec>& _samples() const {return samples;}; 701 691 //! 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. 702 ivec resample ( RESAMPLING_METHOD method =SYSTEMATIC );692 ivec resample ( RESAMPLING_METHOD method=SYSTEMATIC ); 703 693 //! inherited operation : NOT implemneted 704 694 vec sample() const {it_error ( "Not implemented" );return 0;} … … 714 704 for ( int i=0;i<n;i++ ) {pom+=pow ( samples ( i ),2 ) *w ( i );} 715 705 return pom-pow ( mean(),2 ); 706 } 707 //! For this class, qbounds are minimum and maximum value of the population! 708 void qbounds ( vec &lb, vec &ub, double perc=0.95 ) const { 709 // lb in inf so than it will be pushed below; 710 lb.set_size(dim); 711 ub.set_size(dim); 712 lb = std::numeric_limits<double>::infinity(); 713 ub = -std::numeric_limits<double>::infinity(); 714 int j; 715 for ( int i=0;i<n;i++ ) { 716 for ( j=0;j<dim; j++ ) { 717 if ( samples ( i ) ( j ) <lb ( j ) ) {lb ( j ) =samples ( i ) ( j );} 718 if ( samples ( i ) ( j ) >ub ( j ) ) {ub ( j ) =samples ( i ) ( j );} 719 } 720 } 716 721 } 717 722 };