Implements L_1 (city-block / Manhattan) distance. More...
#include <distance_L1.hpp>
Public Types | |
| typedef Distance< DATATYPE, DIMTYPE, SUBSET > | parent |
| base class: the abstract distance interface | |
| typedef Clonable_Impl< Distance_L1, parent > | parent_impl |
| implements clone(); sharing/stateless_clone throw in Distance | |
| Public Types inherited from FST::Distance< DATATYPE, DIMTYPE, SUBSET > | |
| typedef std::shared_ptr< SUBSET > | PSubset |
| shared pointer to a feature subset, as consumed by narrow_to() | |
Public Member Functions | |
| Distance_L1 (const DIMTYPE n) | |
Constructs and immediately reset()s for n raw features (see Distance::reset()). | |
| Distance_L1 (const Distance_L1 &dl1) | |
| Copy-constructor; delegates to parent_impl (deep-copies the current _index[] mapping). | |
| 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 | |
| Public Member Functions inherited from FST::Clonable_Impl< Distance_L1< DATATYPE, DIMTYPE, SUBSET >, Distance< DATATYPE, DIMTYPE, SUBSET > > | |
| 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) | |
| Public Member Functions inherited from FST::Distance< DATATYPE, DIMTYPE, SUBSET > | |
| 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 |
| 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 | |
Additional Inherited Members | |
| 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 inherited from FST::Distance< DATATYPE, DIMTYPE, SUBSET > | |
| DIMTYPE | _n |
| full raw feature count, fixed by reset() | |
| DIMTYPE | _d |
| currently active feature count (see get_d()) | |
| std::unique_ptr< DIMTYPE[]> | _index |
| maps active-feature position [0,_d) to a raw feature index in [0,_n) | |
Implements L_1 (city-block / Manhattan) distance.
sum over the currently active features of |pattern1[f] - pattern2[f]|; a true metric, less sensitive to single large coordinate differences than the Euclidean distance.
|
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.
| pattern1,pattern2 | raw feature vectors of at least get_n() entries each |
Implements FST::Distance< DATATYPE, DIMTYPE, SUBSET >.
|
inlineoverridevirtual |
writes a human-readable identification of the object; base default writes nothing
Reimplemented from FST::Clonable.