Algorithm Search⌘K

Algorithmadvanced

Bregman iteration

Also called Osher-Burger Bregman iteration, iterative regularization by Bregman distances, add-back-the-residual iteration.

Repeat a variational reconstruction while adding the residual back to the data, which reduces the contrast loss of total variation regularization.

Time
O(K (s + m)) worst
Space
O(m) extra
Where
K = the number of outer iterations; m = the number of data values; s = the cost of one inner variational solve
Properties
deterministicnot exactiterativemonotone residualneeds stopping rule with noise
Origin
Stanley Osher, Martin Burger, Donald Goldfarb, Jinjun Xu, Wotao Yin, 2005

Bregman iteration improves a variational reconstruction by solving it several times. Each time it adds the part of the data that the last reconstruction did not explain back to the data, and solves again. For a regularizer RR and data y=Ax+ey = Ax + e, step kk solves min⁡x12∥Ax−yk∥2+λR(x)\min_x \tfrac12\|Ax - y^k\|^2 + \lambda R(x) and then sets yk+1=yk+(y−Axk+1)y^{k+1} = y^k + (y - Ax^{k+1}). This is the same as replacing λR(x)\lambda R(x) by its Bregman divergence from the last iterate, which is where the name comes from. For total variation the first step loses contrast, because shrinking a jump lowers the total variation, and the later steps give the contrast back. The residual ∥Axk−y∥\|Ax^k - y\| never increases and tends to 0, so with noisy data the iteration must be stopped, for example by the discrepancy principle. With exact data and ℓ1\ell_1 it ends at a basis pursuit solution.

In plain words

A cleaning filter for images removes noise but also makes bright objects a little darker and dark objects a little brighter. The method fixes this with a simple loop. Clean the image. Look at what the cleaning removed. Most of that is noise, but some of it is real detail and real contrast. Add the removed part back to the measured image, and clean again. The real detail is now stronger and survives the cleaning, so the new result is closer to the truth. Each round explains more of the measurement. But the noise is also part of the measurement, so if the loop runs too long the noise comes back. The loop must stop when the result explains the measurement about as well as the noise level allows, and not better.

The problem

The input is a linear forward operator AA (given as a routine), data y∈Rmy \in \mathbb{R}^m, a convex regularizer R≥0R \ge 0 with R(0)=0R(0) = 0, a weight λ>0\lambda > 0 and a routine that solves the inner variational problem

solve⁡(d)=argmin⁡x12∥Ax−d∥2+λR(x)\operatorname{solve}(d) = \operatorname*{argmin}_x \tfrac12\|Ax - d\|^2 + \lambda R(x)

for any data vector dd. With noisy data yδy^\delta and a known noise level ∥yδ−Ax†∥≤δ\|y^\delta - Ax^\dagger\| \le \delta, the input also has δ\delta and a factor τ≥1\tau \ge 1. The output is an approximation of the solution x†x^\dagger that has small RR among the solutions of Ax=yAx = y. The weight λ\lambda here is a design choice that sets the speed of the iteration rather than the final smoothing; the stop index plays the role of the regularization parameter.

The algorithm

  1. BregmanIteration(solve, A, y, K, δ, τ)
  2. 1y⁰ ← y
  3. 2for k = 0 to K - 1
  4. 3x ← solve(yᵏ) ▷ argmin ½‖Ax - yᵏ‖² + λR(x)
  5. 4r ← y - A x ▷ what x does not explain
  6. 5if ‖r‖ ≤ τ δ then return x ▷ discrepancy stop
  7. 6yᵏ⁺¹ ← yᵏ + r ▷ add the residual back
  8. 7return x

The optimality condition of line L3 at step k+1k+1 is A⊤(yk−Axk+1)∈λ ∂R(xk+1)A^\top(y^k - Ax^{k+1}) \in \lambda\,\partial R(x^{k+1}). Line L6 turns this into pk+1=A⊤(yk+1−y)/λ∈∂R(xk+1)p^{k+1} = A^\top(y^{k+1} - y)/\lambda \in \partial R(x^{k+1}), a subgradient of RR at the new iterate. With it, line L3 at the next step is the same problem as

xk+1=argmin⁡x12∥Ax−y∥2+λDpk(x,xk),Dp(x,z)=R(x)−R(z)−⟨p,x−z⟩,x^{k+1} = \operatorname*{argmin}_x \tfrac12\|Ax - y\|^2 + \lambda D^{p^k}(x, x^k),\qquad D^{p}(x, z) = R(x) - R(z) - \langle p, x - z\rangle,

because 12∥Ax−yk∥2=12∥Ax−y∥2−λ⟨pk,x⟩\tfrac12\|Ax - y^k\|^2 = \tfrac12\|Ax - y\|^2 - \lambda\langle p^k, x\rangle plus a constant. So each step regularizes by the distance to the last iterate in the geometry of RR, not by RR itself. With exact data, line L6 is also the multiplier update of the augmented Lagrangian method for min⁡R(x)\min R(x) subject to Ax=yAx = y, with multiplier yk−yy^k - y.

