Simple Algorithm
Machine Learning · Descent · 24 min

Convexity & Duality

Why convex problems are tractable, and the power of the dual.

Least squares, logistic regression, the lasso and the support vector machine look like four different problems, but they share the property that makes them tame: they are convex. On a convex problem every local minimum is a global one, a zero gradient proves optimality, and every constraint comes with a price that a second, dual problem computes. This lesson builds that toolkit, from the definition of a convex set to the dual of the support vector machine.

What you’ll learn

  • Define convex sets and functions, and test convexity with the first- and second-order conditions and with the operations that preserve it.
  • Prove that every local minimum of a convex function is global, and explain what strict and strong convexity add.
  • Classify the standard machine learning objectives by convexity, smoothness and strong convexity, and handle nonsmooth ones with subgradients.
  • Form the Lagrangian and the dual of a constrained problem, prove weak duality, and read the KKT conditions on a worked example and on the support vector machine.

Convex sets and convex functions

Training a model means choosing parameters w∈Rd\mathbf w\in\R^d that minimize an objective f(w)f(\mathbf w), usually an empirical risk plus a penalty. Whether that is easy or hard depends less on the dimension dd than on the shape of ff.

A set C⊆RdC\subseteq\R^d is a convex set if it contains the segment between any two of its points: θx+(1−θ)y∈C\theta\mathbf x+(1-\theta)\mathbf y\in C whenever x,y∈C\mathbf x,\mathbf y\in C and θ∈[0,1]\theta\in[0,1]. Balls, half-spaces {x:a⊤x≤b}\{\mathbf x:\mathbf a^\top\mathbf x\le b\}, polyhedra and the cone of positive semidefinite matrices are convex; a ring-shaped region, or the set of vectors with at most kk nonzero entries, is not. Intersections of convex sets are convex, so a problem with many convex constraints still has a convex feasible set.

Building block or ruleWhy it is convex
Affine a⊤x+b\mathbf a^\top\mathbf x+bequality holds in the definition; affine functions are exactly those that are both convex and concave
Any norm ∥x∥\norm{\mathbf x}triangle inequality plus homogeneity: ∥θx+(1−θ)y∥≤θ∥x∥+(1−θ)∥y∥\norm{\theta\mathbf x+(1-\theta)\mathbf y}\le\theta\norm{\mathbf x}+(1-\theta)\norm{\mathbf y}
x⊤Qx\mathbf x^\top Q\mathbf x with Q⪰0Q\succeq0its Hessian 2Q2Q is positive semidefinite
Log-sum-exp log⁡∑iexi\log\sum_ie^{x_i}Hessian diag⁡(p)−pp⊤⪰0\diag(\mathbf p)-\mathbf p\mathbf p^\top\succeq0 with p=softmax⁡(x)\mathbf p=\softmax(\mathbf x): the covariance matrix of a random one-hot vector drawn with probabilities p\mathbf p
−log⁡x-\log x on x>0x>0; eaxe^{ax}second derivatives 1/x21/x^2 and a2eaxa^2e^{ax} are nonnegative
Nonnegative sums; f(Ax+b)f(A\mathbf x+\mathbf b); max⁡ifi(x)\max_if_i(\mathbf x); inf⁡yg(x,y)\inf_{\mathbf y}g(\mathbf x,\mathbf y)each preserves convexity (the last needs gg jointly convex in (x,y)(\mathbf x,\mathbf y))
Almost every convex objective in this course is assembled from these pieces by these rules, so checking convexity is usually a matter of recognizing the assembly rather than computing a Hessian.
Check your understanding

Which of these objectives is not convex in w\mathbf w? (The first three are for a single example (x,y)(\mathbf x,y).)

  1. The logistic loss log⁡(1+e−y w⊤x)\log\big(1+e^{-y\,\mathbf w^\top\mathbf x}\big), with y∈{−1,+1}y\in\{-1,+1\}
  2. The hinge loss max⁡(0, 1−y w⊤x)\max\big(0,\,1-y\,\mathbf w^\top\mathbf x\big), with y∈{−1,+1}y\in\{-1,+1\}
  3. The squared error of a sigmoid output, (y−σ(w⊤x))2\big(y-\sigma(\mathbf w^\top\mathbf x)\big)^2, with y∈{0,1}y\in\{0,1\}
  4. The lasso objective ∥Xw−y∥22+λ∥w∥1\norm{X\mathbf w-\mathbf y}_2^2+\lambda\norm{\mathbf w}_1
