Algorithm Search⌘K

Algorithmresearch

Learned primal-dual reconstruction

Also called learned primal-dual.

An unrolled primal-dual scheme for inverse problems in which learned networks replace both proximal steps, and each of a fixed number of steps calls the forward operator and its adjoint once.

Time
O(K (a + g)) worst
Space
O(p n + d m) extra
Where
K = the number of steps; a = the cost of one call to A plus one call to its adjoint; d = the number of dual channels; g = the cost of one call to each of the two learned maps (outside this page); m = the number of data values; n = the number of unknowns; p = the number of primal channels
Properties
deterministicnot exactiterativelearnedmatrix free
Origin
Jonas Adler, Ozan Oktem, 2018

Learned primal-dual reconstruction is an unrolled version of the Chambolle-Pock algorithm for an inverse problem y=Ax+ey = Ax + e. It runs a fixed number KK of steps. In each step a learned dual map Γi\Gamma_i takes the dual state, the forward projection AxAx and the data yy, and a learned primal map Λi\Lambda_i takes the primal state and the back projection AThA^Th. The maps are small convolutional networks with separate weights in each step, and the primal and dual states have several channels that act as a memory. The whole scheme is trained end to end on pairs of images and data. Adler and Oktem (2018) introduced it for low-dose CT. With the maps set to the two proximal steps it is exactly Chambolle-Pock, and with other fixed maps it is gradient descent. For trained maps there is no convergence or correctness theorem; its accuracy is measured on test data.

In plain words

A classical solver for an imaging problem goes back and forth many times. It compares its current image with the measured data, sends the mismatch back into image space, and corrects the image with a fixed rule. The rules are the same for every patient and every step.

Learned primal-dual keeps the back and forth but lets small networks make the corrections. On the data side, a network looks at the old data-side state, at what the current image predicts, and at the real measurement, and decides on a new data-side state. On the image side, another network looks at the old image and at the sent-back mismatch, and decides on a new image. It does this a fixed number of times, for example ten, and each step has its own networks. The networks are trained on many examples so that the final image is close to the true one.

The problem

The model is y=Ax+ey = Ax + e with x∈Rnx \in \mathbb{R}^n the image, y∈Rmy \in \mathbb{R}^m the data and AA the forward operator, for example a discrete Radon transform. The variational approach minimizes Fy(Ax)+G(x)F_y(Ax) + G(x), for example 12∥Ax−y∥2+λ∥∇x∥1\tfrac12\|Ax - y\|^2 + \lambda\|\nabla x\|_1. The learned approach instead looks for a reconstruction operator RΘ:Rm→RnR_\Theta : \mathbb{R}^m \to \mathbb{R}^n with parameters Θ\Theta that minimizes the empirical risk 1N∑j=1N∥RΘ(yj)−xj∥2\frac1N\sum_{j=1}^N \|R_\Theta(y_j) - x_j\|^2 over training pairs (xj,yj)(x_j, y_j). Learned primal-dual is a choice of RΘR_\Theta that uses AA and ATA^T inside.

The input of the algorithm is the data yy, functions that apply AA and ATA^T, and the trained maps Γ1,…,ΓK\Gamma_1, \ldots, \Gamma_K and Λ1,…,ΛK\Lambda_1, \ldots, \Lambda_K. The output is an image x∈Rnx \in \mathbb{R}^n.

The algorithm

The primal state x=(x(1),…,x(p))x = (x^{(1)}, \ldots, x^{(p)}) has pp images, and the dual state h=(h(1),…,h(d))h = (h^{(1)}, \ldots, h^{(d)}) has dd vectors in data space. This is Algorithm 3 of Adler and Oktem for a linear operator, where the adjoint of the derivative is ATA^T.

  1. LEARNED-PRIMAL-DUAL(y, A, A^T, Γ_1..Γ_K, Λ_1..Λ_K, x_0, h_0)
  2. 1x ← x_0, h ← h_0 ▷ usually all zero
  3. 2for i = 1 to K
  4. 3h ← Γ_i(h, A x^(2), y) ▷ dual update, a given network
  5. 4x ← Λ_i(x, A^T h^(1)) ▷ primal update, a given network
  6. 5return x^(1)

