AI State of the Art
Math/Optimization/12 min
Section 330

Convexity: Convex Functions, Local vs Global Minima

Listen as a podcast →

Optimization: finding the bottom of the valley

Training a machine learning model amounts to solving an optimization problem: finding the parameters θ\theta that minimize a loss function L(θ)L(\theta). The shape of this loss function determines the difficulty of the problem. And convexity is the property that distinguishes "easy" problems from "hard" ones.

Convex functions: the bowl

Definition

A function ff is convex if, for all points xx and yy and any t∈[0,1]t \in [0, 1]:

f(tx+(1−t)y)≤t⋅f(x)+(1−t)⋅f(y)f(tx + (1-t)y) \leq t \cdot f(x) + (1-t) \cdot f(y)

In geometric terms, this means that the line segment connecting any two points on the graph of ff always stays above the curve. In other words, the function "curves upward," like the inside of a bowl.

Blue parabola f(x) = x squared with two red points sitting on the curve and the dashed red segment joining them. A vertical green segment links a point of that chord to the corresponding point of the curve, which lies below it.
The dashed red chord joins two points of the parabola. The green segment shows the gap: the chord always sits above the curve, which is exactly the inequality written above.Source : Marcel Brenndoerfer, Differential Calculus and Optimization

Analogy: the bowl

Imagine a marble in a bowl. No matter where you drop it, it will always end up at the bottom. That's exactly the key property of convex functions: every local minimum is a global minimum. There's only one bottom, and gradient descent inevitably leads there.

Examples of convex functions

  • f(x)=x2f(x) = x^2 (parabola)
  • f(x)=∣x∣f(x) = |x| (absolute value)
  • f(x)=exf(x) = e^x (exponential)
  • f(x)=∥x∥2f(\mathbf{x}) = \|\mathbf{x}\|^2 (squared norm)
  • MSE for linear regression

Fundamental property

For a differentiable convex function, the optimality condition is simple:

∇f(x∗)=0  ⟹  x∗ is a global minimum\nabla f(x^*) = 0 \implies x^* \text{ is a global minimum}

If you find a point where the gradient is zero, you can be certain it's the global minimum. No ambiguity, no trap, that's what makes convex optimization so comfortable.

Non-convex functions: the mountainous landscape

The reality of deep learning

Loss functions of neural networks are massively non-convex. As soon as you introduce nonlinearities (ReLU, sigmoid, tanh) and multiple layers, the loss surface becomes a complex landscape with multiple valleys, hills, and passes.

Analogy: the mountain

Imagine a blindfolded hiker in a mountain range, looking for the lowest point. By only following the descending slope, they might end up in a valley that isn't the deepest, that's a local minimum, and they have no way of knowing that something better exists elsewhere.

Wavy grey curve showing the loss function against a parameter value. A first shallow dip is marked with a blue dot labelled local minimum, and a second, clearly deeper dip is marked with a yellow dot labelled global minimum.
A non-convex loss has several dips. A hiker starting on the left settles at the blue dot with no local way of telling that the yellow dot further along is lower.Source : Bradley Boehmke, Hands-On Machine Learning with R

Types of critical points

In high dimensions, the points where the gradient is zero fall into three categories:

  • Local minimum: the function goes up in all directions
  • Local maximum: the function goes down in all directions
  • Saddle point: the function goes up in some directions and down in others

A saddle point resembles a horse saddle: a minimum in the front-back direction but a maximum in the left-right direction.

Why networks work despite non-convexity

This is the big question of deep learning. If the loss is non-convex, with potentially billions of local minima, how does SGD (Stochastic Gradient Descent) find good solutions? Several elements of the answer:

Saddle points dominate

In very high dimensions (millions or billions of parameters), true local minima are extremely rare. Why? For a critical point to be a local minimum, curvature must be positive in all directions simultaneously. With millions of directions, this is statistically improbable.

The vast majority of critical points are saddle points. And SGD naturally traverses them thanks to stochastic noise: the noisy gradient pushes the trajectory away from saddle points, even when the average gradient is close to zero.

Attraction basins are wide

