A13 · Lesson 38 · Optimization in one and several variables
Finding the lowest point, with and without derivatives
Choose resistor values to bring a filter's response closest to a template. Adjust a solar charger's operating voltage for maximum power. Tune a controller's gains to minimize overshoot, or a network's weights to minimize prediction error. Each is a minimization, and the methods mirror the root finders: a bracketing method that can't fail (golden-section search), derivative-based methods that are fast near the answer (gradient descent, Newton), and derivative-free ones for noisy measurements. The one new idea is the step size: too small and progress crawls, too large and the iteration oscillates or blows up.
- Gradient descent on the bowl from (1, 1), with a fixed step size η. The path joins the iterates .
- With a small η the path creeps down the gentle x direction. Raise η: the steep y direction starts to overshoot and zigzag, and past it diverges.
- The best fixed step, , balances the two directions; the error then shrinks by per step, the same as steepest descent's worst case.
Predict
A function's curvature (second derivative) along its steepest direction is 50. Above what fixed step size does gradient descent diverge?
0.04, which is 2/50. Along a direction with curvature λ, each step multiplies the error by , which passes −1 when . The step size is limited by the steepest direction, even when the slow direction needs big steps: that mismatch, κ, is what makes ill-conditioned problems slow.
Name it
One variable
- Golden-section search: with a bracket where is below both ends, evaluate at a point in the larger part and keep the sub-bracket that still has a low interior point. Placing points at the golden ratio shrinks the bracket by per evaluation, guaranteed for a unimodal f.
- Parabolic interpolation: fit a parabola through three points and jump to its vertex; superlinear near a smooth minimum. Brent's minimizer combines the two, as Brent's root finder does.
- Newton: find a zero of f′: .
A minimum's location can only be found to about relative accuracy (about 8 digits in double), because near it f changes only quadratically: falls below rounding when δ is about .
Several variables
- Gradient descent: . On a quadratic with Hessian eigenvalues from to , it's stable for , and the best fixed step gives the factor .
- Newton: solve with the Hessian H; quadratic convergence near a minimum, but each step needs second derivatives and a linear solve.
- Quasi-Newton (BFGS): build up an approximate Hessian from successive gradients; the usual choice for smooth problems of modest size.
- Derivative-free (Nelder–Mead, perturb-and-observe): compare function values only; slow but robust to noise, as when the "function" is a measurement.
If f is convex, any local minimum is the global one. Otherwise, start from several points.
Worked example
How many golden-section evaluations shrink a bracket of width 5 to ?
Show the solution
- Count the shrink factors. so 33 evaluations.
- Compare with bisection. That's slower than bisection for roots (0.5 per step), but it needs no derivatives and can't be fooled by a unimodal function.
Answer 33 evaluations.
Worked example
Minimize by Newton's method from x = 1.
Show the solution
- The derivatives.
- Newton's iterates. They are 1, 0.91667, 0.90863, 0.9085603, 0.908560296.
- The exact minimum. reached quadratically.
Answer the minimum is at .
Worked example
Minimize by gradient descent with the best fixed step. How fast does it converge?
Show the solution
- The Hessian. It is diag(2, 20).
- The best fixed step.
- The rate. The error then shrinks per step by
- Steps for six digits. and the path zigzags across the long, narrow valley.
- Better methods. Newton's method, which uses the Hessian, would finish this quadratic in one step; conjugate gradients in two.
Answer with the best fixed step, 0.091, the error shrinks by 0.818 per step, so six digits take 69 steps.
Check
How many golden-section evaluations shrink a bracket of width 5 below 0.001?
Check
A quadratic's largest Hessian eigenvalue is 50. Above what fixed step size does gradient descent diverge?
Check
A quadratic's Hessian eigenvalues run from 1 to 10. What's the best fixed gradient-descent step?
Check
One Newton step toward the minimum of from 1: what's the new x?
Check
To about what relative accuracy can a minimum's location be found in a 24-bit format?
Check
A solar charger must find its panel's maximum-power voltage from noisy power readings, with no formula for the panel. Which approach fits?
Check
Gradient descent with the best fixed step minimizes .
(a)
By what factor does the error shrink per step?
(b)
About how many steps gain 6 digits?
Check
A parabola goes through , , , with .
Step 1
Where is its minimum?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Explain why
Why does gradient descent with a fixed step converge slowly on an ill-conditioned problem?
Along each eigendirection of the Hessian, a fixed step multiplies the error by . The steepest direction, with the largest curvature , forces η below or the iteration diverges. With η that small, the gentlest direction, curvature , shrinks only by , which is close to 1 when . The best compromise still leaves a factor , close to 1 for large κ, so the number of steps grows in proportion to κ. Methods that use curvature (Newton, quasi-Newton, conjugate gradients) rescale the directions and avoid that dependence.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.