Line L3 is the only place where the data enters. The dual map sees the old dual state, the forward projection of the second primal channel and the data. Line L4 is the only place where the adjoint enters: the primal map sees the old primal state and the back projection of the first dual channel. Each line calls the operator once, so a step costs one call to AA and one call to ATA^T, as a step of Chambolle-Pock does.

Chambolle-Pock as a special case. Take p=2p = 2, d=1d = 1, and for every step

Γi(h,z,y)=prox⁡σFy∗(h+σz),Λi((x(1),x(2)),w)=(u, 2u−x(1)),u=prox⁡τG(x(1)−τw).\Gamma_i(h, z, y) = \operatorname{prox}_{\sigma F_y^*}(h + \sigma z),\qquad \Lambda_i\big((x^{(1)}, x^{(2)}), w\big) = \big(u,\ 2u - x^{(1)}\big),\quad u = \operatorname{prox}_{\tau G}(x^{(1)} - \tau w).

Then x(1)x^{(1)} is the Chambolle-Pock iterate and x(2)x^{(2)} is the extrapolated point xˉ\bar x. This is Section III.D of the paper.

Gradient descent as a special case. Take p=d=1p = d = 1, Γi(h,z,y)=z−y\Gamma_i(h, z, y) = z - y and Λi(x,w)=x−ωw\Lambda_i(x, w) = x - \omega w. Then each step is x←x−ωAT(Ax−y)x \leftarrow x - \omega A^T(Ax - y), the Landweber iteration.

The trained version. Adler and Oktem use p=d=5p = d = 5 and K=10K = 10. Each map is a residual network: the identity plus three 3×33 \times 3 convolution layers, with PReLU activations after the first two. The input of a dual map has 7 channels (5 dual channels, Ax(2)Ax^{(2)} and yy), and the input of a primal map has 6 (5 primal channels and ATh(1)A^Th^{(1)}). The ten steps have separate weights, about 2.4⋅1052.4 \cdot 10^5 parameters in total. Training minimizes the mean squared error by Adam, with gradients from backpropagation through all steps, including through AA and ATA^T.

Example

The scalar problem A=1A = 1, y=1y = 1, Fy(z)=12(z−1)2F_y(z) = \tfrac12(z - 1)^2 and G(x)=12∣x∣G(x) = \tfrac12|x|, that is min⁡x12(x−1)2+12∣x∣\min_x \tfrac12(x - 1)^2 + \tfrac12|x|, has the solution x⋆=1/2x^\star = 1/2. The optimal dual value is h⋆=Ax⋆−y=−1/2h^\star = Ax^\star - y = -1/2. With τ=σ=1/2\tau = \sigma = 1/2 (so τσ∥A∥2=1/4<1\tau\sigma\|A\|^2 = 1/4 < 1), prox⁡σFy∗(v)=(v−σy)/(1+σ)\operatorname{prox}_{\sigma F_y^*}(v) = (v - \sigma y)/(1 + \sigma) and prox⁡τG\operatorname{prox}_{\tau G} the soft threshold at τ/2=1/4\tau/2 = 1/4. The Chambolle-Pock maps, started from zero, give:

step ii hh x(1)x^{(1)} x(2)=xˉx^{(2)} = \bar x
1 −1/3-1/3 00 00
2 −5/9-5/9 1/361/36 1/181/18
3 −37/54-37/54 13/10813/108 0.2130
4 −233/324-233/324 149/648149/648 0.3395
10 −0.5130-0.5130 0.51990.5199 0.5263

In step 1, line L3 gives h=(0+0−1/2)/(3/2)=−1/3h = (0 + 0 - 1/2)/(3/2) = -1/3, and line L4 gives u=soft⁡(0+1/6,1/4)=0u = \operatorname{soft}(0 + 1/6, 1/4) = 0. In step 2, h=(−1/3−1/2)/(3/2)=−5/9h = (-1/3 - 1/2)/(3/2) = -5/9 and u=soft⁡(5/18,1/4)=1/36u = \operatorname{soft}(5/18, 1/4) = 1/36. The iterates converge to (1/2,−1/2)(1/2, -1/2). A learned scheme with the same two calls per step could, for example, learn to take larger corrections in the first steps.

With the gradient maps, A=1A = 1, y=1y = 1 and ω=0.01\omega = 0.01, the scheme gives 1−0.99K1 - 0.99^{K} after KK steps, which is 0.63397 for K=100K = 100: the Landweber filter factor for ωσ2=0.01\omega\sigma^2 = 0.01.

