|
|
typedef Clonable_Impl< Classifier_Normal_Bayes, Classifier< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > | parent_impl |
| | implements clone(); sharing/stateless_clone throw in Classifier
|
|
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 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 | enable_prelearn_mode (const PDataAccessor da) |
|
void | disable_prelearn_mode () |
| | reverts to the default: learn a new model in every train() call
|
|
bool | get_prelearn_mode () const |
| | true if pre-learn mode is active (see enable_prelearn_mode())
|
| void | initialize (const PDataAccessor da) |
| | (Re)allocates the per-class inverse-covariance, determinant, constant, posterior and log-domain-fallback buffers, sized to da's class/feature counts.
|
| 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 from designated training part of data
|
| virtual bool | test (RETURNTYPE &result, const PDataAccessor da) override |
|
DIMTYPE | get_n () const |
| | "full feature set" dimensionality the model was learned at (see Model_Normal::get_n())
|
|
DIMTYPE | get_d () const |
| | dimensionality currently exposed by the model (see Model_Normal::get_d())
|
| 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 | 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 |
| | the underlying normal (Gaussian) model supplying per-class mean/covariance
|
|
DIMTYPE | _classes |
| | number of classes; sizes the per-class arrays below
|
|
DIMTYPE | _features |
| | raw (full) feature count
|
|
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > | _LUtemp |
| | shared LU-decomposition scratch matrix, reused across classes in train()
|
|
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET >[]> | _inverse |
| | per-class inverse covariance matrix (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _det |
| | per-class covariance determinant (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _constant |
| | per-class normalizing constant sqrt((2*pi)^d * _det[c]) (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _pxw |
| | per-class likelihood p(x|class), cached by classify() (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _Pwx |
| | per-class posterior P(class|x), cached by classify()/classify_scores() (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _log_constant |
| | ln of _constant, computed without forming _constant itself, for the log-domain fallback in classify() (lazy allocation)
|
|
std::unique_ptr< REALTYPE[]> | _ecoef |
| | per-class Mahalanobis terms buffered for the fallback (lazy allocation)
|
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
class FST::Classifier_Normal_Bayes< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >
Implements Bayes classifier based on normal (gaussian) model.
Each class is modelled by its own mean vector and its own covariance matrix (the model is Model_Normal), so the decision boundaries are quadratic – this is the QDA-style classifier; Classifier_LDA is the pooled-covariance, linear-boundary sibling. A pattern is assigned to the class of maximum posterior P(class|x), computed from the Gaussian densities and the class priors of the model.
- Note
- Classifier_Normal_Bayes should be able to handle _model learning in two ways: either [default] to learn() new subspace model in each train() - usable with FS involving multiple DataAccessor training splits, or to pre-learn() full space model and subsequently only narrow() the model in each train() - much faster, but usable only with non-changing set of training patterns, i.e., for one split data access only
- Warning
- Pre-learn mode must stay DISABLED (the default) when this classifier is driven by Criterion_Wrapper: the wrapper changes the training split between train() calls, and a pre-learned model would keep describing the data of the split it was learned on, silently returning optimistic and meaningless accuracies.
- Note
- Every class needs enough patterns for a non-singular covariance matrix of the evaluated subset (more patterns than features, and no exactly dependent features). A singular covariance makes the LU decomposition throw, which the criterion reports as a failed evaluation of that subset.
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
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>
| virtual bool FST::Classifier_Normal_Bayes< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR >::classify_scores |
( |
std::vector< RETURNTYPE > & | scores, |
|
|
const PPattern & | pattern ) |
|
inlineoverridevirtual |
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
pre-learning mode: if true, calls once _model->learn() for full set size and later in train() uses only narrow()ing to access submatrixes (makes sense only as long as training data do not change, i.e., within one split) if false (default), learns new model in each train() call
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
(Re)allocates the per-class inverse-covariance, determinant, constant, posterior and log-domain-fallback buffers, sized to da's class/feature counts.
- Note
- initialize() does NOT itself learn mean[]/cov[] – that happens in enable_prelearn_mode() (once) or in every train() call (default, non-prelearn mode). Must be called once whenever the training set's class/feature shape changes, before train()/test().
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>
| virtual std::ostream & FST::Classifier_Normal_Bayes< 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.
template<class RETURNTYPE, typename DATATYPE, typename REALTYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR>