contrib/mul/pdf1d/pdf1d_kernel_pdf.h
Go to the documentation of this file.
00001 // This is mul/pdf1d/pdf1d_kernel_pdf.h
00002 #ifndef pdf1d_kernel_pdf_h
00003 #define pdf1d_kernel_pdf_h
00004 
00005 //:
00006 // \file
00007 // \brief Univariate kernel_pdf PDF
00008 // \author Tim Cootes
00009 
00010 #include <pdf1d/pdf1d_pdf.h>
00011 #include <vnl/vnl_vector.h>
00012 #include <vcl_vector.h>
00013 #include <vcl_iosfwd.h>
00014 
00015 //: Class for univariate kernel based PDFs.
00016 //  Distribution is the sum of a set of kernel functions placed on the training
00017 //  samples.
00018 //
00019 //  Essentially a special case of a mixture model.  It differs from
00020 //  the former in that a) every component has the same shape, though
00021 //  possibly a different width b) every component has the same weight
00022 //  c) Usually one uses different training algorithms.
00023 //  Mixture models are more general.
00024 class pdf1d_kernel_pdf : public pdf1d_pdf
00025 {
00026  protected:
00027   //: Position of kernel centres
00028   vnl_vector<double> x_;
00029 
00030   //: Width of each kernel
00031   vnl_vector<double> width_;
00032 
00033   //: Workspace
00034   // If non-empty x_(index[i]) <= x_(index[i+1])
00035   mutable vcl_vector<int> index_;
00036 
00037   //: True if all kernels have the same width
00038   bool all_same_width_;
00039 
00040  public:
00041   //: Dflt ctor
00042   pdf1d_kernel_pdf();
00043 
00044   //: Destructor
00045   virtual ~pdf1d_kernel_pdf();
00046 
00047   //: Initialise so all kernels have the same width
00048   virtual void set_centres(const vnl_vector<double>& x, double width);
00049 
00050   //: Initialise so all kernels have given width
00051   virtual void set_centres(const vnl_vector<double>& x,
00052                            const vnl_vector<double>& width);
00053 
00054   //: Position of kernel centres
00055   const vnl_vector<double>& centre() const { return x_; }
00056 
00057   //: Width of each kernel
00058   const vnl_vector<double>& width() const { return width_; }
00059 
00060   //: True if all kernels have the same width
00061   bool all_same_width() const { return all_same_width_; }
00062 
00063   //: The inverse cdf.
00064   // The value of x: P(x'<x) = P for x' drawn from distribution pdf.
00065   // Uses Newton-Raphson.
00066   virtual double inverse_cdf(double P) const;
00067 
00068   //: Version number for I/O
00069   short version_no() const;
00070 
00071   //: Name of the class
00072   virtual vcl_string is_a() const;
00073 
00074   //: Does the name of the class match the argument?
00075   virtual bool is_class(vcl_string const& s) const;
00076 
00077   //: Print class to os
00078   virtual void print_summary(vcl_ostream& os) const;
00079 
00080   //: Save class to binary file stream
00081   virtual void b_write(vsl_b_ostream& bfs) const;
00082 
00083   //: Load class from binary file stream
00084   virtual void b_read(vsl_b_istream& bfs);
00085 };
00086 
00087 #endif // pdf1d_kernel_pdf_h