Affine and convex sets

Mixing recipes in proportions that add up to 100% — and why forbidding negative amounts changes everything.

What you'll learn
  • Tell an affine combination from a convex one
  • Picture the affine hull and convex hull of a set of points
  • Test whether a set is convex

The scripts introduce sets through cooking. Take two curry recipes, described by their proportions of chili and coconut:

recipe_A = np.array([0.8, 0.2])   # spicy: 80% chili, 20% coconut
recipe_B = np.array([0.2, 0.8])   # mild:  20% chili, 80% coconut

A new recipe that blends them in proportions \(\theta_1, \theta_2\) is

\[\theta_1 \mathbf{a} + \theta_2 \mathbf{b}, \qquad \theta_1 + \theta_2 = 1\]

Affine combinations

If the weights only have to add up to one, the blend is an affine combination. The weights may be negative — “use 130% of the spicy recipe and −30% of the mild one” — which makes perfect sense on paper and none in a kitchen. The set of all affine combinations of some points is their affine hull: for two points, the whole infinite line through them.

coef = np.random.uniform(-1, 2, 3)   # allow negative and > 1
coef = coef / coef.sum()             # but make them sum to 1

A set is affine if it contains the whole line through any two of its points. Lines, planes, and the solution set of \(A\mathbf{x} = \mathbf{b}\) are all affine.

Convex combinations

Now also require every weight to be non-negative:

\[\theta_i \ge 0, \qquad \sum_i \theta_i = 1\]

That is a convex combination — a genuine recipe. The set of all of them is the convex hull: for two points, just the segment between them; for three, the filled triangle.

The blended point is green while every weight is non-negative (a convex combination) and orange once a weight goes negative (affine only). With two recipes the convex set is the segment and the affine set the whole dashed line; with three points it is the triangle versus the entire plane.

Notice something about the curry recipes: chili and coconut always sum to 1, so every recipe — including the impossible ones — lies on the single line \(\text{chili} + \text{coconut} = 1\). The constraint “proportions add to 100%” is itself an affine set.

Convex sets

A set is convex if it contains the segment between any two of its points. Equivalently, it contains every convex combination of its points. Discs, boxes, half-spaces and polygons without dents are convex; a crescent, a ring, or a region with holes is not.

Every affine set is convex (a whole line certainly contains the segment), but not the other way round. Convex sets matter because the intersection of convex sets is convex — so stacking up convex constraints never breaks convexity.

Try it yourself. In convex_set.py, add a fourth smoothie recipe that lies inside the triangle of the first three and regenerate the cloud. Does the convex hull change? Now add one outside. Then prove that the intersection of two convex sets is convex, using nothing but the definition.

View source on GitHub →