template<typename Data_, typename Distance_>
class knncolle::DistanceMetric< Data_, Distance_ >
Interface for a distance metric.
- Template Parameters
-
| Data_ | Numeric type for the input data. |
| Distance_ | Floating-point type for the output distance. |
template<typename Data_ , typename Distance_ >
| virtual Distance_ knncolle::DistanceMetric< Data_, Distance_ >::raw |
( |
std::size_t | num_dimensions, |
|
|
const Data_ * | x, |
|
|
const Data_ * | y ) const |
|
pure virtual |
The raw distance r for a distance d is defined so that r(x, y) > r(x, z) iff d(x, y) > d(x, z). r(x, y) is converted to d(x, z) via a monotonic transform in normalize(), and vice versa for denormalize(). We separate out these two steps to avoid, e.g., a costly root operation for a Euclidean distance when only the relative values are of interest.
- Parameters
-
| x | Pointer to the array containing the first vector. |
| y | Pointer to the array containing the second vector. |
| num_dimensions | Length of both vectors. |
- Returns
- The raw distance between
x and y.
template<typename Data_ , typename Distance_ >
Save the distance metric to disk, to be reloaded with load_distance_metric_raw() and friends.
An implementation of this method should create a <prefix>DISTANCE file that contains the distance metric's name. This should be an ASCII file with no newlines, where the method name should follow the <library>::<distance> format, e.g., knncolle::Euclidean. This will be used by load_distance_metric_raw() to determine the exact loader function to call. Other than the DISTANCE file, each implementation may create any number of additional files of any format, as long as they start with prefix.
An implementation of this method is not required to use portable file formats. load_distance_metric_raw() is only expected to work on the same system (i.e., architecture, compiler, compilation settings) that was used for the save() call. Any additional portability is at the discretion of the implementation, e.g., it is common to assume IEEE floating-point and two's-complement integers.
An implementation of this method is not required to create files that are readable by different versions of the implementation. Thus, the files created by this method are generally unsuitable for archival storage. However, implementations are recommended to at least provide enough information to throw an exception if an incompatible version of load_distance_metric_raw() is used.
If a subclass does not implement this method, an error is thrown by default.
- Parameters
-
| prefix | Prefix of the file path(s) in which to save the index. All files created by this method should start with this prefix. Any directories required to write a file starting with prefix should already have been created. |