Algorithm Search⌘K

Algorithmadvanced

One-step-late algorithm

Also called OSL MAP-EM, Green's one-step-late.

Add a prior to MLEM by evaluating the gradient of the penalty at the current image in the denominator of the update.

Time
O(K a d n) totalO(a d n) per_iteration
Space
O(a d + n^2) extra
Where
K = the number of iterations; a = the number of projection angles; d = the number of detector bins; n = the side of the n x n image
Properties
deterministicnot in placeiterativenot monotone objectiveiterative
Origin
Peter J. Green, 1990

The one-step-late algorithm (OSL) computes a penalized likelihood, or maximum a posteriori, image for the emission tomography model yi∼Poisson⁡((Ax+b)i)y_i \sim \operatorname{Poisson}((A x + b)_i). It maximizes Φ(x)=L(x)−βR(x)\Phi(x) = L(x) - \beta R(x), where LL is the Poisson log-likelihood, RR is a smooth penalty such as a sum of squared differences of neighbor pixels, and β≥0\beta \ge 0 sets its weight. The update is the MLEM update with one change: the gradient of the penalty, evaluated at the current image, is added to the denominator, xj←xjgj/(sj+β ∂R/∂xj(x))x_j \leftarrow x_j g_j / (s_j + \beta\, \partial R / \partial x_j(x)). This is cheap and easy to add to an MLEM code. Its fixed points are the maximizers of Φ\Phi. But the method is not a monotone method, and for a large β\beta a denominator can become zero or negative, which gives a negative or undefined image. Green proposed it in 1990.

In plain words

MLEM makes the counts more probable at each step, but with noisy data its images get noisy. A penalty fixes this: it adds a cost when a pixel differs from its neighbors, so the method prefers smooth images. MLEM with a penalty has no simple update, because the penalty ties each pixel to its neighbors.

The one-step-late trick looks at the neighbors in the old image, not the new one. If a pixel is brighter than its neighbors, its new value is divided by a larger number, so it goes down. If it is darker, its value is divided by a smaller number, so it goes up. This keeps the simple form of MLEM. The cost is that the correction is late by one step. If the penalty is strong, the correction can overshoot, and the method can fail.

The problem

Given counts yy, a matrix AA with aij≥0a_{ij} \ge 0 and column sums sj>0s_j > 0, a background b≥0b \ge 0, a weight β≥0\beta \ge 0 and a differentiable penalty RR, maximize

Φ(x)=∑i[yilog⁡yˉi−yˉi]−βR(x),yˉ=Ax+b,\Phi(x) = \sum_i \big[y_i \log \bar y_i - \bar y_i\big] - \beta R(x), \qquad \bar y = A x + b,

over x≥0x \ge 0. With a prior density proportional to e−βR(x)e^{-\beta R(x)}, the maximizer is the maximum a posteriori estimate, and the prior is a Gibbs distribution, a Markov random field on the pixel grid. The page uses the quadratic neighbor penalty

R(x)=12∑{j,k}∈Ewjk(xj−xk)2,∂R∂xj=∑k∼jwjk(xj−xk),R(x) = \tfrac12 \sum_{\{j,k\} \in E} w_{jk} (x_j - x_k)^2, \qquad \frac{\partial R}{\partial x_j} = \sum_{k \sim j} w_{jk} (x_j - x_k),

with EE the edges between neighbor pixels and wjk≥0w_{jk} \ge 0. Then Φ\Phi is concave, and a positive point is a maximizer if and only if ∇Φ=0\nabla \Phi = 0 there. Green's paper uses a log-cosh penalty, which grows more slowly for large differences and keeps edges better; the algorithm is the same.

The algorithm

  1. OSL(A, y, b, β, R, x0, K) ▷ x0 > 0; β ≥ 0; R is differentiable
  2. 1s_j ← Σ_i a_ij for each pixel j
  3. 2x ← x0
  4. 3for k ← 1 to K do
  5. 4ȳ ← A x + b ▷ the forward projection
  6. 5r_i ← y_i / ȳ_i for each bin i ▷ r_i ← 0 if y_i = 0
  7. 6g ← A^T r ▷ the back projection of the ratios
  8. 7u ← ∇R(x) ▷ the penalty gradient at the old image
  9. 8d_j ← s_j + β u_j; fail if some d_j ≤ 0
  10. 9x_j ← x_j g_j / d_j for each pixel j
  11. 10return x

