23.7 Duality

When an iterative solver stops making progress and reports convergence, a natural question remains: is the point it returned actually optimal? For an unconstrained convex function, a zero gradient settles the question at once (Section 23.3). With constraints, however, the optimum usually sits on the boundary with a nonzero gradient (Section 23.6), so that simple test disappears. Both numerical solvers and mathematical proofs therefore need a different tool: a reliable lower bound on the optimal value. In this section we develop a systematic way to construct such bounds and uncover what the Lagrange multipliers of the KKT conditions actually measure.

To see the difficulty concretely, return to the clipping problem of Section 23.6.2. There we minimized the squared distance 12∥x−x0∥2\tfrac12\|\mathbf{x} - \mathbf{x}_0\|^2 to the target x0=(3,4)\mathbf{x}_0 = (3, 4) over the unit disk ∥x∥≤1\|\mathbf{x}\| \le 1, finding the optimum x⋆=(0.6,0.8)\mathbf{x}^\star = (0.6, 0.8) with optimal value 88. (We write x0\mathbf{x}_0 here instead of y\mathbf{y}, reserving y\mathbf{y} for labels and for the argument of the convex conjugate later.) Now imagine an iterative solver stops at x=(0.55,0.835)\mathbf{x} = (0.55, 0.835). This point is feasible, since ∥x∥2=0.9997≤1\|\mathbf{x}\|^2 = 0.9997 \le 1, and achieves an objective value of 8.018.01. How can we tell whether 8.018.01 is nearly optimal, or whether some other point in the disk reaches 77? The gradient at the true optimum is (−2.4,−3.2)(-2.4, -3.2), nowhere near zero, and the disk contains infinitely many points, so checking them one by one is out of the question.

The key idea is to fold the constraint into the objective. Add a nonnegative multiple λ≥0\lambda \ge 0 of the constraint function 12(∥x∥2−1)\tfrac12(\|\mathbf{x}\|^2 - 1) to the objective. At every feasible point this added term is nonpositive, so minimizing the modified objective over all of R2\mathbb{R}^2 must yield a value no larger than the constrained optimum. Each choice of λ≥0\lambda \ge 0 thus produces a lower bound through an unconstrained minimization, and λ=4\lambda = 4 gives a bound of 88—proving immediately that the solver's 8.018.01 is within 0.010.01 of optimal. Searching for the tightest such bound defines a companion optimization problem, the dual problem. Remarkably, the dual problem is always convex, even when the original problem is not. For a convex problem with a strictly feasible point, its optimal value matches the constrained optimum, and its optimal multipliers tell us how rapidly the optimal value improves when each constraint is relaxed.

In what follows, we first use this bounding idea to prove optimality for the clipping problem and state weak duality, a two-line argument that holds for every optimization problem. We then establish strong duality for convex problems, whose proof contains the one subtle geometric step in the section, and interpret the optimal multipliers as shadow prices, connecting weight decay directly to norm constraints. After introducing the convex conjugate as a convenient tool for computing duals of linearly constrained problems (which can be skimmed on a first reading), we work through three revealing examples: the support vector machine, water-filling power allocation, and a nonconvex problem whose best dual bound stays strictly below its optimum. All computations are small enough for NumPy, and d2l handles the plots.

23.7.1 The Dual Problem#

Our first goal is to prove that no feasible point of the clipping problem achieves a value below 88, without checking feasible points one by one. Every lower bound in this section rests on a single elementary observation: at any feasible point, every inequality constraint function is nonpositive.

23.7.1.1 A Lower Bound from One Multiplier#

Recall the clipping problem: minimize f(x)=12∥x−x0∥2f(\mathbf{x}) = \tfrac12\|\mathbf{x} - \mathbf{x}_0\|^2 with x0=(3,4)\mathbf{x}_0 = (3, 4), subject to g(x)=12(∥x∥2−1)≤0g(\mathbf{x}) = \tfrac12(\|\mathbf{x}\|^2 - 1) \le 0. Including the factor of 12\tfrac12 in gg simply makes its gradient equal to x\mathbf{x}. From the KKT conditions we already know the solution: x⋆=x0/∥x0∥=(0.6,0.8)\mathbf{x}^\star = \mathbf{x}_0 / \|\mathbf{x}_0\| = (0.6, 0.8) with optimal value p⋆=12(5−1)2=8p^\star = \tfrac12(5 - 1)^2 = 8, and optimal multiplier λ⋆=4\lambda^\star = 4, determined by the stationarity condition ∇f(x⋆)+λ⋆x⋆=(−2.4,−3.2)+4 (0.6,0.8)=0\nabla f(\mathbf{x}^\star) + \lambda^\star \mathbf{x}^\star = (-2.4, -3.2) + 4\,(0.6, 0.8) = \mathbf{0}.

Now pick any multiplier λ≥0\lambda \ge 0 and any feasible point x\mathbf{x}. Because g(x)≤0g(\mathbf{x}) \le 0 and λ≥0\lambda \ge 0, their product λg(x)\lambda g(\mathbf{x}) is nonpositive, which means f(x)+λg(x)≤f(x)f(\mathbf{x}) + \lambda g(\mathbf{x}) \le f(\mathbf{x}). Minimizing the left-hand side over all of R2\mathbb{R}^2 can only make it smaller still, so that unconstrained minimum is at most f(x)f(\mathbf{x}). Since this holds for every feasible x\mathbf{x}, it also holds for the best feasible x\mathbf{x}:

min⁡x∈R2[f(x)+λg(x)]  ≤  min⁡∥x∥≤1f(x)  =  p⋆for every λ≥0.\min_{\mathbf{x} \in \mathbb{R}^2} \bigl[ f(\mathbf{x}) + \lambda g(\mathbf{x}) \bigr] \;\le\; \min_{\|\mathbf{x}\| \le 1} f(\mathbf{x}) \;=\; p^\star \qquad \textrm{for every } \lambda \ge 0 .

Let us evaluate the left-hand side explicitly. The function being minimized is the Lagrangian L(x,λ)=12∥x−x0∥2+λ2(∥x∥2−1)\mathcal{L}(\mathbf{x}, \lambda) = \tfrac12\|\mathbf{x} - \mathbf{x}_0\|^2 + \tfrac\lambda2(\|\mathbf{x}\|^2 - 1). For any λ≥0\lambda \ge 0, this is a convex quadratic in x\mathbf{x} with Hessian (1+λ)I(1 + \lambda)\mathbf{I}, so its unique minimizer occurs where the gradient (x−x0)+λx(\mathbf{x} - \mathbf{x}_0) + \lambda \mathbf{x} vanishes: x(λ)=x0/(1+λ)\mathbf{x}(\lambda) = \mathbf{x}_0 / (1 + \lambda). Increasing λ\lambda shrinks x0\mathbf{x}_0 more strongly toward the origin. Substituting x(λ)\mathbf{x}(\lambda) back into the Lagrangian—using x(λ)−x0=−λx0/(1+λ)\mathbf{x}(\lambda) - \mathbf{x}_0 = -\lambda\mathbf{x}_0 / (1 + \lambda) and ∥x0∥2=25\|\mathbf{x}_0\|^2 = 25—gives 12∥x(λ)−x0∥2=252λ2/(1+λ)2\tfrac12\|\mathbf{x}(\lambda) - \mathbf{x}_0\|^2 = \tfrac{25}{2}\lambda^2/(1+\lambda)^2 and λ2∥x(λ)∥2=252λ/(1+λ)2\tfrac\lambda2\|\mathbf{x}(\lambda)\|^2 = \tfrac{25}{2}\lambda/(1+\lambda)^2. Combining these two fractions cancels a factor of (1+λ)(1 + \lambda), leaving the minimum value as a simple function of λ\lambda:

q(λ)  =  252 λ1+λ  −  λ2.(23.7.1)q(\lambda) \;=\; \frac{25}{2}\,\frac{\lambda}{1 + \lambda} \;-\; \frac{\lambda}{2}. \tag{23.7.1}

The two terms pull in opposite directions. As λ\lambda grows, the first term rises toward 12.512.5, while the second term—coming from the constant −12-\tfrac12 inside gg—drops linearly without bound. The tightest lower bound sits where these two effects balance.

Plugging in a few numbers makes this balance concrete: q(0)=0q(0) = 0, q(1)=5.75q(1) = 5.75, q(2)=7.33q(2) = 7.33, q(3)=7.875q(3) = 7.875, q(4)=8q(4) = 8, q(5)=7.92q(5) = 7.92, and q(8)=7.11q(8) = 7.11. Every single one of these values is a valid lower bound on p⋆p^\star. Differentiating gives q′(λ)=252(1+λ)2−12q'(\lambda) = \tfrac{25}{2(1 + \lambda)^2} - \tfrac12, which vanishes when (1+λ)2=25(1 + \lambda)^2 = 25, or λ=4\lambda = 4. Since q′′(λ)=−25/(1+λ)3<0q''(\lambda) = -25/(1 + \lambda)^3 \lt 0, λ=4\lambda = 4 is the unique maximum, attaining q(4)=10−2=8=p⋆q(4) = 10 - 2 = 8 = p^\star. The best lower bound equals the true optimum, and the multiplier that achieves it is the KKT multiplier. This certifies that the solver's value of 8.018.01 is within 0.010.01 of optimal; even an unoptimized guess like λ=3\lambda = 3 already certifies that it is within 0.1350.135.

Why does λ=4\lambda = 4 hit the optimum? Look at the constraint value at the Lagrangian minimizer: g(x(λ))=12(25/(1+λ)2−1)g(\mathbf{x}(\lambda)) = \tfrac12\bigl(25/(1 + \lambda)^2 - 1\bigr). When λ<4\lambda \lt 4, the multiplier is too weak to pull the minimizer inside the unit disk (for example, x(1)=(1.5,2)\mathbf{x}(1) = (1.5, 2) has norm 2.52.5), so g(x(λ))>0g(\mathbf{x}(\lambda)) > 0 and the bound reflects an infeasible point. When λ>4\lambda > 4, the multiplier pulls the minimizer too far inside (for example, x(8)\mathbf{x}(8) has norm 59\tfrac59), so λg(x(λ))<0\lambda g(\mathbf{x}(\lambda)) \lt 0 drags the bound back down. Right at λ=4\lambda = 4, the minimizer x(4)=(0.6,0.8)\mathbf{x}(4) = (0.6, 0.8) lands on the boundary circle, the penalty term λg(x(λ))\lambda g(\mathbf{x}(\lambda)) vanishes, and the bound coincides with the objective of a feasible point.

Let us plot q(λ)q(\lambda) alongside p⋆p^\star across a grid of λ\lambda values to see how these bounds behave.

x0 = np.array([3.0, 4.0])                             # the point to clip
f = lambda x: 0.5 * np.sum((x - x0) ** 2)             # objective
g = lambda x: 0.5 * (np.sum(x ** 2) - 1.0)            # constraint g(x) <= 0
x_of = lambda lam: x0 / (1 + lam)                     # minimizer of L(., lam)
q = lambda lam: f(x_of(lam)) + lam * g(x_of(lam))     # dual function
p_star = f(x0 / np.linalg.norm(x0))                   # value at the clipped point
lams = np.linspace(0.0, 12.0, 1201)
qs = np.array([q(l) for l in lams])
d2l.plot(lams, [qs, np.full_like(lams, p_star)], 'lambda', 'value',
         legend=['dual function q(lambda)', 'p* = 8'])

The resulting curve is concave and stays everywhere below the horizontal line p⋆=8p^\star = 8, touching it once at λ=4\lambda = 4. Surprisingly, concavity here has nothing to do with the geometry of the disk: as we now show, the dual function is concave for every optimization problem.

23.7.1.2 The Lagrange Dual Function#

Nothing in the bounding argument above depended on the clipping problem. Let us apply the same construction to the general constrained problem from Section 23.6.2,

min⁡x∈D  f(x)subject togi(x)≤0,  i=1,…,m,hj(x)=0,  j=1,…,p,\min_{\mathbf{x} \in \mathcal{D}}\; f(\mathbf{x}) \quad \textrm{subject to} \quad g_i(\mathbf{x}) \le 0,\; i = 1, \ldots, m, \qquad h_j(\mathbf{x}) = 0,\; j = 1, \ldots, p,

with optimal value p⋆p^\star, defined as the infimum of ff over all feasible points (with p⋆=+∞p^\star = +\infty if no feasible point exists). Here D\mathcal{D} is the domain on which ff and all constraint functions are defined; it is simply Rn\mathbb{R}^n unless we keep a set as a hard constraint, as we will do with [0,1][0, 1] in the duality-gap example at the end of this section. The Lagrangian introduces one multiplier per constraint,

L(x,λ,ν)=f(x)+∑i=1mλi gi(x)+∑j=1pνj hj(x),\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) = f(\mathbf{x}) + \sum_{i=1}^m \lambda_i\, g_i(\mathbf{x}) + \sum_{j=1}^p \nu_j\, h_j(\mathbf{x}),

with λi≥0\lambda_i \ge 0 for inequalities and νj∈R\nu_j \in \mathbb{R} unconstrained in sign for equalities. We write λ⪰0\boldsymbol{\lambda} \succeq 0 to mean λi≥0\lambda_i \ge 0 for every coordinate ii.

Minimizing the Lagrangian over x\mathbf{x} for fixed multipliers turns our lower-bound construction into a function of (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}). The Lagrange dual function is

q(λ,ν)=inf⁡x∈D  L(x,λ,ν).(23.7.2)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) = \inf_{\mathbf{x} \in \mathcal{D}}\; \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}). \tag{23.7.2}

In words, q(λ,ν)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) asks how low ff can go once we drop the hard constraints and replace them with linear penalties weighted by λ\boldsymbol{\lambda} and ν\boldsymbol{\nu}. For the clipping problem this gave (23.7.1). In general, the infimum need not be attained, and it can even be −∞-\infty. For example, suppose we minimize xx subject to −x≤0-x \le 0: the Lagrangian (1−λ)x(1 - \lambda)x is unbounded below unless λ=1\lambda = 1, so q(1)=0q(1) = 0 and q(λ)=−∞q(\lambda) = -\infty for all other λ\lambda. A bound of −∞-\infty is trivially valid but useless. The set of multipliers where q(λ,ν)>−∞q(\boldsymbol{\lambda}, \boldsymbol{\nu}) > -\infty is called the effective domain of qq; when we derive the support vector machine dual below, this implicit domain restriction will surface as an explicit equality constraint.