Correctness

For trained maps there is no correctness theorem. The network maps have no convexity, no fixed point and no stopping rule, and the scheme is only as good as its training data. What is proved is in the proof file below. With the Chambolle-Pock maps, the scheme produces the Chambolle-Pock iterates exactly, by induction on the step; so it converges for τσ∥A∥2<1\tau\sigma\|A\|^2 < 1 by the theorem of Chambolle and Pock (2011, Theorem 1). With the gradient maps, it produces the Landweber iterates.

Adler and Oktem conclude that, since the class of schemes contains these methods, a trained scheme should do at least as well as they do with the same number of steps. This is a heuristic: it needs the networks to approximate the proximal maps well, and it needs the nonconvex training to find good weights.

Proof: With the Chambolle-Pock update maps, learned primal-dual is the Chambolle-Pock algorithm, and with the gradient maps it is Landweber iterationfull

Setting. A∈Rm×nA \in \mathbb{R}^{m \times n} is linear, y∈Rmy \in \mathbb{R}^m is the data, and the scheme of lines L1 to L5 runs KK steps. The primal state is x=(x(1),…,x(Np))x = (x^{(1)}, \ldots, x^{(N_p)}) with x(j)∈Rnx^{(j)} \in \mathbb{R}^n, and the dual state is h=(h(1),…,h(Nd))h = (h^{(1)}, \ldots, h^{(N_d)}) with h(j)∈Rmh^{(j)} \in \mathbb{R}^m. Step ii is

hi=Γi(hi−1,Axi−1(2),y),xi=Λi(xi−1,AThi(1)),h_i = \Gamma_i\big(h_{i-1}, A x^{(2)}_{i-1}, y\big),\qquad x_i = \Lambda_i\big(x_{i-1}, A^T h^{(1)}_i\big),

and the output is xK(1)x^{(1)}_K. For Np=1N_p = 1 the operator is applied to x(1)x^{(1)}. Because AA is linear, the adjoint of its derivative at any point is ATA^T; this is the case in which Algorithm 3 of Adler and Oktem (2018) uses ATA^T.

Nothing is proved here about trained maps Γi\Gamma_i and Λi\Lambda_i. The two statements below are about special choices of the maps. They show that the scheme contains two classical methods, and that the code is correct on these choices.

Chambolle-Pock. Let FF and GG be closed proper convex functions, with F=FyF = F_y depending on the data, and fix τ,σ>0\tau, \sigma > 0 and θ∈[0,1]\theta \in [0, 1]. Chambolle-Pock for min⁡xFy(Ax)+G(x)\min_x F_y(Ax) + G(x), started at x0x^0, xˉ0=x0\bar x^0 = x^0 and h0h^0, is

hi=prox⁡σFy∗(hi−1+σAxˉi−1),xi=prox⁡τG(xi−1−τAThi),xˉi=xi+θ(xi−xi−1).h^{i} = \operatorname{prox}_{\sigma F_y^*}(h^{i-1} + \sigma A\bar x^{i-1}),\qquad x^{i} = \operatorname{prox}_{\tau G}(x^{i-1} - \tau A^Th^{i}),\qquad \bar x^{i} = x^{i} + \theta(x^{i} - x^{i-1}).

Take Np=2N_p = 2, Nd=1N_d = 1 and, for every ii,

Γi(h,z,y)=prox⁡σFy∗(h+σz),Λi((u,v),w)=(p, (1+θ)p−θu)  with p=prox⁡τG(u−τw).\Gamma_i(h, z, y) = \operatorname{prox}_{\sigma F_y^*}(h + \sigma z),\qquad \Lambda_i\big((u, v), w\big) = \big(p,\ (1 + \theta)p - \theta u\big)\ \text{ with } p = \operatorname{prox}_{\tau G}(u - \tau w).

Claim 1. If the scheme starts at x0=(x0,x0)x_0 = (x^0, x^0) and h0=h0h_0 = h^0, then xi=(xi,xˉi)x_i = (x^i, \bar x^i) and hi=hih_i = h^i for every i≥0i \ge 0. In particular the output xK(1)x^{(1)}_K is the Chambolle-Pock iterate xKx^K.

