Skip to content
BIASED

Stochastic and adaptive optimizers

The minibatch gradient and its noise, the noise ball of a constant step and decreasing steps, momentum and Nesterov with noisy gradients, the per-coordinate steps of AdaGrad, RMSProp and Adam with its bias correction, and what each of them leaves unfixed.

A gradient from a sample

Gradient descent uses the full gradient at each step. For Q(w)=1n∑iℓi(w)Q(w)=\frac1n\sum_i\ell_i(w), a uniformly sampled example gives an unbiased gradient estimate at a fixed ww. Averaging BB independent draws with replacement gives

E[g]=∇Q(w),Cov⁡(g)=Σ(w)/B.E[g]=\nabla Q(w),\qquad \operatorname{Cov}(g)=\Sigma(w)/B.

Here Σ(w)\Sigma(w) is the covariance of one sampled example's gradient. The gradient RMSE is tr⁡Σ(w)/B\sqrt{\operatorname{tr}\Sigma(w)/B}, not proportional to 1/B1/B. Stochastic gradient descent uses w←w−ηgw\leftarrow w-\eta g at cost roughly O(Bd)O(Bd) instead of O(nd)O(nd).

For a uniform batch without replacement at fixed weights, multiply that covariance by (n−B)/(n−1)(n-B)/(n-1). During a shuffled epoch, the current weights and later batches depend on earlier choices; the independent-draw proof does not apply unchanged.

On the original 240-row sensor fixture, standardize the eight inputs and centre the target for a fixed training objective. At zero weights, 6000 independent batches give gradient RMSE 28.99,10.05,3.5428.99,10.05,3.54 for B=1,8,64B=1,8,64. Exact finite-dataset predictions are 28.47,10.07,3.5628.47,10.07,3.56. Seed 20261114 controls batch sampling; these are synthetic training calculations.

The noise ball

Unbiased gradients can remain noisy at the optimum. Consider Q(w)=λw2/2Q(w)=\lambda w^2/2 with stochastic gradient λw+ξk\lambda w+\xi_k, where each new noise is independent, mean zero and variance s2s^2. For a constant step,

wk+1=(1−ηλ)wk−ηξk.w_{k+1}=(1-\eta\lambda)w_k-\eta\xi_k.

If 0<ηλ<20<\eta\lambda<2, the mean decays and the variance follows

Vk+1=(1−ηλ)2Vk+η2s2,V∞=ηs2λ(2−ηλ).V_{k+1}=(1-\eta\lambda)^2V_k+\eta^2s^2,\qquad V_\infty=\frac{\eta s^2}{\lambda(2-\eta\lambda)}.

With persistent noise, a smaller stable step reduces the limiting variance. Within the nonoscillating range 0<ηλ≤10<\eta\lambda\le1, it also slows the mean's approach. The expected loss is λ(E[wk]2+Vk)/2\lambda(E[w_k]^2+V_k)/2; it is not the loss of each sampled trajectory.

For λ=s=1\lambda=s=1, w0=2w_0=2 and 240 steps, exact expectation propagation gives losses 0.0319150.031915 at step 0.120.12, 0.0063400.006340 at step 0.0250.025, and 0.0039040.003904 for ηk=0.12/(1+k/30)\eta_k=0.12/(1+k/30) starting at k=0k=0. No Monte Carlo estimate is involved. If every per-example gradient vanishes at a shared optimum, this persistent-noise model no longer applies; constant-step convergence can then be possible under suitable stability assumptions.

Decreasing steps and schedules

For standard stochastic-approximation guarantees, a common step requirement is

∑kηk=∞,∑kηk2<∞.\sum_k\eta_k=\infty,\qquad\sum_k\eta_k^2<\infty.

The first prevents the available movement from ending too soon; the second controls accumulated noise. A positive schedule proportional to 1/k1/k meets both. These sums alone do not prove convergence: assumptions on the objective, noise and iterates also matter. For a strongly convex objective on a convex feasible set, unbiased stochastic gradients with bounded second moment, projected updates and a suitable schedule, weighted averaging yields an O(1/k)O(1/k) expected excess-loss bound. This is not a guarantee for arbitrary networks.

A finite budget needs an experiment. On the synthetic sensor fixture, all methods start at zero and train for 40 epochs with shuffled batches of 24. Five shared seeds 400–404 control permutations. SGD with η=0.15\eta=0.15 has mean training excess loss 0.1160.116; cutting the step tenfold after 20 epochs gives 0.0290.029. At η=0.03\eta=0.03, both results round to 0.0350.035. Reducing the step too early can obstruct progress along a flat direction.

This compares training optimization under a fixed budget. It does not measure generalization or establish a universal best schedule.

Momentum with noisy gradients

Momentum accumulates a velocity:

vk+1=βvk+gk,wk+1=wk−ηvk+1.v_{k+1}=\beta v_k+g_k,\qquad w_{k+1}=w_k-\eta v_{k+1}.

