Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
vpdfl_kernel_pdf_builder Class Reference

Build kernel pdf objects. More...

#include <vpdfl_kernel_pdf_builder.h>

Inheritance diagram for vpdfl_kernel_pdf_builder:
Inheritance graph
[legend]

List of all members.

Public Types

enum  build_type { fixed_width, select_equal, width_from_sep, adaptive }

Public Member Functions

 vpdfl_kernel_pdf_builder ()
 Dflt ctor.
virtual ~vpdfl_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 (vpdfl_pdf_base &model, const vnl_vector< double > &mean) const
 Build default model with given mean.
virtual void build (vpdfl_pdf_base &model, mbl_data_wrapper< vnl_vector< double > > &data) const
 Build model from data.
void build_from_array (vpdfl_pdf_base &model, const vnl_vector< double > *data, int n) const
 Build kernel_pdf from n elements in data[i].
virtual void weighted_build (vpdfl_pdf_base &model, mbl_data_wrapper< vnl_vector< double > > &data, const vcl_vector< double > &wts) const
 Build model from weighted data.
void build_fixed_width (vpdfl_kernel_pdf &kpdf, const vnl_vector< double > *data, int n, double width) const
 Build from n elements in data[i]. Fixed kernel width.
void build_select_equal_width (vpdfl_kernel_pdf &kpdf, const vnl_vector< double > *data, int n) const
 Build from n elements in data[i]. Chooses width.
void build_width_from_separation (vpdfl_kernel_pdf &kpdf, const vnl_vector< double > *data, int n) const
 Kernel width proportional to distance to nearby samples.
