Model Zero
The Null Hypothesis
← Back to articles

Mathematics

A Deep Reading of L1

From absolute values to sparse solutions: the geometry, optimization, and trade-offs behind L1 regularization.

Keywords: L1 regularization · Lasso · sparse optimization · convex geometry · compressed sensing · total variation

A sparse vector meets the diamond-shaped L1 constraint, with optimization paths converging on its boundary.
In this essay

A Bird Building Its Nest

Sometimes a beginning is strong: it catches your attention and leaves you searching for an answer throughout the story. At other times it seems ordinary, giving no hint of what will follow or what will stay with you.

You may wonder what this introduction has to do with a symbol or a story, but a metaphor can make the explanation flow. So imagine a bird trying to build its nest; it cannot carry every branch it finds, and must choose enough to build with.

We will return to it when numbers become choices, but let us stay with three ordinary numbers for now.

The 39 Python examples share state and are intended to run in order. Download the complete script and its requirements.

What Is L1L_{1}

Suppose we have three numbers: 3, −4, and 2. Put them in a vector and call it w.

Geometrically, that vector might describe a direction or displacement; its entries might also be weights learned by a model. Our question is simpler for now: how large are these numbers together?

We need a norm to measure the vector, and L1L_{1} does this by adding the absolute value of each entry: remove its sign, then add the magnitudes. The index j identifies an entry and d counts the entries, so our vector has L1L_{1} magnitude 9.

Run the code blocks in order; the first imports NumPy; other tools appear when we need them.

w=(w1,…,wd),∥w∥1=∑j=1d∣wj∣,∥(3,−4,2)∥1=9. w=(w_1,\ldots,w_d),\qquad \|w\|_1=\sum_{j=1}^{d}|w_j|,\qquad \|(3,-4,2)\|_1=9.
Read this equation in detail

What does the sum collect?

The vector w is an ordered list of numbers, and wⱼ is the entry at position j. The dimension d counts the positions.

The Σ symbol says to repeat the operation from the first position to the last and add the results. Single bars in |wⱼ| remove an entry’s sign; double bars in ‖w‖₁ measure the whole vector using L1L_{1}.

Remove signs, then add

For (3,−4,2)(3, -4, 2), first obtain magnitudes (3,4,2)(3, 4, 2), then add 3+4+2=9. Adding the original entries gives 1 because signs cancel, answering a different question.

Reordering entries or changing their signs preserves L1L_{1}, while doubling every entry doubles it.

A measurement does not select

This equation measures a vector that already exists. It does not turn −4 into zero or decide which entry to remove.

Regularization begins when this quantity becomes a cost paid while searching for a new vector.

python

The Club of Norms

The reason for taking absolute values appears if we use (100,−100)(100, -100). Ordinary addition gives zero although both entries are large; L1L_{1} gives 200.

Mathematicians require conditions before admitting a measurement into the club of norms: it must be nonnegative, vanish only at the zero vector, scale by |c| when the vector is multiplied by c, and obey the triangle inequality. That last condition says that the magnitude of a sum cannot exceed the sum of the magnitudes.

In distance terms, a direct route cannot be longer than a route through an intermediate point when both use the same norm. To make the scaling example precise, w=(3,−2)(3, -2) gives 2w=(6,−4)(6, -4), whose magnitude is 10, twice 5.

∥w∥1≥0,∥w∥1=0  ⟺  w=0,∥cw∥1=∣c∣∥w∥1,∥u+v∥1≤∥u∥1+∥v∥1. \|w\|_1\ge0,\quad \|w\|_1=0\iff w=0,\quad \|cw\|_1=|c|\|w\|_1,\quad \|u+v\|_1\le\|u\|_1+\|v\|_1.
Read this equation in detail

The entry conditions

The four conditions require a nonnegative magnitude, zero only for the zero vector, scaling by |c| under multiplication by c, and the triangle inequality. The symbol ⇔ means both implications hold: the zero vector has zero norm, and a zero norm implies a zero vector.

Why an absolute multiplier?

A negative c changes direction without making magnitude negative, so the scaling factor is |c|. For w=(3,−2)(3, -2), the norm is 5; for −2w=(−6,4)(-6, 4), it is 10.

Entrywise, |cwⱼ|=|c||wⱼ|; summing lets us factor out |c|.

Direct and combined routes

Sum |uⱼ+vⱼ|≤|uⱼ|+|vⱼ| over entries to obtain the vector triangle inequality. With u=(2,−1)(2, -1) and v=(−1,3)(-1, 3), their sum has norm 3, while their separate norms total 7.

Equality is allowed; the inequality does not claim the sum is always strictly smaller.

python

From Streets to Shapes

Geometrically, L1L_{1} measures Manhattan distance. Reaching (3,2)(3, 2) from (0,0)(0, 0) through horizontal and vertical streets costs 5 units, whereas the straight line has length 13\sqrt{13}.

Collect all points whose norm is at most one, and L1L_{1} gives a diamond, L2L_{2} a disk, and L∞L_{\infty} a square. These shapes are more than decoration: their boundaries will later help determine where a solution can settle.

Still, calculating a norm alone changes no model; regularization begins when we give that magnitude a cost inside an optimization problem.

L1L_1

w₁w₂

∣w1∣+∣w2∣≤t\lvert w_1\rvert + \lvert w_2\rvert \le t

L2L_2

w₁w₂

w12+w22≤t\sqrt{w_1^2 + w_2^2} \le t

L∞L_\infty

w₁w₂

max⁡(∣w1∣,∣w2∣)≤t\max(\lvert w_1\rvert, \lvert w_2\rvert) \le t

Figure 1: Norm balls. At a shared budget t, the L₁, L₂, and L∞ balls form a diamond, disk, and square, respectively.

python

The Family and Its Distant Cousin

Our protagonist belongs to a wider family. For p≥1p\ge 1, add the pth powers of the magnitudes and take the corresponding root.

At p=1p=1 we obtain L1L_{1}, at p=2p=2 Euclidean length, and as p grows without bound we obtain the largest individual magnitude. Its distant cousin L0L_{0} counts nonzero entries, so it fails the homogeneity required of a true norm: doubling the entries does not double their count.

For (3,4,0)(3, 4, 0), the values are L0=2L_{0}=2, L1=7L_{1}=7, L2=5L_{2}=5, and L∞=4L_{\infty}=4. Each answers a different question; two vectors can therefore have the same L1L_{1} norm while using very different numbers of entries.

∥w∥p=(∑j=1d∣wj∣p)1/p,∥w∥∞=max⁡j∣wj∣,∥w∥0=#{j:wj≠0}. \|w\|_p=\left(\sum_{j=1}^{d}|w_j|^p\right)^{1/p},\qquad \|w\|_\infty=\max_j|w_j|,\qquad \|w\|_0=\#\{j:w_j\ne0\}.
Read this equation in detail

Which question does p answer?

The parameter p sets how magnitudes combine: raise each to p, add, then take the pth root. At p=1p=1 nothing changes; at p=2p=2 this is the square root of a sum of squares.

Requiring p≥1p\ge 1 makes the expression a norm. Substituting p=0p=0 into this displayed root does not define L0L_{0}.

From a sum to the largest entry

Large p increasingly emphasizes the largest magnitudes. Let m=max⁡∣wj∣m=\max |w_j|.

The p-norm lies between m and d1/pd^{1/p}m. As p tends to infinity, d1/pd^{1/p} tends to 1, so both bounds meet at m, explaining L∞L_{\infty}.

The cousin that counts

The # symbol counts entries satisfying wj≠0w_{j}\ne 0. For (3,4,0)(3, 4, 0), that count is 2, whereas L1=7L_{1}=7, L2=5L_{2}=5, and L∞=4L_{\infty}=4.

Doubling the vector preserves the count instead of doubling it, explaining why the quantity called L0L_{0} is not a norm.

python

Where Did the Story Begin

We may now ask who created L1L_{1}. Absolute value has no single beginning that can be assigned to an inventor: absolute-deviation estimation predates machine learning, and the development of LpL_{p} spaces is a separate mathematical story.

Specific methods are easier to attribute. Hoerl and Kennard developed Ridge regression in 1970 to address unstable coefficients; Williams studied Laplace-prior regularization and pruning in neural networks in 1995; Tibshirani introduced Lasso in 1996, combining regression shrinkage with variable selection.

Chen, Donoho, and Saunders developed Basis Pursuit in 1998, followed by Elastic Net in 2005 and major compressed-sensing results in 2006. Each landmark added a question rather than erasing earlier work.

How Many Branches Do We Need

Return to the bird: choosing concerns the number of branches, not just their combined length. A vector is sparse when most entries are zero, and its support S(w) is the set of positions occupied by the remaining entries.

The support of (0,4,0,−2,0,0)(0, 4, 0, -2, 0, 0) is {2, 4}, so its L0L_{0} count is 2. To charge a fixed cost for every retained entry, we can add λL0\lambda L_{0} to the fitting loss F.