Two fundamental properties of qq hold with no assumptions whatsoever on ff, gig_i, or hjh_j—not even convexity or differentiability.

Proposition (the dual function is concave). For any primal problem, q(λ,ν)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) in (23.7.2) is concave.

Proof. Fix any x∈D\mathbf{x} \in \mathcal{D}. Because the multipliers enter L\mathcal{L} linearly, the map (λ,ν)↦L(x,λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}) \mapsto \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) is affine. The dual function qq is the pointwise infimum of this family of affine functions. Its hypograph—the set of points lying on or below its graph—is therefore the intersection of the half-spaces below these affine functions. Since any intersection of convex sets is convex, qq is concave. ■\blacksquare

Figure 23.7.1 draws this construction for the clipping problem. Each dashed line is the Lagrangian of one fixed x\mathbf{x} as a function of λ\lambda, and qq is the curve that stays below all of them. The objective of the clipping problem happens to be convex, but the argument never used that: a lower envelope of lines is concave whatever shape ff and gg have.

Figure 23.7.1:

The dual function of the clipping problem as a lower envelope. Each fixed x\mathbf{x} contributes one line λ↦L(x,λ)\lambda \mapsto \mathcal{L}(\mathbf{x}, \lambda) (dashed), and q(λ)q(\lambda) is the lowest value that any of these lines takes at λ\lambda. The lines drawn belong to the minimizers x(λ)=x0/(1+λ)\mathbf{x}(\lambda) = \mathbf{x}_0/(1+\lambda) for several values of λ\lambda, and each touches qq at its own λ\lambda (dots). The line of x⋆=x(4)\mathbf{x}^\star = \mathbf{x}(4) is flat because g(x⋆)=0g(\mathbf{x}^\star) = 0; it touches qq at the maximum d⋆=q(4)=p⋆=8d^\star = q(4) = p^\star = 8.

Proposition (weak duality). If x\mathbf{x} is feasible and λ⪰0\boldsymbol{\lambda} \succeq 0, then q(λ,ν)≤f(x)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) \le f(\mathbf{x}). Consequently,

d⋆  =  sup⁡λ⪰0, νq(λ,ν)  ≤  inf⁡x feasiblef(x)  =  p⋆.(23.7.3)d^\star \;=\; \sup_{\boldsymbol{\lambda} \succeq 0,\, \boldsymbol{\nu}} q(\boldsymbol{\lambda}, \boldsymbol{\nu}) \;\le\; \inf_{\mathbf{x}\ \textrm{feasible}} f(\mathbf{x}) \;=\; p^\star. \tag{23.7.3}

Proof. For any feasible x\mathbf{x} and any λ⪰0\boldsymbol{\lambda} \succeq 0, we have λigi(x)≤0\lambda_i g_i(\mathbf{x}) \le 0 (since λi≥0\lambda_i \ge 0 and gi(x)≤0g_i(\mathbf{x}) \le 0) and νjhj(x)=0\nu_j h_j(\mathbf{x}) = 0. Therefore,

q(λ,ν)  ≤  L(x,λ,ν)  =  f(x)+∑iλigi(x)+∑jνjhj(x)  ≤  f(x).q(\boldsymbol{\lambda}, \boldsymbol{\nu}) \;\le\; \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) \;=\; f(\mathbf{x}) + \sum_i \lambda_i g_i(\mathbf{x}) + \sum_j \nu_j h_j(\mathbf{x}) \;\le\; f(\mathbf{x}).

Taking the supremum over (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}) with λ⪰0\boldsymbol{\lambda} \succeq 0 on the left and the infimum over feasible x\mathbf{x} on the right yields (23.7.3). ■\blacksquare

Weak duality is the two-line inequality that turned every q(λ)q(\lambda) in the clipping problem into a certified lower bound. It is also the exact engine behind KKT sufficiency in Section 23.6.2, where evaluating the same chain at the KKT multipliers makes both inequalities tight via complementary slackness.

Maximizing q(λ,ν)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) over λ⪰0\boldsymbol{\lambda} \succeq 0 and ν\boldsymbol{\nu} is called the dual problem. Because it maximizes a concave function over a convex set, the dual problem is always a convex optimization problem, even when the primal problem is badly nonconvex. Its optimal value d⋆d^\star is the tightest lower bound this construction can provide, and every dual-feasible (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}) gives a valid lower bound. The nonnegative difference p⋆−d⋆≥0p^\star - d^\star \ge 0 is the duality gap. For the clipping problem the gap was zero, whereas our final worked example will exhibit a strict gap. The natural next question is when we can guarantee in advance that the gap vanishes.

23.7.2 Strong Duality#

In the clipping problem, the best dual bound matched the primal optimum exactly. For a nonconvex problem, however, the dual bound can fall strictly short, certifying only part of the answer. Fortunately, two mild ingredients— convexity and a single strictly feasible point—are enough to close the gap. A simple geometric view of the attainable constraint and objective values shows why both are needed.

23.7.2.1 Slater's Condition#

Proposition (Slater's condition implies strong duality). Suppose the problem is convex (ff and every gig_i convex, every hjh_j affine) and satisfies Slater's condition (Section 23.6.2.3): there exists a feasible point xˉ\bar{\mathbf{x}} in the relative interior of D\mathcal{D} such that gi(xˉ)<0g_i(\bar{\mathbf{x}}) \lt 0 for every inequality constraint gig_i that is not affine. Then d⋆=p⋆d^\star = p^\star, and whenever p⋆p^\star is finite, the dual optimum is attained.

This is the same constraint qualification introduced for convex problems in Section 23.6.2: at least one point must sit strictly inside all curved inequality constraints. (See Boyd and Vandenberghe (2004), section 5.3.2 for the full proof in multiple dimensions.) The clipping problem satisfies Slater's condition effortlessly: both ff and gg are convex, and the origin 0\mathbf{0} satisfies g(0)=−12<0g(\mathbf{0}) = -\tfrac12 \lt 0. Thus q(4)=p⋆q(4) = p^\star was guaranteed before we ever computed a derivative.

To understand why convexity and strict feasibility close the gap, consider a problem with a single inequality constraint g(x)≤0g(\mathbf{x}) \le 0. Map every point x∈D\mathbf{x} \in \mathcal{D} to the pair (g(x),f(x))(g(\mathbf{x}), f(\mathbf{x})) of its constraint value and objective value, and collect all points lying above and to the right of these pairs:

A={(u,t):u≥g(x), t≥f(x) for some x∈D}.\mathcal{A} = \bigl\{ (u, t) : u \ge g(\mathbf{x}),\ t \ge f(\mathbf{x}) \ \textrm{for some } \mathbf{x} \in \mathcal{D} \bigr\}.

In this (u,t)(u, t)-plane, feasible points correspond to u≤0u \le 0, so the primal optimum p⋆p^\star is simply the lowest height tt that A\mathcal{A} reaches on the vertical axis u=0u = 0. Now fix λ≥0\lambda \ge 0. Over all (u,t)(u, t) contributed by a given x\mathbf{x}, the linear function t+λut + \lambda u is minimized at (g(x),f(x))(g(\mathbf{x}), f(\mathbf{x})), so q(λ)=inf⁡(u,t)∈A(t+λu)q(\lambda) = \inf_{(u, t) \in \mathcal{A}} (t + \lambda u). Geometrically, we take a line t+λu=ct + \lambda u = c of slope −λ-\lambda and push it upward from below until it just supports A\mathcal{A}; its intercept on the vertical axis u=0u = 0 is q(λ)q(\lambda). Because the entire set A\mathcal{A} lies on or above this supporting line, the intercept q(λ)q(\lambda) can never exceed p⋆p^\star. This is weak duality made visible (Figure 23.7.2).

Figure 23.7.2:

The supporting-line geometry of duality. Every x\mathbf{x} maps to (g(x),f(x))(g(\mathbf{x}),f(\mathbf{x})); the shaded set A\mathcal{A} contains these pairs and all points above and to the right of them. Evaluating the dual at λ\lambda pushes a line of slope −λ-\lambda up until it supports A\mathcal{A} from below, and its intercept at u=0u=0 is q(λ)q(\lambda). (a) The clipping problem: A\mathcal{A} is convex and 0\mathbf{0} is strictly feasible, so the optimal supporting line touches at (0,p⋆)(0,p^\star) with slope −4-4, giving d⋆=p⋆=8d^\star=p^\star=8. (b) Minimizing −x2-x^2 on [0,1][0,1] subject to x≤12x\le\tfrac12: A\mathcal{A} is nonconvex, so the highest supporting line passes strictly below (0,p⋆)(0,p^\star), leaving d⋆=−12<−14=p⋆d^\star=-\tfrac12\lt -\tfrac14=p^\star.

With this geometry in place, the proof of strong duality for a single inequality constraint becomes transparent.

Proof (one inequality constraint with g(xˉ)<0g(\bar{\mathbf{x}}) \lt 0, p⋆p^\star finite). First, A\mathcal{A} is convex. Take any two points (u1,t1)(u_1, t_1) and (u2,t2)(u_2, t_2) in A\mathcal{A}, contributed by x1\mathbf{x}_1 and x2\mathbf{x}_2, and any θ∈[0,1]\theta \in [0, 1]. By convexity of gg, the midpoint xθ=θx1+(1−θ)x2\mathbf{x}_\theta = \theta\mathbf{x}_1 + (1 - \theta)\mathbf{x}_2 satisfies g(xθ)≤θg(x1)+(1−θ)g(x2)≤θu1+(1−θ)u2g(\mathbf{x}_\theta) \le \theta g(\mathbf{x}_1) + (1 - \theta) g(\mathbf{x}_2) \le \theta u_1 + (1 - \theta) u_2, and the same inequality holds for ff. Hence the convex combination of (u1,t1)(u_1, t_1) and (u2,t2)(u_2, t_2) belongs to A\mathcal{A}.

Second, (0,p⋆)(0, p^\star) lies on the boundary of A\mathcal{A}: it is a limit of points in A\mathcal{A}, whereas (0,p⋆−ε)∉A(0, p^\star - \varepsilon) \notin \mathcal{A} for every ε>0\varepsilon > 0. Every boundary point of a convex set admits a supporting line: there exists a nonzero vector (λ,γ)≠(0,0)(\lambda, \gamma) \neq (0, 0) such that γt+λu≥γp⋆\gamma t + \lambda u \ge \gamma p^\star for all (u,t)∈A(u, t) \in \mathcal{A} (Boyd and Vandenberghe (2004), section 2.5.2; this is the same geometric fact that produces subgradients in Section 23.3). Because A\mathcal{A} extends indefinitely upward and to the right, we must have γ≥0\gamma \ge 0 and λ≥0\lambda \ge 0.

Could γ=0\gamma = 0? If so, the supporting line is vertical and λ>0\lambda > 0, forcing λu≥0\lambda u \ge 0 (and thus u≥0u \ge 0) throughout A\mathcal{A}. That contradicts the strictly feasible point xˉ\bar{\mathbf{x}}, which contributes u=g(xˉ)<0u = g(\bar{\mathbf{x}}) \lt 0. Therefore γ>0\gamma > 0. Dividing by γ\gamma yields t+(λ/γ) u≥p⋆t + (\lambda/\gamma)\,u \ge p^\star for all (u,t)∈A(u, t) \in \mathcal{A}, which means q(λ/γ)≥p⋆q(\lambda/\gamma) \ge p^\star. Combined with weak duality, q(λ/γ)=p⋆q(\lambda/\gamma) = p^\star: the dual optimum is attained and equals p⋆p^\star. ■\blacksquare

Notice how cleanly the two hypotheses separate in the proof. Convexity is used once, to make A\mathcal{A} convex so that a supporting line exists at (0,p⋆)(0, p^\star). Slater's condition is used once, to prevent that supporting line from being vertical, which would correspond to an infinite multiplier. In panel (a) of Figure 23.7.2, for the clipping problem, a point of norm ∥x∥=r\|\mathbf{x}\| = r has minimum objective 12(5−r)2\tfrac12(5 - r)^2 and constraint value u=12(r2−1)u = \tfrac12(r^2 - 1), so the lower boundary of A\mathcal{A} is the curve t=12(5−1+2u)2t = \tfrac12\bigl(5 - \sqrt{1 + 2u}\bigr)^2. Its slope at u=0u = 0 is −4-4, matching the optimal supporting line of slope −λ⋆=−4-\lambda^\star = -4. Panel (b) previews the nonconvex example at the end of this section: there A\mathcal{A} bends the wrong way, so every line below A\mathcal{A} passes strictly underneath (0,p⋆)(0, p^\star).

23.7.2.2 Saddle Points#

Strong duality can also be restated purely in terms of the Lagrangian, without even mentioning the dual function. Observe that we can rewrite the primal problem as a min--max problem: for any x∈D\mathbf{x} \in \mathcal{D},

sup⁡λ⪰0, νL(x,λ,ν)={f(x)if x is feasible,+∞otherwise.\sup_{\boldsymbol{\lambda} \succeq 0,\, \boldsymbol{\nu}} \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) = \begin{cases} f(\mathbf{x}) & \textrm{if } \mathbf{x} \textrm{ is feasible}, \\ +\infty & \textrm{otherwise}. \end{cases}

If x\mathbf{x} violates any constraint, we can scale the corresponding multiplier to drive L\mathcal{L} to +∞+\infty; if x\mathbf{x} is feasible, the best the multipliers can do is set λi=0\lambda_i = 0 on every slack constraint, leaving f(x)f(\mathbf{x}). Consequently, p⋆=inf⁡xsup⁡λ⪰0,νLp^\star = \inf_{\mathbf{x}} \sup_{\boldsymbol{\lambda} \succeq 0, \boldsymbol{\nu}} \mathcal{L}, while by definition d⋆=sup⁡λ⪰0,νinf⁡xLd^\star = \sup_{\boldsymbol{\lambda} \succeq 0, \boldsymbol{\nu}} \inf_{\mathbf{x}} \mathcal{L}. Weak duality is simply the universal inequality sup⁡inf⁡≤inf⁡sup⁡\sup \inf \le \inf \sup, which holds for any function of two variables. Strong duality says that we can swap the order of minimization and maximization without changing the value. When both optima are attained, this swapability is equivalent to the existence of a saddle point of the Lagrangian.

Proposition (strong duality is a saddle point). Suppose strong duality holds and both optima are attained, at a primal optimum x⋆\mathbf{x}^\star and a dual optimum (λ⋆,ν⋆)(\boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star). Then (x⋆,λ⋆,ν⋆)(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) is a saddle point of the Lagrangian: for all x∈D\mathbf{x} \in \mathcal{D}, all λ⪰0\boldsymbol{\lambda} \succeq 0, and all ν\boldsymbol{\nu},

L(x⋆,λ,ν)  ≤  L(x⋆,λ⋆,ν⋆)  ≤  L(x,λ⋆,ν⋆).(23.7.4)\mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}, \boldsymbol{\nu}) \;\le\; \mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \;\le\; \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star). \tag{23.7.4}

