contrib/brl/bbas/bsta/bsta_parzen_sphere.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/bsta_parzen_sphere.h
00002 #ifndef bsta_parzen_sphere_h_
00003 #define bsta_parzen_sphere_h_
00004 //:
00005 // \file
00006 // \brief A distribution based on a number of samples, independent vector elements with equal variance
00007 // \author Joseph L. Mundy
00008 // \date October 12, 2008
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   (none yet)
00013 // \endverbatim
00014 //
00015 // Do not remove the following statement
00016 // Approved for Public Release, Distribution Unlimited (DISTAR Case 12529)
00017 //
00018 
00019 #include "bsta_parzen.h"
00020 #include <vcl_vector.h>
00021 #include <vcl_algorithm.h>
00022 
00023 //: forward declare vnl_matrix_fixed and vnl_vector_fixed
00024 template<class T, unsigned n, unsigned m> class vnl_matrix_fixed;
00025 template<class T, unsigned n>             class vnl_vector_fixed;
00026 
00027 //: A parzen distribution
00028 // the Gaussian sphere is used as a component of the mixture
00029 template <class T, unsigned n>
00030 class bsta_parzen_sphere : public bsta_parzen<T,n>
00031 {
00032  public:
00033 
00034   //: the covariance type
00035   typedef vnl_matrix_fixed<T,n,n> covar_type;
00036   typedef typename bsta_distribution<T,n>::vector_type vect_t;
00037   typedef typename bsta_distribution<T,n>::math_type math_t;
00038   bsta_parzen_sphere(): bandwidth_(T(1)),
00039     bandwidth_adapted_(false) {}// no samples
00040 
00041   bsta_parzen_sphere(typename bsta_parzen<T,n>::sample_vector const& samples, T bandwidth = T(1)) :
00042     bsta_parzen<T,n>(samples), bandwidth_(bandwidth),
00043     bandwidth_adapted_(false){}
00044 
00045   ~bsta_parzen_sphere() {}
00046 
00047   //: kernel bandwidth
00048   T bandwidth() const {return bandwidth_;}
00049 
00050   void set_bandwidth(T bandwidth) { bandwidth_ = bandwidth; }
00051 
00052   bool bandwidth_adapted() const { return bandwidth_adapted_; }
00053 
00054   void set_bandwidth_adapted(bool bandwidth_adapted)
00055     {bandwidth_adapted_=bandwidth_adapted;}
00056 
00057   //: The mean of the distribution (just the sample mean)
00058   vnl_vector_fixed<T,n> mean() const;
00059 
00060   //: The covariance of the distribution (the sample covariance + bandwidth*I)
00061   covar_type covar() const;
00062 
00063   //: The probability density at sample pt
00064   T prob_density(vect_t const& pt) const;
00065 
00066   //: The probability density integrated over a box (returns a probability)
00067   T probability(vect_t const& min_pt,
00068                 vect_t const& max_pt) const;
00069 
00070   //: The distance and index of the nearest sample
00071   T nearest_sample(const vect_t& pt, unsigned & index) const;
00072 
00073  protected:
00074   T bandwidth_;
00075   bool bandwidth_adapted_;
00076 };
00077 
00078 //: specialize to the scalar case, needed due to differences in computing the covariance matrix
00079 template <class T >
00080 class bsta_parzen_sphere<T,1> : public bsta_parzen<T,1>
00081 {
00082  public:
00083   //actually a scalar
00084   typedef typename bsta_distribution<T,1>::vector_type vect_t;
00085 
00086   bsta_parzen_sphere(): bandwidth_(T(1)),
00087     bandwidth_adapted_(false) {}// no samples
00088 
00089   bsta_parzen_sphere(typename bsta_parzen<T,1>::sample_vector const& samples,
00090                      T bandwidth = T(1)): bsta_parzen<T,1>(samples),
00091     bandwidth_(bandwidth), bandwidth_adapted_(false){}
00092 
00093   ~bsta_parzen_sphere() {}
00094 
00095   //: kernel bandwidth
00096   T bandwidth() const {return bandwidth_;}
00097 
00098   void set_bandwidth(T bandwidth) { bandwidth_ = bandwidth; }
00099 
00100   bool bandwidth_adapted() const { return bandwidth_adapted_; }
00101 
00102   void set_bandwidth_adapted(bool bandwidth_adapted)
00103     {bandwidth_adapted_=bandwidth_adapted;}
00104 
00105   //: The mean of the distribution (just the sample mean)
00106   T mean() const;
00107 
00108   //: The covariance of the distribution (the sample covariance + bandwidth*I)
00109   T covar() const;
00110 
00111   //: The probability density at sample pt
00112   T prob_density(vect_t const& pt) const;
00113 
00114   //: The probability density integrated over a box (returns a probability)
00115   T probability(vect_t const& min_pt,
00116                 vect_t const& max_pt) const;
00117 
00118   //: the distance and index of the nearest sample
00119   T nearest_sample(const vect_t& pt, unsigned & index) const;
00120  protected:
00121   T bandwidth_;
00122   bool bandwidth_adapted_;
00123 };
00124 
00125 #endif // bsta_parzen_sphere_h_