pdf1d_kernel_pdf_builder Class Reference

#include <pdf1d_kernel_pdf_builder.h>

Inheritance diagram for pdf1d_kernel_pdf_builder:

Inheritance graph
[legend]

List of all members.


Detailed Description

Build kernel pdf objects.

Contains algorithms for selecting kernel widths.

Simplest is to use equal widths (set_use_equal_width()).

More interesting is an adaptive kernel estimate (set_use_adaptive()). This tends to get results comparable with the equal width method for simple cases, but can match to more complex distributions more easily. In particular, it tends to approximate the tails more accurately.

See book on Density Estimation by B.W.Silverman (Pub. Chapman and Hall, 1986) for details.

Definition at line 29 of file pdf1d_kernel_pdf_builder.h.


Public Types

enum  build_type { fixed_width, select_equal, width_from_sep, adaptive }

Public Member Functions

 pdf1d_kernel_pdf_builder ()
 Dflt ctor.
virtual ~pdf1d_kernel_pdf_builder ()
 Destructor.
void set_use_fixed_width (double width)
 Use fixed width kernels of given width when building.
void set_use_equal_width ()
 Use equal width kernels of width depending on number of samples.
void set_use_width_from_separation ()
 Kernel width proportional to distance to nearby samples.
void set_use_adaptive ()
 Build adaptive kernel estimate.
virtual void set_min_var (double min_var)
 Define lower threshold on variance for built models.
virtual double min_var () const
 Get lower threshold on variance for built models.
virtual void build_from_array (pdf1d_pdf &model, const double *data, int n) const
 Build from n elements in data[i].
virtual void build (pdf1d_pdf &model, double mean) const
 Build default model with given mean.
virtual void build (pdf1d_pdf &model, mbl_data_wrapper< double > &data) const
 Build model from data.
virtual void weighted_build (pdf1d_pdf &model, mbl_data_wrapper< double > &data, const vcl_vector< double > &wts) const
 Build model from weighted data.
void build_fixed_width (pdf1d_kernel_pdf &kpdf, const double *data, int n, double width) const
 Build from n elements in data[i]. Fixed kernel width.
void build_select_equal_width (pdf1d_kernel_pdf &kpdf, const double *data, int n) const
 Build from n elements in data[i]. Chooses width.
void build_width_from_separation (pdf1d_kernel_pdf &kpdf, const double *data, int n) const
 Kernel width proportional to distance to nearby samples.
void build_adaptive (pdf1d_kernel_pdf &kpdf, const double *data, int n) const
 Build adaptive kernel estimate.
short version_no () const
 Version number for I/O.
virtual vcl_string is_a () const
 Name of the class.
virtual bool is_class (vcl_string const &s) const
 Does the name of the class match the argument?.
virtual void print_summary (vcl_ostream &os) const
 Print class to os.
virtual void b_write (vsl_b_ostream &bfs) const
 Save class to binary file stream.
virtual void b_read (vsl_b_istream &bfs)
 Load class from binary file stream.
virtual pdf1d_pdfnew_model () const =0
 Create empty model.
virtual vcl_string new_model_type () const =0
 Name of the model class returned by new_model().
virtual pdf1d_builderclone () const =0
 Create a copy on the heap and return base class pointer.

Private Member Functions

pdf1d_kernel_pdfkernel_pdf (pdf1d_pdf &model) const

Private Attributes

double min_var_
 Minimum variance of whole model.
build_type build_type_
 Type of building to be performed.
double fixed_width_
 Width set if fixed_width option on build used.

Member Enumeration Documentation

Enumerator:
fixed_width 
select_equal 
width_from_sep 
adaptive 

Definition at line 32 of file pdf1d_kernel_pdf_builder.h.


Constructor & Destructor Documentation

pdf1d_kernel_pdf_builder::pdf1d_kernel_pdf_builder (  ) 

Dflt ctor.

Definition at line 21 of file pdf1d_kernel_pdf_builder.cxx.

pdf1d_kernel_pdf_builder::~pdf1d_kernel_pdf_builder (  )  [virtual]

Destructor.

Definition at line 28 of file pdf1d_kernel_pdf_builder.cxx.


Member Function Documentation

pdf1d_kernel_pdf & pdf1d_kernel_pdf_builder::kernel_pdf ( pdf1d_pdf model  )  const [private]

Definition at line 34 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::set_use_fixed_width ( double  width  ) 

Use fixed width kernels of given width when building.

Definition at line 42 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::set_use_equal_width (  ) 

Use equal width kernels of width depending on number of samples.

This method appears to give a lower density near the tails

Definition at line 49 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::set_use_width_from_separation (  ) 

Kernel width proportional to distance to nearby samples.

Definition at line 55 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::set_use_adaptive (  ) 

Build adaptive kernel estimate.

Definition at line 61 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::set_min_var ( double  min_var  )  [virtual]

Define lower threshold on variance for built models.

Implements pdf1d_builder.

Definition at line 68 of file pdf1d_kernel_pdf_builder.cxx.

double pdf1d_kernel_pdf_builder::min_var (  )  const [virtual]

Get lower threshold on variance for built models.

Implements pdf1d_builder.

