|
|
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)
|
|
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)
|
|
|
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
|
| 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)
|
| 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) |
| 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
|
|
|
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())
|
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).
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 >.
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
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.