Optimization Algorithms

GATE Relevance: Medium

Prerequisites

🎯 Learning Objectives

  • Distinguish batch, stochastic, and mini-batch gradient descent
  • Understand momentum and Nesterov momentum
  • Derive AdaGrad, RMSProp, and Adam update rules
  • Compare optimizers in a summary table
  • Know when to apply learning rate scheduling

1. Gradient Descent Variants

Vanilla Gradient Descent Update

θ ← θ − η · ∇θ J(θ)

Batch Gradient Descent

Computes the gradient using the entire training set:

∇J = (1/N) ∑i=1N ∇Ji
  • Pro: Stable convergence, exact gradient.
  • Con: Very slow for large datasets; requires loading all data into memory.

Stochastic Gradient Descent (SGD)

Uses one random sample per update:

θ ← θ − η · ∇Ji(θ)
  • Pro: Fast updates; can escape local minima due to noise.
  • Con: High variance in gradient estimate; noisy convergence.

Mini-Batch Gradient Descent

Uses a small batch of B samples (typically B = 32, 64, 128, 256):

θ ← θ − η · (1/B) ∑i=1B ∇Ji(θ)
  • Best of both worlds: Lower variance than SGD, faster than full batch.
  • Can leverage GPU parallelism for the batch matrix operations.

2. Momentum

SGD with Momentum

vt = β · vt−1 + η · ∇J(θt)
θt+1 = θt − vt

Typical β = 0.9

Intuition: The velocity v accumulates past gradients like a ball rolling downhill. This accelerates movement along consistent gradient directions and dampens oscillations in others.

Nesterov Accelerated Gradient (NAG)

vt = β · vt−1 + η · ∇J(θt − β · vt−1)
θt+1 = θt − vt

Key difference: NAG computes the gradient at the “look-ahead” position (θ − βv), giving a more accurate gradient estimate and slight improvement in convergence.

3. AdaGrad (Adaptive Gradient)

AdaGrad Update Rule

gt = ∇J(θt)
Gt = Gt−1 + gt ⊙ gt    (accumulate squared gradients)
θt+1 = θt − η / (√Gt + ε) ⊙ gt

ε ≈ 10−8 (for numerical stability)

Pro: Adapts learning rate per-parameter; works well for sparse gradients. Con: Learning rate monotonically decreases (G only grows), eventually stopping learning.

4. RMSProp

RMSProp Update Rule

gt = ∇J(θt)
E[g²]t = γ · E[g²]t−1 + (1 − γ) · gt ⊙ gt
θt+1 = θt − η / (√E[g²]t + ε) ⊙ gt

Typical γ = 0.9, η = 0.001

Key fix over AdaGrad: Uses an exponentially decaying average of squared gradients instead of accumulating them all. This prevents the learning rate from shrinking to zero.

5. Adam (Adaptive Moment Estimation)

Adam combines momentum (first moment) with RMSProp (second moment) and adds bias correction.

Adam Update Rule (Complete)

gt = ∇J(θt)

// First moment estimate (mean of gradients)
mt = β1 · mt−1 + (1 − β1) · gt

// Second moment estimate (mean of squared gradients)
vt = β2 · vt−1 + (1 − β2) · gt ⊙ gt

// Bias correction
m̂t = mt / (1 − β1t)
v̂t = vt / (1 − β2t)

// Parameter update
θt+1 = θt − η · m̂t / (√v̂t + ε)

Default hyperparameters: β1 = 0.9, β2 = 0.999, ε = 10−8, η = 0.001

Why Bias Correction?

m and v are initialised at 0. In early steps, they are biased toward 0. Division by (1 − βt) corrects this. As t → ∞, the correction factor → 1 and has no effect.

6. Optimizer Comparison

OptimizerAdaptive LR?Uses Momentum?Key FeatureBest For
Batch GDNoNoExact gradientSmall datasets, convex
SGDNoNoFast, noisy updatesGeneral purpose
SGD+MomentumNoYesAccelerated convergenceMost DL tasks
NAGNoYesLook-ahead gradientWhen momentum overshoots
AdaGradYesNoPer-param LRSparse data (NLP)
RMSPropYesNoDecaying avg of grad²RNNs, non-stationary
AdamYesYesMomentum + RMSPropDefault choice

7. Learning Rate Scheduling

A fixed learning rate is often suboptimal. Common strategies:

  • Step Decay: Reduce η by a factor every N epochs (e.g., η → η/10 every 30 epochs).
  • Exponential Decay: ηt = η0 · e−λt
  • Cosine Annealing: ηt = ηmin + ½(ηmax − ηmin)(1 + cos(πt/T))
  • Warm-up: Start with a very small η and linearly increase for the first few epochs (common in transformer training).

Summary

  • Mini-batch SGD is the standard; batch size is a key hyperparameter.
  • Momentum accelerates convergence by accumulating past gradients.
  • AdaGrad adapts per-parameter but can die (LR → 0).
  • RMSProp fixes AdaGrad with exponential decay of squared gradients.
  • Adam = Momentum + RMSProp + bias correction. Default choice (β1=0.9, β2=0.999).
  • For GATE: know the update rules, especially Adam’s complete formulation.