Public Member Functions | Private Member Functions | Private Attributes
mbl_lda Class Reference

Class to perform linear discriminant analysis. More...

#include <mbl_lda.h>

List of all members.

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_

Detailed Description

Class to perform linear discriminant analysis.

Definition at line 23 of file mbl_lda.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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]

Basis for discriminant space.

Definition at line 165 of file mbl_lda.h.

const vnl_vector<double>& mbl_lda::basis_e_vals ( ) const [inline]

Eigenvalues associated with each basis vector.

Definition at line 168 of file mbl_lda.h.

const vnl_matrix<double>& mbl_lda::between_covar ( ) const [inline]

Between class covariance matrix.

Definition at line 162 of file mbl_lda.h.

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

Parameters:
labelArray [0..n-1] of integer indices. label[i] gives class of v[i]
nSize of label and of v
vSet of vectors [0..n-1]
wSWithin class covariance to use if compute_wS false
compute_wSThis boolean parameter determines whether to use wS
labelArray [0..n-1] of integers indices
vSet 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.

Parameters:
nNumber of examples
labelinteger indices
vSet of vectors [0..n-1]
  • label[i] gives class of v[i]
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
  • Classes must be labeled from 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.

Parameters:
labelArray [0..n-1] of integers indices
vSet of vectors [0..n-1]
  • label[i] gives class of v[i]
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
  • Classes must be labeled from 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.

Parameters:
labelArray [0..n-1] of integers indices
vSet of vectors [0..n-1]
wSWithin class covariance to use
  • label[i] gives class of v[i]
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
  • Classes must be labeled from 0..n-1

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.

Parameters:
labelArray [0..n-1] of integers indices
vSet of vectors [0..n-1]
  • label[i] gives class of v[i]
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
  • Classes must be labeled from 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.

Parameters:
labelArray [0..n-1] of integers indices
vSet of vectors [0..n-1]
wSWithin class covariance to use
  • label[i] gives class of v[i]
  • Classes must be labeled from 0..n-1
  • If label[i]<0 the class is assumed to be unknown and example i is ignored

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])
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
  • Note also that this is inefficient - it converts the matrix to an array and calls build(v,label)

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.

  • Columns of M form example vectors
  • i'th column belongs to class label(i)
  • Note: label([1..n]) not label([0..n-1])
  • Note also that this is inefficient - it converts the matrix to an array and calls build(v,label)
  • If label[i]<0 the class is assumed to be unknown and example i is ignored
    Parameters:
    MThe columns of this matrix for the example vectors
    labelThe vector of class labels corresponding to these examples
    wSWithin class covariance to use
    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 389 of file mbl_lda.cxx.

const vnl_vector<double>& mbl_lda::class_mean ( int  i) const [inline]

Mean vector for i'th class in original space.

Definition at line 150 of file mbl_lda.h.

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]

Mean vector for i'th class in discriminant space.

Definition at line 153 of file mbl_lda.h.

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]

Mean of means for each class.

Definition at line 156 of file mbl_lda.h.

int mbl_lda::n_classes ( ) const [inline]

Number of classes.

Definition at line 144 of file mbl_lda.h.

int mbl_lda::n_samples ( int  i) const [inline]

Number of examples of each class.

Definition at line 147 of file mbl_lda.h.

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]

Within class covariance matrix.

Definition at line 159 of file mbl_lda.h.

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.


Member Data Documentation

vnl_matrix<double> mbl_lda::basis_ [private]

Definition at line 33 of file mbl_lda.h.

vnl_matrix<double> mbl_lda::betweenS_ [private]

Definition at line 32 of file mbl_lda.h.

vnl_vector<double> mbl_lda::d_m_mean_ [private]

Definition at line 35 of file mbl_lda.h.

vcl_vector<vnl_vector<double> > mbl_lda::d_mean_ [private]

Definition at line 28 of file mbl_lda.h.

vnl_vector<double> mbl_lda::evals_ [private]

Definition at line 34 of file mbl_lda.h.

vcl_vector<vnl_vector<double> > mbl_lda::mean_ [private]

Definition at line 27 of file mbl_lda.h.

Definition at line 29 of file mbl_lda.h.

vcl_vector<int> mbl_lda::n_samples_ [private]

Definition at line 30 of file mbl_lda.h.

vnl_matrix<double> mbl_lda::withinS_ [private]

Definition at line 31 of file mbl_lda.h.


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