Distance

Trait Distance 

Source
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§

Source

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§

Source

fn square_err(&self, rhs: &impl Distance) -> f64

Calculate the square error.

Source

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.

Source

fn l1_err(&self, rhs: &impl Distance) -> f64

Calculate the L1 norm of the error.

This method is also called Manhattan distance.

Source

fn l2_err(&self, rhs: &impl Distance) -> f64

Calculate the L2 norm of the error.

This method is also called Euclidean distance.

Source

fn lp_err(&self, rhs: &impl Distance, p: f64) -> f64

Calculate the Lp norm of the error.

This method is also called Minkowski distance.

Source

fn linf_err(&self, rhs: &impl Distance) -> f64

Calculate the Linf norm of the error.

This method is also called Chebyshev distance.

Source

fn l0_norm(&self) -> f64

Calculate the norm (vector length) according to the origin (zeros).

See also Distance::l0_err().

Source

fn l1_norm(&self) -> f64

Calculate the norm (vector length) according to the origin (zeros).

See also Distance::l1_err().

Source

fn l2_norm(&self) -> f64

Calculate the norm (vector length) according to the origin (zeros).

See also Distance::l2_err().

Source

fn linf_norm(&self) -> f64

Calculate the norm (vector length) according to the origin (zeros).

See also Distance::linf_err().

Source

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.

Implementations on Foreign Types§

Source§

impl Distance for [f64]

Source§

fn as_components(&self) -> impl Iterator<Item = &f64>

Source§

impl<const D: usize> Distance for [f64; D]

Source§

fn as_components(&self) -> impl Iterator<Item = &f64>

Implementors§

Source§

impl<const D: usize> Distance for Efd<D>
where U<D>: EfdDim<D>,