The big picture

Why one kind of landscape is easy to search and every other kind is a gamble.

What you'll learn
  • Say precisely what makes a function convex
  • See why a local minimum of a convex function is the global one
  • Recognise the local-minimum trap on a non-convex landscape

An optimization problem asks for the lowest point of a function, possibly restricted to some allowed region:

\[\min_{x} \; f(x) \quad \text{subject to} \quad x \in \mathcal{C}\]

Imagine searching for that lowest point blindfolded, by feeling the slope under your feet and stepping downhill. On some landscapes that always works. On others you walk confidently into a dip that is not the deepest one, and nothing under your feet tells you so.

Convex functions

A function is convex if the straight line between any two points on its graph never dips below the graph:

\[f\big(\theta x + (1-\theta) y\big) \;\le\; \theta f(x) + (1-\theta) f(y) \qquad \text{for all } \theta \in [0, 1]\]

That one inequality rules out every hidden dip. If there were a second, deeper valley, the chord from the first valley to it would pass under the hill between them — which convexity forbids. So for a convex function:

every local minimum is a global minimum.

That is the entire reason convex optimization is a field of its own.

Eight marbles start at the edges and follow the gradient downhill. On the convex bowl they all meet at the same lowest point. Switch to the non-convex landscape — the repo's own surface — and they stop in different dips, most of them not the deepest.

The scripts use exactly these two surfaces:

# Convex: a bowl
Z_convex = 0.5 * (X**2 + Y**2) + 1

# Non-convex: hills and valleys on top of a gentle bowl
Z_nonconvex = (np.sin(X*2) * np.cos(Y*2) * 2 +
               0.3 * (X**2 + Y**2) +
               np.sin(X*Y) * 1.5 + 4)

Constraints matter too

The region you search can be convex or not, independently of the function. A disc is convex: the straight line between any two points inside it stays inside. A region with holes is not: the straight path between two allowed points can cross a forbidden one.

Two contour plots. Left: a convex bowl inside a circular feasible boundary, with a single global minimum at the centre. Right: a non-convex landscape with many local minima, inside a wavy feasible boundary with five elliptical infeasible holes.
From 1_big_picturein_2d.py. Left: a convex objective over a convex disc — one answer. Right: a non-convex objective, a wavy boundary and forbidden holes — many candidate answers and no way to certify which is best.

A problem is a convex optimization problem when both are convex: a convex objective, minimised over a convex feasible set. That is the shape the rest of this course is about, and the shape the MPC controller will turn out to have.

What you lose without convexity

Non-convex problems are not unsolvable, but every method for them trades something away: random restarts, which can miss the best answer; exhaustive search, which explodes with dimension; or a local answer with no certificate that it is global. Convexity buys you the certificate for free.

Try it yourself. On the non-convex landscape, change the step size and watch which marbles change valleys — the destination depends on how you walk, not just where you start. Then open 0_big_picture.py: its curve \(0.5(x - 0.5)^2 + 1.5e^{-2x^2}\) has a hump near the origin with a minimum on each side, at \(x \approx -0.81\) (\(f \approx 1.26\)) and \(x \approx 1.10\) (\(f \approx 0.31\)). Run gradient descent from \(x = -2\) and from \(x = 2\): which start finds the global minimum?

View source on GitHub →