Algorithm Search⌘K

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.

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
Properties
deterministiciterativenot linear in datanot matrix free
Origin
A. B. Bakushinskii, 1992

The iteratively regularized Gauss-Newton method (IRGNM) solves a nonlinear ill-posed equation F(x)=yF(x) = y from noisy data yδy^\delta with ∥yδ−y∥≤δ\|y^\delta - y\| \le \delta. At the current iterate xkx_k it replaces FF by its linearization and solves a Tikhonov problem for the update. The penalty pulls toward the initial guess x0x_0, not toward xkx_k:

xk+1=xk+(F′(xk)∗F′(xk)+αkI)−1[F′(xk)∗(yδ−F(xk))+αk(x0−xk)],αk=α0qk.x_{k+1} = x_k + \big(F'(x_k)^* F'(x_k) + \alpha_k I\big)^{-1} \big[F'(x_k)^*(y^\delta - F(x_k)) + \alpha_k (x_0 - x_k)\big], \qquad \alpha_k = \alpha_0 q^k .

The weights αk\alpha_k 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 kk with ∥yδ−F(xk)∥≤τδ\|y^\delta - F(x_k)\| \le \tau\delta. For a linear F(x)=AxF(x) = A x, the iterate xk+1x_{k+1} is exactly the Tikhonov solution with parameter αk\alpha_k centered at x0x_0, 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 F:D(F)⊆X→YF: D(F) \subseteq X \to Y between Hilbert spaces (Rn→Rm\mathbb{R}^n \to \mathbb{R}^m in the code) with derivative F′(x)F'(x), data yδy^\delta with ∥yδ−F(x†)∥≤δ\|y^\delta - F(x^\dagger)\| \le \delta, the noise level δ\delta, and an initial guess x0x_0 (which carries the prior knowledge), find an approximation of a solution x†x^\dagger of F(x)=yF(x) = y near x0x_0 whose error tends to 0 as δ→0\delta \to 0.

The algorithm

  1. IRGNM(F, F', y, x₀, α₀, q, K, δ, τ) ▷ α₀ > 0, 0 < q < 1, τ > 1
  2. 1x ← x₀; α ← α₀
  3. 2for k ← 0 to K - 1 do
  4. 3if ‖y - F(x)‖ ≤ τ δ then return (x, k)
  5. 4J ← F'(x)
  6. 5solve (JᵀJ + α I) h = Jᵀ (y - F(x)) + α (x₀ - x)
  7. 6x ← x + h
  8. 7α ← q α
  9. 8return (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

min⁡h ∥y−F(x)−Jh∥2+α∥x+h−x0∥2,\min_h \ \|y - F(x) - J h\|^2 + \alpha \|x + h - x_0\|^2,

whose matrix is symmetric positive definite for α>0\alpha > 0; 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 kk steps αk=α0qk\alpha_k = \alpha_0 q^k. Line L8 returns after KK steps if the residual never reached τδ\tau\delta.

The difference from the Levenberg-Marquardt method is the center of the penalty. Levenberg-Marquardt penalizes the step ∥h∥\|h\|, which pulls toward xkx_k. IRGNM penalizes ∥xk+1−x0∥\|x_{k+1} - x_0\|, which keeps every iterate tied to the prior guess. This is what makes the convergence theory under a source condition on x†−x0x^\dagger - x_0 work.

Example

A scalar trace. Take F(x)=exF(x) = e^x, y=ey = e (so x†=1x^\dagger = 1), exact data, x0=0x_0 = 0, α0=1\alpha_0 = 1 and q=0.5q = 0.5. With J=exkJ = e^{x_k}, the step is xk+1=xk+(J(y−exk)−αkxk)/(J2+αk)x_{k+1} = x_k + \big(J(y - e^{x_k}) - \alpha_k x_k\big)/(J^2 + \alpha_k).

kk αk\alpha_k xkx_k ∣y−F(xk)∣\lvert y - F(x_k)\rvert
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, x1=0+(1⋅1.71828−0)/(1+1)=0.85914x_1 = 0 + (1 \cdot 1.71828 - 0)/(1 + 1) = 0.85914. After the first step the residual halves with each step, as αk\alpha_k does: the pull toward x0=0x_0 = 0 holds the iterate back by an amount proportional to αk\alpha_k. 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 F(x)(s)=∫0sex(t) dtF(x)(s) = \int_0^s e^{x(t)}\,dt on [0,1][0, 1] with n=32n = 32 cells, the truth x†(t)=0.5sin⁡(πt)x^\dagger(t) = 0.5\sin(\pi t), x0=0x_0 = 0, α0=1\alpha_0 = 1, q=0.5q = 0.5, τ=2\tau = 2, and Gaussian noise drawn with random.Random(2) and scaled to norm δ\delta. The error is the discrete L2L^2 norm ∥xk−x†∥/n\|x_k - x^\dagger\|/\sqrt n (a measurement).

kk αk\alpha_k residual, δ=10−2\delta = 10^{-2} error, δ=10−2\delta = 10^{-2} residual, δ=10−3\delta = 10^{-3} error, δ=10−3\delta = 10^{-3}
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 4.8⋅10−74.8 \cdot 10^{-7} 0.00001365 0.0655 0.000003936 0.0065

The discrepancy rule stops at k=9k = 9 for δ=10−2\delta = 10^{-2} and at k=12k = 12 for δ=10−3\delta = 10^{-3}. In both cases the stopped iterate has the smallest error of the whole run. Running on shows semi-convergence: for δ=10−2\delta = 10^{-2} the error grows by a factor of 3.33.3 while the residual falls far below the noise level. With exact data the error falls at every step, to below 0.000050.00005 at k=19k = 19.

Correctness

The proofs are in proofs/correctness.md, in exact arithmetic.

  • The step is well defined and optimal (theorem). For α>0\alpha > 0 the matrix of line L5 is symmetric positive definite, and x+hx + h is the unique minimizer of the linearized Tikhonov functional ∥y−F(x)−J(z−x)∥2+α∥z−x0∥2\|y - F(x) - J(z - x)\|^2 + \alpha\|z - x_0\|^2 over zz.
  • Linear case (theorem). If F(x)=AxF(x) = A x, then xk+1=x0+(A∗A+αkI)−1A∗(y−Ax0)x_{k+1} = x_0 + (A^* A + \alpha_k I)^{-1} A^*(y - A x_0) for every kk, whatever xkx_k is. So IRGNM is Tikhonov regularization centered at x0x_0, evaluated along the sequence α0,α0q,α0q2,…\alpha_0, \alpha_0 q, \alpha_0 q^2, \dots, and the rates and the saturation of Tikhonov regularization carry over (see Tikhonov convergence rates).
  • Termination (theorem). The loop ends after at most KK steps. In the linear case with τ>1\tau > 1, the test of line L3 passes after finitely many steps for every δ>0\delta > 0.

For nonlinear FF, convergence as δ→0\delta \to 0 and the rates O(δ2ν/(2ν+1))O(\delta^{2\nu/(2\nu+1)}) under a source condition x†−x0=(F′(x†)∗F′(x†))νwx^\dagger - x_0 = (F'(x^\dagger)^* F'(x^\dagger))^\nu w need extra conditions on how nonlinear FF is near x†x^\dagger (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. XX and YY are real Hilbert spaces (Rn\mathbb{R}^n and Rm\mathbb{R}^m in the code), F:X→YF: X \to Y is differentiable with derivative F′(x)F'(x), a bounded linear operator, and J∗J^* is the adjoint of JJ. The inputs are yδ∈Yy^\delta \in Y, x0∈Xx_0 \in X, α0>0\alpha_0 > 0, 0<q<10 < q < 1, an integer K≥1K \ge 1, δ≥0\delta \ge 0 and τ>1\tau > 1. In the pass of the loop with counter kk, the current iterate is xkx_k and the current weight is αk=α0qk\alpha_k = \alpha_0 q^k (line L1 sets α0\alpha_0 and line L7 multiplies by qq once per pass). Lines L4 to L6 compute xk+1=xk+hkx_{k+1} = x_k + h_k with

(Jk∗Jk+αkI) hk=Jk∗(yδ−F(xk))+αk(x0−xk),Jk=F′(xk).(1)(J_k^* J_k + \alpha_k I)\, h_k = J_k^*(y^\delta - F(x_k)) + \alpha_k (x_0 - x_k), \qquad J_k = F'(x_k). \tag{1}

Lemma 1 (the system of line L5 is uniquely solvable). For every bounded linear JJ and every α>0\alpha > 0, the operator J∗J+αIJ^* J + \alpha I is self-adjoint, satisfies ⟨(J∗J+αI)h,h⟩≥α∥h∥2\langle (J^* J + \alpha I) h, h\rangle \ge \alpha \|h\|^2, and is invertible with ∥(J∗J+αI)−1∥≤1/α\|(J^* J + \alpha I)^{-1}\| \le 1/\alpha.

Proof. Self-adjointness is clear. For every hh, ⟨(J∗J+αI)h,h⟩=∥Jh∥2+α∥h∥2≥α∥h∥2\langle (J^* J + \alpha I) h, h\rangle = \|J h\|^2 + \alpha\|h\|^2 \ge \alpha\|h\|^2. By the Cauchy-Schwarz inequality, ∥(J∗J+αI)h∥≥α∥h∥\|(J^* J + \alpha I) h\| \ge \alpha \|h\|, 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 {0}\{0\}. So the operator is bijective, and the bound on the inverse follows from ∥(J∗J+αI)h∥≥α∥h∥\|(J^* J + \alpha I) h\| \ge \alpha\|h\|. In Rn\mathbb{R}^n the matrix is symmetric positive definite, so Gaussian elimination solves it. □\square

Theorem 1 (each step minimizes the linearized Tikhonov functional). Let αk>0\alpha_k > 0, rk=yδ−F(xk)r_k = y^\delta - F(x_k) and

Φk(z)=∥rk−Jk(z−xk)∥2+αk∥z−x0∥2.\Phi_k(z) = \|r_k - J_k (z - x_k)\|^2 + \alpha_k \|z - x_0\|^2 .

Then xk+1=xk+hkx_{k+1} = x_k + h_k from (1) is the unique minimizer of Φk\Phi_k over XX.

Proof. Write z=xk+hz = x_k + h. Then Φk(xk+h)=∥rk−Jkh∥2+αk∥h−(x0−xk)∥2\Phi_k(x_k + h) = \|r_k - J_k h\|^2 + \alpha_k\|h - (x_0 - x_k)\|^2. Expanding at hkh_k in the direction gg,

Φk(xk+hk+g)=Φk(xk+hk)−2⟨Jk∗rk+αk(x0−xk)−(Jk∗Jk+αkI)hk, g⟩+∥Jkg∥2+αk∥g∥2.\Phi_k(x_k + h_k + g) = \Phi_k(x_k + h_k) - 2\big\langle J_k^* r_k + \alpha_k (x_0 - x_k) - (J_k^* J_k + \alpha_k I) h_k,\ g\big\rangle + \|J_k g\|^2 + \alpha_k\|g\|^2 .

By (1) the inner product is zero, so Φk(xk+hk+g)=Φk(xk+hk)+∥Jkg∥2+αk∥g∥2\Phi_k(x_k + h_k + g) = \Phi_k(x_k + h_k) + \|J_k g\|^2 + \alpha_k \|g\|^2, which is larger than Φk(xk+hk)\Phi_k(x_k + h_k) for every g≠0g \ne 0. By Lemma 1, (1) has exactly one solution hkh_k, so the minimizer exists and is unique. □\square

Theorem 2 (linear case: Tikhonov centered at x0x_0). Let F(x)=AxF(x) = A x with AA bounded and linear. Then for every kk for which line L6 runs,

xk+1=x0+(A∗A+αkI)−1A∗(yδ−Ax0),x_{k+1} = x_0 + (A^* A + \alpha_k I)^{-1} A^*(y^\delta - A x_0),

the minimizer of ∥Az−yδ∥2+αk∥z−x0∥2\|A z - y^\delta\|^2 + \alpha_k\|z - x_0\|^2. In particular xk+1x_{k+1} does not depend on xkx_k.

Proof. Here Jk=AJ_k = A and rk=yδ−Axkr_k = y^\delta - A x_k. Adding (A∗A+αkI)xk(A^* A + \alpha_k I) x_k to both sides of (1) gives

(A∗A+αkI) xk+1=A∗yδ−A∗Axk+αkx0−αkxk+A∗Axk+αkxk=A∗yδ+αkx0.(A^* A + \alpha_k I)\, x_{k+1} = A^* y^\delta - A^* A x_k + \alpha_k x_0 - \alpha_k x_k + A^* A x_k + \alpha_k x_k = A^* y^\delta + \alpha_k x_0 .

The vector w=x0+(A∗A+αkI)−1A∗(yδ−Ax0)w = x_0 + (A^* A + \alpha_k I)^{-1} A^*(y^\delta - A x_0) satisfies (A∗A+αkI)w=A∗Ax0+αkx0+A∗yδ−A∗Ax0=A∗yδ+αkx0(A^* A + \alpha_k I) w = A^* A x_0 + \alpha_k x_0 + A^* y^\delta - A^* A x_0 = A^* y^\delta + \alpha_k x_0. By Lemma 1 the solution is unique, so xk+1=wx_{k+1} = w. By Theorem 1 with Jk=AJ_k = A, Φk(z)=∥yδ−Az∥2+αk∥z−x0∥2\Phi_k(z) = \|y^\delta - A z\|^2 + \alpha_k\|z - x_0\|^2, and xk+1x_{k+1} is its minimizer. □\square

Theorem 3 (termination). (a) The algorithm stops after at most KK passes of the loop, at line L3 or at line L8. It returns (xk,k)(x_k, k) with k≤Kk \le K, and if it returns at line L3, then ∥yδ−F(xk)∥≤τδ\|y^\delta - F(x_k)\| \le \tau\delta.

(b) Let F(x)=AxF(x) = A x, y=Ax†y = A x^\dagger, ∥yδ−y∥≤δ\|y^\delta - y\| \le \delta with δ>0\delta > 0, and τ>1\tau > 1. Then there is an index k∗k_*, which does not depend on KK, such that the test of line L3 passes at some k≤k∗k \le k_*. So for K>k∗K > k_* the algorithm returns at line L3.

Proof. (a) Each pass either returns at line L3 or increases kk by one. The loop has at most KK passes, and line L8 returns after the last. Every pass is well defined by Lemma 1, because αk=α0qk>0\alpha_k = \alpha_0 q^k > 0. A return at line L3 happens only when its test holds.

(b) Let z=yδ−Ax0z = y^\delta - A x_0 and Rα=α(AA∗+αI)−1R_\alpha = \alpha (A A^* + \alpha I)^{-1}. From the identity A(A∗A+αI)−1A∗=AA∗(AA∗+αI)−1=I−RαA (A^* A + \alpha I)^{-1} A^* = A A^* (A A^* + \alpha I)^{-1} = I - R_\alpha (both sides agree after multiplication by AA∗+αIA A^* + \alpha I, which is invertible by Lemma 1 applied to A∗A^*) and Theorem 2,

yδ−Axk+1=z−A(A∗A+αkI)−1A∗z=Rαkz.y^\delta - A x_{k+1} = z - A (A^* A + \alpha_k I)^{-1} A^* z = R_{\alpha_k} z .

Let EE be the spectral measure of the self-adjoint operator AA∗≥0A A^* \ge 0 and PP the orthogonal projection onto N(A∗)=N(AA∗)\mathcal N(A^*) = \mathcal N(A A^*). Then

∥Rαz∥2=∫[0,∥A∥2](αλ+α)2d⟨Eλz,z⟩.\|R_\alpha z\|^2 = \int_{[0, \|A\|^2]} \Big(\frac{\alpha}{\lambda + \alpha}\Big)^2 d\langle E_\lambda z, z\rangle .

The integrand is at most 1 and tends to 00 for λ>0\lambda > 0 and to 11 at λ=0\lambda = 0 as α→0\alpha \to 0. By dominated convergence, ∥Rαz∥→∥Pz∥\|R_\alpha z\| \to \|P z\| as α→0\alpha \to 0. (For a matrix, write zz in the eigenvectors of AA⊤A A^\top and take the limit in each term.) Now y=Ax†y = A x^\dagger and Ax0A x_0 lie in the range of AA, which is orthogonal to N(A∗)\mathcal N(A^*), so Pz=P(yδ−y)P z = P (y^\delta - y) and ∥Pz∥≤∥yδ−y∥≤δ<τδ\|P z\| \le \|y^\delta - y\| \le \delta < \tau\delta. Since αk=α0qk→0\alpha_k = \alpha_0 q^k \to 0, there is a k0k_0 with ∥Rαkz∥≤τδ\|R_{\alpha_k} z\| \le \tau \delta for all k≥k0k \ge k_0, and k0k_0 depends only on AA, zz, α0\alpha_0, qq, τ\tau and δ\delta. Then ∥yδ−Axk0+1∥≤τδ\|y^\delta - A x_{k_0 + 1}\| \le \tau\delta, so the test of line L3 holds at k=k0+1k = k_0 + 1 at the latest, and k∗=k0+1k_* = k_0 + 1 works. □\square

Remark (nonlinear case). For nonlinear FF, part (b) needs conditions on FF near x†x^\dagger, for example a tangential cone condition or a range invariance condition for F′F', and an initial guess x0x_0 close enough to x†x^\dagger. Under such conditions, Blaschke, Neubauer and Scherzer (1997) proved that the discrepancy principle stops after finitely many steps and that the iterates converge to x†x^\dagger as δ→0\delta \to 0. These results are not proved here.

Complexity

  • Per step. One evaluation of FF at line L3, one Jacobian at line L4, forming JTJJ^T J in O(mn2)O(m n^2), and solving the n×nn \times n system in O(n3)O(n^3). With ff and jj the costs of FF and F′F', that is O(f+j+mn2+n3)O(f + j + m n^2 + n^3).
  • Steps. Each step multiplies α\alpha by qq. The rule stops once αk\alpha_k is small enough for the data error to reach the noise level, so the number of steps grows like log⁡(1/δ)\log(1/\delta) when the a priori analysis applies; in the example it went from 99 to 1212 when δ\delta fell by a factor of 1010.
  • Space. O(mn+n2)O(m n + n^2) for the Jacobian and the normal matrix.
  • Large problems. For images and wave fields, JJ is never formed. Line L5 is solved approximately by conjugate gradients on J∗J+αIJ^* J + \alpha I, with products JhJ h and J∗rJ^* r 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 x0x_0, 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 yδy^\delta.
  • Finite qualification. In the linear case it is Tikhonov regularization, so with an a priori stopping index its rate saturates at ν=1\nu = 1 (in the convention x†−x0=(A∗A)νwx^\dagger - x_0 = (A^* A)^\nu w).
  • Monotone weights. The sequence αk\alpha_k must not fall too fast: the theory asks for 1≤αk/αk+1≤r1 \le \alpha_k/\alpha_{k+1} \le r for some fixed rr, which q∈(0,1)q \in (0, 1) gives with r=1/qr = 1/q.

Variants and improvements

  • Inexact inner solves. Solve line L5 by conjugate gradients with a tolerance that tightens with kk (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 xkx_k and choose αk\alpha_k by an inner discrepancy rule (Hanke's method).
  • Constraints and Banach spaces. Add bounds on xx, or replace ∥x−x0∥2\|x - x_0\|^2 by a convex penalty such as total variation (Kaltenbacher, Neubauer and Scherzer 2008).
  • Nonlinear Landweber. xk+1=xk+ωF′(xk)∗(yδ−F(xk))x_{k+1} = x_k + \omega F'(x_k)^*(y^\delta - F(x_k)) 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 α\alpha and fits the noise; the error grows again, as in the table.
  • qq too small. If α\alpha drops too fast, the linearization is used far from where it is valid, and the iteration can diverge. Values from 0.50.5 to 0.90.9 are common.
  • α0\alpha_0 too small. The first step is then a nearly unregularized Gauss-Newton step from x0x_0, which can be wild. Start with α0\alpha_0 of the order of ∥F′(x0)∥2\|F'(x_0)\|^2.
  • A poor initial guess. The convergence theory is local: x†−x0x^\dagger - x_0 must be small and satisfy a source condition. The method converges to a solution near x0x_0, and the result can depend on x0x_0.
  • A wrong Jacobian at line L4. An inaccurate F′F' slows convergence and breaks the theory. Check it against finite differences, and check the adjoint code if J∗J^* 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.

imgla.pyI0RawGitHub
# 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

  1. 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)
  2. 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)
  3. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.per_iteration
  • a full proof of time.total
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example