Algorithmresearch
Wirtinger flow
Phase retrieval from y_r = |a_r^* x|^2 by gradient descent on the squared misfit, with Wirtinger derivatives, from a spectral start. For Gaussian a_r it converges linearly to x up to a global phase.
- Solves
- Phase retrieval
- Time
- O(K m n) worst
- Space
- O(n) extra
- Where
- K = the number of iterations; m = the number of measurements; n = the length of the signal
- Model
- Real RAM
- Properties
- deterministicnot exactnot in placeoffline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Emmanuel Candès, Xiaodong Li, Mahdi Soltanolkotabi, 2015
Wirtinger flow is a nonconvex method for phase retrieval with known sampling vectors. The data are for , and the method minimizes the squared misfit
by gradient steps. The function is real and not holomorphic, so the gradient is taken with Wirtinger derivatives, which is the same as the ordinary gradient in the real and imaginary parts. The start is the spectral initialization. Candès, Li and Soltanolkotabi (2015) proved that for about Gaussian sampling vectors the start is close to the signal and the steps converge to it at a geometric rate, up to a global phase.
In plain words
You must find an unknown list of complex numbers. For each of many known random lists you are told how strongly it lines up with the unknown list, but not the phase. Any guess can be scored by how badly it fits these numbers.
Wirtinger flow first makes a good guess from the data alone. Then it goes downhill on the score, step by step, like water that runs down a slope. The score has many dips, and a downhill walk can stop in a wrong one. The theory shows that, with enough random measurements, the land near the true answer slopes straight to it, and the first guess lands there. The phase of the whole answer stays unknown, and no method can find it.
The problem
The input is vectors and the values for an unknown . The output is a with a small . The data are the same for and , so this is the right measure of error. In the Gaussian model of the theory, the entries of are independent .
The algorithm
WIRTINGER-FLOW(a₁, …, a_m, y, K, τ₀, μ_max)- 1
z ← SPECTRAL-INIT(a₁, …, a_m, y) - 2
s ← ‖z‖² - 3
for τ ← 1 to K do - 4
μ ← min(1 − exp(−τ/τ₀), μ_max) - 5
g ← (1/m) Σ_r (|a_r* z|² − y_r) a_r (a_r* z) - 6
z ← z − (μ / s) g - 7
return z
Line L1 is the top eigenvector of , scaled to the estimate of . Line L5 is the Wirtinger gradient . It needs one pass to form the values and one pass to add up the vectors. Line L6 divides the step by , which makes the method the same for every scale of . Line L4 is the schedule of the authors: small steps first, then the cap . They suggest and in (2.5), and they used in their experiments with Gaussian vectors. The theorem is for a constant step .
Example
Take , , a unit vector and complex Gaussian vectors, all from seed 1. The table gives for two caps of the step, with (measurements of the implementation):
| step | 0 | 50 | 100 | 200 | 300 | 500 | 1000 |
|---|---|---|---|---|---|---|---|
| 0.67 | 0.17 | 0.0099 | 1.7e-5 | 3.0e-8 | 9.3e-14 | 1.9e-16 | |
| 0.67 | 0.17 | 0.0099 | 4.7e-6 | 9.1e-10 | 1.0e-7 | 0.078 |
The spectral start is from . With the cap , the error falls at a steady geometric rate once the steps reach the cap, and it ends at the level of rounding errors. With the cap , it falls faster at first. Then the error grows again, and the iterates stay at a distance of up to step 2500.
The reason is the curvature at the solution. Near the method is gradient descent with the step on the real and imaginary parts, and is a stable fixed point only if this step is below , where is the largest eigenvalue of the real Hessian of at . That is . For seed 1 this limit is , so the cap is too large, and the rounding errors grow. Over seeds 1 to 5 the limit was to . With the cap , seeds 1 and 4 failed. With the cap , all five reached a distance below by step 1000. For large the Hessian is close to its mean, whose largest eigenvalue is , and the limit is near .
Correctness
The proof page shows these facts.
- The gradient. For a real , at . So is the steepest descent direction, and line L6 is gradient descent on .
- Solutions and stationary points. , and exactly when fits all the data. Every is a zero of and of . The point is also a stationary point, but not a solution, so the start matters.
- Descent. A small enough step decreases .
- Linear convergence. If near the solutions, then every step shrinks by the factor .
Candès, Li and Soltanolkotabi (2015, Theorem 3.3) show that for Gaussian vectors this condition holds and the spectral start is within of the signal, with high probability. With a constant step , this gives
This theorem is cited, not proved here.
Proof: The Wirtinger gradient, the stationary points, and linear convergence under a regularity conditionfull
Vectors are in with . The data are for . Write and . The loss and the step direction are
The algorithm takes (line L6). The claim of correctness has four parts. The step direction is the steepest descent direction of (Lemma 1). The solutions are exactly the zeros of , and they are stationary points (Lemma 2). A small step decreases (Lemma 3). Near the solutions, a regularity condition gives linear convergence to the set of solutions (Lemma 4). That the regularity condition holds with high probability for Gaussian vectors is the work of Candès, Li and Soltanolkotabi (2015), which is cited and not proved here.
The error is . The minimum is at with (or any if ), because .
Lemma 1 (the gradient). For every , every and real ,
Proof. With and , we have . So the derivative of at is , and the derivative of is
On the other side, because is real, so . Twice its real part is the same sum.
So if is read as with the inner product , the ordinary gradient of is . This is the Wirtinger derivative (Candès, Li and Soltanolkotabi 2015, Section 6). Among the directions with , the derivative is smallest at by the Cauchy-Schwarz inequality. So line L6 is gradient descent on with the step .
Lemma 2 (solutions and stationary points). for all , and exactly when for all . In particular and for all real . Also and . Finally .
Proof. is a sum of squares, so with equality exactly when every . For each , so and every term of is . Replacing by does not change and multiplies by , which gives the two identities. At every .
So the method can only find up to a global phase, and the error must be measured by . The point is a stationary point with when , so a stationary point need not be a solution. This is one reason why the start matters.
Lemma 3 (a small step decreases ). If , there is such that for . If the second derivative of is at most on , then .
Proof. By Lemma 1 with , . The function is a polynomial of degree at most in , so it is smooth, and for all small . The second claim is Taylor's theorem with the remainder for some .
So with a bound for , every step decreases . The function is a quartic, so grows with ; a step that is too large can increase , and a fixed step is safe only on a bounded region. This is why the schedule starts small.
Lemma 4 (linear convergence under a regularity condition). Let , let , and let be such that for all
If and , then has . So from any the iterates stay in and .
Proof. Put , so . Then
By (RC) this is at most . The last two terms add to . The distance of is a minimum over all phases, so it is at most the norm on the left side. So , and . Induction on gives the rest.
The factor is not negative: (RC) and the Cauchy-Schwarz inequality give , and the inequality of arithmetic and geometric means gives . So when (RC) holds with , and . Lemma 4 is Lemma 7.10 of Candès, Li and Soltanolkotabi (2015), and (RC) is their Condition 7.9.
The cited theorem. Candès, Li and Soltanolkotabi (2015, Theorem 3.3) take with independent entries and . With probability at least the spectral start has . For a constant there is an event of probability at least on which every with that bound gives
Here , and are numerical constants. Their proof shows that (RC) holds on with and suitable and , and then applies Lemma 4. The spectral start itself is treated on the page on spectral initialization.
What is not claimed. The proof that (RC) holds with high probability for Gaussian vectors, and so the theorem above, is cited and not proved here. The theorem is for a constant step . The schedule that the implementation uses is a tuned choice, and it has no proof. With and the iterates can leave the solution again (see the example on the main page). The tests measure the recovery on fixed seeds with and do not check a theorem there.
Complexity
One step costs for general vectors: two passes over the vectors of length . steps cost , and the extra space is for and . With , the theorem needs steps for the accuracy , so in total. For coded diffraction patterns with masks, , and the products with the are fast Fourier transforms. One step then costs . Theorem 5.1 of the same paper gives a constant step there, with patterns.
Properties
- Up to a global phase. No method can do better with these data.
- Nonconvex. is a quartic with stationary points that are not solutions, such as . The guarantee depends on the start and on random vectors.
- Linear convergence near the signal, in theory with a step of order for Gaussian vectors.
- Deterministic once the start of the power iteration is fixed.
- Simple steps. Only products with the and ; no matrix of size is formed.
Variants and improvements
- Truncated Wirtinger flow. Chen and Candès (2017) leave out the terms with large values in the start and in the gradient. Their method needs a number of equations of the order of , which removes the factor.
- Coded diffraction patterns. Candès, Li and Soltanolkotabi (2015) give a variant of the method with a theorem for random masks and Fourier measurements (Theorem 5.1).
- Other losses. The misfit can use the magnitudes in place of their squares, or another loss of the two values.
- Step rules. A backtracking line search in place of the fixed schedule. A stochastic version uses one or a few per step.
- Convex relaxation. PhaseLift solves a semidefinite program in place of the nonconvex problem. It needs order measurements but works with matrices.
When to use it
Use Wirtinger flow when the sampling vectors are random or close to random, such as Gaussian vectors or random coded diffraction patterns, and the signal is too large for a semidefinite program. Candès, Li and Soltanolkotabi report that about Gaussian measurements were enough for exact recovery with high probability in their trials with (Section 4.2), and they recovered photographs of more than a million pixels from 20 coded diffraction patterns (Section 4.3). For the classical Fourier problem with a support, as in coherent diffraction imaging, the theory does not apply, and the projection methods such as error reduction are more common.
Pitfalls
- Comparing without the phase. Measure the error with , not with .
- A step that is too large. The example shows a cap of that loses a solution it had found to . The safe step depends on the curvature at , which changes with and the seed. If the error grows again, lower .
- A bad start. From a random start the method can stop at a stationary point that is not a solution, such as near .
- Too few measurements. With fewer than real values, a signal in cannot be determined. For a small multiple of the method can fail even from the spectral start.
- Real or complex. For real signals and real vectors the same code works, but the phase is only a sign, and the mean of the spectral matrix is different.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/wirtinger-flow/. The authors are listed in prov/E17F69.jsonl.
"""Wirtinger flow for phase retrieval (Candes, Li and Soltanolkotabi 2015).
The data are y_r = |a_r^H x|^2 for known a_r in C^n (lists of numbers). The
loss is
f(z) = (1 / (2 m)) sum_r (|a_r^H z|^2 - y_r)^2,
and its Wirtinger gradient (the derivative with respect to conj(z)) is
g(z) = (1 / m) sum_r (|a_r^H z|^2 - y_r) a_r (a_r^H z).
For a real direction t and any d, d/dt f(z + t d) at t = 0 is 2 Re <g(z), d>.
The method starts from the spectral estimate z_0 and takes the steps
z <- z - (mu_tau / ||z_0||^2) g(z) with mu_tau = min(1 - exp(-tau / tau0), mu_max);
the values tau0 = 330 and mu_max = 0.4 are those the authors report for
their simulations. The convergence theorem is for a constant step mu <= c1 / n
and Gaussian a_r; the schedule is a tuned choice.
"""
import math
import random
def gaussian_design(rng, m, n):
"""m sampling vectors with entries N(0, 1/2) + i N(0, 1/2)."""
s = math.sqrt(0.5)
return [[complex(rng.gauss(0.0, s), rng.gauss(0.0, s)) for _ in range(n)] for _ in range(m)]
def inner(a, v):
"""<a, v> = a^H v = sum conj(a_i) v_i."""
return sum(complex(u).conjugate() * w for u, w in zip(a, v))
def norm(v):
"""The Euclidean norm."""
return math.sqrt(sum(abs(w) ** 2 for w in v))
def measure(a_rows, x):
"""The phaseless data y_r = |a_r^H x|^2."""
return [abs(inner(a, x)) ** 2 for a in a_rows]
def loss(a_rows, y, z):
"""f(z) = (1 / (2 m)) sum_r (|a_r^H z|^2 - y_r)^2."""
return sum((abs(inner(a, z)) ** 2 - yr) ** 2 for a, yr in zip(a_rows, y)) / (2.0 * len(y))
def wirtinger_gradient(a_rows, y, z):
"""g(z) = (1 / m) sum_r (|a_r^H z|^2 - y_r) a_r (a_r^H z)."""
out = [0j] * len(z)
for a, yr in zip(a_rows, y):
p = inner(a, z)
c = (abs(p) ** 2 - yr) * p
for i, ai in enumerate(a):
out[i] += c * ai
m = len(y)
return [w / m for w in out]
def spectral_start(a_rows, y, iters=100, seed=0):
"""The spectral estimate: lambda times the top eigenvector of (1/m) sum y_r a_r a_r^H."""
n, m = len(a_rows[0]), len(y)
lam = math.sqrt(n * sum(y) / sum(norm(a) ** 2 for a in a_rows))
rng = random.Random(seed)
v = [complex(rng.gauss(0.0, 1.0), rng.gauss(0.0, 1.0)) for _ in range(n)]
for _ in range(iters):
w = [0j] * n
for a, yr in zip(a_rows, y):
c = yr * inner(a, v) / m
for i, ai in enumerate(a):
w[i] += c * ai
s = norm(w)
v = [u / s for u in w]
return [lam * u for u in v]
def step_size(tau, tau0=330.0, mu_max=0.4):
"""mu_tau = min(1 - exp(-tau / tau0), mu_max)."""
return min(1.0 - math.exp(-tau / tau0), mu_max)
def wirtinger_flow(a_rows, y, iters, z0=None, tau0=330.0, mu_max=0.4, record=None):
"""Run Wirtinger flow. Returns z. If record is a list, z_0 .. z_iters are appended to it."""
z = list(spectral_start(a_rows, y) if z0 is None else z0) # @line L1
scale = norm(z) ** 2 # @line L2
if record is not None:
record.append(z)
for tau in range(1, iters + 1): # @line L3
mu = step_size(tau, tau0, mu_max) # @line L4
g = wirtinger_gradient(a_rows, y, z) # @line L5
z = [u - (mu / scale) * v for u, v in zip(z, g)] # @line L6
if record is not None:
record.append(z)
return z # @line L7
def dist(z, x):
"""min over phi of ||z - e^{i phi} x||, reached at the phase of x^H z."""
c = inner(x, z)
phase = c / abs(c) if abs(c) > 0.0 else 1.0
return norm([u - phase * v for u, v in zip(z, x)])
test_wirtinger_flow.py 87 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/wirtinger-flow/. The authors are listed in prov/E17F69.jsonl.
import cmath
import math
import random
from wirtinger_flow import (dist, gaussian_design, inner, loss, measure, norm, spectral_start, step_size,
wirtinger_flow, wirtinger_gradient)
def unit_signal(rng, n):
x = [complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in range(n)]
s = norm(x)
return [v / s for v in x]
def test_gradient_gives_the_directional_derivative() -> None:
# d/dt f(z + t d) at t = 0 equals 2 Re <g(z), d>; check with a central difference.
rng = random.Random(1)
n = 5
a = gaussian_design(rng, 30, n)
y = measure(a, unit_signal(rng, n))
for _ in range(5):
z = unit_signal(rng, n)
d = unit_signal(rng, n)
h = 1e-5
plus = loss(a, y, [u + h * v for u, v in zip(z, d)])
minus = loss(a, y, [u - h * v for u, v in zip(z, d)])
numeric = (plus - minus) / (2 * h)
exact = 2.0 * inner(wirtinger_gradient(a, y, z), d).real
assert abs(numeric - exact) < 1e-7 * max(1.0, abs(exact))
def test_signal_is_a_zero_and_a_stationary_point() -> None:
rng = random.Random(2)
x = unit_signal(rng, 6)
a = gaussian_design(rng, 40, 6)
y = measure(a, x)
assert loss(a, y, x) < 1e-28
assert norm(wirtinger_gradient(a, y, x)) < 1e-14
def test_loss_ignores_a_global_phase() -> None:
rng = random.Random(3)
x = unit_signal(rng, 4)
a = gaussian_design(rng, 20, 4)
y = measure(a, x)
z = unit_signal(rng, 4)
turned = [cmath.exp(1.1j) * v for v in z]
assert abs(loss(a, y, z) - loss(a, y, turned)) < 1e-12
assert abs(dist(z, x) - dist(turned, x)) < 1e-12
def test_step_size_schedule() -> None:
assert abs(step_size(1) - (1.0 - math.exp(-1.0 / 330.0))) < 1e-15
assert step_size(1) < 0.0031
assert step_size(10000) == 0.4
assert step_size(10000, mu_max=0.3) == 0.3
increasing = [step_size(t) for t in range(1, 400)]
assert all(u <= v for u, v in zip(increasing, increasing[1:]))
def test_small_step_decreases_the_loss() -> None:
rng = random.Random(4)
n = 6
a = gaussian_design(rng, 48, n)
y = measure(a, unit_signal(rng, n))
z = spectral_start(a, y)
rec = []
wirtinger_flow(a, y, 30, z0=z, record=rec)
values = [loss(a, y, w) for w in rec]
assert all(v <= u for u, v in zip(values, values[1:]))
def test_recovery_measurement() -> None:
# Measurement, not a theorem: n = 8, m = 8 n, complex Gaussian design, mu_max = 0.3.
n, m = 8, 64
for seed in range(1, 4):
rng = random.Random(seed)
x = unit_signal(rng, n)
a = gaussian_design(rng, m, n)
y = measure(a, x)
z0 = spectral_start(a, y)
z = wirtinger_flow(a, y, 500, z0=z0, mu_max=0.3)
assert dist(z0, x) > 0.3
assert dist(z, x) < 1e-8
History
Candès, Li and Soltanolkotabi put the method on arXiv in 2014 and published it in 2015. The proof shows convergence to the signal from a start that can be computed, for a method that works on vectors of length and not on matrices as PhaseLift does. Their paper also gives a variant for coded diffraction patterns, and recovers large images from such data. Chen and Candès (2017) added truncation to the start and the gradient and showed that a number of measurements of the order of is enough.
References
- Emmanuel J. Candès, Xiaodong Li and Mahdi Soltanolkotabi, Phase retrieval via Wirtinger flow, theory and algorithms, IEEE Transactions on Information Theory 61(4), 2015, 1985 to 2007, equations (2.1), (2.2) and (2.5) (the loss, the update and the step schedule), Theorem 3.3 (Gaussian model), Sections 4.2 and 4.3 (experiments), Theorem 5.1 (coded diffraction model), Section 6 (Wirtinger derivatives), Condition 7.9 and Lemma 7.10 (the regularity condition) (preprint arXiv 1407.1065)
- Yuxin Chen and Emmanuel J. Candès, Solving random quadratic systems of equations is nearly as easy as solving linear systems, Communications on Pure and Applied Mathematics 70(5), 2017, 822 to 883, the truncated Wirtinger flow and its guarantee for a number of equations of the order of n (preprint arXiv 1505.05114)
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 E17F69 Edit this page History Report an error Markdown