@@ -5,6 +5,7 @@ Authors: Josha Dekker, Devon Tuma, Kexing Ying
5
5
-/
6
6
import Mathlib.Probability.Notation
7
7
import Mathlib.Probability.Density
8
+ import Mathlib.Probability.ConditionalProbability
8
9
import Mathlib.Probability.ProbabilityMassFunction.Constructions
9
10
10
11
/-!
@@ -15,11 +16,16 @@ This file defines two related notions of uniform distributions, which will be un
15
16
16
17
Defines the uniform distribution for any set with finite measure.
17
18
19
+ ## Main definitions
20
+ * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the
21
+ push-forward measure agrees with the rescaled restricted measure `μ`.
22
+
18
23
# Uniform probability mass functions
19
24
20
25
This file defines a number of uniform `PMF` distributions from various inputs,
21
26
uniformly drawing from the corresponding object.
22
27
28
+ ## Main definitions
23
29
`PMF.uniformOfFinset` gives each element in the set equal probability,
24
30
with `0` probability for elements not in the set.
25
31
@@ -28,35 +34,38 @@ This file defines a number of uniform `PMF` distributions from various inputs,
28
34
29
35
`PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct.
30
36
Each probability is given by the count of the element divided by the size of the `Multiset`
37
+
38
+ # To Do:
39
+ * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`.
31
40
-/
32
41
33
42
open scoped Classical MeasureTheory BigOperators NNReal ENNReal
34
43
35
- open TopologicalSpace MeasureTheory.Measure
44
+ open TopologicalSpace MeasureTheory.Measure PMF
45
+
46
+ noncomputable section
36
47
37
48
namespace MeasureTheory
38
49
39
50
variable {E : Type *} [MeasurableSpace E] {m : Measure E} {μ : Measure E}
40
- variable {Ω : Type *} {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
41
51
52
+ namespace pdf
42
53
43
- section
44
-
45
- /-! **Uniform Distribution based on a measure** -/
54
+ variable {Ω : Type *}
46
55
47
- namespace pdf
56
+ variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
48
57
49
58
/-- A random variable `X` has uniform distribution on `s` if its push-forward measure is
50
59
`(μ s)⁻¹ • μ.restrict s`. -/
51
- def IsUniform (X : Ω → E) (support : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :=
52
- map X ℙ = (μ support)⁻¹ • μ.restrict support
60
+ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :=
61
+ map X ℙ = ProbabilityTheory.cond μ s
53
62
#align measure_theory.pdf.is_uniform MeasureTheory.pdf.IsUniform
54
63
55
64
namespace IsUniform
56
65
57
66
theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0 ) (hnt : μ s ≠ ∞)
58
67
(hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by
59
- dsimp [IsUniform] at hu
68
+ dsimp [IsUniform, ProbabilityTheory.cond ] at hu
60
69
by_contra h
61
70
rw [map_of_not_aemeasurable h] at hu
62
71
apply zero_ne_one' ℝ≥0 ∞
@@ -66,17 +75,14 @@ theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s
66
75
Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt]
67
76
68
77
theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by
69
- intro t ht
70
- rw [hu, smul_apply, smul_eq_mul]
71
- apply mul_eq_zero.mpr
72
- refine Or.inr (le_antisymm ?_ (zero_le _))
73
- exact ht ▸ restrict_apply_le s t
78
+ rw [hu]
79
+ exact ProbabilityTheory.cond_absolutelyContinuous μ
74
80
75
81
theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0 ) (hnt : μ s ≠ ∞)
76
82
(hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) :
77
83
ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by
78
- rw [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, smul_apply, restrict_apply hA ,
79
- ENNReal.div_eq_inv_mul, smul_eq_mul, Set.inter_comm ]
84
+ rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply' ,
85
+ ENNReal.div_eq_inv_mul.symm ]
80
86
#align measure_theory.pdf.is_uniform.measure_preimage MeasureTheory.pdf.IsUniform.measure_preimage
81
87
82
88
theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0 ) (hnt : μ s ≠ ∞)
@@ -89,12 +95,13 @@ theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt
89
95
90
96
theorem toMeasurable_iff {X : Ω → E} {s : Set E} :
91
97
IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by
92
- by_cases hnt : μ s = ∞
93
- · simp [IsUniform, hnt]
94
- · simp [IsUniform, restrict_toMeasurable hnt]
98
+ unfold IsUniform
99
+ rw [ProbabilityTheory.cond_toMeasurable_eq]
95
100
96
101
protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) :
97
- IsUniform X (toMeasurable μ s) ℙ μ := toMeasurable_iff.2 hu
102
+ IsUniform X (toMeasurable μ s) ℙ μ := by
103
+ unfold IsUniform at *
104
+ rwa [ProbabilityTheory.cond_toMeasurable_eq]
98
105
99
106
theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0 ) (hnt : μ s ≠ ∞)
100
107
(hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
@@ -103,14 +110,16 @@ theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞
103
110
(measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s)
104
111
rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one,
105
112
withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable]
113
+ rfl
106
114
#align measure_theory.pdf.is_uniform.has_pdf MeasureTheory.pdf.IsUniform.hasPDF
107
115
108
116
theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E}
109
117
(hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by
110
118
rcases hμs with H|H
111
- · simp only [IsUniform, H, ENNReal.inv_zero, restrict_eq_zero.mpr H, smul_zero] at hu
119
+ · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H,
120
+ smul_zero] at hu
112
121
simp [pdf, hu]
113
- · simp only [IsUniform, H, ENNReal.inv_top, zero_smul] at hu
122
+ · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu
114
123
simp [pdf, hu]
115
124
116
125
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
@@ -124,7 +133,9 @@ theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
124
133
have : HasPDF X ℙ μ := hasPDF hns hnt hu
125
134
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
126
135
apply (eq_of_map_eq_withDensity _ _).mp
127
- · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one]
136
+ · rw [hu, withDensity_indicator hms,
137
+ withDensity_smul _ measurable_one, withDensity_one]
138
+ rfl
128
139
· exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
129
140
130
141
theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
@@ -163,7 +174,9 @@ theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
163
174
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
164
175
theorem integral_eq (huX : IsUniform X s ℙ) :
165
176
∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
166
- rw [← smul_eq_mul, ← integral_smul_measure, ← huX]
177
+ rw [← smul_eq_mul, ← integral_smul_measure]
178
+ dsimp only [IsUniform, ProbabilityTheory.cond] at huX
179
+ rw [← huX]
167
180
by_cases hX : AEMeasurable X ℙ
168
181
· exact (integral_map hX aestronglyMeasurable_id).symm
169
182
· rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable]
@@ -172,9 +185,33 @@ theorem integral_eq (huX : IsUniform X s ℙ) :
172
185
173
186
end IsUniform
174
187
175
- end pdf
188
+ variable {X : Ω → E}
189
+
190
+ lemma IsUniform.cond {s : Set E} :
191
+ IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by
192
+ unfold IsUniform
193
+ rw [Measure.map_id]
194
+
195
+ /-- The density of the uniform measure on a set with respect to itself. This allows us to abstract
196
+ away the choice of random variable and probability space. -/
197
+ def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0 ∞ :=
198
+ s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0 ∞)) x
176
199
177
- end
200
+ /-- Check that indeed any uniform random variable has the uniformPDF. -/
201
+ lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) :
202
+ (fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by
203
+ unfold uniformPDF
204
+ exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _)
205
+
206
+ /-- Alternative way of writing the uniformPDF. -/
207
+ lemma uniformPDF_ite {s : Set E} {x : E} :
208
+ uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by
209
+ unfold uniformPDF
210
+ unfold Set.indicator
211
+ rename_i inst x_1
212
+ simp_all only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one]
213
+
214
+ end pdf
178
215
179
216
end MeasureTheory
180
217
0 commit comments