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 s.t. , (the primal), with Lagrangian , the Lagrange dual function is
It is a pointwise infimum of affine functions of , so it is concave, even if the primal is not convex. It may be for some multipliers.
The lower bound
For any feasible and any : the constraint terms are and , so
Every dual-feasible point gives a lower bound on . The dual problem looks for the best bound:
Example: least-norm solution
Primal: s.t. . The Lagrangian is minimized at , giving
a concave quadratic. Any gives a lower bound, and the best one closes the gap:
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: s.t. , . The Lagrangian is linear in ; its infimum is unless the coefficient vanishes:
Writing and eliminating gives the familiar dual LP: maximize s.t. . Duality in Linear Programming builds on this.
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 over (write ). The dual function is when . Choosing gives the bound :
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 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 , which is what makes kernels possible (The Dual SVM and Kernels).
Exercises
Exercise 1: A one-dimensional dual
Primal: minimize subject to (write ). Find and .
Answer
, maximized at with .
Solution
is minimized at , giving . Its maximum over is at , . The primal optimum is , : no gap.
Exercise 2: Bounds from any multiplier
In Exercise 1, what lower bound does give?
Answer
.
Solution
. Any gives a valid, but possibly weak, bound.
Exercise 3: Dual of a box-constrained problem (code)
For s.t. with , the dual function is . Maximize it over and compare with .
Answer
and .
Solution
is separable; each term is maximized at . The primal solution is with .
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 is always…
- convex
- concave
- linear
- differentiable
Weak duality states that…
- always
- always
- the dual is infeasible
The dual of s.t. , is…
- s.t.
- s.t.
- s.t.
- the same problem