Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > Class Template Reference

Linear (Fisher/Gaussian shared-covariance) discriminant classifier. More...

#include <classifier_lda.hpp>

Inheritance diagram for FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >:
FST::Clonable_Impl< Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >, Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > FST::Clonable

Public Types

typedef Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > parent
 the abstract base type
typedef Clonable_Impl< Classifier_LDA, parent > parent_impl
 implements clone() via the copy-constructor below
typedef std::shared_ptr< DATAACCESSOR > PDataAccessor
 shared pointer to the data accessor supplying train/test blocks
typedef std::shared_ptr< SUBSET > PSubset
 shared pointer to the feature subset being trained/classified on
typedef DATAACCESSOR::PPattern PPattern
 one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
Public Types inherited from FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >
typedef std::shared_ptr< DATAACCESSOR > PDataAccessor
 shared pointer to the data accessor supplying train/test blocks
typedef std::shared_ptr< SUBSET > const PSubset
 shared pointer to the (fixed, non-reassignable) feature subset being evaluated
typedef DATAACCESSOR::PPattern PPattern
 one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)

Public Member Functions

void initialize (const PDataAccessor da)
 Pre-allocates model and matrix buffers and records the class/feature counts of da. Must be called before the first train(); throws fst_error when da has fewer than 2 classes.
virtual bool classify (DIMTYPE &cls, const PPattern &pattern) override
virtual bool classify_scores (std::vector< RETURNTYPE > &scores, const PPattern &pattern) override
virtual bool train (const PDataAccessor da, const PSubset sub) override
 Learns per-class Gaussian parameters on the designated training part, pools the per-class covariances (weighted by the class priors) into one within-class covariance, inverts it once through the shared Indexed_Matrix LU machinery, and derives the closed-form linear discriminants a_c, b_c (see class doc).
virtual std::ostream & print (std::ostream &os) const override
 writes a human-readable identification of the object; base default writes nothing
Public Member Functions inherited from FST::Clonable_Impl< Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >, Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > >
Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * clone () const override
 dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * sharing_clone () const override
 dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * stateless_clone () const override
 dispatches to the STATELESS_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Public Member Functions inherited from FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >
virtual bool train (const PDataAccessor da, const PSubset sub)=0
 learns from designated training part of data
