|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Thomas Zhu. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Thomas Zhu, Etienne Marion |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.Probability.Distributions.Gaussian.Real |
| 9 | +public import Mathlib.MeasureTheory.Function.ConvergenceInDistribution |
| 10 | + |
| 11 | +import Mathlib.MeasureTheory.Measure.CharacteristicFunction.TaylorExpansion |
| 12 | +import Mathlib.MeasureTheory.Measure.LevyConvergence |
| 13 | +import Mathlib.Probability.Independence.CharacteristicFunction |
| 14 | + |
| 15 | +/-! |
| 16 | +# Central limit theorem |
| 17 | +
|
| 18 | +We prove the central limit theorem in dimension 1. |
| 19 | +
|
| 20 | +## Main statement |
| 21 | +
|
| 22 | +* `tendstoInDistribution_inv_sqrt_mul_sum_sub`: Given a sequence of random variables |
| 23 | + `X : ℕ → Ω → ℝ` that are independent, identically distributed with mean `μ` and variance `v`, |
| 24 | + and a random variable `Y : Ω' → ℝ` following `gaussianReal 0 v`, the sequence |
| 25 | + `n ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution. |
| 26 | +
|
| 27 | +## Tags |
| 28 | +
|
| 29 | +central limit theorem |
| 30 | +-/ |
| 31 | + |
| 32 | +public section |
| 33 | + |
| 34 | +noncomputable section |
| 35 | + |
| 36 | +open MeasureTheory ProbabilityTheory Complex Filter |
| 37 | +open scoped Real Topology |
| 38 | + |
| 39 | +namespace ProbabilityTheory |
| 40 | + |
| 41 | +variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'} |
| 42 | + {P : Measure Ω} {P' : Measure Ω'} {X : ℕ → Ω → ℝ} {Y : Ω' → ℝ} |
| 43 | + |
| 44 | +lemma charFun_inv_sqrt_mul_sum (hindep : iIndepFun X P) |
| 45 | + (hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) {n : ℕ} {t : ℝ} : |
| 46 | + charFun (P.map (fun ω ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k ω)) t = |
| 47 | + (charFun (P.map (X 0)) ((√n)⁻¹ * t)) ^ n := by |
| 48 | + have mX n := (hident n).aemeasurable_fst |
| 49 | + rw [charFun_map_mul_comp, (hindep.restrict _).charFun_map_fun_finset_sum_eq_prod (fun _ _↦ mX _)] |
| 50 | + · simp [fun i ↦ (hident i).map_eq] |
| 51 | + · exact Finset.aemeasurable_fun_sum _ fun _ _ ↦ mX _ |
| 52 | + |
| 53 | +variable [IsProbabilityMeasure P] |
| 54 | + |
| 55 | +lemma tendsto_charFun_inv_sqrt_mul_pow {X : Ω → ℝ} |
| 56 | + (hX : AEMeasurable X P) (h0 : P[X] = 0) (h1 : P[X ^ 2] = 1) (t : ℝ) : |
| 57 | + Tendsto (fun (n : ℕ) ↦ (charFun (P.map X) ((√n)⁻¹ * t)) ^ n) atTop (𝓝 (exp (- t ^ 2 / 2))) := by |
| 58 | + apply tendsto_pow_exp_of_isLittleO_sub_add_div |
| 59 | + suffices (fun (n : ℕ) ↦ charFun (Measure.map X P) ((√n)⁻¹ * t) - |
| 60 | + (1 + (-(((√n)⁻¹ * t) ^ 2 / 2) : ℂ))) =o[atTop] fun n ↦ ((√n)⁻¹ * t) ^ 2 by |
| 61 | + have aux : (fun (n : ℕ) ↦ ‖(1 / n : ℂ)‖) = fun (n : ℕ) ↦ ‖(1 / n : ℝ)‖ := by simp |
| 62 | + rw [← Asymptotics.isLittleO_norm_right, aux, Asymptotics.isLittleO_norm_right] |
| 63 | + refine .of_const_mul_right (c := t ^ 2) ?_ |
| 64 | + convert this using 4 with n <;> norm_cast <;> simp [field] |
| 65 | + have : Tendsto (fun (n : ℕ) ↦ (√n)⁻¹ * t) atTop (𝓝 0) := by |
| 66 | + rw [← zero_mul t] |
| 67 | + exact .mul_const t (tendsto_inv_atTop_zero.comp <| Real.tendsto_sqrt_atTop.comp <| |
| 68 | + tendsto_natCast_atTop_atTop) |
| 69 | + convert (taylor_charFun_two hX h0 h1).comp_tendsto this using 2 |
| 70 | + simp |
| 71 | + ring |
| 72 | + |
| 73 | +variable [IsProbabilityMeasure P'] |
| 74 | + |
| 75 | +/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are |
| 76 | +independent, identically distributed, centered and with variance `1` and a random variable |
| 77 | +`Y : Ω' → ℝ` following `gaussianReal 0 1`, the sequence |
| 78 | +`n ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k` converges to `Y` in distribution. -/ |
| 79 | +theorem tendstoInDistribution_inv_sqrt_mul_sum (hY : HasLaw Y (gaussianReal 0 1) P') |
| 80 | + (h0 : P[X 0] = 0) (h1 : P[X 0 ^ 2] = 1) (hindep : iIndepFun X P) |
| 81 | + (hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) : |
| 82 | + TendstoInDistribution (fun (n : ℕ) ω ↦ (√n)⁻¹ * ∑ k ∈ Finset.range n, X k ω) atTop Y |
| 83 | + (fun _ ↦ P) P' where |
| 84 | + forall_aemeasurable n := |
| 85 | + .const_mul (Finset.aemeasurable_fun_sum _ fun _ _ ↦ (hident _).aemeasurable_fst) _ |
| 86 | + tendsto := by |
| 87 | + refine ProbabilityMeasure.tendsto_iff_tendsto_charFun.2 fun t ↦ ?_ |
| 88 | + rw! [hY.map_eq] |
| 89 | + simpa [charFun_inv_sqrt_mul_sum hindep hident, charFun_gaussianReal, neg_div] using |
| 90 | + tendsto_charFun_inv_sqrt_mul_pow (hident 0).aemeasurable_fst h0 h1 t |
| 91 | + |
| 92 | +/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are |
| 93 | +independent, identically distributed with mean `μ` and non-zero variance `v`, and a random variable |
| 94 | +`Y : Ω' → ℝ` following `gaussianReal 0 1`, the sequence |
| 95 | +`n ↦ (√(n * v)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution. -/ |
| 96 | +private theorem tendstoInDistribution_inv_sqrt_mul_var_mul_sum_sub |
| 97 | + (hY : HasLaw Y (gaussianReal 0 1) P') |
| 98 | + (hX : Var[X 0; P] ≠ 0) (hindep : iIndepFun X P) |
| 99 | + (hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) : |
| 100 | + TendstoInDistribution |
| 101 | + (fun (n : ℕ) ω ↦ (√(n * Var[X 0; P]))⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0])) |
| 102 | + atTop Y (fun _ ↦ P) P' := by |
| 103 | + have mX0 := (hident 0).aemeasurable_fst |
| 104 | + have intX0 : Integrable (X 0) P := memLp_one_iff_integrable.1 <| |
| 105 | + (memLp_two_of_variance_ne_zero mX0.aestronglyMeasurable hX).mono_exponent (by simp) |
| 106 | + have this (n : ℕ) ω : (√(n * Var[X 0; P]))⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0]) = |
| 107 | + (√n)⁻¹ * ∑ k ∈ Finset.range n, (X k ω - P[X 0]) / √Var[X 0; P] := by |
| 108 | + rw [← Finset.sum_div, Finset.sum_sub_distrib] |
| 109 | + simp [field] |
| 110 | + simp_rw [this] |
| 111 | + convert tendstoInDistribution_inv_sqrt_mul_sum hY ?_ ?_ ?_ ?_ |
| 112 | + · rw [integral_div, integral_sub intX0 (by simp)] |
| 113 | + simp |
| 114 | + · simp only [Pi.pow_apply, div_pow] |
| 115 | + rw [integral_div, ← variance_eq_integral mX0, Real.sq_sqrt (variance_nonneg _ _), div_self hX] |
| 116 | + · exact hindep.comp (fun _ x ↦ (x - P[X 0]) / √Var[X 0; P]) (by fun_prop) |
| 117 | + · convert fun n ↦ (hident n).comp (u := fun x ↦ (x - P[X 0]) / √Var[X 0; P]) (by fun_prop) |
| 118 | + |
| 119 | +/-- **Central Limit Theorem:** Given a sequence of random variables `X : ℕ → Ω → ℝ` that are |
| 120 | +independent, identically distributed with mean `μ` and variance `v`, and a random variable |
| 121 | +`Y : Ω' → ℝ` following `gaussianReal 0 v`, the sequence |
| 122 | +`n ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * μ)` converges to `Y` in distribution. -/ |
| 123 | +theorem tendstoInDistribution_inv_sqrt_mul_sum_sub |
| 124 | + (hY : HasLaw Y (gaussianReal 0 Var[X 0; P].toNNReal) P') |
| 125 | + (hX : MemLp (X 0) 2 P) (hindep : iIndepFun X P) |
| 126 | + (hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) P P) : |
| 127 | + TendstoInDistribution |
| 128 | + (fun (n : ℕ) ω ↦ (√n)⁻¹ * (∑ k ∈ Finset.range n, X k ω - n * P[X 0])) |
| 129 | + atTop Y (fun _ ↦ P) P' := by |
| 130 | + obtain h | h := eq_or_ne Var[X 0; P] 0 |
| 131 | + · have : ∀ᵐ ω ∂P, ∀ n, X n ω = P[X 0] := by |
| 132 | + refine ae_all_iff.2 fun n ↦ ?_ |
| 133 | + convert (ae_eq_integral_of_variance_eq_zero ((hident n).memLp_iff.2 hX)) ?_ using 3 |
| 134 | + · rw [(hident n).integral_eq] |
| 135 | + · rwa [(hident n).variance_eq] |
| 136 | + have mX (n : ℕ) := (hident n).aemeasurable_fst |
| 137 | + refine tendstoInDistribution_of_identDistrib 0 (fun n ↦ ?_) ?_ |
| 138 | + · refine ⟨by fun_prop, by fun_prop, Measure.map_congr ?_⟩ |
| 139 | + filter_upwards [this] with ω hω |
| 140 | + simp [hω] |
| 141 | + · exact ⟨by fun_prop, by fun_prop, by simp [hY.map_eq, h]⟩ |
| 142 | + have : HasLaw (fun ω ↦ Y ω / √Var[X 0; P]) (gaussianReal 0 1) P' := by |
| 143 | + convert gaussianReal_div_const hY _ |
| 144 | + · simp |
| 145 | + · ext; simp [h] |
| 146 | + convert (tendstoInDistribution_inv_sqrt_mul_var_mul_sum_sub this h hindep hident).continuous_comp |
| 147 | + (g := (√Var[X 0; P] * ·)) (by fun_prop) |
| 148 | + · simp [field] -- simp [field, hX] triggers the unused simp arguments linter |
| 149 | + field_simp [h] |
| 150 | + · ext |
| 151 | + simp [field] -- simp [field, hX] triggers the unused simp arguments linter |
| 152 | + field_simp [h] |
| 153 | + |
| 154 | +end ProbabilityTheory |
0 commit comments