Algorithm Search⌘K

Algorithmadvanced

Lepskii balancing principle

Also called Lepskii principle, balancing principle, Lepskii method.

Choose the largest parameter on a grid whose solution stays within a noise-driven bound of every solution with a smaller parameter.

Time
Θ(m n + N^2 n) worst · averageΘ(m n + N n) best
Space
Θ(N n) extra
Where
N = the number of grid points; m = the number of measurements; n = the number of unknowns (n <= m)
Properties
a posterioriadaptiveconvergent regularizationdeterministicneeds noise level
Origin
Oleg V. Lepskii, Peter Mathé, Sergei V. Pereverzev, 1990

The balancing principle chooses the regularization parameter by comparing regularized solutions with each other. On a grid α0<α1<⋯<αN−1\alpha_0 < \alpha_1 < \dots < \alpha_{N-1} the error of xαx_{\alpha} splits into an approximation part φ(α)\varphi(\alpha) that grows with α\alpha and a noise part bounded by a known ψ(α)\psi(\alpha) that falls with α\alpha. The best α\alpha balances the two, but φ\varphi depends on the unknown solution. The rule replaces it by a test that uses only computed solutions: take the largest αj\alpha_j with

∥xαj−xαi∥≤4κ ψ(αi)for all i<j,\lVert x_{\alpha_j} - x_{\alpha_i}\rVert \le 4\kappa\,\psi(\alpha_i) \quad\text{for all } i < j,

with a safety factor κ≥1\kappa \ge 1. For Tikhonov regularization with ∥e∥≤δ\lVert e\rVert \le \delta, the bound is ψ(α)=δ/(2α)\psi(\alpha) = \delta/(2\sqrt\alpha). The rule needs δ\delta but no knowledge of the smoothness of x†x^\dagger, and it is proved to reach the best balance up to a constant factor. As a consequence it is order optimal for every source condition the method can exploit, without the saturation at ν=1/2\nu = 1/2 of the discrepancy principle. Lepskii introduced the idea in 1990 for adaptive estimation in statistics, and Mathé and Pereverzev brought it to inverse problems.

In plain words

A smoothing method has a knob, and you know how big the noise is. Too little smoothing lets the noise through, and you can bound that damage exactly from the noise size. Too much smoothing blurs the answer, and you cannot measure that damage because it depends on the true answer. The trick is to compare answers with each other. Start with little smoothing and turn the knob up step by step. As long as each new answer is close to all the less smoothed ones, within what the noise alone could explain, the extra smoothing has not yet hurt. Stop at the last setting that passes this test. It is safe and adapts to the problem, but tends to smooth a bit too much.

The problem

The model is yδ=Ax†+ey^\delta = Ax^\dagger + e with an m×nm \times n matrix AA, ∥e∥≤δ\lVert e\rVert \le \delta and a known δ\delta. Here x†x^\dagger is the minimum norm solution of Ax=Ax†Ax = Ax^\dagger. The Tikhonov solution for α>0\alpha > 0 is xα=(ATA+αI)−1ATyδx_\alpha = (A^TA + \alpha I)^{-1}A^Ty^\delta. The page Tikhonov regularization writes λ\lambda for this α\alpha. With the thin SVD A=∑i≤rsiuiviTA = \sum_{i \le r} s_iu_iv_i^T and bi=⟨ui,yδ⟩b_i = \langle u_i, y^\delta\rangle, xα=∑isibi/(si2+α) vix_\alpha = \sum_i s_ib_i/(s_i^2 + \alpha)\,v_i.

Let xˉα\bar x_\alpha be the solution for exact data. Then ∥xα−x†∥≤φ(α)+ψ(α)\lVert x_\alpha - x^\dagger\rVert \le \varphi(\alpha) + \psi(\alpha) with

φ(α)=∥xˉα−x†∥,∥xα−xˉα∥≤ψ(α)=δ2α,\varphi(\alpha) = \lVert\bar x_\alpha - x^\dagger\rVert, \qquad \lVert x_\alpha - \bar x_\alpha\rVert \le \psi(\alpha) = \frac{\delta}{2\sqrt\alpha},

because s/(s2+α)≤1/(2α)s/(s^2 + \alpha) \le 1/(2\sqrt\alpha) for all s>0s > 0. The function φ\varphi is nondecreasing and unknown, ψ\psi is decreasing and known. Given a grid, the task is to find an αj\alpha_j whose error is within a constant factor of min⁡j(φ(αj)+ψ(αj))\min_j(\varphi(\alpha_j) + \psi(\alpha_j)).

The algorithm

  1. BALANCING(U, s, V, y, delta, alpha_0 < ... < alpha_{N-1}, kappa) ▷ thin SVD of A
  2. 1b_i ← <u_i, y> for i ≤ r
  3. 2c_j ← (s_i b_i / (s_i² + alpha_j))_i for every j ▷ x_{alpha_j} in the basis v_i
  4. 3psi_j ← delta / (2 sqrt(alpha_j)) for every j
  5. 4for j = N - 1 down to 0
  6. 5for i = 0, ..., j - 1
  7. 6if ‖c_j - c_i‖ > 4 kappa psi_i then j fails; go to the next j
  8. 7if no i made j fail
  9. 8return alpha_j, x = Σ_k c_{j,k} v_k, j

Line L1 projects the data on the left singular vectors. Line L2 stores each solution by its coefficients in the basis viv_i, where distances are plain Euclidean distances, and line L3 computes the noise bounds. Lines L4 to L8 scan from the largest parameter down and return the first index that passes the test against every smaller parameter. That is the largest admissible index. Index 00 is always admissible, because it has nothing to test against, so the scan always returns.

Example

