Part I — Calculus, Optimization & Gradients · Chapter 6

Convexity & optimization landscapes

Hook

Every bowl you've dragged a point across so far had exactly one bottom, findable from anywhere. Real loss landscapes are rarely a single bowl — they can fold into separate dips, and worse, they can have flat spots that look like a minimum from one direction and a maximum from another.

Intuition
f(x,y) = 3.05, |∇f| = 4.11

This surface has two dips separated by a ridge. Drag along the ridge itself, right through the middle — the gradient can shrink to nearly nothing there too, even though it obviously isn't the bottom of anything.

Formalize

A function is convex if the Hessian's eigenvalues are non-negative everywhere — informally, if it curves upward (or stays flat) in every direction, at every point. When that fails, a critical point (where f=0\nabla f = 0) needs a second test to classify:

detHf=fxxfyyfxy2\det H_f = f_{xx}f_{yy} - f_{xy}^2
  • HfH_f — the Hessian of ff at the critical point being classified.
  • fxx,fyyf_{xx}, f_{yy} — the two pure second partials (curvature along each axis).
  • fxyf_{xy} — the mixed second partial (how curvature along one axis changes as the other moves).
  1. det > 0 and fxx > 0: a minimum

    Both axes curve upward and agree with each other — a genuine local bottom.

  2. det > 0 and fxx < 0: a maximum

    Both axes curve downward together — a genuine local top.

  3. det < 0: a saddle point

    The axes disagree — curving up along one direction and down along another. The gradient still vanishes here, but it's neither a min nor a max: this is exactly what happened on the ridge above.

  4. Convex functions never produce a saddle

    If ff is convex everywhere, detHf0\det H_f \geq 0 and fxx0f_{xx}\geq 0 hold at every point, so this test can only ever report "minimum" — which is precisely why convexity was such a strong guarantee in the first place.

Play
f = 3.05, |∇f| = 4.11

On the convex bowl, every critical point the test finds is a minimum — there's no other option. Switch to the non-convex landscape and settle near the ridge at the center: same test, same formula, and this time it reports "saddle."

Worked example

Let f(x,y)=(x22)2+y2f(x,y) = (x^2-2)^2+y^2, which has three critical points: the ridge at the origin, and two wells at x=±2x=\pm\sqrt2.

  1. Confirm the origin is critical

    Differentiate via the chain rule — the outer square, times the inner derivative:

    • f/x=2(x22)x(x22)=2(x22)2x=4x(x22)\partial f/\partial x = 2(x^2-2)\cdot\frac{\partial}{\partial x}(x^2-2) = 2(x^2-2)\cdot 2x = 4x(x^2-2)
    • f/y=2y\partial f/\partial y = 2y
    f(0,0)=(4(0)(022), 2(0))=(0,0)\nabla f(0,0) = \big(4(0)(0^2-2),\ 2(0)\big) = (0,0)
  2. Classify it with the Hessian test

    Differentiate the two first partials again:

    • From f/x=4x38x\partial f/\partial x = 4x^3-8x: fxx=/x[4x38x]=12x28f_{xx}=\partial/\partial x[4x^3-8x]=12x^2-8
    • From that same expression: fxy=/y[4x38x]=0f_{xy}=\partial/\partial y[4x^3-8x]=0 (no yy appears in it)
    • From f/y=2y\partial f/\partial y = 2y: fyy=/y[2y]=2f_{yy}=\partial/\partial y[2y]=2

    At x=0x=0: fxx=12(0)28=8f_{xx}=12(0)^2-8=-8, so detHf=(8)(2)02=16<0\det H_f = (-8)(2) - 0^2 = -16 < 0 — a saddle, exactly as the drag confirmed.

  3. Classify a well the same way

    At x=2x=\sqrt2: fxx=12(2)8=16>0f_{xx}=12(2)-8=16>0, so detHf=(16)(2)=32>0\det H_f = (16)(2)=32>0 and fxx>0f_{xx}>0 — a minimum, with f(2,0)=0f(\sqrt2,0)=0, the global minimum value.

Checkpoint

Drag the point to the landscape's saddle point — where the gradient vanishes but the Hessian determinant is negative, so it's neither a minimum nor a maximum.

|∇f| = 4.11
Drag the point to try it
Summary
detHf=fxxfyyfxy2\det H_f = f_{xx}f_{yy}-f_{xy}^2

A vanishing gradient is necessary for a minimum, but never sufficient — the second-derivative test is what tells a genuine bottom apart from a saddle or a ridge. Neural network loss landscapes are almost never convex, and in high dimensions saddle points, not local minima, turn out to be the more common obstacle — which is exactly why practical optimizers need more than "follow the gradient downhill" to escape them.