Function engram::metrics::tanimoto_coefficient

source ·
pub fn tanimoto_coefficient(a: &[f64], b: &[f64]) -> f64
Expand description

Compute the Tanimoto Coefficient for continuous vectors. A measure of similarity for real-valued vectors that generalizes the Jaccard index. Formula: dot(a, b) / (|a|^2 + |b|^2 - dot(a, b))

§Examples

let a = [1.0, 2.0, 3.0];
let b = [1.3, 2.1, 3.0];
let c = [1.5, 2.4, 4.0];
let tc_ab = tanimoto_coefficient(&a, &b);
let tc_ac = tanimoto_coefficient(&a, &c);
assert!((tc_ab - 0.9932).abs() < 1e-4);
assert!((tc_ac - 0.9285).abs() < 1e-4);