shark::LDA Class Reference

Linear Discriminant Analysis (LDA) More...

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

+ Inheritance diagram for shark::LDA:

Public Member Functions

 LDA (double regularization=0.0)
 constructor More...
 
std::string name () const
 From INameable: return the class name. More...
 
double regularization () const
 return the regularization constant More...
 
void setRegularization (double regularization)
 set the regularization constant. 0 means no regularization. More...
 
RealVector parameterVector () const
 inherited from IParameterizable; read the regularization parameter More...
 
void setParameterVector (RealVector const &param)
 inherited from IParameterizable; set the regularization parameter More...
 
size_t numberOfParameters () const
 inherited from IParameterizable More...
 
SHARK_EXPORT_SYMBOL void train (LinearClassifier<> &model, LabeledData< RealVector, unsigned int > const &dataset)
 Compute the LDA solution for a multi-class problem. More...
 
SHARK_EXPORT_SYMBOL void train (LinearClassifier<> &model, WeightedLabeledData< RealVector, unsigned int > const &dataset)
 Compute the LDA solution for a weighted multi-class problem. More...
 
- Public Member Functions inherited from shark::AbstractWeightedTrainer< LinearClassifier<>, unsigned int >
virtual void train (ModelType &model, WeightedDatasetType const &dataset)=0
 Executes the algorithm and trains a model on the given weighted data. More...
 
virtual void train (ModelType &model, DatasetType const &dataset)
 Executes the algorithm and trains a model on the given unweighted data. 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 ()
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 

Protected Attributes

double m_regularization
 

Additional Inherited Members

- Public Types inherited from shark::AbstractWeightedTrainer< LinearClassifier<>, unsigned int >
typedef base_type::ModelType ModelType
 
typedef base_type::InputType InputType
 
typedef base_type::LabelType LabelType
 
typedef base_type::DatasetType DatasetType
 
typedef WeightedLabeledData< InputType, LabelTypeWeightedDatasetType
 
- Public Types inherited from shark::AbstractTrainer< LinearClassifier<>, unsigned int >
typedef LinearClassifier<> ModelType
 
typedef ModelType::InputType InputType
 
typedef unsigned int LabelType
 
typedef LabeledData< InputType, LabelTypeDatasetType
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Detailed Description

Linear Discriminant Analysis (LDA)

This classes implements the well known linear discriminant analysis. LDA assumes that every point is drawn from a multivariate normal distributions. Every class has its own mean but all classes have the same covariance.

An arbitrary number of classes is supported. The resulting model is of the form

\[ \arg \max_c \log(p(x|c)*P(c)) \]

where \( p(x|c) = \exp(-(x-m_c)^T(C+\alpha I)(x-m_c)) \). \( m_c\) are the means of class c, \( C \) is the covariance matrix formed by all data points. The regularization paramter \( \alpha \) is by default 0. The trainer is implemented such, that it still works when C is singular, in this case the singular directions are ignored.

Definition at line 58 of file LDA.h.

Constructor & Destructor Documentation

◆ LDA()

shark::LDA::LDA ( double  regularization = 0.0)
inline

constructor

Definition at line 62 of file LDA.h.

References regularization(), and setRegularization().

Member Function Documentation

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 67 of file LDA.h.

Referenced by main().

◆ numberOfParameters()

size_t shark::LDA::numberOfParameters ( ) const
inlinevirtual

inherited from IParameterizable

Reimplemented from shark::IParameterizable<>.

Definition at line 93 of file LDA.h.

References SHARK_EXPORT_SYMBOL, and train().

◆ parameterVector()

RealVector shark::LDA::parameterVector ( ) const
inlinevirtual

inherited from IParameterizable; read the regularization parameter

Reimplemented from shark::IParameterizable<>.

Definition at line 82 of file LDA.h.

References m_regularization.

◆ regularization()

double shark::LDA::regularization ( ) const
inline

return the regularization constant

Definition at line 71 of file LDA.h.

References m_regularization.

Referenced by LDA(), and setRegularization().

◆ setParameterVector()

void shark::LDA::setParameterVector ( RealVector const &  param)
inlinevirtual

inherited from IParameterizable; set the regularization parameter

Reimplemented from shark::IParameterizable<>.

Definition at line 88 of file LDA.h.

References m_regularization, and SIZE_CHECK.

◆ setRegularization()

void shark::LDA::setRegularization ( double  regularization)
inline

set the regularization constant. 0 means no regularization.

Definition at line 76 of file LDA.h.

References m_regularization, RANGE_CHECK, and regularization().

Referenced by LDA().

◆ train() [1/2]

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

Compute the LDA solution for a multi-class problem.

Referenced by main(), and numberOfParameters().

◆ train() [2/2]

SHARK_EXPORT_SYMBOL void shark::LDA::train ( LinearClassifier<> &  model,
WeightedLabeledData< RealVector, unsigned int > const &  dataset 
)

Compute the LDA solution for a weighted multi-class problem.

Member Data Documentation

◆ m_regularization

double shark::LDA::m_regularization
protected

The regularization parameter \( \lambda \) adds \( - \lambda I \) to the second moment matrix, where \( I \) is the identity matrix

Definition at line 106 of file LDA.h.

Referenced by parameterVector(), regularization(), setParameterVector(), and setRegularization().


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