contrib/brl/bbas/bsta/bsta_weibull.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_weibull.h
00002 #ifndef bsta_weibull_h_
00003 #define bsta_weibull_h_
00004 //:
00005 // \file
00006 // \brief A Weibull distribution
00007 // \author Joseph L. Mundy
00008 // \date November 8, 2008
00009 //  The three-parameter, shifted,  Weibull distribution has the form
00010 //  \verbatim
00011 //                                            _    _ k
00012 //                                           | x-mu |
00013 //                              _    _ k-1  -|------|
00014 //                        k    | x-mu |      |lambda|
00015 //  p(x;lambda, k, mu)= ------ |------|    e -      -
00016 //                      lambda |lambda|
00017 //                             -      -
00018 //  \endverbatim
00019 // where lambda is called the scale parameter, k is the shape parameter and
00020 // mu is the location parameter.
00021 // \verbatim
00022 //  Modifications
00023 //   (none yet)
00024 // \endverbatim
00025 
00026 #include "bsta_distribution.h"
00027 #include <vnl/vnl_gamma.h>
00028 #include <vcl_cassert.h>
00029 #include <vcl_iosfwd.h>
00030 
00031 // A Weibull distribution does not have a natural, unique extension to
00032 // multi-dimensional variables. However, various approaches do exist
00033 // and could be implemented. Thus, it does make sense to still template over n.
00034 // However, only the case for n = 1 will be implemented now.
00035 template <class T>
00036 class bsta_weibull : public bsta_distribution<T,1>
00037 {
00038   typedef typename bsta_distribution<T,1>::vector_type vector_;
00039   typedef typename bsta_distribution<T,1>::vector_type covar_type_;
00040 
00041  public:
00042   bsta_weibull();
00043   //: two parameter form
00044   bsta_weibull(vector_ const& lambda, vector_ const& k);
00045 
00046   //: three parameter form (the "shifted" Weibull)
00047   bsta_weibull(vector_ const& lambda, vector_ const& k, vector_ const& mu);
00048 
00049   //: destructor
00050   ~bsta_weibull(){}
00051 
00052   //: the scale parameter
00053   vector_ lambda() const {return lambda_;}
00054 
00055   //: the shape parameter
00056   vector_ k() const {return k_;}
00057 
00058   //: the location parameter
00059   vector_ mu() const {return mu_;}
00060 
00061   //: The mean of the distribution, for 1-d the vector_ is typedefed to T
00062   vector_ mean() const
00063   {
00064     double dk = static_cast<double>(k_);
00065     assert(dk>0);
00066     double la = static_cast<double>(lambda_);
00067     assert(la>0);
00068     double m = static_cast<double>(mu_);
00069     return static_cast<vector_>(m+la*vnl_gamma(1.0+1/dk));
00070   }
00071 
00072   //: The variance of the distribution
00073   covar_type_ var() const
00074   {
00075     double dk = static_cast<double>(k_);
00076     assert(dk>0);
00077     double la = static_cast<double>(lambda_);
00078     assert(la>0);
00079     double m = vnl_gamma(1.0+1/dk);
00080     double v = vnl_gamma(1.0+2/dk);
00081     double ret = la*la*(v-m*m);
00082     return static_cast<vector_>(ret);
00083   }
00084   //: The co_variance of the distribution same as variance for 1-d case
00085   covar_type_ covar() const
00086     {return this->var();}
00087 
00088   //: The probability density at this sample
00089   T prob_density(const vector_& pt) const;
00090 
00091   //: The probability integrated over a box
00092   T probability(const vector_& min_pt,
00093                 const vector_& max_pt) const;
00094  protected:
00095   vector_ lambda_;
00096   vector_ mu_;
00097   vector_ k_;
00098 };
00099 
00100 template <class T >
00101 inline vcl_ostream& operator<< (vcl_ostream& os,
00102                                 bsta_weibull<T> const& w)
00103 {
00104   os << "weibull:lambda(" << w.lambda() << ")\n"
00105      << "weibull:k(" << w.k() << ")\n"
00106      << "weibull:mu(" << w.mu() << ")\n";
00107   return os;
00108 }
00109 
00110 #endif // bsta_weibull_h_