Example

Take A=IA = I, total variation on a signal, λ=1\lambda = 1 and the clean step y=(0,0,0,0,2,2,2,2)y = (0, 0, 0, 0, 2, 2, 2, 2).

Step 1 is total variation denoising of yy. Each half moves toward the other by λ\lambda divided by its length 4, so x1=(0.25,0.25,0.25,0.25,1.75,1.75,1.75,1.75)x^1 = (0.25, 0.25, 0.25, 0.25, 1.75, 1.75, 1.75, 1.75). The jump fell from 2 to 1.5: this is the contrast loss. The residual is y−x1=(−0.25,…,0.25,… )y - x^1 = (-0.25, \dots, 0.25, \dots), and line L6 gives y1=(−0.25,−0.25,−0.25,−0.25,2.25,2.25,2.25,2.25)y^1 = (-0.25, -0.25, -0.25, -0.25, 2.25, 2.25, 2.25, 2.25), a step with the larger jump 2.5.

Step 2 denoises y1y^1. Again each half moves by 0.250.25, so x2=(0,0,0,0,2,2,2,2)=yx^2 = (0, 0, 0, 0, 2, 2, 2, 2) = y. The contrast is fully restored after one extra step, and the residual is 0.

With ℓ1\ell_1 in place of total variation and A=IA = I, line L3 is soft thresholding at λ=1\lambda = 1. For y=(3,0.5,−2)y = (3, 0.5, -2):

kk yky^k xk+1x^{k+1} ∥xk+1−y∥\|x^{k+1} - y\|
0 (3,0.5,−2)(3, 0.5, -2) (2,0,−1)(2, 0, -1) 1.5
1 (4,1,−3)(4, 1, -3) (3,0,−2)(3, 0, -2) 0.5
2 (4,1.5,−3)(4, 1.5, -3) (3,0.5,−2)(3, 0.5, -2) 0

The two large entries are exact after step 2. The small entry 0.50.5 is below the threshold, but its residual accumulates in yky^k and it enters at step 3. If 0.50.5 is noise, step 3 lets the noise in, and a discrepancy stop with δ=0.5\delta = 0.5 ends the loop after step 2.

Correctness

The full proofs are in proofs/correctness.md. The theorems, for exact inner solves:

  • The residual does not increase: ∥Axk+1−y∥≤∥Axk−y∥\|Ax^{k+1} - y\| \le \|Ax^k - y\| for k≥1k \ge 1, because xkx^k is a candidate in the Bregman form of step k+1k+1 with distance 0.
  • Three-point identity: for every x~\tilde x, D(x~,xk)−D(x~,xk−1)+D(xk,xk−1)=⟨pk−pk−1,xk−x~⟩=⟨y−Axk,Axk−Ax~⟩/λD(\tilde x, x^k) - D(\tilde x, x^{k-1}) + D(x^k, x^{k-1}) = \langle p^k - p^{k-1}, x^k - \tilde x\rangle = \langle y - Ax^k, Ax^k - A\tilde x\rangle/\lambda. With 2⟨a,b⟩≤∥a∥2+∥b∥22\langle a, b\rangle \le \|a\|^2 + \|b\|^2 this gives λ(D(x~,xk)−D(x~,xk−1))≤12∥Ax~−y∥2−12∥Axk−y∥2\lambda\big(D(\tilde x, x^k) - D(\tilde x, x^{k-1})\big) \le \tfrac12\|A\tilde x - y\|^2 - \tfrac12\|Ax^k - y\|^2.
  • Rate: summing over kk gives 12∥AxK−y∥2≤12∥Ax~−y∥2+λR(x~)/K\tfrac12\|Ax^K - y\|^2 \le \tfrac12\|A\tilde x - y\|^2 + \lambda R(\tilde x)/K for every x~\tilde x. With exact data and x~=x†\tilde x = x^\dagger, the squared residual is O(1/K)O(1/K).
  • Noise: with ∥Ax†−yδ∥≤δ\|Ax^\dagger - y^\delta\| \le \delta and x~=x†\tilde x = x^\dagger, the distance D(x†,xk)D(x^\dagger, x^k) strictly decreases as long as ∥Axk−yδ∥>δ\|Ax^k - y^\delta\| > \delta. So the iterates approach the true solution in the Bregman sense until the discrepancy reaches the noise level, which justifies the stop in line L5.
  • Exact fit: if Axk=yAx^k = y then xkx^k minimizes RR over {x:Ax=y}\{x : Ax = y\}, because pk=A⊤wp^k = A^\top w with w=(yk−y)/λw = (y^k - y)/\lambda is a subgradient. For R=∥⋅∥1R = \|\cdot\|_1 this is basis pursuit, and Yin, Osher, Goldfarb and Darbon (2008) show the exact fit is reached after finitely many steps.
Proof: Bregman iteration has a nonincreasing residual, an O(1/K) bound on the squared residual, a decreasing Bregman distance before the discrepancy stop, and an exact fit that minimizes Rfull

