Algorithmcore
Landweber iteration
Also called Landweber method.
Iterate x_{k+1} = x_k + omega A* (y - A x_k), a gradient descent on the residual whose iteration count acts as the regularization parameter.
- Time
- O(k (a + m + n)) totalO(k m n) denseO(a + m + n) per_iteration
- Space
- O(m + n) extra
- Where
- a = the cost of one product with A plus one product with A*; k = the number of iterations; m = the number of data values; n = the number of unknowns
- Model
- Real RAM
- Properties
- deterministiciterativelinear in datamatrix free
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Louis Landweber, 1951
The Landweber iteration solves an ill-posed linear equation from noisy data with . It starts at and repeats the step with a fixed step . Each step is one step of gradient descent on , and costs one product with and one with the adjoint . Run to the end, the iteration converges to the least squares solution of the noisy data, which is useless when is ill-conditioned. Stopped early, it is a regularization method: the iteration count plays the role of the parameter of Tikhonov regularization. The usual stopping rule is the discrepancy principle, which stops at the first with .
In plain words
The method guesses an answer, predicts the data from the guess, and moves the guess a small step in the direction that reduces the misfit. The first steps fix the large, well-measured features of the answer. Later steps fix finer and finer features, and these are exactly the features where the measurement noise is strongest. So the guess first gets better and then gets worse, as it starts to fit the noise. The method is stopped when the misfit is about as large as the noise. The number of steps is then the only tuning knob, and each step is cheap: it needs one simulation of the measurement and one of its reverse.
The problem
Given a bounded linear operator between Hilbert spaces (an matrix in the discrete setting), its adjoint , data with for exact data , and the noise level , find an approximation of the minimum norm solution (see pseudoinverse) whose error tends to as . The operator is only needed as two functions, and .
The algorithm
LANDWEBER(A, y, ω, K, δ, τ) ▷ 0 < ω < 2 / ‖A‖², τ > 1- 1
x ← 0 - 2
for k ← 0 to K - 1 do - 3
r ← y - A x - 4
if ‖r‖ ≤ τ δ then return (x, k) - 5
x ← x + ω A* r - 6
return (x, K)
Line L1 starts at zero; a start makes the method converge to the solution nearest to instead. Line L3 computes the residual of the current iterate. Line L4 is the discrepancy principle: it returns the first iterate whose residual is at the noise level. Without a noise level the test is left out, and must be chosen in another way. Line L5 moves along , which is minus the gradient of . Line L6 returns after steps if the test never passed. The code also has a version for a dense matrix with the default step , which is safe because .
In terms of the singular system of , the iterate is a filtered expansion (see spectral filter factors):
The filter factor is near for components with and near for the others. So acts like in Tikhonov regularization, where the filter is .
Example
A trace. Take , , so , and the noise , so and . With the first component is exact after one step, and the second is . The discrepancy test uses , so .
| L4 stops? | ||||
|---|---|---|---|---|
| 0 | 1.41421 | 1.00603 | no | |
| 1 | 0.98900 | 0.10890 | no | |
| 2 | 0.97811 | 0.10781 | no | |
| 3 | 0.96733 | 0.10673 | no | |
| 10 | 0.89482 | 0.09948 | no | |
| 100 | 0.30264 | 0.04026 | no | |
| 199 | 0.04887 | 0.01489 | yes | |
| 1000 | 0.09995 | 0.00001 | ||
| 0.1 | 0 |
At the filter factor of the second component is . Line L4 returns , because the residual at is . Here the noise has the same sign as the signal, so the error has its minimum near ; in general the minimum is not known, and the discrepancy rule only guarantees the rate below.
Rates on an integral operator. For on the singular values are . The solution satisfies the source condition with and . The test of the code uses the first 200 singular components, , , and puts the noise of size on the component that step amplifies most (a measurement):
| bound of Theorem 3 | |||
|---|---|---|---|
| 100 | 0.0986 | 0.202 | |
| 1000 | 0.0315 | 0.0639 | |
| 10000 | 0.0100 | 0.0202 |
The slopes of error against are and ; the theory gives . With the discrepancy rule and instead, the same problem stopped at , and with errors , and (a measurement).
Correctness
The proofs are in proofs/correctness.md, in exact arithmetic, with .
- Filter form (theorem). By induction on , is the filtered expansion above. The key step is that maps the part of outside the range of to .
- Exact data (theorem). when is in the domain of , because for .
- Monotone residual (theorem). for any data.
- Error bound (theorem). For , the data error is at most . Under the source condition , , the total error is at most . The choice gives for every , which is the best possible worst-case rate.
- Termination (theorem). If is in the range of and , line L4 passes after finitely many steps.
That the discrepancy principle also gives the rate for every is a theorem of Engl, Hanke and Neubauer (Chapter 6); it is cited, not proved here.
Proof: Correctness of the Landweber iterationfull
Exact arithmetic. is a bounded linear operator between Hilbert spaces with a singular system ; for a matrix this is the SVD, with the sums finite. The start is (line L1), the step is with , and (lines L3 and L5). is the orthogonal projection onto the closure of the range of , and for in the domain of .
Lemma 1 (filter form). For every ,
and .
Proof. Induction on . Base: , so the formula gives . Step: assume the formula for . Then , since and . Apply : because is orthogonal to the range of , and . So
With , the bracket is . The residual formula follows from the same computation with in place of .
Lemma 2 (bounds on the filter). Let . For : (a) ; (b) if , then and ; (c) if and , then for .
Proof. (a) , so . (b) Put . Then , so . Bernoulli's inequality gives . Hence , and . (c) . On the function has its maximum where , that is at , with .
Theorem 1 (exact data). If is in the domain of , then as .
Proof. By Lemma 1 and the Picard expansion , the error is , so . Each term tends to by Lemma 2(a) and is bounded by , a summable sequence. By dominated convergence the sum tends to .
Theorem 2 (the residual does not increase). for every and every .
Proof. By Lemma 1, , and by Lemma 2(a).
Theorem 3 (error bound). Let , let with , and let and be the iterates for and . Then . If also with and , then for
Proof. The iterate is linear in the data, so . By Lemma 2(b) each coefficient is multiplied by at most , and by Bessel's inequality . For the second part, , so by the proof of Theorem 1 and Lemma 2(c), . The triangle inequality adds the two parts.
Corollary (a priori rate). With (rounded up to an integer ), Theorem 3 gives as . Substitute: and ; the rounding of changes the second term by a factor .
Theorem 4 (termination of the discrepancy rule). Let , and . Then the loop L2 to L5 with the test of line L4 stops after finitely many steps (for large enough), and the returned satisfies , while every earlier iterate has a residual above .
Proof. By Lemma 1 for the data , . The sum tends to by Lemma 2(a) and dominated convergence, as in Theorem 1. Since is in the range of , , so . So the residual is below for all large , and the first such exists. Line L4 tests the residual of each iterate in order of and returns at the first one that passes, which gives the last two claims.
The order optimality of the discrepancy rule, an error for every with a stopping index , is a theorem of Engl, Hanke and Neubauer (Chapter 6). It is not proved here and the code does not rely on it.
Complexity
- Per iteration (real-ram). Line L3 costs one product with and subtractions, line L4 a norm of length , and line L5 one product with and operations. That is , where is the cost of one product with plus one with . For a dense matrix ; for a sparse projector, is proportional to the number of nonzeros.
- Iterations. The count depends on the noise and on the smoothness of , not on and . The a priori choice of the corollary is , so grows like . With the discrepancy principle, the stopping index is also (EHN Chapter 6). For this is , as in the table above.
- Total. time, and extra space for , and .
CGLS with the discrepancy principle stops after steps (a theorem, EHN Chapter 7), about the square root of the Landweber count. That square root is why Landweber is rarely the fastest choice.
Properties
- Infinite qualification. The bias bound (Lemma 2(c) of the proof) holds for every , so the rate does not saturate, unlike Tikhonov regularization at (see qualification of regularization).
- Linear in the data for a fixed . With the discrepancy rule, depends on the data and the map is not linear.
- Monotone residual and, for exact data, a monotone error . With noisy data the error shows semi-convergence: it decreases, then increases.
- Matrix-free. Only products with and are used. No matrix is formed or factored.
- Smooth filter. Its filter factors are near the Tikhonov factors with .
Variants and improvements
- Preconditioned and weighted forms. with diagonal weights and . In tomography this is SIRT, with the row and column sums of the projector as weights.
- Projected Landweber. Project onto a convex set (for example ) after each step.
- Accelerated methods. The -methods of Brakhage and Hanke and CGLS reach the same accuracy in about the square root of the number of steps (EHN Chapter 6 and 7).
- Nonlinear Landweber. For , use (EHN Chapter 11). The iteratively regularized Gauss-Newton method is a faster alternative.
- Richardson iteration. The same step on the normal equations is the Richardson iteration; Landweber is that iteration used as a regularization method.
When to use it
Use Landweber when you have only a forward and an adjoint code, want the simplest possible method, and can afford many cheap steps. It is the reference method for the theory of iterative regularization, because its filter is explicit. It is a good choice inside nonlinear methods and with constraints such as nonnegativity, where Krylov methods are harder to use. When speed matters, use CGLS or LSQR: they need far fewer products with for the same error. For a small dense problem, truncated SVD or Tikhonov regularization (which writes for ) with a direct solver is simpler.
Pitfalls
- Step too large. With at line L5, the component of the largest singular value grows and the iteration diverges. Estimate by a few steps of the power method on , or use for a matrix.
- No stopping rule. Running the loop of line L2 to convergence fits the noise. The error goes up again after the best (see the trace). Keep the test of line L4, or choose from .
- at line L4. If the data have a part outside the range of , the residual tends to the norm of that part, which can be close to , and the test may never pass. Use , for example to .
- A wrong adjoint at line L5. If the code for is not the true adjoint of the code for , the step is not a gradient step and the theory fails. Check on random vectors.
- Reading the error from the residual. The residual decreases at every step, even when the error has started to increase. A small residual does not mean a small error.
Implementations
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
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Dense linear algebra on lists of rows (float, complex or Fraction entries).
A matrix is a list of rows. A vector is a list of numbers. The inner product
is <u, v> = sum_i conj(u_i) v_i, linear in the second argument, so that the
adjoint A^H satisfies <A x, y> = <x, A^H y>.
"""
import math
def _flat(x):
"""Flatten a list of rows (an image) into one list; a vector is returned as is."""
if x and isinstance(x[0], (list, tuple)):
return [v for row in x for v in row]
return x
def zeros(m, n):
"""The m x n zero matrix."""
return [[0.0] * n for _ in range(m)]
def eye(n):
"""The n x n identity matrix."""
out = zeros(n, n)
for i in range(n):
out[i][i] = 1.0
return out
def transpose(a):
"""A^T."""
return [list(col) for col in zip(*a)]
def conj_transpose(a):
"""A^H, the conjugate transpose."""
return [[v.conjugate() for v in col] for col in zip(*a)]
def matmul(a, b):
"""The product A B."""
bt = list(zip(*b))
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def matvec(a, x):
"""The product A x."""
return [sum(v * w for v, w in zip(row, x)) for row in a]
def rmatvec(a, y):
"""The product A^H y."""
n = len(a[0]) if a else 0
out = [0.0] * n
for row, yi in zip(a, y):
if yi == 0:
continue
for j, v in enumerate(row):
out[j] += v.conjugate() * yi
return out
def dot(u, v):
"""<u, v> = sum_i conj(u_i) v_i. Images (lists of rows) are flattened."""
return sum(a.conjugate() * b for a, b in zip(_flat(u), _flat(v)))
def norm2(x):
"""The Euclidean norm. Images (lists of rows) are flattened."""
return math.sqrt(sum(abs(v) ** 2 for v in _flat(x)))
def solve(a, b):
"""Solve A x = b by Gaussian elimination with partial pivoting.
b is a vector or a matrix (a list of rows). A must be square and
nonsingular; a zero pivot raises ValueError. Fractions stay exact.
"""
n = len(a)
vec = not (b and isinstance(b[0], (list, tuple)))
rhs = [[bi] for bi in b] if vec else [list(r) for r in b]
m = [list(row) + rhs[i] for i, row in enumerate(a)]
w = len(m[0])
for c in range(n):
p = max(range(c, n), key=lambda r: abs(m[r][c]))
if m[p][c] == 0:
raise ValueError("singular matrix")
m[c], m[p] = m[p], m[c]
piv = m[c][c]
for r in range(c + 1, n):
f = m[r][c] / piv
if f != 0:
mr, mc = m[r], m[c]
for j in range(c, w):
mr[j] -= f * mc[j]
x = [[0.0] * (w - n) for _ in range(n)]
for r in range(n - 1, -1, -1):
for j in range(w - n):
s = m[r][n + j] - sum(m[r][k] * x[k][j] for k in range(r + 1, n))
x[r][j] = s / m[r][r]
return [row[0] for row in x] if vec else x
def cholesky(a):
"""Lower triangular L with A = L L^H for a Hermitian positive definite A."""
n = len(a)
low = zeros(n, n)
for j in range(n):
d = a[j][j] - sum(abs(low[j][k]) ** 2 for k in range(j))
d = d.real if isinstance(d, complex) else d
if not d > 0:
raise ValueError("matrix is not positive definite")
ljj = math.sqrt(d)
low[j][j] = ljj
for i in range(j + 1, n):
s = a[i][j] - sum(low[i][k] * low[j][k].conjugate() for k in range(j))
low[i][j] = s / ljj
return low
def cho_solve(low, b):
"""Solve (L L^H) x = b, with L from cholesky."""
n = len(low)
z = [0.0] * n
for i in range(n):
z[i] = (b[i] - sum(low[i][k] * z[k] for k in range(i))) / low[i][i]
x = [0.0] * n
for i in range(n - 1, -1, -1):
s = z[i] - sum(low[k][i].conjugate() * x[k] for k in range(i + 1, n))
x[i] = s / low[i][i].conjugate()
return x
def _rot_params(app, aqq, apq):
"""c, s of the Jacobi rotation that zeroes the (p, q) entry of [[app, apq], [apq, aqq]]."""
theta = (aqq - app) / (2.0 * apq)
t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
c = 1.0 / math.sqrt(1.0 + t * t)
return c, c * t
def sym_eig(a, tol=1e-15, max_sweeps=100):
"""Eigenvalues (ascending) and eigenvectors (as columns) of a real symmetric matrix.
Cyclic Jacobi method. Returns (w, Q) with A = Q diag(w) Q^T.
"""
n = len(a)
m = [[float(v) for v in row] for row in a]
q = eye(n)
for _ in range(max_sweeps):
off = sum(m[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
scale = sum(m[i][i] ** 2 for i in range(n)) + off
if off <= (tol * tol) * scale or off == 0.0:
break
for p in range(n - 1):
for r in range(p + 1, n):
apq = m[p][r]
if apq == 0.0:
continue
c, s = _rot_params(m[p][p], m[r][r], apq)
for k in range(n):
mkp, mkr = m[k][p], m[k][r]
m[k][p] = c * mkp - s * mkr
m[k][r] = s * mkp + c * mkr
mp, mr = m[p], m[r]
for k in range(n):
mpk, mrk = mp[k], mr[k]
mp[k] = c * mpk - s * mrk
mr[k] = s * mpk + c * mrk
m[p][r] = m[r][p] = 0.0
for k in range(n):
qkp, qkr = q[k][p], q[k][r]
q[k][p] = c * qkp - s * qkr
q[k][r] = s * qkp + c * qkr
order = sorted(range(n), key=lambda i: m[i][i])
w = [m[i][i] for i in order]
qs = [[q[k][i] for i in order] for k in range(n)]
return w, qs
def _complete(cols, m):
"""Replace zero columns of an m-row column list by unit vectors orthogonal to the others."""
for idx, col in enumerate(cols):
if any(v != 0.0 for v in col):
continue
for e in range(m):
cand = [0.0] * m
cand[e] = 1.0
for _ in range(2):
for jdx, other in enumerate(cols):
if jdx == idx or not any(v != 0.0 for v in other):
continue
h = sum(a * b for a, b in zip(other, cand))
cand = [a - h * b for a, b in zip(cand, other)]
nrm = math.sqrt(sum(v * v for v in cand))
if nrm > 0.5:
cols[idx] = [v / nrm for v in cand]
break
return cols
def svd(a, tol=1e-15, max_sweeps=100):
"""Thin SVD of a real m x n matrix by one-sided Jacobi (Hestenes).
Returns (U, S, V) with p = min(m, n): U is m x p, S a list of p values in
descending order, V is n x p, U^T U = I, V^T V = I and A = U diag(S) V^T.
"""
m, n = len(a), len(a[0])
if m < n:
v, s, u = svd(transpose(a), tol, max_sweeps)
return u, s, v
cols = [[float(a[i][j]) for i in range(m)] for j in range(n)]
vcols = [[1.0 if i == j else 0.0 for i in range(n)] for j in range(n)]
for _ in range(max_sweeps):
rotated = False
for p in range(n - 1):
for r in range(p + 1, n):
cp, cr = cols[p], cols[r]
alpha = sum(x * x for x in cp)
beta = sum(x * x for x in cr)
gamma = sum(x * y for x, y in zip(cp, cr))
if gamma == 0.0 or abs(gamma) <= tol * math.sqrt(alpha * beta):
continue
rotated = True
c, s = _rot_params(alpha, beta, gamma)
cols[p] = [c * x - s * y for x, y in zip(cp, cr)]
cols[r] = [s * x + c * y for x, y in zip(cp, cr)]
vp, vr = vcols[p], vcols[r]
vcols[p] = [c * x - s * y for x, y in zip(vp, vr)]
vcols[r] = [s * x + c * y for x, y in zip(vp, vr)]
if not rotated:
break
sig = [math.sqrt(sum(x * x for x in col)) for col in cols]
# A column below 1e-150 times the largest one is zero to working precision;
# its squares underflow, so its direction carries no information.
floor = max(sig) * 1e-150 if sig else 0.0
sig = [t if t > floor and t > 1e-150 else 0.0 for t in sig]
order = sorted(range(n), key=lambda j: -sig[j])
s_out = [sig[j] for j in order]
ucols = [[x / sig[j] for x in cols[j]] if sig[j] > 0.0 else [0.0] * m for j in order]
ucols = _complete(ucols, m)
u = [[ucols[j][i] for j in range(n)] for i in range(m)]
v = [[vcols[j][i] for j in order] for i in range(n)]
return u, s_out, v
def adjoint_gap(apply_a, apply_ah, x, y):
"""|<A x, y> - <x, A^H y>| / (||A x|| ||y||) for given functions A and A^H.
x and y may be vectors or images (lists of rows). If the denominator is
zero, the absolute gap is returned.
"""
ax = apply_a(x)
gap = abs(dot(ax, y) - dot(x, apply_ah(y)))
den = norm2(ax) * norm2(y)
return gap / den if den > 0.0 else gap
landweber_iteration.py 87 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/landweber-iteration/. The authors are listed in prov/G6JZZF.jsonl.
"""Landweber iteration for a linear equation A x = y with noisy data.
The step is x_{k+1} = x_k + omega A^T (y - A x_k) with 0 < omega < 2 / ||A||^2.
The operator is given as two functions, apply_a(x) = A x and
apply_at(r) = A^T r, so the same code runs on a dense matrix, on a sparse
projector or on a diagonal model. The iteration count k is the
regularization parameter; with a noise level delta the discrepancy
principle stops at the first k with ||y - A x_k|| <= tau delta.
"""
import math
from typing import Callable, List, Optional, Sequence
from imgla import matvec, rmatvec, norm2
Vector = List[float]
Operator = Callable[[Sequence[float]], Vector]
class LandweberResult:
"""x: the last iterate; k: the number of steps done; residuals: ||y - A x_j||
for j = 0, ..., k; stopped: "discrepancy" or "maxit"."""
def __init__(self, x: Vector, k: int, residuals: List[float], stopped: str) -> None:
self.x, self.k, self.residuals, self.stopped = x, k, residuals, stopped
def landweber(apply_a: Operator, apply_at: Operator, y: Sequence[float], omega: float, kmax: int,
x0: Optional[Sequence[float]] = None, delta: Optional[float] = None,
tau: float = 1.01, n: Optional[int] = None) -> LandweberResult:
"""Run at most kmax Landweber steps from x0 (default 0).
Precondition: 0 < omega < 2 / ||A||^2 (not checked here). If delta is
given, stop at the first k with ||y - A x_k|| <= tau delta. n is the
number of unknowns; it is needed only when x0 is None.
Cost: per step one product with A, one with A^T and O(m + n) more.
"""
if x0 is None:
x = [0.0] * (n if n is not None else len(apply_at([0.0] * len(y)))) # @line L1
else:
x = list(x0)
residuals = []
for k in range(kmax): # @line L2
ax = apply_a(x)
r = [yi - v for yi, v in zip(y, ax)] # @line L3
rn = norm2(r)
residuals.append(rn)
if delta is not None and rn <= tau * delta: # @line L4
return LandweberResult(x, k, residuals, "discrepancy")
g = apply_at(r)
x = [xi + omega * gi for xi, gi in zip(x, g)] # @line L5
r = [yi - v for yi, v in zip(y, apply_a(x))]
residuals.append(norm2(r))
if delta is not None and residuals[-1] <= tau * delta:
return LandweberResult(x, kmax, residuals, "discrepancy")
return LandweberResult(x, kmax, residuals, "maxit") # @line L6
def landweber_matrix(a: List[List[float]], y: Sequence[float], omega: Optional[float] = None,
kmax: int = 100, x0: Optional[Sequence[float]] = None,
delta: Optional[float] = None, tau: float = 1.01) -> LandweberResult:
"""Landweber for a dense matrix A (a list of rows).
The default step is omega = 1 / ||A||_F^2. The Frobenius norm is at least
the spectral norm, so this step is always in (0, 2 / ||A||^2).
Cost: O(m n) per step.
"""
if omega is None:
omega = 1.0 / sum(v * v for row in a for v in row)
return landweber(lambda x: matvec(a, x), lambda r: rmatvec(a, r), y, omega, kmax,
x0=x0, delta=delta, tau=tau, n=len(a[0]))
def filter_factor(omega: float, sigma: float, k: int) -> float:
"""The Landweber filter factor 1 - (1 - omega sigma^2)^k (start x0 = 0)."""
return 1.0 - (1.0 - omega * sigma * sigma) ** k
def error_bound(nu: float, rho: float, omega: float, k: int, delta: float) -> float:
"""The bound (nu / (omega k))^nu rho + sqrt(omega k) delta on ||x_k - x^dagger||.
It holds for x0 = 0, omega ||A||^2 <= 1, k >= 1, the source condition
x^dagger = (A^T A)^nu w with ||w|| <= rho, and ||y - y^delta|| <= delta.
"""
return (nu / (omega * k)) ** nu * rho + math.sqrt(omega * k) * delta
test_landweber_iteration.py 173 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/landweber-iteration/. The authors are listed in prov/G6JZZF.jsonl.
import math
import random
import unittest
from imgla import adjoint_gap, matvec, norm2, rmatvec, svd
from landweber_iteration import error_bound, filter_factor, landweber, landweber_matrix
def rand_matrix(rng, m, n):
return [[rng.uniform(-1.0, 1.0) for _ in range(n)] for _ in range(m)]
def pinv_solution(a, y):
"""x^dagger = A^dagger y from the SVD (the reference method)."""
u, s, v = svd(a)
tol = max(s) * 1e-12
x = [0.0] * len(a[0])
for i, si in enumerate(s):
if si > tol:
c = sum(u[r][i] * y[r] for r in range(len(y))) / si
x = [xj + c * v[j][i] for j, xj in enumerate(x)]
return x
def cumsum(x, h):
"""Matrix-free rectangle rule for (A x)(s) = int_0^s x(t) dt."""
out, acc = [], 0.0
for v in x:
acc += h * v
out.append(acc)
return out
def rcumsum(y, h):
"""The adjoint of cumsum: (A* y)(t) = int_t^1 y(s) ds."""
out, acc = [0.0] * len(y), 0.0
for i in range(len(y) - 1, -1, -1):
acc += h * y[i]
out[i] = acc
return out
class TestLandweber(unittest.TestCase):
def test_check_value(self):
self.assertAlmostEqual(filter_factor(0.01, 1.0, 100), 0.63397, places=5)
res = landweber_matrix([[1.0]], [1.0], omega=0.01, kmax=100)
self.assertAlmostEqual(res.x[0], 0.63397, places=5)
def test_page_trace(self):
# A = diag(1, 0.1), x^dagger = (1, 1), y^delta = (1, 0.11), omega = 1, tau delta = 0.015.
a = [[1.0, 0.0], [0.0, 0.1]]
res = landweber_matrix(a, [1.0, 0.11], omega=1.0, kmax=1000, delta=0.01, tau=1.5)
self.assertEqual((res.k, res.stopped), (199, "discrepancy"))
self.assertAlmostEqual(res.x[1], 1.1 * (1.0 - 0.99 ** 199), places=10)
self.assertAlmostEqual(res.residuals[0], 1.00603, places=5)
self.assertGreater(res.residuals[198], 0.015)
x100 = landweber_matrix(a, [1.0, 0.11], omega=1.0, kmax=100).x
self.assertAlmostEqual(x100[1], 0.69736, places=5)
def test_filter_factors_match_svd(self):
rng = random.Random(11)
a = rand_matrix(rng, 7, 5)
y = [rng.gauss(0.0, 1.0) for _ in range(7)]
u, s, v = svd(a)
omega = 1.0 / (s[0] * s[0])
for k in (1, 3, 10, 40):
x = landweber_matrix(a, y, omega=omega, kmax=k).x
ref = [0.0] * 5
for i, si in enumerate(s):
c = filter_factor(omega, si, k) * sum(u[r][i] * y[r] for r in range(7)) / si
ref = [rj + c * v[j][i] for j, rj in enumerate(ref)]
for p, q in zip(x, ref):
self.assertAlmostEqual(p, q, places=10)
def test_residual_is_monotone(self):
rng = random.Random(12)
for _ in range(5):
a = rand_matrix(rng, 8, 6)
y = [rng.gauss(0.0, 1.0) for _ in range(8)]
res = landweber_matrix(a, y, kmax=60)
for r0, r1 in zip(res.residuals, res.residuals[1:]):
self.assertLessEqual(r1, r0 + 1e-12)
def test_exact_data_converges_to_minimum_norm_solution(self):
rng = random.Random(13)
b = rand_matrix(rng, 6, 2)
c = rand_matrix(rng, 2, 4)
a = [[sum(b[i][t] * c[t][j] for t in range(2)) for j in range(4)] for i in range(6)]
y = [rng.gauss(0.0, 1.0) for _ in range(6)]
u, s, v = svd(a)
omega = 1.0 / (s[0] * s[0])
x = landweber_matrix(a, y, omega=omega, kmax=4000).x
ref = pinv_solution(a, y)
self.assertLess(norm2([p - q for p, q in zip(x, ref)]), 1e-8 * norm2(ref))
def test_discrepancy_stop(self):
rng = random.Random(14)
a = rand_matrix(rng, 10, 6)
xt = [rng.gauss(0.0, 1.0) for _ in range(6)]
e = [rng.gauss(0.0, 1.0) for _ in range(10)]
delta = 0.05
ne = norm2(e)
y = [p + delta * q / ne for p, q in zip(matvec(a, xt), e)]
tau = 1.2
res = landweber_matrix(a, y, kmax=100000, delta=delta, tau=tau)
self.assertEqual(res.stopped, "discrepancy")
self.assertLessEqual(res.residuals[-1], tau * delta)
for r in res.residuals[:-1]:
self.assertGreater(r, tau * delta)
def test_data_error_bound(self):
rng = random.Random(15)
a = rand_matrix(rng, 9, 6)
u, s, v = svd(a)
omega = 1.0 / (s[0] * s[0])
y = [rng.gauss(0.0, 1.0) for _ in range(9)]
e = [rng.gauss(0.0, 1.0) for _ in range(9)]
delta = 1e-3
ne = norm2(e)
yd = [p + delta * q / ne for p, q in zip(y, e)]
for k in (1, 5, 25, 125):
x0 = landweber_matrix(a, y, omega=omega, kmax=k).x
x1 = landweber_matrix(a, yd, omega=omega, kmax=k).x
gap = norm2([p - q for p, q in zip(x0, x1)])
self.assertLessEqual(gap, math.sqrt(omega * k) * delta * (1 + 1e-12))
def test_rate_on_integration_operator(self):
# Diagonal model of (A x)(s) = int_0^s x on L^2(0, 1). x^dagger = 1 - t = A* 1
# has coefficients sqrt2 sigma_k^2, so nu = 1/2 and rho = 1. The noise sits on
# the component that the step count k amplifies most.
n = 200
sig = [2.0 / ((2 * k - 1) * math.pi) for k in range(1, n + 1)]
xd = [math.sqrt(2.0) * t * t for t in sig]
y = [t * x for t, x in zip(sig, xd)]
omega = 1.0 / (sig[0] * sig[0])
def op(x):
return [t * v for t, v in zip(sig, x)]
errs, deltas = [], [1e-2, 1e-3, 1e-4]
for delta in deltas:
k = math.ceil(1.0 / delta)
m = max(range(n), key=lambda i: filter_factor(omega, sig[i], k) / sig[i])
yd = list(y)
yd[m] += delta
x = landweber(op, op, yd, omega, k).x
err = norm2([p - q for p, q in zip(x, xd)])
self.assertLessEqual(err, error_bound(0.5, 1.0, omega, k, delta))
errs.append(err)
for i in range(2):
slope = math.log(errs[i] / errs[i + 1]) / math.log(deltas[i] / deltas[i + 1])
self.assertLess(abs(slope - 0.5), 0.15)
def test_matrix_free_operator(self):
n = 50
h = 1.0 / n
rng = random.Random(16)
x = [rng.gauss(0.0, 1.0) for _ in range(n)]
z = [rng.gauss(0.0, 1.0) for _ in range(n)]
self.assertLess(adjoint_gap(lambda w: cumsum(w, h), lambda w: rcumsum(w, h), x, z), 1e-12)
a = [[h if j <= i else 0.0 for j in range(n)] for i in range(n)]
y = [rng.gauss(0.0, 1.0) for _ in range(n)]
omega = 1.0 / sum(v * v for row in a for v in row)
free = landweber(lambda w: cumsum(w, h), lambda w: rcumsum(w, h), y, omega, 30).x
dense = landweber(lambda w: matvec(a, w), lambda w: rmatvec(a, w), y, omega, 30).x
for p, q in zip(free, dense):
self.assertAlmostEqual(p, q, places=10)
if __name__ == "__main__":
unittest.main()
History
Louis Landweber published the iteration in 1951 for Fredholm integral equations of the first kind and proved its convergence for exact data. Its role as a regularization method, with the iteration count as the parameter, the saturation-free rates under source conditions, and the discrepancy principle as a stopping rule, was worked out in the 1970s and 1980s and is summarized in Chapter 6 of Engl, Hanke and Neubauer (1996). SIRT in tomography is a weighted form of the same iteration.
References
- L. Landweber, An iteration formula for Fredholm integral equations of the first kind, American Journal of Mathematics 73(3), 1951, 615 to 624, the iteration and its convergence for exact data
- Heinz W. Engl, Martin Hanke and Andreas Neubauer, Regularization of Inverse Problems, Kluwer, 1996, Chapter 6 (Landweber iteration as a regularization method, its rates and the discrepancy principle) and Chapter 11 (the nonlinear Landweber iteration)
- Per Christian Hansen, Discrete Inverse Problems, Insight and Algorithms, SIAM, 2010, Chapter 6 (iterative regularization, semi-convergence)
Where this leads
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 G6JZZF Edit this page History Report an error Markdown