Offline · exact source
Exact Lean source

GaussianAffinity

formalization/Cloning/GaussianAffinity.lean

Source hash: 3319531aa3ee8270f4ec2a7748e095bd03322019e32b7c23f61e635198d9d081

Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.

The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.

Declarations in this module
1import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral
2import Mathlib.MeasureTheory.Integral.Pi
3import Cloning.Main
4import Mathlib.Tactic.FieldSimp
5import Mathlib.Tactic.Ring
6 
7/-!
8# Actual Gaussian density affinities
9 
10The normalized precision-parameter density below has variance `1 / (2*a)`.
11The affinity is a Lebesgue integral, evaluated using Mathlib's Gaussian
12integral and finite-product Fubini theorem, rather than an assumed formula.
13-/
14 
15noncomputable section
16open MeasureTheory Real
17open scoped BigOperators
18namespace Cloning.GaussianAffinity
19 
20/-- Centered normalized Gaussian density with positive precision parameter. -/
21def density (a x : ℝ) : ℝ :=
22  (Real.sqrt a / Real.sqrt Real.pi) * Real.exp (-a * x ^ 2)
23 
24theorem density_nonneg (a x : ℝ) : 0 ≤ density a x := by
25  unfold density
26  positivity
27 
28theorem integrable_density {a : ℝ} (ha : 0 < a) : Integrable (density a) :=
29  (integrable_exp_neg_mul_sq ha).const_mul _
30 
31theorem integral_density {a : ℝ} (ha : 0 < a) : ∫ x, density a x = 1 := by
32  unfold density
33  rw [integral_const_mul, integral_gaussian, Real.sqrt_div Real.pi_pos.le]
34  have hs : Real.sqrt a ≠ 0 := ne_of_gt (Real.sqrt_pos.2 ha)
35  have hp : Real.sqrt Real.pi ≠ 0 := ne_of_gt (Real.sqrt_pos.2 Real.pi_pos)
36  field_simp
37 
38theorem sqrt_density (a x : ℝ) :
39    Real.sqrt (density a x) = Real.sqrt (Real.sqrt a / Real.sqrt Real.pi) *
40      Real.exp (-(a / 2) * x ^ 2) := by
41  unfold density
42  rw [Real.sqrt_mul (by positivity), ← Real.exp_half]
43  congr 2
44  ring
45 
46theorem integral_sqrt_density_mul {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :
47    (∫ x, Real.sqrt (density a x) * Real.sqrt (density b x)) =
48      Real.sqrt (2 * Real.sqrt a * Real.sqrt b / (a + b)) := by
49  have hexp (x : ℝ) :
50      Real.sqrt (density a x) * Real.sqrt (density b x) =
51      (Real.sqrt (Real.sqrt a / Real.sqrt Real.pi) *
52        Real.sqrt (Real.sqrt b / Real.sqrt Real.pi)) *
53          Real.exp (-((a + b) / 2) * x ^ 2) := by
54    rw [sqrt_density, sqrt_density]
55    rw [mul_mul_mul_comm, ← Real.exp_add]
56    congr 2
57    ring
58  simp_rw [hexp]
59  rw [integral_const_mul, integral_gaussian,
60    ← Real.sqrt_mul (by positivity : 0 ≤ Real.sqrt a / Real.sqrt Real.pi),
61    ← Real.sqrt_mul (by positivity :
62      0 ≤ (Real.sqrt a / Real.sqrt Real.pi) * (Real.sqrt b / Real.sqrt Real.pi))]
63  congr 1
64  have hp : Real.sqrt Real.pi ≠ 0 := ne_of_gt (Real.sqrt_pos.2 Real.pi_pos)
65  have hab : a + b ≠ 0 := ne_of_gt (add_pos ha hb)
66  field_simp
67  nlinarith [Real.sq_sqrt Real.pi_pos.le]
68 
69/-- Root affinity between one Gaussian and its variance dilation. -/
70theorem integral_dilated_density {a g : ℝ} (ha : 0 < a) (hg : 0 < g) :
71    (∫ x, Real.sqrt (density a x) * Real.sqrt (density (a / g) x)) =
72      Real.sqrt (Cloning.Thermal.classicalBase g) := by
73  rw [integral_sqrt_density_mul ha (div_pos ha hg), Real.sqrt_div ha.le]
74  congr 1
75  unfold Cloning.Thermal.classicalBase
76  have hsa : Real.sqrt a ≠ 0 := ne_of_gt (Real.sqrt_pos.2 ha)
77  have hsg : Real.sqrt g ≠ 0 := ne_of_gt (Real.sqrt_pos.2 hg)
78  have ha0 := ne_of_gt ha
79  have hg0 := ne_of_gt hg
80  have hag : a + a / g ≠ 0 := ne_of_gt (add_pos ha (div_pos ha hg))
81  have hg1 : 1 + g ≠ 0 := by positivity
82  field_simp
83  rw [Real.sq_sqrt ha.le, Real.sq_sqrt hg.le]
84  ring
85 
86variable {ι : Type*} [Fintype ι]
87 
88/-- An actual product Gaussian density, with coordinate-dependent variances. -/
89def productDensity (a : ι → ℝ) (x : ι → ℝ) : ℝ := ∏ i, density (a i) (x i)
90 
91theorem productDensity_nonneg (a : ι → ℝ) (x : ι → ℝ) :
92    0 ≤ productDensity a x :=
93  Finset.prod_nonneg (fun _ _ => density_nonneg _ _)
94 
95theorem integral_productDensity (a : ι → ℝ) (ha : ∀ i, 0 < a i) :
96    ∫ x, productDensity a x = 1 := by
97  unfold productDensity
98  rw [integral_fintype_prod_volume_eq_prod]
99  simp only [integral_density (ha _), Finset.prod_const_one]
100 
101/-- Exact affinity of finite product Gaussian distributions. -/
102theorem integral_product_affinity (a b : ι → ℝ)
103    (ha : ∀ i, 0 < a i) (hb : ∀ i, 0 < b i) :
104    (∫ x, Real.sqrt (productDensity a x) * Real.sqrt (productDensity b x)) =
105      ∏ i, Real.sqrt (2 * Real.sqrt (a i) * Real.sqrt (b i) / (a i + b i)) := by
106  simp_rw [productDensity, Real.sqrt_prod _ (fun i _ => density_nonneg _ _),
107    ← Finset.prod_mul_distrib]
108  rw [integral_fintype_prod_volume_eq_prod
109    (fun i t => Real.sqrt (density (a i) t) * Real.sqrt (density (b i) t))]
110  exact Finset.prod_congr rfl (fun i _ => integral_sqrt_density_mul (ha i) (hb i))
111 
112/-- The classical Gaussian dilation factor in any finite number of coordinates. -/
113theorem integral_product_dilation (a : ι → ℝ) (ha : ∀ i, 0 < a i)
114    {g : ℝ} (hg : 0 < g) :
115    (∫ x, Real.sqrt (productDensity a x) *
116      Real.sqrt (productDensity (fun i => a i / g) x)) =
117      Cloning.Thermal.classicalBase g ^ ((Fintype.card ι : ℝ) / 2) := by
118  simp_rw [productDensity, Real.sqrt_prod _ (fun i _ => density_nonneg _ _),
119    ← Finset.prod_mul_distrib]
120  rw [integral_fintype_prod_volume_eq_prod
121    (fun i t => Real.sqrt (density (a i) t) * Real.sqrt (density (a i / g) t))]
122  simp_rw [integral_dilated_density (ha _) hg]
123  rw [Finset.prod_const, Finset.card_univ, Real.sqrt_eq_rpow,
124    ← Real.rpow_mul_natCast (Cloning.Thermal.classicalBase_pos hg).le]
125  congr 1
126  ring
127 
128/-- The manuscript's `F_cl(g,d)` is the actual Gaussian affinity in `d-1`
129coordinates; the base precision in each coordinate cancels. -/
130theorem integral_product_dilation_eq_classicalValue {d : ℕ} (hd : 1 ≤ d)
131    (a : Fin (d - 1) → ℝ) (ha : ∀ i, 0 < a i) {g : ℝ} (hg : 0 < g) :
132    (∫ x, Real.sqrt (productDensity a x) *
133      Real.sqrt (productDensity (fun i => a i / g) x)) = Cloning.classicalValue g d := by
134  rw [integral_product_dilation a ha hg]
135  simp only [Fintype.card_fin, Cloning.classicalValue, Nat.cast_sub hd, Nat.cast_one]
136 
137/-- A common invertible measurable change of coordinates preserves the
138affinity, using the pushed-forward reference measure on the target space.
139In particular this applies to a common whitening or covariance transform. -/
140theorem integral_product_dilation_map_equiv {E : Type*} [MeasurableSpace E]
141    (e : (ι → ℝ) ≃ᵐ E) (a : ι → ℝ) (ha : ∀ i, 0 < a i)
142    {g : ℝ} (hg : 0 < g) :
143    (∫ y, Real.sqrt (productDensity a (e.symm y)) *
144      Real.sqrt (productDensity (fun i => a i / g) (e.symm y))
145      ∂(Measure.map e volume)) =
146      Cloning.Thermal.classicalBase g ^ ((Fintype.card ι : ℝ) / 2) := by
147  rw [integral_map_equiv]
148  simpa only [MeasurableEquiv.symm_apply_apply] using integral_product_dilation a ha hg
149 
150end Cloning.GaussianAffinity