Skip to content

Commit 2d36cb1

Browse files
committed
feat : refactor IsUniform through uniformMeasure (#10456)
Refactor the definitions and proofs of IsUniform through the new `uniformMeasure`, which abstracts away from the need of a random variable and probability space. A future PR can refactor the PMF parts in terms of a `uniformMeasure`. This was #10141, which was split into a small PR to move the results (merged) and this one.
1 parent a2f4883 commit 2d36cb1

File tree

2 files changed

+107
-30
lines changed

2 files changed

+107
-30
lines changed

Mathlib/Probability/ConditionalProbability.lean

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,52 @@ end Definitions
7878
@[inherit_doc] scoped notation μ "[" s "|" t "]" => ProbabilityTheory.cond μ t s
7979
@[inherit_doc] scoped notation:60 μ "[|" t "]" => ProbabilityTheory.cond μ t
8080

81-
/-- The conditional probability measure of any finite measure on any set of positive measure
81+
/-- The conditional probability measure of any measure on any set of finite positive measure
8282
is a probability measure. -/
83-
theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) :
83+
theorem cond_isProbabilityMeasure_of_finite (hcs : μ s ≠ 0) (hs : μ s ≠ ) :
8484
IsProbabilityMeasure (μ[|s]) :=
8585
by
86-
rw [cond, Measure.smul_apply, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter]
87-
exact ENNReal.inv_mul_cancel hcs (measure_ne_top _ s)⟩
86+
unfold ProbabilityTheory.cond
87+
simp only [Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
88+
MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, smul_eq_mul]
89+
exact ENNReal.inv_mul_cancel hcs hs⟩
90+
91+
/-- The conditional probability measure of any finite measure on any set of positive measure
92+
is a probability measure. -/
93+
theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) :
94+
IsProbabilityMeasure (μ[|s]) := cond_isProbabilityMeasure_of_finite μ hcs (measure_ne_top μ s)
8895
#align probability_theory.cond_is_probability_measure ProbabilityTheory.cond_isProbabilityMeasure
8996

97+
instance cond_isFiniteMeasure :
98+
IsFiniteMeasure (μ[|s]) where
99+
measure_univ_lt_top := by
100+
unfold ProbabilityTheory.cond
101+
have : (μ s)⁻¹ * μ s < ⊤ := by
102+
have : (μ s)⁻¹ * μ s ≤ 1 := by
103+
apply ENNReal.le_inv_iff_mul_le.mp
104+
rfl
105+
exact lt_of_le_of_lt this ENNReal.one_lt_top
106+
simp_all only [MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter,
107+
le_refl, Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
108+
smul_eq_mul]
109+
110+
theorem cond_toMeasurable_eq :
111+
μ[|(toMeasurable μ s)] = μ[|s] := by
112+
unfold cond
113+
by_cases hnt : μ s = ∞
114+
· simp [hnt]
115+
· simp [Measure.restrict_toMeasurable hnt]
116+
117+
theorem cond_absolutelyContinuous :
118+
μ[|s] ≪ μ := by
119+
intro t ht
120+
unfold ProbabilityTheory.cond
121+
rw [Measure.smul_apply, smul_eq_mul]
122+
apply mul_eq_zero.mpr
123+
refine Or.inr (le_antisymm ?_ (zero_le _))
124+
exact ht ▸ Measure.restrict_apply_le s t
125+
126+
90127
section Bayes
91128

