e-means vs k-means

e-means (Bessa et al., Meta FAIR, 2026) is a mini-batch replacement for Lloyd's k-means. Each centroid is the ratio of two exponential moving averages, and the batch size and step size come from fitted formulas, so there is nothing to tune. Both methods below start from the same centroids on the same points.

Data

e-means

5
exact mean of the last epoch's assignments

Compared against

25

One Lloyd iteration reads every point once, so it costs one epoch. The paper's yardstick is Lloyd after 25 iterations. The mini-batch baseline uses the same batches as e-means but never forgets: it averages every point a centroid was ever given.

Lloyd's k-means

Epochs used0
Centroid updates0
Step size1
MSE–

e-means

Epochs used0
Centroid updates0
Step size α–
MSE–

Loss against data read

Mean squared distance from every point to its nearest centroid, measured on all points after each update. One epoch is one pass over the data; both methods compute the same n × k distances per epoch.

Lloyde-meansdashed: where the left method ends

Step size schedule

α starts at α₀ and follows a cosine down to 0.1 α₀. The dot is the current update.

Many starts

One run says little, because both methods depend on where the centroids start. This repeats the current setup from many different starting sets and sorts the final losses, best first. A flat line near 1 means nearly every start ended at the best loss found; a step up is a group of starts that ended in a worse local minimum.

Lloyde-means

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.

MethodUpdate after a batchWhat the centroid is
LloydS ← s,  N ← n  (batch = all points)The exact mean of the current assignments. One update per pass.
MacQueen-style mini-batchS ← S + s,  N ← N + nThe mean of every point ever assigned, including those assigned when the centroid was somewhere else.
e-meansS ← (1−α) S + α s,  N ← (1−α) N + α nA 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:

B = CB · k0.135 · n0.876 · T0.813, rounded to a power of two   (CB = 0.0351 throughput, 0.00439 quality)
α₀ = 0.824 · k−0.462 · B0.900 · n−0.450 · T−0.106, clamped to [0.0001, 1]
αt = α₀ · (0.1 + 0.9 · ½ (1 + cos(π t / ttotal)))

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

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