Algorithm Search⌘K

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.

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
Properties
deterministicnot exactnot in placeoffline
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 yr=∣ar∗x∣2y_r = |a_r^* x|^2 for r=1,…,mr = 1, \dots, m, and the method minimizes the squared misfit

f(z)=12m∑r=1m(∣ar∗z∣2−yr)2f(z) = \frac{1}{2m} \sum_{r=1}^m \bigl(|a_r^* z|^2 - y_r\bigr)^2

by gradient steps. The function ff 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 nlog⁡nn \log n 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 mm vectors ar∈Cna_r \in \mathbb{C}^n and the values yr=∣ar∗x∣2y_r = |a_r^* x|^2 for an unknown xx. The output is a zz with a small dist⁡(z,x)=min⁡φ∥z−eiφx∥\operatorname{dist}(z, x) = \min_\varphi \|z - e^{i\varphi} x\|. The data are the same for xx and eiφxe^{i\varphi} x, so this is the right measure of error. In the Gaussian model of the theory, the entries of ara_r are independent N(0,1/2)+i N(0,1/2)\mathcal{N}(0, 1/2) + i\,\mathcal{N}(0, 1/2).

The algorithm

  1. WIRTINGER-FLOW(a₁, …, a_m, y, K, τ₀, μ_max)
  2. 1z ← SPECTRAL-INIT(a₁, …, a_m, y)
  3. 2s ← ‖z‖²
  4. 3for τ ← 1 to K do
  5. 4μ ← min(1 − exp(−τ/τ₀), μ_max)
  6. 5g ← (1/m) Σ_r (|a_r* z|² − y_r) a_r (a_r* z)
  7. 6z ← z − (μ / s) g
  8. 7return z

Line L1 is the top eigenvector of 1m∑ryrarar∗\frac1m \sum_r y_r a_r a_r^*, scaled to the estimate λ2=n∑ryr/∑r∥ar∥2\lambda^2 = n \sum_r y_r / \sum_r \|a_r\|^2 of ∥x∥2\|x\|^2. Line L5 is the Wirtinger gradient ∂f/∂zˉ\partial f / \partial \bar z. It needs one pass to form the values ar∗za_r^* z and one pass to add up the vectors. Line L6 divides the step by ∥z0∥2\|z_0\|^2, which makes the method the same for every scale of xx. Line L4 is the schedule of the authors: small steps first, then the cap μmax⁡\mu_{\max}. They suggest τ0≈330\tau_0 \approx 330 and μmax⁡≈0.4\mu_{\max} \approx 0.4 in (2.5), and they used 0.20.2 in their experiments with Gaussian vectors. The theorem is for a constant step μ≤c1/n\mu \le c_1 / n.

Example

Take n=8n = 8, m=64m = 64, a unit vector x∈C8x \in \mathbb{C}^8 and complex Gaussian vectors, all from seed 1. The table gives dist⁡(zτ,x)\operatorname{dist}(z_\tau, x) for two caps of the step, with τ0=330\tau_0 = 330 (measurements of the implementation):

step τ\tau 0 50 100 200 300 500 1000
μmax⁡=0.3\mu_{\max} = 0.3 0.67 0.17 0.0099 1.7e-5 3.0e-8 9.3e-14 1.9e-16
μmax⁡=0.4\mu_{\max} = 0.4 0.67 0.17 0.0099 4.7e-6 9.1e-10 1.0e-7 0.078

The spectral start is 0.670.67 from xx. With the cap 0.30.3, 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 0.40.4, it falls faster at first. Then the error grows again, and the iterates stay at a distance of 0.0780.078 up to step 2500.

The reason is the curvature at the solution. Near xx the method is gradient descent with the step μ/(2∥z0∥2)\mu / (2\|z_0\|^2) on the real and imaginary parts, and xx is a stable fixed point only if this step is below 2/λ2 / \lambda, where λ\lambda is the largest eigenvalue of the real Hessian of ff at xx. That is μ<4∥z0∥2/λ\mu < 4\|z_0\|^2 / \lambda. For seed 1 this limit is 0.3870.387, so the cap 0.40.4 is too large, and the rounding errors grow. Over seeds 1 to 5 the limit was 0.350.35 to 0.450.45. With the cap 0.40.4, seeds 1 and 4 failed. With the cap 0.30.3, all five reached a distance below 10−1510^{-15} by step 1000. For large mm the Hessian is close to its mean, whose largest eigenvalue is 8∥x∥28\|x\|^2, and the limit is near 0.50.5.

