Coordinate descent
坐标下降
Solve cheap coordinate subproblems while keeping update order and coupling explicit.
coordinate-descentAdjust one knob while holding the others fixed
A model has many weights, but optimizing all of them together may require an expensive system solve. Coordinate descent changes one weight at a time, treating the others as fixed. If each one-dimensional subproblem is cheap, a sweep through the weights can make useful progress with little temporary storage.
The knobs still interact. After changing x, the best value of y may change immediately. A cyclic update uses that new x. Updating both coordinates from an old snapshot is a different algorithm, even when the formulas look almost identical.
We will solve a coupled quadratic with exact fractions, derive its error after every complete sweep, and then construct a nonsmooth function where coordinate-wise optimality is misleading. Read partial derivatives and quadratic forms first.
Define the subproblem and the coordinate schedule
For objective F on real coordinates, an exact coordinate update chooses a value minimizing the objective with the other coordinates held at their current values:
An implementation also needs to say how j is chosen and what happens if the minimizer is nonunique or unavailable. Common schedules include cyclic order, randomized selection and a greedy choice based on a measure of potential improvement. Their per-step costs and convergence analyses differ. Wright’s Coordinate Descent Algorithms surveys these variants and their assumptions.
For a positive-definite quadratic F(x)=xᵀQx/2−bᵀx, differentiating with respect to one coordinate gives:
Positive definiteness ensures Qⱼⱼ is positive and the coordinate minimum is unique. Cyclic exact updates are the Gauss–Seidel iteration for Qx=b, using newly computed values as soon as they are available. A full Newton step would solve that entire system at once; coordinate descent distributes the work across cheaper updates.
A complete sweep with a solvable recurrence
Our objective is F(x,y)=x²+xy+y²−x, with Q=[[2,1],[1,2]] and b=(1,0). Q has eigenvalues 1 and 3, so the objective is strictly convex. Its unique minimizer is (2/3,−1/3), with value −1/3. Update x first and then y:
Subtracting the optimal y shows that its error contracts by 1/4 per sweep. Starting at (0,0), the full iterates and objective gap are:
This is a result for this particular quadratic and coordinate order, not a universal rate. The first sweep produces (1/2,−1/4). A simultaneous update using old x=0 for the y formula would produce (1/2,0) instead. It is not the same trajectory.
Why this is useful for sparse regression
For a squared-error model, maintaining the current residual can make a coordinate update depend mainly on one feature column. With dense columns, a sweep can use O(nd) work for n observations and d features rather than repeatedly recomputing all predictions. Sparse columns can be cheaper. The glmnet author manuscript develops coordinate updates for regularized regression and generalized linear models; its penalty scaling and residual conventions matter when reusing the formulas.
A separable penalty such as a sum of absolute coordinate values keeps each regularized subproblem local. This connects coordinate descent to Lasso and elastic net. The example here has no regularizer; it isolates update order and coupling.
Track whole sweeps without pretending a finite iterate is exact
Run the complete Python 3.12 standard-library program. It accepts a rational two-coordinate starting point and 0–50 sweeps. It returns the starting point plus one record per completed sweep. A zero-sweep request performs no updates. It reports the remaining objective gap rather than calling three sweeps an exact solution.
from fractions import Fraction as F
def rational(value):
if type(value) not in (int,F):
raise ValueError('integer or Fraction required')
return F(value)
def objective(x,y):
x,y=map(rational,(x,y))
return x*x+x*y+y*y-x
def cyclic(sweeps,start=(0,0)):
if type(sweeps) is not int or not 0 <= sweeps <= 50:
raise ValueError('integer sweep count in [0,50] required')
if type(start) not in (list,tuple) or len(start) != 2:
raise ValueError('two starting coordinates required')
x,y=map(rational,start)
rows=[(x,y,objective(x,y))]
for _ in range(sweeps):
x=(1-y)/2
y=-x/2
rows.append((x,y,objective(x,y)))
return rows
if __name__ == '__main__':
for k,(x,y,value) in enumerate(cyclic(3)):
assert value+F(1,3) == F(1,3*16**k)
print('sweep='+str(k),'x='+str(x),'y='+str(y),
'objective='+str(value),'gap='+str(value+F(1,3)))
t=F(1,4)
nonsmooth=lambda x,y:max(x,y)+(x*x+y*y)/2
assert nonsmooth(-t,0)>0 and nonsmooth(0,-t)>0 and nonsmooth(-t,-t)<0
print('nonsmooth diagonal improvement:',nonsmooth(-t,-t))
Output:
sweep=0 x=0 y=0 objective=0 gap=1/3
sweep=1 x=1/2 y=-1/4 objective=-5/16 gap=1/48
sweep=2 x=5/8 y=-5/16 objective=-85/256 gap=1/768
sweep=3 x=21/32 y=-21/64 objective=-1365/4096 gap=1/12288
nonsmooth diagonal improvement: -3/16
Every reported quadratic gap matches the closed recurrence. Because y is updated last, its partial derivative is zero at the end of a sweep; x’s partial derivative can still be nonzero because changing y affects it. “I minimized each coordinate once” does not mean “all partial derivatives are now zero.”
For a dense d-dimensional quadratic, computing one update directly costs O(d) arithmetic and one full sweep costs O(d²), assuming Q is already available. Our two-coordinate update costs a constant number of operations; saving a trace of k sweeps uses O(k) records. Fraction bit cost grows with the denominator. Comparisons with other optimizers should account for sweeps, coordinate updates and actual derivative/data work separately.
Coordinate-wise optimal need not mean jointly optimal
Consider H(x,y)=max(x,y)+(x²+y²)/2. At (0,0), changing only x gives max(x,0)+x²/2, whose unique minimum is zero at x=0. The same holds for changing only y. Exact coordinate minimization therefore remains at the origin.
Yet moving both coordinates to (−t,−t) gives −t+t², which is negative when t is between zero and one. The origin is not a joint minimum. This function is convex, but its nonsmooth max term couples the coordinates and is not separable. The program checks t=1/4, where the diagonal value is −3/16. Convexity alone is not permission to apply every smooth or separably regularized coordinate-descent theorem.
Constraints that couple coordinates can also make one-coordinate movement impossible without leaving feasibility. Nonunique subproblem minimizers, nonconvex objectives and stale parallel updates require separate analysis. Random coordinate selection does not by itself remove these issues.
The favorable rate in our quadratic comes from its specific coupling. Strongly coupled or poorly scaled coordinates can converge slowly. Rescaling, block updates or a different solver may be more appropriate; compare costs under the same objective and stopping criterion.
Notice which values an update reads
- From (0,0), compute one x-then-y sweep for the quadratic.
Answer 1: x becomes 1/2; the new x makes y=−1/4. Using the old x to get y=0 would be a simultaneous, not cyclic, update.
- Why can x’s partial derivative be nonzero after a full sweep?
Answer 2: x was minimized for the previous y. The later y update changes the x derivative through the xy term. At the first completed sweep it equals −1/4.
- What is the objective gap after two sweeps from the origin?
Answer 3: 1/(3×16²)=1/768. The coordinates are (5/8,−5/16); the gap is positive, so this finite iterate is not the exact minimizer.
- Why does exact coordinate minimization fail at the origin for the nonsmooth H?
Answer 4: Each axis alone has its minimum there, but a joint diagonal move decreases the objective. The nonsmooth coupling violates the separability structure used by common composite coordinate-descent guarantees.
Exploit cheap subproblems without overlooking their coupling
Wright’s survey puts cyclic, randomized and parallel variants in a common framework; the glmnet manuscript shows why sparse data and separable penalties make coordinate updates useful in practice. The exact recurrence and nonsmooth counterexample here provide small checks before moving to a library implementation.
As an extension, change the quadratic’s off-diagonal coupling while keeping it positive definite. Derive the new scalar error recurrence and compare whole-sweep convergence. Then study proximal methods for a different way to combine a smooth term with a nonsmooth penalty.
Make a prediction, then check
In an x-then-y cyclic sweep, which x value does the y update use?
Learning objectives
- Derive a cyclic quadratic update and its exact sweep recurrence.
- Recognize when nonsmooth coupling defeats coordinate-wise optimality.
Prerequisites & connections
Explore related knowledge →References
- Coordinate Descent Algorithms — arXiv v1
Stephen J. Wright · 2015 - Regularization Paths for Generalized Linear Models via Coordinate Descent — author manuscript, 29 April 2009
Jerome Friedman; Trevor Hastie; Robert Tibshirani · 2009
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, literal or exact computational checks, and bilingual review; not independent human or second-agent peer review.
- Single-agent authored technical review: source locations, stated domains and assumptions, derivations, literal or exact reference cases and matching bilingual programs/exercises. Not independent human or second-agent peer review.
- Four focused tests passed on CPython 3.12.4. Exact Fraction examples are used except for the explicitly floating-point damped Newton experiment. Strict bilingual MDX/KaTeX rendering gives four equations, six anchors and four answers per language; repository publication checks are recorded separately.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- Coordinate Descent Algorithms — arXiv v1 · arXiv v1, §2 separable composite setup and §3 Gauss–Seidel/cyclic connection; no universal rate attributed.
- Regularization Paths for Generalized Linear Models via Coordinate Descent — author manuscript, 29 April 2009 · 2009-04-29 author manuscript, coordinate updates and residual reuse for regularized regression; distinct from later journal version.
Related topics