1#ifndef FSTCRITERIONNORMALDIVERGENCE_H
2#define FSTCRITERIONNORMALDIVERGENCE_H
109template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
110class Criterion_Normal_Divergence :
public Clonable_Impl<Criterion_Normal_Divergence<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>,Criterion_Normal<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR> > {
116 Criterion_Normal_Divergence() {
notify(
"Criterion_Normal_Divergence constructor.");}
122 virtual const char*
criterion_name()
const override {
return "Criterion_Normal_Divergence";}
134 Criterion_Normal_Divergence(
const Criterion_Normal_Divergence& cnd);
136 std::unique_ptr<Indexed_Vector<DATATYPE,DIMTYPE,SUBSET> >
_diag;
137 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> >
_invbuf1;
138 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> >
_invbuf2;
139 std::unique_ptr<Indexed_Matrix<REALTYPE,DIMTYPE,SUBSET> >
_LUtemp;
142template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
143Criterion_Normal_Divergence<RETURNTYPE,DATATYPE,REALTYPE,IDXTYPE,DIMTYPE,SUBSET,DATAACCESSOR>::Criterion_Normal_Divergence(
const Criterion_Normal_Divergence& cnd) :
146 notify(
"Criterion_Normal_Divergence copy-constructor.");
155template<
class RETURNTYPE,
typename DATATYPE,
typename REALTYPE,
typename IDXTYPE,
typename DIMTYPE,
class SUBSET,
class DATAACCESSOR>
158 notify(
"Criterion_Normal_Divergence::evaluate_narrowed().");
192 RETURNTYPE right=0.0;
195 _diag->at_raw(i)=0.0;
212 result=0.5*left+0.5*right;
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
Implements Divergence (distance) based on normal (gaussian) model to serve as feature selection crite...
Definition criterion_normal_divergence.hpp:110
virtual void update_derived_model() override
Definition criterion_normal_divergence.hpp:129
Criterion_Normal< RETURNTYPE, DATATYPE, REALTYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR > parent
base class: the normal-model template-method skeleton
Definition criterion_normal_divergence.hpp:112
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_divergence.hpp:156
virtual const char * criterion_name() const override
class name, used in output and error messages
Definition criterion_normal_divergence.hpp:122
std::shared_ptr< DATAACCESSOR > PDataAccessor
shared pointer to the data accessor the model is learned from
Definition criterion_normal_divergence.hpp:114
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _invbuf2
inverse of the narrowed class-2 covariance
Definition criterion_normal_divergence.hpp:138
std::unique_ptr< Indexed_Vector< DATATYPE, DIMTYPE, SUBSET > > _diag
per-feature diagonal of cov1^-1*cov2 + cov2^-1*cov1, summed into the trace term of the divergence
Definition criterion_normal_divergence.hpp:136
std::shared_ptr< SUBSET > PSubset
shared pointer to the feature subset being evaluated
Definition criterion_normal_divergence.hpp:115
virtual void allocate_buffers() override
(re)allocate criterion-specific work buffers for get_n() features (use the alloc_* helpers)
Definition criterion_normal_divergence.hpp:123
Clonable_Impl< Criterion_Normal_Divergence, parent > parent_impl
implements clone(); sharing/stateless_clone throw in Criterion
Definition criterion_normal_divergence.hpp:113
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _invbuf1
inverse of the narrowed class-1 covariance
Definition criterion_normal_divergence.hpp:137
std::unique_ptr< Indexed_Matrix< REALTYPE, DIMTYPE, SUBSET > > _LUtemp
scratch LU-decomposition storage, reused for each matrix inversion
Definition criterion_normal_divergence.hpp:139
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
void alloc_vector(std::unique_ptr< Indexed_Vector< DATATYPE, DIMTYPE, SUBSET > > &v)
lazy (re)allocation of a work vector for get_n() features, for use from allocate_buffers()
Definition criterion_normal.hpp:138
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
void invert(Indexed_Matrix &result, const Indexed_Matrix &LU_matrix)
Definition indexed_matrix.hpp:632
void LUdecompose(Indexed_Matrix &result)
Definition indexed_matrix.hpp:380
DATATYPE & at(const DIMTYPE row, const DIMTYPE col)
indexed access through the narrow_to() subset map – both row and col are mapped, row/col in [0,...
Definition indexed_matrix.hpp:114
Vector representation and operations, allows operation in selected subspace. Also serves as the helpe...
Definition indexed_vector.hpp:100
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