shark::FisherLDA Class Reference

Fisher's Linear Discriminant Analysis for data compression. More...

#include <shark/Algorithms/Trainers/FisherLDA.h>

+ Inheritance diagram for shark::FisherLDA:

Public Member Functions

SHARK_EXPORT_SYMBOL FisherLDA (bool whitening=false, std::size_t subspaceDimension=0)
 Constructor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
void setSubspaceDimensions (std::size_t dimensions)
 
std::size_t subspaceDimensions () const
 
bool whitening () const
 check whether whitening mode is on More...
 
void setWhitening (bool newWhitening)
 if active, the model whitenes the inputs More...
 
SHARK_EXPORT_SYMBOL void train (LinearModel<> &model, LabeledData< RealVector, unsigned int > const &dataset)
 Compute the FisherLDA solution for a multi-class problem. More...
 
- Public Member Functions inherited from shark::AbstractTrainer< LinearModel<>, unsigned int >
virtual void train (ModelType &model, DatasetType const &dataset)=0
 Core of the Trainer interface. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
virtual void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
virtual void write (OutArchive &archive) const
 Write the component to the supplied archive. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Member Functions

SHARK_EXPORT_SYMBOL void meanAndScatter (LabeledData< RealVector, unsigned int > const &dataset, RealVector &mean, RealMatrix &scatter)
 

Protected Attributes

bool m_whitening
 
std::size_t m_subspaceDimensions
 

Additional Inherited Members

- Public Types inherited from shark::AbstractTrainer< LinearModel<>, unsigned int >
typedef LinearModel<> ModelType
 
typedef ModelType::InputType InputType
 
typedef unsigned int LabelType
 
typedef LabeledData< InputType, LabelTypeDatasetType
 

Detailed Description

Fisher's Linear Discriminant Analysis for data compression.

Similar to PCA, Fisher's Linear Discriminant Analysis is a method for reducing the datas dimensionality. In contrast to PCA it also uses class information.

Consider the data's covariance matrix \( S \) and a unit vector \( u \) which defines a one-dimensional subspace of the data. Then, PCA would maximmize the objective \( J(u) = u^T S u \), namely the datas variance in the subspace. Fisher-LDA, however, maximizes

\[ J(u) = ( u^T S_W u )^{-1} ( u^T S_B u ), \]

where \( S_B \) is the covariance matrix of the class-means and \( S_W \) is the average covariance matrix of all classes (in both cases, each class' influence is weighted by it's size). As a result, Fisher-LDA finds a subspace in which the class means are wide-spread while (in average) the variance of each class becomes small. This leads to good lower-dimensional representations of the data in cases where the classes are linearly separable.

If a subspace with more than one dimension is requested, the above step is executed consecutively to find the next optimal subspace-dimension orthogonally to the others.

Note: the max. dimensionality for the subspace is #NumOfClasses-1.

It is possible to choose how many dimnsions are used by setting the appropriate value by calling setSubspaceDImension or in the constructor. Also optionally whitening can be applied. For more detailed information about Fisher-LDA, see Bishop, Pattern Recognition and Machine Learning.

Definition at line 79 of file FisherLDA.h.

Constructor & Destructor Documentation

◆ FisherLDA()

SHARK_EXPORT_SYMBOL shark::FisherLDA::FisherLDA ( bool  whitening = false,
std::size_t  subspaceDimension = 0 
)

Constructor.

Member Function Documentation

◆ meanAndScatter()

SHARK_EXPORT_SYMBOL void shark::FisherLDA::meanAndScatter ( LabeledData< RealVector, unsigned int > const &  dataset,
RealVector &  mean,
RealMatrix &  scatter 
)
protected

Referenced by setWhitening().

◆ name()

std::string shark::FisherLDA::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 86 of file FisherLDA.h.

◆ setSubspaceDimensions()

void shark::FisherLDA::setSubspaceDimensions ( std::size_t  dimensions)
inline

Definition at line 89 of file FisherLDA.h.

References m_subspaceDimensions.

◆ setWhitening()

void shark::FisherLDA::setWhitening ( bool  newWhitening)
inline

if active, the model whitenes the inputs

Definition at line 103 of file FisherLDA.h.

References m_whitening, shark::mean(), meanAndScatter(), SHARK_EXPORT_SYMBOL, and train().

◆ subspaceDimensions()

std::size_t shark::FisherLDA::subspaceDimensions ( ) const
inline

Definition at line 93 of file FisherLDA.h.

References m_subspaceDimensions.

◆ train()

SHARK_EXPORT_SYMBOL void shark::FisherLDA::train ( LinearModel<> &  model,
LabeledData< RealVector, unsigned int > const &  dataset 
)

Compute the FisherLDA solution for a multi-class problem.

Referenced by setWhitening().

◆ whitening()

bool shark::FisherLDA::whitening ( ) const
inline

check whether whitening mode is on

Definition at line 98 of file FisherLDA.h.

References m_whitening.

Member Data Documentation

◆ m_subspaceDimensions

std::size_t shark::FisherLDA::m_subspaceDimensions
protected

Definition at line 113 of file FisherLDA.h.

Referenced by setSubspaceDimensions(), and subspaceDimensions().

◆ m_whitening

bool shark::FisherLDA::m_whitening
protected

Definition at line 112 of file FisherLDA.h.

Referenced by setWhitening(), and whitening().


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