ContentsChapter 3 · Statistics and optimisation4 of 4

3.4

Lagrange multipliers

In this chapter
  1. 3.1Maximum likelihood
  2. 3.2Priors and MAP
  3. 3.3Gradient descent and convexity
  4. 3.4Lagrange multipliers
Before you readThe smallest value of x2+y2x^2+y^2 is at the origin. Where is the smallest value if you have to stay on the line x+y=4x+y=4
Watch: Lagrange multipliers, using tangency to solve constrained optimization · Khan Academy

To minimise f(x,y)f(x,y) subject to g(x,y)=cg(x,y)=c you can only move along the constraint. At a constrained optimum, moving along it cannot improve ff to first order. If ∇g≠0\nabla g\ne 0 that means ∇f\nabla f is perpendicular to the constraint, just like ∇g\nabla g

The Lagrange multiplier λ\lambda makes the gradients proportional. Solve both equations:

∇f=λ∇g,g(x,y)=c.\nabla f=\lambda\nabla g,\qquad g(x,y)=c.

Geometrically, at the solution below the level curve of ff just touches the constraint. A smaller circle never reaches the line.

(x, y) = (3, 1)f = 10∇f = (6, 2)
Move along the dashed line x + y = 4. The circle shows points with the same value of f. Where does it just touch the line, with the gradient pointing straight across it?

For f=x2+y2f=x^2+y^2 and g=x+yg=x+y the gradient equation is (2x,2y)=λ(1,1)(2x,2y)=\lambda(1,1) Thus x=yx=y and x+y=4x+y=4 gives (2,2)(2,2) The equations give candidates, not a guarantee of a minimum. Here the smallest circle that touches the line proves it; in general compare candidate values and check any endpoints or points where ∇g=0\nabla g=0 separately.

Constraints let you fit a model while enforcing a rule, such as making a set of probability weights add to one.

Recall
At a smooth constrained optimum with ∇g≠0\nabla g\neq 0 how are ∇f\nabla f and ∇g\nabla g related?
Recall
Besides the gradient equation, what equation must a Lagrange candidate satisfy?
Exercise
Minimise x2+2y2x^2+2y^2 subject to x+y=6x+y=6 Give the pair (x,y)(x,y)