pub trait Compare<N>{
// Required methods
fn dot(vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>) -> f64;
fn cosine_similarity(
vec: impl Iterator<Item = (usize, N)>,
other: impl Iterator<Item = (usize, N)>,
) -> f64;
fn euclidean_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64;
fn manhattan_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64;
fn chebyshev_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64;
}Required Methods§
Sourcefn dot(vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>) -> f64
fn dot(vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>) -> f64
dot積 d(a, b) = Σ(a_i * b_i)
Sourcefn cosine_similarity(
vec: impl Iterator<Item = (usize, N)>,
other: impl Iterator<Item = (usize, N)>,
) -> f64
fn cosine_similarity( vec: impl Iterator<Item = (usize, N)>, other: impl Iterator<Item = (usize, N)>, ) -> f64
コサイン類似度 cos(θ) = Σ(a_i * b_i) / (||a|| * ||b||) ||a|| = sqrt(Σ(a_i^2))
Sourcefn euclidean_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64
fn euclidean_distance( vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>, ) -> f64
ユークリッド距離 d(a, b) = sqrt(Σ((a_i - b_i)^2))
Sourcefn manhattan_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64
fn manhattan_distance( vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>, ) -> f64
マンハッタン距離 d(a, b) = Σ(|a_i - b_i|)
Sourcefn chebyshev_distance(
vec: impl Iterator<Item = N>,
other: impl Iterator<Item = N>,
) -> f64
fn chebyshev_distance( vec: impl Iterator<Item = N>, other: impl Iterator<Item = N>, ) -> f64
チェビシェフ距離 d(a, b) = max(|a_i - b_i|)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Compare<f32> for DefaultCompare
impl Compare<f64> for DefaultCompare
impl Compare<u8> for DefaultCompare
impl Compare for u8, u16, u32, f32, f64