Numerical Optimization and Gradient Descent
Most of this course chases discrete optima over finite structures; here the search space is continuous and the objective is differentiable. The gradient points uphill, so stepping against it — — walks downhill.
╌╌╌╌
Almost every optimization in this course has been discrete: pick the best subset, the shortest path, the cheapest spanning tree, the longest common subsequence. The search space is finite (if astronomically large), and the tools are combinatorial — exchange arguments, dynamic programming, network flow. This lesson changes the setting. The variable ranges over , a continuum, and the objective is a smooth, differentiable function we want to minimize. There is no finite set to enumerate and no subproblem table to fill. Instead we use calculus: the derivative tells us which way is downhill, and we keep stepping that way. This method underlies curve fitting, logistic regression, and the training of every neural network, and it rests on the gradient.
The continuous problem
We are given a differentiable and want a point where is smallest:
In one dimension, calculus says a minimum of a smooth occurs where the slope vanishes, , and the curve bends upward, . In dimensions the slope becomes a vector, the gradient
and a minimum requires . Solving in closed form is possible only for the simplest (a quadratic gives a linear system). For everything else we need an iterative method that starts somewhere and improves, step by step. Every such method starts from the geometry of the gradient.
The gradient points uphill
Fix a point and ask: among all unit directions , which one increases the fastest? The first-order Taylor expansion answers it. Moving a small distance along ,
so the rate of change in direction is the inner product . By Cauchy–Schwarz this is largest when aligns with and most negative when points the opposite way. So the gradient is the direction of steepest ascent, and its negation is the direction of steepest descent. The gradient is also perpendicular to the level curve through the point: along the level curve does not change, so the steepest-change direction must be orthogonal to it.
Gradient descent
The algorithm follows directly. Start at any . At each step, move a little in the steepest-descent direction:
where is the learning rate (or step size). Each step strictly decreases for small enough , because the first-order change is . We stop when the gradient is nearly zero — the slope has flattened, and we are at (or near) a stationary point.
- 1
- 2while donot yet flat
- 3steepest-ascent direction
- 4step downhill
- 5return
The method has one free parameter, and it matters.
If is too small, the iterates creep toward the minimum, needing huge numbers of steps. If is too large, a step can jump clear over the valley floor and land higher than it started; successive overshoots then bounce between the walls, oscillating, or spiral outward and diverge. Much of first-order optimization comes down to choosing (or adapting) .
Worked example (three learning rates on a parabola). Minimize , for which and the update is — each step multiplies the iterate by the fixed contraction factor . Starting from , the behaviour is decided entirely by :
- gives : the iterates shrink steadily to — healthy convergence.
- gives : still converges, but oscillates in sign, overshooting the minimum each step before creeping in.
- gives : grows without bound — the step is so large it lands farther from the minimum each time, and the method diverges.
The threshold is exactly here (so that ); more generally, for an -smooth objective the safe range is , and is the textbook choice. The condition is a one-line preview of why the strong-convexity rate below is geometric: a fixed multiplicative shrink per step.
Convexity, and why local is global
Gradient descent finds a point where the gradient vanishes — a stationary point. For a general nonconvex that could be a local minimum, a saddle, or a poor local optimum far from the best value. Convexity eliminates this problem.
A convex function is a single bowl with no false bottoms, so local information determines the global optimum.
So on a convex objective, gradient descent's walk downhill until flat
cannot get trapped:
the only flat spot is the bottom.
A convergence guarantee
How fast does gradient descent reach the bottom? The answer depends on two regularity constants. We say is -smooth if its gradient does not change too abruptly, — equivalently is bounded above by a quadratic of curvature . We say is -strongly convex if it is bounded below by a quadratic of curvature (a bowl that curves at least as much as ). With these two constants the rate is classical.
To reach error , the convex case needs steps, while
the strongly convex case needs only — exponentially fewer. The
condition number is the elongation of the bowl: a round bowl () converges in a few steps; a long thin valley ( large) makes gradient descent
zig-zag slowly down the narrow axis. Contrast this with the discrete optimization of the
rest of the course, where rate
is measured in the input size (see
asymptotic analysis); here the iteration count
depends on the conditioning of and the target accuracy , not on a
combinatorial size.
Stochastic gradient descent
In machine learning the objective is an average over data, , where is the loss on the -th of training examples. The exact gradient sums per-example gradients — one full sweep over the dataset per step, which is ruinous when is in the millions. Stochastic gradient descent (SGD) replaces the full gradient with a cheap, noisy estimate from a small random mini-batch :
Each step costs gradients, so SGD takes vastly more, vastly cheaper steps. The mini-batch gradient is an unbiased estimate of the true gradient, so on average it points downhill; the variance is noise that jitters the path.
Second order: Newton's method
Gradient descent uses only the slope. Newton's method also uses the curvature — the matrix of second derivatives, the Hessian — to take a better-scaled step. Approximate near by its second-order Taylor expansion (a quadratic) and jump straight to that quadratic's minimum. Setting the gradient of the approximation to zero gives
Where gradient descent crawls down a long thin valley, Newton's method rescales by the curvature and heads straight for the bottom — and on a quadratic it reaches the exact minimum in one step. Near a minimum its convergence is quadratic: the number of correct digits roughly doubles each iteration.
- 1
- 2while do
- 3gradient
- 4Hessian (curvature)
- 5solve , then step
- 6return
The cost per step is high. Each step forms the Hessian and solves a linear system with it, costing (or memory just to store ) — prohibitive for the high-dimensional problems of machine learning. And the quadratic convergence is only local: started far away, Newton's step can overshoot wildly. Practical solvers therefore use quasi-Newton methods (BFGS), which approximate from successive gradients, and add a line search or trust region for global safety.
One dimension: Newton–Raphson and bisection
The cleanest case of Newton's method is root-finding in one variable: solve . Replacing the Hessian with the scalar derivative, the update becomes the classic Newton–Raphson iteration
Geometrically, follow the tangent at down to where it crosses the axis, and take that crossing as the next guess. (Minimizing is finding a root of ; this is the same iteration applied to the derivative.) It converges quadratically when it converges — computing as a root of gives the famous , doubling correct digits each step. Sqrt(x) asks for this iteration verbatim.
Newton–Raphson is fast but fragile: a near-zero derivative sends the tangent nearly horizontal and flings the next guess far away, and a bad start may not converge at all. When robustness matters more than speed, use bisection. If is continuous and changes sign across an interval — that is, and have opposite signs — the intermediate value theorem guarantees a root inside. Test the midpoint, keep the half-interval that still brackets the sign change, and repeat. The bracket halves every step.
Bisection converges linearly — one bit of accuracy per step, steps to width — slower than Newton's quadratic doubling, but it cannot fail on a continuous sign-changing function. It is, in disguise, the monotone binary search behind the discrete answer-search problems Koko Eating Bananas and Minimize Max Distance to Gas Station: a feasibility predicate is monotone in the answer, so bracket the threshold and halve. The robust strategy in practice is hybrid — Newton steps when they stay inside the bracket, a bisection step as a safe fallback when they do not.1
Modern optimizers and neural-network training
The optimizers that actually train modern models are refinements of plain gradient descent.
Momentum and adaptive rates. The zig-zag down a long thin valley (large condition number ) is the central weakness of vanilla gradient descent. Momentum damps it by accumulating a velocity, , , so consistent directions build speed while oscillating ones cancel; Nesterov's accelerated gradient sharpens this to the optimal rate for smooth convex , a provable improvement over the derived above.2 Adaptive methods — AdaGrad, RMSProp, and especially Adam — give each coordinate its own effective step size from a running estimate of gradient magnitudes, which is why Adam is the default optimizer for deep networks.3 All of them are still ; only the step changes.
Backpropagation is the chain rule. Training a neural network minimizes a loss over millions of parameters , and gradient descent needs . The gradient is computed by backpropagation — the multivariate chain rule applied in reverse across the network's computation graph — which yields all partial derivatives in a single backward pass costing the same order as one forward evaluation. This is reverse-mode automatic differentiation, and it is what makes gradient descent tractable in millions of dimensions where forming the Hessian for Newton's method (the cost above) is infeasible.4
Non-convex reality. The clean local is global
guarantee holds only for convex
; neural-network losses are highly non-convex. Several
empirical facts explain why training still works: in very high dimension most critical points are saddles, not bad
local minima, and the stochastic noise of SGD helps the iterate slip off them; and
the many minima that do exist tend to have similar loss values, so finding a good
one suffices. Understanding why first-order methods succeed on non-convex deep
networks remains an active research question, but the working answer — SGD plus
momentum plus a well-tuned schedule — trains essentially every model in use today.
Takeaways
- Continuous optimization minimizes a differentiable over with calculus, not enumeration. The gradient is the steepest-ascent direction and is orthogonal to level sets; its negation points downhill.
- Gradient descent iterates . The learning rate is the one critical parameter: too small is slow, too large overshoots and diverges.
- Convexity makes every local minimum global, so
descend until flat
finds the true optimum. For convex -smooth the rate is ; under -strong convexity it is geometric, steps with . - Stochastic gradient descent estimates from a random mini-batch — far cheaper, noisier steps; the noise/speed trade-off and step decay make it the standard method for neural-network training.
- Newton's method uses the Hessian for quadratic local convergence but costs per step; in 1-D it is Newton–Raphson root-finding, with bisection the robust linear-time bracketing fallback.1
Footnotes
- Skiena, § — Numerical Problems / Optimization, and CLRS, Ch. — Newton's method for root-finding: gradient descent, Newton–Raphson, and bisection, and the trade-off between fast-but-fragile and slow-but-robust convergence. ↩ ↩2
- Y. Nesterov,
A method of solving a convex programming problem with convergence rate ,
Soviet Mathematics Doklady 27, 1983; and Nesterov, Introductory Lectures on Convex Optimization, Springer, 2004. ↩ - D. P. Kingma and J. Ba,
Adam: A method for stochastic optimization,
ICLR 2015; J. Duchi, E. Hazan, Y. Singer,Adaptive subgradient methods,
JMLR 12, 2011 (AdaGrad). ↩ - D. E. Rumelhart, G. E. Hinton, R. J. Williams,
Learning representations by back-propagating errors,
Nature 323, 1986 — backpropagation as reverse-mode differentiation for training neural networks. ↩
╌╌ END ╌╌