2.2 Unconstrained Methods

DATA 442/642 · Week 2 · PDF · Slides

Line search, steepest descent, momentum, and SGD.

These notes walk through the lecture slides. The original deck is unchanged; use (slides) on the course hub if you want that PDF.

The figures follow Deisenroth, Faisal, and Ong, Mathematics for Machine Learning.

1. Line search

Draw x, predict ypred, score the mismatch with J, take the gradient, and step against it.

Gradient step

Almost every method in this note is

θ(k+1)=θ(k)+α(k)𝐬(k).
  1. Pick a direction 𝐬(k).
  2. Pick a step α(k) (learning rate) that lowers J(θ(k)+α𝐬(k)) in α.
  3. Take the step.

A direction is a descent direction when 𝐬⊤∇J<0. Steepest descent (gradient descent) uses 𝐬=−∇J.

Following the negative gradient


2. Why steepest descent zigzags

Steepest descent can be slow. The step length matters, and the asymptotic rate is worse than Newton-type methods. On a long thin valley the problem is poorly conditioned: −∇J points into the walls, almost orthogonal to the short path to the min. Exact line search still hops.

Well-conditioned versus poorly conditioned contours

See it on a quadratic. Let

J(θ)=12θ⊤𝐐θ−C

with 𝐐 symmetric positive definite. Diagonalize 𝐐=𝐔Λ𝐔⊤. In coordinates 𝐳=𝐔⊤θ, minimizing J is the same as minimizing ∑iλizi2. In two dimensions the contours are ellipses

λ1z12+λ2z22=c.

The axis ratio is the condition number of 𝐐 (largest over smallest eigenvalue). Large condition number: a long thin valley, tiny progress.

Slow zigzag on a poorly scaled bowl


3. Momentum

Remember the last step and refuse to turn on a dime (Rumelhart et al., 1986):

θ(k+1)=θ(k)−α(k)∇J(θ(k))+βΔθ(k), Δθ(k)=θ(k)−θ(k−1)=βΔθ(k−1)−α(k−1)∇J(θ(k−1)),

with β∈[0,1]. A heavy ball in a valley: oscillations damp, progress along the floor improves. Noisy gradients benefit because the memory averages them. Stochastic approximations of ∇J are the usual case, not a special case.


4. SGD and mini-batches

If J=∑n=1NJn, batch gradient descent uses the full sum. That is expensive when N is large and there is no closed form for ∇J.

SGD uses one term (or a random subset) as a noisy stand-in for ∇J. With a decaying step size, SGD converges almost surely to a local min under mild assumptions.

Mini-batch gradient descent sits in between: a random subset, not one row and not all N. Still an unbiased estimate of the true gradient. Cheaper than batch, less noisy than one-row SGD.

Batch, SGD, and mini-batch paths

Why accept an approximate gradient?

Mini-batch What you buy What you pay
Large Accurate ∇J, stable steps, fast matrix kernels Each step is expensive; easy to sit in a sharp hole
Small Cheap steps; noise can leave a bad local min; often enough for generalization Higher variance in the updates

Memory and wall-clock are the practical reasons. Mini-batch size is a sample size for an empirical mean.


5. Practice

  1. What does a large condition number do to steepest descent?

  2. Write the descent test 𝐬⊤∇J<0 in words. Why does 𝐬=−∇J pass it whenever you are not already at a critical point?

  3. Name one reason to prefer a small mini-batch over a large one, and one reason for the opposite.