Lagrange multipliers

Level UniversityDifficulty ★★★★★Concept⌖ Open in the map

What is it?

At a constrained optimum of ff subject to g=0g = 0, the gradients are parallel: ∇f=λ∇g\nabla f = \lambda\nabla g. The multiplier λ\lambda measures how much the optimum would improve if the constraint were relaxed.

Why does it exist?

Substituting the constraint to eliminate a variable works only in easy cases. Lagrange's method keeps all the variables and adds one unknown per constraint, turning a constrained problem into an unconstrained system of equations — and the new unknowns turn out to carry economic and physical meaning.

Intuition

Walk along the curve g=0g = 0 looking at the level sets of ff. While the curve crosses level sets, you can still go lower. At the optimum the curve is tangent to a level set of ff, so their normals — ∇f\nabla f and ∇g\nabla g — point along the same line.

Formal definition

If x∗x^\ast is a local extremum of ff on {g=0}\{g = 0\}, with f,gf, g continuously differentiable and ∇g(x∗)≠0\nabla g(x^\ast) \ne 0, then there is λ\lambda with ∇f(x∗)=λ ∇g(x∗)\nabla f(x^\ast) = \lambda\,\nabla g(x^\ast). Equivalently, (x∗,λ)(x^\ast, \lambda) is a critical point of the Lagrangian

ℒ(x,λ)=f(x)−λ g(x).\mathcal L(x, \lambda) = f(x) - \lambda\,g(x).

Formulas

∇f(x∗)=λ ∇g(x∗),g(x∗)=0\nabla f(x^\ast) = \lambda\,\nabla g(x^\ast), \qquad g(x^\ast) = 0
∂f∗∂c=λ,g(x)=c\frac{\partial f^\ast}{\partial c} = \lambda, \qquad g(x) = c
the multiplier is the sensitivity of the optimum ("shadow price")

Example

Maximize entropy H(p)=−∑ipiln⁡piH(p) = -\sum_i p_i\ln p_i subject to ∑ipi=1\sum_i p_i = 1. ∂pi(H−λ(∑p−1))=−ln⁡pi−1−λ=0\partial_{p_i}\big(H - \lambda(\sum p - 1)\big) = -\ln p_i - 1 - \lambda = 0, so all pip_i are equal: the uniform distribution. Add a constraint on the expected energy and the same computation produces the softmax / Boltzmann distribution pi∝e−βEip_i \propto e^{-\beta E_i}.

Why does it matter?

Support vector machines are derived through their Lagrangian dual (where the kernel trick appears). Constrained training, fairness constraints, the maximum-entropy justification of softmax, and duality in operations research all use the same idea. In physics, Lagrange's other great idea — the Lagrangian of mechanics — runs robot dynamics.

Where it shows up in computing

Where it shows up in AI

  • Support vector machines★★★★★fundamentalAI and machine learning

    The SVM dual is obtained with Lagrange multipliers; only points with αi>0\alpha_i > 0 (support vectors) matter.

  • Regularization★★★★★advancedAI and machine learning

    Penalized training L+λ∥w∥2L + \lambda\norm w^2 is the Lagrangian of training under a norm constraint ∥w∥≤r\norm w \le r.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Maximize f(x,y)=xyf(x,y) = xy subject to x+y=10x + y = 10 with a Lagrange multiplier.

Solution

(y,x)=λ(1,1)(y, x) = \lambda(1, 1) gives x=y=λx = y = \lambda, and x+y=10x + y = 10 gives x=y=5x = y = 5, f=25f = 25, λ=5\lambda = 5.

2AI

Show that the distribution maximizing entropy with a fixed mean energy ∑ipiEi=Eˉ\sum_i p_i E_i = \bar E has the form pi∝e−βEip_i \propto e^{-\beta E_i}.

Solution

∂pi[−∑pln⁡p−λ(∑p−1)−β(∑pE−Eˉ)]=−ln⁡pi−1−λ−βEi=0\partial_{p_i}\big[-\sum p\ln p - \lambda(\sum p - 1) - \beta(\sum pE - \bar E)\big] = -\ln p_i - 1 - \lambda - \beta E_i = 0, so pi=e−1−λe−βEip_i = e^{-1-\lambda}e^{-\beta E_i}: a softmax of −βE-\beta E.

↑ ↓ to navigate · ↵ · Esc