NLA-lib Explorer

Girard–Hutchinson trace estimator

Estimate a trace using quadratic forms of random probes.

Definition

Definition (Girard–Hutchinson estimator). For s\ge1 probes \mathbf{g}_1,\ldots,\mathbf{g}_s, estimate the trace by

\widehat t=\frac1s\sum_{i=1}^s\mathbf{g}_i^{\mathsf{H}}\mathbf{A}\mathbf{g}_i.

The standard random estimator uses isotropic probes, such as independent Rademacher or standard Gaussian vectors. Variance and probability guarantees depend on the probe distribution and matrix assumptions.

Lean statement and details
NLAlib.girardHutchinson.{u_2, u_3, u_4} {𝕜 : Type u_2} [RCLike 𝕜] {n : Type u_3} {m : Type u_4}
  [Fintype n] [Fintype m] (A : Matrix n n 𝕜) (Ω : Matrix n m 𝕜) : 𝕜

Full source on GitHub

Copy link

Mathematical guarantees

Theorem (Unbiased trace estimate). For a nonempty collection of isotropic probes, the estimator has expectation

\mathbb{E}[\widehat t]=\operatorname{tr}(\mathbf{A}).

The probes need not be independent for this expectation identity. Independence and distribution-specific assumptions enter the variance and tail guarantees separately.

Lean statement and details

General form: sizes are index types