Take the same problem as on the GCV page: A=diag(s1,…,s32)A = \mathrm{diag}(s_1, \dots, s_{32}) with si=1/i2s_i = 1/i^2, xi†=1/i2x^\dagger_i = 1/i^2, and ei=10−3gie_i = 10^{-3}g_i with gig_i from random.Random(0).gauss(0, 1). Then δ=∥e∥=0.006508\delta = \lVert e\rVert = 0.006508. The grid is αj=10−6⋅2j\alpha_j = 10^{-6}\cdot 2^j for j=0,…,20j = 0, \dots, 20, and κ=1\kappa = 1. The table shows ψ\psi, the unknown φ\varphi, the error, and the worst ratio max⁡i<j∥xαj−xαi∥/(4ψi)\max_{i < j}\lVert x_{\alpha_j} - x_{\alpha_i}\rVert/(4\psi_i), which must be at most 1 for jj to pass.

jj αj\alpha_j ψj\psi_j φj\varphi_j ∥xαj−x†∥\lVert x_{\alpha_j} - x^\dagger\rVert worst ratio
8 0.000256 0.20337 0.02350 0.09195 0.193
10 0.001024 0.10169 0.03975 0.05823 0.199
11 0.002048 0.07190 0.05161 0.06198 0.200
12 0.004096 0.05084 0.06698 0.07351 0.201
14 0.016384 0.02542 0.11273 0.11659 0.270
15 0.032768 0.01798 0.14628 0.14932 0.496
16 0.065536 0.01271 0.18931 0.19141 0.906
17 0.131072 0.00899 0.24411 0.24521 1.654
18 0.262144 0.00636 0.32012 0.32042 3.219
19 0.524288 0.00449 0.43288 0.43273 6.521
20 1.048576 0.00318 0.58065 0.58039 12.048

The scan of line L4 starts at j=20j = 20, which fails, as do 19, 18 and 17. Index 16 passes with a worst ratio of 0.9060.906, so the rule returns α=0.065536\alpha = 0.065536 with error 0.191410.19141. The best error on the grid is 0.058230.05823, at j=10j = 10.

The guarantee holds: the balancing index of the theory is j∗=11j^\ast = 11, the last jj with φj≤ψj\varphi_j \le \psi_j, and the proof gives the bound 6ψj∗=0.43146\psi_{j^\ast} = 0.4314 on the error, which 0.191410.19141 respects. But the rule over-smooths here by a factor of about 3 in the error, because ψ\psi is a worst-case bound: at α11\alpha_{11} the actual noise in the solution is 0.01910.0191, while ψ11=0.0719\psi_{11} = 0.0719. The same effect appears with the default grid of the implementation, from s322/100s_{32}^2/100 to s12s_1^2 with ratio 1.51.5, which returns α=0.0703\alpha = 0.0703 and error 0.19620.1962.

Correctness

The proof is in proofs/correctness.md. Lines L4 to L8 return the largest admissible index, and they always return, because index 00 is admissible. The main result is an oracle inequality. Assume φ(α0)≤ψ(α0)\varphi(\alpha_0) \le \psi(\alpha_0), which holds when the grid starts at a small enough α\alpha, and let j∗j^\ast be the largest jj with φj≤ψj\varphi_j \le \psi_j. For all i<j≤j∗i < j \le j^\ast,

∥xαj−xαi∥≤φj+ψj+φi+ψi≤2ψj+2ψi≤4ψi,\lVert x_{\alpha_j} - x_{\alpha_i}\rVert \le \varphi_j + \psi_j + \varphi_i + \psi_i \le 2\psi_j + 2\psi_i \le 4\psi_i,

so j∗j^\ast is admissible and the chosen index j^\hat j is at least j∗j^\ast. Then, by the test at i=j∗i = j^\ast,

∥xαj^−x†∥≤∥xαj^−xαj∗∥+∥xαj∗−x†∥≤4κψj∗+2ψj∗=(4κ+2)ψj∗.\lVert x_{\alpha_{\hat j}} - x^\dagger\rVert \le \lVert x_{\alpha_{\hat j}} - x_{\alpha_{j^\ast}}\rVert + \lVert x_{\alpha_{j^\ast}} - x^\dagger\rVert \le 4\kappa\psi_{j^\ast} + 2\psi_{j^\ast} = (4\kappa + 2)\psi_{j^\ast}.

If the grid is geometric with ratio ρ=αj+1/αj\rho = \alpha_{j+1}/\alpha_j, then ψj∗≤ρ min⁡j(φj+ψj)\psi_{j^\ast} \le \sqrt\rho\,\min_j(\varphi_j + \psi_j), and so the error is at most (4κ+2)ρ(4\kappa + 2)\sqrt\rho times the best balance on the grid. This is a theorem.

Under a source condition x†=(ATA)νwx^\dagger = (A^TA)^\nu w with 0<ν≤10 < \nu \le 1, the approximation error of Tikhonov satisfies φ(α)≤αν∥w∥\varphi(\alpha) \le \alpha^\nu\lVert w\rVert, and the best balance is of order δ2ν/(2ν+1)\delta^{2\nu/(2\nu + 1)}. The rule reaches this order for every ν\nu up to the qualification 11 of Tikhonov, without knowing ν\nu, provided the grid covers the balancing point. The discrepancy principle stops at ν=1/2\nu = 1/2. See Tikhonov convergence rates and qualification.

Proof: The scan returns the largest admissible index, and its error is within a constant factor of the best balance of approximation and noise errors on the gridfull

Setting. AA is a real m×nm \times n matrix with thin SVD A=∑i=1rsiuiviTA = \sum_{i=1}^r s_iu_iv_i^T, s1≥⋯≥sr>0s_1 \ge \dots \ge s_r > 0. The data are y=yˉ+ey = \bar y + e with yˉ=Ax†\bar y = Ax^\dagger, ∥e∥≤δ\lVert e\rVert \le \delta, and x†x^\dagger in the span of the viv_i (the minimum norm solution). For α>0\alpha > 0, xα=(ATA+αI)−1ATyx_\alpha = (A^TA + \alpha I)^{-1}A^Ty and xˉα\bar x_\alpha is the same for yˉ\bar y. The grid is α0<α1<⋯<αN−1\alpha_0 < \alpha_1 < \dots < \alpha_{N-1} and κ≥1\kappa \ge 1. Write xj=xαjx_j = x_{\alpha_j}, ψj=δ/(2αj)\psi_j = \delta/(2\sqrt{\alpha_j}) and φj=∥xˉαj−x†∥\varphi_j = \lVert\bar x_{\alpha_j} - x^\dagger\rVert. Call jj admissible if ∥xj−xi∥≤4κψi\lVert x_j - x_i\rVert \le 4\kappa\psi_i for all i<ji < j.

