Hexa Scholar

Inequality constraints and the KKT conditions

A clay figure on navy and gold tiles strains toward a glowing lamp, pressing against one low wooden fence while a second fence stands untouched behind it.
Pressed against one fence, clear of the other.

The question

Get as close as you can to the point T = (4, 3) without crossing two fences. Which fences end up touching your best point?

Four rounds, four fence positions. Decide first; the page then solves the conditions exactly.

  1. 1 SeeCall each fence active or inactive.
  2. 2 TryMove one fence and watch μ.
  3. 3 ProveBuild the sufficiency proof line by line.
  4. 4 ApplyProblems to check yourself.
Before you start · 3 quick checks on a gradient, a half-plane and a Lagrange multiplier, about 3 min

Two ideas before you start

2 ideas

An inequality keeps one side

Figure: the parabola h(x) = (x − 2)², the allowed part x ≤ b shaded, a dashed line at the fence x = b and a tick at the lowest allowed point x*. It needs JavaScript.

Fence at b =

x* = 0.5 g(x*) = 0.5 − 0.5 = 0 active

The constraint x ≤ b keeps everything on one side of the fence. If the bottom of the curve is allowed, the fence plays no part. If not, the best allowed point sits on the fence: the constraint is active.

Exact definition

The problem. Minimize \(f(x)\) over the points \(x \in \mathbb{R}^n\) with \(g_1(x) \le 0, \dots, g_m(x) \le 0\). Each \(g_i\) is a constraint function, and the points that meet every constraint form the feasible set. A constraint written another way is first put in this form: \(x \le b\) becomes \(g(x) = x - b \le 0\), and \(x \ge a\) becomes \(g(x) = a - x \le 0\).

At a feasible point \(x^*\), constraint \(i\) is active when \(g_i(x^*) = 0\), so the point sits on its edge, and inactive when \(g_i(x^*) \lt 0\).

The card uses \(h(x) = (x - 2)^2\) with the one constraint \(g(x) = x - b \le 0\).

At the best point, downhill points out

Figure: the region y ≤ 1 shaded, its edge y = 1, a cross at T = (2, 2), a dashed segment from the chosen point P on the edge to T, and a solid segment for its part along the edge. It needs JavaScript.

Point P =

−∇f(P) = (3, 2) along the fence: 3 straight out: 2

Not the best point: −∇f(P) has the part 3 along the fence, so sliding right along the fence lowers f.

Minimize f(x, y) = (x − 2)² + (y − 2)² with y ≤ 1. The downhill direction is −∇f. Where it has a part along the fence, you can slide downhill. At the best point it points straight out of the region.

Exact definition

The KKT conditions. Let \(f, g_1, \dots, g_m\) be differentiable. A point \(x^*\) and numbers \(\mu_1, \dots, \mu_m\) satisfy the Karush–Kuhn–Tucker (KKT) conditions when

\[\begin{aligned} &\nabla f(x^*) \\ &\quad + \sum_i \mu_i \nabla g_i(x^*) = 0, \\ &g_i(x^*) \le 0, \quad \mu_i \ge 0, \\ &\mu_i\, g_i(x^*) = 0 \end{aligned}\]

for each \(i = 1, \dots, m\). The parts are called stationarity, primal feasibility, dual feasibility and complementary slackness. The numbers \(\mu_i\) are the KKT multipliers. Complementary slackness says that a constraint with \(g_i(x^*) \lt 0\) has \(\mu_i = 0\), so it drops out of stationarity.

Stationarity says \(-\nabla f(x^*) = \sum_i \mu_i \nabla g_i(x^*)\). The gradient \(\nabla g_i\) points toward larger \(g_i\), out of the feasible set at an active constraint, and the weights \(\mu_i\) are at least 0. The card uses \(g(x, y) = y - 1\), so \(\nabla g = (0, 1)\), and \(-\nabla f(P) = 2(T - P)\) with \(T = (2, 2)\). The dashed segment is \(-\nabla f(P)\) drawn at half length, so it ends at \(T\); the solid segment, drawn just above the fence, is its part along the fence, also at half length.

Fine print: other ways to write the problem

Maximizing \(f\) is the same as minimizing \(-f\). A constraint \(g(x) \ge 0\) is written \(-g(x) \le 0\). Some books write constraints as \(g_i(x) \ge 0\) or put a minus sign in front of the multipliers; the conditions then look different but say the same thing. This page always minimizes, writes every constraint as \(g_i(x) \le 0\), and uses \(\mu_i \ge 0\).

