From training practice to optimality#
In intermediate Optimization, you trained models by running gradient descent until the gradient was "small enough." The loss curve flattened; you declared convergence and moved on. This practical stopping criterion — — works well in practice but dodges a deeper question: when is a point truly optimal?
This course asks that question rigorously. A point might satisfy and still fail to be a local minimum. A constrained problem might have a point where no feasible direction improves the objective, yet the point is not a KKT point because a constraint qualification fails. Knowing the difference between "gradient is small" and " is a local minimum" separates applied practitioners from those who can diagnose why an optimizer failed.
Consider a concrete distinction. You train logistic regression on a separable dataset. The loss keeps decreasing epoch after epoch, but the weights — the objective approaches its infimum asymptotically but never attains it on any finite . No point satisfies , yet the training procedure "converges" practically. This course gives you the language to describe that situation: the problem lacks an unconstrained minimizer, and even KKT may not apply without a constraint to bound the weights.
Unconstrained first-order conditions#
Let be differentiable. Suppose is a local minimum: there exists a neighbourhood of such that for all .
Theorem (First-Order Necessary Condition): If is a local minimum and is differentiable at , then
Proof sketch. For any direction , the directional derivative
must be (otherwise points for small would have lower function value). Repeating with gives , implying by linearity. Thus for all , so .
Points where are called stationary points or critical points. Not every stationary point is a local minimum — it could be a maximum or a saddle.
Worked example. Let . The derivative is . Stationary points: .
- — local minimum (check )
- — local maximum ()
- — local minimum
The stationary condition alone cannot distinguish them; we need second-order information.
When differentiability fails. If , then is the global minimum but does not exist. Subgradient methods (intermediate Optimization Week 10) and proximal methods (Week 7 of this course) handle the nondifferentiable case. The first-order necessary condition requires differentiability — lose it, and you need a different theory.
Second-order flavor#
Stationary points are only candidates. The Hessian classifies them: positive definite is a minimum, negative definite a maximum, and indefinite a saddle. First-order conditions find the points; second-order conditions name them.
With twice-differentiable :
-
Necessary: If is a local minimum, then (the Hessian is positive semidefinite, or PSD). Proof: a negative eigenvalue would produce a direction along which decreases quadratically.
-
Sufficient: If and (strictly positive definite), then is a strict local minimum. The quadratic Taylor approximation bounds the function from below in a neighbourhood.
The gap between necessary () and sufficient () is the indefinite or semidefinite-at-zero case, e.g., at : , , yet is neither a minimum nor a maximum — it is an inflection point.
Strong convexity shortcut. If is -strongly convex ( for all ), then any stationary point is automatically the unique global minimum. This is the convex world intermediate Optimization operated in — a world where first-order is enough. This course spends its first seven weeks drilling into what else convex structure buys you beyond GD guarantees.
Worked numeric example. . The gradient:
Setting gives , so . Substituting: . This is a transcendental equation — no closed form. Numerical root finding (e.g., Newton on the scalar equation) is needed. The lesson: even smooth unconstrained problems quickly become analytically intractable; that is why iterative methods exist.
Constraints enter#
Real optimization problems rarely live unconstrained on all of . They come with equality and inequality constraints:
The set of points satisfying all constraints is the feasible set .
Active constraints. At a feasible point , the inequality is active if (the constraint is binding — you are on the boundary) and inactive if (slack remains). Inactive constraints do not restrict local movement — you can wiggle a little and still satisfy them. Active ones matter for optimality because they define the local boundary of the feasible set.
Feasible directions. A vector is a feasible direction at if there exists such that for all . Intuitively, you can take a small step along without leaving the feasible set.
First-order necessary condition (constrained). If is a local minimum of the constrained problem, then for every feasible direction . No feasible direction points strictly downhill.
For equality constraints , the gradient must be orthogonal to any feasible direction — otherwise you could move along the constraint surface and violate . This orthogonality is the geometric seed of Lagrange multipliers.
Worked example. subject to .
The feasible set is a line; the objective contours are circles centred at the origin. Visually, the optimum is where the smallest circle touches the line — at , where the gradient is parallel to the constraint gradient . This parallelism is exactly the Lagrange multiplier condition that Week 2 formalises.
Constraint qualifications (why KKT needs them)#
The geometric argument above — that at optimality, lies in the span of active constraint gradients — requires that the constraint gradients themselves be "well-behaved" at the candidate point. If the constraints are degenerate (e.g., redundant, or gradients are linearly dependent in a pathological way), the multipliers may not exist, or KKT may fail to hold at a genuine local minimum.
A constraint qualification (CQ) is a condition on the constraints that guarantees the existence of Lagrange multipliers at a local minimum. Several CQs exist; the two most common:
-
LICQ (Linear Independence Constraint Qualification): The gradients of all active constraints (both equality and inequality) at are linearly independent. LICQ is the strongest commonly used CQ and the easiest to check.
-
MFCQ (Mangasarian–Fromovitz CQ): The equality constraint gradients are linearly independent, and there exists a vector such that for all equalities and for all active inequalities. MFCQ is weaker than LICQ (it allows some dependence among inequality gradients) but still guarantees multiplier existence.
Why CQs matter in practice. Consider subject to . The only feasible point is , which is trivially optimal. But the constraint gradient at is — it vanishes. LICQ fails (the "gradient" of the active constraint is the zero vector, trivially linearly dependent). KKT does not hold with finite multipliers: there is no such that and simultaneously, because gives , which is false.
This is a manufactured example, but real equivalents arise in control problems where constraints are implicitly redundant or gradients become near-parallel at the boundary. When an IPM solver (Week 6) reports "constraint qualification violation," this is what it means.
CQs are the legal fine print of optimality theory: they ensure the machinery of Lagrange multipliers and KKT actually applies. The good news: for most well-posed convex problems, Slater's condition (Week 2) provides a clean, easy-to-check alternative.
Knowledge Check#
For smooth unconstrained f, a first-order necessary condition at a local minimum is that the gradient equals ____.
A point where ∇f(x) = 0 is called a ____ point.
Browser lab#
Plot a 2D function (the "Mexican hat" in each coordinate). Visualise stationary points: minima at , a local maximum at , and saddles at and . Overlay the gradient field.
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return x**4 + y**4 - 2*x**2 - 2*y**2
def grad(x, y):
return np.array([4*x**3 - 4*x, 4*y**3 - 4*y])
xs = np.linspace(-1.8, 1.8, 300)
ys = np.linspace(-1.8, 1.8, 300)
X, Y = np.meshgrid(xs, ys)
Z = f(X, Y)
fig, ax = plt.subplots(figsize=(7, 6))
cont = ax.contourf(X, Y, Z, levels=30, cmap="coolwarm", alpha=0.85)
plt.colorbar(cont, ax=ax, label="f(x,y)")
# Mark stationary points
stationary = [(-1,-1), (-1,1), (1,-1), (1,1), (0,0), (-1,0), (1,0), (0,-1), (0,1)]
labels = ["min", "min", "min", "min", "max", "saddle", "saddle", "saddle", "saddle"]
colors = ["tab:green"]*4 + ["tab:red"] + ["tab:orange"]*4
for (sx, sy), lbl, clr in zip(stationary, labels, colors):
ax.plot(sx, sy, "o", color=clr, markersize=8, markeredgecolor="black", markeredgewidth=0.5)
# Gradient field on a coarser grid
gx = np.linspace(-1.8, 1.8, 18)
gy = np.linspace(-1.8, 1.8, 18)
GX, GY = np.meshgrid(gx, gy)
U = np.zeros_like(GX)
V = np.zeros_like(GY)
for i in range(GX.shape[0]):
for j in range(GX.shape[1]):
gv = grad(GX[i,j], GY[i,j])
nrm = np.linalg.norm(gv)
if nrm > 0.01:
U[i,j], V[i,j] = gv / nrm
ax.quiver(GX, GY, U, V, scale=30, alpha=0.5, color="black")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_title("Stationary points of $f(x,y)=x^4+y^4-2x^2-2y^2$")
ax.set_aspect("equal")
plt.show()
# Check gradient norms at stationary points
for (sx, sy), lbl in zip(stationary, labels):
g = grad(sx, sy)
print(f"Point ({sx:+.0f}, {sy:+.0f}) [{lbl:6s}]: gradient norm = {np.linalg.norm(g):.6f}")
print("Notice: every one of the nine marked points has gradient norm 0.000000: a vanishing gradient marks maxima, minima and saddles alike.")
Key takeaways#
- A small gradient is not optimality. The first-order condition is necessary only for differentiable unconstrained problems, and it marks maxima and saddles just as well as minima.
- The Hessian classifies stationary points: is necessary at a minimum, is sufficient, and strong convexity makes any stationary point the unique global minimum.
- With constraints, "set the derivative to zero" becomes "no feasible direction descends": for every feasible direction .
- Active constraints are the ones that matter. Inactive constraints do not restrict local movement and will carry zero multiplier.
- KKT needs a constraint qualification. LICQ (active constraint gradients independent) and MFCQ are the standard ones; without a CQ a genuine local minimum can have no multipliers at all, as subject to shows.
- For convex problems, Slater's condition is the easy alternative to checking a CQ by hand.
Further reading#
- Jorge Nocedal & Stephen Wright, Numerical Optimization (2nd ed., Springer, 2006) — Chapter 2 states and proves the first- and second-order optimality conditions.
- Dimitri P. Bertsekas, Nonlinear Programming (3rd ed., Athena Scientific, 2016) — the rigorous theory of stationarity and constraint qualifications.
- Stephen Boyd & Lieven Vandenberghe, Convex Optimization (Cambridge University Press, 2004) — free online; the optimality-condition material for the convex case.
Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.