MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / assign

Function assign

nodedb-vector/src/multivec/plaid.rs:25–38  ·  view source on GitHub ↗

Assign each vector to its nearest centroid index.

(vectors: &[Vec<f32>], centroids: &[Vec<f32>])

Source from the content-addressed store, hash-verified

23
24/// Assign each vector to its nearest centroid index.
25fn assign(vectors: &[Vec<f32>], centroids: &[Vec<f32>]) -> Vec<usize> {
26 vectors
27 .iter()
28 .map(|v| {
29 centroids
30 .iter()
31 .enumerate()
32 .map(|(i, c)| (i, scalar_distance(v, c, DistanceMetric::L2)))
33 .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal))
34 .map(|(i, _)| i)
35 .unwrap_or(0)
36 })
37 .collect()
38}
39
40/// Deterministic LCG step for reproducible randomness across train calls.
41fn lcg_next(s: &mut u64) -> u64 {

Callers 2

kmeansFunction · 0.85
assignMethod · 0.85

Calls 4

scalar_distanceFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
partial_cmpMethod · 0.45

Tested by

no test coverage detected