Claim 1 (what the scan returns). Lines L4 to L8 terminate and return the largest admissible index j^\hat j together with αj^\alpha_{\hat j} and xj^x_{\hat j}.

Proof. Line L2 stores the coefficients cj,k=skbk/(sk2+αj)c_{j,k} = s_kb_k/(s_k^2 + \alpha_j) of xjx_j in the orthonormal basis vkv_k, so ∥cj−ci∥=∥xj−xi∥\lVert c_j - c_i\rVert = \lVert x_j - x_i\rVert. For a given jj, lines L5 to L7 accept jj exactly when no i<ji < j violates the test, that is, when jj is admissible. The scan visits j=N−1,N−2,…j = N - 1, N - 2, \dots in decreasing order and returns at the first accepted jj, which is therefore the largest admissible index. Index 00 has no i<0i < 0 to test, so it is admissible and the scan returns after at most NN outer passes, each with at most N−1N - 1 inner tests. □\square

Claim 2 (the noise bound). ∥xα−xˉα∥≤δ/(2α)\lVert x_\alpha - \bar x_\alpha\rVert \le \delta/(2\sqrt\alpha), and the bound is attained for some ee when α\sqrt\alpha is a singular value.

Proof. xα−xˉα=∑ksk⟨uk,e⟩/(sk2+α) vkx_\alpha - \bar x_\alpha = \sum_k s_k\langle u_k, e\rangle/(s_k^2 + \alpha)\,v_k. By the inequality of arithmetic and geometric means, s2+α≥2sαs^2 + \alpha \ge 2s\sqrt\alpha, so s/(s2+α)≤1/(2α)s/(s^2 + \alpha) \le 1/(2\sqrt\alpha) for all s>0s > 0, with equality at s=αs = \sqrt\alpha. Hence the norm is at most ∥e∥/(2α)≤δ/(2α)\lVert e\rVert/(2\sqrt\alpha) \le \delta/(2\sqrt\alpha). If sk=αs_k = \sqrt\alpha, take e=δuke = \delta u_k. □\square

So ∥xj−x†∥≤φj+ψj\lVert x_j - x^\dagger\rVert \le \varphi_j + \psi_j for every jj.

Claim 3 (monotonicity). ψj\psi_j is strictly decreasing in jj, and φj\varphi_j is nondecreasing in jj.

Proof. The first is clear. For the second, xˉα−x†=−∑kα/(sk2+α) ξkvk\bar x_\alpha - x^\dagger = -\sum_k \alpha/(s_k^2 + \alpha)\,\xi_kv_k with ξk=⟨x†,vk⟩\xi_k = \langle x^\dagger, v_k\rangle, since bˉk=skξk\bar b_k = s_k\xi_k and sk2ξk/(sk2+α)−ξk=−αξk/(sk2+α)s_k^2\xi_k/(s_k^2 + \alpha) - \xi_k = -\alpha\xi_k/(s_k^2 + \alpha). Each factor α/(sk2+α)\alpha/(s_k^2 + \alpha) is increasing in α\alpha. □\square

Claim 4 (oracle inequality). Assume φ0≤ψ0\varphi_0 \le \psi_0 and let j∗=max⁡{j:φj≤ψj}j^\ast = \max\{j : \varphi_j \le \psi_j\}. Then j^≥j∗\hat j \ge j^\ast and

∥xj^−x†∥≤(4κ+2) ψj∗.\lVert x_{\hat j} - x^\dagger\rVert \le (4\kappa + 2)\,\psi_{j^\ast}.

If moreover αj+1/αj≤ρ\alpha_{j+1}/\alpha_j \le \rho for all jj, then

∥xj^−x†∥≤(4κ+2)ρ min⁡0≤j<N(φj+ψj).\lVert x_{\hat j} - x^\dagger\rVert \le (4\kappa + 2)\sqrt\rho\,\min_{0 \le j < N}(\varphi_j + \psi_j).

Proof. First, j∗j^\ast is admissible. Let i<j≤j∗i < j \le j^\ast. By Claim 3 and the definition of j∗j^\ast, φj≤φj∗≤ψj∗≤ψj\varphi_j \le \varphi_{j^\ast} \le \psi_{j^\ast} \le \psi_j. In the same way φi≤ψi\varphi_i \le \psi_i. So

∥xj−xi∥≤∥xj−x†∥+∥xi−x†∥≤φj+ψj+φi+ψi≤2ψj+2ψi≤4ψi≤4κψi,\lVert x_j - x_i\rVert \le \lVert x_j - x^\dagger\rVert + \lVert x_i - x^\dagger\rVert \le \varphi_j + \psi_j + \varphi_i + \psi_i \le 2\psi_j + 2\psi_i \le 4\psi_i \le 4\kappa\psi_i,

using ψj<ψi\psi_j < \psi_i. With j=j∗j = j^\ast this shows that j∗j^\ast is admissible, so j^≥j∗\hat j \ge j^\ast by Claim 1.

If j^=j∗\hat j = j^\ast, the error is at most φj∗+ψj∗≤2ψj∗\varphi_{j^\ast} + \psi_{j^\ast} \le 2\psi_{j^\ast}. Otherwise j∗<j^j^\ast < \hat j, and the admissibility of j^\hat j at i=j∗i = j^\ast gives ∥xj^−xj∗∥≤4κψj∗\lVert x_{\hat j} - x_{j^\ast}\rVert \le 4\kappa\psi_{j^\ast}. So

