Implements L_{p} distance, p equals numerator/denominator (template parameters).
More...
|
|
| Distance_Lp (const DIMTYPE n) |
| | Constructs and immediately reset()s for n raw features (see Distance::reset()).
|
|
| Distance_Lp (const Distance_Lp &dlp) |
| | Copy-constructor; delegates to parent_impl (deep-copies the current _index[] mapping) and copies _p.
|
| virtual DATATYPE | distance (const DATATYPE *pattern1, const DATATYPE *pattern2) override |
| | Distance between two raw patterns over the currently active features only. Reads exactly get_d() entries of each pattern, at the raw indices in _index[] (identity unless narrow_to() is in effect) – concrete distances must index through _index[], never assume a contiguous 0..get_d()-1 layout.
|
| virtual std::ostream & | print (std::ostream &os) const override |
| | writes a human-readable identification of the object; base default writes nothing
|
| Distance< DATATYPE, DIMTYPE, SUBSET > * | clone () const override |
| | dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
|
| Distance< DATATYPE, DIMTYPE, SUBSET > * | sharing_clone () const override |
| | dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
| Distance< DATATYPE, DIMTYPE, SUBSET > * | stateless_clone () const override |
| | dispatches to the STATELESS_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
|
| Distance (const Distance &d) |
| | Copy-constructor; deep-copies the current _index[] mapping (same narrowed/denarrowed state as d).
|
|
void | reset (const DIMTYPE n) |
| | Allocates for n raw features and makes _index[] the identity map 0..n-1, with all n features active (get_d()==get_n()); narrow_to() restricts that.
|
|
void | narrow_to (const PSubset sub) |
| | Restricts distance() to sub's selected features only. Rewrites _index[] to the subset's selected feature indices (raw-feature order) and sets get_d() to the subset size; distance() then reads only those _d entries of a pattern, through _index[], instead of all _n. Precondition: reset() must have been called with n >= the subset size.
|
|
void | denarrow () |
| | Undoes narrow_to(): _index[] reverts to the identity map and get_d() returns to get_n().
|
|
DIMTYPE | get_n () const |
| | the full (raw, unnarrowed) feature count fixed by reset()
|
|
DIMTYPE | get_d () const |
| | the currently active feature count: the narrowed subset size after narrow_to(), get_n() after reset()/denarrow()
|
| Distance * | sharing_clone () const override |
| Distance * | stateless_clone () const override |
| 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
|
template<typename DATATYPE, typename REALTYPE, typename DIMTYPE, class SUBSET, const int numerator = 1, const int denominator = 1>
class FST::Distance_Lp< DATATYPE, REALTYPE, DIMTYPE, SUBSET, numerator, denominator >
Implements L_{p} distance, p equals numerator/denominator (template parameters).
( sum over the currently active features of |pattern1[f] - pattern2[f]|^p )^(1/p), with the exponent p fixed at compile time as the ratio of the two int template parameters (so that a fractional p can be expressed without a floating-point template argument). The defaults numerator=denominator=1 give p=1, i.e. plain L_1 - use Distance_L1 for that case, it is cheaper. Typical instantiations are p=2 (Euclidean, <...,2,1>) and fractional exponents such as p=1/2 (<...,1,2>).
- Note
- p >= 1 yields a true metric; p < 1 does NOT - the triangle inequality fails, so the result is a dissimilarity only. That is legitimate here (Classifier_kNN needs only the neighbour ORDER), and fractional exponents are sometimes preferred in very high dimensions, but do not rely on metric properties.
-
p must not be 0 - the final pow(result,1.0/p) would divide by zero.
template<typename DATATYPE, typename REALTYPE, typename DIMTYPE, class SUBSET, const int numerator, const int denominator>
| DATATYPE FST::Distance_Lp< DATATYPE, REALTYPE, DIMTYPE, SUBSET, numerator, denominator >::distance |
( |
const DATATYPE * | pattern1, |
|
|
const DATATYPE * | pattern2 ) |
|
overridevirtual |
Distance between two raw patterns over the currently active features only. Reads exactly get_d() entries of each pattern, at the raw indices in _index[] (identity unless narrow_to() is in effect) – concrete distances must index through _index[], never assume a contiguous 0..get_d()-1 layout.
- Parameters
-
| pattern1,pattern2 | raw feature vectors of at least get_n() entries each |
- Returns
- a non-negative dissimilarity: 0 for identical patterns, larger values mean farther apart. Implementations are free to return any monotone transform of a true distance (e.g. a squared or fractionally powered one), so the value need NOT satisfy the triangle inequality and need not be a metric. Only the induced ORDER of neighbours matters to the callers (Classifier_kNN).
Implements FST::Distance< DATATYPE, DIMTYPE, SUBSET >.