pub enum Distance {
SquaredEuclidean,
Euclidean,
CosineDistance,
Manhattan,
Chebyshev,
Minkowski(f64),
Hamming,
}
Expand description
Enum listing the available distance metrics.
Variants§
SquaredEuclidean
Squared Euclidean distance (sum of squared differences).
Euclidean
Euclidean distance (square root of the sum of squared differences).
CosineDistance
Cosine distance (1 minus the cosine similarity). If a vector has zero norm, returns 1.
Manhattan
Manhattan distance (sum of absolute differences).
Chebyshev
Chebyshev distance (maximum absolute difference).
Minkowski(f64)
Minkowski distance (generalized distance; p
sets the norm order).
Hamming
Hamming distance (count of positions where elements differ).
Implementations§
Source§impl Distance
impl Distance
Sourcepub fn compute<T>(&self, a: &[T], b: &[T]) -> T
pub fn compute<T>(&self, a: &[T], b: &[T]) -> T
Compute the distance between two slices a
and b
using the selected metric.
§Type Parameters
T
: A numeric type implementingReal
,Send
, andSync
.
§Parameters
a
: A slice representing the first vector.b
: A slice representing the second vector.
§Returns
The computed distance as a value of type T
.
§Panics
Panics with a custom error if the lengths of a
and b
differ or if a metric-specific
parameter is invalid.
§Example
use vq::distances::Distance;
let a = vec![1.0, 2.0, 3.0];
let b = vec![4.0, 5.0, 6.0];
let d = Distance::Euclidean.compute(&a, &b);
println!("Euclidean distance: {}", d);
Auto Trait Implementations§
impl Freeze for Distance
impl RefUnwindSafe for Distance
impl Send for Distance
impl Sync for Distance
impl Unpin for Distance
impl UnwindSafe for Distance
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.