clump
Clustering algorithms.
Algorithms
| Algorithm | Kind | Discovers k | Noise handling | Input |
|---|---|---|---|---|
| K-means | Centroid | No (k required) | None | &impl DataRef |
| Mini-Batch K-means | Centroid (streaming) | No (k required) | None | &impl DataRef |
| DBSCAN | Density | Yes | Labels noise (NOISE sentinel) |
&impl DataRef |
| HDBSCAN | Density (hierarchical) | Yes | Labels noise | &impl DataRef |
| DenStream | Density (streaming) | Yes | Decays outliers | &impl DataRef |
| EVoC | Hierarchical | Yes | Near-duplicate detection | &impl DataRef |
| COP-Kmeans | Constrained centroid | No (k required) | None | &impl DataRef + constraints |
| OPTICS | Density (reachability) | Yes | Reachability plot | &impl DataRef |
| Correlation Clustering | Graph-based | Yes | None | SignedEdge list |
Quickstart
[]
= "0.5.2"
use ;
let data = vec!;
// K-means: returns labels (default: squared Euclidean)
let labels = new.with_seed.fit_predict.unwrap;
assert_eq!;
assert_ne!;
// DBSCAN: discovers clusters from density (default: Euclidean)
let labels = new.fit_predict.unwrap;
Kmeans::fit returns KmeansFit with centroids, which supports predict on new points. Dbscan::fit_predict assigns noise points to clump::NOISE; use fit_predict_with_noise for Option labels.
Zero-copy flat input
All algorithms accept &impl DataRef. Pass Vec<Vec<f32>> or use FlatRef for zero-copy flat buffers:
use ;
let flat = vec!;
let data = new;
let labels = new.with_seed.fit_predict.unwrap;
Streaming clustering
use MiniBatchKmeans;
let mut mbk = new.with_seed;
mbk.update_batch.unwrap;
mbk.update_batch.unwrap;
// Centroids available via mbk.centroids()
Constrained clustering
use ;
let constraints = vec!;
let labels = new
.with_seed
.fit_predict_constrained
.unwrap;
Correlation clustering
use ;
let edges = vec!;
let result = new.fit.unwrap;
let labels = result.labels;
Also see edges_from_distances to build signed edges from a distance matrix.
Distance metrics
All algorithms are generic over DistanceMetric. Built-in: SquaredEuclidean, Euclidean, CosineDistance, InnerProductDistance, CompositeDistance. Use with_metric on any algorithm to swap. Custom metrics: implement DistanceMetric (one method: fn distance(&self, a: &[f32], b: &[f32]) -> f32).
Features
Optional features: parallel (Rayon), gpu (Metal k-means, macOS), serde, ndarray (Array2 conversions), simd (NEON/AVX2/AVX-512 distance).
License
MIT OR Apache-2.0