[][src]Function acap::cos::cosine_similarity

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

Compute the cosine similarity between two points.

Use cosine_distance instead if you are implementing Proximity::distance().

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