Conversely, any saddle point of L\mathcal{L} over x∈D\mathbf{x} \in \mathcal{D} and (λ⪰0,ν)(\boldsymbol{\lambda} \succeq 0, \boldsymbol{\nu}) closes the duality gap, with saddle value p⋆=d⋆p^\star = d^\star.

Proof. By definition of qq and weak duality,

d⋆=q(λ⋆,ν⋆)=inf⁡xL(x,λ⋆,ν⋆)  ≤  L(x⋆,λ⋆,ν⋆)  ≤  f(x⋆)=p⋆,d^\star = q(\boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) = \inf_{\mathbf{x}} \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \;\le\; \mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \;\le\; f(\mathbf{x}^\star) = p^\star,

where the final inequality holds because λi⋆≥0\lambda_i^\star \ge 0 and gi(x⋆)≤0g_i(\mathbf{x}^\star) \le 0 make every penalty term nonpositive. Strong duality (d⋆=p⋆d^\star = p^\star) forces every inequality in this chain to be an equality. Equality on the left means x⋆\mathbf{x}^\star minimizes L(⋅,λ⋆,ν⋆)\mathcal{L}(\cdot, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star), giving the right-hand inequality of (23.7.4). Equality on the right forces ∑iλi⋆gi(x⋆)=0\sum_i \lambda_i^\star g_i(\mathbf{x}^\star) = 0, which is complementary slackness. Hence, for any λ⪰0\boldsymbol{\lambda} \succeq 0 and ν\boldsymbol{\nu}, L(x⋆,λ,ν)=f(x⋆)+∑iλigi(x⋆)≤f(x⋆)=L(x⋆,λ⋆,ν⋆)\mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}, \boldsymbol{\nu}) = f(\mathbf{x}^\star) + \sum_i \lambda_i g_i(\mathbf{x}^\star) \le f(\mathbf{x}^\star) = \mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star), giving the left-hand inequality of (23.7.4).

Conversely, if (x⋆,λ⋆,ν⋆)(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) is a saddle point, then

inf⁡xsup⁡λ⪰0, νL≤sup⁡λ⪰0, νL(x⋆,λ,ν)=L(x⋆,λ⋆,ν⋆)=inf⁡xL(x,λ⋆,ν⋆)≤sup⁡λ⪰0, νinf⁡xL,\begin{aligned} \inf_{\mathbf{x}} \sup_{\boldsymbol{\lambda} \succeq 0,\, \boldsymbol{\nu}} \mathcal{L} &\le \sup_{\boldsymbol{\lambda} \succeq 0,\, \boldsymbol{\nu}} \mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}, \boldsymbol{\nu}) = \mathcal{L}(\mathbf{x}^\star, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \\ &= \inf_{\mathbf{x}} \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \le \sup_{\boldsymbol{\lambda} \succeq 0,\, \boldsymbol{\nu}} \inf_{\mathbf{x}} \mathcal{L}, \end{aligned}

which shows p⋆≤d⋆p^\star \le d^\star. Weak duality supplies the reverse inequality, so p⋆=d⋆p^\star = d^\star. ■\blacksquare

In our clipping example, the saddle point is (x⋆,λ⋆)=((0.6,0.8),4)(\mathbf{x}^\star, \lambda^\star) = ((0.6, 0.8), 4): perturbing x\mathbf{x} away from x⋆\mathbf{x}^\star increases L(⋅,4)\mathcal{L}(\cdot, 4), while varying λ\lambda leaves L(x⋆,λ)=8\mathcal{L}(\mathbf{x}^\star, \lambda) = 8 flat because g(x⋆)=0g(\mathbf{x}^\star) = 0.

Strong duality brings three practical benefits:

  • The dual can be simpler or smaller than the primal. The support vector machine dual has one variable per data point with simple sign constraints and at most one equality; the ridge regression dual in Exercise 8 reduces to a linear system of size equal to the number of examples rather than the feature dimension.
  • Every dual point gives a stopping criterion. For any primal-feasible x\mathbf{x} and any dual-feasible (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}), the gap f(x)−q(λ,ν)f(\mathbf{x}) - q(\boldsymbol{\lambda}, \boldsymbol{\nu}) upper-bounds how far f(x)f(\mathbf{x}) can be from p⋆p^\star.
  • The dual solution helps recover the primal solution. By (23.7.4), x⋆\mathbf{x}^\star is among the minimizers of L(⋅,λ⋆,ν⋆)\mathcal{L}(\cdot, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star). When that minimizer is unique (for instance, when ff is strictly convex), it immediately gives x⋆\mathbf{x}^\star, as in the clipping problem where x(4)=x0/5=x⋆\mathbf{x}(4) = \mathbf{x}_0 / 5 = \mathbf{x}^\star. When the minimizer is not unique, feasibility and complementary slackness pick x⋆\mathbf{x}^\star out of the minimizer set. In a linear program, L(⋅,λ⋆)\mathcal{L}(\cdot, \boldsymbol{\lambda}^\star) is flat in x\mathbf{x}; in the SVM with an unpenalized offset below, minimizing the Lagrangian leaves the offset undetermined, and complementary slackness pins it down.

The saddle-point proposition also settles the necessity of the KKT conditions, which Section 23.6.2 established as sufficient for convex problems. Suppose a convex problem with differentiable ff, gig_i, and hjh_j on D=Rn\mathcal{D} = \mathbb{R}^n satisfies Slater's condition and attains its optimum at x⋆\mathbf{x}^\star. Then strong duality holds with an attained dual optimum (λ⋆,ν⋆)(\boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star). Because x⋆\mathbf{x}^\star minimizes L(⋅,λ⋆,ν⋆)\mathcal{L}(\cdot, \boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) over all of Rn\mathbb{R}^n, its gradient ∇xL\nabla_{\mathbf{x}} \mathcal{L} vanishes there, and as we just saw, complementary slackness holds as well. Combined with primal and dual feasibility, these are precisely the four KKT conditions: under Slater's condition, they are both necessary and sufficient.

Finally, the min--max structure appears even in deep learning problems that have no explicit constraints. Generative adversarial networks (Section 16.1) and adversarial training are formulated directly as min⁡θmax⁡ϕ\min_{\boldsymbol{\theta}} \max_{\boldsymbol{\phi}} games (Goodfellow et al., 2014; Madry et al., 2018). Without a saddle point, a gap can separate their min⁡max⁡\min\max and max⁡min⁡\max\min values. Even when a saddle point does exist, taking simultaneous gradient descent steps in the minimizing variable and ascent steps in the maximizing variable can fail to converge: for the simple bilinear objective xyxy, whose saddle point is the origin, simultaneous descent--ascent spirals outward for every positive step size (Exercise 5).

23.7.3 Multipliers as Prices#

What is a constraint worth? In the clipping problem, if we slightly enlarge the unit disk, how much closer to x0\mathbf{x}_0 can we get? The optimal Lagrange multiplier answers that question directly. Even better, the same sensitivity argument reveals that for a convex loss, weight decay and a norm constraint on the weights trace out the exact same family of solutions.

23.7.3.1 Shadow Prices#

To measure the value of each constraint, perturb its right-hand side and track how the optimal objective changes. For perturbation vectors u∈Rm\mathbf{u} \in \mathbb{R}^m and v∈Rp\mathbf{v} \in \mathbb{R}^p, define the perturbed optimal value

p⋆(u,v)=inf⁡ {f(x):gi(x)≤ui,  hj(x)=vj}.p^\star(\mathbf{u}, \mathbf{v}) = \inf\,\{ f(\mathbf{x}) : g_i(\mathbf{x}) \le u_i,\; h_j(\mathbf{x}) = v_j \}.

At (0,0)(\mathbf{0}, \mathbf{0}) we recover the original optimum p⋆(0,0)p^\star(\mathbf{0}, \mathbf{0}), while taking ui>0u_i > 0 relaxes the ii-th inequality constraint. We have already seen this function geometrically: for a single inequality constraint, p⋆(u)p^\star(u) is the lowest height tt that the set A\mathcal{A} in Figure 23.7.2 reaches at horizontal coordinate uu. The lower boundary of A\mathcal{A} is the graph of p⋆(u)p^\star(u), and the supporting line of slope −λ⋆-\lambda^\star lies everywhere below it. The next proposition extends that geometric inequality to any number of constraints.

Proposition (multipliers are shadow prices). Suppose strong duality holds with dual optimum (λ⋆,ν⋆)(\boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star). Then for all u\mathbf{u} and v\mathbf{v},

p⋆(u,v)  ≥  p⋆(0,0)−λ⋆⊤u−ν⋆⊤v,(23.7.5)p^\star(\mathbf{u}, \mathbf{v}) \;\ge\; p^\star(\mathbf{0}, \mathbf{0}) - \boldsymbol{\lambda}^{\star\top} \mathbf{u} - \boldsymbol{\nu}^{\star\top} \mathbf{v}, \tag{23.7.5}

and if p⋆p^\star is differentiable at (0,0)(\mathbf{0}, \mathbf{0}), then ∇up⋆=−λ⋆\nabla_{\mathbf{u}} p^\star = -\boldsymbol{\lambda}^\star and ∇vp⋆=−ν⋆\nabla_{\mathbf{v}} p^\star = -\boldsymbol{\nu}^\star there.

Proof. Let x\mathbf{x} be any point feasible for the perturbed problem, so gi(x)≤uig_i(\mathbf{x}) \le u_i and hj(x)=vjh_j(\mathbf{x}) = v_j. Using strong duality, the definition of qq as an infimum, λi⋆≥0\lambda_i^\star \ge 0, and the perturbed constraints, we obtain

p⋆(0,0)=q(λ⋆,ν⋆)≤f(x)+∑iλi⋆gi(x)+∑jνj⋆hj(x)≤f(x)+λ⋆⊤u+ν⋆⊤v.\begin{aligned} p^\star(\mathbf{0}, \mathbf{0}) &= q(\boldsymbol{\lambda}^\star, \boldsymbol{\nu}^\star) \le f(\mathbf{x}) + \sum_i \lambda_i^\star g_i(\mathbf{x}) + \sum_j \nu_j^\star h_j(\mathbf{x}) \\ &\le f(\mathbf{x}) + \boldsymbol{\lambda}^{\star\top}\mathbf{u} + \boldsymbol{\nu}^{\star\top}\mathbf{v}. \end{aligned}

Taking the infimum over all perturbed-feasible x\mathbf{x} yields (23.7.5). If p⋆p^\star is differentiable at the origin, the nonnegative function p⋆(u,v)−p⋆(0,0)+λ⋆⊤u+ν⋆⊤vp^\star(\mathbf{u}, \mathbf{v}) - p^\star(\mathbf{0}, \mathbf{0}) + \boldsymbol{\lambda}^{\star\top}\mathbf{u} + \boldsymbol{\nu}^{\star\top}\mathbf{v} attains its global minimum of 00 at (0,0)(\mathbf{0}, \mathbf{0}), so its gradient must vanish there. ■\blacksquare

The optimal multiplier λi⋆\lambda_i^\star is called the shadow price of constraint ii: it measures the rate at which the optimal value improves as the constraint is relaxed. Notice that (23.7.5) is global, holding for perturbations of any size. Relaxing constraint ii by ui>0u_i > 0 can lower the optimal value by at most λi⋆ui\lambda_i^\star u_i, whereas tightening it by the same amount raises the optimal value by at least λi⋆ui\lambda_i^\star u_i; to first order, when p⋆p^\star is differentiable, the change is −λi⋆ui-\lambda_i^\star u_i. A slack constraint has λi⋆=0\lambda_i^\star = 0 by complementary slackness, matching intuition: loosening a constraint that is not binding cannot improve the optimum.

Let us check this on the clipping problem. Relaxing g(x)≤0g(\mathbf{x}) \le 0 to g(x)≤ug(\mathbf{x}) \le u expands the disk to radius r=1+2ur = \sqrt{1 + 2u}, giving p⋆(u)=12(5−1+2u)2p^\star(u) = \tfrac12\bigl(5 - \sqrt{1 + 2u}\bigr)^2—the lower boundary of A\mathcal{A} we computed earlier—whose derivative at u=0u = 0 is indeed −4=−λ⋆-4 = -\lambda^\star. If we relax the constraint by u=12u = \tfrac12 (a disk of radius 2\sqrt2), the new optimum is p⋆(12)=12(5−2)2≈6.43p^\star(\tfrac12) = \tfrac12(5 - \sqrt2)^2 \approx 6.43, safely above the global lower bound 8−4⋅12=68 - 4 \cdot \tfrac12 = 6 guaranteed by (23.7.5).

One subtlety is worth keeping in mind: a multiplier depends on how the constraint is scaled. Here λ⋆=4\lambda^\star = 4 prices uu, which is half the squared radius, rather than the radius rr itself. Per unit of radius, the chain rule gives dp⋆/dr=−(5−r)\mathrm{d}p^\star / \mathrm{d}r = -(5 - r), which equals rr times the derivative with respect to uu and matches −λ⋆-\lambda^\star only because r=1r = 1. Rescaling a constraint rescales its multiplier accordingly: writing ∥x∥2−1≤0\|\mathbf{x}\|^2 - 1 \le 0 without the factor of 12\tfrac12 would halve the multiplier to 22.

