Convexity & Duality
Why convex problems are tractable, and the power of the dual.
Least squares, logistic regression, the lasso and the support vector machine look like four different problems, but they share the property that makes them tame: they are convex. On a convex problem every local minimum is a global one, a zero gradient proves optimality, and every constraint comes with a price that a second, dual problem computes. This lesson builds that toolkit, from the definition of a convex set to the dual of the support vector machine.
What you’ll learn
- Define convex sets and functions, and test convexity with the first- and second-order conditions and with the operations that preserve it.
- Prove that every local minimum of a convex function is global, and explain what strict and strong convexity add.
- Classify the standard machine learning objectives by convexity, smoothness and strong convexity, and handle nonsmooth ones with subgradients.
- Form the Lagrangian and the dual of a constrained problem, prove weak duality, and read the KKT conditions on a worked example and on the support vector machine.
Convex sets and convex functions
Training a model means choosing parameters that minimize an objective , usually an empirical risk plus a penalty. Whether that is easy or hard depends less on the dimension than on the shape of .
A set is a convex set if it contains the segment between any two of its points: whenever and . Balls, half-spaces , polyhedra and the cone of positive semidefinite matrices are convex; a ring-shaped region, or the set of vectors with at most nonzero entries, is not. Intersections of convex sets are convex, so a problem with many convex constraints still has a convex feasible set.
| Building block or rule | Why it is convex |
|---|---|
| Affine | equality holds in the definition; affine functions are exactly those that are both convex and concave |
| Any norm | triangle inequality plus homogeneity: |
| with | its Hessian is positive semidefinite |
| Log-sum-exp | Hessian with : the covariance matrix of a random one-hot vector drawn with probabilities |
| on ; | second derivatives and are nonnegative |
| Nonnegative sums; ; ; | each preserves convexity (the last needs jointly convex in ) |
Which of these objectives is not convex in ? (The first three are for a single example .)
- The logistic loss , with
- The hinge loss , with
- The squared error of a sigmoid output, , with
- The lasso objective
Show the answer
C. The squared error of a sigmoid output, , with
Take and write . Then has , which is negative whenever : the function is concave there and flattens out as . That is one reason logistic regression is fitted with the log loss rather than with squared error. The other three are convex by the rules above: a convex function of an affine map, a maximum of affine functions, and a convex quadratic plus a norm.
Local minima are global
For differentiable functions, convexity has a geometric form that underlies everything that follows:
Every tangent plane is a global under-estimator: the first-order Taylor expansion never lies above the function. For twice-differentiable on an open convex domain, convexity is equivalent to a positive semidefinite Hessian, everywhere, and -strong convexity to , or equivalently to a quadratic lower bound
Suppose is a local minimum but some has . Move a fraction of the way toward ; convexity bounds the value there:
Letting produces points arbitrarily close to with smaller values, contradicting local minimality, so no such exists. If , the first-order condition gives global optimality directly:
For strictly convex , the midpoint of two distinct minimizers would have a strictly smaller value, which is impossible. Strong convexity gives quantitative versions: minimizing the quadratic lower bound over , and pairing it with the same bound at , turns a small gradient into a certificate of near-optimality.
The first inequality is the Polyak–Łojasiewicz inequality, which Convergence Rates of Gradient Descent turns into a linear rate. Without convexity none of this holds: a zero gradient can sit at a saddle point or at a poor local minimum.
The convex objectives of machine learning
Regularized empirical risk minimization has the form
If the loss is convex in its first argument and the penalty is convex, is convex in : each term is a convex function of an affine map, and nonnegative sums preserve convexity. That one observation covers most of classical machine learning. What differs from model to model is whether is also smooth (its gradient is -Lipschitz, ) and strongly convex, and those two constants set how fast gradient methods converge (Gradient Descent).
| Objective | Convex | Smooth | Strongly convex |
|---|---|---|---|
| Least squares | yes | only if has full column rank: | |
| Ridge: add | yes | always, with | |
| Logistic, : | yes | not in general; on separable data there is no minimizer | |
| Hinge | yes | no: kinks at margin | no; adding (the SVM) gives |
| Lasso | yes | no: kinks where | only if has full column rank, so never when |
| Neural network losses | no | at best locally | no |
Write with and . Its derivatives involve the sigmoid :
By the chain rule, and because , each example adds a rank-one curvature term weighted by how uncertain the model is about it:
The weights lie in , so the Hessian is sandwiched as below: convex, with . But the weights vanish for confidently classified points (), so there is no uniform . On linearly separable data keeps decreasing along a separating direction and has no minimizer at all.
Subgradients: optimality without derivatives
The hinge loss and the norm have kinks where no gradient exists. Convexity supplies a replacement. A vector is a subgradient of a convex at if the linear function it defines is a global under-estimator,
and the subdifferential is the set of all of them. Where is differentiable, . At a kink it is a whole set: for but at , and the hinge has .
Minimize over , with . Fermat's rule asks for :
Try each piece. If , then , so , which is consistent only when . Symmetrically, when . And works exactly when :
Compactly, this is soft thresholding. A whole interval of inputs maps to exactly zero because the subdifferential at the kink is a whole interval. This is the mechanism behind the lasso's sparsity, and is the proximal operator of , the building block of Proximal & Projected Methods.
With , what does soft thresholding return for ?
Show the answer
1.7
, so : shrunk toward zero by exactly . Any , such as , returns exactly . A ridge penalty would instead return , a proportional shrink that is never exactly zero unless is.
To minimize a nonsmooth convex function directly, the subgradient method steps along any negative subgradient, . It is not a descent method: for at , the vector is a valid subgradient, and a step of size along it raises to . What it does guarantee is progress in distance to the minimizer, and with constant steps the averaged iterate satisfies , where and bounds the subgradients. That is far slower than gradient descent on smooth problems, and Lower Bounds & Oracle Complexity proves that no first-order method can do better on the class of all Lipschitz convex functions.
Constraints, multipliers and the dual
Many learning problems carry constraints: a budget on the weights, nonnegativity, a margin requirement. The standard form is
with optimal value . It is a convex problem when are convex and every is affine. The Lagrangian folds the constraints into the objective with multipliers and (in this step denotes multipliers, not a penalty strength), and minimizing it over gives the dual function :
Take any feasible and any . Each and each , so the Lagrangian undercuts the objective there:
Minimizing the right side over feasible points shows that every dual value bounds the optimum from below. The best bound is the dual problem, . Since is an infimum of functions affine in , it is concave: the dual is a convex problem even when the primal is not. This is the duality theory in miniature.
Maximize the dual function over . At which is the best lower bound reached?
Show the answer
2
at , where : no duality gap. The pair satisfies the KKT conditions below, stationarity and complementary slackness . And is a price: requiring raises the optimal value at rate for small .
Complementary slackness says that a constraint that is not tight carries zero price. For the support vector machine that is the whole story. With labels , the hard-margin SVM solves
and its dual is
Complementary slackness forces for every point strictly outside the margin, so is built only from points on the margin, the support vectors. The data enter the dual only through inner products , which is what lets the kernel trick replace them (The SVM Dual & Support Vectors).
What convexity buys, and the road ahead
Convexity is what makes optimization guarantees global: they bound the distance to the best possible value, not merely to some stationary point. The table collects the standard guarantees, each proved later in this topic.
| Problem class | Method | Guarantee |
|---|---|---|
| Convex, -smooth | Gradient descent, | |
| Convex, -smooth | Nesterov's accelerated method | , optimal |
| -strongly convex, -smooth | Gradient descent | : a linear rate |
| Convex, -Lipschitz, nonsmooth | Subgradient method | , optimal |
| Smooth plus a simple nonsmooth term (the lasso) | Proximal gradient; FISTA | ; |
| Linear, quadratic and semidefinite programs | Interior-point methods | Newton steps for linear inequalities |
Key takeaways
- Convex functions lie below their chords and above their tangent planes. Norms, convex quadratics, log-sum-exp and affine functions, combined by sums, maxima and affine substitutions, generate almost every convex objective in machine learning.
- For convex , every local minimum is global and (or ) certifies optimality; strong convexity adds uniqueness and .
- Least squares, ridge, logistic regression, the hinge loss and the lasso are convex. They differ in smoothness and strong convexity, which set the speed of first-order methods. Network losses are not convex.
- Subgradients extend optimality to kinks (), and soft thresholding shows how the kink produces exact zeros.
- The Lagrange dual always bounds the primal from below. For convex problems satisfying Slater's condition the bounds meet, and the KKT conditions, through complementary slackness, explain why only the support vectors shape an SVM.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
is convex and differentiable on . Which statement is always true?
- has at least one minimizer
- If , then is a global minimizer
- has exactly one minimizer
- Every stationary point is a strict local minimum
Show the answer
B. If , then is a global minimizer
The first-order condition becomes when the gradient vanishes. Existence and uniqueness need more: is convex with no minimizer, and a constant function has infinitely many.
For ridge regression, , what are the strong convexity constant and the smoothness constant ?
- and
- and
- and
- , since least squares is only convex
Show the answer
C. and
The Hessian is constant, , and its extreme eigenvalues are and . Even when is singular (), : the penalty makes the problem strongly convex, with condition number .
For one example with , what is the subdifferential of with respect to at a point where the margin equals exactly ?
- It is empty, because the loss is not differentiable there
Show the answer
D.
The hinge has : the slopes of all lines through the kink that stay below the graph. Through the affine map this becomes the segment between the two one-sided gradients, (margin above 1) and (margin below 1).
You compute the Lagrange dual of a nonconvex problem. What does its optimal value tell you about ?
- Nothing: duality only applies to convex problems
- It is a lower bound on , possibly strictly below it
- It equals , as duality theory guarantees
- It is an upper bound on
Show the answer
B. It is a lower bound on , possibly strictly below it
Weak duality, for every feasible and , used no convexity at all. The dual is always a concave maximization, so it can be tractable even when the primal is hard; semidefinite relaxations of combinatorial problems work this way. Equality generally needs convexity plus a condition such as Slater's.
In a trained hard-margin SVM, a training point lies strictly outside the margin: . What is its dual variable, and what happens if you delete the point and retrain?
- , and the solution does not change
- , and the boundary moves toward the remaining points
- , but the boundary moves because changed
- is undefined for points outside the margin
Show the answer
A. , and the solution does not change
Its constraint is slack, so complementary slackness, , forces . The solution does not involve the point, and the old solution, still feasible and still satisfying the KKT conditions, stays optimal after it is removed.
Go deeper
- Lagrange Duality & KKT Conditions · Dual problems, strong duality and complementary slackness.
- Proximal & Projected Methods · Optimizing nonsmooth objectives: ISTA, FISTA and projections.
- Lower Bounds & Oracle Complexity · What no first-order method can beat, and why.
Further reading
- S. Boyd & L. Vandenberghe, Convex Optimization (Cambridge University Press, 2004), chapters 2–5.
- R. T. Rockafellar, Convex Analysis (Princeton University Press, 1970).
- C. Cortes & V. Vapnik, "Support-vector networks," Machine Learning 20(3), 273–297 (1995).