TExcelTAD
Home › Optimization › The Lagrange Dual Problem

The Lagrange Dual Problem

Every optimization problem has a shadow problem, its dual, built from the Lagrangian. The dual is always concave (so maximizing it is a convex problem), it always gives a lower bound on the original optimum, and for convex problems it usually gives the optimum exactly. Duality yields certificates of optimality, new algorithms, and the SVM's kernel trick.

The dual function

For the problem min⁡f0(x)\min f_0(\mathbf{x}) s.t. fi(x)≤0f_i(\mathbf{x}) \le 0, hj(x)=0h_j(\mathbf{x}) = 0 (the primal), with Lagrangian L(x,λ,ν)=f0+∑iλifi+∑jνjhj\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu}) = f_0 + \sum_i\lambda_if_i + \sum_j\nu_jh_j, the Lagrange dual function is

g(λ,ν)=inf⁡xL(x,λ,ν)g(\boldsymbol{\lambda}, \boldsymbol{\nu}) = \inf_{\mathbf{x}} \mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}, \boldsymbol{\nu})

It is a pointwise infimum of affine functions of (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}), so it is concave, even if the primal is not convex. It may be −∞-\infty for some multipliers.

The lower bound

For any feasible x~\tilde{\mathbf{x}} and any λ≥0\boldsymbol{\lambda} \ge 0: the constraint terms are λifi(x~)≤0\lambda_if_i(\tilde{\mathbf{x}}) \le 0 and νjhj(x~)=0\nu_jh_j(\tilde{\mathbf{x}}) = 0, so

g(λ,ν)≤L(x~,λ,ν)≤f0(x~)g(\boldsymbol{\lambda}, \boldsymbol{\nu}) \le \mathcal{L}(\tilde{\mathbf{x}}, \boldsymbol{\lambda}, \boldsymbol{\nu}) \le f_0(\tilde{\mathbf{x}})

Every dual-feasible point gives a lower bound on p∗p^*. The dual problem looks for the best bound:

maximize g(λ,ν)subject to λ≥0,d∗≤p∗\text{maximize } g(\boldsymbol{\lambda}, \boldsymbol{\nu}) \quad \text{subject to } \boldsymbol{\lambda} \ge \mathbf{0}, \qquad d^* \le p^*

Example: least-norm solution

Primal: min⁡xTx\min \mathbf{x}^T\mathbf{x} s.t. Ax=bA\mathbf{x} = \mathbf{b}. The Lagrangian xTx+νT(Ax−b)\mathbf{x}^T\mathbf{x} + \boldsymbol{\nu}^T(A\mathbf{x} - \mathbf{b}) is minimized at x=−12ATν\mathbf{x} = -\frac{1}{2}A^T\boldsymbol{\nu}, giving

g(ν)=−14νTAATν−bTνg(\boldsymbol{\nu}) = -\frac{1}{4}\boldsymbol{\nu}^TAA^T\boldsymbol{\nu} - \mathbf{b}^T\boldsymbol{\nu}

a concave quadratic. Any ν\boldsymbol{\nu} gives a lower bound, and the best one closes the gap:

python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
A = rng.normal(size=(2, 4)); b = np.array([1.0, -2.0])
x_star = A.T @ np.linalg.solve(A @ A.T, b)             # least-norm solution
p_star = x_star @ x_star
g = lambda nu: -0.25 * nu @ (A @ A.T) @ nu - b @ nu
for _ in range(3):
    nu = rng.normal(size=2) * 3
    print(f"random nu: lower bound g = {g(nu):9.4f} <= p* = {p_star:.4f}")
nu_star = -2 * np.linalg.solve(A @ A.T, b)             # maximizer of g
print(f"best nu:   g = {g(nu_star):.4f}")
random nu: lower bound g =  -20.1341 <= p* = 11.6066
random nu: lower bound g =    1.8040 <= p* = 11.6066
random nu: lower bound g =   -2.0649 <= p* = 11.6066
best nu:   g = 11.6066

Example: the dual of a linear program

