Go to the documentation of this file.00001
00002 #ifndef bsta_gaussian_sphere_h_
00003 #define bsta_gaussian_sphere_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "bsta_gaussian.h"
00017 #include <vcl_iostream.h>
00018 #include <vnl/vnl_random.h>
00019
00020
00021
00022 template <class T, unsigned n>
00023 class bsta_gaussian_sphere : public bsta_gaussian<T,n>
00024 {
00025 public:
00026 typedef typename bsta_gaussian<T,n>::vector_type vector_;
00027 typedef T covar_type;
00028
00029 bsta_gaussian_sphere()
00030 : bsta_gaussian<T,n>(), var_(T(0)), det_covar_(T(0)) {}
00031
00032
00033 bsta_gaussian_sphere(const vector_& mean,
00034 const covar_type& var)
00035 : bsta_gaussian<T,n>(mean), var_(var), det_covar_(T(-1))
00036 { compute_det(); }
00037
00038
00039 const covar_type& var() const { return var_; }
00040
00041
00042 void set_var(const covar_type& var) { var_ = var; compute_det(); }
00043
00044
00045 const covar_type& covar() const {return var_;}
00046
00047
00048 void set_covar(const covar_type& covar) {this->set_var(covar);}
00049
00050
00051 T dist_prob_density(const T& sqr_mahal_dist) const
00052 {
00053 if (det_covar_ <= 0)
00054 return T(0);
00055 return static_cast<T>(vcl_sqrt(1/(det_covar_*two_pi_power<n>::value()))
00056 * vcl_exp(-sqr_mahal_dist/2));
00057 }
00058
00059
00060 T prob_density(const vector_& pt) const
00061 {
00062 return dist_prob_density(sqr_mahalanobis_dist(pt));
00063 }
00064
00065
00066 T probability(const vector_& min_pt,
00067 const vector_& max_pt) const;
00068
00069
00070 T sqr_mahalanobis_dist(const vector_& pt) const;
00071
00072
00073 T det_covar() const { return det_covar_; }
00074
00075
00076 vector_ sample(vnl_random& rng) const;
00077
00078 protected:
00079
00080 covar_type var_;
00081
00082
00083 T det_covar_;
00084
00085 private:
00086
00087 void compute_det();
00088 };
00089
00090 template <class T , unsigned n>
00091 inline vcl_ostream& operator<< (vcl_ostream& os,
00092 bsta_gaussian_sphere<T, n> const& g)
00093 {
00094 os << "gauss_sphere:mean(" << g.mean() << ")\n"
00095 << "gauss_sphere:var(" << g.var() << ")\n";
00096 return os;
00097 }
00098
00099 #endif // bsta_gaussian_sphere_h_