Searching over subsets can be difficult, since d positions allow 2d2^{d} subsets. In the one-coordinate example, compare the zero solution’s cost a2/2a^{2}/2 with the cost λ\lambda of keeping a.

Choose zero when its cost is lower and keep a unchanged when λ\lambda is lower; at equality both are optimal. Many small entries are not exact sparsity, although a sparse approximation may represent them well.

L1L_1

∑i∣wi∣\sum_i |w_i|
0.6

Changes with coefficient size

L0L_0

# nonzeros
1

Changes only at zero

(1,  0,  0,  0)\left(1,\;0,\;0,\;0\right)L0=1L_0 = 1
(0.25,  0.25,  0.25,  0.25)\left(0.25,\;0.25,\;0.25,\;0.25\right)L0=4L_0 = 4

Figure 2: Magnitude and support. L₁ tracks coefficient magnitude while L₀ counts nonzeros; equal L₁ totals can have different support.

min⁡wF(w)+λ∥w∥0,min⁡w12(w−a)2+λ1w≠0. \min_w F(w)+\lambda\|w\|_0,\qquad \min_w\frac12(w-a)^2+\lambda\mathbf1_{w\ne0}.
Read this equation in detail

Fitting and retaining

The min symbol asks for a w minimizing the total. F measures fitting error, and λ≥0\lambda\ge 0 is the price of each nonzero entry.

In the scalar example, F=(w−a)22F=\frac{(w-a)^2}{2}, where a is the data-preferred value. The indicator 1_{w≠0} equals 1 for a retained nonzero value and 0 at zero.

Compare two choices

At w=0, the cost is a2/2a^{2}/2 with no retention penalty. For a≠0, the best nonzero choice is w=a, giving zero fitting error and cost λ\lambda.

Compare a2/2a^{2}/2 with λ: zero wins below ∣a∣=2λ|a|=\sqrt{2\lambda}, retention above it, and both tie at the boundary. If a=0, zero is optimal.

Why does the survivor stay unchanged?

With a=0.6 and λ=0.3\lambda=0.3, zero costs 0.18 rather than 0.3. A sufficiently large a survives unchanged because the penalty charges for using the entry, not for its magnitude.

This distinguishes hard thresholding from the soft thresholding ahead.

python

What Does Convex Mean

We now need the word convex, because ease of optimization is not merely a description. Join two points on a convex function’s graph with a straight line, and the graph stays below or on that line.

The following inequality states this when a and b are mixed in proportion t. Every local minimum of a convex function on a convex domain is global, but this alone guarantees neither uniqueness nor existence.

Absolute value is convex despite its corner at zero, and squared regression loss is convex in the coefficients, so their sum in Lasso is convex. L0L_{0} instead jumps at zero: mixing 0 and 1 equally gives cost 1 at the midpoint, larger than the average cost 1/2.

Adding a convex penalty to a nonconvex neural-network loss does not make the entire problem convex; nonsmoothness and nonconvexity are different properties.

F(ta+(1−t)b)≤tF(a)+(1−t)F(b),0≤t≤1. F(ta+(1-t)b)\le tF(a)+(1-t)F(b),\qquad 0\le t\le1.
Read this equation in detail

Mix two points

Choose t between 0 and 1 so ta+(1−t)b lies between a and b. The left side evaluates the function there; the right side mixes endpoint function values in the same proportions.

Convexity requires the interior value not to exceed that average. One successful example is insufficient: the condition must hold for all eligible points and proportions.

Hold the idea in an example

For absolute value, a=−2, b=3, and t=0.4 give a mixed point 1 with value 1, versus endpoint average 2.6. The nonzero indicator instead gives 1 at the midpoint of 0 and 1, exceeding the endpoint average 0.5.

What convexity permits

On a convex domain, a local minimum is global, but solutions can be multiple and an infimum may not be attained. A corner at zero does not destroy convexity: smoothness concerns derivatives, while convexity concerns this inequality.

python

A Replacement That Makes the Search Easier

This is why we sometimes replace difficult counting with a convex measurement, calling the replacement a convex relaxation. It creates a new problem; it does not prove that the new solution equals the old one.

On the bounded interval [−M, M], |w|/M is the largest convex function below the nonzero indicator: its convex envelope. Between zero and M, a convex lower bound cannot rise above the line joining (0,0)(0, 0) and (M, 1); scaled absolute value attains that line, and the negative side works similarly.

On a box bounding every entry, the envelope is L1L_{1}/M. On the whole unbounded space it is zero, rather than L1L_{1}.

Even a small example gives different solutions: a=0.6 and λ=0.3\lambda=0.3 make L0L_{0} choose zero while L1L_{1} chooses 0.3. Their relationship is not equality.

Nonzero indicatorConvex envelope10−M0Mw = 0.5
∣w∣M=\frac{|w|}{M} = 0.5L0(w)=L_0(w) = 1

Figure 3: Convex envelope. On [−M, M], |w|/M is the convex envelope of the nonzero indicator, meeting zero at the origin and one at both bounds.

conv env⁡[−M,M]d(∥w∥0)=∥w∥1M,M>0. \operatorname{conv\,env}_{[-M,M]^d}(\|w\|_0)=\frac{\|w\|_1}{M},\qquad M>0.
Read this equation in detail

The envelope is not the original function

A convex envelope is the largest convex function lying below the function being approximated. The box [−M, M]^d bounds each entry’s magnitude by M>0.

The result identifies the envelope of the nonzero count on that box with total absolute magnitude divided by M; it does not equate the count itself with this quantity.

From one interval to a box

In one dimension, the lines joining (0,0)(0,0) to (M,1) and (−M,1) give |w|/M. Convexity prevents a lower bound from rising above these lines.

The box is a product of independent intervals and counting is additive, so the coordinate envelopes add.

Why M matters

For M=2 and w=0.5, the envelope costs 0.25 whereas counting costs 1. Without bounds, slopes 1/M can approach zero, and the global envelope is zero.

Identifying L1L_{1} with an L0L_{0} convex envelope therefore requires a specified bounded domain.

python

When the Solution Touches a Corner

We can see the replacement’s effect before differentiating it. Give two coefficients an L1L_{1} budget t: the allowed region is a diamond with vertices on the axes.

Equal-loss contours are ellipses for a positive-definite quadratic loss. We seek the smallest loss contour touching the allowed region, and contact at a vertex makes one coefficient zero.

In the following example, the unconstrained solution is (2,0.3)(2, 0.3). A budget of 1.2 gives the L1L_{1} solution (1.2, 0), whereas L2L_{2} gives approximately (1.1792, 0.2225).

Yet a diamond has edges too, and an optimum on an edge can have two nonzero coefficients. Under suitable Lagrangian conditions, a budget can be related to a penalty λ\lambda, but there is no universal fixed conversion between t and λ\lambda.

L₁ constraint

β₁β₂
L₁ solutionβ^=(1.2,0)\hat{\beta} = (1.2, 0)

L₂ constraint

β₁β₂
L₂ solutionβ^=(1.1792,0.2225)\hat{\beta} = (1.1792, 0.2225)

Figure 4: Constraint contact. Change t to see both computed solutions for the same loss; the L1 optimum can move from a vertex to an edge.

F(β)=12[(β1−2)2+2(β2−0.3)2],min⁡∥β∥1≤tF(β). F(\beta)=\frac12[(\beta_1-2)^2+2(\beta_2-0.3)^2],\qquad \min_{\|\beta\|_1\le t}F(\beta).
Read this equation in detail

What does the loss describe?

The coefficients β₁ and β₂ specify a point to find. Without constraints, (2,0.3)(2,0.3) makes both squared errors vanish.

The factor 2 makes displacement in the second direction more expensive. The condition ‖β‖₁≤t permits points whose total coefficient magnitude fits budget t.

Why (1.2,0)?

With t=1.2, the unconstrained point is infeasible because it needs 2.3. At (1.2,0), the loss gradient is (−0.8,−0.6).

A constraint price of 0.8 balances the first active coefficient and allows the second to remain zero because its pressure 0.6 is below that price. This makes the corner optimal here.

The shape also has edges

Other data preferences can put the optimum on an edge with both coefficients nonzero. A budget specifies feasibility; λ\lambda in a penalty specifies price.

Their relationship depends on the loss and solution rather than a universal conversion.

python

Why Does a Model Need Regularization

Why impose a budget or penalty at all? A model learns from examples it has seen, but we want it to perform on unseen examples.

It may memorize training details and noise, leading to overfitting. The average observed loss is empirical risk; population risk is expected loss under the distribution of future examples.

Regularization adds a preference Ω\Omega to fitting quality, with λ\lambda setting its price. If model A has loss 0.20 and magnitude 10, while B has loss 0.23 and magnitude 2, then λ=0.01\lambda=0.01 gives objectives 0.30 and 0.25, favoring B.