Setting. A:Rn→RmA : \mathbb{R}^n \to \mathbb{R}^m is linear, y∈Rmy \in \mathbb{R}^m is the data (exact or noisy), λ>0\lambda > 0, and R:Rn→[0,∞]R : \mathbb{R}^n \to [0, \infty] is convex with R(0)=0R(0) = 0. We assume each inner problem min⁡x12∥Ax−d∥2+λR(x)\min_x \tfrac12\|Ax - d\|^2 + \lambda R(x) has a minimizer and the subdifferential sum rule holds for it (true for example when RR is finite everywhere). The iteration is y0=yy^0 = y and, for k≥0k \ge 0,

xk+1∈argmin⁡x12∥Ax−yk∥2+λR(x),yk+1=yk+(y−Axk+1).x^{k+1} \in \operatorname*{argmin}_x \tfrac12\|Ax - y^k\|^2 + \lambda R(x),\qquad y^{k+1} = y^k + (y - Ax^{k+1}).

Put x0=0x^0 = 0 and pk=A⊤(yk−y)/λp^k = A^\top(y^k - y)/\lambda for k≥0k \ge 0, so p0=0p^0 = 0. For p∈∂R(z)p \in \partial R(z) the Bregman distance is Dp(x,z)=R(x)−R(z)−⟨p,x−z⟩≥0D^p(x, z) = R(x) - R(z) - \langle p, x - z\rangle \ge 0. Write Dk(x)=Dpk(x,xk)D_k(x) = D^{p^k}(x, x^k).

Lemma 1 (subgradients). pk∈∂R(xk)p^k \in \partial R(x^k) for all k≥0k \ge 0.

Proof. For k=0k = 0: p0=0p^0 = 0 and R(x)≥0=R(0)R(x) \ge 0 = R(0), so 0∈∂R(0)0 \in \partial R(0). For k≥0k \ge 0 the optimality condition of the inner problem is 0∈A⊤(Axk+1−yk)+λ∂R(xk+1)0 \in A^\top(Ax^{k+1} - y^k) + \lambda\partial R(x^{k+1}), so A⊤(yk−Axk+1)/λ∈∂R(xk+1)A^\top(y^k - Ax^{k+1})/\lambda \in \partial R(x^{k+1}). By the update, yk−Axk+1=yk+1−yy^k - Ax^{k+1} = y^{k+1} - y, so this vector is pk+1p^{k+1}. □\square

Lemma 2 (Bregman form). For k≥0k \ge 0, xk+1x^{k+1} minimizes Φk(x)=12∥Ax−y∥2+λDk(x)\Phi_k(x) = \tfrac12\|Ax - y\|^2 + \lambda D_k(x).

Proof. 12∥Ax−yk∥2=12∥Ax−y∥2−⟨Ax,yk−y⟩+c1=12∥Ax−y∥2−λ⟨pk,x⟩+c1\tfrac12\|Ax - y^k\|^2 = \tfrac12\|Ax - y\|^2 - \langle Ax, y^k - y\rangle + c_1 = \tfrac12\|Ax - y\|^2 - \lambda\langle p^k, x\rangle + c_1, and λDk(x)=λR(x)−λ⟨pk,x⟩+c2\lambda D_k(x) = \lambda R(x) - \lambda\langle p^k, x\rangle + c_2, with c1,c2c_1, c_2 independent of xx. So the two objectives differ by a constant. □\square

Theorem 1 (monotone residual). 12∥Axk+1−y∥2+λDk(xk+1)≤12∥Axk−y∥2\tfrac12\|Ax^{k+1} - y\|^2 + \lambda D_k(x^{k+1}) \le \tfrac12\|Ax^k - y\|^2 for k≥0k \ge 0. In particular ∥Axk+1−y∥≤∥Axk−y∥\|Ax^{k+1} - y\| \le \|Ax^k - y\|.

Proof. Φk(xk+1)≤Φk(xk)\Phi_k(x^{k+1}) \le \Phi_k(x^k) by Lemma 2, and Dk(xk)=0D_k(x^k) = 0. □\square

Lemma 3 (three-point identity). For every x~\tilde x and k≥1k \ge 1,

Dk(x~)−Dk−1(x~)+Dk−1(xk)=⟨pk−pk−1,xk−x~⟩=1λ⟨y−Axk,Axk−Ax~⟩.D_k(\tilde x) - D_{k-1}(\tilde x) + D_{k-1}(x^k) = \langle p^k - p^{k-1}, x^k - \tilde x\rangle = \tfrac1\lambda\langle y - Ax^k, Ax^k - A\tilde x\rangle.