∥xj^−x†∥≤∥xj^−xj∗∥+∥xj∗−x†∥≤4κψj∗+2ψj∗.\lVert x_{\hat j} - x^\dagger\rVert \le \lVert x_{\hat j} - x_{j^\ast}\rVert + \lVert x_{j^\ast} - x^\dagger\rVert \le 4\kappa\psi_{j^\ast} + 2\psi_{j^\ast}.

For the second bound, take any jj. If j≤j∗j \le j^\ast, then φj+ψj≥ψj≥ψj∗\varphi_j + \psi_j \ge \psi_j \ge \psi_{j^\ast}. If j>j∗j > j^\ast, then φj≥φj∗+1>ψj∗+1\varphi_j \ge \varphi_{j^\ast + 1} > \psi_{j^\ast + 1} by the maximality of j∗j^\ast and Claim 3, and ψj∗+1=ψj∗αj∗/αj∗+1≥ψj∗/ρ\psi_{j^\ast + 1} = \psi_{j^\ast}\sqrt{\alpha_{j^\ast}/\alpha_{j^\ast + 1}} \ge \psi_{j^\ast}/\sqrt\rho. In both cases φj+ψj≥ψj∗/ρ\varphi_j + \psi_j \ge \psi_{j^\ast}/\sqrt\rho. Insert this in the first bound. □\square

Claim 5 (order optimality without knowing the smoothness). Let x†=(ATA)νwx^\dagger = (A^TA)^\nu w with 0<ν≤10 < \nu \le 1. Then φ(α)≤αν∥w∥\varphi(\alpha) \le \alpha^\nu\lVert w\rVert. If the geometric grid with ratio ρ\rho satisfies φ0≤ψ0\varphi_0 \le \psi_0 and αN−1≥αbal\alpha_{N-1} \ge \alpha_{\mathrm{bal}}, where αbal=(δ/(2∥w∥))2/(2ν+1)\alpha_{\mathrm{bal}} = (\delta/(2\lVert w\rVert))^{2/(2\nu + 1)} solves αν∥w∥=δ/(2α)\alpha^\nu\lVert w\rVert = \delta/(2\sqrt\alpha), then

∥xj^−x†∥≤2(4κ+2)ρ3/2 ∥w∥1/(2ν+1)(δ/2)2ν/(2ν+1).\lVert x_{\hat j} - x^\dagger\rVert \le 2(4\kappa + 2)\rho^{3/2}\,\lVert w\rVert^{1/(2\nu + 1)}(\delta/2)^{2\nu/(2\nu + 1)}.

Proof. The coefficient of xˉα−x†\bar x_\alpha - x^\dagger on vkv_k is −αsk2νωk/(sk2+α)-\alpha s_k^{2\nu}\omega_k/(s_k^2 + \alpha) with ωk=⟨w,vk⟩\omega_k = \langle w, v_k\rangle. For 0≤ν≤10 \le \nu \le 1, αs2ν/(s2+α)≤αν\alpha s^{2\nu}/(s^2 + \alpha) \le \alpha^\nu: with u=s2/αu = s^2/\alpha this is uν≤1+uu^\nu \le 1 + u, true for u≤1u \le 1 because uν≤1u^\nu \le 1 and for u≥1u \ge 1 because uν≤uu^\nu \le u. So φ(α)≤αν∥w∥\varphi(\alpha) \le \alpha^\nu\lVert w\rVert. Let jj be the smallest grid index with αj≥αbal\alpha_j \ge \alpha_{\mathrm{bal}}; it exists by assumption. If j=0j = 0, then α0≥αbal\alpha_0 \ge \alpha_{\mathrm{bal}}, so ψ0≤ψ(αbal)\psi_0 \le \psi(\alpha_{\mathrm{bal}}), and φ0≤ψ0\varphi_0 \le \psi_0 by assumption. If j>0j > 0, then αbal≤αj≤ρ αbal\alpha_{\mathrm{bal}} \le \alpha_j \le \rho\,\alpha_{\mathrm{bal}}, so ψj≤ψ(αbal)\psi_j \le \psi(\alpha_{\mathrm{bal}}) and φj≤ρναbalν∥w∥=ρνψ(αbal)≤ρ ψ(αbal)\varphi_j \le \rho^\nu\alpha_{\mathrm{bal}}^\nu\lVert w\rVert = \rho^\nu\psi(\alpha_{\mathrm{bal}}) \le \rho\,\psi(\alpha_{\mathrm{bal}}). In both cases φj+ψj≤2ρ ψ(αbal)\varphi_j + \psi_j \le 2\rho\,\psi(\alpha_{\mathrm{bal}}), and ψ(αbal)=∥w∥1/(2ν+1)(δ/2)2ν/(2ν+1)\psi(\alpha_{\mathrm{bal}}) = \lVert w\rVert^{1/(2\nu + 1)}(\delta/2)^{2\nu/(2\nu + 1)}. The second bound of Claim 4 multiplies this by (4κ+2)ρ(4\kappa + 2)\sqrt\rho. □\square

So the rule gives the rate O(δ2ν/(2ν+1))O(\delta^{2\nu/(2\nu + 1)}) for every ν∈(0,1]\nu \in (0, 1], which is the optimal order for Tikhonov regularization, and it does not use ν\nu. The constants are worst-case constants. In the example on the page the rule is well inside its bound but still over-smooths compared with the best grid point; that is a measurement.

Complexity

With the thin SVD given, line L1 costs Θ(mn)\Theta(mn) and lines L2 and L3 cost Θ(Nr)\Theta(Nr). Each distance in line L6 costs Θ(r)\Theta(r). In the worst case the scan tests all pairs, Θ(N2r)\Theta(N^2r). In the best case the largest index passes at once after N−1N - 1 tests. Line L8 costs Θ(n2)⊆O(mn)\Theta(n^2) \subseteq O(mn). The total is Θ(mn+N2n)\Theta(mn + N^2n) in the worst case and Θ(mn+Nn)\Theta(mn + Nn) in the best, with Θ(Nn)\Theta(Nn) extra space for the stored solutions. With a geometric grid, NN grows only like log⁡(αmax⁡/αmin⁡)\log(\alpha_{\max}/\alpha_{\min}), so N2N^2 is small. The SVD itself costs O(mn2)O(mn^2) and dominates.

