Skip to content

Commit 942869b

Browse files
committed
feat(Probability): characteristic function of a Gaussian distribution (#24289)
Characteristic function and complex moment generating function of Gaussian distributions. Co-authored-by: Thomas Zhu (@hanwenzhu)
1 parent c4ac15d commit 942869b

File tree

2 files changed

+96
-29
lines changed

2 files changed

+96
-29
lines changed

Mathlib/Probability/Distributions/Gaussian.lean

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Copyright (c) 2023 Rémy Degenne. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Lorenzo Luccioli, Rémy Degenne, Alexander Bentkamp
55
-/
6-
import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral
7-
import Mathlib.Probability.Moments.Basic
6+
import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform
7+
import Mathlib.Probability.Moments.ComplexMGF
88

99
/-!
1010
# Gaussian distributions over ℝ
@@ -30,7 +30,7 @@ We define a Gaussian measure over the reals.
3030
3131
-/
3232

33-
open scoped ENNReal NNReal Real
33+
open scoped ENNReal NNReal Real Complex
3434

3535
open MeasureTheory
3636

@@ -162,15 +162,22 @@ lemma gaussianPDF_def (μ : ℝ) (v : ℝ≥0) :
162162
gaussianPDF μ v = fun x ↦ ENNReal.ofReal (gaussianPDFReal μ v x) := rfl
163163

164164
@[simp]
165-
lemma gaussianPDF_zero_var (μ : ℝ) : gaussianPDF μ 0 = 0 := by
166-
ext
167-
simp [gaussianPDF]
165+
lemma gaussianPDF_zero_var (μ : ℝ) : gaussianPDF μ 0 = 0 := by ext; simp [gaussianPDF]
166+
167+
@[simp]
168+
lemma toReal_gaussianPDF {μ : ℝ} {v : ℝ≥0} (x : ℝ) :
169+
(gaussianPDF μ v x).toReal = gaussianPDFReal μ v x := by
170+
rw [gaussianPDF, ENNReal.toReal_ofReal (gaussianPDFReal_nonneg μ v x)]
168171

169172
lemma gaussianPDF_pos (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (x : ℝ) : 0 < gaussianPDF μ v x := by
170173
rw [gaussianPDF, ENNReal.ofReal_pos]
171174
exact gaussianPDFReal_pos _ _ _ hv
172175

173-
@[measurability]
176+
lemma gaussianPDF_lt_top {μ : ℝ} {v : ℝ≥0} {x : ℝ} : gaussianPDF μ v x < ∞ := by simp [gaussianPDF]
177+
178+
lemma gaussianPDF_ne_top {μ : ℝ} {v : ℝ≥0} {x : ℝ} : gaussianPDF μ v x ≠ ∞ := by simp [gaussianPDF]
179+
180+
@[measurability, fun_prop]
174181
lemma measurable_gaussianPDF (μ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDF μ v) :=
175182
(measurable_gaussianPDFReal _ _).ennreal_ofReal
176183

@@ -230,6 +237,13 @@ lemma rnDeriv_gaussianReal (μ : ℝ) (v : ℝ≥0) :
230237
· rw [gaussianReal_of_var_ne_zero _ hv]
231238
exact Measure.rnDeriv_withDensity _ (measurable_gaussianPDF μ v)
232239

240+
lemma integral_gaussianReal_eq_integral_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
241+
{μ : ℝ} {v : ℝ≥0} {f : ℝ → E} (hv : v ≠ 0) :
242+
∫ x, f x ∂(gaussianReal μ v) = ∫ x, gaussianPDFReal μ v x • f x := by
243+
simp [gaussianReal, hv,
244+
integral_withDensity_eq_integral_toReal_smul (measurable_gaussianPDF _ _)
245+
(ae_of_all _ fun _ ↦ gaussianPDF_lt_top)]
246+
233247
section Transformations
234248

235249
variable {μ : ℝ} {v : ℝ≥0}
@@ -347,34 +361,77 @@ lemma gaussianReal_mul_const {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussian
347361

348362
end Transformations
349363

350-
open Measurable Real
364+
section CharacteristicFunction
365+
366+
open Real Complex
351367

352368
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {p : Measure Ω} {μ : ℝ} {v : ℝ≥0} {X : Ω → ℝ}
353369

354-
theorem mgf_gaussianReal (hX : p.map X = gaussianReal μ v) (t : ℝ) :
355-
mgf X p t = exp (μ * t + v * t ^ 2 / 2) := by
370+
/-- The complex moment generating function of a Gaussian distribution with mean `μ` and variance `v`
371+
is given by `z ↦ exp (z * μ + v * z ^ 2 / 2)`. -/
372+
theorem complexMGF_id_gaussianReal (z : ℂ) :
373+
complexMGF id (gaussianReal μ v) z = cexp (z * μ + v * z ^ 2 / 2) := by
356374
by_cases hv : v = 0
357-
· simp only [gaussianReal, hv, ↓reduceIte] at hX
358-
simp [mgf_dirac hX, hv]
359-
calc
360-
mgf X p t = (p.map X)[fun x => exp (t * x)] := by
361-
rw [← mgf_id_map, mgf]
362-
all_goals simp [AEMeasurable.of_map_ne_zero, hX, IsProbabilityMeasure.ne_zero]
363-
_ = ∫ x, exp (t * x) * gaussianPDFReal μ v x := by
364-
simp [hX, gaussianReal_of_var_ne_zero μ hv, gaussianPDF_def, ENNReal.ofReal,
365-
integral_withDensity_eq_integral_smul (measurable_gaussianPDFReal μ v).real_toNNReal,
366-
NNReal.smul_def, gaussianPDFReal_nonneg, mul_comm]
367-
_ = ∫ x, exp (μ * t + v * t ^ 2 / 2) * gaussianPDFReal (μ + v * t) v x := by
368-
simp only [gaussianPDFReal_def, mul_left_comm (exp _), mul_assoc, ← exp_add]
369-
congr with x
370-
field_simp only [mul_left_comm, ← exp_sub, ← exp_add]
371-
ring_nf
372-
_ = exp (μ * t + v * t ^ 2 / 2) := by
373-
rw [integral_mul_left, integral_gaussianPDFReal_eq_one (μ + v * t) hv, mul_one]
374-
375+
· simp [complexMGF, hv]
376+
calc ∫ x, cexp (z * x) ∂gaussianReal μ v
377+
_ = ∫ x, gaussianPDFReal μ v x * cexp (z * x) ∂ℙ := by
378+
simp_rw [integral_gaussianReal_eq_integral_smul hv, Complex.real_smul]
379+
_ = (√(2 * π * v))⁻¹
380+
* ∫ x : ℝ, cexp (-(2 * v)⁻¹ * x ^ 2 + (z + μ / v) * x + -μ ^ 2 / (2 * v)) ∂ℙ := by
381+
unfold gaussianPDFReal
382+
push_cast
383+
simp_rw [mul_assoc, integral_mul_left, ← Complex.exp_add]
384+
congr with x
385+
congr 1
386+
ring
387+
_ = (√(2 * π * v))⁻¹ * (π / - -(2 * v)⁻¹) ^ (1 / 2 : ℂ)
388+
* cexp (-μ ^ 2 / (2 * v) - (z + μ / v) ^ 2 / (4 * -(2 * v)⁻¹)) := by
389+
rw [integral_cexp_quadratic (by simpa using pos_iff_ne_zero.mpr hv), ← mul_assoc]
390+
_ = 1 * cexp (-μ ^ 2 / (2 * v) - (z + μ / v) ^ 2 / (4 * -(2 * v)⁻¹)) := by
391+
congr 1
392+
field_simp [Real.sqrt_eq_rpow]
393+
rw [Complex.ofReal_cpow (by positivity)]
394+
push_cast
395+
ring_nf
396+
_ = cexp (z * μ + v * z ^ 2 / 2) := by
397+
rw [one_mul]
398+
congr 1
399+
have : (v : ℂ) ≠ 0 := by simpa
400+
field_simp
401+
ring
402+
403+
/-- The complex moment generating function of a random variable with Gaussian distribution
404+
with mean `μ` and variance `v` is given by `z ↦ exp (z * μ + v * z ^ 2 / 2)`. -/
405+
theorem complexMGF_gaussianReal (hX : p.map X = gaussianReal μ v) (z : ℂ) :
406+
complexMGF X p z = cexp (z * μ + v * z ^ 2 / 2) := by
407+
have hX_meas : AEMeasurable X p := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
408+
rw [← complexMGF_id_map hX_meas, hX, complexMGF_id_gaussianReal]
409+
410+
/-- The characteristic function of a Gaussian distribution with mean `μ` and variance `v`
411+
is given by `t ↦ exp (t * μ - v * t ^ 2 / 2)`. -/
412+
theorem charFun_gaussianReal (t : ℝ) :
413+
charFun (gaussianReal μ v) t = cexp (t * μ * I - v * t ^ 2 / 2) := by
414+
rw [← complexMGF_id_mul_I, complexMGF_id_gaussianReal]
415+
congr
416+
simp only [mul_pow, I_sq, mul_neg, mul_one, sub_eq_add_neg]
417+
ring_nf
418+
419+
/-- The moment generating function of a random variable with Gaussian distribution
420+
with mean `μ` and variance `v` is given by `t ↦ exp (μ * t + v * t ^ 2 / 2)`. -/
421+
theorem mgf_gaussianReal (hX : p.map X = gaussianReal μ v) (t : ℝ) :
422+
mgf X p t = rexp (μ * t + v * t ^ 2 / 2) := by
423+
suffices (mgf X p t : ℂ) = rexp (μ * t + ↑v * t ^ 2 / 2) from mod_cast this
424+
have hX_meas : AEMeasurable X p := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
425+
rw [← mgf_id_map hX_meas, ← complexMGF_ofReal, hX, complexMGF_id_gaussianReal, mul_comm μ]
426+
norm_cast
427+
428+
/-- The cumulant generating function of a random variable with Gaussian distribution
429+
with mean `μ` and variance `v` is given by `t ↦ μ * t + v * t ^ 2 / 2`. -/
375430
theorem cgf_gaussianReal (hX : p.map X = gaussianReal μ v) (t : ℝ) :
376431
cgf X p t = μ * t + v * t ^ 2 / 2 := by
377-
rw [cgf, mgf_gaussianReal hX t, log_exp]
432+
rw [cgf, mgf_gaussianReal hX t, Real.log_exp]
433+
434+
end CharacteristicFunction
378435

379436
end GaussianReal
380437

Mathlib/Probability/Moments/ComplexMGF.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ lemma re_complexMGF_ofReal' : (fun x : ℝ ↦ (complexMGF X μ x).re) = mgf X
104104
ext x
105105
exact re_complexMGF_ofReal x
106106

107+
lemma complexMGF_id_mul_I {μ : Measure ℝ} (t : ℝ) :
108+
complexMGF id μ (t * I) = charFun μ t := by
109+
simp only [complexMGF, id_eq, charFun, RCLike.inner_apply, conj_trivial, ofReal_mul]
110+
congr with x
111+
ring_nf
112+
113+
lemma complexMGF_mul_I (hX : AEMeasurable X μ) (t : ℝ) :
114+
complexMGF X μ (t * I) = charFun (μ.map X) t := by
115+
rw [← complexMGF_id_map hX, complexMGF_id_mul_I]
116+
107117
section Analytic
108118

109119
/-- For `z : ℂ` with `z.re ∈ interior (integrableExpSet X μ)`, the derivative of the function

0 commit comments

Comments
 (0)