Lagrange Multipliers
For equality constraints, the geometric condition "no feasible direction goes downhill" becomes a clean algebraic one: at the optimum, the gradient of the objective is a combination of the gradients of the constraints. The coefficients are the Lagrange multipliers, and they turn out to measure how much each constraint costs. A first pass is in Math for ML: Lagrange multipliers; here we develop the optimization side.
The condition
For subject to , , define the Lagrangian
If is a local minimum and the constraint gradients are linearly independent (LICQ), there are multipliers with
That is equations in unknowns. Geometrically, must be perpendicular to the constraint surface, because any component along the surface would be a feasible descent direction.
Equality-constrained quadratic programs: one linear solve
For subject to , the conditions are linear, the KKT system:
import numpy as np
# minimize x^2 + 2y^2 + 3z^2 subject to x + y + z = 1 and x - y = 0.2
Q = np.diag([2.0, 4.0, 6.0]); c = np.zeros(3)
A = np.array([[1.0, 1.0, 1.0], [1.0, -1.0, 0.0]]); b = np.array([1.0, 0.2])
K = np.block([[Q, A.T], [A, np.zeros((2, 2))]])
sol = np.linalg.solve(K, np.concatenate([-c, b]))
x, nu = sol[:3], sol[3:]
print("x =", np.round(x, 6))
print("nu =", np.round(nu, 6))
print("constraints:", np.round(A @ x, 6), " gradient of L:", np.round(Q @ x + c + A.T @ nu, 10) + 0)x = [0.506667 0.306667 0.186667]
nu = [-1.12 0.106667]
constraints: [1. 0.2] gradient of L: [0. 0. 0.]
This one solve is the inner step of SQP methods and of Newton's method with equality constraints.
Multipliers are prices
Change the constraint to . The optimal value changes at the rate
So is the marginal cost of tightening the constraint, a shadow price. Check it numerically:
import numpy as np
Q = np.diag([2.0, 4.0, 6.0]); A = np.array([[1.0, 1.0, 1.0], [1.0, -1.0, 0.0]])
K = np.block([[Q, A.T], [A, np.zeros((2, 2))]])
def solve(b):
s = np.linalg.solve(K, np.concatenate([np.zeros(3), b]))
return 0.5 * s[:3] @ Q @ s[:3], s[3:]
p0, nu = solve(np.array([1.0, 0.2]))
eps = 1e-6
p1, _ = solve(np.array([1.0 + eps, 0.2]))
print("dp*/d(b1) numerically:", round((p1 - p0) / eps, 4), " -nu_1 =", round(-nu[0], 4))dp*/d(b1) numerically: 1.12 -nu_1 = 1.12
Sensitivity and Shadow Prices develops this for inequalities and linear programs.
A nonlinear example: maximize volume
Maximize the volume of a box with surface area . With , the conditions , , force , so the cube with side 1 wins. SymPy confirms:
import sympy as sp
x, y, z, nu = sp.symbols("x y z nu", positive=True)
L = -x * y * z + nu * (2 * (x * y + y * z + z * x) - 6)
eqs = [sp.diff(L, v) for v in (x, y, z)] + [2 * (x * y + y * z + z * x) - 6]
sol = sp.solve(eqs, [x, y, z, nu], dict=True)[0]
print({str(v): sol[v] for v in (x, y, z, nu)}){'x': 1, 'y': 1, 'z': 1, 'nu': 1/4}
In software
- SciPy's
SLSQPandtrust-constrsolve the Lagrange (KKT) equations iteratively;trust-constrreturns the multipliers inres.v. - In ML, Lagrange multipliers give the maximum-entropy distributions (The Maximum-Entropy Principle), the PCA eigenvalue problem and the SVM dual.
Exercises
Exercise 1: Closest point on a line
Minimize subject to with a Lagrange multiplier.
Answer
, , minimum value 5.
Solution
gives , . Substituting into the constraint: , so , , , and the value is .
Exercise 2: Interpret the multiplier
In Exercise 1, estimate the optimal value if the constraint becomes .
Answer
About (exactly 5.202).
Solution
. Exactly, , so .
Exercise 3: KKT system (code)
Solve subject to with the KKT system.
Answer
, .
Solution
import numpy as np
Q = np.eye(4); A = np.ones((1, 4))
K = np.block([[Q, A.T], [A, np.zeros((1, 1))]])
print(np.linalg.solve(K, np.array([0, 0, 0, 0, 2.0])))[ 0.5 0.5 0.5 0.5 -0.5]
By symmetry all coordinates are equal, and the minimum-norm point on the hyperplane is .
Test yourself
At a solution of s.t. (with LICQ), is…
- zero
- parallel to
- perpendicular to
- random
An equality-constrained QP can be solved by…
- one linear solve of the KKT system
- the simplex method only
- random search
- it has no solution
The multiplier measures…
- the number of constraints
- the rate of change of the optimal value as the constraint is perturbed
- the step size
- the condition number