Part VII · coda · the continuous cousin
Gradients and momentum, projections and linear oracles, and the KKT conditions, which turn out to be the LP duality you already own.
needs 03 (and 02)~1½ h slides + 2 h lablab: uv run co lab 29
29 · overview
Convex sets and functions, smoothness and strong convexity, subgradients.
Gradient descent, heavy ball, Nesterov; rates and a lower bound; stochastic gradients.
Projected gradient; Frank–Wolfe, with your simplex method inside.
The optimality conditions, and why for an LP they are unit 03.
Words with a dotted underline are glossary terms: click one for its definition. G lists every term in the unit, N shows the notes. Optional extra: interactive figures, linked from the slides they support by a small ▸ chip; skip them freely.
section 1
Local information that is global.
29 · convexity
$f(\theta x + (1-\theta) y) \le \theta f(x) + (1-\theta) f(y)$. For differentiable $f$, equivalently
$$f(y) \ge f(x) + \nabla f(x)^\top (y - x)$$The tangent plane is a global under-estimator, so $\nabla f(x) = 0$ means a global minimum.
Any $g$ with $f(y) \ge f(x) + g^\top(y - x)$ for all $y$. Unit 11's Lagrangian dual is concave and non-smooth, and subgradient ascent used exactly this.
| property | definition | for $\frac12 x^\top Q x$ |
|---|---|---|
| $L$-smooth | $\|\nabla f(x) - \nabla f(y)\| \le L \|x - y\|$ | $L = \lambda_{\max}(Q)$ |
| $\mu$-strongly convex | $f(y) \ge f(x) + \nabla f(x)^\top(y-x) + \frac\mu2 \|y-x\|^2$ | $\mu = \lambda_{\min}(Q)$ |
| condition number | $\kappa = L / \mu$ | eigenvalue spread |
$L$ bounds how far a gradient step can safely go (step $1/L$). $\mu$ bounds how flat the bottom can be. Their ratio $\kappa$ decides how many steps you need.
Example: $f = \tfrac12(x^2 + 10y^2)$ has $Q = \mathrm{diag}(1, 10)$, so $L = 10$, $\mu = 1$, $\kappa = 10$: a valley ten times steeper across than along.
Lab step 1 also builds the gradient check that every later unit relies on: central differences, error $O(h^2)$.
section 2
Only gradients, and how far that gets you.
29 · first-order
| method | update | rate, $L$-smooth convex | rate, strongly convex |
|---|---|---|---|
| GD, step $1/L$ | $x - \frac1L \nabla f(x)$ | $\frac{L R^2}{2k}$ | $(1 - \frac1\kappa)^k$ |
| heavy ball (Polyak 1964) | $+\ \beta(x_k - x_{k-1})$ | no general guarantee | $(\frac{\sqrt\kappa - 1}{\sqrt\kappa + 1})^k$ on quadratics |
| Nesterov (1983) | gradient at $x_k + \frac{k-1}{k+2}(x_k - x_{k-1})$ | $\frac{2 L R^2}{(k+1)^2}$ | $(1 - \frac{1}{\sqrt\kappa})^k$ with constant momentum |
$R = \|x_0 - x^*\|$. Heavy ball and Nesterov add momentum; $(1-\frac1\kappa)^k$ is linear convergence. Lab tests check GD's and Nesterov's bounds at every iterate on 12 quadratics.
Any method whose iterates lie in the span of past gradients has, on some $L$-smooth convex function, error $\Omega(L R^2 / k^2)$ for $k \le n/2$. Nesterov's method is optimal up to constants.
Its optimal parameters need $\mu$ and $L$, and outside quadratics it can fail to converge at all (Lessard, Recht & Packard 2016 give a smooth strongly convex example).
29 · first-order · example
$f(x, y) = \tfrac12(x^2 + 10y^2)$, gradient $(x,\ 10y)$, $L = 10$, $\mu = 1$. Start at $(1, 1)$, $f = 5.5$.
| $k$ | point | $f$ |
|---|---|---|
| 0 | $(1, 1)$ | 5.5 |
| 1 | $(0.9, 0)$ | 0.405 |
| 2 | $(0.81, 0)$ | 0.328 |
| 3 | $(0.729, 0)$ | 0.266 |
Each step multiplies $x$ by $1 - \tfrac1L = 0.9$ and $y$ by $1 - \tfrac{10}{L} = 0$. The steep direction is solved at once; the flat one crawls at $1 - \tfrac1\kappa$ per step.
| $k$ | point | $f$ |
|---|---|---|
| 0 | $(1, 1)$ | 5.5 |
| 1 | $(0.81, -0.9)$ | 4.38 |
| 2 | $(0.656, 0.81)$ | 3.50 |
| 3 | $(0.531, -0.729)$ | 2.80 |
A bigger step helps $x$ (factor 0.81) but makes $y$ bounce across the valley (factor $-0.9$). Past $2/L$ it would diverge. This zig-zag is what momentum damps.
29 · first-order
Lab then, quadratics with n = 100 (relative suboptimality):
| κ | GD | heavy ball | Nesterov | CG | L-BFGS |
|---|---|---|---|---|---|
| 100 | 760 | 52 | 435 | 103 | 94 |
| 10 000 | > 20 000 | 542 | 12 048 | 1 329 | 749 |
Predicted: GD 917 and 92 099; heavy ball 46 and 461. Nesterov's worst-case bound is 140 043 and 1.3 million: loose by two orders of magnitude.
Rosenbrock to within 1e−6 of the minimum: GD 34 374, Nesterov 5 019, BFGS 34.
Plot: out/convergence.png.
section 3
Project, or ask a linear oracle.
29 · constraints
$x_{k+1} = \Pi_C(x_k - \frac1L \nabla f(x_k))$, with projection $\Pi_C$. Same rates as GD, if projecting is cheap. Onto the simplex: sort, prefix sums, a threshold, $O(n \log n)$ (lab step 3).
$s_k = \arg\min_{s \in C} \nabla f(x_k)^\top s$ (an LP), then $x_{k+1} = x_k + \frac{2}{k+2}(s_k - x_k)$.
Lab then, least squares on the simplex, n = 200, f − f*:
| method | 100 it. | 1 000 it. | 5 000 it. |
|---|---|---|---|
| projected gradient | 6.9e−4 | 8.8e−11 | at solver precision |
| Frank–Wolfe | 1.0e−1 | 3.5e−3 | 1.9e−4 |
Over a random polytope (n = 30), your simplex method as the oracle cost 2.1 ms per call, HiGHS 1.2 ms, with identical iterates.
Frank–Wolfe is where the two halves of this course meet: a continuous loop whose inner step is a combinatorial optimisation. Over matroid, flow or matching polytopes, the oracle is units 13–15.
29 · constraints · example
Find the point of $\{x \ge 0,\ x_1 + x_2 + x_3 \le 1\}$ closest to $p = (0.8,\ 0.6,\ -0.2)$: minimize $f(x) = \tfrac12\|x - p\|^2$.
Sorted: $0.8, 0.6, -0.2$. Keep the top two and shift them down equally until they sum to 1: $\theta = (0.8 + 0.6 - 1)/2 = 0.2$.
$p - 0.2 = (0.6,\ 0.4,\ -0.4)$, negatives clipped to 0: $\Pi(p) = (0.6,\ 0.4,\ 0)$, with $f = 0.06$.
Keeping all three would need $\theta = (1.2 - 1)/3 = 0.2/3$ and leave the third coordinate negative, so two is right.
| $k$ | $x_k$ | $x_k - p$ | $s_k$ | gap | $f$ |
|---|---|---|---|---|---|
| 0 | $(0, 0, 0)$ | $(-0.8, -0.6, 0.2)$ | $(1, 0, 0)$ | 0.80 | 0.52 |
| 1 | $(1, 0, 0)$ | $(0.2, -0.6, 0.2)$ | $(0, 1, 0)$ | 0.80 | 0.22 |
| 2 | $(\tfrac13, \tfrac23, 0)$ | $(-0.47, 0.07, 0.2)$ | $(1, 0, 0)$ | 0.36 | 0.13 |
The oracle just picks the most negative gradient entry: a corner. Steps $\tfrac22$, then $\tfrac23$. The gap always bounds $f - f^* $: at $k = 2$, $0.13 - 0.06 = 0.07 \le 0.36$.
section 4
You already know these.
29 · KKT
$\min f(x)$ s.t. $g_i(x) \le 0$, with $f$, $g_i$ convex and a Slater point (Slater's condition). $x^*$ is optimal iff there are multipliers $\lambda \ge 0$ with the KKT conditions
$$\begin{aligned} &\nabla f(x^*) + \textstyle\sum_i \lambda_i \nabla g_i(x^*) = 0 \\ &g_i(x^*) \le 0,\ \ \lambda_i \ge 0 \\ &\lambda_i\, g_i(x^*) = 0 \end{aligned}$$Karush (1939); Kuhn & Tucker (1951). With linear constraints no Slater point is needed. The lines are stationarity, feasibility and complementarity.
For $\max c^\top x$, $Ax \le b$, $x \ge 0$: multipliers $y \ge 0$ for $Ax \le b$ and $w \ge 0$ for $-x \le 0$. Stationarity: $c = A^\top y - w$, so $w = A^\top y - c \ge 0$: dual feasibility. Complementarity: $y_i (b - Ax)_i = 0$ and $x_j (A^\top y - c)_j = 0$: complementary slackness, exactly unit 03's certificate.
Lab then, HiGHS on an LP with m = 30, n = 50: residuals 3.6e−13, 0, 3.3e−13, 1.8e−13. Unit 03's exact certificate rejects the same pair rounded to 9 decimals: "primal constraint 12 violated".
"Optimal" means "KKT residuals below a tolerance". Every solver has one. An exact certificate needs exact arithmetic, as unit 03 used.
29 · KKT · example
$\max 2x + y$ over $x + y \le 4$, $x - y \le 1$, $x, y \ge 0$. Optimum $(2.5, 1.5)$, value 6.5. Try multipliers $y = (1.5,\ 0.5)$ on the two constraints.
| condition | on the example | |
|---|---|---|
| primal feasible | $4 \le 4$, $\ 1 \le 1$, $\ x, y \ge 0$ | ✓ |
| stationarity (dual feasible) | $1.5\,(1,1) + 0.5\,(1,-1) = (2, 1) = c$ | ✓ |
| complementarity, constraints | both constraints tight: slack 0 × price | ✓ |
| complementarity, variables | $x, y > 0$ and their reduced costs are 0 | ✓ |
At the corner $(1, 0)$: constraint $x + y \le 4$ has slack 3 but price 1.5. Complementarity residual $1.5 \times 3 = 4.5$. Everything else is fine.
So KKT rejects $(1, 0)$ for exactly the reason unit 03's certificate would: a priced constraint with room left.
The multipliers $1.5$ and $0.5$ are unit 02's shadow prices: loosening $x + y \le 4$ by one unit raises the optimum by 1.5. In the continuous world they are called Lagrange multipliers, and they are the same numbers.
29 · lab
uv run co test 29
uv run co then 29 # rates vs scipy · Rosenbrock · simplex least squares · FW over a polytope · KKT
29 · checkpoint
Boyd & Vandenberghe, Convex Optimization (2004), ch. 5, 9.
Nesterov, Lectures on Convex Optimization (2018).
Bubeck, Found. Trends ML 8 (2015).
Jaggi, ICML 2013.
30 automatic differentiation: where the gradients come from · 31 where discrete meets differentiable.