Definition at line 75 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build_from_array ( pdf1d_pdf model,
const double *  data,
int  n 
) const [virtual]

Build from n elements in data[i].

Build kernel_pdf from n elements in data[i].

Reimplemented from pdf1d_builder.

Definition at line 90 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build ( pdf1d_pdf model,
double  mean 
) const [virtual]

Build default model with given mean.

Implements pdf1d_builder.

Definition at line 80 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build ( pdf1d_pdf model,
mbl_data_wrapper< double > &  data 
) const [virtual]

Build model from data.

The kernel centres in the pdf will have same value and order as the training data

Implements pdf1d_builder.

Definition at line 126 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::weighted_build ( pdf1d_pdf model,
mbl_data_wrapper< double > &  data,
const vcl_vector< double > &  wts 
) const [virtual]

Build model from weighted data.

Implements pdf1d_builder.

Definition at line 158 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build_fixed_width ( pdf1d_kernel_pdf kpdf,
const double *  data,
int  n,
double  width 
) const

Build from n elements in data[i]. Fixed kernel width.

Build from n elements in data[i].

The kernel centres in the pdf will have same value and order as the training data

Definition at line 167 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build_select_equal_width ( pdf1d_kernel_pdf kpdf,
const double *  data,
int  n 
) const

Build from n elements in data[i]. Chooses width.

Same width selected for all points, using $w=(3n/4)^{-0.2}\sigma$, as suggested by Silverman

The kernel centres in the pdf will have same value and order as the training data

Same width selected for all points, using $w=(3n/4)^{-0.2}\sigma$, as suggested by Silverman

Definition at line 177 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build_width_from_separation ( pdf1d_kernel_pdf kpdf,
const double *  data,
int  n 
) const

Kernel width proportional to distance to nearby samples.

The kernel centres in the pdf will have same value and order as the training data

Definition at line 220 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::build_adaptive ( pdf1d_kernel_pdf kpdf,
const double *  data,
int  n 
) const

Build adaptive kernel estimate.

Use equal widths to create a pilot estimate, then use the prob at each data point to modify the widths. Uses Silverman's equation 5.8 with alpha = 0.5 as suggested, and based on a pilot estimate as calculated by build_select_equal_width(). The kernel centres in the pdf will have same value and order as the training data.

This method gives a significantly higher density near the edges of the distribution than suggested by the cumulative histogram of the training data, pushing the cdf estimate closer to 0.5 at the edges. If you want to approximate the cumulative histogram more closely, then build_select_equal_width() may be more effective.

Use equal widths to create a pilot estimate, then use the prob at each data point to modify the widths

Definition at line 244 of file pdf1d_kernel_pdf_builder.cxx.

short pdf1d_kernel_pdf_builder::version_no (  )  const

Version number for I/O.

Reimplemented from pdf1d_builder.

Reimplemented in pdf1d_epanech_kernel_pdf_builder, and pdf1d_gaussian_kernel_pdf_builder.

Definition at line 286 of file pdf1d_kernel_pdf_builder.cxx.

vcl_string pdf1d_kernel_pdf_builder::is_a (  )  const [virtual]

Name of the class.

Reimplemented from pdf1d_builder.

Reimplemented in pdf1d_epanech_kernel_pdf_builder, and pdf1d_gaussian_kernel_pdf_builder.

Definition at line 272 of file pdf1d_kernel_pdf_builder.cxx.

bool pdf1d_kernel_pdf_builder::is_class ( vcl_string const &  s  )  const [virtual]

Does the name of the class match the argument?.

Reimplemented from pdf1d_builder.

Reimplemented in pdf1d_epanech_kernel_pdf_builder, and pdf1d_gaussian_kernel_pdf_builder.

Definition at line 279 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::print_summary ( vcl_ostream &  os  )  const [virtual]

Print class to os.

Implements pdf1d_builder.

Reimplemented in pdf1d_epanech_kernel_pdf_builder, and pdf1d_gaussian_kernel_pdf_builder.

Definition at line 293 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::b_write ( vsl_b_ostream bfs  )  const [virtual]

Save class to binary file stream.

Implements pdf1d_builder.

Definition at line 300 of file pdf1d_kernel_pdf_builder.cxx.

void pdf1d_kernel_pdf_builder::b_read ( vsl_b_istream bfs  )  [virtual]

Load class from binary file stream.

Implements pdf1d_builder.

Definition at line 308 of file pdf1d_kernel_pdf_builder.cxx.

virtual pdf1d_pdf* pdf1d_builder::new_model (  )  const [pure virtual, inherited]

virtual vcl_string pdf1d_builder::new_model_type (  )  const [pure virtual, inherited]

virtual pdf1d_builder* pdf1d_builder::clone (  )  const [pure virtual, inherited]


Member Data Documentation

Minimum variance of whole model.

Definition at line 35 of file pdf1d_kernel_pdf_builder.h.

Type of building to be performed.

Definition at line 38 of file pdf1d_kernel_pdf_builder.h.

Width set if fixed_width option on build used.

Definition at line 41 of file pdf1d_kernel_pdf_builder.h.


The documentation for this class was generated from the following files:

Generated on Sun Nov 22 06:23:40 2009 for contrib/mul/pdf1d by  doxygen 1.5.5