The closest-point problem of Section 23.6.1.3 illustrates the equality case. There, the minimum of 12∥x∥2\tfrac12\|\mathbf{x}\|^2 over the hyperplane a⊤x=b\mathbf{a}^\top\mathbf{x} = b is p⋆(b)=b2/(2∥a∥2)p^\star(b) = b^2 / (2\|\mathbf{a}\|^2), and ∂p⋆/∂b=−ν⋆\partial p^\star / \partial b = -\nu^\star is simply (23.7.5) applied to the perturbation h(x)=a⊤x−b=vh(\mathbf{x}) = \mathbf{a}^\top\mathbf{x} - b = v, which shifts the hyperplane to b+vb + v. That explains the increase of 0.02=0.2⋅0.10.02 = 0.2 \cdot 0.1 that we observed numerically in that section.

23.7.3.2 Weight Decay and Norm Constraints#

In deep learning, we regularly control model complexity either by adding weight decay (Section 2.7) to a training loss ℓ(w)\ell(\mathbf{w}) or by imposing a hard norm constraint on the weights. Using the book's convention, these two problems are

min⁡w  ℓ(w)+λ2∥w∥2andmin⁡w  ℓ(w)subject to12∥w∥2≤12r2.\min_{\mathbf{w}}\; \ell(\mathbf{w}) + \frac{\lambda}{2} \|\mathbf{w}\|^2 \qquad \textrm{and} \qquad \min_{\mathbf{w}}\; \ell(\mathbf{w}) \quad \textrm{subject to} \quad \tfrac12\|\mathbf{w}\|^2 \le \tfrac12 r^2 .

At a stationary point of the penalized problem, ∇ℓ(w)+λw=0\nabla\ell(\mathbf{w}) + \lambda\mathbf{w} = \mathbf{0}. For the constrained problem, introducing a multiplier λ≥0\lambda \ge 0 for g(w)=12∥w∥2−12r2g(\mathbf{w}) = \tfrac12\|\mathbf{w}\|^2 - \tfrac12 r^2 produces the KKT stationarity condition ∇ℓ(w)+λw=0\nabla\ell(\mathbf{w}) + \lambda\mathbf{w} = \mathbf{0}: the very same equation, with the weight-decay coefficient playing the role of the Lagrange multiplier.

When the loss ℓ\ell is convex, this equivalence works in both directions. Going from penalty to constraint, let wλ\mathbf{w}_\lambda minimize the penalized objective and choose the norm budget r=∥wλ∥r = \|\mathbf{w}_\lambda\|. Then wλ\mathbf{w}_\lambda is feasible, the constraint is active (satisfying complementary slackness), and KKT stationarity holds automatically. Because the KKT conditions are sufficient for convex problems (Section 23.6.2), wλ\mathbf{w}_\lambda solves the constrained problem.

Going from constraint to penalty, take any budget r>0r > 0. The origin w=0\mathbf{w} = \mathbf{0} is strictly feasible, so Slater's condition holds. If the constrained minimum is attained at w⋆\mathbf{w}^\star, KKT necessity yields a multiplier λ⋆(r)≥0\lambda^\star(r) \ge 0, and w⋆\mathbf{w}^\star minimizes the convex penalized objective ℓ(w)+λ⋆2∥w∥2\ell(\mathbf{w}) + \tfrac{\lambda^\star}{2}\|\mathbf{w}\|^2. Whenever λ⋆>0\lambda^\star > 0, the quadratic term makes this objective strictly convex, so w⋆\mathbf{w}^\star is its unique minimizer; when the budget is slack, λ⋆=0\lambda^\star = 0 and the penalized problem reduces to unregularized minimization. By the shadow-price proposition, λ⋆(r)=−∂p⋆/∂(12r2)\lambda^\star(r) = -\partial p^\star / \partial(\tfrac12 r^2): the weight-decay coefficient is the marginal reduction in training loss per unit of half squared norm.

In fact, neither direction depends on the ℓ2\ell_2 norm specifically. Replace 12∥w∥2\tfrac12\|\mathbf{w}\|^2 by any convex penalty Ω(w)\Omega(\mathbf{w}), such as the ℓ1\ell_1 norm ∥w∥1\|\mathbf{w}\|_1 used in the lasso (Section 23.6.4.1). Any minimizer wλ\mathbf{w}_\lambda of ℓ+λΩ\ell + \lambda\Omega solves the constrained problem with budget Ω(w)≤Ω(wλ)\Omega(\mathbf{w}) \le \Omega(\mathbf{w}_\lambda), since every w\mathbf{w} within that budget satisfies ℓ(w)≥ℓ(wλ)+λ (Ω(wλ)−Ω(w))≥ℓ(wλ)\ell(\mathbf{w}) \ge \ell(\mathbf{w}_\lambda) + \lambda\,(\Omega(\mathbf{w}_\lambda) - \Omega(\mathbf{w})) \ge \ell(\mathbf{w}_\lambda). Conversely, for convex ℓ\ell and any budget strictly above inf⁡Ω\inf \Omega, Slater's condition holds, and the saddle-point proposition ensures that any constrained minimizer also minimizes ℓ+λ⋆Ω\ell + \lambda^\star\Omega.

Convexity of ℓ\ell, however, is essential for the full equivalence. For a nonconvex loss, a penalized stationary point is still a KKT point of the matching constrained problem, but the global solution sets can differ, and certain norm budgets may be unattainable by any penalty weight λ\lambda (Exercise 6).

It is worth noting a third interpretation of the same quadratic term. For a squared loss with noise variance σ2\sigma^2 and an isotropic Gaussian prior N(0,τ2I)\mathcal{N}(\mathbf{0}, \tau^2\mathbf{I}) on the weights, the penalty λ2∥w∥2\tfrac\lambda2\|\mathbf{w}\|^2 with λ=σ2/τ2\lambda = \sigma^2/\tau^2 is the negative log-prior up to a constant and overall scale (Section 24.6). Thus a single number λ\lambda can be read three ways: as a weight-decay coefficient, as a Lagrange multiplier for a norm budget, and as a ratio of noise to prior variance.

Let us verify this equivalence numerically. For the convex least-squares loss ℓ(w)=12∥Aw−b∥2\ell(\mathbf{w}) = \tfrac12\|\mathbf{A}\mathbf{w} - \mathbf{b}\|^2 on random data, we solve the penalized problem in closed form via (A⊤A+λI)w=A⊤b(\mathbf{A}^\top\mathbf{A} + \lambda\mathbf{I})\mathbf{w} = \mathbf{A}^\top\mathbf{b}, set r=∥wλ∥r = \|\mathbf{w}_\lambda\|, and then solve the constrained problem using projected gradient descent with step size 1/λmax⁡(A⊤A)1/\lambda_{\max}(\mathbf{A}^\top\mathbf{A}), projecting onto the rr-ball by clipping. Does the constrained solver recover the same weights, and does the multiplier computed from stationarity—taking the inner product of ∇ℓ(w)+λw=0\nabla\ell(\mathbf{w}) + \lambda\mathbf{w} = \mathbf{0} with w\mathbf{w} to get λ=−w⊤∇ℓ(w)/r2\lambda = -\mathbf{w}^\top\nabla\ell(\mathbf{w}) / r^2—match λ\lambda?

rng = np.random.default_rng()
A, b = rng.normal(size=(30, 5)), rng.normal(size=30)
grad = lambda w: A.T @ (A @ w - b)                    # gradient of 1/2 |Aw - b|^2
step = 1.0 / np.linalg.eigvalsh(A.T @ A).max()        # 1 / lambda_max(A^T A)
print(' lambda   r = |w_pen|   |w_con - w_pen|   recovered multiplier')
for lam in [0.1, 1.0, 10.0]:
    w_pen = np.linalg.solve(A.T @ A + lam * np.eye(5), A.T @ b)  # penalty form
    r = np.linalg.norm(w_pen)                         # its norm becomes the budget
    w = np.zeros(5)                                   # constraint form: PGD
    for _ in range(5000):
        w -= step * grad(w)
        w *= min(1.0, r / np.linalg.norm(w))          # project onto the r-ball
    lam_rec = -(w @ grad(w)) / r ** 2                 # KKT: grad l + lam w = 0
    print(f'{lam:7.2f}  {r:10.4f}  {np.linalg.norm(w - w_pen):15.2e}  {lam_rec:20.6f}')
 lambda   r = |w_pen|   |w_con - w_pen|   recovered multiplier
   0.10      0.4138         1.28e-16              0.100000
   1.00      0.3860         1.58e-16              1.000000
  10.00      0.2501         5.72e-17             10.000000

In every row, the constrained solution agrees with the penalized one to machine precision, and the multiplier recovered from stationarity matches λ\lambda to all six printed decimals (the exact budgets rr vary with the random draw). Penalty and constraint are simply two parameterizations of the same solution path, with the Lagrange multiplier translating between them.

23.7.4 The Convex Conjugate#

Evaluating the dual function qq normally requires solving a fresh unconstrained minimization for each choice of multipliers. When the constraints are linear, however, we can factor out the shared work and perform that minimization once and for all. For constraints Ax⪯b\mathbf{A}\mathbf{x} \preceq \mathbf{b}, the Lagrangian is f(x)+λ⊤(Ax−b)f(\mathbf{x}) + \boldsymbol{\lambda}^\top(\mathbf{A}\mathbf{x} - \mathbf{b}), so

q(λ)=inf⁡x[f(x)+(A⊤λ)⊤x]−b⊤λ.q(\boldsymbol{\lambda}) = \inf_{\mathbf{x}} \bigl[ f(\mathbf{x}) + (\mathbf{A}^\top\boldsymbol{\lambda})^\top \mathbf{x} \bigr] - \mathbf{b}^\top \boldsymbol{\lambda}.

Notice that the infimum depends on ff and on the single vector A⊤λ\mathbf{A}^\top\boldsymbol{\lambda}, not on A\mathbf{A} or b\mathbf{b} separately. If we compute, once for each common objective ff, the value of inf⁡x[f(x)−y⊤x]\inf_{\mathbf{x}} [f(\mathbf{x}) - \mathbf{y}^\top\mathbf{x}] as a function of y\mathbf{y}, then the dual of any linearly constrained problem with objective ff can be read straight off a lookup table. That lookup table is the convex conjugate.

23.7.4.1 Supporting Lines#

Start in one dimension with f(x)=12x2f(x) = \tfrac12 x^2 and pick a slope y=2y = 2. Which lines t=2x+ct = 2x + c of slope 22 stay everywhere on or below the parabola? We need 2x+c≤12x22x + c \le \tfrac12 x^2 for all xx, meaning c≤min⁡x(12x2−2x)=−2c \le \min_x (\tfrac12 x^2 - 2x) = -2, attained at x=2x = 2. The highest such line, t=2x−2t = 2x - 2, touches the parabola tangentially at (2,2)(2, 2), where f′(2)=2f'(2) = 2. Lowering a line of slope 22 until it touches the graph lands its vertical intercept at −2-2, and the number max⁡x(2x−12x2)=2\max_x (2x - \tfrac12 x^2) = 2 is minus that intercept, as shown in Figure 23.7.3(a).

Figure 23.7.3:

The convex conjugate as a supporting line. (a) For f(x)=12x2f(x)=\tfrac12x^2 and slope 22, lowering the dashed line of slope 22 until it touches the graph lands at x=2x=2 with intercept −2-2, giving f∗(2)=2f^*(2)=2. (b) For f(x)=∣x∣f(x)=|x|, a line of slope 12\tfrac12 supports the graph at the origin with intercept 00, whereas a line of slope 22 climbs faster than ∣x∣|x| for every intercept, giving f∗(12)=0f^*(\tfrac12)=0 and f∗(2)=+∞f^*(2)=+\infty. Thus the conjugate is finite precisely for the slopes that admit a supporting line below the graph.

The convex conjugate (also known as the Fenchel--Legendre transform) of a function f:Rn→R∪{+∞}f : \mathbb{R}^n \to \mathbb{R} \cup \{+\infty\} records this negated intercept for every slope vector y\mathbf{y} (we use an asterisk ∗* for conjugates and a star ⋆\star for optima):

f∗(y)  =  sup⁡x  (y⊤x−f(x)).(23.7.6)f^*(\mathbf{y}) \;=\; \sup_{\mathbf{x}} \;\left( \mathbf{y}^\top \mathbf{x} - f(\mathbf{x}) \right). \tag{23.7.6}

In geometric terms, f∗(y)f^*(\mathbf{y}) is minus the vertical intercept of the highest affine function of slope y\mathbf{y} that lies everywhere below the graph of ff. Rather than describing ff by its point values, the conjugate describes ff by its family of supporting lines. For f(x)=12x2f(x) = \tfrac12 x^2 and any slope yy, the supremum is attained at x=yx = y, giving f∗(y)=12y2f^*(y) = \tfrac12 y^2: the quadratic is its own conjugate.

Allowing ff to take the value +∞+\infty is a convenient way to encode a restricted domain: points where f(x)=+∞f(\mathbf{x}) = +\infty never contribute to the supremum, and convexity of such an extended-valued function simply means convexity of its epigraph.

The supremum itself can also be +∞+\infty. Take f(x)=∣x∣f(x) = |x| and slope y=2y = 2. For x>0x > 0, 2x−∣x∣=x2x - |x| = x grows without bound: no line of slope 22 can stay below the V-shaped graph, no matter how low its intercept. Whenever ∣y∣≤1|y| \le 1, on the other hand, yx−∣x∣≤0yx - |x| \le 0 with equality at x=0x = 0, so the line of slope yy through the origin supports the graph. Therefore f∗(y)=0f^*(y) = 0 for ∣y∣≤1|y| \le 1 and f∗(y)=+∞f^*(y) = +\infty otherwise (Figure 23.7.3(b)). In other words, the conjugate of the absolute value is the indicator function of the interval [−1,1][-1, 1]—the function equal to 00 inside the set and +∞+\infty outside it.

Two immediate properties follow straight from (23.7.6). First, f∗f^* is always convex, regardless of whether ff is convex. For each fixed x\mathbf{x}, the expression y⊤x−f(x)\mathbf{y}^\top\mathbf{x} - f(\mathbf{x}) is affine in y\mathbf{y}, and the pointwise supremum of affine functions is convex because its epigraph is the intersection of the half-spaces above them (the exact mirror image of the argument that made qq concave).

