contrib/mul/pdf1d/pdf1d_epanech_kernel_pdf_sampler.h
Go to the documentation of this file.
00001 #ifndef pdf1d_epanech_kernel_pdf_sampler_h_
00002 #define pdf1d_epanech_kernel_pdf_sampler_h_
00003 //:
00004 // \file
00005 // \brief Implements sampling for an Epanechnikov kernel PDF
00006 // \author Tim Cootes
00007 
00008 #include <vnl/vnl_random.h>
00009 #include <pdf1d/pdf1d_sampler.h>
00010 #include <pdf1d/pdf1d_epanech_kernel_pdf.h>
00011 
00012 class pdf1d_epanech_kernel_pdf;
00013 
00014 //: Generates random samples from an Epanechnikov kernel estimate
00015 class pdf1d_epanech_kernel_pdf_sampler : public pdf1d_sampler
00016 {
00017  protected:
00018   //: The random number generator
00019   vnl_random rng_;
00020  public:
00021 
00022   //: Dflt ctor
00023   pdf1d_epanech_kernel_pdf_sampler();
00024 
00025   //: Destructor
00026   virtual ~pdf1d_epanech_kernel_pdf_sampler();
00027 
00028   const pdf1d_epanech_kernel_pdf& epanech_kernel_pdf() const;
00029 
00030   //: Draw random sample from distribution
00031   virtual double sample();
00032 
00033   //: Fill x with samples possibly chosen so as to represent the distribution
00034   //  Samples equal numbers from each kernel.
00035   virtual void regular_samples(vnl_vector<double>& x);
00036 
00037   //: Reseeds the static random number generator (one per derived class)
00038   virtual void reseed(unsigned long);
00039 
00040   //: Version number for I/O
00041   short version_no() const;
00042 
00043   //: Name of the class
00044   virtual vcl_string is_a() const;
00045 
00046   //: Does the name of the class match the argument?
00047   virtual bool is_class(vcl_string const& s) const;
00048 
00049   //: Create a copy on the heap and return base class pointer
00050   virtual pdf1d_sampler* clone() const;
00051 
00052   //: Transform a unit uniform distribution x into an Epanech distribution y
00053   // $0 <= x <= 1  =>  -sqrt(5) <= y <= sqrt(5)$
00054   // Matlab found 6 solutions to
00055   // ${\frac {3}{20}}\,\left |{\it Dy}\right |\sqrt {5}\left (1-1/5\,{y}^{2}\right )=1$
00056   // The 6th, which has the correct properties is
00057   // $-1/2\,\sqrt [3]{-10\,\sqrt {5}x+5\,\sqrt {-5+20\,{x}^{2}}}-5/2\,
00058   // {\frac {1}{\sqrt [3]{-10\,\sqrt {5}x+5\,\sqrt {-5+20\,{x}^{2}}}}}-1/2\,
00059   // \sqrt {-1}\sqrt {3}\left (\sqrt [3]{-10\,\sqrt {5}x+5\,\sqrt {-5+20\,
00060   // {x}^{2}}}-5\,{\frac {1}{\sqrt [3]{-10\,\sqrt {5}x+5\,\sqrt {-5+20\,
00061   // {x}^{2}}}}}\right )$
00062   static double epan_transform(double x);
00063 };
00064 
00065 #endif // pdf1d_epanech_kernel_pdf_sampler_h_