Optimality Conditions
How do you know you have found a minimum? Optimality conditions turn that question into equations and inequalities you can check, and every algorithm in part 2 is a way of solving them.
First-order necessary condition
If is a local minimum of a differentiable (no constraints), then
Proof idea: if the gradient were not zero, a small step along would lower . Points with zero gradient are stationary points; they can be minima, maxima or saddle points.
Second-order conditions
The Hessian classifies stationary points:
| At a stationary point | Conclusion |
|---|---|
| (all eigenvalues ) | strict local minimum (sufficient) |
| necessary for a local minimum, but not sufficient | |
| eigenvalues of both signs | saddle point |
| strict local maximum |
The second-order Taylor expansion explains the table: near a stationary point, , and the sign of the quadratic form decides whether goes up in every direction.
import numpy as np
# f(x, y) = x^3 - 3x + y^2 - 2y : stationary points where 3x^2 - 3 = 0 and 2y - 2 = 0
f = lambda x, y: x**3 - 3 * x + y**2 - 2 * y
for x in (-1.0, 1.0):
y = 1.0
H = np.array([[6 * x, 0.0], [0.0, 2.0]])
eig = np.linalg.eigvalsh(H)
kind = "local min" if eig.min() > 0 else "saddle" if eig.min() < 0 < eig.max() else "max/degenerate"
print(f"({x:+.0f}, {y:.0f}): f = {f(x, y):+.1f}, Hessian eigenvalues {eig}, {kind}")(-1, 1): f = +1.0, Hessian eigenvalues [-6. 2.], saddle
(+1, 1): f = -3.0, Hessian eigenvalues [2. 6.], local min
When the second-order test is silent
If the Hessian is only semidefinite, higher-order terms decide. and both have ; the first has a minimum at 0, the second does not. Algorithms treat such points as "probably fine" and stop when the gradient is small.
Convex problems: the first-order condition is enough
For a convex differentiable , is necessary and sufficient for a global minimum. For a convex over a convex set , the condition becomes a variational inequality:
In words: from the optimum, no feasible direction goes downhill. On a box this says each coordinate is either interior with zero partial derivative or at a bound with the partial derivative pointing outward.
import numpy as np
# minimize (x - 2)^2 + (y + 1)^2 over the box 0 <= x, y <= 1
grad = lambda p: np.array([2 * (p[0] - 2), 2 * (p[1] + 1)])
x_star = np.clip([2.0, -1.0], 0, 1) # unconstrained minimum, clipped
g = grad(x_star)
print("x* =", x_star, " gradient =", g)
rng = np.random.default_rng(0)
Y = rng.uniform(0, 1, size=(10000, 2))
print("min of grad^T (y - x*) over 10000 box points:", round(float(((Y - x_star) @ g).min()), 4))x* = [1. 0.] gradient = [-2. 2.]
min of grad^T (y - x*) over 10000 box points: 0.0192
At the gradient points out of the box in both coordinates, so every feasible direction has a non-negative directional derivative. (Clipping the unconstrained minimum is only correct here because the objective is separable with equal scaling; in general you need Projected Gradient Descent or the KKT conditions.)
Stopping tests in practice
Algorithms stop when the optimality conditions hold approximately: , often relative to the starting gradient, plus limits on iterations and on the change in . For constrained problems the test is the KKT residual (Inequality Constraints and the KKT Conditions).
In software
- SciPy's
minimizereportsjac(the final gradient) and stops ongtol; checkingnp.linalg.norm(res.jac)is a quick sanity check. - Deep learning training rarely reaches a stationary point: it stops on a validation metric, and in high dimensions most stationary points are saddles, not bad local minima.
Exercises
Exercise 1: Classify
Find and classify the stationary points of .
Answer
Only , a saddle point.
Solution
only at the origin. The Hessian has eigenvalues of both signs, so rises along and falls along .
Exercise 2: One variable
Find the minimum of for and prove it is global.
Answer
, .
Solution
gives , and for all , so is convex on its domain and the stationary point is the global minimum.
Exercise 3: Check a candidate (code)
Is a strict local minimum of the Rosenbrock function? Check the gradient and the Hessian eigenvalues.
Answer
Yes: the gradient is zero and the Hessian eigenvalues are about 0.4 and 1001.6.
Solution
import numpy as np
x, y = 1.0, 1.0
g = np.array([-2 * (1 - x) - 400 * x * (y - x**2), 200 * (y - x**2)])
H = np.array([[2 - 400 * y + 1200 * x**2, -400 * x], [-400 * x, 200.0]])
print(g + 0, [round(float(v), 4) for v in np.linalg.eigvalsh(H)])[0. 0.] [0.3994, 1001.6006]
Both eigenvalues are positive, so the sufficient condition holds. The ratio of about 2500 is the condition number that makes this valley hard for gradient descent.
Test yourself
At a stationary point the Hessian has eigenvalues and . The point is…
- a local minimum
- a local maximum
- a saddle point
- a global minimum
Which statement is true for a convex differentiable ?
- is necessary and sufficient for a global minimum
- It may have several separate local minima with different values
- Its Hessian is always positive definite
- It has no stationary points
and (semidefinite, with a zero eigenvalue). Then …
- must be a strict minimum
- must be a saddle
- may or may not be a local minimum
- must be a maximum