Class to perform linear discriminant analysis. More...
#include <mbl_lda.h>
Public Member Functions | |
mbl_lda () | |
Dflt ctor. | |
virtual | ~mbl_lda () |
Destructor. | |
bool | operator== (const mbl_lda &that) const |
Comparison. | |
int | classify (const vnl_vector< double > &x) const |
Classify a new data point. | |
void | build (const vnl_vector< double > *v, const int *label, int n) |
Perform LDA on data. | |
void | build (const vnl_vector< double > *v, const vcl_vector< int > &label) |
Perform LDA on data. | |
void | build (const vnl_vector< double > *v, const vcl_vector< int > &label, const vnl_matrix< double > &wS) |
Perform LDA on data. | |
void | build (const vcl_vector< vnl_vector< double > > &v, const vcl_vector< int > &label) |
Perform LDA on data. | |
void | build (const vcl_vector< vnl_vector< double > > &v, const vcl_vector< int > &label, const vnl_matrix< double > &wS) |
Perform LDA on data. | |
void | build (const vnl_matrix< double > &M, const vcl_vector< int > &label) |
Perform LDA on data. | |
void | build (const vnl_matrix< double > &M, const vcl_vector< int > &label, const vnl_matrix< double > &wS) |
Perform LDA on data. | |
int | n_classes () const |
Number of classes. | |
int | n_samples (int i) const |
Number of examples of each class. | |
const vnl_vector< double > & | class_mean (int i) const |
Mean vector for i'th class in original space. | |
const vnl_vector< double > & | d_class_mean (int i) const |
Mean vector for i'th class in discriminant space. | |
const vnl_vector< double > & | mean_class_mean () const |
Mean of means for each class. | |
const vnl_matrix< double > & | within_covar () const |
Within class covariance matrix. | |
const vnl_matrix< double > & | between_covar () const |
Between class covariance matrix. | |
const vnl_matrix< double > & | basis () const |
Basis for discriminant space. | |
const vnl_vector< double > & | basis_e_vals () const |
Eigenvalues associated with each basis vector. | |
void | x_to_d (vnl_vector< double > &d, const vnl_vector< double > &x) const |
Project x into discriminant space. | |
void | d_to_x (vnl_vector< double > &x, const vnl_vector< double > &d) const |
Project d from discriminant space into original space. | |
int | nDistinctIDs (const int *id, const int n) |
find out how many id in the label vector. | |
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 |
True if this is (or is derived from) class named s. | |
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. | |
Private Member Functions | |
void | updateCovar (vnl_matrix< double > &S, const vnl_vector< double > &v) |
void | build (const vnl_vector< double > *v, const int *label, int n, const vnl_matrix< double > &wS, bool compute_wS) |
Perform LDA on data. | |
Private Attributes | |
vcl_vector< vnl_vector< double > > | mean_ |
vcl_vector< vnl_vector< double > > | d_mean_ |
vnl_vector< double > | mean_class_mean_ |
vcl_vector< int > | n_samples_ |
vnl_matrix< double > | withinS_ |
vnl_matrix< double > | betweenS_ |
vnl_matrix< double > | basis_ |
vnl_vector< double > | evals_ |
vnl_vector< double > | d_m_mean_ |
mbl_lda::mbl_lda | ( | ) |
Dflt ctor.
Definition at line 40 of file mbl_lda.cxx.
mbl_lda::~mbl_lda | ( | ) | [virtual] |
Destructor.
Definition at line 46 of file mbl_lda.cxx.
void mbl_lda::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Definition at line 478 of file mbl_lda.cxx.
void mbl_lda::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Definition at line 462 of file mbl_lda.cxx.
const vnl_matrix<double>& mbl_lda::basis | ( | ) | const [inline] |
const vnl_vector<double>& mbl_lda::basis_e_vals | ( | ) | const [inline] |
const vnl_matrix<double>& mbl_lda::between_covar | ( | ) | const [inline] |
void mbl_lda::build | ( | const vnl_vector< double > * | v, |
const int * | label, | ||
int | n, | ||
const vnl_matrix< double > & | wS, | ||
bool | compute_wS | ||
) | [private] |
Perform LDA on data.
Classes must be labeled from 0..n-1
label | Array [0..n-1] of integer indices. label[i] gives class of v[i] |
n | Size of label and of v |
v | Set of vectors [0..n-1] |
wS | Within class covariance to use if compute_wS false |
compute_wS | This boolean parameter determines whether to use wS |
label | Array [0..n-1] of integers indices |
v | Set of vectors [0..n-1] |
label[i] gives class of v[i] Classes must be labeled from 0 to m-1
Definition at line 130 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vnl_vector< double > * | v, |
const int * | label, | ||
int | n | ||
) |
Perform LDA on data.
n | Number of examples |
label | integer indices |
v | Set of vectors [0..n-1] |
Definition at line 329 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vnl_vector< double > * | v, |
const vcl_vector< int > & | label | ||
) |
Perform LDA on data.
label | Array [0..n-1] of integers indices |
v | Set of vectors [0..n-1] |
Definition at line 336 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vnl_vector< double > * | v, |
const vcl_vector< int > & | label, | ||
const vnl_matrix< double > & | wS | ||
) |
Perform LDA on data.
label | Array [0..n-1] of integers indices |
v | Set of vectors [0..n-1] |
wS | Within class covariance to use |
Definition at line 343 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vcl_vector< vnl_vector< double > > & | v, |
const vcl_vector< int > & | label | ||
) |
Perform LDA on data.
label | Array [0..n-1] of integers indices |
v | Set of vectors [0..n-1] |
Definition at line 351 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vcl_vector< vnl_vector< double > > & | v, |
const vcl_vector< int > & | label, | ||
const vnl_matrix< double > & | wS | ||
) |
Perform LDA on data.
label | Array [0..n-1] of integers indices |
v | Set of vectors [0..n-1] |
wS | Within class covariance to use |
Definition at line 359 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vnl_matrix< double > & | M, |
const vcl_vector< int > & | label | ||
) |
Perform LDA on data.
Columns of M form example vectors i'th column belongs to class label[i] Note: label([1..n]) not label([0..n-1])
Definition at line 371 of file mbl_lda.cxx.
void mbl_lda::build | ( | const vnl_matrix< double > & | M, |
const vcl_vector< int > & | label, | ||
const vnl_matrix< double > & | wS | ||
) |
Perform LDA on data.
M | The columns of this matrix for the example vectors |
label | The vector of class labels corresponding to these examples |
wS | Within class covariance to use |
Definition at line 389 of file mbl_lda.cxx.
const vnl_vector<double>& mbl_lda::class_mean | ( | int | i | ) | const [inline] |
int mbl_lda::classify | ( | const vnl_vector< double > & | x | ) | const |
Classify a new data point.
projects into discriminant space and picks closest mean class vector
Projects into discriminant space and picks closest mean class vector
Definition at line 54 of file mbl_lda.cxx.
const vnl_vector<double>& mbl_lda::d_class_mean | ( | int | i | ) | const [inline] |
void mbl_lda::d_to_x | ( | vnl_vector< double > & | x, |
const vnl_vector< double > & | d | ||
) | const |
Project d from discriminant space into original space.
Definition at line 415 of file mbl_lda.cxx.
vcl_string mbl_lda::is_a | ( | ) | const [virtual] |
Name of the class.
Definition at line 430 of file mbl_lda.cxx.
bool mbl_lda::is_class | ( | vcl_string const & | s | ) | const [virtual] |
True if this is (or is derived from) class named s.
Definition at line 435 of file mbl_lda.cxx.
const vnl_vector<double>& mbl_lda::mean_class_mean | ( | ) | const [inline] |
int mbl_lda::n_classes | ( | ) | const [inline] |
int mbl_lda::n_samples | ( | int | i | ) | const [inline] |
int mbl_lda::nDistinctIDs | ( | const int * | id, |
const int | n | ||
) |
find out how many id in the label vector.
Definition at line 110 of file mbl_lda.cxx.
bool mbl_lda::operator== | ( | const mbl_lda & | that | ) | const |
Comparison.
Definition at line 72 of file mbl_lda.cxx.
void mbl_lda::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
Print class to os.
Definition at line 442 of file mbl_lda.cxx.
void mbl_lda::updateCovar | ( | vnl_matrix< double > & | S, |
const vnl_vector< double > & | v | ||
) | [private] |
Definition at line 87 of file mbl_lda.cxx.
short mbl_lda::version_no | ( | ) | const |
Version number for I/O.
Definition at line 423 of file mbl_lda.cxx.
const vnl_matrix<double>& mbl_lda::within_covar | ( | ) | const [inline] |
void mbl_lda::x_to_d | ( | vnl_vector< double > & | d, |
const vnl_vector< double > & | x | ||
) | const |
Project x into discriminant space.
Definition at line 406 of file mbl_lda.cxx.
vnl_matrix<double> mbl_lda::basis_ [private] |
vnl_matrix<double> mbl_lda::betweenS_ [private] |
vnl_vector<double> mbl_lda::d_m_mean_ [private] |
vcl_vector<vnl_vector<double> > mbl_lda::d_mean_ [private] |
vnl_vector<double> mbl_lda::evals_ [private] |
vcl_vector<vnl_vector<double> > mbl_lda::mean_ [private] |
vnl_vector<double> mbl_lda::mean_class_mean_ [private] |
vcl_vector<int> mbl_lda::n_samples_ [private] |
vnl_matrix<double> mbl_lda::withinS_ [private] |