E-means
lastmod 2026-11-11created 2026-11-112 edits
k-means that is about 10 times faster at the same test error
About
- A k-means algorithm that combines mini-batches with an exponential moving average (EMA). Across many datasets and scales, it reaches the test error of 25 epochs of Lloyd's algorithm in just 1.2–3 epochs
- Total run time to reach the same test error is 10–45 times shorter than Flash-KMeans on GPU and 8–15 times shorter than Faiss on CPU
- Updates the per-cluster sum S_j and count N_j as
S_j ← (1−α)S_j + αs_jandN_j ← (1−α)N_j + αn_j, reducing the influence of stale assignments. Lloyd resets the statistics on every pass, while MacQueen accumulates all past statistics - Gradient-descent-based mini-batch k-means (Meta FAIR) was unstable at large learning rates, whereas with EMA the centroids stay inside the convex hull of their assigned points, which keeps it stable. On DEEP 1M and SIFT 10M with 16,384 clusters and 5 epochs, its test error is 1.6% and 0.4% lower, respectively, than tuned gradient descent
- Batch size and initial step size are set automatically by scaling laws based on the number of points (n), number of clusters (k), and epochs (T), so no hyperparameter tuning is needed beyond what Lloyd requires
- Default batch:
B = 0.035 × k^0.13 × n^0.88 × T^0.81(coefficient 0.0044 when prioritizing quality) - Step:
α₀ = min(0.824 × k^−0.46 × B^0.90 × n^−0.45 × T^−0.11, 1), decayed to 0.1α₀ with a cosine schedule - A final step recomputes the centroids as the mean of the last epoch's assignments, further lowering the training loss
- Default batch:
faiss/contrib/e_means; use Emeans for PyTorch tensors and NumpyEmeans for NumPy. The default training budget is 5 epochs, and train(x) returns the centroids and the cluster labels from the last epoch