Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR > Class Template Reference

Wraps Classifier objects to serve as feature selection criterion. More...

#include <criterion_wrapper.hpp>

Inheritance diagram for FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >:
FST::Clonable_Impl< Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >, Criterion< RETURNTYPE, SUBSET > > FST::Criterion< RETURNTYPE, SUBSET > FST::Clonable FST::Clonable_Impl< Criterion_Wrapper_Bias_Estimate< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >, Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR > > FST::Criterion_Wrapper_Bias_Estimate< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >

Public Types

typedef Clonable_Impl< Criterion_Wrapper, Criterion< RETURNTYPE, SUBSET > > parent_impl
 implements clone(); sharing/stateless_clone throw in Criterion
typedef std::shared_ptr< CLASSIFIER > PClassifier
 shared pointer to the wrapped classifier
typedef std::shared_ptr< DATAACCESSOR > PDataAccessor
 shared pointer to the data accessor supplying training/test splits
typedef std::shared_ptr< SUBSET > PSubset
 shared pointer to the feature subset being evaluated
Public Types inherited from FST::Criterion< RETURNTYPE, SUBSET >
typedef std::shared_ptr< SUBSET > PSubset
 shared pointer to the feature subset being evaluated

Public Member Functions

virtual void initialize (const PClassifier classifier, const PDataAccessor da)
 Stores the classifier and the data accessor to be used by every later evaluate(). Must be called before the first evaluate(). Both are kept by shared_ptr for the whole life cycle of *this; the accessor must already be initialized and must carry the split setting the evaluation is to run over. Clones take a clone of the classifier and a sharing clone of the accessor, so a threaded search never shares either instance.
virtual bool evaluate (RETURNTYPE &result, const PSubset sub) override
 Trains and tests the wrapped classifier on every split, returning the mean of the per-split values of the configured metric (plain accuracy by default; see set_metric()). Returns false when training fails on any split, or when the metric is undefined on all of them.
void set_metric (const Metric_Spec< RETURNTYPE > &spec)
const Metric_Spec< RETURNTYPE > & get_metric () const
 returns the currently configured wrapper metric (see set_metric())
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< Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >, Criterion< RETURNTYPE, SUBSET > >
Criterion< RETURNTYPE, SUBSET > * clone () const override
 dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
Criterion< RETURNTYPE, SUBSET > * sharing_clone () const override
 dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Criterion< RETURNTYPE, SUBSET > * 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::Criterion< RETURNTYPE, SUBSET >
virtual bool is_monotonic () const
Criterion * sharing_clone () const override
Criterion * stateless_clone () const override
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 Member Functions

 Criterion_Wrapper (const Criterion_Wrapper &cw)
 Copy-constructor; clones _classifier and sharing-clones _da, copies _metric_spec.
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)

Protected Attributes

friend parent_impl
std::shared_ptr< CLASSIFIER > _classifier
 the wrapped classifier trained then tested by evaluate()
std::shared_ptr< DATAACCESSOR > _da
 data accessor supplying the train/test splits
Metric_Spec< RETURNTYPE > _metric_spec
 configured wrapper metric; default = plain accuracy (see set_metric())

Detailed Description

template<class RETURNTYPE, class SUBSET, class CLASSIFIER, class DATAACCESSOR>
class FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >

Wraps Classifier objects to serve as feature selection criterion.

Each evaluate() call runs the full split protocol of the data accessor supplied to initialize(): for every split the wrapped classifier is trained on the TRAIN part and evaluated on the TEST part, and the criterion value is the MEAN of the per-split values. What is measured per split is the configured wrapper metric (see set_metric()); by default that is plain classification accuracy. All supported metrics are oriented so that higher is better, as FST4 searches maximize.

Examples
demo52t.cpp, and demo55.cpp.

Member Function Documentation

◆ evaluate()

template<class RETURNTYPE, class SUBSET, class CLASSIFIER, class DATAACCESSOR>
bool FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >::evaluate ( RETURNTYPE & result,
const PSubset sub )
overridevirtual

Trains and tests the wrapped classifier on every split, returning the mean of the per-split values of the configured metric (plain accuracy by default; see set_metric()). Returns false when training fails on any split, or when the metric is undefined on all of them.

Implements FST::Criterion< RETURNTYPE, SUBSET >.

Reimplemented in FST::Criterion_Wrapper_Bias_Estimate< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >.

◆ print()

template<class RETURNTYPE, class SUBSET, class CLASSIFIER, class DATAACCESSOR>
virtual std::ostream & FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >::print ( std::ostream & os) const
inlineoverridevirtual

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

Reimplemented from FST::Clonable.

Reimplemented in FST::Criterion_Wrapper_Bias_Estimate< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >.

◆ set_metric()

template<class RETURNTYPE, class SUBSET, class CLASSIFIER, class DATAACCESSOR>
void FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >::set_metric ( const Metric_Spec< RETURNTYPE > & spec)
inline

selects the wrapper metric (default: plain accuracy). The spec is immutable configuration, copied by clones - thread-safe, RNG-free.

Member Data Documentation

◆ parent_impl

template<class RETURNTYPE, class SUBSET, class CLASSIFIER, class DATAACCESSOR>
friend FST::Criterion_Wrapper< RETURNTYPE, SUBSET, CLASSIFIER, DATAACCESSOR >::parent_impl
protected

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.