[][src]Function kmeans_colors::get_kmeans_hamerly

pub fn get_kmeans_hamerly<C: Hamerly + Clone>(
    k: usize,
    max_iter: usize,
    converge: f32,
    verbose: bool,
    buf: &[C],
    seed: u64
) -> Kmeans<C>

Find the k-means centroids of a buffer using the Hamerly algorithm. Takes the same arguments as get_kmeans and produces the same results.

Hamerly uses the triangle inequality and caches one lower and upper bound for each point, which allows it to skip the inner loop of distance calculation for each point more often. Asymptotically, this algorithm performs better than the default algorithm for lower dimensional k-means taking advantage of the fact than some centroids converge very quickly. However, this method incurs additional overhead that may perform worse than the naive method at low center counts like k=1. Benchmark the functions to see which performs better for your use case.

Example implementations for Lab and Srgb can be found in colors/kmeans.rs.

Reference

Hamerly, G., & Drake, J. (2017). Chapter 2 Accelerating Lloyd's Algorithm for k-Means Clustering.

Hamerly, G. (2010). Making k-means even faster. In: SIAM international conference on data mining.