Phase 10 - Lesson 10.4

Algorithms: Gradient Descent and Newton's Method

How we actually minimize: first-order steps, second-order steps, and why conditioning matters.

⏱ 55 min● Intermediate🔗 Prereqs: 10.1, 10.2
↖ Phase 10 hub
Builds on: 10.2 gave optimality; now we compute the optimum.
Leads to: 10.5 runs these solvers on portfolio and regression objectives.

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

Gradient descent
The iteration \(x_{k+1}=x_k-t\,\nabla f(x_k)\); step downhill along the negative gradient.
Step size / learning rate
The scalar \(t\gt 0\); too large diverges, too small crawls; line search adapts it.
Strong convexity
There is \(\mu\gt 0\) with \(\nabla^2 f\succeq\mu I\); gives linear convergence.
Condition number
For a quadratic, \(\kappa=\lambda_{\max}/\lambda_{\min}\) of the Hessian; large \(\kappa\) means slow zig-zag descent.
Newton's method
The iteration \(x_{k+1}=x_k-[\nabla^2 f(x_k)]^{-1}\nabla f(x_k)\); uses curvature.
Quadratic convergence
Error squares each step (\(e_{k+1}\approx c\,e_k^2\)) near the optimum; Newton's hallmark.

Intuition & Motivation

Intuition
Gradient descent is hiking downhill by always stepping in the steepest direction - robust and cheap, but on a long narrow valley it zig-zags painfully (bad conditioning). Newton's method fits a local parabola using curvature (the Hessian) and jumps to its minimum; near the solution it doubles correct digits each step, but every step costs a linear solve. The engineering choice is first-order (cheap, scalable) versus second-order (few iterations, expensive per iteration).

Gradient descent

\[x_{k+1}=x_k - t_k\,\nabla f(x_k).\] (10.6)

With a fixed step \(t\le1/L\) (where \(L\) is the Lipschitz constant of \(\nabla f\), i.e. \(\nabla^2 f\preceq LI\)), and strong convexity \(\nabla^2 f\succeq\mu I\), the iterates converge linearly:

\[f(x_k)-f^\star\ \le\ \Big(1-\tfrac{\mu}{L}\Big)^{k}\big(f(x_0)-f^\star\big).\] (10.7)

The ratio \(\kappa=L/\mu\) is the condition number. When \(\kappa\) is large the factor \(1-1/\kappa\) is near 1 and convergence is slow - the classic zig-zag across a stretched bowl. Well-conditioned (\(\kappa\approx1\)) problems converge in a handful of steps.

Worked Example - Gradient descent on a quadratic
1
Minimize \(f(x)=\tfrac12 x^\top Q x-c^\top x\), \(Q\succ0\). Gradient \(\nabla f=Qx-c\), optimum \(x^\star=Q^{-1}c\).
2
Iteration: \(x_{k+1}=x_k-t(Qx_k-c)=(I-tQ)x_k+tc\).
3
Error \(e_k=x_k-x^\star\) evolves as \(e_{k+1}=(I-tQ)e_k\), so \(\|e_k\|\) shrinks by the spectral radius of \(I-tQ\).
4
Optimal fixed step \(t=2/(\lambda_{\min}+\lambda_{\max})\) gives contraction factor \((\kappa-1)/(\kappa+1)\) - slow when \(\kappa\gg1\).

Newton's method

\[x_{k+1}=x_k-\big[\nabla^2 f(x_k)\big]^{-1}\nabla f(x_k).\] (10.8)

Newton minimizes the local second-order Taylor model exactly. On a pure quadratic it reaches \(x^\star=Q^{-1}c\) in one step (the model is exact). Near a smooth minimum with \(\nabla^2 f^\star\succ0\), convergence is quadratic: the number of correct digits roughly doubles per iteration. The price is forming and solving \(\nabla^2 f\,\Delta x=-\nabla f\) (cost \(O(n^3)\)) each step.

MethodInfo usedPer-step costSteps to converge
Gradient descent\(\nabla f\)\(O(n)\) (plus grad)Many; \(\propto\kappa\log(1/\epsilon)\)
Newton\(\nabla f,\ \nabla^2 f\)\(O(n^3)\) solveFew; quadratic locally