Good solutions are not isolated, narrow minima, but wide flat basins. Research shows that these flat basins correspond to solutions that generalize well. The intuition: a wide minimum is "robust" to parameter perturbations, just as a generalizing solution is robust to data perturbations.

Two overlaid curves, the training loss as a solid black line and the test loss as a dashed red line shifted slightly sideways. On the left a wide shallow basin labelled flat minimum, on the right a narrow deep well labelled sharp minimum.
The dashed red test curve is the training curve shifted slightly. In the wide basin on the left that shift barely changes the loss; in the narrow well on the right it sends the test loss shooting up.Source : Keskar et al. 2017, On Large-Batch Training for Deep Learning, via the Mostly Machine Learning blog

Overparameterization helps

A network with more parameters than data has many zero-loss solutions. These solutions form connected manifolds in parameter space. SGD doesn't have to find an isolated point; it just has to reach this manifold, which is much easier.

SGD noise is beneficial

The mini-batch noise in SGD acts as a natural regularizer. It prevents convergence to narrow, "sharp" minima (which overfit) and favors wide, flat minima (which generalize).

The Hessian and convexity

The Hessian

The Hessian H\mathbf{H} is the matrix of second derivatives:

Hij=∂2f∂xi∂xjH_{ij} = \frac{\partial^2 f}{\partial x_i \partial x_j}

It captures the curvature of the function in each direction. In a sense, if the gradient tells you "which direction it's tilting," the Hessian tells you "how curved the terrain is", and it's this curvature that distinguishes minima from maxima and saddle points.

  • ff is convex if and only if H\mathbf{H} is positive semi-definite everywhere (all eigenvalues ≥0\geq 0)
  • At a critical point ∇f=0\nabla f = 0:
    • All eigenvalues >0> 0: local minimum
    • All eigenvalues <0< 0: local maximum
    • Mixed sign eigenvalues: saddle point

In practice

Computing the full Hessian of a neural network is impossible: for nn parameters, it's an n×nn \times n matrix that would occupy petabytes of memory. But you can efficiently compute the Hessian-vector product, which is enough for some second-order optimization methods.

Local convexity and "nearly convex" functions

Strong convexity

A function is μ\mu-strongly convex if:

f(y)≥f(x)+∇f(x)⊤(y−x)+μ2∥y−x∥2f(y) \geq f(x) + \nabla f(x)^\top (y - x) + \frac{\mu}{2} \|y - x\|^2

The term μ2∥y−x∥2\frac{\mu}{2}\|y - x\|^2 guarantees a minimum curvature in all directions. The larger μ\mu, the more "curved" the function and the faster gradient descent converges to the minimum. In AI, L2 regularization makes the loss strongly convex around the minimum, which stabilizes training.

Smoothness

A function is LL-smooth if its gradient doesn't vary too fast:

∥∇f(x)−∇f(y)∥≤L∥x−y∥\|\nabla f(x) - \nabla f(y)\| \leq L \|x - y\|

It's a bound on the maximum curvature. Concretely, for an LL-smooth function, you know gradient descent converges as long as the learning rate satisfies α≤1/L\alpha \leq 1/L. That's why a learning rate that's too large makes training diverge: it exceeds the limit imposed by the curvature of the loss.

The ratio κ=L/μ\kappa = L/\mu

The condition number κ\kappa measures the "imbalance" of curvature:

  • κ\kappa close to 1: the function is well-conditioned, convergence is fast
  • κ\kappa large: the function is ill-conditioned, optimization is slow (narrow, elongated valleys)

This is exactly what motivates the use of adaptive optimizers like Adam, which adapt to the local curvature in each direction.

Key takeaways

  • A convex function has a unique global minimum: optimization is "easy"
  • Neural network loss functions are non-convex: multiple local minima and saddle points
  • In high dimensions, saddle points are far more common than local minima
  • SGD works despite non-convexity thanks to stochastic noise, overparameterization, and wide attraction basins
  • The Hessian captures local curvature and determines the nature of critical points
  • The condition number κ\kappa quantifies the difficulty of optimization

Where this is used. This is what explains why gradient descent works in practice without ever guaranteeing it reaches the best possible minimum.