Show the answer

C. The squared error of a sigmoid output, (y−σ(w⊤x))2\big(y-\sigma(\mathbf w^\top\mathbf x)\big)^2, with y∈{0,1}y\in\{0,1\}

Take y=1y=1 and write z=w⊤xz=\mathbf w^\top\mathbf x. Then h(z)=(1−σ(z))2h(z)=(1-\sigma(z))^2 has h′′(z)=−2σ(z)(1−σ(z))2(1−3σ(z))h''(z)=-2\sigma(z)\big(1-\sigma(z)\big)^2\big(1-3\sigma(z)\big), which is negative whenever σ(z)<1/3\sigma(z)<1/3: the function is concave there and flattens out as z→−∞z\to-\infty. That is one reason logistic regression is fitted with the log loss rather than with squared error. The other three are convex by the rules above: a convex function of an affine map, a maximum of affine functions, and a convex quadratic plus a norm.

Local minima are global

For differentiable functions, convexity has a geometric form that underlies everything that follows:

f(y) ≥ f(x)+∇f(x)⊤(y−x)for all x,y.f(\mathbf y)\ \ge\ f(\mathbf x)+\nabla f(\mathbf x)^\top(\mathbf y-\mathbf x)\qquad\text{for all }\mathbf x,\mathbf y.

Every tangent plane is a global under-estimator: the first-order Taylor expansion never lies above the function. For twice-differentiable ff on an open convex domain, convexity is equivalent to a positive semidefinite Hessian, ∇2f(x)⪰0\nabla^2f(\mathbf x)\succeq0 everywhere, and μ\mu-strong convexity to ∇2f(x)⪰μI\nabla^2f(\mathbf x)\succeq\mu I, or equivalently to a quadratic lower bound

f(y) ≥ f(x)+∇f(x)⊤(y−x)+μ2∥y−x∥2.f(\mathbf y)\ \ge\ f(\mathbf x)+\nabla f(\mathbf x)^\top(\mathbf y-\mathbf x)+\tfrac\mu2\norm{\mathbf y-\mathbf x}^2.
DerivationProof
  1. f(x+θ(y−x))≤(1−θ)f(x)+θf(y)<f(x)(0<θ≤1)f\big(\mathbf x+\theta(\mathbf y-\mathbf x)\big)\le(1-\theta)f(\mathbf x)+\theta f(\mathbf y)<f(\mathbf x)\qquad(0<\theta\le1)

    Suppose x\mathbf x is a local minimum but some y\mathbf y has f(y)<f(x)f(\mathbf y)<f(\mathbf x). Move a fraction θ\theta of the way toward y\mathbf y; convexity bounds the value there:

  2. f(y) ≥ f(x⋆)+∇f(x⋆)⊤(y−x⋆)=f(x⋆)for all yf(\mathbf y)\ \ge\ f(\mathbf x^\star)+\nabla f(\mathbf x^\star)^\top(\mathbf y-\mathbf x^\star)=f(\mathbf x^\star)\qquad\text{for all }\mathbf y

    Letting θ→0\theta\to0 produces points arbitrarily close to x\mathbf x with smaller values, contradicting local minimality, so no such y\mathbf y exists. If ∇f(x⋆)=0\nabla f(\mathbf x^\star)=\mathbf 0, the first-order condition gives global optimality directly:

  3. f(x)−f⋆ ≤ ∥∇f(x)∥22μ,∥x−x⋆∥ ≤ ∥∇f(x)∥μf(\mathbf x)-f^\star\ \le\ \frac{\norm{\nabla f(\mathbf x)}^2}{2\mu},\qquad\norm{\mathbf x-\mathbf x^\star}\ \le\ \frac{\norm{\nabla f(\mathbf x)}}{\mu}

    For strictly convex ff, the midpoint of two distinct minimizers would have a strictly smaller value, which is impossible. Strong convexity gives quantitative versions: minimizing the quadratic lower bound over y\mathbf y, and pairing it with the same bound at x⋆\mathbf x^\star, turns a small gradient into a certificate of near-optimality.