Proof. Expand the three distances. The values R(x~)R(\tilde x), R(xk)R(x^k) and R(xk−1)R(x^{k-1}) cancel, and what is left is −⟨pk,x~−xk⟩+⟨pk−1,x~−xk−1⟩−⟨pk−1,xk−xk−1⟩=⟨pk−pk−1,xk−x~⟩-\langle p^k, \tilde x - x^k\rangle + \langle p^{k-1}, \tilde x - x^{k-1}\rangle - \langle p^{k-1}, x^k - x^{k-1}\rangle = \langle p^k - p^{k-1}, x^k - \tilde x\rangle. Finally pk−pk−1=A⊤(yk−yk−1)/λ=A⊤(y−Axk)/λp^k - p^{k-1} = A^\top(y^k - y^{k-1})/\lambda = A^\top(y - Ax^k)/\lambda. □\square

Lemma 4 (one step against any point). For every x~\tilde x and k≥1k \ge 1,

λ(Dk(x~)−Dk−1(x~))+λDk−1(xk)≤12∥Ax~−y∥2−12∥Axk−y∥2.\lambda\big(D_k(\tilde x) - D_{k-1}(\tilde x)\big) + \lambda D_{k-1}(x^k) \le \tfrac12\|A\tilde x - y\|^2 - \tfrac12\|Ax^k - y\|^2.

Proof. Let r=y−Axkr = y - Ax^k and s=y−Ax~s = y - A\tilde x. Then Axk−Ax~=s−rAx^k - A\tilde x = s - r, and ⟨r,s−r⟩=⟨r,s⟩−∥r∥2≤12∥s∥2+12∥r∥2−∥r∥2\langle r, s - r\rangle = \langle r, s\rangle - \|r\|^2 \le \tfrac12\|s\|^2 + \tfrac12\|r\|^2 - \|r\|^2. Multiply Lemma 3 by λ\lambda. □\square

Theorem 2 (rate). For every x~\tilde x with R(x~)<∞R(\tilde x) < \infty and every K≥1K \ge 1,

12∥AxK−y∥2≤12∥Ax~−y∥2+λR(x~)K.\tfrac12\|Ax^K - y\|^2 \le \tfrac12\|A\tilde x - y\|^2 + \frac{\lambda R(\tilde x)}{K}.

Proof. Sum Lemma 4 over k=1,…,Kk = 1, \dots, K and drop λDk−1(xk)≥0\lambda D_{k-1}(x^k) \ge 0 and λDK(x~)≥0\lambda D_K(\tilde x) \ge 0: ∑k=1K12∥Axk−y∥2≤K⋅12∥Ax~−y∥2+λD0(x~)\sum_{k=1}^K \tfrac12\|Ax^k - y\|^2 \le K\cdot\tfrac12\|A\tilde x - y\|^2 + \lambda D_0(\tilde x). Here D0(x~)=R(x~)−R(0)−0=R(x~)D_0(\tilde x) = R(\tilde x) - R(0) - 0 = R(\tilde x). By Theorem 1 each term of the sum is at least 12∥AxK−y∥2\tfrac12\|Ax^K - y\|^2. Divide by KK. □\square

With exact data y=Ax†y = Ax^\dagger and x~=x†\tilde x = x^\dagger this gives ∥AxK−y∥2≤2λR(x†)/K\|Ax^K - y\|^2 \le 2\lambda R(x^\dagger)/K.

Theorem 3 (noisy data). Let ∥Ax†−y∥≤δ\|Ax^\dagger - y\| \le \delta and R(x†)<∞R(x^\dagger) < \infty. If ∥Axk−y∥>δ\|Ax^k - y\| > \delta for some k≥1k \ge 1, then Dk(x†)<Dk−1(x†)D_k(x^\dagger) < D_{k-1}(x^\dagger). So the Bregman distance to x†x^\dagger strictly decreases at every step before the first kk with ∥Axk−y∥≤δ\|Ax^k - y\| \le \delta, and for τ≥1\tau \ge 1 the stop rule "first kk with ∥Axk−y∥≤τδ\|Ax^k - y\| \le \tau\delta" is reached at an index k∗k_* with Dk(x†)D_k(x^\dagger) strictly decreasing for k<k∗k < k_*.

Proof. Lemma 4 with x~=x†\tilde x = x^\dagger gives λ(Dk(x†)−Dk−1(x†))≤12δ2−12∥Axk−y∥2<0\lambda(D_k(x^\dagger) - D_{k-1}(x^\dagger)) \le \tfrac12\delta^2 - \tfrac12\|Ax^k - y\|^2 < 0. For the second claim: before the stop, ∥Axk−y∥>τδ≥δ\|Ax^k - y\| > \tau\delta \ge \delta. □\square

Theorem 4 (termination of the stop rule). If τ>1\tau > 1 and ∥Ax†−y∥≤δ\|Ax^\dagger - y\| \le \delta with δ>0\delta > 0, the stop rule is reached after at most K=⌈2λR(x†)/((τ2−1)δ2)⌉+1K = \lceil 2\lambda R(x^\dagger)/((\tau^2 - 1)\delta^2)\rceil + 1 steps.

