Skip to main content

cosine

Function cosine 

Source
pub fn cosine<T>(point1: &[T], point2: &[T]) -> T
where T: Float,
Expand description

Compute Cosine distance between two points

§Arguments

  • point1 - First point
  • point2 - Second point

§Returns

  • Cosine distance between the points (1 - cosine similarity)

§Examples

use scirs2_spatial::distance::cosine;

let point1 = &[1.0, 0.0];
let point2 = &[0.0, 1.0];

let dist = cosine(point1, point2);
assert!((dist - 1.0f64).abs() < 1e-6);