Second, because f∗(y)f^*(\mathbf{y}) is the supremum over all x\mathbf{x}, we have f∗(y)≥y⊤x−f(x)f^*(\mathbf{y}) \ge \mathbf{y}^\top\mathbf{x} - f(\mathbf{x}) for every x\mathbf{x} and y\mathbf{y}. Rearranging gives the Fenchel--Young inequality,

y⊤x  ≤  f(x)+f∗(y)for all x,y.(23.7.7)\mathbf{y}^\top \mathbf{x} \;\le\; f(\mathbf{x}) + f^*(\mathbf{y}) \qquad \textrm{for all } \mathbf{x}, \mathbf{y}. \tag{23.7.7}

Equality holds if and only if x\mathbf{x} attains the supremum in (23.7.6). When ff is convex and differentiable, this happens precisely when y=∇f(x)\mathbf{y} = \nabla f(\mathbf{x}), since x↦y⊤x−f(x)\mathbf{x} \mapsto \mathbf{y}^\top\mathbf{x} - f(\mathbf{x}) is then concave and maximized where its gradient vanishes. Convexity matters here: the nonconvex double well ϕ0(x)=(x2−1)2\phi_0(x) = (x^2 - 1)^2 has ϕ0′(0)=0\phi_0'(0) = 0, yet ϕ0∗(0)=−min⁡ϕ0=0\phi_0^*(0) = -\min \phi_0 = 0 and ϕ0(0)+ϕ0∗(0)=1>0\phi_0(0) + \phi_0^*(0) = 1 > 0, because x=0x = 0 is a local maximum rather than a point where a horizontal line supports the graph from below. For the self-conjugate pair 12∥x∥2\tfrac12\|\mathbf{x}\|^2, Fenchel--Young reduces to the familiar inequality y⊤x≤12∥x∥2+12∥y∥2\mathbf{y}^\top\mathbf{x} \le \tfrac12\|\mathbf{x}\|^2 + \tfrac12\|\mathbf{y}\|^2.

Does passing to the conjugate lose any information? For any convex function ff that is proper (never −∞-\infty and not identically +∞+\infty) and closed (its epigraph is a closed set), its supporting lines determine the graph completely, and taking the conjugate a second time recovers ff: f∗∗=ff^{**} = f (Rockafellar, 1970). When ff is nonconvex (and bounded below by at least one affine function), f∗∗f^{**} is the tightest closed convex function lying below ff—its convex envelope (Exercise 1d).

Here are the four conjugate pairs we use in this section and its exercises:

  • 12∥x∥2\tfrac12\|\mathbf{x}\|^2 and 12∥y∥2\tfrac12\|\mathbf{y}\|^2, the self-conjugate pair;
  • 12x⊤Ax\tfrac12\mathbf{x}^\top\mathbf{A}\mathbf{x} and 12y⊤A−1y\tfrac12\mathbf{y}^\top\mathbf{A}^{-1}\mathbf{y} for A≻0\mathbf{A} \succ 0 (attained at x=A−1y\mathbf{x} = \mathbf{A}^{-1}\mathbf{y});
  • exe^x and ylog⁡y−yy \log y - y for y>0y > 0, taking the value 00 at y=0y = 0 and +∞+\infty for y<0y \lt 0 (attained at x=log⁡yx = \log y, so for instance f∗(1)=−1f^*(1) = -1 and f∗(e)=0f^*(e) = 0);
  • λ∥x∥1\lambda\|\mathbf{x}\|_1 and the indicator of the box {y:∥y∥∞≤λ}\{\mathbf{y} : \|\mathbf{y}\|_\infty \le \lambda\}, the vector version of the absolute value above.

23.7.4.2 Duals of Linearly Constrained Problems#

Now return to the linearly constrained problem that motivated the conjugate: minimize f(x)f(\mathbf{x}) subject to Ax⪯b\mathbf{A}\mathbf{x} \preceq \mathbf{b}. Pulling a minus sign out of the infimum turns it directly into the supremum defining f∗f^*:

q(λ)=inf⁡x[f(x)+(A⊤λ)⊤x]−b⊤λ=−sup⁡x[(−A⊤λ)⊤x−f(x)]−b⊤λ=−f∗(−A⊤λ)−b⊤λ.(23.7.8)\begin{aligned} q(\boldsymbol{\lambda}) &= \inf_{\mathbf{x}} \left[ f(\mathbf{x}) + (\mathbf{A}^\top\boldsymbol{\lambda})^\top\mathbf{x} \right] - \mathbf{b}^\top\boldsymbol{\lambda} \\ &= -\sup_{\mathbf{x}} \left[ (-\mathbf{A}^\top\boldsymbol{\lambda})^\top\mathbf{x} - f(\mathbf{x}) \right] - \mathbf{b}^\top\boldsymbol{\lambda} \\ &= -f^*(-\mathbf{A}^\top\boldsymbol{\lambda}) - \mathbf{b}^\top\boldsymbol{\lambda}. \end{aligned} \tag{23.7.8}

For equality constraints Ax=b\mathbf{A}\mathbf{x} = \mathbf{b}, the exact same three lines yield q(ν)=−f∗(−A⊤ν)−b⊤νq(\boldsymbol{\nu}) = -f^*(-\mathbf{A}^\top\boldsymbol{\nu}) - \mathbf{b}^\top\boldsymbol{\nu}, with ν\boldsymbol{\nu} unconstrained in sign. Notice that this gives a second explanation for why qq is concave: f∗f^* is convex, its argument is linear in λ\boldsymbol{\lambda}, and the minus sign flips convexity to concavity.

Let us try (23.7.8) on the smallest possible example: finding the point closest to the origin in a half-plane, min⁡x12∥x∥2\min_{\mathbf{x}} \tfrac12\|\mathbf{x}\|^2 subject to a⊤x≤b\mathbf{a}^\top\mathbf{x} \le b, with a=(1,2)\mathbf{a} = (1, 2) and b=−1b = -1. Since the origin violates the constraint (a⊤0=0>−1\mathbf{a}^\top\mathbf{0} = 0 > -1), the constraint must bind at the optimum. Plugging f∗(y)=12∥y∥2f^*(\mathbf{y}) = \tfrac12\|\mathbf{y}\|^2 and ∥a∥2=5\|\mathbf{a}\|^2 = 5 into (23.7.8) gives the dual function in one step:

q(λ)=−12λ2∥a∥2−bλ=λ−52λ2.q(\lambda) = -\tfrac12 \lambda^2 \|\mathbf{a}\|^2 - b\lambda = \lambda - \tfrac52 \lambda^2 .

Setting q′(λ)=1−5λ=0q'(\lambda) = 1 - 5\lambda = 0 yields λ⋆=15\lambda^\star = \tfrac15 and d⋆=15−110=110d^\star = \tfrac15 - \tfrac1{10} = \tfrac1{10}. The minimizer of the Lagrangian at λ⋆\lambda^\star is the point attaining the conjugate supremum, x=−λ⋆a=(−0.2,−0.4)\mathbf{x} = -\lambda^\star\mathbf{a} = (-0.2, -0.4). Checking directly, a⊤x=−1=b\mathbf{a}^\top\mathbf{x} = -1 = b and f(x)=12(0.04+0.16)=110=d⋆f(\mathbf{x}) = \tfrac12(0.04 + 0.16) = \tfrac1{10} = d^\star, so weak duality certifies that x\mathbf{x} is optimal. This matches the projection formula (b/∥a∥2) a(b / \|\mathbf{a}\|^2)\,\mathbf{a} from Section 23.6.1.3, obtained here for a different hyperplane—and where the primal had two variables, the dual had one and fell in a single line.

23.7.4.3 Log-Sum-Exp and Entropy#

Throughout deep learning, softmax converts raw scores into probabilities by exponentiating and normalizing. Why exponentials, rather than some other positive function? The conjugate of the log-sum-exp function, lse(x)=log⁡∑iexi\mathrm{lse}(\mathbf{x}) = \log \sum_i e^{x_i}, gives a clean answer. Let Δ={p:p⪰0, 1⊤p=1}\Delta = \{\mathbf{p} : \mathbf{p} \succeq 0,\ \mathbf{1}^\top\mathbf{p} = 1\} denote the probability simplex and H(p)=−∑ipilog⁡piH(\mathbf{p}) = -\sum_i p_i \log p_i the Shannon entropy.

To compute lse∗(p)=sup⁡x(p⊤x−lse(x))\mathrm{lse}^*(\mathbf{p}) = \sup_{\mathbf{x}} \bigl(\mathbf{p}^\top\mathbf{x} - \mathrm{lse}(\mathbf{x})\bigr), first check when the supremum can be finite. If any coordinate pip_i is negative, sending xi→−∞x_i \to -\infty drives p⊤x\mathbf{p}^\top\mathbf{x} to +∞+\infty while lse(x)\mathrm{lse}(\mathbf{x}) stays bounded, so the supremum is +∞+\infty. If 1⊤p≠1\mathbf{1}^\top\mathbf{p} \neq 1, shifting all coordinates by a constant x=c1\mathbf{x} = c\mathbf{1} gives c(1⊤p−1)−log⁡nc(\mathbf{1}^\top\mathbf{p} - 1) - \log n (since lse(c1)=c+log⁡n\mathrm{lse}(c\mathbf{1}) = c + \log n), which again blows up as c→±∞c \to \pm\infty. Hence lse∗(p)\mathrm{lse}^*(\mathbf{p}) is finite only on the probability simplex Δ\Delta.

For p\mathbf{p} in the interior of Δ\Delta (all pi>0p_i > 0), setting the gradient with respect to x\mathbf{x} to zero gives softmax(x)=p\mathrm{softmax}(\mathbf{x}) = \mathbf{p}, which is solved by x=log⁡p\mathbf{x} = \log\mathbf{p} (up to an additive constant), yielding the value ∑ipilog⁡pi\sum_i p_i \log p_i. If p\mathbf{p} lies on the boundary of Δ\Delta with some pi=0p_i = 0, no finite maximizer exists because softmax outputs are always strictly positive; nevertheless, sending those coordinates xi→−∞x_i \to -\infty approaches the same value, so the formula extends continuously to all of Δ\Delta under the standard convention 0log⁡0=00 \log 0 = 0. Because lse\mathrm{lse} is convex and finite everywhere, lse∗∗=lse\mathrm{lse}^{**} = \mathrm{lse}, giving the conjugate pair

