Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
vpdfl_pc_gaussian Class Reference

Multi-variate principal Component Gaussian PDF. More...

#include <vpdfl_pc_gaussian.h>

Inheritance diagram for vpdfl_pc_gaussian:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 vpdfl_pc_gaussian ()
 Dflt ctor.
virtual ~vpdfl_pc_gaussian ()
 Destructor.
unsigned n_principal_components () const
 Number of principal components.
virtual vpdfl_sampler_basesampler () const
 Return sampler object for this PDF.
const vpdfl_pc_gaussian_builderpartition_chooser () const
 how the inherited set() function chooses the partition.
void set_partition_chooser (const vpdfl_pc_gaussian_builder *)
 Set the how the inherited set() function chooses the partition.
void set (const vnl_vector< double > &mean, const vnl_matrix< double > &evecs, const vnl_vector< double > &evals, double complementEVal)
 Initialise safely.
virtual void set (const vnl_vector< double > &mean, const vnl_matrix< double > &evecs, const vnl_vector< double > &evals)
 Initialise safely as you would a vpdfl_gaussian.
double log_k_principal () const
 log of normalisation constant for Gaussian.
void get_distances (double &mahalDIFS, double &euclidDFFS, const vnl_vector< double > &x) const
 Return Mahalanobis and Euclidean distances from centroid to input.
double log_p (const vnl_vector< double > &x) const
 Calculate the log probability density at position x.
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_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.
void set (const vnl_vector< double > &mean, const vnl_vector< double > &variance, const vnl_matrix< double > &evecs, const vnl_vector< double > &evals)
 Initialise.
void set (const vnl_vector< double > &mean, const vnl_matrix< double > &covar, double min_eval=1e-6)
 Initialise from mean and covariance matrix.
void set_mean (const vnl_vector< double > &mean)
 Modify just the mean of the distribution.
const vnl_matrix< double > & eigenvecs () const
 Eigenvectors of covariance matrix.
const vnl_vector< double > & eigenvals () const
 Eigenvalues of covariance matrix.
vnl_matrix< double > covariance () const
 The Covariance matrix of the Gaussian.
double log_k () const
 log of normalisation constant for gaussian.
virtual vpdfl_sampler_basenew_sampler () const
 Create a sampler object on the heap.
virtual void gradient (vnl_vector< double > &g, const vnl_vector< double > &x, double &p) const
 Gradient of PDF at x.
virtual double log_prob_thresh (double pass_proportion) const
 Compute threshold for PDF to pass a given proportion.
virtual void nearest_plausible (vnl_vector< double > &x, double log_p_min) const
 Compute nearest point to x which has a density above a threshold.
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 double operator() (const vnl_vector< double > &x) const
 Probability density at x.
virtual void gradient_logp (vnl_vector< double > &g, const vnl_vector< double > &x) const
 Gradient and value of log(p(x)) at x.
virtual bool is_valid_pdf () const
 Return true if the object represents a valid PDF.

Protected Member Functions

void set_variance (const vnl_vector< double > &v)

Protected Attributes

vnl_vector< double > dx_
 Workspace.
vnl_vector< double > b_
 Workspace.

Private Member Functions

void calcPartLogK ()
 Pre-calculate log_k_principal_.

Private Attributes

unsigned partition_
 The number of dimensions to have full Covariance (i.e. elliptical shape).
double log_k_principal_
 The constant when calculating the Mahalanobis dist in the principal space.
vpdfl_pc_gaussian_builderpartition_chooser_
 How the inherited set() function chooses the partition.

Detailed Description

Multi-variate principal Component Gaussian PDF.

The principal components can have general covariance. The complementary components (least significant eigenvalues) have a spherical distribution.

Definition at line 29 of file vpdfl_pc_gaussian.h.


Constructor & Destructor Documentation

vpdfl_pc_gaussian::vpdfl_pc_gaussian ( )

Dflt ctor.

Definition at line 31 of file vpdfl_pc_gaussian.cxx.

vpdfl_pc_gaussian::~vpdfl_pc_gaussian ( ) [virtual]

Destructor.

Definition at line 38 of file vpdfl_pc_gaussian.cxx.


Member Function Documentation

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

Load class from binary file stream.

Reimplemented from vpdfl_gaussian.

Definition at line 275 of file vpdfl_pc_gaussian.cxx.

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

Save class to binary file stream.

Reimplemented from vpdfl_gaussian.

Definition at line 263 of file vpdfl_pc_gaussian.cxx.

void vpdfl_pc_gaussian::calcPartLogK ( ) [private]

Pre-calculate log_k_principal_.

Pre-calculate the constant needed when evaluating Mahalanobis Distance.

Should only be called after setting all other data values.

