Speed

One Coordinate Drops Out

Solve a two-feature orthogonal Lasso problem and watch the weaker coordinate hit exact zero on the corner of the L1 diamond while the stronger coordinate survives.

The problem

With two zero-intercept features X=[x1,x2]X = [x_1, x_2], the Lasso objective is J(w1,w2)=12∥x1w1+x2w2−y∥22+λ(∣w1∣+∣w2∣)J(w_1, w_2) = \frac{1}{2}\|x_1 w_1 + x_2 w_2 - y\|_2^2 + \lambda (|w_1| + |w_2|). Whenever the columns are orthogonal (x1⊤x2=0x_1^\top x_2 = 0), the cross term w1w2(x1⊤x2)w_1 w_2 (x_1^\top x_2) vanishes and J(w1,w2)J(w_1, w_2) splits into two separate 1D problems using sj=xj⊤xjs_j = x_j^\top x_j and cj=xj⊤yc_j = x_j^\top y:

w1=S(c1,λ)s1,w2=S(c2,λ)s2 w_1 = \frac{S(c_1, \lambda)}{s_1}, \qquad w_2 = \frac{S(c_2, \lambda)}{s_2}

Why does one coordinate drop out completely while the other stays active? In the (w1,w2)(w_1, w_2) plane, the L1 budget ∣w1∣+∣w2∣≤t|w_1| + |w_2| \le t is a diamond whose sharp corners sit directly on the coordinate axes (±t,0)(\pm t, 0) and (0,±t)(0, \pm t). Expanding elliptical error contours centered at wolsw_{\text{ols}} hit an axis corner whenever ∣c2∣≤λ<∣c1∣|c_2| \le \lambda < |c_1|, setting w2=0.0w_2 = 0.0 while w1≠0.0w_1 \neq 0.0.

Work through the numbers

Take the four-row [x_1, x_2, y] table (1, 1, 3.5), (1, -1, 2.5), (-1, 1, -2.5), and (-1, -1, -3.5) at lam = 2.5.

Verify orthogonality and column norms first: s1=1+1+1+1=4.0s_1 = 1 + 1 + 1 + 1 = 4.0, s2=1+1+1+1=4.0s_2 = 1 + 1 + 1 + 1 = 4.0, and x1⊤x2=1−1−1+1=0x_1^\top x_2 = 1 - 1 - 1 + 1 = 0. Compute correlations with yy: c1=3.5+2.5+2.5+3.5=12.0c_1 = 3.5 + 2.5 + 2.5 + 3.5 = 12.0 and c2=3.5−2.5+2.5−3.5=2.0c_2 = 3.5 - 2.5 + 2.5 - 3.5 = 2.0, giving wols=[12.0/4.0,2.0/4.0]=[3.0,0.5]w_{\text{ols}} = [12.0 / 4.0, 2.0 / 4.0] = [3.0, 0.5].

Now apply lam = 2.5, which sits strictly between ∣c2∣=2.0|c_2| = 2.0 and ∣c1∣=12.0|c_1| = 12.0:

  • Feature 11 survives: w1=S(12.0,2.5)/4.0=9.5/4.0=2.375w_1 = S(12.0, 2.5) / 4.0 = 9.5 / 4.0 = 2.375.
  • Feature 22 drops out: w2=S(2.0,2.5)/4.0=0.0/4.0=0.0w_2 = S(2.0, 2.5) / 4.0 = 0.0 / 4.0 = 0.0, giving [2.375, 0.0].

Check why nudging w2w_2 off zero loses on the objective: raising w2w_2 from 0.00.0 to 0.10.1 reduces 12SSE\frac{1}{2}\text{SSE} by 0.5⋅4⋅(0.52−0.42)=0.180.5 \cdot 4 \cdot (0.5^2 - 0.4^2) = 0.18, whereas λ∣w2∣\lambda |w_2| charges 2.5⋅0.1=0.252.5 \cdot 0.1 = 0.25, a net penalty loss of +0.07+0.07.

The live model