Properties

  • A posteriori: it needs δ\delta and yδy^\delta, not x†x^\dagger or its smoothness.
  • Adaptive: one rule is order optimal for all smoothness classes the method can exploit. For Tikhonov that is 0<ν≤10 < \nu \le 1.
  • Proved oracle inequality on the grid, with the constant (4κ+2)ρ(4\kappa + 2)\sqrt\rho.
  • Works for any regularization method with a known noise bound ψ\psi: Landweber with ψk=k δ\psi_k = \sqrt k\,\delta, truncated SVD with ψk=δ/sk\psi_k = \delta/s_k, and statistical noise models with a stochastic bound.
  • Tends to over-smooth in practice, because ψ\psi bounds the worst case of the noise, not the typical case.

Variants and improvements

  • Statistical noise. For white noise of variance σ2\sigma^2, replace ψ\psi by a bound on the typical noise in the solution, such as σ∑isi2/(si2+α)2\sigma\sqrt{\sum_i s_i^2/(s_i^2 + \alpha)^2} times a factor that grows with log⁡N\log N. This is the setting of Lepskii's original work.
  • Smaller constants. Many users replace 4κ4\kappa by 22 or less. The rule then picks smaller α\alpha and is often more accurate, but the proof above no longer applies.
  • Nonlinear problems and iterations. The same comparison works for iteratively regularized Gauss-Newton and for stopping Landweber, with the appropriate ψ\psi.

When to use it

Use it when the noise level is known, the smoothness of the solution is not, and you want a rule with a proved guarantee that does not saturate. It is a natural choice for theory-driven work and for methods with high qualification, where the discrepancy principle loses the best rate. If you want the most accurate α\alpha for one dataset and the noise is white, UPRE is usually closer to the best. If δ\delta is unknown, the rule cannot be used; see the quasi-optimality criterion and the Bakushinskii veto.

Pitfalls

  • A grid that starts too high. The oracle inequality needs φ(α0)≤ψ(α0)\varphi(\alpha_0) \le \psi(\alpha_0). If α0\alpha_0 already over-smooths, the rule has nothing to balance against. Start the grid well below sr2s_r^2.
  • A wrong ψ\psi. For Tikhonov the noise bound is δ/(2α)\delta/(2\sqrt\alpha), not δ/α\delta/\alpha. A too large ψ\psi in line L3 makes every index admissible, and line L8 returns the largest α\alpha.
  • Testing only against the previous index in line L5. The proof needs the test against every smaller index; a chain of small steps can drift far.
  • Scanning from the small end and stopping at the first failure. This gives a different rule, with a different index, unless the admissible set is an interval. The implementation scans from the large end and returns the largest admissible index, as the theory requires.
  • Expecting the best α\alpha. The guarantee is a factor of 6ρ6\sqrt\rho in the worst case, and in the example the rule loses a factor of 3. Use it for safety, not for the last few percent.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

imgla.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Dense linear algebra on lists of rows (float, complex or Fraction entries).

