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