Skip to content

Add Hamerly's accelerated K-means algorithm to linfa-clustering#439

Open
mrsanor wants to merge 2 commits intorust-ml:masterfrom
mrsanor:kmeans-hamerly
Open

Add Hamerly's accelerated K-means algorithm to linfa-clustering#439
mrsanor wants to merge 2 commits intorust-ml:masterfrom
mrsanor:kmeans-hamerly

Conversation

@mrsanor
Copy link
Copy Markdown

@mrsanor mrsanor commented Apr 21, 2026

Implement K-means Hamerly's triangle-inequality optimization as an alternative to Lloyd's algorithm for K-means clustering for speed optimization. For each observation the algorithm maintains upper/lower distance bounds and skips centroid comparisons that cannot change the assignment, yielding the same results as Lloyd but with significantly fewer distance computations when clusters are well separated.

Key changes:

  • The new Hamerly K-means algorithm (uses the same m_k-means for centroid calculations as Lloyd)
  • Add KMeansAlgorithm enum (Lloyd | Hamerly) and .algorithm() builder method
  • Reject Hamerly for incremental fit_with
  • Comprehensive tests

Here are the benchmarks between Lloyd and Hamerly

Screenshot 2026-04-21 at 15-26-35 k_means Summary - Criterion rs

mrsanor added 2 commits April 21, 2026 15:44
Implement K-means Hamerly's triangle-inequality optimization as an alternative to Lloyd's algorithm for K-means clustering. For each observation the algorithm maintains upper/lower distance bounds and skips centroid comparisons that cannot change the assignment, yielding the same results as Lloyd but with significantly fewer distance computations when clusters are well separated.

Key changes:
- The new Hamerly K-means algorithm
- Add KMeansAlgorithm enum (Lloyd | Hamerly) and .algorithm() builder method
- Reject Hamerly for incremental fit_with
- Comprehensive tests
@mrsanor mrsanor changed the title feat(linfa-clustering): Add Hamerly's accelerated K-means algorithm Add Hamerly's accelerated K-means algorithm to linfa-clustering Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant