At and Beyond the Threshold
Compute the exact all-zero boundary max |X^T y| and verify that every penalty at or beyond lam_max yields w = 0.
The problem
How large must become before Lasso drops every feature and predicts zero everywhere? You do not need to solve a path of models by trial and error to find out: the subgradient optimality condition at answers the question in one matrix-vector product.
At , the residual is , the smooth fit gradient is , and the L1 subdifferential is the hypercube . Zero lies inside if and only if for every column . Therefore the exact all-zero threshold—even when columns of are correlated—is the infinity norm
Work through the numbers
Inspect the orthogonal four-row [x_1, x_2, y] table (1, 1, -1.5), (1, -1, -2.5), (-1, 1, 2.5), and (-1, -1, 1.5) with .
Dot each column with : and . Taking absolute values before maximizing gives lam_max = max(|-8.0|, |2.0|) = 8.0. Taking the raw maximum misses the dominant negative correlation completely.
Compare three penalty values around lam_max = 8.0:
- Below (
lam = 5.0): . - At threshold (
lam = 8.0): and , returning[8.0, 0.0, 0.0]. - Beyond (
lam = 11.0): both magnitudes still sit inside , so[8.0, 0.0, 0.0]stays completely unchanged.
The live model
The left panel compares column correlation magnitudes and against the horizontal orange threshold line at lam, marking lam_max in purple; the right panel plots hitting zero at and hitting zero at . Slide lam from 5.0 through 8.0 up to 12.0 to see the solution freeze at [0, 0] the instant lam reaches lam_max.
![Correlation magnitude bars |c1| = 8 and |c2| = 2 met by threshold line lam = 8 = lam_max, where both Lasso paths reach exact zero [8.0, 0.0, 0.0].](../assets/ml/at-and-beyond-the-threshold--demo.png)
let lam = scene.parameter("lam", 8.0, 0.0, 12.0, 1.0);
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 c_vec = torch.cat(torch.list().add(c1.reshape(1)).add(c2.reshape(1)), 0);
let lam_max = c_vec.abs().max();
let w1 = (c1.sign() * (c1.abs() - lam).relu()).div(s1);
let w2 = (c2.sign() * (c2.abs() - lam).relu()).div(s2);
let parts = torch.list().add(lam_max.reshape(1));
let parts2 = parts.add(w1.reshape(1)).add(w2.reshape(1));
let answer = torch.cat(parts2, 0);
out.set("corrs", c_vec).set("threshold_state", answer);
{
"corrs": [
-8,
2
],
"threshold_state": [
8,
0,
0
]
}Your turn
Compute [lam_max, w_1, w_2] for the orthogonal [x_1, x_2, y] table input at penalty lam. On the default table the starter reports [2.0, 0.0, 0.0] where the page computed [8.0, 0.0, 0.0].
![Starter reports lam_max = 2.0 instead of 8.0 on correlations [-8, 2].](../assets/ml/at-and-beyond-the-threshold--exercise.png)
let lam = scene.parameter("lam", 8.0, 0.0, 12.0, 1.0);
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 c_vec = torch.cat(torch.list().add(c1.reshape(1)).add(c2.reshape(1)), 0);
let lam_max = c_vec.max();
let w1 = (c1.sign() * (c1.abs() - lam).relu()).div(s1);
let w2 = (c2.sign() * (c2.abs() - lam).relu()).div(s2);
let parts = torch.list().add(lam_max.reshape(1));
let parts2 = parts.add(w1.reshape(1)).add(w2.reshape(1));
let answer = torch.cat(parts2, 0);
out.set("corrs", c_vec).set("threshold_state", answer);
{
"corrs": [
-8,
2
],
"threshold_state": [
2,
0,
0
]
}Return [lam_max, w_1, w_2] for the orthogonal [x_1, x_2, y] table input at penalty lam. On the default table the starter reports [2.0, 0.0, 0.0] where the page computed [8.0, 0.0, 0.0].
Read the result carefully
Regularization path libraries do not guess an upper bound for : they compute first (divided by the row count when their objective averages the squared error) and build a descending grid from down to a small fraction of it, such as , because testing two values above wastes computation on identical zero vectors. Also keep the norm duality straight: an L1 penalty on induces an L-infinity () threshold on , never the sum .
Recap
- Every Lasso weight equals exact zero if and only if .
- Always take absolute values of before maximizing so strong negative correlations set properly.
- At the last surviving coordinate reaches
0.0, and for all the solution remains[0, ..., 0].