Inequality constraints and the KKT conditions
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 SeeCall each fence active or inactive.
- 2 TryMove one fence and watch μ.
- 3 ProveBuild the sufficiency proof line by line.
- 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 ideasAn 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.
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.
−∇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.
Which fences hold the best point back?
- Minimize f(x, y) = (x − 4)² + (y − 3)², the squared distance to T = (4, 3), over the shaded region behind both fences.
- For each fence, choose Active or Inactive, then press Check my choice. The page solves the KKT conditions for your choice and says which condition breaks, if any.
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.
| Round | Your choice | Right choice | Match |
|---|
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.
Explorer: move the fence
Move \(b\) with the slider. The upper figure shows \(f\) and the fence; the lower one shows the lowest value \(p^*(b)\) as the fence moves, with a dashed line of slope \(-\mu\) through the current point.
Goals
Why the KKT conditions are enough for a convex problem
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.
- Necessary too, under a constraint qualification. Let \(x^*\) be a local minimizer, and let \(f\) and every \(g_i\) have continuous first derivatives. If every \(g_i\) is affine, or if every \(g_i\) is convex and some point has \(g_i \lt 0\) for all \(i\) (Slater's condition), then multipliers that meet the four conditions exist. The proof needs a separation argument like the one in the lesson on separating hyperplanes and is not given here.
- Without such a condition they can fail.
- Without convexity a KKT point is only a candidate. As with a zero of the gradient in the lesson on critical points, the candidates still have to be compared.
- Equality constraints. \(h(x) = 0\) is the pair \(h(x) \le 0\) and \(-h(x) \le 0\), both always active. Their multipliers \(\mu^+, \mu^- \ge 0\) enter stationarity as \((\mu^+ - \mu^-)\nabla h(x^*)\), so \(\nabla f(x^*) = \lambda\nabla h(x^*)\) with \(\lambda = \mu^- - \mu^+\), a number of either sign: the condition of the lesson on Lagrange multipliers.
Problems
Each problem has hints and a full solution. Exact answers can be typed as a decimal or a fraction.
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
- S. Boyd and L. Vandenberghe, Convex Optimization, section 5.5.3, “KKT optimality conditions.”
- J. Nocedal and S. J. Wright, Numerical Optimization, chapter 12, “Theory of constrained optimization.”