Quant Memo
Core

Subgradient Methods

A way to run gradient-descent-style optimization on functions that have sharp corners — like absolute value or hinge loss — where an ordinary derivative doesn't exist, by using any of several valid 'generalized slopes' at the corner.

Prerequisites: Convex Sets and Convex Functions, Gradient Descent

Gradient descent needs a well-defined slope at every point, but many important loss functions have sharp corners where the ordinary derivative simply doesn't exist — the absolute-value penalty x|x| used in L1 regularization has a kink at zero, and the hinge loss used in support vector machines has one at its margin boundary. At that exact corner, "the slope" is ambiguous: approaching from the left gives one value, from the right gives another. Subgradient methods answer the question: what do you do when you can't compute the gradient because there isn't a single one?

An analogy: the crease of a folded card

Picture a V-shaped valley, like a book folded open and turned upside down. Everywhere except the crease at the bottom, the slope is well-defined and a ball rolls downhill normally. Right at the crease, though, the surface has no single tilt: it's tilting one way just to the left and another way just to the right. Any direction "between" those two tilts — including straight down along the crease — is a reasonable stand-in for "the slope" there, even though none of them is uniquely correct. A subgradient is exactly this: any valid stand-in for a slope at a point where the true slope isn't unique.

The method, one symbol at a time

For a convex function ff that may not be differentiable everywhere, a vector gg is a subgradient of ff at point xx if, for every other point yy,

f(y)f(x)+gT(yx).f(y) \geq f(x) + g^T (y - x) .

In plain English: gg defines a straight line (or plane) through (x,f(x))(x, f(x)) that lies entirely below the function everywhere else — it's a valid "supporting" slope even if it isn't the unique tangent slope. The set of all such valid gg at a point is called the subdifferential. Where ff is smooth, this set contains exactly one vector — the ordinary gradient — and everything reduces to normal gradient descent. At a kink, the set contains a whole range of valid slopes, and the subgradient method simply picks any one of them and takes a step:

xk+1=xkαkgk,gkf(xk).x_{k+1} = x_k - \alpha_k \, g_k, \qquad g_k \in \partial f(x_k) .

Unlike ordinary gradient descent, the step size αk\alpha_k must typically shrink over iterations (rather than stay fixed), because a subgradient doesn't guarantee the function actually decreases at every single step — only that, on average over many steps, progress is made toward the minimum.

Worked example 1: minimizing x|x| by hand

Minimize f(x)=xf(x) = |x|, whose subdifferential is {1}\{-1\} for x<0x<0, {+1}\{+1\} for x>0x>0, and the interval [1,1][-1,1] at x=0x=0. Starting at x0=3x_0=3 with shrinking step αk=1/(k+1)\alpha_k = 1/(k+1): at x0=3x_0=3, subgradient g0=1g_0=1, so x1=31(1)=2x_1 = 3-1(1)=2. At x1=2x_1=2: g1=1g_1=1, α1=1/2\alpha_1=1/2, x2=20.5=1.5x_2=2-0.5=1.5. At x2=1.5x_2=1.5: g2=1g_2=1, α2=1/3\alpha_2=1/3, x31.17x_3\approx1.17. The sequence keeps shrinking toward the true minimum at x=0x=0, but — unlike gradient descent on a smooth bowl — it approaches slowly and never lands exactly on 0 in finitely many steps; the shrinking step size is what eventually gets it arbitrarily close.

Worked example 2: an L1-regularized regression step

A quant fitting a sparse factor-selection regression minimizes squared error plus an L1 penalty, f(β)=12(y^y)2+λβf(\beta) = \tfrac12(\hat y - y)^2 + \lambda|\beta|. Suppose at the current coefficient β=0.02\beta = 0.02 with λ=0.1\lambda = 0.1, the squared-error part contributes a gradient of 0.05-0.05, and since β>0\beta > 0 the penalty's subgradient is exactly +λ=0.1+\lambda = 0.1. The combined subgradient is 0.05+0.1=0.05-0.05 + 0.1 = 0.05. With step size α=0.1\alpha = 0.1, the update is βnew=0.020.1(0.05)=0.015\beta_{\text{new}} = 0.02 - 0.1(0.05) = 0.015. Note the coefficient moved toward zero even though the squared-error term alone was pulling it up — this is the L1 penalty's subgradient at work, and it's exactly the mechanism (formalized more efficiently via proximal gradient methods) that drives L1-regularized coefficients to become exactly zero rather than merely small.

Function explorer
-2222.0
x = 1.00f(x) = 2.000

Compare a smooth curve against a V-shaped kink: notice that away from the kink the "slope" behaves normally, but at the kink itself any line between the left- and right-hand slopes stays below the curve — that whole range is valid.

What this means in practice

Subgradient methods (or their more refined descendant, proximal gradient methods) are what make L1-regularized regression (lasso), support-vector-machine training, and any loss function with a hard threshold or absolute-value term optimizable with gradient-based tools at all. Without this generalization, a kink in the loss would simply break standard gradient descent at that exact point.

At points where a convex function isn't smooth, any slope of a line that stays below the whole function is a valid "subgradient" — picking one and stepping downhill, with a shrinking step size, still converges to the minimum even though no single gradient exists there.

Because a subgradient step is not guaranteed to decrease the function value at every single iteration — only on average — using a fixed, non-shrinking step size (as is common and fine for smooth gradient descent) can cause the iterates to bounce around near the minimum forever without settling. The step size must be explicitly shrunk over time (for example αk1/k\alpha_k \propto 1/k) for convergence guarantees to hold, which also makes subgradient methods noticeably slower to converge than smooth gradient descent even on otherwise similar problems.

Related concepts

Practice in interviews

Further reading

  • Boyd, Subgradient Methods (lecture notes)
  • Bertsekas, Convex Optimization Theory, ch. 3
ShareTwitterLinkedIn