Sacrificing some training fit may improve generalization, but does not guarantee it. Loss, regularizer, weighted penalty, and the full objective need to remain distinguishable.

R^n(θ)=1n∑i=1nℓ(yi,fθ(xi)),R(θ)=E[ℓ(Y,fθ(X))],Jλ=R^n+λΩ. \widehat R_n(\theta)=\frac1n\sum_{i=1}^{n}\ell(y_i,f_\theta(x_i)),\qquad R(\theta)=\mathbb E[\ell(Y,f_\theta(X))],\qquad J_\lambda=\widehat R_n+\lambda\Omega.
Read this equation in detail

What do we observe and what do we want?

Parameters θ\theta define fθ, and each observed pair (xᵢ,yᵢ) supplies a loss ℓ comparing response with prediction. Empirical risk adds these losses and divides by n.

Population risk instead averages loss over a fresh random pair (X,Y), so it is not directly available from training.

Pay for a preference

Add a chosen preference Ω\Omega(θ\theta), weighted by λ\lambda. If two models have losses 0.20 and 0.23 and magnitudes 10 and 2, λ=0.01\lambda=0.01 gives totals 0.30 and 0.25.

The second wins under the regularized objective despite its slightly worse fitting loss.

An objective is not a future-performance certificate

We minimize a training-computable quantity with our chosen preference. A lower regularized objective does not guarantee lower population risk: the preference may be unsuitable or λ\lambda excessive.

Independent evaluation remains necessary.

python

The Price of Magnitude: λ\lambda

When Ω\Omega is L1L_{1}, we charge the combined magnitudes of the coefficients we choose to regularize, which need not be every model parameter. We may exclude an intercept or some biases, so a strong penalty does not necessarily make the whole model zero. λ\lambda is distinct from learning rate η\eta, pruning threshold τ\tau, and stopping tolerance: they change the preference, the search step, a later removal decision, and numerical accuracy respectively.

Its effective price also depends on units and loss normalization. Multiplying both mean loss and penalty by n preserves the solution; changing the mean to a sum without scaling the penalty changes its strength.

For centered squared-error Lasso, λmax is the largest absolute column–response correlation divided by n, at which all slope coefficients can be zero. The two printed values agree because the penalty is also multiplied by the observation count; leaving λ\lambda unchanged when switching from a mean to a sum changes the problem.

β1\beta_1β2\beta_2β3\beta_3
00.551.11.652.2-1012λβ
λ = 0.4β=(1.6,  −0.6,  0)\boldsymbol{\beta} = (1.6,\; -0.6,\; 0)

Figure 5: Regularization path. Orthogonal example: Sλ(a) coefficients shrink and vanish; a coefficient path is not a statistical importance ranking.

Jλ(θ)=F(θ)+λ∑j∈P∣θj∣,λmax⁡=∥XTyn∥∞. J_\lambda(\theta)=F(\theta)+\lambda\sum_{j\in P}|\theta_j|,\qquad \lambda_{\max}=\left\|\frac{X^Ty}{n}\right\|_\infty.
Read this equation in detail

Which parameters are charged?

The set P identifies penalized parameters; slopes may be included while the intercept is exempt. F measures fitting loss, and λ\lambda prices each unit of absolute magnitude.

Switching from mean to summed loss also requires multiplying λ\lambda by n to preserve the same problem.

Where does λmax come from?

For Lasso loss ‖y−Xβ‖₂²/(2n), the residual at β=0\beta=0 is y and the loss gradient is −Xᵀy/n. Zero can balance this gradient when every column–response correlation has magnitude at most λ.

Taking the largest magnitude gives the displayed infinity norm.

Which zero do we mean?

With centered X and y and a separate unpenalized intercept, λ\lambda≥λmax makes all slopes zero. Predictions can still equal the training response mean.

Feature units and loss normalization change λmax, so it is not a universal tuning recommendation.

python

Data We Can Recreate

Let us examine data we can reproduce, using the research report’s synthetic example. x2 is strongly correlated with x1, x3 is noise, and the response depends on x1 plus additional noise. Each row of X is an observation, each column a predictor, and y is what we want to predict.

Fix the seeds to repeat the experiment. Learn column means and scales from training alone, then apply them to an independent reference sample; subtract the training response mean to fit slopes without penalizing an intercept.

These numbers are for teaching. In an actual study, the reference sample should not become data used repeatedly to tune the model.

python

From Least Squares to Ridge and Lasso

Ordinary least squares, OLS, seeks β\beta making Xβ close to y. Differentiation gives the normal equations; independent columns allow an inverse formula, but in practice a stable numerical least-squares solver is preferable, and dependent columns can give nonunique coefficients.

Ridge adds half λ\lambda times squared L2L_{2}, shrinking weakly determined directions; Lasso adds λL1\lambda L_{1} and can set some coefficients to zero. Our data give approximately (2.0563, −0.1672, −0.0386) for OLS, (1.0626, 0.7356, −0.0325) for Ridge at 0.10, and (1.8211, 0, 0) for Lasso at 0.07.

Reference errors are close: 0.3862, 0.4051, and 0.3869. Different coefficient allocations need not mean substantially different predictions.

The code leaves solver details to the library so the comparison stays clear; we will unpack thresholding shortly. To see when every coefficient disappears, try multiples of λmax; at and above it, only the mean response remains in this centered model.

Ridge vs OLS

-7.71-7.71007.717.71OLS predictionRidge prediction

Lasso vs OLS

-7.71-7.71007.717.71OLS predictionLasso prediction
β^1\hat{\beta}_1β^2\hat{\beta}_2β^3\hat{\beta}_3Ref. MSE
OLS
2.0563
-0.1672
-0.0386
0.3862
Ridge
1.0626
0.7356
-0.0325
0.4051
Lasso
1.8211
0
0
0.3869

Figure 6: OLS, Ridge, and Lasso. Values are computed from the same data and seeds as the code; reference error is educational and is not used to choose λ.

β^OLS∈arg⁡min⁡β∥y−Xβ∥222n,β^R=(XTX+nλI)−1XTy,β^L∈arg⁡min⁡β{∥y−Xβ∥222n+λ∥β∥1}. \widehat\beta_{\rm OLS}\in\arg\min_\beta\frac{\|y-X\beta\|_2^2}{2n},\quad \widehat\beta_R=(X^TX+n\lambda I)^{-1}X^Ty,\quad \widehat\beta_L\in\arg\min_\beta\left\{\frac{\|y-X\beta\|_2^2}{2n}+\lambda\|\beta\|_1\right\}.
Read this equation in detail

Read the dimensions

X has n observation rows and d predictor columns; β\beta has d entries, so Xβ gives n predictions to compare with y. Squared L2L_{2} residual norm is the sum of squared errors.

Dividing by 2n gives an averaged loss with a convenient derivative. The argmin symbol denotes minimizing coefficient values rather than the minimum loss itself, and may describe multiple solutions.

Why add nλ to the matrix?

Ridge loss has gradient Xᵀ(Xβ−y)/n and its penalty has gradient λβ. Set their sum to zero and multiply by n to obtain (XᵀX+nλI)β\beta=Xᵀy.

For λ\lambda>0 the matrix is invertible even with dependent columns; solve the linear system rather than explicitly forming its inverse.

The distinction at zero

OLS fits without a penalty, Ridge adds a quadratic price, and Lasso a linear magnitude price. Lasso’s corner allows exact zeros and requires more than an ordinary derivative at zero.

Here data are centered and the intercept is handled separately; comparisons must preserve data and loss normalization.

python
python

How Does Zero Become a Solution

The absolute-value corner is what makes zero possible. Solve the one-number problem so the idea does not hide inside matrices: minimize (w−a)²/2+λ|w|, where a is the value preferred by the data alone.

If w is positive, the derivative is w−a+λ\lambda, giving a−λ\lambda when a>λ\lambda. If w is negative, the derivative is w−a−λ\lambda, giving a+λ\lambda when a<−λ\lambda.

At zero there is no single derivative, but there is a set of supporting slopes [−1, 1], the convex subdifferential. Zero is optimal exactly when |a|≤λ.

Soft-thresholding therefore removes values inside this interval and subtracts λ\lambda from the magnitudes that survive. Ridge instead gives a/(1+λ\lambda), ordinarily shrinking a nonzero value without removing it at finite λ\lambda.

-3-1.501.53-3-1.501.53Lasso estimateRidge estimateaŵ
OLSRidgeLasso
Lasso
w^L=Sλ(a)=0.6\hat w_L = S_\lambda(a) = 0.6
Ridge
w^R=a1+λ=0.7778\hat w_R = \frac{a}{1+\lambda} = 0.7778

Figure 7: Soft thresholding. Lasso maps a central interval to zero; Ridge continuously shrinks every nonzero coefficient.

