Algorithmadvanced
Iteratively regularized Gauss-Newton method
Also called IRGNM.
Solve a nonlinear ill-posed equation by Gauss-Newton steps, each one regularized toward an initial guess with a weight that decreases geometrically.
- Solves
- Nonlinear least squares
- Time
- O(k (f + j + m n^2 + n^3)) totalO(f + j + m n^2 + n^3) per_iteration
- Space
- O(m n + n^2) extra
- Where
- f = the cost of one evaluation of F; j = the cost of one evaluation of the Jacobian; k = the number of Gauss-Newton steps; m = the number of data values; n = the number of unknowns
- Model
- Real RAM
- Properties
- deterministiciterativenot linear in datanot matrix free
- Evidence
- Proof sketchCode in 1 languages
- Origin
- A. B. Bakushinskii, 1992
The iteratively regularized Gauss-Newton method (IRGNM) solves a nonlinear ill-posed equation from noisy data with . At the current iterate it replaces by its linearization and solves a Tikhonov problem for the update. The penalty pulls toward the initial guess , not toward :
The weights fall geometrically, so the iteration fits the data more and more closely. With noisy data it must be stopped, usually by the discrepancy principle: at the first with . For a linear , the iterate is exactly the Tikhonov solution with parameter centered at , so the method is a nonlinear version of Tikhonov regularization with a decreasing parameter. It is a standard method for parameter identification, inverse scattering and impedance tomography.
In plain words
Gauss-Newton solves a nonlinear equation by repeatedly replacing it with a straight-line approximation and solving that. For an ill-posed problem each of these linear problems is unstable, so each one is solved with a Tikhonov penalty. The penalty asks the answer to stay near a fixed first guess. At first the penalty is strong, so the method makes only careful, smooth changes. Each step weakens the penalty by a fixed factor, so the method trusts the data more and more. When the predicted data match the measured data to within the noise, the method stops, because a closer fit would only fit the noise.
The problem
Given a differentiable map between Hilbert spaces ( in the code) with derivative , data with , the noise level , and an initial guess (which carries the prior knowledge), find an approximation of a solution of near whose error tends to 0 as .
The algorithm
IRGNM(F, F', y, x₀, α₀, q, K, δ, τ) ▷ α₀ > 0, 0 < q < 1, τ > 1- 1
x ← x₀; α ← α₀ - 2
for k ← 0 to K - 1 do - 3
if ‖y - F(x)‖ ≤ τ δ then return (x, k) - 4
J ← F'(x) - 5
solve (JᵀJ + α I) h = Jᵀ (y - F(x)) + α (x₀ - x) - 6
x ← x + h - 7
α ← q α - 8
return (x, K)
Line L1 starts at the initial guess, which is also the center of the penalty in every step. Line L3 is the discrepancy principle. Line L4 evaluates the Jacobian at the current iterate. Line L5 is the normal equation of the linearized Tikhonov problem
whose matrix is symmetric positive definite for ; the code solves it by Gaussian elimination. Line L6 takes the full step, with no line search. Line L7 lowers the weight, so that after steps . Line L8 returns after steps if the residual never reached .
The difference from the Levenberg-Marquardt method is the center of the penalty. Levenberg-Marquardt penalizes the step , which pulls toward . IRGNM penalizes , which keeps every iterate tied to the prior guess. This is what makes the convergence theory under a source condition on work.
Example
A scalar trace. Take , (so ), exact data, , and . With , the step is .
| 0 | 1 | 0 | 1.71828 |
| 1 | 0.5 | 0.85914 | 0.35715 |
| 2 | 0.25 | 0.92724 | 0.19075 |
| 3 | 0.125 | 0.96495 | 0.09362 |
| 4 | 0.0625 | 0.98279 | 0.04639 |
| 7 | 0.00781 | 0.99788 | 0.00575 |
For example, . After the first step the residual halves with each step, as does: the pull toward holds the iterate back by an amount proportional to . Plain Gauss-Newton would converge quadratically here, because this scalar problem is well posed; the regularization costs speed and buys stability.
A nonlinear integral equation. The test problem of the code is a discrete form of on with cells, the truth , , , , , and Gaussian noise drawn with random.Random(2) and scaled to norm . The error is the discrete norm (a measurement).
| residual, | error, | residual, | error, | ||
|---|---|---|---|---|---|
| 0 | 1 | 1.387 | 0.3536 | 1.389 | 0.3536 |
| 4 | 0.0625 | 0.2877 | 0.1219 | 0.2869 | 0.1223 |
| 8 | 0.0039 | 0.02766 | 0.0236 | 0.02664 | 0.0217 |
| 9 | 0.0020 | 0.01550 (stop) | 0.0196 | 0.01396 | 0.0139 |
| 12 | 0.00024 | 0.003811 | 0.0392 | 0.001917 (stop) | 0.0055 |
| 16 | 0.000015 | 0.0004085 | 0.0624 | 0.0001253 | 0.0063 |
| 21 | 0.00001365 | 0.0655 | 0.000003936 | 0.0065 |
The discrepancy rule stops at for and at for . In both cases the stopped iterate has the smallest error of the whole run. Running on shows semi-convergence: for the error grows by a factor of while the residual falls far below the noise level. With exact data the error falls at every step, to below at .
Correctness
The proofs are in proofs/correctness.md, in exact arithmetic.
- The step is well defined and optimal (theorem). For the matrix of line L5 is symmetric positive definite, and is the unique minimizer of the linearized Tikhonov functional over .
- Linear case (theorem). If , then for every , whatever is. So IRGNM is Tikhonov regularization centered at , evaluated along the sequence , and the rates and the saturation of Tikhonov regularization carry over (see Tikhonov convergence rates).
- Termination (theorem). The loop ends after at most steps. In the linear case with , the test of line L3 passes after finitely many steps for every .
For nonlinear , convergence as and the rates under a source condition need extra conditions on how nonlinear is near (Bakushinskii 1992 for an a priori stopping index; Blaschke, Neubauer and Scherzer 1997 for the discrepancy principle; Kaltenbacher, Neubauer and Scherzer 2008, Chapter 4). They are cited, not proved here.
Proof: Correctness of the iteratively regularized Gauss-Newton methodfull
Exact arithmetic. and are real Hilbert spaces ( and in the code), is differentiable with derivative , a bounded linear operator, and is the adjoint of . The inputs are , , , , an integer , and . In the pass of the loop with counter , the current iterate is and the current weight is (line L1 sets and line L7 multiplies by once per pass). Lines L4 to L6 compute with
Lemma 1 (the system of line L5 is uniquely solvable). For every bounded linear and every , the operator is self-adjoint, satisfies , and is invertible with .
Proof. Self-adjointness is clear. For every , . By the Cauchy-Schwarz inequality, , so the operator is injective with closed range. Its range is dense, because a vector orthogonal to the range is in the kernel of the (self-adjoint) operator, which is . So the operator is bijective, and the bound on the inverse follows from . In the matrix is symmetric positive definite, so Gaussian elimination solves it.
Theorem 1 (each step minimizes the linearized Tikhonov functional). Let , and
Then from (1) is the unique minimizer of over .
Proof. Write . Then . Expanding at in the direction ,
By (1) the inner product is zero, so , which is larger than for every . By Lemma 1, (1) has exactly one solution , so the minimizer exists and is unique.
Theorem 2 (linear case: Tikhonov centered at ). Let with bounded and linear. Then for every for which line L6 runs,
the minimizer of . In particular does not depend on .
Proof. Here and . Adding to both sides of (1) gives
The vector satisfies . By Lemma 1 the solution is unique, so . By Theorem 1 with , , and is its minimizer.
Theorem 3 (termination). (a) The algorithm stops after at most passes of the loop, at line L3 or at line L8. It returns with , and if it returns at line L3, then .
(b) Let , , with , and . Then there is an index , which does not depend on , such that the test of line L3 passes at some . So for the algorithm returns at line L3.
Proof. (a) Each pass either returns at line L3 or increases by one. The loop has at most passes, and line L8 returns after the last. Every pass is well defined by Lemma 1, because . A return at line L3 happens only when its test holds.
(b) Let and . From the identity (both sides agree after multiplication by , which is invertible by Lemma 1 applied to ) and Theorem 2,
Let be the spectral measure of the self-adjoint operator and the orthogonal projection onto . Then
The integrand is at most 1 and tends to for and to at as . By dominated convergence, as . (For a matrix, write in the eigenvectors of and take the limit in each term.) Now and lie in the range of , which is orthogonal to , so and . Since , there is a with for all , and depends only on , , , , and . Then , so the test of line L3 holds at at the latest, and works.
Remark (nonlinear case). For nonlinear , part (b) needs conditions on near , for example a tangential cone condition or a range invariance condition for , and an initial guess close enough to . Under such conditions, Blaschke, Neubauer and Scherzer (1997) proved that the discrepancy principle stops after finitely many steps and that the iterates converge to as . These results are not proved here.
Complexity
- Per step. One evaluation of at line L3, one Jacobian at line L4, forming in , and solving the system in . With and the costs of and , that is .
- Steps. Each step multiplies by . The rule stops once is small enough for the data error to reach the noise level, so the number of steps grows like when the a priori analysis applies; in the example it went from to when fell by a factor of .
- Space. for the Jacobian and the normal matrix.
- Large problems. For images and wave fields, is never formed. Line L5 is solved approximately by conjugate gradients on , with products and computed by linearized and adjoint solves. Then a step costs a few tens of forward and adjoint solves.
Properties
- Prior-centered. Every iterate is the minimizer of a Tikhonov functional centered at , so the iterates do not drift away from the prior as Gauss-Newton iterates can.
- Nonlinear in the data. Both the linearization points and the stopping index depend on .
- Finite qualification. In the linear case it is Tikhonov regularization, so with an a priori stopping index its rate saturates at (in the convention ).
- Monotone weights. The sequence must not fall too fast: the theory asks for for some fixed , which gives with .
Variants and improvements
- Inexact inner solves. Solve line L5 by conjugate gradients with a tolerance that tightens with (truncated Newton-CG methods).
- Other inner regularizations. Replace Tikhonov in line L5 by a few Landweber or CG steps, or by iterated Tikhonov to raise the qualification.
- Regularizing Levenberg-Marquardt. Center the penalty at and choose by an inner discrepancy rule (Hanke's method).
- Constraints and Banach spaces. Add bounds on , or replace by a convex penalty such as total variation (Kaltenbacher, Neubauer and Scherzer 2008).
- Nonlinear Landweber. is cheaper per step but needs many more steps (see Landweber iteration).
When to use it
Use IRGNM for a nonlinear inverse problem with a moderate number of unknowns, a Jacobian (or its products) that you can compute, a reasonable first guess, and a known noise level. Examples are coefficient identification in differential equations, inverse scattering, and electrical impedance tomography (see the Calderon problem). It needs far fewer steps than nonlinear Landweber. For very large problems where only a gradient is affordable, as in full waveform inversion, quasi-Newton methods with a fixed penalty are more common. For a well-posed nonlinear least squares problem, plain Gauss-Newton or Levenberg-Marquardt is faster.
Pitfalls
- No stopping rule. If line L3 is left out, the method keeps lowering and fits the noise; the error grows again, as in the table.
- too small. If drops too fast, the linearization is used far from where it is valid, and the iteration can diverge. Values from to are common.
- too small. The first step is then a nearly unregularized Gauss-Newton step from , which can be wild. Start with of the order of .
- A poor initial guess. The convergence theory is local: must be small and satisfy a source condition. The method converges to a solution near , and the result can depend on .
- A wrong Jacobian at line L4. An inaccurate slows convergence and breaks the theory. Check it against finite differences, and check the adjoint code if is applied matrix-free.
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
iteratively_regularized_gauss_newton.py 84 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iteratively-regularized-gauss-newton/. The authors are listed in prov/KK6851.jsonl.
"""The iteratively regularized Gauss-Newton method (IRGNM) for F(x) = y with noisy data.
One step solves a Tikhonov problem for the linearization of F at x_k, with
the penalty centered at the initial guess x0:
x_{k+1} = x_k + (J_k^T J_k + alpha_k I)^(-1) [J_k^T (y - F(x_k)) + alpha_k (x0 - x_k)],
where J_k = F'(x_k) and alpha_k = alpha0 q^k with 0 < q < 1. The method stops
by the discrepancy principle: at the first k with ||y - F(x_k)|| <= tau delta.
F returns a list and jac returns the Jacobian as a list of rows. The inner
system is solved by Gaussian elimination, which is exact on Fractions.
"""
import math
from imgla import matvec, solve
def _norm(v):
return math.sqrt(sum(t * t for t in v))
def irgnm_step(jac_x, r, x, x0, alpha):
"""Solve (J^T J + alpha I) h = J^T r + alpha (x0 - x) and return x + h."""
n = len(x)
jt = [[jac_x[i][j] for i in range(len(jac_x))] for j in range(n)]
m = [[sum(p * q for p, q in zip(jt[i], jt[j])) + (alpha if i == j else 0)
for j in range(n)] for i in range(n)]
jtr = [sum(p * q for p, q in zip(row, r)) for row in jt]
rhs = [g + alpha * (a - b) for g, a, b in zip(jtr, x0, x)]
h = solve(m, rhs) # @line L5
return [xi + hi for xi, hi in zip(x, h)] # @line L6
class IRGNMResult:
"""x: the last iterate; k: steps done; iterates: x_0, ..., x_k; residuals:
||y - F(x_j)||; alphas: alpha_j used in step j; stopped: "discrepancy" or "maxit"."""
def __init__(self, **kw):
self.__dict__.update(kw)
def irgnm(f, jac, y, x0, alpha0, q=0.5, kmax=50, delta=None, tau=2.0):
"""Run at most kmax IRGNM steps from x0 with alpha_k = alpha0 q^k."""
x = list(x0)
alpha = alpha0 # @line L1
iterates, residuals, alphas = [list(x)], [], []
for k in range(kmax): # @line L2
r = [yi - fi for yi, fi in zip(y, f(x))]
rn = _norm(r)
residuals.append(rn)
if delta is not None and rn <= tau * delta: # @line L3
return IRGNMResult(x=x, k=k, iterates=iterates, residuals=residuals,
alphas=alphas, stopped="discrepancy")
jx = jac(x) # @line L4
x = irgnm_step(jx, r, x, x0, alpha)
alphas.append(alpha)
alpha = alpha * q # @line L7
iterates.append(list(x))
residuals.append(_norm([yi - fi for yi, fi in zip(y, f(x))]))
stopped = "discrepancy" if delta is not None and residuals[-1] <= tau * delta else "maxit"
return IRGNMResult(x=x, k=kmax, iterates=iterates, residuals=residuals, # @line L8
alphas=alphas, stopped=stopped)
def exp_integration_problem(n):
"""F(x) = A exp(x) with (A x)_i = h (x_1 + ... + x_i), h = 1 / n.
This is a discrete form of F(x)(s) = int_0^s exp(x(t)) dt. Returns (F, F', A).
"""
h = 1.0 / n
a = [[h if j <= i else 0.0 for j in range(n)] for i in range(n)]
def f(x):
return matvec(a, [math.exp(t) for t in x])
def jac(x):
ex = [math.exp(t) for t in x]
return [[row[j] * ex[j] for j in range(n)] for row in a]
return f, jac, a
test_iteratively_regularized_gauss_newton.py 107 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iteratively-regularized-gauss-newton/. The authors are listed in prov/KK6851.jsonl.
import math
import random
import unittest
from fractions import Fraction
from imgla import adjoint_gap, matvec, norm2, rmatvec, solve
from iteratively_regularized_gauss_newton import exp_integration_problem, irgnm, irgnm_step
def smooth_truth(n):
return [0.5 * math.sin(math.pi * (i + 0.5) / n) for i in range(n)]
def noisy(y, delta, seed):
rng = random.Random(seed)
e = [rng.gauss(0.0, 1.0) for _ in range(len(y))]
ne = norm2(e)
return [p + delta * q / ne for p, q in zip(y, e)]
class TestIRGNM(unittest.TestCase):
def test_linear_case_is_centered_tikhonov(self):
rng = random.Random(51)
a = [[Fraction(rng.randint(-3, 3)) for _ in range(3)] for _ in range(4)]
y = [Fraction(rng.randint(-5, 5)) for _ in range(4)]
x0 = [Fraction(1), Fraction(-1), Fraction(2)]
alpha0, q = Fraction(2), Fraction(1, 2)
def f(x):
return [sum(p * t for p, t in zip(row, x)) for row in a]
res = irgnm(f, lambda x: a, y, x0, alpha0, q, kmax=4)
r0 = [p - t for p, t in zip(y, f(x0))]
for k in range(4):
alpha = alpha0 * q ** k
m = [[sum(a[r][i] * a[r][j] for r in range(4)) + (alpha if i == j else 0)
for j in range(3)] for i in range(3)]
h = solve(m, [sum(a[r][i] * r0[r] for r in range(4)) for i in range(3)])
self.assertEqual(res.iterates[k + 1], [p + t for p, t in zip(x0, h)])
def test_jacobian_and_adjoint(self):
n = 16
f, jac, a = exp_integration_problem(n)
rng = random.Random(52)
x = [rng.uniform(-0.5, 0.5) for _ in range(n)]
d = [rng.gauss(0.0, 1.0) for _ in range(n)]
eps = 1e-5
fp = f([p + eps * t for p, t in zip(x, d)])
fm = f([p - eps * t for p, t in zip(x, d)])
fd = [(p - t) / (2 * eps) for p, t in zip(fp, fm)]
jd = matvec(jac(x), d)
self.assertLess(norm2([p - t for p, t in zip(fd, jd)]), 1e-8 * norm2(jd))
j = jac(x)
z = [rng.gauss(0.0, 1.0) for _ in range(n)]
self.assertLess(adjoint_gap(lambda v: matvec(j, v), lambda v: rmatvec(j, v), d, z), 1e-12)
def test_step_minimizes_linearized_tikhonov(self):
n = 12
f, jac, a = exp_integration_problem(n)
rng = random.Random(53)
x = [rng.uniform(-0.5, 0.5) for _ in range(n)]
x0 = [0.0] * n
y = [rng.uniform(0.0, 1.0) for _ in range(n)]
r = [p - t for p, t in zip(y, f(x))]
alpha = 0.01
j = jac(x)
xn = irgnm_step(j, r, x, x0, alpha)
h = [p - t for p, t in zip(xn, x)]
# Gradient of ||J h - r||^2 + alpha ||x + h - x0||^2 is zero at the step.
g = rmatvec(j, [p - t for p, t in zip(matvec(j, h), r)])
g = [gi + alpha * (xi + hi - x0i) for gi, xi, hi, x0i in zip(g, x, h, x0)]
self.assertLess(norm2(g), 1e-12 * (norm2(rmatvec(j, r)) + alpha))
def test_exact_data_converges(self):
n = 32
f, jac, a = exp_integration_problem(n)
xt = smooth_truth(n)
res = irgnm(f, jac, f(xt), [0.0] * n, 1.0, 0.5, kmax=20)
errs = [norm2([p - q for p, q in zip(x, xt)]) / math.sqrt(n) for x in res.iterates]
self.assertLess(errs[-1], 0.005)
for e0, e1 in zip(errs, errs[1:]):
self.assertLess(e1, e0)
def test_discrepancy_stop(self):
n = 32
f, jac, a = exp_integration_problem(n)
xt = smooth_truth(n)
y = f(xt)
final = []
for delta in (1e-2, 1e-3):
yd = noisy(y, delta, 2)
res = irgnm(f, jac, yd, [0.0] * n, 1.0, 0.5, kmax=30, delta=delta, tau=2.0)
self.assertEqual(res.stopped, "discrepancy")
self.assertLessEqual(res.residuals[-1], 2.0 * delta)
for rn in res.residuals[:-1]:
self.assertGreater(rn, 2.0 * delta)
longer = irgnm(f, jac, yd, [0.0] * n, 1.0, 0.5, kmax=res.k + 8)
errs = [norm2([p - q for p, q in zip(x, xt)]) for x in longer.iterates]
self.assertLess(errs[res.k], 1.5 * min(errs))
final.append(errs[res.k])
self.assertLess(final[1], final[0])
if __name__ == "__main__":
unittest.main()
History
A. B. Bakushinskii proposed the method in 1992 and proved convergence with an a priori stopping index under a source condition. B. Blaschke (later Kaltenbacher), A. Neubauer and O. Scherzer proved convergence and rates with the discrepancy principle in 1997. The book of Kaltenbacher, Neubauer and Scherzer (2008) presents the theory of this and related Newton type methods, including inexact inner solves and Banach space versions.
References
- A. B. Bakushinskii, The problem of the convergence of the iteratively regularized Gauss-Newton method, Computational Mathematics and Mathematical Physics 32(9), 1992, 1353 to 1359, the method and its convergence with an a priori stopping rule (general locator)
- B. Blaschke, A. Neubauer and O. Scherzer, On convergence rates for the iteratively regularized Gauss-Newton method, IMA Journal of Numerical Analysis 17(3), 1997, 421 to 436, convergence and rates with the discrepancy principle under conditions on the nonlinearity (general locator)
- B. Kaltenbacher, A. Neubauer and O. Scherzer, Iterative Regularization Methods for Nonlinear Ill-Posed Problems, de Gruyter, Berlin, 2008, Chapter 4, Newton type methods (the IRGNM, its convergence and rates) (general locator)
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 KK6851 Edit this page History Report an error Markdown