Simple Algorithm
Deep Learning · Emergence · 28 min

A Theory of Data Augmentation

Orbit averaging, variance reduction and when augmentation provably helps.

Why does training on rotated copies help, and when can it hurt? Give augmentation a mathematical setting, a group of transformations acting on the inputs, and the answers become theorems. Augmentation is averaging over orbits; when the data distribution is invariant it provably reduces variance, sometimes as much as multiplying the data; in a kernel model it is averaged features plus a variance penalty; and building the invariance into the model can beat augmenting by an exact, computable margin.

What you’ll learn

  • Set up augmentation with a group acting on the inputs (orbits, invariant functions, the orbit-averaging operator) and show that augmented training is ERM on the orbit-averaged loss.
  • Prove the invariance lemma (orbit averaging is a conditional expectation) and derive the variance reduction of augmented estimators, exactly in a worked example (Chen, Dobriban & Lee, 2020).
  • Derive the kernel view of augmentation: first-order feature averaging plus a second-order variance penalty (Dao et al., 2019).
  • State the strict generalization benefit of invariant linear models (Elesedy & Zaidi, 2021), describe learned augmentation distributions, and explain how approximate and label-changing transformations break the theory.

Groups, orbits and averaging

Two facts organize everything that follows. First, fˉ\bar f is invariant: fˉ(hx)=Egf(ghx)=Eg′f(g′x)\bar f(h\mathbf x)=\E_gf(gh\mathbf x)=\E_{g'}f(g'\mathbf x), because g↦ghg\mapsto gh maps the uniform distribution on GG to itself. Averaging over a group projects any function onto the invariant ones.

Second, augmented training is an ordinary ERM. Sampling g∼Qg\sim Q afresh for each example makes SGD an unbiased method for the augmented loss Lˉ(θ,x)=Eg∼QL(θ,gx)\bar L(\boldsymbol\theta,\mathbf x)=\E_{g\sim Q}L(\boldsymbol\theta,g\mathbf x), so the augmented estimator minimizes 1n∑iLˉ(θ,xi)\frac1n\sum_i\bar L(\boldsymbol\theta,\mathbf x_i): the same empirical risk minimization, with each loss replaced by its orbit average.

Augmentation reduces variance

DerivationWhy it holds
  1. fˉ(X)=Eg∼Qf(gX)=E[f(X)∣GX]\bar f(X)=\E_{g\sim Q}f(gX)=\E\big[f(X)\mid GX\big]

    Under exact invariance, once you know which orbit XX lies on, its position within the orbit looks like gXgX with g∼Qg\sim Q: for a finite group acting freely, each of the orbit's points is equally likely. Averaging over gg is therefore conditioning on the orbit, which is (1):

  2. Cov⁡f(X)=Cov⁡(E[f(X)∣GX])+E[Cov⁡(f(X)∣GX)]=Cov⁡fˉ(X)+EXCov⁡gf(gX)\Cov f(X)=\Cov\big(\E[f(X)\mid GX]\big)+\E\big[\Cov(f(X)\mid GX)\big]=\Cov\bar f(X)+\E_X\Cov_gf(gX)

    The tower property gives (2), the law of total covariance gives (3), and Jensen's inequality for conditional expectations gives (4):

  3. This is the Rao–Blackwell theorem in disguise: replace a statistic by its conditional expectation given (here) the orbit, keep the mean, and shed the within-orbit variance. Applied to the loss, the augmented empirical risk has the same expectation as the original for every θ\boldsymbol\theta and smaller variance; applied to an estimator θ^(X)\hat{\boldsymbol\theta}(X), its average Egθ^(gX)\E_g\hat{\boldsymbol\theta}(gX) has the same bias and a covariance smaller in the Loewner order, so smaller error under every convex loss.

