Part VII · coda · the continuous cousin

29

Convexity, gradients, and what continuity changes

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

The route

1 · convexity

Convex sets and functions, smoothness and strong convexity, subgradients.

2 · first-order methods

Gradient descent, heavy ball, Nesterov; rates and a lower bound; stochastic gradients.

3 · constraints

Projected gradient; Frank–Wolfe, with your simplex method inside.

4 · KKT

The optimality conditions, and why for an LP they are unit 03.

getting around

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

Convexity

Local information that is global.

29 · convexity

Convex, smooth, strongly convex

convex function

$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.

subgradient

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.

propertydefinitionfor $\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

First-order methods

Only gradients, and how far that gets you.

29 · first-order

Gradient descent, momentum, and the lower bound

methodupdaterate, $L$-smooth convexrate, 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.

lower bound (Nemirovski & Yudin 1983; Nesterov)

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.

heavy ball's catch

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

Gradient steps, on a κ = 10 quadratic

$f(x, y) = \tfrac12(x^2 + 10y^2)$, gradient $(x,\ 10y)$, $L = 10$, $\mu = 1$. Start at $(1, 1)$, $f = 5.5$.

step 1/L = 0.1
$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.

step 0.19, just under 2/L
$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

Measured: iterations to 1e−8

Lab then, quadratics with n = 100 (relative suboptimality):

κGDheavy ballNesterovCGL-BFGS
1007605243510394
10 000> 20 00054212 0481 329749

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.

  • Tuned heavy ball wins, and isn't a fair entry: it was given μ and L.
  • Nesterov's convex schedule is ahead of GD to 1e−8, but its tail flattens: at κ = 100, GD catches up near machine precision. That schedule doesn't use strong convexity.
  • CG and L-BFGS build curvature from gradients and need no parameters. On quadratics CG is optimal among Krylov methods.

Plot: out/convergence.png.

section 3

Constraints

Project, or ask a linear oracle.

29 · constraints

Projected gradient and Frank–Wolfe

projected gradient

$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).

Frank–Wolfe (1956)

$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)$.

  • No projection, only a linear oracle: your unit-02 simplex method.
  • A free certificate, the Frank–Wolfe gap: $g_k = \nabla f(x_k)^\top(x_k - s_k) \ge f(x_k) - f^*$.
  • Rate $O(LD^2/k)$, and no faster in general.

Lab then, least squares on the simplex, n = 200, f − f*:

method100 it.1 000 it.5 000 it.
projected gradient6.9e−48.8e−11at solver precision
Frank–Wolfe1.0e−13.5e−31.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.

the handshake

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

Projection and Frank–Wolfe, on one point

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$.

projection onto the simplex, in one shot

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.

Frank–Wolfe from the origin
$k$$x_k$$x_k - p$$s_k$gap$f$
0$(0, 0, 0)$$(-0.8, -0.6, 0.2)$$(1, 0, 0)$0.800.52
1$(1, 0, 0)$$(0.2, -0.6, 0.2)$$(0, 1, 0)$0.800.22
2$(\tfrac13, \tfrac23, 0)$$(-0.47, 0.07, 0.2)$$(1, 0, 0)$0.360.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

KKT

You already know these.

29 · KKT

The KKT conditions, and the LP case

$\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.

the LP case

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".

in floating point

"Optimal" means "KKT residuals below a tolerance". Every solver has one. An exact certificate needs exact arithmetic, as unit 03 used.

29 · KKT · example

KKT, on unit 01's polygon

$\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.

the four checks
conditionon 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, constraintsboth constraints tight: slack 0 × price✓
complementarity, variables$x, y > 0$ and their reduced costs are 0✓
the same multipliers at a wrong point

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

Lab 29 — what you build

about 2 hours · uv run co lab 29
  1. Test functions and a central-difference gradient check.
  2. Gradient descent, heavy ball, Nesterov.
  3. Projection onto the simplex, and projected gradient.
  4. Frank–Wolfe with your unit-02 simplex method as the oracle.
  5. KKT residuals for LPs and QPs.
uv run co test 29
uv run co then 29     # rates vs scipy · Rosenbrock · simplex least squares · FW over a polytope · KKT

29 · checkpoint

Done when

checkpoint
  • All five lab steps are ✓.
  • You can derive the KKT conditions for a linear program and show they reduce exactly to complementary slackness from unit 03.
  • You can say when Frank–Wolfe beats projected gradient, and when it doesn't.

Reading

Boyd & Vandenberghe, Convex Optimization (2004), ch. 5, 9.
Nesterov, Lectures on Convex Optimization (2018).
Bubeck, Found. Trends ML 8 (2015).
Jaggi, ICML 2013.

Next

30 automatic differentiation: where the gradients come from · 31 where discrete meets differentiable.