The Soft-Threshold Rule
Solve the 1D Lasso objective in closed form with the soft-threshold operator and see the dead zone appear around zero.
The problem
Iterating subgradients revealed why chatters near zero, yet we do not need iterative steps in one dimension at all. Because is a quadratic on , another quadratic on , and has subdifferential at , we can solve the optimality condition in exact closed form.
Checking the three sign regions yields the soft-threshold operator :
- When , setting gives .
- When , setting gives .
- When , lies inside , pinning .
All three branches collapse into one expression:
Work through the numbers
Apply at lam = 1.0 to four unconstrained coordinates z = [3.0, 1.2, 0.5, -2.4].
Take magnitudes first: |z| = [3.0, 1.2, 0.5, 2.4]. Subtract lam = 1.0 from every magnitude to get [2.0, 0.2, -0.5, 1.4]. Now clamp negative values at zero via : the third entry -0.5 sits inside the dead zone , so it clamps to 0.0, giving shrunk magnitudes [2.0, 0.2, 0.0, 1.4]. Finally restore original signs [+1, +1, +1, -1] to obtain S(z, 1.0) = [2.0, 0.2, 0.0, -1.4].
Look at what happens if you omit the zero clamp and evaluate directly: the third coordinate overshoots the origin and flips sign to , producing [2.0, 0.2, -0.5, -1.4]. Raising lam to 1.5 widens the dead zone so 1.2 also hits zero, yielding [1.5, 0.0, 0.0, -0.9].
The live model
The canvas draws the 45-degree reference line (gray), the threshold fences and (orange), and the piecewise-linear soft-threshold transfer curve (blue), marking the four input coordinates as dots (green when zeroed). Slide lam from 0.0 to 3.2 to watch the flat dead zone widen and swallow coordinates one by one.
![Piecewise-linear soft-threshold transfer curve with dead zone [-1, 1], mapping [3.0, 1.2, 0.5, -2.4] to [2.0, 0.2, 0.0, -1.4].](../assets/ml/the-soft-threshold-rule--demo.png)
let lam = scene.parameter("lam", 1.0, 0.0, 3.2, 0.2);
let mag = (input.abs() - lam).relu();
let answer = input.sign() * mag;
out.set("shrunk_mag", mag).set("soft", answer);
{
"shrunk_mag": [
2,
0.19999999999999996,
0,
1.4
],
"soft": [
2,
0.19999999999999996,
0,
-1.4
]
}Your turn
Write the closed-form soft-threshold operator so answer returns the shrunk weight vector for any input and lam. On the default vector the starter returns input unchanged ([3.0, 1.2, 0.5, -2.4] where the page computed [2.0, 0.2, 0.0, -1.4]).
![Starter leaves the input vector unthresholded, returning [3.0, 1.2, 0.5, -2.4] instead of [2.0, 0.2, 0.0, -1.4].](../assets/ml/the-soft-threshold-rule--exercise.png)
let lam = scene.parameter("lam", 1.0, 0.0, 3.2, 0.2);
let answer = input;
out.set("soft", answer);
{
"soft": [
3,
1.2,
0.5,
-2.4
]
}Evaluate the closed-form soft-threshold operator at penalty lam for every coordinate in input. On the default vector the starter returns [3.0, 1.2, 0.5, -2.4] where the page computed [2.0, 0.2, 0.0, -1.4].
Read the result carefully
Do not confuse soft thresholding with hard thresholding ( if , else ). Hard thresholding jumps discontinuously from to at the boundary, making tiny perturbations in trigger large jumps in predictions. Soft thresholding is continuous everywhere: outside , every surviving coordinate is pulled inward by so the two outer ramps meet the flat zero segment without a gap.
Recap
- The exact minimizer of is .
- Inputs inside the dead zone map to exact
0.0; inputs outside shrink toward zero by . - Clamping at zero prevents penalty pull from pushing a small weight past the origin into the opposite sign.