88template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
89class Distance :
public Clonable {
92 Distance() :
_n(0),
_d(0) {}
97 void reset(
const DIMTYPE n);
121 virtual DATATYPE
distance(
const DATATYPE *pattern1,
const DATATYPE *pattern2) =0;
123 Distance*
clone()
const override =0;
124 Distance*
sharing_clone()
const override {
throw fst_error(
"Distance::sharing_clone() not supported, use Distance::clone() instead.");}
125 Distance*
stateless_clone()
const override {
throw fst_error(
"Distance::stateless_clone() not supported, use Distance::clone() instead.");}
132template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
133Distance<DATATYPE,DIMTYPE,SUBSET>::Distance(
const Distance& d) :
137 notify(
"Distance copy-constructor.");
141template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
147 for(DIMTYPE i=0;i<
_n;i++)
_index[i]=i;
151template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
154 assert(
_n>=sub->get_d_raw());
157 for(DIMTYPE f : sub->selected_features())
_index[
_d++]=f;
161template<
typename DATATYPE,
typename DIMTYPE,
class SUBSET>
165 for(DIMTYPE i=0;i<
_n;i++)
_index[i]=i;
Abstract class, defines interface for distance evaluators to be used in Classifier_kNN.
Definition distance.hpp:89
Distance * clone() const override=0
DIMTYPE get_n() const
the full (raw, unnarrowed) feature count fixed by reset()
Definition distance.hpp:108
Distance * stateless_clone() const override
Definition distance.hpp:125
void denarrow()
Undoes narrow_to(): _index[] reverts to the identity map and get_d() returns to get_n().
Definition distance.hpp:162
void narrow_to(const PSubset sub)
Restricts distance() to sub's selected features only. Rewrites _index[] to the subset's selected feat...
Definition distance.hpp:152
DIMTYPE _d
currently active feature count (see get_d())
Definition distance.hpp:128
void reset(const DIMTYPE n)
Allocates for n raw features and makes _index[] the identity map 0..n-1, with all n features active (...
Definition distance.hpp:142
DIMTYPE get_d() const
the currently active feature count: the narrowed subset size after narrow_to(), get_n() after reset()...
Definition distance.hpp:109
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset, as consumed by narrow_to()
Definition distance.hpp:91
virtual DATATYPE distance(const DATATYPE *pattern1, const DATATYPE *pattern2)=0
Distance between two raw patterns over the currently active features only. Reads exactly get_d() entr...
std::unique_ptr< DIMTYPE[]> _index
maps active-feature position [0,_d) to a raw feature index in [0,_n)
Definition distance.hpp:129
DIMTYPE _n
full raw feature count, fixed by reset()
Definition distance.hpp:127
Distance * sharing_clone() const override
Definition distance.hpp:124
FST4 specific error passing class.
Definition error.hpp:61
Defines interface for classes that may need to get cloned.
FST4 specific error passing class.
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