Week 8 · Bowls, not bumpy hills: convexity
Read the words of the video
- Imagine rolling a marble in a smooth bowl; it always finds the single lowest spot. But on a bumpy field, it might get stuck in a small dip, not the true bottom. Mathematicians call 'bowl-shaped' problems 'convex'. In these, if you find a bottom, it's the real bottom, no fake dips!
- Convex means 'no dents'. A convex 'set' is a shape where a straight line between any two points stays inside. A convex 'function' is like a bowl; its graph never goes above a straight chord. We check this using something called the Hessian. Convex problems are easy because any bottom you find is the true, deepest one.
- Let's check if a function, like 'x squared plus a times x times y plus y squared', is convex. We use a tool called the Hessian. If its special numbers, called eigenvalues, are all positive or zero, the function is convex. For our example, this happens only if 'a' is between minus two and plus two.
- Remember, convex sets have no dents, and convex functions are bowl-shaped. The Hessian helps us check them! For convex problems, finding any local minimum means you've found the true global minimum. This topic is super important for your exams and for understanding advanced machine learning. You've got this!
The one-minute story
Roll a marble inside a smooth bowl. Wherever you drop it, it ends up at the one lowest point. Now roll a marble on a bumpy field. It may settle in a small dip that is not the lowest place on the field, and you would never know there was a deeper valley elsewhere.
Convex is the mathematician's word for "bowl-shaped". For a convex problem there are no fake dips: if you reach a bottom, it is the bottom. That is why convex problems are the happy, solvable corner of machine learning, and why week 7's gradient descent is trustworthy for them.
This week: what convex sets are (shapes with no dents), what convex functions are (bowls), how to check convexity quickly (using the Hessian from week 7 and positive semi-definiteness from week 5), and why it matters.
By the end of this week you can:
- test whether a set is convex, and build convex combinations and convex hulls;
- test whether a function is convex using the definition, the Hessian, or closure rules;
- say what concave, strictly convex and the epigraph mean;
- explain why a local minimum of a convex function is global.
Words you need
- Convex set - a shape where the straight segment between any two of its points stays inside the shape.
- Convex combination - a mix with ; the points on the segment between and .
- Convex hull - the smallest convex set that contains some given points (stretch a rubber band round them).
- Convex function - a function whose graph never goes above the straight chord between two of its points.
- Concave - the upside-down version: is concave if is convex.
- Epigraph - the region on or above the graph of a function.
- Strictly convex - convex with no flat stretches; its minimum, if it exists, is unique.
Idea 1: Convex sets
A set is convex if for any and any , the point is also in . In words: walk in a straight line between any two points of the set and you never leave it.
Convex: a line, a plane, a filled disc, a filled ball, a square, a triangle, a half-plane , any intersection of convex sets (so a polygon cut out by several half-planes is convex).
Not convex: a ring (annulus), the outside of a disc, a crescent, a star shape, the union of two separate discs, the set of points with (just the circle line).
Useful rules:
- Intersection of convex sets is convex.
- Union of convex sets is generally not convex.
- If is convex and is a linear map, the image is convex.
Convex hull
A convex combination of points is with all and . The set of all convex combinations is the convex hull.
Question. The convex hull of is a triangle. Is in it? Is ?
Solution. The triangle is the set .
- : . Inside. (Explicitly, : weights are and add to 1.)
- : . Outside.
Idea 2: Convex functions
A function is convex if the straight chord between any two points on its graph lies on or above the graph:
Three ways to check convexity
- Second derivative (one variable): convex everywhere.
- Hessian (many variables): convex the Hessian is positive semi-definite at every point. (If it is positive definite everywhere, the function is strictly convex.) This is weeks 5 and 7 joining hands.
- First-order: is convex for all . The right side is exactly the linear approximation from week 2, so the statement says: the tangent line (plane) always lies below the graph.
Convexity and the epigraph
The epigraph of is , everything on or above the graph. Then: is a convex function its epigraph is a convex set. This is the link between the two halves of the week.
Building convex functions from others
- Sum of convex functions is convex. Non-negative multiple () is convex.
- Maximum of convex functions is convex. (So , the hinge loss, is convex.)
- is convex if is (compose with an affine map).
- If is convex and is convex and non-decreasing, then is convex. (E.g. .)
- Not safe: difference of convex functions, or a product of convex functions.
Well-known convex functions: , , , , on , any norm , and when is PSD. Not convex: on all of , , (two dips), (that is concave).
Question. Decide whether (a) and (b) are convex, and (c) for which is convex.
Solution.
(a) , eigenvalues , so strictly convex.
(b) , so with eigenvalues and . PSD but not PD: convex, but not strictly (it is flat along the line , where it is identically 0).
(c) has eigenvalues . Both are iff . So is convex exactly when .
Idea 3: Why convexity makes life easy
For a convex function on a convex set, every local minimum is a global minimum. Also, the set of all minimisers is itself convex, and for a strictly convex function the minimiser is unique. Moreover, is enough to guarantee a global minimum (no Hessian check needed).
Why? Suppose is a local minimum but some other point has a lower value, . Walk a tiny fraction of the way from towards , to . The chord rule gives . But can be as close to as we like (make small), so there are points arbitrarily near that are lower. That contradicts " is a local minimum". So no such exists.
Where do convex problems turn up?
- Least squares has Hessian , which is always PSD: convex.
- Ridge regression adds : strictly convex (MLT week 6).
- The logistic loss and the SVM objective are convex (MLT weeks 9 and 10).
- k-means and neural networks are not convex; that is why they only promise "a local minimum".
Jensen's inequality: for a convex , . For example , which is just "variance ".
Your turn
Which are convex? (a) (b) (c) (d) the union of two touching discs
Need a hint?
Draw them.
Show the full solution
(a) convex (filled disc). (b) not convex (the outside of a disc: take two points on opposite sides, the segment cuts through the hole). (c) convex (triangle, intersection of three half-planes). (d) generally not convex: two discs side by side leave a pinched waist, and a segment between far points can leave the union.
Is in the convex hull of ?
Need a hint?
The triangle is , , and above the hypotenuse? Find the hypotenuse line.
Show the full solution
The hypotenuse joins and : . At : . Yes, inside.
Is convex on all of ? On ?
Need a hint?
.
Show the full solution
is negative for , so not convex on . For we have , so it is convex on .
Is convex?
Need a hint?
Test the chord between and at the midpoint.
Show the full solution
and , so the chord at has height . But : the graph is above the chord. So not convex. (Convex minus convex is not guaranteed convex.)
Which of these are convex functions of ? (a) (b) (c) for (d)
Need a hint?
Use closure rules and the Hessian.
Show the full solution
(a) convex. (b) convex: the max of two convex functions. (c) convex: . (d) Hessian has eigenvalues and : indefinite, not convex.
Exam radar
Convexity belongs to the End Term. Summaries mention convex functions in 21 papers, convex sets in 13, convexity in 8, convex set in 9, Hessian matrix in 13, alongside the optimisation topics of weeks 7 and 9.
Typical questions: "Which of the following functions are convex?", "For what values of is this function convex?" (Hessian eigenvalues), "Which statements about convex sets are true?", "Is this point in the convex hull?", and "what does the composition of two functions look like near a point".
The newest papers (2025 to 2026) still carry convexity MSQs every time: sets, hull, epigraph and composition.
- Union of convex sets is usually not convex. Intersection is.
- Convex function "has one minimum": and are convex with many minimisers. Only strictly convex gives uniqueness.
- A convex function need not have a minimum at all ().
- Convex means PSD Hessian (allowing zero eigenvalues), strictly convex means PD.
- Concave not convex. is concave; is neither.
Quick quiz
The Hessian of f has eigenvalues 3 and 0 everywhere. The function f is...
- not convex
- convex but not strictly convex
- strictly convex
- concave
Which set is convex?
- a circle line (only the boundary)
- the union of two separate discs
- the intersection of two discs
- a ring (annulus)
A local minimum of a convex function is...
- always a local maximum too
- always a global minimum
- never unique
- always zero
Select all convex functions. (select all that apply)
- x squared
- |x|
- x cubed on all of the real line
- sin x
Recap
- Convex set: segments between its points stay inside. Intersections convex, unions not.
- Convex function: chord above graph; ; Hessian PSD; tangent plane below graph; epigraph is a convex set.
- Sum, non-negative multiple, max, and affine composition preserve convexity.
- Convex local minimum = global minimum, and zero gradient is enough. Least squares, ridge, logistic loss, SVM are convex; k-means and neural nets are not.
- Convex set: for
- Convex function:
- 1-D: ; many variables: (PSD); strictly convex:
- First-order:
- Jensen:
- Epigraph: convex convex
- MLT week 6 - Ridge and LASSO: taming overfitting: Ridge and LASSO are convex problems, so a global best exists and can be found.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 13 real questions on this week All Quiz 2 papers