Represents a mixture model (a set of individual pdfs + weights). More...
#include <vpdfl_mixture.h>
Public Member Functions | |
vpdfl_mixture () | |
Dflt ctor. | |
vpdfl_mixture (const vpdfl_mixture &) | |
Copy ctor. | |
vpdfl_mixture & | operator= (const vpdfl_mixture &) |
Copy operator. | |
virtual | ~vpdfl_mixture () |
Destructor. | |
virtual double | operator() (const vnl_vector< double > &x) const |
Probability density at x. | |
virtual double | log_p (const vnl_vector< double > &x) const |
Log of probability density at x. | |
virtual void | gradient (vnl_vector< double > &g, const vnl_vector< double > &x, double &p) const |
Gradient of PDF at x. | |
virtual void | nearest_plausible (vnl_vector< double > &x, double log_p_min) const |
Not Yet Implemented. | |
void | init (const vpdfl_pdf_base &comp_type, unsigned n) |
Initialise to use n components of type comp_type. | |
virtual vpdfl_sampler_base * | new_sampler () const |
Return instance object for this PDF. | |
unsigned | n_components () const |
Number of components in mixture. | |
double | weight (unsigned i) const |
Get ith weight. | |
const vcl_vector< double > & | weights () const |
Array of weights. | |
vcl_vector< double > & | weights () |
Array of weights. | |
unsigned | nearest_comp (const vnl_vector< double > &x) const |
Return index of component nearest to x. | |
void | set (const vcl_vector< vpdfl_pdf_base * > components, const vcl_vector< double > &weights) |
Set the contents of the mixture model. | |
void | add_component (const vpdfl_pdf_base &comp) |
Add a component to current model. | |
void | clear () |
Remove all components cleanly. | |
const vpdfl_pdf_base & | component (unsigned i) const |
Get ith component. | |
vcl_vector< vpdfl_pdf_base * > & | components () |
Access to components - for use by builders. | |
const vcl_vector < vpdfl_pdf_base * > & | components () const |
Access to components - for use by builders. | |
void | set_mean_and_variance (vnl_vector< double > &m, vnl_vector< double > &v) |
Set the whole pdf mean and variance values. | |
virtual bool | is_valid_pdf () const |
Return true if the object represents a valid PDF. | |
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_pdf_base * | 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. | |
const vnl_vector< double > & | mean () const |
Mean of distribution. | |
const vnl_vector< double > & | variance () const |
Variance of each dimension. | |
int | n_dims () const |
Number of dimensions. | |
virtual int | n_peaks () const |
Number of peaks of distribution. | |
virtual const vnl_vector < double > & | peak (int) const |
Position of the i'th peak. | |
virtual void | gradient_logp (vnl_vector< double > &g, const vnl_vector< double > &x) const |
Gradient and value of log(p(x)) at x. | |
virtual double | log_prob_thresh (double pass_proportion) const |
Compute threshold for PDF to pass a given proportion. | |
Protected Member Functions | |
void | set_mean (const vnl_vector< double > &m) |
void | set_variance (const vnl_vector< double > &v) |
Private Member Functions | |
void | delete_stuff () |
Private Attributes | |
vcl_vector< vpdfl_pdf_base * > | component_ |
vcl_vector< double > | weight_ |
vnl_vector< double > | ws_ |
Workspace so we don't have to keep creating vectors. |
Represents a mixture model (a set of individual pdfs + weights).
Definition at line 25 of file vpdfl_mixture.h.
vpdfl_mixture::vpdfl_mixture | ( | ) |
Dflt ctor.
Definition at line 31 of file vpdfl_mixture.cxx.
vpdfl_mixture::vpdfl_mixture | ( | const vpdfl_mixture & | m | ) |
Copy ctor.
Definition at line 35 of file vpdfl_mixture.cxx.
vpdfl_mixture::~vpdfl_mixture | ( | ) | [virtual] |
Destructor.
Definition at line 70 of file vpdfl_mixture.cxx.
void vpdfl_mixture::add_component | ( | const vpdfl_pdf_base & | comp | ) |
Add a component to current model.
Clone taken of comp
Definition at line 164 of file vpdfl_mixture.cxx.
void vpdfl_mixture::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Implements vpdfl_pdf_base.
Definition at line 278 of file vpdfl_mixture.cxx.
void vpdfl_mixture::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Implements vpdfl_pdf_base.
Definition at line 267 of file vpdfl_mixture.cxx.
void vpdfl_mixture::clear | ( | ) |
Remove all components cleanly.
Definition at line 186 of file vpdfl_mixture.cxx.
vpdfl_pdf_base * vpdfl_mixture::clone | ( | ) | const [virtual] |
Create a copy on the heap and return base class pointer.
Implements vpdfl_pdf_base.
Definition at line 246 of file vpdfl_mixture.cxx.
const vpdfl_pdf_base& vpdfl_mixture::component | ( | unsigned | i | ) | const [inline] |
Get ith component.
Definition at line 104 of file vpdfl_mixture.h.
vcl_vector<vpdfl_pdf_base*>& vpdfl_mixture::components | ( | ) | [inline] |
Access to components - for use by builders.
Care must be taken to ensure consistency when modifying Use component(i) where possible
Definition at line 109 of file vpdfl_mixture.h.
const vcl_vector<vpdfl_pdf_base*>& vpdfl_mixture::components | ( | ) | const [inline] |
Access to components - for use by builders.
Use component(i) where possible
Definition at line 113 of file vpdfl_mixture.h.
void vpdfl_mixture::delete_stuff | ( | ) | [private] |
Definition at line 61 of file vpdfl_mixture.cxx.
void vpdfl_mixture::gradient | ( | vnl_vector< double > & | g, |
const vnl_vector< double > & | x, | ||
double & | p | ||
) | const [virtual] |
void vpdfl_pdf_base::gradient_logp | ( | vnl_vector< double > & | g, |
const vnl_vector< double > & | x | ||
) | const [virtual, inherited] |
Gradient and value of log(p(x)) at x.
Gradient of log(p(x)) at x.
Computes gradient df/dx of f(x)=log(p(x)) at x. Result is vector of same dimensionality as x. Default baseclass implementation uses gradient() to compute grad/p
Computes gradient df/dx of f(x)=log(p(x)) at x. Default baseclass implementation uses gradient() to compute grad/p
Reimplemented in vpdfl_axis_gaussian.
Definition at line 127 of file vpdfl_pdf_base.cxx.
void vpdfl_mixture::init | ( | const vpdfl_pdf_base & | comp_type, |
unsigned | n | ||
) |
Initialise to use n components of type comp_type.
Clones taken by comp_type
Definition at line 87 of file vpdfl_mixture.cxx.
vcl_string vpdfl_mixture::is_a | ( | ) | const [virtual] |
Name of the class.
Reimplemented from vpdfl_pdf_base.
Definition at line 225 of file vpdfl_mixture.cxx.
bool vpdfl_mixture::is_class | ( | vcl_string const & | s | ) | const [virtual] |
Does the name of the class match the argument?.
Reimplemented from vpdfl_pdf_base.
Definition at line 232 of file vpdfl_mixture.cxx.
bool vpdfl_mixture::is_valid_pdf | ( | ) | const [virtual] |
Return true if the object represents a valid PDF.
This will return false, if n_dims() is 0, for example just ofter default construction.
Reimplemented from vpdfl_pdf_base.
Definition at line 196 of file vpdfl_mixture.cxx.
double vpdfl_mixture::log_p | ( | const vnl_vector< double > & | x | ) | const [virtual] |
Log of probability density at x.
Implements vpdfl_pdf_base.
Definition at line 321 of file vpdfl_mixture.cxx.
double vpdfl_pdf_base::log_prob_thresh | ( | double | pass_proportion | ) | const [virtual, inherited] |
Compute threshold for PDF to pass a given proportion.
Reimplemented in vpdfl_gaussian, and vpdfl_axis_gaussian.
Definition at line 40 of file vpdfl_pdf_base.cxx.
const vnl_vector<double>& vpdfl_pdf_base::mean | ( | ) | const [inline, inherited] |
Mean of distribution.
Definition at line 46 of file vpdfl_pdf_base.h.
unsigned vpdfl_mixture::n_components | ( | ) | const [inline] |
Number of components in mixture.
Definition at line 75 of file vpdfl_mixture.h.
int vpdfl_pdf_base::n_dims | ( | ) | const [inline, inherited] |
Number of dimensions.
Definition at line 52 of file vpdfl_pdf_base.h.
virtual int vpdfl_pdf_base::n_peaks | ( | ) | const [inline, virtual, inherited] |
Number of peaks of distribution.
Definition at line 55 of file vpdfl_pdf_base.h.
unsigned vpdfl_mixture::nearest_comp | ( | const vnl_vector< double > & | x | ) | const |
Return index of component nearest to x.
Definition at line 373 of file vpdfl_mixture.cxx.
void vpdfl_mixture::nearest_plausible | ( | vnl_vector< double > & | x, |
double | log_p_min | ||
) | const [virtual] |
Not Yet Implemented.
Compute nearest point to x which has a density above a threshold.
Compute nearest point to x which has a density above a threshold If log_p(x)>log_p_min then x unchanged. Otherwise x is moved (typically up the gradient) until log_p(x)>=log_p_min.
x | This may be modified to the nearest plausible position. |
log_p_min | lower threshold for log_p(x) |
If log_p(x)>log_p_min then x unchanged. Otherwise x is moved (typically up the gradient) until log_p(x)>=log_p_min.
x | This may be modified to the nearest plausible position. |
Implements vpdfl_pdf_base.
Definition at line 402 of file vpdfl_mixture.cxx.
vpdfl_sampler_base * vpdfl_mixture::new_sampler | ( | ) | const [virtual] |
Return instance object for this PDF.
Return instance of this PDF.
Object is created on heap. Caller responsible for deletion.
Implements vpdfl_pdf_base.
Definition at line 77 of file vpdfl_mixture.cxx.
double vpdfl_mixture::operator() | ( | const vnl_vector< double > & | x | ) | const [virtual] |
Probability density at x.
Reimplemented from vpdfl_pdf_base.
Definition at line 314 of file vpdfl_mixture.cxx.
vpdfl_mixture & vpdfl_mixture::operator= | ( | const vpdfl_mixture & | m | ) |
Copy operator.
Definition at line 41 of file vpdfl_mixture.cxx.
virtual const vnl_vector<double>& vpdfl_pdf_base::peak | ( | int | ) | const [inline, virtual, inherited] |
Position of the i'th peak.
Definition at line 58 of file vpdfl_pdf_base.h.
void vpdfl_mixture::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
void vpdfl_mixture::set | ( | const vcl_vector< vpdfl_pdf_base * > | components, |
const vcl_vector< double > & | weights | ||
) |
Set the contents of the mixture model.
Clones are taken of all the data, and the class will be responsible for their deletion.
Definition at line 131 of file vpdfl_mixture.cxx.
void vpdfl_pdf_base::set_mean | ( | const vnl_vector< double > & | m | ) | [inline, protected, inherited] |
Reimplemented in vpdfl_gaussian.
Definition at line 35 of file vpdfl_pdf_base.h.
void vpdfl_mixture::set_mean_and_variance | ( | vnl_vector< double > & | m, |
vnl_vector< double > & | v | ||
) |
Set the whole pdf mean and variance values.
Components and Weights should already be correct so that the error checking can work. #define NDEBUG to turn off error checking.
Definition at line 216 of file vpdfl_mixture.cxx.
void vpdfl_pdf_base::set_variance | ( | const vnl_vector< double > & | v | ) | [inline, protected, inherited] |
Definition at line 36 of file vpdfl_pdf_base.h.
const vnl_vector<double>& vpdfl_pdf_base::variance | ( | ) | const [inline, inherited] |
Variance of each dimension.
Definition at line 49 of file vpdfl_pdf_base.h.
short vpdfl_mixture::version_no | ( | ) | const |
Version number for I/O.
Reimplemented from vpdfl_pdf_base.
Definition at line 239 of file vpdfl_mixture.cxx.
double vpdfl_mixture::weight | ( | unsigned | i | ) | const [inline] |
Get ith weight.
Definition at line 78 of file vpdfl_mixture.h.
const vcl_vector<double>& vpdfl_mixture::weights | ( | ) | const [inline] |
vcl_vector<double>& vpdfl_mixture::weights | ( | ) | [inline] |
Array of weights.
Warning care must be taken to ensure consistency when modifying weights Warning. Use weight(i) where possible
Definition at line 87 of file vpdfl_mixture.h.
vcl_vector<vpdfl_pdf_base*> vpdfl_mixture::component_ [private] |
Definition at line 27 of file vpdfl_mixture.h.
vcl_vector<double> vpdfl_mixture::weight_ [private] |
Definition at line 28 of file vpdfl_mixture.h.
vnl_vector<double> vpdfl_mixture::ws_ [mutable, private] |
Workspace so we don't have to keep creating vectors.
Definition at line 31 of file vpdfl_mixture.h.