Correctness

The proof page shows these facts.

  • The gradient. For a real tt, ddtf(z+td)=2Re⁡⟨g(z),d⟩\frac{d}{dt} f(z + t d) = 2 \operatorname{Re}\langle g(z), d \rangle at t=0t = 0. So −g-g is the steepest descent direction, and line L6 is gradient descent on R2n\mathbb{R}^{2n}.
  • Solutions and stationary points. f≥0f \ge 0, and f(z)=0f(z) = 0 exactly when zz fits all the data. Every eiφxe^{i\varphi} x is a zero of ff and of gg. The point z=0z = 0 is also a stationary point, but not a solution, so the start matters.
  • Descent. A small enough step decreases ff.
  • Linear convergence. If Re⁡⟨g(z),z−eiφ(z)x⟩≥1αdist⁡2(z,x)+1β∥g(z)∥2\operatorname{Re}\langle g(z), z - e^{i\varphi(z)} x \rangle \ge \frac1\alpha \operatorname{dist}^2(z, x) + \frac1\beta \|g(z)\|^2 near the solutions, then every step μ≤2/β\mu \le 2/\beta shrinks dist⁡2\operatorname{dist}^2 by the factor 1−2μ/α1 - 2\mu/\alpha.

Candès, Li and Soltanolkotabi (2015, Theorem 3.3) show that for m≥c0 nlog⁡nm \ge c_0\, n \log n Gaussian vectors this condition holds and the spectral start is within 18∥x∥\frac18\|x\| of the signal, with high probability. With a constant step μ≤c1/n\mu \le c_1 / n, this gives

dist⁡(zτ,x)≤18(1−μ4)τ/2∥x∥.\operatorname{dist}(z_\tau, x) \le \frac18 \Bigl(1 - \frac\mu4\Bigr)^{\tau/2} \|x\| .

This theorem is cited, not proved here.

Proof: The Wirtinger gradient, the stationary points, and linear convergence under a regularity conditionfull

Vectors are in Cn\mathbb{C}^n with ⟨u,v⟩=u∗v\langle u, v \rangle = u^* v. The data are yr=∣ar∗x∣2y_r = |a_r^* x|^2 for r=1,…,mr = 1, \dots, m. Write pr(z)=ar∗zp_r(z) = a_r^* z and er(z)=∣pr(z)∣2−yre_r(z) = |p_r(z)|^2 - y_r. The loss and the step direction are

f(z)=12m∑r=1mer(z)2,g(z)=1m∑r=1mer(z) ar pr(z).f(z) = \frac{1}{2m} \sum_{r=1}^m e_r(z)^2, \qquad g(z) = \frac1m \sum_{r=1}^m e_r(z)\, a_r\, p_r(z).

