vpdfl_mixture_builder Class Reference

#include <vpdfl_mixture_builder.h>

Inheritance diagram for vpdfl_mixture_builder:

Inheritance graph
[legend]

List of all members.


Detailed Description

Uses the EM algorithm to build vpdfl_mixture objects.

Definition at line 28 of file vpdfl_mixture_builder.h.


Public Member Functions

 vpdfl_mixture_builder ()
 Dflt ctor.
 vpdfl_mixture_builder (const vpdfl_mixture_builder &)
 Copy ctor.
vpdfl_mixture_builderoperator= (const vpdfl_mixture_builder &)
 Copy operator.
virtual ~vpdfl_mixture_builder ()
 Destructor.
void init (const vpdfl_builder_base &builder, int n)
 Initialise n builders of type builder.
bool weights_fixed () const
 Whether weights on components left unchanged during iterations.
void set_weights_fixed (bool b)
 Whether weights on components left unchanged during iterations.
void set_max_iterations (int n)
 Define maximum number of EM iterations allowed.
int max_iterations () const
 Define maximum number of EM iterations allowed.
unsigned n_builders () const
 Number of basis builders.
vpdfl_builder_basebuilder (unsigned i)
 Return i-th builder.
virtual vpdfl_pdf_basenew_model () const
 Create empty model.
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.
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 preset_initial_means (const vcl_vector< vnl_vector< double > > &component_means)
 Preset initial component means.
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 vpdfl_builder_baseclone () const
 Create a copy on the heap and return base class pointer.
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.

Static Public Member Functions

static void calc_mean_and_variance (vpdfl_mixture &model)
 Calculate and set the mixture's mean and variance.
static vcl_auto_ptr
< vpdfl_builder_base
new_builder_from_stream (vcl_istream &is)
 Create a vpdfl_builder_base object given a config steram.
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

void initialise_given_means (vpdfl_mixture &model, const vnl_vector< double > *data, const vcl_vector< vnl_vector< double > > &mean, const vcl_vector< double > &wts) const
 Assumes means set up. Estimates starting components.
void initialise_to_regular_samples (vpdfl_mixture &model, const vnl_vector< double > *data, const vcl_vector< double > &wts) const
 Means centred on data[i*f].
void initialise_diagonal (vpdfl_mixture &model, const vnl_vector< double > *data, const vcl_vector< double > &wts) const
 Select positions along diagonal of bounding box.
void initialise (vpdfl_mixture &model, const vnl_vector< double > *data, const vcl_vector< double > &wts) const
 Select positions and widths for components to start.
void e_step (vpdfl_mixture &model, vcl_vector< vnl_vector< double > > &probs, const vnl_vector< double > *data, const vcl_vector< double > &wts) const
 The Expectation part of the EM algorithm.
double m_step (vpdfl_mixture &model, const vcl_vector< vnl_vector< double > > &probs, const vnl_vector< double > *data, const vcl_vector< double > &wts) const
 The Maximisation part of the EM algorithm.
void init ()
void delete_stuff ()

Private Attributes

vcl_vector< vpdfl_builder_base * > builder_
double min_var_
int max_its_
vcl_vector< vnl_vector< double > > initial_means_
bool weights_fixed_
 Whether weights changed during iterations.

Constructor & Destructor Documentation

vpdfl_mixture_builder::vpdfl_mixture_builder (  ) 

Dflt ctor.

Definition at line 49 of file vpdfl_mixture_builder.cxx.

vpdfl_mixture_builder::vpdfl_mixture_builder ( const vpdfl_mixture_builder b  ) 

Copy ctor.

Definition at line 56 of file vpdfl_mixture_builder.cxx.

vpdfl_mixture_builder::~vpdfl_mixture_builder (  )  [virtual]

Destructor.

Definition at line 95 of file vpdfl_mixture_builder.cxx.


Member Function Documentation