Lines L4 to L6 are the same as in MLEM. Line L7 is the only new work, and for a neighbor penalty it costs O(n2)O(n^2). Line L8 is where the method can fail: the code raises an error, because a zero denominator has no result and a negative one gives a negative pixel. Some codes clip djd_j to a small positive number instead; that hides the failure but does not fix it. With β=0\beta = 0, OSL is MLEM.

Example

Take two pixels, each seen by one bin: A=IA = I, b=0b = 0, counts y=(1,3)y = (1, 3), and one edge between the pixels with w12=1w_{12} = 1. Then xjgj=yjx_j g_j = y_j and line L9 reads x1←1/(1+β(x1−x2))x_1 \leftarrow 1 / (1 + \beta (x_1 - x_2)) and x2←3/(1+β(x2−x1))x_2 \leftarrow 3 / (1 + \beta (x_2 - x_1)). The start is the flat image (2,2)(2, 2). There the penalty gradient is 0, so the first iterate is the MLEM image (1,3)(1, 3) for every β\beta.

iteration β=1/10\beta = 1/10 β=3/10\beta = 3/10 β=1\beta = 1
1 (1,3)(1, 3) (1,3)(1, 3) (1,3)(1, 3)
2 (5/4,5/2)(5/4, 5/2) (5/2,15/8)(5/2, 15/8) d1=−1d_1 = -1: fails
3 (8/7,8/3)(8/7, 8/3) (16/19,48/13)(16/19, 48/13)
4 (105/89,315/121)(105/89, 315/121) (1235/179,3705/2291)(1235/179, 3705/2291)
5 d2<0d_2 < 0: fails
maximizer of Φ\Phi (1.1696,2.6200)(1.1696, 2.6200) (1.3948,2.3382)(1.3948, 2.3382) (1.7071,2.1213)(1.7071, 2.1213)

For β=1/10\beta = 1/10 the iterates converge to the maximizer, and Φ\Phi rises at each step in this run: −0.9042-0.9042, −0.8561-0.8561, −0.8496-0.8496, …\ldots For β=3/10\beta = 3/10 the late correction overshoots: the bright pixel becomes the dark one and back, with a growing amplitude. Φ\Phi falls from −1.3042-1.3042 to −1.6315-1.6315 in the second step, and the fifth step has a negative denominator. For β=1\beta = 1, the second step would give x1=1/(1−2)=−1x_1 = 1/(1 - 2) = -1. For β=1/2\beta = 1/2 the denominator is exactly 0. In all three cases the maximizer is a positive point; only the iteration fails.

Correctness

A positive xx with positive denominators is a fixed point of line L9 if and only if gj(x)=sj+βuj(x)g_j(x) = s_j + \beta u_j(x) for every jj, that is ∂Φ/∂xj=0\partial \Phi / \partial x_j = 0. Since Φ\Phi is concave for a convex penalty, a positive fixed point is a maximizer. So when OSL converges to a positive point, the limit is the right answer.