∂∣w∣∣w=0=[−1,1],0∈−a+λ[−1,1],Sλ(a)=sign⁡(a)(∣a∣−λ)+,(x)+=max⁡(x,0). \partial|w|\big|_{w=0}=[-1,1],\qquad 0\in-a+\lambda[-1,1],\qquad S_\lambda(a)=\operatorname{sign}(a)(|a|-\lambda)_+,\quad (x)_+=\max(x,0).
Read this equation in detail

More than one supporting slope

The ∂ symbol denotes a convex subdifferential. At w=0, each g between −1 and 1 defines a line gw lying below |w| and passing through zero, giving the set [−1,1].

These are supporting slopes satisfying a definition, rather than arbitrary ordinary derivatives.

How can the set contain zero?

The fitting-loss derivative at zero is −a. Zero is optimal if a g in [−1,1] satisfies −a+λg=0.

For λ>0 this requires g=a/λ, allowed exactly when |a|≤λ. If λ=0\lambda=0, the unregularized solution is w=a.

Combine the cases

For a>λ\lambda the solution is a−λ\lambda; for a<−λ\lambda it is a+λ\lambda; between them it is zero. The positive-part operation keeps max(x,0), and sign restores direction.

Thus a=2 and λ=0.8\lambda=0.8 give 1.2, whereas a=0.5 gives zero. The boundary |a|=λ also gives zero.

python

The Balance at the Solution

Returning to a vector, we examine each coefficient’s relationship with the residual r=y−Xβ after joint fitting. The KKT conditions say that a column’s residual correlation equals λ\lambda times the sign of its nonzero coefficient; for a zero coefficient, the correlation may lie anywhere in [−λ\lambda, λ\lambda].

This balances fitting pressure against penalty pressure and certifies optimality for the convex problem. Coordinate descent isolates the current column’s effect, forms its partial residual, and computes correlation c_j and average squared column magnitude q_j.

The update is Sλ(c_j)/q_j. The solver does not guess a zero: the thresholding subproblem creates it.

A printed value near zero means the balance conditions hold numerically; it does not by itself tell us how the model will perform on new data.

xjTrn=λsign⁡(β^j) (β^j≠0),∣xjTrn∣≤λ (β^j=0),βj←Sλ(cj)qj. \frac{x_j^Tr}{n}=\lambda\operatorname{sign}(\widehat\beta_j)\ (\widehat\beta_j\ne0),\qquad \left|\frac{x_j^Tr}{n}\right|\le\lambda\ (\widehat\beta_j=0),\qquad \beta_j\leftarrow\frac{S_\lambda(c_j)}{q_j}.
Read this equation in detail

Pressure left by the residual

At a solution r=y−Xβ̂, column xⱼ contains predictor j’s observations. The quantity xⱼᵀr/n is its residual association under our normalization, not a standardized Pearson correlation.

The fitting gradient is its negative and must balance the penalty subgradient.

Active versus zero

For a nonzero coefficient, absolute value has slope sign(β\betâⱼ), giving equality with λ\lambda times that sign. At zero the allowable slopes span [−1,1], so association magnitude need only be ≤λ\lambda.

All-coordinate conditions certify convex Lasso optimality, not performance on new data.

Update one coordinate

Add the current column’s contribution back to the residual to form a partial residual. Set cⱼ=xⱼᵀr_partial/n and qⱼ=xⱼᵀxⱼ/n.

The scalar quadratic is qⱼβⱼ²/2−cⱼβⱼ; adding λ|βⱼ| gives Sλ(cⱼ)/qⱼ for qⱼ>0. If cⱼ=0.2 and λ=0.3\lambda=0.3, the update is zero regardless of positive qⱼ.

python

A Step That Reaches Zero

Following a slope directly may jump across the corner instead of landing on it. For |w|, starting at 0.03 with step 0.1 can alternate between 0.03 and −0.07.

Proximal gradient separates movement that reduces the smooth loss from handling the penalty: take a gradient step, then apply threshold ηλ. In the example below, (0.04, −0.20, 0) first becomes (0.03, −0.15, 0.06), then (0,−0.11,0.02)(0, -0.11, 0.02).

One entry disappears, another shrinks, and a previously zero entry returns. Zero is not permanent when the fitting gradient changes.

For a smooth convex loss with L-Lipschitz gradient, the usual condition 0<η≤1\eta\le 1/L supports the appropriate convergence results.

w(k+1)=Sηλ(w(k)−η∇F(w(k))). w^{(k+1)}=S_{\eta\lambda}\left(w^{(k)}-\eta\nabla F(w^{(k)})\right).
Read this equation in detail

Fit, then handle the penalty

The index k counts iterations, ∇F is the smooth-loss gradient, and η\eta is the step size. First compute v=w⁽ᵏ⁾−η\eta∇F(w⁽ᵏ⁾), a movement intended to reduce F.

Then solve a proximal problem balancing proximity to v against magnitude cost. Its L1L_{1} solution is soft thresholding at ηλ.

Why ηλ instead of λ\lambda?

The proximal objective is ‖w−v‖₂²/(2η)+λ‖w‖₁. Multiplying by η preserves the solution and gives threshold ηλ.

With η=0.1\eta=0.1 and λ=0.4\lambda=0.4, the threshold is 0.04 and (0.03,−0.15,0.06) becomes (0,−0.11,0.02)(0,-0.11,0.02).

Zero is not the end

A later fitting gradient may push a zero entry outside the threshold interval and reactivate it. Convergence needs assumptions on F and the step size; for convex F with L-Lipschitz gradient, 0<η≤1\eta\le 1/L is a usual choice.

This update does not grant a nonconvex network a global-minimum certificate.

python

How Accurate Is the Solution

After finding a solution, we need to know its numerical accuracy, a different question from prediction quality. In squared-error Lasso, a feasible dual value provides a lower bound for the original optimum; the primal–dual gap bounds remaining objective error.

The code builds a feasible dual vector from the residual and calculates that gap. Approaching zero means approaching the solution of this optimization problem, without certifying prediction quality.

Here both objectives approach approximately 0.3200; rounding can leave a tiny difference. The gap can also support safe screening of columns, but here we stay with our first question: has the numerical search finished?

0300600900120010⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰Current gapIterationPrimal–dual gap
Objective gap
Current gap
Pk−Dk=5.82×10−3P_k-D_k=5.82\times10^{-3}
Bounds on the optimum
Dk≤F∗≤PkD_k\leq F^*\leq P_k

Figure 8: Optimality gap. The gap between a primal objective and feasible dual value bounds objective error; the vertical scale is logarithmic and is not prediction error.

python

Choosing λ\lambda

Even an accurate solution can use an unsuitable λ\lambda, so choose regularization strength with observations kept out of fitting. Cross-validation divides training into folds, fits on some and evaluates on the rest.

Standardization must be learned within each training fold to prevent validation information leaking into preprocessing. Pipeline joins the steps and GridSearchCV searches λ\lambda, which Lasso calls alpha under the same normalization used here.

This example selects about 0.0297, but that number is not a general recommendation. If we estimate performance after tuning without an independent test sample, an outer evaluation such as nested validation is needed.

Temporal or grouped data need splits respecting their time or group structure.

python

Between Bias and Variance

Regularization’s statistical effect is not exhausted by counting zeros. Bias is the difference between an estimator’s mean over hypothetical samples and the true value; variance describes its changes across those samples.

Coefficient mean squared error combines squared bias and variance. We may accept bias to reduce variance, but excessive regularization increases error.

If a has mean 2 and variance 1, Ridge at λ=0.25\lambda=0.25 gives bias −0.4 and variance 0.64, reducing MSE from 1 to 0.8; at λ=3\lambda=3 it rises to 2.3125. With correlated columns, different coefficients may give nearly identical predictions.

Even Ridge flexibility is not simply its coefficient count: in the centered formulation, it is the sum of d_k2k^{2}/(d_k2k^{2}+nλ) over singular directions.

E[(β^−β⋆)2]=Bias⁡(β^)2+Var⁡(β^),df⁡R=∑kdk2dk2+nλ. \mathbb E[(\widehat\beta-\beta^\star)^2]=\operatorname{Bias}(\widehat\beta)^2+\operatorname{Var}(\widehat\beta),\qquad \operatorname{df}_{R}=\sum_k\frac{d_k^2}{d_k^2+n\lambda}.
Read this equation in detail

Estimation error across samples

The value β\beta★ is the true coefficient, while β\betâ varies across training samples. Split β\betâ−β\beta★ into (β\betâ−Eβ̂)+(Eβ̂−β\beta★), square, and take expectation.

The cross term vanishes because E(β\betâ−Eβ̂)=0, leaving variance plus squared bias. This is coefficient-estimation error; full prediction error can also include response noise.

Accept bias when more is saved

An unregularized estimator with mean 2 and variance 1, shrunk by 1/(1+0.25)=0.8, has bias −0.4 and variance 0.64. Its MSE is 0.16+0.64=0.8 instead of 1.