lse∗(p)={∑ipilog⁡pi=−H(p),p∈Δ,+∞,otherwise,lse(x)=max⁡p∈Δ(p⊤x+H(p))(dually).(23.7.9)\begin{aligned} \mathrm{lse}^*(\mathbf{p}) &= \begin{cases} \sum_i p_i \log p_i = -H(\mathbf{p}), & \mathbf{p} \in \Delta, \\ +\infty, & \textrm{otherwise,} \end{cases} \\ \mathrm{lse}(\mathbf{x}) &= \max_{\mathbf{p} \in \Delta} \left( \mathbf{p}^\top \mathbf{x} + H(\mathbf{p}) \right) \quad \textrm{(dually)}. \end{aligned} \tag{23.7.9}

Read the second line of (23.7.9) in words: log-sum-exp is the maximum of an expected score p⊤x\mathbf{p}^\top\mathbf{x} plus an entropy bonus H(p)H(\mathbf{p}) over all distributions on nn outcomes. Which distribution achieves this maximum? By the equality condition of Fenchel--Young, it is p=∇lse(x)\mathbf{p} = \nabla\mathrm{lse}(\mathbf{x}), whose ii-th entry is ∂ lse/∂xi=exi/∑jexj\partial\,\mathrm{lse}/\partial x_i = e^{x_i} / \sum_j e^{x_j}—precisely the softmax (whose Hessian we computed in Section 23.3). Put another way, among all distributions achieving the same expected score p⊤x\mathbf{p}^\top\mathbf{x}, softmax is the one with the largest entropy, matching the maximum-entropy derivation in Section 24.4.2 (and Exercise 2 derives softmax from that constraint side). Without the entropy term, maximizing p⊤x\mathbf{p}^\top\mathbf{x} over Δ\Delta puts all mass on arg⁡max⁡ixi\arg\max_i x_i; adding entropy softens that hard selection into a smooth probability distribution. The very same conjugacy construction, applied to the convex generator of an ff-divergence, produces the variational bounds used to train ff-GANs (Section 25.3.4).

23.7.5 Worked Examples#

We now work through three examples that highlight what duality reveals in practice. In the support vector machine, complementary slackness concentrates the solution on a handful of data points, while the dual exposes the data only through inner products. In water-filling, the Lagrange multiplier carries tangible engineering units—communication rate per unit of power. Finally, a one-dimensional nonconvex problem demonstrates the strict duality gap that convexity prevents.

23.7.5.1 The Support Vector Machine Dual#

Given linearly separable training data (xi,yi)(\mathbf{x}_i, y_i) with labels yi∈{±1}y_i \in \{\pm 1\}, the support vector machine (Boser et al., 1992) seeks the separating hyperplane w⊤x+b=0\mathbf{w}^\top\mathbf{x} + b = 0 with the widest possible margin. Its primal problem is

min⁡w,b  12∥w∥2subject toyi (w⊤xi+b)≥1,    i=1,…,n.(23.7.10)\min_{\mathbf{w}, b}\; \tfrac12 \|\mathbf{w}\|^2 \quad \textrm{subject to} \quad y_i\,(\mathbf{w}^\top \mathbf{x}_i + b) \ge 1, \;\; i = 1, \ldots, n. \tag{23.7.10}

Because the distance from a point x\mathbf{x} to the hyperplane is ∣w⊤x+b∣/∥w∥|\mathbf{w}^\top\mathbf{x} + b| / \|\mathbf{w}\| (Section 21.1), the two margin hyperplanes w⊤x+b=±1\mathbf{w}^\top\mathbf{x} + b = \pm 1 sit at distance 1/∥w∥1/\|\mathbf{w}\| on either side of the decision boundary, or 2/∥w∥2/\|\mathbf{w}\| apart. Minimizing 12∥w∥2\tfrac12\|\mathbf{w}\|^2 therefore maximizes the margin. This is a convex quadratic program with one affine inequality per training point. Since the constraints are affine, Slater's condition requires only a feasible point—which we obtain by rescaling any separating (w,b)(\mathbf{w}, b) until every point has margin at least 11. Strong duality is thus guaranteed.

Introduce one nonnegative multiplier αi≥0\alpha_i \ge 0 for each constraint and form the Lagrangian,

L(w,b,α)=12∥w∥2+∑iαi(1−yi(w⊤xi+b)).\mathcal{L}(\mathbf{w}, b, \boldsymbol{\alpha}) = \tfrac12\|\mathbf{w}\|^2 + \sum_i \alpha_i \left(1 - y_i(\mathbf{w}^\top\mathbf{x}_i + b)\right).

To compute the dual function q(α)=inf⁡w,bLq(\boldsymbol{\alpha}) = \inf_{\mathbf{w}, b} \mathcal{L}, notice first that L\mathcal{L} is affine in the unpenalized offset bb, with coefficient −∑iαiyi-\sum_i \alpha_i y_i. Unless that coefficient vanishes, sending b→±∞b \to \pm\infty drives L\mathcal{L} to −∞-\infty, so q(α)=−∞q(\boldsymbol{\alpha}) = -\infty whenever ∑iαiyi≠0\sum_i \alpha_i y_i \neq 0. Here we see the effective domain of (23.7.2) in action: the finiteness condition ∑iαiyi=0\sum_i \alpha_i y_i = 0 becomes an explicit equality constraint in the dual. On this domain the bb-term disappears, leaving a strictly convex quadratic in w\mathbf{w} whose unique minimum occurs where ∇wL=0\nabla_{\mathbf{w}} \mathcal{L} = \mathbf{0}:

w=∑iαiyi xi,on the domain∑iαiyi=0.\mathbf{w} = \sum_i \alpha_i y_i\, \mathbf{x}_i, \qquad\textrm{on the domain}\qquad \sum_i \alpha_i y_i = 0.

Thus the optimal weight vector is a linear combination of the training inputs, weighted by their multipliers. Substituting this expression back into L\mathcal{L} yields the SVM dual:

max⁡α⪰0, ∑iαiyi=0    ∑iαi  −  12∑i,jαiαj yiyj xi⊤xj.(23.7.11)\max_{\boldsymbol{\alpha} \succeq 0,\ \sum_i \alpha_i y_i = 0}\;\; \sum_i \alpha_i \;-\; \tfrac12 \sum_{i,j} \alpha_i \alpha_j\, y_i y_j\, \mathbf{x}_i^\top \mathbf{x}_j. \tag{23.7.11}

Two striking consequences follow before we even choose a solver. First, complementary slackness, αi(1−yi(w⊤xi+b))=0\alpha_i (1 - y_i(\mathbf{w}^\top\mathbf{x}_i + b)) = 0, tells us that any point with αi>0\alpha_i > 0 must satisfy yi(w⊤xi+b)=1y_i(\mathbf{w}^\top\mathbf{x}_i + b) = 1, lying right on one of the margin hyperplanes. These points are the support vectors. In Figure 23.7.4 they can only be among the four ringed points. Their constraints are active and their normals balance ∇f\nabla f, as in Figure 23.6.2, whereas every point with αi=0\alpha_i = 0 drops out of w\mathbf{w} completely. Second, the training inputs enter (23.7.11) exclusively through inner products xi⊤xj\mathbf{x}_i^\top\mathbf{x}_j. Replacing those inner products with a kernel function k(xi,xj)k(\mathbf{x}_i, \mathbf{x}_j) immediately yields a nonlinear classifier—a structure the primal formulation hides.

Figure 23.7.4:

Maximum-margin separation of the eight points that the code cell below uses. The solid line is the decision boundary w⋆⊤x+b⋆=0\mathbf{w}^{\star\top}\mathbf{x} + b^\star = 0 with w⋆=(47,47)\mathbf{w}^\star = (\tfrac47, \tfrac47) and b⋆=−37b^\star = -\tfrac37. The dashed lines are the margin hyperplanes w⋆⊤x+b⋆=±1\mathbf{w}^{\star\top}\mathbf{x} + b^\star = \pm 1, a distance 2/∥w⋆∥2/\|\mathbf{w}^\star\| apart. Only the four ringed points, which lie on a margin hyperplane, can carry αi>0\alpha_i > 0.

Notice that the equality constraint ∑iαiyi=0\sum_i \alpha_i y_i = 0 arose solely because the unpenalized offset bb left the Lagrangian affine in one direction. To keep the dual feasible set as simple as the nonnegative orthant (where projection just clips negative entries to zero), we solve a closely related variant in code by folding the offset into the weights: augment each input with a constant feature x~i=(xi,1)\tilde{\mathbf{x}}_i = (\mathbf{x}_i, 1), set w~=(w,b)\tilde{\mathbf{w}} = (\mathbf{w}, b), and minimize 12∥w~∥2\tfrac12\|\tilde{\mathbf{w}}\|^2 subject to yiw~⊤x~i≥1y_i \tilde{\mathbf{w}}^\top \tilde{\mathbf{x}}_i \ge 1. Because this variant penalizes bb as well, its decision boundary can differ slightly from (23.7.10); in return, its Lagrangian is strictly convex in every primal variable, eliminating the equality constraint. Defining Qij=yiyjx~i⊤x~j\mathbf{Q}_{ij} = y_i y_j \tilde{\mathbf{x}}_i^\top \tilde{\mathbf{x}}_j, the dual becomes

max⁡α⪰0    1⊤α−12α⊤Q α,(23.7.12)\max_{\boldsymbol{\alpha} \succeq 0}\;\; \mathbf{1}^\top \boldsymbol{\alpha} - \tfrac12 \boldsymbol{\alpha}^\top \mathbf{Q}\, \boldsymbol{\alpha}, \tag{23.7.12}

a concave quadratic over the nonnegative orthant. Applying projected gradient ascent—the update of Section 23.6.3 with the step sign flipped—iterates α←max⁡(0, α+η (1−Qα))\boldsymbol{\alpha} \leftarrow \max(\mathbf{0},\, \boldsymbol{\alpha} + \eta\,(\mathbf{1} - \mathbf{Q}\boldsymbol{\alpha})) using the safe step size η=1/λmax⁡(Q)\eta = 1/\lambda_{\max}(\mathbf{Q}). Let us run this ascent on eight points in the plane and check three predictions: does the recovered hyperplane separate the data, do all positive multipliers sit on points of margin 11, and does the dual value match the primal value?

X = np.array([[1.0, 1.5], [2.0, 0.5], [2.5, 2.0], [1.5, 3.0],
              [-1.0, -0.5], [-2.0, 1.0], [-1.5, -2.0], [0.5, -1.5]])
y = np.array([1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0])
Xa = np.hstack([X, np.ones((len(X), 1))])     # fold the offset b into w
G = y[:, None] * Xa                           # rows y_i x~_i
Q = G @ G.T                                   # Q_ij = y_i y_j x~_i^T x~_j
alpha = np.zeros(len(X))
eta = 1.0 / np.linalg.eigvalsh(Q).max()       # 1 / lambda_max(Q)
for _ in range(5000):                         # projected gradient ascent
    alpha = np.maximum(0.0, alpha + eta * (1.0 - Q @ alpha))
w = G.T @ alpha                               # w~* = sum_i alpha_i y_i x~_i
margins = y * (Xa @ w)
dual, primal = alpha.sum() - 0.5 * alpha @ Q @ alpha, 0.5 * w @ w
print('alpha* =', alpha.round(4))
print('rank of Q =', np.linalg.matrix_rank(Q), '  multipliers > 0:', int((alpha > 1e-8).sum()))
print('w* =', w[:2].round(4), ' b* =', w[2].round(4),
      ' separates data:', bool((np.sign(Xa @ w) == y).all()))
print('margins y_i (w^T x_i + b) =', margins.round(4))
print(f'primal = {primal:.6f}, dual = {dual:.6f}, gap = {abs(primal - dual):.1e}, '
      f'comp. slack = {np.abs(alpha * (margins - 1.0)).max():.1e}')
alpha* = [0.1309 0.0732 0.     0.     0.     0.2442 0.     0.3885]
rank of Q = 3   multipliers > 0: 4
w* = [0.5714 0.5714]  b* = -0.4286  separates data: True
margins y_i (w^T x_i + b) = [1.     1.     2.1429 2.1429 1.2857 1.     2.4286 1.    ]
primal = 0.418367, dual = 0.418367, gap = 4.4e-16, comp. slack = 3.0e-16

All three predictions hold. Four multipliers are positive, and precisely those four points sit at margin 11; the other four have margins between 1.291.29 and 2.432.43 with αi=0\alpha_i = 0. The printed digits match the exact solution w~⋆=(47,47,−37)\tilde{\mathbf{w}}^\star = (\tfrac47, \tfrac47, -\tfrac37)—that is, w⋆=(47,47)\mathbf{w}^\star = (\tfrac47, \tfrac47) and b⋆=−37b^\star = -\tfrac37—with p⋆=d⋆=4198≈0.418367p^\star = d^\star = \tfrac{41}{98} \approx 0.418367 and a duality gap near 10−1610^{-16}. (The equality of the primal and dual values also follows directly from the identity ∑iαi⋆=∥w~⋆∥2\sum_i \alpha_i^\star = \|\tilde{\mathbf{w}}^\star\|^2 at the optimum; see Exercise 4a.)

The printout also highlights a subtle point about interpreting dual solutions. Because the primal objective 12∥w~∥2\tfrac12\|\tilde{\mathbf{w}}\|^2 is strictly convex, the primal optimum w~⋆\tilde{\mathbf{w}}^\star is unique. The dual optimum α⋆\boldsymbol{\alpha}^\star is not. Here Q=GG⊤\mathbf{Q} = \mathbf{G}\mathbf{G}^\top, where G\mathbf{G} is the 8×38 \times 3 matrix with rows yix~i⊤y_i\tilde{\mathbf{x}}_i^\top, so Q\mathbf{Q} has rank at most 33. Because the four support vectors correspond to four vectors in R3\mathbb{R}^3, they are linearly dependent: there exists a nonzero vector d\mathbf{d} supported on those four indices with G⊤d=0\mathbf{G}^\top\mathbf{d} = \mathbf{0}. Moving α⋆\boldsymbol{\alpha}^\star along d\mathbf{d} leaves the quadratic term unchanged (since Qd=0\mathbf{Q}\mathbf{d} = \mathbf{0}) and leaves the linear term unchanged as well, because every support vector has margin 11: 1⊤d=∑idi yiw~⋆⊤x~i=w~⋆⊤G⊤d=0\mathbf{1}^\top\mathbf{d} = \sum_i d_i\, y_i\tilde{\mathbf{w}}^{\star\top}\tilde{\mathbf{x}}_i = \tilde{\mathbf{w}}^{\star\top}\mathbf{G}^\top\mathbf{d} = 0. Thus an entire line segment of multiplier vectors is optimal, all yielding the same w~⋆\tilde{\mathbf{w}}^\star and the same dual value; projected ascent from 0\mathbf{0} simply returns one point on that segment. At each endpoint of the segment, one of the four margin-11 points actually has αi=0\alpha_i = 0 (Exercise 4c). Remember that complementary slackness runs in one direction: αi>0\alpha_i > 0 guarantees margin 11, but margin 11 does not force αi>0\alpha_i > 0.

23.7.5.2 Water-Filling#

Our second worked example has both a closed-form solution and an unforgettable physical picture. Suppose a transmitter must divide a total power budget PP across nn independent communication channels. Channel ii has background noise power Ni>0N_i > 0, and allocating power Pi≥0P_i \ge 0 to it yields a transmission rate of log⁡(1+Pi/Ni)\log(1 + P_i / N_i) nats per use (Cover and Thomas, 1999). (Cover and Thomas include a factor of 12\tfrac12 for a real Gaussian channel, which rescales the Lagrange multiplier below without changing the optimal allocation.) To maximize the total rate, we solve

max⁡P  U(P)=∑i=1nlog⁡(1+PiNi)subject toPi≥0,    ∑iPi=P.(23.7.13)\max_{\mathbf{P}}\; U(\mathbf{P}) = \sum_{i=1}^n \log\left(1 + \frac{P_i}{N_i}\right) \quad \textrm{subject to} \quad P_i \ge 0, \;\; \sum_i P_i = P. \tag{23.7.13}

Maximizing the concave function UU is equivalent to minimizing the convex function −U-U under affine constraints. Because a strictly positive feasible allocation exists, Slater's condition holds, and the KKT conditions are both necessary and sufficient. Introducing a multiplier ν\nu for the budget equality ∑iPi−P=0\sum_i P_i - P = 0 and multipliers λi≥0\lambda_i \ge 0 for the nonnegativity constraints −Pi≤0-P_i \le 0, stationarity of the Lagrangian of −U-U reads

1Ni+Pi=ν−λi.\frac{1}{N_i + P_i} = \nu - \lambda_i .

Now read off the two cases. Whenever channel ii receives positive power (Pi>0P_i > 0), complementary slackness forces λi=0\lambda_i = 0, so Ni+Pi=1/νN_i + P_i = 1/\nu: every active channel ends up at the exact same total level 1/ν1/\nu. Whenever channel ii receives no power (Pi=0P_i = 0), dual feasibility λi=ν−1/Ni≥0\lambda_i = \nu - 1/N_i \ge 0 requires Ni≥1/νN_i \ge 1/\nu. Writing θ=1/ν\theta = 1/\nu for this common threshold, the optimal allocation takes the compact form

Pi⋆=max⁡(θ−Ni, 0),with θ set by ∑imax⁡(θ−Ni, 0)=P.P_i^\star = \max(\theta - N_i,\, 0), \qquad \textrm{with } \theta \textrm{ set by } \sum_i \max(\theta - N_i,\, 0) = P.

This is the classic water-filling rule. Imagine each channel as a basin whose floor sits at height NiN_i, and pour a volume PP of water into the collection of basins. As Figure 23.7.5 illustrates, the water settles to a uniform surface level θ\theta, pouring the most power into the quietest channels and leaving any basin whose floor exceeds θ\theta completely dry. Because ∑imax⁡(θ−Ni,0)\sum_i \max(\theta - N_i, 0) is continuous, piecewise linear, zero for θ≤min⁡iNi\theta \le \min_i N_i, and strictly increasing for θ>min⁡iNi\theta > \min_i N_i, any budget P>0P > 0 determines a unique water level θ\theta, which bisection finds effortlessly. (The simplex projection in Section 23.6.3 has the same threshold structure inverted: subtract a common level from each coordinate and clip at zero.)

Figure 23.7.5:

Water-filling for the noise floors and budget in the code cell below: pouring P=3P=3 units of power into basins with floors at NiN_i fills the three quietest channels to the common level θ=1/ν⋆≈1.43\theta=1/\nu^\star\approx1.43, allocating Pi⋆=θ−NiP_i^\star=\theta-N_i to each, while the two basins with floors above θ\theta receive nothing, as complementary slackness requires.

The shadow-price proposition gives ν⋆\nu^\star an immediate engineering meaning. Since maximizing UU is minimizing −U-U, relaxing the budget from PP to P+vP + v changes −U⋆-U^\star at rate −ν⋆-\nu^\star, so dU⋆/dP=ν⋆=1/θ\mathrm{d}U^\star / \mathrm{d}P = \nu^\star = 1/\theta: the optimal multiplier is the extra communication rate gained per unit of additional power. Let us compute the water-filling allocation for five channels and check this shadow-price prediction against finite differences at P±10−4P \pm 10^{-4}.

N = np.array([0.1, 0.4, 0.8, 1.6, 2.5])       # channel noise levels
P = 3.0                                       # total power budget

def water_fill(P, N, steps=60):
    lo, hi = N.min(), N.min() + P             # bracket for the water level
    for _ in range(steps):                    # bisection on the level theta
        mid = 0.5 * (lo + hi)
        lo, hi = (mid, hi) if np.maximum(0, mid - N).sum() < P else (lo, mid)
    theta = 0.5 * (lo + hi)
    return theta, np.maximum(0.0, theta - N)

theta, power = water_fill(P, N)
print('water level theta =', f'{theta:.6f}', ' P* =', power.round(4),
      ' total =', f'{power.sum():.6f}')
print('wet channels at the common level:', (N + power)[power > 0].round(6))
print('dry channels above the level:    ', bool((N[power == 0] >= theta).all()))
rate = lambda power: np.log(1.0 + power / N).sum()
dP = 1e-4                                     # shadow price, two ways
nu = 1.0 / theta
sens = (rate(water_fill(P + dP, N)[1]) - rate(water_fill(P - dP, N)[1])) / (2 * dP)
print(f'nu = 1/theta = {nu:.6f} vs finite-difference dU*/dP = {sens:.6f}')
water level theta = 1.433333  P* = [1.3333 1.0333 0.6333 0.     0.    ]  total = 3.000000
wet channels at the common level: [1.433333 1.433333 1.433333]
dry channels above the level:     True
nu = 1/theta = 0.697674 vs finite-difference dU*/dP = 0.697674

The power budget is met to machine precision, the three active channels all sit at the common level θ=(3+0.1+0.4+0.8)/3≈1.4333\theta = (3 + 0.1 + 0.4 + 0.8)/3 \approx 1.4333, and the noisy channels at 1.61.6 and 2.52.5 stay dry, just as dual feasibility requires. Moreover, the multiplier ν⋆=1/θ=0.697674\nu^\star = 1/\theta = 0.697674 matches the finite-difference sensitivity dU⋆/dP\mathrm{d}U^\star / \mathrm{d}P to all six printed digits.

23.7.5.3 An Explicit Duality Gap#

Weak duality holds for every problem, but strong duality does not. A one-dimensional nonconvex example makes the gap concrete. Over the domain D=[0,1]\mathcal{D} = [0, 1], consider

min⁡x∈[0,1]  f(x)=−x2subject tog(x)=x−12≤0.\min_{x \in [0, 1]}\; f(x) = -x^2 \quad \textrm{subject to} \quad g(x) = x - \tfrac12 \le 0 .

Because f(x)=−x2f(x) = -x^2 is concave rather than convex, the problem is nonconvex. The feasible set is [0,12][0, \tfrac12], and the minimum sits at the right endpoint, p⋆=f(12)=−14p^\star = f(\tfrac12) = -\tfrac14. We dualize only the constraint g(x)≤0g(x) \le 0, keeping D=[0,1]\mathcal{D} = [0, 1] as a hard domain constraint so that the infimum in (23.7.2) runs over [0,1][0, 1] (weak duality applies unchanged). For any λ≥0\lambda \ge 0, the Lagrangian L(x,λ)=−x2+λ(x−12)\mathcal{L}(x, \lambda) = -x^2 + \lambda(x - \tfrac12) is concave in xx, so its minimum on [0,1][0, 1] must occur at one of the two endpoints: L(0,λ)=−λ/2\mathcal{L}(0, \lambda) = -\lambda/2 or L(1,λ)=λ/2−1\mathcal{L}(1, \lambda) = \lambda/2 - 1. Therefore,

q(λ)=min⁡ ⁣(−λ2,  λ2−1),q(\lambda) = \min\!\left(-\frac{\lambda}{2},\; \frac{\lambda}{2} - 1\right),

which is piecewise linear and concave, as guaranteed. The two lines intersect at λ⋆=1\lambda^\star = 1, where d⋆=−12<−14=p⋆d^\star = -\tfrac12 \lt -\tfrac14 = p^\star: a strict duality gap of 14\tfrac14. Let us plot q(λ)q(\lambda) alongside p⋆p^\star to compare this nonconvex dual curve with the clipping plot from the start of the section.

xs = np.linspace(0.0, 1.0, 4001)              # the domain D = [0, 1]
fx, gx = -xs**2, xs - 0.5                     # objective and constraint on D
p_star = fx[gx <= 0.0].min()                  # primal optimum: -1/4
lams = np.linspace(0.0, 3.0, 601)
q = np.array([(fx + lam * gx).min() for lam in lams])  # dual function on D
d_star, lam_star = q.max(), lams[q.argmax()]
print(f'p* = {p_star:.4f},  d* = {d_star:.4f} at lambda = {lam_star:.2f},'
      f'  gap = {p_star - d_star:.4f}')
d2l.plot(lams, [q, np.full_like(lams, p_star)], 'lambda', 'value',
         legend=['dual function q(lambda)', 'primal optimum p*'])
p* = -0.2500,  d* = -0.5000 at lambda = 1.00,  gap = 0.2500

Unlike the clipping curve, which rose smoothly to touch p⋆p^\star, this tent peaks at −12-\tfrac12, a full quarter below the primal optimum. Notice that a strictly feasible point certainly exists—x=14x = \tfrac14 lies in the interior of D\mathcal{D} with g(14)=−14<0g(\tfrac14) = -\tfrac14 \lt 0—so the gap is caused entirely by the lack of convexity, not by a failure of Slater's condition. Returning to panel (b) of Figure 23.7.2, the image curve {(u,−(u+12)2):u∈[−12,12]}\{(u, -(u + \tfrac12)^2) : u \in [-\tfrac12, \tfrac12]\} bends downward, so no supporting line below A\mathcal{A} can reach (0,p⋆)(0, p^\star); the highest one, of slope −1-1, certifies only −12-\tfrac12.

Two open challenges remain. First, for a nonconvex problem, the dual can bound the optimum but need not reach it. Second, even when a saddle point exists, updating x\mathbf{x} and λ\boldsymbol{\lambda} simultaneously can fail to converge, a central difficulty in minimax training. While training an entire deep network is nonconvex, many of its building blocks (projections, clipped updates, last-layer fits, and convex trust-region subproblems) are convex, and everything in this section applies directly to them. So far, however, every derivation in this chapter has assumed exact real arithmetic; in the next section we turn to what happens when finite floating-point precision, rather than the optimization algorithm itself, determines the answer.

23.7.6 Summary#

For any constrained optimization problem, the Lagrange dual function q(λ,ν)=inf⁡x∈DL(x,λ,ν)q(\boldsymbol{\lambda}, \boldsymbol{\nu}) = \inf_{\mathbf{x} \in \mathcal{D}} \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) is concave and satisfies weak duality, q(λ,ν)≤p⋆q(\boldsymbol{\lambda}, \boldsymbol{\nu}) \le p^\star, so every choice of λ⪰0\boldsymbol{\lambda} \succeq 0 certifies a lower bound on the primal optimum. When the primal problem is convex and satisfies Slater's condition (a strictly feasible point for all non-affine inequalities), strong duality closes the gap (d⋆=p⋆d^\star = p^\star) and attained primal--dual optima form a saddle point of the Lagrangian. For linear constraints, the dual reduces to the convex conjugate, q(λ)=−f∗(−A⊤λ)−b⊤λq(\boldsymbol{\lambda}) = -f^*(-\mathbf{A}^\top\boldsymbol{\lambda}) - \mathbf{b}^\top\boldsymbol{\lambda}, which turns conjugate pairs such as log-sum-exp and negative entropy directly into dual formulations. Under strong duality, the optimal multipliers act as shadow prices (λi⋆=−∂p⋆/∂ui\lambda_i^\star = -\partial p^\star / \partial u_i and νj⋆=−∂p⋆/∂vj\nu_j^\star = -\partial p^\star / \partial v_j wherever p⋆p^\star is differentiable), explaining why weight decay matches a norm constraint for convex losses, why SVM multipliers vanish off the support vectors, and why the water-filling multiplier 1/θ1/\theta measures communication rate per unit of power. Without convexity, a strict duality gap can remain, as shown by minimizing −x2-x^2 on [0,1][0, 1] subject to x≤12x \le \tfrac12.

