Maximum and Minimum Values
Finding the highest and lowest values of a function of several variables works as in one variable: the candidates are the points where the derivative vanishes, plus the boundary. The new feature is the saddle point, a critical point that is a minimum in one direction and a maximum in another. This lesson proves the critical-point condition, derives the second-derivative test from the Hessian, finds absolute extrema on closed bounded sets, and explains why saddle points dominate the loss landscapes of deep networks.
For one variable see Maximum and Minimum Values; the survey version of optimisation is Optimization.
Local extrema and critical points
has a local maximum at if for all in some disk around ; a local minimum if there. If the inequality holds on the whole domain, the extremum is absolute (global).
Theorem (Fermat, several variables). If has a local extremum at an interior point and its first partials exist there, then , i.e. .
Proof. has a local extremum at , so by the one-variable theorem. The same with .
A critical point is a point where or where a partial derivative does not exist. Not every critical point is an extremum: has at the origin, but increases along the -axis and decreases along the -axis. That is a saddle point.
The second-derivative test
Near a critical point , the gradient term of Taylor's expansion vanishes, and
So the shape near is decided by the quadratic form . Write .
Second-derivative test. Suppose the second partials of are continuous near a critical point with .
| condition | conclusion |
|---|---|
| and | local minimum |
| and | local maximum |
| saddle point | |
| no conclusion |
Why. Complete the square, with , , and :
If , both coefficients have the sign of , so is positive for every when (minimum) and negative when (maximum). If the two terms have opposite signs, and takes both signs (saddle). Continuity of the second partials makes the same signs hold at nearby points, which turns the quadratic picture into a statement about .
Eigenvalue view. is symmetric, so it has real eigenvalues with and . Both positive minimum; both negative maximum; mixed signs saddle. This version works in any number of variables: classify a critical point of by the signs of the eigenvalues of its Hessian.
import sympy as sp
x, y = sp.symbols("x y", real=True)
f = x**3 - 3 * x + y**3 - 3 * y**2
crit = sp.solve([sp.diff(f, x), sp.diff(f, y)], [x, y], dict=True)
H = sp.hessian(f, (x, y))
for c in sorted(crit, key=lambda d: (d[x], d[y])):
Hc = H.subs(c)
D = Hc.det()
eig = sorted(v for v, m in Hc.eigenvals().items() for _ in range(m)) # with multiplicity
kind = "saddle" if D < 0 else ("min" if Hc[0, 0] > 0 else "max") if D > 0 else "?"
print(f"({c[x]}, {c[y]}) f = {f.subs(c)} D = {D} eigenvalues {eig} -> {kind}")(-1, 0) f = 2 D = 36 eigenvalues [-6, -6] -> max
(-1, 2) f = -2 D = -36 eigenvalues [-6, 6] -> saddle
(1, 0) f = -2 D = -36 eigenvalues [-6, 6] -> saddle
(1, 2) f = -6 D = 36 eigenvalues [6, 6] -> min
The Hessian here is diagonal, , so the eigenvalues can be read off: one local maximum , one local minimum and two saddles. (solve returns a list of dicts; SymPy's eigenvals() returns {eigenvalue: multiplicity}, hence the expansion.)
really is inconclusive: (minimum), (maximum) and (saddle) all have at the origin.
Absolute extrema on closed, bounded sets
Extreme Value Theorem. If is continuous on a closed and bounded set , then attains an absolute maximum and an absolute minimum on .
(Closed: contains its boundary points. Bounded: fits in some disk.) Without either condition the theorem fails: on the open square has no maximum, and on the whole plane has none either.
Closed-interval method in 2D:
- Find the values of at the critical points inside .
- Find the extreme values of on the boundary of (parametrise each piece of the boundary and do one-variable calculus, or use Lagrange multipliers).
- The largest of all these values is the absolute maximum, the smallest the absolute minimum.
Example: on the rectangle , . Inside: and give , . On the edges:
Absolute maximum 9 at ; absolute minimum 0 at and .
import numpy as np
f = lambda x, y: x**2 - 2 * x * y + 2 * y
X, Y = np.meshgrid(np.linspace(0, 3, 301), np.linspace(0, 2, 201))
Z = f(X, Y)
i = np.unravel_index(np.argmax(Z), Z.shape)
j = np.unravel_index(np.argmin(Z), Z.shape)
print(f"grid max {Z[i]:.4f} at ({X[i]:.2f}, {Y[i]:.2f})")
print(f"grid min {Z[j]:.4f} at ({X[j]:.2f}, {Y[j]:.2f})")
print("number of grid points with value < 1e-9:", int(np.sum(np.abs(Z) < 1e-9)))grid max 9.0000 at (3.00, 0.00)
grid min 0.0000 at (0.00, 0.00)
number of grid points with value < 1e-9: 2
In software: saddles in ML loss landscapes
Training a network means minimising a loss over millions of weights. At a critical point, the Hessian has one eigenvalue per weight, and the point is a local minimum only if all of them are positive. If eigenvalue signs behaved like independent coin flips, the chance that all are positive would be ; random-matrix arguments and experiments on real networks support the same qualitative picture: in high dimensions, most critical points with high loss are saddles, and the minima that do exist tend to have low loss.
That changes what an optimiser has to do. Plain gradient descent slows down near a saddle () but is pushed away along any direction with a negative eigenvalue, unless it starts exactly on the stable set. The noise in stochastic gradient descent and momentum both help it escape. Second-order methods must be careful: Newton's method jumps to the nearest critical point, saddles included, which is one reason deep learning favours first-order methods.
import numpy as np
# f(x, y) = x^2 - y^2 + y^4/4 : saddle at (0,0), minima at (0, ±√2)
grad = lambda p: np.array([2 * p[0], -2 * p[1] + p[1]**3])
def run(p, noise, steps=60, eta=0.1, seed=3):
rng = np.random.default_rng(seed)
p = np.array(p, float)
for _ in range(steps):
p = p - eta * grad(p) + noise * rng.normal(size=2)
return p
print("start on the stable line, no noise :", np.round(run([1.0, 0.0], 0.0), 4))
print("same start, tiny noise 1e-3 :", np.round(run([1.0, 0.0], 1e-3), 4))
print("minimum value at (0, √2) :", round(-2 + 4 / 4, 4))start on the stable line, no noise : [0. 0.]
same start, tiny noise 1e-3 : [-0.0017 -1.4142]
minimum value at (0, √2) : -1.0
Without noise, gradient descent started on the -axis converges to the saddle and stops; a little noise is enough to slide off it into a true minimum (here the one at ; which of the two minima it reaches depends on the random kicks). See Gradient Descent and Jacobian and Hessian.
Exercises
Exercise 1: Classify
Find and classify the critical points of .
Answer
One critical point, , a local (and global) minimum with .
Solution
Since is a positive-definite quadratic plus a linear term, this local minimum is global.
Exercise 2: Four critical points
Classify the critical points of .
Answer
minimum (), maximum (), and saddles.
Solution
Exercise 3: Closed region
Find the absolute extrema of on the closed disk .
Answer
Minimum at ; maximum 8 at .
Solution
Exercise 4: Hessian eigenvalues (code)
For , the origin is a critical point. Use NumPy to compute the Hessian's eigenvalues and classify it.
Answer
Eigenvalues , 2 and (mixed signs), so the origin is a saddle point.
Solution
The Hessian of a quadratic is constant: .
import numpy as np
H = np.array([[2, 2, 0], [2, 2, -4], [0, -4, 2]], float)
print(np.round(np.linalg.eigvalsh(H), 3))[-2.472 2. 6.472]
Test yourself
At a critical point , , . What is it?
- Local minimum
- Local maximum
- Saddle point
- The test is inconclusive
Which hypothesis does the Extreme Value Theorem need besides continuity?
- The domain is closed and bounded
- is differentiable
- has exactly one critical point
- The domain is open
Why are saddle points a bigger issue than poor local minima in deep networks?
- Saddles have larger loss gradients
- With many weights, a critical point is rarely positive definite in every direction, so most critical points are saddles
- Gradient descent cannot be used near minima
- Saddles only exist in two dimensions