Uses the EM algorithm to build pdf1d_mixture objects. More...
#include <pdf1d_mixture_builder.h>
Public Member Functions | |
pdf1d_mixture_builder () | |
Dflt ctor. | |
pdf1d_mixture_builder (const pdf1d_mixture_builder &) | |
Copy ctor. | |
pdf1d_mixture_builder & | operator= (const pdf1d_mixture_builder &) |
Copy operator. | |
virtual | ~pdf1d_mixture_builder () |
Destructor. | |
void | init (pdf1d_builder &builder, int n) |
Initialise n builders of type builder. | |
void | set_max_iterations (int n) |
Define maximum number of EM iterations allowed. | |
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. | |
virtual pdf1d_pdf * | new_model () const |
Create empty model. | |
virtual vcl_string | new_model_type () const |
Name of the model class returned by new_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 (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. | |
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 pdf1d_builder * | clone () 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 | build_from_array (pdf1d_pdf &model, const double *data, int n) const |
Build model from data. | |
Static Public Member Functions | |
static void | calc_mean_and_variance (pdf1d_mixture &model) |
Calculate and set the mixture's mean and variance. | |
Private Member Functions | |
void | initialise (pdf1d_mixture &model, const double *data, const vcl_vector< double > &wts) const |
void | e_step (pdf1d_mixture &model, vcl_vector< vnl_vector< double > > &probs, const double *data, const vcl_vector< double > &wts) const |
The Expectation part of the EM algorithm. | |
double | m_step (pdf1d_mixture &model, const vcl_vector< vnl_vector< double > > &probs, const double *data, const vcl_vector< double > &wts) const |
The Maximisation part of the EM algorithm. | |
void | init () |
void | delete_stuff () |
Private Attributes | |
vcl_vector< pdf1d_builder * > | builder_ |
double | min_var_ |
int | max_its_ |
bool | weights_fixed_ |
Whether weights changed during iterations. |
Uses the EM algorithm to build pdf1d_mixture objects.
Definition at line 19 of file pdf1d_mixture_builder.h.
pdf1d_mixture_builder::pdf1d_mixture_builder | ( | ) |
Dflt ctor.
Definition at line 33 of file pdf1d_mixture_builder.cxx.
pdf1d_mixture_builder::pdf1d_mixture_builder | ( | const pdf1d_mixture_builder & | b | ) |
Copy ctor.
Definition at line 39 of file pdf1d_mixture_builder.cxx.
pdf1d_mixture_builder::~pdf1d_mixture_builder | ( | ) | [virtual] |
Destructor.
Definition at line 75 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Implements pdf1d_builder.
Definition at line 462 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Implements pdf1d_builder.
Definition at line 451 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::build | ( | pdf1d_pdf & | model, |
double | mean | ||
) | const [virtual] |
Build default model with given mean.
Implements pdf1d_builder.
Definition at line 138 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::build | ( | pdf1d_pdf & | model, |
mbl_data_wrapper< 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 pdf1d_builder.
Definition at line 147 of file pdf1d_mixture_builder.cxx.
void pdf1d_builder::build_from_array | ( | pdf1d_pdf & | model, |
const double * | data, | ||
int | n | ||
) | const [virtual, inherited] |
Build model from data.
Default wraps up data and calls build(model,wrapper);
Reimplemented in pdf1d_kernel_pdf_builder, pdf1d_exponential_builder, pdf1d_flat_builder, and pdf1d_gaussian_builder.
Definition at line 26 of file pdf1d_builder.cxx.
void pdf1d_mixture_builder::calc_mean_and_variance | ( | pdf1d_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 389 of file pdf1d_mixture_builder.cxx.
pdf1d_builder * pdf1d_mixture_builder::clone | ( | ) | const [virtual] |
Create a copy on the heap and return base class pointer.
Implements pdf1d_builder.
Definition at line 432 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::delete_stuff | ( | ) | [private] |
Definition at line 67 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::e_step | ( | pdf1d_mixture & | model, |
vcl_vector< vnl_vector< double > > & | probs, | ||
const double * | data, | ||
const vcl_vector< double > & | wts | ||
) | const [private] |
The Expectation part of the EM algorithm.
Definition at line 274 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::init | ( | ) | [private] |
Definition at line 23 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::init | ( | pdf1d_builder & | builder, |
int | n | ||
) |
Initialise n builders of type builder.
Clone taken of builder
Definition at line 84 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::initialise | ( | pdf1d_mixture & | model, |
const double * | data, | ||
const vcl_vector< double > & | wts | ||
) | const [private] |
Definition at line 226 of file pdf1d_mixture_builder.cxx.
vcl_string pdf1d_mixture_builder::is_a | ( | ) | const [virtual] |
Name of the class.
Reimplemented from pdf1d_builder.
Definition at line 411 of file pdf1d_mixture_builder.cxx.
bool pdf1d_mixture_builder::is_class | ( | vcl_string const & | s | ) | const [virtual] |
Does the name of the class match the argument?.
Reimplemented from pdf1d_builder.
Definition at line 418 of file pdf1d_mixture_builder.cxx.
double pdf1d_mixture_builder::m_step | ( | pdf1d_mixture & | model, |
const vcl_vector< vnl_vector< double > > & | probs, | ||
const double * | data, | ||
const vcl_vector< double > & | wts | ||
) | const [private] |
The Maximisation part of the EM algorithm.
Definition at line 332 of file pdf1d_mixture_builder.cxx.
double pdf1d_mixture_builder::min_var | ( | ) | const [virtual] |
Get lower threshold on variance for built models.
Implements pdf1d_builder.
Definition at line 130 of file pdf1d_mixture_builder.cxx.
pdf1d_pdf * pdf1d_mixture_builder::new_model | ( | ) | const [virtual] |
Create empty model.
Implements pdf1d_builder.
Definition at line 109 of file pdf1d_mixture_builder.cxx.
vcl_string pdf1d_mixture_builder::new_model_type | ( | ) | const [virtual] |
Name of the model class returned by new_model().
Implements pdf1d_builder.
Definition at line 114 of file pdf1d_mixture_builder.cxx.
pdf1d_mixture_builder & pdf1d_mixture_builder::operator= | ( | const pdf1d_mixture_builder & | b | ) |
Copy operator.
Definition at line 47 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
Print class to os.
Implements pdf1d_builder.
Definition at line 439 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::set_max_iterations | ( | int | n | ) |
Define maximum number of EM iterations allowed.
Definition at line 95 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::set_min_var | ( | double | min_var | ) | [virtual] |
Define lower threshold on variance for built models.
Implements pdf1d_builder.
Definition at line 122 of file pdf1d_mixture_builder.cxx.
void pdf1d_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 101 of file pdf1d_mixture_builder.cxx.
short pdf1d_mixture_builder::version_no | ( | ) | const |
Version number for I/O.
Reimplemented from pdf1d_builder.
Definition at line 425 of file pdf1d_mixture_builder.cxx.
void pdf1d_mixture_builder::weighted_build | ( | pdf1d_pdf & | model, |
mbl_data_wrapper< 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 pdf1d_builder.
Definition at line 158 of file pdf1d_mixture_builder.cxx.
bool pdf1d_mixture_builder::weights_fixed | ( | ) | const [inline] |
Whether weights on components left unchanged during iterations.
Definition at line 69 of file pdf1d_mixture_builder.h.
vcl_vector<pdf1d_builder*> pdf1d_mixture_builder::builder_ [private] |
Definition at line 22 of file pdf1d_mixture_builder.h.
int pdf1d_mixture_builder::max_its_ [private] |
Definition at line 24 of file pdf1d_mixture_builder.h.
double pdf1d_mixture_builder::min_var_ [private] |
Definition at line 23 of file pdf1d_mixture_builder.h.
bool pdf1d_mixture_builder::weights_fixed_ [private] |
Whether weights changed during iterations.
Definition at line 27 of file pdf1d_mixture_builder.h.