Definition at line 128 of file vpdfl_pc_gaussian.cxx.

vpdfl_pdf_base * vpdfl_pc_gaussian::clone ( ) const [virtual]

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

Reimplemented from vpdfl_gaussian.

Definition at line 243 of file vpdfl_pc_gaussian.cxx.

vnl_matrix< double > vpdfl_gaussian::covariance ( ) const [inherited]

The Covariance matrix of the Gaussian.

This value is calculated on the fly each time so calling this function may not be very efficient

Definition at line 180 of file vpdfl_gaussian.cxx.

const vnl_vector<double>& vpdfl_gaussian::eigenvals ( ) const [inline, inherited]

Eigenvalues of covariance matrix.

The list is ordered - largest Eigenvalues first.

Definition at line 89 of file vpdfl_gaussian.h.

const vnl_matrix<double>& vpdfl_gaussian::eigenvecs ( ) const [inline, inherited]

Eigenvectors of covariance matrix.

List ordering corresponds to eVals();

Definition at line 85 of file vpdfl_gaussian.h.

void vpdfl_pc_gaussian::get_distances ( double &  mahalDIFS,
double &  euclidDFFS,
const vnl_vector< double > &  x 
) const

Return Mahalanobis and Euclidean distances from centroid to input.

Strictly it is the normalised Mahalanobis distance (-log_p()) from the input projected into the principal space to the centroid, and the Euclidean distance from the input to the input projected into the principal space. Also, the two values are the squares of the distances.

Definition at line 71 of file vpdfl_pc_gaussian.cxx.

void vpdfl_gaussian::gradient ( vnl_vector< double > &  g,
const vnl_vector< double > &  x,
double &  p 
) const [virtual, inherited]

Gradient of PDF at x.

Implements vpdfl_pdf_base.

Definition at line 242 of file vpdfl_gaussian.cxx.

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.

vcl_string vpdfl_pc_gaussian::is_a ( ) const [virtual]

Name of the class.

Reimplemented from vpdfl_gaussian.

Definition at line 222 of file vpdfl_pc_gaussian.cxx.

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

Does the name of the class match the argument?.

Reimplemented from vpdfl_gaussian.

Definition at line 229 of file vpdfl_pc_gaussian.cxx.

bool vpdfl_pdf_base::is_valid_pdf ( ) const [virtual, inherited]

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 in vpdfl_mixture.

Definition at line 141 of file vpdfl_pdf_base.cxx.

double vpdfl_gaussian::log_k ( ) const [inline, inherited]

log of normalisation constant for gaussian.

Definition at line 97 of file vpdfl_gaussian.h.

double vpdfl_pc_gaussian::log_k_principal ( ) const [inline]

log of normalisation constant for Gaussian.

Definition at line 93 of file vpdfl_pc_gaussian.h.

double vpdfl_pc_gaussian::log_p ( const vnl_vector< double > &  x) const [virtual]

Calculate the log probability density at position x.

You could use vpdfl_gaussian::log_p() which would give the same answer, but this method, only rotates into the principal components, not the entire rotated space, so saving considerable time.

Reimplemented from vpdfl_gaussian.

Definition at line 49 of file vpdfl_pc_gaussian.cxx.

double vpdfl_gaussian::log_prob_thresh ( double  pass_proportion) const [virtual, inherited]

Compute threshold for PDF to pass a given proportion.

Reimplemented from vpdfl_pdf_base.

Definition at line 281 of file vpdfl_gaussian.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.

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_pc_gaussian::n_principal_components ( ) const [inline]

Number of principal components.

i.e. the number of dimensions to have full Covariance (i.e. elliptical shape)

Definition at line 56 of file vpdfl_pc_gaussian.h.

void vpdfl_gaussian::nearest_plausible ( vnl_vector< double > &  x,
double  log_p_min 
) const [virtual, inherited]

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 directly towards the mean (i.e. to the nearest plausible point using a Mahalanobis distance) until log_p(x)=log_p_min.

Parameters:
xThis may be modified to the nearest plausible position.
log_p_minlower threshold for log_p(x)

Implements vpdfl_pdf_base.

Definition at line 290 of file vpdfl_gaussian.cxx.

vpdfl_sampler_base * vpdfl_gaussian::new_sampler ( ) const [virtual, inherited]

Create a sampler object on the heap.

Caller is responsible for deletion.

Implements vpdfl_pdf_base.

Definition at line 189 of file vpdfl_gaussian.cxx.

double vpdfl_pdf_base::operator() ( const vnl_vector< double > &  x) const [virtual, inherited]

Probability density at x.

Reimplemented in vpdfl_mixture, and vpdfl_gaussian_kernel_pdf.

Definition at line 34 of file vpdfl_pdf_base.cxx.

