1#ifndef FSTCRITERIONNORMALBHATTACHARYYA_H
2#define FSTCRITERIONNORMALBHATTACHARYYA_H
104template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
105class Criterion_Normal_Bhattacharyya :
public Clonable_Impl<Criterion_Normal_Bhattacharyya<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>,Criterion_Normal<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR> > {
111 Criterion_Normal_Bhattacharyya() {
notify(
"Criterion_Normal_Bhattacharyya constructor.");}
115 virtual const char*
criterion_name()
const override {
return "Criterion_Normal_Bhattacharyya";}
131 Criterion_Normal_Bhattacharyya(
const Criterion_Normal_Bhattacharyya& cnb);
133 std::unique_ptr<Indexed_Matrix<DATATYPE,DIMTYPE,SUBSET> >
_cov12;
134 std::unique_ptr<Indexed_Matrix<DATATYPE,DIMTYPE,SUBSET> >
_cov12_div2;
135 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> >
_invbuf;
136 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> >
_LUtemp;
139template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
140Criterion_Normal_Bhattacharyya<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Criterion_Normal_Bhattacharyya(
const Criterion_Normal_Bhattacharyya& cnb) :
143 notify(
"Criterion_Normal_Bhattacharyya copy-constructor.");
150template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
153 notify(
"Criterion_Normal_Bhattacharyya::evaluate_narrowed().");
163 RETURNTYPE logdet1,logdet2,logdet3;
193 if(!std::isfinite(logdet1) || !std::isfinite(logdet2))
194 throw FST::fst_error(
"Criterion_Normal_Bhattacharyya::evaluate: singular class covariance matrix on the evaluated subset (zero determinant)");
195 RETURNTYPE right=0.5*(logdet3-0.5*(logdet1+logdet2));
208 result=0.25*left+right;
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
Implements Bhattacharyya distance based on normal (gaussian) model to serve as feature selection crit...
Definition criterion_normal_bhattacharyya.hpp:105
std::unique_ptr< Indexed_Matrix< DATATYPE, DIMTYPE, SUBSET > > _cov12
(cov[0]+cov[1]), computed by update_derived_model()
Definition criterion_normal_bhattacharyya.hpp:133
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _LUtemp
scratch LU-decomposition storage, reused for each matrix inversion/determinant
Definition criterion_normal_bhattacharyya.hpp:136
virtual const char * criterion_name() const override
class name, used in output and error messages
Definition criterion_normal_bhattacharyya.hpp:115
Criterion_Normal< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > parent
base class: the normal-model template-method skeleton
Definition criterion_normal_bhattacharyya.hpp:107
virtual void allocate_buffers() override
(re)allocate criterion-specific work buffers for get_n() features (use the alloc_* helpers)
Definition criterion_normal_bhattacharyya.hpp:116
std::shared_ptr< SUBSET > PSubset
shared pointer to the feature subset being evaluated
Definition criterion_normal_bhattacharyya.hpp:110
virtual void update_derived_model() override
Definition criterion_normal_bhattacharyya.hpp:122
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _invbuf
inverse of the narrowed _cov12, used in the quadratic-form term
Definition criterion_normal_bhattacharyya.hpp:135
Clonable_Impl< Criterion_Normal_Bhattacharyya, parent > parent_impl
implements clone(); sharing/stateless_clone throw in Criterion
Definition criterion_normal_bhattacharyya.hpp:108
std::unique_ptr< Indexed_Matrix< DATATYPE, DIMTYPE, SUBSET > > _cov12_div2
_cov12/2, the pooled covariance whose determinant enters the Bhattacharyya distance
Definition criterion_normal_bhattacharyya.hpp:134
std::shared_ptr< DATAACCESSOR > PDataAccessor
shared pointer to the data accessor the model is learned from
Definition criterion_normal_bhattacharyya.hpp:109
virtual bool evaluate_narrowed(RETURNTYPE &result, const PSubset sub) override
narrow remaining buffers to sub, redim work buffers to get_d(), compute the criterion value....
Definition criterion_normal_bhattacharyya.hpp:151
Abstract class, defines interface for feature selection criterion implementations based on normal mod...
Definition criterion_normal.hpp:100
std::unique_ptr< Model_Normal< DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > > _model
the learned per-class normal (mean/covariance) model, narrowed in evaluate()
Definition criterion_normal.hpp:149
void alloc_matrix(std::unique_ptr< Indexed_Matrix< MATRIXVALUETYPE, DIMTYPE, SUBSET > > &m, const bool LUstorage=false)
lazy (re)allocation of a work matrix for get_n() features; LUstorage as required by Indexed_Matrix::L...
Definition criterion_normal.hpp:144
DIMTYPE get_n() const
the full (raw, unnarrowed) feature count the model was learned for
Definition criterion_normal.hpp:119
std::unique_ptr< Indexed_Vector< DATATYPE, DIMTYPE, SUBSET > > _meandif
mean[0]-mean[1], shared by all two-class normal criteria
Definition criterion_normal.hpp:150
DIMTYPE get_d() const
the currently active (narrowed) feature count, see evaluate()
Definition criterion_normal.hpp:120
Matrix representation and operations, allows operation in selected subspace.
Definition indexed_matrix.hpp:102
FST4 specific error passing class.
Definition error.hpp:61
Defines interface for feature selection criterion implementations based on normal model.
FST4 specific error passing class.
Matrix representation and operations, allows operation in selected subspace.
Vector representation and operations, allows operation in selected subspace.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112