TExcelTAD
Home › Optimization › Penalty and Augmented Lagrangian Methods

Penalty and Augmented Lagrangian Methods

The simplest way to handle constraints is to stop handling them: add a penalty for violating them to the objective and use an unconstrained method. Pure penalties need huge weights and become ill-conditioned; the augmented Lagrangian method fixes this by adding a multiplier estimate, and it is the basis of solvers such as LANCELOT, ALGENCAN and of ADMM.

Quadratic penalty

For min⁡f(x)\min f(\mathbf{x}) s.t. h(x)=0h(\mathbf{x}) = 0, minimize

Qμ(x)=f(x)+μ2∑jhj(x)2Q_\mu(\mathbf{x}) = f(\mathbf{x}) + \frac{\mu}{2}\sum_j h_j(\mathbf{x})^2

for an increasing sequence of μ\mu. Inequalities use max⁡(0,gi(x))2\max(0, g_i(\mathbf{x}))^2. The minimizer x(μ)\mathbf{x}(\mu) violates the constraint by about 1/μ1/\mu, so you need μ→∞\mu \to \infty, and the Hessian of QμQ_\mu has eigenvalues of order μ\mu: the condition number explodes.

python · try it yourself
import numpy as np

# minimize x + y subject to x^2 + y^2 = 2  (solution (-1, -1), multiplier 0.5)
def penalty_min(mu):
    x = np.array([-1.0, -1.0]) * 0.9
    for _ in range(200):                                     # Newton on Q_mu
        h = x @ x - 2
        g = np.ones(2) + mu * h * 2 * x
        H = mu * (4 * np.outer(x, x) + 2 * h * np.eye(2))
        x = x - np.linalg.solve(H, g)
    return x
for mu in (1, 10, 100, 1000):
    x = penalty_min(mu)
    H = mu * (4 * np.outer(x, x) + 2 * (x @ x - 2) * np.eye(2))
    print(f"mu = {mu:5d}: x = {np.round(x, 5)}, violation = {x @ x - 2:+.1e}, cond(H) = {np.linalg.cond(H):.0f}")
mu =     1: x = [-1.10716 -1.10716], violation = +4.5e-01, cond(H) = 12
mu =    10: x = [-1.01227 -1.01227], violation = +4.9e-02, cond(H) = 84
mu =   100: x = [-1.00125 -1.00125], violation = +5.0e-03, cond(H) = 804
mu =  1000: x = [-1.00012 -1.00012], violation = +5.0e-04, cond(H) = 8004

The violation shrinks like 1/μ1/\mu while the condition number grows like μ\mu.

Exact penalties

The L1 penalty f(x)+ρ∑j∣hj(x)∣f(\mathbf{x}) + \rho\sum_j\lvert h_j(\mathbf{x}) \rvert is exact: for ρ\rho larger than the largest multiplier ∣νj∗∣\lvert \nu_j^* \rvert, its minimizer is the true solution for a finite ρ\rho. The price is non-smoothness, which SQP methods handle by using it only as a merit function to accept or reject steps.

The augmented Lagrangian

Add the multiplier term back:

Lμ(x,ν)=f(x)+νTh(x)+μ2∥h(x)∥2\mathcal{L}_\mu(\mathbf{x}, \boldsymbol{\nu}) = f(\mathbf{x}) + \boldsymbol{\nu}^T\mathbf{h}(\mathbf{x}) + \frac{\mu}{2}\lVert \mathbf{h}(\mathbf{x}) \rVert^2

Minimize over x\mathbf{x} with ν\boldsymbol{\nu} fixed, then update the multipliers by the method of multipliers rule:

ν←ν+μ h(x)\boldsymbol{\nu} \leftarrow \boldsymbol{\nu} + \mu\,\mathbf{h}(\mathbf{x})

Comparing stationarity conditions shows why: at the minimizer, ∇f+(ν+μh)T∇h=0\nabla f + (\boldsymbol{\nu} + \mu\mathbf{h})^T\nabla\mathbf{h} = \mathbf{0}, so ν+μh\boldsymbol{\nu} + \mu\mathbf{h} is the natural new multiplier estimate. Once ν\boldsymbol{\nu} is close to ν∗\boldsymbol{\nu}^*, a moderate fixed μ\mu gives an accurate solution.

python · try it yourself
import numpy as np

def al_min(nu, mu, x):
    for _ in range(100):                                     # Newton on the augmented Lagrangian
        h = x @ x - 2
        g = np.ones(2) + (nu + mu * h) * 2 * x
        H = 2 * (nu + mu * h) * np.eye(2) + 4 * mu * np.outer(x, x)
        x = x - np.linalg.solve(H, g)
    return x