The first inequality is the Polyak–Łojasiewicz inequality, which Convergence Rates of Gradient Descent turns into a linear rate. Without convexity none of this holds: a zero gradient can sit at a saddle point or at a poor local minimum.

The convex objectives of machine learning

Regularized empirical risk minimization has the form

F(w)=1n∑i=1nℓ(w⊤xi, yi)+λ Ω(w).F(\mathbf w)=\frac1n\sum_{i=1}^n\ell\big(\mathbf w^\top\mathbf x_i,\,y_i\big)+\lambda\,\Omega(\mathbf w).

If the loss is convex in its first argument and the penalty Ω\Omega is convex, FF is convex in w\mathbf w: each term is a convex function of an affine map, and nonnegative sums preserve convexity. That one observation covers most of classical machine learning. What differs from model to model is whether FF is also smooth (its gradient is LL-Lipschitz, ∇2F⪯LI\nabla^2F\preceq LI) and strongly convex, and those two constants set how fast gradient methods converge (Gradient Descent).

ObjectiveConvexSmoothStrongly convex
Least squares 12n∥Xw−y∥2\frac1{2n}\norm{X\mathbf w-\mathbf y}^2yesL=λmax⁡(X⊤X)/nL=\lambda_{\max}(X^\top X)/nonly if XX has full column rank: μ=λmin⁡(X⊤X)/n\mu=\lambda_{\min}(X^\top X)/n
Ridge: add λ2∥w∥2\frac\lambda2\norm{\mathbf w}^2yesL=λmax⁡(X⊤X)/n+λL=\lambda_{\max}(X^\top X)/n+\lambdaalways, with μ=λmin⁡(X⊤X)/n+λ≥λ\mu=\lambda_{\min}(X^\top X)/n+\lambda\ge\lambda
Logistic, y∈{−1,+1}y\in\{-1,+1\}: 1n∑ilog⁡(1+e−yiw⊤xi)\frac1n\sum_i\log\big(1+e^{-y_i\mathbf w^\top\mathbf x_i}\big)yesL≤λmax⁡(X⊤X)/(4n)L\le\lambda_{\max}(X^\top X)/(4n)not in general; on separable data there is no minimizer
Hinge 1n∑imax⁡(0,1−yiw⊤xi)\frac1n\sum_i\max\big(0,1-y_i\mathbf w^\top\mathbf x_i\big)yesno: kinks at margin 11no; adding λ2∥w∥2\frac\lambda2\norm{\mathbf w}^2 (the SVM) gives μ=λ\mu=\lambda
Lasso 12n∥Xw−y∥2+λ∥w∥1\frac1{2n}\norm{X\mathbf w-\mathbf y}^2+\lambda\norm{\mathbf w}_1yesno: kinks where wj=0w_j=0only if XX has full column rank, so never when d>nd>n
Neural network lossesnoat best locallyno
λmax⁡\lambda_{\max} and λmin⁡\lambda_{\min} are extreme eigenvalues, and their ratio sets the condition number κ=L/μ\kappa=L/\mu. A convex objective can still be slow to optimize when it is badly conditioned or nonsmooth; the rest of this topic is about those two difficulties.
DerivationWhy the logistic loss is convex and smooth
  1. ℓ′(z)=−(1−σ(z)),ℓ′′(z)=σ(z)(1−σ(z))∈(0,14]\ell'(z)=-\big(1-\sigma(z)\big),\qquad\ell''(z)=\sigma(z)\big(1-\sigma(z)\big)\in\big(0,\tfrac14\big]

    Write z=y w⊤xz=y\,\mathbf w^\top\mathbf x with y∈{−1,+1}y\in\{-1,+1\} and ℓ(z)=log⁡(1+e−z)\ell(z)=\log(1+e^{-z}). Its derivatives involve the sigmoid σ(z)=1/(1+e−z)\sigma(z)=1/(1+e^{-z}):

  2. ∇2F(w)=1n∑i=1nσ(zi)(1−σ(zi)) xixi⊤=1nX⊤DX,D=diag⁡(σ(zi)(1−σ(zi)))\nabla^2F(\mathbf w)=\frac1n\sum_{i=1}^n\sigma(z_i)\big(1-\sigma(z_i)\big)\,\mathbf x_i\mathbf x_i^\top=\frac1nX^\top DX,\qquad D=\diag\big(\sigma(z_i)(1-\sigma(z_i))\big)

    By the chain rule, and because y2=1y^2=1, each example adds a rank-one curvature term weighted by how uncertain the model is about it:

  3. 0 ⪯ ∇2F(w) ⪯ λmax⁡(X⊤X)4n I0\ \preceq\ \nabla^2F(\mathbf w)\ \preceq\ \frac{\lambda_{\max}(X^\top X)}{4n}\,I

    The weights lie in (0,14](0,\frac14], so the Hessian is sandwiched as below: convex, with L=λmax⁡(X⊤X)/(4n)L=\lambda_{\max}(X^\top X)/(4n). But the weights vanish for confidently classified points (∣zi∣→∞\abs{z_i}\to\infty), so there is no uniform μ>0\mu>0. On linearly separable data FF keeps decreasing along a separating direction and has no minimizer at all.

