§4.4 Constrained optimization
Sometimes we don’t want the best anywhere — we want the best within a set of feasible points: constrained optimization constrained optimization Optimizing f over x within a feasible set S rather than all x — by projection, re-parametrization, or the KKT machinery. defined in ch. 4 — open in glossary . A typical wish is smallness, imposed as a norm constraint like :
When the free minimum lies outside 𝕊, the answer sits on the boundary — and the constraint’s multiplier must push. (Preview: §7.2 turns exactly this picture into weight-decay regularization.)
Three simple approaches before the general machinery: project each gradient-descent result back into (or run the line search line search Evaluate f(x − ε∇f) for several ε and keep the best — step-size selection by trial. defined in ch. 4 — open in glossary only over feasible step sizes, ideally after projecting the gradient into the feasible region’s tangent space); or re-parametrize the problem so the constraint is automatic — e.g. minimize to enforce exactly unit norm, at the price of case-by-case creativity.
The KKT machinery
The general solution: describe via equality constraints and inequality constraints , then build the generalized Lagrangian generalized lagrangian L(x, λ, α) = f(x) + Σλᵢg⁽ⁱ⁾(x) + Σαⱼh⁽ʲ⁾(x): converts constrained problems into unconstrained min-max over KKT multipliers. defined in ch. 4 — open in glossary :
Term by term
| the original objective | scalar | |
| equality (= 0) and inequality (≤ 0) constraint functions describing 𝕊 | m + n fns | |
| the KKT multipliers — new variables, one per constraint (α ≥ 0); the generalization of Lagrange multipliers to inequalities | scalars |
Then, as long as at least one feasible point exists and cannot reach ,
What this really says
The inner max is an infinitely harsh referee. If satisfies every constraint, no choice of multipliers can inflate beyond (eq 4.17: the g-terms are zero, the best α on a negative h is 0). If any constraint is violated, the referee sends the corresponding multiplier to infinity, making (eq 4.18). So the outer min can never profit from infeasibility — the constrained problem became an unconstrained min-max. (For maximization, build the Lagrangian of −f; the sign on the λ-terms is free since λ may take either sign.)
Active vs inactive. A constraint is active if — the solution sits ON its boundary. Inactive constraints () get : removing them would leave a local solution in place (though they may have excluded other solutions elsewhere). Either the boundary shapes the solution and its multiplier pushes, or it doesn’t and its multiplier is zeroed: complementary slackness, . Together, the KKT conditions kkt conditions Necessary optimality conditions: ∇L = 0, all constraints satisfied, complementary slackness α⊙h(x) = 0 (each inequality active or its multiplier zero). defined in ch. 4 — open in glossary — necessary (not always sufficient) for optimality:
- (gradient of the generalized Lagrangian vanishes);
- all constraints on and the multipliers hold;
- complementary slackness.
§4.5 Example: linear least squares
Everything in this chapter, exercised on one function — linear least squares linear least squares Minimize ½‖Ax − b‖₂²: gradient AᵀAx − Aᵀb; solvable by GD (alg 4.1), one Newton step, or the pseudoinverse. defined in ch. 4 — open in glossary . Minimize :
step 1/3: Squared L² as a dot product (§2.5) — the ½ is cosmetic, chosen to cancel the 2 from differentiation.
- 1set the step size and tolerance to small positive numbersⓘ
- 2while doⓘ
- 3ⓘ
- 4end whileⓘ
The bowl being descended is exactly the lab from §4.3.1 with — revisit it and imagine as the (squared) conditioning of .
The constrained version
Now minimize the same subject to — the unit-disk picture at the top of this page, solved with the KKT recipe:
step 1/5: One inequality constraint h(x) = xᵀx − 1 ≤ 0, one multiplier λ ≥ 0; solve min_x max_{λ≥0} L.
That concludes the mathematical preliminaries. Next: full-fledged learning systems — chapter 5, Machine Learning Basics.
Check yourself — KKT and least squares
1.Why does min_x max_{λ, α≥0} L(x, λ, α) solve the constrained problem?
2.What does complementary slackness (α ⊙ h(x) = 0) say at the optimum?
3.For f(x) = ½‖Ax − b‖², why does Newton's method finish in exactly one step while gradient descent iterates?
4.In the constrained least-squares solve, what role does gradient ascent on λ play?
5.The expression x = (AᵀA + 2λI)⁻¹Aᵀb will reappear later in the book. As what?