Excessive shrinkage can make squared bias exceed the variance saved.

Ridge flexibility by direction

The dₖ are singular values of centered X, not the predictor count. Each direction contributes dk2d_{k}²/(dk2d_{k}²+nλ), between 0 and 1 for λ\lambda>0.

Their sum gives fitted degrees of freedom excluding the intercept. Strong directions retain more flexibility.

At λ=0\lambda=0 use the limit on nonzero directions rather than a 0/0 expression.

python

Did We Choose the Right Variable

Recovering the true support is a third question, separate from prediction and coefficient estimation. A correlated predictor may replace a signal-generating predictor with little predictive loss, so a sparse support is not proof of the correct support, still less of causality.

Support-recovery theory requires conditions on the design, noise, sample size, signal strength, and tuning, including limits on how inactive predictors imitate active ones. We can inspect stability by refitting on subsamples and counting how often each variable is selected.

Frequencies around (1.000, 0.204, 0.188) over 250 half-samples illustrate the signal, proxy, and noise distinction, but are not Bayesian inclusion probabilities. Formal stability-selection guarantees require additional assumptions.

Ordinary confidence intervals after data-driven variable selection may also mislead unless the selection effect is addressed.

x₁ · Signal250 / 250 100.0%
x₂ · Proxy51 / 250 20.4%
x₃ · Noise47 / 250 18.8%

Figure 9: Selection stability. Selection at λ=0.07; vary the number of half-samples in the sequence fixed by seed 2026. Frequency is not a Bayesian inclusion probability.

python

Sparsity in the Representation

Sparsity need not live in the original numbers. A sound recording may have almost no zero samples yet contain only a few frequencies.

Write x=Da, where the columns of D are dictionary atoms and a gives their contributions: sparsity may lie in a. More atoms than signal dimensions make the dictionary overcomplete and representations potentially nonunique.

Basis Pursuit seeks the smallest L1L_{1} among representations satisfying the measurements, which differs from asking for the fewest atoms. The code expresses each coefficient as the difference of two nonnegative parts, turning absolute-value minimization into a linear program.

It recovers (1,0,0)(1, 0, 0) in the favorable example; one success is not a guarantee for every dictionary.

min⁡a∥a∥1subject toDa=x. \min_a\|a\|_1\quad\text{subject to}\quad Da=x.
Read this equation in detail

Signal, atoms, and coefficients

The signal x contains samples, columns of D are dictionary atoms, and a gives each atom’s contribution. Multiplying Da combines those atoms.

More atoms than signal dimensions can permit multiple representations, requiring a criterion to choose among them.

Fitting is an exact constraint

Subject to means the reconstruction must equal x; among feasible representations we minimize ‖a‖₁. In the supplied dictionary, (1,0,0)(1,0,0) produces (1,0)(1,0), while (0,−1,1)(0,-1,1) produces the same signal with magnitude cost 2 rather than 1.

A linear-programming reading

Write each aⱼ=aⱼ⁺−aⱼ⁻ with nonnegative parts and minimize their sum subject to D(a⁺−a⁻)=x. A minimum-cost solution need not keep both parts positive for the same entry, so their total realizes absolute value.

This minimizes L1L_{1} magnitude, not necessarily the number of atoms in every dictionary.

python

What the Measurements Cannot See

Compressed sensing measures y=Ax using fewer measurements than unknowns. Any h satisfying Ah=0 is invisible to the measurements, making x+h an alternative explanation; these directions form the null space.

For L1L_{1} to recover every signal with at most s active entries, the null-space property is necessary and sufficient: for every nonzero h in the null space and every set S of at most s positions, its L1L_{1} magnitude inside S must be smaller than outside S. If x is supported in S, the reverse triangle inequality gives the chain below, making every alternative more expensive.

In the favorable example, alternatives are (1−t, −t, t), with minimum cost at t=0. But A=[1, 2] and y=1 favor (0,0.5)(0, 0.5) over (1,0)(1, 0), although both are one-sparse.

Sparsity alone cannot replace missing information or correct unequal column prices. Notice that the measurement is unchanged while L1L_{1} cost falls from 1 to 0.5; that is why the solver chooses the alternative.

True signalCurrent candidateL₁ minimum

Recovery succeeds

Null-space condition holds∥hS∥1=1<2=∥hSc∥1\|h_S\|_1=1<2=\|h_{S^c}\|_1
012-0.400.51.1t
Current candidatez(0)=(1,0,0)z(0)=(1,0,0)
Unchanged measurementAz=(1,0)=yAz=(1,0)=y
Current L₁ cost1

Recovery fails

Null-space condition fails∥hS∥1=2>1=∥hSc∥1\|h_S\|_1=2>1=\|h_{S^c}\|_1
012-0.400.51.1t
Current candidatez(0)=(1,0)z(0)=(1,0)
Unchanged measurementAz=(1)=yAz=(1)=y
Current L₁ cost1

Figure 10: Recovery and failure. Every point on each path satisfies its measurements; minimum L1 chooses the original in the first example and an alternative in the second.

∥hS∥1<∥hSc∥1⟹∥x+h∥1≥∥x∥1−∥hS∥1+∥hSc∥1>∥x∥1. \|h_S\|_1<\|h_{S^c}\|_1\quad\Longrightarrow\quad \|x+h\|_1\ge\|x\|_1-\|h_S\|_1+\|h_{S^c}\|_1>\|x\|_1.
Read this equation in detail

What measurements cannot see

Assume x has support S, the positions of its nonzero entries, and nonzero h lies in the null space: Ah=0. Then x+h has identical measurements.

The complement Sᶜ contains positions outside the support, splitting h into hS and hSᶜ.

Read the inequality step by step

On S, the reverse triangle inequality gives ‖xS+hS‖₁≥‖xS‖₁−‖hS‖₁. Outside S, x is zero, so the whole quantity ‖hSᶜ‖₁ is added.

If that increase exceeds the amount h can remove inside S, the alternative costs more than x.

Every alternative matters

Checking one h does not establish recovery. To recover every signal supported on S, require the strict inequality for every nonzero null-space h.

For A=(1,2)(1,2), x=(1,0)(1,0), and h=(−1,0.5)(-1,0.5), the alternative is (0,0.5)(0,0.5); the condition fails because 1 is not less than 0.5.

python

When Noise Enters

With noise, we allow a measurement residual up to ε rather than demanding an exact match, as in Basis Pursuit Denoising. Under suitable conditions, such as a robust null-space property or restricted isometry approximately preserving sparse-vector lengths, reconstruction error can be controlled by noise and the tail of the best sparse approximation. σ_s(a)_1 is the smallest L1L_{1} error after retaining the s largest magnitudes.

A large tail or unsuitable measurements removes the same justification. The code calculates this tail; it does not verify the theorem’s assumptions or determine its constants.

min⁡a∥a∥1 subject to ∥Aa−y∥2≤ϵ,∥a^−a∥2≤Cϵ+Dσs(a)1s. \min_a\|a\|_1\ \text{subject to}\ \|Aa-y\|_2\le\epsilon,\qquad \|\widehat a-a\|_2\le C\epsilon+D\frac{\sigma_s(a)_1}{\sqrt{s}}.
Read this equation in detail

Leave room for noise

In y=Aa+e, e denotes measurement error. A bound ‖e‖₂≤ε motivates allowing residual norm at most ε instead of forcing a fit to noise.

Here a is the signal coefficient vector, â the recovered solution, and s the number of entries retained by the best sparse approximation.

Two sources of recovery error

The term Cε accounts for noise; Dσs(a)₁/√s accounts for the tail discarded by the best s-entry approximation. Sum magnitudes outside the largest s entries to obtain σs(a)₁.

For (3,−1,0.2,−0.1,0.05)(3,-1,0.2,-0.1,0.05) with s=2, the tail is 0.35 and its normalized value is about 0.2475 before the constant multiplier.

Where do guarantees come from?

Existence and values of positive C and D depend on assumptions on A, such as a sufficiently strong restricted-isometry condition. They cannot be chosen arbitrarily to guarantee every matrix.

Under the required conditions, exact sparsity and zero noise make the right side zero, giving exact recovery.

python

Where Do We Put Absolute Value

In images, the location of absolute value changes the story. Penalizing Hu−y changes how measurement errors are treated; penalizing a in u=Da favors a sparse representation; penalizing neighboring differences favors similar regions.

For readings (10,11,12,250,13)(10, 11, 12, 250, 13), squared-error fitting chooses the mean 59.2 while absolute-error fitting chooses the median 12, reducing domination by the extreme observation. This does not make L1L_{1} best for every noise process.

With an orthonormal dictionary, squared-error denoising plus L1L_{1} on a reduces to thresholding Dᵀy and reconstructing D Sλ(Dᵀy). This simple formula does not automatically extend to redundant dictionaries or general operators.

