Go to the documentation of this file.00001
00002 #ifndef bsta_parzen_h_
00003 #define bsta_parzen_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "bsta_distribution.h"
00020 #include <vcl_vector.h>
00021 #include <vcl_iostream.h>
00022
00023
00024 template<class T, unsigned n> class vnl_vector_fixed;
00025
00026
00027 template<class T, unsigned n> class bsta_parzen;
00028
00029
00030 template<class T, unsigned n>
00031 class vless
00032 {
00033 public:
00034 vless():parz_ptr_(0){}
00035 vless(bsta_parzen<T, n>* parz_ptr): parz_ptr_(parz_ptr){}
00036 bool operator()(vnl_vector_fixed<T,n> const& va,
00037 vnl_vector_fixed<T,n> const& vb) const
00038 {
00039 if (!parz_ptr_) return false;
00040 if (!parz_ptr_->size()) return false;
00041 T pda = parz_ptr_->prob_density(va);
00042 T pdb = parz_ptr_->prob_density(vb);
00043 return pdb < pda;
00044 }
00045 bool operator()(T const& va, T const& vb) const
00046 {
00047 if (!parz_ptr_) return false;
00048 bool comp = parz_ptr_->prob_density(vb)<parz_ptr_->prob_density(va);
00049 return comp;
00050 }
00051 private:
00052
00053 bsta_parzen<T, n>* parz_ptr_;
00054 };
00055
00056
00057
00058 template <class T, unsigned n>
00059 class bsta_parzen : public bsta_distribution<T,n>
00060 {
00061 public:
00062 typedef typename bsta_distribution<T,n>::vector_type vect_t;
00063 typedef vcl_vector<vect_t > sample_vector;
00064 typedef typename sample_vector::const_iterator sv_const_it;
00065
00066 protected:
00067
00068 sample_vector samples_;
00069
00070 public:
00071
00072 bsta_parzen() {}
00073 virtual ~bsta_parzen() {}
00074
00075 bsta_parzen(sample_vector const& samples)
00076 : samples_(samples) {}
00077
00078
00079 void insert_sample(const vect_t& sample)
00080 { samples_.push_back(sample); }
00081
00082
00083 void insert_samples(const sample_vector & samples)
00084 { for (sv_const_it sit = samples.begin();
00085 sit != samples.end(); ++sit)
00086 samples_.push_back(*sit);
00087 }
00088
00089 sample_vector samples() const
00090 { return samples_; }
00091
00092 vect_t sample(unsigned index) const
00093 { if (index>=samples_.size())
00094 { vect_t v(T(0)); return v; }
00095 return samples_[index];
00096 }
00097
00098 bool remove_sample(unsigned index)
00099 { if (index>=samples_.size()) return false;
00100 samples_.erase(samples_.begin()+index);
00101 return true;
00102 }
00103
00104
00105 void clear() { samples_.clear(); }
00106
00107
00108 unsigned size() const { return samples_.size(); }
00109 };
00110
00111 #endif // bsta_parzen_h_