n(θ^n,G−θ0) →d N(0, V−1(Cov⁡∇L(θ0,X)−EXCov⁡g∇L(θ0,gX))V−1)\sqrt n\big(\hat{\boldsymbol\theta}_{n,G}-\boldsymbol\theta_0\big)\ \xrightarrow{d}\ \mathcal N\Big(\mathbf 0,\ V^{-1}\big(\Cov\nabla L(\boldsymbol\theta_0,X)-\E_X\Cov_g\nabla L(\boldsymbol\theta_0,gX)\big)V^{-1}\Big)
For augmented M-estimators under exact invariance and standard regularity conditions (fixed dimension, n→∞n\to\infty, VV the Hessian of the population risk at the minimizer θ0\boldsymbol\theta_0), Chen, Dobriban and Lee prove asymptotic normality with this covariance. Plain ERM has V−1Cov⁡∇L V−1V^{-1}\Cov\nabla L\,V^{-1}: the gain is exactly the average within-orbit covariance of the loss gradient. For strongly convex losses they also prove a finite-sample bound in which the same covariance reduction appears.
DerivationWorked example: a d-fold gain
  1. θ^=Xˉ,E∥θ^−μ∥2=d σ2n\hat{\boldsymbol\theta}=\bar X,\qquad\E\norm{\hat{\boldsymbol\theta}-\boldsymbol\mu}^2=\frac{d\,\sigma^2}{n}

    Let X∼N(μ,σ2Id)X\sim\mathcal N(\boldsymbol\mu,\sigma^2I_d) with μ=m1\boldsymbol\mu=m\mathbf 1 (all coordinates equal), and let GG be the dd cyclic shifts of coordinates. Shifting permutes independent coordinates with equal means, so the distribution is exactly invariant. Estimate μ\boldsymbol\mu with the loss L(θ,x)=∥x−θ∥2L(\boldsymbol\theta,\mathbf x)=\norm{\mathbf x-\boldsymbol\theta}^2. ERM gives the sample mean vector:

  2. θ^G=Eg gXˉ=(1nd∑i,kXik)1,E∥θ^G−μ∥2=d⋅σ2nd=σ2n\hat{\boldsymbol\theta}_G=\E_g\,g\bar X=\Big(\frac{1}{nd}\sum_{i,k}X_{ik}\Big)\mathbf 1,\qquad\E\norm{\hat{\boldsymbol\theta}_G-\boldsymbol\mu}^2=d\cdot\frac{\sigma^2}{nd}=\frac{\sigma^2}{n}

    The augmented risk 1n∑iEg∥gXi−θ∥2\frac1n\sum_i\E_g\norm{gX_i-\boldsymbol\theta}^2 is minimized by the orbit average of Xˉ\bar X, which sets every coordinate to the average of all ndnd observed coordinates:

  3. A factor-dd reduction: augmentation is worth as much as dd times more data here, because the symmetry lets each observation inform every coordinate.

Predict before you look

In the example, take d=8d=8 coordinates and n=50n=50 samples. How many samples would un-augmented ERM need to reach the augmented estimator's mean squared error?

Show the answer

400 samples

ERM's error is dσ2/Nd\sigma^2/N and the augmented error is σ2/n\sigma^2/n; equating gives N=dn=8×50=400N=dn=8\times50=400.

Real symmetries are rarely exact. If gXgX is only close in distribution to XX, averaging over the orbit also adds bias. Chen, Dobriban and Lee quantify the resulting trade-off: the variance removed depends on how much the loss varies along orbits, the bias on a Wasserstein distance between XX and its transformed copies. Augmentation helps when the first outweighs the second, which is why the safe range of a transformation is an empirical question.

The kernel view: averaged features plus a variance penalty

Dao, Gu, Ratner, Smith, De Sa and Ré (2019) analyzed augmentation for linear models on features, f(x)=w⊤ϕ(x)f(\mathbf x)=\mathbf w^\top\boldsymbol\phi(\mathbf x), which covers kernel machines and a network's last layer, with a loss ℓ(f,y)\ell(f,y) twice differentiable in ff. Expand the augmented loss of one example around the orbit-averaged feature ϕˉ(x)=Egϕ(gx)\bar{\boldsymbol\phi}(\mathbf x)=\E_g\boldsymbol\phi(g\mathbf x):

