Almost Everywhere: Measure-Zero Math in Machine Learning
A statement holds almost everywhere when the places where it fails form a set of measure zero, which means the exceptions take up no room. Sheldon Axler defines it in his Definition 3.27: if (X, S, µ) is a measure space, a set E contains µ-almost every element of X when µ(X \ E) = 0. The exceptions can exist. They just take up no room, as measured by µ.
Why bother? Axler gives the reason in one sentence: what happens on a set of measure 0 often does not matter. Two functions that differ only on such a set have the same integral. That is what lets analysts say "equal almost everywhere" and move on, and the phrase turns up wherever integrals and probabilities do. A ReLU unit, for example, is not differentiable at 0, and that single point is a set of measure 0 on the real line.
Try it by hand. Why does a point, or even infinitely many points, take up no room? Axler's Result 2.4 says every countable subset of the real line has outer measure 0, and the proof is a trick you can run yourself. List the rationals as a₁, a₂, a₃, and so on. Fix a small ε, say 0.001. Wrap a₁ in an interval of length 2ε/2 = 0.001. Wrap a₂ in one of length 2ε/4 = 0.0005. Wrap a₃ in one of length 0.00025, and a₄ in 0.000125. The lengths halve each time, so even after infinitely many intervals the total is at most 2ε = 0.002. Every rational is covered, and the cover is shorter than 0.002. Since ε can be made as small as you like, the rationals have measure 0. So, in Axler's words, almost every real number is irrational.
The trap: reading "almost everywhere" as "everywhere" or as "for all but a few". It means outside a set of measure zero, and the answer depends on the measure. On the real line with Lebesgue measure, a single point has measure 0. Under counting measure, every point has measure 1, so µ(X \ E) = 0 only if nothing is left out, and "almost everywhere" turns into plain "everywhere".
Prof Rod's rule: before you say "almost everywhere", say which measure you mean.