Proof. By Theorem 2 with x~=x†\tilde x = x^\dagger, ∥AxK−y∥2≤δ2+2λR(x†)/K\|Ax^K - y\|^2 \le \delta^2 + 2\lambda R(x^\dagger)/K, and this is at most τ2δ2\tau^2\delta^2 once K≥2λR(x†)/((τ2−1)δ2)K \ge 2\lambda R(x^\dagger)/((\tau^2 - 1)\delta^2). □\square

Theorem 5 (exact fit). If Axk=yAx^k = y for some k≥1k \ge 1, then xkx^k minimizes RR over {x:Ax=y}\{x : Ax = y\}.

Proof. By Lemma 1, pk=A⊤w∈∂R(xk)p^k = A^\top w \in \partial R(x^k) with w=(yk−y)/λw = (y^k - y)/\lambda. For any xx with Ax=yAx = y: R(x)≥R(xk)+⟨A⊤w,x−xk⟩=R(xk)+⟨w,Ax−Axk⟩=R(xk)R(x) \ge R(x^k) + \langle A^\top w, x - x^k\rangle = R(x^k) + \langle w, Ax - Ax^k\rangle = R(x^k). □\square

Remark (augmented Lagrangian). With μk=yk−y\mu^k = y^k - y, the inner problem is min⁡xλR(x)+⟨μk,y−Ax⟩+12∥Ax−y∥2\min_x \lambda R(x) + \langle \mu^k, y - Ax\rangle + \tfrac12\|Ax - y\|^2 up to a constant, and the update is μk+1=μk+(y−Axk+1)\mu^{k+1} = \mu^k + (y - Ax^{k+1}). This is the method of multipliers with penalty 1 for min⁡λR(x)\min \lambda R(x) subject to Ax=yAx = y. The finite termination for R=∥⋅∥1R = \|\cdot\|_1 (Yin, Osher, Goldfarb and Darbon 2008) is not proved here.

Complexity

Each outer step costs one inner solve and one product with AA, plus O(m)O(m) for the update, so KK steps cost O(K(s+m))O(K(s + m)) time and O(m)O(m) extra memory for yky^k. The inner solve dominates: for total variation it is itself an iterative method, such as Chambolle's projection algorithm or the Chambolle-Pock algorithm. The squared residual is O(1/K)O(1/K) by the rate above. With noise and a discrepancy stop, the number of outer steps depends on λ\lambda: a large λ\lambda gives many small steps and a fine control of the stop, a small λ\lambda gives few large steps.

Properties

  • The residual is monotone, and the Bregman distance to the true solution decreases until the noise level is reached. This is the same semi-convergence behavior as Landweber iteration: the error first falls and then grows as noise is fitted.
  • The method is an iterative regularization: the stop index, not λ\lambda, is the regularization parameter.
  • For R(x)=12∥x∥2R(x) = \tfrac12\|x\|^2 the Bregman distance is 12∥x−xk∥2\tfrac12\|x - x^k\|^2, and the method is iterated Tikhonov regularization.
  • For exact data it is the augmented Lagrangian method (method of multipliers) for min⁡R\min R subject to Ax=yAx = y.
  • The scale of features enters in order of size: large, high contrast features are recovered in the first steps, small and low contrast ones later. Noise is small scale, so it enters last.
  • The iterates are not monotone in RR or in the error norm; only the residual and, before the stop, the Bregman distance are.

Variants and improvements

  • Split Bregman applies the same add-back step to the constraint d=Φxd = \Phi x of a split problem, which gives a fast method for ℓ1\ell_1 and total variation problems. For linear constraints it is ADMM.
  • Linearized Bregman: Yin, Osher, Goldfarb and Darbon (2008) replace the inner solve by one gradient step and a shrinkage, which gives a cheap method for basis pursuit. Cai, Osher and Shen (2009) showed that its limit solves min⁡∥x∥1+12μ∥x∥2\min \|x\|_1 + \tfrac1{2\mu}\|x\|^2 subject to Ax=yAx = y, where μ\mu is the parameter of the method.
  • Inverse scale space: letting λ→∞\lambda \to \infty with a time scaling gives a continuous flow ∂tp=A⊤(y−Ax)\partial_t p = A^\top(y - Ax), p∈∂R(x)p \in \partial R(x), studied by Burger, Gilboa, Osher and Xu (2006).
  • Inexact inner solves: in practice the inner problem is solved only approximately, often with one sweep, which leads to split Bregman and ADMM.
  • Other data terms: the Bregman form with DpkD^{p^k} works for any convex data term, for example the Kullback-Leibler divergence for Poisson data, but then the subgradient no longer has the simple form A⊤(yk−y)/λA^\top(y^k - y)/\lambda and line L6 must be replaced by an explicit update of pkp^k.

When to use it

Use it when a convex regularizer such as total variation or ℓ1\ell_1 gives the right structure but loses contrast or shrinks large coefficients, and you can solve the variational problem as a black box. It is also a simple way to get the minimal RR solution of Ax=yAx = y from a solver for the penalized problem. If you only need the penalized solution for one fixed λ\lambda, do not use it; use the inner solver once. With noisy data you need an estimate of the noise level or another stop rule.