void vpdfl_mixture_builder::initialise_given_means ( vpdfl_mixture model,
const vnl_vector< double > *  data,
const vcl_vector< vnl_vector< double > > &  mean,
const vcl_vector< double > &  wts 
) const [private]

Assumes means set up. Estimates starting components.

Parameters:
mean_sep : Rough guess of mean separation between points

Definition at line 246 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::initialise_to_regular_samples ( vpdfl_mixture model,
const vnl_vector< double > *  data,
const vcl_vector< double > &  wts 
) const [private]

Means centred on data[i*f].

Definition at line 321 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::initialise_diagonal ( vpdfl_mixture model,
const vnl_vector< double > *  data,
const vcl_vector< double > &  wts 
) const [private]

Select positions along diagonal of bounding box.

Definition at line 290 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::initialise ( vpdfl_mixture model,
const vnl_vector< double > *  data,
const vcl_vector< double > &  wts 
) const [private]

Select positions and widths for components to start.

Definition at line 343 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::e_step ( vpdfl_mixture model,
vcl_vector< vnl_vector< double > > &  probs,
const vnl_vector< double > *  data,
const vcl_vector< double > &  wts 
) const [private]

The Expectation part of the EM algorithm.

Definition at line 364 of file vpdfl_mixture_builder.cxx.

double vpdfl_mixture_builder::m_step ( vpdfl_mixture model,
const vcl_vector< vnl_vector< double > > &  probs,
const vnl_vector< double > *  data,
const vcl_vector< double > &  wts 
) const [private]

The Maximisation part of the EM algorithm.

Definition at line 429 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::init (  )  [private]

Definition at line 39 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::delete_stuff (  )  [private]

Definition at line 86 of file vpdfl_mixture_builder.cxx.

vpdfl_mixture_builder & vpdfl_mixture_builder::operator= ( const vpdfl_mixture_builder b  ) 

Copy operator.

Definition at line 65 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::init ( const vpdfl_builder_base builder,
int  n 
)

Initialise n builders of type builder.

Clone taken of builder

Definition at line 104 of file vpdfl_mixture_builder.cxx.

bool vpdfl_mixture_builder::weights_fixed (  )  const [inline]

Whether weights on components left unchanged during iterations.

Definition at line 94 of file vpdfl_mixture_builder.h.

void vpdfl_mixture_builder::set_weights_fixed ( bool  b  ) 

Whether weights on components left unchanged during iterations.

Define whether weights on components can change or not.

Definition at line 120 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::set_max_iterations ( int  n  ) 

Define maximum number of EM iterations allowed.

Definition at line 115 of file vpdfl_mixture_builder.cxx.

int vpdfl_mixture_builder::max_iterations (  )  const [inline]

Define maximum number of EM iterations allowed.

Definition at line 103 of file vpdfl_mixture_builder.h.

unsigned vpdfl_mixture_builder::n_builders (  )  const [inline]

Number of basis builders.

Definition at line 106 of file vpdfl_mixture_builder.h.

vpdfl_builder_base& vpdfl_mixture_builder::builder ( unsigned  i  )  [inline]

Return i-th builder.

Definition at line 109 of file vpdfl_mixture_builder.h.

vpdfl_pdf_base * vpdfl_mixture_builder::new_model (  )  const [virtual]

Create empty model.

Implements vpdfl_builder_base.

Definition at line 128 of file vpdfl_mixture_builder.cxx.

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

Define lower threshold on variance for built models.

Implements vpdfl_builder_base.

Definition at line 136 of file vpdfl_mixture_builder.cxx.

double vpdfl_mixture_builder::min_var (  )  const [virtual]

Get lower threshold on variance for built models.

Implements vpdfl_builder_base.

Definition at line 144 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::calc_mean_and_variance ( vpdfl_mixture model  )  [static]

Calculate and set the mixture's mean and variance.

This should be used after the weights or components of the model have been altered.

