contrib/brl/bbas/bsta/bsta_weibull.txx
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_weibull.txx
00002 #ifndef bsta_weibull_txx_
00003 #define bsta_weibull_txx_
00004 //:
00005 // \file
00006 
00007 #include "bsta_weibull.h"
00008 #include <vcl_cassert.h>
00009 #include <vcl_cmath.h>
00010 
00011 
00012 template <class T>
00013 bsta_weibull<T>::bsta_weibull():  lambda_(static_cast<vector_>(1)),
00014                                          mu_(static_cast<vector_>(0)),
00015                                          k_(static_cast<vector_>(1))
00016 {}
00017 
00018 template <class T>
00019 bsta_weibull<T>::bsta_weibull(vector_ const& lambda, vector_ const& k):
00020   lambda_(lambda), mu_(static_cast<vector_>(0)), k_(k)
00021 {}
00022 
00023 template <class T>
00024 bsta_weibull<T>::bsta_weibull(vector_ const& lambda, vector_ const& k,
00025                               vector_ const& mu)
00026 : lambda_(lambda), mu_(mu), k_(k)
00027 {}
00028 
00029 template <class T>
00030 T bsta_weibull<T>::prob_density(const vector_& pt) const
00031 {
00032   double dk = static_cast<double>(k_);
00033   assert(dk>0);
00034   double la = static_cast<double>(lambda_);
00035   assert(la>0);
00036   double m = static_cast<double>(mu_);
00037   double c = dk/la;
00038   double x = static_cast<double>(pt)-m;
00039   x /= la;
00040   c *= vcl_pow(x,dk-1.0);
00041   c *= vcl_exp(-vcl_pow(x,dk));
00042   return static_cast<T>(c);
00043 }
00044 
00045 template <class T>
00046 T bsta_weibull<T>::probability(const vector_& min_pt,
00047                                const vector_& max_pt) const
00048 {
00049   double dk = static_cast<double>(k_);
00050   assert(dk>0);
00051   double la = static_cast<double>(lambda_);
00052   assert(la>0);
00053   double m = static_cast<double>(mu_);
00054   double xmin = min_pt-m;
00055   double xmax = max_pt-m;
00056   double tp = vcl_exp(-vcl_pow(xmin/la, dk));
00057   double tm = vcl_exp(-vcl_pow(xmax/la, dk));
00058   return static_cast<T>(tp-tm);
00059 }
00060 
00061 
00062 // only allow instantiation of univariate weibull distributions for now
00063 #define BSTA_WEIBULL_INSTANTIATE(T) \
00064 template class bsta_weibull<T >
00065 
00066 
00067 #endif // bsta_weibull_txx_