23.7.7 Exercises#

  1. Conjugate pairs. Compute each conjugate from (23.7.6).

    1. f(x)=λ∥x∥1f(\mathbf{x}) = \lambda\|\mathbf{x}\|_1 with λ>0\lambda > 0.
    2. f(x)=12x⊤Axf(\mathbf{x}) = \tfrac12 \mathbf{x}^\top \mathbf{A} \mathbf{x} with A≻0\mathbf{A} \succ 0. What does the Fenchel--Young inequality (23.7.7) state for this pair?
    3. The softplus f(t)=log⁡(1+et)f(t) = \log(1 + e^t) on R\mathbb{R}. The binary cross-entropy of a logit tt against a soft label p∈[0,1]p \in [0, 1] is log⁡(1+et)−pt\log(1 + e^t) - pt. Use Fenchel--Young to show that it is at least the binary entropy H(p)=−plog⁡p−(1−p)log⁡(1−p)H(p) = -p\log p - (1-p)\log(1-p), with equality exactly when p=1/(1+e−t)p = 1/(1 + e^{-t}), the sigmoid of tt. Write the difference as a KL divergence.
    4. The double well ϕ0(x)=(x2−1)2\phi_0(x) = (x^2 - 1)^2 of Section 23.3.4 (the function ϕ\phi there without its tilt x/2x/2) is not convex. Find its convex envelope ϕ0∗∗\phi_0^{**} and the set on which ϕ0∗∗<ϕ0\phi_0^{**} \lt \phi_0.

    Adapted from Boyd and Vandenberghe, Convex Optimization, Examples 3.22 and 3.26.

  2. Maximum entropy and temperature. The entropy of a probability vector p∈Rn\mathbf{p} \in \mathbb{R}^n is H(p)=−∑ipilog⁡piH(\mathbf{p}) = -\sum_i p_i \log p_i. This exercise derives the softmax from the constraint side.

    1. Maximize HH subject to ∑ipi=1\sum_i p_i = 1 with one Lagrange multiplier, ignoring the sign constraints pi≥0p_i \ge 0. Show that the only stationary point is the uniform distribution. Why does ignoring the sign constraints not change the answer?
    2. Fix scores s1,…,sns_1, \ldots, s_n, not all equal, and a target sˉ\bar s strictly between min⁡isi\min_i s_i and max⁡isi\max_i s_i, and add the constraint ∑ipisi=sˉ\sum_i p_i s_i = \bar s. Show that the maximizer is p=softmax(βs)\mathbf{p} = \mathrm{softmax}(\beta\mathbf{s}) for a scalar β\beta determined by the multiplier of the score constraint. Show that the mean score under softmax(βs)\mathrm{softmax}(\beta\mathbf{s}) increases strictly with β\beta, so that exactly one β\beta meets the target.
    3. Let H⋆(sˉ)H^\star(\bar s) be the maximal entropy. Show that dH⋆/dsˉ=−β\mathrm{d}H^\star / \mathrm{d}\bar s = -\beta, so that the multiplier prices the score constraint as the multiplier of Section 23.6.1.3 prices the offset bb. For which targets sˉ\bar s is β\beta negative? What happens to the softmax temperature 1/β1/\beta as sˉ\bar s approaches max⁡isi\max_i s_i?
  3. A dual certificate for ℓ1\ell_1 minimization. Basis pursuit,

min⁡x  ∥x∥1subject toAx=b,(23.7.14)\min_{\mathbf{x}}\; \|\mathbf{x}\|_1 \quad \textrm{subject to} \quad \mathbf{A}\mathbf{x} = \mathbf{b}, \tag{23.7.14}

