Algorithmresearch
Learned ISTA
Also called LISTA.
A fixed number of ISTA-shaped layers soft(W_e y + S x, theta) whose matrices and thresholds are trained on data, to approximate sparse codes in fewer steps than ISTA.
- Solves
- Sparse signal recovery
- Time
- O(K (m n + n^2)) worst
- Space
- O(n) extra
- Where
- K = the number of layers; m = the number of measurements; n = the number of unknowns
- Model
- Real RAM
- Properties
- deterministicnot exactiterativelearned
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Karol Gregor, Yann LeCun, 2010
Learned ISTA (LISTA) is a network of layers, each of the form , that maps data to an approximate sparse code . With the weights , and it is exactly steps of ISTA for the lasso . LISTA instead trains , and on examples, so that a few layers give codes that ISTA needs many more steps to reach. Gregor and LeCun (2010) introduced it, and it was the first unrolled network (see algorithm unrolling). The equality with ISTA is a theorem. The speed-up is a measurement on a data distribution, and the trained network has no correctness guarantee for data outside that distribution.
In plain words
ISTA finds a sparse code by small steps. Each step does a fixed matrix product, adds a fixed vector made from the data, and then sets the small entries to zero and shrinks the others. It needs many steps, because the step rules were chosen to work for every possible input.
LISTA keeps the shape of one step but lets a computer tune its numbers from examples. You run the tuned step a few times, for example three times, and stop. If the new inputs look like the examples, the tuned steps reach a good code much sooner than the general ones. If they do not, nothing promises a good answer.
The problem
The input is a vector and trained weights: for each layer an matrix , an matrix and a vector of thresholds. With tied weights all layers share one triple. The output is a code .
The training problem behind the weights is this. For a dictionary or forward operator and a weight , let be the lasso solution (see sparse signal recovery and lasso regression). Gregor and LeCun choose the weights that minimize the mean of over a training set of data vectors . Other papers train against the true sparse signal instead of the lasso solution.
The algorithm
Here .
LISTA(y, (W_e^k, S^k, θ^k) for k = 1..K)- 1
x ← 0 - 2
for k = 1 to K - 3
c ← W_e^k y + S^k x ▷ linear part of layer k - 4
x ← soft(c, θ^k) ▷ shrinkage with learned thresholds - 5
return x
Line L3 is the only place where the data enters. With tied weights the vector is computed once before the loop. Gregor and LeCun write the first layer as ; it is the case of line L3.
The ISTA weights. ISTA for the lasso with step , , is . Expand the argument: with and . So one layer with these weights and is one ISTA step.
Training. The weights are fitted by stochastic gradient descent on the loss above. The gradient comes from backpropagation through lines L3 and L4: soft thresholding passes the gradient through the active entries () and blocks it at the others, and its derivative in is on the active entries. The implementation writes these formulas by hand and checks them against finite differences.
Example
Take , and . The third column of has norm 1 and equals . The lasso solution is : at this point the residual is and , which is on the support and less than in absolute value elsewhere. The matrix has the eigenvalues 2 and 1, so and .
LISTA with the ISTA weights, run for layers, gives the ISTA iterates:
| 1 | (0.25, 0.35, 0.45) | 0.6225 |
| 2 | (0.24, 0.345, 0.46) | 0.6085 |
| 10 | (0.188016, 0.283988, 0.54) | 0.4956 |
| 40 | (0.008, 0.044, 0.84) | 0.0748 |
| 46 | (0, 0, 0.889332) | 0.0107 |
| 50 | (0, 0, 0.899333) | 0.000667 |
The first layer gives . The false entries and fall slowly, and ISTA finds the correct support only at step 46. After that the error halves at each step, because on the support the step multiplies the error by . Step 50 is the first with an error below 0.001.
Now take a hand-made network of one layer: has the rows , and , and . For every with it returns , and this is the lasso solution for that by the same check as above. So on this family of inputs one layer does the work of 50 ISTA steps. For , outside the family, the lasso solution is , but the same layer returns . This is the whole story of LISTA in small form: weights fitted to a family of inputs can be much faster than ISTA on it, and can be wrong off it.
Correctness
Three statements are proved in the proof file below. First, one layer with the ISTA weights is one ISTA step, so the network is ISTA by induction. Second, with these weights the fixed points of a layer are exactly the lasso solutions, because soft thresholding is the proximal operator of the norm. Third, the backpropagation formulas give the gradient of the training loss wherever no entry sits exactly on a threshold.
For trained weights there is no correctness theorem. What is known is about existence. Chen, Liu, Wang and Yin (2018) assume a noise level, entries of bounded by and at most nonzero entries. Theorem 1 of their paper: if a network recovers every such from noiseless data as , with bounded weights, then and . This coupling motivates LISTA-CP, with layers . Theorem 2: if is small enough, there are weights and thresholds for LISTA-CP with for constants and a noise bound . The theorem does not say that training finds these weights.
Proof: LISTA with the ISTA weights is ISTA, its fixed points are the lasso solutions, and the backpropagation formulas give the gradient of the training lossfull
Setting. , , and . The lasso objective is . Soft thresholding with a vector of thresholds is . A LISTA layer with weights maps to , and the network starts from (lines L1 to L5).
What is proved here is a statement about the algorithm around the weights. Nothing is proved about trained weights: for them the page reports measurements only.
Fact (P). For , is the proximal operator of : it is the unique minimizer of . Proof. The function is separable and strongly convex, so it has one minimizer, and each coordinate solves . The optimality condition gives if , if , and if , because then . This is the soft threshold.
Lemma 1 (one layer is one ISTA step). Let , and . Then for every ,
the ISTA step with step . Proof. . The thresholds are equal.
Corollary. By induction on , the -layer network with these weights in every layer returns the ISTA iterate started at . The base case is in both; the step is Lemma 1. The test test_lista_with_ista_weights_is_ista checks this for .
Lemma 2 (fixed points). With the weights of Lemma 1, is a fixed point of the layer if and only if minimizes . Proof. By (P), with holds if and only if , that is . Multiply by : this is . Since is convex, is the condition for a minimizer.
So with the ISTA weights a deep enough network approaches a lasso solution: ISTA converges for , with (Beck and Teboulle 2009, Theorem 3.1; see iterative shrinkage-thresholding). LISTA with other weights has no such guarantee in general.
Lemma 3 (why and must be coupled). Take no thresholds () and tied weights. If every is a fixed point of the layer for the data , then . Proof. With the layer is the linear map . If it fixes every , then for all , so . Chen, Liu, Wang and Yin (2018, Theorem 1) prove the same coupling in the limit, with thresholds, for networks that recover every sparse ; this motivates LISTA-CP, which sets in each layer.
Lemma 4 (backpropagation). Let and for , and let for a target . Suppose for all and . Set , and for let if and otherwise, and . Then
Proof. Under the assumption, each is differentiable near : on the active branch it is , with derivative 1 in and in ; on the dead branch it is 0 near the point. We show by downward induction that . For this is the derivative of . If it holds for , the chain rule through gives , and through it gives . The weight enters only through , linearly with , which gives ; the same argument gives for , and the threshold formula is the chain rule through the active branch. For tied weights, the gradient is the sum of the layer gradients, because the tied weight enters each layer once. The set where some has measure zero in the data for fixed weights, and the test checks the formulas against central differences.
Complexity
The model is real-ram. A layer with general weights costs one product with ( operations), one with ( operations) and for the threshold. So layers cost time and extra space, and with tied weights . The weights take memory, or when tied.
One ISTA step costs one product with and one with : for a dense matrix, or the cost of these two calls for a matrix-free operator. So a layer of LISTA costs about the same as a step of ISTA when is close to , and more when , because is a dense matrix. LISTA-CP and ALISTA keep the form , which costs per layer and stores only once.
Training is outside the cost of the reconstruction. By backpropagation, one gradient on one example costs a small constant times the forward pass, and it stores the intermediate vectors , so memory.
Properties
- ISTA is a special case. With the ISTA weights, LISTA is ISTA, so it inherits the bound of Beck and Teboulle (2009, Theorem 3.1) for the start .
- Fixed depth. The number of layers is chosen before training, so the cost of a reconstruction is known in advance. There is no stopping rule.
- Learned for a distribution. The speed-up holds on data like the training data. Gregor and LeCun measured it on patches of natural images from the Berkeley data set, with and the squared error to the optimal code as the metric: for 100 code units FISTA needed 18 steps to reach the error of one LISTA layer, and for 400 code units 35 steps. This is a measurement, not a property of the algorithm.
- Not a lasso solver. With trained weights the output is in general not a lasso solution for any , even when it is close to one.
Variants and improvements
- Untied layers. Each layer has its own . This is the form of the pseudocode above.
- LISTA-CP and LISTA-CPSS (Chen, Liu, Wang and Yin 2018). Couple , as Theorem 1 requires, and optionally keep the largest entries out of the threshold (support selection).
- ALISTA (Liu, Chen, Wang and Yin, ICLR 2019). Compute from by a data-free optimization and train only one step size and one threshold per layer.
- Learned coordinate descent (LCoD). In the same paper, Gregor and LeCun truncate and train coordinate descent in the same way.
- Learned AMP. Unfold approximate message passing instead of ISTA.
- Unrolling in general. Any iterative solver can be truncated and trained in the same way; see algorithm unrolling and learned primal-dual.
When to use it
Use LISTA when you must compute sparse codes for many inputs from one distribution under a fixed time budget, and you have enough training data from that distribution. Typical uses are fast feature extraction and the encoder of a sparse autoencoder. Do not use it when the inputs change their statistics, when you need the exact lasso solution, or when the forward operator changes from case to case: then use ISTA or FISTA, which work for every input.
Pitfalls
- Wrong scaling of the ISTA start. Initializing with gives a network that does not even match a convergent ISTA. Compute by power iteration and add a small margin.
- Negative thresholds. A gradient step can push below 0, which turns shrinkage into expansion. Project the thresholds to after each step.
- Kinks. Soft thresholding is not differentiable at . A finite difference check at such a point fails for a correct gradient; test at random points.
- Reading a measured speed-up as a rate. "One layer is worth 18 FISTA steps" was measured on one data set and one . It is not a bound.
- Evaluating on the training data. The loss must be measured on held-out examples; the example above shows how a network can be exact on its family and wrong off it.
Implementations
The network is a given input: the code takes the list of layer weights as an argument and runs lines L1 to L5 around it. The tests build the weights by hand (the ISTA weights and the one-layer network of the example) or from a fixed seed, and train small tied networks on synthetic data. No real data and no downloaded weights are used. The tests check that LISTA with the ISTA weights equals an independent ISTA for 1 to 11 layers, the example values, the backpropagation formulas against central differences, and that a trained 3-layer network has less than a quarter of the loss of 3 ISTA steps on its training set.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lista/. The authors are listed in prov/KG5S6M.jsonl.
"""Learned ISTA (LISTA) of Gregor and LeCun.
The network is given: a list of layers, each a triple (W_e, S, theta) with
W_e an n x m matrix, S an n x n matrix and theta a list of n thresholds.
Layer k maps x to soft(W_e y + S x, theta). With W_e = A^T / L,
S = I - A^T A / L and theta = lambda / L in every layer, K layers are
K steps of ISTA for the lasso (1/2)||A x - y||^2 + lambda ||x||_1.
Matrices are lists of rows. Vectors are lists of floats.
"""
def matvec(a, x):
"""The product A x."""
return [sum(v * w for v, w in zip(row, x)) for row in a]
def soft(v, theta):
"""Soft thresholding: sign(v_i) max(|v_i| - theta_i, 0), entry by entry."""
out = []
for vi, ti in zip(v, theta):
if vi > ti:
out.append(vi - ti)
elif vi < -ti:
out.append(vi + ti)
else:
out.append(0.0)
return out
def lista(y, layers):
"""Run the given layers on the data y and return the code x.
layers is a list of K triples (W_e, S, theta). A network with tied
weights repeats the same triple K times.
Cost: K products with W_e (n m each) and with S (n^2 each).
"""
n = len(layers[0][1])
x = [0.0] * n # @line L1
for w_e, s, theta in layers: # @line L2
c = [a + b for a, b in zip(matvec(w_e, y), matvec(s, x))] # @line L3
x = soft(c, theta) # @line L4
return x # @line L5
def ista_weights(a, lam, lip):
"""The triple (W_e, S, theta) for which one LISTA layer is one ISTA step.
lip must be at least ||A||^2, the Lipschitz constant of the gradient of
(1/2)||A x - y||^2.
"""
m, n = len(a), len(a[0])
w_e = [[a[i][j] / lip for i in range(m)] for j in range(n)]
s = [[(1.0 if j == k else 0.0) - sum(a[i][j] * a[i][k] for i in range(m)) / lip
for k in range(n)] for j in range(n)]
return w_e, s, [lam / lip] * n
def ista(a, y, lam, lip, iters, x0=None):
"""Plain ISTA: x <- soft(x - A^T (A x - y) / lip, lam / lip), written from the gradient."""
m, n = len(a), len(a[0])
x = list(x0) if x0 is not None else [0.0] * n
for _ in range(iters):
r = [ax - yi for ax, yi in zip(matvec(a, x), y)]
g = [sum(a[i][j] * r[i] for i in range(m)) for j in range(n)]
x = soft([xj - gj / lip for xj, gj in zip(x, g)], [lam / lip] * n)
return x
def lasso_objective(a, y, lam, x):
"""(1/2)||A x - y||^2 + lam ||x||_1."""
r = [ax - yi for ax, yi in zip(matvec(a, x), y)]
return 0.5 * sum(v * v for v in r) + lam * sum(abs(v) for v in x)
def lista_loss_and_grad(y, layers, target):
"""Loss (1/2)||x^K - target||^2 and its gradient in every weight, by backpropagation.
Returns (loss, grads) with grads[k] = (dW_e, dS, dtheta) for layer k.
Soft thresholding is not differentiable where |c_i| = theta_i; the
formula uses the derivative of the active branch, which is right
everywhere else.
"""
n = len(layers[0][1])
xs = [[0.0] * n]
cs = []
for w_e, s, theta in layers:
c = [a + b for a, b in zip(matvec(w_e, y), matvec(s, xs[-1]))]
cs.append(c)
xs.append(soft(c, theta))
g = [a - b for a, b in zip(xs[-1], target)]
loss = 0.5 * sum(v * v for v in g)
grads = [None] * len(layers)
for k in range(len(layers) - 1, -1, -1):
w_e, s, theta = layers[k]
c, x_prev = cs[k], xs[k]
dc = [gi if abs(ci) > ti else 0.0 for gi, ci, ti in zip(g, c, theta)]
dtheta = [-gi * (1.0 if ci > 0 else -1.0) if abs(ci) > ti else 0.0
for gi, ci, ti in zip(g, c, theta)]
d_we = [[dci * yj for yj in y] for dci in dc]
d_s = [[dci * xj for xj in x_prev] for dci in dc]
grads[k] = (d_we, d_s, dtheta)
g = [sum(s[i][j] * dc[i] for i in range(n)) for j in range(n)]
return loss, grads
def train_tied(data, layers_count, start, step, epochs):
"""Fit tied weights (W_e, S, theta) by full-batch gradient descent.
data is a list of pairs (y, target). start is the initial triple, for
example the ISTA weights. The gradient of tied weights is the sum of the
gradients of the K copies. Returns the trained triple.
"""
w_e = [row[:] for row in start[0]]
s = [row[:] for row in start[1]]
theta = list(start[2])
for _ in range(epochs):
gw = [[0.0] * len(w_e[0]) for _ in w_e]
gs = [[0.0] * len(s[0]) for _ in s]
gt = [0.0] * len(theta)
for y, target in data:
_, grads = lista_loss_and_grad(y, [(w_e, s, theta)] * layers_count, target)
for d_we, d_s, dth in grads:
for i, row in enumerate(d_we):
for j, v in enumerate(row):
gw[i][j] += v
for i, row in enumerate(d_s):
for j, v in enumerate(row):
gs[i][j] += v
for i, v in enumerate(dth):
gt[i] += v
scale = step / len(data)
w_e = [[v - scale * d for v, d in zip(row, drow)] for row, drow in zip(w_e, gw)]
s = [[v - scale * d for v, d in zip(row, drow)] for row, drow in zip(s, gs)]
theta = [max(0.0, v - scale * d) for v, d in zip(theta, gt)]
return w_e, s, theta
test_lista.py 136 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lista/. The authors are listed in prov/KG5S6M.jsonl.
import random
from lista import (
ista,
ista_weights,
lasso_objective,
lista,
lista_loss_and_grad,
matvec,
soft,
train_tied,
)
A = [[1.0, 0.0, 0.6], [0.0, 1.0, 0.8]]
Y = [0.6, 0.8]
LAM = 0.1
LIP = 2.0 # ||A||^2: the eigenvalues of A A^T are 2 and 1
def close(u, v, tol):
return all(abs(a - b) <= tol for a, b in zip(u, v)) and len(u) == len(v)
def random_problem(rng, m, n):
a = [[rng.gauss(0.0, 0.5) for _ in range(n)] for _ in range(m)]
v = [1.0] * n
nv = 1.0
for _ in range(200):
w = [sum(a[i][j] * sum(a[i][k] * v[k] for k in range(n)) for i in range(m)) for j in range(n)]
nv = sum(t * t for t in w) ** 0.5
v = [t / nv for t in w]
return a, 1.01 * nv
def test_soft_thresholding():
assert soft([0.3, -0.3, 0.05, -2.0], [0.1] * 4) == [0.3 - 0.1, -0.3 + 0.1, 0.0, -1.9]
def test_first_ista_step_of_the_example():
x = lista(Y, [ista_weights(A, LAM, LIP)])
assert close(x, [0.25, 0.35, 0.45], 1e-12)
def test_lista_with_ista_weights_is_ista():
rng = random.Random(1)
a, lip = random_problem(rng, 5, 8)
y = [rng.gauss(0.0, 1.0) for _ in range(5)]
w = ista_weights(a, 0.2, lip)
for k in range(1, 12):
assert close(lista(y, [w] * k), ista(a, y, 0.2, lip, k), 1e-12)
def test_ista_objective_does_not_increase():
x = [0.0, 0.0, 0.0]
f = lasso_objective(A, Y, LAM, x)
for _ in range(60):
x = ista(A, Y, LAM, LIP, 1, x)
f_new = lasso_objective(A, Y, LAM, x)
assert f_new <= f + 1e-15
f = f_new
assert abs(f - 0.095) < 1e-6
def test_example_ista_needs_46_steps_for_the_support():
w = ista_weights(A, LAM, LIP)
assert lista(Y, [w] * 45)[1] > 0.0
x46 = lista(Y, [w] * 46)
assert x46[0] == 0.0 and x46[1] == 0.0
err50 = sum((a - b) ** 2 for a, b in zip(lista(Y, [w] * 50), [0.0, 0.0, 0.9])) ** 0.5
err49 = sum((a - b) ** 2 for a, b in zip(lista(Y, [w] * 49), [0.0, 0.0, 0.9])) ** 0.5
assert err50 < 1e-3 < err49
def test_one_hand_made_layer_is_exact_on_its_family_only():
layer = ([[0.0, 0.0], [0.0, 0.0], [0.6, 0.8]], [[0.0] * 3 for _ in range(3)], [0.0, 0.0, 0.1])
for t in (0.3, 0.9, 1.0, 2.5):
y = [0.6 * t, 0.8 * t]
assert close(lista(y, [layer]), [0.0, 0.0, t - 0.1], 1e-12)
assert close(ista(A, y, LAM, LIP, 3000), [0.0, 0.0, t - 0.1], 1e-9)
# Off the family the same layer is wrong: the lasso solution for y = (1, 0) is (0.9, 0, 0).
assert close(ista(A, [1.0, 0.0], LAM, LIP, 3000), [0.9, 0.0, 0.0], 1e-9)
assert close(lista([1.0, 0.0], [layer]), [0.0, 0.0, 0.5], 1e-12)
def test_backpropagation_matches_finite_differences():
rng = random.Random(3)
m, n, k = 3, 4, 3
layers = []
for _ in range(k):
w_e = [[rng.gauss(0.0, 0.5) for _ in range(m)] for _ in range(n)]
s = [[rng.gauss(0.0, 0.3) for _ in range(n)] for _ in range(n)]
theta = [rng.uniform(0.05, 0.2) for _ in range(n)]
layers.append((w_e, s, theta))
y = [rng.gauss(0.0, 1.0) for _ in range(m)]
target = [rng.gauss(0.0, 1.0) for _ in range(n)]
_, grads = lista_loss_and_grad(y, layers, target)
h = 1e-6
def loss_with(layer, part, i, j, delta):
new = [(list(map(list, w)), list(map(list, s)), list(t)) for w, s, t in layers]
if part == 2:
new[layer][2][i] += delta
else:
new[layer][part][i][j] += delta
return lista_loss_and_grad(y, new, target)[0]
for layer in range(k):
for part, rows, cols in ((0, n, m), (1, n, n), (2, n, 1)):
for i in range(rows):
for j in range(cols):
fd = (loss_with(layer, part, i, j, h) - loss_with(layer, part, i, j, -h)) / (2 * h)
g = grads[layer][part][i] if part == 2 else grads[layer][part][i][j]
assert abs(fd - g) < 1e-6 * (1.0 + abs(g))
def test_training_beats_ista_with_the_same_depth():
rng = random.Random(7)
m, n, k, lam = 4, 6, 3, 0.1
a, lip = random_problem(rng, m, n)
data = []
for _ in range(20):
xt = [0.0] * n
for j in rng.sample(range(n), 2):
xt[j] = rng.choice([-1.0, 1.0]) * rng.uniform(0.5, 1.5)
y = matvec(a, xt)
data.append((y, ista(a, y, lam, lip, 2000)))
def mean_loss(w):
return sum(lista_loss_and_grad(y, [w] * k, t)[0] for y, t in data) / len(data)
start = ista_weights(a, lam, lip)
trained = train_tied(data, k, start, 0.2, 150)
assert mean_loss(trained) < 0.25 * mean_loss(start)
History
Gregor and LeCun (2010) observed that sparse coding by ISTA or coordinate descent is too slow for real-time feature extraction, wrote ISTA as a recurrent network with the matrices and , and trained a truncated version to predict the optimal codes. This started the line of work now called algorithm unrolling or deep unfolding, surveyed by Monga, Li and Eldar (2021). Chen, Liu, Wang and Yin (2018) gave the first convergence theory, with the coupled form LISTA-CP, and ALISTA (2019) reduced the trained parameters to a few scalars per layer.
References
- Karol Gregor and Yann LeCun, Learning fast approximations of sparse coding, Proceedings of the 27th International Conference on Machine Learning (ICML), 2010, pages 399 to 406 (eq. 2 for ISTA in the form h_theta(W_e X + S Z), Section 3 and Algorithms 3 and 4 for the LISTA forward and backward pass, Table 1 for the comparison with FISTA)
- Xiaohan Chen, Jialin Liu, Zhangyang Wang and Wotao Yin, Theoretical linear convergence of unfolded ISTA and its practical weights and thresholds, Advances in Neural Information Processing Systems 31 (NeurIPS), 2018, Theorem 1 (the coupling of W and S is necessary) and Theorem 2 (LISTA-CP weights with linear convergence exist)
- Amir Beck and Marc Teboulle, A fast iterative shrinkage-thresholding algorithm for linear inverse problems, SIAM Journal on Imaging Sciences 2(1), 2009, Section 3, Theorem 3.1 (the O(1/k) bound of ISTA, which LISTA with the ISTA weights inherits)
- Vishal Monga, Yuelong Li and Yonina C. Eldar, Algorithm unrolling, interpretable, efficient deep learning for signal and image processing, IEEE Signal Processing Magazine 38(2), 2021, pages 18 to 44 (LISTA as the first unrolled network, and its later variants)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag KG5S6M Edit this page History Report an error Markdown