Search

Search papers and lessons

L1 Minimization

Level 3 · 10 min read

L1 minimization fits a model while penalising the sum of absolute values of its parameters, which tends to set many of them exactly to zero and so picks out a few important ones.

On this page

  • Colour = topic mix
  • Optimization
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

Many problems ask for a vector x\mathbf{x} that fits some data while staying simple. L1 minimization measures simplicity by the sum of absolute values, ∥x∥1=∑i∣xi∣\|\mathbf{x}\|_1 = \sum_i |x_i|, and minimises that sum, either as a penalty or under a constraint. Unlike the squared penalty, it tends to push many entries to exactly zero. The result is a sparse answer that says which few inputs matter.

Where you'll see it: in the lasso for sparse regression, in compressed sensing that reconstructs images from few measurements, and in robust fitting that ignores outliers.

Intuition

Why absolute values make zeros

Suppose you must pick a point on a line, and you want the point that is "small". If smallness is measured by the squared norm, the best point is pulled toward zero smoothly, and rarely lands on it. If smallness is measured by the absolute value of each coordinate, the cost has a sharp corner exactly at zero. Sharp corners are where optimal solutions tend to land, because a sharp corner gives a cheap way to set a coordinate to zero and pay nothing for it.

The picture below shows the soft-thresholding map that this produces, which is the basic step of the lasso.

−3−2−10123−3−2−10123unpenalised estimate ypenalised estimate x
  • soft threshold, λ = 1
  • no penalty
The L1 penalty shrinks every estimate toward zero by a fixed amount and sets anything within that amount of zero exactly to zero. The flat stretch around 0 is where sparsity comes from.

Two shapes of penalty

Picture the set of points with ∥x∥1≤1\|\mathbf{x}\|_1 \le 1 in two dimensions. It is a diamond with corners on the axes. The set with ∥x∥2≤1\|\mathbf{x}\|_2 \le 1 is a smooth circle. Now slide a straight line of candidate solutions toward the origin until it just touches the shape. A circle is usually touched on its side, at a point where neither coordinate is zero. A diamond is usually touched at a corner, where one coordinate is exactly zero. The rest of the math makes this precise.

The math

Definitions

For a vector x∈Rn\mathbf{x} \in \mathbb{R}^n, the L1 norm is

∥x∥1=∑i=1n∣xi∣,\|\mathbf{x}\|_1 = \sum_{i=1}^{n} |x_i|,

the sum of the absolute values of the entries. Each xix_i is one coordinate, and ∣xi∣|x_i| is its distance from zero. The L1 norm is a norm, so it is nonnegative, zero only for the zero vector, and satisfies the triangle inequality.

Definition: L1 minimization problem

Given a matrix AA and a vector b\mathbf{b}, find

min⁡x  ∥x∥1subject toAx=b.\min_{\mathbf{x}} \; \|\mathbf{x}\|_1 \quad \text{subject to} \quad A\mathbf{x} = \mathbf{b}.

This is called basis pursuit. The penalised version, min⁡x12∥Ax−b∥22+λ∥x∥1\min_{\mathbf{x}} \tfrac{1}{2}\|A\mathbf{x} - \mathbf{b}\|_2^2 + \lambda\|\mathbf{x}\|_1 with λ>0\lambda \gt 0, is the lasso.

In the constrained form, Ax=bA\mathbf{x} = \mathbf{b} says the answer must fit the measurements exactly. The objective ∥x∥1\|\mathbf{x}\|_1 then chooses, among all exact fits, the one with the smallest total absolute size. In the lasso, λ\lambda trades fit against sparsity: larger λ\lambda gives sparser answers with worse fit.

Convexity

The L1 norm is a convex function. Each ∣xi∣|x_i| is convex, because it is the maximum of the two linear functions xix_i and −xi-x_i, and a maximum of convex functions is convex. A sum of convex functions is convex. The constraint Ax=bA\mathbf{x} = \mathbf{b} is linear, so basis pursuit is a convex problem. Every local minimum is therefore global, and efficient algorithms exist.

Reformulation as a linear program

Write each entry as a difference of two nonnegative numbers, xi=ui−vix_i = u_i - v_i with ui,vi≥0u_i, v_i \ge 0. At the optimum, ∣xi∣=ui+vi|x_i| = u_i + v_i. Then basis pursuit becomes

min⁡u,v≥0  ∑i(ui+vi)subject toA(u−v)=b.\min_{\mathbf{u}, \mathbf{v} \ge 0} \; \sum_i (u_i + v_i) \quad \text{subject to} \quad A(\mathbf{u} - \mathbf{v}) = \mathbf{b}.

