SafeZone AI Learn
Learn/ Mathematical Foundations/ Optimization · lesson 2 of 7

Convexity and the geometry of loss surfaces

Convex sets and functions, the first- and second-order conditions, strong convexity and smoothness — and why these two constants govern everything gradient descent does next.

Training a model means minimizing a loss function. Everything that follows in this module — learning rates, momentum, Adam, the pathologies of deep-net training — is determined by the geometry of that loss surface. Convexity is the cleanest geometry there is, and it is the right place to start for two reasons: it is the setting where optimization has actual guarantees, and it supplies the two constants (μ\mu and LL) that will quantify the behaviour of every algorithm in this module, convex or not.

Convex sets and convex functions

A set CRdC \subseteq \mathbb{R}^d is convex if the line segment between any two of its points stays inside it:

x,yC    θx+(1θ)yCθ[0,1].x, y \in C \;\Rightarrow\; \theta x + (1-\theta)y \in C \quad \forall\, \theta \in [0,1].

A function f:RdRf:\mathbb{R}^d \to \mathbb{R} is convex if its graph never dips below any of its chords — Jensen’s inequality in its simplest form:

f(θx+(1θ)y)    θf(x)+(1θ)f(y)x,y,  θ[0,1].f\big(\theta x + (1-\theta)y\big) \;\le\; \theta f(x) + (1-\theta) f(y) \qquad \forall\, x, y,\; \theta \in [0,1].

If the inequality is strict for xyx \neq y, ff is strictly convex (at most one minimizer). Geometrically: a convex function is a bowl, possibly a degenerate one with flat directions.

Drag the two endpoints. On the convex function every chord you can draw sits on or above the curve. On the non-convex double well, place the endpoints on the two shoulders: the chord passes under the central bump — a certificate that convexity fails. The red-shaded band is exactly where the second derivative is negative; note that it coincides with where you can make the chord test fail.

The first-order condition: tangents are global underestimators

For differentiable ff, convexity is equivalent to

f(y)    f(x)+f(x)(yx)x,y.f(y) \;\ge\; f(x) + \nabla f(x)^\top (y - x) \qquad \forall\, x, y.

Read this carefully, because it is the engine behind every convergence proof you will meet: the tangent plane at any point lies below the entire function. The local linear model that gradient descent trusts is never optimistic. It has an immediate, famous consequence:

If f(x)=0\nabla f(x^\star) = 0 at some point of a convex function, then f(y)f(x)f(y) \ge f(x^\star) for every yy. Every stationary point is a global minimum. There is nothing to get trapped in.

This single line is what non-convex optimization gives up.

The second-order condition, and the two constants that matter

For twice-differentiable ff, convexity is equivalent to the Hessian being positive semidefinite everywhere: 2f(x)0\nabla^2 f(x) \succeq 0, i.e. every eigenvalue of the curvature matrix is 0\ge 0. Two refinements bound the curvature from both sides, and these bounds are the module’s recurring characters:

μ\mu-strong convexity — curvature bounded below:

2f(x)μIf(y)f(x)+f(x)(yx)+μ2yx2.\nabla^2 f(x) \succeq \mu I \quad\Longleftrightarrow\quad f(y) \ge f(x) + \nabla f(x)^\top (y-x) + \tfrac{\mu}{2}\lVert y - x \rVert^2 .

The function is at least as curved as a quadratic bowl of curvature μ\mu; minimizers are unique, and distance to the optimum is controlled by the gradient norm.

LL-smoothness — curvature bounded above (gradient is LL-Lipschitz):

f(x)f(y)Lxyf(y)f(x)+f(x)(yx)+L2yx2.\lVert \nabla f(x) - \nabla f(y) \rVert \le L \lVert x - y \rVert \quad\Longrightarrow\quad f(y) \le f(x) + \nabla f(x)^\top (y-x) + \tfrac{L}{2}\lVert y - x \rVert^2 .

The function is never curvier than a quadratic of curvature LL; overshooting a step is bounded, which is what will make a constant learning rate legal.

Their ratio is the condition number

κ  =  Lμ    1,\kappa \;=\; \frac{L}{\mu} \;\ge\; 1,

the single most important scalar in this module. κ=1\kappa = 1 is a perfectly round bowl; large κ\kappa is a long narrow ravine — steep across, flat along. In the next lesson κ\kappa will appear, exactly, in the convergence rate of gradient descent; in the momentum lesson its square root will appear in the convergence rate, and that square root is the whole reason momentum exists.

Where ML sits on the convexity spectrum

ObjectiveConvex?Why
Least squares 12Xwy2\tfrac{1}{2}\lVert Xw - y\rVert^2YesHessian XX0X^\top X \succeq 0 always; strongly convex iff XX has full column rank
Ridge regressionStrongly convexadds λI\lambda I to the Hessian, so μλ\mu \ge \lambda
LassoConvex, non-smoothw\lvert w \rvert has a kink at 0 — needs subgradients or proximal steps
Logistic regressionConvexlog-sum-exp composed with a linear map; strongly convex only with regularization
SVM (hinge loss)Convex, non-smoothmax of linear functions
Any neural network with 1\ge 1 hidden layerNopermutation symmetry alone manufactures exponentially many equivalent minima, plus genuine saddles
Matrix factorization, kk-means, deep RL objectivesNoproducts of parameters / discrete structure

Two things to take from the table. First, the classical ML core is convex — which is why those methods come with guarantees and reliable solvers, and why understanding the convex case is not an academic detour. Second, everything with a hidden layer is not, yet we will train it with the same family of algorithms. The honest framing for deep learning is: we run methods with convex-case guarantees on non-convex problems, and we study (the non-convex landscapes lesson) why that works far better than it has any right to.

What convexity buys — and the price of losing it

For a convex, LL-smooth ff, plain gradient descent with η=1/L\eta = 1/L satisfies f(xt)fLx0x22tf(x_t) - f^\star \le \frac{L\lVert x_0 - x^\star\rVert^2}{2t} — a global guarantee from purely local steps, with no initialization cleverness required. Add strong convexity and the rate becomes geometric. Lose convexity and the honest statement collapses to: gradient descent converges to a stationary point, f0\lVert \nabla f \rVert \to 0 — which could be a minimum, a plateau, or a saddle. The gap between those two statements is the intellectual territory of this module.

A caveat worth internalizing

“Convex” is a property of the function in a given parameterization. The same statistical problem can be convex in one parameterization and non-convex in another — e.g. a linear model is convex in its weights, but factorize the weight matrix as W=UVW = UV^\top (as LoRA and every matrix-factorization method do) and the objective is non-convex in (U,V)(U, V) even though nothing statistical changed.

Exercises

Work these before the next lesson

  1. Show that f(x)=max(a1x+b1,  a2x+b2)f(x) = \max(a_1^\top x + b_1,\; a_2^\top x + b_2) is convex directly from the chord definition. (This generalizes: a max of convex functions is convex — the hinge loss and ReLU networks’ loss pieces come from here.)
    Solution

    Worked solutions are part of Premiumunlock all of them for £5/month →

  2. 3 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →

References

  • S. Boyd & L. Vandenberghe, Convex Optimization, Cambridge UP 2004 — chapters 2–3 are the canonical treatment (free PDF from the authors).
  • Y. Nesterov, Lectures on Convex Optimization, 2nd ed., Springer 2018 — the source for the rate statements used throughout this module.
  • S. Bubeck, “Convex Optimization: Algorithms and Complexity”, Foundations and Trends in ML, 2015 — compact, modern, proof-first.