Proof. By induction on ii. For i=0i = 0 the claim is the choice of the start, since xˉ0=x0\bar x^0 = x^0. Suppose it holds for i−1i - 1. Line L3 computes hi=Γi(hi−1,Axˉi−1,y)=prox⁡σFy∗(hi−1+σAxˉi−1)=hih_i = \Gamma_i(h^{i-1}, A\bar x^{i-1}, y) = \operatorname{prox}_{\sigma F_y^*}(h^{i-1} + \sigma A\bar x^{i-1}) = h^i. Line L4 computes p=prox⁡τG(xi−1−τAThi)=xip = \operatorname{prox}_{\tau G}(x^{i-1} - \tau A^Th^i) = x^i, and the second component (1+θ)xi−θxi−1=xi+θ(xi−xi−1)=xˉi(1 + \theta)x^i - \theta x^{i-1} = x^i + \theta(x^i - x^{i-1}) = \bar x^i. So xi=(xi,xˉi)x_i = (x^i, \bar x^i).

Consequence. With θ=1\theta = 1 and τσ∥A∥2<1\tau\sigma\|A\|^2 < 1, if a saddle point exists, the Chambolle-Pock iterates converge to a saddle point and the averages have a primal-dual gap of O(1/K)O(1/K) (Chambolle and Pock 2011, Theorem 1; see Chambolle-Pock algorithm). By Claim 1, learned primal-dual with these maps inherits both results. The test test_cp_maps_give_chambolle_pock_on_a_matrix compares the code with a direct Chambolle-Pock loop and finds equal iterates to 10−1210^{-12}.

Gradient descent. Take Np=Nd=1N_p = N_d = 1, Γi(h,z,y)=z−y\Gamma_i(h, z, y) = z - y and Λi(x,w)=x−ωw\Lambda_i(x, w) = x - \omega w for a step ω>0\omega > 0.

Claim 2. The output after KK steps is the KK-th iterate of Landweber iteration x←x−ωAT(Ax−y)x \leftarrow x - \omega A^T(Ax - y) from the same start.

Proof. Line L3 sets hi=Axi−1−yh_i = Ax_{i-1} - y, the residual, and line L4 sets xi=xi−1−ωAT(Axi−1−y)x_i = x_{i-1} - \omega A^T(Ax_{i-1} - y). This is one Landweber step, so induction on ii gives the claim. Landweber converges to the minimum norm least squares solution for x0=0x_0 = 0 and 0<ω<2/∥A∥20 < \omega < 2/\|A\|^2 (see Landweber iteration). With A=1A = 1, y=1y = 1, ω=0.01\omega = 0.01 and K=100K = 100 the output is 1−0.99100=0.633971 - 0.99^{100} = 0.63397, the Landweber filter factor at ωσ2=0.01\omega\sigma^2 = 0.01; the test checks this value.

What this does not prove. Adler and Oktem argue that, since the scheme contains these methods, a trained scheme with the same number of steps should do at least as well as they do. This is a heuristic. It needs the network class to contain or approximate the maps above, and it needs training to find the best maps, which a nonconvex training problem does not guarantee. Measured comparisons are reported on the page as measurements.

Complexity

The model is real-ram. Each of the KK steps calls AA once, ATA^T once and each learned map once. So the time is O(K(a+g))O(K(a + g)), where aa is the cost of one call to AA and one to ATA^T, and gg is the cost of the two networks. The cost of the networks depends on their architecture and is outside this page; for convolutional maps on an image of nn pixels it is linear in nn times the number of channels and weights. The extra space is O(pn+dm)O(pn + dm) for the states. Training needs the gradient through all KK steps, which by backpropagation costs a constant times the forward pass and stores all intermediate states, O(K(pn+dm))O(K(pn + dm)) memory, unless gradient checkpointing trades time for memory.

For comparison, Chambolle-Pock with the same KK costs O(Ka)O(Ka) plus two proximal steps per iteration, but it needs hundreds of iterations where the learned scheme uses ten.

