TExcelTAD
Home › Optimization › The Lasso with ISTA and FISTA

The Lasso with ISTA and FISTA

The lasso fits a linear model with an L1 penalty,

min⁡w 12∥Xw−y∥2+λ∥w∥1\min_{\mathbf{w}}\ \frac{1}{2}\lVert X\mathbf{w} - \mathbf{y} \rVert^2 + \lambda\lVert \mathbf{w} \rVert_1

and produces sparse models: many coefficients exactly zero. It is the standard example of a smooth-plus-nonsmooth problem. ISTA is proximal gradient applied to it; FISTA adds Nesterov's momentum and improves the rate from O(1/k)O(1/k) to O(1/k2)O(1/k^2) at no extra cost per iteration.

ISTA

The smooth part has gradient XT(Xw−y)X^T(X\mathbf{w} - \mathbf{y}) and Lipschitz constant L=∥X∥22L = \lVert X \rVert_2^2; the prox of λ∥⋅∥1\lambda\lVert \cdot \rVert_1 is soft thresholding:

wk+1=Sλ/L(wk−1LXT(Xwk−y))\mathbf{w}_{k+1} = S_{\lambda/L}\left(\mathbf{w}_k - \frac{1}{L}X^T(X\mathbf{w}_k - \mathbf{y})\right)

"Iterative shrinkage-thresholding algorithm": a gradient step, then shrink every coefficient toward zero.

FISTA

Beck and Teboulle's FISTA extrapolates before each step:

wk+1=Sλ/L(zk−1LXT(Xzk−y))tk+1=1+1+4tk22,zk+1=wk+1+tk−1tk+1(wk+1−wk)\begin{aligned} \mathbf{w}_{k+1} &= S_{\lambda/L}\left(\mathbf{z}_k - \tfrac{1}{L}X^T(X\mathbf{z}_k - \mathbf{y})\right) \\ t_{k+1} &= \frac{1 + \sqrt{1 + 4t_k^2}}{2}, \qquad \mathbf{z}_{k+1} = \mathbf{w}_{k+1} + \frac{t_k - 1}{t_{k+1}}(\mathbf{w}_{k+1} - \mathbf{w}_k) \end{aligned}
python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
n, d = 100, 200                                         # more features than examples
X = rng.normal(size=(n, d)) / np.sqrt(n)
w_true = np.zeros(d); w_true[rng.choice(d, 8, replace=False)] = rng.normal(scale=3, size=8)
y = X @ w_true + 0.05 * rng.normal(size=n)
lam = 0.05; L = np.linalg.norm(X, 2)**2
F = lambda w: 0.5 * np.sum((X @ w - y)**2) + lam * np.abs(w).sum()
soft = lambda v, k: np.sign(v) * np.maximum(np.abs(v) - k, 0)

def ista(iters):
    w = np.zeros(d)
    for _ in range(iters):
        w = soft(w - X.T @ (X @ w - y) / L, lam / L)
    return w
def fista(iters):
    w = z = np.zeros(d); t = 1.0
    for _ in range(iters):
        w_new = soft(z - X.T @ (X @ z - y) / L, lam / L)
        t_new = (1 + np.sqrt(1 + 4 * t * t)) / 2
        z = w_new + (t - 1) / t_new * (w_new - w)
        w, t = w_new, t_new
    return w

F_star = F(fista(20000))
for k in (10, 30, 100, 300):
    print(f"k = {k:4d}: ISTA gap {F(ista(k)) - F_star:.2e}   FISTA gap {F(fista(k)) - F_star:.2e}")
w = fista(5000)
print("non-zeros found:", int(np.sum(np.abs(w) > 1e-6)), " true support recovered:", set(np.nonzero(np.abs(w) > 0.3)[0]) == set(np.nonzero(w_true)[0]))
k =   10: ISTA gap 1.34e+00   FISTA gap 9.35e-01
k =   30: ISTA gap 7.46e-01   FISTA gap 3.37e-02
k =  100: ISTA gap 1.50e-01   FISTA gap 8.46e-06
k =  300: ISTA gap 2.96e-06   FISTA gap 7.24e-10
non-zeros found: 41  true support recovered: True

With 200 features and only 100 examples, ordinary least squares has infinitely many solutions; the lasso picks a sparse one. Most of its non-zero coefficients are tiny, and the large ones (above 0.3) are exactly the 8 true features.

Choosing λ\lambda: the regularization path

For λ≥λmax⁡=∥XTy∥∞\lambda \ge \lambda_{\max} = \lVert X^T\mathbf{y} \rVert_\infty the solution is w=0\mathbf{w} = 0 (check: 0∈∂F(0)0 \in \partial F(\mathbf{0})). Decreasing λ\lambda lets coefficients enter one by one. Solvers compute a whole path of λ\lambda values, warm-starting each from the previous, and pick λ\lambda by cross-validation.

