TL;DR
A set is convex if, for any two points in it, the straight line segment joining them lies entirely inside the set. Discs, squares and filled triangles are convex. Shapes with a dent, a hole or two separate pieces are not. Convexity is what makes optimization reliable: when both the region of allowed choices and the cost are convex, any local best point is the global best.
Where you'll see it: in the feasible region of a linear program, which is an intersection of half-planes and therefore convex; in the definition of a convex function; and in support vector machines, where two classes can be separated by a straight line exactly when their convex hulls do not overlap.
Intuition
Stretch a rubber band
Put a rubber band around a set of nails on a board and let it snap tight. The shape it makes is the convex hull of the nails: the smallest convex shape that contains all of them. Now take a crescent. Pick two points on its horns and draw the straight line between them. The line cuts across the empty hollow. That is what non-convexity looks like. A convex set never lets a straight line leave it.
In one dimension the picture is even simpler: a convex subset of the real line is a single interval with no gaps. The plot below shows a set that is two pieces. The midpoint of two of its points falls in the gap, so the set is not convex.
Why does this matter? Suppose you want to minimize a cost over a region of allowed choices. If the region has dents, a local method can get stuck in a pocket that is worse than a valley far away. If the region is convex, there are no pockets. Checking convexity is the first thing people do before trying to optimize anything.
The math
A set is convex if for every pair of points and every number with , the point
also lies in .
Here is the space of vectors with real entries, and each vector is a point. The expression is a point on the straight line through and . When it is ; when it is ; when it is the midpoint. As slides from 0 to 1, the point traces the whole segment. So the definition says the entire segment stays in .
Convex combinations
A convex combination of points is a weighted average
The weights are non-negative and sum to one, so the result cannot escape the region spanned by the points. The two-point case in the definition is the special case . The convex hull of a set , written , is the set of all convex combinations of points of . It is the smallest convex set containing .
Three facts that do most of the work
Intersections keep convexity. If and are convex, so is . Take and in both sets. The segment between them lies in , because is convex, and in , for the same reason. So it lies in . This is why constraints can be stacked: each constraint defines a convex set, and the feasible region is their intersection.
Unions do not. Two disjoint discs have a union that is not convex. Pick a point in each disc, and the segment between them crosses the gap.
Linear inequalities define convex sets. For any vector and number , the set is convex. If and , then
The left-hand side is a dot product of with a point, and the inequality is preserved because the weights and are non-negative.
Worked examples
Let be the closed unit disc, where is the length of , its distance from the origin. Take and . Both have length 1, so both lie in .
- Take . The point is .
- Its length is .
- Since , the midpoint is in .
Now take the ring . Take and . Both lie in .
- The midpoint is .
- Its length is 0, which is less than 1, so the midpoint is not in .
Interpretation: the disc has no hole, so every segment between its points stays inside. The ring's hole is exactly what a segment can cross.
A workshop makes two products. Let and be the quantities made. The constraints , and (machine hours) define a feasible set . Each constraint is a linear inequality, so each set is convex, and is their intersection, hence convex.
Check this with numbers. Take and . Both are feasible, and both sit on the machine-hours edge: and .
- Midpoint, : .
- Check: , and both coordinates are non-negative. The midpoint is feasible.
- Point at toward : .
- Check: . Feasible again.
Interpretation: a plan that mixes two feasible plans is still feasible, because the machine hours of a mix are the weighted average of the two plans' hours, and neither exceeds 12. The region has no holes, so mixing never leaves it. This is part of why linear programs are so tractable.
Tradeoffs and failure modes
Convexity is a property you have to check, and it is not always there.
| Situation | Problem | Better choice |
|---|---|---|
| Feasible region defined only by linear constraints | None: the region is convex | Use a convex solver, such as linear programming |
| Region with holes, several pieces, or a bulging inward boundary | Local search can stall in a pocket | Split into convex pieces, solve each, keep the best; or replace with a convex approximation |
| Convex region but non-convex objective (typical of neural network losses) | Local minima; the global guarantee is gone | Accept a good local solution, use restarts, or pick a better initialization |
| Set in high dimensions | Impossible to picture and hard to check by eye | Check the defining inequalities, or test the definition on random pairs of points |
Do not confuse this with a convex function. Convexity of a set is a property of the set. Convexity of a function is defined through chords of its graph, a different object, although the two ideas are linked: a function is convex exactly when the region above its graph is a convex set.
History
Convex sets were studied as geometry before they became tools for optimization. Hermann Minkowski developed much of the theory of convex bodies in the 1890s and early 1900s, in his work on the geometry of numbers. In the mid-20th century, researchers found that convexity gave real guarantees for optimization. Linear programming, made practical by George Dantzig's simplex method in the late 1940s, works over convex feasible regions. R. Tyrrell Rockafellar's 1970 book Convex Analysis gathered the general theory in a form that became standard. Efficient algorithms for general convex problems, the interior-point methods, followed in the 1980s and 1990s.
Check yourself
QuestionIn words, what must be true of every pair of points for a set to be convex?Show answer
For every two points in the set, the entire straight segment joining them must also lie in the set. Equivalently, every point with must be in the set.
QuestionLet , and . Compute .Show answer
Step 1: . Step 2: . Step 3: Add: . The answer is . This point lies one quarter of the way from to , so it is closer to on the segment.
QuestionWhy is the intersection of two convex sets always convex, while the union of two convex sets usually is not?Show answer
For the intersection, take two points that lie in both sets. Each set contains the segment between them, so both sets contain the whole segment, and so does their intersection. For the union, the two points may each lie in only one set. The segment between them then has to cross from one set to the other, and it can pass through the gap between the sets, which is outside the union.
QuestionA robot's allowed positions form a room with a square pillar in the middle. Is the set of allowed positions convex? Why does this matter for a planner that moves in straight lines?Show answer
No. Two positions on opposite sides of the pillar can each be allowed, but the straight line between them passes through the pillar, which is forbidden. A planner that moves in straight lines must route around the pillar. If the free space were convex, a straight line between any two allowed positions would be allowed, and the planner could move directly.