Then enlarge only the outlier: the mean follows it, while the median stays at 12 in this sample.

python
python

The Image and Its Neighboring Differences

Total variation, TV, measures how much neighbors differ, rather than their pixel intensities. The row (10,10,10,50,50,50)(10, 10, 10, 50, 50, 50) has no zero pixels, but differences (0,0,40,0,0)(0, 0, 40, 0, 0) are sparse.

Minimizing half the squared image error plus λTV encourages similar regions separated by fewer transitions. For two pixels, their mean stays unchanged and their difference becomes S₂λ(y2−y1): small differences disappear while a large edge may remain.

Full-image differences are coupled, so we cannot independently threshold every difference. Anisotropic TV sums |Dx u|+|Dy u|; isotropic TV sums the square roots of the squared components.

Too much TV can turn gradients into steps and erase fine texture. In a second experiment, increase λ\lambda for the two pixels until their difference vanishes at 1.5; what disappears is the difference, not the pixels.

uᵢ0204060123456|Du|020401–22–33–44–55–6
Observed rowTV estimate
u^=(10,10,10,50,50,50),∥Du^∥1=40\hat{u}=(10,10,10,50,50,50),\qquad \|D\hat{u}\|_1=40

Figure 11: Neighboring differences. The original row has one transition. The solution is the exact TV result for this six-entry row; we do not independently threshold a general image’s differences.

TV⁡(u)=∑i=1n−1∣ui+1−ui∣,min⁡u12∥u−y∥22+λTV⁡(u). \operatorname{TV}(u)=\sum_{i=1}^{n-1}|u_{i+1}-u_i|,\qquad \min_u\frac12\|u-y\|_2^2+\lambda\operatorname{TV}(u).
Read this equation in detail

Measure changes between neighbors

Entries uᵢ form the signal being estimated, while y is observed. Each uᵢ₊₁−uᵢ measures a neighboring change; TV sums their magnitudes.

The row (10,10,10,50,50,50)(10,10,10,50,50,50) has one nonzero difference of 40, despite every entry being nonzero.

Balance two pixels

For y=(10,13)(10,13), the mean is 11.5. Let δ\delta denote the estimated difference.

Fitting loss becomes (δ−3)²/4 and the penalty is λ|δ|, so δ̂=S₂λ(3). At λ=1\lambda=1 the difference is 1 and pixels are (11,12)(11,12); at λ≥1.5\lambda\ge 1.5 both become 11.5.

Neither pixel was asked to become zero.

Region size changes the threshold

In the six-entry row, each region has three entries, giving difference max(40−2λ/3,0) and merging at λ=60\lambda=60. General-image differences share pixels and must reconstruct one consistent signal; independent thresholding of every difference is not generally a TV solution.

python
python

Weights and Activations

The idea enters neural networks once we specify what should become small. A neuron computes z=wᵀx+b and applies an activation; ReLU gives max(0, z).

A weight is a stored trainable number, whereas an activation is a response varying with the input, so a zero activation does not mean a deleted weight. The usual weight penalty sums absolute values of every selected matrix or tensor entry.

It is not the induced matrix one-norm, which takes the largest column sum. A zero connection does not remove an entire neuron while other connections remain.

The code distinguishes the two measurements and compares scattered zeros with a whole zero row; the figure lets us switch patterns.

Input weights

WW
10.20-0.80.40.1
0.05-0.080.100.2-0.1
0.80-0.60.20.30
00.150.2-0.100.05
Exact zeros 6/24Zero rows 0/4

Entrywise L₁

Sλ(Wij)S_\lambda(W_{ij})
0.850.050-0.650.250
00000.050
0.650-0.450.050.150
000.05000
Exact zeros 14/24Zero rows 0/4

Row-group L₂

(1−λ/∥Wi,:∥2)+Wi,:\left(1-\lambda/\|W_{i,:}\|_2\right)_+W_{i,:}
0.890.180-0.710.360.09
0.02-0.030.0400.09-0.04
0.690-0.520.170.260
00.070.09-0.0500.02
Exact zeros 6/24Zero rows 0/4

Figure 12: Zero patterns. Compare element thresholds with row-group thresholds; deleting one connection differs from deleting a complete group. Values are rounded; ≈0 marks a small nonzero weight.

z=wTx+b,h=max⁡(0,z),∥W∥1,entry=∑i,j∣Wij∣,∥W∥1,induced=max⁡j∑i∣Wij∣. z=w^Tx+b,\quad h=\max(0,z),\qquad \|W\|_{1,\mathrm{entry}}=\sum_{i,j}|W_{ij}|,\quad \|W\|_{1,\mathrm{induced}}=\max_j\sum_i|W_{ij}|.
Read this equation in detail

From weights to activation

For a neuron, x contains inputs, w its weights, and wᵀx sums input–weight products. Add bias b to obtain z; ReLU returns z when positive and zero when negative.

An activation can be zero for one input without the stored weights becoming zero.

Two quantities with the same label

Entrywise matrix L1L_{1} adds every |Wᵢⱼ| as if flattening W into a vector. Induced L1L_{1} measures the largest input-norm amplification under multiplication by W and equals the largest absolute column sum.

The shared numeral does not make the quantities identical.

Calculate the distinction

For rows (1,0,−2)(1,0,-2) and (0,0.5,0)(0,0.5,0), entrywise magnitude is 3.5, while column sums are 1, 0.5, and 2, giving induced norm 2. Our neural-weight L1L_{1} penalty uses the entrywise sum; naming the convention avoids confusing the two penalties.

python

The Same Function with Different Weights

If we regularize activations using their average L1L_{1} across inputs, the penalty derivative reaches weights through the chain rule; we are no longer directly measuring stored weights. ReLU may respond to one input and switch off for another.

There is another reason not to read every small weight as low importance. In f(x)=b ReLU(ax), multiplying a by a positive c and dividing b by c preserves predictions while changing parameter magnitudes and their penalty.

Interpreting weights therefore requires the layers, units, and exclusions to be known. The example shows one function wearing different parameter magnitudes.

λn∑i∥hθ(xi)∥1,bReLU⁡(ax)=bcReLU⁡(cax)(c>0). \frac{\lambda}{n}\sum_i\|h_\theta(x_i)\|_1,\qquad b\operatorname{ReLU}(ax)=\frac bc\operatorname{ReLU}(cax)\quad(c>0).
Read this equation in detail

Penalize what a neuron does

The first term sums activation magnitudes hθ(xᵢ) across training examples and averages by n. It penalizes responses to those examples rather than weights directly.

A neuron may be silent for one input and active for another, so activation sparsity is different from weight sparsity.

Keep the function, change the weights

In this two-layer example, a multiplies the input before ReLU and b multiplies its output. For c>0, ReLU(cz)=cReLU(z); multiply the inner weight by c and divide the outer weight by c to preserve bReLU(ax).

The price is not preserved

With a=2 and b=3, total weight magnitude is 5. Taking c=4 changes weights to 8 and 0.75 and total magnitude to 8.75 without changing predictions.

Rescaling need not lower the penalty: it shows the penalty prices a particular function representation. Positivity of c is required for the identity.

python

From a Connection to a Channel

The goal may therefore be removal of entire groups, such as channels or filters, rather than individual connections. A group penalty adds L2L_{2} lengths of predefined groups and can zero a whole group.

Channel-scale regularization instead penalizes γ\gamma in h_c=γ_c ẑ_c+β_c. A zero γ\gamma removes the input-dependent component, but β\beta may leave a constant contribution; downstream effects must be traced before deleting the channel.

The complete network loss generally remains nonconvex, and SGD or Adam with penalty subgradients does not guarantee exact zeros. Regularization, proximal optimization, and pruning are different operations.

This code is a numerical illustration of thresholding weights and maintaining a fixed mask through one refinement step, rather than a full network-training protocol.

python

Has the Model Become Smaller and Faster

Distinguish four achievements that may hide beneath the word sparsity: small weights, actual zero weights, a smaller representation, and faster computation. The fraction with |w|≤τ is not the fraction of exact zeros, and a dense matrix keeps the same storage even when zeros multiply.

One million FP32 entries need 4,000,000 raw bytes. Keeping 100,000 entries in a 1000×1000 CSR matrix with 32-bit indices needs approximately 804,004 bytes for values, indices, and row pointers.

Sparse encoding may be larger at low sparsity, or slower because of indexing overhead. Removing 32 of 64 output channels from a 64×64×3×3 convolution reduces that layer from 36,864 to 18,432 weights once its shape is rebuilt; it does not prove a twofold model speedup.

Latency, throughput, and memory must be measured on the intended device.

DenseValues: 400,000 BColumn indices: 400,000 BRow pointers: 4,004 B
NCSR=nnz(bv+bi)+(m+1)biN_{\mathrm{CSR}}=n_{\mathrm{nz}}(b_v+b_i)+(m+1)b_i