DerivationFirst-order averaging, second-order variance
  1. Eg ℓ(w⊤ϕ(gx),y)=ℓ(w⊤ϕˉ,y)+ℓ′(w⊤ϕˉ,y) w⊤Eg[Δg]+12 Eg[ℓ′′(⋅) (w⊤Δg)2]+…\E_g\,\ell\big(\mathbf w^\top\boldsymbol\phi(g\mathbf x),y\big)=\ell\big(\mathbf w^\top\bar{\boldsymbol\phi},y\big)+\ell'\big(\mathbf w^\top\bar{\boldsymbol\phi},y\big)\,\mathbf w^\top\E_g[\boldsymbol\Delta_g]+\tfrac12\,\E_g\big[\ell''(\cdot)\,(\mathbf w^\top\boldsymbol\Delta_g)^2\big]+\dots

    Write ϕ(gx)=ϕˉ(x)+Δg\boldsymbol\phi(g\mathbf x)=\bar{\boldsymbol\phi}(\mathbf x)+\boldsymbol\Delta_g with EgΔg=0\E_g\boldsymbol\Delta_g=\mathbf 0, and Taylor-expand ℓ\ell in its first argument around w⊤ϕˉ\mathbf w^\top\bar{\boldsymbol\phi}:

  2. Eg ℓ(w⊤ϕ(gx),y)≈ℓ(w⊤ϕˉ(x),y)⏟averaged features+12 ℓ′′(w⊤ϕˉ(x),y)  w⊤Cov⁡g[ϕ(gx)] w⏟variance penalty\E_g\,\ell\big(\mathbf w^\top\boldsymbol\phi(g\mathbf x),y\big)\approx\underbrace{\ell\big(\mathbf w^\top\bar{\boldsymbol\phi}(\mathbf x),y\big)}_{\text{averaged features}}+\underbrace{\tfrac12\,\ell''\big(\mathbf w^\top\bar{\boldsymbol\phi}(\mathbf x),y\big)\;\mathbf w^\top\Cov_g\big[\boldsymbol\phi(g\mathbf x)\big]\,\mathbf w}_{\text{variance penalty}}

    The first-order term vanishes because EgΔg=0\E_g\boldsymbol\Delta_g=\mathbf 0. Evaluating ℓ′′\ell'' at the center leaves

  3. The first term trains on invariant features, equivalent to using the averaged kernel kˉ(x,x′)=Eg,g′k(gx,g′x′)\bar k(\mathbf x,\mathbf x')=\E_{g,g'}k(g\mathbf x,g'\mathbf x'). The second is a data-dependent Tikhonov penalty on how much the prediction varies across the orbit, weighted by the loss curvature, the same structure as dropout's Fisher-weighted penalty and mixup's R2R_2 term. Dao et al. used the approximation to train faster on augmented data and to predict, before training, whether a transformation will help.

Check your understanding

In the expansion of the augmented loss, why does the first-order term vanish?

  1. Because the loss is minimized, so its derivative ℓ′\ell' is zero
  2. Because the group is finite
  3. Because the deviations Δg=ϕ(gx)−ϕˉ(x)\boldsymbol\Delta_g=\boldsymbol\phi(g\mathbf x)-\bar{\boldsymbol\phi}(\mathbf x) average to zero over the group by construction
  4. Because the features are normalized to unit length
Show the answer

C. Because the deviations Δg=ϕ(gx)−ϕˉ(x)\boldsymbol\Delta_g=\boldsymbol\phi(g\mathbf x)-\bar{\boldsymbol\phi}(\mathbf x) average to zero over the group by construction

Expanding around the orbit mean makes the linear term proportional to EgΔg=0\E_g\boldsymbol\Delta_g=\mathbf 0, whatever ℓ′\ell' is. What survives at second order is the variance of the prediction across the orbit.

Architecture versus augmentation

Instead of teaching an invariance with data, one can build it into the model: convolutions are translation-equivariant by construction, group convolutions and steerable networks add rotations and reflections, and equivariant graph networks respect permutations and 3D symmetries (Rotation-Equivariant & Steerable CNNs, Equivariant Networks for 3D Geometry). For linear regression the benefit is exactly computable:

