Convex Sets and Convex Functions
A convex set keeps every segment between its points inside itself, and a convex function sits below all its chords, which together guarantee a single global bottom.
Why Does This Exist?
Optimisation needs a promise: that the search cannot get stuck somewhere that merely looks best nearby. Convex sets and convex functions are that promise, split into two halves. The set half says the ground you search over has no holes or dents that trap you. The function half says the surface you descend has exactly one bottom.
Without the pair, every algorithm needs restarts, luck, or exhaustive search. With it, linear regression, logistic regression, SVMs and lasso all converge to the same answer from any start, and a single local check certifies the global optimum. This page defines both halves and proves the guarantee; convex optimization then builds the algorithms and certificates on top, and convexity and loss landscapes shows what breaks when networks leave this world.
The one idea you need first
A line segment between points and is the set of weighted averages for . At you get the midpoint. Everything on this page is a statement about where those averages land.
Think of It Like This
A walled lake versus two separate ponds
A convex set is a walled lake: stand anywhere in the water with a friend anywhere else, stretch a rope between you, and the whole rope stays wet. The midpoint of any two swimmers is still swimming.
Now drain the middle so only two separate ponds remain. Two swimmers in different ponds stretch their rope across dry grass: the midpoint left the set. That pair of ponds is non-convex, and an optimiser wading downhill can be stranded in the wrong pond with no path to the better one.
A convex function adds the matching surface rule: the lakebed between any two soundings never bulges above the straight line joining them. No hidden ridge can dam the descent.
Where the analogy stops: real lakes are two-dimensional, where you can see the dent. In high dimensions the dent is invisible and the test is algebraic, the segment formula and the chord inequality, not eyesight.
How It Actually Works
Convex sets
A set is convex when the segment between any two of its points stays inside it:
Examples: the unit disk, any line or hyperplane, the set of matrices with bounded norm. Non-examples: two separate disks, a crescent, any set with a hole. Intersections of convex sets stay convex, which is why adding convex constraints keeps a problem convex.
Convex functions
A function on a convex domain is convex when its graph sits below every chord:
The special case is Jensen's inequality for two points: of the average never exceeds the average of . For twice-differentiable the working test is curvature: convex exactly when the Hessian is positive semi-definite everywhere, the same positive-definite machinery the landscape pages use.
Why one bottom follows
Suppose is a local minimum but some is better: . Walk the segment from toward . Convexity forces along the segment below the chord, so arbitrarily close to there are points with value below , contradicting local minimality. Hence every local minimum is global. The gradient being zero, or KKT holding under constraints, then certifies the answer instead of merely suggesting it.
Worked example
Both halves, with numbers small enough to check by hand.
Set. Take the unit disk with and , both on the boundary since . The midpoint is with squared norm , so with norm . The segment stayed inside, as the diagram shows. Contrast the two-point set : the same midpoint is not in at all, so is not convex.
Function. Take with , , . The midpoint is with . The chord average is . Since , the chord sits above the curve, confirming convexity at this pair with a gap of exactly 1.
Code
import numpy as np
def in_unit_disk(p: np.ndarray) -> bool: return float(p @ p) <= 1.0 + 1e-12
a = np.array([1.0, 0.0])b = np.array([0.0, 1.0])m = 0.5 * a + 0.5 * bprint(m, round(float(m @ m), 4), in_unit_disk(m))# -> [0.5 0.5] 0.5 True midpoint norm^2 is 0.5, inside the disk
def f(x: float) -> float: return x ** 2
mid, chord = f(0.5 * (1 + 3)), (f(1) + f(3)) / 2print(mid, chord, mid <= chord)# -> 4.0 5.0 True curve below chord, gap of 1.0The disk check prints norm-squared and True; the chord check prints against , the same gap the diagram draws.
Watch Out For
Assuming a convex function over any domain is a convex problem
Convexity of the function alone is not enough: the domain must be convex too. Minimising over the two-point set from the worked example has no segment to descend along, and "local versus global" stops meaning anything. Optimisers assume they can step toward a better point and stay feasible; a non-convex domain breaks that step.
Always check both halves before claiming the guarantee: convex objective and convex feasible set. If the domain is discrete, disconnected, or holed, you have a combinatorial or non-convex problem wearing convex clothes.
Reading Jensen backwards on concave objectives
For concave functions such as the logarithm, the inequality flips: of the average exceeds the average of . Applying the convex direction to a concave utility or log-likelihood silently reverses a bound, turning a valid lower bound into an invalid one and an EM or variational argument into nonsense.
Check the curvature sign first. If , you hold a concave function and the chord sits below the graph. Misreading the direction is the most common way a correct-looking derivation produces an impossible number, such as a "lower bound" above the true value.
The Quick Version
- A set is convex when every segment between its points stays inside it; intersections preserve this.
- A function is convex when its graph sits below every chord, equivalently a positive semi-definite Hessian.
- Jensen at two points: of the average never exceeds the average of .
- Every local minimum of a convex function over a convex set is global.
- Unit disk midpoint has norm about and stays inside; the same pair as a bare two-point set fails.
- On between 1 and 3, the curve gives 4 against a chord of 5, a gap of 1.
- Convex function plus non-convex domain is not a convex problem; check both halves.
- Concave functions flip Jensen, so confirm the curvature sign before bounding.