Figure 13: Sparsity and storage. At 1000×1000 FP32, CSR storage breaks even with dense storage at about 50.1% exact zeros; these raw sizes do not predict runtime.

s0=#{j:wj=0}d,sτ=#{j:∣wj∣≤τ}d. s_0=\frac{\#\{j:w_j=0\}}{d},\qquad s_\tau=\frac{\#\{j:|w_j|\le\tau\}}{d}.
Read this equation in detail

Exact zeros and decided zeros

The dimension d counts weights and # counts entries meeting the condition. s₀ counts actual zeros; sτ counts magnitudes at most τ≥0\tau\ge 0, including small nonzeros. Dividing by d produces a fraction between 0 and 1, which can be multiplied by 100 for a percentage.

An example exposes the gap

Weights (0.003,−0.2,0.07,−0.0001) contain no exact zeros, so s₀=0. At τ=0.01\tau=0.01, two entries meet the threshold and sτ=0.5\tau=0.5.

Explicitly pruning those two then makes exact sparsity 0.5; the pre-pruning measurement differs from the operation’s result.

What the count does not tell us

Increasing τ\tau raises the small-weight count without automatically improving the model. Zeros may remain in dense storage, sparse storage needs indices, and hardware may not exploit them.

Measure size, latency, and prediction quality separately from this fraction.

python

When L1L_{1} and L2L_{2} Meet

When one preference is insufficient, change the penalty to fit the need. Elastic Net combines L1L_{1} with squared L2L_{2}.

In the following convention α=1\alpha=1 returns Lasso and α=0\alpha=0 returns Ridge. For identical predictors, (c, 0) and (c/2, c/2) have identical predictions and the same L1L_{1} charge when c is positive, but the quadratic term prefers the balanced allocation.

In coordinate descent, thresholding stays in the numerator while λ\lambda(1−α\alpha) enters the denominator to provide quadratic shrinkage. Here α\alpha is the mixing fraction; alpha in the earlier Lasso software was λ\lambda.

Recognizing the letter cannot replace reading its definition. Use two identical predictors in the next experiment: Lasso permits different allocations of the same total, while the quadratic term favors an equal split.

min⁡β∥y−Xβ∥222n+λ[α∥β∥1+1−α2∥β∥22],βj←Sλα(cj)qj+λ(1−α). \min_\beta\frac{\|y-X\beta\|_2^2}{2n}+\lambda\left[\alpha\|\beta\|_1+\frac{1-\alpha}{2}\|\beta\|_2^2\right],\qquad \beta_j\leftarrow\frac{S_{\lambda\alpha}(c_j)}{q_j+\lambda(1-\alpha)}.
Read this equation in detail

Specify the mixture

Here α\alpha between 0 and 1 is the L1L_{1} fraction and 1−α\alpha the quadratic fraction. At α=1\alpha=1 we obtain Lasso; at α=0\alpha=0, Ridge under this normalization. λ≥0\lambda\ge 0 scales both.

Some sources define the mixture differently, so inspect the formula before transferring parameter names.

How does the coordinate update change?

The coordinate fitting term is qⱼβⱼ²/2−cⱼβⱼ. The quadratic penalty increases curvature by λ\lambda(1−α\alpha), while the linear penalty sets threshold λα.

Threshold cⱼ and divide by qⱼ+λ\lambda(1−α\alpha), assuming a positive denominator.

Why split identical predictors?

If prediction depends on the sum of two positive coefficients, (2,0)(2,0) and (1,1)(1,1) give the same sum and L1L_{1}. Their squared magnitudes differ: 4 versus 2.

The quadratic term favors sharing. This explains grouping without imposing predefined groups as Group Lasso does.

python
python

Different Prices and Whole Groups

Prices may also differ across coefficients. Weighted L1L_{1} multiplies each magnitude by ω_j, while Adaptive Lasso derives those weights from an initial estimate, often (|β̃_j|+ε)^−γ.

Initially strong signals may receive less shrinkage, but a misleading initial estimate can mislead the weights, and oracle-property results are conditional. Group Lasso penalizes each group’s length; in its isolated proximal problem it multiplies the entire group by (1−λ/||a||2)+.

Sparse Group Lasso allows both group removal and zeros within surviving groups. For nonoverlapping groups in a Euclidean proximal subproblem, apply elementwise thresholding first and group shrinkage second.

The code illustrates the distinction without assuming that all groups are independent in a general fitting problem.

λ∑jωj∣βj∣,∑gλg∥βGg∥2,prox⁡λ∥⋅∥2(a)=(1−λ∥a∥2)+a. \lambda\sum_j\omega_j|\beta_j|,\qquad \sum_g\lambda_g\|\beta_{G_g}\|_2,\qquad \operatorname{prox}_{\lambda\|\cdot\|_2}(a)=\left(1-\frac{\lambda}{\|a\|_2}\right)_+a.
Read this equation in detail

Different prices for individuals

Nonnegative weights ωⱼ give coefficients different prices in λΣωⱼ|βⱼ|. If derived from preliminary estimates, small preliminary coefficients may receive larger prices.

For example 1/(|βⱼ_initial|+ε) avoids division by zero, but constructing estimates and prices is a methodological choice, not an automatic selection guarantee.

A group pays together

Group Gg contains coefficients whose Euclidean magnitude is penalized jointly at price λg. Group L2L_{2} can remove the entire weak group, but does not force every small entry inside a surviving group to zero.

Move the group toward zero

The proximal map minimizes ‖w−a‖₂²/2+λ‖w‖₂. If ‖a‖₂≤λ, choose zero; otherwise preserve direction and reduce length by λ, giving factor 1−λ/‖a‖₂.

Define the result as zero at a=0 without dividing. This is a single-group proximal formula; overlapping groups require additional handling.

python

When Order Matters

When order matters, Fused Lasso combines penalties on magnitudes and neighboring differences, favoring zeros and constant regions according to the two strengths. We can also constrain coefficients to be nonnegative when that suits the phenomenon; the scalar proximal threshold becomes max(a−λ\lambda, 0), not because negative values are inherently wrong.

Nonconvex penalties try to reduce shrinkage bias or change sparsity preferences, but give up some convex guarantees. Method choice begins with the meaning of groups, adjacency, signs, and the target, rather than a contest for the largest zero count.

λ1∑j∣wj∣+λ2∑j=2d∣wj−wj−1∣. \lambda_1\sum_j|w_j|+\lambda_2\sum_{j=2}^{d}|w_j-w_{j-1}|.
Read this equation in detail

Carry two prices

λ₁ prices values themselves and λ₂ prices each difference from the previous entry. The second sum starts at j=2 so a previous entry exists.

Ordering must be meaningful, such as time or pixel position; permuting entries may preserve the first penalty while changing the second.

What does a zero difference mean?

A zero difference means adjacent entries agree, not that either is zero. For (0,0,2,2,2)(0,0,2,2,2), total magnitude is 6 and total absolute difference 2.

With λ₁=0.1 and λ₂=0.4, the penalty is 0.6+0.8=1.4, separate from fitting loss omitted here.

Why solve jointly?

Each entry participates in its own magnitude and neighboring differences. Independently removing small differences does not generally solve the joint problem.

The penalty encourages constant pieces and possibly zero values; fitting loss and both prices determine the actual pieces.

python

Simplicity in the Directions

Simplicity may therefore lie in directions rather than entries. In SVD we write M=U diag(σ_i)Vᵀ.

The columns of U and V are orthonormal directions, and the singular values σ_i are their magnitudes. Rank counts nonzero singular values; the nuclear norm sums them.

A 2×2 all-ones matrix is dense but rank one, whereas the identity contains zeros and has rank two. Minimizing half the squared Frobenius error plus τ||W||* soft-thresholds singular values, removing directions and shrinking survivors.

This differs from truncated SVD, which keeps the largest k singular values unchanged. In our example, (3.1648, 0.3792) becomes (2.4648, 0) at τ=0.7\tau=0.7, reducing rank to one.

Computational savings still require suitable low-rank factors and execution rather than a same-sized stored matrix.

Nuclear norm · soft shrinkage

(σi−τ)+(\sigma_i-\tau)_+
σ1\sigma_13.1648 → 2.4648
σ2\sigma_20.3792 → 0
Rank1Nuclear norm2.4648

Rank 1 · truncation

(σ1,0)(\sigma_1,0)
σ1\sigma_13.1648 → 3.1648
σ2\sigma_20.3792 → 0
Rank1Nuclear norm3.1648
Original valueRetained · Nuclear norm · soft shrinkageRetained · Rank 1 · truncation

Figure 14: Singular-value shrinkage. Soft thresholding reduces every surviving singular value by τ; rank-1 truncation keeps the largest one unchanged.