virtual bool test (RETURNTYPE &result, const PDataAccessor da)
virtual bool test_confusion (std::vector< RETURNTYPE > &confusion, DIMTYPE &classes, const PDataAccessor da)
virtual bool test_scores (std::vector< std::pair< RETURNTYPE, DIMTYPE > > &scores, const PDataAccessor da)
virtual bool test_scores_matrix (std::vector< RETURNTYPE > &scores, std::vector< DIMTYPE > &labels, DIMTYPE &classes, const PDataAccessor da)
virtual bool test_metric (RETURNTYPE &result, const PDataAccessor da, const Metric_Spec< RETURNTYPE > &spec)
Public Member Functions inherited from FST::Clonable
bool is_clone () const
bool is_sharing () const
 true if this instance is a sharing_clone() result (referencing, not owning, the source's structures)
bool is_sharing_clone () const
 true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result, not a clone()/stateless_clone() one

Protected Attributes

std::unique_ptr< Model_Normal< DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > _model
 per-class means/covariances (learned by train(), see Model_Normal)
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _LUtemp
 LU scratch (lazy allocation).
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _pooled
 pooled within-class covariance
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _pooledinv
 its inverse
DIMTYPE _classes
 number of classes, as recorded by initialize()
DIMTYPE _features
 raw (full) feature count, as recorded by initialize()
DIMTYPE _subfeatures
 d = current subset size
std::vector< DIMTYPE > _index
 subset position -> raw feature index (first d entries valid)
std::vector< RETURNTYPE > _cs_sc
 classify() score scratch (member to avoid per-pattern allocation)
std::vector< REALTYPE > _a
 classes x d discriminant directions, row-major
std::vector< REALTYPE > _b
 classes discriminant offsets
std::vector< REALTYPE > _m
 d-entry centering point of the discriminants: the prior-weighted mean of the class means (see train())

Private Member Functions

 Classifier_LDA (const Classifier_LDA &cld)
 Deep-copies the learned model and the pooled-covariance matrices (LU scratch, pooled covariance, its inverse); the discriminant vectors _a/_b and _index copy by value.

Private Attributes

friend parent_impl

Additional Inherited Members

Protected Member Functions inherited from FST::Clonable
void set_cloned (const bool cloned=true)
 marks/unmarks this instance as a clone; call from clone()/stateless_clone() overrides (Clonable_Impl does this automatically)
void set_sharing (const bool sharing=true)
 marks/unmarks this instance as sharing (see is_sharing())
void set_sharing_cloned (const bool cloned=true, const bool sharing=true)
 sets both flags at once; call from sharing_clone() overrides (Clonable_Impl does this automatically)

Detailed Description

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
class FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >

Linear (Fisher/Gaussian shared-covariance) discriminant classifier.

The pooled within-class covariance (per-class Model_Normal covariances weighted by the class priors) yields the closed-form linear discriminants delta_c(x) = a_c^T x + b_c with a_c = S_pooled^{-1} mu_c and b_c = -1/2 mu_c^T a_c + log P(c). Deterministic and RNG-free; the single matrix inverse goes through the same Indexed_Matrix LU machinery as the normal-model filters and the normal Bayes classifier — including the optional Eigen-backed path (FST4_USE_EIGEN), which stays in parity.

Complements gmahalanobis (a two-class filter) and Classifier_Normal_Bayes (per-class covariances, QDA-like): one shared covariance = linear boundaries, K classes supported, roughly K times cheaper per training than the Bayes classifier at equal subset size (one inverse, not K). classify_scores() exposes the discriminants (log-posteriors up to a shared shift; computed in centered form relative to the prior-weighted mean of the class means, so a large common feature offset costs no digits) for the ranking metrics (AUC); they are uncalibrated - monotone in the posterior, but neither probabilities nor comparable across trainings. Like the other normal-model components, it fails on singular pooled covariance (e.g. constant features or subset size exceeding the sample count).

Member Function Documentation

◆ classify()

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
bool FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::classify ( DIMTYPE & cls,
const PPattern & pattern )
overridevirtual

Classifies one pattern; on success cls receives the predicted class index (0-based, in [0,classes)). Returns false when no decision can be made at all - the model has not been trained, or the implementation hit an unrecoverable condition; false is not a "reject" option and aborts the enclosing test loop.

Implements FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.

◆ classify_scores()

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
bool FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::classify_scores ( std::vector< RETURNTYPE > & scores,
const PPattern & pattern )
overridevirtual

per-class real scores for one pattern (any monotone transform of the class posteriors); enables ranking-based metrics (AUC). Default: not supported.

Reimplemented from FST::Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.

◆ print()

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
virtual std::ostream & FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::print ( std::ostream & os) const
inlineoverridevirtual

writes a human-readable identification of the object; base default writes nothing

Reimplemented from FST::Clonable.

◆ train()

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
bool FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::train ( const PDataAccessor da,
const PSubset sub )
overridevirtual

Learns per-class Gaussian parameters on the designated training part, pools the per-class covariances (weighted by the class priors) into one within-class covariance, inverts it once through the shared Indexed_Matrix LU machinery, and derives the closed-form linear discriminants a_c, b_c (see class doc).

Precondition
initialize() has been called for a data accessor with the same class and feature counts as da.
Returns
false if the pooled covariance is singular (any resulting discriminant coefficient is non-finite); true otherwise.

Member Data Documentation

◆ parent_impl

template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
friend FST::Classifier_LDA< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::parent_impl
private

grants Clonable_Impl access to the copy-constructor


The documentation for this class was generated from the following file:
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.