|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Yaël Dillies. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Yaël Dillies |
| 5 | +-/ |
| 6 | +module |
| 7 | + |
| 8 | +public import Mathlib.MeasureTheory.Integral.Bochner.Basic |
| 9 | +public import Mathlib.Probability.CondVar |
| 10 | + |
| 11 | +import Mathlib.Probability.Notation |
| 12 | + |
| 13 | +/-! |
| 14 | +# Distributions on two values |
| 15 | +
|
| 16 | +This file proves a few lemmas about random variables that take at most two values. |
| 17 | +-/ |
| 18 | + |
| 19 | +public section |
| 20 | + |
| 21 | +open MeasureTheory |
| 22 | +open scoped ProbabilityTheory |
| 23 | + |
| 24 | +namespace MeasureTheory |
| 25 | +variable {Ω : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} |
| 26 | + |
| 27 | +/-- If an `AEMeasurable` function is ae equal to `0` or `1`, then its integral is equal to the |
| 28 | +measure of the set where it equals `1`. -/ |
| 29 | +lemma integral_of_ae_eq_zero_or_one (hXmeas : AEMeasurable X μ) (hX : ∀ᵐ ω ∂μ, X ω = 0 ∨ X ω = 1) : |
| 30 | + μ[X] = μ.real {ω | X ω = 1} := by |
| 31 | + refine (integral_map (f := id) hXmeas <| by fun_prop).symm.trans ?_ |
| 32 | + rw [(Measure.ae_eq_or_eq_iff_map_eq_dirac_add_dirac hXmeas zero_ne_one).1 hX] |
| 33 | + by_cases h : μ {ω | X ω = 1} = ⊤ |
| 34 | + · simp [h, Measure.real, Set.preimage, integral_undef, Integrable, HasFiniteIntegral] |
| 35 | + rw [integral_add_measure ⟨by fun_prop, by simp [HasFiniteIntegral]⟩ <| |
| 36 | + .smul_measure (by simp [integrable_dirac]) h] |
| 37 | + simp [Measure.real, Set.preimage] |
| 38 | + |
| 39 | +/-- If a random variable is ae equal to `0` or `1`, then one minus its expectation is equal to the |
| 40 | +probability that it equals `0`. -/ |
| 41 | +lemma integral_one_sub_of_ae_eq_zero_or_one (hXmeas : AEMeasurable X μ) |
| 42 | + (hX : ∀ᵐ ω ∂μ, X ω = 0 ∨ X ω = 1) : ∫ ω, 1 - X ω ∂μ = μ.real {ω | X ω = 0} := by |
| 43 | + calc |
| 44 | + _ = μ.real {ω | 1 - X ω = 1} := |
| 45 | + integral_of_ae_eq_zero_or_one (aemeasurable_const (b := 1).sub hXmeas) |
| 46 | + (by simpa [sub_eq_zero, or_comm, eq_comm (a := (1 : ℝ))] using hX) |
| 47 | + _ = μ.real {ω | X ω = 0} := by simp |
| 48 | + |
| 49 | +end MeasureTheory |
| 50 | + |
| 51 | + |
| 52 | +namespace ProbabilityTheory |
| 53 | +variable {Ω : Type*} {m : MeasurableSpace Ω} {X Y : Ω → ℝ} {μ : Measure ℝ} {P : Measure Ω} |
| 54 | + |
| 55 | +/-- If a random variable is ae equal to `0` or `1`, then its conditional variance is the product of |
| 56 | +the conditional probabilities that it's equal to `0` and that it's equal to `1`. -/ |
| 57 | +lemma condVar_of_ae_eq_zero_or_one {m₀ : MeasurableSpace Ω} (hm : m ≤ m₀) {μ : Measure[m₀] Ω} |
| 58 | + [IsFiniteMeasure μ] (hXmeas : AEMeasurable[m₀] X μ) (hX : ∀ᵐ ω ∂μ, X ω = 0 ∨ X ω = 1) : |
| 59 | + Var[X; μ | m] =ᵐ[μ] μ[X | m] * μ[1 - X | m] := by |
| 60 | + wlog hXmeas : Measurable[m₀] X |
| 61 | + · obtain ⟨Y, hYmeas, hXY⟩ := ‹AEMeasurable[m₀] X μ› |
| 62 | + calc |
| 63 | + Var[X; μ | m] |
| 64 | + _ =ᵐ[μ] Var[Y; μ | m] := condVar_congr_ae hXY |
| 65 | + _ =ᵐ[μ] μ[Y | m] * μ[1 - Y | m] := by |
| 66 | + refine this hm hYmeas.aemeasurable ?_ hYmeas |
| 67 | + filter_upwards [hX, hXY] with ω hXω hXYω |
| 68 | + simp [hXω, ← hXYω] |
| 69 | + _ =ᵐ[μ] μ[X | m] * μ[1 - X | m] := by |
| 70 | + refine .mul ?_ ?_ <;> |
| 71 | + exact condExp_congr_ae <| by filter_upwards [hXY] with ω hω; simp [hω] |
| 72 | + calc |
| 73 | + _ =ᵐ[μ] μ[X ^ 2 | m] - μ[X | m] ^ 2 := |
| 74 | + condVar_ae_eq_condExp_sq_sub_sq_condExp hm <| .of_bound hXmeas.aestronglyMeasurable 1 <| by |
| 75 | + filter_upwards [hX]; rintro ω (hω | hω) <;> simp [hω] |
| 76 | + _ =ᵐ[μ] μ[X | m] - μ[X | m] ^ 2 := by |
| 77 | + refine .sub ?_ ae_eq_rfl |
| 78 | + exact condExp_congr_ae <| by filter_upwards [hX]; rintro ω (hω | hω) <;> simp [hω] |
| 79 | + _ =ᵐ[μ] μ[X | m] * μ[1 - X | m] := by |
| 80 | + rw [sq, ← one_sub_mul, mul_comm] |
| 81 | + refine .mul ae_eq_rfl ?_ |
| 82 | + calc |
| 83 | + 1 - μ[X | m] |
| 84 | + _ = μ[1 | m] - μ[X | m] := by simp [Pi.one_def, hm] |
| 85 | + _ =ᵐ[μ] μ[1 - X | m] := by |
| 86 | + refine (condExp_sub (integrable_const _) |
| 87 | + (.of_bound (C := 1) hXmeas.aestronglyMeasurable ?_) _).symm |
| 88 | + filter_upwards [hX] |
| 89 | + rintro ω (hω | hω) <;> simp [hω] |
| 90 | + |
| 91 | +/-- If a random variable is ae equal to `0` or `1`, then its variance is the product of |
| 92 | +the probabilities that it's equal to `0` and that it's equal to `1`. -/ |
| 93 | +lemma variance_of_ae_eq_zero_or_one {μ : Measure Ω} [IsZeroOrProbabilityMeasure μ] |
| 94 | + (hXmeas : AEMeasurable X μ) (hX : ∀ᵐ ω ∂μ, X ω = 0 ∨ X ω = 1) : |
| 95 | + Var[X; μ] = μ.real {ω | X ω = 0} * μ.real {ω | X ω = 1} := by |
| 96 | + obtain rfl | hμ := eq_zero_or_isProbabilityMeasure μ |
| 97 | + · simp |
| 98 | + simpa [Pi.mul_def, integral_of_ae_eq_zero_or_one, integral_one_sub_of_ae_eq_zero_or_one, mul_comm, |
| 99 | + *] using condVar_of_ae_eq_zero_or_one bot_le hXmeas hX |
| 100 | + |
| 101 | +end ProbabilityTheory |
0 commit comments