For a constant gradient and 0≤β<10\le\beta<1, velocity approaches g/(1−β)g/(1-\beta). Thus η/(1−β)\eta/(1-\beta) describes the effective step in a sustained direction. It is not a universal formula for stationary noise when gradients depend on the changing weights.

On an exact strongly convex quadratic, carefully tuned heavy-ball parameters can improve the asymptotic dependence from the condition number κ\kappa to κ\sqrt\kappa. The error may increase temporarily; this does not promise a decrease at each step. Nesterov's method evaluates a gradient at a look-ahead point and has suitable smooth strongly convex guarantees. Those assumptions must travel with the rate.

In our 40-epoch sensor experiment, momentum with β=0.9\beta=0.9, η=0.015\eta=0.015 gives mean excess loss 0.0540.054, or 0.0300.030 with the halfway cut. The learning rate, momentum and schedule work together. Replacing them with a single “effective step” does not prove two algorithms have identical noise.

A step per coordinate: AdaGrad and RMSProp

Coordinates may see gradients on very different scales. AdaGrad tracks every squared gradient:

Gk=Gk−1+gk2,wk+1=wk−ηgkGk+ε.G_k=G_{k-1}+g_k^2,\qquad w_{k+1}=w_k-\frac{\eta g_k}{\sqrt{G_k}+\varepsilon}.

Operations are coordinatewise. A rarely active coordinate accumulates less history and can keep a larger effective step. For a constant nonzero scalar gradient cc, Gk=kc2G_k=kc^2, so with negligible ε\varepsilon the update magnitude is η/k\eta/\sqrt{k}. This statement concerns the update, not a guarantee about the loss.

RMSProp replaces the cumulative sum by recent history:

vk=ρvk−1+(1−ρ)gk2.v_k=\rho v_{k-1}+(1-\rho)g_k^2.

It divides by the square root of that moving average, with a small stabilizer. Forgetting old squared gradients prevents the denominator from growing forever merely because training continues. It also means history is no longer monotone. Neither accumulator is the full Hessian; per-coordinate scaling cannot generally remove correlations between coordinates.

Adam and its bias correction

Adam combines a moving mean of gradients with a moving mean of their squares. Starting from m0=v0=0m_0=v_0=0, at step k≥1k\ge1 compute

mk=β1mk−1+(1−β1)gk,vk=β2vk−1+(1−β2)gk2.m_k=\beta_1m_{k-1}+(1-\beta_1)g_k,\qquad v_k=\beta_2v_{k-1}+(1-\beta_2)g_k^2.

Correct the initialization bias and update:

m^k=mk1−β1k,v^k=vk1−β2k,wk=wk−1−ηm^kv^k+ε.\hat m_k=\frac{m_k}{1-\beta_1^k},\quad\hat v_k=\frac{v_k}{1-\beta_2^k},\quad w_k=w_{k-1}-\eta\frac{\hat m_k}{\sqrt{\hat v_k}+\varepsilon}.

With a stationary gradient mean, the uncorrected first moment has expectation multiplied by 1−β1k1-\beta_1^k; the analogous second-moment calculation explains its correction. This removes the zero-initialization factor, not every source of statistical bias.

At the first step, m^1=g1\hat m_1=g_1 and v^1=g12\hat v_1=g_1^2. A nonzero scalar gradient therefore gives update −ηg1/(∣g1∣+ε)-\eta g_1/(|g_1|+\varepsilon), approximately −ηsign⁡(g1)-\eta\operatorname{sign}(g_1) when the stabilizer is negligible. Large and small gradients can initially produce similar-sized coordinate updates. This is not a guarantee that their coordinates reach a good solution equally quickly.

What is fixed and what is not

SGD makes gradient steps cheaper. Momentum remembers direction. Adaptive methods use coordinatewise gradient history. None of these operations validates the model or removes the need to choose a learning rate.

For the same 40-epoch synthetic experiment, Adam with η=0.003\eta=0.003 gives mean training excess loss 21.15521.155, while η=0.1\eta=0.1 gives 0.0450.045. Cutting the smaller step halfway worsens the result to 28.62028.620: too little progress is not repaired by making the step even smaller. These are finite-budget measurements with shared permutations, not a general superiority claim.

Adam has counterexamples to general convergence, and diagonal scaling has no universal condition-number rate. On neural networks, use held-out evidence rather than transferring a convex theorem without its assumptions. The optional notebook reproduces the original fixture, checks gradients by finite differences and executes the first Adam step. It uses no external data or downloaded weights.

Next, Regularization changes the objective to control unstable fits. The reviewed source note retains primary algorithm references and theorem conditions. New calculations and assessment were prepared for the Fedor Pakhurov project with Codex assistance.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • Optimizers: noise and a finite budgetoptional

    Compare batch noise and SGD, momentum and Adam training; separately compute the exact expectation of a noisy scalar recurrence.

    ~25 min · easier on a computer · The matching course topic has been read.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.