euclidean_grad

Function euclidean_grad 

Source
pub fn euclidean_grad<T>(x: &Array1<T>, y: &Array1<T>) -> (T, Vec<T>)
where T: Float,
Expand description

Computes the Euclidean distance and its gradient between two vectors.

The function calculates the Euclidean distance between two input vectors x and y and returns both the distance and the gradient. The gradient indicates how much each element in the input vectors contributes to the distance.

§Parameters

  • x: An Array1<T> representing the first vector.
  • y: An Array1<T> representing the second vector.

§Type Parameter

  • T: A generic type that must implement the Float trait. This ensures that the elements in vectors x and y can be used for arithmetic operations involving floating-point numbers.

§Returns

A tuple containing:

  1. The Euclidean distance between the two input vectors, of type T.
  2. An Array1<T> representing the gradient. Each element in this array corresponds to the contribution of each element in the input vectors towards the Euclidean distance.

§Panics

  • If the input arrays do not have the same length, the function will panic with an appropriate error message.