Subgradients: optimality without derivatives

The hinge loss and the ℓ1\ell_1 norm have kinks where no gradient exists. Convexity supplies a replacement. A vector g\mathbf g is a subgradient of a convex ff at x\mathbf x if the linear function it defines is a global under-estimator,

f(y) ≥ f(x)+g⊤(y−x)for all y,f(\mathbf y)\ \ge\ f(\mathbf x)+\mathbf g^\top(\mathbf y-\mathbf x)\qquad\text{for all }\mathbf y,

and the subdifferential ∂f(x)\partial f(\mathbf x) is the set of all of them. Where ff is differentiable, ∂f(x)={∇f(x)}\partial f(\mathbf x)=\{\nabla f(\mathbf x)\}. At a kink it is a whole set: ∂∣w∣={sign⁡w}\partial\abs w=\{\sign w\} for w≠0w\ne0 but [−1,1][-1,1] at w=0w=0, and the hinge h(z)=max⁡(0,1−z)h(z)=\max(0,1-z) has ∂h(1)=[−1,0]\partial h(1)=[-1,0].

DerivationSoft thresholding: the lasso in one dimension
  1. z−w ∈ λ ∂∣w∣z-w\ \in\ \lambda\,\partial\abs w

    Minimize 12(w−z)2+λ∣w∣\frac12(w-z)^2+\lambda\abs w over w∈Rw\in\R, with λ>0\lambda>0. Fermat's rule asks for 0∈w−z+λ ∂∣w∣0\in w-z+\lambda\,\partial\abs w:

  2. w⋆={z−λ,z>λ0,∣z∣≤λz+λ,z<−λw^\star=\begin{cases}z-\lambda, & z>\lambda\\ 0, & \abs z\le\lambda\\ z+\lambda, & z<-\lambda\end{cases}

    Try each piece. If w>0w>0, then z−w=λz-w=\lambda, so w=z−λw=z-\lambda, which is consistent only when z>λz>\lambda. Symmetrically, w=z+λw=z+\lambda when z<−λz<-\lambda. And w=0w=0 works exactly when z∈λ[−1,1]z\in\lambda[-1,1]:

  3. Sλ(z)=sign⁡(z) (∣z∣−λ)+S_\lambda(z)=\sign(z)\,\big(\abs z-\lambda\big)_+

    Compactly, this is soft thresholding. A whole interval of inputs maps to exactly zero because the subdifferential at the kink is a whole interval. This is the mechanism behind the lasso's sparsity, and SλS_\lambda is the proximal operator of λ∣⋅∣\lambda\abs{\cdot}, the building block of Proximal & Projected Methods.

Predict before you look

With λ=0.8\lambda=0.8, what does soft thresholding return for z=2.5z=2.5?

Show the answer

1.7

z>λz>\lambda, so w⋆=z−λ=1.7w^\star=z-\lambda=1.7: shrunk toward zero by exactly λ\lambda. Any ∣z∣≤0.8\abs z\le0.8, such as z=0.6z=0.6, returns exactly 00. A ridge penalty λ2w2\frac\lambda2w^2 would instead return z/(1+λ)z/(1+\lambda), a proportional shrink that is never exactly zero unless zz is.

To minimize a nonsmooth convex function directly, the subgradient method steps along any negative subgradient, xt+1=xt−ηtgt\mathbf x_{t+1}=\mathbf x_t-\eta_t\mathbf g_t. It is not a descent method: for f(x)=∣x1∣+2∣x2∣f(\mathbf x)=\abs{x_1}+2\abs{x_2} at (1,0)(1,0), the vector (1,2)(1,2) is a valid subgradient, and a step of size η≤1\eta\le1 along it raises ff to 1+3η1+3\eta. What it does guarantee is progress in distance to the minimizer, and with constant steps η=R/(GT)\eta=R/(G\sqrt T) the averaged iterate satisfies f(xˉT)−f⋆≤RG/Tf(\bar{\mathbf x}_T)-f^\star\le RG/\sqrt T, where R≥∥x1−x⋆∥R\ge\norm{\mathbf x_1-\mathbf x^\star} and GG bounds the subgradients. That is far slower than gradient descent on smooth problems, and Lower Bounds & Oracle Complexity proves that no first-order method can do better on the class of all Lipschitz convex functions.

Constraints, multipliers and the dual

Many learning problems carry constraints: a budget on the weights, nonnegativity, a margin requirement. The standard form is

minimize f0(x)subject tofi(x)≤0  (i=1,…,m),hj(x)=0  (j=1,…,p),\text{minimize }f_0(\mathbf x)\quad\text{subject to}\quad f_i(\mathbf x)\le0\ \ (i=1,\dots,m),\qquad h_j(\mathbf x)=0\ \ (j=1,\dots,p),

with optimal value p⋆p^\star. It is a convex problem when f0,…,fmf_0,\dots,f_m are convex and every hjh_j is affine. The Lagrangian folds the constraints into the objective with multipliers λi≥0\lambda_i\ge0 and νj∈R\nu_j\in\R (in this step λ\boldsymbol\lambda denotes multipliers, not a penalty strength), and minimizing it over x\mathbf x gives the dual function qq:

L(x,λ,ν)=f0(x)+∑i=1mλifi(x)+∑j=1pνjhj(x),q(λ,ν)=inf⁡xL(x,λ,ν).\mathcal L(\mathbf x,\boldsymbol\lambda,\boldsymbol\nu)=f_0(\mathbf x)+\sum_{i=1}^m\lambda_if_i(\mathbf x)+\sum_{j=1}^p\nu_jh_j(\mathbf x),\qquad q(\boldsymbol\lambda,\boldsymbol\nu)=\inf_{\mathbf x}\mathcal L(\mathbf x,\boldsymbol\lambda,\boldsymbol\nu).
DerivationWeak duality in two lines
  1. q(λ,ν) ≤ L(x~,λ,ν) ≤ f0(x~)q(\boldsymbol\lambda,\boldsymbol\nu)\ \le\ \mathcal L(\tilde{\mathbf x},\boldsymbol\lambda,\boldsymbol\nu)\ \le\ f_0(\tilde{\mathbf x})

    Take any feasible x~\tilde{\mathbf x} and any λ≥0\boldsymbol\lambda\ge\mathbf 0. Each λifi(x~)≤0\lambda_if_i(\tilde{\mathbf x})\le0 and each hj(x~)=0h_j(\tilde{\mathbf x})=0, so the Lagrangian undercuts the objective there:

  2. d⋆ ≤ p⋆(weak duality)d^\star\ \le\ p^\star\qquad\text{(weak duality)}

    Minimizing the right side over feasible points shows that every dual value bounds the optimum from below. The best bound is the dual problem, d⋆=max⁡λ≥0, νq(λ,ν)d^\star=\max_{\boldsymbol\lambda\ge\mathbf 0,\,\boldsymbol\nu}q(\boldsymbol\lambda,\boldsymbol\nu). Since qq is an infimum of functions affine in (λ,ν)(\boldsymbol\lambda,\boldsymbol\nu), it is concave: the dual is a convex problem even when the primal is not. This is the duality theory in miniature.

Predict before you look

Maximize the dual function q(λ)=λ−λ2/4q(\lambda)=\lambda-\lambda^2/4 over λ≥0\lambda\ge0. At which λ⋆\lambda^\star is the best lower bound reached?

Show the answer

2

q′(λ)=1−λ/2=0q'(\lambda)=1-\lambda/2=0 at λ⋆=2\lambda^\star=2, where q(2)=1=p⋆q(2)=1=p^\star: no duality gap. The pair satisfies the KKT conditions below, stationarity 2x⋆−λ⋆=02x^\star-\lambda^\star=0 and complementary slackness λ⋆(1−x⋆)=0\lambda^\star(1-x^\star)=0. And λ⋆\lambda^\star is a price: requiring x≥1+ux\ge1+u raises the optimal value (1+u)2(1+u)^2 at rate 2=λ⋆2=\lambda^\star for small uu.

Complementary slackness says that a constraint that is not tight carries zero price. For the support vector machine that is the whole story. With labels yi∈{−1,+1}y_i\in\{-1,+1\}, the hard-margin SVM solves

min⁡w,b 12∥w∥2subject toyi(w⊤xi+b)≥1  (i=1,…,n),\min_{\mathbf w,b}\ \tfrac12\norm{\mathbf w}^2\quad\text{subject to}\quad y_i(\mathbf w^\top\mathbf x_i+b)\ge1\ \ (i=1,\dots,n),

and its dual is

max⁡α≥0 ∑iαi−12∑i,jαiαjyiyj xi⊤xjsubject to∑iαiyi=0,withw⋆=∑iαi⋆yixi.\max_{\boldsymbol\alpha\ge\mathbf 0}\ \sum_i\alpha_i-\frac12\sum_{i,j}\alpha_i\alpha_jy_iy_j\,\mathbf x_i^\top\mathbf x_j\quad\text{subject to}\quad\sum_i\alpha_iy_i=0,\qquad\text{with}\quad\mathbf w^\star=\sum_i\alpha_i^\star y_i\mathbf x_i.

Complementary slackness forces αi⋆=0\alpha_i^\star=0 for every point strictly outside the margin, so w⋆\mathbf w^\star is built only from points on the margin, the support vectors. The data enter the dual only through inner products xi⊤xj\mathbf x_i^\top\mathbf x_j, which is what lets the kernel trick replace them (The SVM Dual & Support Vectors).

What convexity buys, and the road ahead

Convexity is what makes optimization guarantees global: they bound the distance to the best possible value, not merely to some stationary point. The table collects the standard guarantees, each proved later in this topic.

Problem classMethodGuarantee
Convex, LL-smoothGradient descent, η=1/L\eta=1/Lf(xt)−f⋆≤L∥x0−x⋆∥22tf(\mathbf x_t)-f^\star\le\dfrac{L\norm{\mathbf x_0-\mathbf x^\star}^2}{2t}
Convex, LL-smoothNesterov's accelerated methodO(L∥x0−x⋆∥2/t2)\order{L\norm{\mathbf x_0-\mathbf x^\star}^2/t^2}, optimal
μ\mu-strongly convex, LL-smoothGradient descentO((1−μ/L)t)\order{(1-\mu/L)^t}: a linear rate
Convex, GG-Lipschitz, nonsmoothSubgradient methodO(GR/t)\order{GR/\sqrt t}, optimal
Smooth plus a simple nonsmooth term (the lasso)Proximal gradient; FISTAO(1/t)\order{1/t}; O(1/t2)\order{1/t^2}
Linear, quadratic and semidefinite programsInterior-point methodsO(m log⁡(m/ε))\order{\sqrt m\,\log(m/\varepsilon)} Newton steps for mm linear inequalities
RR bounds the distance from the start to a minimizer and GG bounds the subgradients. "Optimal" means no first-order method can do better on the whole class when the dimension is large, as Lower Bounds & Oracle Complexity proves; the convergence rates themselves are proved in Convergence Rates of Gradient Descent, Momentum & Nesterov Acceleration and Proximal & Projected Methods.

Key takeaways

  • Convex functions lie below their chords and above their tangent planes. Norms, convex quadratics, log-sum-exp and affine functions, combined by sums, maxima and affine substitutions, generate almost every convex objective in machine learning.
  • For convex ff, every local minimum is global and ∇f=0\nabla f=\mathbf 0 (or 0∈∂f\mathbf 0\in\partial f) certifies optimality; strong convexity adds uniqueness and f−f⋆≤∥∇f∥2/(2μ)f-f^\star\le\norm{\nabla f}^2/(2\mu).
  • Least squares, ridge, logistic regression, the hinge loss and the lasso are convex. They differ in smoothness and strong convexity, which set the speed of first-order methods. Network losses are not convex.
  • Subgradients extend optimality to kinks (0∈∂f(x⋆)\mathbf 0\in\partial f(\mathbf x^\star)), and soft thresholding sign⁡(z)(∣z∣−λ)+\sign(z)(\abs z-\lambda)_+ shows how the ℓ1\ell_1 kink produces exact zeros.
  • The Lagrange dual always bounds the primal from below. For convex problems satisfying Slater's condition the bounds meet, and the KKT conditions, through complementary slackness, explain why only the support vectors shape an SVM.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

ff is convex and differentiable on Rd\R^d. Which statement is always true?

  1. ff has at least one minimizer
  2. If ∇f(x)=0\nabla f(\mathbf x)=\mathbf 0, then x\mathbf x is a global minimizer
  3. ff has exactly one minimizer
  4. Every stationary point is a strict local minimum
Show the answer

B. If ∇f(x)=0\nabla f(\mathbf x)=\mathbf 0, then x\mathbf x is a global minimizer

The first-order condition f(y)≥f(x)+∇f(x)⊤(y−x)f(\mathbf y)\ge f(\mathbf x)+\nabla f(\mathbf x)^\top(\mathbf y-\mathbf x) becomes f(y)≥f(x)f(\mathbf y)\ge f(\mathbf x) when the gradient vanishes. Existence and uniqueness need more: exe^x is convex with no minimizer, and a constant function has infinitely many.

Question 2

For ridge regression, F(w)=12n∥Xw−y∥2+λ2∥w∥2F(\mathbf w)=\frac1{2n}\norm{X\mathbf w-\mathbf y}^2+\frac\lambda2\norm{\mathbf w}^2, what are the strong convexity constant μ\mu and the smoothness constant LL?

  1. μ=λ\mu=\lambda and L=λL=\lambda
  2. μ=λmin⁡(X⊤X)\mu=\lambda_{\min}(X^\top X) and L=λmax⁡(X⊤X)L=\lambda_{\max}(X^\top X)
  3. μ=λmin⁡(X⊤X)/n+λ\mu=\lambda_{\min}(X^\top X)/n+\lambda and L=λmax⁡(X⊤X)/n+λL=\lambda_{\max}(X^\top X)/n+\lambda
  4. μ=0\mu=0, since least squares is only convex
Show the answer

C. μ=λmin⁡(X⊤X)/n+λ\mu=\lambda_{\min}(X^\top X)/n+\lambda and L=λmax⁡(X⊤X)/n+λL=\lambda_{\max}(X^\top X)/n+\lambda

The Hessian is constant, ∇2F=X⊤X/n+λI\nabla^2F=X^\top X/n+\lambda I, and its extreme eigenvalues are μ\mu and LL. Even when X⊤XX^\top X is singular (d>nd>n), μ≥λ>0\mu\ge\lambda>0: the penalty makes the problem strongly convex, with condition number κ=L/μ\kappa=L/\mu.

Question 3

For one example with y∈{−1,+1}y\in\{-1,+1\}, what is the subdifferential of max⁡(0, 1−y w⊤x)\max(0,\,1-y\,\mathbf w^\top\mathbf x) with respect to w\mathbf w at a point where the margin y w⊤xy\,\mathbf w^\top\mathbf x equals exactly 11?

  1. {0}\{\mathbf 0\}
  2. {−yx}\{-y\mathbf x\}
  3. It is empty, because the loss is not differentiable there
  4. {−s yx: s∈[0,1]}\{-s\,y\mathbf x:\ s\in[0,1]\}
Show the answer

D. {−s yx: s∈[0,1]}\{-s\,y\mathbf x:\ s\in[0,1]\}

The hinge h(z)=max⁡(0,1−z)h(z)=\max(0,1-z) has ∂h(1)=[−1,0]\partial h(1)=[-1,0]: the slopes of all lines through the kink that stay below the graph. Through the affine map z=y w⊤xz=y\,\mathbf w^\top\mathbf x this becomes the segment between the two one-sided gradients, 0\mathbf 0 (margin above 1) and −yx-y\mathbf x (margin below 1).

Question 4

You compute the Lagrange dual of a nonconvex problem. What does its optimal value d⋆d^\star tell you about p⋆p^\star?

  1. Nothing: duality only applies to convex problems
  2. It is a lower bound on p⋆p^\star, possibly strictly below it
  3. It equals p⋆p^\star, as duality theory guarantees
  4. It is an upper bound on p⋆p^\star
Show the answer

B. It is a lower bound on p⋆p^\star, possibly strictly below it

Weak duality, q(λ,ν)≤f0(x~)q(\boldsymbol\lambda,\boldsymbol\nu)\le f_0(\tilde{\mathbf x}) for every feasible x~\tilde{\mathbf x} and λ≥0\boldsymbol\lambda\ge\mathbf 0, used no convexity at all. The dual is always a concave maximization, so it can be tractable even when the primal is hard; semidefinite relaxations of combinatorial problems work this way. Equality generally needs convexity plus a condition such as Slater's.

Question 5

In a trained hard-margin SVM, a training point lies strictly outside the margin: yi(w⋆⊤xi+b⋆)>1y_i\big(\mathbf w^{\star\top}\mathbf x_i+b^\star\big)>1. What is its dual variable, and what happens if you delete the point and retrain?

  1. αi⋆=0\alpha_i^\star=0, and the solution does not change
  2. αi⋆>0\alpha_i^\star>0, and the boundary moves toward the remaining points
  3. αi⋆=0\alpha_i^\star=0, but the boundary moves because nn changed
  4. αi⋆\alpha_i^\star is undefined for points outside the margin
Show the answer

A. αi⋆=0\alpha_i^\star=0, and the solution does not change

Its constraint is slack, so complementary slackness, αi⋆(yi(w⋆⊤xi+b⋆)−1)=0\alpha_i^\star\big(y_i(\mathbf w^{\star\top}\mathbf x_i+b^\star)-1\big)=0, forces αi⋆=0\alpha_i^\star=0. The solution w⋆=∑jαj⋆yjxj\mathbf w^\star=\sum_j\alpha_j^\star y_j\mathbf x_j does not involve the point, and the old solution, still feasible and still satisfying the KKT conditions, stays optimal after it is removed.

Go deeper

Further reading

  • S. Boyd & L. Vandenberghe, Convex Optimization (Cambridge University Press, 2004), chapters 2–5.
  • R. T. Rockafellar, Convex Analysis (Princeton University Press, 1970).
  • C. Cortes & V. Vapnik, "Support-vector networks," Machine Learning 20(3), 273–297 (1995).