Properties

  • Uses the physics. Every step calls AA and ATA^T, so the network never has to learn the forward model. This is the difference from post-processing networks that only clean up a filtered back projection.
  • Fixed cost. The number of steps is fixed before training, so the reconstruction time is known in advance.
  • Contains classical schemes. Chambolle-Pock and gradient descent are special cases, as shown above.
  • Measured results. Adler and Oktem report two CT tests. The first uses random ellipse phantoms on a 128×128128 \times 128 grid, a parallel beam geometry with 30 views and 182 detector pixels, and 5 percent Gaussian noise, with the Shepp-Logan phantom for validation. The second uses human abdomen images of 512×512512 \times 512 pixels from the Mayo Clinic low-dose CT challenge, a fan beam geometry with 1000 angles and Poisson noise with 10410^4 incident photons per pixel. In both tests learned primal-dual had the highest PSNR and SSIM among the methods compared, which included FBP, TV regularization and a learned post-processing network. On the ellipse data the gain over the learned gradient scheme and the post-processing network was more than 6 dB. The learned methods that call the operator were about 6 times slower than FBP plus a network, and at least 100 times faster than TV with 1000 iterations. These are measurements on those data sets, not properties of the algorithm.

Variants and improvements

  • Learned PDHG. Keep p=d=1p = d = 1, the update forms h+σAxh + \sigma Ax and x−τAThx - \tau A^Th, and the over-relaxation, and learn only the two proximal maps (Algorithm 2 of the paper). It did about as well as classical methods in their tests.
  • Learned primal. Fix the dual map to the residual Ax(2)−yAx^{(2)} - y and learn only the primal map. In the ellipse test it was the closest competitor, 1.3 dB behind.
  • Learned gradient (Adler and Oktem 2017). Feed the gradient of the data term to a learned update; this is the earlier scheme.
  • Nonlinear forward models. For a nonlinear operator T\mathcal{T}, line L4 uses the adjoint of the derivative [∂T(x(1))]∗[\partial\mathcal{T}(x^{(1)})]^*. The paper treats the pre-log CT model T(x)=e−μAx\mathcal{T}(x) = e^{-\mu Ax} this way.
  • Other unrolled schemes. The variational network unrolls a gradient scheme for MRI, and LISTA unrolls ISTA; see algorithm unrolling.

When to use it

Use learned primal-dual when the forward operator is known and fixed, when many training pairs from the same acquisition setting exist, and when the reconstruction must be fast and better than FBP on undersampled or noisy data, as in low-dose or sparse-view CT. Do not use it when the geometry or the noise level changes from scan to scan without retraining, when no training data exist, or when you need a guarantee such as a bound on the data misfit. Then a variational method or a plug-and-play scheme with an explicit data term is safer.

Pitfalls

  • Wrong adjoint. The scheme backpropagates through ATA^T, and a back projector that is not the exact adjoint of the projector gives wrong training gradients. Check ∣⟨Ax,h⟩−⟨x,ATh⟩∣|\langle Ax, h\rangle - \langle x, A^Th\rangle| on random vectors.
  • Distribution shift. A network trained at one dose, one geometry or one anatomy can produce plausible but wrong structures elsewhere. Evaluate on held-out data from the target setting.
  • Memory of training. Backpropagation through KK steps with large images stores all states; the memory, not the time, is often the limit.
  • Reading the PSNR as a guarantee. A higher mean PSNR on a test set does not bound the error on any one image.
  • Scaling. The data and the images must be scaled as in training; the network is not invariant to a change of units.

Implementations

The update maps are given functions: the code takes the lists Γ1,…,ΓK\Gamma_1, \ldots, \Gamma_K and Λ1,…,ΛK\Lambda_1, \ldots, \Lambda_K, and functions for AA and ATA^T, as arguments and runs lines L1 to L5 around them. The tests build the maps by hand, as the Chambolle-Pock maps and the gradient maps, or as small residual networks with weights from a fixed seed. No network is trained and no weights are downloaded. The tests check the adjoint of a periodic blur operator, the equality with a direct Chambolle-Pock loop on a matrix and on a blur, the example values above, convergence to the lasso solution (0,0,0.9)(0, 0, 0.9) of the LISTA example, the Landweber check value 0.63397, and that a step calls AA and ATA^T exactly once.

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.