python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
n, d = 100, 200
X = rng.normal(size=(n, d)) / np.sqrt(n)
w_true = np.zeros(d); w_true[rng.choice(d, 8, replace=False)] = rng.normal(scale=3, size=8)
y = X @ w_true + 0.05 * rng.normal(size=n)
L = np.linalg.norm(X, 2)**2
soft = lambda v, k: np.sign(v) * np.maximum(np.abs(v) - k, 0)
lam_max = np.abs(X.T @ y).max()
w = np.zeros(d)
for frac in (1.0, 0.5, 0.2, 0.1, 0.05, 0.01):
    lam = frac * lam_max
    z, t, w_prev = w.copy(), 1.0, w.copy()               # warm start
    for _ in range(2000):
        w_new = soft(z - X.T @ (X @ z - y) / L, lam / L)
        t_new = (1 + np.sqrt(1 + 4 * t * t)) / 2
        z = w_new + (t - 1) / t_new * (w_new - w_prev); w_prev, t = w_new, t_new
    w = w_prev
    print(f"lambda = {frac:4.2f} * lambda_max: {int(np.sum(np.abs(w) > 1e-6)):3d} non-zero coefficients")
lambda = 1.00 * lambda_max:   0 non-zero coefficients
lambda = 0.50 * lambda_max:   4 non-zero coefficients
lambda = 0.20 * lambda_max:   8 non-zero coefficients
lambda = 0.10 * lambda_max:   8 non-zero coefficients
lambda = 0.05 * lambda_max:  10 non-zero coefficients
lambda = 0.01 * lambda_max:  41 non-zero coefficients

Practical notes

  • FISTA's objective is not monotone; a restart (set t=1t = 1 when FF increases) often speeds it up further.
  • If LL is unknown, use backtracking on the smooth part.
  • Coordinate descent (Coordinate Descent) is usually faster for the plain lasso on tabular data; ISTA/FISTA shine when XX is only available as fast operators (FFTs, wavelets, convolutions), as in compressed sensing and image deblurring.

In software

  • scikit-learn Lasso/LassoCV (coordinate descent), sklearn.linear_model.lasso_path; SPAMS, pyproximal and many imaging libraries implement FISTA.
  • Compressed sensing MRI reconstructs images from undersampled scans with exactly this kind of L1-regularized least squares.

Exercises

Exercise 1: λmax⁡\lambda_{\max}

Show that w=0\mathbf{w} = 0 is optimal when λ≥∥XTy∥∞\lambda \ge \lVert X^T\mathbf{y} \rVert_\infty.

Answer

Then 0∈−XTy+λ[−1,1]d\mathbf{0} \in -X^T\mathbf{y} + \lambda[-1, 1]^d.

Solution

At w=0\mathbf{w} = 0 the gradient of the smooth part is −XTy-X^T\mathbf{y}, and the subdifferential of λ∥w∥1\lambda\lVert \mathbf{w} \rVert_1 is the box [−λ,λ]d[-\lambda, \lambda]^d. Zero is in the sum iff every ∣(XTy)j∣≤λ\lvert (X^T\mathbf{y})_j \rvert \le \lambda.

Exercise 2: One ISTA step

With X=IX = I (so L=1L = 1), y=(3,−0.5,1.2)\mathbf{y} = (3, -0.5, 1.2), λ=1\lambda = 1, start at w=0\mathbf{w} = 0. What is w1\mathbf{w}_1, and is it optimal?

Answer

(2,0,0.2)(2, 0, 0.2); yes.

Solution

The gradient step gives w−(w−y)=y\mathbf{w} - (\mathbf{w} - \mathbf{y}) = \mathbf{y}; soft thresholding by 1 gives (2,0,0.2)(2, 0, 0.2). With X=IX = I the problem is separable and that is the exact solution.

Exercise 3: Momentum coefficient (code)

Print the FISTA extrapolation weights tk−1tk+1\frac{t_k - 1}{t_{k+1}} for the first 6 iterations. What do they approach?

Answer

They start at 0 and increase toward 1.

Solution
python · try it yourself
import numpy as np
t, out = 1.0, []
for k in range(6):
    t_new = (1 + np.sqrt(1 + 4 * t * t)) / 2
    out.append(round(float((t - 1) / t_new), 4)); t = t_new
print(out)
[0.0, 0.2818, 0.434, 0.5311, 0.5988, 0.6489]

Since tk≈(k+1)/2t_k \approx (k + 1)/2, the weight behaves like k−1k+2→1\frac{k - 1}{k + 2} \to 1: more and more momentum, which is what produces the O(1/k2)O(1/k^2) rate.

Test yourself

ISTA is…

  1. Newton's method for the lasso
  2. proximal gradient descent with soft thresholding
  3. the simplex method
  4. a subgradient method with diminishing steps

FISTA improves ISTA's convex rate from O(1/k)O(1/k) to…

  1. O(1/k)O(1/\sqrt{k})
  2. O(1/k2)O(1/k^2)
  3. O(e−k)O(e^{-k})
  4. O(1)O(1)

For λ≥∥XTy∥∞\lambda \ge \lVert X^T\mathbf{y} \rVert_\infty the lasso solution is…

  1. the least-squares solution
  2. w=0\mathbf{w} = \mathbf{0}
  3. undefined
  4. dense