contrib/brl/bbas/bsta/bsta_beta.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_beta.h
00002 #ifndef bsta_beta_h_
00003 #define bsta_beta_h_
00004 //:
00005 // \file
00006 // \brief  Beta distribution function implementation
00007 // \author Gamze Tunali (gtunali@brown.edu)
00008 // \date   November 13, 2009
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   (none yet)
00013 // \endverbatim
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   // default constructor
00024   bsta_beta() : alpha_(T(0.00001)), beta_(T(0.00001)) {}
00025 
00026   //: pre: alpha>0 and beta>0
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   //: constructs from a set of sample values
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   //: pre: x should be in [0,1]
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