NLAlib.integral_girardHutchinson.{u_1, u_2, u_3, u_4} {Ω : Type u_1} {mΩ : MeasurableSpace Ω}
  {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {n : Type u_3} {m : Type u_4} [Fintype n] [Fintype m]
  [DecidableEq n] [Nonempty m] {X : Ω → Matrix n m 𝕜}
  (hX : ∀ (j : m), IsIsotropic (fun ω i ↦ X ω i j) μ) (A : Matrix n n 𝕜) :
  ∫ (ω : Ω), girardHutchinson A (X ω) ∂μ = A.trace

Full source on GitHub

Copy link

Further results

Theorem (Girard–Hutchinson: tail bound for sub-Gaussian probes).

If the entries of the real n \times m test matrix \mathbf{\Omega} are independent, each satisfies the sub-Gaussian moment generating function bound with variance proxy c (HasSubgaussianMGF) and has second moment 1, then for every real square \mathbf{B} and every \tau \ge 0, \mathbb{P}\bigl[\lvert \operatorname{tr}\mathbf{B} - \mathsf{girardHutchinson}(\mathbf{B}, \mathbf{\Omega}) \rvert \ge \tau\bigr] \le 2\exp\Bigl(-\frac{1}{196}\min\Bigl( \frac{m\tau^2}{c^2\|\mathbf{B}\|_{\mathsf{F}}^2}, \frac{m\tau}{c\|\mathbf{B}\|_2}\Bigr)\Bigr)\,; the constant is hansonWrightConstant. No symmetry of \mathbf{B} is needed. Junk cases: with no columns (m = 0) the estimate is 0 and the bound is 2; a zero denominator makes its fraction 0, and the bound is again 2. The proof is Hanson–Wright (NLAlib.measureReal_abs_quadForm_sub_integral_ge_le) for m \cdot \mathsf{girardHutchinson}(\mathbf{B}, \mathbf{\Omega}) = \operatorname{vec}(\mathbf{\Omega})^{\mathsf{T}}(\mathbf{I}_m \otimes \mathbf{B}) \operatorname{vec}(\mathbf{\Omega}), whose matrix has squared Frobenius norm m\|\mathbf{B}\|_{\mathsf{F}}^2 and spectral norm \|\mathbf{B}\|_2. [MeyerMuscoMuscoWoodruff2021, Lemma 2 and Appendix A]; there with unspecified constants, in the sample-size form m = O(\log(1/\delta)/\varepsilon^2) for \lvert \cdot \rvert \le \varepsilon\|\mathbf{B}\|_{\mathsf{F}}.

General form: sizes are index types

Lean statement and details
NLAlib.measureReal_abs_trace_sub_girardHutchinson_ge_le.{u_1, u_3, u_4} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {n : Type u_3} {m : Type u_4} [Fintype n] [Fintype m]
  {X : Ω → Matrix n m ℝ} {c : ℝ≥0} (hind : iIndepFun (fun p ω ↦ X ω p.1 p.2) μ)
  (hsub : ∀ (i : n) (j : m), HasSubgaussianMGF (fun ω ↦ X ω i j) c μ)
  (hvar : ∀ (i : n) (j : m), ∫ (ω : Ω), X ω i j ^ 2 ∂μ = 1) (B : Matrix n n ℝ) {τ : ℝ}
  (hτ : 0 ≤ τ) :
  μ.real {ω | τ ≤ |B.trace - girardHutchinson B (X ω)|} ≤
    2 *
      rexp
        (-(hansonWrightConstant *
            min (↑(Fintype.card m) * τ ^ 2 / (↑c ^ 2 * frobNorm B ^ 2))
              (↑(Fintype.card m) * τ / (↑c * specNorm B))))

Full source on GitHub

Copy link

Theorem (The variance of the Girard–Hutchinson estimator).

for m nonempty, independent isotropic probes whose single-probe estimates are square integrable with second moment v about the mean, \mathbb{E}\lvert \operatorname{tr}\mathbf{A} - \mathsf{girardHutchinson}(\mathbf{A}, \mathbf{\Omega})\rvert^2 = \frac{v}{m}\,. Over \mathbb{C} the left side is the variance of the complex estimate; the real variance form is NLAlib.variance_girardHutchinson. [Epperly2023, Variance].

General form: sizes are index types

Lean statement and details
NLAlib.integral_norm_trace_sub_girardHutchinson_sq.{u_1, u_2, u_3, u_4} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {n : Type u_3} {m : Type u_4}
  [Fintype n] [Fintype m] [DecidableEq n] [Nonempty m] {X : Ω → Matrix n m 𝕜}
  (hind : iIndepFun (fun j ω i ↦ X ω i j) μ) (hX : ∀ (j : m), IsIsotropic (fun ω i ↦ X ω i j) μ)
  {A : Matrix n n 𝕜} (hL2 : ∀ (j : m), MemLp (fun ω ↦ quadForm A fun i ↦ X ω i j) 2 μ) {v : ℝ}
  (hv : ∀ (j : m), ∫ (ω : Ω), ‖(quadForm A fun i ↦ X ω i j) - A.trace‖ ^ 2 ∂μ = v) :
  ∫ (ω : Ω), ‖A.trace - girardHutchinson A (X ω)‖ ^ 2 ∂μ = v / ↑(Fintype.card m)

Full source on GitHub

Copy link

Theorem (Girard–Hutchinson variance: real Gaussian probe).

\operatorname{Var}(\mathbf{g}^{\mathsf{T}}\mathbf{A}\mathbf{g}) = 2 \|\mathbf{A}\|_{\mathsf{F}}^2 for a standard Gaussian vector \mathbf{g} and real symmetric \mathbf{A}; any real \mathbf{A} is NLAlib.variance_quadForm_eq_hermitianPart_of_hasLaw_gaussianVector. [Epperly2023, Real-Valued Test Vectors].

Lean statement and details
NLAlib.variance_quadForm_of_hasLaw_gaussianVector.{u_1, u_2} {Ω : Type u_1} {mΩ : MeasurableSpace Ω}
  {μ : Measure Ω} {n : Type u_2} [Fintype n] {g : Ω → n → ℝ} (hg : HasLaw g (gaussianVector n) μ)
  {A : Matrix n n ℝ} (hA : A.IsHermitian) : Var[fun ω ↦ quadForm A (g ω); μ] = 2 * frobNorm A ^ 2

Full source on GitHub

Copy link

Theorem (Girard–Hutchinson variance: Rademacher probe).

\operatorname{Var}(\mathbf{x}^{\mathsf{T}}\mathbf{A}\mathbf{x}) = 2 (\|\mathbf{A}\|_{\mathsf{F}}^2 - \sum_i \mathbf{A}_{i,i}^2) for a vector \mathbf{x} of independent random signs and real symmetric \mathbf{A}; any real \mathbf{A} is NLAlib.variance_quadForm_eq_hermitianPart_of_hasLaw_rademacherVector. Optimality among independent, centred real coordinates of variance one with a common finite fourth moment is NLAlib.variance_quadForm_le_of_hasLaw_rademacherVector. [Epperly2023, Real-Valued Test Vectors].

Lean statement and details
NLAlib.variance_quadForm_of_hasLaw_rademacherVector.{u_1, u_2} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {n : Type u_2} [Fintype n] {x : Ω → n → ℝ}
  (hx : HasLaw x (rademacherVector n) μ) {A : Matrix n n ℝ} (hA : A.IsHermitian) :
  Var[fun ω ↦ quadForm A (x ω); μ] = 2 * (frobNorm A ^ 2 - ∑ i, A i i ^ 2)

Full source on GitHub

Copy link

Theorem (Optimality of Rademacher probes).

(Hutchinson): among real probes with independent coordinates in L^4, each of mean 0, variance 1 and the same fourth moment m_4 = \mathbb{E}[\mathbf{x}_i^4], random signs minimise the variance of the Girard–Hutchinson estimate for every real symmetric \mathbf{A}: \operatorname{Var}(\boldsymbol{\varepsilon}^{\mathsf{T}}\mathbf{A}\boldsymbol{\varepsilon}) \le \operatorname{Var}(\mathbf{x}^{\mathsf{T}}\mathbf{A}\mathbf{x}) for a Rademacher vector \boldsymbol{\varepsilon}, on any probability space. The variance 2\|\mathbf{A}\|_{\mathsf{F}}^2 + (m_4 - 3)\sum_i \mathbf{A}_{i,i}^2 (NLAlib.variance_quadForm_of_isHermitian) is increasing in m_4, and m_4 = \mathbb{E}\mathbf{x}_i^4 \ge (\mathbb{E}\mathbf{x}_i^2)^2 = 1 with equality for signs. Due to Hutchinson; [Epperly2023, Optimality: Independent Vectors with Independent Coordinates].

Lean statement and details
NLAlib.variance_quadForm_le_of_hasLaw_rademacherVector.{u_1, u_2, u_4} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {n : Type u_2} [Fintype n] {Ω' : Type u_4}
  {mΩ' : MeasurableSpace Ω'} {ν : Measure Ω'} {ε : Ω' → n → ℝ}
  (hε : HasLaw ε (rademacherVector n) ν) {x : Ω → n → ℝ} (hind : iIndepFun (fun i ω ↦ x ω i) μ)
  (hL4 : ∀ (i : n), MemLp (fun ω ↦ x ω i) 4 μ) (hmean : ∀ (i : n), ∫ (ω : Ω), x ω i ∂μ = 0)
  (hvar : ∀ (i : n), ∫ (ω : Ω), x ω i ^ 2 ∂μ = 1) {m₄ : ℝ}
  (hm₄ : ∀ (i : n), ∫ (ω : Ω), x ω i ^ 4 ∂μ = m₄) {A : Matrix n n ℝ} (hA : A.IsHermitian) :
  Var[fun ω ↦ quadForm A (ε ω); ν] ≤ Var[fun ω ↦ quadForm A (x ω); μ]

Full source on GitHub

Copy link

Used by other algorithms

Mathematical background

Appears under these tasks