learned_primal_dual.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/learned-primal-dual/. The authors are listed in prov/8N7P4C.jsonl.
"""Learned primal-dual reconstruction (Adler and Oktem 2018, Algorithm 3).

The update maps are given functions. The primal state is a list of N_p
vectors in R^n and the dual state a list of N_d vectors in R^m. In step i:

    h <- dual_maps[i](h, A x[1], y)        (a list of N_d vectors)
    x <- primal_maps[i](x, A^T h[0])       (a list of N_p vectors)

and the result is x[0]. The forward operator is linear here, so the adjoint
of its derivative is A^T. The functions cp_maps and gradient_maps build the
update maps for which the scheme is Chambolle-Pock or gradient descent.
With N_p = 1 the forward operator is applied to x[0].
"""

import math


def learned_primal_dual(y, apply_a, apply_at, dual_maps, primal_maps, x0, h0):
    """Run len(dual_maps) steps of the learned primal-dual scheme.

    x0 is a list of N_p primal vectors and h0 a list of N_d dual vectors.
    Each step calls apply_a once, apply_at once and each map once.
    Returns the first primal component.
    """
    x = [list(v) for v in x0]  # @line L1
    h = [list(v) for v in h0]  # @line L1
    for gamma, lam in zip(dual_maps, primal_maps):  # @line L2
        h = gamma(h, apply_a(x[1] if len(x) > 1 else x[0]), y)  # @line L3
        x = lam(x, apply_at(h[0]))  # @line L4
    return x[0]  # @line L5


def cp_maps(prox_tau_g, prox_sigma_fstar, tau, sigma, theta=1.0):
    """The pair (Gamma, Lambda) for which one step is one Chambolle-Pock step.

    N_p = 2 (x and the extrapolated point x_bar) and N_d = 1.
    prox_sigma_fstar(v, y) must return prox_{sigma F_y*}(v), and
    prox_tau_g(v) must return prox_{tau G}(v).
    """
    def gamma(h, a_xbar, y):
        return [prox_sigma_fstar([a + sigma * b for a, b in zip(h[0], a_xbar)], y)]

    def lam(x, at_h):
        new = prox_tau_g([a - tau * b for a, b in zip(x[0], at_h)])
        xbar = [(1.0 + theta) * a - theta * b for a, b in zip(new, x[0])]
        return [new, xbar]

    return gamma, lam


def gradient_maps(step):
    """The pair (Gamma, Lambda) for which one step is a gradient step on (1/2)||A x - y||^2.

    N_p = 1 and N_d = 1: the dual state is the residual A x - y, and the
    primal map is x - step * A^T h. This is Landweber iteration.
    """
    def gamma(h, a_x, y):
        return [[a - b for a, b in zip(a_x, y)]]

    def lam(x, at_h):
        return [[a - step * b for a, b in zip(x[0], at_h)]]

    return gamma, lam


def least_squares_dual_prox(sigma):
    """prox_{sigma F_y*} for F_y(z) = (1/2)||z - y||^2, that is (v - sigma y) / (1 + sigma)."""
    def prox(v, y):
        return [(a - sigma * b) / (1.0 + sigma) for a, b in zip(v, y)]
    return prox


def l1_prox(weight):
    """prox of weight * ||x||_1: soft thresholding at weight."""
    def prox(v):
        return [a - weight if a > weight else a + weight if a < -weight else 0.0 for a in v]
    return prox


def residual_network(rng, n_in, n_out, width, scale):
    """A small given network: v -> v[:n_out] + W2 tanh(W1 v + b1), with seeded weights.

    It stands in for a trained update map in tests; it is not trained.
    """
    w1 = [[rng.gauss(0.0, scale) for _ in range(n_in)] for _ in range(width)]
    b1 = [rng.gauss(0.0, scale) for _ in range(width)]
    w2 = [[rng.gauss(0.0, scale) for _ in range(width)] for _ in range(n_out)]

    def net(v):
        hidden = [math.tanh(sum(w * t for w, t in zip(row, v)) + b) for row, b in zip(w1, b1)]
        return [v[i] + sum(w * t for w, t in zip(row, hidden)) for i, row in enumerate(w2)]
    return net
test_learned_primal_dual.py 147 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/learned-primal-dual/. The authors are listed in prov/8N7P4C.jsonl.

import random

from learned_primal_dual import (
    cp_maps,
    gradient_maps,
    l1_prox,
    learned_primal_dual,
    least_squares_dual_prox,
    residual_network,
)


def matvec(a, x):
    return [sum(v * w for v, w in zip(row, x)) for row in a]


def rmatvec(a, y):
    return [sum(a[i][j] * y[i] for i in range(len(a))) for j in range(len(a[0]))]