92129
@[simp]
@@ -103,6 +140,9 @@ theorem cond_apply (hms : MeasurableSet s) (t : Set Ω) : μ[t|s] = (μ s)⁻¹
103140
rw [cond, Measure.smul_apply, Measure.restrict_apply' hms, Set.inter_comm, smul_eq_mul]
104141
#align probability_theory.cond_apply ProbabilityTheory.cond_apply
105142

143+
theorem cond_apply' {t : Set Ω} (hA : MeasurableSet t) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
144+
rw [cond, Measure.smul_apply, Measure.restrict_apply hA, Set.inter_comm, smul_eq_mul]
145+
106146
theorem cond_inter_self (hms : MeasurableSet s) (t : Set Ω) : μ[s ∩ t|s] = μ[t|s] := by
107147
rw [cond_apply _ hms, ← Set.inter_assoc, Set.inter_self, ← cond_apply _ hms]
108148
#align probability_theory.cond_inter_self ProbabilityTheory.cond_inter_self

Mathlib/Probability/Distributions/Uniform.lean

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Josha Dekker, Devon Tuma, Kexing Ying
55
-/
66
import Mathlib.Probability.Notation
77
import Mathlib.Probability.Density
8+
import Mathlib.Probability.ConditionalProbability
89
import Mathlib.Probability.ProbabilityMassFunction.Constructions
910

1011
/-!
@@ -15,11 +16,16 @@ This file defines two related notions of uniform distributions, which will be un
1516
1617
Defines the uniform distribution for any set with finite measure.
1718
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+
1823
# Uniform probability mass functions
1924
2025
This file defines a number of uniform `PMF` distributions from various inputs,
2126
uniformly drawing from the corresponding object.
2227
28+
## Main definitions
2329
`PMF.uniformOfFinset` gives each element in the set equal probability,
2430
with `0` probability for elements not in the set.
2531
@@ -28,35 +34,38 @@ This file defines a number of uniform `PMF` distributions from various inputs,
2834
2935
`PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct.
3036
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`.
3140
-/
3241

3342
open scoped Classical MeasureTheory BigOperators NNReal ENNReal
3443

35-
open TopologicalSpace MeasureTheory.Measure
44+
open TopologicalSpace MeasureTheory.Measure PMF
45+
46+
noncomputable section
3647

3748
namespace MeasureTheory
3849

3950
variable {E : Type*} [MeasurableSpace E] {m : Measure E} {μ : Measure E}
40-
variable {Ω : Type*} {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
4151

52+
namespace pdf
4253

43-
section
44-
45-
/-! **Uniform Distribution based on a measure** -/
54+
variable {Ω : Type*}
4655

47-
namespace pdf
56+
variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
4857

4958
/-- A random variable `X` has uniform distribution on `s` if its push-forward measure is
5059
`(μ 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
5362
#align measure_theory.pdf.is_uniform MeasureTheory.pdf.IsUniform
5463

5564
namespace IsUniform
5665

5766
theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
5867
(hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by
59-
dsimp [IsUniform] at hu
68+
dsimp [IsUniform, ProbabilityTheory.cond] at hu
6069
by_contra h
6170
rw [map_of_not_aemeasurable h] at hu
6271
apply zero_ne_one' ℝ≥0
@@ -66,17 +75,14 @@ theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s
6675
Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt]
6776

6877
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 μ
7480

7581
theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
7682
(hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) :
7783
ℙ (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]
8086
#align measure_theory.pdf.is_uniform.measure_preimage MeasureTheory.pdf.IsUniform.measure_preimage
8187

8288
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
8995

9096
theorem toMeasurable_iff {X : Ω → E} {s : Set E} :
9197
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]
95100

96101
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]
98105

99106
theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
100107
(hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
@@ -103,14 +110,16 @@ theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞
103110
(measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s)
104111
rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one,
105112
withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable]
113+
rfl
106114
#align measure_theory.pdf.is_uniform.has_pdf MeasureTheory.pdf.IsUniform.hasPDF
107115

108116
theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E}
109117
(hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by
110118
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
112121
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
114123
simp [pdf, hu]
115124

116125
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)
124133
have : HasPDF X ℙ μ := hasPDF hns hnt hu
125134
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
126135
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
128139
· exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
129140

130141
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 ℙ) :
163174
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
164175
theorem integral_eq (huX : IsUniform X s ℙ) :
165176
∫ 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]
167180
by_cases hX : AEMeasurable X ℙ
168181
· exact (integral_map hX aestronglyMeasurable_id).symm
169182
· rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable]
@@ -172,9 +185,33 @@ theorem integral_eq (huX : IsUniform X s ℙ) :
172185

173186
end IsUniform
174187

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
176199

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
178215

179216
end MeasureTheory
180217

0 commit comments

Comments
 (0)