void build_adaptive (vpdfl_kernel_pdf &kpdf, const vnl_vector< 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 void config_from_stream (vcl_istream &is)
 Read initialisation settings from a stream.
virtual vpdfl_pdf_basenew_model () const =0
 Create empty model.
virtual vpdfl_builder_baseclone () const =0
 Create a copy on the heap and return base class pointer.

Static Public Member Functions

static vcl_auto_ptr
< vpdfl_builder_base
new_builder_from_stream (vcl_istream &is)
 Create a vpdfl_builder_base object given a config stream.
static vcl_auto_ptr
< vpdfl_builder_base
new_pdf_builder_from_stream (vcl_istream &)
 Create a vpdfl_builder_base object given a config stream (recursive style).

Private Member Functions

vpdfl_kernel_pdfkernel_pdf (vpdfl_pdf_base &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.

Detailed Description

Build kernel pdf objects.

Contains algorithms for selecting kernel widths.

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

A fixed width can be supplied (set_use_fixed_width(w))

The widths can be estimated from the proximity of neighbours set_use_width_from_separation()

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 36 of file vpdfl_kernel_pdf_builder.h.


Member Enumeration Documentation

Enumerator:
fixed_width 
select_equal 
width_from_sep 
adaptive 

Definition at line 39 of file vpdfl_kernel_pdf_builder.h.


Constructor & Destructor Documentation

vpdfl_kernel_pdf_builder::vpdfl_kernel_pdf_builder ( )

Dflt ctor.

Definition at line 38 of file vpdfl_kernel_pdf_builder.cxx.

vpdfl_kernel_pdf_builder::~vpdfl_kernel_pdf_builder ( ) [virtual]

Destructor.

Definition at line 47 of file vpdfl_kernel_pdf_builder.cxx.


Member Function Documentation

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

Load class from binary file stream.

Implements vpdfl_builder_base.

Definition at line 339 of file vpdfl_kernel_pdf_builder.cxx.

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

Save class to binary file stream.

Implements vpdfl_builder_base.

Definition at line 329 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build ( vpdfl_pdf_base model,
const vnl_vector< double > &  mean 
) const [virtual]

Build default model with given mean.

Implements vpdfl_builder_base.

Definition at line 99 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build ( vpdfl_pdf_base model,
mbl_data_wrapper< vnl_vector< double > > &  data 
) const [virtual]

Build model from data.

Implements vpdfl_builder_base.

Definition at line 141 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build_adaptive ( vpdfl_kernel_pdf kpdf,
const vnl_vector< 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

Definition at line 262 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build_fixed_width ( vpdfl_kernel_pdf kpdf,
const vnl_vector< double > *  data,
int  n,
double  width 
) const

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

Build from n elements in data[i].

Definition at line 182 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build_from_array ( vpdfl_pdf_base model,
const vnl_vector< double > *  data,
int  n 
) const

Build kernel_pdf from n elements in data[i].

Definition at line 110 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build_select_equal_width ( vpdfl_kernel_pdf kpdf,
const vnl_vector< double > *  data,
int  n 
) const

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

Same width selected for all points, using $w=(4/(2n+d.n)^{1/(d+4)}\sigma$, as suggested by Silverman Note: This value only suitable for gaussian kernels!

Definition at line 193 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::build_width_from_separation ( vpdfl_kernel_pdf kpdf,
const vnl_vector< double > *  data,
int  n 
) const

Kernel width proportional to distance to nearby samples.

Width to nearest neighbour, allowing for repeats.

Definition at line 212 of file vpdfl_kernel_pdf_builder.cxx.

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

Create a copy on the heap and return base class pointer.

Implemented in vpdfl_mixture_builder, vpdfl_pc_gaussian_builder, vpdfl_gaussian_builder, vpdfl_axis_gaussian_builder, and vpdfl_gaussian_kernel_pdf_builder.

void vpdfl_kernel_pdf_builder::config_from_stream ( vcl_istream &  is) [virtual]

Read initialisation settings from a stream.

Parameters:

   {
     min_var: 1.0e-6
     // kernel_widths can be fixed_width,select_equal,width_from_sep,adaptive
     kernel_widths: fixed_width
     // Width to be used when it is fixed_width
     fixed_width: 1.0
   }
   
Exceptions:
mbl_exception_parse_errorif the parse fails.

Reimplemented from vpdfl_builder_base.

Definition at line 370 of file vpdfl_kernel_pdf_builder.cxx.

vcl_string vpdfl_kernel_pdf_builder::is_a ( ) const [virtual]

Name of the class.

Reimplemented from vpdfl_builder_base.

Reimplemented in vpdfl_gaussian_kernel_pdf_builder.

Definition at line 293 of file vpdfl_kernel_pdf_builder.cxx.

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

Does the name of the class match the argument?.

Reimplemented from vpdfl_builder_base.

Reimplemented in vpdfl_gaussian_kernel_pdf_builder.

Definition at line 302 of file vpdfl_kernel_pdf_builder.cxx.

vpdfl_kernel_pdf & vpdfl_kernel_pdf_builder::kernel_pdf ( vpdfl_pdf_base model) const [private]

Definition at line 53 of file vpdfl_kernel_pdf_builder.cxx.

double vpdfl_kernel_pdf_builder::min_var ( ) const [virtual]

Get lower threshold on variance for built models.

Implements vpdfl_builder_base.

Definition at line 94 of file vpdfl_kernel_pdf_builder.cxx.

vcl_auto_ptr< vpdfl_builder_base > vpdfl_builder_base::new_builder_from_stream ( vcl_istream &  is) [static, inherited]

Create a vpdfl_builder_base object given a config stream.

Exceptions:
mbl_exceptionif parse error.
vcl_runtime_exceptionif parse error.

This will store the constructed builder.

Incoming properties.

Definition at line 55 of file vpdfl_builder_base.cxx.

virtual vpdfl_pdf_base* vpdfl_builder_base::new_model ( ) const [pure virtual, inherited]
vcl_auto_ptr< vpdfl_builder_base > vpdfl_builder_base::new_pdf_builder_from_stream ( vcl_istream &  is) [static, inherited]

Create a vpdfl_builder_base object given a config stream (recursive style).

Creates object, then uses config_from_stream(is) to set up internals

Exceptions:
vcl_runtime_exceptionif parse error.

Creates object, then uses config_from_stream(is) to set up internals

Definition at line 145 of file vpdfl_builder_base.cxx.

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

Print class to os.

Implements vpdfl_builder_base.

Definition at line 320 of file vpdfl_kernel_pdf_builder.cxx.

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

Define lower threshold on variance for built models.

Implements vpdfl_builder_base.

Definition at line 87 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::set_use_adaptive ( )

Build adaptive kernel estimate.

Definition at line 80 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::set_use_equal_width ( )

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

Definition at line 68 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::set_use_fixed_width ( double  width)

Use fixed width kernels of given width when building.

Definition at line 61 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::set_use_width_from_separation ( )

Kernel width proportional to distance to nearby samples.

Definition at line 74 of file vpdfl_kernel_pdf_builder.cxx.

short vpdfl_kernel_pdf_builder::version_no ( ) const

Version number for I/O.

Reimplemented from vpdfl_builder_base.

Definition at line 311 of file vpdfl_kernel_pdf_builder.cxx.

void vpdfl_kernel_pdf_builder::weighted_build ( vpdfl_pdf_base model,
mbl_data_wrapper< vnl_vector< double > > &  data,
const vcl_vector< double > &  wts 
) const [virtual]

Build model from weighted data.

Implements vpdfl_builder_base.

Definition at line 173 of file vpdfl_kernel_pdf_builder.cxx.


Member Data Documentation

Type of building to be performed.

Definition at line 45 of file vpdfl_kernel_pdf_builder.h.

Width set if fixed_width option on build used.

Definition at line 48 of file vpdfl_kernel_pdf_builder.h.

Minimum variance of whole model.

Definition at line 42 of file vpdfl_kernel_pdf_builder.h.


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