Primal: min⁡cTx\min \mathbf{c}^T\mathbf{x} s.t. Ax=bA\mathbf{x} = \mathbf{b}, x≥0\mathbf{x} \ge \mathbf{0}. The Lagrangian cTx−λTx+νT(Ax−b)\mathbf{c}^T\mathbf{x} - \boldsymbol{\lambda}^T\mathbf{x} + \boldsymbol{\nu}^T(A\mathbf{x} - \mathbf{b}) is linear in x\mathbf{x}; its infimum is −∞-\infty unless the coefficient vanishes:

g(λ,ν)={−bTνif ATν−λ+c=0−∞otherwiseg(\boldsymbol{\lambda}, \boldsymbol{\nu}) = \begin{cases} -\mathbf{b}^T\boldsymbol{\nu} & \text{if } A^T\boldsymbol{\nu} - \boldsymbol{\lambda} + \mathbf{c} = \mathbf{0} \\ -\infty & \text{otherwise} \end{cases}

Writing y=−ν\mathbf{y} = -\boldsymbol{\nu} and eliminating λ≥0\boldsymbol{\lambda} \ge 0 gives the familiar dual LP: maximize bTy\mathbf{b}^T\mathbf{y} s.t. ATy≤cA^T\mathbf{y} \le \mathbf{c}. Duality in Linear Programming builds on this.

python · try it yourself
import numpy as np
from scipy.optimize import linprog

c = np.array([2.0, 3.0, 1.0]); A = np.array([[1.0, 1.0, 1.0], [1.0, 2.0, -1.0]]); b = np.array([4.0, 2.0])
primal = linprog(c, A_eq=A, b_eq=b, bounds=[(0, None)] * 3)
dual = linprog(-b, A_ub=A.T, b_ub=c, bounds=[(None, None)] * 2)     # max b^T y  ->  min -b^T y
print("primal optimum p* =", round(primal.fun, 6), " at x =", np.round(primal.x, 4))
print("dual optimum   d* =", round(-dual.fun, 6), " at y =", np.round(dual.x, 4))
primal optimum p* = 7.0  at x = [3. 0. 1.]
dual optimum   d* = 7.0  at y = [1.5 0.5]

Example: a non-convex problem

Duality works for non-convex problems too, giving a convex relaxation. For two-way partitioning, minimize xTWx\mathbf{x}^TW\mathbf{x} over xi∈{−1,1}x_i \in \{-1, 1\} (write xi2=1x_i^2 = 1). The dual function is g(ν)=−1Tνg(\boldsymbol{\nu}) = -\mathbf{1}^T\boldsymbol{\nu} when W+diag⁡(ν)⪰0W + \operatorname{diag}(\boldsymbol{\nu}) \succeq 0. Choosing ν=−λmin⁡(W)1\boldsymbol{\nu} = -\lambda_{\min}(W)\mathbf{1} gives the bound p∗≥nλmin⁡(W)p^* \ge n\lambda_{\min}(W):

python · try it yourself
import numpy as np
from itertools import product

rng = np.random.default_rng(1)
n = 10
M = rng.normal(size=(n, n)); W = (M + M.T) / 2
best = min(np.array(s) @ W @ np.array(s) for s in product([-1, 1], repeat=n))
print("exact optimum by brute force (1024 cases):", round(float(best), 4))
print("dual lower bound n * lambda_min(W):       ", round(float(n * np.linalg.eigvalsh(W).min()), 4))
exact optimum by brute force (1024 cases): -20.4383
dual lower bound n * lambda_min(W):        -26.9413

The bound is valid but not tight: for non-convex problems a duality gap p∗−d∗>0p^* - d^* > 0 is normal.

In software

  • Branch-and-bound solvers use dual (relaxation) bounds to prune the search tree (Branch and Bound).
  • The SVM dual depends on the data only through inner products xiTxj\mathbf{x}_i^T\mathbf{x}_j, which is what makes kernels possible (The Dual SVM and Kernels).

Exercises

Exercise 1: A one-dimensional dual

Primal: minimize x2x^2 subject to x≥1x \ge 1 (write 1−x≤01 - x \le 0). Find g(λ)g(\lambda) and d∗d^*.

Answer

g(λ)=λ−λ2/4g(\lambda) = \lambda - \lambda^2/4, maximized at λ=2\lambda = 2 with d∗=1=p∗d^* = 1 = p^*.

Solution

L=x2+λ(1−x)\mathcal{L} = x^2 + \lambda(1 - x) is minimized at x=λ/2x = \lambda/2, giving g(λ)=λ2/4+λ−λ2/2=λ−λ2/4g(\lambda) = \lambda^2/4 + \lambda - \lambda^2/2 = \lambda - \lambda^2/4. Its maximum over λ≥0\lambda \ge 0 is at λ=2\lambda = 2, g=1g = 1. The primal optimum is x=1x = 1, p∗=1p^* = 1: no gap.

Exercise 2: Bounds from any multiplier

In Exercise 1, what lower bound does λ=1\lambda = 1 give?

Answer

g(1)=0.75≤1g(1) = 0.75 \le 1.

Solution

1−14=0.751 - \frac{1}{4} = 0.75. Any λ≥0\lambda \ge 0 gives a valid, but possibly weak, bound.

Exercise 3: Dual of a box-constrained problem (code)

For min⁡12∥x−a∥2\min \frac{1}{2}\lVert \mathbf{x} - \mathbf{a} \rVert^2 s.t. x≤0\mathbf{x} \le \mathbf{0} with a=(1,−2,3)\mathbf{a} = (1, -2, 3), the dual function is g(λ)=λTa−12∥λ∥2g(\boldsymbol{\lambda}) = \boldsymbol{\lambda}^T\mathbf{a} - \frac{1}{2}\lVert \boldsymbol{\lambda} \rVert^2. Maximize it over λ≥0\boldsymbol{\lambda} \ge 0 and compare with p∗p^*.

Answer

λ∗=(1,0,3)\boldsymbol{\lambda}^* = (1, 0, 3) and d∗=p∗=5d^* = p^* = 5.

Solution

gg is separable; each term λiai−λi2/2\lambda_ia_i - \lambda_i^2/2 is maximized at λi=max⁡(ai,0)\lambda_i = \max(a_i, 0). The primal solution is x∗=min⁡(a,0)=(0,−2,0)\mathbf{x}^* = \min(\mathbf{a}, \mathbf{0}) = (0, -2, 0) with p∗=12(1+9)=5p^* = \frac{1}{2}(1 + 9) = 5.

python · try it yourself
import numpy as np
a = np.array([1.0, -2.0, 3.0])
lam = np.maximum(a, 0); x = np.minimum(a, 0)
print("d* =", lam @ a - 0.5 * lam @ lam, " p* =", 0.5 * (x - a) @ (x - a))
d* = 5.0  p* = 5.0

Test yourself

The Lagrange dual function g(λ,ν)g(\boldsymbol{\lambda}, \boldsymbol{\nu}) is always…

  1. convex
  2. concave
  3. linear
  4. differentiable

Weak duality states that…

  1. d∗≤p∗d^* \le p^* always
  2. d∗=p∗d^* = p^* always
  3. d∗≥p∗d^* \ge p^*
  4. the dual is infeasible

The dual of min⁡cTx\min \mathbf{c}^T\mathbf{x} s.t. Ax=bA\mathbf{x} = \mathbf{b}, x≥0\mathbf{x} \ge \mathbf{0} is…

  1. max⁡bTy\max \mathbf{b}^T\mathbf{y} s.t. ATy≤cA^T\mathbf{y} \le \mathbf{c}
  2. min⁡bTy\min \mathbf{b}^T\mathbf{y} s.t. Ay=cA\mathbf{y} = \mathbf{c}
  3. max⁡cTy\max \mathbf{c}^T\mathbf{y} s.t. y≥0\mathbf{y} \ge 0
  4. the same problem