TL;DR
Coordinate descent minimises a function of several variables by picking one variable at a time, minimising over that variable while every other variable stays fixed, and cycling through the variables. Each single-variable problem is usually much easier than the full one, so a cheap step on each coordinate can add up to a good solution.
Where you'll see it: fitting lasso and elastic-net regressions, the least-squares solvers inside many statistics packages, and training of sparse linear models with millions of features.
Intuition
Picture a hilly field described by two numbers, east-west and north-south. Gradient descent takes a step in the steepest direction, which may be diagonal and needs you to know the slope in both directions at once. Coordinate descent takes a different approach. It first walks due east until it reaches the lowest point on that line, then walks due north to the lowest point on that line, then east again, and so on. Each walk is a one-dimensional problem, which is easy to solve, and the walks zig-zag toward the bottom of the valley.
The method exists because many problems have a structure where moving along one coordinate is cheap and exact, even when the full problem is tangled. In regression with many features, changing one coefficient while the others are fixed reduces to a simple formula. A gradient step over all coefficients at once has to touch every feature on every step, which is expensive when there are many features and most of them are zero.
flowchart LR
A["start at x"] --> B["minimise over x_1, others fixed"]
B --> C["minimise over x_2, others fixed"]
C --> D["... over x_n"]
D --> E{"any coordinate still moving?"}
E -- yes --> B
E -- no --> F["stop: approximate minimiser"]
The zig-zag is also the method's weakness. When two variables are strongly correlated, the valley is narrow and diagonal, and axis-aligned steps make slow progress. A diagonal step would be much better, which is why coordinate descent works best when the variables are only weakly coupled.
The math
Let be the function to minimise and write . Coordinate descent updates one coordinate at a time:
The other coordinates are held at their latest values. A full pass that updates in order is one cycle. The cyclic version visits coordinates in a fixed order, and the random version picks one at random each step.
When is smooth and strictly convex, the single-coordinate problem has a closed-form solution in many cases. For a quadratic
the derivative with respect to is . Setting it to zero with the other coordinates fixed gives
This is the Gauss–Seidel method for solving , which is why the two are often taught together.
Convergence
For a smooth, strictly convex , cyclic coordinate descent converges to the unique minimiser. Its rate depends on the coupling between coordinates, which is the off-diagonal part of in the quadratic case. Weak coupling means fast convergence, and strong coupling means the zig-zag described above.
For a non-smooth , coordinate descent can stall. Take . At , moving along alone gives , which has its minimum at , and the same holds for . So no single-coordinate move improves on , where , yet . The kink couples the two coordinates, and the method stalls. Non-smoothness is safe when it is separable. If
with smooth and convex and each convex (possibly non-smooth, for example , see Subgradient), then coordinate descent still converges. The lasso penalty is exactly this kind of term, which is why the method suits sparse regression.
The lasso update
Take the lasso objective with each feature column standardised so that . Let be the correlation of feature with the partial residual (the residual with feature 's own contribution left out). The one-dimensional problem in then has the closed-form solution
This is the Soft Thresholding operator. It shrinks toward zero by and sets it exactly to zero when is below . Exact zeros are what make the lasso select variables, and coordinate descent is the usual way to compute it.
Worked examples
Minimise by cyclic coordinate descent, starting at .
- The derivative with respect to is . Setting it to zero with fixed gives .
- The derivative with respect to is . Setting it to zero with fixed gives .
- Cycle 1: . Then .
- Cycle 2: . Then .
- Cycle 3: . Then .
The exact minimiser solves and , which gives . The iterates approach that value, and the gap shrinks by a factor of about each cycle. Here the coupling is on each side of the diagonal, and the factor is the product of the two coupling terms. The interpretation: each cycle removes most of the remaining error, so three cycles already get within about 0.02 of the answer.
Use the standardised lasso setting above. Fix the other coefficients, and suppose . The penalty is .
- Compute .
- Since , take the positive part, which is .
- Multiply by the sign of , which is . So .
Now take with the same penalty.
- Compute .
- The positive part of is , so .
The coefficient is zeroed out entirely. Coordinate descent on the lasso does exactly this, one coordinate at a time, and repeats until the coefficients stop changing.
Tradeoffs and failure modes
Coordinate descent is a good choice when each one-dimensional update is cheap or closed-form, when the problem is sparse so most updates change nothing, and when the penalty is separable. It is a poor choice when variables are strongly coupled, since convergence can be slow, and when the non-smooth part couples several coordinates, since the method can stall at a non-minimiser.
| Situation | Problem | Better choice |
|---|---|---|
| Many features, sparse solution | Each update is cheap, and most coefficients stay zero | Coordinate descent or its variants |
| Strongly correlated features | The zig-zag is slow | Gradient methods with a good preconditioner, or a full Newton-type step |
| Non-separable non-smooth penalty | The method can stop at a non-minimiser | Proximal gradient or subgradient methods |
| Very large with a cheap gradient | Each cycle touches every coordinate | Stochastic gradient descent |
History
The idea of optimising one variable at a time is very old. The Gauss–Seidel iteration for linear systems, which is coordinate descent on a quadratic, is named after Carl Friedrich Gauss and Philipp Ludwig von Seidel, and dates from the nineteenth century. Its use for large regression problems grew in the 2000s, when the lasso became a standard tool and people needed to fit it to very large datasets. Friedman, Hastie, Höfling and Tibshirani popularised coordinate descent for the lasso and elastic net in that period, and it is now the default in several statistical packages. Stephen Wright's 2015 survey gives the theory for the cases where it works.
Check yourself
QuestionFor , the first cycle of coordinate descent from gives . What is after that first cycle?Show answer
With fixed, the derivative in is . Setting it to zero gives , so . This matches step 3 of the worked example.
QuestionIn the standardised lasso update , what is when and ?Show answer
The absolute value is , so . The positive part is , and the sign of is . So . The shrinkage moves the value toward zero by and keeps its sign.
QuestionWhy does coordinate descent get stuck on some non-smooth functions, and why does adding a separable penalty like fix the problem?Show answer
A kink that couples coordinates, such as at , can make every single-axis move fail to lower the value even though a diagonal move would. Coordinate descent cannot take the diagonal move, so it stops. When the non-smooth part is a sum of terms, one per coordinate, each kink lies along a single axis, so a point with no improving axis move is a true minimiser. The stuck corners cannot form, so the method converges.
QuestionA researcher has a problem with a million features, where a gradient over all features costs a great deal but each feature touches only a few samples. Argue whether coordinate descent is a reasonable choice.Show answer
It is a reasonable choice if each coordinate's update is cheap, because a single coordinate step only needs the samples that involve that feature, and a sparse solution means many updates change nothing. The cost of a full cycle is then proportional to the number of non-zero entries, not to the full gradient. The risk is strong correlation between features, which slows convergence. A check is to run a few cycles and see whether the objective is falling at a useful rate before committing to the method.