A matrix is a list of rows. A vector is a list of numbers. The inner product
is <u, v> = sum_i conj(u_i) v_i, linear in the second argument, so that the
adjoint A^H satisfies <A x, y> = <x, A^H y>.
"""

import math


def _flat(x):
    """Flatten a list of rows (an image) into one list; a vector is returned as is."""
    if x and isinstance(x[0], (list, tuple)):
        return [v for row in x for v in row]
    return x


def zeros(m, n):
    """The m x n zero matrix."""
    return [[0.0] * n for _ in range(m)]


def eye(n):
    """The n x n identity matrix."""
    out = zeros(n, n)
    for i in range(n):
        out[i][i] = 1.0
    return out


def transpose(a):
    """A^T."""
    return [list(col) for col in zip(*a)]


def conj_transpose(a):
    """A^H, the conjugate transpose."""
    return [[v.conjugate() for v in col] for col in zip(*a)]


def matmul(a, b):
    """The product A B."""
    bt = list(zip(*b))
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def matvec(a, x):
    """The product A x."""
    return [sum(v * w for v, w in zip(row, x)) for row in a]


def rmatvec(a, y):
    """The product A^H y."""
    n = len(a[0]) if a else 0
    out = [0.0] * n
    for row, yi in zip(a, y):
        if yi == 0:
            continue
        for j, v in enumerate(row):
            out[j] += v.conjugate() * yi
    return out


def dot(u, v):
    """<u, v> = sum_i conj(u_i) v_i. Images (lists of rows) are flattened."""
    return sum(a.conjugate() * b for a, b in zip(_flat(u), _flat(v)))


def norm2(x):
    """The Euclidean norm. Images (lists of rows) are flattened."""
    return math.sqrt(sum(abs(v) ** 2 for v in _flat(x)))


def solve(a, b):
    """Solve A x = b by Gaussian elimination with partial pivoting.

    b is a vector or a matrix (a list of rows). A must be square and
    nonsingular; a zero pivot raises ValueError. Fractions stay exact.
    """
    n = len(a)
    vec = not (b and isinstance(b[0], (list, tuple)))
    rhs = [[bi] for bi in b] if vec else [list(r) for r in b]
    m = [list(row) + rhs[i] for i, row in enumerate(a)]
    w = len(m[0])
    for c in range(n):
        p = max(range(c, n), key=lambda r: abs(m[r][c]))
        if m[p][c] == 0:
            raise ValueError("singular matrix")
        m[c], m[p] = m[p], m[c]
        piv = m[c][c]
        for r in range(c + 1, n):
            f = m[r][c] / piv
            if f != 0:
                mr, mc = m[r], m[c]
                for j in range(c, w):
                    mr[j] -= f * mc[j]
    x = [[0.0] * (w - n) for _ in range(n)]
    for r in range(n - 1, -1, -1):
        for j in range(w - n):
            s = m[r][n + j] - sum(m[r][k] * x[k][j] for k in range(r + 1, n))
            x[r][j] = s / m[r][r]
    return [row[0] for row in x] if vec else x


def cholesky(a):
    """Lower triangular L with A = L L^H for a Hermitian positive definite A."""
    n = len(a)
    low = zeros(n, n)
    for j in range(n):
        d = a[j][j] - sum(abs(low[j][k]) ** 2 for k in range(j))
        d = d.real if isinstance(d, complex) else d
        if not d > 0:
            raise ValueError("matrix is not positive definite")
        ljj = math.sqrt(d)
        low[j][j] = ljj
        for i in range(j + 1, n):
            s = a[i][j] - sum(low[i][k] * low[j][k].conjugate() for k in range(j))
            low[i][j] = s / ljj
    return low


def cho_solve(low, b):
    """Solve (L L^H) x = b, with L from cholesky."""
    n = len(low)
    z = [0.0] * n
    for i in range(n):
        z[i] = (b[i] - sum(low[i][k] * z[k] for k in range(i))) / low[i][i]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        s = z[i] - sum(low[k][i].conjugate() * x[k] for k in range(i + 1, n))
        x[i] = s / low[i][i].conjugate()
    return x


def _rot_params(app, aqq, apq):
    """c, s of the Jacobi rotation that zeroes the (p, q) entry of [[app, apq], [apq, aqq]]."""
    theta = (aqq - app) / (2.0 * apq)
    t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
    c = 1.0 / math.sqrt(1.0 + t * t)
    return c, c * t


def sym_eig(a, tol=1e-15, max_sweeps=100):
    """Eigenvalues (ascending) and eigenvectors (as columns) of a real symmetric matrix.

    Cyclic Jacobi method. Returns (w, Q) with A = Q diag(w) Q^T.
    """
    n = len(a)
    m = [[float(v) for v in row] for row in a]
    q = eye(n)
    for _ in range(max_sweeps):
        off = sum(m[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
        scale = sum(m[i][i] ** 2 for i in range(n)) + off
        if off <= (tol * tol) * scale or off == 0.0:
            break
        for p in range(n - 1):
            for r in range(p + 1, n):
                apq = m[p][r]
                if apq == 0.0:
                    continue
                c, s = _rot_params(m[p][p], m[r][r], apq)
                for k in range(n):
                    mkp, mkr = m[k][p], m[k][r]
                    m[k][p] = c * mkp - s * mkr
                    m[k][r] = s * mkp + c * mkr
                mp, mr = m[p], m[r]
                for k in range(n):
                    mpk, mrk = mp[k], mr[k]
                    mp[k] = c * mpk - s * mrk
                    mr[k] = s * mpk + c * mrk
                m[p][r] = m[r][p] = 0.0
                for k in range(n):
                    qkp, qkr = q[k][p], q[k][r]
                    q[k][p] = c * qkp - s * qkr
                    q[k][r] = s * qkp + c * qkr
    order = sorted(range(n), key=lambda i: m[i][i])
    w = [m[i][i] for i in order]
    qs = [[q[k][i] for i in order] for k in range(n)]
    return w, qs


def _complete(cols, m):
    """Replace zero columns of an m-row column list by unit vectors orthogonal to the others."""
    for idx, col in enumerate(cols):
        if any(v != 0.0 for v in col):
            continue
        for e in range(m):
            cand = [0.0] * m
            cand[e] = 1.0
            for _ in range(2):
                for jdx, other in enumerate(cols):
                    if jdx == idx or not any(v != 0.0 for v in other):
                        continue
                    h = sum(a * b for a, b in zip(other, cand))
                    cand = [a - h * b for a, b in zip(cand, other)]
            nrm = math.sqrt(sum(v * v for v in cand))
            if nrm > 0.5:
                cols[idx] = [v / nrm for v in cand]
                break
    return cols


def svd(a, tol=1e-15, max_sweeps=100):
    """Thin SVD of a real m x n matrix by one-sided Jacobi (Hestenes).

    Returns (U, S, V) with p = min(m, n): U is m x p, S a list of p values in
    descending order, V is n x p, U^T U = I, V^T V = I and A = U diag(S) V^T.
    """
    m, n = len(a), len(a[0])
    if m < n:
        v, s, u = svd(transpose(a), tol, max_sweeps)
        return u, s, v
    cols = [[float(a[i][j]) for i in range(m)] for j in range(n)]
    vcols = [[1.0 if i == j else 0.0 for i in range(n)] for j in range(n)]
    for _ in range(max_sweeps):
        rotated = False
        for p in range(n - 1):
            for r in range(p + 1, n):
                cp, cr = cols[p], cols[r]
                alpha = sum(x * x for x in cp)
                beta = sum(x * x for x in cr)
                gamma = sum(x * y for x, y in zip(cp, cr))
                if gamma == 0.0 or abs(gamma) <= tol * math.sqrt(alpha * beta):
                    continue
                rotated = True
                c, s = _rot_params(alpha, beta, gamma)
                cols[p] = [c * x - s * y for x, y in zip(cp, cr)]
                cols[r] = [s * x + c * y for x, y in zip(cp, cr)]
                vp, vr = vcols[p], vcols[r]
                vcols[p] = [c * x - s * y for x, y in zip(vp, vr)]
                vcols[r] = [s * x + c * y for x, y in zip(vp, vr)]
        if not rotated:
            break
    sig = [math.sqrt(sum(x * x for x in col)) for col in cols]
    # A column below 1e-150 times the largest one is zero to working precision;
    # its squares underflow, so its direction carries no information.
    floor = max(sig) * 1e-150 if sig else 0.0
    sig = [t if t > floor and t > 1e-150 else 0.0 for t in sig]
    order = sorted(range(n), key=lambda j: -sig[j])
    s_out = [sig[j] for j in order]
    ucols = [[x / sig[j] for x in cols[j]] if sig[j] > 0.0 else [0.0] * m for j in order]
    ucols = _complete(ucols, m)
    u = [[ucols[j][i] for j in range(n)] for i in range(m)]
    v = [[vcols[j][i] for j in order] for i in range(n)]
    return u, s_out, v


def adjoint_gap(apply_a, apply_ah, x, y):
    """|<A x, y> - <x, A^H y>| / (||A x|| ||y||) for given functions A and A^H.

    x and y may be vectors or images (lists of rows). If the denominator is
    zero, the absolute gap is returned.
    """
    ax = apply_a(x)
    gap = abs(dot(ax, y) - dot(x, apply_ah(y)))
    den = norm2(ax) * norm2(y)
    return gap / den if den > 0.0 else gap
lepskii_balancing_principle.py 98 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lepskii-balancing-principle/. The authors are listed in prov/WKH6V6.jsonl.
"""The Lepskii balancing principle for Tikhonov regularization.

