Go to the documentation of this file.00001
00002 #ifndef bsta_beta_h_
00003 #define bsta_beta_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bsta_distribution.h"
00016 #include <vcl_vector.h>
00017 #include <vcl_iostream.h>
00018
00019 template <class T>
00020 class bsta_beta : public bsta_distribution<T,1>
00021 {
00022 public:
00023
00024 bsta_beta() : alpha_(T(0.00001)), beta_(T(0.00001)) {}
00025
00026
00027 bsta_beta(T alpha, T beta) : alpha_(alpha), beta_(beta)
00028 { if (alpha_< 0) alpha_=T(0.00001); if (beta_<0) beta_=T(0.00001); }
00029
00030
00031 bsta_beta(vcl_vector<T> x);
00032
00033 static bool bsta_beta_from_moments(T mean, T var, T& alpha, T& beta);
00034
00035 T alpha() const { return alpha_; }
00036
00037 T beta() const { return beta_; }
00038
00039 void set_alpha_beta(T alpha, T beta)
00040 {
00041 alpha_=alpha; beta_=beta;
00042 if (alpha_ < 0)
00043 alpha_=T(0.00001);
00044 if (beta_ <0)
00045 beta_=T(0.00001);
00046 }
00047
00048
00049 T prob_density(T x) const;
00050
00051 T cum_dist_funct(T x) const;
00052
00053 T distance(T x) const;
00054 T mean() const { return alpha_/(alpha_+beta_); }
00055
00056 T var() const { T t=alpha_+beta_; return (alpha_*beta_)/(t*t*(t+1)); }
00057
00058 private:
00059 T alpha_;
00060 T beta_;
00061 };
00062
00063 template <class T>
00064 inline vcl_ostream& operator<< (vcl_ostream& os,
00065 bsta_beta<T> const& b)
00066 {
00067 return
00068 os << "beta: (alpha,beta) = (" << b.alpha() << " " << b.beta() <<' '<<b.mean()<<' '<<b.var()<< ")\n";
00069 }
00070
00071 #endif