Interactive: watch the zig-zag

Common Mistakes to Avoid
  • Choosing a step \(t\gt 2/L\); gradient descent then diverges (overshoots the bowl).
  • Blaming the algorithm for slow convergence when the real culprit is a large condition number \(\kappa\); precondition or rescale instead.
  • Using Newton far from the optimum without safeguards (line search / trust region); the raw step can overshoot or head uphill.
  • Inverting the Hessian explicitly. Solve the linear system \(\nabla^2 f\,\Delta x=-\nabla f\) instead.
Quant Practitioner Tips
  • Normalize/scale features so \(\kappa\) is small - often the biggest practical speedup for first-order methods.
  • Use Newton (or quasi-Newton like BFGS) when \(n\) is moderate and high accuracy is needed; gradient methods when \(n\) is huge.
  • Backtracking line search makes both methods robust with almost no tuning.

Practice this in the Euler Lab

Computational problems that exercise exactly this technique. Each opens in the Euler Lab with a Python workbench, a progressive hint ladder, and answer checking. Tier A/B run at full scale in the browser.

Warm-up:
#39 Integer Right Triangles (2%, tier A) #11 Largest Product in a Grid (5%, tier A) #44 Pentagon Numbers (6%, tier A) #18 Maximum Path Sum I (7%, tier A)

Applied:
#485 Maximum Number of Divisors (19%, tier B) #190 Maximising a Weighted Product (21%, tier B) #183 Maximum Product of Parts (23%, tier B)

Challenge:
#869 Prime Guessing (41%, tier C) #143 Torricelli Triangles (43%, tier C)

73 Project Euler problems in total are mapped to this lesson. Open the Euler Lab to filter them all.

Knowledge Check

Q1 Medium
For a strongly convex \(f\), gradient descent with a suitable fixed step converges:
Sublinearly
Linearly, at rate depending on \(\kappa=L/\mu\)
Quadratically
Not at all
Q2 Medium
Newton's method on a strictly convex QUADRATIC converges in:
Infinitely many steps
One step
Two steps
\(\kappa\) steps
Q3 Easy
A large condition number \(\kappa\) primarily makes gradient descent:
Diverge
Zig-zag and converge slowly
Converge quadratically
Ignore the gradient

Practical Exercise

For \(f(x)=\tfrac12 x^\top Q x-c^\top x\) with \(Q=\diag(1,100)\), \(c=(1,1)^\top\): (a) What is \(\kappa\)? (b) With optimal fixed step, what contraction factor does gradient descent achieve? (c) How many Newton steps are needed?

▶ Show full solution

(a) \(\kappa=\lambda_{\max}/\lambda_{\min}=100/1=100\).

(b) Contraction factor \((\kappa-1)/(\kappa+1)=99/101\approx0.980\) - each step cuts the error by only about 2%, so roughly \(\sim\kappa\log(1/\epsilon)\) iterations are needed.

(c) One. The objective is quadratic, so Newton reaches \(x^\star=Q^{-1}c=(1,\,0.01)^\top\) in a single step, independent of \(\kappa\).

After the reveal, answer for yourself: Why does Newton's step count ignore \(\kappa\) while gradient descent's scales with it?

Lesson Summary

Gradient descent \(x_{k+1}=x_k-t\nabla f(x_k)\) is cheap and scalable but converges linearly at a rate set by the condition number \(\kappa\), zig-zagging on ill-conditioned problems. Newton's method \(x_{k+1}=x_k-[\nabla^2 f]^{-1}\nabla f\) uses curvature for local quadratic convergence (one step on a quadratic) at \(O(n^3)\) per iteration. Conditioning, step size, and per-step cost drive the choice between them.

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: State the gradient-descent convergence rate for strongly convex \(f\).
A: \(f(x_k)-f^\star\le(1-\mu/L)^k(f(x_0)-f^\star)\) - linear, slower as the condition number \(\kappa=L/\mu\) grows.
Q: Contrast Newton and gradient descent in one line each.
A: Newton: uses the Hessian, quadratic local convergence, \(O(n^3)\)/step. Gradient descent: uses only the gradient, linear convergence, cheap per step.

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.