VI.2 · Optimization
When does a stop mean we have found the best point?
Compare local neighborhoods with the entire objective domain. Zero gradients locate candidates; curvature and explicit lower-value witnesses decide what those candidates actually guarantee.
Inspect what a stationary point means
Parameter space: θ₁ and θ₂
Candidate θ ≈ (2, 1); objective ≈ 4; gradient ≈ (2, 4). Coordinates are model parameters; data inputs are held fixed. This candidate is not a stationary point. The marked points are the complete analytic stationary set of this example.
Loss slice: θ₂ = 0
This is a slice of the objective in parameter space, with θ₂ fixed at zero.
- Candidate parameters
- (2, 1)
- Objective value
- 4
- Actual gradient
- (2, 4)
- Hessian of the objective
- (1, 0); (0, 4)
- Stationary classification
- not a smooth stationary point
≈ binary64 calculation · = analytic classification. Replay selects the same evaluated step in every view.
This candidate is not a stationary point. The marked points are the complete analytic stationary set of this example.
| θ | Classification | Global behavior |
|---|---|---|
| (0, 0) | strict minimum | unique global minimum |
Evaluate the candidate
Candidate θ ≈ (2, 1); objective ≈ 4; gradient ≈ (2, 4). Coordinates are model parameters; data inputs are held fixed.
from −3 to 3, up to 2 decimal places
from −3 to 3, up to 2 decimal places
from 0.25 to 4, up to 2 decimal places
from −2 to 2, up to 2 decimal places
For the cubic , inspect and then . The first is a strict local minimum with loss ; the second has loss . Predict why a correct local-minimum label and a failed global claim can both describe the same candidate.
Intuition: best nearby and best everywhere
Imagine tuning a controller in small increments. Every small change from a setting may worsen its score, while a very different setting performs much better. The first comparison is local. A global claim must compare every feasible parameter choice, including regions a short run never visits.
A stationary point is where first-order sensitivity vanishes. It may be a valley, a peak, a saddle, or a degenerate point that second-order curvature cannot classify. A gradient-based algorithm can remain fixed at any of these. No movement is a fact about its update rule; optimality is a claim about the objective.
Definition: neighborhoods, domains, and stationarity
A point is a local minimum if some radius satisfies
It is a strict local minimum when the inequality is strict for every such . A global minimum satisfies for every . Maxima reverse these inequalities. A stationary point is a differentiable point with .
Here a saddle has both higher and lower objective values arbitrarily near a stationary point. The term is local; it does not say whether distant global optima exist. Stationarity is a necessary condition for a differentiable interior local optimum, not a sufficient condition. Boundary and nonsmooth optima require different reasoning.
Mechanics: inspect the candidate and its witnesses
For each candidate read its parameter coordinates, loss, and gradient, then calculate its Hessian for the curvature test. First check whether the objective is differentiable there and whether the gradient vanishes. Only then apply a stationary-point curvature test. A positive-definite Hessian at a nonstationary point describes local bending, not an optimum at that point.
Use nearby displacements along both coordinate directions to test the meaning of a label. To disprove globality, one valid lower-loss point is enough. To prove globality, several successful comparisons are insufficient: use a bound or a whole-domain property. Resetting the view or changing its extent cannot supply that proof.
Derivation: why zero gradient is necessary but insufficient
At a differentiable interior local minimum, consider any direction . The one-variable function has a minimum at , so
Taking each coordinate direction gives . This argument uses valid points on both sides of zero and differentiability. It cannot be applied to at zero or to a direction leaving a feasible boundary.
If is twice continuously differentiable near a stationary point, Taylor expansion gives
Positive-definite makes the leading quadratic positive in every nonzero direction, establishing a strict local minimum. Negative-definite establishes a strict local maximum. Opposite-sign eigenvalues establish a saddle. A zero eigenvalue leaves the test inconclusive because the remainder can decide the sign along a flat quadratic direction.
For the cubic, solve the equations directly:
Worked examples: one local minimum, no global minimum
At the cubic has loss and Hessian . An exact expansion makes the local guarantee visible:
For , this is positive whenever . Thus the point is a strict local minimum. Yet
The witness disproves globality; the limit shows the entire objective is unbounded below, so it has no global minimum. At the Hessian gives a saddle, not a two-dimensional maximum.
The worked stage returns to the canonical quadratic rather than the cubic. At it has loss and gradient , so the current candidate is not stationary. Its marked stationary point is ; nonnegativity of both squared terms proves that point is the unique global minimum. Use the opening explorer for the cubic comparisons.
Worked example: Inspect what a stationary point means
Parameter space: θ₁ and θ₂
Candidate θ ≈ (2, 1); objective ≈ 4; gradient ≈ (2, 4). Coordinates are model parameters; data inputs are held fixed. This candidate is not a stationary point. The marked points are the complete analytic stationary set of this example.
Loss slice: θ₂ = 0
This is a slice of the objective in parameter space, with θ₂ fixed at zero.
- Candidate parameters
- (2, 1)
- Objective value
- 4
- Actual gradient
- (2, 4)
- Hessian of the objective
- (1, 0); (0, 4)
- Stationary classification
- not a smooth stationary point
≈ binary64 calculation · = analytic classification. Replay selects the same evaluated step in every view.
This candidate is not a stationary point. The marked points are the complete analytic stationary set of this example.
| θ | Classification | Global behavior |
|---|---|---|
| (0, 0) | strict minimum | unique global minimum |
Evaluate the candidate
Candidate θ ≈ (2, 1); objective ≈ 4; gradient ≈ (2, 4). Coordinates are model parameters; data inputs are held fixed.
The double well behaves differently. Its gradient and Hessian are
The stationary points are . Both outer points have loss . Because everywhere, these are global minima. At the middle the loss is and the Hessian is : movement along x lowers loss, while movement along y raises it. The middle is a saddle even though the horizontal slice has a local maximum there.
Executable reference code
The independent standard-library reference solves the polynomial stationary cases by explicit substitution and evaluates their loss and diagonal Hessian entries exactly. Assertions include the literal cubic witness , both double-well minimizers, a maximum, a saddle, and inconclusive Hessians. Higher-order and one-sided evaluations check why inconclusive and nonsmooth cases need separate arguments.
The NumPy reference batches the candidates and sends their symmetric Hessians to numpy.linalg.eigvalsh. This is a library cross-check of the signs, not a floating search for roots. Its finite tail values illustrate the cubic’s decline; the analytic polynomial limit remains the proof of unboundedness.
"""Exact stationary-point calculations and counterexamples to local/global claims."""
from fractions import Fraction as F
def cubic(x, y):
x, y = F(x), F(y)
return x**3 - 3*x + y*y, (3*x*x - 3, 2*y), (6*x, F(2))
def double_well(x, y):
x, y = F(x), F(y)
return (x*x - 1)**2 + y*y, (4*x*(x*x - 1), 2*y), (12*x*x - 4, F(2))
def diagonal_test(diagonal):
# A zero eigenvalue leaves this second-order test inconclusive.
first, second = diagonal
if first > 0 and second > 0:
return "strict local minimum"
if first < 0 and second < 0:
return "strict local maximum"
if first * second < 0:
return "saddle"
return "inconclusive"
def main():
for x, expected in ((-1, "saddle"), (1, "strict local minimum")):
loss, gradient, diagonal = cubic(x, 0)
assert gradient == (0, 0)
assert diagonal_test(diagonal) == expected
assert loss == (2 if x == -1 else -2)
assert cubic(-3, 0)[0] == -18 < cubic(1, 0)[0]
# Along x=-n, y=0 the values -n^3+3n tend to minus infinity.
assert [cubic(-n, 0)[0] for n in (2, 3, 4)] == [-2, -18, -52]
for x, expected in ((-1, "strict local minimum"), (0, "saddle"), (1, "strict local minimum")):
loss, gradient, diagonal = double_well(x, 0)
assert gradient == (0, 0) and diagonal_test(diagonal) == expected
assert loss == (1 if x == 0 else 0)
assert diagonal_test((-2, -2)) == "strict local maximum" # -x^2-y^2.
assert diagonal_test((2, -2)) == "saddle" # x^2-y^2.
assert diagonal_test((0, 0)) == "inconclusive" # x^4+y^4 has a minimum.
assert diagonal_test((0, 2)) == "inconclusive" # x^3+y^2 has a saddle.
h = F(1, 10)
assert h**4 + h**4 > 0
assert (-h)**3 < 0 < h**3
assert (abs(-h)/(-h), abs(h)/h) == (-1, 1) # |x|+y^2: no gradient at x=0.
print("Exact cubic stationary points: (-1,0) saddle; (1,0) local minimum")
print("Exact lower witness (-3,0):", cubic(-3, 0)[0], "; no global minimum")
print("Exact double-well minimizers: (-1,0), (1,0); loss 0")
if __name__ == "__main__":
main()"""Vectorized stationary candidates and NumPy Hessian eigenvalue cross-checks."""
import numpy as np
def main():
candidates = np.array([[-1, 0], [1, 0]], dtype=np.float64)
x, y = candidates.T
cubic_gradients = np.column_stack((3*x*x - 3, 2*y))
cubic_hessians = np.zeros((2, 2, 2), dtype=np.float64)
cubic_hessians[:, 0, 0], cubic_hessians[:, 1, 1] = 6*x, 2
np.testing.assert_array_equal(cubic_gradients, np.zeros((2, 2)))
eigenvalues = np.linalg.eigvalsh(cubic_hessians)
np.testing.assert_array_equal(eigenvalues, [[-6, 2], [2, 6]])
np.testing.assert_array_equal(x**3 - 3*x + y*y, [2, -2])
witnesses = -np.array([2, 3, 4], dtype=np.float64)
np.testing.assert_array_equal(witnesses**3 - 3*witnesses, [-2, -18, -52])
well_x = np.array([-1, 0, 1], dtype=np.float64)
well_gradients = 4*well_x*(well_x*well_x - 1)
well_hessians = np.zeros((3, 2, 2), dtype=np.float64)
well_hessians[:, 0, 0], well_hessians[:, 1, 1] = 12*well_x*well_x - 4, 2
np.testing.assert_array_equal(well_gradients, [0, 0, 0])
np.testing.assert_array_equal(np.linalg.eigvalsh(well_hessians), [[2, 8], [-4, 2], [2, 8]])
degenerate_hessians = np.array([[[0, 0], [0, 0]], [[0, 0], [0, 2]]], dtype=np.float64)
np.testing.assert_array_equal(np.linalg.eigvalsh(degenerate_hessians), [[0, 0], [0, 2]])
h = np.array([-0.1, 0.1], dtype=np.float64)
assert np.all(h**4 > 0) and h[0]**3 < 0 < h[1]**3
print("Binary64 Hessian eigenvalues at cubic candidates ≈", eigenvalues)
print("Zero eigenvalues are inconclusive: compare x^4+y^4 with x^3+y^2.")
print("Finite witnesses disprove globality; the polynomial tail proves unboundedness.")
if __name__ == "__main__":
main()Explore: identical stopping behavior, different outcomes
At the origin, compare and . Both have zero gradient. The first has a unique global maximum of ; the second has a saddle, with losses and along the coordinate directions. Neither is a minimum for an unconstrained minimization problem.
Next compare with . Both are stationary at the origin and have singular positive-semidefinite Hessians there. The fourth-power objective is positive at every nonzero point, proving a strict global minimum. The degenerate cubic takes values and at and for every , proving a saddle.
Finally inspect . It is nonnegative and vanishes only at the origin, so it has a unique global minimum. Its left and right x slopes are and , so the classical gradient is undefined there. A correct label must preserve both facts.
Common mistakes and counterexamples
“Gradient zero” does not mean “minimum”: the peak and saddle already disprove it. “Positive Hessian here” does not mean “global”: the cubic’s strict local minimum already disproves it. “Hessian semidefinite here” does not even mean “local minimum”: at the origin disproves that stronger claim.
Do not judge classification by the sign of the loss. Adding a constant preserves every local and global comparison, so a positive loss can mark a minimum and a negative loss can mark a maximum. Also distinguish a one-dimensional slice from the full domain. The central double-well slice peaks in x while the full objective rises in y.
Numerical considerations
The rational polynomial examples support exact stationary equations and exact sign tests. A numerical trajectory is a binary64 approximation: a small computed gradient can reflect proximity to a stationary point, poor scaling, rounding, or an unreliable derivative. It does not supply an exact stationarity certificate or a global comparison.
Near a zero Hessian eigenvalue, small numerical errors can change a reported sign. Treat a numerically unresolved sign as unresolved and inspect scale and tolerances. Sampling a shrinking neighborhood can illustrate a saddle, but a plot that rounds all nearby values together may conceal higher-order behavior. For , the loss decays as the fourth power of displacement, faster than its quadratic model can reveal.
Engineering and ML connections
An optimizer’s initialization can determine which region of a nonconvex objective it explores. Trying several starts can expose alternative outcomes, but it does not prove that the best observed one is globally optimal. An engineering report should say whether its guarantee is local, global, or only empirical.
Hessian and curvature supplies the second-order test; convexity will add a whole-domain condition that converts local minima into global ones. In gradient descent, a zero update at a saddle will make the distinction operational. Nonsmooth penalties and feasible boundaries also require conditions beyond the differentiable-interior gradient test.
Exercises
Use explicit witnesses when rejecting a global claim, and a bound when proving one. Every classification must state which hypotheses justify it.
Summary and checkpoints
Local optima compare a neighborhood; global optima compare the whole domain. Zero gradients locate differentiable interior candidates, and definite Hessians classify them locally. Check that you can explain why is a cubic local minimum but not global, prove both double-well minima globally, and resolve singular or nonsmooth examples without fabricating a derivative. A stopped algorithm still needs an objective-level interpretation.