§4.4–4.5Constrained Optimization · Example: Linear Least Squares

Part I DL pp. 93–97 · ~6 min read

  • constrained optimization
  • generalized lagrangian
  • kkt conditions
  • linear least squares

§4.4 Constrained optimization

Sometimes we don’t want the best x\boldsymbol{x} anywhere — we want the best x\boldsymbol{x} within a set S\mathbb{S} of feasible points: constrained optimization . A typical wish is smallness, imposed as a norm constraint like x1\|\boldsymbol{x}\| \le 1:

feasible set 𝕊: ‖x‖ ≤ 1unconstrained minimum (infeasible)constrained optimum —ON the boundary: constraint ACTIVE

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 S\mathbb{S} (or run the line search 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 g(θ)=f([cosθ,sinθ])g(\theta) = f([\cos\theta, \sin\theta]^\top) to enforce exactly unit norm, at the price of case-by-case creativity.

The KKT machinery

The general solution: describe S={xi,g(i)(x)=0 and j,h(j)(x)0}\mathbb{S} = \{\boldsymbol{x} \mid \forall i,\, g^{(i)}(\boldsymbol{x}) = 0 \text{ and } \forall j,\, h^{(j)}(\boldsymbol{x}) \le 0\} via equality constraints g(i)g^{(i)} and inequality constraints h(j)h^{(j)}, then build the generalized Lagrangian :

Term by term

L(x,λ,α)=f(x)+iλig(i)(x)+jαjh(j)(x)L(\boldsymbol{x}, \boldsymbol{\lambda}, \boldsymbol{\alpha}) = f(\boldsymbol{x}) + \sum_i \lambda_i\, g^{(i)}(\boldsymbol{x}) + \sum_j \alpha_j\, h^{(j)}(\boldsymbol{x})
f(x)f(\boldsymbol{x})the original objectivescalar
g(i),h(j)g^{(i)},\, h^{(j)}equality (= 0) and inequality (≤ 0) constraint functions describing 𝕊m + n fns
λi,αj\lambda_i,\, \alpha_jthe KKT multipliers — new variables, one per constraint (α ≥ 0); the generalization of Lagrange multipliers to inequalitiesscalars

Then, as long as at least one feasible point exists and ff cannot reach \infty,

minxmaxλmaxα,α0L(x,λ,α)has the same optimum asminxSf(x).\min_{\boldsymbol{x}} \max_{\boldsymbol{\lambda}} \max_{\boldsymbol{\alpha}, \boldsymbol{\alpha} \ge 0} L(\boldsymbol{x}, \boldsymbol{\lambda}, \boldsymbol{\alpha}) \quad\text{has the same optimum as}\quad \min_{\boldsymbol{x} \in \mathbb{S}} f(\boldsymbol{x}).

What this really says

The inner max is an infinitely harsh referee. If x\boldsymbol{x} satisfies every constraint, no choice of multipliers can inflate LL beyond f(x)f(\boldsymbol{x}) (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 L=L = \infty (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 h(i)(x)=0h^{(i)}(\boldsymbol{x}^*) = 0 — the solution sits ON its boundary. Inactive constraints (h<0h < 0) get αi=0\alpha_i = 0: 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, αh(x)=0\boldsymbol{\alpha} \odot \boldsymbol{h}(\boldsymbol{x}) = \boldsymbol{0}. Together, the KKT conditions necessary (not always sufficient) for optimality:

  1. L=0\nabla L = 0 (gradient of the generalized Lagrangian vanishes);
  2. all constraints on x\boldsymbol{x} and the multipliers hold;
  3. complementary slackness.

§4.5 Example: linear least squares

Everything in this chapter, exercised on one function — linear least squares . Minimize f(x)=12Axb22f(\boldsymbol{x}) = \frac{1}{2}\|\boldsymbol{A}\boldsymbol{x} - \boldsymbol{b}\|_2^2:

The gradient (eqs 4.21 → 4.22)
f(x)=12Axb22=12(Axb)(Axb)f(\boldsymbol{x}) = \tfrac{1}{2}\|\boldsymbol{A}\boldsymbol{x} - \boldsymbol{b}\|_2^2 = \tfrac{1}{2}(\boldsymbol{A}\boldsymbol{x} - \boldsymbol{b})^\top(\boldsymbol{A}\boldsymbol{x} - \boldsymbol{b})

step 1/3: Squared L² as a dot product (§2.5) — the ½ is cosmetic, chosen to cancel the 2 from differentiation.

Algorithm 4.1 — minimize ½‖Ax − b‖₂² by gradient descent (click lines)
  1. 1set the step size ϵ\epsilon and tolerance δ\delta to small positive numbers
  2. 2while AAxAb2>δ\|\boldsymbol{A}^\top\boldsymbol{A}\boldsymbol{x} - \boldsymbol{A}^\top\boldsymbol{b}\|_2 > \delta do
  3. 3xxϵ(AAxAb)\boldsymbol{x} \leftarrow \boldsymbol{x} - \epsilon\,(\boldsymbol{A}^\top\boldsymbol{A}\boldsymbol{x} - \boldsymbol{A}^\top\boldsymbol{b})
  4. 4end while

The bowl being descended is exactly the lab from §4.3.1 with H=AA\boldsymbol{H} = \boldsymbol{A}^\top\boldsymbol{A} — revisit it and imagine κ\kappa as the (squared) conditioning of A\boldsymbol{A}.

The constrained version

Now minimize the same ff subject to xx1\boldsymbol{x}^\top\boldsymbol{x} \le 1 — the unit-disk picture at the top of this page, solved with the KKT recipe:

Constrained least squares via the Lagrangian (eqs 4.23 → 4.27)
L(x,λ)=f(x)+λ(xx1)L(\boldsymbol{x}, \lambda) = f(\boldsymbol{x}) + \lambda\,(\boldsymbol{x}^\top\boldsymbol{x} - 1)

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?

5 questions