Search

Search papers and lessons

Convex Set

Level 2 · 11 min read

A set is convex when the straight segment between any two of its points stays inside the set. This one picture underlies much of optimization.

On this page

  • Colour = topic mix
  • Linear algebra
  • Optimization
  • Sign in to see your progress

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.

−0.500.511.522.533.5−0.6−0.4−0.200.20.40.6x
The set S is the two thick pieces [0, 1] and [2, 3]. The points 0.5 and 2.5 are both in S, but their midpoint 1.5 (the marked point) is in the gap, outside S. So S 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

Definition: Convex set

A set C⊆RnC \subseteq \mathbb{R}^n is convex if for every pair of points x,y∈C\mathbf{x}, \mathbf{y} \in C and every number θ\theta with 0≤θ≤10 \le \theta \le 1, the point

θx+(1−θ)y\theta \mathbf{x} + (1 - \theta)\mathbf{y}

also lies in CC.

Here Rn\mathbb{R}^n is the space of vectors with nn real entries, and each vector is a point. The expression θx+(1−θ)y\theta \mathbf{x} + (1-\theta)\mathbf{y} is a point on the straight line through x\mathbf{x} and y\mathbf{y}. When θ=1\theta = 1 it is x\mathbf{x}; when θ=0\theta = 0 it is y\mathbf{y}; when θ=0.5\theta = 0.5 it is the midpoint. As θ\theta slides from 0 to 1, the point traces the whole segment. So the definition says the entire segment stays in CC.

Convex combinations

A convex combination of points x1,…,xk\mathbf{x}_1, \dots, \mathbf{x}_k is a weighted average

θ1x1+θ2x2+⋯+θkxk,θi≥0,θ1+⋯+θk=1.\theta_1 \mathbf{x}_1 + \theta_2 \mathbf{x}_2 + \cdots + \theta_k \mathbf{x}_k, \qquad \theta_i \ge 0, \quad \theta_1 + \cdots + \theta_k = 1.

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 k=2k = 2. The convex hull of a set SS, written conv⁡(S)\operatorname{conv}(S), is the set of all convex combinations of points of SS. It is the smallest convex set containing SS.

Three facts that do most of the work

Intersections keep convexity. If CC and DD are convex, so is C∩DC \cap D. Take x\mathbf{x} and y\mathbf{y} in both sets. The segment between them lies in CC, because CC is convex, and in DD, for the same reason. So it lies in C∩DC \cap D. 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 a\mathbf{a} and number bb, the set {x:a⊤x≤b}\{\mathbf{x} : \mathbf{a}^\top \mathbf{x} \le b\} is convex. If a⊤x≤b\mathbf{a}^\top \mathbf{x} \le b and a⊤y≤b\mathbf{a}^\top \mathbf{y} \le b, then

a⊤(θx+(1−θ)y)=θ a⊤x+(1−θ) a⊤y≤θb+(1−θ)b=b.\mathbf{a}^\top\big(\theta \mathbf{x} + (1-\theta)\mathbf{y}\big) = \theta\, \mathbf{a}^\top \mathbf{x} + (1-\theta)\, \mathbf{a}^\top \mathbf{y} \le \theta b + (1-\theta) b = b.

The left-hand side is a dot product of a\mathbf{a} with a point, and the inequality is preserved because the weights θ\theta and 1−θ1-\theta are non-negative.

Worked examples

Example
A disc is convex, a ring is not

Let D={x∈R2:∥x∥≤1}D = \{\mathbf{x} \in \mathbb{R}^2 : \|\mathbf{x}\| \le 1\} be the closed unit disc, where ∥x∥\|\mathbf{x}\| is the length of x\mathbf{x}, its distance from the origin. Take x=(1,0)\mathbf{x} = (1, 0) and y=(0,1)\mathbf{y} = (0, 1). Both have length 1, so both lie in DD.

  1. Take θ=0.5\theta = 0.5. The point is 0.5⋅(1,0)+0.5⋅(0,1)=(0.5,0.5)0.5 \cdot (1, 0) + 0.5 \cdot (0, 1) = (0.5, 0.5).
  2. Its length is 0.52+0.52=0.5≈0.707\sqrt{0.5^2 + 0.5^2} = \sqrt{0.5} \approx 0.707.
  3. Since 0.707≤10.707 \le 1, the midpoint is in DD.