The objective and constraints are linear, so this is a linear program. It can be solved with standard tools for linear programming.

The soft-thresholding formula

The one-dimensional lasso problem has a closed form. Minimise 12(x−y)2+λ∣x∣\tfrac{1}{2}(x - y)^2 + \lambda|x| over a real xx, for a fixed yy and λ>0\lambda \gt 0. The absolute value has no derivative at zero, so use the subgradient. The optimality condition is

x−y+λs=0,where s=sign⁡(x) if x≠0, and s∈[−1,1] if x=0.x - y + \lambda s = 0, \quad \text{where } s = \operatorname{sign}(x) \text{ if } x \neq 0, \text{ and } s \in [-1, 1] \text{ if } x = 0.

If ∣y∣≤λ|y| \le \lambda, the solution is x=0x = 0, because then s=y/λs = y/\lambda fits inside [−1,1][-1, 1]. Otherwise x=y−λ sign⁡(y)x = y - \lambda\,\operatorname{sign}(y). Together:

x⋆=sign⁡(y) max⁡(∣y∣−λ, 0).x^\star = \operatorname{sign}(y)\,\max(|y| - \lambda,\ 0).

This is the function in the plot above. With orthonormal feature columns (uncorrelated, unit length), the lasso solution is exactly this rule applied to each least-squares coefficient. In general it is applied coordinate by coordinate inside an iterative solver.

Why the solution is sparse

Basis pursuit always has a solution at a vertex of the feasible region of the linear program above (when a solution exists). Intuitively, the level sets of ∥x∥1\|\mathbf{x}\|_1 are diamond-shaped polytopes with corners on the coordinate axes, and a linear constraint generically meets such a shape at a corner. A corner has zeros in all but a few coordinates, so the answer has at most as many nonzero entries as there are constraints. The L2 norm has no corners, so its minimiser generically has no zeros. This contrast is the heart of the lesson.

Worked examples

Example
Sparse versus dense on a line

Find the point on the line x1+2x2=4x_1 + 2x_2 = 4 with the smallest L1 norm, and compare with the smallest L2 norm.

  1. Parametrise the line as x1=4−2x2x_1 = 4 - 2x_2, so the L1 norm is ∣4−2x2∣+∣x2∣|4 - 2x_2| + |x_2|.
  2. Try x2∈[0,2]x_2 \in [0, 2], where x1=4−2x2≥0x_1 = 4 - 2x_2 \ge 0. The norm is 4−2x2+x2=4−x24 - 2x_2 + x_2 = 4 - x_2, which decreases as x2x_2 grows. Its smallest value on this range is at x2=2x_2 = 2, giving x=(0,2)\mathbf{x} = (0, 2) with norm 2.
  3. For x2<0x_2 \lt 0, the norm is 4−2x2−x2=4−3x2>44 - 2x_2 - x_2 = 4 - 3x_2 \gt 4, which is worse. For x2>2x_2 \gt 2, x1x_1 is negative and the norm is (2x2−4)+x2=3x2−4>2(2x_2 - 4) + x_2 = 3x_2 - 4 \gt 2, also worse.
  4. So the L1 minimiser is (0,2)(0, 2). It has a zero, and only one input is used.
  5. For the L2 norm, the closest point to the origin on the line is the projection of (0,0)(0, 0), which is 45(1,2)=(0.8,1.6)\frac{4}{5}(1, 2) = (0.8, 1.6), with squared norm 3.23.2. Both coordinates are nonzero.
  6. Interpretation: the L1 answer names one input, while the L2 answer spreads weight over both.
Example
Lasso with one feature

Take y=3y = 3 with penalty λ=1\lambda = 1, and y=0.4y = 0.4 with the same penalty.

  1. For y=3y = 3: ∣y∣=3>λ|y| = 3 \gt \lambda, so x⋆=sign⁡(3)(3−1)=2x^\star = \operatorname{sign}(3)(3 - 1) = 2.
  2. For y=0.4y = 0.4: ∣y∣=0.4≤λ=1|y| = 0.4 \le \lambda = 1, so x⋆=0x^\star = 0.
  3. Check the first case with the optimality condition: x−y+λs=2−3+1⋅1=0x - y + \lambda s = 2 - 3 + 1 \cdot 1 = 0, with s=1s = 1 since x>0x \gt 0. It holds.
  4. Interpretation: the lasso shrinks a strong signal by λ\lambda and removes a weak one entirely. The second case is where sparsity comes from.
Example
Robust centre: the median, not the mean

