contrib/mul/vpdfl/vpdfl_kernel_pdf.h
Go to the documentation of this file.
00001 // This is mul/vpdfl/vpdfl_kernel_pdf.h
00002 #ifndef vpdfl_kernel_pdf_h
00003 #define vpdfl_kernel_pdf_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Multi-variate kernel PDF
00010 // \author Tim Cootes
00011 
00012 #include <vpdfl/vpdfl_pdf_base.h>
00013 #include <vcl_vector.h>
00014 #include <vcl_iosfwd.h>
00015 
00016 //: Multi-variate kernel PDF
00017 //  Distribution is the sum of a set of kernel functions placed on the training
00018 //  samples.
00019 //
00020 //  Essentially a special case of a mixture model.  It differs from
00021 //  the former in that a) every component has the same shape, though
00022 //  possibly a different width b) every component has the same weight
00023 //  c) Usually one uses different training algorithms.
00024 class vpdfl_kernel_pdf : public vpdfl_pdf_base
00025 {
00026  protected:
00027   //: Position of kernel centres
00028   vcl_vector<vnl_vector<double> > x_;
00029 
00030   //: Width of each kernel
00031   vnl_vector<double> width_;
00032 
00033   //: True if all kernels have the same width
00034   bool all_same_width_;
00035 
00036   //: Compute mean/variance given current centres and widths
00037   void calc_mean_var();
00038 
00039  public:
00040 
00041   //: Dflt ctor
00042   vpdfl_kernel_pdf();
00043 
00044   //: Destructor
00045   virtual ~vpdfl_kernel_pdf();
00046 
00047   //: Initialise so all kernels have the same width.
00048   //  width is essentially the sd on the kernels
00049   void set_centres(const vnl_vector<double>* x, int n, double width);
00050 
00051   //: Initialise so all kernels have given width.
00052   //  width[i] is essentially the sd on kernel i
00053   void set_centres(const vnl_vector<double>* x, int n,
00054                    const vnl_vector<double>& width);
00055 
00056   //: Position of kernel centres
00057   const vcl_vector<vnl_vector<double> >& centre() const { return x_; }
00058 
00059   //: Width of each kernel
00060   const vnl_vector<double>& width() const { return width_; }
00061 
00062   //: True if all kernels have the same width
00063   bool all_same_width() const { return all_same_width_; }
00064 
00065   //: Version number for I/O
00066   short version_no() const;
00067 
00068   //: Name of the class
00069   virtual vcl_string is_a() const;
00070 
00071   //: Does the name of the class match the argument?
00072   virtual bool is_class(vcl_string const& s) const;
00073 
00074   //: Print class to os
00075   virtual void print_summary(vcl_ostream& os) const;
00076 
00077   //: Save class to binary file stream
00078   virtual void b_write(vsl_b_ostream& bfs) const;
00079 
00080   //: Load class from binary file stream
00081   virtual void b_read(vsl_b_istream& bfs);
00082 };
00083 
00084 #endif // vpdfl_kernel_pdf_h