[][src]Function acap::cos::cosine_distance

pub fn cosine_distance<T, U>(x: T, y: U) -> T::Value where
    T: Coordinates,
    U: Coordinates<Value = T::Value>,
    T::Value: Real

Compute the cosine distance between two points.

\begin{aligned}
\mathrm{cosine\_distance}(x, y) &= 1 - \mathrm{cosine\_similarity}(x, y) \\
&= 1 - \frac{x \cdot y}{\|x\| \|y\|} \\
&= 1 - \frac{\sum_i x_i y_i}{\sqrt{\sum_i x_i^2} \sqrt{\sum_i y_i^2}} \\
&= 1 - \cos \theta
\end{aligned}