Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
mcal_pca Class Reference

Class to perform Principle Component Analysis. More...

#include <mcal_pca.h>

Inheritance diagram for mcal_pca:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 mcal_pca ()
 Dflt ctor.
virtual ~mcal_pca ()
 Destructor.
void set_mode_choice (unsigned min, unsigned max, double var_proportion)
 Define limits on number of parameters to use in model.
void set_min_modes (unsigned min)
 Set the choice for the minimum number of model.
unsigned min_modes () const
 Current lower limit on number of parameters.
void set_max_modes (unsigned max)
 Define upper limit on number of parameters.
unsigned max_modes () const
 Current upper limit on number of parameters.
virtual void set_var_prop (double v)
 Define proportion of data variance to explain.
virtual double var_prop () const
 Current proportion of data variance to explain.
void set_max_d_in_memory (double max_n)
 Max number of doubles allowed in memory.
double max_d_in_memory () const
 Max number of doubles allowed in memory.
void set_use_chunks (bool chunks)
 Set whether we may build in chunks if required.
bool use_chunks () const
 Indicate whether to use chunks if required.
virtual void build_about_mean (mbl_data_wrapper< vnl_vector< double > > &data, const vnl_vector< double > &mean, vnl_matrix< double > &modes, vnl_vector< double > &mode_var)
 Compute modes of the supplied data relative to the supplied mean.
short version_no () const
 Version number for I/O.
virtual vcl_string is_a () const
 Name of the class.
virtual mcal_component_analyzerclone () 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.
void compute_mean (mbl_data_wrapper< vnl_vector< double > > &data, vnl_vector< double > &mean)
 Compute the mean of the supplied data.
virtual void build (mbl_data_wrapper< vnl_vector< double > > &data, vnl_vector< double > &mean, vnl_matrix< double > &modes, vnl_vector< double > &mode_var)
 Compute mean and modes from the supplied data.
virtual void build_from_array (const vnl_vector< double > *data, int n, vnl_vector< double > &mean, vnl_matrix< double > &modes, vnl_vector< double > &mode_var)
 Build mean and modes from data in array data[0..n-1].

Static Public Member Functions

static vcl_auto_ptr
< mcal_component_analyzer
create_from_stream (vcl_istream &is)
 Create a concrete mcal_component_analyzer object, from a text specification.

Private Member Functions

unsigned choose_n_modes (const vnl_vector< double > &evals)
 Return the number of modes to retain.
void fillDDt (vnl_matrix< double > &DDt, const vnl_matrix< double > &A, int rlo, int rhi, int clo, int chi)
 Utility function.
void build_evecs_nd_smaller (mbl_data_wrapper< vnl_vector< double > > &data, const vnl_vector< double > &mean, vnl_matrix< double > &evecs, vnl_vector< double > &evals)
 Compute eigenvectors assuming fewer dimensions than samples.
void build_evecs_ns_smaller (mbl_data_wrapper< vnl_vector< double > > &data, const vnl_vector< double > &mean, vnl_matrix< double > &evecs, vnl_vector< double > &evals)
 Compute eigenvectors assuming fewer samples than dimensions.

Private Attributes

double var_prop_
 Define how many modes to use.
unsigned int min_modes_
unsigned int max_modes_
double max_d_in_memory_
 Max number of doubles allowed in memory.
bool use_chunks_
 Whether to use chunks if required.

Detailed Description

Class to perform Principle Component Analysis.

Applies a PCA to compute mean, variance and eigenvectors/values of covariance matrix of supplied data.

Definition at line 17 of file mcal_pca.h.


Constructor & Destructor Documentation

mcal_pca::mcal_pca ( )

Dflt ctor.

Definition at line 24 of file mcal_pca.cxx.

mcal_pca::~mcal_pca ( ) [virtual]

Destructor.

Definition at line 38 of file mcal_pca.cxx.


Member Function Documentation

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

Load class from binary file stream.

Implements mcal_component_analyzer.

Definition at line 502 of file mcal_pca.cxx.

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

Save class to binary file stream.

Implements mcal_component_analyzer.

Definition at line 488 of file mcal_pca.cxx.

void mcal_component_analyzer::build ( mbl_data_wrapper< vnl_vector< double > > &  data,
vnl_vector< double > &  mean,
vnl_matrix< double > &  modes,
vnl_vector< double > &  mode_var 
) [virtual, inherited]

Compute mean and modes from the supplied data.

Model is x = mean + modes*b, where b is a vector of weights on each mode. mode_var[i] gives the variance of the data projected onto that mode. Default computes the mean, then calls build_about_mean

Computes the mean, then calls build_about_mean

Definition at line 41 of file mcal_component_analyzer.cxx.

void mcal_pca::build_about_mean ( mbl_data_wrapper< vnl_vector< double > > &  data,
const vnl_vector< double > &  mean,
vnl_matrix< double > &  modes,
vnl_vector< double > &  mode_var 
) [virtual]

Compute modes of the supplied data relative to the supplied mean.

Model is x = mean + modes*b, where b is a vector of weights on each mode. mode_var[i] gives the variance of the data projected onto that mode.

Implements mcal_component_analyzer.

Definition at line 411 of file mcal_pca.cxx.

void mcal_pca::build_evecs_nd_smaller ( mbl_data_wrapper< vnl_vector< double > > &  data,
const vnl_vector< double > &  mean,
vnl_matrix< double > &  evecs,
vnl_vector< double > &  evals 
) [private]

Compute eigenvectors assuming fewer dimensions than samples.

Definition at line 86 of file mcal_pca.cxx.