The update is not the maximizer of a surrogate of Φ\Phi. Exact EM with a penalty leads to the coupled equations xjgj(x)/xj′−sj−βuj(x′)=0x_j g_j(x) / x'_j - s_j - \beta u_j(x') = 0, and OSL replaces uj(x′)u_j(x') with uj(x)u_j(x). So the monotone argument of MLEM does not apply. The example above proves that Φ\Phi can decrease and that a denominator can become 0 or negative. A sufficient condition for a positive denominator at a nonnegative image is β∑k∼jwjkxk<sj\beta \sum_{k \sim j} w_{jk} x_k < s_j, but it depends on the current image. Lange (1990) added a line search along the OSL step and proved that this modified method increases Φ\Phi and converges, under conditions on the penalty. The proofs are in proofs/correctness.md.

Proof: Fixed points of the one-step-late algorithm, and why it is not monotonefull

We use the notation of the page. AA is an m×Nm \times N matrix with aij≥0a_{ij} \ge 0 and column sums sj>0s_j > 0, b≥0b \ge 0, y≥0y \ge 0, β≥0\beta \ge 0, and

Φ(x)=L(x)−βR(x),L(x)=∑i[yilog⁡yˉi−yˉi],R(x)=12∑{j,k}∈Ewjk(xj−xk)2,\Phi(x) = L(x) - \beta R(x), \qquad L(x) = \sum_i \big[y_i \log \bar y_i - \bar y_i\big], \qquad R(x) = \tfrac12 \sum_{\{j,k\} \in E} w_{jk} (x_j - x_k)^2,

with yˉ=Ax+b\bar y = A x + b and weights wjk≥0w_{jk} \ge 0 on the edges EE. Write uj(x)=∂R/∂xj=∑k∼jwjk(xj−xk)u_j(x) = \partial R / \partial x_j = \sum_{k \sim j} w_{jk} (x_j - x_k) and gj(x)=∑iaijyi/yˉig_j(x) = \sum_i a_{ij} y_i / \bar y_i. One iteration (lines L4 to L9) maps xx to

xj′=xj gj(x)sj+βuj(x),(1)x'_j = \frac{x_j\, g_j(x)}{s_j + \beta u_j(x)}, \tag{1}

and it is defined only if every denominator dj(x)=sj+βuj(x)d_j(x) = s_j + \beta u_j(x) is positive. We work in exact arithmetic.

Where the update comes from. For a fixed admissible xx, the MLEM proof gives the surrogate L(x′)≥C+∑j[xjgj(x)log⁡xj′−sjxj′]L(x') \ge C + \sum_j [x_j g_j(x) \log x'_j - s_j x'_j]. Maximizing this surrogate minus βR(x′)\beta R(x') would need the solution of the coupled equations

xjgj(x)xj′−sj−βuj(x′)=0for all j,\frac{x_j g_j(x)}{x'_j} - s_j - \beta u_j(x') = 0 \quad \text{for all } j,

which couple the pixels through uj(x′)u_j(x'). Green's idea is to evaluate uju_j one step late, at the old image xx. Then each equation has one unknown and the solution is (1). So (1) is not the maximizer of a surrogate of Φ\Phi, and the monotone argument of MLEM does not apply.

Theorem 1 (fixed points). Let x>0x > 0 with yˉi>0\bar y_i > 0 wherever yi>0y_i > 0, and dj(x)>0d_j(x) > 0 for all jj. Then xx is a fixed point of (1) if and only if ∇Φ(x)=0\nabla \Phi(x) = 0.

Proof. ∂Φ/∂xj=gj(x)−sj−βuj(x)\partial \Phi / \partial x_j = g_j(x) - s_j - \beta u_j(x). Since xj>0x_j > 0 and dj(x)>0d_j(x) > 0, (1) gives xj′=xjx'_j = x_j if and only if gj(x)=sj+βuj(x)g_j(x) = s_j + \beta u_j(x), that is ∂Φ/∂xj=0\partial \Phi / \partial x_j = 0. □\square

Φ\Phi is concave, because LL is concave and RR is a convex quadratic. So a positive fixed point is a maximizer of Φ\Phi over x≥0x \ge 0. If Φ\Phi is strictly concave (for example if AA has full column rank on the rows with yi>0y_i > 0), it is the unique maximizer.

Theorem 2 (a sufficient condition for a positive denominator). If x≥0x \ge 0 and β∑k∼jwjkxk<sj\beta \sum_{k \sim j} w_{jk} x_k < s_j, then dj(x)>0d_j(x) > 0.

Proof. uj(x)=xj∑k∼jwjk−∑k∼jwjkxk≥−∑k∼jwjkxku_j(x) = x_j \sum_{k \sim j} w_{jk} - \sum_{k \sim j} w_{jk} x_k \ge -\sum_{k \sim j} w_{jk} x_k, because xj≥0x_j \ge 0. So dj(x)≥sj−β∑k∼jwjkxk>0d_j(x) \ge s_j - \beta \sum_{k \sim j} w_{jk} x_k > 0. □\square

The condition depends on the current image, so it cannot be checked once in advance. For a fixed image it holds for β\beta small enough, and it can fail for a large β\beta, as the next theorem shows.

Theorem 3 (failure for a large beta). There are data and a β>0\beta > 0 for which the second iterate has a nonpositive denominator, and data and a β>0\beta > 0 for which Φ\Phi decreases from one iterate to the next.

Proof. Take two pixels, A=IA = I, b=0b = 0, y=(1,3)y = (1, 3), one edge with w12=1w_{12} = 1, and the start x0=(2,2)x^0 = (2, 2). Then gj(x)=yj/xjg_j(x) = y_j / x_j, so xjgj(x)=yjx_j g_j(x) = y_j and (1) reads x1′=1/(1+β(x1−x2))x'_1 = 1 / (1 + \beta (x_1 - x_2)) and x2′=3/(1+β(x2−x1))x'_2 = 3 / (1 + \beta (x_2 - x_1)). At x0x^0 the penalty gradient is 0, so x1=(1,3)x^1 = (1, 3) for every β\beta. At x1x^1, d1=1−2βd_1 = 1 - 2\beta, which is 0 for β=1/2\beta = 1/2 and −1-1 for β=1\beta = 1. For β=1\beta = 1 the formula (1) would give x12=1/(−1)=−1<0x^2_1 = 1/(-1) = -1 < 0.

For β=3/10\beta = 3/10, d1(x1)=2/5d_1(x^1) = 2/5 and d2(x1)=8/5d_2(x^1) = 8/5, so x2=(5/2,15/8)x^2 = (5/2, 15/8). Then

Φ(x1)=log⁡1−1+3log⁡3−3−320⋅4=−1.3042,Φ(x2)=log⁡52−52+3log⁡158−158−320⋅2564=−1.6315,\Phi(x^1) = \log 1 - 1 + 3 \log 3 - 3 - \tfrac{3}{20} \cdot 4 = -1.3042, \qquad \Phi(x^2) = \log \tfrac52 - \tfrac52 + 3 \log \tfrac{15}{8} - \tfrac{15}{8} - \tfrac{3}{20} \cdot \tfrac{25}{64} = -1.6315,

so Φ(x2)<Φ(x1)\Phi(x^2) < \Phi(x^1). □\square

In the same example with β=3/10\beta = 3/10 the iterates oscillate with a growing amplitude: x3=(16/19,48/13)x^3 = (16/19, 48/13), x4=(1235/179,3705/2291)x^4 = (1235/179, 3705/2291), and d2(x4)<0d_2(x^4) < 0. The maximizer of Φ\Phi for β=3/10\beta = 3/10 is about (1.395,2.338)(1.395, 2.338), a positive point. So the failure is a property of the iteration, not of the problem.

Convergence (cited, not proved here). Green (1990) gave no general convergence proof. Lange (1990) showed that a modified OSL with a line search along the OSL direction increases Φ\Phi at each step and converges under conditions on the penalty. For a small β\beta the plain update usually converges in practice; this is an observation, as in the β=1/10\beta = 1/10 example of the page.

Complexity

In the real-RAM model, with aa angles of dd bins and an n×nn \times n image, one iteration costs one forward and one back projection, O(adn)O(a d n), plus O(n2)O(n^2) for the gradient of a neighbor penalty. So it costs O(adn)O(a d n) time and O(ad+n2)O(a d + n^2) extra space, and KK iterations cost O(Kadn)O(K a d n). The number of iterations to converge is not bounded by a theorem, and the method may not converge at all.

Properties

  • The same cost as MLEM. It needs only the projector pair and the penalty gradient.
  • Correct fixed points. A positive limit is a maximizer of the penalized likelihood.
  • Not monotone. Φ\Phi can decrease, as the example shows.
  • Not always positive. The image stays positive only while every denominator is positive. A strong penalty or a steep edge can break this.
  • Converges for a small weight, in practice. With a small β\beta the method behaves like MLEM, and it converges in the runs of the tests. This is an observation, not a theorem.
  • Not linear in the data, like MLEM.

Variants and improvements

  • OSL with a line search. Lange (1990) searched along the step from xx to the OSL image for a point that raises Φ\Phi. This gives a monotone method with a convergence proof.
  • Ordered subsets. The OSL denominator can be used in each sub-iteration of OSEM. Then the penalty gradient is usually scaled by 1/T1/T for TT subsets. The result has the same convergence problems as OSEM.
  • Other penalties. Any differentiable penalty fits: log-cosh, Huber or a smoothed total variation. With total variation the method is used for deconvolution as Richardson-Lucy with total variation.
  • Monotone alternatives. De Pierro's modified EM and separable paraboloidal surrogates find a separable surrogate of the penalty too. They keep the monotone property for any β\beta, at a similar cost per iteration.

When to use it

Use OSL when you have an MLEM or OSEM code and want a quick penalized result with a small β\beta, for example to reduce the noise without changing the code much. Check the denominators at each iteration. Use SPS or another monotone method when β\beta is large, when you need a guarantee, or when the image must match the true maximizer, for example in a study of the penalty.

Pitfalls

  • A large β\beta. The denominator can become 0 or negative. The failure can come after a few good steps, as in the β=3/10\beta = 3/10 example.
  • Clipping the denominator. Replacing a negative djd_j with a small positive number avoids the crash, but the iteration then has no relation to Φ\Phi, and its limit is not the maximizer.
  • Assuming a monotone objective. Do not test Φ\Phi for a monotone increase, and do not use its increase as a stopping rule.
  • A non-convex penalty. With a non-convex penalty, Φ\Phi has many stationary points, and a fixed point need not be a maximizer.
  • The scale of β\beta. β\beta multiplies a penalty whose size depends on the units of xx and on the counts. A value that works for one scan can fail for another with more counts or a different matrix.

Implementations

The Python code takes the system matrix as sparse rows of (column, weight) pairs, a list of edges with weights for the quadratic neighbor penalty, and works with float or fractions.Fraction data. It raises an error when a denominator is not positive. The tests check the iterates of the example exactly for β=1/10\beta = 1/10, 3/103/10, 1/21/2 and 11, the limit and the penalized KKT equations, the decrease of Φ\Phi and the failure for β=3/10\beta = 3/10, the case β=0\beta = 0 against MLEM, a fixed point on a random 4×44 \times 4 problem, the penalty gradient against finite differences, and the adjoint test of the projector pair.

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.

one_step_late_algorithm.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/one-step-late-algorithm/. The authors are listed in prov/J6NCZD.jsonl.
"""Green's one-step-late (OSL) algorithm for penalized likelihood emission
reconstruction.

The model is y_i ~ Poisson((A x)_i + b_i), and the goal is to maximize

    Phi(x) = L(x) - beta R(x),  L(x) = sum_i [y_i log ybar_i - ybar_i],

over x >= 0, with the quadratic neighbor penalty R(x) = (1/2) sum over the
edges {j, k} of w_jk (x_j - x_k)^2. One iteration is the MLEM update with the
gradient of R at the old image in the denominator:

    x_j <- x_j (sum_i a_ij y_i / ybar_i) / (s_j + beta dR/dx_j(x)).

A is given as sparse rows of (column, weight) pairs. A denominator that is
not positive raises ValueError, because the update would then be negative or
undefined. The update works with float or fractions.Fraction data.
"""

import math


def forward(rows, x):
    """A x for sparse rows."""
    return [sum(w * x[j] for j, w in row) for row in rows]


def back(rows, v, ncols):
    """A^T v for sparse rows with ncols columns."""
    out = [0 * v[0] if v else 0] * ncols
    for row, vi in zip(rows, v):
        if vi != 0:
            for j, w in row:
                out[j] += w * vi
    return out


def grid_edges(n, weight=1):
    """The edges (j, k, w) of the 4-neighbor graph of an n x n image, each once."""
    edges = []
    for i in range(n):
        for j in range(n):
            p = i * n + j
            if j + 1 < n:
                edges.append((p, p + 1, weight))
            if i + 1 < n:
                edges.append((p, p + n, weight))
    return edges


def penalty(x, edges):
    """R(x) = (1/2) sum w_jk (x_j - x_k)^2 over the edges."""
    return sum(w * (x[j] - x[k]) ** 2 for j, k, w in edges) / 2


def penalty_grad(x, edges):
    """dR/dx_j = sum over the neighbors k of w_jk (x_j - x_k)."""
    g = [0 * x[0]] * len(x)
    for j, k, w in edges:
        d = w * (x[j] - x[k])
        g[j] += d
        g[k] -= d
    return g


def objective(rows, y, x, beta, edges, b=None):
    """Phi(x) = L(x) - beta R(x) as a float; -inf if a ray with y_i > 0 has ybar_i <= 0."""
    total = 0.0
    for i, (row, yi) in enumerate(zip(rows, y)):
        li = sum(w * x[j] for j, w in row) + (b[i] if b is not None else 0)
        if yi != 0:
            if li <= 0:
                return -math.inf
            total += float(yi) * math.log(float(li))
        total -= float(li)
    return total - float(beta) * float(penalty(x, edges))


def osl(rows, ncols, y, beta, edges, b=None, iters=50, x0=None, callback=None):
    """Run the one-step-late algorithm and return the image after iters iterations.

    beta >= 0 is the penalty weight; edges is a list of (j, k, w) with w >= 0;
    x0 is a positive start (by default the constant image whose projections
    have the total count of y); callback(k, x) is called after each iteration.
    """
    s = [0] * ncols  # @line L1
    for row in rows:
        for j, w in row:
            s[j] += w
    if x0 is None:
        c = sum(y) / sum(s)
        x0 = [c] * ncols
    x = list(x0)  # @line L2
    for k in range(iters):  # @line L3
        ybar = forward(rows, x)  # @line L4
        if b is not None:
            ybar = [li + bi for li, bi in zip(ybar, b)]
        ratio = [yi / li if yi != 0 else 0 * li for yi, li in zip(y, ybar)]  # @line L5
        g = back(rows, ratio, ncols)  # @line L6
        u = penalty_grad(x, edges)  # @line L7
        den = [sj + beta * uj for sj, uj in zip(s, u)]  # @line L8
        for j, dj in enumerate(den):
            if dj <= 0:
                raise ValueError("nonpositive denominator at pixel %d" % j)
        x = [xj * gj / dj for xj, gj, dj in zip(x, g, den)]  # @line L9
        if callback is not None:
            callback(k + 1, x)
    return x  # @line L10
test_one_step_late_algorithm.py 115 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/one-step-late-algorithm/. The authors are listed in prov/J6NCZD.jsonl.

import math
import random
from fractions import Fraction as F

from one_step_late_algorithm import back, forward, grid_edges, objective, osl, penalty, penalty_grad

# The two-pixel example of the page: A = I, y = (1, 3), one edge of weight 1.
ROWS2 = [[(0, F(1))], [(1, F(1))]]
Y2 = [F(1), F(3)]
E2 = [(0, 1, 1)]


def _iterates(beta, iters):
    seen = []
    try:
        osl(ROWS2, 2, Y2, beta, E2, iters=iters, callback=lambda k, x: seen.append(x))
    except ValueError:
        return seen, True
    return seen, False


def _random_problem(rng, n):
    rows = []
    for _ in range(3 * n * n):
        row = [(j, rng.uniform(0.1, 1.0)) for j in range(n * n) if rng.random() < 0.4]
        rows.append(row or [(rng.randrange(n * n), 0.5)])
    xt = [rng.uniform(0.5, 2.0) for _ in range(n * n)]
    lam = forward(rows, xt)
    y = []
    for v in lam:
        # Poisson sample by the product method; the means here are small
        k, p, limit = 0, rng.random(), math.exp(-5.0 * v)
        while p > limit:
            k += 1
            p *= rng.random()
        y.append(k)
    return [[(j, 5.0 * w) for j, w in row] for row in rows], y


def test_small_beta_exact_iterates_and_limit() -> None:
    seen, failed = _iterates(F(1, 10), 4)
    assert not failed
    assert seen == [[F(1), F(3)], [F(5, 4), F(5, 2)], [F(8, 7), F(8, 3)], [F(105, 89), F(315, 121)]]
    x = osl([[(0, 1.0)], [(1, 1.0)]], 2, [1.0, 3.0], 0.1, E2, iters=200)
    assert abs(x[0] - 1.1696403991) < 1e-9 and abs(x[1] - 2.6200041112) < 1e-9
    # the penalized KKT equations: y_j / x_j - 1 - beta dR/dx_j = 0
    g = penalty_grad(x, E2)
    assert abs(1 / x[0] - 1 - 0.1 * g[0]) < 1e-12 and abs(3 / x[1] - 1 - 0.1 * g[1]) < 1e-12


def test_medium_beta_oscillates_and_fails() -> None:
    seen, failed = _iterates(F(3, 10), 10)
    assert seen[:4] == [[F(1), F(3)], [F(5, 2), F(15, 8)], [F(16, 19), F(48, 13)], [F(1235, 179), F(3705, 2291)]]
    assert failed and len(seen) == 4
    obj = [objective(ROWS2, Y2, x, F(3, 10), E2) for x in seen]
    assert obj[1] < obj[0] and obj[3] < obj[2]


def test_large_beta_gives_a_nonpositive_denominator() -> None:
    seen, failed = _iterates(F(1), 5)
    assert failed and seen == [[F(1), F(3)]]
    x = seen[0]
    den0 = 1 + 1 * penalty_grad(x, E2)[0]
    assert den0 == -1 and x[0] * (Y2[0] / x[0]) / den0 == -1
    seen, failed = _iterates(F(1, 2), 5)
    assert failed and 1 + F(1, 2) * penalty_grad(seen[0], E2)[0] == 0


def test_beta_zero_is_mlem() -> None:
    a = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1]]
    rows = [[(j, F(w)) for j, w in enumerate(r) if w] for r in a]
    x = osl(rows, 4, [F(v) for v in (3, 7, 4, 6, 5)], F(0), grid_edges(2), iters=1, x0=[F(1)] * 4)
    assert x == [F(2), F(9, 4), F(11, 4), F(3)]


