This post is a sequel to Formulating the Support Vector Machine Optimization Problem.

## The Karush-Kuhn-Tucker theorem

Generic optimization problems are hard to solve efficiently. However, optimization problems whose objective and constraints have special structure often succumb to analytic simplifications. For example, if you want to optimize a linear function subject to linear equality constraints, one can compute the Lagrangian of the system and find the zeros of its gradient. More generally, optimizing a linear function subject to linear equality and inequality constraints can be solved using various so-called “linear programming” techniques, such as the simplex algorithm.

However, when the objective is not linear, as is the case with SVM, things get harder. Likewise, if the constraints don’t form a convex set you’re (usually) out of luck from the standpoint of analysis. You have to revert to numerical techniques and cross your fingers. Note that the set of points satisfying a collection of linear inequalities forms a convex set, provided they can all be satisfied.

We are in luck. The SVM problem can be expressed as a so-called “convex quadratic” optimization problem, meaning the objective is a quadratic function and the constraints form a convex set (are linear inequalities and equalities). There is a neat theorem that addresses such, and it’s the “convex quadratic” generalization of the Lagrangian method. The result is due to Karush, Kuhn, and Tucker, (dubbed the KKT theorem) but we will state a more specific case that is directly applicable to SVM.

**Theorem [Karush 1939, Kuhn-Tucker 1951]:** Suppose you have an optimization problem in of the following form:

Where is a differentiable function of the input variables and are affine (degree-1 polynomials). Suppose is a local minimum of . Then there exist constants (called KKT or Lagrange multipliers) such that the following are true. Note the parenthetical labels contain many intentionally undefined terms.

- (gradient of Lagrangian is zero)
- for all (primal constraints are satisfied)
- for all (dual constraints are satisfied)
- for all (complementary slackness conditions)

We’ll discuss momentarily how to interpret these conditions, but first a few asides. A large chunk of the work in SVMs is converting the original, geometric problem statement, that of maximizing the margin of a linear separator, into a form suitable for this theorem. We did that last time. However, the conditions of this theorem also provide the structure for a more analytic algorithm, the Sequential Minimal Optimization algorithm, which allows us to avoid numerical methods. We’ll see how this works explicitly next time when we implement SMO.

You may recall that for the basic Lagrangian, each constraint in the optimization problem corresponds to one Lagrangian multiplier, and hence one term of the Lagrangian. Here it’s largely the same—each constraint in the SVM problem (and hence each training point) corresponds to a KKT multiplier—but in addition each KKT multiplier corresponds to a *constraint *for a new optimization problem that this theorem implicitly defines (called the dual problem). So the pseudocode of the Sequential Minimal Optimization algorithm is to start with some arbitrary separating hyperplane , and find any training point that corresponds to a violated constraint. Fix so it works for , and repeat until you can’t find any more violated constraints.

Now to interpret those four conditions. The difficulty in this part of the discussion is in the notion of primal/dual problems. The “original” optimization problem is often called the “primal” problem. While a “primal problem” can be either a minimization or a maximization (and there is a corresponding KKT theorem for each) we’ll use the one of the form:

Next we define a corresponding “dual” optimization problem, which is a *maximization* problem whose objective and constraints are related to the primal in a standard, but tedious-to-write-down way. In general, this dual maximization problem has the guarantee that its optimal solution (a max) is a lower bound on the optimal solution for the primal (a min). This can be useful in many settings. In the most pleasant settings, including SVM, you get an even stronger guarantee, that the optimal solutions for the primal and dual problems have *equal objective value*. That is, the bound that the dual objective provides on the primal optimum is tight. In that case, the primal and dual are two equivalent perspectives on the same problem. Solving the dual provides a solution to the primal, and vice versa.

The KKT theorem implicitly defines a dual problem, which can only possibly be clear from the statement of the theorem if you’re intimately familiar with duals and Lagrangians already. This dual problem has variables , one entry for each constraint of the primal. For KKT, the dual constraints are simply non-negativity of the variables

And the objective for the dual is this nasty beast

where is the generalized Lagrangian (which is simpler in this writeup because the primal has no equality constraints), defined as:

While a proper discussion of primality and duality could fill a book, we’ll have to leave it at that. If you want to journey deeper into this rabbit hole, these notes give a great introduction from the perspective of the classical Lagrangian, without any scarring.

But we can begin to see why the KKT conditions are the way they are. The first requires the generalized Lagrangian has gradient zero. Just like with classical Lagrangians, this means the primal objective is at a local minimum. The second requires the constraints of the primal problem to be satisfied. The third does the same for the dual constraints. The fourth is the interesting one, because it says that at an optimal solution, the primal and dual constraints are intertwined.

4. for all (complementary slackness conditions)

More specifically, these “complementary slackness” conditions require that for each , either the dual constraint is actually *tight* (), or else the primal constraint is tight. At least one of the two must be exactly at the limit (equal to zero, not strictly less than). The “product equals zero means one factor is zero” trick comes in handy here to express an OR, despite haunting generations of elementary algebra students. In terms of the SVM problem, complementary slackness translates to the fact that, for the optimal separating hyperplane , if a data point doesn’t have functional margin exactly 1, then that data point isn’t a support vector. Indeed, when we’ll see in the next section how that affects the corresponding training point .

## The nitty gritty for SVM

Now that we’ve recast the SVM into a form suitable for the KKT theorem, let’s compute the dual and understand how these dual constraints are related to the optimal solution of the primal SVM problem.

The primal problem statement is

Subject to the constraints that all training points with training labels satisfy

Which we can rewrite as

The generalized Lagrangian is

We can compute for each variable. First, the individual components of .

Note that is the -th component of the -th training point , since this is the only part of the expression that involves .

Setting all these equal to zero means we require . This is interesting! The optimality criterion, that the gradient of the Lagrangian must be zero, actually shows us how to write the optimal solution in terms of the Lagrange multipliers and the training data/labels. It also hints at the fact that, because of this complementary slackness condition, many of the will turn out to be zero, and hence the optimal solution can be written as a *sparse *sum of the training examples.

For the remaining entries of the Lagrangian where the variable is a KKT multiplier, it coincides with the requirement that the constraints of the primal are satisfied:

Next, the KKT theorem says that one needs to have both feasibility of the dual:

And finally the complementary slackness conditions,

To be completely clear, the dual problem for the SVM is just the generalized Lagrangian:

subject to the non-negativity constraints:

All of the equality constraints above (Lagrangian being zero, complementary slackness) are consequences of the KKT theorem.

At this point, we’re ready to derive and implement the Sequential Minimal Optimization Algorithm and run it on some data. We’ll do that next time.