const vpdfl_pc_gaussian_builder * vpdfl_pc_gaussian::partition_chooser ( ) const

how the inherited set() function chooses the partition.

Definition at line 321 of file vpdfl_pc_gaussian.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_pc_gaussian::print_summary ( vcl_ostream &  os) const [virtual]

Print class to os.

Reimplemented from vpdfl_gaussian.

Definition at line 250 of file vpdfl_pc_gaussian.cxx.

vpdfl_sampler_base * vpdfl_pc_gaussian::sampler ( ) const [virtual]

Return sampler object for this PDF.

Return instance of this PDF.

Object is created on heap. Caller responsible for deletion. The sampler object is a vpdfl_gaussian_sampler. There is no vpdfl_pc_gaussian_sampler.

Definition at line 213 of file vpdfl_pc_gaussian.cxx.

void vpdfl_gaussian::set ( const vnl_vector< double > &  mean,
const vnl_vector< double > &  variance,
const vnl_matrix< double > &  evecs,
const vnl_vector< double > &  evals 
) [inherited]

Initialise.

WARNING - the error checking for inconsistent parameters is not foolproof.

Definition at line 128 of file vpdfl_gaussian.cxx.

void vpdfl_gaussian::set ( const vnl_vector< double > &  mean,
const vnl_matrix< double > &  covar,
double  min_eval = 1e-6 
) [inherited]

Initialise from mean and covariance matrix.

Note, eigenvectors computed from covar, and those corresponding to evals smaller than min_eval are truncated

This functions should only be used by builders.

Note, eigenvectors computed from covar, and those corresponding to evals smaller than min_eval are truncated

Definition at line 154 of file vpdfl_gaussian.cxx.

void vpdfl_pc_gaussian::set ( const vnl_vector< double > &  mean,
const vnl_matrix< double > &  evecs,
const vnl_vector< double > &  evals,
double  complementEVal 
)

Initialise safely.

The partition between principal components space and complementary space is defined by the length of the Eigenvalues vector (evals.) Calculates the variance, and checks that the Eigenvalues are ordered and the Eigenvectors are unit normal Turn off assertions to remove error checking.

Definition at line 146 of file vpdfl_pc_gaussian.cxx.

void vpdfl_pc_gaussian::set ( const vnl_vector< double > &  mean,
const vnl_matrix< double > &  evecs,
const vnl_vector< double > &  evals 
) [virtual]

Initialise safely as you would a vpdfl_gaussian.

Calculates the variance, and checks that the Eigenvalues are ordered and the Eigenvectors are unit normal Turn off assertions to remove error checking. This function takes a fully specified set of Eigenvectors and Eigenvalues, and truncates the principal space as defined in partition_chooser() which must not be null.

Calculates the variance, and checks that the Eigenvalues are ordered and the Eigenvectors are unit normal Turn off assertions to remove error checking.

Reimplemented from vpdfl_gaussian.

Definition at line 181 of file vpdfl_pc_gaussian.cxx.

void vpdfl_gaussian::set_mean ( const vnl_vector< double > &  mean) [inherited]

Modify just the mean of the distribution.

This functions should only be used by builders.

Reimplemented from vpdfl_pdf_base.

Definition at line 144 of file vpdfl_gaussian.cxx.

void vpdfl_pc_gaussian::set_partition_chooser ( const vpdfl_pc_gaussian_builder partition_chooser)

Set the how the inherited set() function chooses the partition.

If not NULL, a local copy of the builder will be taken.

Definition at line 328 of file vpdfl_pc_gaussian.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_pc_gaussian::version_no ( ) const

Version number for I/O.

Reimplemented from vpdfl_gaussian.

Definition at line 236 of file vpdfl_pc_gaussian.cxx.


Member Data Documentation

vnl_vector<double> vpdfl_gaussian::b_ [mutable, protected, inherited]

Workspace.

Usually the input vector after normalisation.

Definition at line 41 of file vpdfl_gaussian.h.

vnl_vector<double> vpdfl_gaussian::dx_ [mutable, protected, inherited]

Workspace.

The difference between an input vector and the mean

Definition at line 38 of file vpdfl_gaussian.h.

The constant when calculating the Mahalanobis dist in the principal space.

Definition at line 36 of file vpdfl_pc_gaussian.h.

unsigned vpdfl_pc_gaussian::partition_ [private]

The number of dimensions to have full Covariance (i.e. elliptical shape).

The rest are assumed spherical

Definition at line 33 of file vpdfl_pc_gaussian.h.

How the inherited set() function chooses the partition.

If NULL, set(const vnl_vector<double>&,const vnl_matrix<double>& evecs,const vnl_vector<double>&) will fail.

Definition at line 45 of file vpdfl_pc_gaussian.h.


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