Wirtinger flow: phaseless measurements, objective and Wirtinger gradient, spectral initialization, phase distance, Gaussian and coded diffraction models, Hessian, regularity condition
DefinitionWirtingerFlow_BasicObjects of Sections 2-7 of Candès, Li and Soltanolkotabi (2015).
- Signals and samples (eq. 1.1). Signals carry the Euclidean norm and the inner product . Given sampling vectors , indexed by a finite set of size , the phaseless samples are .
- Objective and Wirtinger gradient (eqs. 2.1, 2.2; Section 7.2). The objective is , and its Wirtinger gradient is
- Distance (Definition 3.2). . A minimising phase is written .
- Iterations. The gradient iteration of Lemma 7.10 is . The Wirtinger flow with constant learning parameter (eq. 2.2) is .
- Spectral initialization (Algorithm 1, Theorem 3.3). . An initial estimate is , where is a unit eigenvector of for its largest eigenvalue.
- Regularity condition (Condition 7.9). holds if, for every with and every minimising phase ,
where uses the data . 7. Hessian (Sections 6, 7.2). In conjugate coordinates,
The matrix of Lemma 7.1 is . The stacked vector is written . is the operator norm, and is the sample covariance. 8. Gaussian model (Definition 3.1). The vectors are i.i.d., and each has i.i.d. coordinates with law (independent real and imaginary parts). 9. Coded diffraction model (Section 4.1, eqs. 4.1-4.2). A law of a complex random variable is admissible with bound if is symmetric, , , and . The patterns are i.i.d. with i.i.d. entries of law . The sampling vectors are for and , so and .
Formalization Note The minimum in Definition 3.2 is written as an infimum over the compact interval , where it is attained. Since need not be unique (the phase is unique once , but on the endpoints and give the same phase, so itself is unique only modulo ), is required for every minimising phase. The leading eigenvector is characterised by comparison with every real eigenvalue, which is enough because is Hermitian. A sample of either model is the array of coordinates of the random vectors, and its law is a finite product measure.
import Mathlib
/-!
Candès, Li and Soltanolkotabi, *Phase Retrieval via Wirtinger Flow: Theory and Algorithms*,
arXiv:1407.1065v3 (2015): the phaseless measurements of eq. (1.1), the objective and Wirtinger
gradient of eqs. (2.1)-(2.2) and Section 7.2, the spectral initialization of Algorithm 1, the
distance of Definition 3.2, the Gaussian model of Definition 3.1, the admissible coded diffraction
model of Section 4.1 (eqs. (4.1)-(4.2)), the complex Hessian of Sections 6 and 7.2 with its
expectation from Lemma 7.1, and the regularity condition of Condition 7.9.
-/
open MeasureTheory ProbabilityTheory Complex
noncomputable section
namespace WirtingerFlow
/-- Signals and sampling vectors live in `ℂⁿ` with its Euclidean norm and the inner product
`⟨u, v⟩ = u^* v` (conjugate-linear in the first argument), as throughout the paper. -/
abbrev Sig (n : ℕ) := EuclideanSpace ℂ (Fin n)
/-- A coordinate vector `(v(0), …, v(n-1))` viewed as an element of `ℂⁿ`. -/
def toSig {n : ℕ} (v : Fin n → ℂ) : Sig n := WithLp.toLp 2 v
variable {R : Type*} [Fintype R] {n : ℕ}
/-- Eq. (1.1): the phaseless samples `y_r = |⟨a_r, x⟩|² = |a_r^* x|²`, indexed by a finite set of
`m = |R|` sampling vectors `a_r`. -/
def meas (a : R → Sig n) (x : Sig n) (r : R) : ℝ := ‖inner ℂ (a r) x‖ ^ 2
/-- Eq. (2.1) with the quadratic loss `ℓ(x, y) = (x - y)²`:
`f(z) = (1/2m) ∑_r (y_r - |a_r^* z|²)²`. -/
def loss (a : R → Sig n) (y : R → ℝ) (z : Sig n) : ℝ :=
1 / (2 * (Fintype.card R : ℝ)) * ∑ r, (y r - ‖inner ℂ (a r) z‖ ^ 2) ^ 2
/-- Eq. (2.2) and Section 7.2: the Wirtinger gradient
`∇f(z) = (1/m) ∑_r (|a_r^* z|² - y_r) (a_r a_r^*) z`. -/
def grad (a : R → Sig n) (y : R → ℝ) (z : Sig n) : Sig n :=
((1 / (Fintype.card R : ℝ) : ℝ) : ℂ) •
∑ r, ((((‖inner ℂ (a r) z‖ ^ 2 - y r : ℝ)) : ℂ) * inner ℂ (a r) z) • a r
/-- Definition 3.2: `dist(z, x) = min_{φ ∈ [0, 2π]} ‖z - e^{iφ} x‖` (the minimum is attained, so it
is written as an infimum over the compact interval). -/
def phaseDist (z x : Sig n) : ℝ :=
sInf ((fun φ : ℝ => ‖z - Complex.exp ((φ : ℂ) * I) • x‖) '' Set.Icc 0 (2 * Real.pi))
/-- Section 7.1: `φ` is a phase `φ(z) ∈ [0, 2π]` attaining `dist(z, x) = ‖z - e^{iφ(z)} x‖`. -/
def IsMinPhase (z x : Sig n) (φ : ℝ) : Prop :=
φ ∈ Set.Icc 0 (2 * Real.pi) ∧ ‖z - Complex.exp ((φ : ℂ) * I) • x‖ = phaseDist z x
/-- Lemma 7.10: the gradient iteration `z_{τ+1} = z_τ - μ ∇f(z_τ)` started at `z_0`. -/
def gdSeq (a : R → Sig n) (y : R → ℝ) (μ : ℝ) (z0 : Sig n) : ℕ → Sig n
| 0 => z0
| τ + 1 => gdSeq a y μ z0 τ - (μ : ℂ) • grad a y (gdSeq a y μ z0 τ)
/-- Eq. (2.2) with a constant learning parameter `μ_τ = μ`:
the Wirtinger flow iterates `z_{τ+1} = z_τ - (μ / ‖z_0‖²) ∇f(z_τ)`. -/
def wfSeq (a : R → Sig n) (y : R → ℝ) (μ : ℝ) (z0 : Sig n) : ℕ → Sig n :=
gdSeq a y (μ / ‖z0‖ ^ 2) z0
/-- Algorithm 1: the matrix `Y = (1/m) ∑_r y_r a_r a_r^*`, acting on `v` as
`Y v = (1/m) ∑_r y_r (a_r^* v) a_r`. -/
def specOp (a : R → Sig n) (y : R → ℝ) (v : Sig n) : Sig n :=
((1 / (Fintype.card R : ℝ) : ℝ) : ℂ) • ∑ r, ((y r : ℂ) * inner ℂ (a r) v) • a r
/-- Algorithm 1: `v` is an eigenvector of `Y` for its largest eigenvalue. Since `Y` is Hermitian
when `y` is real, every eigenvalue is real, so the comparison ranges over real eigenvalues. -/
def IsLeadingEigvec (Y : Sig n → Sig n) (v : Sig n) : Prop :=
v ≠ 0 ∧ ∃ c : ℝ, Y v = (c : ℂ) • v ∧
∀ (c' : ℝ) (w : Sig n), w ≠ 0 → Y w = (c' : ℂ) • w → c' ≤ c
/-- Theorem 3.3: the Wirtinger flow initial estimates, i.e. every leading eigenvector of `Y` of unit
norm rescaled to squared Euclidean norm `m^{-1} ∑_r y_r`. -/
def initSet (a : R → Sig n) (y : R → ℝ) : Set (Sig n) :=
{z | ∃ v : Sig n, IsLeadingEigvec (specOp a y) v ∧ ‖v‖ = 1 ∧
z = ((Real.sqrt ((∑ r, y r) / (Fintype.card R : ℝ)) : ℝ) : ℂ) • v}
/-- Condition 7.9, `RC(α, β, ε)` for the objective `f` with data `y = |A x|²`: for every `z` with
`dist(z, x) ≤ ε` and every phase `φ(z)` attaining `dist(z, x)`,
`Re ⟨∇f(z), z - x e^{iφ(z)}⟩ ≥ (1/α) dist²(z, x) + (1/β) ‖∇f(z)‖²`. -/
def RegCond (a : R → Sig n) (x : Sig n) (α β ε : ℝ) : Prop :=
∀ z : Sig n, phaseDist z x ≤ ε → ∀ φ : ℝ, IsMinPhase z x φ →
1 / α * phaseDist z x ^ 2 + 1 / β * ‖grad a (meas a x) z‖ ^ 2 ≤
(inner ℂ (grad a (meas a x) z) (z - Complex.exp ((φ : ℂ) * I) • x)).re
/-- Sections 6 and 7.2: the complex Hessian of `f` in conjugate coordinates,
`∇²f(z) = (1/m) ∑_r [[(2|a_r^* z|² - y_r) a_r a_r^*, (a_r^* z)² a_r a_r^T],
[(conj(a_r^* z))² ā_r a_r^*, (2|a_r^* z|² - y_r) ā_r a_r^T]]`, a `2n × 2n` matrix. -/
def hess (a : R → Sig n) (y : R → ℝ) (z : Sig n) : Matrix (Fin n ⊕ Fin n) (Fin n ⊕ Fin n) ℂ :=
((1 / (Fintype.card R : ℝ) : ℝ) : ℂ) • ∑ r, Matrix.fromBlocks
((((2 * ‖inner ℂ (a r) z‖ ^ 2 - y r : ℝ)) : ℂ) •
Matrix.vecMulVec (WithLp.ofLp (a r)) (star (WithLp.ofLp (a r))))
((inner ℂ (a r) z) ^ 2 • Matrix.vecMulVec (WithLp.ofLp (a r)) (WithLp.ofLp (a r)))
((starRingEnd ℂ (inner ℂ (a r) z)) ^ 2 •
Matrix.vecMulVec (star (WithLp.ofLp (a r))) (star (WithLp.ofLp (a r))))
((((2 * ‖inner ℂ (a r) z‖ ^ 2 - y r : ℝ)) : ℂ) •
Matrix.vecMulVec (star (WithLp.ofLp (a r))) (WithLp.ofLp (a r)))
/-- Section 6: the conjugate-coordinate vector `[h; h̄] ∈ ℂ^{2n}`. -/
def stack (h : Sig n) : Fin n ⊕ Fin n → ℂ :=
Sum.elim (WithLp.ofLp h) (star (WithLp.ofLp h))
/-- Lemma 7.1: the matrix
`I_{2n} + (3/2) [x; x̄][x^*, x^T] - (1/2) [x; -x̄][x^*, -x^T]`. -/
def expHess (x : Sig n) : Matrix (Fin n ⊕ Fin n) (Fin n ⊕ Fin n) ℂ :=
1 + (3 / 2 : ℂ) • Matrix.vecMulVec (stack x) (star (stack x)) -
(1 / 2 : ℂ) • Matrix.vecMulVec (Sum.elim (WithLp.ofLp x) (-star (WithLp.ofLp x)))
(star (Sum.elim (WithLp.ofLp x) (-star (WithLp.ofLp x))))
/-- Lemma 7.8: the sample covariance matrix `m^{-1} ∑_r a_r a_r^*`. -/
def covMat (a : R → Sig n) : Matrix (Fin n) (Fin n) ℂ :=
((1 / (Fintype.card R : ℝ) : ℝ) : ℂ) •
∑ r, Matrix.vecMulVec (WithLp.ofLp (a r)) (star (WithLp.ofLp (a r)))
/-- The operator (spectral) norm `‖M‖` of a complex square matrix acting on Euclidean space, used
in Lemmas 7.4 and 7.8. -/
def opNorm {ι : Type*} [Fintype ι] [DecidableEq ι] (M : Matrix ι ι ℂ) : ℝ :=
‖Matrix.toEuclideanCLM (𝕜 := ℂ) M‖
/-- Definition 3.1: the standard complex Gaussian `N(0, 1/2) + i N(0, 1/2)` on `ℂ`. -/
def stdCGauss : Measure ℂ :=
((gaussianReal 0 (1 / 2 : NNReal)).prod (gaussianReal 0 (1 / 2 : NNReal))).map
fun p : ℝ × ℝ => (p.1 : ℂ) + (p.2 : ℂ) * I
/-- Definition 3.1: a sampling vector `a ∼ N(0, I/2) + i N(0, I/2)` in `ℂⁿ`, in coordinates. -/
def cnGauss (n : ℕ) : Measure (Fin n → ℂ) :=
Measure.pi fun _ : Fin n => stdCGauss
/-- Definition 3.1: the Gaussian model, `m` i.i.d. sampling vectors `a_1, …, a_m`; the sample is the
`m × n` array of their coordinates. -/
def gaussModel (m n : ℕ) : Measure (Fin m → Fin n → ℂ) :=
Measure.pi fun _ : Fin m => cnGauss n
/-- The sampling vectors `a_r ∈ ℂⁿ`, `r = 1, …, m`, read off a sample of the Gaussian model. -/
def rows {m : ℕ} (A : Fin m → Fin n → ℂ) : Fin m → Sig n :=
fun r => toSig (A r)
/-- Section 4.1, eq. (4.2): `ν`, the law of a complex random variable `d`, is admissible with bound
`M`: `d` is symmetric (`-d` has the law of `d`), `|d| ≤ M`, `E d = 0`, `E d² = 0` and
`E|d|⁴ = 2 (E|d|²)²`. -/
def IsAdmissible (ν : Measure ℂ) (M : ℝ) : Prop :=
IsProbabilityMeasure ν ∧ ν.map (fun d : ℂ => -d) = ν ∧ (∀ᵐ d ∂ν, ‖d‖ ≤ M) ∧
∫ d, d ∂ν = 0 ∧ ∫ d, d ^ 2 ∂ν = 0 ∧ ∫ d, ‖d‖ ^ 4 ∂ν = 2 * (∫ d, ‖d‖ ^ 2 ∂ν) ^ 2
/-- Section 4.1: `L` i.i.d. modulation patterns `d_ℓ = (d_ℓ(0), …, d_ℓ(n-1))` with i.i.d. entries
of law `ν`. -/
def cdpModel (ν : Measure ℂ) (L n : ℕ) : Measure (Fin L → Fin n → ℂ) :=
Measure.pi fun _ : Fin L => Measure.pi fun _ : Fin n => ν
/-- Eq. (4.1) and Appendix A: the coded diffraction sampling vectors `a_r = D_ℓ f_k`,
`r = (ℓ, k)`, with entries `a_r(t) = d_ℓ(t) e^{i 2π k t / n}`, so that
`y_r = |∑_t x[t] d̄_ℓ(t) e^{-i 2π k t / n}|² = |a_r^* x|²`. -/
def cdpVecs {L : ℕ} (d : Fin L → Fin n → ℂ) : Fin L × Fin n → Sig n :=
fun r => toSig fun t =>
d r.1 t * Complex.exp (2 * Real.pi * I * (r.2 : ℂ) * (t : ℂ) / (n : ℂ))
end WirtingerFlow
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Signal space (). For a natural number (possibly , in which case the space is the zero space), is , with coordinates indexed by . It carries the Euclidean norm and the inner product
which is conjugate-linear in the first argument and linear in the second. Throughout, denotes in this sense.
Coordinate embedding (). Given any function , is the same tuple regarded as an element of with the Euclidean structure above. Nothing is changed or normalized.
Common setting for the next several definitions. is an arbitrary finite index set and is its cardinality. may be empty, so is allowed. Whenever a formula below contains a factor or , the convention applies when , so that factor (and hence the whole expression) is . The family consists of arbitrary vectors in , and consists of arbitrary real numbers. In particular, is not required to be nonnegative, nor to arise from any signal unless stated.
Measurements (). For sampling vectors in , a signal and an index , the measurement is the real number
Objective (). For and as in the common setting and , the objective is
When , this equals for every .
Gradient (). For , and , the vector is
When , this is the zero vector. This is a definition by explicit formula. No statement is made here about its relation to any derivative of .
Phase distance (). For , define
This is the infimum of the values of a continuous function over the closed interval , so it is attained, and it is always . If , then .
Minimizing phase (). For and a real number , the property holds exactly when both of the following are true:
- ;
- .
Several phases may qualify. For example, if , every does.
Gradient iteration (). Given , , a real step size (of any sign, including ) and a starting point , the sequence is defined recursively by
where is the gradient defined above. The step size is the same at every step.
Wirtinger flow iterates (). Given , , a real number and , the Wirtinger flow sequence is the gradient iteration above with the constant step size :
If , the convention makes the step size , and the sequence is constantly .
Spectral operator (). For and , is the map given by
When , this is the zero map.
Leading eigenvector (). Let be an arbitrary function; it is not assumed linear or Hermitian. A vector is a leading eigenvector of when all of the following hold:
- ;
- there is a real number with ;
- for every real and every nonzero with , we have .
Only real eigenvalues take part in the comparison. Non-real with are neither required nor compared. When , no vector satisfies this property.
Initial estimates (). For and , is the set of all vectors
where ranges over all unit vectors () that are leading eigenvectors (in the sense above) of the spectral operator . Here is the real square root, with the convention for . This set contains every such rescaled eigenvector, including all unit-modulus phase multiples and all vectors in a multi-dimensional top eigenspace. Two degenerate cases:
- When , the set is empty.
- When , is the zero map and the scale factor is , so the set is (provided ).
Regularity condition (). Let be sampling vectors, a signal, and arbitrary real numbers (no sign or nonzero assumptions). Write for the gradient built with the data . Then means the following: for every with , and every satisfying ,
where . Degenerate cases:
- If (respectively ), the corresponding coefficient (respectively ) is .
- Negative or are permitted.
- If , no qualifies, and the condition holds vacuously.
Complex Hessian (). For , and , is the complex matrix, with rows and columns indexed by two copies of (first copy = top/left block), given by
Here is the entrywise conjugate, the plain transpose and . Thus has entries , and has entries . When , this is the zero matrix.
Conjugate stacking (). For , is the vector
whose first block is and whose second block is the entrywise conjugate .
Expected Hessian matrix (). For , with no normalization assumed on (any norm, including ), is the matrix
with the same block indexing as the Hessian. This is a definition of a specific matrix. No statement about any expectation is made here.
Sample covariance (). For , is the matrix
When , this is the zero matrix.
Operator norm (). For a complex square matrix indexed by any finite set , is the operator norm of acting on with the Euclidean norm:
which is the largest singular value of .
Standard complex Gaussian (). This is the probability measure on given by the law of , where and are independent real Gaussian random variables, each with mean and variance . (Technically, it is the pushforward of the product measure under .)
Gaussian vector (). This is the product measure on coordinate tuples under which the coordinates are independent, each with the standard complex Gaussian law above. When , it is the unit mass on the single empty tuple.
Gaussian model (). This is the product measure on complex arrays , with and , under which the rows are independent, each distributed as the Gaussian vector above. Equivalently, all entries are independent standard complex Gaussians.
Rows of a sample (). For an complex array , is the family , where is the -th row regarded as a vector in .
Admissible distribution (). For a measure on and a real number , means that all of the following hold, writing :
- is a probability measure;
- is symmetric: the law of equals ;
- holds -almost surely;
- ;
- (the square, not the modulus squared);
- .
By the almost-sure bound, all these expectations are of bounded variables. No normalization such as is imposed, and is not excluded. The point mass at satisfies every condition for any . If , no is admissible.
Coded diffraction model (). For a measure on (not required here to be a probability measure) and natural numbers , is the product measure on arrays , with and , in which every one of the entries has marginal and all entries are independent.
Coded diffraction sampling vectors (). For an complex array , is the family of vectors , indexed by pairs with and (so vectors), with entries
Consequently,
When or , the index set is empty.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.