Skip to main content

Module utils

Module utils 

Source
Expand description

Math utilities for diarization.

Shared vector math (cosine similarity, L2 normalization, pairwise similarity matrices, mean centroids, segment merging) used by clustering, embedding, and overlap modules. See cosine_similarity.

Functions§

cosine_similarity
{ true } pub fn cosine_similarity(a: &f32, b: &f32) -> f32 { ret >= -1.0 && ret <= 1.0 } Compute cosine similarity between two vectors.
cosine_similarity_f32_f64
{ true } pub fn cosine_similarity_f32_f64(a: &f32, b: &f64) -> f32 { ret >= -1.0 && ret <= 1.0 } Compute cosine similarity between an f32 slice and an f64 slice.
l2_normalize
{ true } pub fn l2_normalize(vec: &mut f32) { true } L2-normalize a vector in-place.
mean_vector
{ true } pub fn mean_vector(vectors: &[Vec<f32>]) -> Option<Vec<f32>> { ret.as_ref().map_or(true, |v| vectors.iter().all(|u| u.len() == v.len())) } Compute the element-wise mean of a list of vectors.
merge_segments
{ true } pub fn merge_segments(segments: Vec<Segment>, max_gap_secs: f64) -> Vec<Segment> { ret.len() <= segments.len() } Merge adjacent segments with the same speaker if the gap between them is less than max_gap_secs.