The Lasso with ISTA and FISTA
The lasso fits a linear model with an L1 penalty,
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 to at no extra cost per iteration.
ISTA
The smooth part has gradient and Lipschitz constant ; the prox of is soft thresholding:
"Iterative shrinkage-thresholding algorithm": a gradient step, then shrink every coefficient toward zero.
FISTA
Beck and Teboulle's FISTA extrapolates before each step:
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 : the regularization path
For the solution is (check: ). Decreasing lets coefficients enter one by one. Solvers compute a whole path of values, warm-starting each from the previous, and pick by cross-validation.
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 when increases) often speeds it up further.
- If 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 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,pyproximaland 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:
Show that is optimal when .
Answer
Then .
Solution
At the gradient of the smooth part is , and the subdifferential of is the box . Zero is in the sum iff every .
Exercise 2: One ISTA step
With (so ), , , start at . What is , and is it optimal?
Answer
; yes.
Solution
The gradient step gives ; soft thresholding by 1 gives . With the problem is separable and that is the exact solution.
Exercise 3: Momentum coefficient (code)
Print the FISTA extrapolation weights for the first 6 iterations. What do they approach?
Answer
They start at 0 and increase toward 1.
Solution
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 , the weight behaves like : more and more momentum, which is what produces the rate.
Test yourself
ISTA is…
- Newton's method for the lasso
- proximal gradient descent with soft thresholding
- the simplex method
- a subgradient method with diminishing steps
FISTA improves ISTA's convex rate from to…
For the lasso solution is…
- the least-squares solution
- undefined
- dense