Five measurements are 1,2,3,4,1001, 2, 3, 4, 100. Find the constant cc that minimises ∑i∣xi−c∣\sum_i |x_i - c|, and compare with minimising ∑i(xi−c)2\sum_i (x_i - c)^2.

  1. Minimising the sum of squares gives the mean: (1+2+3+4+100)/5=22(1 + 2 + 3 + 4 + 100)/5 = 22.
  2. Minimising the sum of absolute deviations gives the median. The middle value of the sorted list is 33.
  3. Check: at c=3c = 3 the sum is 2+1+0+1+97=1012 + 1 + 0 + 1 + 97 = 101. At c=22c = 22 it is 21+20+19+18+78=15621 + 20 + 19 + 18 + 78 = 156, which is larger.
  4. Interpretation: the outlier 100 pulls the mean to 22, but it has only a bounded effect on the L1 fit. This is the reason least absolute deviation is used for robust fitting.

Tradeoffs and failure modes

L1 minimization is powerful when its assumptions hold, and it can mislead when they do not.

SituationWhat goes wrongBetter choice
Features are strongly correlatedThe lasso picks one of a correlated group more or less arbitrarilyElastic net, which mixes the L1 and L2 penalties
Solution should be dense (many small effects)L1 zeroes out real but small effectsL2 regularization, which shrinks everything smoothly
Measurements are noisy, not exactBasis pursuit with exact equality can overfit the noiseThe lasso with a tuned λ\lambda, or a constraint with a noise tolerance
Large λ\lambda chosen blindlyToo much shrinkage biases the nonzero coefficients toward zeroChoose λ\lambda by cross-validation
Very large problemsGeneric linear programming solvers can be slowIterative methods such as proximal gradient descent with soft-thresholding

A common mistake is reading the nonzero coefficients of a lasso fit as causal effects. The L1 penalty chooses a sparse set of predictors, but a different sample or a correlated predictor can produce a different set.

History

Least absolute deviation fitting is older than the L2 method. Pierre-Simon Laplace considered it in the late eighteenth century, when he was comparing ways to combine astronomical measurements. It was used again in geophysics in the 1970s, where robustness to outliers in seismic data was valued.

The modern wave started with Robert Tibshirani's lasso in 1996, which applied the L1 penalty to regression to get sparse, interpretable models. Shaobing Chen, David Donoho and Michael Saunders introduced basis pursuit in 1998 for signal decomposition. Around 2004 to 2006, work by Emmanuel Candès, Terence Tao, Justin Romberg and David Donoho showed that a signal can be recovered exactly from far fewer measurements than its length, if it is sparse and the measurements are random enough. That result, compressed sensing, made L1 minimization a standard tool in imaging and signal processing.

Check yourself

QuestionWhy does minimising ∥x∥1\|\mathbf{x}\|_1 over a line tend to give a solution with zeros, while minimising ∥x∥2\|\mathbf{x}\|_2 does not?Show answer

The level sets of the L1 norm are polytopes with corners on the coordinate axes. A line generically touches such a shape at a corner, where some coordinates are zero. The L2 level sets are smooth spheres, so the touching point generically has every coordinate nonzero.

QuestionFind the lasso solution for y=−2.5y = -2.5 with penalty λ=1\lambda = 1.Show answer

Since ∣y∣=2.5>1|y| = 2.5 \gt 1, the formula gives x⋆=sign⁡(−2.5) max⁡(2.5−1,0)=−1.5x^\star = \operatorname{sign}(-2.5)\,\max(2.5 - 1, 0) = -1.5. Check: x−y+λs=−1.5+2.5+1⋅(−1)=0x - y + \lambda s = -1.5 + 2.5 + 1 \cdot (-1) = 0, with s=sign⁡(x)=−1s = \operatorname{sign}(x) = -1. The condition holds.

QuestionWhy is basis pursuit a convex problem even though the absolute value has a corner at zero?Show answer

Each ∣xi∣|x_i| is the maximum of the linear functions xix_i and −xi-x_i, so it is convex even with its corner. A sum of convex functions is convex, and the equality constraint is linear, so the whole problem is convex. Its local minima are therefore global.

QuestionA dataset has one outlier far from the rest. Would you expect an L1 fit or an L2 fit of a constant to move more toward the outlier, and why?Show answer

The L2 fit, which is the mean, moves toward the outlier, because squared deviations give it a large weight. The L1 fit, which is the median, moves only a little, because the absolute deviation grows linearly and the median depends only on the ordering of the points. This is why L1 fits are called robust.

Sources