def test_fixed_point_satisfies_the_penalized_kkt_conditions() -> None:
    rng = random.Random(6)
    n = 4
    rows, y = _random_problem(rng, n)
    edges = grid_edges(n)
    beta = 0.05
    x = osl(rows, n * n, y, beta, edges, iters=2500)
    assert all(v > 0 for v in x)
    ybar = forward(rows, x)
    grad_l = back(rows, [yi / li for yi, li in zip(y, ybar)], n * n)
    s = back(rows, [1.0] * len(rows), n * n)
    u = penalty_grad(x, edges)
    for gj, sj, uj in zip(grad_l, s, u):
        assert abs(gj - sj - beta * uj) < 1e-8 * sj


def test_penalty_gradient_by_finite_differences() -> None:
    rng = random.Random(1)
    edges = [(j, k, rng.uniform(0.5, 2.0)) for j, k, _ in grid_edges(3)]
    x = [rng.uniform(0.0, 3.0) for _ in range(9)]
    g = penalty_grad(x, edges)
    h = 1e-6
    for j in range(9):
        xp, xm = list(x), list(x)
        xp[j] += h
        xm[j] -= h
        assert abs((penalty(xp, edges) - penalty(xm, edges)) / (2 * h) - g[j]) < 1e-6


def test_projector_adjoint() -> None:
    rng = random.Random(2)
    rows, _ = _random_problem(rng, 3)
    x = [rng.gauss(0.0, 1.0) for _ in range(9)]
    v = [rng.gauss(0.0, 1.0) for _ in range(len(rows))]
    ax, atv = forward(rows, x), back(rows, v, 9)
    gap = abs(sum(p * q for p, q in zip(ax, v)) - sum(p * q for p, q in zip(x, atv)))
    assert gap <= 1e-10 * math.sqrt(sum(p * p for p in ax) * sum(q * q for q in v))

History

Green published the one-step-late algorithm in 1990 in IEEE Transactions on Medical Imaging, for Bayesian reconstruction of emission tomography with a Gibbs prior. He noted that the exact M-step of EM with a penalty has no closed form, and he evaluated the derivative of the penalty at the current image to get one. In the same year, Lange showed that the plain method can fail and gave a convergent form with a line search. De Pierro (1995) later found a separable surrogate for the penalty, which gave monotone methods. The separable paraboloidal surrogates of Erdogan and Fessler (1999) built on that idea.

References

  1. P. J. Green, Bayesian reconstructions from emission tomography data using a modified EM algorithm, IEEE Transactions on Medical Imaging 9(1), 1990, pp. 84 to 93 (the one-step-late update for a Gibbs prior)
  2. K. Lange, Convergence of EM image reconstruction algorithms with Gibbs smoothing, IEEE Transactions on Medical Imaging 9(4), 1990, pp. 439 to 446 (a modified one-step-late algorithm with a line search, and its convergence)
  3. L. A. Shepp and Y. Vardi, Maximum likelihood reconstruction for emission tomography, IEEE Transactions on Medical Imaging 1(2), 1982, pp. 113 to 122 (the MLEM update that OSL modifies)

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