pub trait Distance {
// Required method
fn as_components(&self) -> impl Iterator<Item = &f64>;
// Provided methods
fn square_err(&self, rhs: &impl Distance) -> f64 { ... }
fn l0_err(&self, rhs: &impl Distance) -> f64 { ... }
fn l1_err(&self, rhs: &impl Distance) -> f64 { ... }
fn l2_err(&self, rhs: &impl Distance) -> f64 { ... }
fn lp_err(&self, rhs: &impl Distance, p: f64) -> f64 { ... }
fn linf_err(&self, rhs: &impl Distance) -> f64 { ... }
fn l0_norm(&self) -> f64 { ... }
fn l1_norm(&self) -> f64 { ... }
fn l2_norm(&self) -> f64 { ... }
fn linf_norm(&self) -> f64 { ... }
fn lp_norm(&self, p: f64) -> f64 { ... }
}Expand description
Be able to calculate the distance between two instances.
Each data number has the same weight by default, but you can change it by
implementing Distance::as_components().
Required Methods§
Sourcefn as_components(&self) -> impl Iterator<Item = &f64>
fn as_components(&self) -> impl Iterator<Item = &f64>
Get the components of the data.
The Iterator::size_hint() method is used to determine the size of
the data.
Provided Methods§
Sourcefn square_err(&self, rhs: &impl Distance) -> f64
fn square_err(&self, rhs: &impl Distance) -> f64
Calculate the square error.
Sourcefn l0_err(&self, rhs: &impl Distance) -> f64
fn l0_err(&self, rhs: &impl Distance) -> f64
Calculate the L0 norm of the error.
This method is also called Hamming distance, which counts the number of errors that are less than the epsilon.
Sourcefn l1_err(&self, rhs: &impl Distance) -> f64
fn l1_err(&self, rhs: &impl Distance) -> f64
Calculate the L1 norm of the error.
This method is also called Manhattan distance.
Sourcefn l2_err(&self, rhs: &impl Distance) -> f64
fn l2_err(&self, rhs: &impl Distance) -> f64
Calculate the L2 norm of the error.
This method is also called Euclidean distance.
Sourcefn lp_err(&self, rhs: &impl Distance, p: f64) -> f64
fn lp_err(&self, rhs: &impl Distance, p: f64) -> f64
Calculate the Lp norm of the error.
This method is also called Minkowski distance.
Sourcefn linf_err(&self, rhs: &impl Distance) -> f64
fn linf_err(&self, rhs: &impl Distance) -> f64
Calculate the Linf norm of the error.
This method is also called Chebyshev distance.
Sourcefn l0_norm(&self) -> f64
fn l0_norm(&self) -> f64
Calculate the norm (vector length) according to the origin (zeros).
See also
Distance::l0_err().
Sourcefn l1_norm(&self) -> f64
fn l1_norm(&self) -> f64
Calculate the norm (vector length) according to the origin (zeros).
See also
Distance::l1_err().
Sourcefn l2_norm(&self) -> f64
fn l2_norm(&self) -> f64
Calculate the norm (vector length) according to the origin (zeros).
See also
Distance::l2_err().
Sourcefn linf_norm(&self) -> f64
fn linf_norm(&self) -> f64
Calculate the norm (vector length) according to the origin (zeros).
See also
Distance::linf_err().
Sourcefn lp_norm(&self, p: f64) -> f64
fn lp_norm(&self, p: f64) -> f64
Calculate the norm (vector length) according to the origin (zeros).
See also Distance::lp_err().
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.