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 s.t. , minimize
for an increasing sequence of . Inequalities use . The minimizer violates the constraint by about , so you need , and the Hessian of has eigenvalues of order : the condition number explodes.
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 while the condition number grows like .
Exact penalties
The L1 penalty is exact: for larger than the largest multiplier , its minimizer is the true solution for a finite . 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:
Minimize over with fixed, then update the multipliers by the method of multipliers rule:
Comparing stationarity conditions shows why: at the minimizer, , so is the natural new multiplier estimate. Once is close to , a moderate fixed gives an accurate solution.
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 fixed at 10, the violation drops by a constant factor each outer iteration and the multiplier converges to , with no ill-conditioning.
Inequalities
For , the augmented Lagrangian term is and the update is , which keeps multipliers non-negative automatically.
In software
- ALGENCAN, LANCELOT and the
auglagmethods 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 -minimization into easy parts.
Exercises
Exercise 1: Penalty solution in closed form
Minimize subject to with the quadratic penalty . Find .
Answer
.
Solution
Derivative gives , which tends to 1 as ; the violation is of order .
Exercise 2: Multiplier from the penalty
In Exercise 1, compute and compare with the true multiplier.
Answer
.
Solution
The Lagrangian at needs , so . The penalty method's implied multiplier converges to it, which is why is a good update.
Exercise 3: Augmented Lagrangian by hand (code)
Run the method of multipliers for Exercise 1 with and for 5 iterations.
Answer
approaches geometrically and approaches 1.
Solution
Minimizing gives .
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 shrinks by a factor per iteration; larger shrinks it faster.
Test yourself
Why does the pure quadratic penalty method become hard to solve as grows?
- The Hessian becomes ill-conditioned
- The function becomes linear
- Gradients vanish
- Constraints disappear
The method-of-multipliers update for an equality constraint is…
- only
An exact (L1) penalty recovers the true solution when…
- exceeds the largest multiplier magnitude
- only
- the problem is linear