Now take the ring R={x:1≤∥x∥≤2}R = \{\mathbf{x} : 1 \le \|\mathbf{x}\| \le 2\}. Take x=(1,0)\mathbf{x} = (1, 0) and y=(−1,0)\mathbf{y} = (-1, 0). Both lie in RR.

  1. The midpoint is 0.5⋅(1,0)+0.5⋅(−1,0)=(0,0)0.5 \cdot (1, 0) + 0.5 \cdot (-1, 0) = (0, 0).
  2. Its length is 0, which is less than 1, so the midpoint is not in RR.

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.

Example
A feasible region for a small workshop

A workshop makes two products. Let x1x_1 and x2x_2 be the quantities made. The constraints x1≥0x_1 \ge 0, x2≥0x_2 \ge 0 and 2x1+3x2≤122x_1 + 3x_2 \le 12 (machine hours) define a feasible set PP. Each constraint is a linear inequality, so each set is convex, and PP is their intersection, hence convex.

Check this with numbers. Take A=(6,0)A = (6, 0) and B=(0,4)B = (0, 4). Both are feasible, and both sit on the machine-hours edge: 2⋅6+0=122 \cdot 6 + 0 = 12 and 0+3⋅4=120 + 3 \cdot 4 = 12.

  1. Midpoint, θ=0.5\theta = 0.5: 0.5⋅(6,0)+0.5⋅(0,4)=(3,2)0.5 \cdot (6, 0) + 0.5 \cdot (0, 4) = (3, 2).
  2. Check: 2⋅3+3⋅2=12≤122 \cdot 3 + 3 \cdot 2 = 12 \le 12, and both coordinates are non-negative. The midpoint is feasible.
  3. Point at θ=0.25\theta = 0.25 toward AA: 0.25⋅(6,0)+0.75⋅(0,4)=(1.5,3)0.25 \cdot (6, 0) + 0.75 \cdot (0, 4) = (1.5, 3).
  4. Check: 2⋅1.5+3⋅3=3+9=12≤122 \cdot 1.5 + 3 \cdot 3 = 3 + 9 = 12 \le 12. 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.

SituationProblemBetter choice
Feasible region defined only by linear constraintsNone: the region is convexUse a convex solver, such as linear programming
Region with holes, several pieces, or a bulging inward boundaryLocal search can stall in a pocketSplit 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 goneAccept a good local solution, use restarts, or pick a better initialization
Set in high dimensionsImpossible to picture and hard to check by eyeCheck 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 θx+(1−θ)y\theta \mathbf{x} + (1-\theta)\mathbf{y} with 0≤θ≤10 \le \theta \le 1 must be in the set.

QuestionLet x=(1,2)\mathbf{x} = (1, 2), y=(3,0)\mathbf{y} = (3, 0) and θ=0.25\theta = 0.25. Compute θx+(1−θ)y\theta \mathbf{x} + (1-\theta)\mathbf{y}.Show answer

Step 1: 0.25⋅(1,2)=(0.25,0.5)0.25 \cdot (1, 2) = (0.25, 0.5). Step 2: 0.75⋅(3,0)=(2.25,0)0.75 \cdot (3, 0) = (2.25, 0). Step 3: Add: (0.25+2.25,0.5+0)=(2.5,0.5)(0.25 + 2.25, 0.5 + 0) = (2.5, 0.5). The answer is (2.5,0.5)(2.5, 0.5). This point lies one quarter of the way from y\mathbf{y} to x\mathbf{x}, so it is closer to y\mathbf{y} 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.

Sources