∥M∥∗=∑iσi,min⁡W12∥W−M∥F2+τ∥W∥∗,W^=Udiag⁡((σi−τ)+)VT. \|M\|_* =\sum_i\sigma_i,\qquad \min_W\frac12\|W-M\|_F^2+\tau\|W\|_*,\qquad \widehat W=U\operatorname{diag}((\sigma_i-\tau)_+)V^T.
Read this equation in detail

Simplicity in directions

Write M=UΣVᵀ with singular values σi≥0\sigmaᵢ\ge 0. The nuclear norm sums them, whereas rank counts the nonzero ones.

Squared Frobenius error sums squared matrix-entry errors. Here W should stay close to M while paying price τ≥0\tau\ge 0 for total singular magnitude.

From scalar to singular-value thresholds

For this quadratic Frobenius problem, orthogonal invariance allows the solution’s directions to align with U and V. Each singular value then solves (s−σᵢ)²/2+τs with s≥0, yielding max(σᵢ−τ\tau,0).

Reconstruct W using the new values and unchanged directions.

Shrinkage is not fixed-rank truncation

Values about 3.1648 and 0.3792 become 2.4648 and 0 at τ=0.7\tau=0.7, reducing rank to 1. Rank-1 truncated SVD instead keeps 3.1648 unchanged and removes the second value, solving a different problem with potentially smaller Frobenius error.

This threshold formula does not directly solve arbitrary matrix-measurement losses.

python

A Probabilistic Reading of Regularization

Regularization also has a probabilistic reading. Under suitable likelihood and normalization conventions, a Gaussian prior gives a quadratic penalty and independent Laplace priors give an absolute-value penalty for MAP estimation, the point of highest posterior density.

A sparse posterior mode does not mean that draws from the continuous posterior have positive probability of landing exactly at zero; a point mass there requires a different model, such as spike-and-slab. Not all regularization methods are norm penalties: early stopping chooses a point along a learning trajectory, dropout changes activations during training, and data augmentation encodes acceptable input transformations.

Their connection is the preference they introduce into learning, rather than one formula containing them all. In the code, compare the increase from 0 to 1 with the increase from 1 to 2: the quadratic penalty grows more, while absolute value increases by the same amount.

p(βj)∝e−βj2/(2s2)orp(βj)∝e−∣βj∣/b. p(\beta_j)\propto e^{-\beta_j^2/(2s^2)}\quad\text{or}\quad p(\beta_j)\propto e^{-|\beta_j|/b}.
Read this equation in detail

What does proportionality omit?

The ∝ symbol gives a density’s shape while omitting a normalization factor independent of βⱼ. Gaussian scale s>0 is its standard deviation; Laplace has scale b>0.

Both are centered at zero but price distance from it differently.

From a density to a penalty

Negative logarithms turn the exponentials into βⱼ²/(2s22s^{2}) or |βⱼ|/b plus constants. Independent coefficient priors make these terms additive.

Add them to negative log likelihood for a MAP objective; determining λ\lambda also requires noise scale and likelihood-loss normalization.

A peak is not a point mass

The MAP estimate can be exactly zero because of the penalty’s corner, while a continuous Laplace prior assigns zero probability to any single point, as Gaussian density does. MAP coefficients alone do not describe posterior uncertainty.

A sparse estimate and a complete probability distribution are different objects.

python

What Does the Result Establish

We still need to read a result within what it actually establishes. Multiply a predictor column by c and divide its coefficient by c to preserve predictions, and its L1L_{1} price changes by 1/|c|; feature scale therefore affects selection.

Identical columns may give multiple Lasso coefficient allocations with identical predictions, and surviving coefficients remain shrunk, introducing bias. L1L_{1} on weights does not automatically give the robustness of L1L_{1} residual loss, and zero differences do not mean the same thing as zero pixels or channels.

State what was penalized, how loss and feature scales were handled, how the problem was solved and tuned, and what zero means. Then evaluate prediction, stability, size, and time separately.

The bird has chosen its branches, but the nest must still work; likewise, the word sparse is insufficient until we know why the solution became sparse and what it achieved. Turn the change of units into an actual fit: enlarge one of two orthogonal columns, then standardize them; the selection change here comes from the price of units.

python
python

References

The sources are listed in APA 7 style. DOI links point to the published records.

Beck, A., & Teboulle, M. (2009). A fast iterative shrinkage-thresholding algorithm for linear inverse problems. SIAM Journal on Imaging Sciences, 2(1), 183–202. https://doi.org/10.1137/080716542

Boyd, S. (n.d.). ℓ1-norm methods for convex-cardinality problems [Lecture slides]. Stanford University. https://web.stanford.edu/class/ee364b/lectures/l1_methods_slides.pdf

Cai, J.-F., Candès, E. J., & Shen, Z. (2010). A singular value thresholding algorithm for matrix completion. SIAM Journal on Optimization, 20(4), 1956–1982. https://doi.org/10.1137/080738970

Candès, E. J., Romberg, J., & Tao, T. (2006). Robust uncertainty principles: Exact signal reconstruction from highly incomplete frequency information. IEEE Transactions on Information Theory, 52(2), 489–509. https://doi.org/10.1109/TIT.2005.862083

Chen, S. S., Donoho, D. L., & Saunders, M. A. (1998). Atomic decomposition by basis pursuit. SIAM Journal on Scientific Computing, 20(1), 33–61. https://doi.org/10.1137/S1064827596304010

Donoho, D. L. (2006). Compressed sensing. IEEE Transactions on Information Theory, 52(4), 1289–1306. https://doi.org/10.1109/TIT.2006.871582

Fercoq, O., Gramfort, A., & Salmon, J. (2015). Mind the duality gap: Safer rules for the Lasso. In F. Bach & D. Blei (Eds.), Proceedings of the 32nd International Conference on Machine Learning (Vol. 37, pp. 333–342). PMLR. https://proceedings.mlr.press/v37/fercoq15.html

Friedman, J., Hastie, T., & Tibshirani, R. (2010). Regularization paths for generalized linear models via coordinate descent. Journal of Statistical Software, 33(1), 1–22. https://doi.org/10.18637/jss.v033.i01

Hoerl, A. E., & Kennard, R. W. (1970). Ridge regression: Biased estimation for nonorthogonal problems. Technometrics, 12(1), 55–67. https://doi.org/10.1080/00401706.1970.10488634

Lee, J. D., Sun, D. L., Sun, Y., & Taylor, J. E. (2016). Exact post-selection inference, with application to the Lasso. The Annals of Statistics, 44(3), 907–927. https://doi.org/10.1214/15-AOS1371

Meinshausen, N., & Bühlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 72(4), 417–473. https://doi.org/10.1111/j.1467-9868.2010.00740.x

Parikh, N., & Boyd, S. (2014). Proximal algorithms. Foundations and Trends in Optimization, 1(3), 127–239. https://doi.org/10.1561/2400000003

Scardapane, S., Comminiello, D., Hussain, A., & Uncini, A. (2017). Group sparse regularization for deep neural networks. Neurocomputing, 241, 81–89. https://doi.org/10.1016/j.neucom.2017.02.029

Tibshirani, R. (1996). Regression shrinkage and selection via the Lasso. Journal of the Royal Statistical Society: Series B (Methodological), 58(1), 267–288. https://doi.org/10.1111/j.2517-6161.1996.tb02080.x

Wainwright, M. J. (2009). Sharp thresholds for high-dimensional and noisy sparsity recovery using ℓ1-constrained quadratic programming (Lasso). IEEE Transactions on Information Theory, 55(5), 2183–2202. https://doi.org/10.1109/TIT.2009.2016018

Wen, W., Wu, C., Wang, Y., Chen, Y., & Li, H. (2016). Learning structured sparsity in deep neural networks. In D. D. Lee, M. Sugiyama, U. von Luxburg, I. Guyon, & R. Garnett (Eds.), Advances in Neural Information Processing Systems 29 (pp. 2074–2082). Curran Associates. https://proceedings.neurips.cc/paper/2016/hash/41bfd20a38bb1b0bec75acf0845530a7-Abstract.html

Williams, P. M. (1995). Bayesian regularization and pruning using a Laplace prior. Neural Computation, 7(1), 117–143. https://doi.org/10.1162/neco.1995.7.1.117

Yuan, M., & Lin, Y. (2006). Model selection and estimation in regression with grouped variables. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(1), 49–67. https://doi.org/10.1111/j.1467-9868.2005.00532.x

Zhao, P., & Yu, B. (2006). On model selection consistency of Lasso. Journal of Machine Learning Research, 7, 2541–2563. https://jmlr.org/papers/v7/zhao06a.html

Zou, H. (2006). The adaptive Lasso and its oracle properties. Journal of the American Statistical Association, 101(476), 1418–1429. https://doi.org/10.1198/016214506000000735

Zou, H., & Hastie, T. (2005). Regularization and variable selection via the elastic net. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 67(2), 301–320. https://doi.org/10.1111/j.1467-9868.2005.00503.x

Read more