E[test error(w)−test error(wˉ)]=σξ2 dim⁡An−d−1>0\E\big[\text{test error}(\mathbf w)-\text{test error}(\bar{\mathbf w})\big]=\sigma_\xi^2\,\frac{\dim A}{n-d-1}>0
The gain grows with dim⁡A\dim A, how much of the model space the symmetry rules out; it diverges at the interpolation threshold n≈dn\approx d when w\mathbf w is not invariant, and for n<d−1n<d-1 an additional term appears even without noise. For permutations of the dd coordinates the invariant predictors are the multiples of 1\mathbf 1, so dim⁡A=d−1\dim A=d-1. With d=10d=10 and n=50n=50, least squares has excess risk σξ2 d/(n−d−1)=1039σξ2\sigma_\xi^2\,d/(n-d-1)=\tfrac{10}{39}\sigma_\xi^2, and symmetrizing removes 939σξ2\tfrac9{39}\sigma_\xi^2 of it: 90%.

Built-in invariance is exact for every input, costs no extra data or compute, and is the right choice when the symmetry is known and implementable. Augmentation is more flexible: it can express approximate symmetries and transformations that are not groups at all, such as crops, but enforces invariance only approximately and only near the data, at the price of more training.

Learning the augmentation. Augerino (Benton, Finzi, Izmailov & Wilson, 2020) learns how much invariance to impose. Transformations are sampled as g=exp⁡(∑iεiθiGi)g=\exp\big(\sum_i\varepsilon_i\theta_iG_i\big) with ε∼U[−1,1]k\varepsilon\sim U[-1,1]^k and generators GiG_i for translations, rotation, scalings and shear, so θi\theta_i is the range of each, and the objective is Eg∼μθℓ(fw(gx),y)−λ∥θ∥2\E_{g\sim\mu_\theta}\ell(f_{\mathbf w}(g\mathbf x),y)-\lambda\norm{\boldsymbol\theta}^2, minimized jointly over w\mathbf w and θ\boldsymbol\theta. The reward for width is needed because the training loss is flat inside the range of the data's true invariance and gives no push to widen it; with the reward, the ranges expand until the loss rises at the edge of the real symmetry. Predictions average over sampled transformations.

When the theory breaks

The theorems assume a group under which the data distribution, and the labels, are invariant. Practice violates this in several ways. Small rotations do not form a group (two 40° turns make 80°), and the label of a digit is invariant only under some of them: averaging over the full rotation group mislabels sixes and nines, adding bias that no variance reduction repays. Crops destroy information and cannot be undone, so they are not group actions; mixup transforms pairs of examples. And invariances can be class-dependent (Balestriero, Bottou & LeCun, 2022), while the theory assumes one group acting on all classes.

In deep networks, augmentation can also act through feature learning rather than through variance alone. Shen, Bubeck and Gunasekar (2022) showed, for a two-layer convolutional network on a "multi-view" data model, that augmentation changes which features are learned, favoring informative features that would otherwise be hard to learn, an effect stronger for nonlinear models than for linear ones.

Key takeaways

  • With a group GG acting on inputs, augmented training is ERM with the loss replaced by its orbit average EgL(θ,gx)\E_gL(\boldsymbol\theta,g\mathbf x); orbit averaging projects any function onto the invariant ones.
  • Under exact invariance, orbit averaging is conditioning on the orbit: it keeps means and removes the within-orbit variance (a Rao–Blackwell argument), so augmented estimators are never worse under convex losses and their asymptotic covariance shrinks by V−1EXCov⁡g∇L V−1V^{-1}\E_X\Cov_g\nabla L\,V^{-1} (Chen, Dobriban & Lee, 2020).
  • For linear models on features, augmentation is to second order training on orbit-averaged features plus a curvature-weighted penalty on the prediction's variance across the orbit (Dao et al., 2019).
  • Building the invariance into a linear model gains exactly σξ2dim⁡A/(n−d−1)\sigma_\xi^2\dim A/(n-d-1) in test error when n>d+1n>d+1 (Elesedy & Zaidi, 2021); augmentation trades exactness for flexibility, and its ranges can be learned (Augerino).
  • Label-changing, non-group and class-dependent transformations break the assumptions; approximate invariance adds bias, and augmentation also reshapes which features deep networks learn.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why is the orbit average fˉ(x)=Eg∼Qf(gx)\bar f(\mathbf x)=\E_{g\sim Q}f(g\mathbf x) invariant under the group?

  1. Because ff itself must already be invariant
  2. Because for any hh, the map g↦ghg\mapsto gh leaves the uniform distribution on GG unchanged, so fˉ(hx)\bar f(h\mathbf x) averages the same values
  3. Because averaging always produces constant functions
  4. Because the group has finitely many elements