Definition at line 521 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_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 152 of file vpdfl_mixture_builder.cxx.

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

Build model from data.

Use EM algorithm to best fit mixture model to given data If model does not have the correct number of components they will be initialised to means scattered through the data. If they model has the correct number of components it is assumed that they have been set to sensible initial values. The EM algorithm will be used to optimise their parameters.

Implements vpdfl_builder_base.

Definition at line 162 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_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.

Use EM algorithm to best fit mixture model to given data If model does not have the correct number of components they will be initialised to means scattered through the data. If they model has the correct number of components it is assumed that they have been set to sensible initial values. The EM algorithm will be used to optimise their parameters.

Implements vpdfl_builder_base.

Definition at line 172 of file vpdfl_mixture_builder.cxx.

void vpdfl_mixture_builder::preset_initial_means ( const vcl_vector< vnl_vector< double > > &  component_means  ) 

Preset initial component means.

When initialise is called these means will be used as the initial guess Note that the vector must is copied

Definition at line 358 of file vpdfl_mixture_builder.cxx.

short vpdfl_mixture_builder::version_no (  )  const

Version number for I/O.

Reimplemented from vpdfl_builder_base.

Definition at line 556 of file vpdfl_mixture_builder.cxx.

vcl_string vpdfl_mixture_builder::is_a (  )  const [virtual]

Name of the class.

Reimplemented from vpdfl_builder_base.

Definition at line 542 of file vpdfl_mixture_builder.cxx.

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

Does the name of the class match the argument?.

Reimplemented from vpdfl_builder_base.

Definition at line 549 of file vpdfl_mixture_builder.cxx.

vpdfl_builder_base * vpdfl_mixture_builder::clone (  )  const [virtual]

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

Implements vpdfl_builder_base.

Definition at line 563 of file vpdfl_mixture_builder.cxx.

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

Print class to os.

Implements vpdfl_builder_base.

Definition at line 570 of file vpdfl_mixture_builder.cxx.

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

Save class to binary file stream.

Implements vpdfl_builder_base.

Definition at line 584 of file vpdfl_mixture_builder.cxx.

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

Load class from binary file stream.

Implements vpdfl_builder_base.

Definition at line 595 of file vpdfl_mixture_builder.cxx.

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

Read initialisation settings from a stream.

Parameters:

   {
     min_var: 1.0e-6
     // Number of pdf bases to use
     n_pdfs: 3
     // Type of basis pdf
     basis_pdf: axis_gaussian { min_var: 0.0001 }
     // Maximum number of iterations
     max_its: 10
     // When true, fix weights during EM
     weights_fixed: false
   }
   
Exceptions:
mbl_exception_parse_error if the parse fails.
Parameters:
   {
     min_var: 1.0e-6
     n_pdfs: 3
     // Type of basis pdf
     basis_pdf: axis_gaussian { min_var: 0.0001 }
   }
   
Exceptions:
mbl_exception_parse_error if the parse fails.

Reimplemented from vpdfl_builder_base.

Definition at line 639 of file vpdfl_mixture_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 steram.

Exceptions:
mbl_exception if parse error.
vcl_runtime_exception if parse error.

This will store the constructed builder.

Incoming properties.

Definition at line 55 of file vpdfl_builder_base.cxx.

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_exception if parse error.
Creates object, then uses config_from_stream(is) to set up internals

Definition at line 145 of file vpdfl_builder_base.cxx.


Member Data Documentation

Definition at line 30 of file vpdfl_mixture_builder.h.

Definition at line 31 of file vpdfl_mixture_builder.h.

Definition at line 32 of file vpdfl_mixture_builder.h.

vcl_vector<vnl_vector<double> > vpdfl_mixture_builder::initial_means_ [private]

Definition at line 33 of file vpdfl_mixture_builder.h.

Whether weights changed during iterations.

Definition at line 36 of file vpdfl_mixture_builder.h.


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

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