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 thanmax_gap_secs.