The left side of stationarity is the gradient in \(x\) of the Lagrangian \(L(x, \mu) = f(x) + \sum_i \mu_i g_i(x)\). An equality constraint \(h(x) = 0\) is the pair \(h(x) \le 0\) and \(-h(x) \le 0\); stage 3 shows how this gives the condition of the lesson on Lagrange multipliers.

1 See

Which fences hold the best point back?

How the page decides

Fence 1 is \(g_1(x, y) = x + y - c \le 0\) and fence 2 is \(g_2(x, y) = x - d \le 0\); each round has its own \(c\) and \(d\). A fence you call active gives the equation \(g_i(x, y) = 0\). A fence you call inactive gives \(\mu_i = 0\), by complementary slackness. Together with stationarity, \[\begin{aligned} &2(x - 4) + \mu_1 + \mu_2 = 0, \\ &2(y - 3) + \mu_1 = 0, \end{aligned}\] that is a small linear system, and the page solves it with exact fractions. Your choice is right when its solution also meets primal feasibility, \(g_1, g_2 \le 0\), and dual feasibility, \(\mu_1, \mu_2 \ge 0\).

The function \(f\) is convex and both fences are straight lines, so a point that meets all four conditions is the best point; stage 3 proves this. In every round exactly one of the four choices passes. You get one check per round, then the page shows the best point. There are four rounds; a table then compares your choices with the right ones. Start over clears everything.

Fence 1: x + y ≤ c
Fence 2: x ≤ d
2 Try

One fence on a line

Minimize \(f(x) = (x - 3)^2\) subject to \(x \le b\), that is \(g(x) = x - b \le 0\). Write \(p^*(b)\) for the lowest value. Two quick questions first. The explorer below them opens once both are answered.

The explorer and its goals open after you answer both questions.

3 Prove

Why the KKT conditions are enough for a convex problem

Theorem

Assumptions. \(n \ge 1\) and \(m \ge 1\). The functions \(f, g_1, \dots, g_m : \mathbb{R}^n \to \mathbb{R}\) are convex and differentiable. The point \(x^* \in \mathbb{R}^n\) and the numbers \(\mu_1, \dots, \mu_m\) satisfy the KKT conditions: \(g_i(x^*) \le 0\), \(\mu_i \ge 0\) and \(\mu_i g_i(x^*) = 0\) for each \(i\), and

\[\begin{aligned} &\nabla f(x^*) \\ &\quad + \sum_i \mu_i \nabla g_i(x^*) = 0. \end{aligned}\]

Conclusion. \(f(x) \ge f(x^*)\) for every feasible \(x\), that is, every \(x\) with \(g_i(x) \le 0\) for all \(i\). So \(x^*\) is a global minimizer.

Setup. Fix a feasible \(x\) and put \(v = x - x^*\). Each sum runs over \(i = 1, \dots, m\), one term per constraint.

Facts the proof uses.

  • a convex differentiable function \(h\) on \(\mathbb{R}^n\) lies on or above its tangent planes: \(h(y) \ge h(z) + \nabla h(z)\cdot(y - z)\) for all \(y, z\), as shown in the lesson on convex optimization;
  • multiplying an inequality by a number that is at least 0 keeps its direction, and multiplying by \(-1\) turns it around;
  • ordinary algebra of numbers and of finite sums.

Each option is one step about the \(f\), \(g_i\), \(\mu_i\), \(x^*\), \(x\) and \(v\) of the theorem. Pick the one that is true for every choice of functions, KKT point, multipliers and feasible \(x\) the theorem covers.

4 Apply

Problems

Each problem has hints and a full solution. Exact answers can be typed as a decimal or a fraction.

Key point Write every constraint as \(g_i \le 0\). Guess which constraints are active, set those \(g_i = 0\) and the other \(\mu_i = 0\), and solve stationarity. Keep the guess only if every \(g_i \le 0\) and every \(\mu_i \ge 0\); otherwise the broken condition points to a constraint to reconsider. For a convex problem a point that passes is a lowest point. In stage 2 and in P4 the multiplier was also the rate at which the lowest value falls as the constraint is loosened.
Level Advanced undergraduate Prerequisites Lagrange multipliers; convex optimization; gradients (checked in Before you start) Time ~40 min

Related lessons: Lagrange multipliers handles equality constraints, where the multiplier can have either sign. Convex optimization shows why a local minimum of a convex problem is global. Critical points classifies a zero of the gradient when there are no constraints.

Further reading