void mcal_pca::build_evecs_ns_smaller ( mbl_data_wrapper< vnl_vector< double > > &  data,
const vnl_vector< double > &  mean,
vnl_matrix< double > &  evecs,
vnl_vector< double > &  evals 
) [private]

Compute eigenvectors assuming fewer samples than dimensions.

Definition at line 146 of file mcal_pca.cxx.

void mcal_component_analyzer::build_from_array ( const vnl_vector< double > *  data,
int  n,
vnl_vector< double > &  mean,
vnl_matrix< double > &  modes,
vnl_vector< double > &  mode_var 
) [virtual, inherited]

Build mean and modes from data in array data[0..n-1].

Utility function - wraps data and uses build(data,mean,modes)

Definition at line 51 of file mcal_component_analyzer.cxx.

unsigned mcal_pca::choose_n_modes ( const vnl_vector< double > &  evals) [private]

Return the number of modes to retain.

Definition at line 44 of file mcal_pca.cxx.

mcal_component_analyzer * mcal_pca::clone ( ) const [virtual]

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

Implements mcal_component_analyzer.

Definition at line 465 of file mcal_pca.cxx.

void mcal_component_analyzer::compute_mean ( mbl_data_wrapper< vnl_vector< double > > &  data,
vnl_vector< double > &  mean 
) [inherited]

Compute the mean of the supplied data.

Definition at line 25 of file mcal_component_analyzer.cxx.

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

Read initialisation settings from a stream.

Parameters:

   {
     min_modes: 0 max_modes: 99 var_prop: 0.99
     // Maximum number of doubles to store in memory at once
     max_d_in_memory: 1e8
     // Indicate how to build from large amounts of data
     use_chunks: false
   }
   
Exceptions:
mbl_exception_parse_errorif the parse fails.

Parameters:

   {
     min_modes: 0 max_modes: 99 prop_modes: 0.99
     // Maximum number of doubles to store in memory at once
     max_d_in_memory: 1e8
     // Indicate how to build from large amounts of data
     use_chunks: false
   }
   
Exceptions:
mbl_exception_parse_errorif the parse fails.

Reimplemented from mcal_component_analyzer.

Definition at line 535 of file mcal_pca.cxx.

vcl_auto_ptr< mcal_component_analyzer > mcal_component_analyzer::create_from_stream ( vcl_istream &  is) [static, inherited]

Create a concrete mcal_component_analyzer object, from a text specification.

Definition at line 84 of file mcal_component_analyzer.cxx.

void mcal_pca::fillDDt ( vnl_matrix< double > &  DDt,
const vnl_matrix< double > &  A,
int  rlo,
int  rhi,
int  clo,
int  chi 
) [private]

Utility function.

Support function for chunks.

Definition at line 334 of file mcal_pca.cxx.

vcl_string mcal_pca::is_a ( ) const [virtual]

Name of the class.

Implements mcal_component_analyzer.

Definition at line 447 of file mcal_pca.cxx.

double mcal_pca::max_d_in_memory ( ) const [inline]

Max number of doubles allowed in memory.

Definition at line 82 of file mcal_pca.h.

unsigned mcal_pca::max_modes ( ) const

Current upper limit on number of parameters.

Definition at line 380 of file mcal_pca.cxx.

unsigned mcal_pca::min_modes ( ) const

Current lower limit on number of parameters.

Definition at line 368 of file mcal_pca.cxx.

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

Print class to os.

Implements mcal_component_analyzer.

Definition at line 474 of file mcal_pca.cxx.

void mcal_pca::set_max_d_in_memory ( double  max_n)

Max number of doubles allowed in memory.

Definition at line 397 of file mcal_pca.cxx.

void mcal_pca::set_max_modes ( unsigned  max)

Define upper limit on number of parameters.

Definition at line 373 of file mcal_pca.cxx.

void mcal_pca::set_min_modes ( unsigned  min)

Set the choice for the minimum number of model.

Definition at line 361 of file mcal_pca.cxx.

void mcal_pca::set_mode_choice ( unsigned  min,
unsigned  max,
double  var_proportion 
)

Define limits on number of parameters to use in model.

Parameters:
var_proportionProportion of variance in data to explain

Definition at line 352 of file mcal_pca.cxx.

void mcal_pca::set_use_chunks ( bool  chunks)

Set whether we may build in chunks if required.

Definition at line 403 of file mcal_pca.cxx.

void mcal_pca::set_var_prop ( double  v) [virtual]

Define proportion of data variance to explain.

Definition at line 386 of file mcal_pca.cxx.

bool mcal_pca::use_chunks ( ) const [inline]

Indicate whether to use chunks if required.

Definition at line 88 of file mcal_pca.h.

double mcal_pca::var_prop ( ) const [virtual]

Current proportion of data variance to explain.

Definition at line 392 of file mcal_pca.cxx.

short mcal_pca::version_no ( ) const

Version number for I/O.

Reimplemented from mcal_component_analyzer.

Definition at line 456 of file mcal_pca.cxx.


Member Data Documentation

double mcal_pca::max_d_in_memory_ [private]

Max number of doubles allowed in memory.

Definition at line 44 of file mcal_pca.h.

unsigned int mcal_pca::max_modes_ [private]

Definition at line 22 of file mcal_pca.h.

unsigned int mcal_pca::min_modes_ [private]

Definition at line 22 of file mcal_pca.h.

bool mcal_pca::use_chunks_ [private]

Whether to use chunks if required.

Definition at line 47 of file mcal_pca.h.

double mcal_pca::var_prop_ [private]

Define how many modes to use.

Definition at line 21 of file mcal_pca.h.


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