Pitfalls

  • Without a stop rule the iteration fits the noise: the residual goes to 0 and the noise enters the reconstruction. With a noise level, stop at the first kk with ∥Axk−yδ∥≤τδ\|Ax^k - y^\delta\| \le \tau\delta.
  • The add-back must use the original data yy, not the current yky^k: line L4 is y−Axy - Ax. Using yk−Axy^k - Ax gives a different and divergent method.
  • The rate and monotonicity need accurate inner solves. A very rough inner solve breaks the monotone residual, though the loop often still works in practice.
  • The weight λ\lambda changes meaning: here it sets the step size of the iteration. A small λ\lambda makes each step fit the data almost fully, so the residual can already fall far below the noise level in the first step, and the stop rule then has nothing to choose.
  • The subgradient pkp^k is implicit in yky^k. If the inner solver works with a different scaling of the data term, for example μ2∥Ax−d∥2+R(x)\tfrac\mu2\|Ax - d\|^2 + R(x), the update must use the same scaling.

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.

bregman_iteration.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bregman-iteration/. The authors are listed in prov/3BKXGP.jsonl.
"""Bregman iteration of Osher, Burger, Goldfarb, Xu and Yin (2005).

Each outer step solves the variational problem
    x^{k+1} = argmin_x (1/2)||A x - y^k||^2 + lam R(x)
and then adds the residual back to the data: y^{k+1} = y^k + (y - A x^{k+1}).
The caller gives the inner solver. Three inner solvers are included:
soft thresholding (A = I, R = ||.||_1, exact), 1D total variation denoising
(A = I, R = TV, by an accelerated dual projected gradient) and the LASSO
(R = ||.||_1, general A, by FISTA).
"""

import math
from typing import Callable

Vec = list[float]


def norm(v: Vec) -> float:
    return math.sqrt(sum(a * a for a in v))


def bregman_iteration(solve: Callable[[Vec], Vec], A: Callable[[Vec], Vec], y: Vec, iters: int,
                      delta: float | None = None, tau: float = 1.0) -> tuple[Vec, list[Vec], list[Vec]]:
    """Return (x, xs, ys): the final iterate, all iterates x^1.. and all data y^0...

    solve(d) must return argmin_x (1/2)||A x - d||^2 + lam R(x) for a fixed lam.
    With delta set, stop at the first k with ||A x^k - y|| <= tau delta
    (the discrepancy principle; use tau >= 1). Precondition: R convex and
    the inner problem has a minimizer. Cost: iters inner solves plus
    iters products with A.
    """
    yk = y[:]  # @line L1
    xs: list[Vec] = []
    ys: list[Vec] = [yk[:]]
    x: Vec = []
    for _ in range(iters):  # @line L2
        x = solve(yk)  # @line L3
        xs.append(x)
        r = [a - b for a, b in zip(y, A(x))]  # @line L4
        if delta is not None and norm(r) <= tau * delta:  # @line L5
            break
        yk = [a + b for a, b in zip(yk, r)]  # @line L6
        ys.append(yk[:])
    return x, xs, ys  # @line L7


def soft_threshold(lam: float) -> Callable[[Vec], Vec]:
    """Exact inner solver for A = I, R = ||.||_1: argmin (1/2)||x - d||^2 + lam ||x||_1."""
    return lambda d: [math.copysign(max(abs(a) - lam, 0.0), a) for a in d]


def tv1d(lam: float, tol: float = 1e-13, max_iter: int = 200000) -> Callable[[Vec], Vec]:
    """Inner solver for A = I, R = sum |x_{i+1} - x_i| on a signal.

    It runs FISTA on the dual problem min_{|p_i| <= 1} (1/2)||d - lam D^T p||^2
    with the step 1/(4 lam^2) and stops when the duality gap is at most tol.
    Then ||x - x*||^2 <= 2 tol. Cost O(n) per step.
    """
    def solve(d: Vec) -> Vec:
        n = len(d)
        if n == 1:
            return d[:]

        def DT(p: Vec) -> Vec:  # D^T p, with (D x)_i = x_{i+1} - x_i
            out = [0.0] * n
            for i, v in enumerate(p):
                out[i] -= v
                out[i + 1] += v
            return out

        p = [0.0] * (n - 1)
        q = p[:]
        t = 1.0
        x = d[:]
        for it in range(max_iter):
            w = DT(q)
            x = [a - lam * b for a, b in zip(d, w)]
            g = [x[i + 1] - x[i] for i in range(n - 1)]  # minus the dual gradient / lam
            p_new = [min(1.0, max(-1.0, a + b / (4.0 * lam))) for a, b in zip(q, g)]
            t_new = (1.0 + math.sqrt(1.0 + 4.0 * t * t)) / 2.0
            q = [a + (t - 1.0) / t_new * (a - b) for a, b in zip(p_new, p)]
            p, t = p_new, t_new
            if it % 20 == 0:
                x = [a - lam * b for a, b in zip(d, DT(p))]
                primal = 0.5 * sum((a - b) ** 2 for a, b in zip(x, d)) + lam * sum(abs(x[i + 1] - x[i]) for i in range(n - 1))
                dual = 0.5 * sum(a * a for a in d) - 0.5 * sum(a * a for a in x)
                if primal - dual <= tol:
                    return x
        return [a - lam * b for a, b in zip(d, DT(p))]
    return solve