Show the answer

B. Because for any hh, the map g↦ghg\mapsto gh leaves the uniform distribution on GG unchanged, so fˉ(hx)\bar f(h\mathbf x) averages the same values

fˉ(hx)=Egf(ghx)=Eg′f(g′x)=fˉ(x)\bar f(h\mathbf x)=\E_gf(gh\mathbf x)=\E_{g'}f(g'\mathbf x)=\bar f(\mathbf x) with g′=ghg'=gh. This works for any ff, which is why orbit averaging projects onto invariant functions.

Question 2

Under exact invariance, how does replacing a loss by its orbit average change it, at every parameter value?

  1. It lowers the expected loss and raises its variance
  2. It keeps both the expected loss and its variance
  3. It introduces a bias proportional to the size of the group
  4. It keeps the expected loss and lowers its variance, by the average within-orbit variance
Show the answer

D. It keeps the expected loss and lowers its variance, by the average within-orbit variance

The orbit average is a conditional expectation given the orbit, so the tower property keeps the mean and the law of total variance removes the within-orbit part. Bias appears only when the invariance is approximate.

Question 3

In Elesedy and Zaidi's theorem (Gaussian inputs, invariant linear target, n>d+1n>d+1), which change makes symmetrizing the least-squares estimate more valuable?

  1. A larger dim⁡A\dim A, the dimension of the predictors the symmetry rules out
  2. More training examples nn
  3. Less label noise σξ2\sigma_\xi^2
  4. A group whose invariant predictors span all of Rd\R^d
Show the answer

A. A larger dim⁡A\dim A, the dimension of the predictors the symmetry rules out

The gain is σξ2dim⁡A/(n−d−1)\sigma_\xi^2\dim A/(n-d-1): it grows with the number of directions the symmetry eliminates and with the noise, and shrinks as nn grows. A group that leaves every predictor invariant has dim⁡A=0\dim A=0 and gives nothing.

Question 4

Augerino learns the ranges θ\boldsymbol\theta of its transformations jointly with the weights. Why does its objective include a reward −λ∥θ∥2-\lambda\norm{\boldsymbol\theta}^2 for wide ranges?

  1. To make training faster
  2. Because without it the ranges would grow without bound
  3. Because inside the range of the data's true invariance the training loss is flat, so it gives no push toward wider augmentation; the reward supplies it, and the loss stops the expansion at the edge of the symmetry
  4. To keep the network's weights small
Show the answer

C. Because inside the range of the data's true invariance the training loss is flat, so it gives no push toward wider augmentation; the reward supplies it, and the loss stops the expansion at the edge of the symmetry

If the label really is invariant over a range, augmenting within it barely changes the training loss, so gradient descent has no reason to widen θ\boldsymbol\theta. A small reward for width expands it until augmentation starts to hurt the fit, which marks the boundary of the real invariance.

Further reading

  • S. Chen, E. Dobriban & J. H. Lee, "A group-theoretic framework for data augmentation," Journal of Machine Learning Research 21(245), 1–71 (2020).
  • T. Dao, A. Gu, A. Ratner, V. Smith, C. De Sa & C. Ré, "A kernel theory of modern data augmentation," ICML (2019).
  • B. Elesedy & S. Zaidi, "Provably strict generalisation benefit for equivariant models," ICML (2021).
  • G. Benton, M. Finzi, P. Izmailov & A. G. Wilson, "Learning invariances in neural networks from training data," NeurIPS (2020).
  • R. Shen, S. Bubeck & S. Gunasekar, "Data augmentation as feature manipulation," ICML (2022).