with A∈Rm×n\mathbf{A} \in \mathbb{R}^{m \times n} and m<nm \lt n, selects a sparse solution of an underdetermined linear system. Its constraints are affine, so Slater's condition needs only a feasible point and gives d⋆=p⋆d^\star = p^\star whenever the system has a solution. The conjugate of ∥⋅∥1\|\cdot\|_1 is the indicator of the box {y:∥y∥∞≤1}\{\mathbf{y} : \|\mathbf{y}\|_\infty \le 1\}.

  1. Use the equality form of (23.7.8) to show that, after replacing ν\boldsymbol{\nu} by −ν-\boldsymbol{\nu}, the dual problem is max⁡νb⊤ν\max_{\boldsymbol{\nu}} \mathbf{b}^\top \boldsymbol{\nu} subject to ∥A⊤ν∥∞≤1\|\mathbf{A}^\top \boldsymbol{\nu}\|_\infty \le 1.

  2. Solve both problems by hand for A=(1    2)\mathbf{A} = (1\;\; 2) and b=2b = 2, and check d⋆=p⋆d^\star = p^\star.

  3. Let x⋆\mathbf{x}^\star and ν⋆\boldsymbol{\nu}^\star be optimal. Show that xi⋆=0x_i^\star = 0 wherever ∣(A⊤ν⋆)i∣<1|(\mathbf{A}^\top \boldsymbol{\nu}^\star)_i| \lt 1, and that (A⊤ν⋆)i=sign(xi⋆)(\mathbf{A}^\top \boldsymbol{\nu}^\star)_i = \mathrm{sign}(x_i^\star) wherever xi⋆≠0x_i^\star \neq 0. A candidate x\mathbf{x} with Ax=b\mathbf{A}\mathbf{x} = \mathbf{b} is given. Which conditions must a vector ν\boldsymbol{\nu} satisfy to certify that x\mathbf{x} is optimal without solving the problem?

  4. Support vectors and the dual value. For the offset-folded SVM dual (23.7.12), let α⋆\boldsymbol{\alpha}^\star be optimal and w~⋆=∑iαi⋆yix~i\tilde{\mathbf{w}}^\star = \sum_i \alpha_i^\star y_i \tilde{\mathbf{x}}_i.

    1. Show that ∑iαi⋆=∥w~⋆∥2\sum_i \alpha_i^\star = \|\tilde{\mathbf{w}}^\star\|^2 by writing the KKT conditions of the dual over the orthant. Conclude that the dual optimal value equals the primal value 12∥w~⋆∥2\tfrac12 \|\tilde{\mathbf{w}}^\star\|^2.
    2. Show that deleting a training point with αj⋆=0\alpha_j^\star = 0 leaves the remaining multipliers optimal for the smaller problem and leaves w~⋆\tilde{\mathbf{w}}^\star unchanged. In leave-one-out validation, each of the nn points is classified by the SVM trained on the other n−1n - 1 points. Conclude that the leave-one-out error rate is at most the fraction of points with αi⋆>0\alpha_i^\star > 0, for every optimal α⋆\boldsymbol{\alpha}^\star. Which optimal α⋆\boldsymbol{\alpha}^\star gives the best bound?
    3. [code] The matrix Q\mathbf{Q} of the SVM cell has rank 33. Let SS be the four indices with αi⋆>0\alpha_i^\star > 0 and GS\mathbf{G}_S the corresponding rows of G. Find a nonzero d∈R4\mathbf{d} \in \mathbb{R}^4 with GS⊤d=0\mathbf{G}_S^\top\mathbf{d} = \mathbf{0} (use np.linalg.svd of GS⊤\mathbf{G}_S^\top), and move αS⋆+td\boldsymbol{\alpha}^\star_S + t\mathbf{d} in each direction until a coordinate reaches zero. Verify that both endpoints are dual feasible, have dual value 4198\tfrac{41}{98}, and give the same w~⋆\tilde{\mathbf{w}}^\star. Which margin-11 point has αi=0\alpha_i = 0 at each endpoint? What does this say about reading "support vector" off the multipliers? (You should find the endpoints (0,0.204,0,0,0,0.192,0,0.441)(0, 0.204, 0, 0, 0, 0.192, 0, 0.441) and (0.204,0,0,0,0,0.273,0,0.359)(0.204, 0, 0, 0, 0, 0.273, 0, 0.359).)
  5. [code] Gradient descent--ascent. ● Primal--dual methods and GAN training update the minimizing variable by gradient descent and the maximizing variable by gradient ascent at the same time.

    1. For the bilinear game min⁡xmax⁡y xy\min_x \max_y\, xy, whose saddle point is the origin, write simultaneous descent--ascent, x←x−ηyx \leftarrow x - \eta y and y←y+ηxy \leftarrow y + \eta x, as a linear map. Show that every nonzero start spirals away from the saddle for every η>0\eta > 0. Show that the alternating version, in which the yy-update uses the new xx, is a linear map with determinant 11. What do its iterates do for η<2\eta \lt 2?
    2. Run simultaneous descent--ascent on the Lagrangian L(x,ν)=12x⊤x+ν(a⊤x−b)\mathcal{L}(\mathbf{x}, \nu) = \tfrac12\mathbf{x}^\top \mathbf{x} + \nu(\mathbf{a}^\top \mathbf{x} - b) of the closest-point problem of Section 23.6.1.3, here with a=(1,2)\mathbf{a} = (1, 2), b=1b = 1, and the start x=0\mathbf{x} = \mathbf{0}, ν=0\nu = 0. Find the step sizes for which the iterates converge to (x⋆,ν⋆)(\mathbf{x}^\star, \nu^\star). Derive them from the eigenvalues of the update acting on the pair (a⊤x/∥a∥,ν)(\mathbf{a}^\top \mathbf{x} / \|\mathbf{a}\|, \nu) and on the components of x\mathbf{x} orthogonal to a\mathbf{a}.
    3. Add ϵ2x2\tfrac{\epsilon}{2} x^2 with 0<ϵ≤20 \lt \epsilon \le 2 to the objective of the bilinear game. For which step sizes does simultaneous descent--ascent converge now? Which term of the Lagrangian of the previous part plays the role of ϵ\epsilon?
  6. [code] Penalty versus constraint without convexity. ● For a convex loss, Section 23.7.3.2 shows that weight decay and a norm constraint trace the same solutions. Take instead the nonconvex one-dimensional loss ℓ(w)=(w−1)2(w−3)2−w\ell(w) = (w - 1)^2 (w - 3)^2 - w, whose local minima lie near w=1.16w = 1.16 and w=3.11w = 3.11.

    1. On a fine grid of ww, compute the penalized minimizers wλ=argminw ℓ(w)+λ2w2w_\lambda = \mathrm{argmin}_w\, \ell(w) + \tfrac\lambda2 w^2 for λ\lambda on a logarithmic grid, and the constrained optimum p⋆(r)=min⁡{ℓ(w):w2≤r2}p^\star(r) = \min \{\ell(w) : w^2 \le r^2\} for r∈[0,3.2]r \in [0, 3.2]. Plot the points (wλ2,ℓ(wλ))(w_\lambda^2, \ell(w_\lambda)) on top of the curve (r2,p⋆(r))(r^2, p^\star(r)). Which budgets rr are never the norm ∣wλ∣|w_\lambda| of a penalized minimizer?
    2. Show that wλw_\lambda minimizes ℓ(w)+λ2w2\ell(w) + \tfrac\lambda2 w^2 if and only if the line of slope −λ2-\tfrac\lambda2 through (wλ2,ℓ(wλ))(w_\lambda^2, \ell(w_\lambda)) lies below every point of the set {(w2,ℓ(w)):w∈R}\{(w^2, \ell(w)) : w \in \mathbb{R}\}. Use this and the supporting-line picture of Figure 23.7.2 to explain the missing budgets.
    3. Pick a budget rr in the missing range at which the constraint is active. Compute the KKT multiplier λ\lambda of the constrained solution, with the constraint written 12w2≤12r2\tfrac12 w^2 \le \tfrac12 r^2 as in the text, and find a point where the penalized objective with this λ\lambda is lower. Compute the duality gap p⋆(r)−d⋆(r)p^\star(r) - d^\star(r) of the constrained problem.
  7. [extended] Entropic optimal transport. ●● Given probability vectors p∈Rn\mathbf{p} \in \mathbb{R}^n and r∈Rm\mathbf{r} \in \mathbb{R}^m and a cost matrix C∈Rn×m\mathbf{C} \in \mathbb{R}^{n \times m}, optimal transport finds the cheapest plan Γ\boldsymbol{\Gamma} that moves the mass p\mathbf{p} to the mass r\mathbf{r},

OT=min⁡Γ≥0  ∑i,jCijΓijsubject toΓ1=p,    Γ⊤1=r,(23.7.15)\mathrm{OT} = \min_{\boldsymbol{\Gamma} \ge 0}\; \sum_{i,j} C_{ij} \Gamma_{ij} \quad \textrm{subject to} \quad \boldsymbol{\Gamma} \mathbf{1} = \mathbf{p}, \;\; \boldsymbol{\Gamma}^\top \mathbf{1} = \mathbf{r}, \tag{23.7.15}

a linear program with nmnm variables. Entropic regularization (Cuturi, 2013) adds ε∑i,jΓij(log⁡Γij−1)\varepsilon \sum_{i,j} \Gamma_{ij} (\log \Gamma_{ij} - 1) to the objective, with ε>0\varepsilon > 0; let Γε\boldsymbol{\Gamma}_\varepsilon be the regularized optimum. Its solution by Sinkhorn iterations is used to compare distributions (Peyré and Cuturi, 2019).

  1. Form the Lagrangian with the terms ϕ⊤(p−Γ1)+ψ⊤(r−Γ⊤1)\boldsymbol{\phi}^\top (\mathbf{p} - \boldsymbol{\Gamma} \mathbf{1}) + \boldsymbol{\psi}^\top (\mathbf{r} - \boldsymbol{\Gamma}^\top \mathbf{1}) for the marginal constraints. Show that Γε=diag(u) K diag(v)\boldsymbol{\Gamma}_\varepsilon = \mathrm{diag}(\mathbf{u})\, \mathbf{K}\, \mathrm{diag}(\mathbf{v}) with Kij=e−Cij/εK_{ij} = e^{-C_{ij} / \varepsilon}, ui=eϕi/εu_i = e^{\phi_i / \varepsilon}, and vj=eψj/εv_j = e^{\psi_j / \varepsilon}. Why can the sign constraints Γij≥0\Gamma_{ij} \ge 0 be left out of the Lagrangian?
  2. Show that the dual function is
q(ϕ,ψ)=p⊤ϕ+r⊤ψ−ε∑i,je(ϕi+ψj−Cij)/ε,(23.7.16)q(\boldsymbol{\phi}, \boldsymbol{\psi}) = \mathbf{p}^\top \boldsymbol{\phi} + \mathbf{r}^\top \boldsymbol{\psi} - \varepsilon \sum_{i,j} e^{(\phi_i + \psi_j - C_{ij}) / \varepsilon}, \tag{23.7.16}

and that maximizing it exactly over ϕ\boldsymbol{\phi} with ψ\boldsymbol{\psi} fixed gives the Sinkhorn update u=p/(Kv)\mathbf{u} = \mathbf{p} / (\mathbf{K} \mathbf{v}), elementwise. Conclude that Sinkhorn's algorithm is block-coordinate ascent on a concave function and that its dual value never decreases. Why is every dual value a lower bound on OT\mathrm{OT}?

  1. Let H(Γ)=−∑i,jΓijlog⁡ΓijH(\boldsymbol{\Gamma}) = -\sum_{i,j} \Gamma_{ij} \log \Gamma_{ij}, and grant that every feasible plan satisfies max⁡(H(p),H(r))≤H(Γ)≤H(p)+H(r)\max(H(\mathbf{p}), H(\mathbf{r})) \le H(\boldsymbol{\Gamma}) \le H(\mathbf{p}) + H(\mathbf{r}). Show that 0≤∑i,jCij(Γε)ij−OT≤εmin⁡(H(p),H(r))0 \le \sum_{i,j} C_{ij} (\boldsymbol{\Gamma}_\varepsilon)_{ij} - \mathrm{OT} \le \varepsilon \min(H(\mathbf{p}), H(\mathbf{r})).
  2. Let the costs lie in [0,1][0, 1]. In float64, e−xe^{-x} rounds to zero for xx above about 745745. For which ε\varepsilon can entries of K\mathbf{K} vanish, and what then happens to the multiplicative updates u=p/(Kv)\mathbf{u} = \mathbf{p} / (\mathbf{K}\mathbf{v})? Explain why updating ϕ\boldsymbol{\phi} and ψ\boldsymbol{\psi} directly, with a log-sum-exp in place of the products with K\mathbf{K}, avoids the problem.
  1. [code] The dual of ridge regression. Write min⁡w12∥Aw−b∥2+λ2∥w∥2\min_{\mathbf{w}}\tfrac12\|\mathbf{A}\mathbf{w} - \mathbf{b}\|^2 + \tfrac\lambda2\|\mathbf{w}\|^2, with A∈Rn×d\mathbf{A} \in \mathbb{R}^{n \times d}, as min⁡w,z12∥z∥2+λ2∥w∥2\min_{\mathbf{w}, \mathbf{z}}\tfrac12\|\mathbf{z}\|^2 + \tfrac\lambda2\|\mathbf{w}\|^2 subject to Aw−b−z=0\mathbf{A}\mathbf{w} - \mathbf{b} - \mathbf{z} = \mathbf{0}, with multiplier α∈Rn\boldsymbol{\alpha} \in \mathbb{R}^n.
    1. Minimize the Lagrangian over z\mathbf{z} and w\mathbf{w} to get z=α\mathbf{z} = \boldsymbol{\alpha}, w=−A⊤α/λ\mathbf{w} = -\mathbf{A}^\top\boldsymbol{\alpha}/\lambda, and the dual function q(α)=−12∥α∥2−12λα⊤AA⊤α−b⊤αq(\boldsymbol{\alpha}) = -\tfrac12\|\boldsymbol{\alpha}\|^2 - \tfrac1{2\lambda}\boldsymbol{\alpha}^\top\mathbf{A}\mathbf{A}^\top\boldsymbol{\alpha} - \mathbf{b}^\top\boldsymbol{\alpha}. Why does strong duality hold?
    2. Maximize qq to get α⋆=−λ(AA⊤+λI)−1b\boldsymbol{\alpha}^\star = -\lambda(\mathbf{A}\mathbf{A}^\top + \lambda\mathbf{I})^{-1}\mathbf{b} and w⋆=A⊤(AA⊤+λI)−1b\mathbf{w}^\star = \mathbf{A}^\top(\mathbf{A}\mathbf{A}^\top + \lambda\mathbf{I})^{-1}\mathbf{b}. Explain why the solution is a combination of the rows of A\mathbf{A}, as the SVM weight vector is a combination of the data points, and why the data enter only through AA⊤\mathbf{A}\mathbf{A}^\top.
    3. For n=20n = 20 examples and d=50d = 50 features, verify numerically that the primal solve (A⊤A+λI)w=A⊤b(\mathbf{A}^\top\mathbf{A} + \lambda\mathbf{I})\mathbf{w} = \mathbf{A}^\top\mathbf{b} and the dual formula agree to about 10−1410^{-14}, and that the primal and dual values coincide. Which solve is cheaper when n≪dn \ll d? What does replacing AA⊤\mathbf{A}\mathbf{A}^\top by a kernel matrix give?

Discussions