The algorithm takes zτ=zτ−1−(μτ/∥z0∥2) g(zτ−1)z_\tau = z_{\tau-1} - (\mu_\tau / \|z_0\|^2)\, g(z_{\tau-1}) (line L6). The claim of correctness has four parts. The step direction is the steepest descent direction of ff (Lemma 1). The solutions are exactly the zeros of ff, and they are stationary points (Lemma 2). A small step decreases ff (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 dist⁡(z,x)=min⁡φ∥z−eiφx∥\operatorname{dist}(z, x) = \min_\varphi \|z - e^{i\varphi} x\|. The minimum is at eiφ(z)=c/∣c∣e^{i\varphi(z)} = c / |c| with c=x∗zc = x^* z (or any φ\varphi if c=0c = 0), because ∥z−eiφx∥2=∥z∥2+∥x∥2−2Re⁡(e−iφc)\|z - e^{i\varphi} x\|^2 = \|z\|^2 + \|x\|^2 - 2 \operatorname{Re}(e^{-i\varphi} c).

Lemma 1 (the gradient). For every zz, every d∈Cnd \in \mathbb{C}^n and real tt,

ddtf(z+td)∣t=0=2Re⁡⟨g(z),d⟩.\frac{d}{dt} f(z + t d) \Big|_{t = 0} = 2 \operatorname{Re} \langle g(z), d \rangle .

Proof. With p=pr(z)p = p_r(z) and b=ar∗db = a_r^* d, we have ∣p+tb∣2=∣p∣2+2tRe⁡(pˉb)+t2∣b∣2|p + t b|^2 = |p|^2 + 2t \operatorname{Re}(\bar p b) + t^2 |b|^2. So the derivative of er(z+td)e_r(z + td) at t=0t = 0 is 2Re⁡(pˉb)2 \operatorname{Re}(\bar p b), and the derivative of ff is

12m∑r2er⋅2Re⁡(pr‾ ar∗d)=2m∑rerRe⁡(pr‾ ar∗d).\frac{1}{2m} \sum_r 2 e_r \cdot 2 \operatorname{Re}(\overline{p_r}\, a_r^* d) = \frac{2}{m} \sum_r e_r \operatorname{Re}(\overline{p_r}\, a_r^* d).

On the other side, g∗=1m∑rerpr‾ ar∗g^* = \frac1m \sum_r e_r \overline{p_r}\, a_r^* because ere_r is real, so ⟨g,d⟩=1m∑rerpr‾ ar∗d\langle g, d \rangle = \frac1m \sum_r e_r \overline{p_r}\, a_r^* d. Twice its real part is the same sum. □\square

So if Cn\mathbb{C}^n is read as R2n\mathbb{R}^{2n} with the inner product Re⁡⟨u,v⟩\operatorname{Re} \langle u, v \rangle, the ordinary gradient of ff is 2g2g. This gg is the Wirtinger derivative ∂f/∂zˉ\partial f / \partial \bar z (Candès, Li and Soltanolkotabi 2015, Section 6). Among the directions dd with ∥d∥=1\|d\| = 1, the derivative 2Re⁡⟨g,d⟩2 \operatorname{Re}\langle g, d \rangle is smallest at d=−g/∥g∥d = -g / \|g\| by the Cauchy-Schwarz inequality. So line L6 is gradient descent on R2n\mathbb{R}^{2n} with the step μτ/(2∥z0∥2)\mu_\tau / (2\|z_0\|^2).

Lemma 2 (solutions and stationary points). f(z)≥0f(z) \ge 0 for all zz, and f(z)=0f(z) = 0 exactly when ∣ar∗z∣2=yr|a_r^* z|^2 = y_r for all rr. In particular f(eiφx)=0f(e^{i\varphi} x) = 0 and g(eiφx)=0g(e^{i\varphi} x) = 0 for all real φ\varphi. Also f(eiφz)=f(z)f(e^{i\varphi} z) = f(z) and g(eiφz)=eiφg(z)g(e^{i\varphi} z) = e^{i\varphi} g(z). Finally g(0)=0g(0) = 0.

Proof. ff is a sum of squares, so f≥0f \ge 0 with equality exactly when every er=0e_r = 0. For z=eiφxz = e^{i\varphi} x each er=∣eiφar∗x∣2−yr=0e_r = |e^{i\varphi} a_r^* x|^2 - y_r = 0, so f=0f = 0 and every term of gg is 00. Replacing zz by eiφze^{i\varphi} z does not change ere_r and multiplies prp_r by eiφe^{i\varphi}, which gives the two identities. At z=0z = 0 every pr=0p_r = 0. □\square

So the method can only find xx up to a global phase, and the error must be measured by dist⁡\operatorname{dist}. The point z=0z = 0 is a stationary point with f(0)=12m∑ryr2>0f(0) = \frac{1}{2m} \sum_r y_r^2 > 0 when x≠0x \neq 0, so a stationary point need not be a solution. This is one reason why the start matters.

Lemma 3 (a small step decreases ff). If g(z)≠0g(z) \neq 0, there is t∗>0t^* > 0 such that f(z−tg(z))<f(z)f(z - t g(z)) < f(z) for 0<t<t∗0 < t < t^*. If the second derivative of ϕ(t)=f(z−tg(z))\phi(t) = f(z - t g(z)) is at most LL on [0,s][0, s], then f(z−sg(z))≤f(z)−2s∥g(z)∥2+12Ls2f(z - s g(z)) \le f(z) - 2 s \|g(z)\|^2 + \frac12 L s^2.

Proof. By Lemma 1 with d=−gd = -g, ϕ′(0)=−2∥g∥2<0\phi'(0) = -2\|g\|^2 < 0. The function ϕ\phi is a polynomial of degree at most 44 in tt, so it is smooth, and ϕ(t)<ϕ(0)\phi(t) < \phi(0) for all small t>0t > 0. The second claim is Taylor's theorem with the remainder 12ϕ′′(ξ)s2\frac12 \phi''(\xi) s^2 for some ξ∈[0,s]\xi \in [0, s]. □\square

So with LL a bound for ϕ′′\phi'', every step s<4∥g∥2/Ls < 4\|g\|^2 / L decreases ff. The function ff is a quartic, so LL grows with ∥z∥\|z\|; a step that is too large can increase ff, 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 ∇f(z)=g(z)\nabla f(z) = g(z), let E={z:dist⁡(z,x)≤ε}E = \{z : \operatorname{dist}(z, x) \le \varepsilon\}, and let α,β>0\alpha, \beta > 0 be such that for all z∈Ez \in E

Re⁡⟨g(z),z−eiφ(z)x⟩≥1αdist⁡2(z,x)+1β∥g(z)∥2.(RC)\operatorname{Re} \langle g(z), z - e^{i\varphi(z)} x \rangle \ge \frac1\alpha \operatorname{dist}^2(z, x) + \frac1\beta \|g(z)\|^2 . \tag{RC}

If z∈Ez \in E and 0<μ≤2/β0 < \mu \le 2/\beta, then z+=z−μg(z)z^+ = z - \mu g(z) has dist⁡2(z+,x)≤(1−2μ/α)dist⁡2(z,x)\operatorname{dist}^2(z^+, x) \le (1 - 2\mu/\alpha)\operatorname{dist}^2(z, x). So from any z0∈Ez_0 \in E the iterates stay in EE and dist⁡2(zτ,x)≤(1−2μ/α)τdist⁡2(z0,x)\operatorname{dist}^2(z_\tau, x) \le (1 - 2\mu/\alpha)^\tau \operatorname{dist}^2(z_0, x).

Proof. Put h=z−eiφ(z)xh = z - e^{i\varphi(z)} x, so ∥h∥=dist⁡(z,x)\|h\| = \operatorname{dist}(z, x). Then

∥z+−eiφ(z)x∥2=∥h−μg∥2=∥h∥2−2μRe⁡⟨g,h⟩+μ2∥g∥2.\|z^+ - e^{i\varphi(z)} x\|^2 = \|h - \mu g\|^2 = \|h\|^2 - 2\mu \operatorname{Re}\langle g, h \rangle + \mu^2 \|g\|^2 .

By (RC) this is at most ∥h∥2−2μα∥h∥2−2μβ∥g∥2+μ2∥g∥2\|h\|^2 - \frac{2\mu}{\alpha}\|h\|^2 - \frac{2\mu}{\beta}\|g\|^2 + \mu^2\|g\|^2. The last two terms add to μ(μ−2/β)∥g∥2≤0\mu (\mu - 2/\beta) \|g\|^2 \le 0. The distance of z+z^+ is a minimum over all phases, so it is at most the norm on the left side. So dist⁡2(z+,x)≤(1−2μ/α)dist⁡2(z,x)≤ε2\operatorname{dist}^2(z^+, x) \le (1 - 2\mu/\alpha) \operatorname{dist}^2(z, x) \le \varepsilon^2, and z+∈Ez^+ \in E. Induction on τ\tau gives the rest. □\square

The factor 1−2μ/α1 - 2\mu/\alpha is not negative: (RC) and the Cauchy-Schwarz inequality give 1α∥h∥2+1β∥g∥2≤∥g∥∥h∥\frac1\alpha \|h\|^2 + \frac1\beta \|g\|^2 \le \|g\| \|h\|, and the inequality of arithmetic and geometric means gives 1α∥h∥2+1β∥g∥2≥2αβ∥g∥∥h∥\frac1\alpha \|h\|^2 + \frac1\beta \|g\|^2 \ge \frac{2}{\sqrt{\alpha\beta}} \|g\| \|h\|. So αβ≥4\alpha \beta \ge 4 when (RC) holds with g≠0g \neq 0, and 2μ/α≤4/(αβ)≤12\mu/\alpha \le 4/(\alpha\beta) \le 1. 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 ara_r with independent entries N(0,1/2)+i N(0,1/2)\mathcal{N}(0, 1/2) + i\,\mathcal{N}(0, 1/2) and m≥c0 nlog⁡nm \ge c_0\, n \log n. With probability at least 1−10e−γn−8/n21 - 10 e^{-\gamma n} - 8/n^2 the spectral start has dist⁡(z0,x)≤18∥x∥\operatorname{dist}(z_0, x) \le \frac18 \|x\|. For a constant μτ=μ≤c1/n\mu_\tau = \mu \le c_1 / n there is an event of probability at least 1−13e−γn−me−1.5m−8/n21 - 13 e^{-\gamma n} - m e^{-1.5 m} - 8/n^2 on which every z0z_0 with that bound gives

dist⁡(zτ,x)≤18(1−μ4)τ/2∥x∥.\operatorname{dist}(z_\tau, x) \le \frac18 \Bigl(1 - \frac\mu4\Bigr)^{\tau/2} \|x\| .

Here c0c_0, c1c_1 and γ\gamma are numerical constants. Their proof shows that (RC) holds on EE with ε=18∥x∥\varepsilon = \frac18 \|x\| and suitable α\alpha and β\beta, 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 μ≤c1/n\mu \le c_1 / n. The schedule μτ=min⁡(1−e−τ/τ0,μmax⁡)\mu_\tau = \min(1 - e^{-\tau/\tau_0}, \mu_{\max}) that the implementation uses is a tuned choice, and it has no proof. With μmax⁡=0.4\mu_{\max} = 0.4 and n=8n = 8 the iterates can leave the solution again (see the example on the main page). The tests measure the recovery on fixed seeds with μmax⁡=0.3\mu_{\max} = 0.3 and do not check a theorem there.

Complexity

One step costs O(mn)O(m n) for general vectors: two passes over the mm vectors of length nn. KK steps cost O(Kmn)O(K m n), and the extra space is O(n)O(n) for zz and gg. With μ=c1/n\mu = c_1 / n, the theorem needs O(nlog⁡(1/ε))O(n \log(1/\varepsilon)) steps for the accuracy ε\varepsilon, so O(mn2log⁡(1/ε))O(m n^2 \log(1/\varepsilon)) in total. For coded diffraction patterns with LL masks, m=Lnm = L n, and the products with the ara_r are fast Fourier transforms. One step then costs O(Lnlog⁡n)O(L n \log n). Theorem 5.1 of the same paper gives a constant step there, with L≥c0(log⁡n)4L \ge c_0 (\log n)^4 patterns.

Properties

  • Up to a global phase. No method can do better with these data.
  • Nonconvex. ff is a quartic with stationary points that are not solutions, such as z=0z = 0. The guarantee depends on the start and on random vectors.
  • Linear convergence near the signal, in theory with a step of order 1/n1/n for Gaussian vectors.
  • Deterministic once the start of the power iteration is fixed.
  • Simple steps. Only products with the ara_r and ar∗a_r^*; no matrix of size n×nn \times n 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 nn, which removes the log⁡n\log n 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 ∣ar∗z∣|a_r^* z| 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 rr per step.
  • Convex relaxation. PhaseLift solves a semidefinite program in place of the nonconvex problem. It needs order nn measurements but works with n×nn \times n 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 4.5n4.5 n Gaussian measurements were enough for exact recovery with high probability in their trials with n=128n = 128 (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 dist⁡\operatorname{dist}, not with ∥z−x∥\|z - x\|.
  • A step that is too large. The example shows a cap of 0.40.4 that loses a solution it had found to 10−910^{-9}. The safe step depends on the curvature at xx, which changes with mm and the seed. If the error grows again, lower μmax⁡\mu_{\max}.
  • A bad start. From a random start the method can stop at a stationary point that is not a solution, such as near z=0z = 0.
  • Too few measurements. With fewer than 2n2n real values, a signal in Cn\mathbb{C}^n cannot be determined. For a small multiple of nn 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.

wirtinger_flow.pyI0RawGitHub
# 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 nn and not on n×nn \times n 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 nn is enough.

References

  1. 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)
  2. 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.

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
  • at least three sources
  • a scene preset for the example