Model: y = A x + e with ||e|| <= delta. Tikhonov: x_alpha minimizes
||A x - y||^2 + alpha ||x||^2. The noise part of the error is bounded by
psi(alpha) = delta / (2 sqrt(alpha)), because s / (s^2 + alpha) <= 1 / (2 sqrt(alpha)).

On a grid alpha_1 < alpha_2 < ... < alpha_N the rule takes the largest j with
||x_{alpha_j} - x_{alpha_i}|| <= 4 kappa psi(alpha_i) for every i < j
(kappa >= 1 is a safety factor; kappa = 1 is the plain rule).
"""

import math

from imgla import norm2, svd


def coefficients(u, s, y):
    """b_i = <u_i, y> for the s_i > 0."""
    m = len(y)
    return [sum(u[i][k] * y[i] for i in range(m)) for k in range(len(s)) if s[k] > 0.0]


def noise_bound(delta, alpha):
    """psi(alpha) = delta / (2 sqrt(alpha)): the bound on ||(A^T A + alpha I)^(-1) A^T e||."""
    return delta / (2.0 * math.sqrt(alpha))


def geometric_grid(alpha_min, alpha_max, ratio):
    """alpha_min, alpha_min * ratio, ... up to the first value >= alpha_max."""
    out = [alpha_min]
    while out[-1] < alpha_max:
        out.append(out[-1] * ratio)
    return out


def tikhonov_coeffs(s, b, alpha):
    """The coefficients of x_alpha in the basis v_i: s_i b_i / (s_i^2 + alpha)."""
    return [si * bi / (si * si + alpha) for si, bi in zip(s, b)]


def tikhonov_svd(s, v, b, alpha):
    """x_alpha = sum_i s_i b_i / (s_i^2 + alpha) v_i."""
    n = len(v)
    c = tikhonov_coeffs(s, b, alpha)
    return [sum(c[k] * v[j][k] for k in range(len(c))) for j in range(n)]


def balancing(u, s, v, y, delta, alphas=None, kappa=1.0, ratio=1.5):
    """Return (alpha, x, j) for the balancing principle on the increasing grid alphas.

    By default the grid runs from (s_r^2) / 100 to s_1^2 with the given ratio.
    Index j is 0-based. The scan goes from the largest alpha down and stops at
    the first admissible index, which is the largest one.
    """
    s = [si for si in s if si > 0.0]
    b = coefficients(u, s, y)  # @line L1
    if alphas is None:
        alphas = geometric_grid(s[-1] ** 2 / 100.0, s[0] ** 2, ratio)
    coeffs = [tikhonov_coeffs(s, b, a) for a in alphas]  # @line L2
    psi = [noise_bound(delta, a) for a in alphas]  # @line L3
    for j in range(len(alphas) - 1, -1, -1):  # @line L4
        ok = True
        for i in range(j):  # @line L5
            dist = math.sqrt(sum((p - q) ** 2 for p, q in zip(coeffs[j], coeffs[i])))
            if dist > 4.0 * kappa * psi[i]:  # @line L6
                ok = False
                break
        if ok:  # @line L7
            return alphas[j], tikhonov_svd(s, v, b, alphas[j]), j  # @line L8
    raise AssertionError("index 0 is always admissible")


def balancing_matrix(a, y, delta, **kw):
    """The same for a dense matrix: compute the SVD, then call balancing."""
    u, s, v = svd(a)
    return balancing(u, s, v, y, delta, **kw)


def bias_norms(s, v, xt, alphas):
    """phi(alpha) = ||x_alpha^0 - x_true|| for exact data y = A x_true (an oracle, for tests).

    With c_i = <v_i, x_true>, x_alpha^0 - x_true has the coefficients
    -alpha / (s_i^2 + alpha) c_i on v_i, plus the part of x_true outside the
    span of the v_i, which no alpha changes.
    """
    n = len(xt)
    s = [si for si in s if si > 0.0]
    c = [sum(v[j][k] * xt[j] for j in range(n)) for k in range(len(s))]
    out2 = max(norm2(xt) ** 2 - sum(t * t for t in c), 0.0)
    res = []
    for a in alphas:
        tot = out2
        for si, ci in zip(s, c):
            tot += (a / (si * si + a) * ci) ** 2
        res.append(math.sqrt(tot))
    return res
test_lepskii_balancing_principle.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lepskii-balancing-principle/. The authors are listed in prov/WKH6V6.jsonl.

import math
import random

from imgla import eye, matmul, matvec, norm2, solve, svd, transpose
from lepskii_balancing_principle import (
    balancing,
    balancing_matrix,
    bias_norms,
    coefficients,
    geometric_grid,
    noise_bound,
    tikhonov_coeffs,
    tikhonov_svd,
)

EYE = eye(32)


def diag_problem(seed, sigma=1e-3, power=2.0, n=32):
    """A = diag(1/i^2), x_i = 1/i^power, white noise of standard deviation sigma."""
    s = [1.0 / i ** 2 for i in range(1, n + 1)]
    xt = [1.0 / i ** power for i in range(1, n + 1)]
    rng = random.Random(seed)
    e = [sigma * rng.gauss(0.0, 1.0) for _ in range(n)]
    y = [si * xi + ei for si, xi, ei in zip(s, xt, e)]
    return s, xt, y, norm2(e)


def test_page_example():
    s, xt, y, delta = diag_problem(0)
    assert abs(delta - 0.0065079) < 1e-6
    alphas = [1e-6 * 2 ** j for j in range(21)]
    alpha, x, j = balancing(EYE, s, EYE, y, delta, alphas=alphas)
    assert j == 16 and alpha == alphas[16]
    assert abs(math.dist(x, xt) - 0.19141) < 1e-5
    phi = bias_norms(s, EYE, xt, alphas)
    psi = [noise_bound(delta, a) for a in alphas]
    jstar = max(k for k in range(21) if phi[k] <= psi[k])
    assert jstar == 11
    assert math.dist(x, xt) <= 6.0 * psi[jstar]


def test_noise_bound_holds_and_is_attained():
    rng = random.Random(1)
    a = [[rng.gauss(0.0, 1.0) / (j + 1) for j in range(5)] for _ in range(7)]
    u, s, v = svd(a)
    at = transpose(a)
    for alpha in (1e-4, 1e-2, 1.0):
        ata = matmul(at, a)
        for i in range(5):
            ata[i][i] += alpha
        for _ in range(20):
            e = [rng.gauss(0.0, 1.0) for _ in range(7)]
            d = norm2(e)
            assert norm2(solve(ata, matvec(at, e))) <= noise_bound(d, alpha) * (1.0 + 1e-12)
    s1 = [1.0, 0.5]
    alpha = 0.25
    coeff = tikhonov_coeffs(s1, [0.0, 1.0], alpha)
    assert abs(norm2(coeff) - noise_bound(1.0, alpha)) < 1e-15


def test_oracle_inequality_over_noise_levels_and_seeds():
    for power in (1.5, 2.0, 3.0):
        for sigma in (1e-2, 1e-3, 1e-4, 1e-5):
            for seed in range(3):
                s, xt, y, delta = diag_problem(seed, sigma, power)
                alphas = geometric_grid(1e-9, 1.0, 2.0)
                alpha, x, j = balancing(EYE, s, EYE, y, delta, alphas=alphas)
                phi = bias_norms(s, EYE, xt, alphas)
                psi = [noise_bound(delta, a) for a in alphas]
                assert phi[0] <= psi[0]
                jstar = max(k for k in range(len(alphas)) if phi[k] <= psi[k])
                err = math.dist(x, xt)
                assert j >= jstar
                assert err <= 6.0 * psi[jstar] * (1.0 + 1e-12)
                oracle = min(p + q for p, q in zip(phi, psi))
                assert err <= 6.0 * math.sqrt(2.0) * oracle * (1.0 + 1e-12)


def test_result_is_the_largest_admissible_index():
    s, xt, y, delta = diag_problem(5)
    alphas = geometric_grid(1e-8, 1.0, 1.7)
    alpha, x, j = balancing(EYE, s, EYE, y, delta, alphas=alphas, kappa=1.3)
    co = [tikhonov_coeffs(s, y, a) for a in alphas]

    def admissible(k):
        return all(math.dist(co[k], co[i]) <= 4 * 1.3 * noise_bound(delta, alphas[i]) for i in range(k))

    assert admissible(j)
    assert not any(admissible(k) for k in range(j + 1, len(alphas)))
    assert all(admissible(k) for k in range(j))


def test_bias_is_nondecreasing_in_alpha():
    s, xt, y, delta = diag_problem(0)
    alphas = geometric_grid(1e-9, 10.0, 1.3)
    phi = bias_norms(s, EYE, xt, alphas)
    assert all(phi[k] <= phi[k + 1] for k in range(len(phi) - 1))


def test_dense_matrix_path():
    rng = random.Random(9)
    a = [[rng.gauss(0.0, 1.0) / (j + 1) ** 2 for j in range(6)] for _ in range(9)]
    xt = [1.0, -0.5, 0.25, 0.1, -0.05, 0.02]
    e = [1e-3 * rng.gauss(0.0, 1.0) for _ in range(9)]
    y = [p + q for p, q in zip(matvec(a, xt), e)]
    al1, x1, j1 = balancing_matrix(a, y, norm2(e))
    u, s, v = svd(a)
    b = coefficients(u, s, y)
    assert math.dist(x1, tikhonov_svd(s, v, b, al1)) <= 1e-12 * norm2(x1)
    at = transpose(a)
    ata = matmul(at, a)
    for i in range(6):
        ata[i][i] += al1
    assert math.dist(x1, solve(ata, matvec(at, y))) <= 1e-8 * norm2(x1)

History

Lepskii (1990) introduced the method to choose a bandwidth in nonparametric estimation in Gaussian white noise, without knowing the smoothness of the signal, and showed that it adapts to the unknown smoothness. Goldenshluger and Pereverzev applied it to ill-posed problems with random noise around 2000. Mathé and Pereverzev (2003) used it for linear ill-posed problems in variable Hilbert scales, and Mathé (2006) revisited the method for linear ill-posed problems. It is now a standard tool for adaptive parameter choice in regularization and in learning theory.

References

  1. O. V. Lepskii, On a problem of adaptive estimation in Gaussian white noise, Theory of Probability and Its Applications 35(3), 1990, pages 454 to 466 (the English translation is dated 1991)
  2. Peter Mathé and Sergei V. Pereverzev, Geometry of linear ill-posed problems in variable Hilbert scales, Inverse Problems 19(3), 2003, pages 789 to 803
  3. Heinz W. Engl, Martin Hanke and Andreas Neubauer, Regularization of Inverse Problems, Kluwer, 1996, chapters 4 and 5 (order optimality and the saturation of the discrepancy principle, for comparison)

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.average
  • a full proof of time.best
  • 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