Go to the documentation of this file.00001
00002 #ifndef vpdl_gaussian_sphere_h_
00003 #define vpdl_gaussian_sphere_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vpdl/vpdl_gaussian_base.h>
00016 #include <vnl/vnl_erf.h>
00017 #include <vcl_limits.h>
00018 #include <vcl_cassert.h>
00019
00020 #include <vpdl/vpdt/vpdt_gaussian.h>
00021 #include <vpdl/vpdt/vpdt_probability.h>
00022 #include <vpdl/vpdt/vpdt_log_probability.h>
00023
00024
00025 template<class T, unsigned int n=0>
00026 class vpdl_gaussian_sphere : public vpdl_gaussian_base<T,n>
00027 {
00028 public:
00029
00030 typedef typename vpdt_field_default<T,n>::type vector;
00031
00032 typedef typename vpdt_field_traits<vector>::matrix_type matrix;
00033
00034 typedef T covar_type;
00035
00036
00037
00038
00039 vpdl_gaussian_sphere(unsigned int var_dim = n)
00040 : impl_(var_dim) {}
00041
00042
00043 vpdl_gaussian_sphere(const vector& mean_val, const covar_type& var)
00044 : impl_(mean_val,var) {}
00045
00046
00047 virtual ~vpdl_gaussian_sphere() {}
00048
00049
00050 virtual vpdl_distribution<T,n>* clone() const
00051 {
00052 return new vpdl_gaussian_sphere<T,n>(*this);
00053 }
00054
00055
00056 virtual unsigned int dimension() const { return impl_.dimension(); }
00057
00058
00059 virtual T density(const vector& pt) const
00060 {
00061 return impl_.density(pt);
00062 }
00063
00064
00065 virtual T prob_density(const vector& pt) const
00066 {
00067 return vpdt_prob_density(impl_,pt);
00068 }
00069
00070
00071 virtual T log_prob_density(const vector& pt) const
00072 {
00073 return vpdt_log_prob_density(impl_,pt);
00074 };
00075
00076
00077
00078
00079
00080 virtual T gradient_density(const vector& pt, vector& g) const
00081 {
00082 return impl_.gradient_density(pt,g);
00083 }
00084
00085
00086
00087
00088 T norm_const() const
00089 {
00090 return impl_.norm_const();
00091 }
00092
00093
00094
00095 T sqr_mahal_dist(const vector& pt) const
00096 {
00097 return impl_.sqr_mahal_dist(pt);
00098 }
00099
00100
00101
00102
00103 virtual T cumulative_prob(const vector& pt) const
00104 {
00105 return impl_.cumulative_prob(pt);
00106 }
00107
00108
00109
00110
00111 T box_prob(const vector& min_pt, const vector& max_pt) const
00112 {
00113 const unsigned int dim = this->dimension();
00114
00115 double s2 = 1/vcl_sqrt(2*impl_.covar);
00116
00117 double prob = T(1);
00118 for (unsigned int i=0; i<dim; ++i) {
00119 if (vpdt_index(max_pt,i)<=vpdt_index(min_pt,i))
00120 return T(0);
00121 prob *= (vnl_erf(s2*(vpdt_index(max_pt,i)-vpdt_index(impl_.mean,i))) -
00122 vnl_erf(s2*(vpdt_index(min_pt,i)-vpdt_index(impl_.mean,i))))/2;
00123 }
00124 return static_cast<T>(prob);
00125 }
00126
00127
00128 virtual const vector& mean() const { return impl_.mean; }
00129
00130
00131 virtual void set_mean(const vector& mean_val) { impl_.mean = mean_val; }
00132
00133
00134 virtual void compute_mean(vector& mean_val) const { mean_val = impl_.mean; }
00135
00136
00137 const covar_type& covariance() const { return impl_.covar; }
00138
00139
00140 void set_covariance(const covar_type& var) { impl_.covar = var; }
00141
00142
00143
00144 virtual void compute_covar(matrix& covar) const
00145 {
00146 impl_.compute_covar(covar);
00147 }
00148
00149 protected:
00150
00151 vpdt_gaussian<vector,covar_type> impl_;
00152 };
00153
00154
00155 #endif // vpdl_gaussian_sphere_h_