What the algorithm does
k-means looks for k centroids that minimise the mean squared distance from each point to its nearest centroid. Every method here keeps, for each cluster j, a sum Sj and a mass Nj, and places the centroid at cj = Sj / Nj. They differ only in how a batch's sum sj and count nj of newly assigned points enter those two numbers.
| Method | Update after a batch | What the centroid is |
|---|---|---|
| Lloyd | S ← s, N ← n (batch = all points) | The exact mean of the current assignments. One update per pass. |
| MacQueen-style mini-batch | S ← S + s, N ← N + n | The mean of every point ever assigned, including those assigned when the centroid was somewhere else. |
| e-means | S ← (1−α) S + α s, N ← (1−α) N + α n | A weighted mean that forgets old assignments at rate α. Many updates per pass. |
Because the centroid is a ratio of two moving averages, it is always a weighted average of points that were assigned to it, so it cannot overshoot the way a gradient step with a large learning rate can. A cluster that receives nothing in a batch keeps its position while its mass decays. With one batch holding all the data and α = 1, the update is exactly one Lloyd iteration. In the "Full batch" scenario the first update matches Lloyd's to the last digit; after that the cosine schedule lowers α, so e-means takes smaller steps than Lloyd and falls behind. Full batches with one update per pass are far from what the laws choose.
No hyperparameters
The batch size B and the first step size α₀ come from two power laws the authors fitted over many datasets, as functions of the number of points n, the number of clusters k and the epoch budget T:
These are the constants in the FAISS implementation. The quality law uses batches about eight times smaller, and FAISS picks it automatically for data with 16 dimensions or fewer, which includes this page's 2-D points.
Two more parts
- Revival. Every five updates, a cluster whose mass has fallen below τ = 0.1 times the average mass is moved next to a busy cluster, chosen with probability proportional to mass. The two then share the donor's mass and sit a hair apart, so the next batches pull them to opposite halves. FAISS turns this off for 1-D and 2-D data, where the authors measured that it hurt, and so does this page unless you switch it on. The "Clumped start" scenario switches it on; revived centroids flash with a white ring.
- Closing means. During the last epoch the algorithm also keeps plain sums and counts of the points each cluster received. At the end each centroid jumps to that exact mean. It costs no extra pass and shows as the small final drop in the loss curve.
What this page does and does not show
The e-means panel is a JavaScript port of Algorithm 1 as written in faiss/contrib/e_means (base.py and e_means.py): the same update, laws, constants, cosine floor, revival rule, split offsets, initial mass 2−16 and closing means. It uses 64-bit floats and its own random number generator, so it does not reproduce FAISS's numbers digit for digit.
The laws were fitted on 100,000 to 10 million points in tens to thousands of dimensions. A few thousand points in the plane is far outside that range, so treat what you see here as an illustration of the mechanism. The paper's main results are about large embedding datasets: the authors report that e-means reaches Lloyd's 25-iteration loss in 1.4 to 2.6 epochs, and runs 10 to 45 times faster on a GPU with their fused assignment kernels. Nothing on this page measures speed.
What to expect from the scenarios, measured with the "Many starts" panel on this page's 5,000 points. On the uniform square with 16 clusters, the shipped recipe ends below Lloyd's 25 iterations from most starts and rarely lands in a poor solution. On five well-separated blobs in a row, the shipped recipe falls into the same local minimum as Lloyd about as often (two centroids sharing one blob, one centroid straddling two). The authors' blog reports e-means escaping a five-blob trap of this kind; this page reproduces that only with much smaller, noisier batches than the laws choose here, which is the "tiny batches" scenario. Their exact toy setup is not known to me, so the difference may lie there.
Loss here is measured on the training points. The curve for e-means is computed by an extra full assignment after each update, which the algorithm itself never does.
Sources
- Bessa, Mazaré, Szilvasy, Touvron, Picard, Douze, Jégou, "e-means: outperforming k-means (in one-tenth the epochs)", arXiv:2611.09501
- Project page and blog: e-means.github.io, with the authors' own playground
- Reference code: faiss/contrib/e_means (MIT licence)