def blur(kernel):
    """Periodic convolution with a kernel centered at index 0, and its adjoint (the correlation)."""
    def apply(x):
        n = len(x)
        return [sum(kernel[k] * x[(i - k) % n] for k in range(len(kernel))) for i in range(n)]

    def adjoint(y):
        n = len(y)
        return [sum(kernel[k] * y[(i + k) % n] for k in range(len(kernel))) for i in range(n)]
    return apply, adjoint


def chambolle_pock(apply_a, apply_at, y, lam, tau, sigma, iters, n, m):
    """Chambolle-Pock for (1/2)||A x - y||^2 + lam ||x||_1, written out directly."""
    x, xbar, h = [0.0] * n, [0.0] * n, [0.0] * m
    for _ in range(iters):
        ax = apply_a(xbar)
        h = [(hi + sigma * axi - sigma * yi) / (1.0 + sigma) for hi, axi, yi in zip(h, ax, y)]
        ath = apply_at(h)
        v = [xi - tau * gi for xi, gi in zip(x, ath)]
        t = tau * lam
        new = [vi - t if vi > t else vi + t if vi < -t else 0.0 for vi in v]
        xbar = [2.0 * a - b for a, b in zip(new, x)]
        x = new
    return x


def lpd_with_cp_maps(apply_a, apply_at, y, lam, tau, sigma, iters, n, m):
    gamma, lam_map = cp_maps(l1_prox(tau * lam), least_squares_dual_prox(sigma), tau, sigma)
    return learned_primal_dual(y, apply_a, apply_at, [gamma] * iters, [lam_map] * iters,
                               [[0.0] * n, [0.0] * n], [[0.0] * m])


def test_adjoint_of_the_blur_operator():
    rng = random.Random(11)
    apply_a, apply_at = blur([0.5, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2])
    for _ in range(5):
        x = [rng.gauss(0.0, 1.0) for _ in range(16)]
        y = [rng.gauss(0.0, 1.0) for _ in range(16)]
        ax, aty = apply_a(x), apply_at(y)
        gap = abs(sum(a * b for a, b in zip(ax, y)) - sum(a * b for a, b in zip(x, aty)))
        norm = sum(a * a for a in ax) ** 0.5 * sum(b * b for b in y) ** 0.5
        assert gap <= 1e-10 * norm


def test_cp_maps_give_chambolle_pock_on_a_matrix():
    rng = random.Random(5)
    m, n = 5, 8
    a = [[rng.gauss(0.0, 0.4) for _ in range(n)] for _ in range(m)]
    y = [rng.gauss(0.0, 1.0) for _ in range(m)]
    def fa(x): return matvec(a, x)
    def fat(h): return rmatvec(a, h)
    for k in (1, 2, 3, 7, 20):
        u = lpd_with_cp_maps(fa, fat, y, 0.1, 0.5, 0.5, k, n, m)
        v = chambolle_pock(fa, fat, y, 0.1, 0.5, 0.5, k, n, m)
        assert max(abs(p - q) for p, q in zip(u, v)) <= 1e-12


def test_cp_maps_give_chambolle_pock_on_a_blur():
    rng = random.Random(6)
    apply_a, apply_at = blur([0.5, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25])
    y = [rng.gauss(0.0, 1.0) for _ in range(12)]
    u = lpd_with_cp_maps(apply_a, apply_at, y, 0.05, 0.9, 0.9, 30, 12, 12)
    v = chambolle_pock(apply_a, apply_at, y, 0.05, 0.9, 0.9, 30, 12, 12)
    assert max(abs(p - q) for p, q in zip(u, v)) <= 1e-12


def test_scalar_example():
    def ident(x): return list(x)
    xs = [lpd_with_cp_maps(ident, ident, [1.0], 0.5, 0.5, 0.5, k, 1, 1)[0] for k in (1, 2, 3, 4)]
    assert abs(xs[0]) < 1e-15
    assert abs(xs[1] - 1 / 36) < 1e-15
    assert abs(xs[2] - 13 / 108) < 1e-15
    assert abs(xs[3] - 149 / 648) < 1e-15
    assert abs(lpd_with_cp_maps(ident, ident, [1.0], 0.5, 0.5, 0.5, 200, 1, 1)[0] - 0.5) < 1e-9