nu, mu, x = 0.0, 10.0, np.array([-0.9, -0.9])
for k in range(1, 5):
    x = al_min(nu, mu, x)
    nu = nu + mu * (x @ x - 2)
    print(f"outer {k}: x = {np.round(x, 8)}, violation = {x @ x - 2:+.1e}, nu = {nu:.8f}")
outer 1: x = [-1.01227313 -1.01227313], violation = +4.9e-02, nu = 0.49393784
outer 2: x = [-1.00014967 -1.00014967], violation = +6.0e-04, nu = 0.49992518
outer 3: x = [-1.00000185 -1.00000185], violation = +7.4e-06, nu = 0.49999908
outer 4: x = [-1.00000002 -1.00000002], violation = +9.1e-08, nu = 0.49999999

With μ\mu fixed at 10, the violation drops by a constant factor each outer iteration and the multiplier converges to ν∗=0.5\nu^* = 0.5, with no ill-conditioning.

Inequalities

For gi(x)≤0g_i(\mathbf{x}) \le 0, the augmented Lagrangian term is 12μ(max⁡(0,λi+μgi(x))2−λi2)\frac{1}{2\mu}\left(\max(0, \lambda_i + \mu g_i(\mathbf{x}))^2 - \lambda_i^2\right) and the update is λi←max⁡(0,λi+μgi(x))\lambda_i \leftarrow \max(0, \lambda_i + \mu g_i(\mathbf{x})), which keeps multipliers non-negative automatically.

In software

  • ALGENCAN, LANCELOT and the auglag methods in NLopt; PyTorch-based constrained training libraries (e.g. Cooper) use augmented Lagrangian updates for fairness or norm constraints.
  • ADMM is an augmented Lagrangian method that splits the x\mathbf{x}-minimization into easy parts.

Exercises

Exercise 1: Penalty solution in closed form

Minimize x2x^2 subject to x=1x = 1 with the quadratic penalty x2+μ2(x−1)2x^2 + \frac{\mu}{2}(x - 1)^2. Find x(μ)x(\mu).

Answer

x(μ)=μ2+μx(\mu) = \frac{\mu}{2 + \mu}.

Solution

Derivative 2x+μ(x−1)=02x + \mu(x - 1) = 0 gives x=μ/(2+μ)x = \mu/(2 + \mu), which tends to 1 as μ→∞\mu \to \infty; the violation x−1=−2/(2+μ)x - 1 = -2/(2 + \mu) is of order 1/μ1/\mu.

Exercise 2: Multiplier from the penalty

In Exercise 1, compute μ h(x(μ))\mu\,h(x(\mu)) and compare with the true multiplier.

Answer

μh=−2μ2+μ→−2=ν∗\mu h = -\frac{2\mu}{2 + \mu} \to -2 = \nu^*.

Solution

The Lagrangian x2+ν(x−1)x^2 + \nu(x - 1) at x=1x = 1 needs 2+ν=02 + \nu = 0, so ν∗=−2\nu^* = -2. The penalty method's implied multiplier μh\mu h converges to it, which is why ν+μh\boldsymbol{\nu} + \mu\mathbf{h} is a good update.

Exercise 3: Augmented Lagrangian by hand (code)

Run the method of multipliers for Exercise 1 with μ=1\mu = 1 and ν0=0\nu_0 = 0 for 5 iterations.

Answer

ν\nu approaches −2-2 geometrically and xx approaches 1.

Solution

Minimizing x2+ν(x−1)+12(x−1)2x^2 + \nu(x - 1) + \frac{1}{2}(x - 1)^2 gives x=1−ν3x = \frac{1 - \nu}{3}.

python · try it yourself
nu = 0.0
for k in range(5):
    x = (1 - nu) / 3
    nu = nu + (x - 1)
    print(k + 1, round(x, 5), round(nu, 5))
1 0.33333 -0.66667
2 0.55556 -1.11111
3 0.7037 -1.40741
4 0.80247 -1.60494
5 0.86831 -1.73663

The error in ν\nu shrinks by a factor 23\frac{2}{3} per iteration; larger μ\mu shrinks it faster.

Test yourself

Why does the pure quadratic penalty method become hard to solve as μ\mu grows?

  1. The Hessian becomes ill-conditioned
  2. The function becomes linear
  3. Gradients vanish
  4. Constraints disappear

The method-of-multipliers update for an equality constraint is…

  1. ν←ν+μh(x)\nu \leftarrow \nu + \mu h(\mathbf{x})
  2. ν←ν−∇f\nu \leftarrow \nu - \nabla f
  3. ν←0\nu \leftarrow 0
  4. μ←2μ\mu \leftarrow 2\mu only

An exact (L1) penalty recovers the true solution when…

  1. ρ\rho exceeds the largest multiplier magnitude
  2. ρ=0\rho = 0
  3. ρ→∞\rho \to \infty only
  4. the problem is linear