def lasso_fista(A: list[list[float]], lam: float, iters: int = 3000) -> Callable[[Vec], Vec]:
    """Inner solver for R = ||.||_1 and a matrix A: FISTA with step 1/||A||_F^2. Cost O(iters m n)."""
    m, n = len(A), len(A[0])
    L = sum(a * a for row in A for a in row)

    def solve(d: Vec) -> Vec:
        x = [0.0] * n
        z = x[:]
        t = 1.0
        for _ in range(iters):
            r = [sum(A[i][j] * z[j] for j in range(n)) - d[i] for i in range(m)]
            g = [sum(A[i][j] * r[i] for i in range(m)) for j in range(n)]
            v = [a - b / L for a, b in zip(z, g)]
            x_new = [math.copysign(max(abs(a) - lam / L, 0.0), a) for a in v]
            t_new = (1.0 + math.sqrt(1.0 + 4.0 * t * t)) / 2.0
            z = [a + (t - 1.0) / t_new * (a - b) for a, b in zip(x_new, x)]
            x, t = x_new, t_new
        return x
    return solve


def matvec(A: list[list[float]]) -> Callable[[Vec], Vec]:
    return lambda x: [sum(a * b for a, b in zip(row, x)) for row in A]
test_bregman_iteration.py 142 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bregman-iteration/. The authors are listed in prov/3BKXGP.jsonl.

import itertools
import math
import random

from bregman_iteration import bregman_iteration, lasso_fista, matvec, norm, soft_threshold, tv1d

IDENT = lambda x: x[:]


def tv(x):
    return sum(abs(x[i + 1] - x[i]) for i in range(len(x) - 1))


def rof_brute(f, lam):
    """Exact 1D TV denoising by trying every sign pattern of the differences."""
    n = len(f)
    best, best_val = None, math.inf
    for s in itertools.product((-1, 0, 1), repeat=n - 1):
        cuts = [0] + [b + 1 for b in range(n - 1) if s[b] != 0] + [n]
        u = []
        for a, b in zip(cuts, cuts[1:]):
            sl = s[a - 1] if a > 0 else 0
            sr = s[b - 1] if b < n else 0
            u.extend([sum(f[a:b]) / (b - a) - lam * (sl - sr) / (b - a)] * (b - a))
        val = 0.5 * sum((a - b) ** 2 for a, b in zip(u, f)) + lam * tv(u)
        if val < best_val:
            best, best_val = u, val
    return best


def solve_square(M, r):
    n = len(r)
    a = [row[:] + [r[i]] for i, row in enumerate(M)]
    for c in range(n):
        piv = max(range(c, n), key=lambda i: abs(a[i][c]))
        if abs(a[piv][c]) < 1e-10:
            return None
        a[c], a[piv] = a[piv], a[c]
        for i in range(c + 1, n):
            t = a[i][c] / a[c][c]
            for j in range(c, n + 1):
                a[i][j] -= t * a[c][j]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        x[i] = (a[i][n] - sum(a[i][j] * x[j] for j in range(i + 1, n))) / a[i][i]
    return x


def basis_pursuit_brute(A, y):
    """min ||x||_1 subject to A x = y, by trying every basic solution (an LP optimum is a vertex)."""
    m, n = len(A), len(A[0])
    best = math.inf
    for S in itertools.combinations(range(n), m):
        xs = solve_square([[A[i][j] for j in S] for i in range(m)], y)
        if xs is not None:
            best = min(best, sum(abs(v) for v in xs))
    return best


def test_l1_example() -> None:
    _, xs, ys = bregman_iteration(soft_threshold(1.0), IDENT, [3.0, 0.5, -2.0], 3)
    assert xs[0] == [2.0, 0.0, -1.0]
    assert ys[1] == [4.0, 1.0, -3.0]
    assert xs[1] == [3.0, 0.0, -2.0]
    assert xs[2] == [3.0, 0.5, -2.0]


def test_tv_inner_solver_brute_force() -> None:
    rng = random.Random(4)
    for _ in range(10):
        n = rng.randint(2, 7)
        f = [float(rng.randint(-3, 3)) for _ in range(n)]
        lam = rng.choice((0.4, 1.0, 2.5))
        x = tv1d(lam)(f)
        ref = rof_brute(f, lam)
        assert max(abs(a - b) for a, b in zip(x, ref)) < 1e-6