def test_cp_maps_reach_the_lasso_solution_of_the_lista_example():
    a = [[1.0, 0.0, 0.6], [0.0, 1.0, 0.8]]
    def fa(x): return matvec(a, x)
    def fat(h): return rmatvec(a, h)
    x = lpd_with_cp_maps(fa, fat, [0.6, 0.8], 0.1, 0.5, 0.5, 3000, 3, 2)
    assert max(abs(p - q) for p, q in zip(x, [0.0, 0.0, 0.9])) < 1e-8


def test_gradient_maps_give_landweber():
    gamma, lam = gradient_maps(0.01)
    def ident(x): return list(x)
    x = learned_primal_dual([1.0], ident, ident, [gamma] * 100, [lam] * 100, [[0.0]], [[0.0]])
    assert abs(x[0] - (1.0 - 0.99 ** 100)) < 1e-12
    assert abs(x[0] - 0.63397) < 5e-6


def test_given_networks_and_call_counts():
    rng = random.Random(21)
    n_p, n_d, m, n, iters = 3, 2, 6, 6, 4
    apply_a, apply_at = blur([0.6, 0.2, 0.0, 0.0, 0.0, 0.2])
    calls = {"a": 0, "at": 0}

    def counted_a(x):
        calls["a"] += 1
        return apply_a(x)

    def counted_at(h):
        calls["at"] += 1
        return apply_at(h)

    def split(v, parts, size):
        return [v[i * size:(i + 1) * size] for i in range(parts)]

    dual_maps, primal_maps = [], []
    for _ in range(iters):
        dnet = residual_network(rng, n_d * m + 2 * m, n_d * m, 8, 0.3)
        pnet = residual_network(rng, n_p * n + n, n_p * n, 8, 0.3)
        dual_maps.append(lambda h, ax, y, f=dnet: split(f([t for v in h for t in v] + ax + y), n_d, m))
        primal_maps.append(lambda x, ath, f=pnet: split(f([t for v in x for t in v] + ath), n_p, n))
    y = [rng.gauss(0.0, 1.0) for _ in range(m)]
    x0 = [[0.0] * n for _ in range(n_p)]
    h0 = [[0.0] * m for _ in range(n_d)]
    out1 = learned_primal_dual(y, counted_a, counted_at, dual_maps, primal_maps, x0, h0)
    assert calls == {"a": iters, "at": iters}
    out2 = learned_primal_dual(y, apply_a, apply_at, dual_maps, primal_maps, x0, h0)
    assert out1 == out2 and len(out1) == n
    assert any(abs(t) > 1e-6 for t in out1)

History

Gregor and LeCun (2010) unrolled ISTA into a trained network, and Yang, Sun, Li and Xu (2016) and Hammernik et al. (2018) unrolled ADMM and gradient schemes for MRI. Adler and Oktem (2017) proposed a partially learned gradient scheme for nonlinear inverse problems, and in 2018 they introduced learned primal-dual, which replaces both proximal maps of the primal-dual hybrid gradient method by networks and keeps a memory of several channels. It became a common baseline for learned CT reconstruction. The survey of Arridge, Maass, Oktem and Schonlieb (2019) places it among the data-driven methods for inverse problems.

References

  1. Jonas Adler and Ozan Oktem, Learned primal-dual reconstruction, IEEE Transactions on Medical Imaging 37(6), 2018 (arXiv 1707.06474), pages 1322 to 1332 (Section III.C and Algorithm 3 for the scheme, Section III.D for the reduction to PDHG and to gradient descent, Section IV for the CT data and the networks, Section V for the results)
  2. Jonas Adler and Ozan Oktem, Solving ill-posed inverse problems using iterative deep neural networks, Inverse Problems 33(12), 2017, article 124007 (the partially learned gradient scheme)
  3. Antonin Chambolle and Thomas Pock, A first-order primal-dual algorithm for convex problems with applications to imaging, Journal of Mathematical Imaging and Vision 40(1), 2011, pages 120 to 145 (Algorithm 1 and Theorem 1, the method that learned primal-dual contains)
  4. Simon Arridge, Peter Maass, Ozan Oktem and Carola-Bibiane Schonlieb, Solving inverse problems using data-driven models, Acta Numerica 28, 2019, pages 1 to 174 (survey of learned iterative schemes)

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.worst
  • 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