The left panel plots the (w1,w2)(w_1, w_2) plane with the orange L1 diamond passing through [w_1, w_2] (green) and wolsw_{\text{ols}} (gray); the right panel traces the piecewise-linear paths ∣w1(λ)∣|w_1(\lambda)| and ∣w2(λ)∣|w_2(\lambda)| with a red cursor at lam. Slide lam across 2.0: w2(λ)w_2(\lambda) hits the horizontal axis at lam = 2.0 and stays flat at 0.0 while w1(λ)w_1(\lambda) keeps descending linearly toward lam = 12.0.

L1 diamond in (w1, w2) plane and piecewise-linear Lasso paths showing w2 dropping to exact 0.0 at lam = 2.0 while w1 = 2.375 at lam = 2.5.
let lam = scene.parameter("lam", 2.5, 0.0, 13.0, 0.5);
let x1 = input.select(1, 0);
let x2 = input.select(1, 1);
let ys = input.select(1, 2);
let s1 = x1.square().sum();
let s2 = x2.square().sum();
let c1 = (x1 * ys).sum();
let c2 = (x2 * ys).sum();
let w1 = (c1.sign() * (c1.abs() - lam).relu()).div(s1);
let w2 = (c2.sign() * (c2.abs() - lam).relu()).div(s2);
let c_pair = torch.list().add(c1.reshape(1)).add(c2.reshape(1));
let corrs = torch.cat(c_pair, 0);
let w_pair = torch.list().add(w1.reshape(1)).add(w2.reshape(1));
let answer = torch.cat(w_pair, 0);
out.set("corrs", corrs).set("weights", answer);
{
  "corrs": [
    12,
    2
  ],
  "weights": [
    2.375,
    0
  ]
}

Your turn

Compute [w_1, w_2] for the orthogonal [x_1, x_2, y] table input at penalty lam. On the default table the starter returns [9.5, 0.0] where the page computed [2.375, 0.0].

Starter returns unnormalized [9.5, 0.0] instead of [2.375, 0.0] at lam = 2.5.
let lam = scene.parameter("lam", 2.5, 0.0, 13.0, 0.5);
let x1 = input.select(1, 0);
let x2 = input.select(1, 1);
let ys = input.select(1, 2);
let s1 = x1.square().sum();
let s2 = x2.square().sum();
let c1 = (x1 * ys).sum();
let c2 = (x2 * ys).sum();
let w1 = c1.sign() * (c1.abs() - lam).relu();
let w2 = c2.sign() * (c2.abs() - lam).relu();
let pair = torch.list().add(w1.reshape(1)).add(w2.reshape(1));
let answer = torch.cat(pair, 0);
out.set("weights", answer);
{
  "weights": [
    9.5,
    0
  ]
}

Compute [w_1, w_2] for the orthogonal [x_1, x_2, y] table input at penalty lam. On the default table the starter returns [9.5, 0.0] where the page computed [2.375, 0.0].

Read the result carefully

Compare the piecewise-linear Lasso path here against Ridge's curved path wj=cj/(sj+λ)w_j = c_j / (s_j + \lambda) (the minimizer of 12∥Xw−y∥22+12λ∥w∥22\frac{1}{2}\|X w - y\|_2^2 + \frac{1}{2}\lambda\|w\|_2^2). Under Ridge, w2(λ)=2/(4+λ)w_2(\lambda) = 2 / (4 + \lambda) bends smoothly and stays positive (2 / 6.5 = 0.308 at lam = 2.5). Under Lasso, each orthogonal coordinate decreases at constant slope 1/sj1 / s_j until it strikes zero at λ=∣cj∣\lambda = |c_j|, creating a knot where the active set changes size.

Recap

  • When x1⊤x2=0x_1^\top x_2 = 0, two-feature Lasso decouples into wj=S(xj⊤y,λ)/(xj⊤xj)w_j = S(x_j^\top y, \lambda) / (x_j^\top x_j) for j=1,2j = 1, 2.
  • Any penalty in the window ∣c2∣≤λ<∣c1∣|c_2| \le \lambda < |c_1| zeros out feature 22 completely while keeping feature 11 active.
  • Geometrically, exact coordinate dropout occurs because error contours meet an axis corner of the L1 diamond ∣w1∣+∣w2∣≤t|w_1| + |w_2| \le t.