def test_tv_step_contrast_restored() -> None:
    f = [0.0] * 4 + [2.0] * 4
    _, xs, ys = bregman_iteration(tv1d(1.0), IDENT, f, 2)
    assert max(abs(a - b) for a, b in zip(xs[0], [0.25] * 4 + [1.75] * 4)) < 1e-6
    assert max(abs(a - b) for a, b in zip(ys[1], [-0.25] * 4 + [2.25] * 4)) < 1e-6
    assert max(abs(a - b) for a, b in zip(xs[1], f)) < 1e-6


def test_monotone_residual_and_rate() -> None:
    rng = random.Random(8)
    for _ in range(4):
        n = 7
        y = [rng.uniform(-2, 2) for _ in range(n)]
        lam = 1.5
        K = 8
        _, xs, _ = bregman_iteration(tv1d(lam), IDENT, y, K)
        res = [norm([a - b for a, b in zip(x, y)]) for x in xs]
        for a, b in zip(res, res[1:]):
            assert b <= a + 1e-6
        # 1/2 ||x^k - y||^2 <= 1/2 ||xt - y||^2 + lam TV(xt) / k for every xt.
        for _ in range(10):
            xt = [rng.uniform(-2, 2) for _ in range(n)]
            for k, r in enumerate(res, start=1):
                bound = 0.5 * sum((a - b) ** 2 for a, b in zip(xt, y)) + lam * tv(xt) / k
                assert 0.5 * r * r <= bound + 1e-6


def test_basis_pursuit_limit() -> None:
    rng = random.Random(21)
    for _ in range(3):
        m, n = 3, 5
        A = [[rng.gauss(0, 1) for _ in range(n)] for _ in range(m)]
        xs_true = [0.0] * n
        xs_true[rng.randrange(n)] = rng.choice((-2.0, 2.0))
        y = matvec(A)(xs_true)
        x, _, _ = bregman_iteration(lasso_fista(A, 0.5, iters=500), matvec(A), y, 4)
        assert norm([a - b for a, b in zip(matvec(A)(x), y)]) < 1e-4
        assert abs(sum(abs(v) for v in x) - basis_pursuit_brute(A, y)) < 1e-3


def test_discrepancy_stop_and_bregman_distance() -> None:
    rng = random.Random(13)
    lam = 1.0
    xd = [rng.choice((0.0, 0.0, 4.0, -3.0)) for _ in range(12)]
    e = [rng.gauss(0, 0.3) for _ in range(12)]
    yd = [a + b for a, b in zip(xd, e)]
    delta = norm(e)
    x, xs, ys = bregman_iteration(soft_threshold(lam), IDENT, yd, 100, delta=delta, tau=1.0)
    k = len(xs)
    assert norm([a - b for a, b in zip(x, yd)]) <= delta
    assert all(norm([a - b for a, b in zip(xi, yd)]) > delta for xi in xs[:-1])
    # p^k = (y^k - y) / lam lies in the subdifferential of ||.||_1 at x^k (A = I).
    dist = []
    for j in range(1, k + 1):
        p = [(a - b) / lam for a, b in zip(ys[j], yd)] if j < len(ys) else None
        if p is None:
            break
        assert all(abs(pi) <= 1 + 1e-12 for pi in p)
        dist.append(sum(abs(a) for a in xd) - sum(a * b for a, b in zip(p, xd)))
    for a, b in zip(dist, dist[1:]):
        assert b < a + 1e-12

History

Lev Bregman introduced his distance in 1967 together with a method for finding a point in the intersection of convex sets, and it became a standard tool of convex optimization. Osher, Burger, Goldfarb, Xu and Yin (2005) used it to build an iterative regularization method for total variation image restoration. They showed that adding back the residual cures the contrast loss of the Rudin-Osher-Fatemi model and proved the monotone residual and the decrease of the Bregman distance up to the noise level. Burger and Osher (2004) had already given convergence rates in Bregman distances for convex variational regularization. Yin, Osher, Goldfarb and Darbon (2008) applied the iteration to basis pursuit in compressed sensing and introduced linearized Bregman, and Goldstein and Osher (2009) combined it with a splitting to obtain the split Bregman method.

References

  1. Stanley Osher, Martin Burger, Donald Goldfarb, Jinjun Xu and Wotao Yin, An iterative regularization method for total variation-based image restoration, Multiscale Modeling and Simulation 4(2), 2005, pages 460 to 489
  2. L. M. Bregman, The relaxation method of finding the common point of convex sets and its application to the solution of problems in convex programming, USSR Computational Mathematics and Mathematical Physics 7(3), 1967, pages 200 to 217
  3. Wotao Yin, Stanley Osher, Donald Goldfarb and Jerome Darbon, Bregman iterative algorithms for l1-minimization with applications to compressed sensing, SIAM Journal on Imaging Sciences 1(1), 2008, pages 143 to 168
  4. Martin Burger and Stanley Osher, Convergence rates of convex variational regularization, Inverse Problems 20(5), 2004, pages 1411 to 1421
  5. Tom Goldstein and Stanley Osher, The split Bregman method for L1-regularized problems, SIAM Journal on Imaging Sciences 2(2), 2009, pages 323 to 343

Where this leads

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