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
- Model
- Real RAM
- Properties
- deterministicnot in placeiterativenot monotone objectiveiterative
- Evidence
- Proof sketchCode in 1 languages
- 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 . It maximizes , where is the Poisson log-likelihood, is a smooth penalty such as a sum of squared differences of neighbor pixels, and 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, . This is cheap and easy to add to an MLEM code. Its fixed points are the maximizers of . But the method is not a monotone method, and for a large 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 , a matrix with and column sums , a background , a weight and a differentiable penalty , maximize
over . With a prior density proportional to , 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
with the edges between neighbor pixels and . Then is concave, and a positive point is a maximizer if and only if 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
OSL(A, y, b, β, R, x0, K) ▷ x0 > 0; β ≥ 0; R is differentiable- 1
s_j ← Σ_i a_ij for each pixel j - 2
x ← x0 - 3
for k ← 1 to K do - 4
ȳ ← A x + b ▷ the forward projection - 5
r_i ← y_i / ȳ_i for each bin i ▷ r_i ← 0 if y_i = 0 - 6
g ← A^T r ▷ the back projection of the ratios - 7
u ← ∇R(x) ▷ the penalty gradient at the old image - 8
d_j ← s_j + β u_j; fail if some d_j ≤ 0 - 9
x_j ← x_j g_j / d_j for each pixel j - 10
return 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 . 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 to a small positive number instead; that hides the failure but does not fix it. With , OSL is MLEM.
Example
Take two pixels, each seen by one bin: , , counts , and one edge between the pixels with . Then and line L9 reads and . The start is the flat image . There the penalty gradient is 0, so the first iterate is the MLEM image for every .
| iteration | |||
|---|---|---|---|
| 1 | |||
| 2 | : fails | ||
| 3 | |||
| 4 | |||
| 5 | : fails | ||
| maximizer of |
For the iterates converge to the maximizer, and rises at each step in this run: , , , For the late correction overshoots: the bright pixel becomes the dark one and back, with a growing amplitude. falls from to in the second step, and the fifth step has a negative denominator. For , the second step would give . For the denominator is exactly 0. In all three cases the maximizer is a positive point; only the iteration fails.
Correctness
A positive with positive denominators is a fixed point of line L9 if and only if for every , that is . Since 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 . Exact EM with a penalty leads to the coupled equations , and OSL replaces with . So the monotone argument of MLEM does not apply. The example above proves that can decrease and that a denominator can become 0 or negative. A sufficient condition for a positive denominator at a nonnegative image is , but it depends on the current image. Lange (1990) added a line search along the OSL step and proved that this modified method increases 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. is an matrix with and column sums , , , , and
with and weights on the edges . Write and . One iteration (lines L4 to L9) maps to
and it is defined only if every denominator is positive. We work in exact arithmetic.
Where the update comes from. For a fixed admissible , the MLEM proof gives the surrogate . Maximizing this surrogate minus would need the solution of the coupled equations
which couple the pixels through . Green's idea is to evaluate one step late, at the old image . Then each equation has one unknown and the solution is (1). So (1) is not the maximizer of a surrogate of , and the monotone argument of MLEM does not apply.
Theorem 1 (fixed points). Let with wherever , and for all . Then is a fixed point of (1) if and only if .
Proof. . Since and , (1) gives if and only if , that is .
is concave, because is concave and is a convex quadratic. So a positive fixed point is a maximizer of over . If is strictly concave (for example if has full column rank on the rows with ), it is the unique maximizer.
Theorem 2 (a sufficient condition for a positive denominator). If and , then .
Proof. , because . So .
The condition depends on the current image, so it cannot be checked once in advance. For a fixed image it holds for small enough, and it can fail for a large , as the next theorem shows.
Theorem 3 (failure for a large beta). There are data and a for which the second iterate has a nonpositive denominator, and data and a for which decreases from one iterate to the next.
Proof. Take two pixels, , , , one edge with , and the start . Then , so and (1) reads and . At the penalty gradient is 0, so for every . At , , which is 0 for and for . For the formula (1) would give .
For , and , so . Then
so .
In the same example with the iterates oscillate with a growing amplitude: , , and . The maximizer of for is about , 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 at each step and converges under conditions on the penalty. For a small the plain update usually converges in practice; this is an observation, as in the example of the page.
Complexity
In the real-RAM model, with angles of bins and an image, one iteration costs one forward and one back projection, , plus for the gradient of a neighbor penalty. So it costs time and extra space, and iterations cost . 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. 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 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 to the OSL image for a point that raises . 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 for 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 , 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 , for example to reduce the noise without changing the code much. Check the denominators at each iteration. Use SPS or another monotone method when 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 . The denominator can become 0 or negative. The failure can come after a few good steps, as in the example.
- Clipping the denominator. Replacing a negative with a small positive number avoids the crash, but the iteration then has no relation to , and its limit is not the maximizer.
- Assuming a monotone objective. Do not test for a monotone increase, and do not use its increase as a stopping rule.
- A non-convex penalty. With a non-convex penalty, has many stationary points, and a fixed point need not be a maximizer.
- The scale of . multiplies a penalty whose size depends on the units of 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 , , and , the limit and the penalized KKT equations, the decrease of and the failure for , the case against MLEM, a fixed point on a random 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.
# 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
- 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)
- 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)
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag J6NCZD Edit this page History Report an error Markdown