source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Probability/CondVar.lean | import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real
import Mathlib.MeasureTheory.Integral.Average
import Mathlib.Probability.Moments.Variance
/-!
# Conditional variance
This file defines the variance of a real-valued random variable conditional to a sigma-algebra.
## TODO
Define the Lebesgue conditional variance. See
[GibbsMeasure](https://github.com/james18lpc/GibbsMeasure) for a definition of the Lebesgue
conditional expectation).
-/
open MeasureTheory Filter
open scoped ENNReal
namespace ProbabilityTheory
variable {Ω : Type*} {m₀ m m' : MeasurableSpace Ω} {hm : m ≤ m₀} {X Y : Ω → ℝ} {μ : Measure[m₀] Ω}
{s : Set Ω}
variable (m X μ) in
/-- Conditional variance of a real-valued random variable. It is defined as `0` if any one of the
following conditions is true:
- `m` is not a sub-σ-algebra of `m₀`,
- `μ` is not σ-finite with respect to `m`,
- `X - μ[X | m]` is not square-integrable. -/
noncomputable def condVar : Ω → ℝ := μ[(X - μ[X | m]) ^ 2 | m]
@[inherit_doc] scoped notation "Var[" X "; " μ " | " m "]" => condVar m X μ
/-- Conditional variance of a real-valued random variable. It is defined as `0` if any one of the
following conditions is true:
- `m` is not a sub-σ-algebra of `m₀`,
- `volume` is not σ-finite with respect to `m`,
- `X - 𝔼[X | m]` is not square-integrable. -/
scoped notation "Var[" f "|" m "]" => Var[f; MeasureTheory.volume | m]
lemma condVar_of_not_le (hm : ¬m ≤ m₀) : Var[X; μ | m] = 0 := by rw [condVar, condExp_of_not_le hm]
lemma condVar_of_not_sigmaFinite (hμm : ¬SigmaFinite (μ.trim hm)) :
Var[X; μ | m] = 0 := by rw [condVar, condExp_of_not_sigmaFinite hm hμm]
open scoped Classical in
lemma condVar_of_sigmaFinite [SigmaFinite (μ.trim hm)] :
Var[X; μ | m] =
if Integrable (fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2) μ then
if StronglyMeasurable[m] (fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2) then
fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2
else aestronglyMeasurable_condExpL1.mk (condExpL1 hm μ fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2)
else 0 := condExp_of_sigmaFinite _
lemma condVar_of_stronglyMeasurable [SigmaFinite (μ.trim hm)]
(hX : StronglyMeasurable[m] X) (hXint : Integrable ((X - μ[X|m]) ^ 2) μ) :
Var[X; μ | m] = fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2 :=
condExp_of_stronglyMeasurable _ ((hX.sub stronglyMeasurable_condExp).pow _) hXint
lemma condVar_of_not_integrable (hXint : ¬ Integrable (fun ω ↦ (X ω - (μ[X | m]) ω) ^ 2) μ) :
Var[X; μ | m] = 0 := condExp_of_not_integrable hXint
@[simp] lemma condVar_zero : Var[0; μ | m] = 0 := by simp [condVar]
@[simp]
lemma condVar_const (hm : m ≤ m₀) (c : ℝ) : Var[fun _ ↦ c; μ | m] = 0 := by
obtain rfl | hc := eq_or_ne c 0
· simp [← Pi.zero_def]
by_cases hμm : IsFiniteMeasure μ
· simp [condVar, hm]
· simp [condVar, condExp_of_not_integrable, integrable_const_iff_isFiniteMeasure hc,
integrable_const_iff_isFiniteMeasure <| pow_ne_zero _ hc, hμm, Pi.pow_def]
lemma stronglyMeasurable_condVar : StronglyMeasurable[m] (Var[X; μ | m]) :=
stronglyMeasurable_condExp
lemma condVar_congr_ae (h : X =ᵐ[μ] Y) : Var[X; μ | m] =ᵐ[μ] Var[Y; μ | m] :=
condExp_congr_ae <| by filter_upwards [h, condExp_congr_ae h] with ω hω hω'; dsimp; rw [hω, hω']
lemma condVar_of_aestronglyMeasurable [hμm : SigmaFinite (μ.trim hm)]
(hX : AEStronglyMeasurable[m] X μ) (hXint : Integrable ((X - μ[X|m]) ^ 2) μ) :
Var[X; μ | m] =ᵐ[μ] (X - μ[X | m]) ^ 2 :=
condExp_of_aestronglyMeasurable' _ ((continuous_pow _).comp_aestronglyMeasurable
(hX.sub stronglyMeasurable_condExp.aestronglyMeasurable)) hXint
lemma integrable_condVar : Integrable Var[X; μ | m] μ := integrable_condExp
/-- The integral of the conditional variance `Var[X | m]` over an `m`-measurable set is equal to
the integral of `(X - μ[X | m]) ^ 2` on that set. -/
lemma setIntegral_condVar [SigmaFinite (μ.trim hm)] (hX : Integrable ((X - μ[X|m]) ^ 2) μ)
(hs : MeasurableSet[m] s) :
∫ ω in s, (Var[X; μ | m]) ω ∂μ = ∫ ω in s, (X ω - (μ[X | m]) ω) ^ 2 ∂μ :=
setIntegral_condExp _ hX hs
-- `(· ^ 2)` is a postfix operator called `_sq` in lemma names, but
-- `condVar_ae_eq_condExp_sq_sub_condExp_sq` is a bit ridiculous, so we exceptionally denote it by
-- `sq_` as it were a prefix.
lemma condVar_ae_eq_condExp_sq_sub_sq_condExp (hm : m ≤ m₀) [IsFiniteMeasure μ] (hX : MemLp X 2 μ) :
Var[X; μ | m] =ᵐ[μ] μ[X ^ 2 | m] - μ[X | m] ^ 2 := by
calc
Var[X; μ | m]
_ = μ[X ^ 2 - 2 * X * μ[X | m] + μ[X | m] ^ 2 | m] := by rw [condVar, sub_sq]
_ =ᵐ[μ] μ[X ^ 2 | m] - 2 * μ[X | m] ^ 2 + μ[X | m] ^ 2 := by
have aux₀ : Integrable (X ^ 2) μ := hX.integrable_sq
have aux₁ : Integrable (2 * X * μ[X | m]) μ := by
rw [mul_assoc]
exact (memLp_one_iff_integrable.1 <| hX.condExp.mul hX).const_mul _
have aux₂ : Integrable (μ[X | m] ^ 2) μ := hX.condExp.integrable_sq
filter_upwards [condExp_add (m := m) (aux₀.sub aux₁) aux₂, condExp_sub (m := m) aux₀ aux₁,
condExp_mul_of_stronglyMeasurable_right stronglyMeasurable_condExp aux₁
((hX.integrable one_le_two).const_mul _), condExp_ofNat (m := m) 2 X]
with ω hω₀ hω₁ hω₂ hω₃
simp [hω₀, hω₁, hω₂, hω₃,
condExp_of_stronglyMeasurable hm (stronglyMeasurable_condExp.pow _) aux₂]
simp [mul_assoc, sq]
_ = μ[X ^ 2 | m] - μ[X | m] ^ 2 := by ring
lemma condVar_ae_le_condExp_sq (hm : m ≤ m₀) [IsFiniteMeasure μ] (hX : MemLp X 2 μ) :
Var[X; μ | m] ≤ᵐ[μ] μ[X ^ 2 | m] := by
filter_upwards [condVar_ae_eq_condExp_sq_sub_sq_condExp hm hX] with ω hω
dsimp at hω
nlinarith
/-- **Law of total variance** -/
lemma integral_condVar_add_variance_condExp (hm : m ≤ m₀) [IsProbabilityMeasure μ]
(hX : MemLp X 2 μ) : μ[Var[X; μ | m]] + Var[μ[X | m]; μ] = Var[X; μ] := by
calc
μ[Var[X; μ | m]] + Var[μ[X | m]; μ]
_ = μ[(μ[X ^ 2 | m] - μ[X | m] ^ 2 : Ω → ℝ)] + (μ[μ[X | m] ^ 2] - μ[μ[X | m]] ^ 2) := by
congr 1
· exact integral_congr_ae <| condVar_ae_eq_condExp_sq_sub_sq_condExp hm hX
· exact variance_eq_sub hX.condExp
_ = μ[X ^ 2] - μ[μ[X | m] ^ 2] + (μ[μ[X | m] ^ 2] - μ[X] ^ 2) := by
rw [integral_sub' integrable_condExp, integral_condExp hm, integral_condExp hm]
exact hX.condExp.integrable_sq
_ = Var[X; μ] := by rw [variance_eq_sub hX]; ring
lemma condVar_bot' [NeZero μ] (X : Ω → ℝ) :
Var[X; μ | ⊥] = fun _ => ⨍ ω, (X ω - ⨍ ω', X ω' ∂μ) ^ 2 ∂μ := by
simp [condVar, condExp_bot', average, measureReal_def]
lemma condVar_bot_ae_eq (X : Ω → ℝ) :
Var[X; μ | ⊥] =ᵐ[μ] fun _ ↦ ⨍ ω, (X ω - ⨍ ω', X ω' ∂μ) ^ 2 ∂μ := by
obtain rfl | hμ := eq_zero_or_neZero μ
· rw [ae_zero]
exact eventually_bot
· exact .of_forall <| congr_fun (condVar_bot' X)
lemma condVar_bot [IsProbabilityMeasure μ] (hX : AEMeasurable X μ) :
Var[X; μ | ⊥] = fun _ω ↦ Var[X; μ] := by
simp [condVar_bot', average_eq_integral, variance_eq_integral hX]
lemma condVar_smul (c : ℝ) (X : Ω → ℝ) : Var[c • X; μ | m] =ᵐ[μ] c ^ 2 • Var[X; μ | m] := by
calc
Var[c • X; μ | m]
_ =ᵐ[μ] μ[c ^ 2 • (X - μ[X | m]) ^ 2 | m] := by
rw [condVar]
refine condExp_congr_ae ?_
filter_upwards [condExp_smul (m := m) c X] with ω hω
simp [hω, ← mul_sub, mul_pow]
_ =ᵐ[μ] c ^ 2 • Var[X; μ | m] := condExp_smul ..
@[simp] lemma condVar_neg (X : Ω → ℝ) : Var[-X; μ | m] =ᵐ[μ] Var[X; μ | m] := by
refine condExp_congr_ae ?_
filter_upwards [condExp_neg (m := m) X] with ω hω
simp [hω]
ring
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Density.lean | import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
import Mathlib.Probability.Independence.Basic
/-!
# Probability density function
This file defines the probability density function of random variables, by which we mean
measurable functions taking values in a Borel space. The probability density function is defined
as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f`
is said to the probability density function of a random variable `X` if for all measurable
sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing
the distribution of a random variable, and are useful for calculating probabilities and
finding moments (although the latter is better achieved with moment-generating functions).
This file also defines the continuous uniform distribution and proves some properties about
random variables with this distribution.
## Main definitions
* `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with
respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X`
is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`.
* `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`.
* `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform
distribution if it has a constant probability density function with a compact, non-null support.
## Main results
* `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician,
i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for
all measurable `g : E → F`.
* `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with
pdf `f` has expectation `∫ x, x * f x dx`.
* `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with
its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ`
is the Lebesgue measure.
## TODO
Ultimately, we would also like to define characteristic functions to describe distributions as
it exists for all random variables. However, to define this, we will need Fourier transforms
which we currently do not have.
-/
open scoped MeasureTheory NNReal ENNReal
open TopologicalSpace MeasureTheory Measure ProbabilityTheory
noncomputable section
namespace MeasureTheory
variable {Ω E : Type*} [MeasurableSpace E]
/-- A random variable `X : Ω → E` is said to have a probability density function (`HasPDF`)
with respect to the measure `ℙ` on `Ω` and `μ` on `E`
if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ`
and they have a Lebesgue decomposition (`HaveLebesgueDecomposition`). -/
class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
Prop where
protected aemeasurable' : AEMeasurable X ℙ
protected haveLebesgueDecomposition' : (map X ℙ).HaveLebesgueDecomposition μ
protected absolutelyContinuous' : map X ℙ ≪ μ
section HasPDF
variable {_ : MeasurableSpace Ω} {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E}
theorem hasPDF_iff :
HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ :=
⟨fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩, fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩⟩
theorem hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) :
HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by
rw [hasPDF_iff]
simp only [hX, true_and]
variable (X ℙ μ) in
@[measurability]
theorem HasPDF.aemeasurable [HasPDF X ℙ μ] : AEMeasurable X ℙ := HasPDF.aemeasurable' μ
instance HasPDF.haveLebesgueDecomposition [HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ :=
HasPDF.haveLebesgueDecomposition'
theorem HasPDF.absolutelyContinuous [HasPDF X ℙ μ] : map X ℙ ≪ μ := HasPDF.absolutelyContinuous'
/-- A random variable that `HasPDF` is quasi-measure-preserving. -/
theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E)
[HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ :=
{ measurable := h
absolutelyContinuous := HasPDF.absolutelyContinuous .. }
theorem HasPDF.congr (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ :=
⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition,
ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩
theorem HasPDF.congr_iff (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ :=
⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩
/-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/
theorem hasPDF_of_map_eq_withDensity (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ)
(h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by
refine ⟨hX, ?_, ?_⟩ <;> rw [h]
· rw [withDensity_congr_ae hf.ae_eq_mk]
exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk
· exact withDensity_absolutelyContinuous μ f
end HasPDF
/-- If `X` is a random variable, then `pdf X ℙ μ`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/
def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
E → ℝ≥0∞ :=
(map X ℙ).rnDeriv μ
theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} :
pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl
theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
{X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by
rw [pdf_def, map_of_not_aemeasurable hX]
exact rnDeriv_zero μ
theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
{μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 :=
rnDeriv_of_not_haveLebesgueDecomposition h
theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
(X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by
contrapose! h
exact pdf_of_not_aemeasurable h
theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E}
(hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by
refine ⟨?_, ?_, hac⟩
· exact aemeasurable_of_pdf_ne_zero X hpdf
· contrapose! hpdf
have := pdf_of_not_haveLebesgueDecomposition hpdf
filter_upwards using congrFun this
@[measurability]
theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by
exact measurable_rnDeriv _ _
theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ :=
withDensity_rnDeriv_le _ _
theorem setLIntegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) (s : Set E) :
∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by
apply (withDensity_apply_le _ s).trans
exact withDensity_pdf_le_map _ _ _ s
theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] :
map X ℙ = μ.withDensity (pdf X ℙ μ) := by
rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous]
theorem map_eq_setLIntegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E}
(hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by
rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ]
namespace pdf
variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by
rw [pdf_def, pdf_def, map_congr hXY]
theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] :
∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by
rw [← setLIntegral_univ, ← map_eq_setLIntegral_pdf X ℙ μ MeasurableSet.univ,
map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ]
theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by
rw [map_eq_withDensity_pdf X ℙ μ]
apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf
rw [lintegral_eq_measure_univ]
exact measure_ne_top _ _
theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f :=
map_eq_withDensity_pdf X ℙ μ ▸
withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf
nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} :
∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ :=
rnDeriv_lt_top (map X ℙ) μ
nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} :
(fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ :=
ofReal_toReal_ae_eq ae_lt_top
section IntegralPDFMul
/-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/
theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞}
(hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by
rw [pdf_def,
← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) :
Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by
rw [← Function.comp_def,
← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous]
rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
/-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable
function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ`
where `μ` is a measure on the codomain of `X`. -/
theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by
rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous,
withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
end IntegralPDFMul
section
variable {F : Type*} [MeasurableSpace F] {ν : Measure F} (X : Ω → E) [HasPDF X ℙ μ] {g : E → F}
/-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving`
map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`.
`quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a
probability measure and a real-valued random variable. -/
theorem quasiMeasurePreserving_hasPDF (hg : QuasiMeasurePreserving g μ ν)
(hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) : HasPDF (g ∘ X) ℙ ν := by
have hgm : AEMeasurable g (map X ℙ) := hg.aemeasurable.mono_ac HasPDF.absolutelyContinuous
rw [hasPDF_iff, ← AEMeasurable.map_map_of_aemeasurable hgm (HasPDF.aemeasurable X ℙ μ)]
refine ⟨hg.measurable.comp_aemeasurable (HasPDF.aemeasurable _ _ μ), hmap, ?_⟩
exact (HasPDF.absolutelyContinuous.map hg.1).trans hg.2
theorem quasiMeasurePreserving_hasPDF' [SFinite ℙ] [SigmaFinite ν]
(hg : QuasiMeasurePreserving g μ ν) : HasPDF (g ∘ X) ℙ ν :=
quasiMeasurePreserving_hasPDF X hg inferInstance
end
section Real
variable {X : Ω → ℝ}
nonrec theorem _root_.Real.hasPDF_iff [SFinite ℙ] :
HasPDF X ℙ ↔ AEMeasurable X ℙ ∧ map X ℙ ≪ volume := by
rw [hasPDF_iff, and_iff_right (inferInstance : HaveLebesgueDecomposition _ _)]
/-- A real-valued random variable `X` `HasPDF X ℙ λ` (where `λ` is the Lebesgue measure) if and
only if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `λ`. -/
nonrec theorem _root_.Real.hasPDF_iff_of_aemeasurable [SFinite ℙ] (hX : AEMeasurable X ℙ) :
HasPDF X ℙ ↔ map X ℙ ≪ volume := by
rw [Real.hasPDF_iff, and_iff_right hX]
variable [IsFiniteMeasure ℙ]
/-- If `X` is a real-valued random variable that has pdf `f`, then the expectation of `X` equals
`∫ x, x * f x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_mul_eq_integral [HasPDF X ℙ] : ∫ x, x * (pdf X ℙ volume x).toReal = ∫ x, X x ∂ℙ :=
calc
_ = ∫ x, (pdf X ℙ volume x).toReal * x := by congr with x; exact mul_comm _ _
_ = _ := integral_pdf_smul measurable_id.aestronglyMeasurable
theorem hasFiniteIntegral_mul {f : ℝ → ℝ} {g : ℝ → ℝ≥0∞} (hg : pdf X ℙ =ᵐ[volume] g)
(hgi : ∫⁻ x, ‖f x‖ₑ * g x ≠ ∞) :
HasFiniteIntegral fun x => f x * (pdf X ℙ volume x).toReal := by
rw [hasFiniteIntegral_iff_enorm]
have : (fun x => ‖f x‖ₑ * g x) =ᵐ[volume] fun x => ‖f x * (pdf X ℙ volume x).toReal‖ₑ := by
refine ae_eq_trans ((ae_eq_refl _).fun_mul (ae_eq_trans hg.symm ofReal_toReal_ae_eq.symm)) ?_
simp_rw [← smul_eq_mul, enorm_smul, smul_eq_mul]
refine .fun_mul (ae_eq_refl _) ?_
simp only [Real.enorm_eq_ofReal ENNReal.toReal_nonneg, ae_eq_refl]
rwa [lt_top_iff_ne_top, ← lintegral_congr_ae this]
end Real
section TwoVariables
variable {F : Type*} [MeasurableSpace F] {ν : Measure F} {X : Ω → E} {Y : Ω → F}
/-- Random variables are independent iff their joint density is a product of marginal densities. -/
theorem indepFun_iff_pdf_prod_eq_pdf_mul_pdf
[IsFiniteMeasure ℙ] [SigmaFinite μ] [SigmaFinite ν] [HasPDF (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν)] :
IndepFun X Y ℙ ↔
pdf (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν) =ᵐ[μ.prod ν] fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 := by
have : HasPDF X ℙ μ := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (fun ω ↦ (X ω, Y ω))
quasiMeasurePreserving_fst
have : HasPDF Y ℙ ν := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (fun ω ↦ (X ω, Y ω))
quasiMeasurePreserving_snd
have h₀ : (ℙ.map X).prod (ℙ.map Y) =
(μ.prod ν).withDensity fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 :=
prod_eq fun s t hs ht ↦ by rw [withDensity_apply _ (hs.prod ht), ← prod_restrict,
lintegral_prod_mul (measurable_pdf X ℙ μ).aemeasurable (measurable_pdf Y ℙ ν).aemeasurable,
map_eq_setLIntegral_pdf X ℙ μ hs, map_eq_setLIntegral_pdf Y ℙ ν ht]
rw [indepFun_iff_map_prod_eq_prod_map_map (HasPDF.aemeasurable X ℙ μ) (HasPDF.aemeasurable Y ℙ ν),
← eq_of_map_eq_withDensity, h₀]
exact (((measurable_pdf X ℙ μ).comp measurable_fst).mul
((measurable_pdf Y ℙ ν).comp measurable_snd)).aemeasurable
end TwoVariables
end pdf
end MeasureTheory
section Group
namespace ProbabilityTheory
variable {Ω G : Type*} {mΩ : MeasurableSpace Ω} {ℙ : Measure Ω} [Group G] {mG : MeasurableSpace G}
[MeasurableMul₂ G] [MeasurableInv G] {μ : Measure G} [IsMulLeftInvariant μ] {X Y : Ω → G}
@[to_additive]
theorem IndepFun.mul_hasPDF' [SFinite μ] [HasPDF X ℙ μ] [HasPDF Y ℙ μ]
(σX : SigmaFinite (ℙ.map X)) (σY : SigmaFinite (ℙ.map Y)) (hXY : IndepFun X Y ℙ) :
HasPDF (X * Y) ℙ μ := by
have : AEMeasurable X ℙ := HasPDF.aemeasurable' μ
have : AEMeasurable Y ℙ := HasPDF.aemeasurable' μ
rw [hasPDF_iff_of_aemeasurable (by fun_prop),
hXY.map_mul_eq_map_mconv_map₀' (by fun_prop) (by fun_prop) σX σY]
refine ⟨?_, mconv_absolutelyContinuous HasPDF.absolutelyContinuous⟩
apply HaveLebesgueDecomposition.mconv <;> exact HasPDF.absolutelyContinuous
@[to_additive]
theorem IndepFun.mul_hasPDF [SFinite μ] [HasPDF X ℙ μ] [HasPDF Y ℙ μ] [IsFiniteMeasure ℙ]
(hXY : IndepFun X Y ℙ) : HasPDF (X * Y) ℙ μ := by
apply hXY.mul_hasPDF' <;> apply IsFiniteMeasure.toSigmaFinite
@[to_additive]
theorem IndepFun.pdf_mul_eq_mlconvolution_pdf' [SigmaFinite μ] [HasPDF X ℙ μ] [HasPDF Y ℙ μ]
(σX : SigmaFinite (ℙ.map X)) (σY : SigmaFinite (ℙ.map Y)) (hXY : IndepFun X Y ℙ) :
pdf (X * Y) ℙ μ =ᵐ[μ] pdf X ℙ μ ⋆ₘₗ[μ] pdf Y ℙ μ := by
rw [pdf, hXY.map_mul_eq_map_mconv_map₀' (HasPDF.aemeasurable' μ) (HasPDF.aemeasurable' μ) σX σY]
apply rnDeriv_mconv' <;> exact HasPDF.absolutelyContinuous
@[to_additive]
theorem IndepFun.pdf_mul_eq_mlconvolution_pdf [SFinite μ] [HasPDF X ℙ μ] [HasPDF Y ℙ μ]
[IsFiniteMeasure ℙ] (hXY : IndepFun X Y ℙ) :
pdf (X * Y) ℙ μ =ᵐ[μ] pdf X ℙ μ ⋆ₘₗ[μ] pdf Y ℙ μ := by
rw [pdf, hXY.map_mul_eq_map_mconv_map₀ (HasPDF.aemeasurable' μ) (HasPDF.aemeasurable' μ)]
apply rnDeriv_mconv <;> exact HasPDF.absolutelyContinuous
end ProbabilityTheory
end Group |
.lake/packages/mathlib/Mathlib/Probability/StrongLaw.lean | import Mathlib.Probability.IdentDistrib
import Mathlib.Probability.Independence.Integrable
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.Analysis.SpecificLimits.FloorPow
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Asymptotics.SpecificAsymptotics
/-!
# The strong law of large numbers
We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`:
If `X n` is a sequence of independent identically distributed integrable random
variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`.
We give here the strong version, due to Etemadi, that only requires pairwise independence.
This file also contains the Lᵖ version of the strong law of large numbers provided by
`ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to
`𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ.
## Implementation
The main point is to prove the result for real-valued random variables, as the general case
of Banach-space-valued random variables follows from this case and approximation by simple
functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`.
We follow the proof by Etemadi
[Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law],
which goes as follows.
It suffices to prove the result for nonnegative `X`, as one can prove the general result by
splitting a general `X` into its positive part and negative part.
Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent
random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that
* Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by
`1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`).
* Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost
surely to `0`. This follows from a variance control, as
```
∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε)
≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality)
≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2)
≤ ∑_i (C/i^2) 𝔼[Yᵢ^2]
≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`)
```
* As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along
the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely.
* To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and
that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small.
-/
noncomputable section
open MeasureTheory Filter Finset Asymptotics
open Set (indicator)
open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal
open scoped Function -- required for scoped `on` notation
namespace ProbabilityTheory
/-! ### Prerequisites on truncations -/
section Truncation
variable {α : Type*}
/-- Truncating a real-valued function to the interval `(-A, A]`. -/
def truncation (f : α → ℝ) (A : ℝ) :=
indicator (Set.Ioc (-A) A) id ∘ f
variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ}
theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ)
{A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by
apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable
exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable
theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by
simp only [truncation, Set.indicator, id, Function.comp_apply]
split_ifs with h
· exact abs_le_abs h.2 (neg_le.2 h.1.le)
· simp [abs_nonneg]
@[simp]
theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl
theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by
simp only [truncation, indicator, id, Function.comp_apply]
split_ifs
· exact le_rfl
· simp [abs_nonneg]
theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) :
truncation f A x = f x := by
simp only [truncation, indicator, id, Function.comp_apply, ite_eq_left_iff]
intro H
apply H.elim
simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le]
theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) :
truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by
ext x
rcases (h x).lt_or_eq with (hx | hx)
· simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply]
by_cases h'x : f x ≤ A
· have : -A < f x := by linarith [h x]
simp only [this, true_and]
· simp only [h'x, and_false]
· simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self]
theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x :=
Set.indicator_apply_nonneg fun _ => h
theorem _root_.MeasureTheory.AEStronglyMeasurable.memLp_truncation [IsFiniteMeasure μ]
(hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : MemLp (truncation f A) p μ :=
MemLp.of_bound hf.truncation |A| (Eventually.of_forall fun _ => abs_truncation_le_bound _ _ _)
theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ]
(hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by
rw [← memLp_one_iff_integrable]; exact hf.memLp_truncation
theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A)
{n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by
have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc
change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _
rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le,
← integral_indicator M]
· simp only [indicator, zero_pow hn, id, ite_pow]
· linarith
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ}
{n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) :
∫ x, truncation f A x ^ n ∂μ = ∫ y in 0..A, y ^ n ∂Measure.map f μ := by
have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc
have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc
rw [truncation_eq_of_nonneg h'f]
change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _
rcases le_or_gt 0 A with (hA | hA)
· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA,
← integral_indicator M]
· simp only [indicator, zero_pow hn, id, ite_pow]
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
· rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le,
← integral_indicator M']
· simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero,
zero_eq_neg]
apply integral_eq_zero_of_ae
have : ∀ᵐ x ∂Measure.map f μ, (0 : ℝ) ≤ x :=
(ae_map_iff hf.aemeasurable measurableSet_Ici).2 (Eventually.of_forall h'f)
filter_upwards [this] with x hx
simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp]
intro _ h''x
have : x = 0 := by linarith
simp [this, zero_pow hn]
· exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ}
(hA : 0 ≤ A) : ∫ x, truncation f A x ∂μ = ∫ y in -A..A, y ∂Measure.map f μ := by
simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero
theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ}
(h'f : 0 ≤ f) : ∫ x, truncation f A x ∂μ = ∫ y in 0..A, y ∂Measure.map f μ := by
simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f
theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f μ) (h'f : 0 ≤ f) {A : ℝ} :
∫ x, truncation f A x ∂μ ≤ ∫ x, f x ∂μ := by
apply integral_mono_of_nonneg
(Eventually.of_forall fun x => ?_) hf (Eventually.of_forall fun x => ?_)
· exact truncation_nonneg _ (h'f x)
· calc
truncation f A x ≤ |truncation f A x| := le_abs_self _
_ ≤ |f x| := abs_truncation_le_abs_self _ _ _
_ = f x := abs_of_nonneg (h'f x)
/-- If a function is integrable, then the integral of its truncated versions converges to the
integral of the whole function. -/
theorem tendsto_integral_truncation {f : α → ℝ} (hf : Integrable f μ) :
Tendsto (fun A => ∫ x, truncation f A x ∂μ) atTop (𝓝 (∫ x, f x ∂μ)) := by
refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_
· exact Eventually.of_forall fun A ↦ hf.aestronglyMeasurable.truncation
· filter_upwards with A
filter_upwards with x
rw [Real.norm_eq_abs]
exact abs_truncation_le_abs_self _ _ _
· exact hf.abs
· filter_upwards with x
apply tendsto_const_nhds.congr' _
filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA
exact (truncation_eq_self hA).symm
theorem IdentDistrib.truncation {β : Type*} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ}
{g : β → ℝ} (h : IdentDistrib f g μ ν) {A : ℝ} :
IdentDistrib (truncation f A) (truncation g A) μ ν :=
h.comp (measurable_id.indicator measurableSet_Ioc)
end Truncation
section StrongLawAeReal
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
section MomentEstimates
theorem sum_prob_mem_Ioc_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) {K : ℕ} {N : ℕ}
(hKN : K ≤ N) :
∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} ≤ ENNReal.ofReal (𝔼[X] + 1) := by
let ρ : Measure ℝ := Measure.map X ℙ
haveI : IsProbabilityMeasure ρ := Measure.isProbabilityMeasure_map hint.aemeasurable
have A : ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ ≤ 𝔼[X] + 1 :=
calc
∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ =
∑ j ∈ range K, ∑ i ∈ Ico j N, ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
apply sum_congr rfl fun j hj => ?_
rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)]
intro k _
exact continuous_const.intervalIntegrable _ _
_ = ∑ i ∈ range N, ∑ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
simp_rw [sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add simp Nat.lt_succ_iff)
_ ≤ ∑ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by
gcongr with i
simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min]
refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_
apply intervalIntegral.integral_nonneg
· simp only [le_add_iff_nonneg_right, zero_le_one]
· simp only [zero_le_one, imp_true_iff]
_ ≤ ∑ i ∈ range N, ∫ x in i..(i + 1 : ℕ), x + 1 ∂ρ := by
gcongr with i
have I : (i : ℝ) ≤ (i + 1 : ℕ) := by
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
simp_rw [intervalIntegral.integral_of_le I, ← integral_const_mul]
apply setIntegral_mono_on
· exact continuous_const.integrableOn_Ioc
· exact (continuous_id.add continuous_const).integrableOn_Ioc
· exact measurableSet_Ioc
· intro x hx
simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx
simp [hx.1.le]
_ = ∫ x in 0..N, x + 1 ∂ρ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
· norm_cast
· exact (continuous_id.add continuous_const).intervalIntegrable _ _
_ = ∫ x in 0..N, x ∂ρ + ∫ x in 0..N, 1 ∂ρ := by
rw [intervalIntegral.integral_add]
· exact continuous_id.intervalIntegrable _ _
· exact continuous_const.intervalIntegrable _ _
_ = 𝔼[truncation X N] + ∫ x in 0..N, 1 ∂ρ := by
rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
_ ≤ 𝔼[X] + ∫ x in 0..N, 1 ∂ρ := by
grw [integral_truncation_le_integral_of_nonneg hint hnonneg]
_ ≤ 𝔼[X] + 1 := by
gcongr
rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)]
simp only [integral_const, measureReal_restrict_apply', measurableSet_Ioc, Set.univ_inter,
Algebra.id.smul_eq_mul, mul_one]
rw [← ENNReal.toReal_one]
exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one
have B : ∀ a b, ℙ {ω | X ω ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) ∂ρ) := by
intro a b
rw [ofReal_setIntegral_one ρ _,
Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc]
rfl
calc
∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} =
∑ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by simp_rw [B]
_ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by
simp [ENNReal.ofReal_sum_of_nonneg]
_ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) ∂ρ) := by
congr 1
refine sum_congr rfl fun j hj => ?_
rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))]
_ ≤ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A
theorem tsum_prob_mem_Ioi_lt_top {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) :
(∑' j : ℕ, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by
suffices ∀ K : ℕ, ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)} ≤ ENNReal.ofReal (𝔼[X] + 1) from
(le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds
(Eventually.of_forall this)).trans_lt ENNReal.ofReal_lt_top
intro K
have A : Tendsto (fun N : ℕ => ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N}) atTop
(𝓝 (∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)})) := by
refine tendsto_finset_sum _ fun i _ => ?_
have : {ω | X ω ∈ Set.Ioi (i : ℝ)} = ⋃ N : ℕ, {ω | X ω ∈ Set.Ioc (i : ℝ) N} := by
apply Set.Subset.antisymm _ _
· intro ω hω
obtain ⟨N, hN⟩ : ∃ N : ℕ, X ω ≤ N := exists_nat_ge (X ω)
exact Set.mem_iUnion.2 ⟨N, hω, hN⟩
· simp +contextual only [Set.mem_Ioc, Set.mem_Ioi,
Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff]
rw [this]
apply tendsto_measure_iUnion_atTop
intro m n hmn x hx
exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩
apply le_of_tendsto_of_tendsto A tendsto_const_nhds
filter_upwards [Ici_mem_atTop K] with N hN
exact sum_prob_mem_Ioc_le hint hnonneg hN
theorem sum_variance_truncation_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) (K : ℕ) :
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≤ 2 * 𝔼[X] := by
set Y := fun n : ℕ => truncation X n
let ρ : Measure ℝ := Measure.map X ℙ
have Y2 : ∀ n, 𝔼[Y n ^ 2] = ∫ x in 0..n, x ^ 2 ∂ρ := by
intro n
change 𝔼[fun x => Y n x ^ 2] = _
rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg]
calc
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] =
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in 0..j, x ^ 2 ∂ρ := by simp_rw [Y2]
_ = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∑ k ∈ range j, ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
congr 1 with j
congr 1
rw [intervalIntegral.sum_integral_adjacent_intervals]
· norm_cast
intro k _
exact (continuous_id.pow _).intervalIntegrable _ _
_ = ∑ k ∈ range K, (∑ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;>
aesop (add unsafe lt_trans)
_ ≤ ∑ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by
gcongr with k
· refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _
simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one]
· apply sum_Ioo_inv_sq_le
_ ≤ ∑ k ∈ range K, ∫ x in k..(k + 1 : ℕ), 2 * x ∂ρ := by
gcongr with k
have Ik : (k : ℝ) ≤ (k + 1 : ℕ) := by simp
rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik,
intervalIntegral.integral_of_le Ik]
refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_
· apply Continuous.integrableOn_Ioc
exact continuous_const.mul (continuous_pow 2)
· apply Continuous.integrableOn_Ioc
exact continuous_const.mul continuous_id'
· calc
2 / (↑k + 1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring
_ ≤ 1 * (2 * x) := by
have : 0 < x := k.cast_nonneg.trans_lt hx.1
gcongr
exact (div_le_one <| by positivity).2 <| mod_cast hx.2
_ = 2 * x := by rw [one_mul]
_ = 2 * ∫ x in (0 : ℝ)..K, x ∂ρ := by
rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_]
swap; · exact (continuous_const.mul continuous_id').intervalIntegrable _ _
rw [intervalIntegral.integral_const_mul]
norm_cast
_ ≤ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by
rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg]
exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two
end MomentEstimates
/-! Proof of the strong law of large numbers (almost sure version, assuming only
pairwise independence) for nonnegative random variables, following Etemadi's proof. -/
section StrongLawNonneg
variable (X : ℕ → Ω → ℝ) (hint : Integrable (X 0))
(hindep : Pairwise (IndepFun on X)) (hident : ∀ i, IdentDistrib (X i) (X 0))
(hnonneg : ∀ i ω, 0 ≤ X i ω)
include hint hindep hident hnonneg in
/-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to
the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `ε > 0`.
This follows from a variance control. -/
theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {ε : ℝ} (εpos : 0 < ε) : ∀ᵐ ω, ∀ᶠ n : ℕ in atTop,
|∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]| <
ε * ⌊c ^ n⌋₊ := by
/- Let `S n = ∑ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that
`|S k - 𝔼[S k]| / k ≤ ε` along the sequence of powers of `c`. For this, we apply Borel-Cantelli:
it suffices to show that the converse probabilities are summable. From Chebyshev inequality,
this will follow from a variance control `∑' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in
`I2` using pairwise independence to expand the variance of the sum as the sum of the variances,
and then a straightforward but tedious computation (essentially boiling down to the fact that
the sum of `1/(c ^ i)^2` beyond a threshold `j` is comparable to `1/j^2`).
Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer
parts everywhere, making things more painful. We write `u i = ⌊c^i⌋₊` for brevity. -/
have c_pos : 0 < c := zero_lt_one.trans c_one
have hX : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i =>
(hident i).symm.aestronglyMeasurable_snd hint.1
have A : ∀ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i =>
stronglyMeasurable_id.indicator measurableSet_Ioc
set Y := fun n : ℕ => truncation (X n) n
set S := fun n => ∑ i ∈ range n, Y i with hS
let u : ℕ → ℕ := fun n => ⌊c ^ n⌋₊
have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_right_mono₀ c_one.le hij)
have I1 : ∀ K, ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ 2 * 𝔼[X 0] := by
intro K
calc
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤
∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by
gcongr with j
rw [(hident j).truncation.variance_eq]
exact variance_le_expectation_sq (hX 0).truncation
_ ≤ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K
let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0])
have I2 : ∀ N, ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≤ C := by
intro N
calc
∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] =
∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * ∑ j ∈ range (u i), Var[Y j] := by
congr 1 with i
congr 1
rw [hS, IndepFun.variance_sum]
· intro j _
exact (hident j).aestronglyMeasurable_fst.memLp_truncation
· intro k _ l _ hkl
exact (hindep hkl).comp (A k).measurable (A l).measurable
_ = ∑ j ∈ range (u (N - 1)), (∑ i ∈ range N with j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by
simp_rw [mul_sum, sum_mul, sum_sigma']
refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_
· simp only [mem_sigma, mem_range, mem_filter, and_imp,
Sigma.forall]
exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩
all_goals simp
_ ≤ ∑ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by
gcongr ∑ _ ∈ _, ?_ with j
rcases eq_zero_or_pos j with (rfl | hj)
· simp only [Nat.cast_zero]
simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl]
apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _)
convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2
· simp only [u, Nat.cast_lt]
· simp only [u, one_div]
_ = c ^ 5 * (c - 1)⁻¹ ^ 3 * ∑ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by
simp_rw [mul_sum, div_eq_mul_inv, mul_assoc]
_ ≤ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by
apply mul_le_mul_of_nonneg_left (I1 _)
apply mul_nonneg (pow_nonneg c_pos.le _)
exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _
have I3 : ∀ N, ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤
ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by
intro N
calc
∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤
∑ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * ε) ^ 2) := by
gcongr with i _
apply meas_ge_le_variance_div_sq
· exact memLp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memLp_truncation
· apply mul_pos (Nat.cast_pos.2 _) εpos
refine zero_lt_one.trans_le ?_
apply Nat.le_floor
rw [Nat.cast_one]
apply one_le_pow₀ c_one.le
_ = ENNReal.ofReal (∑ i ∈ range N, Var[S (u i)] / (u i * ε) ^ 2) := by
rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_]
exact div_nonneg (variance_nonneg _ _) (sq_nonneg _)
_ ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by
apply ENNReal.ofReal_le_ofReal
simp_rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ (ε⁻¹), mul_pow, mul_assoc,
← mul_sum]
gcongr
simpa only [inv_pow] using I2 N
have I4 : (∑' i, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|}) < ∞ :=
(le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt
ENNReal.ofReal_lt_top
filter_upwards [ae_eventually_notMem I4.ne] with ω hω
simp_rw [S, not_le, mul_comm, sum_apply] at hω
convert hω; simp only [Y, u, sum_apply]
include hint hindep hident hnonneg in
/-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers
(with respect to the truncated expectation) along the sequence
`c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `ε`. -/
theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω -
𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by
obtain ⟨v, -, v_pos, v_lim⟩ :
∃ v : ℕ → ℝ, StrictAnti v ∧ (∀ n : ℕ, 0 < v n) ∧ Tendsto v atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ)
have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i)
filter_upwards [ae_all_iff.2 this] with ω hω
apply Asymptotics.isLittleO_iff.2 fun ε εpos => ?_
obtain ⟨i, hi⟩ : ∃ i, v i < ε := ((tendsto_order.1 v_lim).2 ε εpos).exists
filter_upwards [hω i] with n hn
simp only [Real.norm_eq_abs, Nat.abs_cast]
exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _))
include hint hident in
/-- The expectation of the truncated version of `Xᵢ` behaves asymptotically like the whole
expectation. This follows from convergence and Cesàro averaging. -/
theorem strong_law_aux3 :
(fun n => 𝔼[∑ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : ℕ → ℝ) := by
have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by
convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1
ext i
exact (hident i).truncation.integral_eq
convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1
ext1 n
simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj]
rw [integral_finset_sum _ fun i _ => ?_]
exact ((hident i).symm.integrable_snd hint).1.integrable_truncation
include hint hindep hident hnonneg in
/-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers
(with respect to the original expectation) along the sequence
`c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the
fact that the truncated and the original expectations have the same asymptotic behavior. -/
theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop]
fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by
filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with ω hω
have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop :=
tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one)
convert hω.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1
ext1 n
simp
include hint hident hnonneg in
/-- The truncated and non-truncated versions of `Xᵢ` have the same asymptotic behavior, as they
almost surely coincide at all but finitely many steps. This follows from a probability computation
and Borel-Cantelli. -/
theorem strong_law_aux5 :
∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range n, truncation (X i) i ω - ∑ i ∈ range n, X i ω) =o[atTop]
fun n : ℕ => (n : ℝ) := by
have A : (∑' j : ℕ, ℙ {ω | X j ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by
convert tsum_prob_mem_Ioi_lt_top hint (hnonneg 0) using 2
ext1 j
exact (hident j).measure_mem_eq measurableSet_Ioi
have B : ∀ᵐ ω, Tendsto (fun n : ℕ => truncation (X n) n ω - X n ω) atTop (𝓝 0) := by
filter_upwards [ae_eventually_notMem A.ne] with ω hω
apply tendsto_const_nhds.congr' _
filter_upwards [hω, Ioi_mem_atTop 0] with n hn npos
simp only [truncation, indicator, Set.mem_Ioc, id, Function.comp_apply]
split_ifs with h
· exact (sub_self _).symm
· have : -(n : ℝ) < X n ω := by
apply lt_of_lt_of_le _ (hnonneg n ω)
simpa only [Right.neg_neg_iff, Nat.cast_pos] using npos
simp only [this, true_and, not_le] at h
exact (hn h).elim
filter_upwards [B] with ω hω
convert isLittleO_sum_range_of_tendsto_zero hω using 1
ext n
rw [sum_sub_distrib]
include hint hindep hident hnonneg in
/-- `Xᵢ` satisfies the strong law of large numbers along the sequence
`c^n`, for any `c > 1`. This follows from the version for the truncated `Xᵢ`, and the fact that
`Xᵢ` and its truncated version have the same asymptotic behavior. -/
theorem strong_law_aux6 {c : ℝ} (c_one : 1 < c) :
∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c ^ n⌋₊, X i ω) / ⌊c ^ n⌋₊) atTop (𝓝 𝔼[X 0]) := by
have H : ∀ n : ℕ, (0 : ℝ) < ⌊c ^ n⌋₊ := by
intro n
refine zero_lt_one.trans_le ?_
simp only [Nat.one_le_cast, Nat.one_le_floor_iff, one_le_pow₀ c_one.le]
filter_upwards [strong_law_aux4 X hint hindep hident hnonneg c_one,
strong_law_aux5 X hint hident hnonneg] with ω hω h'ω
rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ]
have L : (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, X i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop] fun n =>
(⌊c ^ n⌋₊ : ℝ) := by
have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop :=
tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one)
convert hω.sub (h'ω.comp_tendsto A) using 1
ext1 n
simp only [Function.comp_apply, sub_sub_sub_cancel_left]
convert L.mul_isBigO (isBigO_refl (fun n : ℕ => (⌊c ^ n⌋₊ : ℝ)⁻¹) atTop) using 1 <;>
(ext1 n; field [(H n).ne'])
include hint hindep hident hnonneg in
/-- `Xᵢ` satisfies the strong law of large numbers along all integers. This follows from the
corresponding fact along the sequences `c^n`, and the fact that any integer can be sandwiched
between `c^n` and `c^(n+1)` with comparably small error if `c` is close enough to `1`
(which is formalized in `tendsto_div_of_monotone_of_tendsto_div_floor_pow`). -/
theorem strong_law_aux7 :
∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 𝔼[X 0]) := by
obtain ⟨c, -, cone, clim⟩ :
∃ c : ℕ → ℝ, StrictAnti c ∧ (∀ n : ℕ, 1 < c n) ∧ Tendsto c atTop (𝓝 1) :=
exists_seq_strictAnti_tendsto (1 : ℝ)
have : ∀ k, ∀ᵐ ω,
Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c k ^ n⌋₊, X i ω) / ⌊c k ^ n⌋₊) atTop (𝓝 𝔼[X 0]) :=
fun k => strong_law_aux6 X hint hindep hident hnonneg (cone k)
filter_upwards [ae_all_iff.2 this] with ω hω
apply tendsto_div_of_monotone_of_tendsto_div_floor_pow _ _ _ c cone clim _
· intro m n hmn
exact sum_le_sum_of_subset_of_nonneg (range_mono hmn) fun i _ _ => hnonneg i ω
· exact hω
end StrongLawNonneg
/-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent
identically distributed integrable real-valued random variables, then `∑ i ∈ range n, X i / n`
converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only
requires pairwise independence. Superseded by `strong_law_ae`, which works for random variables
taking values in any Banach space. -/
theorem strong_law_ae_real {Ω : Type*} {m : MeasurableSpace Ω} {μ : Measure Ω}
(X : ℕ → Ω → ℝ) (hint : Integrable (X 0) μ)
(hindep : Pairwise ((· ⟂ᵢ[μ] ·) on X))
(hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) :
∀ᵐ ω ∂μ, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 μ[X 0]) := by
let mΩ : MeasureSpace Ω := ⟨μ⟩
-- first get rid of the trivial case where the space is not a probability space
by_cases h : ∀ᵐ ω, X 0 ω = 0
· have I : ∀ᵐ ω, ∀ i, X i ω = 0 := by
rw [ae_all_iff]
intro i
exact (hident i).symm.ae_snd (p := fun x ↦ x = 0) measurableSet_eq h
filter_upwards [I] with ω hω
simpa [hω] using (integral_eq_zero_of_ae h).symm
have : IsProbabilityMeasure μ :=
hint.isProbabilityMeasure_of_indepFun (X 0) (X 1) h (hindep zero_ne_one)
-- then consider separately the positive and the negative part, and apply the result
-- for nonnegative functions to them.
let pos : ℝ → ℝ := fun x => max x 0
let neg : ℝ → ℝ := fun x => max (-x) 0
have posm : Measurable pos := measurable_id'.max measurable_const
have negm : Measurable neg := measurable_id'.neg.max measurable_const
have A : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (pos ∘ X i) ω) / n) atTop (𝓝 𝔼[pos ∘ X 0]) :=
strong_law_aux7 _ hint.pos_part (fun i j hij => (hindep hij).comp posm posm)
(fun i => (hident i).comp posm) fun i ω => le_max_right _ _
have B : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (neg ∘ X i) ω) / n) atTop (𝓝 𝔼[neg ∘ X 0]) :=
strong_law_aux7 _ hint.neg_part (fun i j hij => (hindep hij).comp negm negm)
(fun i => (hident i).comp negm) fun i ω => le_max_right _ _
filter_upwards [A, B] with ω hωpos hωneg
convert hωpos.sub hωneg using 2
· simp only [pos, neg, ← sub_div, ← sum_sub_distrib, max_zero_sub_max_neg_zero_eq_self,
Function.comp_apply]
· simp only [pos, neg, ← integral_sub hint.pos_part hint.neg_part,
max_zero_sub_max_neg_zero_eq_self, Function.comp_apply, mΩ]
end StrongLawAeReal
section StrongLawVectorSpace
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ]
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
[MeasurableSpace E]
open Set TopologicalSpace
/-- Preliminary lemma for the strong law of large numbers for vector-valued random variables:
the composition of the random variables with a simple function satisfies the strong law of large
numbers. -/
lemma strong_law_ae_simpleFunc_comp (X : ℕ → Ω → E) (h' : Measurable (X 0))
(hindep : Pairwise ((· ⟂ᵢ[μ] ·) on X))
(hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) (φ : SimpleFunc E E) :
∀ᵐ ω ∂μ,
Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, φ (X i ω))) atTop (𝓝 μ[φ ∘ (X 0)]) := by
-- this follows from the one-dimensional version when `φ` takes a single value, and is then
-- extended to the general case by linearity.
classical
refine SimpleFunc.induction (motive := fun ψ ↦ ∀ᵐ ω ∂μ,
Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, ψ (X i ω))) atTop (𝓝 μ[ψ ∘ (X 0)])) ?_ ?_ φ
· intro c s hs
simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const,
SimpleFunc.coe_zero, piecewise_eq_indicator, Function.comp_apply]
let F : E → ℝ := indicator s 1
have F_meas : Measurable F := (measurable_indicator_const_iff 1).2 hs
let Y : ℕ → Ω → ℝ := fun n ↦ F ∘ (X n)
have : ∀ᵐ (ω : Ω) ∂μ, Tendsto (fun (n : ℕ) ↦ (n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y i ω)
atTop (𝓝 μ[Y 0]) := by
simp only [smul_eq_mul, ← div_eq_inv_mul]
apply strong_law_ae_real
· exact SimpleFunc.integrable_of_isFiniteMeasure
((SimpleFunc.piecewise s hs (SimpleFunc.const _ (1 : ℝ))
(SimpleFunc.const _ (0 : ℝ))).comp (X 0) h')
· exact fun i j hij ↦ IndepFun.comp (hindep hij) F_meas F_meas
· exact fun i ↦ (hident i).comp F_meas
filter_upwards [this] with ω hω
have I : indicator s (Function.const E c) = (fun x ↦ (indicator s (1 : E → ℝ) x) • c) := by
ext
rw [← indicator_smul_const_apply]
congr! 1
ext
simp
simp only [I, integral_smul_const]
convert Tendsto.smul_const hω c using 1
simp [F, Y, ← sum_smul, smul_smul]
· rintro φ ψ - hφ hψ
filter_upwards [hφ, hψ] with ω hωφ hωψ
convert hωφ.add hωψ using 1
· simp [sum_add_distrib]
· congr 1
rw [← integral_add]
· rfl
· exact (φ.comp (X 0) h').integrable_of_isFiniteMeasure
· exact (ψ.comp (X 0) h').integrable_of_isFiniteMeasure
variable [BorelSpace E]
/-- Preliminary lemma for the strong law of large numbers for vector-valued random variables,
assuming measurability in addition to integrability. This is weakened to ae measurability in
the full version `ProbabilityTheory.strong_law_ae`. -/
lemma strong_law_ae_of_measurable
(X : ℕ → Ω → E) (hint : Integrable (X 0) μ) (h' : StronglyMeasurable (X 0))
(hindep : Pairwise ((· ⟂ᵢ[μ] ·) on X))
(hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) :
∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 μ[X 0]) := by
/- Choose a simple function `φ` such that `φ (X 0)` approximates well enough `X 0` -- this is
possible as `X 0` is strongly measurable. Then `φ (X n)` approximates well `X n`.
Then the strong law for `φ (X n)` implies the strong law for `X n`, up to a small
error controlled by `n⁻¹ ∑_{i=0}^{n-1} ‖X i - φ (X i)‖`. This one is also controlled thanks
to the one-dimensional law of large numbers: it converges ae to `𝔼[‖X 0 - φ (X 0)‖]`, which
is arbitrarily small for well-chosen `φ`. -/
let s : Set E := Set.range (X 0) ∪ {0}
have zero_s : 0 ∈ s := by simp [s]
have : SeparableSpace s := h'.separableSpace_range_union_singleton
have : Nonempty s := ⟨0, zero_s⟩
-- sequence of approximating simple functions.
let φ : ℕ → SimpleFunc E E :=
SimpleFunc.nearestPt (fun k => Nat.casesOn k 0 ((↑) ∘ denseSeq s) : ℕ → E)
let Y : ℕ → ℕ → Ω → E := fun k i ↦ (φ k) ∘ (X i)
-- strong law for `φ (X n)`
have A : ∀ᵐ ω ∂μ, ∀ k,
Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, Y k i ω)) atTop (𝓝 μ[Y k 0]) :=
ae_all_iff.2 (fun k ↦ strong_law_ae_simpleFunc_comp X h'.measurable hindep hident (φ k))
-- strong law for the error `‖X i - φ (X i)‖`
have B : ∀ᵐ ω ∂μ, ∀ k, Tendsto (fun n : ℕ ↦ (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n)
atTop (𝓝 μ[(fun ω ↦ ‖(X 0 - Y k 0) ω‖)]) := by
apply ae_all_iff.2 (fun k ↦ ?_)
let G : ℕ → E → ℝ := fun k x ↦ ‖x - φ k x‖
have G_meas : ∀ k, Measurable (G k) :=
fun k ↦ (measurable_id.sub_stronglyMeasurable (φ k).stronglyMeasurable).norm
have I : ∀ k i, (fun ω ↦ ‖(X i - Y k i) ω‖) = (G k) ∘ (X i) := fun k i ↦ rfl
apply strong_law_ae_real (fun i ω ↦ ‖(X i - Y k i) ω‖)
· exact (hint.sub ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure).norm
· unfold Function.onFun
simp_rw [I]
intro i j hij
exact (hindep hij).comp (G_meas k) (G_meas k)
· intro i
simp_rw [I]
apply (hident i).comp (G_meas k)
-- check that, when both convergences above hold, then the strong law is satisfied
filter_upwards [A, B] with ω hω h'ω
rw [tendsto_iff_norm_sub_tendsto_zero, tendsto_order]
refine ⟨fun c hc ↦ Eventually.of_forall (fun n ↦ hc.trans_le (norm_nonneg _)), ?_⟩
-- start with some positive `ε` (the desired precision), and fix `δ` with `3 δ < ε`.
intro ε (εpos : 0 < ε)
obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ δ + δ + δ < ε := ⟨ε/4, by positivity, by linarith⟩
-- choose `k` large enough so that `φₖ (X 0)` approximates well enough `X 0`, up to the
-- precision `δ`.
obtain ⟨k, hk⟩ : ∃ k, ∫ ω, ‖(X 0 - Y k 0) ω‖ ∂μ < δ := by
simp_rw [Pi.sub_apply, norm_sub_rev (X 0 _)]
exact ((tendsto_order.1 (tendsto_integral_norm_approxOn_sub h'.measurable hint)).2 δ
δpos).exists
have : ‖μ[Y k 0] - μ[X 0]‖ < δ := by
rw [norm_sub_rev, ← integral_sub hint]
· exact (norm_integral_le_integral_norm _).trans_lt hk
· exact ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure
-- consider `n` large enough for which the above convergences have taken place within `δ`.
have I : ∀ᶠ n in atTop, (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n < δ :=
(tendsto_order.1 (h'ω k)).2 δ hk
have J : ∀ᶠ (n : ℕ) in atTop, ‖(n : ℝ) ⁻¹ • (∑ i ∈ range n, Y k i ω) - μ[Y k 0]‖ < δ := by
specialize hω k
rw [tendsto_iff_norm_sub_tendsto_zero] at hω
exact (tendsto_order.1 hω).2 δ δpos
filter_upwards [I, J] with n hn h'n
-- at such an `n`, the strong law is realized up to `ε`.
calc
‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, X i ω - μ[X 0]‖
= ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω) +
((n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - μ[Y k 0]) + (μ[Y k 0] - μ[X 0])‖ := by
congr
simp only [sum_sub_distrib, smul_sub]
abel
_ ≤ ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω)‖ +
‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - μ[Y k 0]‖ + ‖μ[Y k 0] - μ[X 0]‖ :=
norm_add₃_le
_ ≤ (∑ i ∈ Finset.range n, ‖X i ω - Y k i ω‖) / n + δ + δ := by
gcongr
simp only [norm_smul, norm_inv, RCLike.norm_natCast,
div_eq_inv_mul]
gcongr
exact norm_sum_le _ _
_ ≤ δ + δ + δ := by
gcongr
exact hn.le
_ < ε := hδ
omit [IsProbabilityMeasure μ] in
/-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent
identically distributed integrable random variables taking values in a Banach space,
then `n⁻¹ • ∑ i ∈ range n, X i` converges almost surely to `𝔼[X 0]`. We give here the strong
version, due to Etemadi, that only requires pairwise independence. -/
theorem strong_law_ae (X : ℕ → Ω → E) (hint : Integrable (X 0) μ)
(hindep : Pairwise ((· ⟂ᵢ[μ] ·) on X))
(hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) :
∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 μ[X 0]) := by
-- First exclude the trivial case where the space is not a probability space
by_cases h : ∀ᵐ ω ∂μ, X 0 ω = 0
· have I : ∀ᵐ ω ∂μ, ∀ i, X i ω = 0 := by
rw [ae_all_iff]
intro i
exact (hident i).symm.ae_snd (p := fun x ↦ x = 0) measurableSet_eq h
filter_upwards [I] with ω hω
simpa [hω] using (integral_eq_zero_of_ae h).symm
have : IsProbabilityMeasure μ :=
hint.isProbabilityMeasure_of_indepFun (X 0) (X 1) h (hindep zero_ne_one)
-- we reduce to the case of strongly measurable random variables, by using `Y i` which is strongly
-- measurable and ae equal to `X i`.
have A : ∀ i, Integrable (X i) μ := fun i ↦ (hident i).integrable_iff.2 hint
let Y : ℕ → Ω → E := fun i ↦ (A i).1.mk (X i)
have B : ∀ᵐ ω ∂μ, ∀ n, X n ω = Y n ω :=
ae_all_iff.2 (fun i ↦ AEStronglyMeasurable.ae_eq_mk (A i).1)
have Yint : Integrable (Y 0) μ := Integrable.congr hint (AEStronglyMeasurable.ae_eq_mk (A 0).1)
have C : ∀ᵐ ω ∂μ,
Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹ • (∑ i ∈ range n, Y i ω)) atTop (𝓝 μ[Y 0]) := by
apply strong_law_ae_of_measurable Y Yint ((A 0).1.stronglyMeasurable_mk)
(fun i j hij ↦ IndepFun.congr (hindep hij) (A i).1.ae_eq_mk (A j).1.ae_eq_mk)
(fun i ↦ ((A i).1.identDistrib_mk.symm.trans (hident i)).trans (A 0).1.identDistrib_mk)
filter_upwards [B, C] with ω h₁ h₂
have : μ[X 0] = μ[Y 0] := integral_congr_ae (AEStronglyMeasurable.ae_eq_mk (A 0).1)
rw [this]
apply Tendsto.congr (fun n ↦ ?_) h₂
congr with i
exact (h₁ i).symm
end StrongLawVectorSpace
section StrongLawLp
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω}
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
[MeasurableSpace E] [BorelSpace E]
/-- **Strong law of large numbers**, Lᵖ version: if `X n` is a sequence of independent
identically distributed random variables in Lᵖ, then `n⁻¹ • ∑ i ∈ range n, X i`
converges in `Lᵖ` to `𝔼[X 0]`. -/
theorem strong_law_Lp {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (X : ℕ → Ω → E)
(hℒp : MemLp (X 0) p μ) (hindep : Pairwise ((· ⟂ᵢ[μ] ·) on X))
(hident : ∀ i, IdentDistrib (X i) (X 0) μ μ) :
Tendsto (fun (n : ℕ) => eLpNorm (fun ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω) - μ[X 0]) p μ)
atTop (𝓝 0) := by
-- First exclude the trivial case where the space is not a probability space
by_cases h : ∀ᵐ ω ∂μ, X 0 ω = 0
· have I : ∀ᵐ ω ∂μ, ∀ i, X i ω = 0 := by
rw [ae_all_iff]
intro i
exact (hident i).symm.ae_snd (p := fun x ↦ x = 0) measurableSet_eq h
have A (n : ℕ) : eLpNorm (fun ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω) - μ[X 0]) p μ = 0 := by
simp only [integral_eq_zero_of_ae h, sub_zero]
apply eLpNorm_eq_zero_of_ae_zero
filter_upwards [I] with ω hω
simp [hω]
simp [A]
-- Then use ae convergence and uniform integrability
have : IsProbabilityMeasure μ := MemLp.isProbabilityMeasure_of_indepFun
(X 0) (X 1) (zero_lt_one.trans_le hp).ne' hp' hℒp h (hindep zero_ne_one)
have hmeas : ∀ i, AEStronglyMeasurable (X i) μ := fun i =>
(hident i).aestronglyMeasurable_iff.2 hℒp.1
have hint : Integrable (X 0) μ := hℒp.integrable hp
have havg (n : ℕ) :
AEStronglyMeasurable (fun ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω)) μ :=
AEStronglyMeasurable.const_smul (aestronglyMeasurable_fun_sum _ fun i _ => hmeas i) _
refine tendsto_Lp_finite_of_tendstoInMeasure hp hp' havg (memLp_const _) ?_
(tendstoInMeasure_of_tendsto_ae havg (strong_law_ae _ hint hindep hident))
rw [(_ : (fun (n : ℕ) ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω))
= fun (n : ℕ) => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i))]
· apply UniformIntegrable.unifIntegrable
apply uniformIntegrable_average hp
exact MemLp.uniformIntegrable_of_identDistrib hp hp' hℒp hident
· ext n ω
simp only [Pi.smul_apply, sum_apply]
end StrongLawLp
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/IdentDistrib.lean | import Mathlib.Probability.Moments.Variance
import Mathlib.MeasureTheory.Function.UniformIntegrable
/-!
# Identically distributed random variables
Two random variables defined on two (possibly different) probability spaces but taking value in
the same space are *identically distributed* if their distributions (i.e., the image probability
measures on the target space) coincide. We define this concept and establish its basic properties
in this file.
## Main definitions and results
* `IdentDistrib f g μ ν` registers that the image of `μ` under `f` coincides with the image of `ν`
under `g` (and that `f` and `g` are almost everywhere measurable, as otherwise the image measures
don't make sense). The measures can be kept implicit as in `IdentDistrib f g` if the spaces
are registered as measure spaces.
* `IdentDistrib.comp`: being identically distributed is stable under composition with measurable
maps.
There are two main kinds of lemmas, under the assumption that `f` and `g` are identically
distributed: lemmas saying that two quantities computed for `f` and `g` are the same, and lemmas
saying that if `f` has some property then `g` also has it. The first kind is registered as
`IdentDistrib.foo_fst`, the second one as `IdentDistrib.foo_snd` (in the latter case, to deduce
a property of `f` from one of `g`, use `h.symm.foo_snd` where `h : IdentDistrib f g μ ν`). For
instance:
* `IdentDistrib.measure_mem_eq`: if `f` and `g` are identically distributed, then the probabilities
that they belong to a given measurable set are the same.
* `IdentDistrib.integral_eq`: if `f` and `g` are identically distributed, then their integrals
are the same.
* `IdentDistrib.variance_eq`: if `f` and `g` are identically distributed, then their variances
are the same.
* `IdentDistrib.aestronglyMeasurable_snd`: if `f` and `g` are identically distributed and `f`
is almost everywhere strongly measurable, then so is `g`.
* `IdentDistrib.memLp_snd`: if `f` and `g` are identically distributed and `f`
belongs to `ℒp`, then so does `g`.
We also register several dot notation shortcuts for convenience.
For instance, if `h : IdentDistrib f g μ ν`, then `h.sq` states that `f^2` and `g^2` are
identically distributed, and `h.norm` states that `‖f‖` and `‖g‖` are identically distributed, and
so on.
-/
open MeasureTheory Filter Finset
noncomputable section
open scoped Topology MeasureTheory ENNReal NNReal
variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ]
namespace ProbabilityTheory
/-- Two functions defined on two (possibly different) measure spaces are identically distributed if
their image measures coincide. This only makes sense when the functions are ae measurable
(as otherwise the image measures are not defined), so we require this as well in the definition. -/
structure IdentDistrib (f : α → γ) (g : β → γ)
(μ : Measure α := by volume_tac)
(ν : Measure β := by volume_tac) : Prop where
aemeasurable_fst : AEMeasurable f μ
aemeasurable_snd : AEMeasurable g ν
map_eq : Measure.map f μ = Measure.map g ν
namespace IdentDistrib
open TopologicalSpace
variable {μ : Measure α} {ν : Measure β} {f : α → γ} {g : β → γ}
protected theorem refl (hf : AEMeasurable f μ) : IdentDistrib f f μ μ :=
{ aemeasurable_fst := hf
aemeasurable_snd := hf
map_eq := rfl }
protected theorem symm (h : IdentDistrib f g μ ν) : IdentDistrib g f ν μ :=
{ aemeasurable_fst := h.aemeasurable_snd
aemeasurable_snd := h.aemeasurable_fst
map_eq := h.map_eq.symm }
protected theorem trans {ρ : Measure δ} {h : δ → γ} (h₁ : IdentDistrib f g μ ν)
(h₂ : IdentDistrib g h ν ρ) : IdentDistrib f h μ ρ :=
{ aemeasurable_fst := h₁.aemeasurable_fst
aemeasurable_snd := h₂.aemeasurable_snd
map_eq := h₁.map_eq.trans h₂.map_eq }
protected theorem comp_of_aemeasurable {u : γ → δ} (h : IdentDistrib f g μ ν)
(hu : AEMeasurable u (Measure.map f μ)) : IdentDistrib (u ∘ f) (u ∘ g) μ ν :=
{ aemeasurable_fst := hu.comp_aemeasurable h.aemeasurable_fst
aemeasurable_snd := by rw [h.map_eq] at hu; exact hu.comp_aemeasurable h.aemeasurable_snd
map_eq := by
rw [← AEMeasurable.map_map_of_aemeasurable hu h.aemeasurable_fst, ←
AEMeasurable.map_map_of_aemeasurable _ h.aemeasurable_snd, h.map_eq]
rwa [← h.map_eq] }
protected theorem comp {u : γ → δ} (h : IdentDistrib f g μ ν) (hu : Measurable u) :
IdentDistrib (u ∘ f) (u ∘ g) μ ν :=
h.comp_of_aemeasurable hu.aemeasurable
protected theorem of_ae_eq {g : α → γ} (hf : AEMeasurable f μ) (heq : f =ᵐ[μ] g) :
IdentDistrib f g μ μ :=
{ aemeasurable_fst := hf
aemeasurable_snd := hf.congr heq
map_eq := Measure.map_congr heq }
lemma _root_.MeasureTheory.AEMeasurable.identDistrib_mk
(hf : AEMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ :=
IdentDistrib.of_ae_eq hf hf.ae_eq_mk
lemma _root_.MeasureTheory.AEStronglyMeasurable.identDistrib_mk
[TopologicalSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ]
(hf : AEStronglyMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ :=
IdentDistrib.of_ae_eq hf.aemeasurable hf.ae_eq_mk
theorem measure_mem_eq (h : IdentDistrib f g μ ν) {s : Set γ} (hs : MeasurableSet s) :
μ (f ⁻¹' s) = ν (g ⁻¹' s) := by
rw [← Measure.map_apply_of_aemeasurable h.aemeasurable_fst hs, ←
Measure.map_apply_of_aemeasurable h.aemeasurable_snd hs, h.map_eq]
alias measure_preimage_eq := measure_mem_eq
theorem ae_snd (h : IdentDistrib f g μ ν) {p : γ → Prop} (pmeas : MeasurableSet {x | p x})
(hp : ∀ᵐ x ∂μ, p (f x)) : ∀ᵐ x ∂ν, p (g x) := by
apply (ae_map_iff h.aemeasurable_snd pmeas).1
rw [← h.map_eq]
exact (ae_map_iff h.aemeasurable_fst pmeas).2 hp
theorem ae_mem_snd (h : IdentDistrib f g μ ν) {t : Set γ} (tmeas : MeasurableSet t)
(ht : ∀ᵐ x ∂μ, f x ∈ t) : ∀ᵐ x ∂ν, g x ∈ t :=
h.ae_snd tmeas ht
/-- In a second countable topology, the first function in an identically distributed pair is a.e.
strongly measurable. So is the second function, but use `h.symm.aestronglyMeasurable_fst` as
`h.aestronglyMeasurable_snd` has a different meaning. -/
theorem aestronglyMeasurable_fst [TopologicalSpace γ] [PseudoMetrizableSpace γ]
[OpensMeasurableSpace γ] [SecondCountableTopology γ] (h : IdentDistrib f g μ ν) :
AEStronglyMeasurable f μ :=
h.aemeasurable_fst.aestronglyMeasurable
/-- If `f` and `g` are identically distributed and `f` is a.e. strongly measurable, so is `g`. -/
theorem aestronglyMeasurable_snd [TopologicalSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ]
(h : IdentDistrib f g μ ν) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable g ν := by
refine aestronglyMeasurable_iff_aemeasurable_separable.2 ⟨h.aemeasurable_snd, ?_⟩
rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩
refine ⟨closure t, t_sep.closure, ?_⟩
apply h.ae_mem_snd isClosed_closure.measurableSet
filter_upwards [ht] with x hx using subset_closure hx
theorem aestronglyMeasurable_iff [TopologicalSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ]
(h : IdentDistrib f g μ ν) : AEStronglyMeasurable f μ ↔ AEStronglyMeasurable g ν :=
⟨fun hf => h.aestronglyMeasurable_snd hf, fun hg => h.symm.aestronglyMeasurable_snd hg⟩
theorem essSup_eq [ConditionallyCompleteLinearOrder γ] [TopologicalSpace γ] [OpensMeasurableSpace γ]
[OrderClosedTopology γ] (h : IdentDistrib f g μ ν) : essSup f μ = essSup g ν := by
have I : ∀ a, μ {x : α | a < f x} = ν {x : β | a < g x} := fun a =>
h.measure_mem_eq measurableSet_Ioi
simp_rw [essSup_eq_sInf, I]
theorem lintegral_eq {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (h : IdentDistrib f g μ ν) :
∫⁻ x, f x ∂μ = ∫⁻ x, g x ∂ν := by
change ∫⁻ x, id (f x) ∂μ = ∫⁻ x, id (g x) ∂ν
rw [← lintegral_map' aemeasurable_id h.aemeasurable_fst, ←
lintegral_map' aemeasurable_id h.aemeasurable_snd, h.map_eq]
theorem integral_eq [NormedAddCommGroup γ] [NormedSpace ℝ γ] [BorelSpace γ]
(h : IdentDistrib f g μ ν) : ∫ x, f x ∂μ = ∫ x, g x ∂ν := by
by_cases hf : AEStronglyMeasurable f μ
· have A : AEStronglyMeasurable id (Measure.map f μ) := by
rw [aestronglyMeasurable_iff_aemeasurable_separable]
rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩
refine ⟨aemeasurable_id, ⟨closure t, t_sep.closure, ?_⟩⟩
rw [ae_map_iff h.aemeasurable_fst]
· filter_upwards [ht] with x hx using subset_closure hx
· exact isClosed_closure.measurableSet
change ∫ x, id (f x) ∂μ = ∫ x, id (g x) ∂ν
rw [← integral_map h.aemeasurable_fst A]
rw [h.map_eq] at A
rw [← integral_map h.aemeasurable_snd A, h.map_eq]
· rw [integral_non_aestronglyMeasurable hf]
rw [h.aestronglyMeasurable_iff] at hf
rw [integral_non_aestronglyMeasurable hf]
theorem eLpNorm_eq [NormedAddCommGroup γ] [OpensMeasurableSpace γ] (h : IdentDistrib f g μ ν)
(p : ℝ≥0∞) : eLpNorm f p μ = eLpNorm g p ν := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp only [h_top, eLpNorm, eLpNormEssSup, ENNReal.top_ne_zero, if_true,
if_false]
apply essSup_eq
exact h.comp (measurable_coe_nnreal_ennreal.comp measurable_nnnorm)
simp only [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', one_div]
congr 1
apply lintegral_eq
exact h.comp (Measurable.pow_const (measurable_coe_nnreal_ennreal.comp measurable_nnnorm)
p.toReal)
theorem memLp_snd [NormedAddCommGroup γ] [BorelSpace γ] {p : ℝ≥0∞} (h : IdentDistrib f g μ ν)
(hf : MemLp f p μ) : MemLp g p ν := by
refine ⟨h.aestronglyMeasurable_snd hf.aestronglyMeasurable, ?_⟩
rw [← h.eLpNorm_eq]
exact hf.2
theorem memLp_iff [NormedAddCommGroup γ] [BorelSpace γ] {p : ℝ≥0∞} (h : IdentDistrib f g μ ν) :
MemLp f p μ ↔ MemLp g p ν :=
⟨fun hf => h.memLp_snd hf, fun hg => h.symm.memLp_snd hg⟩
theorem integrable_snd [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν)
(hf : Integrable f μ) : Integrable g ν := by
rw [← memLp_one_iff_integrable] at hf ⊢
exact h.memLp_snd hf
theorem integrable_iff [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) :
Integrable f μ ↔ Integrable g ν :=
⟨fun hf => h.integrable_snd hf, fun hg => h.symm.integrable_snd hg⟩
protected theorem norm [NormedAddCommGroup γ] [OpensMeasurableSpace γ] (h : IdentDistrib f g μ ν) :
IdentDistrib (fun x => ‖f x‖) (fun x => ‖g x‖) μ ν :=
h.comp measurable_norm
protected theorem nnnorm [NormedAddCommGroup γ] [OpensMeasurableSpace γ]
(h : IdentDistrib f g μ ν) :
IdentDistrib (fun x => ‖f x‖₊) (fun x => ‖g x‖₊) μ ν :=
h.comp measurable_nnnorm
protected theorem pow [Pow γ ℕ] [MeasurablePow γ ℕ] (h : IdentDistrib f g μ ν) {n : ℕ} :
IdentDistrib (fun x => f x ^ n) (fun x => g x ^ n) μ ν :=
h.comp (measurable_id.pow_const n)
protected theorem sq [Pow γ ℕ] [MeasurablePow γ ℕ] (h : IdentDistrib f g μ ν) :
IdentDistrib (fun x => f x ^ 2) (fun x => g x ^ 2) μ ν :=
h.comp (measurable_id.pow_const 2)
protected theorem coe_nnreal_ennreal {f : α → ℝ≥0} {g : β → ℝ≥0} (h : IdentDistrib f g μ ν) :
IdentDistrib (fun x => (f x : ℝ≥0∞)) (fun x => (g x : ℝ≥0∞)) μ ν :=
h.comp measurable_coe_nnreal_ennreal
@[to_additive]
theorem mul_const [Mul γ] [MeasurableMul γ] (h : IdentDistrib f g μ ν) (c : γ) :
IdentDistrib (fun x => f x * c) (fun x => g x * c) μ ν :=
h.comp (measurable_mul_const c)
@[to_additive]
theorem const_mul [Mul γ] [MeasurableMul γ] (h : IdentDistrib f g μ ν) (c : γ) :
IdentDistrib (fun x => c * f x) (fun x => c * g x) μ ν :=
h.comp (measurable_const_mul c)
@[to_additive]
theorem div_const [Div γ] [MeasurableDiv γ] (h : IdentDistrib f g μ ν) (c : γ) :
IdentDistrib (fun x => f x / c) (fun x => g x / c) μ ν :=
h.comp (MeasurableDiv.measurable_div_const c)
@[to_additive]
theorem const_div [Div γ] [MeasurableDiv γ] (h : IdentDistrib f g μ ν) (c : γ) :
IdentDistrib (fun x => c / f x) (fun x => c / g x) μ ν :=
h.comp (MeasurableDiv.measurable_const_div c)
@[to_additive]
lemma inv [Inv γ] [MeasurableInv γ] (h : IdentDistrib f g μ ν) :
IdentDistrib f⁻¹ g⁻¹ μ ν := h.comp measurable_inv
theorem evariance_eq {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) :
evariance f μ = evariance g ν := by
convert (h.sub_const (∫ x, f x ∂μ)).nnnorm.coe_nnreal_ennreal.sq.lintegral_eq
rw [h.integral_eq]
rfl
theorem variance_eq {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) :
variance f μ = variance g ν := by rw [variance, h.evariance_eq]; rfl
end IdentDistrib
section UniformIntegrable
open TopologicalSpace
variable {E : Type*} [MeasurableSpace E] [NormedAddCommGroup E] [BorelSpace E]
{μ : Measure α} [IsFiniteMeasure μ]
/-- This lemma is superseded by `MemLp.uniformIntegrable_of_identDistrib` which only requires
`AEStronglyMeasurable`. -/
theorem MemLp.uniformIntegrable_of_identDistrib_aux {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞}
(hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : MemLp (f j) p μ) (hfmeas : ∀ i, StronglyMeasurable (f i))
(hf : ∀ i, IdentDistrib (f i) (f j) μ μ) : UniformIntegrable f p μ := by
refine uniformIntegrable_of' hp hp' hfmeas fun ε hε => ?_
by_cases hι : Nonempty ι
swap; · exact ⟨0, fun i => False.elim (hι <| Nonempty.intro i)⟩
obtain ⟨C, hC₁, hC₂⟩ := hℒp.eLpNorm_indicator_norm_ge_pos_le (hfmeas _) hε
refine ⟨⟨C, hC₁.le⟩, fun i => le_trans (le_of_eq ?_) hC₂⟩
have : {x | (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖f i x‖₊} = {x | C ≤ ‖f i x‖} := by
ext x
simp_rw [← norm_toNNReal]
exact Real.le_toNNReal_iff_coe_le (norm_nonneg _)
rw [this, ← eLpNorm_norm, ← eLpNorm_norm (Set.indicator _ _)]
simp_rw [norm_indicator_eq_indicator_norm, coe_nnnorm]
let F : E → ℝ := (fun x : E => if (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖x‖₊ then ‖x‖ else 0)
have F_meas : Measurable F := by
apply measurable_norm.indicator (measurableSet_le measurable_const measurable_nnnorm)
have : ∀ k, (fun x ↦ Set.indicator {x | C ≤ ‖f k x‖} (fun a ↦ ‖f k a‖) x) = F ∘ f k := by
intro k
ext x
simp only [Set.indicator, Set.mem_setOf_eq]; norm_cast
rw [this, this, ← eLpNorm_map_measure F_meas.aestronglyMeasurable (hf i).aemeasurable_fst,
(hf i).map_eq, eLpNorm_map_measure F_meas.aestronglyMeasurable (hf j).aemeasurable_fst]
/-- A sequence of identically distributed Lᵖ functions is p-uniformly integrable. -/
theorem MemLp.uniformIntegrable_of_identDistrib {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞}
(hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : MemLp (f j) p μ) (hf : ∀ i, IdentDistrib (f i) (f j) μ μ) :
UniformIntegrable f p μ := by
have hfmeas : ∀ i, AEStronglyMeasurable (f i) μ := fun i =>
(hf i).aestronglyMeasurable_iff.2 hℒp.1
set g : ι → α → E := fun i => (hfmeas i).choose
have hgmeas : ∀ i, StronglyMeasurable (g i) := fun i => (Exists.choose_spec <| hfmeas i).1
have hgeq : ∀ i, g i =ᵐ[μ] f i := fun i => (Exists.choose_spec <| hfmeas i).2.symm
have hgℒp : MemLp (g j) p μ := hℒp.ae_eq (hgeq j).symm
exact UniformIntegrable.ae_eq
(MemLp.uniformIntegrable_of_identDistrib_aux hp hp' hgℒp hgmeas fun i =>
(IdentDistrib.of_ae_eq (hgmeas i).aemeasurable (hgeq i)).trans
((hf i).trans <| IdentDistrib.of_ae_eq (hfmeas j).aemeasurable (hgeq j).symm)) hgeq
end UniformIntegrable
/-- If `X` and `Y` are independent and `(X, Y)` and `(X', Y')` are identically distributed,
then `X'` and `Y'` are independent. -/
lemma indepFun_of_identDistrib_pair
{μ : Measure γ} {μ' : Measure δ} [IsFiniteMeasure μ] [IsFiniteMeasure μ']
{X : γ → α} {X' : δ → α} {Y : γ → β} {Y' : δ → β} (h_indep : X ⟂ᵢ[μ] Y)
(h_ident : IdentDistrib (fun ω ↦ (X ω, Y ω)) (fun ω ↦ (X' ω, Y' ω)) μ μ') :
X' ⟂ᵢ[μ'] Y' := by
rw [indepFun_iff_map_prod_eq_prod_map_map _ _, ← h_ident.map_eq,
(indepFun_iff_map_prod_eq_prod_map_map _ _).1 h_indep]
· exact congr (congrArg Measure.prod <| (h_ident.comp measurable_fst).map_eq)
(h_ident.comp measurable_snd).map_eq
· exact measurable_fst.aemeasurable.comp_aemeasurable h_ident.aemeasurable_fst
· exact measurable_snd.aemeasurable.comp_aemeasurable h_ident.aemeasurable_fst
· exact measurable_fst.aemeasurable.comp_aemeasurable h_ident.aemeasurable_snd
· exact measurable_snd.aemeasurable.comp_aemeasurable h_ident.aemeasurable_snd
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/HasLawExists.lean | import Mathlib.Probability.HasLaw
import Mathlib.Probability.Independence.InfinitePi
/-!
# Existence of Random Variables
This file contains lemmas that state the existence of random variables with given distributions
and a given dependency structure (currently only mutual independence is considered).
-/
open MeasureTheory Measure
namespace ProbabilityTheory
universe u v
lemma _root_.Measure.exists_hasLaw {𝓧 : Type u} {m𝓧 : MeasurableSpace 𝓧} (μ : Measure 𝓧) :
∃ Ω : Type u, ∃ _ : MeasurableSpace Ω, ∃ P : Measure Ω, ∃ X : Ω → 𝓧,
Measurable X ∧ HasLaw X μ P :=
⟨𝓧, m𝓧, μ, id, measurable_id, .id⟩
lemma exists_hasLaw_indepFun {ι : Type v} (𝓧 : ι → Type u)
{m𝓧 : ∀ i, MeasurableSpace (𝓧 i)} (μ : (i : ι) → Measure (𝓧 i))
[hμ : ∀ i, IsProbabilityMeasure (μ i)] :
∃ Ω : Type (max u v), ∃ _ : MeasurableSpace Ω, ∃ P : Measure Ω, ∃ X : (i : ι) → Ω → (𝓧 i),
(∀ i, Measurable (X i)) ∧ (∀ i, HasLaw (X i) (μ i) P)
∧ iIndepFun X P ∧ IsProbabilityMeasure P := by
use Π i, (𝓧 i), .pi, infinitePi μ, fun i ↦ Function.eval i
refine ⟨by fun_prop, fun i ↦ MeasurePreserving.hasLaw (measurePreserving_eval_infinitePi _ _),
?_, by infer_instance⟩
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop), map_id']
congr
funext i
exact ((measurePreserving_eval_infinitePi μ i).map_eq).symm
lemma exists_iid (ι : Type v) {𝓧 : Type u} {m𝓧 : MeasurableSpace 𝓧}
(μ : Measure 𝓧) [IsProbabilityMeasure μ] :
∃ Ω : Type (max u v), ∃ _ : MeasurableSpace Ω, ∃ P : Measure Ω, ∃ X : ι → Ω → 𝓧,
(∀ i, Measurable (X i)) ∧ (∀ i, HasLaw (X i) μ P) ∧ iIndepFun X P ∧ IsProbabilityMeasure P :=
exists_hasLaw_indepFun (fun _ ↦ 𝓧) (fun _ ↦ μ)
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Notation.lean | import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic
import Mathlib.MeasureTheory.Measure.Decomposition.Lebesgue
/-! # Notations for probability theory
This file defines the following notations, for functions `X,Y`, measures `P, Q` defined on a
measurable space `m0`, and another measurable space structure `m` with `hm : m ≤ m0`,
- `P[X] = ∫ a, X a ∂P`
- `𝔼[X] = ∫ a, X a`
- `𝔼[X|m]`: conditional expectation of `X` with respect to the measure `volume` and the
measurable space `m`. The similar `P[X|m]` for a measure `P` is defined in
`MeasureTheory.Function.ConditionalExpectation.Basic`.
- `P⟦s|m⟧ = P[s.indicator (fun ω => (1 : ℝ)) | m]`, conditional probability of a set.
- `X =ₐₛ Y`: `X =ᵐ[volume] Y`
- `X ≤ₐₛ Y`: `X ≤ᵐ[volume] Y`
- `∂P/∂Q = P.rnDeriv Q`
We note that the notation `∂P/∂Q` applies to three different cases, namely,
`MeasureTheory.Measure.rnDeriv`, `MeasureTheory.SignedMeasure.rnDeriv` and
`MeasureTheory.ComplexMeasure.rnDeriv`.
- `ℙ` is a notation for `volume` on a measured space.
To use these notations, you need to use `open scoped ProbabilityTheory`
or `open ProbabilityTheory`.
-/
open MeasureTheory
open scoped MeasureTheory
/-- `𝔼[f|m]` is the conditional expectation of `f` with respect to `m`. -/
scoped[ProbabilityTheory] notation "𝔼[" X "|" m "]" =>
MeasureTheory.condExp m MeasureTheory.MeasureSpace.volume X
-- `scoped[ProbabilityTheory]` isn't legal for `macro`s.
namespace ProbabilityTheory
/-- `P[X]` is the expectation of `X` under the measure `P`.
Note that this notation can conflict with the `GetElem` notation for lists. Usually if you see an
error about ambiguous notation when trying to write `l[i]` for a list, it means that Lean could
not find `i < l.length`, and so fell back to trying this notation as well. -/
scoped macro:max P:term noWs "[" X:term "]" : term => `(∫ x, ↑($X x) ∂$P)
end ProbabilityTheory
/-- `𝔼[X]` is the expectation of `X`, defined as its Lebesgue integral. -/
scoped[ProbabilityTheory] notation "𝔼[" X "]" => ∫ a, (X : _ → _) a
/-- `P⟦s|m⟧` is the conditional expectation of `s` with respect to `m` under measure `P`. -/
scoped[ProbabilityTheory] notation P "⟦" s "|" m "⟧" =>
MeasureTheory.condExp m P (Set.indicator s fun ω => (1 : ℝ))
/-- `X =ₐₛ Y` if `X = Y` almost surely. -/
scoped[ProbabilityTheory] notation:50 X " =ₐₛ " Y:50 => X =ᵐ[MeasureTheory.MeasureSpace.volume] Y
/-- `X ≤ₐₛ Y` if `X ≤ Y` almost surely. -/
scoped[ProbabilityTheory] notation:50 X " ≤ₐₛ " Y:50 => X ≤ᵐ[MeasureTheory.MeasureSpace.volume] Y
/-- `∂P/∂Q` is the Radon–Nikodym derivative of `P` with respect to `Q`. -/
scoped[ProbabilityTheory] notation "∂" P "/∂" Q:100 => MeasureTheory.Measure.rnDeriv P Q
/-- `ℙ` is a notation for `volume` on a measured space. -/
scoped[ProbabilityTheory] notation "ℙ" => MeasureTheory.MeasureSpace.volume |
.lake/packages/mathlib/Mathlib/Probability/UniformOn.lean | import Mathlib.Probability.ConditionalProbability
import Mathlib.MeasureTheory.Measure.Count
/-!
# Classical probability
The classical formulation of probability states that the probability of an event occurring in a
finite probability space is the ratio of that event to all possible events.
This notion can be expressed with measure theory using
the counting measure. In particular, given the sets `s` and `t`, we define the probability of `t`
occurring in `s` to be `|s|⁻¹ * |s ∩ t|`. With this definition, we recover the probability over
the entire sample space when `s = Set.univ`.
Classical probability is often used in combinatorics and we prove some useful lemmas in this file
for that purpose.
## Main definition
* `ProbabilityTheory.uniformOn`: given a set `s`, `uniformOn s` is the counting measure
conditioned on `s`. This is a probability measure when `s` is finite and nonempty.
## Notes
The original aim of this file is to provide a measure-theoretic method of describing the
probability an element of a set `s` satisfies some predicate `P`. Our current formulation still
allow us to describe this by abusing the definitional equality of sets and predicates by simply
writing `uniformOn s P`. We should avoid this however as none of the lemmas are written for
predicates.
-/
noncomputable section
open ProbabilityTheory
open MeasureTheory MeasurableSpace
namespace ProbabilityTheory
variable {Ω : Type*} [MeasurableSpace Ω] {s : Set Ω}
/-- Given a set `s`, `uniformOn s` is the uniform measure on `s`, defined as the counting measure
conditioned by `s`. One should think of `uniformOn s t` as the proportion of `s` that is contained
in `t`.
This is a probability measure when `s` is finite and nonempty and is given by
`ProbabilityTheory.uniformOn_isProbabilityMeasure`. -/
def uniformOn (s : Set Ω) : Measure Ω :=
Measure.count[|s]
instance {s : Set Ω} : IsZeroOrProbabilityMeasure (uniformOn s) := by
unfold uniformOn; infer_instance
@[simp]
theorem uniformOn_empty_meas : (uniformOn ∅ : Measure Ω) = 0 := by simp [uniformOn]
theorem uniformOn_empty {s : Set Ω} : uniformOn s ∅ = 0 := by simp
/-- See `uniformOn_eq_zero` for a version assuming `MeasurableSingletonClass Ω` instead of
`MeasurableSet s`. -/
@[simp] lemma uniformOn_eq_zero' (hs : MeasurableSet s) : uniformOn s = 0 ↔ s.Infinite ∨ s = ∅ := by
simp [uniformOn, hs]
/-- See `uniformOn_eq_zero'` for a version assuming `MeasurableSet s` instead of
`MeasurableSingletonClass Ω`. -/
@[simp] lemma uniformOn_eq_zero [MeasurableSingletonClass Ω] :
uniformOn s = 0 ↔ s.Infinite ∨ s = ∅ := by simp [uniformOn]
theorem finite_of_uniformOn_ne_zero {s t : Set Ω} (h : uniformOn s t ≠ 0) : s.Finite := by
by_contra hs'
simp [uniformOn, cond, Measure.count_apply_infinite hs'] at h
theorem uniformOn_univ [Fintype Ω] {s : Set Ω} :
uniformOn Set.univ s = Measure.count s / Fintype.card Ω := by
simp [uniformOn, cond_apply, ← ENNReal.div_eq_inv_mul]
variable [MeasurableSingletonClass Ω]
theorem uniformOn_isProbabilityMeasure {s : Set Ω} (hs : s.Finite) (hs' : s.Nonempty) :
IsProbabilityMeasure (uniformOn s) := by
apply cond_isProbabilityMeasure_of_finite
· rwa [Measure.count_ne_zero_iff]
· exact (Measure.count_apply_lt_top.2 hs).ne
theorem uniformOn_singleton (ω : Ω) (t : Set Ω) [Decidable (ω ∈ t)] :
uniformOn {ω} t = if ω ∈ t then 1 else 0 := by
rw [uniformOn, cond_apply (measurableSet_singleton ω), Measure.count_singleton, inv_one,
one_mul]
split_ifs
· rw [(by simpa : ({ω} : Set Ω) ∩ t = {ω}), Measure.count_singleton]
· simpa
variable {s t u : Set Ω}
theorem uniformOn_inter_self (hs : s.Finite) : uniformOn s (s ∩ t) = uniformOn s t := by
rw [uniformOn, cond_inter_self hs.measurableSet]
theorem uniformOn_self (hs : s.Finite) (hs' : s.Nonempty) : uniformOn s s = 1 := by
rw [uniformOn, cond_apply hs.measurableSet, Set.inter_self, ENNReal.inv_mul_cancel]
· rwa [Measure.count_ne_zero_iff]
· exact (Measure.count_apply_lt_top.2 hs).ne
theorem uniformOn_eq_one_of (hs : s.Finite) (hs' : s.Nonempty) (ht : s ⊆ t) :
uniformOn s t = 1 := by
haveI := uniformOn_isProbabilityMeasure hs hs'
refine eq_of_le_of_not_lt prob_le_one ?_
rw [not_lt, ← uniformOn_self hs hs']
exact measure_mono ht
theorem pred_true_of_uniformOn_eq_one (h : uniformOn s t = 1) : s ⊆ t := by
have hsf := finite_of_uniformOn_ne_zero (by rw [h]; exact one_ne_zero)
rw [uniformOn, cond_apply hsf.measurableSet, mul_comm] at h
replace h := ENNReal.eq_inv_of_mul_eq_one_left h
rw [inv_inv, Measure.count_apply_finite _ hsf, Measure.count_apply_finite _ (hsf.inter_of_left _),
Nat.cast_inj] at h
suffices s ∩ t = s by exact this ▸ fun x hx => hx.2
rw [← @Set.Finite.toFinset_inj _ _ _ (hsf.inter_of_left _) hsf]
exact Finset.eq_of_subset_of_card_le (Set.Finite.toFinset_mono s.inter_subset_left) h.ge
theorem uniformOn_eq_zero_iff (hs : s.Finite) : uniformOn s t = 0 ↔ s ∩ t = ∅ := by
simp [uniformOn, cond_apply hs.measurableSet, Measure.count_apply_eq_top, Set.not_infinite.2 hs,
Measure.count_apply_finite _ (hs.inter_of_left _)]
theorem uniformOn_of_univ (hs : s.Finite) (hs' : s.Nonempty) : uniformOn s Set.univ = 1 :=
uniformOn_eq_one_of hs hs' s.subset_univ
theorem uniformOn_inter (hs : s.Finite) :
uniformOn s (t ∩ u) = uniformOn (s ∩ t) u * uniformOn s t := by
by_cases hst : s ∩ t = ∅
· rw [hst, uniformOn_empty_meas, Measure.coe_zero, Pi.zero_apply, zero_mul,
uniformOn_eq_zero_iff hs, ← Set.inter_assoc, hst, Set.empty_inter]
rw [uniformOn, uniformOn, cond_apply hs.measurableSet, cond_apply hs.measurableSet,
cond_apply (hs.inter_of_left _).measurableSet, mul_comm _ (Measure.count (s ∩ t)),
← mul_assoc, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, ENNReal.mul_inv_cancel, one_mul,
mul_comm, Set.inter_assoc]
· rwa [← Measure.count_eq_zero_iff] at hst
· exact (Measure.count_apply_lt_top.2 <| hs.inter_of_left _).ne
theorem uniformOn_inter' (hs : s.Finite) :
uniformOn s (t ∩ u) = uniformOn (s ∩ u) t * uniformOn s u := by
rw [← Set.inter_comm]
exact uniformOn_inter hs
theorem uniformOn_union (hs : s.Finite) (htu : Disjoint t u) :
uniformOn s (t ∪ u) = uniformOn s t + uniformOn s u := by
rw [uniformOn, cond_apply hs.measurableSet, cond_apply hs.measurableSet,
cond_apply hs.measurableSet, Set.inter_union_distrib_left, measure_union, mul_add]
exacts [htu.mono inf_le_right inf_le_right, (hs.inter_of_left _).measurableSet]
theorem uniformOn_compl (t : Set Ω) (hs : s.Finite) (hs' : s.Nonempty) :
uniformOn s t + uniformOn s tᶜ = 1 := by
rw [← uniformOn_union hs disjoint_compl_right, Set.union_compl_self,
(uniformOn_isProbabilityMeasure hs hs').measure_univ]
theorem uniformOn_disjoint_union (hs : s.Finite) (ht : t.Finite) (hst : Disjoint s t) :
uniformOn s u * uniformOn (s ∪ t) s + uniformOn t u * uniformOn (s ∪ t) t =
uniformOn (s ∪ t) u := by
rcases s.eq_empty_or_nonempty with (rfl | hs') <;> rcases t.eq_empty_or_nonempty with (rfl | ht')
· simp
· simp [uniformOn_self ht ht']
· simp [uniformOn_self hs hs']
rw [uniformOn, uniformOn, uniformOn, cond_apply hs.measurableSet,
cond_apply ht.measurableSet, cond_apply (hs.union ht).measurableSet,
cond_apply (hs.union ht).measurableSet, cond_apply (hs.union ht).measurableSet]
conv_lhs =>
rw [Set.union_inter_cancel_left, Set.union_inter_cancel_right,
mul_comm (Measure.count (s ∪ t))⁻¹, mul_comm (Measure.count (s ∪ t))⁻¹, ← mul_assoc,
← mul_assoc, mul_comm _ (Measure.count s), mul_comm _ (Measure.count t), ← mul_assoc,
← mul_assoc]
rw [ENNReal.mul_inv_cancel, ENNReal.mul_inv_cancel, one_mul, one_mul, ← add_mul, ← measure_union,
Set.union_inter_distrib_right, mul_comm]
exacts [hst.mono inf_le_left inf_le_left, (ht.inter_of_left _).measurableSet,
Measure.count_ne_zero ht', (Measure.count_apply_lt_top.2 ht).ne, Measure.count_ne_zero hs',
(Measure.count_apply_lt_top.2 hs).ne]
/-- A version of the law of total probability for counting probabilities. -/
theorem uniformOn_add_compl_eq (u t : Set Ω) (hs : s.Finite) :
uniformOn (s ∩ u) t * uniformOn s u + uniformOn (s ∩ uᶜ) t * uniformOn s uᶜ =
uniformOn s t := by
conv_rhs =>
rw [(by simp : s = s ∩ u ∪ s ∩ uᶜ),
← uniformOn_disjoint_union (hs.inter_of_left _) (hs.inter_of_left _)
(disjoint_compl_right.mono inf_le_right inf_le_right)]
simp [uniformOn_inter_self hs]
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/ConditionalProbability.lean | import Mathlib.MeasureTheory.Measure.Typeclasses.Probability
/-!
# Conditional Probability
This file defines conditional probability and includes basic results relating to it.
Given some measure `μ` defined on a measure space on some type `Ω` and some `s : Set Ω`,
we define the measure of `μ` conditioned on `s` as the restricted measure scaled by
the inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling
ensures that this is a probability measure (when `μ` is a finite measure).
From this definition, we derive the "axiomatic" definition of conditional probability
based on application: for any `s t : Set Ω`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`.
## Main Statements
* `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent
to conditioning on their intersection.
* `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`.
## Notation
This file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`,
and `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the
application `μ[|s] t`).
These notations are contained in the scope `ProbabilityTheory`.
## Implementation notes
Because we have the alternative measure restriction application principles
`Measure.restrict_apply` and `Measure.restrict_apply'`, which require
measurability of the restricted and restricting sets, respectively,
many of the theorems here will have corresponding alternatives as well.
For the sake of brevity, we've chosen to only go with `Measure.restrict_apply'`
for now, but the alternative theorems can be added if needed.
Use of `@[simp]` generally follows the rule of removing conditions on a measure
when possible.
Hypotheses that are used to "define" a conditional distribution by requiring that
the conditioning set has non-zero measure should be named using the abbreviation
"c" (which stands for "conditionable") rather than "nz". For example `(hci : μ (s ∩ t) ≠ 0)`
(rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined.
## Tags
conditional, conditioned, bayes
-/
noncomputable section
open ENNReal MeasureTheory MeasureTheory.Measure MeasurableSpace Set
variable {Ω Ω' α : Type*} {m : MeasurableSpace Ω} {m' : MeasurableSpace Ω'} {μ : Measure Ω}
{s t : Set Ω}
namespace ProbabilityTheory
variable (μ) in
/-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s`
and scaled by the inverse of `μ s` (to make it a probability measure):
`(μ s)⁻¹ • μ.restrict s`. -/
def cond (s : Set Ω) : Measure Ω :=
(μ s)⁻¹ • μ.restrict s
@[inherit_doc ProbabilityTheory.cond]
scoped macro:max μ:term noWs "[|" s:term "]" : term =>
`(ProbabilityTheory.cond $μ $s)
@[inherit_doc cond]
scoped macro:max μ:term noWs "[" t:term " | " s:term "]" : term =>
`(ProbabilityTheory.cond $μ $s $t)
/-!
We can't use `notation` or `notation3` as it does not support `noWs`, and so we have to write
our own delaborators.
-/
section delaborators
open Lean PrettyPrinter.Delaborator SubExpr
/-- Unexpander for `μ[|s]` notation. -/
@[app_unexpander ProbabilityTheory.cond]
def condUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $μ $s) => `($μ[|$s])
| _ => throw ()
/-- info: μ[|s] : Measure Ω -/
#guard_msgs in
#check μ[|s]
/-- Delaborator for `μ[t|s]` notation. -/
@[app_delab DFunLike.coe]
def delabCondApplied : Delab :=
whenNotPPOption getPPExplicit <| whenPPOption getPPNotation <| withOverApp 6 do
let e ← getExpr
guard <| e.isAppOfArity' ``DFunLike.coe 6
guard <| (e.getArg!' 4).isAppOf' ``ProbabilityTheory.cond
let t ← withAppArg delab
withAppFn <| withAppArg do
let μ ← withNaryArg 2 delab
let s ← withNaryArg 3 delab
`($μ[$t|$s])
/-- info: μ[t | s] : ℝ≥0∞ -/
#guard_msgs in
#check μ[t | s]
/-- info: μ[t | s] : ℝ≥0∞ -/
#guard_msgs in
#check μ[|s] t
end delaborators
/-- The conditional probability measure of measure `μ` on `{ω | X ω ∈ s}`.
It is `μ` restricted to `{ω | X ω ∈ s}` and scaled by the inverse of `μ {ω | X ω ∈ s}`
(to make it a probability measure): `(μ {ω | X ω ∈ s})⁻¹ • μ.restrict {ω | X ω ∈ s}`. -/
scoped macro:max μ:term noWs "[|" X:term " in " s:term "]" : term => `($μ[|$X ⁻¹' $s])
/-- The conditional probability measure of measure `μ` on set `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[" s:term " | " X:term " in " t:term "]" : term =>
`($μ[$s | $X ⁻¹' $t])
/-- The conditional probability measure of measure `μ` on `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[|" X:term " ← " x:term "]" : term => `($μ[|$X in {$x:term}])
/-- The conditional probability measure of measure `μ` on set `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[" s:term " | " X:term " ← " x:term "]" : term =>
`($μ[$s | $X in {$x:term}])
/-- The conditional probability measure of any measure on any set of finite positive measure
is a probability measure. -/
theorem cond_isProbabilityMeasure_of_finite (hcs : μ s ≠ 0) (hs : μ s ≠ ∞) :
IsProbabilityMeasure μ[|s] :=
⟨by
unfold ProbabilityTheory.cond
simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply,
Set.univ_inter, smul_eq_mul]
exact ENNReal.inv_mul_cancel hcs hs⟩
/-- The conditional probability measure of any finite measure on any set of positive measure
is a probability measure. -/
theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) :
IsProbabilityMeasure μ[|s] := cond_isProbabilityMeasure_of_finite hcs (measure_ne_top μ s)
instance : IsZeroOrProbabilityMeasure μ[|s] := by
constructor
simp only [cond, Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply,
univ_inter, smul_eq_mul, ← ENNReal.div_eq_inv_mul]
rcases eq_or_ne (μ s) 0 with h | h
· simp [h]
rcases eq_or_ne (μ s) ∞ with h' | h'
· simp [h']
simp [ENNReal.div_self h h']
variable (μ) in
theorem cond_toMeasurable_eq :
μ[|(toMeasurable μ s)] = μ[|s] := by
unfold cond
by_cases hnt : μ s = ∞
· simp [hnt]
· simp [Measure.restrict_toMeasurable hnt]
lemma cond_absolutelyContinuous : μ[|s] ≪ μ :=
smul_absolutelyContinuous.trans restrict_le_self.absolutelyContinuous
lemma absolutelyContinuous_cond_univ [IsFiniteMeasure μ] : μ ≪ μ[|univ] := by
rw [cond, restrict_univ]
refine absolutelyContinuous_smul ?_
simp [measure_ne_top]
lemma ae_cond_of_forall_mem (hs : MeasurableSet s) {p : Ω → Prop} (h : ∀ x ∈ s, p x) :
∀ᵐ x ∂μ[|s], p x := ae_smul_measure (ae_restrict_of_forall_mem hs h) _
lemma ae_cond_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ[|s], x ∈ s :=
ae_smul_measure (ae_restrict_mem₀ hs) _
lemma ae_cond_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ[|s], x ∈ s :=
ae_smul_measure (ae_restrict_mem hs) _
section Bayes
variable (μ) in
@[simp] lemma cond_empty : μ[|∅] = 0 := by simp [cond]
variable (μ) in
@[simp] lemma cond_univ [IsProbabilityMeasure μ] : μ[|Set.univ] = μ := by
simp [cond, measure_univ, Measure.restrict_univ]
@[simp] lemma cond_eq_zero : μ[|s] = 0 ↔ μ s = ∞ ∨ μ s = 0 := by simp [cond]
lemma cond_eq_zero_of_meas_eq_zero (hμs : μ s = 0) : μ[|s] = 0 := by simp [hμs]
/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/
theorem cond_apply (hms : MeasurableSet s) (μ : Measure Ω) (t : Set Ω) :
μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
rw [cond, Measure.smul_apply, Measure.restrict_apply' hms, Set.inter_comm, smul_eq_mul]
theorem cond_apply' (ht : MeasurableSet t) (μ : Measure Ω) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
rw [cond, Measure.smul_apply, Measure.restrict_apply ht, Set.inter_comm, smul_eq_mul]
@[simp] lemma cond_apply_self (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : μ[s|s] = 1 := by
simpa [cond] using ENNReal.inv_mul_cancel hs₀ hs
theorem cond_inter_self (hms : MeasurableSet s) (t : Set Ω) (μ : Measure Ω) :
μ[s ∩ t|s] = μ[t|s] := by
rw [cond_apply hms, ← Set.inter_assoc, Set.inter_self, ← cond_apply hms]
theorem inter_pos_of_cond_ne_zero (hms : MeasurableSet s) (hcst : μ[t | s] ≠ 0) :
0 < μ (s ∩ t) := by
refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul (a := (μ s)⁻¹) ?_)
convert hcst
simp [hms, Set.inter_comm, cond]
lemma cond_pos_of_inter_ne_zero [IsFiniteMeasure μ] (hms : MeasurableSet s) (hci : μ (s ∩ t) ≠ 0) :
0 < μ[t | s] := by
rw [cond_apply hms]
refine ENNReal.mul_pos ?_ hci
exact ENNReal.inv_ne_zero.mpr (measure_ne_top _ _)
lemma cond_cond_eq_cond_inter' (hms : MeasurableSet s) (hmt : MeasurableSet t) (hcs : μ s ≠ ∞) :
μ[|s][|t] = μ[|s ∩ t] := by
ext u
obtain hst | hst := eq_or_ne (μ (s ∩ t)) 0
· have : μ (s ∩ t ∩ u) = 0 := measure_mono_null Set.inter_subset_left hst
simp [cond_apply, *, ← Set.inter_assoc]
· have hs : μ s ≠ 0 := (measure_pos_of_superset Set.inter_subset_left hst).ne'
simp [*, hms.inter hmt, cond_apply, ← Set.inter_assoc, ENNReal.mul_inv, ← mul_assoc,
mul_comm _ (μ s)⁻¹, ENNReal.inv_mul_cancel]
/-- Conditioning first on `s` and then on `t` results in the same measure as conditioning
on `s ∩ t`. -/
theorem cond_cond_eq_cond_inter (hms : MeasurableSet s) (hmt : MeasurableSet t) (μ : Measure Ω)
[IsFiniteMeasure μ] : μ[|s][|t] = μ[|s ∩ t] :=
cond_cond_eq_cond_inter' hms hmt (measure_ne_top μ s)
theorem cond_mul_eq_inter' (hms : MeasurableSet s) (hcs' : μ s ≠ ∞) (t : Set Ω) :
μ[t|s] * μ s = μ (s ∩ t) := by
obtain hcs | hcs := eq_or_ne (μ s) 0
· simp [hcs, measure_inter_null_of_null_left]
· rw [cond_apply hms, mul_comm, ← mul_assoc, ENNReal.mul_inv_cancel hcs hcs', one_mul]
theorem cond_mul_eq_inter (hms : MeasurableSet s) (t : Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] :
μ[t|s] * μ s = μ (s ∩ t) := cond_mul_eq_inter' hms (measure_ne_top _ s) t
/-- A version of the law of total probability. -/
theorem cond_add_cond_compl_eq (hms : MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] :
μ[t|s] * μ s + μ[t|sᶜ] * μ sᶜ = μ t := by
rw [cond_mul_eq_inter hms, cond_mul_eq_inter hms.compl, Set.inter_comm _ t,
Set.inter_comm _ t]
exact measure_inter_add_diff t hms
/-- **Bayes' Theorem** -/
theorem cond_eq_inv_mul_cond_mul (hms : MeasurableSet s) (hmt : MeasurableSet t) (μ : Measure Ω)
[IsFiniteMeasure μ] : μ[t|s] = (μ s)⁻¹ * μ[s|t] * μ t := by
rw [mul_assoc, cond_mul_eq_inter hmt s, Set.inter_comm, cond_apply hms]
end Bayes
lemma comap_cond {i : Ω' → Ω} (hi : MeasurableEmbedding i) (hi' : ∀ᵐ ω ∂μ, ω ∈ range i)
(hs : MeasurableSet s) : comap i μ[|s] = (comap i μ)[|i in s] := by
ext t ht
change μ (range i)ᶜ = 0 at hi'
rw [cond_apply, comap_apply, cond_apply, comap_apply, comap_apply, image_inter,
image_preimage_eq_inter_range, inter_right_comm, measure_inter_conull hi',
measure_inter_conull hi']
all_goals first
| exact hi.injective
| exact hi.measurableSet_image'
| exact hs
| exact ht
| exact hi.measurable hs
| exact (hi.measurable hs).inter ht
variable [Fintype α] [MeasurableSpace α] [DiscreteMeasurableSpace α]
/-- The **law of total probability** for a random variable taking finitely many values: a measure
`μ` can be expressed as a linear combination of its conditional measures `μ[|X ← x]` on fibers of a
random variable `X` valued in a fintype. -/
lemma sum_meas_smul_cond_fiber {X : Ω → α} (hX : Measurable X) (μ : Measure Ω) [IsFiniteMeasure μ] :
∑ x, μ (X ⁻¹' {x}) • μ[|X ← x] = μ := by
ext E hE
calc
_ = ∑ x, μ (X ⁻¹' {x} ∩ E) := by
simp only [Measure.coe_finset_sum, Measure.coe_smul, Finset.sum_apply,
Pi.smul_apply, smul_eq_mul]
simp_rw [mul_comm (μ _), cond_mul_eq_inter (hX (.singleton _))]
_ = _ := by
have : ⋃ x ∈ Finset.univ, X ⁻¹' {x} ∩ E = E := by ext; simp
rw [← measure_biUnion_finset _ fun _ _ ↦ (hX (.singleton _)).inter hE, this]
aesop (add simp [PairwiseDisjoint, Set.Pairwise, Function.onFun, disjoint_left])
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/CDF.lean | import Mathlib.Probability.Kernel.Disintegration.CondCDF
/-!
# Cumulative distribution function of a real probability measure
The cumulative distribution function (cdf) of a probability measure over `ℝ` is a monotone, right
continuous function with limit 0 at -∞ and 1 at +∞, such that `cdf μ x = μ (Iic x)` for all `x : ℝ`.
Two probability measures are equal if and only if they have the same cdf.
## Main definitions
* `ProbabilityTheory.cdf μ`: cumulative distribution function of `μ : Measure ℝ`, defined as the
conditional cdf (`ProbabilityTheory.condCDF`) of the product measure
`(Measure.dirac Unit.unit).prod μ` evaluated at `Unit.unit`.
The definition could be replaced by the more elementary `cdf μ x = μ.real (Iic x)`, but using
`condCDF` gives us access to its API, from which most properties of the cdf follow directly.
## Main statements
* `ProbabilityTheory.ofReal_cdf`: for a probability measure `μ` and `x : ℝ`,
`ENNReal.ofReal (cdf μ x) = μ (Iic x)`.
* `MeasureTheory.Measure.ext_of_cdf`: two probability measures are equal if and only if they have
the same cdf.
## TODO
The definition could be extended to a finite measure by rescaling `condCDF`, but it would be nice
to have more structure on Stieltjes functions first. Right now, if `f` is a Stieltjes function,
`2 • f` makes no sense. We could define Stieltjes functions as a submodule.
The definition could be extended to `ℝⁿ`, either by extending the definition of `condCDF`, or by
using another construction here.
-/
open MeasureTheory Measure Set Filter
open scoped Topology
namespace ProbabilityTheory
/-- Cumulative distribution function of a real measure. The definition currently makes sense only
for probability measures. In that case, it satisfies `cdf μ x = μ.real (Iic x)` (see
`ProbabilityTheory.cdf_eq_real`). -/
noncomputable
def cdf (μ : Measure ℝ) : StieltjesFunction :=
condCDF ((dirac Unit.unit).prod μ) Unit.unit
section ExplicitMeasureArg
variable (μ : Measure ℝ)
/-- The cdf is non-negative. -/
lemma cdf_nonneg (x : ℝ) : 0 ≤ cdf μ x := condCDF_nonneg _ _ _
/-- The cdf is lower or equal to 1. -/
lemma cdf_le_one (x : ℝ) : cdf μ x ≤ 1 := condCDF_le_one _ _ _
/-- The cdf is monotone. -/
lemma monotone_cdf : Monotone (cdf μ) := (condCDF _ _).mono
/-- The cdf tends to 0 at -∞. -/
lemma tendsto_cdf_atBot : Tendsto (cdf μ) atBot (𝓝 0) := tendsto_condCDF_atBot _ _
/-- The cdf tends to 1 at +∞. -/
lemma tendsto_cdf_atTop : Tendsto (cdf μ) atTop (𝓝 1) := tendsto_condCDF_atTop _ _
lemma ofReal_cdf [IsProbabilityMeasure μ] (x : ℝ) : ENNReal.ofReal (cdf μ x) = μ (Iic x) := by
have h := lintegral_condCDF ((dirac Unit.unit).prod μ) x
simpa only [fst_prod, prod_prod, measure_univ, one_mul, lintegral_dirac] using h
lemma cdf_eq_real [IsProbabilityMeasure μ] (x : ℝ) : cdf μ x = μ.real (Iic x) := by
rw [measureReal_def, ← ofReal_cdf μ x, ENNReal.toReal_ofReal (cdf_nonneg μ x)]
instance instIsProbabilityMeasurecdf : IsProbabilityMeasure (cdf μ).measure := by
constructor
simp only [StieltjesFunction.measure_univ _ (tendsto_cdf_atBot μ) (tendsto_cdf_atTop μ), sub_zero,
ENNReal.ofReal_one]
/-- The measure associated to the cdf of a probability measure is the same probability measure. -/
lemma measure_cdf [IsProbabilityMeasure μ] : (cdf μ).measure = μ := by
refine ext_of_Iic (cdf μ).measure μ (fun a ↦ ?_)
rw [StieltjesFunction.measure_Iic _ (tendsto_cdf_atBot μ), sub_zero, ofReal_cdf]
end ExplicitMeasureArg
lemma cdf_measure_stieltjesFunction (f : StieltjesFunction) (hf0 : Tendsto f atBot (𝓝 0))
(hf1 : Tendsto f atTop (𝓝 1)) :
cdf f.measure = f := by
refine (cdf f.measure).eq_of_measure_of_tendsto_atBot f ?_ (tendsto_cdf_atBot _) hf0
have h_prob : IsProbabilityMeasure f.measure :=
⟨by rw [f.measure_univ hf0 hf1, sub_zero, ENNReal.ofReal_one]⟩
exact measure_cdf f.measure
open unitInterval in
lemma unitInterval.cdf_eq_real (μ : Measure I) [IsProbabilityMeasure μ] (x : I) :
cdf (μ.map Subtype.val) x.1 = μ.real (Icc 0 x) := by
haveI : IsProbabilityMeasure (μ.map Subtype.val) := isProbabilityMeasure_map (by fun_prop)
rw [ProbabilityTheory.cdf_eq_real,
map_measureReal_apply measurable_subtype_coe measurableSet_Iic, subtype_Iic_eq_Icc]
end ProbabilityTheory
open ProbabilityTheory
/-- If two real probability distributions have the same cdf, they are equal. -/
lemma MeasureTheory.Measure.eq_of_cdf (μ ν : Measure ℝ) [IsProbabilityMeasure μ]
[IsProbabilityMeasure ν] (h : cdf μ = cdf ν) : μ = ν := by
rw [← measure_cdf μ, ← measure_cdf ν, h]
@[simp] lemma MeasureTheory.Measure.cdf_eq_iff (μ ν : Measure ℝ) [IsProbabilityMeasure μ]
[IsProbabilityMeasure ν] :
cdf μ = cdf ν ↔ μ = ν :=
⟨eq_of_cdf μ ν, fun h ↦ by rw [h]⟩ |
.lake/packages/mathlib/Mathlib/Probability/ConditionalExpectation.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.Independence.Basic
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic
/-!
# Probabilistic properties of the conditional expectation
This file contains some properties about the conditional expectation which does not belong in
the main conditional expectation file.
## Main result
* `MeasureTheory.condExp_indep_eq`: If `m₁, m₂` are independent σ-algebras and `f` is an
`m₁`-measurable function, then `𝔼[f | m₂] = 𝔼[f]` almost everywhere.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory
namespace MeasureTheory
open ProbabilityTheory
variable {Ω E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
{m₁ m₂ m : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → E}
/-- If `m₁, m₂` are independent σ-algebras and `f` is `m₁`-measurable, then `𝔼[f | m₂] = 𝔼[f]`
almost everywhere. -/
theorem condExp_indep_eq (hle₁ : m₁ ≤ m) (hle₂ : m₂ ≤ m) [SigmaFinite (μ.trim hle₂)]
(hf : StronglyMeasurable[m₁] f) (hindp : Indep m₁ m₂ μ) : μ[f|m₂] =ᵐ[μ] fun _ => μ[f] := by
by_cases hfint : Integrable f μ
swap; · rw [condExp_of_not_integrable hfint, integral_undef hfint]; rfl
refine (ae_eq_condExp_of_forall_setIntegral_eq hle₂ hfint
(fun s _ hs ↦ integrableOn_const hs.ne) (fun s hms hs => ?_)
stronglyMeasurable_const.aestronglyMeasurable).symm
rw [setIntegral_const]
rw [← memLp_one_iff_integrable] at hfint
refine MemLp.induction_stronglyMeasurable hle₁ ENNReal.one_ne_top _ ?_ ?_ ?_ ?_ hfint ?_
· exact ⟨f, hf, EventuallyEq.rfl⟩
· intro c t hmt _
rw [Indep_iff] at hindp
rw [integral_indicator (hle₁ _ hmt), setIntegral_const, smul_smul, measureReal_def,
measureReal_def, ← ENNReal.toReal_mul,
mul_comm, ← hindp _ _ hmt hms, setIntegral_indicator (hle₁ _ hmt), setIntegral_const,
Set.inter_comm, measureReal_def]
· intro u v _ huint hvint hu hv hu_eq hv_eq
rw [memLp_one_iff_integrable] at huint hvint
rw [integral_add' huint hvint, smul_add, hu_eq, hv_eq,
integral_add' huint.integrableOn hvint.integrableOn]
· have heq₁ : (fun f : lpMeas E ℝ m₁ 1 μ => ∫ x, (f : Ω → E) x ∂μ) =
(fun f : Lp E 1 μ => ∫ x, f x ∂μ) ∘ Submodule.subtypeL _ := by
refine funext fun f => integral_congr_ae ?_
simp_rw [Submodule.coe_subtypeL', Submodule.coe_subtype]; norm_cast
have heq₂ : (fun f : lpMeas E ℝ m₁ 1 μ => ∫ x in s, (f : Ω → E) x ∂μ) =
(fun f : Lp E 1 μ => ∫ x in s, f x ∂μ) ∘ Submodule.subtypeL _ := by
refine funext fun f => integral_congr_ae (ae_restrict_of_ae ?_)
simp_rw [Submodule.coe_subtypeL', Submodule.coe_subtype]
exact Eventually.of_forall fun _ => (by trivial)
refine isClosed_eq (Continuous.const_smul ?_ _) ?_
· rw [heq₁]
exact continuous_integral.comp (ContinuousLinearMap.continuous _)
· rw [heq₂]
exact (continuous_setIntegral _).comp (ContinuousLinearMap.continuous _)
· intro u v huv _ hueq
rwa [← integral_congr_ae huv, ←
(setIntegral_congr_ae (hle₂ _ hms) _ : ∫ x in s, u x ∂μ = ∫ x in s, v x ∂μ)]
filter_upwards [huv] with x hx _ using hx
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/ProbabilityMassFunction/Integrals.lean | import Mathlib.Probability.ProbabilityMassFunction.Basic
import Mathlib.Probability.ProbabilityMassFunction.Constructions
import Mathlib.MeasureTheory.Integral.Bochner.Basic
/-!
# Integrals with a measure derived from probability mass functions.
This file connects `PMF` with `integral`. The main result is that the integral (i.e. the expected
value) with regard to a measure derived from a `PMF` is a sum weighted by the `PMF`.
It also provides the expected value for specific probability mass functions.
-/
namespace PMF
open MeasureTheory NNReal ENNReal TopologicalSpace
section General
variable {α : Type*} [MeasurableSpace α] [MeasurableSingletonClass α]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
theorem integral_eq_tsum (p : PMF α) (f : α → E) (hf : Integrable f p.toMeasure) :
∫ a, f a ∂(p.toMeasure) = ∑' a, (p a).toReal • f a := calc
_ = ∫ a in p.support, f a ∂(p.toMeasure) := by rw [restrict_toMeasure_support p]
_ = ∑' (a : support p), (p.toMeasure {a.val}).toReal • f a := by
apply integral_countable f p.support_countable
rwa [IntegrableOn, restrict_toMeasure_support p]
_ = ∑' (a : support p), (p a).toReal • f a := by
congr with x; congr 2
apply PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _)
_ = ∑' a, (p a).toReal • f a :=
tsum_subtype_eq_of_support_subset <| calc
(fun a ↦ (p a).toReal • f a).support ⊆ (fun a ↦ (p a).toReal).support :=
Function.support_smul_subset_left _ _
_ ⊆ support p := fun x h1 h2 => h1 (by simp [h2])
theorem integral_eq_sum [Fintype α] (p : PMF α) (f : α → E) :
∫ a, f a ∂(p.toMeasure) = ∑ a, (p a).toReal • f a := by
rw [integral_fintype _ .of_finite]
congr with x
rw [measureReal_def]
congr 2
exact PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _)
end General
theorem bernoulli_expectation {p : ℝ≥0} (h : p ≤ 1) :
∫ b, cond b 1 0 ∂((bernoulli p h).toMeasure) = p.toReal := by simp [integral_eq_sum]
end PMF |
.lake/packages/mathlib/Mathlib/Probability/ProbabilityMassFunction/Monad.lean | import Mathlib.Probability.ProbabilityMassFunction.Basic
/-!
# Monad Operations for Probability Mass Functions
This file constructs two operations on `PMF` that give it a monad structure.
`pure a` is the distribution where a single value `a` has probability `1`.
`bind pa pb : PMF β` is the distribution given by sampling `a : α` from `pa : PMF α`,
and then sampling from `pb a : PMF β` to get a final result `b : β`.
`bindOnSupport` generalizes `bind` to allow binding to a partial function,
so that the second argument only needs to be defined on the support of the first argument.
-/
noncomputable section
variable {α β γ : Type*}
open NNReal ENNReal
open MeasureTheory
namespace PMF
section Pure
open scoped Classical in
/-- The pure `PMF` is the `PMF` where all the mass lies in one point.
The value of `pure a` is `1` at `a` and `0` elsewhere. -/
def pure (a : α) : PMF α :=
⟨fun a' => if a' = a then 1 else 0, hasSum_ite_eq _ _⟩
variable (a a' : α)
open scoped Classical in
@[simp]
theorem pure_apply : pure a a' = if a' = a then 1 else 0 := rfl
@[simp]
theorem support_pure : (pure a).support = {a} :=
Set.ext fun a' => by simp [mem_support_iff]
theorem mem_support_pure_iff : a' ∈ (pure a).support ↔ a' = a := by simp
theorem pure_apply_self : pure a a = 1 :=
if_pos rfl
theorem pure_apply_of_ne (h : a' ≠ a) : pure a a' = 0 :=
if_neg h
instance [Inhabited α] : Inhabited (PMF α) :=
⟨pure default⟩
section Measure
variable (s : Set α)
open scoped Classical in
@[simp]
theorem toOuterMeasure_pure_apply : (pure a).toOuterMeasure s = if a ∈ s then 1 else 0 := by
refine (toOuterMeasure_apply (pure a) s).trans ?_
split_ifs with ha
· refine (tsum_congr fun b => ?_).trans (tsum_ite_eq a 1)
exact ite_eq_left_iff.2 fun hb =>
symm (ite_eq_right_iff.2 fun h => (hb <| h.symm ▸ ha).elim)
· refine (tsum_congr fun b => ?_).trans tsum_zero
exact ite_eq_right_iff.2 fun hb =>
ite_eq_right_iff.2 fun h => (ha <| h ▸ hb).elim
variable [MeasurableSpace α]
open scoped Classical in
/-- The measure of a set under `pure a` is `1` for sets containing `a` and `0` otherwise. -/
@[simp]
theorem toMeasure_pure_apply (hs : MeasurableSet s) :
(pure a).toMeasure s = if a ∈ s then 1 else 0 :=
(toMeasure_apply_eq_toOuterMeasure_apply (pure a) hs).trans (toOuterMeasure_pure_apply a s)
theorem toMeasure_pure : (pure a).toMeasure = Measure.dirac a :=
Measure.ext fun s hs => by rw [toMeasure_pure_apply a s hs, Measure.dirac_apply' a hs]; rfl
@[simp]
theorem toPMF_dirac [Countable α] [h : MeasurableSingletonClass α] :
(Measure.dirac a).toPMF = pure a := by
rw [toPMF_eq_iff_toMeasure_eq, toMeasure_pure]
end Measure
end Pure
section Bind
/-- The monadic bind operation for `PMF`. -/
def bind (p : PMF α) (f : α → PMF β) : PMF β :=
⟨fun b => ∑' a, p a * f a b,
ENNReal.summable.hasSum_iff.2
(ENNReal.tsum_comm.trans <| by simp only [ENNReal.tsum_mul_left, tsum_coe, mul_one])⟩
variable (p : PMF α) (f : α → PMF β) (g : β → PMF γ)
@[simp]
theorem bind_apply (b : β) : p.bind f b = ∑' a, p a * f a b := rfl
@[simp]
theorem support_bind : (p.bind f).support = ⋃ a ∈ p.support, (f a).support :=
Set.ext fun b => by simp [mem_support_iff, ENNReal.tsum_eq_zero, not_or]
theorem mem_support_bind_iff (b : β) :
b ∈ (p.bind f).support ↔ ∃ a ∈ p.support, b ∈ (f a).support := by
simp only [support_bind, Set.mem_iUnion, exists_prop]
@[simp]
theorem pure_bind (a : α) (f : α → PMF β) : (pure a).bind f = f a := by
ext
simp
@[simp]
theorem bind_pure : p.bind pure = p :=
PMF.ext fun x => (bind_apply _ _ _).trans (_root_.trans
(tsum_eq_single x fun y hy => by rw [pure_apply_of_ne _ _ hy.symm, mul_zero]) <|
by rw [pure_apply_self, mul_one])
@[simp]
theorem bind_const (p : PMF α) (q : PMF β) : (p.bind fun _ => q) = q :=
PMF.ext fun x => by rw [bind_apply, ENNReal.tsum_mul_right, tsum_coe, one_mul]
@[simp]
theorem bind_bind : (p.bind f).bind g = p.bind fun a => (f a).bind g :=
PMF.ext fun b => by
simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm,
ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm
theorem bind_comm (p : PMF α) (q : PMF β) (f : α → β → PMF γ) :
(p.bind fun a => q.bind (f a)) = q.bind fun b => p.bind fun a => f a b :=
PMF.ext fun b => by
simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm,
ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm
section Measure
variable (s : Set β)
@[simp]
theorem toOuterMeasure_bind_apply :
(p.bind f).toOuterMeasure s = ∑' a, p a * (f a).toOuterMeasure s := by
classical
calc
(p.bind f).toOuterMeasure s = ∑' b, if b ∈ s then ∑' a, p a * f a b else 0 := by
simp [toOuterMeasure_apply, Set.indicator_apply]
_ = ∑' (b) (a), p a * if b ∈ s then f a b else 0 := tsum_congr fun b => by split_ifs <;> simp
_ = ∑' (a) (b), p a * if b ∈ s then f a b else 0 := ENNReal.tsum_comm
_ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 := tsum_congr fun _ => ENNReal.tsum_mul_left
_ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 :=
(tsum_congr fun a => (congr_arg fun x => p a * x) <| tsum_congr fun b => by split_ifs <;> rfl)
_ = ∑' a, p a * (f a).toOuterMeasure s :=
tsum_congr fun a => by simp only [toOuterMeasure_apply, Set.indicator_apply]
/-- The measure of a set under `p.bind f` is the sum over `a : α`
of the probability of `a` under `p` times the measure of the set under `f a`. -/
@[simp]
theorem toMeasure_bind_apply [MeasurableSpace β] (hs : MeasurableSet s) :
(p.bind f).toMeasure s = ∑' a, p a * (f a).toMeasure s :=
(toMeasure_apply_eq_toOuterMeasure_apply (p.bind f) hs).trans
((toOuterMeasure_bind_apply p f s).trans
(tsum_congr fun a =>
congr_arg (fun x => p a * x) (toMeasure_apply_eq_toOuterMeasure_apply (f a) hs).symm))
end Measure
end Bind
instance : Monad PMF where
pure a := pure a
bind pa pb := pa.bind pb
section BindOnSupport
/-- Generalized version of `bind` allowing `f` to only be defined on the support of `p`.
`p.bind f` is equivalent to `p.bindOnSupport (fun a _ ↦ f a)`, see `bindOnSupport_eq_bind`. -/
def bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β) : PMF β :=
⟨fun b => ∑' a, p a * if h : p a = 0 then 0 else f a h b, ENNReal.summable.hasSum_iff.2 (by
refine ENNReal.tsum_comm.trans (_root_.trans (tsum_congr fun a => ?_) p.tsum_coe)
simp_rw [ENNReal.tsum_mul_left]
split_ifs with h
· simp only [h, zero_mul]
· rw [(f a h).tsum_coe, mul_one])⟩
variable {p : PMF α} (f : ∀ a ∈ p.support, PMF β)
@[simp]
theorem bindOnSupport_apply (b : β) :
p.bindOnSupport f b = ∑' a, p a * if h : p a = 0 then 0 else f a h b := rfl
@[simp]
theorem support_bindOnSupport :
(p.bindOnSupport f).support = ⋃ (a : α) (h : a ∈ p.support), (f a h).support := by
ext
-- `simp` suffices; squeezed for performance
simp only [mem_support_iff, bindOnSupport_apply, ne_eq, ENNReal.tsum_eq_zero,
dite_eq_left_iff, mul_eq_zero, not_forall, not_or, and_exists_self,
Set.mem_iUnion]
theorem mem_support_bindOnSupport_iff (b : β) :
b ∈ (p.bindOnSupport f).support ↔ ∃ (a : α) (h : a ∈ p.support), b ∈ (f a h).support := by
simp only [support_bindOnSupport, Set.mem_iUnion]
/-- `bindOnSupport` reduces to `bind` if `f` doesn't depend on the additional hypothesis. -/
@[simp]
theorem bindOnSupport_eq_bind (p : PMF α) (f : α → PMF β) :
(p.bindOnSupport fun a _ => f a) = p.bind f := by
ext b
have : ∀ a, ite (p a = 0) 0 (p a * f a b) = p a * f a b :=
fun a => ite_eq_right_iff.2 fun h => h.symm ▸ symm (zero_mul <| f a b)
simp only [bindOnSupport_apply fun a _ => f a, p.bind_apply f, dite_eq_ite, mul_ite,
mul_zero, this]
theorem bindOnSupport_eq_zero_iff (b : β) :
p.bindOnSupport f b = 0 ↔ ∀ (a) (ha : p a ≠ 0), f a ha b = 0 := by
simp only [bindOnSupport_apply, ENNReal.tsum_eq_zero, mul_eq_zero, or_iff_not_imp_left]
exact ⟨fun h a ha => Trans.trans (dif_neg ha).symm (h a ha),
fun h a ha => Trans.trans (dif_neg ha) (h a ha)⟩
@[simp]
theorem pure_bindOnSupport (a : α) (f : ∀ (a' : α) (_ : a' ∈ (pure a).support), PMF β) :
(pure a).bindOnSupport f = f a ((mem_support_pure_iff a a).mpr rfl) := by
refine PMF.ext fun b => ?_
simp only [bindOnSupport_apply, pure_apply]
classical
refine _root_.trans (tsum_congr fun a' => ?_) (tsum_ite_eq a (fun _ ↦ _))
by_cases h : a' = a <;> simp [h]
theorem bindOnSupport_pure (p : PMF α) : (p.bindOnSupport fun a _ => pure a) = p := by
simp only [PMF.bind_pure, PMF.bindOnSupport_eq_bind]
@[simp]
theorem bindOnSupport_bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β)
(g : ∀ b ∈ (p.bindOnSupport f).support, PMF γ) :
(p.bindOnSupport f).bindOnSupport g =
p.bindOnSupport fun a ha =>
(f a ha).bindOnSupport fun b hb =>
g b ((mem_support_bindOnSupport_iff f b).mpr ⟨a, ha, hb⟩) := by
refine PMF.ext fun a => ?_
dsimp only [bindOnSupport_apply]
simp only [← tsum_dite_right, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm]
classical
simp only [ENNReal.tsum_eq_zero]
refine ENNReal.tsum_comm.trans (tsum_congr fun a' => tsum_congr fun b => ?_)
split_ifs with h _ h_1 H h_2
any_goals ring1
· absurd H
simpa [h] using h_1 a'
· simp [h_2]
theorem bindOnSupport_comm (p : PMF α) (q : PMF β) (f : ∀ a ∈ p.support, ∀ b ∈ q.support, PMF γ) :
(p.bindOnSupport fun a ha => q.bindOnSupport (f a ha)) =
q.bindOnSupport fun b hb => p.bindOnSupport fun a ha => f a ha b hb := by
apply PMF.ext; rintro c
simp only [bindOnSupport_apply, ← tsum_dite_right,
ENNReal.tsum_mul_left.symm]
refine _root_.trans ENNReal.tsum_comm (tsum_congr fun b => tsum_congr fun a => ?_)
split_ifs with h1 h2 h2 <;> ring
section Measure
variable (s : Set β)
@[simp]
theorem toOuterMeasure_bindOnSupport_apply :
(p.bindOnSupport f).toOuterMeasure s =
∑' a, p a * if h : p a = 0 then 0 else (f a h).toOuterMeasure s := by
simp only [toOuterMeasure_apply]
classical
calc
(∑' b, ite (b ∈ s) (∑' a, p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0) =
∑' (b) (a), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
tsum_congr fun b => by split_ifs with hbs <;> simp only [tsum_zero]
_ = ∑' (a) (b), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
ENNReal.tsum_comm
_ = ∑' a, p a * ∑' b, ite (b ∈ s) (dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
(tsum_congr fun a => by simp only [← ENNReal.tsum_mul_left, mul_ite, mul_zero])
_ = ∑' a, p a * dite (p a = 0) (fun h => 0) fun h => ∑' b, ite (b ∈ s) (f a h b) 0 :=
tsum_congr fun a => by split_ifs with ha <;> simp only [ite_self, tsum_zero]
/-- The measure of a set under `p.bindOnSupport f` is the sum over `a : α`
of the probability of `a` under `p` times the measure of the set under `f a _`.
The additional if statement is needed since `f` is only a partial function. -/
@[simp]
theorem toMeasure_bindOnSupport_apply [MeasurableSpace β] (hs : MeasurableSet s) :
(p.bindOnSupport f).toMeasure s =
∑' a, p a * if h : p a = 0 then 0 else (f a h).toMeasure s := by
simp only [toMeasure_apply_eq_toOuterMeasure_apply _ hs, toOuterMeasure_bindOnSupport_apply]
end Measure
end BindOnSupport
end PMF |
.lake/packages/mathlib/Mathlib/Probability/ProbabilityMassFunction/Basic.lean | import Mathlib.Topology.Instances.ENNReal.Lemmas
import Mathlib.MeasureTheory.Measure.Dirac
/-!
# Probability mass functions
This file is about probability mass functions or discrete probability measures:
a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`.
Construction of monadic `pure` and `bind` is found in `ProbabilityMassFunction/Monad.lean`,
other constructions of `PMF`s are found in `ProbabilityMassFunction/Constructions.lean`.
Given `p : PMF α`, `PMF.toOuterMeasure` constructs an `OuterMeasure` on `α`,
by assigning each set the sum of the probabilities of each of its elements.
Under this outer measure, every set is Carathéodory-measurable,
so we can further extend this to a `Measure` on `α`, see `PMF.toMeasure`.
`PMF.toMeasure.isProbabilityMeasure` shows this associated measure is a probability measure.
Conversely, given a probability measure `μ` on a measurable space `α` with all singleton sets
measurable, `μ.toPMF` constructs a `PMF` on `α`, setting the probability mass of a point `x`
to be the measure of the singleton set `{x}`.
## Tags
probability mass function, discrete probability measure
-/
noncomputable section
variable {α : Type*}
open NNReal ENNReal MeasureTheory
/-- A probability mass function, or discrete probability measures is a function `α → ℝ≥0∞` such
that the values have (infinite) sum `1`. -/
def PMF.{u} (α : Type u) : Type u :=
{ f : α → ℝ≥0∞ // HasSum f 1 }
namespace PMF
instance instFunLike : FunLike (PMF α) α ℝ≥0∞ where
coe p a := p.1 a
coe_injective' _ _ h := Subtype.eq h
@[ext]
protected theorem ext {p q : PMF α} (h : ∀ x, p x = q x) : p = q :=
DFunLike.ext p q h
theorem hasSum_coe_one (p : PMF α) : HasSum p 1 :=
p.2
@[simp]
theorem tsum_coe (p : PMF α) : ∑' a, p a = 1 :=
p.hasSum_coe_one.tsum_eq
theorem tsum_coe_ne_top (p : PMF α) : ∑' a, p a ≠ ∞ :=
p.tsum_coe.symm ▸ ENNReal.one_ne_top
theorem tsum_coe_indicator_ne_top (p : PMF α) (s : Set α) : ∑' a, s.indicator p a ≠ ∞ :=
ne_of_lt (lt_of_le_of_lt
(ENNReal.tsum_le_tsum (fun _ => Set.indicator_apply_le fun _ => le_rfl))
(lt_of_le_of_ne le_top p.tsum_coe_ne_top))
@[simp]
theorem coe_ne_zero (p : PMF α) : ⇑p ≠ 0 := fun hp =>
zero_ne_one ((tsum_zero.symm.trans (tsum_congr fun x => symm (congr_fun hp x))).trans p.tsum_coe)
/-- The support of a `PMF` is the set where it is nonzero. -/
def support (p : PMF α) : Set α :=
Function.support p
@[simp]
theorem mem_support_iff (p : PMF α) (a : α) : a ∈ p.support ↔ p a ≠ 0 := Iff.rfl
@[simp]
theorem support_nonempty (p : PMF α) : p.support.Nonempty :=
Function.support_nonempty_iff.2 p.coe_ne_zero
@[simp]
theorem support_countable (p : PMF α) : p.support.Countable :=
Summable.countable_support_ennreal (tsum_coe_ne_top p)
theorem apply_eq_zero_iff (p : PMF α) (a : α) : p a = 0 ↔ a ∉ p.support := by
rw [mem_support_iff, Classical.not_not]
theorem apply_pos_iff (p : PMF α) (a : α) : 0 < p a ↔ a ∈ p.support :=
pos_iff_ne_zero.trans (p.mem_support_iff a).symm
theorem apply_eq_one_iff (p : PMF α) (a : α) : p a = 1 ↔ p.support = {a} := by
refine ⟨fun h => Set.Subset.antisymm (fun a' ha' => by_contra fun ha => ?_)
fun a' ha' => ha'.symm ▸ (p.mem_support_iff a).2 fun ha => zero_ne_one <| ha.symm.trans h,
fun h => _root_.trans (symm <| tsum_eq_single a
fun a' ha' => (p.apply_eq_zero_iff a').2 (h.symm ▸ ha')) p.tsum_coe⟩
suffices 1 < ∑' a, p a from ne_of_lt this p.tsum_coe.symm
classical
have : 0 < ∑' b, ite (b = a) 0 (p b) := lt_of_le_of_ne' zero_le'
(ENNReal.summable.tsum_ne_zero_iff.2
⟨a', ite_ne_left_iff.2 ⟨ha, Ne.symm <| (p.mem_support_iff a').2 ha'⟩⟩)
calc
1 = 1 + 0 := (add_zero 1).symm
_ < p a + ∑' b, ite (b = a) 0 (p b) :=
(ENNReal.add_lt_add_of_le_of_lt ENNReal.one_ne_top (le_of_eq h.symm) this)
_ = ite (a = a) (p a) 0 + ∑' b, ite (b = a) 0 (p b) := by rw [eq_self_iff_true, if_true]
_ = (∑' b, ite (b = a) (p b) 0) + ∑' b, ite (b = a) 0 (p b) := by
congr
exact symm (tsum_eq_single a fun b hb => if_neg hb)
_ = ∑' b, (ite (b = a) (p b) 0 + ite (b = a) 0 (p b)) := ENNReal.tsum_add.symm
_ = ∑' b, p b := tsum_congr fun b => by split_ifs <;> simp only [zero_add, add_zero]
theorem coe_le_one (p : PMF α) (a : α) : p a ≤ 1 := by
classical
refine hasSum_le (fun b => ?_) (hasSum_ite_eq a (p a)) (hasSum_coe_one p)
split_ifs with h <;> simp only [h, zero_le', le_rfl]
theorem apply_ne_top (p : PMF α) (a : α) : p a ≠ ∞ :=
ne_of_lt (lt_of_le_of_lt (p.coe_le_one a) ENNReal.one_lt_top)
theorem apply_lt_top (p : PMF α) (a : α) : p a < ∞ :=
lt_of_le_of_ne le_top (p.apply_ne_top a)
section OuterMeasure
open OuterMeasure
/-- Construct an `OuterMeasure` from a `PMF`, by assigning measure to each set `s : Set α` equal
to the sum of `p x` for each `x ∈ α`. -/
def toOuterMeasure (p : PMF α) : OuterMeasure α :=
OuterMeasure.sum fun x : α => p x • dirac x
variable (p : PMF α) (s : Set α)
theorem toOuterMeasure_apply : p.toOuterMeasure s = ∑' x, s.indicator p x :=
tsum_congr fun x => smul_dirac_apply (p x) x s
@[simp]
theorem toOuterMeasure_caratheodory : p.toOuterMeasure.caratheodory = ⊤ := by
refine eq_top_iff.2 <| le_trans (le_sInf fun x hx => ?_) (le_sum_caratheodory _)
have ⟨y, hy⟩ := hx
exact
((le_of_eq (dirac_caratheodory y).symm).trans (le_smul_caratheodory _ _)).trans (le_of_eq hy)
@[simp]
theorem toOuterMeasure_apply_finset (s : Finset α) : p.toOuterMeasure s = ∑ x ∈ s, p x := by
refine (toOuterMeasure_apply p s).trans ((tsum_eq_sum (s := s) ?_).trans ?_)
· exact fun x hx => Set.indicator_of_notMem (Finset.mem_coe.not.2 hx) _
· exact Finset.sum_congr rfl fun x hx => Set.indicator_of_mem (Finset.mem_coe.2 hx) _
theorem toOuterMeasure_apply_singleton (a : α) : p.toOuterMeasure {a} = p a := by
refine (p.toOuterMeasure_apply {a}).trans ((tsum_eq_single a fun b hb => ?_).trans ?_)
· classical exact ite_eq_right_iff.2 fun hb' => False.elim <| hb hb'
· classical exact ite_eq_left_iff.2 fun ha' => False.elim <| ha' rfl
theorem toOuterMeasure_injective : (toOuterMeasure : PMF α → OuterMeasure α).Injective :=
fun p q h => PMF.ext fun x => (p.toOuterMeasure_apply_singleton x).symm.trans
((congr_fun (congr_arg _ h) _).trans <| q.toOuterMeasure_apply_singleton x)
@[simp]
theorem toOuterMeasure_inj {p q : PMF α} : p.toOuterMeasure = q.toOuterMeasure ↔ p = q :=
toOuterMeasure_injective.eq_iff
theorem toOuterMeasure_apply_eq_zero_iff : p.toOuterMeasure s = 0 ↔ Disjoint p.support s := by
rw [toOuterMeasure_apply, ENNReal.tsum_eq_zero]
exact funext_iff.symm.trans Set.indicator_eq_zero'
theorem toOuterMeasure_apply_eq_one_iff : p.toOuterMeasure s = 1 ↔ p.support ⊆ s := by
refine (p.toOuterMeasure_apply s).symm ▸ ⟨fun h a hap => ?_, fun h => ?_⟩
· refine by_contra fun hs => ne_of_lt ?_ (h.trans p.tsum_coe.symm)
have hs' : s.indicator p a = 0 := Set.indicator_apply_eq_zero.2 fun hs' => False.elim <| hs hs'
have hsa : s.indicator p a < p a := hs'.symm ▸ (p.apply_pos_iff a).2 hap
exact ENNReal.tsum_lt_tsum (p.tsum_coe_indicator_ne_top s)
(fun x => Set.indicator_apply_le fun _ => le_rfl) hsa
· classical suffices ∀ (x) (_ : x ∉ s), p x = 0 from
_root_.trans (tsum_congr
fun a => (Set.indicator_apply s p a).trans
(ite_eq_left_iff.2 <| symm ∘ this a)) p.tsum_coe
exact fun a ha => (p.apply_eq_zero_iff a).2 <| Set.notMem_subset h ha
@[simp]
theorem toOuterMeasure_apply_inter_support :
p.toOuterMeasure (s ∩ p.support) = p.toOuterMeasure s := by
simp only [toOuterMeasure_apply, PMF.support, Set.indicator_inter_support]
/-- Slightly stronger than `OuterMeasure.mono` having an intersection with `p.support`. -/
theorem toOuterMeasure_mono {s t : Set α} (h : s ∩ p.support ⊆ t) :
p.toOuterMeasure s ≤ p.toOuterMeasure t :=
le_trans (le_of_eq (toOuterMeasure_apply_inter_support p s).symm) (p.toOuterMeasure.mono h)
theorem toOuterMeasure_apply_eq_of_inter_support_eq {s t : Set α}
(h : s ∩ p.support = t ∩ p.support) : p.toOuterMeasure s = p.toOuterMeasure t :=
le_antisymm (p.toOuterMeasure_mono (h.symm ▸ Set.inter_subset_left))
(p.toOuterMeasure_mono (h ▸ Set.inter_subset_left))
@[simp]
theorem toOuterMeasure_apply_fintype [Fintype α] : p.toOuterMeasure s = ∑ x, s.indicator p x :=
(p.toOuterMeasure_apply s).trans (tsum_eq_sum fun x h => absurd (Finset.mem_univ x) h)
end OuterMeasure
section Measure
/-- Since every set is Carathéodory-measurable under `PMF.toOuterMeasure`,
we can further extend this `OuterMeasure` to a `Measure` on `α`. -/
def toMeasure [MeasurableSpace α] (p : PMF α) : Measure α :=
p.toOuterMeasure.toMeasure (p.toOuterMeasure_caratheodory.symm ▸ le_top)
variable [MeasurableSpace α] (p : PMF α) {s : Set α}
theorem toOuterMeasure_apply_le_toMeasure_apply (s : Set α) : p.toOuterMeasure s ≤ p.toMeasure s :=
le_toMeasure_apply p.toOuterMeasure _ s
theorem toMeasure_apply_eq_toOuterMeasure_apply (hs : MeasurableSet s) :
p.toMeasure s = p.toOuterMeasure s :=
toMeasure_apply p.toOuterMeasure _ hs
theorem toMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = ∑' x, s.indicator p x :=
(p.toMeasure_apply_eq_toOuterMeasure_apply hs).trans (p.toOuterMeasure_apply s)
theorem toMeasure_apply_singleton (a : α) (h : MeasurableSet ({a} : Set α)) :
p.toMeasure {a} = p a := by
simp [p.toMeasure_apply_eq_toOuterMeasure_apply h, toOuterMeasure_apply_singleton]
theorem toMeasure_apply_eq_zero_iff (hs : MeasurableSet s) :
p.toMeasure s = 0 ↔ Disjoint p.support s := by
rw [p.toMeasure_apply_eq_toOuterMeasure_apply hs, toOuterMeasure_apply_eq_zero_iff]
theorem toMeasure_apply_eq_one_iff (hs : MeasurableSet s) : p.toMeasure s = 1 ↔ p.support ⊆ s :=
(p.toMeasure_apply_eq_toOuterMeasure_apply hs).symm ▸ p.toOuterMeasure_apply_eq_one_iff s
theorem toMeasure_mono {t : Set α} (hs : MeasurableSet s)
(h : s ∩ p.support ⊆ t) : p.toMeasure s ≤ p.toMeasure t := by
rw [p.toMeasure_apply_eq_toOuterMeasure_apply hs]
exact (p.toOuterMeasure_mono h).trans (p.toOuterMeasure_apply_le_toMeasure_apply t)
@[simp]
theorem toMeasure_apply_inter_support (hs : MeasurableSet s) :
p.toMeasure (s ∩ p.support) = p.toMeasure s :=
(measure_mono s.inter_subset_left).antisymm (p.toMeasure_mono hs (refl _))
@[simp]
theorem restrict_toMeasure_support : p.toMeasure.restrict p.support = p.toMeasure := by
ext s hs
rw [Measure.restrict_apply hs, p.toMeasure_apply_inter_support hs]
theorem toMeasure_apply_eq_of_inter_support_eq {t : Set α} (hs : MeasurableSet s)
(ht : MeasurableSet t) (h : s ∩ p.support = t ∩ p.support) : p.toMeasure s = p.toMeasure t := by
simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using
p.toOuterMeasure_apply_eq_of_inter_support_eq h
section MeasurableSingletonClass
variable [MeasurableSingletonClass α]
theorem toMeasure_injective : (toMeasure : PMF α → Measure α).Injective := by
intro p q h
ext x
rw [← p.toMeasure_apply_singleton x <| measurableSet_singleton x,
← q.toMeasure_apply_singleton x <| measurableSet_singleton x, h]
@[simp]
theorem toMeasure_inj {p q : PMF α} : p.toMeasure = q.toMeasure ↔ p = q :=
toMeasure_injective.eq_iff
theorem toMeasure_apply_eq_toOuterMeasure (s : Set α) : p.toMeasure s = p.toOuterMeasure s := by
have hs := (p.support_countable.mono s.inter_subset_right).measurableSet
rw [← restrict_toMeasure_support, Measure.restrict_apply' p.support_countable.measurableSet,
p.toMeasure_apply_eq_toOuterMeasure_apply hs, toOuterMeasure_apply_inter_support]
@[simp]
theorem toMeasure_apply_finset (s : Finset α) : p.toMeasure s = ∑ x ∈ s, p x :=
(p.toMeasure_apply_eq_toOuterMeasure s).trans (p.toOuterMeasure_apply_finset s)
theorem toMeasure_apply_eq_tsum (s : Set α) : p.toMeasure s = ∑' x, s.indicator p x :=
(p.toMeasure_apply_eq_toOuterMeasure s).trans (p.toOuterMeasure_apply s)
@[deprecated (since := "2025-06-23")] alias toMeasure_apply_of_finite := toMeasure_apply_eq_tsum
@[simp]
theorem toMeasure_apply_fintype (s : Set α) [Fintype α] : p.toMeasure s = ∑ x, s.indicator p x :=
(p.toMeasure_apply_eq_toOuterMeasure s).trans (p.toOuterMeasure_apply_fintype s)
end MeasurableSingletonClass
end Measure
end PMF
namespace MeasureTheory
open PMF
namespace Measure
/-- Given that `α` is a countable, measurable space with all singleton sets measurable,
we can convert any probability measure into a `PMF`, where the mass of a point
is the measure of the singleton set under the original measure. -/
def toPMF [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (μ : Measure α)
[h : IsProbabilityMeasure μ] : PMF α :=
⟨fun x => μ ({x} : Set α),
ENNReal.summable.hasSum_iff.2
(_root_.trans
(symm <|
(tsum_indicator_apply_singleton μ Set.univ MeasurableSet.univ).symm.trans
(tsum_congr fun x => congr_fun (Set.indicator_univ _) x))
h.measure_univ)⟩
variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (μ : Measure α)
[IsProbabilityMeasure μ]
theorem toPMF_apply (x : α) : μ.toPMF x = μ {x} := rfl
@[simp]
theorem toPMF_toMeasure : μ.toPMF.toMeasure = μ :=
Measure.ext fun s hs => by
rw [μ.toPMF.toMeasure_apply hs, ← μ.tsum_indicator_apply_singleton s hs]
rfl
end Measure
end MeasureTheory
namespace PMF
/-- The measure associated to a `PMF` by `toMeasure` is a probability measure. -/
instance toMeasure.isProbabilityMeasure [MeasurableSpace α] (p : PMF α) :
IsProbabilityMeasure p.toMeasure :=
⟨by
simpa only [MeasurableSet.univ, toMeasure_apply_eq_toOuterMeasure_apply, Set.indicator_univ,
toOuterMeasure_apply, ENNReal.coe_eq_one] using tsum_coe p⟩
variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (p : PMF α)
@[simp]
theorem toMeasure_toPMF : p.toMeasure.toPMF = p :=
PMF.ext fun x => by
rw [← p.toMeasure_apply_singleton x (measurableSet_singleton x), p.toMeasure.toPMF_apply]
theorem toMeasure_eq_iff_eq_toPMF (μ : Measure α) [IsProbabilityMeasure μ] :
p.toMeasure = μ ↔ p = μ.toPMF := by rw [← toMeasure_inj, Measure.toPMF_toMeasure]
theorem toPMF_eq_iff_toMeasure_eq (μ : Measure α) [IsProbabilityMeasure μ] :
μ.toPMF = p ↔ μ = p.toMeasure := by rw [← toMeasure_inj, Measure.toPMF_toMeasure]
end PMF |
.lake/packages/mathlib/Mathlib/Probability/ProbabilityMassFunction/Constructions.lean | import Mathlib.Probability.ProbabilityMassFunction.Monad
import Mathlib.Control.ULiftable
/-!
# Specific Constructions of Probability Mass Functions
This file gives a number of different `PMF` constructions for common probability distributions.
`map` and `seq` allow pushing a `PMF α` along a function `f : α → β` (or distribution of
functions `f : PMF (α → β)`) to get a `PMF β`.
`ofFinset` and `ofFintype` simplify the construction of a `PMF α` from a function `f : α → ℝ≥0∞`,
by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`.
`normalize` constructs a `PMF α` by normalizing a function `f : α → ℝ≥0∞` by its sum,
and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution.
`bernoulli` represents the Bernoulli distribution on `Bool`.
-/
universe u v
namespace PMF
noncomputable section
variable {α β γ : Type*}
open NNReal ENNReal Finset MeasureTheory
section Map
/-- The functorial action of a function on a `PMF`. -/
def map (f : α → β) (p : PMF α) : PMF β :=
bind p (pure ∘ f)
variable (f : α → β) (p : PMF α) (b : β)
theorem monad_map_eq_map {α β : Type u} (f : α → β) (p : PMF α) : f <$> p = p.map f := rfl
open scoped Classical in
@[simp]
theorem map_apply : (map f p) b = ∑' a, if b = f a then p a else 0 := by simp [map]
@[simp]
theorem support_map : (map f p).support = f '' p.support :=
Set.ext fun b => by simp [map, @eq_comm β b]
theorem mem_support_map_iff : b ∈ (map f p).support ↔ ∃ a ∈ p.support, f a = b := by simp
theorem bind_pure_comp : bind p (pure ∘ f) = map f p := rfl
theorem map_id : map id p = p :=
bind_pure _
theorem map_comp (g : β → γ) : (p.map f).map g = p.map (g ∘ f) := by simp [map, Function.comp_def]
theorem pure_map (a : α) : (pure a).map f = pure (f a) :=
pure_bind _ _
theorem map_bind (q : α → PMF β) (f : β → γ) : (p.bind q).map f = p.bind fun a => (q a).map f :=
bind_bind _ _ _
@[simp]
theorem bind_map (p : PMF α) (f : α → β) (q : β → PMF γ) : (p.map f).bind q = p.bind (q ∘ f) :=
(bind_bind _ _ _).trans (congr_arg _ (funext fun _ => pure_bind _ _))
@[simp]
theorem map_const : p.map (Function.const α b) = pure b := by
simp only [map, Function.comp_def, bind_const, Function.const]
section Measure
variable (s : Set β)
@[simp]
theorem toOuterMeasure_map_apply : (p.map f).toOuterMeasure s = p.toOuterMeasure (f ⁻¹' s) := by
simp [map, Set.indicator, toOuterMeasure_apply p (f ⁻¹' s)]
rfl
variable {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
@[simp]
theorem toMeasure_map_apply (hf : Measurable f)
(hs : MeasurableSet s) : (p.map f).toMeasure s = p.toMeasure (f ⁻¹' s) := by
rw [toMeasure_apply_eq_toOuterMeasure_apply _ hs,
toMeasure_apply_eq_toOuterMeasure_apply _ (measurableSet_preimage hf hs)]
exact toOuterMeasure_map_apply f p s
@[simp]
lemma toMeasure_map (p : PMF α) (hf : Measurable f) : p.toMeasure.map f = (p.map f).toMeasure := by
ext s hs : 1; rw [PMF.toMeasure_map_apply _ _ _ hf hs, Measure.map_apply hf hs]
end Measure
end Map
section Seq
/-- The monadic sequencing operation for `PMF`. -/
def seq (q : PMF (α → β)) (p : PMF α) : PMF β :=
q.bind fun m => p.bind fun a => pure (m a)
variable (q : PMF (α → β)) (p : PMF α) (b : β)
theorem monad_seq_eq_seq {α β : Type u} (q : PMF (α → β)) (p : PMF α) : q <*> p = q.seq p := rfl
open scoped Classical in
@[simp]
theorem seq_apply : (seq q p) b = ∑' (f : α → β) (a : α), if b = f a then q f * p a else 0 := by
simp only [seq, mul_boole, bind_apply, pure_apply]
refine tsum_congr fun f => ENNReal.tsum_mul_left.symm.trans (tsum_congr fun a => ?_)
simpa only [mul_zero] using mul_ite (b = f a) (q f) (p a) 0
@[simp]
theorem support_seq : (seq q p).support = ⋃ f ∈ q.support, f '' p.support :=
Set.ext fun b => by simp [-mem_support_iff, seq, @eq_comm β b]
theorem mem_support_seq_iff : b ∈ (seq q p).support ↔ ∃ f ∈ q.support, b ∈ f '' p.support := by simp
end Seq
instance : LawfulFunctor PMF where
map_const := rfl
id_map := bind_pure
comp_map _ _ _ := (map_comp _ _ _).symm
instance : LawfulMonad PMF := LawfulMonad.mk'
(bind_pure_comp := fun _ _ => rfl)
(id_map := id_map)
(pure_bind := pure_bind)
(bind_assoc := bind_bind)
/--
This instance allows `do` notation for `PMF` to be used across universes, for instance as
```lean4
example {R : Type u} [Ring R] (x : PMF ℕ) : PMF R := do
let ⟨n⟩ ← ULiftable.up x
pure n
```
where `x` is in universe `0`, but the return value is in universe `u`.
-/
instance : ULiftable PMF.{u} PMF.{v} where
congr e :=
{ toFun := map e, invFun := map e.symm
left_inv := fun a => by simp [map_comp, map_id]
right_inv := fun a => by simp [map_comp, map_id] }
section OfFinset
/-- Given a finset `s` and a function `f : α → ℝ≥0∞` with sum `1` on `s`,
such that `f a = 0` for `a ∉ s`, we get a `PMF`. -/
def ofFinset (f : α → ℝ≥0∞) (s : Finset α) (h : ∑ a ∈ s, f a = 1)
(h' : ∀ (a) (_ : a ∉ s), f a = 0) : PMF α :=
⟨f, h ▸ hasSum_sum_of_ne_finset_zero h'⟩
variable {f : α → ℝ≥0∞} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ (a) (_ : a ∉ s), f a = 0)
@[simp]
theorem ofFinset_apply (a : α) : ofFinset f s h h' a = f a := rfl
@[simp]
theorem support_ofFinset : (ofFinset f s h h').support = ↑s ∩ Function.support f :=
Set.ext fun a => by simpa [mem_support_iff] using mt (h' a)
theorem mem_support_ofFinset_iff (a : α) : a ∈ (ofFinset f s h h').support ↔ a ∈ s ∧ f a ≠ 0 := by
simp
theorem ofFinset_apply_of_notMem {a : α} (ha : a ∉ s) : ofFinset f s h h' a = 0 :=
h' a ha
@[deprecated (since := "2025-05-23")] alias ofFinset_apply_of_not_mem := ofFinset_apply_of_notMem
section Measure
variable (t : Set α)
@[simp]
theorem toOuterMeasure_ofFinset_apply :
(ofFinset f s h h').toOuterMeasure t = ∑' x, t.indicator f x :=
toOuterMeasure_apply (ofFinset f s h h') t
@[simp]
theorem toMeasure_ofFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) :
(ofFinset f s h h').toMeasure t = ∑' x, t.indicator f x :=
(toMeasure_apply_eq_toOuterMeasure_apply _ ht).trans (toOuterMeasure_ofFinset_apply h h' t)
end Measure
end OfFinset
section OfFintype
/-- Given a finite type `α` and a function `f : α → ℝ≥0∞` with sum 1, we get a `PMF`. -/
def ofFintype [Fintype α] (f : α → ℝ≥0∞) (h : ∑ a, f a = 1) : PMF α :=
ofFinset f Finset.univ h fun a ha => absurd (Finset.mem_univ a) ha
variable [Fintype α] {f : α → ℝ≥0∞} (h : ∑ a, f a = 1)
@[simp]
theorem ofFintype_apply (a : α) : ofFintype f h a = f a := rfl
@[simp]
theorem support_ofFintype : (ofFintype f h).support = Function.support f := rfl
theorem mem_support_ofFintype_iff (a : α) : a ∈ (ofFintype f h).support ↔ f a ≠ 0 := Iff.rfl
open scoped Classical in
@[simp]
lemma map_ofFintype [Fintype β] (f : α → ℝ≥0∞) (h : ∑ a, f a = 1) (g : α → β) :
(ofFintype f h).map g = ofFintype (fun b ↦ ∑ a with g a = b, f a)
(by simpa [Finset.sum_fiberwise_eq_sum_filter univ univ g f]) := by
ext b : 1
simp only [sum_filter, eq_comm, map_apply, ofFintype_apply]
exact tsum_eq_sum fun _ h ↦ (h <| mem_univ _).elim
section Measure
variable (s : Set α)
@[simp high]
theorem toOuterMeasure_ofFintype_apply : (ofFintype f h).toOuterMeasure s = ∑' x, s.indicator f x :=
toOuterMeasure_apply (ofFintype f h) s
@[simp]
theorem toMeasure_ofFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) :
(ofFintype f h).toMeasure s = ∑' x, s.indicator f x :=
(toMeasure_apply_eq_toOuterMeasure_apply _ hs).trans (toOuterMeasure_ofFintype_apply h s)
end Measure
end OfFintype
section normalize
/-- Given an `f` with non-zero and non-infinite sum, get a `PMF` by normalizing `f` by its `tsum`.
-/
def normalize (f : α → ℝ≥0∞) (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ∞) : PMF α :=
⟨fun a => f a * (∑' x, f x)⁻¹,
ENNReal.summable.hasSum_iff.2 (ENNReal.tsum_mul_right.trans (ENNReal.mul_inv_cancel hf0 hf))⟩
variable {f : α → ℝ≥0∞} (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ∞)
@[simp]
theorem normalize_apply (a : α) : (normalize f hf0 hf) a = f a * (∑' x, f x)⁻¹ := rfl
@[simp]
theorem support_normalize : (normalize f hf0 hf).support = Function.support f :=
Set.ext fun a => by simp [hf, mem_support_iff]
theorem mem_support_normalize_iff (a : α) : a ∈ (normalize f hf0 hf).support ↔ f a ≠ 0 := by simp
end normalize
section Filter
/-- Create new `PMF` by filtering on a set with non-zero measure and normalizing. -/
def filter (p : PMF α) (s : Set α) (h : ∃ a ∈ s, a ∈ p.support) : PMF α :=
PMF.normalize (s.indicator p) (by simpa using h) (p.tsum_coe_indicator_ne_top s)
variable {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support)
@[simp]
theorem filter_apply (a : α) :
(p.filter s h) a = s.indicator p a * (∑' a', (s.indicator p) a')⁻¹ := by
rw [filter, normalize_apply]
theorem filter_apply_eq_zero_of_notMem {a : α} (ha : a ∉ s) : (p.filter s h) a = 0 := by
rw [filter_apply, Set.indicator_apply_eq_zero.mpr fun ha' => absurd ha' ha, zero_mul]
@[deprecated (since := "2025-05-23")]
alias filter_apply_eq_zero_of_not_mem := filter_apply_eq_zero_of_notMem
theorem mem_support_filter_iff {a : α} : a ∈ (p.filter s h).support ↔ a ∈ s ∧ a ∈ p.support :=
(mem_support_normalize_iff _ _ _).trans Set.indicator_apply_ne_zero
@[simp]
theorem support_filter : (p.filter s h).support = s ∩ p.support :=
Set.ext fun _ => mem_support_filter_iff _
theorem filter_apply_eq_zero_iff (a : α) : (p.filter s h) a = 0 ↔ a ∉ s ∨ a ∉ p.support := by
rw [apply_eq_zero_iff, support_filter, Set.mem_inter_iff, not_and_or]
theorem filter_apply_ne_zero_iff (a : α) : (p.filter s h) a ≠ 0 ↔ a ∈ s ∧ a ∈ p.support := by
rw [Ne, filter_apply_eq_zero_iff, not_or, Classical.not_not, Classical.not_not]
end Filter
section bernoulli
/-- A `PMF` which assigns probability `p` to `true` and `1 - p` to `false`. -/
def bernoulli (p : ℝ≥0) (h : p ≤ 1) : PMF Bool :=
ofFintype (fun b => cond b p (1 - p)) (by simp [h])
variable {p : ℝ≥0} (h : p ≤ 1) (b : Bool)
@[simp]
theorem bernoulli_apply : bernoulli p h b = cond b p (1 - p) := by
simp only [bernoulli, ofFintype_apply]
exact Eq.symm (Bool.apply_cond ofNNReal)
@[simp]
theorem support_bernoulli : (bernoulli p h).support = { b | cond b (p ≠ 0) (p ≠ 1) } := by
refine Set.ext fun b => ?_
induction b
· simp_rw [mem_support_iff, bernoulli_apply, Bool.cond_false, Ne, ENNReal.coe_sub,
ENNReal.coe_one, Bool.cond_prop, Set.mem_setOf_eq, Bool.false_eq_true, ite_false, not_iff_not]
constructor
· intro h'
simp only [tsub_eq_zero_iff_le, one_le_coe_iff] at h'
exact eq_of_le_of_ge h h'
· intro h'
simp only [h', ENNReal.coe_one, tsub_self]
· simp only [mem_support_iff, bernoulli_apply, Bool.cond_true, Set.mem_setOf_eq, ne_eq,
ENNReal.coe_eq_zero]
theorem mem_support_bernoulli_iff : b ∈ (bernoulli p h).support ↔ cond b (p ≠ 0) (p ≠ 1) := by simp
end bernoulli
end
end PMF |
.lake/packages/mathlib/Mathlib/Probability/ProbabilityMassFunction/Binomial.lean | import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Probability.ProbabilityMassFunction.Constructions
import Mathlib.Tactic.FinCases
/-!
# The binomial distribution
This file defines the probability mass function of the binomial distribution.
## Main results
* `binomial_one_eq_bernoulli`: For `n = 1`, it is equal to `PMF.bernoulli`.
-/
namespace PMF
open ENNReal NNReal
/-- The binomial `PMF`: the probability of observing exactly `i` “heads” in a sequence of `n`
independent coin tosses, each having probability `p` of coming up “heads”. -/
def binomial (p : ℝ≥0) (h : p ≤ 1) (n : ℕ) : PMF (Fin (n + 1)) :=
.ofFintype (fun i =>
↑(p ^ (i : ℕ) * (1 - p) ^ ((Fin.last n - i) : ℕ) * (n.choose i : ℕ))) (by
dsimp only
norm_cast
convert (add_pow p (1 - p) n).symm
· rw [Finset.sum_fin_eq_sum_range]
apply Finset.sum_congr rfl
intro i hi
rw [Finset.mem_range] at hi
rw [dif_pos hi]
· rw [add_tsub_cancel_of_le (mod_cast h), one_pow])
theorem binomial_apply (p : ℝ≥0) (h : p ≤ 1) (n : ℕ) (i : Fin (n + 1)) :
binomial p h n i = p ^ (i : ℕ) * (1 - p) ^ ((Fin.last n - i) : ℕ) * (n.choose i : ℕ) := by
simp [binomial]
@[simp]
theorem binomial_apply_zero (p : ℝ≥0) (h : p ≤ 1) (n : ℕ) :
binomial p h n 0 = (1 - p) ^ n := by
simp [binomial_apply]
@[simp]
theorem binomial_apply_last (p : ℝ≥0) (h : p ≤ 1) (n : ℕ) :
binomial p h n (.last n) = p ^ n := by
simp [binomial_apply]
theorem binomial_apply_self (p : ℝ≥0) (h : p ≤ 1) (n : ℕ) :
binomial p h n (.last n) = p ^ n := by simp
/-- The binomial distribution on one coin is the Bernoulli distribution. -/
theorem binomial_one_eq_bernoulli (p : ℝ≥0) (h : p ≤ 1) :
binomial p h 1 = (bernoulli p h).map (cond · 1 0) := by
ext i; fin_cases i <;> simp [tsum_bool, binomial_apply]
end PMF |
.lake/packages/mathlib/Mathlib/Probability/Moments/CovarianceBilinDual.lean | import Mathlib.Analysis.LocallyConvex.ContinuousOfBounded
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.Probability.Moments.Variance
/-!
# Covariance in Banach spaces
We define the covariance of a finite measure in a Banach space `E`,
as a continuous bilinear form on `Dual ℝ E`.
## Main definitions
Let `μ` be a finite measure on a normed space `E` with the Borel σ-algebra. We then define
* `Dual.toLp`: the function `MemLp.toLp` as a continuous linear map from `Dual 𝕜 E` (for `RCLike 𝕜`)
into the space `Lp 𝕜 p μ` for `p ≥ 1`. This needs a hypothesis `MemLp id p μ` (we set it to the
junk value 0 if that's not the case).
* `covarianceBilinDual` : covariance of a measure `μ` with `∫ x, ‖x‖^2 ∂μ < ∞` on a Banach space,
as a continuous bilinear form `Dual ℝ E →L[ℝ] Dual ℝ E →L[ℝ] ℝ`.
If the second moment of `μ` is not finite, we set `covarianceBilinDual μ = 0`.
## Main statements
* `covarianceBilinDual_apply` : the covariance of `μ` on `L₁, L₂ : Dual ℝ E` is equal to
`∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ`.
* `covarianceBilinDual_same_eq_variance`: `covarianceBilinDual μ L L = Var[L; μ]`.
## Implementation notes
The hypothesis that `μ` has a second moment is written as `MemLp id 2 μ` in the code.
-/
open MeasureTheory ProbabilityTheory Complex NormedSpace
open scoped ENNReal NNReal Real Topology
variable {E : Type*} [NormedAddCommGroup E] {mE : MeasurableSpace E} {μ : Measure E} {p : ℝ≥0∞}
namespace StrongDual
section LinearMap
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
open Classical in
/-- Linear map from the dual to `Lp` equal to `MemLp.toLp` if `MemLp id p μ` and to 0 otherwise. -/
noncomputable
def toLpₗ (μ : Measure E) (p : ℝ≥0∞) :
StrongDual 𝕜 E →ₗ[𝕜] Lp 𝕜 p μ :=
if h_Lp : MemLp id p μ then
{ toFun := fun L ↦ MemLp.toLp L (h_Lp.continuousLinearMap_comp L)
map_add' u v := by push_cast; rw [MemLp.toLp_add]
map_smul' c L := by push_cast; rw [MemLp.toLp_const_smul]; rfl }
else 0
@[simp]
lemma toLpₗ_apply (h_Lp : MemLp id p μ) (L : StrongDual 𝕜 E) :
L.toLpₗ μ p = MemLp.toLp L (h_Lp.continuousLinearMap_comp L) := by
simp [toLpₗ, dif_pos h_Lp]
@[simp]
lemma toLpₗ_of_not_memLp (h_Lp : ¬ MemLp id p μ) (L : StrongDual 𝕜 E) :
L.toLpₗ μ p = 0 := by
simp [toLpₗ, dif_neg h_Lp]
lemma norm_toLpₗ_le [OpensMeasurableSpace E] (L : StrongDual 𝕜 E) :
‖L.toLpₗ μ p‖ ≤ ‖L‖ * (eLpNorm id p μ).toReal := by
by_cases h_Lp : MemLp id p μ
swap
· simp only [h_Lp, not_false_eq_true, toLpₗ_of_not_memLp, Lp.norm_zero]
positivity
by_cases hp : p = 0
· simp only [h_Lp, toLpₗ_apply, Lp.norm_toLp]
simp [hp]
by_cases hp_top : p = ∞
· simp only [hp_top, StrongDual.toLpₗ_apply h_Lp, Lp.norm_toLp, eLpNorm_exponent_top] at h_Lp ⊢
simp only [eLpNormEssSup, id_eq]
suffices (essSup (fun x ↦ ‖L x‖ₑ) μ).toReal ≤ (essSup (fun x ↦ ‖L‖ₑ *‖x‖ₑ) μ).toReal by
rwa [ENNReal.essSup_const_mul, ENNReal.toReal_mul, toReal_enorm] at this
gcongr
· rw [ENNReal.essSup_const_mul]
exact ENNReal.mul_ne_top (by simp) h_Lp.eLpNorm_ne_top
· exact essSup_mono_ae <| ae_of_all _ L.le_opNorm_enorm
have h0 : 0 < p.toReal := by simp [ENNReal.toReal_pos_iff, pos_iff_ne_zero, hp, Ne.lt_top hp_top]
suffices ‖L.toLpₗ μ p‖
≤ (‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ).toReal ^ p.toReal⁻¹ by
refine this.trans_eq ?_
simp only [ENNReal.toReal_mul]
rw [← ENNReal.toReal_rpow, Real.mul_rpow (by positivity) (by positivity),
← Real.rpow_mul (by positivity), mul_inv_cancel₀ h0.ne', Real.rpow_one, toReal_enorm]
rw [eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top, ENNReal.toReal_rpow]
simp
rw [StrongDual.toLpₗ_apply h_Lp, Lp.norm_toLp,
eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top]
simp only [one_div]
refine ENNReal.toReal_le_of_le_ofReal (by positivity) ?_
suffices ∫⁻ x, ‖L x‖ₑ ^ p.toReal ∂μ ≤ ‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ by
rw [← ENNReal.ofReal_rpow_of_nonneg (by positivity) (by positivity)]
gcongr
rwa [ENNReal.ofReal_toReal]
refine ENNReal.mul_ne_top (by simp) ?_
have h := h_Lp.eLpNorm_ne_top
rw [eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top] at h
simpa [h0] using h
calc ∫⁻ x, ‖L x‖ₑ ^ p.toReal ∂μ
_ ≤ ∫⁻ x, ‖L‖ₑ ^ p.toReal * ‖x‖ₑ ^ p.toReal ∂μ := by
refine lintegral_mono fun x ↦ ?_
rw [← ENNReal.mul_rpow_of_nonneg]
swap; · positivity
gcongr
exact L.le_opNorm_enorm x
_ = ‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ := by rw [lintegral_const_mul]; fun_prop
end LinearMap
section ContinuousLinearMap
variable {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [OpensMeasurableSpace E]
/-- Continuous linear map from the dual to `Lp` equal to `MemLp.toLp` if `MemLp id p μ`
and to 0 otherwise. -/
noncomputable
def toLp (μ : Measure E) (p : ℝ≥0∞) [Fact (1 ≤ p)] :
StrongDual 𝕜 E →L[𝕜] Lp 𝕜 p μ where
toLinearMap := StrongDual.toLpₗ μ p
cont := by
refine LinearMap.continuous_of_locally_bounded _ fun s hs ↦ ?_
rw [image_isVonNBounded_iff]
simp_rw [isVonNBounded_iff'] at hs
obtain ⟨r, hxr⟩ := hs
refine ⟨r * (eLpNorm id p μ).toReal, fun L hLs ↦ ?_⟩
specialize hxr L hLs
refine (StrongDual.norm_toLpₗ_le L).trans ?_
gcongr
@[simp]
lemma toLp_apply [Fact (1 ≤ p)] (h_Lp : MemLp id p μ) (L : StrongDual 𝕜 E) :
L.toLp μ p = MemLp.toLp L (h_Lp.continuousLinearMap_comp L) := by
simp [toLp, h_Lp]
@[simp]
lemma toLp_of_not_memLp [Fact (1 ≤ p)] (h_Lp : ¬ MemLp id p μ) (L : StrongDual 𝕜 E) :
L.toLp μ p = 0 := by
simp [toLp, h_Lp]
end ContinuousLinearMap
end StrongDual
namespace ProbabilityTheory
section Centered
variable [NormedSpace ℝ E] [OpensMeasurableSpace E]
/-- Continuous bilinear form with value `∫ x, L₁ x * L₂ x ∂μ` on `(L₁, L₂)`.
This is equal to the covariance only if `μ` is centered. -/
noncomputable
def uncenteredCovarianceBilinDual (μ : Measure E) : StrongDual ℝ E →L[ℝ] StrongDual ℝ E →L[ℝ] ℝ :=
ContinuousLinearMap.bilinearComp (isBoundedBilinearMap_inner (𝕜 := ℝ)).toContinuousLinearMap
(StrongDual.toLp μ 2) (StrongDual.toLp μ 2)
@[deprecated (since := "2025-10-10")] alias uncenteredCovarianceBilin :=
uncenteredCovarianceBilinDual
lemma uncenteredCovarianceBilinDual_apply (h : MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
uncenteredCovarianceBilinDual μ L₁ L₂ = ∫ x, L₁ x * L₂ x ∂μ := by
simp only [uncenteredCovarianceBilinDual, ContinuousLinearMap.bilinearComp_apply,
StrongDual.toLp_apply h, L2.inner_def, RCLike.inner_apply, conj_trivial]
refine integral_congr_ae ?_
filter_upwards [MemLp.coeFn_toLp (h.continuousLinearMap_comp L₁),
MemLp.coeFn_toLp (h.continuousLinearMap_comp L₂)] with x hxL₁ hxL₂
simp only [id_eq] at hxL₁ hxL₂
rw [hxL₁, hxL₂, mul_comm]
@[deprecated (since := "2025-10-10")] alias uncenteredCovarianceBilin_apply :=
uncenteredCovarianceBilinDual_apply
lemma uncenteredCovarianceBilinDual_of_not_memLp (h : ¬ MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
uncenteredCovarianceBilinDual μ L₁ L₂ = 0 := by
simp [uncenteredCovarianceBilinDual, StrongDual.toLp_of_not_memLp h]
@[deprecated (since := "2025-10-10")] alias uncenteredCovarianceBilin_of_not_memLp :=
uncenteredCovarianceBilinDual_of_not_memLp
@[simp]
lemma uncenteredCovarianceBilinDual_zero : uncenteredCovarianceBilinDual (0 : Measure E) = 0 := by
ext
have : Subsingleton (Lp ℝ 2 (0 : Measure E)) := ⟨fun x y ↦ Lp.ext_iff.2 rfl⟩
simp [uncenteredCovarianceBilinDual, Subsingleton.eq_zero (StrongDual.toLp 0 2)]
@[deprecated (since := "2025-10-10")] alias uncenteredCovarianceBilin_zero :=
uncenteredCovarianceBilinDual_zero
lemma norm_uncenteredCovarianceBilinDual_le (L₁ L₂ : StrongDual ℝ E) :
‖uncenteredCovarianceBilinDual μ L₁ L₂‖ ≤ ‖L₁‖ * ‖L₂‖ * ∫ x, ‖x‖ ^ 2 ∂μ := by
by_cases h : MemLp id 2 μ
swap; · simp only [uncenteredCovarianceBilinDual_of_not_memLp h, norm_zero]; positivity
calc ‖uncenteredCovarianceBilinDual μ L₁ L₂‖
_ = ‖∫ x, L₁ x * L₂ x ∂μ‖ := by rw [uncenteredCovarianceBilinDual_apply h]
_ ≤ ∫ x, ‖L₁ x‖ * ‖L₂ x‖ ∂μ := (norm_integral_le_integral_norm _).trans (by simp)
_ ≤ ∫ x, ‖L₁‖ * ‖x‖ * ‖L₂‖ * ‖x‖ ∂μ := by
refine integral_mono_ae ?_ ?_ (ae_of_all _ fun x ↦ ?_)
· simp_rw [← norm_mul]
exact (MemLp.integrable_mul (h.continuousLinearMap_comp L₁)
(h.continuousLinearMap_comp L₂)).norm
· simp_rw [mul_assoc]
refine Integrable.const_mul ?_ _
simp_rw [← mul_assoc, mul_comm _ (‖L₂‖), mul_assoc, ← pow_two]
refine Integrable.const_mul ?_ _
exact h.integrable_norm_pow (by simp)
· simp only
rw [mul_assoc]
gcongr
· exact ContinuousLinearMap.le_opNorm L₁ x
· exact ContinuousLinearMap.le_opNorm L₂ x
_ = ‖L₁‖ * ‖L₂‖ * ∫ x, ‖x‖ ^ 2 ∂μ := by
rw [← integral_const_mul]
congr with x
ring
@[deprecated (since := "2025-10-10")] alias norm_uncenteredCovarianceBilin_le :=
norm_uncenteredCovarianceBilinDual_le
end Centered
section Covariance
variable [NormedSpace ℝ E] [BorelSpace E]
open Classical in
/-- Continuous bilinear form with value `∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ` on `(L₁, L₂)`
if `MemLp id 2 μ`. If not, we set it to zero. -/
noncomputable
def covarianceBilinDual (μ : Measure E) : StrongDual ℝ E →L[ℝ] StrongDual ℝ E →L[ℝ] ℝ :=
uncenteredCovarianceBilinDual (μ.map (fun x ↦ x - ∫ x, x ∂μ))
omit [BorelSpace E] in
lemma _root_.MeasureTheory.memLp_id_of_self_sub_integral {p : ℝ≥0∞}
(h_Lp : MemLp (fun x ↦ x - ∫ y, y ∂μ) p μ) : MemLp id p μ := by
have : (id : E → E) = fun x ↦ x - ∫ x, x ∂μ + ∫ x, x ∂μ := by ext; simp
rw [this]
apply h_Lp.add
set c := ∫ x, x ∂μ
/- We need to check that the constant `c = ∫ x, x ∂μ` is in `L^p`. Note that we don't assume
that `μ` is finite, so this requires an argument. If the constant is zero, it's obvious.
If it's nonzero, this means that `x` is integrable for `μ` (as otherwise the integral would be
`0` by our choice of junk value), so `‖x‖ ^ (1/p)` is in `L^p`.
The constant `c` is controlled by `2 ‖x - c‖` close to `0` (say when `‖x‖ ≤ ‖c‖ / 2`)
and by a multiple of `‖x‖ ^ (1/p)` away from `0`. Those two functions
are in `L^p` by assumptions, so the constant `c` also is. -/
by_cases hx : c = 0
· simp [hx]
rcases eq_or_ne p 0 with rfl | hp0
· simp [aestronglyMeasurable_const]
rcases eq_or_ne p ∞ with rfl | hptop
· exact memLp_top_const c
apply (integrable_norm_rpow_iff (by fun_prop) hp0 hptop).1
have I : Integrable (fun (x : E) ↦ ‖x‖) μ := by
apply Integrable.norm
contrapose! hx
exact integral_undef hx
have := (h_Lp.integrable_norm_rpow hp0 hptop).const_mul (2 ^ p.toReal)
apply (((I.const_mul (2 * ‖c‖ ^ (p.toReal - 1))).add this)).mono' (by fun_prop)
filter_upwards [] with y
lift p to ℝ≥0 using hptop
simp only [ENNReal.coe_toReal, Real.norm_eq_abs, Pi.add_apply]
rw [abs_of_nonneg (by positivity)]
rcases le_total ‖y‖ (‖c‖ / 2)
· have : ‖c‖ ≤ ‖y‖ + ‖y - c‖ := Eq.trans_le (by abel_nf) (norm_sub_le y (y - c))
calc ‖c‖ ^ (p : ℝ)
_ ≤ (2 * ‖y - c‖) ^ (p : ℝ) :=
Real.rpow_le_rpow (by positivity) (by linarith) (by positivity)
_ = 0 + 2 ^ (p : ℝ) * ‖y - c‖ ^ (p : ℝ) := by
rw [Real.mul_rpow (by simp) (by positivity)]
ring
_ ≤ 2 * ‖c‖ ^ (p - 1 : ℝ) * ‖y‖ + 2 ^ (p : ℝ) * ‖y - c‖ ^ (p : ℝ) := by
gcongr
positivity
· calc ‖c‖ ^ (p : ℝ )
_ = ‖c‖ ^ ((p - 1) + 1 : ℝ) := by abel_nf
_ = ‖c‖ ^ (p - 1 : ℝ) * ‖c‖ := by rw [Real.rpow_add (by positivity), Real.rpow_one]
_ ≤ ‖c‖ ^ (p - 1 : ℝ) * (2 * ‖y‖) := by gcongr; linarith
_ = 2 * ‖c‖ ^ (p - 1 : ℝ) * ‖y‖ + 0 := by ring
_ ≤ 2 * ‖c‖ ^ (p - 1 : ℝ) * ‖y‖ + 2 ^ (p : ℝ) * ‖y - c‖ ^ (p : ℝ) := by gcongr; positivity
lemma covarianceBilinDual_of_not_memLp' (h : ¬ MemLp (fun x ↦ x - ∫ y, y ∂μ) 2 μ)
(L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = 0 := by
rw [covarianceBilinDual, uncenteredCovarianceBilinDual_of_not_memLp]
rw [(measurableEmbedding_subRight _).memLp_map_measure_iff]
exact h
@[simp]
lemma covarianceBilinDual_of_not_memLp (h : ¬ MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = 0 := by
apply covarianceBilinDual_of_not_memLp'
contrapose! h
exact memLp_id_of_self_sub_integral h
@[simp]
lemma covarianceBilinDual_zero : covarianceBilinDual (0 : Measure E) = 0 := by
rw [covarianceBilinDual, Measure.map_zero, uncenteredCovarianceBilinDual_zero]
lemma covarianceBilinDual_comm (L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = covarianceBilinDual μ L₂ L₁ := by
by_cases h : MemLp (fun x ↦ x - ∫ y, y ∂μ) 2 μ
· have h' : MemLp id 2 (Measure.map (fun x ↦ x - ∫ (x : E), x ∂μ) μ) :=
(measurableEmbedding_subRight _).memLp_map_measure_iff.mpr <| h
simp_rw [covarianceBilinDual, uncenteredCovarianceBilinDual_apply h', mul_comm (L₁ _)]
· simp [h, covarianceBilinDual_of_not_memLp']
@[simp]
lemma covarianceBilinDual_self_nonneg (L : StrongDual ℝ E) : 0 ≤ covarianceBilinDual μ L L := by
by_cases h : MemLp id 2 μ
· simp only [covarianceBilinDual, uncenteredCovarianceBilinDual,
ContinuousLinearMap.bilinearComp_apply, IsBoundedBilinearMap.toContinuousLinearMap_apply]
exact real_inner_self_nonneg
· simp [h]
variable [CompleteSpace E] [IsFiniteMeasure μ]
lemma covarianceBilinDual_apply (h : MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = ∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ := by
rw [covarianceBilinDual, uncenteredCovarianceBilinDual_apply,
integral_map (by fun_prop) (by fun_prop)]
· have hL (L : StrongDual ℝ E) : μ[L] = L (∫ x, x ∂μ) :=
L.integral_comp_comm (h.integrable (by simp))
simp [← hL]
· exact (measurableEmbedding_subRight _).memLp_map_measure_iff.mpr <| h.sub (memLp_const _)
lemma covarianceBilinDual_apply' (h : MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = ∫ x, L₁ (x - μ[id]) * L₂ (x - μ[id]) ∂μ := by
rw [covarianceBilinDual_apply h]
have hL (L : StrongDual ℝ E) : μ[L] = L (∫ x, x ∂μ) :=
L.integral_comp_comm (h.integrable (by simp))
simp [← hL]
lemma covarianceBilinDual_eq_covariance (h : MemLp id 2 μ) (L₁ L₂ : StrongDual ℝ E) :
covarianceBilinDual μ L₁ L₂ = cov[L₁, L₂; μ] := by
rw [covarianceBilinDual_apply h, covariance]
lemma covarianceBilinDual_self_eq_variance (h : MemLp id 2 μ) (L : StrongDual ℝ E) :
covarianceBilinDual μ L L = Var[L; μ] := by
rw [covarianceBilinDual_eq_covariance h, covariance_self (by fun_prop)]
@[deprecated (since := "2025-07-16")] alias covarianceBilin_same_eq_variance :=
covarianceBilinDual_self_eq_variance
end Covariance
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/SubGaussian.lean | import Mathlib.Probability.Kernel.Condexp
import Mathlib.Probability.Moments.MGFAnalytic
import Mathlib.Probability.Moments.Tilted
/-!
# Sub-Gaussian random variables
This presentation of sub-Gaussian random variables is inspired by section 2.5 of
[vershynin2018high]. Let `X` be a random variable. Consider the following five properties, in which
`Kᵢ` are positive reals,
* (i) for all `t ≥ 0`, `ℙ(|X| ≥ t) ≤ 2 * exp(-t^2 / K₁^2)`,
* (ii) for all `p : ℕ` with `1 ≤ p`, `𝔼[|X|^p]^(1/p) ≤ K₂ sqrt(p)`,
* (iii) for all `|t| ≤ 1/K₃`, `𝔼[exp (t^2 * X^2)] ≤ exp (K₃^2 * t^2)`,
* (iv) `𝔼[exp(X^2 / K₄)] ≤ 2`,
* (v) for all `t : ℝ`, `𝔼[exp (t * X)] ≤ exp (K₅ * t^2 / 2)`.
Properties (i) to (iv) are equivalent, in the sense that there exists a constant `C` such that
if `X` satisfies one of those properties with constant `K`, then it satisfies any other one with
constant at most `CK`.
If `𝔼[X] = 0` then properties (i)-(iv) are equivalent to (v) in that same sense.
Property (v) implies that `X` has expectation zero.
The name sub-Gaussian is used by various authors to refer to any one of (i)-(v). We will say that a
random variable has sub-Gaussian moment-generating function (mgf) with constant `K₅` to mean that
property (v) holds with that constant. The function `exp (K₅ * t^2 / 2)` which appears in
property (v) is the mgf of a Gaussian with variance `K₅`.
That property (v) is the most convenient one to work with if one wants to prove concentration
inequalities using Chernoff's method.
TODO: implement definitions for (i)-(iv) when it makes sense. For example the maximal constant `K₄`
such that (iv) is true is an Orlicz norm. Prove relations between those properties.
### Conditionally sub-Gaussian random variables and kernels
A related notion to sub-Gaussian random variables is that of conditionally sub-Gaussian random
variables. A random variable `X` is conditionally sub-Gaussian in the sense of (v) with respect to
a sigma-algebra `m` and a measure `μ` if for all `t : ℝ`, `exp (t * X)` is `μ`-integrable and
the conditional mgf of `X` conditioned on `m` is almost surely bounded by `exp (c * t^2 / 2)`
for some constant `c`.
As in other parts of Mathlib's probability library (notably the independence and conditional
independence definitions), we express both sub-Gaussian and conditionally sub-Gaussian properties
as special cases of a notion of sub-Gaussianity with respect to a kernel and a measure.
## Main definitions
* `Kernel.HasSubgaussianMGF`: a random variable `X` has a sub-Gaussian moment-generating function
with parameter `c` with respect to a kernel `κ` and a measure `ν` if for `ν`-almost all `ω'`,
for all `t : ℝ`, the moment-generating function of `X` with respect to `κ ω'` is bounded by
`exp (c * t ^ 2 / 2)`.
* `HasCondSubgaussianMGF`: a random variable `X` has a conditionally sub-Gaussian moment-generating
function with parameter `c` with respect to a sigma-algebra `m` and a measure `μ` if for all
`t : ℝ`, `exp (t * X)` is `μ`-integrable and the moment-generating function of `X` conditioned
on `m` is almost surely bounded by `exp (c * t ^ 2 / 2)` for all `t : ℝ`.
The actual definition uses `Kernel.HasSubgaussianMGF`: `HasCondSubgaussianMGF` is defined as
sub-Gaussian with respect to the conditional expectation kernel for `m` and the restriction of `μ`
to the sigma-algebra `m`.
* `HasSubgaussianMGF`: a random variable `X` has a sub-Gaussian moment-generating function
with parameter `c` with respect to a measure `μ` if for all `t : ℝ`, `exp (t * X)`
is `μ`-integrable and the moment-generating function of `X` is bounded by `exp (c * t ^ 2 / 2)`
for all `t : ℝ`.
This is equivalent to `Kernel.HasSubgaussianMGF` with a constant kernel.
See `HasSubgaussianMGF_iff_kernel`.
## Main statements
* `measure_sum_ge_le_of_iIndepFun`: Hoeffding's inequality for sums of independent sub-Gaussian
random variables.
* `hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero`: Hoeffding's lemma for random variables with
expectation zero.
* `measure_sum_ge_le_of_HasCondSubgaussianMGF`: the Azuma-Hoeffding inequality for sub-Gaussian
random variables.
## Implementation notes
### Definition of `Kernel.HasSubgaussianMGF`
The definition of sub-Gaussian with respect to a kernel and a measure is the following:
```
structure Kernel.HasSubgaussianMGF (X : Ω → ℝ) (c : ℝ≥0)
(κ : Kernel Ω' Ω) (ν : Measure Ω' := by volume_tac) : Prop where
integrable_exp_mul : ∀ t, Integrable (fun ω ↦ exp (t * X ω)) (κ ∘ₘ ν)
mgf_le : ∀ᵐ ω' ∂ν, ∀ t, mgf X (κ ω') t ≤ exp (c * t ^ 2 / 2)
```
An interesting point is that the integrability condition is not integrability of `exp (t * X)`
with respect to `κ ω'` for `ν`-almost all `ω'`, but integrability with respect to `κ ∘ₘ ν`.
This is a stronger condition, as the weaker one did not allow to prove interesting results about
the sum of two sub-Gaussian random variables.
For the conditional case, that integrability condition reduces to integrability of `exp (t * X)`
with respect to `μ`.
### Definition of `HasCondSubgaussianMGF`
We define `HasCondSubgaussianMGF` as a special case of `Kernel.HasSubgaussianMGF` with the
conditional expectation kernel for `m`, `condExpKernel μ m`, and the restriction of `μ` to `m`,
`μ.trim hm` (where `hm` states that `m` is a sub-sigma-algebra).
Note that `condExpKernel μ m ∘ₘ μ.trim hm = μ`. The definition is equivalent to the two
conditions
* for all `t`, `exp (t * X)` is `μ`-integrable,
* for `μ.trim hm`-almost all `ω`, for all `t`, the mgf with respect to the conditional
distribution `condExpKernel μ m ω` is bounded by `exp (c * t ^ 2 / 2)`.
For any `t`, we can write the mgf of `X` with respect to the conditional expectation kernel as
a conditional expectation, `(μ.trim hm)`-almost surely:
`mgf X (condExpKernel μ m ·) t =ᵐ[μ.trim hm] μ[fun ω' ↦ exp (t * X ω') | m]`.
## References
* [R. Vershynin, *High-dimensional probability: An introduction with applications in data
science*][vershynin2018high]
-/
open MeasureTheory Real
open scoped ENNReal NNReal Topology
namespace ProbabilityTheory
section Kernel
variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'}
{ν : Measure Ω'} {κ : Kernel Ω' Ω} {X : Ω → ℝ} {c : ℝ≥0}
/-! ### Sub-Gaussian with respect to a kernel and a measure -/
/-- A random variable `X` has a sub-Gaussian moment-generating function with parameter `c`
with respect to a kernel `κ` and a measure `ν` if for `ν`-almost all `ω'`, for all `t : ℝ`,
the moment-generating function of `X` with respect to `κ ω'` is bounded by `exp (c * t ^ 2 / 2)`.
This implies in particular that `X` has expectation 0. -/
structure Kernel.HasSubgaussianMGF (X : Ω → ℝ) (c : ℝ≥0)
(κ : Kernel Ω' Ω) (ν : Measure Ω' := by volume_tac) : Prop where
integrable_exp_mul : ∀ t, Integrable (fun ω ↦ exp (t * X ω)) (κ ∘ₘ ν)
mgf_le : ∀ᵐ ω' ∂ν, ∀ t, mgf X (κ ω') t ≤ exp (c * t ^ 2 / 2)
namespace Kernel.HasSubgaussianMGF
section BasicProperties
lemma aestronglyMeasurable (h : HasSubgaussianMGF X c κ ν) :
AEStronglyMeasurable X (κ ∘ₘ ν) := by
have h_int := h.integrable_exp_mul 1
simpa using (aemeasurable_of_aemeasurable_exp h_int.1.aemeasurable).aestronglyMeasurable
lemma ae_integrable_exp_mul (h : HasSubgaussianMGF X c κ ν) (t : ℝ) :
∀ᵐ ω' ∂ν, Integrable (fun y ↦ exp (t * X y)) (κ ω') :=
Measure.ae_integrable_of_integrable_comp (h.integrable_exp_mul t)
lemma ae_aestronglyMeasurable (h : HasSubgaussianMGF X c κ ν) :
∀ᵐ ω' ∂ν, AEStronglyMeasurable X (κ ω') := by
have h_int := h.ae_integrable_exp_mul 1
filter_upwards [h_int] with ω h_int
simpa using (aemeasurable_of_aemeasurable_exp h_int.1.aemeasurable).aestronglyMeasurable
lemma ae_forall_integrable_exp_mul (h : HasSubgaussianMGF X c κ ν) :
∀ᵐ ω' ∂ν, ∀ t, Integrable (fun ω ↦ exp (t * X ω)) (κ ω') := by
have h_int (n : ℤ) : ∀ᵐ ω' ∂ν, Integrable (fun ω ↦ exp (n * X ω)) (κ ω') :=
h.ae_integrable_exp_mul _
rw [← ae_all_iff] at h_int
filter_upwards [h_int] with ω' h_int t
exact integrable_exp_mul_of_le_of_le (h_int _) (h_int _) (Int.floor_le t) (Int.le_ceil t)
lemma ae_forall_memLp_exp_mul (h : HasSubgaussianMGF X c κ ν) (p : ℝ≥0) :
∀ᵐ ω' ∂ν, ∀ t, MemLp (fun ω ↦ exp (t * X ω)) p (κ ω') := by
filter_upwards [h.ae_forall_integrable_exp_mul] with ω' hi t
constructor
· exact (hi t).1
· by_cases hp : p = 0
· simp [hp]
rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top (mod_cast hp) (by simp),
ENNReal.coe_toReal]
have hf := (hi (p * t)).lintegral_lt_top
convert hf using 3 with ω
rw [enorm_eq_ofReal (by positivity), ENNReal.ofReal_rpow_of_nonneg (by positivity),
← exp_mul, mul_comm, ← mul_assoc]
positivity
lemma memLp_exp_mul (h : HasSubgaussianMGF X c κ ν) (t : ℝ) (p : ℝ≥0) :
MemLp (fun ω ↦ exp (t * X ω)) p (κ ∘ₘ ν) := by
by_cases hp0 : p = 0
· simpa [hp0] using (h.integrable_exp_mul t).1
constructor
· exact (h.integrable_exp_mul t).1
· rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top (mod_cast hp0) (by simp)]
simp only [ENNReal.coe_toReal]
have h' := (h.integrable_exp_mul (p * t)).2
rw [hasFiniteIntegral_def] at h'
convert h' using 3 with ω
rw [enorm_eq_ofReal (by positivity), enorm_eq_ofReal (by positivity),
ENNReal.ofReal_rpow_of_nonneg (by positivity), ← exp_mul, mul_comm, ← mul_assoc]
positivity
lemma cgf_le (h : HasSubgaussianMGF X c κ ν) :
∀ᵐ ω' ∂ν, ∀ t, cgf X (κ ω') t ≤ c * t ^ 2 / 2 := by
filter_upwards [h.mgf_le, h.ae_forall_integrable_exp_mul] with ω' h h_int t
calc cgf X (κ ω') t
_ = log (mgf X (κ ω') t) := rfl
_ ≤ log (exp (c * t ^ 2 / 2)) := by
by_cases h0 : κ ω' = 0
· simpa [h0] using by positivity
gcongr
· exact mgf_pos' h0 (h_int t)
· exact h t
_ ≤ c * t ^ 2 / 2 := by rw [log_exp]
lemma isFiniteMeasure (h : HasSubgaussianMGF X c κ ν) :
∀ᵐ ω' ∂ν, IsFiniteMeasure (κ ω') := by
filter_upwards [h.ae_integrable_exp_mul 0, h.mgf_le] with ω' h h_mgf
simpa [integrable_const_iff] using h
lemma measure_univ_le_one (h : HasSubgaussianMGF X c κ ν) :
∀ᵐ ω' ∂ν, κ ω' Set.univ ≤ 1 := by
filter_upwards [h.isFiniteMeasure, h.mgf_le] with ω' h h_mgf
suffices (κ ω').real Set.univ ≤ 1 by
rwa [← ENNReal.ofReal_one, ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) zero_le_one]
simpa [mgf] using h_mgf 0
end BasicProperties
protected lemma of_rat (h_int : ∀ t : ℝ, Integrable (fun ω ↦ exp (t * X ω)) (κ ∘ₘ ν))
(h_mgf : ∀ q : ℚ, ∀ᵐ ω' ∂ν, mgf X (κ ω') q ≤ exp (c * q ^ 2 / 2)) :
Kernel.HasSubgaussianMGF X c κ ν where
integrable_exp_mul := h_int
mgf_le := by
rw [← ae_all_iff] at h_mgf
have h_int : ∀ᵐ ω' ∂ν, ∀ t, Integrable (fun ω ↦ exp (t * X ω)) (κ ω') := by
have h_int' (n : ℤ) := Measure.ae_integrable_of_integrable_comp (h_int n)
rw [← ae_all_iff] at h_int'
filter_upwards [h_int'] with ω' h_int t
exact integrable_exp_mul_of_le_of_le (h_int _) (h_int _) (Int.floor_le t) (Int.le_ceil t)
filter_upwards [h_mgf, h_int] with ω' h_mgf h_int t
refine Rat.denseRange_cast.induction_on t ?_ h_mgf
exact isClosed_le (continuous_mgf h_int) (by fun_prop)
@[simp]
lemma fun_zero [IsFiniteMeasure ν] [IsZeroOrMarkovKernel κ] :
HasSubgaussianMGF (fun _ ↦ 0) 0 κ ν where
integrable_exp_mul := by simp
mgf_le := by simpa using ae_of_all _ fun _ ↦ measureReal_le_one
@[simp]
lemma zero [IsFiniteMeasure ν] [IsZeroOrMarkovKernel κ] : HasSubgaussianMGF 0 0 κ ν := fun_zero
@[simp]
lemma zero_kernel : HasSubgaussianMGF X c (0 : Kernel Ω' Ω) ν := by
constructor
· simp
· simp [exp_nonneg]
@[simp]
lemma zero_measure : HasSubgaussianMGF X c κ (0 : Measure Ω') := ⟨by simp, by simp⟩
lemma neg {c : ℝ≥0} (h : HasSubgaussianMGF X c κ ν) : HasSubgaussianMGF (-X) c κ ν where
integrable_exp_mul t := by simpa using h.integrable_exp_mul (-t)
mgf_le := by filter_upwards [h.mgf_le] with ω' hm t using by simpa [mgf] using hm (-t)
lemma congr {Y : Ω → ℝ} (h : HasSubgaussianMGF X c κ ν) (h' : X =ᵐ[κ ∘ₘ ν] Y) :
HasSubgaussianMGF Y c κ ν where
integrable_exp_mul t := by
refine (integrable_congr ?_).mpr (h.integrable_exp_mul t)
filter_upwards [h'] with ω hω using by rw [hω]
mgf_le := by
have h'' := Measure.ae_ae_of_ae_comp h'
filter_upwards [h.mgf_le, h''] with ω' h_mgf h' t
rw [mgf_congr (Filter.EventuallyEq.symm h')]
exact h_mgf t
lemma _root_.ProbabilityTheory.Kernel.HasSubgaussianMGF_congr {Y : Ω → ℝ} (h : X =ᵐ[κ ∘ₘ ν] Y) :
HasSubgaussianMGF X c κ ν ↔ HasSubgaussianMGF Y c κ ν :=
⟨fun hX ↦ congr hX h, fun hY ↦ congr hY (ae_eq_symm h)⟩
lemma of_map {Ω'' : Type*} {mΩ'' : MeasurableSpace Ω''} {κ : Kernel Ω' Ω''}
{Y : Ω'' → Ω} {X : Ω → ℝ} (hY : Measurable Y) (h : HasSubgaussianMGF X c (κ.map Y) ν) :
HasSubgaussianMGF (X ∘ Y) c κ ν where
integrable_exp_mul t := by
have h1 := h.integrable_exp_mul t
rwa [← Measure.map_comp _ _ hY, integrable_map_measure h1.aestronglyMeasurable (by fun_prop)]
at h1
mgf_le := by
filter_upwards [h.ae_forall_integrable_exp_mul, h.mgf_le] with ω' h_int h_mgf t
convert h_mgf t
ext t
rw [map_apply _ hY, mgf_map hY.aemeasurable]
convert (h_int t).1
rw [map_apply _ hY]
section ChernoffBound
lemma measure_ge_le_exp_add (h : HasSubgaussianMGF X c κ ν) (ε : ℝ) :
∀ᵐ ω' ∂ν, ∀ t, 0 ≤ t → (κ ω').real {ω | ε ≤ X ω} ≤ exp (-t * ε + c * t ^ 2 / 2) := by
filter_upwards [h.mgf_le, h.ae_forall_integrable_exp_mul, h.isFiniteMeasure] with ω' h1 h2 _ t ht
calc (κ ω').real {ω | ε ≤ X ω}
_ ≤ exp (-t * ε) * mgf X (κ ω') t := measure_ge_le_exp_mul_mgf ε ht (h2 t)
_ ≤ exp (-t * ε + c * t ^ 2 / 2) := by
rw [exp_add]
gcongr
exact h1 t
/-- Chernoff bound on the right tail of a sub-Gaussian random variable. -/
lemma measure_ge_le (h : HasSubgaussianMGF X c κ ν) {ε : ℝ} (hε : 0 ≤ ε) :
∀ᵐ ω' ∂ν, (κ ω').real {ω | ε ≤ X ω} ≤ exp (-ε ^ 2 / (2 * c)) := by
by_cases hc0 : c = 0
· filter_upwards [h.measure_univ_le_one] with ω' h
simp only [hc0, NNReal.coe_zero, mul_zero, div_zero, exp_zero]
refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_
simp only [ENNReal.ofReal_one]
exact (measure_mono (Set.subset_univ _)).trans h
filter_upwards [measure_ge_le_exp_add h ε] with ω' h
calc (κ ω').real {ω | ε ≤ X ω}
-- choose the minimizer of the r.h.s. of `h` for `t ≥ 0`. That is, `t = ε / c`.
_ ≤ exp (-(ε / c) * ε + c * (ε / c) ^ 2 / 2) := h (ε / c) (by positivity)
_ = exp (- ε ^ 2 / (2 * c)) := by congr; field
end ChernoffBound
section Zero
lemma measure_pos_eq_zero_of_hasSubGaussianMGF_zero (h : HasSubgaussianMGF X 0 κ ν) :
∀ᵐ ω' ∂ν, (κ ω') {ω | 0 < X ω} = 0 := by
have hs : {ω | 0 < X ω} = ⋃ ε : {ε : ℚ // 0 < ε}, {ω | ε ≤ X ω} := by
ext ω
simp only [Set.mem_setOf_eq, Set.mem_iUnion, Subtype.exists, exists_prop]
constructor
· intro hp
obtain ⟨q, h1, h2⟩ := exists_rat_btwn hp
exact ⟨q, (q.cast_pos.1 h1), h2.le⟩
· intro ⟨q, h1, h2⟩
exact lt_of_lt_of_le (q.cast_pos.2 h1) h2
have hb (ε : ℚ) : ∀ᵐ ω' ∂ν, 0 < ε → (κ ω') {ω | ε ≤ X ω} = 0 := by
filter_upwards [h.measure_ge_le_exp_add ε, h.isFiniteMeasure] with ω' hm _ hε
simp only [neg_mul, NNReal.coe_zero, zero_mul, zero_div, add_zero] at hm
suffices (κ ω').real {ω | ε ≤ X ω} = 0 by simpa [Measure.real, ENNReal.toReal_eq_zero_iff]
have hl : Filter.Tendsto (fun t ↦ rexp (-(t * ε))) Filter.atTop (𝓝 0) := by
apply tendsto_exp_neg_atTop_nhds_zero.comp
exact Filter.Tendsto.atTop_mul_const (ε.cast_pos.2 hε) (fun _ a ↦ a)
apply le_antisymm
· exact ge_of_tendsto hl (Filter.eventually_atTop.2 ⟨0, hm⟩)
· exact measureReal_nonneg
/- `ν`-almost everywhere, `{ω | 0 < X ω}` is a countable union of `κ ω'`-null sets. -/
filter_upwards [ae_all_iff.2 hb] with ω' hn
simp only [hs, measure_iUnion_null_iff, Subtype.forall]
exact fun _ ↦ hn _
lemma ae_eq_zero_of_hasSubgaussianMGF_zero (h : HasSubgaussianMGF X 0 κ ν) :
∀ᵐ ω' ∂ν, X =ᵐ[κ ω'] 0 := by
filter_upwards [(h.neg).measure_pos_eq_zero_of_hasSubGaussianMGF_zero,
h.measure_pos_eq_zero_of_hasSubGaussianMGF_zero]
intro ω' h1 h2
simp_rw [Pi.neg_apply, Left.neg_pos_iff] at h1
apply nonpos_iff_eq_zero.1
calc (κ ω') {ω | X ω ≠ 0}
_ = (κ ω') {ω | X ω < 0 ∨ 0 < X ω} := by simp_rw [ne_iff_lt_or_gt]
_ ≤ (κ ω') {ω | X ω < 0} + (κ ω') {ω | 0 < X ω} := measure_union_le _ _
_ = 0 := by simp [h1, h2]
/-- Auxiliary lemma for `ae_eq_zero_of_hasSubgaussianMGF_zero'`. -/
lemma ae_eq_zero_of_hasSubgaussianMGF_zero_of_measurable
(hX : Measurable X) (h : HasSubgaussianMGF X 0 κ ν) :
X =ᵐ[κ ∘ₘ ν] 0 := by
rw [Filter.EventuallyEq, Measure.ae_comp_iff (measurableSet_eq_fun hX (by fun_prop))]
exact h.ae_eq_zero_of_hasSubgaussianMGF_zero
lemma ae_eq_zero_of_hasSubgaussianMGF_zero' (h : HasSubgaussianMGF X 0 κ ν) :
X =ᵐ[κ ∘ₘ ν] 0 := by
have hX := h.aestronglyMeasurable
have h' : HasSubgaussianMGF (hX.mk X) 0 κ ν := h.congr hX.ae_eq_mk
exact hX.ae_eq_mk.trans (ae_eq_zero_of_hasSubgaussianMGF_zero_of_measurable hX.measurable_mk h')
end Zero
section Add
lemma add {Y : Ω → ℝ} {cX cY : ℝ≥0} (hX : HasSubgaussianMGF X cX κ ν)
(hY : HasSubgaussianMGF Y cY κ ν) :
HasSubgaussianMGF (fun ω ↦ X ω + Y ω) ((cX.sqrt + cY.sqrt) ^ 2) κ ν := by
by_cases hX0 : cX = 0
· simp only [hX0, NNReal.sqrt_zero, zero_add, NNReal.sq_sqrt] at hX ⊢
refine hY.congr ?_
filter_upwards [ae_eq_zero_of_hasSubgaussianMGF_zero' hX] with ω hX0 using by simp [hX0]
by_cases hY0 : cY = 0
· simp only [hY0, NNReal.sqrt_zero, add_zero, NNReal.sq_sqrt] at hY ⊢
refine hX.congr ?_
filter_upwards [ae_eq_zero_of_hasSubgaussianMGF_zero' hY] with ω hY0 using by simp [hY0]
exact
{ integrable_exp_mul t := by
simp_rw [mul_add, exp_add]
convert MemLp.integrable_mul (hX.memLp_exp_mul t 2) (hY.memLp_exp_mul t 2)
norm_cast
infer_instance
mgf_le := by
let p := (cX.sqrt + cY.sqrt) / cX.sqrt
let q := (cX.sqrt + cY.sqrt) / cY.sqrt
filter_upwards [hX.mgf_le, hY.mgf_le, hX.ae_forall_memLp_exp_mul p,
hY.ae_forall_memLp_exp_mul q] with ω' hmX hmY hlX hlY t
calc (κ ω')[fun ω ↦ exp (t * (X ω + Y ω))]
_ ≤ (κ ω')[fun ω ↦ exp (t * X ω) ^ (p : ℝ)] ^ (1 / (p : ℝ)) *
(κ ω')[fun ω ↦ exp (t * Y ω) ^ (q : ℝ)] ^ (1 / (q : ℝ)) := by
simp_rw [mul_add, exp_add]
apply integral_mul_le_Lp_mul_Lq_of_nonneg
· exact ⟨by simp [field, p, q], by positivity, by positivity⟩
· exact ae_of_all _ fun _ ↦ exp_nonneg _
· exact ae_of_all _ fun _ ↦ exp_nonneg _
· simpa using (hlX t)
· simpa using (hlY t)
_ ≤ exp (cX * (t * p) ^ 2 / 2) ^ (1 / (p : ℝ)) *
exp (cY * (t * q) ^ 2 / 2) ^ (1 / (q : ℝ)) := by
simp_rw [← exp_mul _ p, ← exp_mul _ q, mul_right_comm t _ p, mul_right_comm t _ q]
gcongr
· exact hmX (t * p)
· exact hmY (t * q)
_ = exp ((cX.sqrt + cY.sqrt) ^ 2 * t ^ 2 / 2) := by
simp_rw [← exp_mul, ← exp_add]
simp only [NNReal.coe_div, NNReal.coe_add, coe_sqrt, one_div, inv_div, exp_eq_exp, p, q]
field_simp
linear_combination t ^ 2 * (-√↑cY * Real.sq_sqrt cX.coe_nonneg
-√↑cX * Real.sq_sqrt cY.coe_nonneg) }
variable {Ω'' : Type*} {mΩ'' : MeasurableSpace Ω''} {Y : Ω'' → ℝ} {cY : ℝ≥0}
lemma prodMkLeft_compProd {η : Kernel Ω Ω''} (h : HasSubgaussianMGF Y cY η (κ ∘ₘ ν)) :
HasSubgaussianMGF Y cY (prodMkLeft Ω' η) (ν ⊗ₘ κ) := by
by_cases hν : SFinite ν
swap; · simp [hν]
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
constructor
· simpa using h.integrable_exp_mul
· have h2 := h.mgf_le
rw [← Measure.snd_compProd, Measure.snd] at h2
exact ae_of_ae_map (by fun_prop) h2
variable [SFinite ν]
lemma integrable_exp_add_compProd {η : Kernel (Ω' × Ω) Ω''} [IsZeroOrMarkovKernel η]
(hX : HasSubgaussianMGF X c κ ν) (hY : HasSubgaussianMGF Y cY η (ν ⊗ₘ κ)) (t : ℝ) :
Integrable (fun ω ↦ exp (t * (X ω.1 + Y ω.2))) ((κ ⊗ₖ η) ∘ₘ ν) := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
rcases eq_zero_or_isMarkovKernel η with rfl | hη
· simp
simp_rw [mul_add, exp_add]
refine MemLp.integrable_mul (p := 2) (q := 2) ?_ ?_
· have h := hX.memLp_exp_mul t 2
simp only [ENNReal.coe_ofNat] at h
have : κ ∘ₘ ν = ((κ ⊗ₖ η) ∘ₘ ν).map Prod.fst := by
rw [Measure.map_comp _ _ measurable_fst, ← fst_eq, fst_compProd]
rwa [this, memLp_map_measure_iff h.1 measurable_fst.aemeasurable] at h
· have h := hY.memLp_exp_mul t 2
rwa [ENNReal.coe_ofNat, Measure.comp_compProd_comm, Measure.snd,
memLp_map_measure_iff h.1 measurable_snd.aemeasurable] at h
/-- For `ν : Measure Ω'`, `κ : Kernel Ω' Ω` and `η : (Ω' × Ω) Ω''`, if a random variable `X : Ω → ℝ`
has a sub-Gaussian mgf with respect to `κ` and `ν` and another random variable `Y : Ω'' → ℝ` has
a sub-Gaussian mgf with respect to `η` and `ν ⊗ₘ κ : Measure (Ω' × Ω)`, then `X + Y` (random
variable on the measurable space `Ω × Ω''`) has a sub-Gaussian mgf with respect to
`κ ⊗ₖ η : Kernel Ω' (Ω × Ω'')` and `ν`. -/
lemma add_compProd {η : Kernel (Ω' × Ω) Ω''} [IsZeroOrMarkovKernel η]
(hX : HasSubgaussianMGF X c κ ν) (hY : HasSubgaussianMGF Y cY η (ν ⊗ₘ κ)) :
HasSubgaussianMGF (fun p ↦ X p.1 + Y p.2) (c + cY) (κ ⊗ₖ η) ν := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
refine .of_rat (integrable_exp_add_compProd hX hY) fun q ↦ ?_
filter_upwards [hX.mgf_le, hX.ae_integrable_exp_mul q, Measure.ae_ae_of_ae_compProd hY.mgf_le,
Measure.ae_integrable_of_integrable_comp <| integrable_exp_add_compProd hX hY q]
with ω' hX_mgf hX_int hY_mgf h_int_mul
calc mgf (fun p ↦ X p.1 + Y p.2) ((κ ⊗ₖ η) ω') q
_ = ∫ x, exp (q * X x) * ∫ y, exp (q * Y y) ∂(η (ω', x)) ∂(κ ω') := by
simp_rw [mgf, mul_add, exp_add] at h_int_mul ⊢
simp_rw [integral_compProd h_int_mul, integral_const_mul]
_ ≤ ∫ x, exp (q * X x) * exp (cY * q ^ 2 / 2) ∂(κ ω') := by
refine integral_mono_of_nonneg ?_ (hX_int.mul_const _) ?_
· exact ae_of_all _ fun ω ↦ mul_nonneg (by positivity)
(integral_nonneg (fun _ ↦ by positivity))
· filter_upwards [all_ae_of hY_mgf q] with ω hY_mgf
gcongr
exact hY_mgf
_ ≤ exp (↑(c + cY) * q ^ 2 / 2) := by
rw [integral_mul_const, NNReal.coe_add, add_mul, add_div, exp_add]
gcongr
exact hX_mgf q
/-- For `ν : Measure Ω'`, `κ : Kernel Ω' Ω` and `η : Ω Ω''`, if a random variable `X : Ω → ℝ`
has a sub-Gaussian mgf with respect to `κ` and `ν` and another random variable `Y : Ω'' → ℝ` has
a sub-Gaussian mgf with respect to `η` and `κ ∘ₘ ν : Measure Ω`, then `X + Y` (random
variable on the measurable space `Ω × Ω''`) has a sub-Gaussian mgf with respect to
`κ ⊗ₖ prodMkLeft Ω' η : Kernel Ω' (Ω × Ω'')` and `ν`. -/
lemma add_comp {η : Kernel Ω Ω''} [IsZeroOrMarkovKernel η]
(hX : HasSubgaussianMGF X c κ ν) (hY : HasSubgaussianMGF Y cY η (κ ∘ₘ ν)) :
HasSubgaussianMGF (fun p ↦ X p.1 + Y p.2) (c + cY) (κ ⊗ₖ prodMkLeft Ω' η) ν :=
hX.add_compProd hY.prodMkLeft_compProd
end Add
end Kernel.HasSubgaussianMGF
end Kernel
section Conditional
/-! ### Conditionally sub-Gaussian moment-generating function -/
variable {Ω : Type*} {m mΩ : MeasurableSpace Ω} {hm : m ≤ mΩ} [StandardBorelSpace Ω]
{μ : Measure Ω} [IsFiniteMeasure μ] {X : Ω → ℝ} {c : ℝ≥0}
variable (m) (hm) in
/-- A random variable `X` has a conditionally sub-Gaussian moment-generating function
with parameter `c` with respect to a sigma-algebra `m` and a measure `μ` if for all `t : ℝ`,
`exp (t * X)` is `μ`-integrable and the moment-generating function of `X` conditioned on `m` is
almost surely bounded by `exp (c * t ^ 2 / 2)` for all `t : ℝ`.
This implies in particular that `X` has expectation 0.
The actual definition uses `Kernel.HasSubgaussianMGF`: `HasCondSubgaussianMGF` is defined as
sub-Gaussian with respect to the conditional expectation kernel for `m` and the restriction of `μ`
to the sigma-algebra `m`. -/
def HasCondSubgaussianMGF (X : Ω → ℝ) (c : ℝ≥0)
(μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.HasSubgaussianMGF X c (condExpKernel μ m) (μ.trim hm)
namespace HasCondSubgaussianMGF
lemma mgf_le (h : HasCondSubgaussianMGF m hm X c μ) :
∀ᵐ ω' ∂(μ.trim hm), ∀ t, mgf X (condExpKernel μ m ω') t ≤ exp (c * t ^ 2 / 2) :=
Kernel.HasSubgaussianMGF.mgf_le h
lemma cgf_le (h : HasCondSubgaussianMGF m hm X c μ) :
∀ᵐ ω' ∂(μ.trim hm), ∀ t, cgf X (condExpKernel μ m ω') t ≤ c * t ^ 2 / 2 :=
Kernel.HasSubgaussianMGF.cgf_le h
lemma ae_trim_condExp_le (h : HasCondSubgaussianMGF m hm X c μ) (t : ℝ) :
∀ᵐ ω' ∂(μ.trim hm), (μ[fun ω ↦ exp (t * X ω)|m]) ω' ≤ exp (c * t ^ 2 / 2) := by
have h_eq := condExp_ae_eq_trim_integral_condExpKernel hm (h.integrable_exp_mul t)
simp_rw [condExpKernel_comp_trim] at h_eq
filter_upwards [h.mgf_le, h_eq] with ω' h_mgf h_eq
rw [h_eq]
exact h_mgf t
lemma ae_condExp_le (h : HasCondSubgaussianMGF m hm X c μ) (t : ℝ) :
∀ᵐ ω' ∂μ, (μ[fun ω ↦ exp (t * X ω)|m]) ω' ≤ exp (c * t ^ 2 / 2) :=
ae_of_ae_trim hm (h.ae_trim_condExp_le t)
@[simp]
lemma fun_zero : HasCondSubgaussianMGF m hm (fun _ ↦ 0) 0 μ := Kernel.HasSubgaussianMGF.fun_zero
@[simp]
lemma zero : HasCondSubgaussianMGF m hm 0 0 μ := Kernel.HasSubgaussianMGF.zero
lemma memLp_exp_mul (h : HasCondSubgaussianMGF m hm X c μ) (t : ℝ) (p : ℝ≥0) :
MemLp (fun ω ↦ exp (t * X ω)) p μ :=
condExpKernel_comp_trim (μ := μ) hm ▸ Kernel.HasSubgaussianMGF.memLp_exp_mul h t p
lemma integrable_exp_mul (h : HasCondSubgaussianMGF m hm X c μ) (t : ℝ) :
Integrable (fun ω ↦ exp (t * X ω)) μ :=
condExpKernel_comp_trim (μ := μ) hm ▸ Kernel.HasSubgaussianMGF.integrable_exp_mul h t
end HasCondSubgaussianMGF
end Conditional
/-! ### Sub-Gaussian moment-generating function -/
variable {Ω : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {X : Ω → ℝ} {c : ℝ≥0}
/-- A random variable `X` has a sub-Gaussian moment-generating function with parameter `c`
with respect to a measure `μ` if for all `t : ℝ`, `exp (t * X)` is `μ`-integrable and
the moment-generating function of `X` is bounded by `exp (c * t ^ 2 / 2)` for all `t : ℝ`.
This implies in particular that `X` has expectation 0.
This is equivalent to `Kernel.HasSubgaussianMGF X c (Kernel.const Unit μ) (Measure.dirac ())`,
as proved in `HasSubgaussianMGF_iff_kernel`.
Properties about sub-Gaussian moment-generating functions should be proved first for
`Kernel.HasSubgaussianMGF` when possible. -/
structure HasSubgaussianMGF (X : Ω → ℝ) (c : ℝ≥0) (μ : Measure Ω := by volume_tac) : Prop where
integrable_exp_mul : ∀ t : ℝ, Integrable (fun ω ↦ exp (t * X ω)) μ
mgf_le : ∀ t : ℝ, mgf X μ t ≤ exp (c * t ^ 2 / 2)
lemma HasSubgaussianMGF_iff_kernel :
HasSubgaussianMGF X c μ
↔ Kernel.HasSubgaussianMGF X c (Kernel.const Unit μ) (Measure.dirac ()) :=
⟨fun ⟨h1, h2⟩ ↦ ⟨by simpa, by simpa⟩, fun ⟨h1, h2⟩ ↦ ⟨by simpa using h1, by simpa using h2⟩⟩
namespace HasSubgaussianMGF
lemma aestronglyMeasurable (h : HasSubgaussianMGF X c μ) : AEStronglyMeasurable X μ := by
have h_int := h.integrable_exp_mul 1
simpa using (aemeasurable_of_aemeasurable_exp h_int.1.aemeasurable).aestronglyMeasurable
lemma aemeasurable (h : HasSubgaussianMGF X c μ) : AEMeasurable X μ :=
h.aestronglyMeasurable.aemeasurable
lemma congr (h : HasSubgaussianMGF X c μ) {Y : Ω → ℝ} (h' : X =ᵐ[μ] Y) :
HasSubgaussianMGF Y c μ := by
rw [HasSubgaussianMGF_iff_kernel] at h ⊢
apply h.congr
simpa
lemma memLp_exp_mul (h : HasSubgaussianMGF X c μ) (t : ℝ) (p : ℝ≥0) :
MemLp (fun ω ↦ exp (t * X ω)) p μ := by
rw [HasSubgaussianMGF_iff_kernel] at h
simpa using h.memLp_exp_mul t p
lemma cgf_le (h : HasSubgaussianMGF X c μ) (t : ℝ) : cgf X μ t ≤ c * t ^ 2 / 2 := by
rw [HasSubgaussianMGF_iff_kernel] at h
simpa using (all_ae_of h.cgf_le t)
@[simp]
lemma fun_zero [IsZeroOrProbabilityMeasure μ] : HasSubgaussianMGF (fun _ ↦ 0) 0 μ := by
simp [HasSubgaussianMGF_iff_kernel]
@[simp]
lemma zero [IsZeroOrProbabilityMeasure μ] : HasSubgaussianMGF 0 0 μ := fun_zero
lemma neg {c : ℝ≥0} (h : HasSubgaussianMGF X c μ) : HasSubgaussianMGF (-X) c μ := by
simpa [HasSubgaussianMGF_iff_kernel] using (HasSubgaussianMGF_iff_kernel.1 h).neg
lemma of_map {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
{Y : Ω' → Ω} {X : Ω → ℝ} (hY : AEMeasurable Y μ) (h : HasSubgaussianMGF X c (μ.map Y)) :
HasSubgaussianMGF (X ∘ Y) c μ where
integrable_exp_mul t := by
have h1 := h.integrable_exp_mul t
rwa [integrable_map_measure h1.aestronglyMeasurable (by fun_prop)] at h1
mgf_le t := by
convert h.mgf_le t using 1
rw [mgf_map hY (h.integrable_exp_mul t).1]
lemma trim (hm : m ≤ mΩ) (hXm : Measurable[m] X) (hX : HasSubgaussianMGF X c μ) :
HasSubgaussianMGF X c (μ.trim hm) where
integrable_exp_mul t := by
refine (hX.integrable_exp_mul t).trim hm ?_
exact Measurable.stronglyMeasurable <| by fun_prop
mgf_le t := by
rw [mgf, ← integral_trim]
· exact hX.mgf_le t
· exact Measurable.stronglyMeasurable <| by fun_prop
section ChernoffBound
/-- Chernoff bound on the right tail of a sub-Gaussian random variable. -/
lemma measure_ge_le (h : HasSubgaussianMGF X c μ) {ε : ℝ} (hε : 0 ≤ ε) :
μ.real {ω | ε ≤ X ω} ≤ exp (-ε ^ 2 / (2 * c)) := by
rw [HasSubgaussianMGF_iff_kernel] at h
simpa using h.measure_ge_le hε
end ChernoffBound
section Zero
lemma ae_eq_zero_of_hasSubgaussianMGF_zero (h : HasSubgaussianMGF X 0 μ) : X =ᵐ[μ] 0 := by
simpa using (HasSubgaussianMGF_iff_kernel.1 h).ae_eq_zero_of_hasSubgaussianMGF_zero
end Zero
section Add
lemma add {Y : Ω → ℝ} {cX cY : ℝ≥0} (hX : HasSubgaussianMGF X cX μ)
(hY : HasSubgaussianMGF Y cY μ) :
HasSubgaussianMGF (fun ω ↦ X ω + Y ω) ((cX.sqrt + cY.sqrt) ^ 2) μ := by
have := (HasSubgaussianMGF_iff_kernel.1 hX).add (HasSubgaussianMGF_iff_kernel.1 hY)
simpa [HasSubgaussianMGF_iff_kernel] using this
lemma add_of_indepFun {Y : Ω → ℝ} {cX cY : ℝ≥0} (hX : HasSubgaussianMGF X cX μ)
(hY : HasSubgaussianMGF Y cY μ) (hindep : X ⟂ᵢ[μ] Y) :
HasSubgaussianMGF (fun ω ↦ X ω + Y ω) (cX + cY) μ where
integrable_exp_mul t := by
simp_rw [mul_add, exp_add]
convert MemLp.integrable_mul (hX.memLp_exp_mul t 2) (hY.memLp_exp_mul t 2)
norm_cast
infer_instance
mgf_le t := by
calc mgf (X + Y) μ t
_ = mgf X μ t * mgf Y μ t :=
hindep.mgf_add (hX.integrable_exp_mul t).1 (hY.integrable_exp_mul t).1
_ ≤ exp (cX * t ^ 2 / 2) * exp (cY * t ^ 2 / 2) := by
gcongr
· exact mgf_nonneg
· exact hX.mgf_le t
· exact hY.mgf_le t
_ = exp ((cX + cY) * t ^ 2 / 2) := by rw [← exp_add]; congr; ring
private lemma sum_of_iIndepFun_of_forall_aemeasurable
{ι : Type*} {X : ι → Ω → ℝ} (h_indep : iIndepFun X μ) {c : ι → ℝ≥0}
(h_meas : ∀ i, AEMeasurable (X i) μ)
{s : Finset ι} (h_subG : ∀ i ∈ s, HasSubgaussianMGF (X i) (c i) μ) :
HasSubgaussianMGF (fun ω ↦ ∑ i ∈ s, X i ω) (∑ i ∈ s, c i) μ := by
have : IsProbabilityMeasure μ := h_indep.isProbabilityMeasure
classical
induction s using Finset.induction_on with
| empty => simp
| insert i s his h =>
simp_rw [← Finset.sum_apply, Finset.sum_insert his, Pi.add_apply, Finset.sum_apply]
have h_indep' := (h_indep.indepFun_finset_sum_of_notMem₀ h_meas his).symm
refine add_of_indepFun (h_subG _ (Finset.mem_insert_self _ _)) (h ?_) ?_
· exact fun i hi ↦ h_subG _ (Finset.mem_insert_of_mem hi)
· convert h_indep'
rw [Finset.sum_apply]
lemma sum_of_iIndepFun {ι : Type*} {X : ι → Ω → ℝ} (h_indep : iIndepFun X μ) {c : ι → ℝ≥0}
{s : Finset ι} (h_subG : ∀ i ∈ s, HasSubgaussianMGF (X i) (c i) μ) :
HasSubgaussianMGF (fun ω ↦ ∑ i ∈ s, X i ω) (∑ i ∈ s, c i) μ := by
have : HasSubgaussianMGF (fun ω ↦ ∑ (i : s), X i ω) (∑ (i : s), c i) μ := by
apply sum_of_iIndepFun_of_forall_aemeasurable
· exact h_indep.precomp Subtype.val_injective
· exact fun i ↦ (h_subG i i.2).aemeasurable
· exact fun i _ ↦ h_subG i i.2
rw [Finset.sum_coe_sort] at this
exact this.congr (ae_of_all _ fun ω ↦ Finset.sum_attach s (fun i ↦ X i ω))
/-- **Hoeffding inequality** for sub-Gaussian random variables. -/
lemma measure_sum_ge_le_of_iIndepFun {ι : Type*} {X : ι → Ω → ℝ} (h_indep : iIndepFun X μ)
{c : ι → ℝ≥0}
{s : Finset ι} (h_subG : ∀ i ∈ s, HasSubgaussianMGF (X i) (c i) μ) {ε : ℝ} (hε : 0 ≤ ε) :
μ.real {ω | ε ≤ ∑ i ∈ s, X i ω} ≤ exp (-ε ^ 2 / (2 * ∑ i ∈ s, c i)) :=
(sum_of_iIndepFun h_indep h_subG).measure_ge_le hε
/-- **Hoeffding inequality** for sub-Gaussian random variables. -/
lemma measure_sum_range_ge_le_of_iIndepFun {X : ℕ → Ω → ℝ} (h_indep : iIndepFun X μ) {c : ℝ≥0}
{n : ℕ} (h_subG : ∀ i < n, HasSubgaussianMGF (X i) c μ) {ε : ℝ} (hε : 0 ≤ ε) :
μ.real {ω | ε ≤ ∑ i ∈ Finset.range n, X i ω} ≤ exp (-ε ^ 2 / (2 * n * c)) := by
have h := (sum_of_iIndepFun h_indep (c := fun _ ↦ c)
(s := Finset.range n) (by simpa)).measure_ge_le hε
simpa [← mul_assoc] using h
end Add
end HasSubgaussianMGF
section HoeffdingLemma
protected lemma mgf_le_of_mem_Icc_of_integral_eq_zero [IsProbabilityMeasure μ] {a b t : ℝ}
(hm : AEMeasurable X μ) (hb : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) (hc : μ[X] = 0) (ht : 0 < t) :
mgf X μ t ≤ exp ((‖b - a‖₊ / 2) ^ 2 * t ^ 2 / 2) := by
have hi (u : ℝ) : Integrable (fun ω ↦ exp (u * X ω)) μ := integrable_exp_mul_of_mem_Icc hm hb
have hs : Set.Icc 0 t ⊆ interior (integrableExpSet X μ) := by simp [hi, integrableExpSet]
obtain ⟨u, h1, h2⟩ := exists_cgf_eq_iteratedDeriv_two_cgf_mul ht hc hs
rw [← exp_cgf (hi t), exp_le_exp, h2]
gcongr
calc
_ = Var[X; μ.tilted (u * X ·)] := by
rw [← variance_tilted_mul (hs (Set.mem_Icc_of_Ioo h1))]
_ ≤ ((b - a) / 2) ^ 2 := by
convert variance_le_sq_of_bounded ((tilted_absolutelyContinuous μ (u * X ·)) hb) _
· exact isProbabilityMeasure_tilted (hi u)
· exact hm.mono_ac (tilted_absolutelyContinuous μ (u * X ·))
_ = (‖b - a‖₊ / 2) ^ 2 := by simp [field]
/-- **Hoeffding's lemma**: with respect to a probability measure `μ`, if `X` is a random variable
that has expectation zero and is almost surely in `Set.Icc a b` for some `a ≤ b`, then `X` has a
sub-Gaussian moment-generating function with parameter `((b - a) / 2) ^ 2`. -/
lemma hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero [IsProbabilityMeasure μ] {a b : ℝ}
(hm : AEMeasurable X μ) (hb : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) (hc : μ[X] = 0) :
HasSubgaussianMGF X ((‖b - a‖₊ / 2) ^ 2) μ where
integrable_exp_mul t := integrable_exp_mul_of_mem_Icc hm hb
mgf_le t := by
obtain ht | ht | ht := lt_trichotomy 0 t
· exact ProbabilityTheory.mgf_le_of_mem_Icc_of_integral_eq_zero hm hb hc ht
· simp [← ht]
calc
_ = mgf (-X) μ (-t) := by simp [mgf]
_ ≤ exp ((‖-a - -b‖₊ / 2) ^ 2 * (-t) ^ 2 / 2) := by
apply ProbabilityTheory.mgf_le_of_mem_Icc_of_integral_eq_zero (hm.neg)
· filter_upwards [hb] with ω ⟨hl, hr⟩ using ⟨neg_le_neg_iff.2 hr, neg_le_neg_iff.2 hl⟩
· rw [integral_neg, hc, neg_zero]
· rwa [Left.neg_pos_iff]
_ = exp (((‖b - a‖₊ / 2) ^ 2) * t ^ 2 / 2) := by ring_nf
/-- A corollary of Hoeffding's lemma for bounded random variables. -/
lemma hasSubgaussianMGF_of_mem_Icc [IsProbabilityMeasure μ] {a b : ℝ} (hm : AEMeasurable X μ)
(hb : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) :
HasSubgaussianMGF (fun ω ↦ X ω - μ[X]) ((‖b - a‖₊ / 2) ^ 2) μ := by
rw [← sub_sub_sub_cancel_right b a μ[X]]
apply hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero (hm.sub_const _)
· filter_upwards [hb] with ω hab using by simpa using hab
· simp [integral_sub (Integrable.of_mem_Icc a b hm hb) (integrable_const _)]
end HoeffdingLemma
section Martingale
variable [StandardBorelSpace Ω]
/-- If `X` is sub-Gaussian with parameter `cX` with respect to the restriction of `μ` to
a sub-sigma-algebra `m` and `Y` is conditionally sub-Gaussian with parameter `cY` with respect to
`m` and `μ` then `X + Y` is sub-Gaussian with parameter `cX + cY` with respect to `μ`.
`HasSubgaussianMGF X cX (μ.trim hm)` can be obtained from `HasSubgaussianMGF X cX μ` if `X` is
`m`-measurable. See `HasSubgaussianMGF.trim`. -/
lemma HasSubgaussianMGF_add_of_HasCondSubgaussianMGF [IsFiniteMeasure μ]
{Y : Ω → ℝ} {cX cY : ℝ≥0} (hm : m ≤ mΩ)
(hX : HasSubgaussianMGF X cX (μ.trim hm)) (hY : HasCondSubgaussianMGF m hm Y cY μ) :
HasSubgaussianMGF (X + Y) (cX + cY) μ := by
suffices HasSubgaussianMGF (fun p ↦ X p.1 + Y p.2) (cX + cY)
(@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω ↦ (id ω, id ω)) μ) by
have h_eq : X + Y = (fun p ↦ X p.1 + Y p.2) ∘ (fun ω ↦ (id ω, id ω)) := rfl
rw [h_eq]
refine HasSubgaussianMGF.of_map ?_ this
exact @Measurable.aemeasurable _ _ _ (m.prod mΩ) _ _
((measurable_id'' hm).prodMk measurable_id)
rw [HasSubgaussianMGF_iff_kernel] at hX ⊢
have hY' : Kernel.HasSubgaussianMGF Y cY (condExpKernel μ m)
(Kernel.const Unit (μ.trim hm) ∘ₘ Measure.dirac ()) := by simpa
convert hX.add_comp hY'
ext
rw [Kernel.const_apply, ← Measure.compProd, compProd_trim_condExpKernel]
variable {Y : ℕ → Ω → ℝ} {cY : ℕ → ℝ≥0} {ℱ : Filtration ℕ mΩ}
/-- Let `Y` be a random process adapted to a filtration `ℱ`, such that for all `i : ℕ`, `Y i` is
conditionally sub-Gaussian with parameter `cY i` with respect to `ℱ (i - 1)`.
In particular, `n ↦ ∑ i ∈ range n, Y i` is a martingale.
Then the sum `∑ i ∈ range n, Y i` is sub-Gaussian with parameter `∑ i ∈ range n, cY i`. -/
lemma HasSubgaussianMGF_sum_of_HasCondSubgaussianMGF [IsZeroOrProbabilityMeasure μ]
(h_adapted : Adapted ℱ Y) (h0 : HasSubgaussianMGF (Y 0) (cY 0) μ) (n : ℕ)
(h_subG : ∀ i < n - 1, HasCondSubgaussianMGF (ℱ i) (ℱ.le i) (Y (i + 1)) (cY (i + 1)) μ) :
HasSubgaussianMGF (fun ω ↦ ∑ i ∈ Finset.range n, Y i ω) (∑ i ∈ Finset.range n, cY i) μ := by
induction n with
| zero => simp
| succ n hn =>
induction n with
| zero => simp [h0]
| succ n =>
specialize hn fun i hi ↦ h_subG i (by cutsat)
simp_rw [Finset.sum_range_succ _ (n + 1)]
refine HasSubgaussianMGF_add_of_HasCondSubgaussianMGF (ℱ.le n) ?_ (h_subG n (by cutsat))
refine HasSubgaussianMGF.trim (ℱ.le n) ?_ hn
refine Finset.measurable_fun_sum (Finset.range (n + 1)) fun m hm ↦
((h_adapted m).mono (ℱ.mono ?_)).measurable
simp only [Finset.mem_range] at hm
cutsat
/-- **Azuma-Hoeffding inequality** for sub-Gaussian random variables. -/
lemma measure_sum_ge_le_of_HasCondSubgaussianMGF [IsZeroOrProbabilityMeasure μ]
(h_adapted : Adapted ℱ Y) (h0 : HasSubgaussianMGF (Y 0) (cY 0) μ) (n : ℕ)
(h_subG : ∀ i < n - 1, HasCondSubgaussianMGF (ℱ i) (ℱ.le i) (Y (i + 1)) (cY (i + 1)) μ)
{ε : ℝ} (hε : 0 ≤ ε) :
μ.real {ω | ε ≤ ∑ i ∈ Finset.range n, Y i ω}
≤ exp (-ε ^ 2 / (2 * ∑ i ∈ Finset.range n, cY i)) :=
(HasSubgaussianMGF_sum_of_HasCondSubgaussianMGF h_adapted h0 n h_subG).measure_ge_le hε
end Martingale
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/Tilted.lean | import Mathlib.MeasureTheory.Measure.Tilted
import Mathlib.Probability.Moments.MGFAnalytic
/-!
# Results relating `Measure.tilted` to `mgf` and `cgf`
For a random variable `X : Ω → ℝ` and a measure `μ`, the tilted measure `μ.tilted (t * X ·)` is
linked to the moment-generating function (`mgf`) and the cumulant-generating function (`cgf`)
of `X`.
## Main statements
* `integral_tilted_mul_self`: the integral of `X` against the tilted measure `μ.tilted (t * X ·)`
is the first derivative of the cumulant-generating function of `X` at `t`.
`(μ.tilted (t * X ·))[X] = deriv (cgf X μ) t`
* `variance_tilted_mul`: the variance of `X` under the tilted measure `μ.tilted (t * X ·)`
is the second derivative of the cumulant-generating function of `X` at `t`.
`Var[X; μ.tilted (t * X ·)] = iteratedDeriv 2 (cgf X μ) t`
-/
open MeasureTheory Real Set Finset
open scoped NNReal ENNReal ProbabilityTheory
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ ν : Measure Ω} {X : Ω → ℝ} {t u : ℝ}
namespace ProbabilityTheory
section Apply
/-! ### Apply lemmas for `tilted` expressed with `mgf` or `cgf`. -/
lemma tilted_mul_apply_mgf' {s : Set Ω} (hs : MeasurableSet s) :
μ.tilted (t * X ·) s = ∫⁻ a in s, ENNReal.ofReal (exp (t * X a) / mgf X μ t) ∂μ := by
rw [tilted_apply' _ _ hs, mgf]
lemma tilted_mul_apply_mgf [SFinite μ] (s : Set Ω) :
μ.tilted (t * X ·) s = ∫⁻ a in s, ENNReal.ofReal (exp (t * X a) / mgf X μ t) ∂μ := by
rw [tilted_apply, mgf]
lemma tilted_mul_apply_cgf' {s : Set Ω} (hs : MeasurableSet s)
(ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
μ.tilted (t * X ·) s = ∫⁻ a in s, ENNReal.ofReal (exp (t * X a - cgf X μ t)) ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [tilted_mul_apply_mgf' hs, exp_sub, exp_cgf ht]
lemma tilted_mul_apply_cgf [SFinite μ] (s : Set Ω) (ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
μ.tilted (t * X ·) s = ∫⁻ a in s, ENNReal.ofReal (exp (t * X a - cgf X μ t)) ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [tilted_mul_apply_mgf s, exp_sub, exp_cgf ht]
lemma tilted_mul_apply_eq_ofReal_integral_mgf' {s : Set Ω} (hs : MeasurableSet s) :
μ.tilted (t * X ·) s = ENNReal.ofReal (∫ a in s, exp (t * X a) / mgf X μ t ∂μ) := by
rw [tilted_apply_eq_ofReal_integral' _ hs, mgf]
lemma tilted_mul_apply_eq_ofReal_integral_mgf [SFinite μ] (s : Set Ω) :
μ.tilted (t * X ·) s = ENNReal.ofReal (∫ a in s, exp (t * X a) / mgf X μ t ∂μ) := by
rw [tilted_apply_eq_ofReal_integral _ s, mgf]
lemma tilted_mul_apply_eq_ofReal_integral_cgf' {s : Set Ω} (hs : MeasurableSet s)
(ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
μ.tilted (t * X ·) s = ENNReal.ofReal (∫ a in s, exp (t * X a - cgf X μ t) ∂μ) := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [tilted_mul_apply_eq_ofReal_integral_mgf' hs, exp_sub]
rwa [exp_cgf]
lemma tilted_mul_apply_eq_ofReal_integral_cgf [SFinite μ] (s : Set Ω)
(ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
μ.tilted (t * X ·) s = ENNReal.ofReal (∫ a in s, exp (t * X a - cgf X μ t) ∂μ) := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [tilted_mul_apply_eq_ofReal_integral_mgf s, exp_sub]
rwa [exp_cgf]
end Apply
section Integral
/-! ### Integral of `tilted` expressed with `mgf` or `cgf`. -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
lemma setIntegral_tilted_mul_eq_mgf' (g : Ω → E) {s : Set Ω} (hs : MeasurableSet s) :
∫ x in s, g x ∂(μ.tilted (t * X ·)) = ∫ x in s, (exp (t * X x) / mgf X μ t) • (g x) ∂μ := by
rw [setIntegral_tilted' _ _ hs, mgf]
lemma setIntegral_tilted_mul_eq_mgf [SFinite μ] (g : Ω → E) (s : Set Ω) :
∫ x in s, g x ∂(μ.tilted (t * X ·)) = ∫ x in s, (exp (t * X x) / mgf X μ t) • (g x) ∂μ := by
rw [setIntegral_tilted, mgf]
lemma setIntegral_tilted_mul_eq_cgf' (g : Ω → E) {s : Set Ω}
(hs : MeasurableSet s) (ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
∫ x in s, g x ∂(μ.tilted (t * X ·)) = ∫ x in s, exp (t * X x - cgf X μ t) • (g x) ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [setIntegral_tilted_mul_eq_mgf' _ hs, exp_sub, exp_cgf ht]
lemma setIntegral_tilted_mul_eq_cgf [SFinite μ] (g : Ω → E) (s : Set Ω)
(ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
∫ x in s, g x ∂(μ.tilted (t * X ·)) = ∫ x in s, exp (t * X x - cgf X μ t) • (g x) ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [setIntegral_tilted_mul_eq_mgf, exp_sub, exp_cgf ht]
lemma integral_tilted_mul_eq_mgf (g : Ω → E) :
∫ ω, g ω ∂(μ.tilted (t * X ·)) = ∫ ω, (exp (t * X ω) / mgf X μ t) • (g ω) ∂μ := by
rw [integral_tilted, mgf]
lemma integral_tilted_mul_eq_cgf (g : Ω → E) (ht : Integrable (fun ω ↦ exp (t * X ω)) μ) :
∫ ω, g ω ∂(μ.tilted (t * X ·)) = ∫ ω, exp (t * X ω - cgf X μ t) • (g ω) ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
· simp_rw [integral_tilted_mul_eq_mgf, exp_sub]
rwa [exp_cgf]
/-- The integral of `X` against the tilted measure `μ.tilted (t * X ·)` is the first derivative of
the cumulant-generating function of `X` at `t`. -/
lemma integral_tilted_mul_self (ht : t ∈ interior (integrableExpSet X μ)) :
(μ.tilted (t * X ·))[X] = deriv (cgf X μ) t := by
simp_rw [integral_tilted_mul_eq_mgf, deriv_cgf ht, ← integral_div, smul_eq_mul]
congr with ω
ring
end Integral
lemma memLp_tilted_mul (ht : t ∈ interior (integrableExpSet X μ)) (p : ℝ≥0) :
MemLp X p (μ.tilted (t * X ·)) := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet ht
by_cases hp : p = 0
· simpa [hp] using hX.aestronglyMeasurable.mono_ac (tilted_absolutelyContinuous _ _)
refine ⟨hX.aestronglyMeasurable.mono_ac (tilted_absolutelyContinuous _ _), ?_⟩
rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top]
rotate_left
· simp [hp]
· simp
simp_rw [ENNReal.coe_toReal, ← ofReal_norm_eq_enorm, norm_eq_abs,
ENNReal.ofReal_rpow_of_nonneg (x := |X _|) (p := p) (abs_nonneg (X _)) p.2]
refine Integrable.lintegral_lt_top ?_
simp_rw [integrable_tilted_iff (interior_subset (s := integrableExpSet X μ) ht),
smul_eq_mul, mul_comm]
exact integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet ht p.2
/-- The variance of `X` under the tilted measure `μ.tilted (t * X ·)` is the second derivative of
the cumulant-generating function of `X` at `t`. -/
lemma variance_tilted_mul (ht : t ∈ interior (integrableExpSet X μ)) :
Var[X; μ.tilted (t * X ·)] = iteratedDeriv 2 (cgf X μ) t := by
rw [variance_eq_integral]
swap; · exact (memLp_tilted_mul ht 1).aestronglyMeasurable.aemeasurable
rw [integral_tilted_mul_self ht, iteratedDeriv_two_cgf_eq_integral ht, integral_tilted_mul_eq_mgf,
← integral_div]
simp only [smul_eq_mul]
congr with ω
ring
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/Variance.lean | import Mathlib.Probability.Moments.Covariance
/-!
# Variance of random variables
We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the
`ProbabilityTheory` locale).
## Main definitions
* `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended
non-negative real.
* `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number.
## Main results
* `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`.
* `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e.,
`ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`.
* `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with
`evariance` without requiring the random variables to be L².
* `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent
random variables is the sum of the variances.
* `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise
independent random variables is the sum of the variances.
* `ProbabilityTheory.variance_le_sub_mul_sub`: the variance of a random variable `X` satisfying
`a ≤ X ≤ b` almost everywhere is at most `(b - 𝔼 X) * (𝔼 X - a)`.
* `ProbabilityTheory.variance_le_sq_of_bounded`: the variance of a random variable `X` satisfying
`a ≤ X ≤ b` almost everywhere is at most`((b - a) / 2) ^ 2`.
-/
open MeasureTheory Filter Finset
noncomputable section
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal
namespace ProbabilityTheory
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {X Y : Ω → ℝ} {μ : Measure Ω}
variable (X μ) in
-- TODO: Consider if `evariance` or `eVariance` is better. Also,
-- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`.
/-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of
`‖X - 𝔼[X]‖^2`. -/
def evariance : ℝ≥0∞ := ∫⁻ ω, ‖X ω - μ[X]‖ₑ ^ 2 ∂μ
variable (X μ) in
/-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal`
to `evariance`. -/
def variance : ℝ := (evariance X μ).toReal
/-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the measure `μ`.
This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/
scoped notation "eVar[" X "; " μ "]" => ProbabilityTheory.evariance X μ
/-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the volume
measure.
This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/
scoped notation "eVar[" X "]" => eVar[X; MeasureTheory.MeasureSpace.volume]
/-- The `ℝ`-valued variance of the real-valued random variable `X` according to the measure `μ`.
It is set to `0` if `X` has infinite variance. -/
scoped notation "Var[" X "; " μ "]" => ProbabilityTheory.variance X μ
/-- The `ℝ`-valued variance of the real-valued random variable `X` according to the volume measure.
It is set to `0` if `X` has infinite variance. -/
scoped notation "Var[" X "]" => Var[X; MeasureTheory.MeasureSpace.volume]
theorem evariance_congr (h : X =ᵐ[μ] Y) : eVar[X; μ] = eVar[Y; μ] := by
simp_rw [evariance, integral_congr_ae h]
apply lintegral_congr_ae
filter_upwards [h] with ω hω using by simp [hω]
theorem variance_congr (h : X =ᵐ[μ] Y) : Var[X; μ] = Var[Y; μ] := by
simp_rw [variance, evariance_congr h]
theorem evariance_lt_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ < ∞ := by
have := ENNReal.pow_lt_top (hX.sub <| memLp_const <| μ[X]).2 (n := 2)
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, ← ENNReal.rpow_two] at this
simp only [ENNReal.toReal_ofNat, Pi.sub_apply, one_div] at this
rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this
simp_rw [ENNReal.rpow_two] at this
exact this
lemma evariance_ne_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ ≠ ∞ :=
(evariance_lt_top hX).ne
theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬MemLp X 2 μ) :
evariance X μ = ∞ := by
by_contra h
rw [← Ne, ← lt_top_iff_ne_top] at h
have : MemLp (fun ω => X ω - μ[X]) 2 μ := by
refine ⟨by fun_prop, ?_⟩
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top]
simp only [ENNReal.toReal_ofNat, ENNReal.rpow_two]
exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne
refine hX ?_
convert this.add (memLp_const μ[X])
ext ω
rw [Pi.add_apply, sub_add_cancel]
theorem evariance_lt_top_iff_memLp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) :
evariance X μ < ∞ ↔ MemLp X 2 μ where
mp := by contrapose!; rw [top_le_iff]; exact evariance_eq_top hX
mpr := evariance_lt_top
lemma evariance_eq_top_iff [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) :
evariance X μ = ∞ ↔ ¬ MemLp X 2 μ := by simp [← evariance_lt_top_iff_memLp hX]
lemma variance_of_not_memLp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ)
(hX_not : ¬ MemLp X 2 μ) :
variance X μ = 0 := by simp [variance, (evariance_eq_top_iff hX).mpr hX_not]
theorem ofReal_variance [IsFiniteMeasure μ] (hX : MemLp X 2 μ) :
.ofReal (variance X μ) = evariance X μ := by
rw [variance, ENNReal.ofReal_toReal]
exact evariance_ne_top hX
protected alias _root_.MeasureTheory.MemLp.evariance_lt_top := evariance_lt_top
protected alias _root_.MeasureTheory.MemLp.evariance_ne_top := evariance_ne_top
protected alias _root_.MeasureTheory.MemLp.ofReal_variance_eq := ofReal_variance
variable (X μ) in
theorem evariance_eq_lintegral_ofReal :
evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by
simp [evariance, ← enorm_pow, Real.enorm_of_nonneg (sq_nonneg _)]
lemma variance_eq_integral (hX : AEMeasurable X μ) : Var[X; μ] = ∫ ω, (X ω - μ[X]) ^ 2 ∂μ := by
simp [variance, evariance, toReal_enorm, ← integral_toReal ((hX.sub_const _).enorm.pow_const _) <|
.of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top]
lemma variance_of_integral_eq_zero (hX : AEMeasurable X μ) (hXint : μ[X] = 0) :
variance X μ = ∫ ω, X ω ^ 2 ∂μ := by
simp [variance_eq_integral hX, hXint]
@[simp]
theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance]
theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) :
evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by
simp [evariance, lintegral_eq_zero_iff' ((hX.sub_const _).enorm.pow_const _), EventuallyEq,
sub_eq_zero]
theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by
rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne]
congr with ω
rw [integral_const_mul, ← mul_sub, enorm_mul, mul_pow, ← enorm_pow,
Real.enorm_of_nonneg (sq_nonneg _)]
@[simp]
theorem variance_zero (μ : Measure Ω) : variance 0 μ = 0 := by
simp only [variance, evariance_zero, ENNReal.toReal_zero]
lemma covariance_self {X : Ω → ℝ} (hX : AEMeasurable X μ) :
cov[X, X; μ] = Var[X; μ] := by
rw [covariance, variance_eq_integral hX]
congr with x
ring
@[deprecated (since := "2025-06-25")] alias covariance_same := covariance_self
theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ :=
ENNReal.toReal_nonneg
theorem variance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
variance (fun ω => c * X ω) μ = c ^ 2 * variance X μ := by
rw [variance, evariance_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (sq_nonneg _)]
rfl
theorem variance_smul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
variance (c • X) μ = c ^ 2 * variance X μ :=
variance_mul c X μ
theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ)
(μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by
convert variance_smul (algebraMap A ℝ c) X μ using 1
· simp only [algebraMap_smul]
· simp only [Algebra.smul_def, map_pow]
theorem variance_eq_sub [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : MemLp X 2 μ) :
variance X μ = μ[X ^ 2] - μ[X] ^ 2 := by
rw [← covariance_self hX.aemeasurable, covariance_eq_sub hX hX, pow_two, pow_two]
@[deprecated (since := "2025-08-07")] alias variance_def' := variance_eq_sub
lemma variance_add_const [IsProbabilityMeasure μ] (hX : AEStronglyMeasurable X μ) (c : ℝ) :
Var[fun ω ↦ X ω + c; μ] = Var[X; μ] := by
by_cases hX_Lp : MemLp X 2 μ
· have hX_int : Integrable X μ := hX_Lp.integrable one_le_two
rw [variance_eq_integral (hX.add_const _).aemeasurable,
integral_add hX_int (by fun_prop), integral_const, variance_eq_integral hX.aemeasurable]
simp
· rw [variance_of_not_memLp (hX.add_const _), variance_of_not_memLp hX hX_Lp]
refine fun h_memLp ↦ hX_Lp ?_
have : X = fun ω ↦ X ω + c - c := by ext; ring
rw [this]
exact h_memLp.sub (memLp_const c)
lemma variance_const_add [IsProbabilityMeasure μ] (hX : AEStronglyMeasurable X μ) (c : ℝ) :
Var[fun ω ↦ c + X ω; μ] = Var[X; μ] := by
simp_rw [add_comm c, variance_add_const hX c]
lemma variance_fun_neg : Var[fun ω ↦ -X ω; μ] = Var[X; μ] := by
convert variance_mul (-1) X μ
· ext; ring
· simp
lemma variance_neg : Var[-X; μ] = Var[X; μ] := variance_fun_neg
lemma variance_sub_const [IsProbabilityMeasure μ] (hX : AEStronglyMeasurable X μ) (c : ℝ) :
Var[fun ω ↦ X ω - c; μ] = Var[X; μ] := by
simp_rw [sub_eq_add_neg, variance_add_const hX (-c)]
lemma variance_const_sub [IsProbabilityMeasure μ] (hX : AEStronglyMeasurable X μ) (c : ℝ) :
Var[fun ω ↦ c - X ω; μ] = Var[X; μ] := by
simp_rw [sub_eq_add_neg]
rw [variance_const_add (by fun_prop) c, variance_fun_neg]
lemma variance_add [IsFiniteMeasure μ] (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
Var[X + Y; μ] = Var[X; μ] + 2 * cov[X, Y; μ] + Var[Y; μ] := by
rw [← covariance_self, covariance_add_left hX hY (hX.add hY), covariance_add_right hX hX hY,
covariance_add_right hY hX hY, covariance_self, covariance_self, covariance_comm]
· ring
· exact hY.aemeasurable
· exact hX.aemeasurable
· exact hX.aemeasurable.add hY.aemeasurable
lemma variance_fun_add [IsFiniteMeasure μ] (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
Var[fun ω ↦ X ω + Y ω; μ] = Var[X; μ] + 2 * cov[X, Y; μ] + Var[Y; μ] :=
variance_add hX hY
lemma variance_sub [IsFiniteMeasure μ] (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
Var[X - Y; μ] = Var[X; μ] - 2 * cov[X, Y; μ] + Var[Y; μ] := by
rw [sub_eq_add_neg, variance_add hX hY.neg, variance_neg, covariance_neg_right]
ring
lemma variance_fun_sub [IsFiniteMeasure μ] (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
Var[fun ω ↦ X ω - Y ω; μ] = Var[X; μ] - 2 * cov[X, Y; μ] + Var[Y; μ] :=
variance_sub hX hY
variable {ι : Type*} {s : Finset ι} {X : (i : ι) → Ω → ℝ}
lemma variance_sum' [IsFiniteMeasure μ] (hX : ∀ i ∈ s, MemLp (X i) 2 μ) :
Var[∑ i ∈ s, X i; μ] = ∑ i ∈ s, ∑ j ∈ s, cov[X i, X j; μ] := by
rw [← covariance_self, covariance_sum_left' (by simpa)]
· refine Finset.sum_congr rfl fun i hi ↦ ?_
rw [covariance_sum_right' (by simpa) (hX i hi)]
· exact memLp_finset_sum' _ (by simpa)
· exact (memLp_finset_sum' _ (by simpa)).aemeasurable
lemma variance_sum [IsFiniteMeasure μ] [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) :
Var[∑ i, X i; μ] = ∑ i, ∑ j, cov[X i, X j; μ] :=
variance_sum' (fun _ _ ↦ hX _)
lemma variance_fun_sum' [IsFiniteMeasure μ] (hX : ∀ i ∈ s, MemLp (X i) 2 μ) :
Var[fun ω ↦ ∑ i ∈ s, X i ω; μ] = ∑ i ∈ s, ∑ j ∈ s, cov[X i, X j; μ] := by
convert variance_sum' hX
simp
lemma variance_fun_sum [IsFiniteMeasure μ] [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) :
Var[fun ω ↦ ∑ i, X i ω; μ] = ∑ i, ∑ j, cov[X i, X j; μ] := by
convert variance_sum hX
simp
variable {X : Ω → ℝ}
@[simp]
lemma variance_dirac [MeasurableSingletonClass Ω] (x : Ω) : Var[X; Measure.dirac x] = 0 := by
rw [variance_eq_integral]
· simp
· exact aemeasurable_dirac
lemma variance_map {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
{Y : Ω' → Ω} (hX : AEMeasurable X (μ.map Y)) (hY : AEMeasurable Y μ) :
Var[X; μ.map Y] = Var[X ∘ Y; μ] := by
rw [variance_eq_integral hX, integral_map hY, variance_eq_integral (hX.comp_aemeasurable hY),
integral_map hY]
· congr
· exact hX.aestronglyMeasurable
· refine AEStronglyMeasurable.pow ?_ _
exact AEMeasurable.aestronglyMeasurable (by fun_prop)
lemma _root_.MeasureTheory.MeasurePreserving.variance_fun_comp {Ω' : Type*}
{mΩ' : MeasurableSpace Ω'} {ν : Measure Ω'} {X : Ω → Ω'}
(hX : MeasurePreserving X μ ν) {f : Ω' → ℝ} (hf : AEMeasurable f ν) :
Var[fun ω ↦ f (X ω); μ] = Var[f; ν] := by
rw [← hX.map_eq, variance_map (hX.map_eq ▸ hf) hX.aemeasurable, Function.comp_def]
lemma variance_map_equiv {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
(X : Ω → ℝ) (Y : Ω' ≃ᵐ Ω) :
Var[X; μ.map Y] = Var[X ∘ Y; μ] := by
simp_rw [variance, evariance, lintegral_map_equiv, integral_map_equiv, Function.comp_apply]
lemma variance_id_map (hX : AEMeasurable X μ) : Var[id; μ.map X] = Var[X; μ] := by
simp [variance_map measurable_id.aemeasurable hX]
theorem variance_le_expectation_sq [IsProbabilityMeasure μ] {X : Ω → ℝ}
(hm : AEStronglyMeasurable X μ) : variance X μ ≤ μ[X ^ 2] := by
by_cases hX : MemLp X 2 μ
· rw [variance_eq_sub hX]
simp only [sq_nonneg, sub_le_self_iff]
rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
· by_cases hint : Integrable X μ; swap
· simp only [integral_undef hint, Pi.pow_apply, sub_zero]
exact le_rfl
· rw [integral_undef]
· exact integral_nonneg fun a => sq_nonneg _
intro h
have A : MemLp (X - fun ω : Ω => μ[X]) 2 μ :=
(memLp_two_iff_integrable_sq (by fun_prop)).2 h
have B : MemLp (fun _ : Ω => μ[X]) 2 μ := memLp_const _
apply hX
convert A.add B
simp
· exact Eventually.of_forall fun x => sq_nonneg _
· exact (AEMeasurable.pow_const (hm.aemeasurable.sub_const _) _).aestronglyMeasurable
theorem evariance_def' [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : AEStronglyMeasurable X μ) :
evariance X μ = (∫⁻ ω, ‖X ω‖ₑ ^ 2 ∂μ) - ENNReal.ofReal (μ[X] ^ 2) := by
by_cases hℒ : MemLp X 2 μ
· rw [← ofReal_variance hℒ, variance_eq_sub hℒ, ENNReal.ofReal_sub _ (sq_nonneg _)]
congr
simp_rw [← enorm_pow, enorm]
rw [lintegral_coe_eq_integral]
· simp
· simpa using hℒ.abs.integrable_sq
· symm
rw [evariance_eq_top hX hℒ, ENNReal.sub_eq_top_iff]
refine ⟨?_, ENNReal.ofReal_ne_top⟩
rw [MemLp, not_and] at hℒ
specialize hℒ hX
simp only [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, not_lt, top_le_iff,
ENNReal.toReal_ofNat, one_div, ENNReal.rpow_eq_top_iff, inv_lt_zero, inv_pos, and_true,
or_iff_not_imp_left, not_and_or, zero_lt_two] at hℒ
exact mod_cast hℒ fun _ => zero_le_two
set_option linter.deprecated false in
/-- **Chebyshev's inequality** for `ℝ≥0∞`-valued variance. -/
theorem meas_ge_le_evariance_div_sq {X : Ω → ℝ} (hX : AEStronglyMeasurable X μ) {c : ℝ≥0}
(hc : c ≠ 0) : μ {ω | ↑c ≤ |X ω - μ[X]|} ≤ evariance X μ / c ^ 2 := by
have A : (c : ℝ≥0∞) ≠ 0 := by rwa [Ne, ENNReal.coe_eq_zero]
have B : AEStronglyMeasurable (fun _ : Ω => μ[X]) μ := aestronglyMeasurable_const
convert meas_ge_le_mul_pow_eLpNorm μ two_ne_zero ENNReal.ofNat_ne_top (hX.sub B) A using 1
· norm_cast
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top]
simp only [ENNReal.toReal_ofNat, one_div, Pi.sub_apply]
rw [div_eq_mul_inv, ENNReal.inv_pow, mul_comm, ENNReal.rpow_two]
congr
simp_rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_two,
ENNReal.rpow_one, evariance]
/-- **Chebyshev's inequality**: one can control the deviation probability of a real random variable
from its expectation in terms of the variance. -/
theorem meas_ge_le_variance_div_sq [IsFiniteMeasure μ] {X : Ω → ℝ} (hX : MemLp X 2 μ) {c : ℝ}
(hc : 0 < c) : μ {ω | c ≤ |X ω - μ[X]|} ≤ ENNReal.ofReal (variance X μ / c ^ 2) := by
rw [ENNReal.ofReal_div_of_pos (sq_pos_of_ne_zero hc.ne.symm), hX.ofReal_variance_eq]
convert @meas_ge_le_evariance_div_sq _ _ _ _ hX.1 c.toNNReal (by simp [hc]) using 1
· simp only [Real.coe_toNNReal', max_le_iff, abs_nonneg, and_true]
· rw [ENNReal.ofReal_pow hc.le]
rfl
/-- The variance of the sum of two independent random variables is the sum of the variances. -/
nonrec theorem IndepFun.variance_add {X Y : Ω → ℝ} (hX : MemLp X 2 μ)
(hY : MemLp Y 2 μ) (h : X ⟂ᵢ[μ] Y) : Var[X + Y; μ] = Var[X; μ] + Var[Y; μ] := by
by_cases h' : X =ᵐ[μ] 0
· rw [variance_congr h', variance_congr h'.add_right]
simp
have := hX.isProbabilityMeasure_of_indepFun X Y (by simp) (by simp) h' h
rw [variance_add hX hY, h.covariance_eq_zero hX hY]
simp
/-- The variance of the sum of two independent random variables is the sum of the variances. -/
lemma IndepFun.variance_fun_add {X Y : Ω → ℝ} (hX : MemLp X 2 μ)
(hY : MemLp Y 2 μ) (h : X ⟂ᵢ[μ] Y) : Var[fun ω ↦ X ω + Y ω; μ] = Var[X; μ] + Var[Y; μ] :=
h.variance_add hX hY
/-- The variance of a finite sum of pairwise independent random variables is the sum of the
variances. -/
nonrec theorem IndepFun.variance_sum {ι : Type*} {X : ι → Ω → ℝ} {s : Finset ι}
(hs : ∀ i ∈ s, MemLp (X i) 2 μ)
(h : Set.Pairwise ↑s fun i j => X i ⟂ᵢ[μ] X j) :
variance (∑ i ∈ s, X i) μ = ∑ i ∈ s, variance (X i) μ := by
by_cases h'' : ∀ i ∈ s, X i =ᵐ[μ] 0
· rw [variance_congr (Y := 0), variance_zero]
· symm
refine Finset.sum_eq_zero fun i hi ↦ ?_
simp [variance_congr (h'' i hi)]
· have := fun (i : s) ↦ h'' i.1 i.2
filter_upwards [ae_all_iff.2 this] with ω hω
simp only [sum_apply, Pi.zero_apply]
exact Finset.sum_eq_zero fun i hi ↦ hω ⟨i, hi⟩
obtain ⟨j, hj1, hj2⟩ := not_forall₂.1 h''
obtain rfl | h' := s.eq_singleton_or_nontrivial hj1
· simp
obtain ⟨k, hk1, hk2⟩ := h'.exists_ne j
have := (hs j hj1).isProbabilityMeasure_of_indepFun (X j) (X k) (by simp) (by simp) hj2
(h hj1 hk1 hk2.symm)
rw [variance_sum' hs]
refine Finset.sum_congr rfl (fun i hi ↦ ?_)
rw [← covariance_self (hs i hi).aemeasurable]
refine Finset.sum_eq_single_of_mem i hi fun j hj1 hj2 ↦ ?_
exact (h hi hj1 hj2.symm).covariance_eq_zero (hs i hi) (hs j hj1)
/-- **The Bhatia-Davis inequality on variance**
The variance of a random variable `X` satisfying `a ≤ X ≤ b` almost everywhere is at most
`(b - 𝔼 X) * (𝔼 X - a)`. -/
lemma variance_le_sub_mul_sub [IsProbabilityMeasure μ] {a b : ℝ} {X : Ω → ℝ}
(h : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) (hX : AEMeasurable X μ) :
variance X μ ≤ (b - μ[X]) * (μ[X] - a) := by
have ha : ∀ᵐ ω ∂μ, a ≤ X ω := h.mono fun ω h => h.1
have hb : ∀ᵐ ω ∂μ, X ω ≤ b := h.mono fun ω h => h.2
have hX_int₂ : Integrable (fun ω ↦ -X ω ^ 2) μ :=
(memLp_of_bounded h hX.aestronglyMeasurable 2).integrable_sq.neg
have hX_int₁ : Integrable (fun ω ↦ (a + b) * X ω) μ :=
((integrable_const (max |a| |b|)).mono' hX.aestronglyMeasurable
(by filter_upwards [ha, hb] with ω using abs_le_max_abs_abs)).const_mul (a + b)
have h0 : 0 ≤ -μ[X ^ 2] + (a + b) * μ[X] - a * b :=
calc
_ ≤ ∫ ω, (b - X ω) * (X ω - a) ∂μ := by
apply integral_nonneg_of_ae
filter_upwards [ha, hb] with ω ha' hb'
exact mul_nonneg (by linarith : 0 ≤ b - X ω) (by linarith : 0 ≤ X ω - a)
_ = ∫ ω, -X ω ^ 2 + (a + b) * X ω - a * b ∂μ :=
integral_congr_ae <| ae_of_all μ fun ω ↦ by ring
_ = ∫ ω, - X ω ^ 2 + (a + b) * X ω ∂μ - ∫ _, a * b ∂μ :=
integral_sub (by fun_prop) (integrable_const (a * b))
_ = ∫ ω, - X ω ^ 2 + (a + b) * X ω ∂μ - a * b := by simp
_ = - μ[X ^ 2] + (a + b) * μ[X] - a * b := by
simp [← integral_neg, ← integral_const_mul, integral_add hX_int₂ hX_int₁]
calc
_ ≤ (a + b) * μ[X] - a * b - μ[X] ^ 2 := by
rw [variance_eq_sub (memLp_of_bounded h hX.aestronglyMeasurable 2)]
linarith
_ = (b - μ[X]) * (μ[X] - a) := by ring
/-- **Popoviciu's inequality on variances**
The variance of a random variable `X` satisfying `a ≤ X ≤ b` almost everywhere is at most
`((b - a) / 2) ^ 2`. -/
lemma variance_le_sq_of_bounded [IsProbabilityMeasure μ] {a b : ℝ} {X : Ω → ℝ}
(h : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) (hX : AEMeasurable X μ) :
variance X μ ≤ ((b - a) / 2) ^ 2 :=
calc
_ ≤ (b - μ[X]) * (μ[X] - a) := variance_le_sub_mul_sub h hX
_ = ((b - a) / 2) ^ 2 - (μ[X] - (b + a) / 2) ^ 2 := by ring
_ ≤ ((b - a) / 2) ^ 2 := sub_le_self _ (sq_nonneg _)
section Prod
variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {ν : Measure Ω'}
[IsProbabilityMeasure μ] [IsProbabilityMeasure ν]
{X : Ω → ℝ} {Y : Ω' → ℝ}
lemma variance_add_prod (hfμ : MemLp X 2 μ) (hgν : MemLp Y 2 ν) :
Var[fun p ↦ X p.1 + Y p.2; μ.prod ν] = Var[X; μ] + Var[Y; ν] := by
refine (IndepFun.variance_fun_add (hfμ.comp_fst ν) (hgν.comp_snd μ) ?_).trans ?_
· exact indepFun_prod₀ hfμ.aemeasurable hgν.aemeasurable
· rw [measurePreserving_fst.variance_fun_comp hfμ.aemeasurable,
measurePreserving_snd.variance_fun_comp hgν.aemeasurable]
end Prod
section NormedSpace
variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {mE : MeasurableSpace E}
[NormedAddCommGroup F] [NormedSpace ℝ F] {mF : MeasurableSpace F}
{μ : Measure E} [IsProbabilityMeasure μ] {ν : Measure F} [IsProbabilityMeasure ν]
lemma variance_dual_prod' {L : StrongDual ℝ (E × F)}
(hLμ : MemLp (L.comp (.inl ℝ E F)) 2 μ) (hLν : MemLp (L.comp (.inr ℝ E F)) 2 ν) :
Var[L; μ.prod ν] = Var[L.comp (.inl ℝ E F); μ] + Var[L.comp (.inr ℝ E F); ν] := by
have : L = fun x : E × F ↦ L.comp (.inl ℝ E F) x.1 + L.comp (.inr ℝ E F) x.2 := by
ext; rw [L.comp_inl_add_comp_inr]
rw [this, variance_add_prod hLμ hLν]
lemma variance_dual_prod {L : StrongDual ℝ (E × F)} (hLμ : MemLp id 2 μ) (hLν : MemLp id 2 ν) :
Var[L; μ.prod ν] = Var[L.comp (.inl ℝ E F); μ] + Var[L.comp (.inr ℝ E F); ν] :=
variance_dual_prod' (ContinuousLinearMap.comp_memLp' _ hLμ)
(ContinuousLinearMap.comp_memLp' _ hLν)
end NormedSpace
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/MGFAnalytic.lean | import Mathlib.Probability.Moments.ComplexMGF
import Mathlib.Analysis.SpecialFunctions.Complex.Analytic
import Mathlib.Analysis.Calculus.Taylor
/-!
# The moment-generating function is analytic
The moment-generating function `mgf X μ` of a random variable `X` with respect to a measure `μ`
is analytic on the interior of `integrableExpSet X μ`, the interval on which it is defined.
## Main results
* `analyticOn_mgf`: the moment-generating function is analytic on the interior of the interval
on which it is defined.
* `iteratedDeriv_mgf`: the n-th derivative of the mgf at `t` is `μ[X ^ n * exp (t * X)]`.
* `analyticOn_cgf`: the cumulant-generating function is analytic on the interior of the interval
`integrableExpSet X μ`.
-/
open MeasureTheory Filter Finset Real
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal Topology Nat
namespace ProbabilityTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} {t u v : ℝ}
/-- For `t : ℝ` with `t ∈ interior (integrableExpSet X μ)`, the derivative of the function
`x ↦ μ[X ^ n * exp (x * X)]` at `t` is `μ[X ^ (n + 1) * exp (t * X)]`. -/
lemma hasDerivAt_integral_pow_mul_exp_real (ht : t ∈ interior (integrableExpSet X μ)) (n : ℕ) :
HasDerivAt (fun t ↦ μ[fun ω ↦ X ω ^ n * exp (t * X ω)])
μ[fun ω ↦ X ω ^ (n + 1) * exp (t * X ω)] t := by
have h_re_of_mem n t (ht' : t ∈ interior (integrableExpSet X μ)) :
(∫ ω, X ω ^ n * Complex.exp (t * X ω) ∂μ).re = ∫ ω, X ω ^ n * exp (t * X ω) ∂μ := by
rw [← RCLike.re_eq_complex_re, ← integral_re]
· norm_cast
· refine integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet ?_ n
simpa using ht'
have h_re n : ∀ᶠ t' : ℝ in 𝓝 t, (∫ ω, X ω ^ n * Complex.exp (t' * X ω) ∂μ).re
= ∫ ω, X ω ^ n * exp (t' * X ω) ∂μ := by
filter_upwards [isOpen_interior.eventually_mem ht] with t ht' using h_re_of_mem n t ht'
rw [← EventuallyEq.hasDerivAt_iff (h_re _), ← h_re_of_mem _ t ht]
exact (hasDerivAt_integral_pow_mul_exp (by simp [ht]) n).real_of_complex
section DerivMGF
/-- For `t ∈ interior (integrableExpSet X μ)`, the derivative of `mgf X μ` at `t` is
`μ[X * exp (t * X)]`. -/
lemma hasDerivAt_mgf (h : t ∈ interior (integrableExpSet X μ)) :
HasDerivAt (mgf X μ) (μ[fun ω ↦ X ω * exp (t * X ω)]) t := by
convert hasDerivAt_integral_pow_mul_exp_real h 0
· simp [mgf]
· simp
lemma hasDerivAt_iteratedDeriv_mgf (ht : t ∈ interior (integrableExpSet X μ)) (n : ℕ) :
HasDerivAt (iteratedDeriv n (mgf X μ)) μ[fun ω ↦ X ω ^ (n + 1) * exp (t * X ω)] t := by
induction n generalizing t with
| zero => simp [hasDerivAt_mgf ht]
| succ n hn =>
rw [iteratedDeriv_succ]
have : deriv (iteratedDeriv n (mgf X μ))
=ᶠ[𝓝 t] fun t ↦ μ[fun ω ↦ X ω ^ (n + 1) * exp (t * X ω)] := by
have h_mem : ∀ᶠ y in 𝓝 t, y ∈ interior (integrableExpSet X μ) :=
isOpen_interior.eventually_mem ht
filter_upwards [h_mem] with y hy using HasDerivAt.deriv (hn hy)
rw [EventuallyEq.hasDerivAt_iff this]
exact hasDerivAt_integral_pow_mul_exp_real ht (n + 1)
/-- For `t ∈ interior (integrableExpSet X μ)`, the n-th derivative of `mgf X μ` at `t` is
`μ[X ^ n * exp (t * X)]`. -/
lemma iteratedDeriv_mgf (ht : t ∈ interior (integrableExpSet X μ)) (n : ℕ) :
iteratedDeriv n (mgf X μ) t = μ[fun ω ↦ X ω ^ n * exp (t * X ω)] := by
induction n generalizing t with
| zero => simp [mgf]
| succ n hn =>
rw [iteratedDeriv_succ]
exact (hasDerivAt_iteratedDeriv_mgf ht n).deriv
/-- The derivatives of the moment-generating function at zero are the moments. -/
lemma iteratedDeriv_mgf_zero (h : 0 ∈ interior (integrableExpSet X μ)) (n : ℕ) :
iteratedDeriv n (mgf X μ) 0 = μ[X ^ n] := by
simp [iteratedDeriv_mgf h n]
/-- For `t ∈ interior (integrableExpSet X μ)`, the derivative of `mgf X μ` at `t` is
`μ[X * exp (t * X)]`. -/
lemma deriv_mgf (h : t ∈ interior (integrableExpSet X μ)) :
deriv (mgf X μ) t = μ[fun ω ↦ X ω * exp (t * X ω)] :=
(hasDerivAt_mgf h).deriv
lemma deriv_mgf_zero (h : 0 ∈ interior (integrableExpSet X μ)) : deriv (mgf X μ) 0 = μ[X] := by
simp [deriv_mgf h]
end DerivMGF
section AnalyticMGF
/-- The moment-generating function is analytic at every `t ∈ interior (integrableExpSet X μ)`. -/
lemma analyticAt_mgf (ht : t ∈ interior (integrableExpSet X μ)) :
AnalyticAt ℝ (mgf X μ) t := by
rw [← re_complexMGF_ofReal']
exact (analyticAt_complexMGF (by simp [ht])).re_ofReal
lemma analyticOnNhd_mgf : AnalyticOnNhd ℝ (mgf X μ) (interior (integrableExpSet X μ)) :=
fun _ hx ↦ analyticAt_mgf hx
/-- The moment-generating function is analytic on the interior of the interval on which it is
defined. -/
lemma analyticOn_mgf : AnalyticOn ℝ (mgf X μ) (interior (integrableExpSet X μ)) :=
analyticOnNhd_mgf.analyticOn
lemma hasFPowerSeriesAt_mgf (hv : v ∈ interior (integrableExpSet X μ)) :
HasFPowerSeriesAt (mgf X μ)
(FormalMultilinearSeries.ofScalars ℝ
(fun n ↦ (μ[fun ω ↦ X ω ^ n * exp (v * X ω)] : ℝ) / n !)) v := by
convert (analyticAt_mgf hv).hasFPowerSeriesAt
rw [iteratedDeriv_mgf hv]
lemma differentiableAt_mgf (ht : t ∈ interior (integrableExpSet X μ)) :
DifferentiableAt ℝ (mgf X μ) t := (analyticAt_mgf ht).differentiableAt
lemma differentiableOn_mgf : DifferentiableOn ℝ (mgf X μ) (interior (integrableExpSet X μ)) :=
fun _ hx ↦ (differentiableAt_mgf hx).differentiableWithinAt
-- todo: this should be extended to `integrableExpSet X μ`, not only its interior
lemma continuousOn_mgf : ContinuousOn (mgf X μ) (interior (integrableExpSet X μ)) :=
differentiableOn_mgf.continuousOn
lemma continuous_mgf (h : ∀ t, Integrable (fun ω ↦ exp (t * X ω)) μ) :
Continuous (mgf X μ) := by
rw [← continuousOn_univ]
convert continuousOn_mgf
symm
rw [interior_eq_univ]
ext t
simpa using h t
lemma analyticOnNhd_iteratedDeriv_mgf (n : ℕ) :
AnalyticOnNhd ℝ (iteratedDeriv n (mgf X μ)) (interior (integrableExpSet X μ)) := by
rw [iteratedDeriv_eq_iterate]
exact analyticOnNhd_mgf.iterated_deriv n
lemma analyticOn_iteratedDeriv_mgf (n : ℕ) :
AnalyticOn ℝ (iteratedDeriv n (mgf X μ)) (interior (integrableExpSet X μ)) :=
(analyticOnNhd_iteratedDeriv_mgf n).analyticOn
lemma analyticAt_iteratedDeriv_mgf (hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
AnalyticAt ℝ (iteratedDeriv n (mgf X μ)) v :=
analyticOnNhd_iteratedDeriv_mgf n v hv
lemma differentiableAt_iteratedDeriv_mgf (hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
DifferentiableAt ℝ (iteratedDeriv n (mgf X μ)) v :=
(analyticAt_iteratedDeriv_mgf hv n).differentiableAt
end AnalyticMGF
section AnalyticCGF
lemma analyticAt_cgf (h : v ∈ interior (integrableExpSet X μ)) : AnalyticAt ℝ (cgf X μ) v := by
by_cases hμ : μ = 0
· simp only [hμ, cgf_zero_measure]
exact analyticAt_const
· exact (analyticAt_mgf h).log <| mgf_pos' hμ (interior_subset (s := integrableExpSet X μ) h)
lemma analyticOnNhd_cgf : AnalyticOnNhd ℝ (cgf X μ) (interior (integrableExpSet X μ)) :=
fun _ hx ↦ analyticAt_cgf hx
/-- The cumulant-generating function is analytic on the interior of the interval
`integrableExpSet X μ`. -/
lemma analyticOn_cgf : AnalyticOn ℝ (cgf X μ) (interior (integrableExpSet X μ)) :=
analyticOnNhd_cgf.analyticOn
end AnalyticCGF
section DerivCGF
lemma deriv_cgf (h : v ∈ interior (integrableExpSet X μ)) :
deriv (cgf X μ) v = μ[fun ω ↦ X ω * exp (v * X ω)] / mgf X μ v := by
by_cases hμ : μ = 0
· simp only [hμ, cgf_zero_measure, integral_zero_measure, mgf_zero_measure, div_zero,
Pi.zero_apply]
exact deriv_const v 0
have hv : Integrable (fun ω ↦ exp (v * X ω)) μ := interior_subset (s := integrableExpSet X μ) h
calc deriv (fun x ↦ log (mgf X μ x)) v
_ = deriv (mgf X μ) v / mgf X μ v := by
rw [deriv.log (differentiableAt_mgf h) ((mgf_pos' hμ hv).ne')]
_ = μ[fun ω ↦ X ω * exp (v * X ω)] / mgf X μ v := by rw [deriv_mgf h]
lemma deriv_cgf_zero (h : 0 ∈ interior (integrableExpSet X μ)) :
deriv (cgf X μ) 0 = μ[X] / μ.real Set.univ := by simp [deriv_cgf h]
lemma iteratedDeriv_two_cgf (h : v ∈ interior (integrableExpSet X μ)) :
iteratedDeriv 2 (cgf X μ) v
= μ[fun ω ↦ (X ω) ^ 2 * exp (v * X ω)] / mgf X μ v - deriv (cgf X μ) v ^ 2 := by
rw [iteratedDeriv_succ, iteratedDeriv_one]
by_cases hμ : μ = 0
· simp [hμ]
have h_mem : ∀ᶠ y in 𝓝 v, y ∈ interior (integrableExpSet X μ) :=
isOpen_interior.eventually_mem h
have h_d_cgf : deriv (cgf X μ) =ᶠ[𝓝 v] fun u ↦ μ[fun ω ↦ X ω * exp (u * X ω)] / mgf X μ u := by
filter_upwards [h_mem] with u hu using deriv_cgf hu
have h_d_mgf : deriv (mgf X μ) =ᶠ[𝓝 v] fun u ↦ μ[fun ω ↦ X ω * exp (u * X ω)] := by
filter_upwards [h_mem] with u hu using deriv_mgf hu
rw [h_d_cgf.deriv_eq]
calc deriv (fun u ↦ (∫ ω, X ω * exp (u * X ω) ∂μ) / mgf X μ u) v
_ = (deriv (fun u ↦ ∫ ω, X ω * exp (u * X ω) ∂μ) v * mgf X μ v -
(∫ ω, X ω * exp (v * X ω) ∂μ) * deriv (mgf X μ) v) / mgf X μ v ^ 2 := by
rw [deriv_fun_div]
· rw [h_d_mgf.symm.differentiableAt_iff, ← iteratedDeriv_one]
exact differentiableAt_iteratedDeriv_mgf h 1
· exact differentiableAt_mgf h
· exact (mgf_pos' hμ (interior_subset (s := integrableExpSet X μ) h)).ne'
_ = (deriv (fun u ↦ ∫ ω, X ω * exp (u * X ω) ∂μ) v * mgf X μ v -
(∫ ω, X ω * exp (v * X ω) ∂μ) * ∫ ω, X ω * exp (v * X ω) ∂μ) / mgf X μ v ^ 2 := by
rw [deriv_mgf h]
_ = deriv (fun u ↦ ∫ ω, X ω * exp (u * X ω) ∂μ) v / mgf X μ v - deriv (cgf X μ) v ^ 2 := by
rw [sub_div]
congr 1
· rw [pow_two, div_mul_eq_div_div, mul_div_assoc, div_self, mul_one]
exact (mgf_pos' hμ (interior_subset (s := integrableExpSet X μ) h)).ne'
· rw [deriv_cgf h]
ring
_ = (∫ ω, (X ω) ^ 2 * exp (v * X ω) ∂μ) / mgf X μ v - deriv (cgf X μ) v ^ 2 := by
congr
convert (hasDerivAt_integral_pow_mul_exp_real h 1).deriv using 1
simp
lemma iteratedDeriv_two_cgf_eq_integral (h : v ∈ interior (integrableExpSet X μ)) :
iteratedDeriv 2 (cgf X μ) v
= μ[fun ω ↦ (X ω - deriv (cgf X μ) v) ^ 2 * exp (v * X ω)] / mgf X μ v := by
by_cases hμ : μ = 0
· simp [hμ, iteratedDeriv_succ]
rw [iteratedDeriv_two_cgf h]
calc (∫ ω, (X ω) ^ 2 * exp (v * X ω) ∂μ) / mgf X μ v - deriv (cgf X μ) v ^ 2
_ = (∫ ω, (X ω) ^ 2 * exp (v * X ω) ∂μ - 2 * (∫ ω, X ω * exp (v * X ω) ∂μ) * deriv (cgf X μ) v
+ deriv (cgf X μ) v ^ 2 * mgf X μ v) / mgf X μ v := by
rw [add_div, sub_div, sub_add]
congr 1
rw [mul_div_cancel_right₀, deriv_cgf h]
· ring
· exact (mgf_pos' hμ (interior_subset (s := integrableExpSet X μ) h)).ne'
_ = (∫ ω, ((X ω) ^ 2 - 2 * X ω * deriv (cgf X μ) v + deriv (cgf X μ) v ^ 2) * exp (v * X ω) ∂μ)
/ mgf X μ v := by
congr 1
simp_rw [add_mul, sub_mul]
have h_int : Integrable (fun ω ↦ 2 * X ω * deriv (cgf X μ) v * exp (v * X ω)) μ := by
simp_rw [mul_assoc, mul_comm (deriv (cgf X μ) v)]
refine Integrable.const_mul ?_ _
simp_rw [← mul_assoc]
refine Integrable.mul_const ?_ _
convert integrable_pow_mul_exp_of_mem_interior_integrableExpSet h 1
simp
rw [integral_add]
rotate_left
· exact (integrable_pow_mul_exp_of_mem_interior_integrableExpSet h 2).sub h_int
· exact (interior_subset (s := integrableExpSet X μ) h).const_mul _
rw [integral_sub (integrable_pow_mul_exp_of_mem_interior_integrableExpSet h 2) h_int]
congr
· rw [← integral_const_mul, ← integral_mul_const]
congr with ω
ring
· rw [integral_const_mul, mgf]
_ = (∫ ω, (X ω - deriv (cgf X μ) v) ^ 2 * exp (v * X ω) ∂μ) / mgf X μ v := by
congr with ω
ring
lemma exists_cgf_eq_iteratedDeriv_two_cgf_mul [IsZeroOrProbabilityMeasure μ] (ht : 0 < t)
(hc : μ[X] = 0) (hs : Set.Icc 0 t ⊆ interior (integrableExpSet X μ)) :
∃ u ∈ Set.Ioo 0 t, cgf X μ t = (iteratedDeriv 2 (cgf X μ) u) * t ^ 2 / 2 := by
have hu : UniqueDiffOn ℝ (Set.Icc 0 t) := uniqueDiffOn_Icc ht
rw [← sub_zero (cgf X μ t)]
nth_rw 3 [← sub_zero t]
convert taylor_mean_remainder_lagrange_iteratedDeriv ht ((analyticOn_cgf.mono hs).contDiffOn hu)
have hd : derivWithin (cgf X μ) (Set.Icc 0 t) 0 = 0 := by
convert (analyticAt_cgf (hs ⟨le_refl 0, le_of_lt ht⟩)).differentiableAt.derivWithin _
· simpa [hc] using (deriv_cgf_zero (hs ⟨le_refl 0, le_of_lt ht⟩)).symm
· exact hu 0 ⟨le_refl 0, le_of_lt ht⟩
simp [hd]
end DerivCGF
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/Basic.lean | import Mathlib.Probability.IdentDistrib
/-!
# Moments and moment-generating function
## Main definitions
* `ProbabilityTheory.moment X p μ`: `p`th moment of a real random variable `X` with respect to
measure `μ`, `μ[X^p]`
* `ProbabilityTheory.centralMoment X p μ`:`p`th central moment of `X` with respect to measure `μ`,
`μ[(X - μ[X])^p]`
* `ProbabilityTheory.mgf X μ t`: moment-generating function of `X` with respect to measure `μ`,
`μ[exp(t*X)]`
* `ProbabilityTheory.cgf X μ t`: cumulant-generating function, logarithm of the moment-generating
function
## Main results
* `ProbabilityTheory.IndepFun.mgf_add`: if two real random variables `X` and `Y` are independent
and their moment-generating functions are defined at `t`, then
`mgf (X + Y) μ t = mgf X μ t * mgf Y μ t`
* `ProbabilityTheory.IndepFun.cgf_add`: if two real random variables `X` and `Y` are independent
and their cumulant-generating functions are defined at `t`, then
`cgf (X + Y) μ t = cgf X μ t + cgf Y μ t`
* `ProbabilityTheory.measure_ge_le_exp_cgf` and `ProbabilityTheory.measure_le_le_exp_cgf`:
Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that
the cumulant-generating function exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also
`ProbabilityTheory.measure_ge_le_exp_mul_mgf` and
`ProbabilityTheory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead
of `cgf`.
-/
open MeasureTheory Filter Finset Real
noncomputable section
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal
namespace ProbabilityTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {p : ℕ} {μ : Measure Ω}
/-- Moment of a real random variable, `μ[X ^ p]`. -/
def moment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ :=
μ[X ^ p]
lemma moment_def (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) :
moment X p μ = μ[X ^ p] := rfl
/-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/
def centralMoment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ :=
μ[(X - fun (_ : Ω) => μ[X]) ^ p]
@[simp]
theorem moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 := by
simp only [moment, hp, zero_pow, Ne, not_false_iff, Pi.zero_apply, integral_const,
smul_eq_mul, mul_zero]
@[simp]
lemma moment_zero_measure : moment X p (0 : Measure Ω) = 0 := by simp [moment]
@[simp]
theorem centralMoment_zero (hp : p ≠ 0) : centralMoment 0 p μ = 0 := by
simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul,
mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow, Ne, not_false_iff]
lemma moment_one (X : Ω → ℝ) (μ : Measure Ω) :
moment X 1 μ = μ[X] := by simp [moment]
@[simp]
lemma centralMoment_zero_measure : centralMoment X p (0 : Measure Ω) = 0 := by
simp [centralMoment]
theorem centralMoment_one' [IsFiniteMeasure μ] (h_int : Integrable X μ) :
centralMoment X 1 μ = (1 - μ.real Set.univ) * μ[X] := by
simp only [centralMoment, Pi.sub_apply, pow_one]
rw [integral_sub h_int (integrable_const _)]
simp only [sub_mul, integral_const, smul_eq_mul, one_mul]
@[simp]
theorem centralMoment_one [IsZeroOrProbabilityMeasure μ] : centralMoment X 1 μ = 0 := by
rcases eq_zero_or_isProbabilityMeasure μ with rfl | h
· simp [centralMoment]
by_cases h_int : Integrable X μ
· rw [centralMoment_one' h_int]
simp
· simp only [centralMoment, Pi.sub_apply, pow_one]
have : ¬Integrable (fun x => X x - integral μ X) μ := by
refine fun h_sub => h_int ?_
have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp
rw [h_add]
fun_prop
rw [integral_undef this]
lemma centralMoment_two_eq_variance (hX : AEMeasurable X μ) : centralMoment X 2 μ = variance X μ :=
(variance_eq_integral hX).symm
section MomentGeneratingFunction
variable {t : ℝ}
/-- Moment-generating function of a real random variable `X`: `fun t => μ[exp(t*X)]`. -/
def mgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ :=
μ[fun ω => exp (t * X ω)]
/-- Cumulant-generating function of a real random variable `X`: `fun t => log μ[exp(t*X)]`. -/
def cgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ :=
log (mgf X μ t)
@[simp]
theorem mgf_zero_fun : mgf 0 μ t = μ.real Set.univ := by
simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one]
@[simp]
theorem cgf_zero_fun : cgf 0 μ t = log (μ.real Set.univ) := by simp only [cgf, mgf_zero_fun]
@[simp]
theorem mgf_zero_measure : mgf X (0 : Measure Ω) = 0 := by ext; simp [mgf]
@[simp]
theorem cgf_zero_measure : cgf X (0 : Measure Ω) = 0 := by ext; simp [cgf]
@[simp]
theorem mgf_const' (c : ℝ) : mgf (fun _ => c) μ t = μ.real Set.univ * exp (t * c) := by
simp only [mgf, integral_const, smul_eq_mul]
theorem mgf_const (c : ℝ) [IsProbabilityMeasure μ] : mgf (fun _ => c) μ t = exp (t * c) := by
simp
@[simp]
theorem cgf_const' [IsFiniteMeasure μ] (hμ : μ ≠ 0) (c : ℝ) :
cgf (fun _ => c) μ t = log (μ.real Set.univ) + t * c := by
simp only [cgf, mgf_const']
rw [log_mul _ (exp_pos _).ne']
· rw [log_exp _]
· rw [Ne, measureReal_eq_zero_iff, Measure.measure_univ_eq_zero]
simp only [hμ, not_false_iff]
@[simp]
theorem cgf_const [IsProbabilityMeasure μ] (c : ℝ) : cgf (fun _ => c) μ t = t * c := by
simp only [cgf, mgf_const, log_exp]
@[simp]
theorem mgf_zero' : mgf X μ 0 = μ.real Set.univ := by
simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one]
theorem mgf_zero [IsProbabilityMeasure μ] : mgf X μ 0 = 1 := by
simp [mgf_zero']
theorem cgf_zero' : cgf X μ 0 = log (μ.real Set.univ) := by simp only [cgf, mgf_zero']
@[simp]
theorem cgf_zero [IsZeroOrProbabilityMeasure μ] : cgf X μ 0 = 0 := by
rcases eq_zero_or_isProbabilityMeasure μ with rfl | h <;> simp [cgf_zero']
theorem mgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : mgf X μ t = 0 := by
simp only [mgf, integral_undef hX]
theorem cgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : cgf X μ t = 0 := by
simp only [cgf, mgf_undef hX, log_zero]
theorem mgf_nonneg : 0 ≤ mgf X μ t := by
unfold mgf; positivity
theorem mgf_pos' (hμ : μ ≠ 0) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) :
0 < mgf X μ t := by
simp_rw [mgf]
have : ∫ x : Ω, exp (t * X x) ∂μ = ∫ x : Ω in Set.univ, exp (t * X x) ∂μ := by
simp only [Measure.restrict_univ]
rw [this, setIntegral_pos_iff_support_of_nonneg_ae _ _]
· have h_eq_univ : (Function.support fun x : Ω => exp (t * X x)) = Set.univ := by
ext1 x
simp only [Function.mem_support, Set.mem_univ, iff_true]
exact (exp_pos _).ne'
rw [h_eq_univ, Set.inter_univ _]
refine Ne.bot_lt ?_
simp only [hμ, ENNReal.bot_eq_zero, Ne, Measure.measure_univ_eq_zero, not_false_iff]
· filter_upwards with x
rw [Pi.zero_apply]
exact (exp_pos _).le
· rwa [integrableOn_univ]
theorem mgf_pos [IsProbabilityMeasure μ] (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) :
0 < mgf X μ t :=
mgf_pos' (IsProbabilityMeasure.ne_zero μ) h_int_X
lemma mgf_pos_iff [hμ : NeZero μ] :
0 < mgf X μ t ↔ Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine ⟨fun h ↦ ?_, fun h ↦ mgf_pos' hμ.out h⟩
contrapose! h with h
simp [mgf_undef h]
lemma exp_cgf [hμ : NeZero μ] (hX : Integrable (fun ω ↦ exp (t * X ω)) μ) :
exp (cgf X μ t) = mgf X μ t := by rw [cgf, exp_log (mgf_pos' hμ.out hX)]
lemma mgf_map {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'} {Y : Ω' → Ω} {X : Ω → ℝ}
(hY : AEMeasurable Y μ) {t : ℝ} (hX : AEStronglyMeasurable (fun ω ↦ exp (t * X ω)) (μ.map Y)) :
mgf X (μ.map Y) t = mgf (X ∘ Y) μ t := by
simp_rw [mgf, integral_map hY hX, Function.comp_apply]
lemma mgf_id_map (hX : AEMeasurable X μ) : mgf id (μ.map X) = mgf X μ := by
ext t
rw [mgf_map hX, Function.id_comp]
exact (measurable_const_mul _).exp.aestronglyMeasurable
lemma mgf_congr {Y : Ω → ℝ} (h : X =ᵐ[μ] Y) : mgf X μ t = mgf Y μ t :=
integral_congr_ae <| by filter_upwards [h] with ω hω using by rw [hω]
lemma mgf_congr_identDistrib {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ' : Measure Ω'}
{Y : Ω' → ℝ} (h : IdentDistrib X Y μ μ') :
mgf X μ = mgf Y μ' := by
rw [← mgf_id_map h.aemeasurable_fst, ← mgf_id_map h.aemeasurable_snd, h.map_eq]
theorem mgf_neg : mgf (-X) μ t = mgf X μ (-t) := by simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul]
theorem cgf_neg : cgf (-X) μ t = cgf X μ (-t) := by simp_rw [cgf, mgf_neg]
theorem mgf_smul_left (α : ℝ) : mgf (α • X) μ t = mgf X μ (α * t) := by
simp_rw [mgf, Pi.smul_apply, smul_eq_mul, mul_comm α t, mul_assoc]
theorem mgf_const_add (α : ℝ) : mgf (fun ω => α + X ω) μ t = exp (t * α) * mgf X μ t := by
rw [mgf, mgf, ← integral_const_mul]
congr with x
dsimp
rw [mul_add, exp_add]
theorem mgf_add_const (α : ℝ) : mgf (fun ω => X ω + α) μ t = mgf X μ t * exp (t * α) := by
simp only [add_comm, mgf_const_add, mul_comm]
lemma mgf_add_measure {ν : Measure Ω}
(hμ : Integrable (fun ω ↦ exp (t * X ω)) μ) (hν : Integrable (fun ω ↦ exp (t * X ω)) ν) :
mgf X (μ + ν) t = mgf X μ t + mgf X ν t := by
rw [mgf, integral_add_measure hμ hν, mgf, mgf]
lemma mgf_sum_measure {ι : Type*} {μ : ι → Measure Ω}
(hμ : Integrable (fun ω ↦ exp (t * X ω)) (Measure.sum μ)) :
mgf X (Measure.sum μ) t = ∑' i, mgf X (μ i) t := by
simp_rw [mgf, integral_sum_measure hμ]
lemma mgf_smul_measure (c : ℝ≥0∞) : mgf X (c • μ) t = c.toReal * mgf X μ t := by
rw [mgf, integral_smul_measure, mgf, smul_eq_mul]
/-- The moment-generating function is monotone in the random variable for `t ≥ 0`. -/
lemma mgf_mono_of_nonneg {Y : Ω → ℝ} (hXY : X ≤ᵐ[μ] Y) (ht : 0 ≤ t)
(htY : Integrable (fun ω ↦ exp (t * Y ω)) μ) :
mgf X μ t ≤ mgf Y μ t := by
by_cases htX : Integrable (fun ω ↦ exp (t * X ω)) μ
· refine integral_mono_ae htX htY ?_
filter_upwards [hXY] with ω hω using by gcongr
· rw [mgf_undef htX]
exact mgf_nonneg
/-- The moment-generating function is antitone in the random variable for `t ≤ 0`. -/
lemma mgf_anti_of_nonpos {Y : Ω → ℝ} (hXY : X ≤ᵐ[μ] Y) (ht : t ≤ 0)
(htX : Integrable (fun ω ↦ exp (t * X ω)) μ) :
mgf Y μ t ≤ mgf X μ t := by
by_cases htY : Integrable (fun ω ↦ exp (t * Y ω)) μ
· refine integral_mono_ae htY htX ?_
filter_upwards [hXY] with ω hω using exp_monotone <| mul_le_mul_of_nonpos_left hω ht
· rw [mgf_undef htY]
exact mgf_nonneg
section IndepFun
/-- This is a trivial application of `IndepFun.comp` but it will come up frequently. -/
theorem IndepFun.exp_mul {X Y : Ω → ℝ} (h_indep : X ⟂ᵢ[μ] Y) (s t : ℝ) :
(fun ω => exp (s * X ω)) ⟂ᵢ[μ] (fun ω => exp (t * Y ω)) := by
have h_meas : ∀ t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp
change IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y) μ
exact IndepFun.comp h_indep (h_meas s) (h_meas t)
theorem IndepFun.mgf_add {X Y : Ω → ℝ} (h_indep : X ⟂ᵢ[μ] Y)
(hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ)
(hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) :
mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by
simp_rw [mgf, Pi.add_apply, mul_add, exp_add]
exact (h_indep.exp_mul t t).integral_mul_eq_mul_integral hX hY
theorem IndepFun.mgf_add' {X Y : Ω → ℝ} (h_indep : X ⟂ᵢ[μ] Y) (hX : AEStronglyMeasurable X μ)
(hY : AEStronglyMeasurable Y μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by
have A : Continuous fun x : ℝ => exp (t * x) := by fun_prop
have h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ :=
A.aestronglyMeasurable.comp_aemeasurable hX.aemeasurable
have h'Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ :=
A.aestronglyMeasurable.comp_aemeasurable hY.aemeasurable
exact h_indep.mgf_add h'X h'Y
theorem IndepFun.cgf_add {X Y : Ω → ℝ} (h_indep : X ⟂ᵢ[μ] Y)
(h_int_X : Integrable (fun ω => exp (t * X ω)) μ)
(h_int_Y : Integrable (fun ω => exp (t * Y ω)) μ) :
cgf (X + Y) μ t = cgf X μ t + cgf Y μ t := by
by_cases hμ : μ = 0
· simp [hμ]
simp only [cgf, h_indep.mgf_add h_int_X.aestronglyMeasurable h_int_Y.aestronglyMeasurable]
exact log_mul (mgf_pos' hμ h_int_X).ne' (mgf_pos' hμ h_int_Y).ne'
theorem aestronglyMeasurable_exp_mul_add {X Y : Ω → ℝ}
(h_int_X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ)
(h_int_Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) :
AEStronglyMeasurable (fun ω => exp (t * (X + Y) ω)) μ := by
simp_rw [Pi.add_apply, mul_add, exp_add]
exact AEStronglyMeasurable.mul h_int_X h_int_Y
theorem aestronglyMeasurable_exp_mul_sum {X : ι → Ω → ℝ} {s : Finset ι}
(h_int : ∀ i ∈ s, AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ) :
AEStronglyMeasurable (fun ω => exp (t * (∑ i ∈ s, X i) ω)) μ := by
classical
induction s using Finset.induction_on with
| empty =>
simp only [sum_apply, sum_empty, mul_zero, exp_zero]
exact aestronglyMeasurable_const
| insert i s hi_notin_s h_rec =>
have : ∀ i : ι, i ∈ s → AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi =>
h_int i (mem_insert_of_mem hi)
specialize h_rec this
rw [sum_insert hi_notin_s]
apply aestronglyMeasurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec
theorem IndepFun.integrable_exp_mul_add {X Y : Ω → ℝ} (h_indep : X ⟂ᵢ[μ] Y)
(h_int_X : Integrable (fun ω => exp (t * X ω)) μ)
(h_int_Y : Integrable (fun ω => exp (t * Y ω)) μ) :
Integrable (fun ω => exp (t * (X + Y) ω)) μ := by
simp_rw [Pi.add_apply, mul_add, exp_add]
exact (h_indep.exp_mul t t).integrable_mul h_int_X h_int_Y
theorem iIndepFun.integrable_exp_mul_sum [IsFiniteMeasure μ] {X : ι → Ω → ℝ}
(h_indep : iIndepFun X μ) (h_meas : ∀ i, Measurable (X i))
{s : Finset ι} (h_int : ∀ i ∈ s, Integrable (fun ω => exp (t * X i ω)) μ) :
Integrable (fun ω => exp (t * (∑ i ∈ s, X i) ω)) μ := by
classical
induction s using Finset.induction_on with
| empty =>
simp only [sum_apply, sum_empty, mul_zero, exp_zero]
exact integrable_const _
| insert i s hi_notin_s h_rec =>
have : ∀ i : ι, i ∈ s → Integrable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi =>
h_int i (mem_insert_of_mem hi)
specialize h_rec this
rw [sum_insert hi_notin_s]
refine IndepFun.integrable_exp_mul_add ?_ (h_int i (mem_insert_self _ _)) h_rec
exact (h_indep.indepFun_finset_sum_of_notMem h_meas hi_notin_s).symm
-- TODO(vilin97): weaken `h_meas` to `AEMeasurable (X i)` or `AEStronglyMeasurable (X i)` throughout
-- https://github.com/leanprover-community/mathlib4/issues/20367
theorem iIndepFun.mgf_sum {X : ι → Ω → ℝ}
(h_indep : iIndepFun X μ) (h_meas : ∀ i, Measurable (X i))
(s : Finset ι) : mgf (∑ i ∈ s, X i) μ t = ∏ i ∈ s, mgf (X i) μ t := by
have : IsProbabilityMeasure μ := h_indep.isProbabilityMeasure
classical
induction s using Finset.induction_on with
| empty => simp
| insert i s hi_notin_s h_rec =>
have h_int' : ∀ i : ι, AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i =>
((h_meas i).const_mul t).exp.aestronglyMeasurable
rw [sum_insert hi_notin_s,
IndepFun.mgf_add (h_indep.indepFun_finset_sum_of_notMem h_meas hi_notin_s).symm (h_int' i)
(aestronglyMeasurable_exp_mul_sum fun i _ => h_int' i),
h_rec, prod_insert hi_notin_s]
theorem iIndepFun.cgf_sum {X : ι → Ω → ℝ}
(h_indep : iIndepFun X μ) (h_meas : ∀ i, Measurable (X i))
{s : Finset ι} (h_int : ∀ i ∈ s, Integrable (fun ω => exp (t * X i ω)) μ) :
cgf (∑ i ∈ s, X i) μ t = ∑ i ∈ s, cgf (X i) μ t := by
have : IsProbabilityMeasure μ := h_indep.isProbabilityMeasure
simp_rw [cgf]
rw [← log_prod fun j hj => ?_]
· rw [h_indep.mgf_sum h_meas]
· exact (mgf_pos (h_int j hj)).ne'
end IndepFun
theorem mgf_congr_of_identDistrib
(X : Ω → ℝ) {Ω' : Type*} {m' : MeasurableSpace Ω'} {μ' : Measure Ω'} (X' : Ω' → ℝ)
(hident : IdentDistrib X X' μ μ') (t : ℝ) :
mgf X μ t = mgf X' μ' t := hident.comp (measurable_const_mul t).exp |>.integral_eq
theorem mgf_sum_of_identDistrib
{X : ι → Ω → ℝ}
{s : Finset ι} {j : ι}
(h_meas : ∀ i, Measurable (X i))
(h_indep : iIndepFun X μ)
(hident : ∀ i ∈ s, ∀ j ∈ s, IdentDistrib (X i) (X j) μ μ)
(hj : j ∈ s) (t : ℝ) : mgf (∑ i ∈ s, X i) μ t = mgf (X j) μ t ^ #s := by
rw [h_indep.mgf_sum h_meas]
exact Finset.prod_eq_pow_card fun i hi =>
mgf_congr_of_identDistrib (X i) (X j) (hident i hi j hj) t
section Chernoff
/-- **Chernoff bound** on the upper tail of a real random variable. -/
theorem measure_ge_le_exp_mul_mgf [IsFiniteMeasure μ] (ε : ℝ) (ht : 0 ≤ t)
(h_int : Integrable (fun ω => exp (t * X ω)) μ) :
μ.real {ω | ε ≤ X ω} ≤ exp (-t * ε) * mgf X μ t := by
rcases ht.eq_or_lt with ht_zero_eq | ht_pos
· rw [ht_zero_eq.symm]
simp only [neg_zero, zero_mul, exp_zero, mgf_zero', one_mul]
gcongr
exacts [measure_ne_top _ _, Set.subset_univ _]
calc
μ.real {ω | ε ≤ X ω} = μ.real {ω | exp (t * ε) ≤ exp (t * X ω)} := by
congr 1 with ω
simp only [Set.mem_setOf_eq, exp_le_exp]
exact ⟨fun h => mul_le_mul_of_nonneg_left h ht_pos.le,
fun h => le_of_mul_le_mul_left h ht_pos⟩
_ ≤ (exp (t * ε))⁻¹ * μ[fun ω => exp (t * X ω)] := by
have : exp (t * ε) * μ.real {ω | exp (t * ε) ≤ exp (t * X ω)} ≤
μ[fun ω => exp (t * X ω)] :=
mul_meas_ge_le_integral_of_nonneg (ae_of_all _ fun x => (exp_pos _).le) h_int _
rwa [mul_comm (exp (t * ε))⁻¹, ← div_eq_mul_inv, le_div_iff₀' (exp_pos _)]
_ = exp (-t * ε) * mgf X μ t := by rw [neg_mul, exp_neg]; rfl
/-- **Chernoff bound** on the lower tail of a real random variable. -/
theorem measure_le_le_exp_mul_mgf [IsFiniteMeasure μ] (ε : ℝ) (ht : t ≤ 0)
(h_int : Integrable (fun ω => exp (t * X ω)) μ) :
μ.real {ω | X ω ≤ ε} ≤ exp (-t * ε) * mgf X μ t := by
rw [← neg_neg t, ← mgf_neg, neg_neg, ← neg_mul_neg (-t)]
refine Eq.trans_le ?_ (measure_ge_le_exp_mul_mgf (-ε) (neg_nonneg.mpr ht) ?_)
· simp only [Pi.neg_apply, neg_le_neg_iff]
· simp_rw [Pi.neg_apply, neg_mul_neg]
exact h_int
/-- **Chernoff bound** on the upper tail of a real random variable. -/
theorem measure_ge_le_exp_cgf [IsFiniteMeasure μ] (ε : ℝ) (ht : 0 ≤ t)
(h_int : Integrable (fun ω => exp (t * X ω)) μ) :
μ.real {ω | ε ≤ X ω} ≤ exp (-t * ε + cgf X μ t) := by
refine (measure_ge_le_exp_mul_mgf ε ht h_int).trans ?_
rw [exp_add]
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le
/-- **Chernoff bound** on the lower tail of a real random variable. -/
theorem measure_le_le_exp_cgf [IsFiniteMeasure μ] (ε : ℝ) (ht : t ≤ 0)
(h_int : Integrable (fun ω => exp (t * X ω)) μ) :
μ.real {ω | X ω ≤ ε} ≤ exp (-t * ε + cgf X μ t) := by
refine (measure_le_le_exp_mul_mgf ε ht h_int).trans ?_
rw [exp_add]
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le
end Chernoff
lemma mgf_dirac {x : ℝ} (hX : μ.map X = .dirac x) (t : ℝ) : mgf X μ t = exp (x * t) := by
have : IsProbabilityMeasure (μ.map X) := by rw [hX]; infer_instance
rw [← mgf_id_map (.of_map_ne_zero <| IsProbabilityMeasure.ne_zero _), mgf, hX, integral_dirac,
mul_comm, id_def]
lemma mgf_dirac' [MeasurableSingletonClass Ω] {ω : Ω} :
mgf X (Measure.dirac ω) t = exp (t * X ω) := by
rw [mgf, integral_dirac]
end MomentGeneratingFunction
lemma aemeasurable_exp_mul {X : Ω → ℝ} (t : ℝ) (hX : AEMeasurable X μ) :
AEStronglyMeasurable (fun ω ↦ rexp (t * X ω)) μ :=
(measurable_exp.comp_aemeasurable (hX.const_mul t)).aestronglyMeasurable
lemma integrable_exp_mul_of_le [IsFiniteMeasure μ] {X : Ω → ℝ} (t b : ℝ) (ht : 0 ≤ t)
(hX : AEMeasurable X μ) (hb : ∀ᵐ ω ∂μ, X ω ≤ b) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine .of_mem_Icc 0 (rexp (t * b)) (measurable_exp.comp_aemeasurable (hX.const_mul t)) ?_
filter_upwards [hb] with ω hb
exact ⟨by positivity, by gcongr⟩
lemma integrable_exp_mul_of_mem_Icc [IsFiniteMeasure μ] {X : Ω → ℝ} {a b t : ℝ}
(hm : AEMeasurable X μ) (hb : ∀ᵐ ω ∂μ, X ω ∈ Set.Icc a b) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
apply Integrable.of_mem_Icc (exp (min (a * t) (b * t))) (exp (max (a * t) (b * t)))
· exact (measurable_exp.comp_aemeasurable (hm.const_mul t))
filter_upwards [hb] with ω ⟨hl, hr⟩
simp only [Set.mem_Icc, exp_le_exp, inf_le_iff, le_sup_iff]
by_cases ht : 0 ≤ t
· exact ⟨Or.inl (by nlinarith), Or.inr (by nlinarith)⟩
· exact ⟨Or.inr (by nlinarith), Or.inl (by nlinarith)⟩
end ProbabilityTheory
namespace ContinuousLinearMap
variable {𝕜 E F : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace 𝕜 E] [NormedSpace ℝ E] [NormedSpace 𝕜 F] [NormedSpace ℝ F] [CompleteSpace E]
[CompleteSpace F] [MeasurableSpace E] {μ : Measure E}
lemma integral_comp_id_comm' (h : Integrable id μ) (L : E →L[𝕜] F) :
μ[L] = L μ[id] := by
change ∫ x, L (id x) ∂μ = _
rw [L.integral_comp_comm h]
lemma integral_comp_id_comm (h : Integrable id μ) (L : E →L[𝕜] F) :
μ[L] = L (∫ x, x ∂μ) :=
L.integral_comp_id_comm' h
variable [OpensMeasurableSpace E] [MeasurableSpace F] [BorelSpace F] [SecondCountableTopology F]
lemma integral_id_map (h : Integrable id μ) (L : E →L[𝕜] F) :
∫ x, x ∂(μ.map L) = L (∫ x, x ∂μ) := by
rw [integral_map (by fun_prop) (by fun_prop)]
simp [L.integral_comp_id_comm h]
end ContinuousLinearMap |
.lake/packages/mathlib/Mathlib/Probability/Moments/ComplexMGF.lean | import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.MeasureTheory.Measure.CharacteristicFunction
import Mathlib.Probability.Moments.Basic
import Mathlib.Probability.Moments.IntegrableExpMul
/-!
# The complex-valued moment-generating function
The moment-generating function (mgf) is `t : ℝ ↦ μ[fun ω ↦ rexp (t * X ω)]`. It can be extended to
a complex function `z : ℂ ↦ μ[fun ω ↦ cexp (z * X ω)]`, which we call `complexMGF X μ`.
That function is holomorphic on the vertical strip with base the interior of the interval
of definition of the mgf.
On the vertical line that goes through 0, `complexMGF X μ` is equal to the characteristic function.
This allows us to link properties of the characteristic function and the mgf (mostly deducing
properties of the mgf from those of the characteristic function).
## Main definitions
* `complexMGF X μ`: the function `z : ℂ ↦ μ[fun ω ↦ cexp (z * X ω)]`.
## Main results
* `complexMGF_ofReal`: for `x : ℝ`, `complexMGF X μ x = mgf X μ x`.
* `hasDerivAt_complexMGF`: for all `z : ℂ` such that the real part `z.re` belongs to the interior
of the interval of definition of the mgf, `complexMGF X μ` is differentiable at `z`
with derivative `μ[X * exp (z * X)]`.
* `differentiableOn_complexMGF`: `complexMGF X μ` is holomorphic on the vertical strip
`{z | z.re ∈ interior (integrableExpSet X μ)}`.
* `analyticOn_complexMGF`: `complexMGF X μ` is analytic on the vertical strip
`{z | z.re ∈ interior (integrableExpSet X μ)}`.
* `eqOn_complexMGF_of_mgf`: if two random variables have the same moment-generating function,
then they have the same `complexMGF` on the vertical strip
`{z | z.re ∈ interior (integrableExpSet X μ)}`.
Once we know that equal `mgf` implies equal distributions, we will be able to show that
the `complexMGF` are equal everywhere, not only on the strip.
This lemma will be used in the proof of the equality of distributions.
* `ext_of_complexMGF_eq`: If the complex moment-generating functions of two random variables `X`
and `Y` with respect to the finite measures `μ`, `μ'`, respectively, coincide, then
`μ.map X = μ'.map Y`. In other words, complex moment-generating functions separate the
distributions of random variables.
## TODO
* Prove that if two random variables have the same `mgf`, then the have the same `complexMGF`.
-/
open MeasureTheory Filter Finset Real Complex
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal Topology
namespace ProbabilityTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} {t u v : ℝ} {z ε : ℂ}
/-- Complex extension of the moment-generating function. -/
noncomputable
def complexMGF (X : Ω → ℝ) (μ : Measure Ω) (z : ℂ) : ℂ := μ[fun ω ↦ cexp (z * X ω)]
lemma complexMGF_undef (hX : AEMeasurable X μ) (h : ¬ Integrable (fun ω ↦ rexp (z.re * X ω)) μ) :
complexMGF X μ z = 0 := by
rw [complexMGF, integral_undef]
rw [← integrable_norm_iff (by fun_prop)]
simpa [Complex.norm_exp] using h
lemma complexMGF_id_map (hX : AEMeasurable X μ) : complexMGF id (μ.map X) = complexMGF X μ := by
ext t
rw [complexMGF, integral_map hX]
· rfl
· fun_prop
lemma complexMGF_congr_identDistrib {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ' : Measure Ω'}
{Y : Ω' → ℝ} (h : IdentDistrib X Y μ μ') :
complexMGF X μ = complexMGF Y μ' := by
rw [← complexMGF_id_map h.aemeasurable_fst, ← complexMGF_id_map h.aemeasurable_snd, h.map_eq]
lemma norm_complexMGF_le_mgf : ‖complexMGF X μ z‖ ≤ mgf X μ z.re := by
rw [complexMGF, ← re_add_im z]
simp_rw [add_mul, Complex.exp_add, re_add_im]
calc ‖∫ ω, cexp (z.re * X ω) * cexp (z.im * I * X ω) ∂μ‖
_ ≤ ∫ ω, ‖cexp (z.re * X ω) * cexp (z.im * I * X ω)‖ ∂μ := norm_integral_le_integral_norm _
_ = ∫ ω, rexp (z.re * X ω) ∂μ := by simp [Complex.norm_exp]
lemma complexMGF_ofReal (x : ℝ) : complexMGF X μ x = mgf X μ x := by
rw [complexMGF, mgf, ← integral_complex_ofReal]
norm_cast
lemma re_complexMGF_ofReal (x : ℝ) : (complexMGF X μ x).re = mgf X μ x := by
simp [complexMGF_ofReal]
lemma re_complexMGF_ofReal' : (fun x : ℝ ↦ (complexMGF X μ x).re) = mgf X μ := by
ext x
exact re_complexMGF_ofReal x
lemma complexMGF_id_mul_I {μ : Measure ℝ} (t : ℝ) :
complexMGF id μ (t * I) = charFun μ t := by
simp only [complexMGF, id_eq, charFun, RCLike.inner_apply, conj_trivial, ofReal_mul]
congr with x
ring_nf
lemma complexMGF_mul_I (hX : AEMeasurable X μ) (t : ℝ) :
complexMGF X μ (t * I) = charFun (μ.map X) t := by
rw [← complexMGF_id_map hX, complexMGF_id_mul_I]
section Analytic
/-- For `z : ℂ` with `z.re ∈ interior (integrableExpSet X μ)`, the derivative of the function
`z' ↦ μ[X ^ n * cexp (z' * X)]` at `z` is `μ[X ^ (n + 1) * cexp (z * X)]`. -/
lemma hasDerivAt_integral_pow_mul_exp (hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
HasDerivAt (fun z ↦ μ[fun ω ↦ X ω ^ n * cexp (z * X ω)])
μ[fun ω ↦ X ω ^ (n + 1) * cexp (z * X ω)] z := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet hz
have hz' := hz
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hz'
obtain ⟨l, u, hlu, h_subset⟩ := hz'
let t := ((z.re - l) ⊓ (u - z.re)) / 2
have h_pos : 0 < (z.re - l) ⊓ (u - z.re) := by simp [hlu.1, hlu.2]
have ht : 0 < t := half_pos h_pos
refine (hasDerivAt_integral_of_dominated_loc_of_deriv_le
(bound := fun ω ↦ |X ω| ^ (n + 1) * rexp (z.re * X ω + t / 2 * |X ω|))
(F := fun z ω ↦ X ω ^ n * cexp (z * X ω))
(F' := fun z ω ↦ X ω ^ (n + 1) * cexp (z * X ω)) (half_pos ht) ?_ ?_ ?_ ?_ ?_ ?_).2
· exact .of_forall fun z ↦ by fun_prop
· exact integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet hz n
· fun_prop
· refine ae_of_all _ fun ω ε hε ↦ ?_
simp only [norm_mul, norm_pow, norm_real, Real.norm_eq_abs]
rw [Complex.norm_exp]
simp only [mul_re, ofReal_re, ofReal_im, mul_zero, sub_zero]
gcongr
have : ε = z + (ε - z) := by simp
rw [this, add_re, add_mul]
gcongr _ + ?_
refine (le_abs_self _).trans ?_
rw [abs_mul]
gcongr
refine (abs_re_le_norm _).trans ?_
simp only [Metric.mem_ball, dist_eq_norm] at hε
exact hε.le
· refine integrable_pow_abs_mul_exp_add_of_integrable_exp_mul ?_ ?_ ?_ ?_ (t := t) (n + 1)
· exact h_subset (add_half_inf_sub_mem_Ioo hlu)
· exact h_subset (sub_half_inf_sub_mem_Ioo hlu)
· positivity
· exact lt_of_lt_of_le (by simp [ht]) (le_abs_self _)
· refine ae_of_all _ fun ω ε hε ↦ ?_
simp only
simp_rw [pow_succ, mul_assoc]
refine HasDerivAt.const_mul _ ?_
simp_rw [← smul_eq_mul, Complex.exp_eq_exp_ℂ]
convert hasDerivAt_exp_smul_const (X ω : ℂ) ε using 1
rw [smul_eq_mul, mul_comm]
/-- For all `z : ℂ` with `z.re ∈ interior (integrableExpSet X μ)`,
`complexMGF X μ` is differentiable at `z` with derivative `μ[X * exp (z * X)]`. -/
theorem hasDerivAt_complexMGF (hz : z.re ∈ interior (integrableExpSet X μ)) :
HasDerivAt (complexMGF X μ) μ[fun ω ↦ X ω * cexp (z * X ω)] z := by
convert hasDerivAt_integral_pow_mul_exp hz 0
· simp [complexMGF]
· simp
/-- `complexMGF X μ` is holomorphic on the vertical strip
`{z | z.re ∈ interior (integrableExpSet X μ)}`. -/
theorem differentiableOn_complexMGF :
DifferentiableOn ℂ (complexMGF X μ) {z | z.re ∈ interior (integrableExpSet X μ)} := by
intro z hz
have h := hasDerivAt_complexMGF hz
rw [hasDerivAt_iff_hasFDerivAt] at h
exact h.hasFDerivWithinAt.differentiableWithinAt
theorem analyticOnNhd_complexMGF :
AnalyticOnNhd ℂ (complexMGF X μ) {z | z.re ∈ interior (integrableExpSet X μ)} :=
differentiableOn_complexMGF.analyticOnNhd (isOpen_interior.preimage Complex.continuous_re)
/-- `complexMGF X μ` is analytic on the vertical strip
`{z | z.re ∈ interior (integrableExpSet X μ)}`. -/
theorem analyticOn_complexMGF :
AnalyticOn ℂ (complexMGF X μ) {z | z.re ∈ interior (integrableExpSet X μ)} :=
analyticOnNhd_complexMGF.analyticOn
/-- `complexMGF X μ` is analytic at any point `z` with `z.re ∈ interior (integrableExpSet X μ)`. -/
lemma analyticAt_complexMGF (hz : z.re ∈ interior (integrableExpSet X μ)) :
AnalyticAt ℂ (complexMGF X μ) z :=
analyticOnNhd_complexMGF z hz
end Analytic
section Deriv
/-! ### Iterated derivatives of `complexMGF` -/
lemma hasDerivAt_iteratedDeriv_complexMGF (hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
HasDerivAt (iteratedDeriv n (complexMGF X μ)) μ[fun ω ↦ X ω ^ (n + 1) * cexp (z * X ω)] z := by
induction n generalizing z with
| zero => simp [hasDerivAt_complexMGF hz]
| succ n hn =>
rw [iteratedDeriv_succ]
have : deriv (iteratedDeriv n (complexMGF X μ))
=ᶠ[𝓝 z] fun z ↦ μ[fun ω ↦ X ω ^ (n + 1) * cexp (z * X ω)] := by
have h_mem : ∀ᶠ y in 𝓝 z, y.re ∈ interior (integrableExpSet X μ) := by
refine IsOpen.eventually_mem ?_ hz
exact isOpen_interior.preimage Complex.continuous_re
filter_upwards [h_mem] with y hy using HasDerivAt.deriv (hn hy)
rw [EventuallyEq.hasDerivAt_iff this]
exact hasDerivAt_integral_pow_mul_exp hz (n + 1)
/-- For `z : ℂ` with `z.re ∈ interior (integrableExpSet X μ)`, the n-th derivative of the function
`complexMGF X μ` at `z` is `μ[X ^ n * cexp (z * X)]`. -/
lemma iteratedDeriv_complexMGF (hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
iteratedDeriv n (complexMGF X μ) z = μ[fun ω ↦ X ω ^ n * cexp (z * X ω)] := by
induction n generalizing z with
| zero => simp [complexMGF]
| succ n hn =>
rw [iteratedDeriv_succ]
exact (hasDerivAt_iteratedDeriv_complexMGF hz n).deriv
end Deriv
section EqOfMGF
/-! We prove that if two random variables have the same `mgf`, then
they also have the same `complexMGF`. -/
variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {Y : Ω' → ℝ} {μ' : Measure Ω'}
/-- If two random variables have the same moment-generating function then they have
the same `integrableExpSet`. -/
lemma integrableExpSet_eq_of_mgf' (hXY : mgf X μ = mgf Y μ') (hμμ' : μ = 0 ↔ μ' = 0) :
integrableExpSet X μ = integrableExpSet Y μ' := by
ext t
simp only [integrableExpSet, Set.mem_setOf_eq]
by_cases hμ : μ = 0
· simp [hμ, hμμ'.mp hμ]
have : NeZero μ := ⟨hμ⟩
have : NeZero μ' := ⟨(not_iff_not.mpr hμμ').mp hμ⟩
rw [← mgf_pos_iff, ← mgf_pos_iff, hXY]
/-- If two random variables have the same moment-generating function then they have
the same `integrableExpSet`. -/
lemma integrableExpSet_eq_of_mgf [IsProbabilityMeasure μ]
(hXY : mgf X μ = mgf Y μ') :
integrableExpSet X μ = integrableExpSet Y μ' := by
refine integrableExpSet_eq_of_mgf' hXY ?_
simp only [IsProbabilityMeasure.ne_zero, false_iff]
suffices mgf Y μ' 0 ≠ 0 by
intro h_contra
simp [h_contra] at this
rw [← hXY]
exact (mgf_pos (by simp)).ne'
/-- If two random variables have the same moment-generating function then they have
the same `complexMGF` on the vertical strip `{z | z.re ∈ interior (integrableExpSet X μ)}`.
TODO: once we know that equal `mgf` implies equal distributions, we will be able to show that
the `complexMGF` are equal everywhere, not only on the strip.
This lemma will be used in the proof of the equality of distributions. -/
lemma eqOn_complexMGF_of_mgf' (hXY : mgf X μ = mgf Y μ') (hμμ' : μ = 0 ↔ μ' = 0) :
Set.EqOn (complexMGF X μ) (complexMGF Y μ') {z | z.re ∈ interior (integrableExpSet X μ)} := by
by_cases h_empty : interior (integrableExpSet X μ) = ∅
· simp [h_empty]
rw [← ne_eq, ← Set.nonempty_iff_ne_empty] at h_empty
obtain ⟨t, ht⟩ := h_empty
have hX : AnalyticOnNhd ℂ (complexMGF X μ) {z | z.re ∈ interior (integrableExpSet X μ)} :=
analyticOnNhd_complexMGF
have hY : AnalyticOnNhd ℂ (complexMGF Y μ') {z | z.re ∈ interior (integrableExpSet Y μ')} :=
analyticOnNhd_complexMGF
rw [integrableExpSet_eq_of_mgf' hXY hμμ'] at hX ht ⊢
refine AnalyticOnNhd.eqOn_of_preconnected_of_frequently_eq hX hY
(convex_integrableExpSet.interior.linear_preimage reLm).isPreconnected
(z₀ := (t : ℂ)) (by simp [ht]) ?_
have h_real : ∃ᶠ (x : ℝ) in 𝓝[≠] t, complexMGF X μ x = complexMGF Y μ' x := by
refine .of_forall fun y ↦ ?_
rw [complexMGF_ofReal, complexMGF_ofReal, hXY]
rw [frequently_iff_seq_forall] at h_real ⊢
obtain ⟨xs, hx_tendsto, hx_eq⟩ := h_real
refine ⟨fun n ↦ xs n, ?_, fun n ↦ ?_⟩
· rw [tendsto_nhdsWithin_iff] at hx_tendsto ⊢
constructor
· rw [tendsto_ofReal_iff]
exact hx_tendsto.1
· simpa using hx_tendsto.2
· simp [hx_eq]
/-- If two random variables have the same moment-generating function then they have
the same `complexMGF` on the vertical strip `{z | z.re ∈ interior (integrableExpSet X μ)}`. -/
lemma eqOn_complexMGF_of_mgf [IsProbabilityMeasure μ]
(hXY : mgf X μ = mgf Y μ') :
Set.EqOn (complexMGF X μ) (complexMGF Y μ') {z | z.re ∈ interior (integrableExpSet X μ)} := by
refine eqOn_complexMGF_of_mgf' hXY ?_
simp only [IsProbabilityMeasure.ne_zero, false_iff]
suffices mgf Y μ' 0 ≠ 0 by
intro h_contra
simp [h_contra] at this
rw [← hXY]
exact (mgf_pos (by simp)).ne'
end EqOfMGF
section ext
variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {Y : Ω' → ℝ} {μ' : Measure Ω'}
/-- If the complex moment-generating functions of two random variables `X` and `Y` with respect to
the finite measures `μ`, `μ'`, respectively, coincide, then `μ.map X = μ'.map Y`. In other words,
complex moment-generating functions separate the distributions of random variables. -/
theorem _root_.MeasureTheory.Measure.ext_of_complexMGF_eq [IsFiniteMeasure μ]
[IsFiniteMeasure μ'] (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ')
(h : complexMGF X μ = complexMGF Y μ') :
μ.map X = μ'.map Y := by
have inner_ne_zero (x : ℝ) (h : x ≠ 0) : bilinFormOfRealInner x ≠ 0 :=
DFunLike.ne_iff.mpr ⟨x, inner_self_ne_zero.mpr h⟩
apply MeasureTheory.ext_of_integral_char_eq continuous_probChar probChar_ne_one inner_ne_zero
continuous_inner (fun w ↦ ?_)
rw [funext_iff] at h
specialize h (Multiplicative.toAdd w * I)
simp_rw [complexMGF, mul_assoc, mul_comm I, ← mul_assoc] at h
simp only [BoundedContinuousFunction.char_apply, bilinFormOfRealInner_apply_apply,
RCLike.inner_apply, conj_trivial, probChar_apply, ofReal_mul]
rwa [integral_map hX (by fun_prop), integral_map hY (by fun_prop)]
lemma _root_.MeasureTheory.Measure.ext_of_complexMGF_id_eq
{μ μ' : Measure ℝ} [IsFiniteMeasure μ] [IsFiniteMeasure μ']
(h : complexMGF id μ = complexMGF id μ') :
μ = μ' := by
simpa using Measure.ext_of_complexMGF_eq aemeasurable_id aemeasurable_id h
end ext
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/Covariance.lean | import Mathlib.Probability.Independence.Integration
/-!
# Covariance
We define the covariance of two real-valued random variables.
## Main definitions
* `covariance`: covariance of two real-valued random variables, with notation `cov[X, Y; μ]`.
`cov[X, Y; μ] = ∫ ω, (X ω - μ[X]) * (Y ω - μ[Y]) ∂μ`.
## Main statements
* `covariance_self`: `cov[X, X; μ] = Var[X; μ]`
## Notation
* `cov[X, Y; μ] = covariance X Y μ`
* `cov[X, Y] = covariance X Y volume`
-/
open MeasureTheory
namespace ProbabilityTheory
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {X Y Z : Ω → ℝ} {μ : Measure Ω}
/-- The covariance of two real-valued random variables defined as
the integral of `(X - 𝔼[X])(Y - 𝔼[Y])`. -/
noncomputable def covariance (X Y : Ω → ℝ) (μ : Measure Ω) : ℝ :=
∫ ω, (X ω - μ[X]) * (Y ω - μ[Y]) ∂μ
@[inherit_doc]
scoped notation "cov[" X ", " Y "; " μ "]" => ProbabilityTheory.covariance X Y μ
/-- The covariance of the real-valued random variables `X` and `Y`
according to the volume measure. -/
scoped notation "cov[" X ", " Y "]" => cov[X, Y; MeasureTheory.MeasureSpace.volume]
lemma covariance_eq_sub [IsProbabilityMeasure μ] (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
cov[X, Y; μ] = μ[X * Y] - μ[X] * μ[Y] := by
simp_rw [covariance, sub_mul, mul_sub]
repeat rw [integral_sub]
· simp_rw [integral_mul_const, integral_const_mul, integral_const, measureReal_univ_eq_one,
one_smul]
simp
· exact hY.const_mul _ |>.integrable (by simp)
· exact integrable_const _
· exact hX.integrable_mul hY
· exact hX.mul_const _ |>.integrable (by simp)
· exact (hX.integrable_mul hY).sub (hX.mul_const _ |>.integrable (by simp))
· exact (hY.const_mul _ |>.integrable (by simp)).sub (integrable_const _)
@[simp] lemma covariance_zero_left : cov[0, Y; μ] = 0 := by simp [covariance]
@[simp] lemma covariance_zero_right : cov[X, 0; μ] = 0 := by simp [covariance]
@[simp] lemma covariance_zero_measure : cov[X, Y; (0 : Measure Ω)] = 0 := by simp [covariance]
variable (X Y) in
lemma covariance_comm : cov[X, Y; μ] = cov[Y, X; μ] := by
simp_rw [covariance]
congr with x
ring
@[simp]
lemma covariance_const_left [IsProbabilityMeasure μ] (c : ℝ) : cov[fun _ ↦ c, Y; μ] = 0 := by
simp [covariance]
@[simp]
lemma covariance_const_right [IsProbabilityMeasure μ] (c : ℝ) : cov[X, fun _ ↦ c; μ] = 0 := by
simp [covariance]
@[simp]
lemma covariance_add_const_left [IsProbabilityMeasure μ] (hX : Integrable X μ) (c : ℝ) :
cov[fun ω ↦ X ω + c, Y; μ] = cov[X, Y; μ] := by
simp_rw [covariance]
congr with ω
rw [integral_add hX (by fun_prop)]
simp
@[simp]
lemma covariance_const_add_left [IsProbabilityMeasure μ] (hX : Integrable X μ) (c : ℝ) :
cov[fun ω ↦ c + X ω, Y; μ] = cov[X, Y; μ] := by
simp_rw [add_comm c]
exact covariance_add_const_left hX c
@[simp]
lemma covariance_add_const_right [IsProbabilityMeasure μ] (hY : Integrable Y μ) (c : ℝ) :
cov[X, fun ω ↦ Y ω + c; μ] = cov[X, Y; μ] := by
rw [covariance_comm, covariance_add_const_left hY c, covariance_comm]
@[simp]
lemma covariance_const_add_right [IsProbabilityMeasure μ] (hY : Integrable Y μ) (c : ℝ) :
cov[X, fun ω ↦ c + Y ω; μ] = cov[X, Y; μ] := by
simp_rw [add_comm c]
exact covariance_add_const_right hY c
lemma covariance_add_left [IsFiniteMeasure μ]
(hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) (hZ : MemLp Z 2 μ) :
cov[X + Y, Z; μ] = cov[X, Z; μ] + cov[Y, Z; μ] := by
simp_rw [covariance, Pi.add_apply]
rw [← integral_add]
· congr with x
rw [integral_add (hX.integrable (by simp)) (hY.integrable (by simp))]
ring
· exact (hX.sub (memLp_const _)).integrable_mul (hZ.sub (memLp_const _))
· exact (hY.sub (memLp_const _)).integrable_mul (hZ.sub (memLp_const _))
lemma covariance_add_right [IsFiniteMeasure μ]
(hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) (hZ : MemLp Z 2 μ) :
cov[X, Y + Z; μ] = cov[X, Y; μ] + cov[X, Z; μ] := by
rw [covariance_comm, covariance_add_left hY hZ hX, covariance_comm X, covariance_comm Z]
lemma covariance_smul_left (c : ℝ) : cov[c • X, Y; μ] = c * cov[X, Y; μ] := by
simp_rw [covariance, Pi.smul_apply, smul_eq_mul, ← integral_const_mul, ← mul_assoc, mul_sub,
integral_const_mul]
lemma covariance_smul_right (c : ℝ) : cov[X, c • Y; μ] = c * cov[X, Y; μ] := by
rw [covariance_comm, covariance_smul_left, covariance_comm]
lemma covariance_mul_left (c : ℝ) : cov[fun ω ↦ c * X ω, Y; μ] = c * cov[X, Y; μ] :=
covariance_smul_left c
lemma covariance_mul_right (c : ℝ) : cov[X, fun ω ↦ c * Y ω; μ] = c * cov[X, Y; μ] :=
covariance_smul_right c
@[simp]
lemma covariance_neg_left : cov[-X, Y; μ] = -cov[X, Y; μ] := by
calc cov[-X, Y; μ]
_ = cov[(-1 : ℝ) • X, Y; μ] := by simp
_ = -cov[X, Y; μ] := by rw [covariance_smul_left]; simp
@[simp]
lemma covariance_fun_neg_left : cov[fun ω ↦ -X ω, Y; μ] = -cov[X, Y; μ] :=
covariance_neg_left
@[simp]
lemma covariance_neg_right : cov[X, -Y; μ] = -cov[X, Y; μ] := by
calc cov[X, -Y; μ]
_ = cov[X, (-1 : ℝ) • Y; μ] := by simp
_ = -cov[X, Y; μ] := by rw [covariance_smul_right]; simp
@[simp]
lemma covariance_fun_neg_right : cov[X, fun ω ↦ -Y ω; μ] = -cov[X, Y; μ] :=
covariance_neg_right
lemma covariance_sub_left [IsFiniteMeasure μ]
(hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) (hZ : MemLp Z 2 μ) :
cov[X - Y, Z; μ] = cov[X, Z; μ] - cov[Y, Z; μ] := by
simp_rw [sub_eq_add_neg, covariance_add_left hX hY.neg hZ, covariance_neg_left]
lemma covariance_sub_right [IsFiniteMeasure μ]
(hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) (hZ : MemLp Z 2 μ) :
cov[X, Y - Z; μ] = cov[X, Y; μ] - cov[X, Z; μ] := by
simp_rw [sub_eq_add_neg, covariance_add_right hX hY hZ.neg, covariance_neg_right]
@[simp]
lemma covariance_sub_const_left [IsProbabilityMeasure μ] (hX : Integrable X μ) (c : ℝ) :
cov[fun ω ↦ X ω - c, Y; μ] = cov[X, Y; μ] := by
simp [sub_eq_add_neg, hX]
@[simp]
lemma covariance_const_sub_left [IsProbabilityMeasure μ] (hX : Integrable X μ) (c : ℝ) :
cov[fun ω ↦ c - X ω, Y; μ] = -cov[X, Y; μ] := by
simp [sub_eq_add_neg, hX.neg']
@[simp]
lemma covariance_sub_const_right [IsProbabilityMeasure μ] (hY : Integrable Y μ) (c : ℝ) :
cov[X, fun ω ↦ Y ω - c; μ] = cov[X, Y; μ] := by
simp [sub_eq_add_neg, hY]
@[simp]
lemma covariance_const_sub_right [IsProbabilityMeasure μ] (hY : Integrable Y μ) (c : ℝ) :
cov[X, fun ω ↦ c - Y ω; μ] = -cov[X, Y; μ] := by
simp [sub_eq_add_neg, hY.neg']
section Sum
variable {ι : Type*} {X : ι → Ω → ℝ} {s : Finset ι} [IsFiniteMeasure μ]
lemma covariance_sum_left' (hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[∑ i ∈ s, X i, Y; μ] = ∑ i ∈ s, cov[X i, Y; μ] := by
classical
induction s using Finset.induction with
| empty => simp
| insert i s hi h_ind =>
rw [Finset.sum_insert hi, Finset.sum_insert hi, covariance_add_left, h_ind]
· exact fun j hj ↦ hX j (by simp [hj])
· exact hX i (by simp)
· exact memLp_finset_sum' s (fun j hj ↦ hX j (by simp [hj]))
· exact hY
lemma covariance_sum_left [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[∑ i, X i, Y; μ] = ∑ i, cov[X i, Y; μ] :=
covariance_sum_left' (fun _ _ ↦ hX _) hY
lemma covariance_fun_sum_left' (hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[fun ω ↦ ∑ i ∈ s, X i ω, Y; μ] = ∑ i ∈ s, cov[X i, Y; μ] := by
convert covariance_sum_left' hX hY
simp
lemma covariance_fun_sum_left [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[fun ω ↦ ∑ i, X i ω, Y; μ] = ∑ i, cov[X i, Y; μ] := by
convert covariance_sum_left hX hY
simp
lemma covariance_sum_right' (hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[Y, ∑ i ∈ s, X i; μ] = ∑ i ∈ s, cov[Y, X i; μ] := by
rw [covariance_comm, covariance_sum_left' hX hY]
simp_rw [covariance_comm]
lemma covariance_sum_right [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[Y, ∑ i, X i; μ] = ∑ i, cov[Y, X i; μ] :=
covariance_sum_right' (fun _ _ ↦ hX _) hY
lemma covariance_fun_sum_right' (hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[Y, fun ω ↦ ∑ i ∈ s, X i ω; μ] = ∑ i ∈ s, cov[Y, X i; μ] := by
convert covariance_sum_right' hX hY
simp
lemma covariance_fun_sum_right [Fintype ι] (hX : ∀ i, MemLp (X i) 2 μ) (hY : MemLp Y 2 μ) :
cov[Y, fun ω ↦ ∑ i, X i ω; μ] = ∑ i, cov[Y, X i; μ] :=
covariance_fun_sum_right' (fun _ _ ↦ hX _) hY
lemma covariance_sum_sum' {ι' : Type*} {Y : ι' → Ω → ℝ} {t : Finset ι'}
(hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : ∀ i ∈ t, MemLp (Y i) 2 μ) :
cov[∑ i ∈ s, X i, ∑ j ∈ t, Y j; μ] = ∑ i ∈ s, ∑ j ∈ t, cov[X i, Y j; μ] := by
rw [covariance_sum_left' hX]
· exact Finset.sum_congr rfl fun i hi ↦ by rw [covariance_sum_right' hY (hX i hi)]
· exact memLp_finset_sum' t hY
lemma covariance_sum_sum [Fintype ι] {ι' : Type*} [Fintype ι'] {Y : ι' → Ω → ℝ}
(hX : ∀ i, MemLp (X i) 2 μ) (hY : ∀ i, MemLp (Y i) 2 μ) :
cov[∑ i, X i, ∑ j, Y j; μ] = ∑ i, ∑ j, cov[X i, Y j; μ] :=
covariance_sum_sum' (fun _ _ ↦ hX _) (fun _ _ ↦ hY _)
lemma covariance_fun_sum_fun_sum' {ι' : Type*} {Y : ι' → Ω → ℝ} {t : Finset ι'}
(hX : ∀ i ∈ s, MemLp (X i) 2 μ) (hY : ∀ i ∈ t, MemLp (Y i) 2 μ) :
cov[fun ω ↦ ∑ i ∈ s, X i ω, fun ω ↦ ∑ j ∈ t, Y j ω; μ]
= ∑ i ∈ s, ∑ j ∈ t, cov[X i, Y j; μ] := by
convert covariance_sum_sum' hX hY
all_goals simp
lemma covariance_fun_sum_fun_sum [Fintype ι] {ι' : Type*} [Fintype ι'] {Y : ι' → Ω → ℝ}
(hX : ∀ i, MemLp (X i) 2 μ) (hY : ∀ i, MemLp (Y i) 2 μ) :
cov[fun ω ↦ ∑ i, X i ω, fun ω ↦ ∑ j, Y j ω; μ] = ∑ i, ∑ j, cov[X i, Y j; μ] :=
covariance_fun_sum_fun_sum' (fun _ _ ↦ hX _) (fun _ _ ↦ hY _)
end Sum
section Map
variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
lemma covariance_map_equiv (X Y : Ω → ℝ) (Z : Ω' ≃ᵐ Ω) :
cov[X, Y; μ.map Z] = cov[X ∘ Z, Y ∘ Z; μ] := by
simp_rw [covariance, integral_map_equiv, Function.comp_apply]
lemma covariance_map {Z : Ω' → Ω} (hX : AEStronglyMeasurable X (μ.map Z))
(hY : AEStronglyMeasurable Y (μ.map Z)) (hZ : AEMeasurable Z μ) :
cov[X, Y; μ.map Z] = cov[X ∘ Z, Y ∘ Z; μ] := by
simp_rw [covariance, Function.comp_apply]
repeat rw [integral_map]
any_goals assumption
exact (hX.sub aestronglyMeasurable_const).mul (hY.sub aestronglyMeasurable_const)
lemma covariance_map_fun {Z : Ω' → Ω} (hX : AEStronglyMeasurable X (μ.map Z))
(hY : AEStronglyMeasurable Y (μ.map Z)) (hZ : AEMeasurable Z μ) :
cov[X, Y; μ.map Z] = cov[fun ω ↦ X (Z ω), fun ω ↦ Y (Z ω); μ] :=
covariance_map hX hY hZ
end Map
lemma IndepFun.covariance_eq_zero (h : X ⟂ᵢ[μ] Y) (hX : MemLp X 2 μ) (hY : MemLp Y 2 μ) :
cov[X, Y; μ] = 0 := by
by_cases h' : ∀ᵐ ω ∂μ, X ω = 0
· refine integral_eq_zero_of_ae ?_
filter_upwards [h'] with ω hω
simp [hω, integral_eq_zero_of_ae h']
have := hX.isProbabilityMeasure_of_indepFun X Y (by simp) (by simp) h' h
rw [covariance_eq_sub hX hY, h.integral_mul_eq_mul_integral
hX.aestronglyMeasurable hY.aestronglyMeasurable, sub_self]
section Prod
variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {ν : Measure Ω'}
[IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {X : Ω → ℝ} {Y : Ω' → ℝ}
lemma covariance_fst_snd_prod (hfμ : MemLp X 2 μ) (hgν : MemLp Y 2 ν) :
cov[fun p ↦ X p.1, fun p ↦ Y p.2; μ.prod ν] = 0 :=
(indepFun_prod₀ hfμ.aemeasurable hgν.aemeasurable).covariance_eq_zero
(hfμ.comp_fst ν) (hgν.comp_snd μ)
end Prod
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/IntegrableExpMul.lean | import Mathlib.MeasureTheory.Function.L1Space.Integrable
import Mathlib.MeasureTheory.Order.Group.Lattice
/-!
# Domain of the moment-generating function
For `X` a real random variable and `μ` a finite measure, the set
`{t | Integrable (fun ω ↦ exp (t * X ω)) μ}` is an interval containing zero. This is the set of
points for which the moment-generating function `mgf X μ t` is well defined.
We denote that set by `integrableExpSet X μ`.
We prove the integrability of other functions for `t` in the interior of that interval.
## Main definitions
* `ProbabilityTheory.IntegrableExpSet`: the interval of reals for which `exp (t * X)` is integrable.
## Main results
* `ProbabilityTheory.integrable_exp_mul_of_le_of_le`: if `exp (u * X)` is integrable for `u = a` and
`u = b` then it is integrable on `[a, b]`.
* `ProbabilityTheory.convex_integrableExpSet`: `integrableExpSet X μ` is a convex set.
* `ProbabilityTheory.integrable_exp_mul_of_nonpos_of_ge`: if `exp (u * X)` is integrable for `u ≤ 0`
then it is integrable on `[u, 0]`.
* `ProbabilityTheory.integrable_rpow_abs_mul_exp_of_mem_interior`: for `v` in the interior of the
interval in which `exp (t * X)` is integrable, for all nonnegative `p : ℝ`,
`|X| ^ p * exp (v * X)` is integrable.
* `ProbabilityTheory.memLp_of_mem_interior_integrableExpSet`: if 0 belongs to the interior of
`integrableExpSet X μ`, then `X` is in `ℒp` for all finite `p`.
-/
open MeasureTheory Filter Finset Real
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal Topology
namespace ProbabilityTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} {t u v : ℝ}
section Interval
lemma integrable_exp_mul_of_le_of_le {a b : ℝ}
(ha : Integrable (fun ω ↦ exp (a * X ω)) μ) (hb : Integrable (fun ω ↦ exp (b * X ω)) μ)
(hat : a ≤ t) (htb : t ≤ b) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine Integrable.mono (ha.add hb) ?_ (ae_of_all _ fun ω ↦ ?_)
· by_cases hab : a = b
· have ha_eq_t : a = t := le_antisymm hat (hab ▸ htb)
rw [← ha_eq_t]
exact ha.1
· refine AEMeasurable.aestronglyMeasurable ?_
refine measurable_exp.comp_aemeasurable (AEMeasurable.const_mul ?_ _)
by_cases ha_zero : a = 0
· refine aemeasurable_of_aemeasurable_exp_mul ?_ hb.1.aemeasurable
rw [ha_zero] at hab
exact Ne.symm hab
· exact aemeasurable_of_aemeasurable_exp_mul ha_zero ha.1.aemeasurable
· simp only [norm_eq_abs, abs_exp, Pi.add_apply]
conv_rhs => rw [abs_of_nonneg (by positivity)]
rcases le_total 0 (X ω) with h | h
· calc exp (t * X ω)
_ ≤ exp (b * X ω) := exp_le_exp.mpr (mul_le_mul_of_nonneg_right htb h)
_ ≤ exp (a * X ω) + exp (b * X ω) := le_add_of_nonneg_left (exp_nonneg _)
· calc exp (t * X ω)
_ ≤ exp (a * X ω) := exp_le_exp.mpr (mul_le_mul_of_nonpos_right hat h)
_ ≤ exp (a * X ω) + exp (b * X ω) := le_add_of_nonneg_right (exp_nonneg _)
/-- If `ω ↦ exp (u * X ω)` is integrable at `u` and `-u`, then it is integrable on `[-u, u]`. -/
lemma integrable_exp_mul_of_abs_le
(hu_int_pos : Integrable (fun ω ↦ exp (u * X ω)) μ)
(hu_int_neg : Integrable (fun ω ↦ exp (-u * X ω)) μ)
(htu : |t| ≤ |u|) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine integrable_exp_mul_of_le_of_le (a := -|u|) (b := |u|) ?_ ?_ ?_ ?_
· rcases le_total 0 u with hu | hu
· rwa [abs_of_nonneg hu]
· simpa [abs_of_nonpos hu]
· rcases le_total 0 u with hu | hu
· rwa [abs_of_nonneg hu]
· rwa [abs_of_nonpos hu]
· rw [neg_le]
exact (neg_le_abs t).trans htu
· exact (le_abs_self t).trans htu
/-- If `ω ↦ exp (u * X ω)` is integrable at `u ≥ 0`, then it is integrable on `[0, u]`. -/
lemma integrable_exp_mul_of_nonneg_of_le [IsFiniteMeasure μ]
(hu : Integrable (fun ω ↦ exp (u * X ω)) μ) (h_nonneg : 0 ≤ t) (htu : t ≤ u) :
Integrable (fun ω ↦ exp (t * X ω)) μ :=
integrable_exp_mul_of_le_of_le (by simp) hu h_nonneg htu
/-- If `ω ↦ exp (u * X ω)` is integrable at `u ≤ 0`, then it is integrable on `[u, 0]`. -/
lemma integrable_exp_mul_of_nonpos_of_ge [IsFiniteMeasure μ]
(hu : Integrable (fun ω ↦ exp (u * X ω)) μ) (h_nonpos : t ≤ 0) (htu : u ≤ t) :
Integrable (fun ω ↦ exp (t * X ω)) μ :=
integrable_exp_mul_of_le_of_le hu (by simp) htu h_nonpos
end Interval
section IntegrableExpSet
/-- The interval of reals `t` for which `exp (t * X)` is integrable. -/
def integrableExpSet (X : Ω → ℝ) (μ : Measure Ω) : Set ℝ :=
{t | Integrable (fun ω ↦ exp (t * X ω)) μ}
lemma integrable_of_mem_integrableExpSet (h : t ∈ integrableExpSet X μ) :
Integrable (fun ω ↦ exp (t * X ω)) μ := h
/-- `integrableExpSet X μ` is a convex subset of `ℝ` (it is an interval). -/
lemma convex_integrableExpSet : Convex ℝ (integrableExpSet X μ) := by
rintro t₁ ht₁ t₂ ht₂ a b ha hb hab
wlog h_le : t₁ ≤ t₂
· rw [add_comm] at hab ⊢
exact this ht₂ ht₁ hb ha hab (not_le.mp h_le).le
refine integrable_exp_mul_of_le_of_le ht₁ ht₂ ?_ ?_
· simp only [smul_eq_mul]
calc t₁
_ = a * t₁ + b * t₁ := by rw [← add_mul, hab, one_mul]
_ ≤ a * t₁ + b * t₂ := by gcongr
· simp only [smul_eq_mul]
calc a * t₁ + b * t₂
_ ≤ a * t₂ + b * t₂ := by gcongr
_ = t₂ := by rw [← add_mul, hab, one_mul]
end IntegrableExpSet
section FiniteMoments
lemma aemeasurable_of_integrable_exp_mul (huv : u ≠ v)
(hu_int : Integrable (fun ω ↦ exp (u * X ω)) μ)
(hv_int : Integrable (fun ω ↦ exp (v * X ω)) μ) :
AEMeasurable X μ := by
by_cases hu : u = 0
· have hv : v ≠ 0 := ne_of_ne_of_eq huv.symm hu
exact aemeasurable_of_aemeasurable_exp_mul hv hv_int.aemeasurable
· exact aemeasurable_of_aemeasurable_exp_mul hu hu_int.aemeasurable
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then
`ω ↦ exp (t * |X| + v * X)` is integrable. -/
lemma integrable_exp_mul_abs_add (ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) :
Integrable (fun ω ↦ exp (t * |X ω| + v * X ω)) μ := by
have h_int_add : Integrable (fun a ↦ exp ((v + t) * X a) + exp ((v - t) * X a)) μ :=
ht_int_pos.add <| by simpa using ht_int_neg
refine Integrable.mono h_int_add ?_ (ae_of_all _ fun ω ↦ ?_)
· by_cases ht : t = 0
· simp only [ht, zero_mul, zero_add, add_zero] at ht_int_pos ⊢
exact ht_int_pos.1
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ ht_int_pos ht_int_neg
· fun_prop
· rw [← sub_ne_zero]
simp [ht]
· simp only [norm_eq_abs, abs_exp]
conv_rhs => rw [abs_of_nonneg (by positivity)]
-- ⊢ exp (t * |X ω| + v * X ω) ≤ exp ((v + t) * X ω) + exp ((v - t) * X ω)
rcases le_total 0 (X ω) with h_nonneg | h_nonpos
· rw [abs_of_nonneg h_nonneg, ← add_mul, add_comm, le_add_iff_nonneg_right]
positivity
· rw [abs_of_nonpos h_nonpos, mul_neg, mul_comm, ← mul_neg, mul_comm, ← add_mul, add_comm,
← sub_eq_add_neg, le_add_iff_nonneg_left]
positivity
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t`, then `ω ↦ exp (t * |X ω|)` is
integrable. -/
lemma integrable_exp_mul_abs (ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) :
Integrable (fun ω ↦ exp (t * |X ω|)) μ := by
have h := integrable_exp_mul_abs_add (t := t) (μ := μ) (X := X) (v := 0) ?_ ?_
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then
`ω ↦ exp (|t| * |X| + v * X)` is integrable. -/
lemma integrable_exp_abs_mul_abs_add (ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) :
Integrable (fun ω ↦ exp (|t| * |X ω| + v * X ω)) μ := by
rcases le_total 0 t with ht_nonneg | ht_nonpos
· simp_rw [abs_of_nonneg ht_nonneg]
exact integrable_exp_mul_abs_add ht_int_pos ht_int_neg
· simp_rw [abs_of_nonpos ht_nonpos]
exact integrable_exp_mul_abs_add ht_int_neg (by simpa using ht_int_pos)
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t`, then `ω ↦ exp (|t| * |X ω|)` is
integrable. -/
lemma integrable_exp_abs_mul_abs (ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) :
Integrable (fun ω ↦ exp (|t| * |X ω|)) μ := by
rcases le_total 0 t with ht_nonneg | ht_nonpos
· simp_rw [abs_of_nonneg ht_nonneg]
exact integrable_exp_mul_abs ht_int_pos ht_int_neg
· simp_rw [abs_of_nonpos ht_nonpos]
exact integrable_exp_mul_abs ht_int_neg (by simpa using ht_int_pos)
/-- Auxiliary lemma for `rpow_abs_le_mul_max_exp`. -/
lemma rpow_abs_le_mul_max_exp_of_pos (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : 0 < t) :
|x| ^ p ≤ (p / t) ^ p * max (exp (t * x)) (exp (-t * x)) := by
by_cases hp_zero : p = 0
· simp only [hp_zero, rpow_zero, zero_div, neg_mul, one_mul, le_sup_iff, one_le_exp_iff,
Left.nonneg_neg_iff]
exact le_total 0 (t * x)
have h_x_le c (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := le_inv_mul_exp x hc
have h_neg_x_le c (hc : 0 < c) : -x ≤ c⁻¹ * exp (-c * x) := by simpa using le_inv_mul_exp (-x) hc
have h_abs_le c (hc : 0 < c) : |x| ≤ c⁻¹ * max (exp (c * x)) (exp (-c * x)) := by
refine abs_le.mpr ⟨?_, ?_⟩
· rw [neg_le]
refine (h_neg_x_le c hc).trans ?_
gcongr
exact le_max_right _ _
· refine (h_x_le c hc).trans ?_
gcongr
exact le_max_left _ _
calc |x| ^ p
_ ≤ ((t / p)⁻¹ * max (exp (t / p * x)) (exp (-t / p * x))) ^ p := by
refine rpow_le_rpow (abs_nonneg _) ?_ hp
convert h_abs_le (t / p) (div_pos ht (hp.lt_of_ne' hp_zero)) using 5
rw [neg_div]
_ = (p / t) ^ p * max (exp (t * x)) (exp (-t * x)) := by
rw [mul_rpow (by positivity) (by positivity)]
congr
· simp
· rw [rpow_max (by positivity) (by positivity) hp, ← exp_mul, ← exp_mul]
ring_nf
congr <;> rw [mul_assoc, mul_inv_cancel₀ hp_zero, mul_one]
lemma rpow_abs_le_mul_max_exp (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : t ≠ 0) :
|x| ^ p ≤ (p / |t|) ^ p * max (exp (t * x)) (exp (-t * x)) := by
rcases lt_or_gt_of_ne ht with ht_neg | ht_pos
· rw [abs_of_nonpos ht_neg.le, sup_comm]
convert rpow_abs_le_mul_max_exp_of_pos x hp (t := -t) (by simp [ht_neg])
simp
· rw [abs_of_nonneg ht_pos.le]
exact rpow_abs_le_mul_max_exp_of_pos x hp ht_pos
lemma rpow_abs_le_mul_exp_abs (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : t ≠ 0) :
|x| ^ p ≤ (p / |t|) ^ p * exp (|t| * |x|) := by
refine (rpow_abs_le_mul_max_exp_of_pos x hp (t := |t|) ?_).trans_eq ?_
· simp [ht]
· congr
rcases le_total 0 x with hx | hx
· rw [abs_of_nonneg hx]
simp only [neg_mul, sup_eq_left, exp_le_exp, neg_le_self_iff]
positivity
· rw [abs_of_nonpos hx]
simp only [neg_mul, mul_neg, sup_eq_right, exp_le_exp, le_neg_self_iff]
exact mul_nonpos_of_nonneg_of_nonpos (abs_nonneg _) hx
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for nonnegative `p : ℝ` and any `x ∈ [0, |t|)`,
`|X| ^ p * exp (v * X + x * |X|)` is integrable. -/
lemma integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul {x : ℝ}
(h_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(h_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (h_nonneg : 0 ≤ x) (hx : x < |t|)
{p : ℝ} (hp : 0 ≤ p) :
Integrable (fun a ↦ |X a| ^ p * exp (v * X a + x * |X a|)) μ := by
have ht : t ≠ 0 := by
suffices |t| ≠ 0 by simpa
exact (h_nonneg.trans_lt hx).ne'
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ h_int_pos h_int_neg
swap; · rw [← sub_ne_zero]; simp [ht]
rw [← integrable_norm_iff]
swap; · fun_prop
simp only [norm_mul, norm_eq_abs, abs_exp]
have h_le a : |X a| ^ p * exp (v * X a + x * |X a|)
≤ (p / (|t| - x)) ^ p * exp (v * X a + |t| * |X a|) := by
simp_rw [exp_add, mul_comm (exp (v * X a)), ← mul_assoc]
gcongr ?_ * _
have : |t| = |t| - x + x := by simp
nth_rw 2 [this]
rw [add_mul, exp_add, ← mul_assoc]
gcongr ?_ * _
convert rpow_abs_le_mul_exp_abs (X a) hp (t := |t| - x) _ using 4
· nth_rw 2 [abs_of_nonneg]
simp [hx.le]
· nth_rw 2 [abs_of_nonneg]
simp [hx.le]
· rw [sub_ne_zero]
exact hx.ne'
refine Integrable.mono (g := fun a ↦ (p / (|t| - x)) ^ p * exp (v * X a + |t| * |X a|))
?_ ?_ <| ae_of_all _ fun ω ↦ ?_
· refine Integrable.const_mul ?_ _
simp_rw [add_comm (v * X _)]
exact integrable_exp_abs_mul_abs_add h_int_pos h_int_neg
· fun_prop
· simp only [norm_mul, norm_eq_abs, abs_exp]
simp_rw [abs_rpow_of_nonneg (abs_nonneg _), abs_abs]
refine (h_le ω).trans_eq ?_
congr
symm
simp only [abs_eq_self]
exact rpow_nonneg (div_nonneg hp (sub_nonneg_of_le hx.le)) _
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for any `n : ℕ` and any `x ∈ [0, |t|)`,
`|X| ^ n * exp (v * X + x * |X|)` is integrable. -/
lemma integrable_pow_abs_mul_exp_add_of_integrable_exp_mul {x : ℝ}
(h_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(h_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (h_nonneg : 0 ≤ x) (hx : x < |t|)
(n : ℕ) :
Integrable (fun a ↦ |X a| ^ n * exp (v * X a + x * |X a|)) μ := by
convert integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul h_int_pos h_int_neg h_nonneg hx
n.cast_nonneg
simp
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for nonnegative `p : ℝ`, `|X| ^ p * exp (v * X)` is integrable. -/
lemma integrable_rpow_abs_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul ht_int_pos ht_int_neg le_rfl _ hp
using 4
· simp
· simp [ht]
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all `n : ℕ`,
`|X| ^ n * exp (v * X)` is integrable. -/
lemma integrable_pow_abs_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all nonnegative `p : ℝ`,
`X ^ p * exp (v * X)` is integrable. -/
lemma integrable_rpow_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p * exp (v * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ ht_int_pos ht_int_neg
swap; · rw [← sub_ne_zero]; simp [ht]
rw [← integrable_norm_iff]
· simp_rw [norm_eq_abs, abs_mul, abs_exp]
have h := integrable_rpow_abs_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg hp
refine h.mono' ?_ ?_
· fun_prop
· refine ae_of_all _ fun ω ↦ ?_
simp only [norm_mul, norm_eq_abs, abs_abs, abs_exp]
gcongr
exact abs_rpow_le_abs_rpow _ _
· fun_prop
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all `n : ℕ`,
`X ^ n * exp (v * X)` is integrable. -/
lemma integrable_pow_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ |X ω| ^ p` is
integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p) μ := by
have h := integrable_rpow_abs_mul_exp_of_integrable_exp_mul (μ := μ) (X := X) ht (v := 0) ?_ ?_ hp
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ |X ω| ^ n` is
integrable for all `n : ℕ`. That is, all moments of `X` are finite. -/
lemma integrable_pow_abs_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n) μ := by
convert integrable_rpow_abs_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ X ω ^ p` is
integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p) μ := by
have h := integrable_rpow_mul_exp_of_integrable_exp_mul (μ := μ) (X := X) ht (v := 0) ?_ ?_ hp
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ X ω ^ n` is
integrable for all `n : ℕ`. -/
lemma integrable_pow_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n) μ := by
convert integrable_rpow_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
section IntegrableExpSet
lemma add_half_inf_sub_mem_Ioo {l u v : ℝ} (hv : v ∈ Set.Ioo l u) :
v + ((v - l) ⊓ (u - v)) / 2 ∈ Set.Ioo l u := by
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hv.1, hv.2]
constructor
· calc l < v := hv.1
_ ≤ v + ((v - l) ⊓ (u - v)) / 2 := le_add_of_nonneg_right (by positivity)
· calc v + ((v - l) ⊓ (u - v)) / 2
_ < v + ((v - l) ⊓ (u - v)) := by gcongr; exact half_lt_self (by positivity)
_ ≤ v + (u - v) := by gcongr; exact inf_le_right
_ = u := by abel
lemma sub_half_inf_sub_mem_Ioo {l u v : ℝ} (hv : v ∈ Set.Ioo l u) :
v - ((v - l) ⊓ (u - v)) / 2 ∈ Set.Ioo l u := by
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hv.1, hv.2]
constructor
· calc l = v - (v - l) := by abel
_ ≤ v - ((v - l) ⊓ (u - v)) := by gcongr; exact inf_le_left
_ < v - ((v - l) ⊓ (u - v)) / 2 := by gcongr; exact half_lt_self (by positivity)
· calc v - ((v - l) ⊓ (u - v)) / 2
_ ≤ v := by
rw [sub_le_iff_le_add]
exact le_add_of_nonneg_right (by positivity)
_ < u := hv.2
/-- If the interior of the interval `integrableExpSet X μ` is nonempty,
then `X` is a.e. measurable. -/
lemma aemeasurable_of_mem_interior_integrableExpSet (hv : v ∈ interior (integrableExpSet X μ)) :
AEMeasurable X μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
let t := ((v - l) ⊓ (u - v)) / 2
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
have ht : 0 < t := half_pos h_pos
by_cases hvt : v + t = 0
· have hvt' : v - t ≠ 0 := by
rw [sub_ne_zero]
refine fun h_eq ↦ ht.ne' ?_
simpa [h_eq] using hvt
exact aemeasurable_of_aemeasurable_exp_mul hvt'
(h_subset (sub_half_inf_sub_mem_Ioo hvlu)).aemeasurable
· exact aemeasurable_of_aemeasurable_exp_mul hvt
(h_subset (add_half_inf_sub_mem_Ioo hvlu)).aemeasurable
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ p * exp (v * X)` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p * exp (v * X ω)) μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
refine integrable_rpow_abs_mul_exp_of_integrable_exp_mul
(t := min (v - l) (u - v) / 2) ?_ ?_ ?_ hp
· positivity
· exact h_subset (add_half_inf_sub_mem_Ioo hvlu)
· exact h_subset (sub_half_inf_sub_mem_Ioo hvlu)
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n * exp (v * X)` is integrable for all `n : ℕ`. -/
lemma integrable_pow_abs_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hv
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ p * exp (v * X)` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p * exp (v * X ω)) μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
refine integrable_rpow_mul_exp_of_integrable_exp_mul
(t := min (v - l) (u - v) / 2) ?_ ?_ ?_ hp
· positivity
· exact h_subset (add_half_inf_sub_mem_Ioo hvlu)
· exact h_subset (sub_half_inf_sub_mem_Ioo hvlu)
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n * exp (v * X)` is integrable for all `n : ℕ`. -/
lemma integrable_pow_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_mul_exp_of_mem_interior_integrableExpSet hv
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p) μ := by
convert integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet h hp using 1
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n` is integrable for all `n : ℕ`. -/
lemma integrable_pow_abs_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n) μ := by
convert integrable_pow_abs_mul_exp_of_mem_interior_integrableExpSet h n
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p) μ := by
convert integrable_rpow_mul_exp_of_mem_interior_integrableExpSet h hp using 1
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n` is integrable for all `n : ℕ`. -/
lemma integrable_pow_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n) μ := by
convert integrable_pow_mul_exp_of_mem_interior_integrableExpSet h n
simp
/-- If 0 belongs to the interior of `integrableExpSet X μ`, then `X` is in `ℒp` for all
finite `p`. -/
lemma memLp_of_mem_interior_integrableExpSet (h : 0 ∈ interior (integrableExpSet X μ)) (p : ℝ≥0) :
MemLp X p μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet h
by_cases hp_zero : p = 0
· simp only [hp_zero, ENNReal.coe_zero, memLp_zero_iff_aestronglyMeasurable]
exact hX.aestronglyMeasurable
rw [← integrable_norm_rpow_iff hX.aestronglyMeasurable (mod_cast hp_zero) (by simp)]
simp only [norm_eq_abs, ENNReal.coe_toReal]
exact integrable_rpow_abs_of_mem_interior_integrableExpSet h p.2
section Complex
open Complex
variable {z : ℂ}
lemma integrable_cexp_mul_of_re_mem_integrableExpSet (hX : AEMeasurable X μ)
(hz : z.re ∈ integrableExpSet X μ) :
Integrable (fun ω ↦ cexp (z * X ω)) μ := by
rw [← integrable_norm_iff]
· simpa [Complex.norm_exp] using hz
· fun_prop
lemma integrable_cexp_mul_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) :
Integrable (fun ω ↦ cexp (z * X ω)) μ :=
integrable_cexp_mul_of_re_mem_integrableExpSet
(aemeasurable_of_mem_interior_integrableExpSet hz) (interior_subset hz)
lemma integrable_rpow_abs_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ (|X ω| ^ p : ℝ) * cexp (z * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet hz
rw [← integrable_norm_iff]
swap; · fun_prop
simpa [abs_rpow_of_nonneg (abs_nonneg _), Complex.norm_exp]
using integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hz hp
lemma integrable_pow_abs_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * cexp (z * X ω)) μ := by
convert integrable_rpow_abs_mul_cexp_of_re_mem_interior_integrableExpSet hz (Nat.cast_nonneg n)
simp
lemma integrable_rpow_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ (X ω ^ p : ℝ) * cexp (z * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet hz
rw [← integrable_norm_iff]
swap; · fun_prop
simp only [norm_mul, norm_real, Complex.norm_exp, mul_re, ofReal_re,
ofReal_im, mul_zero, sub_zero]
refine (integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hz hp).mono ?_ ?_
· fun_prop
refine ae_of_all _ fun ω ↦ ?_
simp only [norm_mul, Real.norm_eq_abs, Real.abs_exp]
gcongr
exact abs_rpow_le_abs_rpow _ _
lemma integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * cexp (z * X ω)) μ := by
convert integrable_rpow_mul_cexp_of_re_mem_interior_integrableExpSet hz (Nat.cast_nonneg n)
simp
end Complex
end IntegrableExpSet
end FiniteMoments
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Moments/CovarianceBilin.lean | import Mathlib.Analysis.InnerProductSpace.Positive
import Mathlib.Analysis.Normed.Lp.MeasurableSpace
import Mathlib.MeasureTheory.SpecificCodomains.WithLp
import Mathlib.Probability.Moments.Basic
import Mathlib.Probability.Moments.CovarianceBilinDual
/-!
# Covariance in Hilbert spaces
Given a measure `μ` defined over a Banach space `E`, one can consider the associated covariance
bilinear form which maps `L₁ L₂ : StrongDual ℝ E` to `cov[L₁, L₂; μ]`. This is called
`covarianceBilinDual μ` and is defined in the `CovarianceBilinDual` file.
In the special case where `E` is a Hilbert space, each `L : StrongDual ℝ E` can be represented
as the scalar product against some element of `E`. This motivates the definition of
`covarianceBilin`, which is a continuous bilinear form mapping `x y : E` to
`cov[⟪x, ·⟫, ⟪y, ·⟫; μ]`.
## Main definitions
* `covarianceBilin μ`: the continuous bilinear form over `E` representing the covariance of a
measure over `E`.
* `covarianceOperator μ`: the bounded operator over `E` such that
`⟪covarianceOperator μ x, y⟫ = ∫ z, ⟪x, z⟫ * ⟪y, z⟫ ∂μ`.
## Tags
covariance, Hilbert space, bilinear form
-/
open MeasureTheory InnerProductSpace NormedSpace WithLp EuclideanSpace
open scoped RealInnerProductSpace
namespace ProbabilityTheory
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] {μ : Measure E}
/-- Covariance of a measure on an inner product space, as a continuous bilinear form. -/
noncomputable
def covarianceBilin (μ : Measure E) : E →L[ℝ] E →L[ℝ] ℝ :=
ContinuousLinearMap.bilinearComp (covarianceBilinDual μ)
(toDualMap ℝ E).toContinuousLinearMap (toDualMap ℝ E).toContinuousLinearMap
@[simp]
lemma covarianceBilin_zero : covarianceBilin (0 : Measure E) = 0 := by
rw [covarianceBilin]
simp
lemma covarianceBilin_eq_covarianceBilinDual (x y : E) :
covarianceBilin μ x y = covarianceBilinDual μ (toDualMap ℝ E x) (toDualMap ℝ E y) := rfl
@[simp]
lemma covarianceBilin_of_not_memLp (h : ¬MemLp id 2 μ) :
covarianceBilin μ = 0 := by
ext
simp [covarianceBilin_eq_covarianceBilinDual, h]
lemma covarianceBilin_apply [CompleteSpace E] [IsFiniteMeasure μ] (h : MemLp id 2 μ) (x y : E) :
covarianceBilin μ x y = ∫ z, ⟪x, z - μ[id]⟫ * ⟪y, z - μ[id]⟫ ∂μ := by
simp [covarianceBilin, covarianceBilinDual_apply' h]
lemma covarianceBilin_comm (x y : E) :
covarianceBilin μ x y = covarianceBilin μ y x := by
rw [covarianceBilin_eq_covarianceBilinDual, covarianceBilinDual_comm,
covarianceBilin_eq_covarianceBilinDual]
lemma covarianceBilin_self [CompleteSpace E] [IsFiniteMeasure μ] (h : MemLp id 2 μ) (x : E) :
covarianceBilin μ x x = Var[fun u ↦ ⟪x, u⟫; μ] := by
rw [covarianceBilin_eq_covarianceBilinDual, covarianceBilinDual_self_eq_variance h]
rfl
lemma covarianceBilin_apply_eq_cov [CompleteSpace E] [IsFiniteMeasure μ]
(h : MemLp id 2 μ) (x y : E) :
covarianceBilin μ x y = cov[fun u ↦ ⟪x, u⟫, fun u ↦ ⟪y, u⟫; μ] := by
rw [covarianceBilin_eq_covarianceBilinDual, covarianceBilinDual_eq_covariance h]
rfl
lemma covarianceBilin_real {μ : Measure ℝ} [IsFiniteMeasure μ] (x y : ℝ) :
covarianceBilin μ x y = x * y * Var[id; μ] := by
by_cases h : MemLp id 2 μ
· simp only [covarianceBilin_apply_eq_cov h, RCLike.inner_apply, conj_trivial, mul_comm]
rw [covariance_mul_left, covariance_mul_right, ← mul_assoc, covariance_self aemeasurable_id']
rfl
· simp [h, variance_of_not_memLp, aestronglyMeasurable_id]
lemma covarianceBilin_real_self {μ : Measure ℝ} [IsFiniteMeasure μ] (x : ℝ) :
covarianceBilin μ x x = x ^ 2 * Var[id; μ] := by
rw [covarianceBilin_real, pow_two]
@[simp]
lemma covarianceBilin_self_nonneg (x : E) :
0 ≤ covarianceBilin μ x x := by
simp [covarianceBilin]
lemma isPosSemidef_covarianceBilin :
(covarianceBilin μ).toBilinForm.IsPosSemidef where
eq := covarianceBilin_comm
nonneg := covarianceBilin_self_nonneg
lemma covarianceBilin_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[MeasurableSpace F] [BorelSpace F] [SecondCountableTopology F] [CompleteSpace F]
[CompleteSpace E] [IsFiniteMeasure μ] (h : MemLp id 2 μ) (L : E →L[ℝ] F) (u v : F) :
covarianceBilin (μ.map L) u v = covarianceBilin μ (L.adjoint u) (L.adjoint v) := by
rw [covarianceBilin_apply, covarianceBilin_apply h]
· simp_rw [id, L.integral_id_map (h.integrable (by simp))]
rw [integral_map]
· simp_rw [← map_sub, ← L.adjoint_inner_left]
all_goals fun_prop
· exact memLp_map_measure_iff (by fun_prop) (by fun_prop) |>.2 (L.comp_memLp' h)
lemma covarianceBilin_map_const_add [CompleteSpace E] [IsProbabilityMeasure μ] (c : E) :
covarianceBilin (μ.map (fun x ↦ c + x)) = covarianceBilin μ := by
by_cases h : MemLp id 2 μ
· ext x y
have h_Lp : MemLp id 2 (μ.map (fun x ↦ c + x)) :=
(measurableEmbedding_addLeft _).memLp_map_measure_iff.mpr <| (memLp_const c).add h
rw [covarianceBilin_apply h_Lp,
covarianceBilin_apply h, integral_map (by fun_prop) (by fun_prop)]
congr with z
rw [integral_map (by fun_prop) h_Lp.1]
simp only [id_eq]
rw [integral_add (integrable_const _)]
· simp
· exact h.integrable (by simp)
· ext
rw [covarianceBilin_of_not_memLp, covarianceBilin_of_not_memLp h]
rw [(measurableEmbedding_addLeft _).memLp_map_measure_iff.not]
contrapose! h
convert (memLp_const (-c)).add h
ext; simp
lemma covarianceBilin_apply_basisFun {ι Ω : Type*} [Fintype ι] {mΩ : MeasurableSpace Ω}
{μ : Measure Ω} [IsFiniteMeasure μ] {X : ι → Ω → ℝ} (hX : ∀ i, MemLp (X i) 2 μ) (i j : ι) :
covarianceBilin (μ.map (fun ω ↦ toLp 2 (X · ω)))
(basisFun ι ℝ i) (basisFun ι ℝ j) = cov[X i, X j; μ] := by
have (i : ι) := (hX i).aemeasurable
rw [covarianceBilin_apply_eq_cov, covariance_map]
· simp [basisFun_inner]; rfl
· exact Measurable.aestronglyMeasurable (by fun_prop)
· exact Measurable.aestronglyMeasurable (by fun_prop)
· fun_prop
· exact (memLp_map_measure_iff aestronglyMeasurable_id (by fun_prop)).2 (MemLp.of_eval_piLp hX)
lemma covarianceBilin_apply_basisFun_self {ι Ω : Type*} [Fintype ι] {mΩ : MeasurableSpace Ω}
{μ : Measure Ω} [IsFiniteMeasure μ] {X : ι → Ω → ℝ} (hX : ∀ i, MemLp (X i) 2 μ) (i : ι) :
covarianceBilin (μ.map (fun ω ↦ toLp 2 (X · ω)))
(basisFun ι ℝ i) (basisFun ι ℝ i) = Var[X i; μ] := by
rw [covarianceBilin_apply_basisFun hX, covariance_self]
have (i : ι) := (hX i).aemeasurable
fun_prop
lemma covarianceBilin_apply_pi {ι Ω : Type*} [Fintype ι] {mΩ : MeasurableSpace Ω}
{μ : Measure Ω} [IsFiniteMeasure μ] {X : ι → Ω → ℝ}
(hX : ∀ i, MemLp (X i) 2 μ) (x y : EuclideanSpace ℝ ι) :
covarianceBilin (μ.map (fun ω ↦ toLp 2 (X · ω))) x y =
∑ i, ∑ j, x i * y j * cov[X i, X j; μ] := by
have (i : ι) := (hX i).aemeasurable
nth_rw 1 [covarianceBilin_apply_eq_cov, covariance_map_fun, ← (basisFun ι ℝ).sum_repr' x,
← (basisFun ι ℝ).sum_repr' y]
· simp_rw [sum_inner, real_inner_smul_left, basisFun_inner]
rw [covariance_fun_sum_fun_sum]
· refine Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ ?_
rw [covariance_mul_left, covariance_mul_right]
ring
all_goals exact fun i ↦ (hX i).const_mul _
any_goals exact Measurable.aestronglyMeasurable (by fun_prop)
· fun_prop
· exact (memLp_map_measure_iff aestronglyMeasurable_id (by fun_prop)).2 (MemLp.of_eval_piLp hX)
section covarianceOperator
variable [CompleteSpace E]
/-- The covariance operator of the measure `μ`. This is the bounded operator `F : E →L[ℝ] E`
associated to the continuous bilinear form `B : E →L[ℝ] E →L[ℝ] ℝ` such that
`B x y = ∫ z, ⟪x, z⟫ * ⟪y, z⟫ ∂μ` (see `covarianceOperator_inner`). Namely we have
`B x y = ⟪F x, y⟫`.
Note that the bilinear form `B` is the _uncentered_ covariance bilinear form associated to the
measure `µ`, which is not to be confused with the covariance bilinear form defined earlier in this
file as `covarianceBilin μ`. -/
noncomputable def covarianceOperator (μ : Measure E) : E →L[ℝ] E :=
continuousLinearMapOfBilin <| ContinuousLinearMap.bilinearComp (uncenteredCovarianceBilinDual μ)
(toDualMap ℝ E).toContinuousLinearMap (toDualMap ℝ E).toContinuousLinearMap
@[simp]
lemma covarianceOperator_zero : covarianceOperator (0 : Measure E) = 0 := by
simp [covarianceOperator]
@[simp]
lemma covarianceOperator_of_not_memLp (hμ : ¬MemLp id 2 μ) :
covarianceOperator μ = 0 := by
ext x
refine (unique_continuousLinearMapOfBilin _ fun y ↦ ?_).symm
simp [hμ, uncenteredCovarianceBilinDual_of_not_memLp]
lemma covarianceOperator_inner (hμ : MemLp id 2 μ) (x y : E) :
⟪covarianceOperator μ x, y⟫ = ∫ z, ⟪x, z⟫ * ⟪y, z⟫ ∂μ := by
simp [covarianceOperator, uncenteredCovarianceBilinDual_apply hμ]
lemma covarianceOperator_apply (hμ : MemLp id 2 μ) (x : E) :
covarianceOperator μ x = ∫ y, ⟪x, y⟫ • y ∂μ := by
refine (unique_continuousLinearMapOfBilin _ fun y ↦ ?_).symm
rw [real_inner_comm, ← integral_inner]
· simp_rw [inner_smul_right, ← continuousLinearMapOfBilin_apply, ← covarianceOperator_inner hμ]
rfl
exact memLp_one_iff_integrable.1 <| hμ.smul (hμ.const_inner x)
lemma isPositive_covarianceOperator : (covarianceOperator μ).toLinearMap.IsPositive := by
by_cases hμ : MemLp id 2 μ
swap; · simp [hμ]
refine ⟨fun x y ↦ ?_, fun x ↦ ?_⟩
· simp_rw [ContinuousLinearMap.coe_coe, real_inner_comm _ x, covarianceOperator_inner hμ,
mul_comm]
· simp only [ContinuousLinearMap.coe_coe, covarianceOperator_inner hμ, ← pow_two,
RCLike.re_to_real]
positivity
end covarianceOperator
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/BoundedContinuousFunction.lean | import Mathlib.MeasureTheory.Measure.HasOuterApproxClosedProd
import Mathlib.Probability.Independence.Process
import Mathlib.Probability.Notation
/-!
# Characterizing independence via bounded continuous functions
Given two random variables `X : Ω → E` and `Y : Ω → F` such that `E` and `F` are Borel spaces
satisfying `HasOuterApproxClosed`, `X` and `Y` are independent if for any real bounded continuous
functions `f` and `g`, `∫ ω, f (X ω) * g (Y ω) ∂P = (∫ ω, f (X ω) ∂P) * (∫ ω, g (Y ω) ∂P)`.
Consider now `X : (s : S) → Ω → E s`, with `Fintype S` and each `E s` being a Borel space satisfying
`HasOuterApproxClosed`. Then to apply the above result we need that `Π s, E s` is a Borel space,
and therefore that each `E s` is second countable. We can circumvent this restriction by proving
that `fun ω s ↦ X s ω` and `Y` are independent if for any family of bounded continuous functions
`f : (s : S) → E s → ℝ` and any bounded continuous function `g : F → ℝ` we have
`∫ ω, ∏ s, f s (X s ω) * g (Y ω) ∂P = ∫ ω, ∏ s, f s (X s ω) ∂P * ∫ ω, g (Y ω) ∂P`.
We can use this result in the case where `S := Unit` to deduce the first statement we mentioned.
We take this approach in this file. We first prove `pi_indepFun_pi_of_prod_bcf`, which allows to
prove the result when `E` and `F` are product spaces without assuming second countability, and
then we deduce the other cases from there.
Building on this, we also prove `process_indepFun_process_of_prod_bcf`. This time we do not require
`Fintype S` and require the hypothesis to be satisfied for each `I : Finset S`. Then we similarly
deduce other versions where one of the variables is not necessarily a process.
We then turn to independence between an event and a random variable. We prove
`indicator_indepFun_pi_of_prod_bcf`: the indicator of an event `A` is independent
of a finite family of random variables `X : (s : S) → Ω → E s` if for any family of bounded
continuous functions `f : (s : S) → E s → ℝ` we have
`∫ ω in A, ∏ s, f s (X s ω) ∂P = P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P`. Once again we deduce
other versions from this, and also write versions where `X` is a stochastic process.
Then we build on that to show that a `σ`-algebra `m` is independent from a stochastic process `X`
if for any `A` such that `MeasurableSet[m] A`, any `I : Finset S` and any bounded continuous
function `f : (Π s : I, E s) → ℝ`, we have `∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P`.
This again is formulated with different versions. We also provide versions in terms of
`IndepSets` instead of `Indep`.
# Main statement
* `indep_comap_process_of_bcf`: A `σ`-algebra `m` is independent from a stochastic process `X`
if for any `A` such that `MeasurableSet[m] A`, any `I : Finset S`, and any bounded continuous
function `f : (Π s : I, E s) → ℝ`, we have
`∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P`.
# Notations
to avoid writing `boundedContinuousFunction` in the names, which is quite lengthy, we abbreviate it
to `bcf`.
# Tags
independence, bounded continuous functions
-/
open MeasureTheory Measure ProbabilityTheory ENNReal
open scoped BoundedContinuousFunction
variable {Ω S T : Type*} {m mΩ : MeasurableSpace Ω} {P : Measure Ω}
/-- If the indicator of a set `A` is indepent from a variable `X`, then set `A` is independent
from the sigma algebra generated by `X`. -/
lemma IndepFun.singleton_indepSets_of_indicator {𝓧 : Type*} [mX : MeasurableSpace 𝓧] {A : Set Ω}
{X : Ω → 𝓧} (h : (A.indicator (1 : Ω → ℝ)) ⟂ᵢ[P] X) :
IndepSets {A} {s | MeasurableSet[mX.comap X] s} P := by
rw [IndepSets_iff]
rintro s - hs ⟨t, ht, rfl⟩
rw [Set.mem_singleton_iff.1 hs]
have hA' : A = A.indicator (1 : Ω → ℝ) ⁻¹' {1} := by ext; simp [Set.indicator]
rw [hA']
exact h.measure_inter_preimage_eq_mul _ _ (by simp) ht
variable {E : S → Type*} {F : T → Type*} {G H : Type*}
[∀ s, TopologicalSpace (E s)] [∀ s, MeasurableSpace (E s)] [∀ s, BorelSpace (E s)]
[∀ s, HasOuterApproxClosed (E s)]
[∀ t, TopologicalSpace (F t)] [∀ t, MeasurableSpace (F t)] [∀ t, BorelSpace (F t)]
[∀ t, HasOuterApproxClosed (F t)]
[TopologicalSpace G] [MeasurableSpace G] [BorelSpace G] [HasOuterApproxClosed G]
[TopologicalSpace H] [MeasurableSpace H] [BorelSpace H] [HasOuterApproxClosed H]
{X : (s : S) → Ω → E s} {Y : (t : T) → Ω → F t} {Z : Ω → G} {U : Ω → H}
section Fintype
variable [Fintype S] [Fintype T]
section IndepFun
variable [IsFiniteMeasure P]
lemma pi_indepFun_pi_of_prod_bcf (mX : ∀ s, AEMeasurable (X s) P)
(mY : ∀ t, AEMeasurable (Y t) P)
(h : ∀ (f : (s : S) → E s →ᵇ ℝ) (g : (t : T) → F t →ᵇ ℝ),
P[(∏ s, f s ∘ (X s)) * (∏ t, g t ∘ (Y t))] = P[∏ s, f s ∘ (X s)] * P[∏ t, g t ∘ (Y t)]) :
IndepFun (fun ω s ↦ X s ω) (fun ω t ↦ Y t ω) P := by
rw [indepFun_iff_map_prod_eq_prod_map_map (aemeasurable_pi_lambda _ mX)
(aemeasurable_pi_lambda _ mY)]
refine eq_prod_of_integral_prod_mul_prod_boundedContinuousFunction fun f g ↦ ?_
rw [integral_map, integral_map, integral_map]
· convert h f g <;> simp
any_goals fun_prop
all_goals exact Measurable.aestronglyMeasurable (by fun_prop)
/-- Two families of random variables $(X_1, ..., X_p)$ and $(Y_1, ..., Y_q)$ are independent if
for all real bounded continuous functions $f$ and $g$,
$$P[f(X_1, ..., X_p) g(Y_1, ..., Y_q)] = P[f(X_1, ..., X_p)] * P[g(Y_1, ..., Y_q)].$$ -/
lemma pi_indepFun_pi_of_bcf (mX : ∀ s, AEMeasurable (X s) P)
(mY : ∀ t, AEMeasurable (Y t) P)
(h : ∀ (f : (Π s, E s) →ᵇ ℝ) (g : (Π t, F t) →ᵇ ℝ),
P[fun ω ↦ f (X · ω) * g (Y · ω)] = P[fun ω ↦ f (X · ω)] * P[fun ω ↦ g (Y · ω)]) :
IndepFun (fun ω s ↦ X s ω) (fun ω t ↦ Y t ω) P := by
refine pi_indepFun_pi_of_prod_bcf mX mY fun f g ↦ ?_
convert h (∏ s, (f s).compContinuous ⟨Function.eval s, by fun_prop⟩)
(∏ t, (g t).compContinuous ⟨Function.eval t, by fun_prop⟩) <;> simp
lemma indepFun_pi_of_prod_bcf (mZ : AEMeasurable Z P)
(mY : ∀ t, AEMeasurable (Y t) P)
(h : ∀ (f : G →ᵇ ℝ) (g : (t : T) → F t →ᵇ ℝ),
P[f ∘ Z * (∏ t, g t ∘ (Y t))] = P[f ∘ Z] * P[∏ t, g t ∘ (Y t)]) :
IndepFun Z (fun ω t ↦ Y t ω) P := by
rw [indepFun_iff_map_prod_eq_prod_map_map mZ (aemeasurable_pi_lambda _ mY)]
refine eq_prod_of_integral_mul_prod_boundedContinuousFunction fun f g ↦ ?_
rw [integral_map, integral_map, integral_map]
· convert h f g <;> simp
any_goals fun_prop
all_goals exact Measurable.aestronglyMeasurable (by fun_prop)
lemma indepFun_pi_of_bcf (mZ : AEMeasurable Z P)
(mY : ∀ t, AEMeasurable (Y t) P)
(h : ∀ (f : G →ᵇ ℝ) (g : (Π t, F t) →ᵇ ℝ),
P[fun ω ↦ f (Z ω) * g (Y · ω)] = P[f ∘ Z] * P[fun ω ↦ g (Y · ω)]) :
IndepFun Z (fun ω t ↦ Y t ω) P := by
refine indepFun_pi_of_prod_bcf mZ mY fun f g ↦ ?_
convert h f (∏ t, (g t).compContinuous ⟨Function.eval t, by fun_prop⟩) <;> simp
lemma pi_indepFun_of_prod_bcf (mX : ∀ s, AEMeasurable (X s) P)
(mU : AEMeasurable U P)
(h : ∀ (f : (s : S) → E s →ᵇ ℝ) (g : H →ᵇ ℝ),
P[(∏ s, f s ∘ (X s)) * g ∘ U] = P[∏ s, f s ∘ (X s)] * P[g ∘ U]) :
IndepFun (fun ω s ↦ X s ω) U P := by
rw [indepFun_iff_map_prod_eq_prod_map_map (aemeasurable_pi_lambda _ mX) mU]
refine eq_prod_of_integral_prod_mul_boundedContinuousFunction fun f g ↦ ?_
rw [integral_map, integral_map, integral_map]
· convert h f g <;> simp
any_goals fun_prop
all_goals exact Measurable.aestronglyMeasurable (by fun_prop)
lemma pi_indepFun_of_bcf (mX : ∀ s, AEMeasurable (X s) P)
(mU : AEMeasurable U P)
(h : ∀ (f : (Π s, E s) →ᵇ ℝ) (g : H →ᵇ ℝ),
P[fun ω ↦ f (X · ω) * g (U ω)] = P[fun ω ↦ f (X · ω)] * P[g ∘ U]) :
IndepFun (fun ω s ↦ X s ω) U P := by
refine pi_indepFun_of_prod_bcf mX mU fun f g ↦ ?_
convert h (∏ s, (f s).compContinuous ⟨Function.eval s, by fun_prop⟩) g <;> simp
/-- Two random variables $X$ and $Y$ are independent if
for all real bounded continuous functions $f$ and $g$,
$$P[f(X) g(Y)] = P[f(X)] * P[g(Y)].$$ -/
lemma indepFun_of_bcf (mZ : AEMeasurable Z P) (mU : AEMeasurable U P)
(h : ∀ (f : G →ᵇ ℝ) (g : H →ᵇ ℝ), P[f ∘ Z * g ∘ U] = P[f ∘ Z] * P[g ∘ U]) :
IndepFun Z U P := by
rw [indepFun_iff_map_prod_eq_prod_map_map mZ mU]
refine eq_prod_of_integral_mul_boundedContinuousFunction fun f g ↦ ?_
rw [integral_map, integral_map, integral_map]
· exact h f g
any_goals fun_prop
exact Measurable.aestronglyMeasurable (by fun_prop)
end IndepFun
variable [IsProbabilityMeasure P]
section Indicator
lemma indicator_indepFun_pi_of_prod_bcf
{A : Set Ω} (mA : NullMeasurableSet A P) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ f : (s : S) → E s →ᵇ ℝ, ∫ ω in A, ∏ s, f s (X s ω) ∂P =
P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
(A.indicator (1 : Ω → ℝ)) ⟂ᵢ[P] (fun ω s ↦ X s ω) := by
refine indepFun_pi_of_prod_bcf
((aemeasurable_indicator_const_iff 1).2 mA) mX fun f g ↦ ?_
have h1 ω : f (A.indicator 1 ω) * ∏ s, g s (X s ω) =
A.indicator (fun ω ↦ f 1 * ∏ s, g s (X s ω)) ω +
f 0 * ∏ s, g s (X s ω) - A.indicator (fun ω ↦ f 0 * ∏ s, g s (X s ω)) ω := by
classical
rw [Set.indicator_apply]
split_ifs <;> simp_all
have h2 ω : f (A.indicator 1 ω) =
A.indicator (fun _ ↦ f 1) ω + Aᶜ.indicator (fun _ ↦ f 0) ω := by
classical
rw [Set.indicator_apply]
split_ifs <;> simp_all
have hg {c : ℝ} : Integrable (fun ω ↦ c * ∏ s, g s (X s ω)) P := by
refine Integrable.of_bound ?_ (‖c‖ * ∏ s, ‖g s‖) (ae_of_all _ fun ω ↦ ?_)
· exact (Finset.aestronglyMeasurable_fun_prod _ fun s _ ↦
(g s).continuous.aestronglyMeasurable.comp_aemeasurable (mX s)).const_mul _
· rw [norm_mul, norm_prod]
gcongr with s
exact (g s).norm_coe_le_norm _
simp_rw [Pi.mul_apply, Finset.prod_apply, Function.comp_apply, h1, h2]
rw [integral_sub, integral_add, integral_indicator₀ mA, integral_indicator₀ mA,
integral_const_mul, integral_const_mul, integral_const_mul, integral_add,
integral_indicator₀ mA, integral_indicator₀ mA.compl, integral_const, integral_const, h]
· simp [measureReal_compl₀ mA]
ring
· exact (integrable_const _).indicator₀ mA
· exact (integrable_const _).indicator₀ mA.compl
· exact hg.indicator₀ mA
· exact hg
· exact (hg.indicator₀ mA).add hg
· exact hg.indicator₀ mA
/-- The indicator of a set $A$ and a family of random variables $(X_1, ..., X_p)$ are independent
if for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X_1, ..., X_p)] = P(A) P[f(X_1, ..., X_p)].$$ -/
lemma indicator_indepFun_pi_of_bcf
{A : Set Ω} (mA : NullMeasurableSet A P) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ f : (Π s, E s) →ᵇ ℝ, ∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
(A.indicator (1 : Ω → ℝ)) ⟂ᵢ[P] (fun ω s ↦ X s ω) := by
refine indicator_indepFun_pi_of_prod_bcf mA mX fun f ↦ ?_
convert h (∏ s, (f s).compContinuous ⟨Function.eval s, by fun_prop⟩) <;> simp
/-- The indicator of a set $A$ and a random variable $X$ are independent
if for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X)] = P(A) P[f(X)].$$ -/
lemma indicator_indepFun_of_bcf
{A : Set Ω} (mA : NullMeasurableSet A P) (mZ : AEMeasurable Z P)
(h : ∀ f : G →ᵇ ℝ, ∫ ω in A, f (Z ω) ∂P = P.real A * ∫ ω, f (Z ω) ∂P) :
(A.indicator (1 : Ω → ℝ)) ⟂ᵢ[P] Z := by
suffices (A.indicator (1 : Ω → ℝ)) ⟂ᵢ[P] (fun ω (_ : Unit) ↦ Z ω) from
this.comp (measurable_id) (measurable_pi_apply ())
refine indicator_indepFun_pi_of_prod_bcf mA (fun _ ↦ mZ) fun f ↦ ?_
convert h (f ()) <;> simp
end Indicator
section IndepSets
lemma indepSets_comap_pi_of_prod_bcf
{𝒜 : Set (Set Ω)} (m𝒜 : ∀ A ∈ 𝒜, NullMeasurableSet A P) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ A ∈ 𝒜, ∀ f : (s : S) → E s →ᵇ ℝ, ∫ ω in A, ∏ s, f s (X s ω) ∂P =
P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
IndepSets 𝒜 {A | MeasurableSet[MeasurableSpace.pi.comap (fun ω s ↦ X s ω)] A} P :=
indepSets_iff_singleton_indepSets.2 fun A hA ↦ IndepFun.singleton_indepSets_of_indicator
(indicator_indepFun_pi_of_prod_bcf (m𝒜 A hA) mX (h A hA))
lemma indepSets_comap_pi_of_bcf
{𝒜 : Set (Set Ω)} (m𝒜 : ∀ A ∈ 𝒜, NullMeasurableSet A P) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ A ∈ 𝒜, ∀ f : (Π s, E s) →ᵇ ℝ, ∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
IndepSets 𝒜 {A | MeasurableSet[MeasurableSpace.pi.comap (fun ω s ↦ X s ω)] A} P :=
indepSets_iff_singleton_indepSets.2 fun A hA ↦ IndepFun.singleton_indepSets_of_indicator
(indicator_indepFun_pi_of_bcf (m𝒜 A hA) mX (h A hA))
lemma indepSets_comap_of_bcf
{𝒜 : Set (Set Ω)} (m𝒜 : ∀ A ∈ 𝒜, NullMeasurableSet A P) (mZ : AEMeasurable Z P)
(h : ∀ A ∈ 𝒜, ∀ f : G →ᵇ ℝ, ∫ ω in A, f (Z ω) ∂P = P.real A * ∫ ω, f (Z ω) ∂P) :
IndepSets 𝒜 {A | MeasurableSet[MeasurableSpace.comap Z inferInstance] A} P :=
indepSets_iff_singleton_indepSets.2 fun A hA ↦ IndepFun.singleton_indepSets_of_indicator
(indicator_indepFun_of_bcf (m𝒜 A hA) mZ (h A hA))
end IndepSets
section Indep
lemma indep_comap_pi_of_prod_bcf (hm : m ≤ mΩ) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ A, MeasurableSet[m] A → ∀ f : (s : S) → E s →ᵇ ℝ,
∫ ω in A, ∏ s, f s (X s ω) ∂P = P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
Indep m (MeasurableSpace.pi.comap (fun ω s ↦ X s ω)) P :=
(Indep_iff_IndepSets _ _ P).2
(indepSets_comap_pi_of_prod_bcf (fun A hA ↦ (hm A hA).nullMeasurableSet) mX h)
/-- A sigma-algebra $\mathcal{A}$ and a family of random variables $(X_1, ..., X_p)$ are independent
if for all set $A \in \mathcal{A}$ and for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X_1, ..., X_p)] = P(A) P[f(X_1, ..., X_p)].$$ -/
lemma indep_comap_pi_of_bcf (hm : m ≤ mΩ) (mX : ∀ s, AEMeasurable (X s) P)
(h : ∀ A, MeasurableSet[m] A → ∀ f : (Π s, E s) →ᵇ ℝ,
∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
Indep m (MeasurableSpace.pi.comap (fun ω s ↦ X s ω)) P :=
(Indep_iff_IndepSets _ _ P).2
(indepSets_comap_pi_of_bcf (fun A hA ↦ (hm A hA).nullMeasurableSet) mX h)
/-- A sigma-algebra $\mathcal{A}$ and a random variable $X$ are independent
if for all set $A \in \mathcal{A}$ and for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X)] = P(A) P[f(X)].$$ -/
lemma indep_comap_of_bcf (hm : m ≤ mΩ) (mZ : AEMeasurable Z P)
(h : ∀ A, MeasurableSet[m] A → ∀ f : G →ᵇ ℝ,
∫ ω in A, f (Z ω) ∂P = P.real A * ∫ ω, f (Z ω) ∂P) :
Indep m (MeasurableSpace.comap Z inferInstance) P :=
(Indep_iff_IndepSets _ _ P).2
(indepSets_comap_of_bcf (fun A hA ↦ (hm A hA).nullMeasurableSet) mZ h)
end Indep
end Fintype
section Process
section IndepFun
variable [IsZeroOrProbabilityMeasure P]
lemma process_indepFun_process_of_prod_bcf
(mX : ∀ s, Measurable (X s)) (mY : ∀ t, Measurable (Y t))
(h : ∀ (I : Finset S) (J : Finset T) (f : (s : I) → E s →ᵇ ℝ) (g : (t : J) → F t →ᵇ ℝ),
P[(∏ s, f s ∘ (X s)) * (∏ t, g t ∘ (Y t))] = P[∏ s, f s ∘ (X s)] * P[∏ t, g t ∘ (Y t)]) :
IndepFun (fun ω s ↦ X s ω) (fun ω t ↦ Y t ω) P :=
IndepFun.process_indepFun_process mX mY
fun I J ↦ pi_indepFun_pi_of_prod_bcf (by fun_prop) (by fun_prop) (h I J)
/-- Two stochastic processes $(X_s)_{s \in S}$ and $(Y_t)_{t \in T}$ are independent if
for all $s_1, ..., s_p \in S, t_1, ..., t_q \in T$ and
for all real bounded continuous functions $f$ and $g$,
$$P[f(X_{s_1}, ..., X_{s_p}) g(Y_{t_1}, ..., Y_{t_q})] =
P[f(X_{s_1}, ..., X_{s_p})] * P[g(Y_{t_1}, ..., Y_{t_q})].$$ -/
lemma process_indepFun_process_of_bcf
(mX : ∀ s, Measurable (X s)) (mY : ∀ t, Measurable (Y t))
(h : ∀ (I : Finset S) (J : Finset T) (f : (Π s : I, E s) →ᵇ ℝ) (g : (Π t : J, F t) →ᵇ ℝ),
P[fun ω ↦ f (X · ω) * g (Y · ω)] = P[fun ω ↦ f (X · ω)] * P[fun ω ↦ g (Y · ω)]) :
IndepFun (fun ω s ↦ X s ω) (fun ω t ↦ Y t ω) P :=
IndepFun.process_indepFun_process mX mY
fun I J ↦ pi_indepFun_pi_of_bcf (by fun_prop) (by fun_prop) (h I J)
lemma indepFun_process_of_prod_bcf
(mZ : AEMeasurable Z P) (mY : ∀ t, Measurable (Y t))
(h : ∀ (f : G →ᵇ ℝ) (J : Finset T) (g : (t : J) → F t →ᵇ ℝ),
P[f ∘ Z * (∏ t, g t ∘ (Y t))] = P[f ∘ Z] * P[∏ t, g t ∘ (Y t)]) :
IndepFun Z (fun ω t ↦ Y t ω) P :=
IndepFun.indepFun_process mZ mY fun J ↦
indepFun_pi_of_prod_bcf (by fun_prop) (by fun_prop) (h · J)
lemma indepFun_process_of_bcf
(mZ : AEMeasurable Z P) (mY : ∀ t, Measurable (Y t))
(h : ∀ (f : G →ᵇ ℝ) (J : Finset T) (g : (Π t : J, F t) →ᵇ ℝ),
P[fun ω ↦ f (Z ω) * g (Y · ω)] = P[f ∘ Z] * P[fun ω ↦ g (Y · ω)]) :
IndepFun Z (fun ω t ↦ Y t ω) P :=
IndepFun.indepFun_process mZ mY fun J ↦ indepFun_pi_of_bcf (by fun_prop) (by fun_prop) (h · J)
lemma process_indepFun_of_prod_bcf
(mX : ∀ s, Measurable (X s)) (mU : AEMeasurable U P)
(h : ∀ (I : Finset S) (f : (s : I) → E s →ᵇ ℝ) (g : H →ᵇ ℝ),
P[(∏ s, f s ∘ (X s)) * g ∘ U] = P[∏ s, f s ∘ (X s)] * P[g ∘ U]) :
IndepFun (fun ω s ↦ X s ω) U P :=
IndepFun.process_indepFun mX mU fun I ↦ pi_indepFun_of_prod_bcf (by fun_prop) (by fun_prop) (h I)
lemma process_indepFun_of_bcf
(mX : ∀ s, Measurable (X s)) (mU : AEMeasurable U P)
(h : ∀ (I : Finset S) (f : (Π s : I, E s) →ᵇ ℝ) (g : H →ᵇ ℝ),
P[fun ω ↦ f (X · ω) * g (U ω)] = P[fun ω ↦ f (X · ω)] * P[g ∘ U]) :
IndepFun (fun ω s ↦ X s ω) U P :=
IndepFun.process_indepFun mX mU fun I ↦ pi_indepFun_of_bcf (by fun_prop) (by fun_prop) (h I)
end IndepFun
variable [IsProbabilityMeasure P]
section Indicator
lemma indicator_indepFun_process_of_prod_bcf
{A : Set Ω} (mA : NullMeasurableSet A P) (mX : ∀ s, Measurable (X s))
(h : ∀ (I : Finset S) (f : (s : I) → E s →ᵇ ℝ),
∫ ω in A, ∏ s, f s (X s ω) ∂P = P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
IndepFun (A.indicator (1 : Ω → ℝ)) (fun ω s ↦ X s ω) P :=
IndepFun.indepFun_process ((aemeasurable_indicator_const_iff 1).2 mA) mX
fun I ↦ indicator_indepFun_pi_of_prod_bcf mA (by fun_prop) (h I)
/-- The indicator of a set $A$ and a stochastic process $(X_s)_{s \in S}$ are independent if
for all $s_1, ..., s_p \in S$ and for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X_{s_1}, ..., X_{s_p})] =
P(A) P[f(X_{s_1}, ..., X_{s_p})].$$ -/
lemma indicator_indepFun_process_of_bcf
{A : Set Ω} (mA : NullMeasurableSet A P) (mX : ∀ s, Measurable (X s))
(h : ∀ (I : Finset S) (f : (Π s : I, E s) →ᵇ ℝ),
∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
IndepFun (A.indicator (1 : Ω → ℝ)) (fun ω s ↦ X s ω) P :=
IndepFun.indepFun_process ((aemeasurable_indicator_const_iff 1).2 mA) mX
fun I ↦ indicator_indepFun_pi_of_bcf mA (by fun_prop) (h I)
end Indicator
section IndepSets
lemma indepSets_comap_process_of_prod_bcf
{𝒜 : Set (Set Ω)} (m𝒜 : ∀ A ∈ 𝒜, NullMeasurableSet A P) (mX : ∀ s, Measurable (X s))
(h : ∀ A ∈ 𝒜, ∀ (I : Finset S) (f : (s : I) → E s →ᵇ ℝ),
∫ ω in A, ∏ s, f s (X s ω) ∂P = P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
IndepSets 𝒜 {A | MeasurableSet[MeasurableSpace.pi.comap (fun ω s ↦ X s ω)] A} P :=
indepSets_iff_singleton_indepSets.2 fun A hA ↦ IndepFun.singleton_indepSets_of_indicator
(indicator_indepFun_process_of_prod_bcf (m𝒜 A hA) mX (h A hA))
lemma indepSets_comap_process_of_bcf
{𝒜 : Set (Set Ω)} (m𝒜 : ∀ A ∈ 𝒜, NullMeasurableSet A P) (mX : ∀ s, Measurable (X s))
(h : ∀ A ∈ 𝒜, ∀ (I : Finset S) (f : (Π s : I, E s) →ᵇ ℝ),
∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
IndepSets 𝒜 {A | MeasurableSet[MeasurableSpace.pi.comap (fun ω s ↦ X s ω)] A} P :=
indepSets_iff_singleton_indepSets.2 fun A hA ↦ IndepFun.singleton_indepSets_of_indicator
(indicator_indepFun_process_of_bcf (m𝒜 A hA) mX (h A hA))
end IndepSets
section Indep
lemma indep_comap_process_of_prod_bcf
(hm : m ≤ mΩ) (mX : ∀ s, Measurable (X s))
(h : ∀ A, MeasurableSet[m] A → ∀ (I : Finset S) (f : (s : I) → E s →ᵇ ℝ),
∫ ω in A, ∏ s, f s (X s ω) ∂P = P.real A * ∫ ω, ∏ s, f s (X s ω) ∂P) :
Indep m (MeasurableSpace.pi.comap (fun ω s ↦ X s ω)) P :=
(Indep_iff_IndepSets _ _ P).2
(indepSets_comap_process_of_prod_bcf (fun A hA ↦ (hm A hA).nullMeasurableSet) mX h)
/-- A sigma-algebra $\mathcal{A}$ and a stochastic process $(X_s)_{s \in S}$ are independent if
for all $A \in \mathcal{A}$, for all $s_1, ..., s_p \in S$ and
for all real bounded continuous function $f$,
$$P[\mathbb{I}_A f(X_{s_1}, ..., X_{s_p})] =
P(A) P[f(X_{s_1}, ..., X_{s_p})].$$ -/
lemma indep_comap_process_of_bcf
(hm : m ≤ mΩ) (mX : ∀ s, Measurable (X s))
(h : ∀ A, MeasurableSet[m] A → ∀ (I : Finset S) (f : (Π s : I, E s) →ᵇ ℝ),
∫ ω in A, f (X · ω) ∂P = P.real A * ∫ ω, f (X · ω) ∂P) :
Indep m (MeasurableSpace.pi.comap (fun ω s ↦ X s ω)) P :=
(Indep_iff_IndepSets _ _ P).2
(indepSets_comap_process_of_bcf (fun A hA ↦ (hm A hA).nullMeasurableSet) mX h)
end Indep
end Process |
.lake/packages/mathlib/Mathlib/Probability/Independence/InfinitePi.lean | import Mathlib.Probability.Independence.Basic
import Mathlib.Probability.ProductMeasure
/-!
# Independence of an infinite family of random variables
In this file we provide several results about independence of arbitrary families of random
variables, relying on `Measure.infinitePi`.
## Implementation note
There are several possible measurability assumptions:
* The map `ω ↦ (Xᵢ(ω))ᵢ` is measurable.
* For all `i`, the map `ω ↦ Xᵢ(ω)` is measurable.
* The map `ω ↦ (Xᵢ(ω))ᵢ` is almost everywhere measurable.
* For all `i`, the map `ω ↦ Xᵢ(ω)` is almost everywhere measurable.
Although the first two options are equivalent, the last two are not if the index set is not
countable.
-/
open MeasureTheory Measure ProbabilityTheory
namespace ProbabilityTheory
variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P]
{𝓧 : ι → Type*} {m𝓧 : ∀ i, MeasurableSpace (𝓧 i)} {X : Π i, Ω → 𝓧 i}
/-- Random variables are independent iff their joint distribution is the product measure. This
is a version where the random variable `ω ↦ (Xᵢ(ω))ᵢ` is almost everywhere measurable.
See `iIndepFun_iff_map_fun_eq_infinitePi_map₀'` for a version which only assumes that
each `Xᵢ` is almost everywhere measurable and that `ι` is countable. -/
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀ (mX : AEMeasurable (fun ω i ↦ X i ω) P) :
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) where
mp h := by
have _ i := isProbabilityMeasure_map (mX.eval i)
refine eq_infinitePi _ fun s t ht ↦ ?_
rw [iIndepFun_iff_finset] at h
have : (s : Set ι).pi t = s.restrict ⁻¹' (Set.univ.pi fun i ↦ t i) := by ext; simp
rw [this, ← map_apply, AEMeasurable.map_map_of_aemeasurable]
· have : s.restrict ∘ (fun ω i ↦ X i ω) = fun ω i ↦ s.restrict X i ω := by ext; simp
rw [this, (iIndepFun_iff_map_fun_eq_pi_map ?_).1 (h s), pi_pi]
· simp only [Finset.restrict]
rw [s.prod_coe_sort fun i ↦ P.map (X i) (t i)]
exact fun i ↦ mX.eval i
any_goals fun_prop
· exact mX
· exact .univ_pi fun i ↦ ht i
mpr h := by
have _ i := isProbabilityMeasure_map (mX.eval i)
rw [iIndepFun_iff_finset]
intro s
rw [iIndepFun_iff_map_fun_eq_pi_map]
· have : s.restrict ∘ (fun ω i ↦ X i ω) = fun ω i ↦ s.restrict X i ω := by ext; simp
rw [← this, ← AEMeasurable.map_map_of_aemeasurable, h, infinitePi_map_restrict]
· simp
· fun_prop
exact mX
exact fun i ↦ mX.eval i
/-- Random variables are independent iff their joint distribution is the product measure. This is
an `AEMeasurable` version of `iIndepFun_iff_map_fun_eq_infinitePi_map`, which is why it requires
`ι` to be countable. -/
lemma iIndepFun_iff_map_fun_eq_infinitePi_map₀' [Countable ι] (mX : ∀ i, AEMeasurable (X i) P) :
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) :=
iIndepFun_iff_map_fun_eq_infinitePi_map₀ <| aemeasurable_pi_iff.2 mX
/-- Random variables are independent iff their joint distribution is the product measure. -/
lemma iIndepFun_iff_map_fun_eq_infinitePi_map (mX : ∀ i, Measurable (X i)) :
iIndepFun X P ↔ P.map (fun ω i ↦ X i ω) = infinitePi (fun i ↦ P.map (X i)) :=
iIndepFun_iff_map_fun_eq_infinitePi_map₀ <| measurable_pi_iff.2 mX |>.aemeasurable
/-- Given random variables `X i : Ω i → 𝓧 i`, they are independent when viewed as random
variables defined on the product space `Π i, Ω i`. -/
lemma iIndepFun_infinitePi {Ω : ι → Type*} {mΩ : ∀ i, MeasurableSpace (Ω i)}
{P : (i : ι) → Measure (Ω i)} [∀ i, IsProbabilityMeasure (P i)] {X : (i : ι) → Ω i → 𝓧 i}
(mX : ∀ i, Measurable (X i)) :
iIndepFun (fun i ω ↦ X i (ω i)) (infinitePi P) := by
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop), infinitePi_map_pi _ mX]
congrm infinitePi fun i ↦ ?_
rw [← infinitePi_map_eval P i, map_map (mX i) (by fun_prop), Function.comp_def]
section curry
omit [IsProbabilityMeasure P]
section dependent
variable {κ : ι → Type*} {𝓧 : (i : ι) → κ i → Type*} {m𝓧 : ∀ i j, MeasurableSpace (𝓧 i j)}
/-- Consider `((Xᵢⱼ)ⱼ)ᵢ` a family of families of random variables.
Assume that for any `i`, the random variables `(Xᵢⱼ)ⱼ` are independent.
Assume furthermore that the random variables `((Xᵢⱼ)ⱼ)ᵢ` are independent.
Then the random variables `(Xᵢⱼ)` indexed by pairs `(i, j)` are independent.
This is a dependent version of `iIndepFun_uncurry'`. -/
lemma iIndepFun_uncurry {X : (i : ι) → (j : κ i) → Ω → 𝓧 i j} (mX : ∀ i j, Measurable (X i j))
(h1 : iIndepFun (fun i ω ↦ (X i · ω)) P) (h2 : ∀ i, iIndepFun (X i) P) :
iIndepFun (fun (p : (i : ι) × (κ i)) ω ↦ X p.1 p.2 ω) P := by
have := h1.isProbabilityMeasure
have : ∀ i j, IsProbabilityMeasure (P.map (X i j)) :=
fun i j ↦ isProbabilityMeasure_map (mX i j).aemeasurable
have : ∀ i, IsProbabilityMeasure (P.map (fun ω ↦ (X i · ω))) :=
fun i ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
have : (MeasurableEquiv.piCurry 𝓧) ∘ (fun ω p ↦ X p.1 p.2 ω) = fun ω i j ↦ X i j ω := by
ext; simp [Sigma.curry]
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop),
← (MeasurableEquiv.piCurry 𝓧).map_measurableEquiv_injective.eq_iff,
map_map (by fun_prop) (by fun_prop), this,
(iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)).1 h1,
infinitePi_map_piCurry (fun i j ↦ P.map (X i j))]
congrm infinitePi fun i ↦ ?_
rw [(iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)).1 (h2 i)]
/-- Given random variables `X i j : Ω i j → 𝓧 i j`, they are independent when viewed as random
variables defined on the product space `Π i, Π j, Ω i j`. -/
lemma iIndepFun_uncurry_infinitePi {Ω : (i : ι) → κ i → Type*} {mΩ : ∀ i j, MeasurableSpace (Ω i j)}
{X : (i : ι) → (j : κ i) → Ω i j → 𝓧 i j}
(μ : (i : ι) → (j : κ i) → Measure (Ω i j)) [∀ i j, IsProbabilityMeasure (μ i j)]
(mX : ∀ i j, Measurable (X i j)) :
iIndepFun (fun (p : (i : ι) × κ i) (ω : Π i, Π j, Ω i j) ↦ X p.1 p.2 (ω p.1 p.2))
(infinitePi (fun i ↦ infinitePi (μ i))) := by
refine iIndepFun_uncurry (P := infinitePi (fun i ↦ infinitePi (μ i)))
(X := fun i j ω ↦ X i j (ω i j)) (by fun_prop) ?_ fun i ↦ ?_
· exact iIndepFun_infinitePi (P := fun i ↦ infinitePi (μ i))
(X := fun i u j ↦ X i j (u j)) (by fun_prop)
rw [iIndepFun_iff_map_fun_eq_infinitePi_map (by fun_prop)]
change map ((fun f ↦ f i) ∘ (fun ω i j ↦ X i j (ω i j)))
(infinitePi fun i ↦ infinitePi (μ i)) = _
rw [← map_map (by fun_prop) (by fun_prop),
infinitePi_map_pi (X := fun i ↦ (j : κ i) → Ω i j) (μ := fun i ↦ infinitePi (μ i))
(f := fun i f j ↦ X i j (f j)), @infinitePi_map_eval .., infinitePi_map_pi]
· congrm infinitePi fun j ↦ ?_
change _ = map (((fun f ↦ f j) ∘ (fun f ↦ f i)) ∘ (fun ω i j ↦ X i j (ω i j)))
(infinitePi fun i ↦ infinitePi (μ i))
rw [← map_map (by fun_prop) (by fun_prop), infinitePi_map_pi (X := fun i ↦ (j : κ i) → Ω i j)
(μ := fun i ↦ infinitePi (μ i)) (f := fun i f j ↦ X i j (f j)),
← map_map (by fun_prop) (by fun_prop),
@infinitePi_map_eval .., infinitePi_map_pi, @infinitePi_map_eval ..]
any_goals fun_prop
· exact fun _ ↦ isProbabilityMeasure_map (by fun_prop)
· exact fun _ ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
any_goals fun_prop
exact fun _ ↦ isProbabilityMeasure_map (Measurable.aemeasurable (by fun_prop))
end dependent
section nondependent
variable {κ : Type*} {𝓧 : ι → κ → Type*} {m𝓧 : ∀ i j, MeasurableSpace (𝓧 i j)}
/-- Consider `((Xᵢⱼ)ⱼ)ᵢ` a family of families of random variables.
Assume that for any `i`, the random variables `(Xᵢⱼ)ⱼ` are independent.
Assume furthermore that the random variables `((Xᵢⱼ)ⱼ)ᵢ` are independent.
Then the random variables `(Xᵢⱼ)` indexed by pairs `(i, j)` are independent.
This is a non-dependent version of `iIndepFun_uncurry`. -/
lemma iIndepFun_uncurry' {X : (i : ι) → (j : κ) → Ω → 𝓧 i j} (mX : ∀ i j, Measurable (X i j))
(h1 : iIndepFun (fun i ω ↦ (X i · ω)) P) (h2 : ∀ i, iIndepFun (X i) P) :
iIndepFun (fun (p : ι × κ) ω ↦ X p.1 p.2 ω) P :=
(iIndepFun_uncurry mX h1 h2).of_precomp (Equiv.sigmaEquivProd ι κ).surjective
/-- Given random variables `X i j : Ω i j → 𝓧 i j`, they are independent when viewed as random
variables defined on the product space `Π i, Π j, Ω i j`. -/
lemma iIndepFun_uncurry_infinitePi' {Ω : ι → κ → Type*} {mΩ : ∀ i j, MeasurableSpace (Ω i j)}
{X : (i : ι) → (j : κ) → Ω i j → 𝓧 i j}
(μ : (i : ι) → (j : κ) → Measure (Ω i j)) [∀ i j, IsProbabilityMeasure (μ i j)]
(mX : ∀ i j, Measurable (X i j)) :
iIndepFun (fun (p : ι × κ) (ω : Π i, Π j, Ω i j) ↦ X p.1 p.2 (ω p.1 p.2))
(infinitePi (fun i ↦ infinitePi (μ i))) :=
(iIndepFun_uncurry_infinitePi μ mX).of_precomp (Equiv.sigmaEquivProd ι κ).surjective
end nondependent
end curry
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/Process.lean | import Mathlib.MeasureTheory.Constructions.Cylinders
import Mathlib.Probability.Independence.Basic
/-!
# Independence of stochastic processes
We prove that a stochastic process $(X_s)_{s \in S}$ is independent from a random variable $Y$ if
for all $s_1, ..., s_p \in S$ the family $(X_{s_1}, ..., X_{s_p})$ is independent from $Y$.
We prove that two stochastic processes $(X_s)_{s \in S}$ and $(Y_t)_{t \in T}$ are independent if
for all $s_1, ..., s_p \in S$ and $t_1, ..., t_q \in T$ the two families
$(X_{s_1}, ..., X_{s_p})$ and $(Y_{t_1}, ..., Y_{t_q})$ are independent.
We prove an analogous condition for a family of stochastic processes.
## Tags
independence, stochastic processes
-/
open MeasureTheory MeasurableSpace
namespace ProbabilityTheory
variable {S Ω : Type*} {mΩ : MeasurableSpace Ω}
namespace Kernel
variable {α : Type*} {mα : MeasurableSpace α} {κ : Kernel α Ω} {P : Measure α}
/-- A stochastic process $(X_s)_{s \in S}$ is independent from a random variable $Y$ if
for all $s_1, ..., s_p \in S$ the family $(X_{s_1}, ..., X_{s_p})$ is independent from $Y$. -/
lemma IndepFun.process_indepFun {𝓧 : S → Type*} {𝓨 : Type*}
[∀ i, MeasurableSpace (𝓧 i)] [MeasurableSpace 𝓨] {X : (i : S) → Ω → 𝓧 i}
{Y : Ω → 𝓨} (hX : ∀ i, Measurable (X i)) (hY : Measurable Y)
(h : ∀ (I : Finset S),
IndepFun (fun ω (i : I) ↦ X i ω) Y κ P) [IsZeroOrMarkovKernel κ] :
IndepFun (fun ω i ↦ X i ω) Y κ P := by
-- The π-system obtained by pulling back the π-system of square cylinders by `X`.
let πX := {s : Set Ω | ∃ t ∈ squareCylinders (fun i ↦ {s : Set (𝓧 i) | MeasurableSet s}),
(fun ω i ↦ X i ω) ⁻¹' t = s}
have πX_pi : IsPiSystem πX :=
IsPiSystem.comap (isPiSystem_squareCylinders (fun _ ↦ isPiSystem_measurableSet) (by simp)) _
have πX_gen : (MeasurableSpace.pi.comap fun ω i ↦ X i ω) = generateFrom πX := by
rw [generateFrom_squareCylinders.symm, MeasurableSpace.comap_generateFrom]
rfl
-- To prove independence, we prove independence of the generating π-system with the `σ`-alebra.
refine IndepSets.indep (measurable_pi_iff.2 hX).comap_le hY.comap_le
πX_pi (@isPiSystem_measurableSet Ω (.comap Y inferInstance)) πX_gen
(@generateFrom_measurableSet Ω (.comap Y inferInstance)).symm ?_
rintro - - ⟨-, ⟨I, s, hs, rfl⟩, rfl⟩ ⟨t, ht, rfl⟩
simp only [Set.mem_pi, Set.mem_univ, Set.mem_setOf_eq, forall_const] at hs
have : (fun ω i ↦ X i ω) ⁻¹' .pi I s =
(fun ω (i : I) ↦ X i ω) ⁻¹' .pi (SetLike.coe Finset.univ) (fun i ↦ s i)
:= by
ext; simp
have h1 : MeasurableSet <| .pi (SetLike.coe Finset.univ) (fun (i : I) ↦ s i) :=
.pi (Finset.countable_toSet _) (fun _ _ ↦ hs _)
filter_upwards [(h I).measure_inter_preimage_eq_mul _ _ h1 ht] with ω hω
rw [this, hω]
/-- A random variable $X$ is independent from a stochastic process $(Y_s)_{s \in S}$ if
for all $s_1, ..., s_p \in S$ the variable $Y$ is independent from the family
$(X_{s_1}, ..., X_{s_p})$. -/
lemma IndepFun.indepFun_process {𝓧 : Type*} {𝓨 : S → Type*}
[MeasurableSpace 𝓧] [∀ i, MeasurableSpace (𝓨 i)] {X : Ω → 𝓧}
{Y : (i : S) → Ω → 𝓨 i} (hX : Measurable X) (hY : ∀ i, Measurable (Y i))
(h : ∀ (I : Finset S),
IndepFun X (fun ω (i : I) ↦ Y i ω) κ P) [IsZeroOrMarkovKernel κ] :
IndepFun X (fun ω i ↦ Y i ω) κ P :=
(IndepFun.process_indepFun hY hX (fun I ↦ (h I).symm)).symm
/-- Two stochastic processes $(X_s)_{s \in S}$ and $(Y_t)_{t \in T}$ are independent if
for all $s_1, ..., s_p \in S$ and $t_1, ..., t_q \in T$ the two families
$(X_{s_1}, ..., X_{s_p})$ and $(Y_{t_1}, ..., Y_{t_q})$ are independent. -/
lemma IndepFun.process_indepFun_process {T : Type*} {𝓧 : S → Type*} {𝓨 : T → Type*}
[∀ i, MeasurableSpace (𝓧 i)] [∀ j, MeasurableSpace (𝓨 j)] {X : (i : S) → Ω → 𝓧 i}
{Y : (j : T) → Ω → 𝓨 j} (hX : ∀ i, Measurable (X i)) (hY : ∀ j, Measurable (Y j))
(h : ∀ (I : Finset S) (J : Finset T),
IndepFun (fun ω (i : I) ↦ X i ω) (fun ω (j : J) ↦ Y j ω) κ P) [IsZeroOrMarkovKernel κ] :
IndepFun (fun ω i ↦ X i ω) (fun ω j ↦ Y j ω) κ P := by
refine IndepFun.process_indepFun hX (measurable_pi_lambda _ hY) fun I ↦ ?_
exact IndepFun.indepFun_process (measurable_pi_lambda _ fun _ ↦ hX _) hY fun J ↦ h I J
/-- Stochastic processes $((X^s_t)_{t \in T_s})_{s \in S}$ are mutually independent if
for all $s_1, ..., s_n$ and all $t^{s_i}_1, ..., t^{s_i}_{p_i}$ the families
$(X^{s_1}_{t^{s_1}_1}, ..., X^{s_1}_{t^{s_1}_{p_1}}), ...,
(X^{s_n}_{t^{s_n}_1}, ..., X^{s_n}_{t^{s_n}_{p_n}})$ are mutually independent. -/
lemma iIndepFun.iIndepFun_process {T : S → Type*} {𝓧 : (i : S) → (j : T i) → Type*}
[∀ i j, MeasurableSpace (𝓧 i j)] {X : (i : S) → (j : T i) → Ω → 𝓧 i j}
(hX : ∀ i j, Measurable (X i j))
(h : ∀ (I : Finset S) (J : (i : I) → Finset (T i)),
iIndepFun (fun i ω (j : J i) ↦ X i j ω) κ P) :
iIndepFun (fun i ω j ↦ X i j ω) κ P := by
obtain rfl | hμ := eq_or_ne P 0
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[P] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel (h ∅ fun _ ↦ ∅).ae_isProbabilityMeasure hμ
apply iIndepFun.congr (Filter.EventuallyEq.symm η_eq)
let π i := {s : Set Ω | ∃ t ∈ squareCylinders (fun j ↦ {s : Set (𝓧 i j) | MeasurableSet s}),
(fun ω j ↦ X i j ω) ⁻¹' t = s}
have π_pi i : IsPiSystem (π i) :=
(isPiSystem_squareCylinders (fun _ ↦ isPiSystem_measurableSet) (by simp)).comap _
have π_gen i : (MeasurableSpace.pi.comap fun ω j ↦ X i j ω) = generateFrom (π i) := by
rw [generateFrom_squareCylinders.symm, MeasurableSpace.comap_generateFrom]
rfl
refine iIndepSets.iIndep _ (fun i ↦ (measurable_pi_iff.2 (hX i)).comap_le) π π_pi π_gen
fun I s hs ↦ ?_
simp only [squareCylinders, Set.mem_pi, Set.mem_univ, Set.mem_setOf_eq, forall_const,
↓existsAndEq, and_true, π] at hs
choose! J t ht hs using hs
simp_rw [Set.iInter₂_congr (fun i hi ↦ (hs i hi).symm),
I.prod_congr rfl (fun i hi ↦ congrArg _ (hs i hi).symm)]
have : (⋂ i ∈ I, (fun ω j ↦ X i j ω) ⁻¹' .pi (J i) (t i)) =
(⋂ i ∈ (.univ : Finset I), (fun ω (j : J i) ↦ X i j ω) ⁻¹'
.pi (SetLike.coe Finset.univ) (fun j ↦ t i j)) := by
ext; simp
have h' (i : I) (hi : i ∈ Finset.univ) :
MeasurableSet <| (SetLike.coe Finset.univ).pi fun (j : J i) ↦ t i j :=
.pi (Finset.countable_toSet _) (fun _ _ ↦ ht _ i.2 _)
filter_upwards [(h I (fun i ↦ J i)).measure_inter_preimage_eq_mul _ _ .univ h',
η_eq] with ω hω hη
rw [this, ← hη, hω, ← I.prod_coe_sort]
congrm ∏ _, κ ω ?_
ext; simp
end Kernel
variable {P : Measure Ω}
/-- A stochastic process $(X_s)_{s \in S}$ is independent from a random variable $Y$ if
for all $s_1, ..., s_p \in S$ the family $(X_{s_1}, ..., X_{s_p})$ is independent from $Y$. -/
lemma IndepFun.process_indepFun {𝓧 : S → Type*} {𝓨 : Type*}
[∀ i, MeasurableSpace (𝓧 i)] [MeasurableSpace 𝓨] {X : (i : S) → Ω → 𝓧 i}
{Y : Ω → 𝓨} (hX : ∀ i, Measurable (X i)) (hY : AEMeasurable Y P)
(h : ∀ (I : Finset S),
IndepFun (fun ω (i : I) ↦ X i ω) Y P) [IsZeroOrProbabilityMeasure P] :
IndepFun (fun ω i ↦ X i ω) Y P := by
suffices (fun ω i ↦ X i ω) ⟂ᵢ[P] (hY.mk Y) from
this.congr .rfl hY.ae_eq_mk.symm
exact Kernel.IndepFun.process_indepFun hX hY.measurable_mk (fun I ↦ (h I).congr .rfl hY.ae_eq_mk)
/-- A random variable $X$ is independent from a stochastic process $(Y_s)_{s \in S}$ if
for all $s_1, ..., s_p \in S$ the variable $Y$ is independent from the family
$(X_{s_1}, ..., X_{s_p})$. -/
lemma IndepFun.indepFun_process {𝓧 : Type*} {𝓨 : S → Type*}
[MeasurableSpace 𝓧] [∀ i, MeasurableSpace (𝓨 i)] {X : Ω → 𝓧}
{Y : (i : S) → Ω → 𝓨 i} (hX : AEMeasurable X P) (hY : ∀ i, Measurable (Y i))
(h : ∀ (I : Finset S),
IndepFun X (fun ω (i : I) ↦ Y i ω) P) [IsZeroOrProbabilityMeasure P] :
IndepFun X (fun ω i ↦ Y i ω) P := by
suffices (hX.mk X) ⟂ᵢ[P] (fun ω i ↦ Y i ω) from
this.congr hX.ae_eq_mk.symm .rfl
exact Kernel.IndepFun.indepFun_process hX.measurable_mk hY (fun I ↦ (h I).congr hX.ae_eq_mk .rfl)
/-- Two stochastic processes $(X_s)_{s \in S}$ and $(Y_t)_{t \in T}$ are independent if
for all $s_1, ..., s_p \in S$ and $t_1, ..., t_q \in T$ the two families
$(X_{s_1}, ..., X_{s_p})$ and $(Y_{t_1}, ..., Y_{t_q})$ are independent. -/
lemma IndepFun.process_indepFun_process {T : Type*} {𝓧 : S → Type*} {𝓨 : T → Type*}
[∀ i, MeasurableSpace (𝓧 i)] [∀ j, MeasurableSpace (𝓨 j)] {X : (i : S) → Ω → 𝓧 i}
{Y : (j : T) → Ω → 𝓨 j} (hX : ∀ i, Measurable (X i)) (hY : ∀ j, Measurable (Y j))
(h : ∀ (I : Finset S) (J : Finset T),
IndepFun (fun ω (i : I) ↦ X i ω) (fun ω (j : J) ↦ Y j ω) P) [IsZeroOrProbabilityMeasure P] :
IndepFun (fun ω i ↦ X i ω) (fun ω j ↦ Y j ω) P :=
Kernel.IndepFun.process_indepFun_process hX hY h
/-- Stochastic processes $((X^s_t)_{t \in T_s})_{s \in S}$ are mutually independent if
for all $s_1, ..., s_n$ and all $t^{s_i}_1, ..., t^{s_i}_{p_i}$ the families
$(X^{s_1}_{t^{s_1}_1}, ..., X^{s_1}_{t^{s_1}_{p_1}}), ...,
(X^{s_n}_{t^{s_n}_1}, ..., X^{s_n}_{t^{s_n}_{p_n}})$ are mutually independent. -/
lemma iIndepFun.iIndepFun_process {T : S → Type*} {𝓧 : (i : S) → (j : T i) → Type*}
[∀ i j, MeasurableSpace (𝓧 i j)] {X : (i : S) → (j : T i) → Ω → 𝓧 i j}
(hX : ∀ i j, Measurable (X i j))
(h : ∀ (I : Finset S) (J : (i : I) → Finset (T i)), iIndepFun (fun i ω (j : J i) ↦ X i j ω) P) :
iIndepFun (fun i ω j ↦ X i j ω) P :=
Kernel.iIndepFun.iIndepFun_process hX h
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/ZeroOne.lean | import Mathlib.Probability.Independence.Basic
import Mathlib.Probability.Independence.Conditional
/-!
# Kolmogorov's 0-1 law
Let `s : ι → MeasurableSpace Ω` be an independent sequence of sub-σ-algebras. Then any set which
is measurable with respect to the tail σ-algebra `limsup s atTop` has probability 0 or 1.
## Main statements
* `measure_zero_or_one_of_measurableSet_limsup_atTop`: Kolmogorov's 0-1 law. Any set which is
measurable with respect to the tail σ-algebra `limsup s atTop` of an independent sequence of
σ-algebras `s` has probability 0 or 1.
-/
open MeasureTheory MeasurableSpace
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory
variable {α Ω ι : Type*} {_mα : MeasurableSpace α} {s : ι → MeasurableSpace Ω}
{m m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μα : Measure α} {μ : Measure Ω}
theorem Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω}
(h_indep : Kernel.IndepSet t t κ μα) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 ∨ κ a t = ∞ := by
specialize h_indep t t (measurableSet_generateFrom (Set.mem_singleton t))
(measurableSet_generateFrom (Set.mem_singleton t))
filter_upwards [h_indep] with a ha
by_cases h0 : κ a t = 0
· exact Or.inl h0
by_cases h_top : κ a t = ∞
· exact Or.inr (Or.inr h_top)
rw [← one_mul (κ a (t ∩ t)), Set.inter_self, ENNReal.mul_left_inj h0 h_top] at ha
exact Or.inr (Or.inl ha.symm)
theorem measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω}
(h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 ∨ μ t = ∞ := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self h_indep
theorem Kernel.measure_eq_zero_or_one_of_indepSet_self' (h : ∀ᵐ a ∂μα, IsFiniteMeasure (κ a))
{t : Set Ω} (h_indep : IndepSet t t κ μα) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by
filter_upwards [measure_eq_zero_or_one_or_top_of_indepSet_self h_indep, h] with a h_0_1_top h'
simpa only [measure_ne_top (κ a), or_false] using h_0_1_top
theorem Kernel.measure_eq_zero_or_one_of_indepSet_self [h : ∀ a, IsFiniteMeasure (κ a)] {t : Set Ω}
(h_indep : IndepSet t t κ μα) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 :=
Kernel.measure_eq_zero_or_one_of_indepSet_self' (ae_of_all μα h) h_indep
theorem measure_eq_zero_or_one_of_indepSet_self [IsFiniteMeasure μ] {t : Set Ω}
(h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep
theorem condExp_eq_zero_or_one_of_condIndepSet_self
[StandardBorelSpace Ω]
(hm : m ≤ m0) [hμ : IsFiniteMeasure μ] {t : Set Ω} (ht : MeasurableSet t)
(h_indep : CondIndepSet m hm t t μ) :
∀ᵐ ω ∂μ, (μ⟦t|m⟧) ω = 0 ∨ (μ⟦t|m⟧) ω = 1 := by
-- TODO: Why is not inferred?
have (a : _) : IsFiniteMeasure (condExpKernel μ m a) := inferInstance
have h := ae_of_ae_trim hm (Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep)
filter_upwards [condExpKernel_ae_eq_condExp hm ht, h] with ω hω_eq hω
rwa [← hω_eq, measureReal_eq_zero_iff, measureReal_def, ENNReal.toReal_eq_one_iff]
open Filter
theorem Kernel.indep_biSup_compl (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (t : Set ι) :
Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) κ μα :=
indep_iSup_of_disjoint h_le h_indep disjoint_compl_right
theorem indep_biSup_compl (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (t : Set ι) :
Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) μ :=
Kernel.indep_biSup_compl h_le h_indep t
theorem condIndep_biSup_compl [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (t : Set ι) :
CondIndep m (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) hm μ :=
Kernel.indep_biSup_compl h_le h_indep t
section Abstract
variable {β : Type*} {p : Set ι → Prop} {f : Filter ι} {ns : β → Set ι}
/-! We prove a version of Kolmogorov's 0-1 law for the σ-algebra `limsup s f` where `f` is a filter
for which we can define the following two functions:
* `p : Set ι → Prop` such that for a set `t`, `p t → tᶜ ∈ f`,
* `ns : α → Set ι` a directed sequence of sets which all verify `p` and such that
`⋃ a, ns a = Set.univ`.
For the example of `f = atTop`, we can take
`p = bddAbove` and `ns : ι → Set ι := fun i => Set.Iic i`.
-/
theorem Kernel.indep_biSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα)
(hf : ∀ t, p t → tᶜ ∈ f) {t : Set ι} (ht : p t) :
Indep (⨆ n ∈ t, s n) (limsup s f) κ μα := by
refine indep_of_indep_of_le_right (indep_biSup_compl h_le h_indep t) ?_
refine limsSup_le_of_le (by isBoundedDefault) ?_
simp only [Set.mem_compl_iff, eventually_map]
exact eventually_of_mem (hf t ht) le_iSup₂
theorem indep_biSup_limsup
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f)
{t : Set ι} (ht : p t) :
Indep (⨆ n ∈ t, s n) (limsup s f) μ :=
Kernel.indep_biSup_limsup h_le h_indep hf ht
theorem condIndep_biSup_limsup [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f)
{t : Set ι} (ht : p t) :
CondIndep m (⨆ n ∈ t, s n) (limsup s f) hm μ :=
Kernel.indep_biSup_limsup h_le h_indep hf ht
theorem Kernel.indep_iSup_directed_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) :
Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) κ μα := by
rcases eq_or_ne μα 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μα] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hμ
replace h_indep := h_indep.congr η_eq
apply Indep.congr (Filter.EventuallyEq.symm η_eq)
apply indep_iSup_of_directed_le
· exact fun a => indep_biSup_limsup h_le h_indep hf (hnsp a)
· exact fun a => iSup₂_le fun n _ => h_le n
· exact limsup_le_iSup.trans (iSup_le h_le)
· intro a b
obtain ⟨c, hc⟩ := hns a b
refine ⟨c, ?_, ?_⟩ <;> refine iSup_mono fun n => iSup_mono' fun hn => ⟨?_, le_rfl⟩
· exact hc.1 hn
· exact hc.2 hn
theorem indep_iSup_directed_limsup
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) :
Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) μ :=
Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp
theorem condIndep_iSup_directed_limsup [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) :
CondIndep m (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) hm μ :=
Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp
theorem Kernel.indep_iSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα)
(hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
Indep (⨆ n, s n) (limsup s f) κ μα := by
suffices (⨆ a, ⨆ n ∈ ns a, s n) = ⨆ n, s n by
rw [← this]
exact indep_iSup_directed_limsup h_le h_indep hf hns hnsp
rw [iSup_comm]
refine iSup_congr fun n => ?_
have h : ⨆ (i : β) (_ : n ∈ ns i), s n = ⨆ _ : ∃ i, n ∈ ns i, s n := by rw [iSup_exists]
haveI : Nonempty (∃ i : β, n ∈ ns i) := ⟨hns_univ n⟩
rw [h, iSup_const]
theorem indep_iSup_limsup
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
Indep (⨆ n, s n) (limsup s f) μ :=
Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ
theorem condIndep_iSup_limsup [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
CondIndep m (⨆ n, s n) (limsup s f) hm μ :=
Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ
theorem Kernel.indep_limsup_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα)
(hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
Indep (limsup s f) (limsup s f) κ μα :=
indep_of_indep_of_le_left (indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ) limsup_le_iSup
theorem indep_limsup_self
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
Indep (limsup s f) (limsup s f) μ :=
Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ
theorem condIndep_limsup_self [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f)
(hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) :
CondIndep m (limsup s f) (limsup s f) hm μ :=
Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ
theorem Kernel.measure_zero_or_one_of_measurableSet_limsup (h_le : ∀ n, s n ≤ m0)
(h_indep : iIndep s κ μα)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a))
(hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by
apply measure_eq_zero_or_one_of_indepSet_self' ?_
((indep_limsup_self h_le h_indep hf hns hnsp hns_univ).indepSet_of_measurableSet ht_tail
ht_tail)
filter_upwards [h_indep.ae_isProbabilityMeasure] with a ha using by infer_instance
theorem measure_zero_or_one_of_measurableSet_limsup
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a))
(hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) :
μ t = 0 ∨ μ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ
ht_tail
theorem condExp_zero_or_one_of_measurableSet_limsup [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ)
(hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a))
(hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) :
∀ᵐ ω ∂μ, (μ⟦t|m⟧) ω = 0 ∨ (μ⟦t|m⟧) ω = 1 := by
have h := ae_of_ae_trim hm
(Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ ht_tail)
have ht : MeasurableSet t := limsup_le_iSup.trans (iSup_le h_le) t ht_tail
filter_upwards [condExpKernel_ae_eq_condExp hm ht, h] with ω hω_eq hω
rwa [← hω_eq, measureReal_eq_zero_iff, measureReal_def, ENNReal.toReal_eq_one_iff]
end Abstract
section AtTop
variable [SemilatticeSup ι] [NoMaxOrder ι] [Nonempty ι]
theorem Kernel.indep_limsup_atTop_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) :
Indep (limsup s atTop) (limsup s atTop) κ μα := by
let ns : ι → Set ι := Set.Iic
have hnsp : ∀ i, BddAbove (ns i) := fun i => bddAbove_Iic
refine indep_limsup_self h_le h_indep ?_ ?_ hnsp ?_
· simp only [mem_atTop_sets, Set.mem_compl_iff, BddAbove, upperBounds, Set.Nonempty]
rintro t ⟨a, ha⟩
obtain ⟨b, hb⟩ : ∃ b, a < b := exists_gt a
refine ⟨b, fun c hc hct => ?_⟩
suffices ∀ i ∈ t, i < c from lt_irrefl c (this c hct)
exact fun i hi => (ha hi).trans_lt (hb.trans_le hc)
· exact Monotone.directed_le fun i j hij k hki => le_trans hki hij
· exact fun n => ⟨n, le_rfl⟩
theorem indep_limsup_atTop_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) :
Indep (limsup s atTop) (limsup s atTop) μ :=
Kernel.indep_limsup_atTop_self h_le h_indep
theorem condIndep_limsup_atTop_self [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) :
CondIndep m (limsup s atTop) (limsup s atTop) hm μ :=
Kernel.indep_limsup_atTop_self h_le h_indep
theorem Kernel.measure_zero_or_one_of_measurableSet_limsup_atTop (h_le : ∀ n, s n ≤ m0)
(h_indep : iIndep s κ μα) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by
apply measure_eq_zero_or_one_of_indepSet_self' ?_
((indep_limsup_atTop_self h_le h_indep).indepSet_of_measurableSet ht_tail ht_tail)
filter_upwards [h_indep.ae_isProbabilityMeasure] with a ha using by infer_instance
/-- **Kolmogorov's 0-1 law** : any event in the tail σ-algebra of an independent sequence of
sub-σ-algebras has probability 0 or 1.
The tail σ-algebra `limsup s atTop` is the same as `⋂ n, ⋃ i ≥ n, s i`. -/
theorem measure_zero_or_one_of_measurableSet_limsup_atTop
(h_le : ∀ n, s n ≤ m0)
(h_indep : iIndep s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) :
μ t = 0 ∨ μ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_zero_or_one_of_measurableSet_limsup_atTop h_le h_indep ht_tail
theorem condExp_zero_or_one_of_measurableSet_limsup_atTop [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0)
(h_indep : iCondIndep m hm s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) :
∀ᵐ ω ∂μ, (μ⟦t|m⟧) ω = 0 ∨ (μ⟦t|m⟧) ω = 1 :=
condExp_eq_zero_or_one_of_condIndepSet_self hm (limsup_le_iSup.trans (iSup_le h_le) t ht_tail)
((condIndep_limsup_atTop_self hm h_le h_indep).condIndepSet_of_measurableSet ht_tail ht_tail)
end AtTop
section AtBot
variable [SemilatticeInf ι] [NoMinOrder ι] [Nonempty ι]
theorem Kernel.indep_limsup_atBot_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) :
Indep (limsup s atBot) (limsup s atBot) κ μα := by
let ns : ι → Set ι := Set.Ici
have hnsp : ∀ i, BddBelow (ns i) := fun i => bddBelow_Ici
refine indep_limsup_self h_le h_indep ?_ ?_ hnsp ?_
· simp only [mem_atBot_sets, Set.mem_compl_iff, BddBelow, lowerBounds, Set.Nonempty]
rintro t ⟨a, ha⟩
obtain ⟨b, hb⟩ : ∃ b, b < a := exists_lt a
refine ⟨b, fun c hc hct => ?_⟩
suffices ∀ i ∈ t, c < i from lt_irrefl c (this c hct)
exact fun i hi => hc.trans_lt (hb.trans_le (ha hi))
· exact Antitone.directed_le fun _ _ ↦ Set.Ici_subset_Ici.2
· exact fun n => ⟨n, le_rfl⟩
theorem indep_limsup_atBot_self
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) :
Indep (limsup s atBot) (limsup s atBot) μ :=
Kernel.indep_limsup_atBot_self h_le h_indep
theorem condIndep_limsup_atBot_self [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ]
(h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) :
CondIndep m (limsup s atBot) (limsup s atBot) hm μ :=
Kernel.indep_limsup_atBot_self h_le h_indep
/-- **Kolmogorov's 0-1 law**, kernel version: any event in the tail σ-algebra of an independent
sequence of sub-σ-algebras has probability 0 or 1 almost surely. -/
theorem Kernel.measure_zero_or_one_of_measurableSet_limsup_atBot (h_le : ∀ n, s n ≤ m0)
(h_indep : iIndep s κ μα) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atBot] t) :
∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by
apply measure_eq_zero_or_one_of_indepSet_self' ?_
((indep_limsup_atBot_self h_le h_indep).indepSet_of_measurableSet ht_tail ht_tail)
filter_upwards [h_indep.ae_isProbabilityMeasure] with a ha using by infer_instance
/-- **Kolmogorov's 0-1 law** : any event in the tail σ-algebra of an independent sequence of
sub-σ-algebras has probability 0 or 1. -/
theorem measure_zero_or_one_of_measurableSet_limsup_atBot
(h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) {t : Set Ω}
(ht_tail : MeasurableSet[limsup s atBot] t) :
μ t = 0 ∨ μ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_zero_or_one_of_measurableSet_limsup_atBot h_le h_indep ht_tail
/-- **Kolmogorov's 0-1 law**, conditional version: any event in the tail σ-algebra of a
conditionally independent sequence of sub-σ-algebras has conditional probability 0 or 1. -/
theorem condExp_zero_or_one_of_measurableSet_limsup_atBot [StandardBorelSpace Ω]
(hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0)
(h_indep : iCondIndep m hm s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atBot] t) :
∀ᵐ ω ∂μ, (μ⟦t|m⟧) ω = 0 ∨ (μ⟦t|m⟧) ω = 1 :=
condExp_eq_zero_or_one_of_condIndepSet_self hm (limsup_le_iSup.trans (iSup_le h_le) t ht_tail)
((condIndep_limsup_atBot_self hm h_le h_indep).condIndepSet_of_measurableSet ht_tail ht_tail)
end AtBot
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/Integration.lean | import Mathlib.MeasureTheory.Integral.Pi
import Mathlib.Probability.Independence.Integrable
import Mathlib.Probability.Notation
/-!
# Integration in Probability Theory
Integration results for independent random variables. Specifically, for two
independent random variables X and Y over the extended non-negative
reals, `E[X * Y] = E[X] * E[Y]`, and similar results.
## Implementation notes
Many lemmas in this file take two arguments of the same typeclass. It is worth remembering that lean
will always pick the later typeclass in this situation, and does not care whether the arguments are
`[]`, `{}`, or `()`. All of these use the `MeasurableSpace` `M2` to define `μ`:
```lean
example {M1 : MeasurableSpace Ω} [M2 : MeasurableSpace Ω] {μ : Measure Ω} : sorry := sorry
example [M1 : MeasurableSpace Ω] {M2 : MeasurableSpace Ω} {μ : Measure Ω} : sorry := sorry
```
-/
open Set MeasureTheory
open scoped ENNReal MeasureTheory
variable {Ω 𝕜 : Type*} [RCLike 𝕜] {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f g : Ω → ℝ≥0∞}
{X Y : Ω → 𝕜}
namespace ProbabilityTheory
/-- If a random variable `f` in `ℝ≥0∞` is independent of an event `T`, then if you restrict the
random variable to `T`, then `E[f * indicator T c 0]=E[f] * E[indicator T c 0]`. It is useful for
`lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace`. -/
theorem lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator {Mf mΩ : MeasurableSpace Ω}
{μ : Measure Ω} (hMf : Mf ≤ mΩ) (c : ℝ≥0∞) {T : Set Ω} (h_meas_T : MeasurableSet T)
(h_ind : IndepSets {s | MeasurableSet[Mf] s} {T} μ) (h_meas_f : Measurable[Mf] f) :
(∫⁻ ω, f ω * T.indicator (fun _ => c) ω ∂μ) =
(∫⁻ ω, f ω ∂μ) * ∫⁻ ω, T.indicator (fun _ => c) ω ∂μ := by
revert f
have h_mul_indicator : ∀ g, Measurable g → Measurable fun a => g a * T.indicator (fun _ => c) a :=
fun g h_mg => h_mg.mul (measurable_const.indicator h_meas_T)
apply @Measurable.ennreal_induction _ Mf
· intro c' s' h_meas_s'
simp_rw [← inter_indicator_mul]
rw [lintegral_indicator (MeasurableSet.inter (hMf _ h_meas_s') h_meas_T),
lintegral_indicator (hMf _ h_meas_s'), lintegral_indicator h_meas_T]
simp only [lintegral_const, univ_inter,
MeasurableSet.univ, Measure.restrict_apply]
rw [IndepSets_iff] at h_ind
rw [mul_mul_mul_comm, h_ind s' T h_meas_s' (Set.mem_singleton _)]
· intro f' g _ h_meas_f' _ h_ind_f' h_ind_g
have h_measM_f' : Measurable f' := h_meas_f'.mono hMf le_rfl
simp_rw [Pi.add_apply, right_distrib]
rw [lintegral_add_left (h_mul_indicator _ h_measM_f'), lintegral_add_left h_measM_f',
right_distrib, h_ind_f', h_ind_g]
· intro f h_meas_f h_mono_f h_ind_f
have h_measM_f : ∀ n, Measurable (f n) := fun n => (h_meas_f n).mono hMf le_rfl
simp_rw [ENNReal.iSup_mul]
rw [lintegral_iSup h_measM_f h_mono_f, lintegral_iSup, ENNReal.iSup_mul]
· simp_rw [← h_ind_f]
· exact fun n => h_mul_indicator _ (h_measM_f n)
· exact fun m n h_le a => mul_le_mul_right' (h_mono_f h_le a) _
/--
If `f` and `g` are independent random variables with values in `ℝ≥0∞`,
then `E[f * g] = E[f] * E[g]`. However, instead of directly using the independence
of the random variables, it uses the independence of measurable spaces for the
domains of `f` and `g`. This is similar to the sigma-algebra approach to
independence. See `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun` for
a more common variant of the product of independent variables. -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace
{Mf Mg mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (hMg : Mg ≤ mΩ)
(h_ind : Indep Mf Mg μ) (h_meas_f : Measurable[Mf] f) (h_meas_g : Measurable[Mg] g) :
∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by
revert g
have h_measM_f : Measurable f := h_meas_f.mono hMf le_rfl
apply @Measurable.ennreal_induction _ Mg
· intro c s h_s
apply lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator hMf _ (hMg _ h_s) _ h_meas_f
apply indepSets_of_indepSets_of_le_right h_ind
rwa [singleton_subset_iff]
· intro f' g _ h_measMg_f' _ h_ind_f' h_ind_g'
have h_measM_f' : Measurable f' := h_measMg_f'.mono hMg le_rfl
simp_rw [Pi.add_apply, left_distrib]
rw [lintegral_add_left h_measM_f', lintegral_add_left (h_measM_f.mul h_measM_f'), left_distrib,
h_ind_f', h_ind_g']
· intro f' h_meas_f' h_mono_f' h_ind_f'
have h_measM_f' : ∀ n, Measurable (f' n) := fun n => (h_meas_f' n).mono hMg le_rfl
simp_rw [ENNReal.mul_iSup]
rw [lintegral_iSup, lintegral_iSup h_measM_f' h_mono_f', ENNReal.mul_iSup]
· simp_rw [← h_ind_f']
· exact fun n => h_measM_f.mul (h_measM_f' n)
· exact fun n m (h_le : n ≤ m) a => mul_le_mul_left' (h_mono_f' h_le a) _
/-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`,
then `E[f * g] = E[f] * E[g]`. -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (h_meas_f : Measurable f)
(h_meas_g : Measurable g) (h_indep_fun : f ⟂ᵢ[μ] g) :
(∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace
(measurable_iff_comap_le.1 h_meas_f) (measurable_iff_comap_le.1 h_meas_g) h_indep_fun
(Measurable.of_comap_le le_rfl) (Measurable.of_comap_le le_rfl)
/-- If `f` and `g` with values in `ℝ≥0∞` are independent and almost everywhere measurable,
then `E[f * g] = E[f] * E[g]` (slightly generalizing
`lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun`). -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' (h_meas_f : AEMeasurable f μ)
(h_meas_g : AEMeasurable g μ) (h_indep_fun : f ⟂ᵢ[μ] g) :
(∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by
have fg_ae : f * g =ᵐ[μ] h_meas_f.mk _ * h_meas_g.mk _ := h_meas_f.ae_eq_mk.mul h_meas_g.ae_eq_mk
rw [lintegral_congr_ae h_meas_f.ae_eq_mk, lintegral_congr_ae h_meas_g.ae_eq_mk,
lintegral_congr_ae fg_ae]
apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun h_meas_f.measurable_mk
h_meas_g.measurable_mk
exact h_indep_fun.congr h_meas_f.ae_eq_mk h_meas_g.ae_eq_mk
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' (h_meas_f : AEMeasurable f μ)
(h_meas_g : AEMeasurable g μ) (h_indep_fun : f ⟂ᵢ[μ] g) :
∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' h_meas_f h_meas_g h_indep_fun
theorem lintegral_prod_eq_prod_lintegral_of_indepFun {ι : Type*}
(s : Finset ι) (X : ι → Ω → ℝ≥0∞) (hX : iIndepFun X μ)
(x_mea : ∀ i, Measurable (X i)) :
∫⁻ ω, ∏ i ∈ s, (X i ω) ∂μ = ∏ i ∈ s, ∫⁻ ω, X i ω ∂μ := by
have : IsProbabilityMeasure μ := hX.isProbabilityMeasure
induction s using Finset.cons_induction with
| empty => simp only [Finset.prod_empty, lintegral_const, measure_univ, mul_one]
| cons j s hj ihs =>
simp only [← Finset.prod_apply, Finset.prod_cons, ← ihs]
apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'
· exact (x_mea j).aemeasurable
· exact s.aemeasurable_prod (fun i _ ↦ (x_mea i).aemeasurable)
· exact (iIndepFun.indepFun_finset_prod_of_notMem hX x_mea hj).symm
/-- The product of two independent, integrable, real-valued random variables is integrable. -/
theorem IndepFun.integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [BorelSpace β] (hXY : X ⟂ᵢ[μ] Y) (hX : Integrable X μ)
(hY : Integrable Y μ) : Integrable (X * Y) μ := by
let nX : Ω → ℝ≥0∞ := fun a => ‖X a‖ₑ
let nY : Ω → ℝ≥0∞ := fun a => ‖Y a‖ₑ
have hXY' : nX ⟂ᵢ[μ] nY := hXY.comp measurable_enorm measurable_enorm
have hnX : AEMeasurable nX μ := hX.1.aemeasurable.enorm
have hnY : AEMeasurable nY μ := hY.1.aemeasurable.enorm
have hmul : ∫⁻ a, nX a * nY a ∂μ = (∫⁻ a, nX a ∂μ) * ∫⁻ a, nY a ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' hnX hnY hXY'
refine ⟨hX.1.mul hY.1, ?_⟩
simp only [nX, nY] at hmul
simp_rw [hasFiniteIntegral_iff_enorm, Pi.mul_apply, enorm_mul, hmul]
exact ENNReal.mul_lt_top hX.2 hY.2
/-- If the product of two independent real-valued random variables is integrable and
the second one is not almost everywhere zero, then the first one is integrable. -/
theorem IndepFun.integrable_left_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [OpensMeasurableSpace β]
(hXY : X ⟂ᵢ[μ] Y) (h'XY : Integrable (X * Y) μ)
(hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'Y : ¬Y =ᵐ[μ] 0) :
Integrable X μ := by
refine ⟨hX, ?_⟩
have I : (∫⁻ ω, ‖Y ω‖ₑ ∂μ) ≠ 0 := fun H ↦ by
have I : (fun ω => ‖Y ω‖ₑ : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hY.enorm).1 H
apply h'Y
filter_upwards [I] with ω hω
simpa using hω
refine hasFiniteIntegral_iff_enorm.mpr <| lt_top_iff_ne_top.2 fun H => ?_
have J : (‖X ·‖ₑ) ⟂ᵢ[μ] (‖Y ·‖ₑ) := hXY.comp measurable_enorm measurable_enorm
have A : ∫⁻ ω, ‖X ω * Y ω‖ₑ ∂μ < ∞ := h'XY.2
simp only [enorm_mul] at A
rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.enorm hY.enorm J, H] at A
simp only [ENNReal.top_mul I, lt_self_iff_false] at A
/-- If the product of two independent real-valued random variables is integrable and the
first one is not almost everywhere zero, then the second one is integrable. -/
theorem IndepFun.integrable_right_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [OpensMeasurableSpace β]
(hXY : X ⟂ᵢ[μ] Y) (h'XY : Integrable (X * Y) μ)
(hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'X : ¬X =ᵐ[μ] 0) :
Integrable Y μ := by
refine ⟨hY, ?_⟩
have I : ∫⁻ ω, ‖X ω‖ₑ ∂μ ≠ 0 := fun H ↦ by
have I : ((‖X ·‖ₑ) : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hX.enorm).1 H
apply h'X
filter_upwards [I] with ω hω
simpa using hω
refine lt_top_iff_ne_top.2 fun H => ?_
have J : (fun ω => ‖X ω‖ₑ : Ω → ℝ≥0∞) ⟂ᵢ[μ] (fun ω => ‖Y ω‖ₑ : Ω → ℝ≥0∞) :=
IndepFun.comp hXY measurable_enorm measurable_enorm
have A : ∫⁻ ω, ‖X ω * Y ω‖ₑ ∂μ < ∞ := h'XY.2
simp only [enorm_mul] at A
rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.enorm hY.enorm J, H] at A
simp only [ENNReal.mul_top I, lt_self_iff_false] at A
lemma IndepFun.integral_fun_comp_mul_comp {𝓧 𝓨 : Type*} {m𝓧 : MeasurableSpace 𝓧}
{m𝓨 : MeasurableSpace 𝓨} {X : Ω → 𝓧} {Y : Ω → 𝓨} {f : 𝓧 → 𝕜} {g : 𝓨 → 𝕜}
(hXY : X ⟂ᵢ[μ] Y) (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ)
(hf : AEStronglyMeasurable f (μ.map X)) (hg : AEStronglyMeasurable g (μ.map Y)) :
∫ ω, f (X ω) * g (Y ω) ∂μ = (∫ ω, f (X ω) ∂μ) * ∫ ω, g (Y ω) ∂μ := by
have hfXgY := (hXY.comp₀ hX hY hf.aemeasurable hg.aemeasurable)
have hfX := (hf.comp_aemeasurable hX)
have hgY := (hg.comp_aemeasurable hY)
by_cases h'X : ∀ᵐ ω ∂μ, f (X ω) = 0
· have h' : ∀ᵐ ω ∂μ, f (X ω) * g (Y ω) = 0 := by
filter_upwards [h'X] with ω hω
simp [hω]
simp [integral_congr_ae h'X, integral_congr_ae h']
by_cases h'Y : ∀ᵐ ω ∂μ, g (Y ω) = 0
· have h' : ∀ᵐ ω ∂μ, f (X ω) * g (Y ω) = 0 := by
filter_upwards [h'Y] with ω hω
simp [hω]
simp [integral_congr_ae h'Y, integral_congr_ae h']
by_cases h : Integrable (fun ω ↦ f (X ω) * g (Y ω)) μ
· have :=
(hfXgY.integrable_left_of_integrable_mul h hfX hgY h'Y).isProbabilityMeasure_of_indepFun
_ _ h'X hfXgY
change ∫ ω, (fun x ↦ f x.1 * g x.2) (X ω, Y ω) ∂μ = _
rw [← integral_map (f := fun x ↦ f x.1 * g x.2) (φ := fun ω ↦ (X ω, Y ω)),
(indepFun_iff_map_prod_eq_prod_map_map hX hY).1 hXY, integral_prod_mul, integral_map,
integral_map]
any_goals fun_prop
rw [(indepFun_iff_map_prod_eq_prod_map_map hX hY).1 hXY]
exact hf.comp_fst.mul hg.comp_snd
· rw [integral_undef h]
obtain h | h : ¬(Integrable (fun ω ↦ f (X ω)) μ) ∨ ¬(Integrable (fun ω ↦ g (Y ω)) μ) :=
not_and_or.1 fun ⟨HX, HY⟩ ↦ h (hfXgY.integrable_mul HX HY)
all_goals simp [integral_undef h]
lemma IndepFun.integral_comp_mul_comp {𝓧 𝓨 : Type*} {m𝓧 : MeasurableSpace 𝓧}
{m𝓨 : MeasurableSpace 𝓨} {X : Ω → 𝓧} {Y : Ω → 𝓨} {f : 𝓧 → 𝕜} {g : 𝓨 → 𝕜}
(hXY : X ⟂ᵢ[μ] Y) (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ)
(hf : AEStronglyMeasurable f (μ.map X)) (hg : AEStronglyMeasurable g (μ.map Y)) :
μ[(f ∘ X) * (g ∘ Y)] = μ[f ∘ X] * μ[g ∘ Y] :=
hXY.integral_fun_comp_mul_comp hX hY hf hg
lemma IndepFun.integral_mul_eq_mul_integral
(hXY : X ⟂ᵢ[μ] Y) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) :
μ[X * Y] = μ[X] * μ[Y] :=
hXY.integral_comp_mul_comp hX.aemeasurable hY.aemeasurable
aestronglyMeasurable_id aestronglyMeasurable_id
lemma IndepFun.integral_fun_mul_eq_mul_integral
(hXY : X ⟂ᵢ[μ] Y) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) :
∫ ω, X ω * Y ω ∂μ = μ[X] * μ[Y] :=
hXY.integral_mul_eq_mul_integral hX hY
@[deprecated (since := "2025-07-30")] alias IndepFun.integral_mul_of_nonneg :=
IndepFun.integral_mul_eq_mul_integral
@[deprecated (since := "2025-07-30")] alias IndepFun.integral_mul_of_integrable :=
IndepFun.integral_mul_eq_mul_integral
@[deprecated (since := "2025-07-30")] alias IndepFun.integral_mul :=
IndepFun.integral_mul_eq_mul_integral
@[deprecated (since := "2025-07-30")] alias IndepFun.integral_mul' :=
IndepFun.integral_fun_mul_eq_mul_integral
/-- Independence of functions `f` and `g` into arbitrary types is characterized by the relation
`E[(φ ∘ f) * (ψ ∘ g)] = E[φ ∘ f] * E[ψ ∘ g]` for all measurable `φ` and `ψ` with values in `ℝ`
satisfying appropriate integrability conditions. -/
theorem indepFun_iff_integral_comp_mul [IsFiniteMeasure μ] {β β' : Type*} {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} {f : Ω → β} {g : Ω → β'} {hfm : Measurable f} {hgm : Measurable g} :
f ⟂ᵢ[μ] g ↔ ∀ {φ : β → ℝ} {ψ : β' → ℝ}, Measurable φ → Measurable ψ →
Integrable (φ ∘ f) μ → Integrable (ψ ∘ g) μ →
integral μ (φ ∘ f * ψ ∘ g) = integral μ (φ ∘ f) * integral μ (ψ ∘ g) := by
refine ⟨fun hfg _ _ hφ hψ _ _ => hfg.integral_comp_mul_comp
hfm.aemeasurable hgm.aemeasurable hφ.aestronglyMeasurable hψ.aestronglyMeasurable, ?_⟩
rw [IndepFun_iff]
rintro h _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩
specialize
h (measurable_one.indicator hA) (measurable_one.indicator hB)
((integrable_const 1).indicator (hfm.comp measurable_id hA))
((integrable_const 1).indicator (hgm.comp measurable_id hB))
rwa [← ENNReal.toReal_eq_toReal_iff' (measure_ne_top μ _), ENNReal.toReal_mul, ← measureReal_def,
← measureReal_def, ← measureReal_def, ← integral_indicator_one ((hfm hA).inter (hgm hB)),
← integral_indicator_one (hfm hA), ← integral_indicator_one (hgm hB), Set.inter_indicator_one]
exact ENNReal.mul_ne_top (measure_ne_top μ _) (measure_ne_top μ _)
variable {ι : Type*} [Fintype ι] {𝓧 : ι → Type*} {m𝓧 : ∀ i, MeasurableSpace (𝓧 i)}
{X : (i : ι) → Ω → 𝓧 i} {f : (i : ι) → 𝓧 i → 𝕜}
lemma iIndepFun.integral_fun_prod_comp (hX : iIndepFun X μ)
(mX : ∀ i, AEMeasurable (X i) μ) (hf : ∀ i, AEStronglyMeasurable (f i) (μ.map (X i))) :
∫ ω, ∏ i, f i (X i ω) ∂μ = ∏ i, ∫ ω, f i (X i ω) ∂μ := by
have := hX.isProbabilityMeasure
change ∫ ω, (fun x ↦ ∏ i, f i (x i)) (X · ω) ∂μ = _
rw [← integral_map (f := fun x ↦ ∏ i, f i (x i)) (φ := fun ω ↦ (X · ω)),
(iIndepFun_iff_map_fun_eq_pi_map mX).1 hX, integral_fintype_prod_eq_prod]
· congr with i
rw [integral_map (mX i) (hf i)]
· fun_prop
rw [(iIndepFun_iff_map_fun_eq_pi_map mX).1 hX]
exact Finset.aestronglyMeasurable_fun_prod Finset.univ fun i _ ↦
(hf i).comp_quasiMeasurePreserving (Measure.quasiMeasurePreserving_eval _ i)
lemma iIndepFun.integral_prod_comp (hX : iIndepFun X μ)
(mX : ∀ i, AEMeasurable (X i) μ) (hf : ∀ i, AEStronglyMeasurable (f i) (μ.map (X i))) :
μ[∏ i, (f i) ∘ (X i)] = ∏ i, μ[(f i) ∘ (X i)] := by
convert hX.integral_fun_prod_comp mX hf
simp
variable {X : (i : ι) → Ω → 𝕜}
lemma iIndepFun.integral_prod_eq_prod_integral
(hX : iIndepFun X μ) (mX : ∀ i, AEStronglyMeasurable (X i) μ) :
μ[∏ i, X i] = ∏ i, μ[X i] :=
hX.integral_prod_comp (fun i ↦ (mX i).aemeasurable) (fun _ ↦ aestronglyMeasurable_id)
lemma iIndepFun.integral_fun_prod_eq_prod_integral
(hX : iIndepFun X μ) (mX : ∀ i, AEStronglyMeasurable (X i) μ) :
∫ ω, ∏ i, X i ω ∂μ = ∏ i, μ[X i] :=
hX.integral_fun_prod_comp (fun i ↦ (mX i).aemeasurable) (fun _ ↦ aestronglyMeasurable_id)
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/CharacteristicFunction.lean | import Mathlib.MeasureTheory.Measure.CharacteristicFunction
import Mathlib.Probability.Independence.Basic
/-!
# Links between independence and characteristic function
Two random variables are independent if and only if their joint characteristic function is equal
to the product of the characteristic functions. More specifically, prove this in Hilbert spaces for
two variables and a finite family of variables. We prove the analoguous statemens in Banach spaces,
with an arbitrary Lp norm, for the dual characteristic function.
-/
namespace ProbabilityTheory
open MeasureTheory WithLp
open scoped ENNReal
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω}
(p : ℝ≥0∞) [Fact (1 ≤ p)]
section IndepFun
variable [IsFiniteMeasure P] {E F : Type*}
{mE : MeasurableSpace E} [NormedAddCommGroup E] [CompleteSpace E]
[BorelSpace E] [SecondCountableTopology E]
{mF : MeasurableSpace F} [NormedAddCommGroup F] [CompleteSpace F]
[BorelSpace F] [SecondCountableTopology F]
{X : Ω → E} {Y : Ω → F}
section InnerProductSpace
variable [InnerProductSpace ℝ E] [InnerProductSpace ℝ F]
/-- Two random variables are independent if and only if their joint characteristic function is equal
to the product of the characteristic functions. This is the version for Hilbert spaces, see
`indepFun_iff_charFunDual_prod` for the Banach space version. -/
lemma indepFun_iff_charFun_prod (hX : AEMeasurable X P) (hY : AEMeasurable Y P) :
X ⟂ᵢ[P] Y ↔ ∀ t, charFun (P.map (fun ω ↦ toLp 2 (X ω, Y ω))) t =
charFun (P.map X) t.ofLp.1 * charFun (P.map Y) t.ofLp.2 := by
rw [indepFun_iff_map_prod_eq_prod_map_map hX hY, ← charFun_eq_prod_iff,
AEMeasurable.map_map_of_aemeasurable (by fun_prop) (by fun_prop), Function.comp_def]
end InnerProductSpace
section NormedSpace
variable [NormedSpace ℝ E] [NormedSpace ℝ F]
/-- Two random variables are independent if and only if their joint characteristic function is equal
to the product of the characteristic functions. This is the version for Banach spaces, see
`indepFun_iff_charFun_prod` for the Hilbert space version. -/
lemma indepFun_iff_charFunDual_prod (hX : AEMeasurable X P) (hY : AEMeasurable Y P) :
X ⟂ᵢ[P] Y ↔ ∀ L, charFunDual (P.map (fun ω ↦ (X ω, Y ω))) L =
charFunDual (P.map X) (L.comp (.inl ℝ E F)) *
charFunDual (P.map Y) (L.comp (.inr ℝ E F)) := by
rw [indepFun_iff_map_prod_eq_prod_map_map hX hY, ← charFunDual_eq_prod_iff]
/-- Two random variables are independent if and only if their joint characteristic function is equal
to the product of the characteristic functions. This is `indepFun_iff_charFunDual_prod` for
`WithLp`. See `indepFun_iff_charFun_prod` for the Hilbert space version. -/
lemma indepFun_iff_charFunDual_prod' (hX : AEMeasurable X P) (hY : AEMeasurable Y P) :
X ⟂ᵢ[P] Y ↔ ∀ L, charFunDual (P.map (fun ω ↦ toLp p (X ω, Y ω))) L =
charFunDual (P.map X) (L.comp
((prodContinuousLinearEquiv p ℝ E F).symm.toContinuousLinearMap.comp
(.inl ℝ E F))) *
charFunDual (P.map Y) (L.comp
((prodContinuousLinearEquiv p ℝ E F).symm.toContinuousLinearMap.comp
(.inr ℝ E F))) := by
rw [indepFun_iff_map_prod_eq_prod_map_map hX hY, ← charFunDual_eq_prod_iff' p,
AEMeasurable.map_map_of_aemeasurable (by fun_prop) (by fun_prop), Function.comp_def]
end NormedSpace
end IndepFun
section iIndepFun
variable [IsProbabilityMeasure P] {ι : Type*} [Fintype ι] {E : ι → Type*}
{mE : ∀ i, MeasurableSpace (E i)} [∀ i, NormedAddCommGroup (E i)] [∀ i, CompleteSpace (E i)]
[∀ i, BorelSpace (E i)] [∀ i, SecondCountableTopology (E i)] {X : (i : ι) → Ω → E i}
section InnerProductSpace
variable [∀ i, InnerProductSpace ℝ (E i)]
/-- A finite number of random variables are independent if and only if their joint characteristic
function is equal to the product of the characteristic functions. This is the version for Hilbert
spaces, see `iIndepFun_iff_charFunDual_pi` for the Hilbert space version. -/
lemma iIndepFun_iff_charFun_pi (hX : ∀ i, AEMeasurable (X i) P) :
iIndepFun X P ↔ ∀ t, charFun (P.map (fun ω ↦ toLp 2 (X · ω))) t =
∏ i, charFun (P.map (X i)) (t i) := by
rw [iIndepFun_iff_map_fun_eq_pi_map hX, ← charFun_eq_pi_iff,
AEMeasurable.map_map_of_aemeasurable (by fun_prop) (by fun_prop), Function.comp_def]
end InnerProductSpace
section NormedSpace
variable [∀ i, NormedSpace ℝ (E i)] [DecidableEq ι]
/-- A finite number of random variables are independent if and only if their joint characteristic
function is equal to the product of the characteristic functions. This is the version for Banach
spaces, see `iIndepFun_iff_charFun_pi` for the Hilbert space version. -/
lemma iIndepFun_iff_charFunDual_pi (hX : ∀ i, AEMeasurable (X i) P) :
iIndepFun X P ↔ ∀ L, charFunDual (P.map (fun ω ↦ (X · ω))) L =
∏ i, charFunDual (P.map (X i)) (L.comp (.single ℝ E i)) := by
rw [iIndepFun_iff_map_fun_eq_pi_map hX, ← charFunDual_eq_pi_iff]
/-- A finite number of random variables are independent if and only if their joint characteristic
function is equal to the product of the characteristic functions.
This is `iIndepFun_iff_charFunDual_pi` for `WithLp`. See `iIndepFun_iff_charFun_pi` for the
Hilbert space version. -/
lemma iIndepFun_iff_charFunDual_pi' (hX : ∀ i, AEMeasurable (X i) P) :
iIndepFun X P ↔ ∀ L, charFunDual (P.map (fun ω ↦ toLp p (X · ω))) L =
∏ i, charFunDual (P.map (X i)) (L.comp
((PiLp.continuousLinearEquiv p ℝ E).symm.toContinuousLinearMap.comp (.single ℝ E i))) := by
rw [iIndepFun_iff_map_fun_eq_pi_map hX, ← charFunDual_eq_pi_iff' p,
AEMeasurable.map_map_of_aemeasurable (by fun_prop) (by fun_prop), Function.comp_def]
end NormedSpace
end iIndepFun
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/Basic.lean | import Mathlib.Probability.Independence.Kernel
import Mathlib.MeasureTheory.Constructions.Pi
import Mathlib.MeasureTheory.Group.Convolution
/-!
# Independence of sets of sets and measure spaces (σ-algebras)
* A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for
any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`,
`μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. It will be used for families of π-systems.
* A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. I.e., `m : ι → MeasurableSpace Ω` is independent with respect to a
measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`.
* Independence of sets (or events in probabilistic parlance) is defined as independence of the
measurable space structures they generate: a set `s` generates the measurable space structure with
measurable sets `∅, s, sᶜ, univ`.
* Independence of functions (or random variables) is also defined as independence of the measurable
space structures they generate: a function `f` for which we have a measurable space `m` on the
codomain generates `MeasurableSpace.comap f m`.
## Main statements
* `iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the
measurable space structures they generate are independent.
* `IndepSets.indep`: variant with two π-systems.
## Notation
* `X ⟂ᵢ[μ] Y` for `IndepFun X Y μ`, independence of two random variables.
* `X ⟂ᵢ Y` for `IndepFun X Y volume`.
These notations are scoped in the `ProbabilityTheory` namespace.
## Implementation notes
The definitions of independence in this file are a particular case of independence with respect to a
kernel and a measure, as defined in the file `Kernel.lean`.
We provide four definitions of independence:
* `iIndepSets`: independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to
be used with π-systems.
* `iIndep`: independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`,
* `iIndepSet`: independence of a family of sets `s : ι → Set Ω`,
* `iIndepFun`: independence of a family of functions. For measurable spaces
`m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`.
Additionally, we provide four corresponding statements for two measurable space structures (resp.
sets of sets, sets, functions) instead of a family. These properties are denoted by the same names
as for a family, but without the starting `i`, for example `IndepFun` is the version of `iIndepFun`
for two functions.
The definition of independence for `iIndepSets` uses finite sets (`Finset`). See
`ProbabilityTheory.Kernel.iIndepSets`. An alternative and equivalent way of defining independence
would have been to use countable sets.
Most of the definitions and lemmas in this file list all variables instead of using the `variable`
keyword at the beginning of a section, for example
`lemma Indep.symm {Ω} {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : measure Ω} ...` .
This is intentional, to be able to control the order of the `MeasurableSpace` variables. Indeed
when defining `μ` in the example above, the measurable space used is the last one defined, here
`{_mΩ : MeasurableSpace Ω}`, and not `m₁` or `m₂`.
## References
* Williams, David. Probability with martingales. Cambridge university press, 1991.
Part A, Chapter 4.
-/
assert_not_exists MeasureTheory.Integrable
open MeasureTheory MeasurableSpace Set
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory
variable {Ω ι β γ : Type*} {κ : ι → Type*}
section Definitions
/-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i) `.
It will be used for families of pi_systems. -/
def iIndepSets {_mΩ : MeasurableSpace Ω}
(π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepSets π (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets
`t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def IndepSets {_mΩ : MeasurableSpace Ω}
(s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepSets s1 s2 (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. `m : ι → MeasurableSpace Ω` is independent with respect to measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. -/
def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) :
Prop :=
Kernel.iIndep m (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def Indep (m₁ m₂ : MeasurableSpace Ω)
{_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.Indep m₁ m₂ (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepSet s (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepSet s t (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/
def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)]
(f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepFun f (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `MeasurableSpace.comap f m`.
We use the notation `f ⟂ᵢ[μ] g` for `IndepFun f g μ` (scoped in `ProbabilityTheory`). -/
def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [MeasurableSpace β] [MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepFun f g (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
end Definitions
@[inherit_doc ProbabilityTheory.IndepFun]
scoped[ProbabilityTheory] notation3 X:50 " ⟂ᵢ[" μ "] " Y:50 => ProbabilityTheory.IndepFun X Y μ
@[inherit_doc ProbabilityTheory.IndepFun]
scoped[ProbabilityTheory] notation3 X:50 " ⟂ᵢ " Y:50 => ProbabilityTheory.IndepFun X Y volume
section Definition_lemmas
variable {π : ι → Set (Set Ω)} {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω}
{S : Finset ι} {s : ι → Set Ω}
lemma iIndepSets_iff (π : ι → Set (Set Ω)) (μ : Measure Ω) :
iIndepSets π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i),
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp only [iIndepSets, Kernel.iIndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply]
lemma iIndepSets.meas_biInter (h : iIndepSets π μ) (s : Finset ι) {f : ι → Set Ω}
(hf : ∀ i, i ∈ s → f i ∈ π i) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) :=
(iIndepSets_iff _ _).1 h s hf
lemma iIndepSets.isProbabilityMeasure (h : iIndepSets π μ) : IsProbabilityMeasure μ :=
⟨by simpa using h ∅ (f := fun _ ↦ univ)⟩
lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π μ) (hs : ∀ i, s i ∈ π i) :
μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← h.meas_biInter _ fun _i _ ↦ hs _]
lemma IndepSets_iff (s1 s2 : Set (Set Ω)) (μ : Measure Ω) :
IndepSets s1 s2 μ ↔ ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (μ (t1 ∩ t2) = μ t1 * μ t2) := by
simp only [IndepSets, Kernel.IndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply]
lemma iIndep_iff_iIndepSets (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
iIndep m μ ↔ iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := by
simp only [iIndep, iIndepSets, Kernel.iIndep]
lemma iIndep.iIndepSets' {m : ι → MeasurableSpace Ω}
{_ : MeasurableSpace Ω} {μ : Measure Ω} (hμ : iIndep m μ) :
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := (iIndep_iff_iIndepSets _ _).1 hμ
lemma iIndep.isProbabilityMeasure (h : iIndep m μ) : IsProbabilityMeasure μ :=
h.iIndepSets'.isProbabilityMeasure
lemma iIndep_iff (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
iIndep m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)),
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp only [iIndep_iff_iIndepSets, iIndepSets_iff]; rfl
lemma iIndep.meas_biInter (hμ : iIndep m μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) :
μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := (iIndep_iff _ _).1 hμ _ hs
lemma iIndep.meas_iInter [Fintype ι] (hμ : iIndep m μ) (hs : ∀ i, MeasurableSet[m i] (s i)) :
μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← hμ.meas_biInter fun _ _ ↦ hs _]
lemma Indep_iff_IndepSets (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
Indep m₁ m₂ μ ↔ IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by
simp only [Indep, IndepSets, Kernel.Indep]
lemma Indep_iff (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
Indep m₁ m₂ μ
↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
rw [Indep_iff_IndepSets, IndepSets_iff]; rfl
lemma iIndepSet_iff_iIndep (s : ι → Set Ω) (μ : Measure Ω) :
iIndepSet s μ ↔ iIndep (fun i ↦ generateFrom {s i}) μ := by
simp only [iIndepSet, iIndep, Kernel.iIndepSet]
lemma iIndepSet.isProbabilityMeasure (h : iIndepSet s μ) : IsProbabilityMeasure μ :=
((iIndepSet_iff_iIndep _ _).1 h).isProbabilityMeasure
lemma iIndepSet_iff (s : ι → Set Ω) (μ : Measure Ω) :
iIndepSet s μ ↔ ∀ (s' : Finset ι) {f : ι → Set Ω}
(_H : ∀ i, i ∈ s' → MeasurableSet[generateFrom {s i}] (f i)),
μ (⋂ i ∈ s', f i) = ∏ i ∈ s', μ (f i) := by
simp only [iIndepSet_iff_iIndep, iIndep_iff]
lemma IndepSet_iff_Indep (s t : Set Ω) (μ : Measure Ω) :
IndepSet s t μ ↔ Indep (generateFrom {s}) (generateFrom {t}) μ := by
simp only [IndepSet, Indep, Kernel.IndepSet]
lemma IndepSet_iff (s t : Set Ω) (μ : Measure Ω) :
IndepSet s t μ ↔ ∀ t1 t2, MeasurableSet[generateFrom {s}] t1
→ MeasurableSet[generateFrom {t}] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
simp only [IndepSet_iff_Indep, Indep_iff]
lemma iIndepFun_iff_iIndep {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) :
iIndepFun f μ ↔ iIndep (fun x ↦ (m x).comap (f x)) μ := by
simp only [iIndepFun, iIndep, Kernel.iIndepFun]
@[nontriviality, simp]
lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} [IsProbabilityMeasure μ] :
iIndepSets m μ := Kernel.iIndepSets.of_subsingleton
@[nontriviality, simp]
lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} [IsProbabilityMeasure μ] :
iIndep m μ := Kernel.iIndep.of_subsingleton
@[nontriviality, simp]
lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)}
{f : ∀ i, Ω → β i} [IsProbabilityMeasure μ] : iIndepFun f μ :=
Kernel.iIndepFun.of_subsingleton
protected lemma iIndepFun.iIndep {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) :
iIndep (fun x ↦ (m x).comap (f x)) μ := hf
lemma iIndepFun_iff {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) :
iIndepFun f μ ↔ ∀ (s : Finset ι) {f' : ι → Set Ω}
(_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (f' i)),
μ (⋂ i ∈ s, f' i) = ∏ i ∈ s, μ (f' i) := by
simp only [iIndepFun_iff_iIndep, iIndep_iff]
lemma iIndepFun.meas_biInter {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) (hs : ∀ i, i ∈ S → MeasurableSet[(m i).comap (f i)] (s i)) :
μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := hf.iIndep.meas_biInter hs
lemma iIndepFun.meas_iInter [Fintype ι] {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) (hs : ∀ i, MeasurableSet[(m i).comap (f i)] (s i)) :
μ (⋂ i, s i) = ∏ i, μ (s i) := hf.iIndep.meas_iInter hs
lemma IndepFun_iff_Indep [mβ : MeasurableSpace β]
[mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) :
f ⟂ᵢ[μ] g ↔ Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) μ := by
simp only [IndepFun, Indep, Kernel.IndepFun]
lemma IndepFun_iff {β γ} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (μ : Measure Ω) :
f ⟂ᵢ[μ] g ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1
→ MeasurableSet[MeasurableSpace.comap g mγ] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
rw [IndepFun_iff_Indep, Indep_iff]
lemma IndepFun.meas_inter [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ}
(hfg : f ⟂ᵢ[μ] g) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s)
(ht : MeasurableSet[mγ.comap g] t) :
μ (s ∩ t) = μ s * μ t :=
(IndepFun_iff _ _ _).1 hfg _ _ hs ht
end Definition_lemmas
section Indep
variable {m₁ m₂ m₃ : MeasurableSpace Ω} (m' : MeasurableSpace Ω)
{_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
@[symm]
theorem IndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ μ) : IndepSets s₂ s₁ μ :=
Kernel.IndepSets.symm h
@[symm]
theorem Indep.symm (h : Indep m₁ m₂ μ) : Indep m₂ m₁ μ := IndepSets.symm h
theorem indep_bot_right [IsZeroOrProbabilityMeasure μ] : Indep m' ⊥ μ :=
Kernel.indep_bot_right m'
theorem indep_bot_left [IsZeroOrProbabilityMeasure μ] : Indep ⊥ m' μ := (indep_bot_right m').symm
theorem indepSet_empty_right [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet s ∅ μ :=
Kernel.indepSet_empty_right s
theorem indepSet_empty_left [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet ∅ s μ :=
Kernel.indepSet_empty_left s
theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : IndepSets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) :
IndepSets s₃ s₂ μ :=
Kernel.indepSets_of_indepSets_of_le_left h_indep h31
theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : IndepSets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) :
IndepSets s₁ s₃ μ :=
Kernel.indepSets_of_indepSets_of_le_right h_indep h32
theorem indep_of_indep_of_le_left (h_indep : Indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) :
Indep m₃ m₂ μ :=
Kernel.indep_of_indep_of_le_left h_indep h31
theorem indep_of_indep_of_le_right (h_indep : Indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) :
Indep m₁ m₃ μ :=
Kernel.indep_of_indep_of_le_right h_indep h32
theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : IndepSets s₁ s' μ) (h₂ : IndepSets s₂ s' μ) :
IndepSets (s₁ ∪ s₂) s' μ :=
Kernel.IndepSets.union h₁ h₂
@[simp]
theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} :
IndepSets (s₁ ∪ s₂) s' μ ↔ IndepSets s₁ s' μ ∧ IndepSets s₂ s' μ :=
Kernel.IndepSets.union_iff
theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(hyp : ∀ n, IndepSets (s n) s' μ) :
IndepSets (⋃ n, s n) s' μ :=
Kernel.IndepSets.iUnion hyp
theorem IndepSets.biUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' μ) :
IndepSets (⋃ n ∈ u, s n) s' μ :=
Kernel.IndepSets.biUnion hyp
@[deprecated (since := "2025-10-28")] alias IndepSets.bUnion := IndepSets.biUnion
theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : IndepSets s₁ s' μ) :
IndepSets (s₁ ∩ s₂) s' μ :=
Kernel.IndepSets.inter s₂ h₁
theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(h : ∃ n, IndepSets (s n) s' μ) :
IndepSets (⋂ n, s n) s' μ :=
Kernel.IndepSets.iInter h
theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' μ) :
IndepSets (⋂ n ∈ u, s n) s' μ :=
Kernel.IndepSets.bInter h
theorem indepSets_singleton_iff {s t : Set Ω} :
IndepSets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t := by
simp only [IndepSets, Kernel.indepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
lemma indepSets_iff_singleton_indepSets {𝒜 ℬ : Set (Set Ω)} :
IndepSets 𝒜 ℬ μ ↔ ∀ A ∈ 𝒜, IndepSets {A} ℬ μ where
mp h A hA := indepSets_of_indepSets_of_le_left h (Set.singleton_subset_iff.2 hA)
mpr h := by
rw [← 𝒜.biUnion_of_singleton]
exact IndepSets.biUnion h
end Indep
/-! ### Deducing `Indep` from `iIndep` -/
section FromIndepToIndep
variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
theorem iIndepSets.indepSets {s : ι → Set (Set Ω)}
(h_indep : iIndepSets s μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) μ :=
Kernel.iIndepSets.indepSets h_indep hij
theorem iIndep.indep
(h_indep : iIndep m μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) μ :=
Kernel.iIndep.indep h_indep hij
theorem iIndepFun.indepFun {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f μ) {i j : ι}
(hij : i ≠ j) :
f i ⟂ᵢ[μ] f j :=
Kernel.iIndepFun.indepFun hf_Indep hij
end FromIndepToIndep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section FromMeasurableSpacesToSetsOfSets
variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
theorem iIndep.iIndepSets
{s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m μ) :
iIndepSets s μ :=
Kernel.iIndep.iIndepSets hms h_indep
theorem Indep.indepSets {s1 s2 : Set (Set Ω)}
(h_indep : Indep (generateFrom s1) (generateFrom s2) μ) :
IndepSets s1 s2 μ :=
Kernel.Indep.indepSets h_indep
end FromMeasurableSpacesToSetsOfSets
section FromPiSystemsToMeasurableSpaces
variable {m : ι → MeasurableSpace Ω} {m1 m2 _mΩ : MeasurableSpace Ω} {μ : Measure Ω}
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
theorem IndepSets.indep [IsZeroOrProbabilityMeasure μ]
{p1 p2 : Set (Set Ω)} (h1 : m1 ≤ _mΩ) (h2 : m2 ≤ _mΩ) (hp1 : IsPiSystem p1)
(hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2)
(hyp : IndepSets p1 p2 μ) :
Indep m1 m2 μ :=
Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp
theorem IndepSets.indep' [IsZeroOrProbabilityMeasure μ]
{p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 μ) :
Indep (generateFrom p1) (generateFrom p2) μ :=
Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp
theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)}
{S T : Set ι} (h_indep : iIndepSets s μ) (hST : Disjoint S T) :
IndepSets (piiUnionInter s S) (piiUnionInter s T) μ :=
Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST
theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (S T : Set ι) (hST : Disjoint S T) :
Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST
theorem indep_iSup_of_disjoint
(h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m μ) {S T : Set ι} (hST : Disjoint S T) :
Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) μ :=
Kernel.indep_iSup_of_disjoint h_le h_indep hST
theorem indep_iSup_of_directed_le
[IsZeroOrProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ)
(h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Directed (· ≤ ·) m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm
theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) :
Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_lt hsm hs i
theorem iIndepSet.indep_generateFrom_le [Preorder ι]
{s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) {k : ι} (hk : i < k) :
Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk
theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (n : ℕ) :
Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n
theorem indep_iSup_of_monotone [SemilatticeSup ι] [IsZeroOrProbabilityMeasure μ]
(h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Monotone m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm
theorem indep_iSup_of_antitone [SemilatticeInf ι] [IsZeroOrProbabilityMeasure μ]
(h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Antitone m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm
theorem iIndepSets.piiUnionInter_of_notMem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι}
(hp_ind : iIndepSets π μ) (haS : a ∉ S) :
IndepSets (piiUnionInter π S) (π a) μ :=
Kernel.iIndepSets.piiUnionInter_of_notMem hp_ind haS
@[deprecated (since := "2025-05-23")]
alias iIndepSets.piiUnionInter_of_not_mem := iIndepSets.piiUnionInter_of_notMem
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem iIndepSets.iIndep
(h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n))
(h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π μ) :
iIndep m μ :=
Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind
end FromPiSystemsToMeasurableSpaces
section IndepSet
/-! ### Independence of measurable sets
We prove the following equivalences on `IndepSet`, for measurable sets `s, t`.
* `IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t`,
* `IndepSet s t μ ↔ IndepSets {s} {t} μ`.
-/
variable {m₁ m₂ _mΩ : MeasurableSpace Ω} {μ : Measure Ω} {s t : Set Ω} (S T : Set (Set Ω))
theorem indepSet_iff_indepSets_singleton (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac)
[IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ IndepSets {s} {t} μ :=
Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _
theorem indepSet_iff_measure_inter_eq_mul (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac)
[IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t :=
(indepSet_iff_indepSets_singleton hs_meas ht_meas μ).trans indepSets_singleton_iff
lemma IndepSet.measure_inter_eq_mul {μ : Measure Ω} (h : IndepSet s t μ) :
μ (s ∩ t) = μ s * μ t := by
simpa using Kernel.IndepSet.measure_inter_eq_mul _ _ h
theorem IndepSets.indepSet_of_mem (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t)
(μ : Measure Ω := by volume_tac) [IsZeroOrProbabilityMeasure μ]
(h_indep : IndepSets S T μ) :
IndepSet s t μ :=
Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep
theorem Indep.indepSet_of_measurableSet
(h_indep : Indep m₁ m₂ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) :
IndepSet s t μ :=
Kernel.Indep.indepSet_of_measurableSet h_indep hs ht
theorem indep_iff_forall_indepSet (μ : Measure Ω) :
Indep m₁ m₂ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t μ :=
Kernel.indep_iff_forall_indepSet m₁ m₂ _ _
theorem iIndep_comap_mem_iff {f : ι → Set Ω} :
iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) μ ↔ iIndepSet f μ :=
Kernel.iIndep_comap_mem_iff
alias ⟨_, iIndepSet.iIndep_comap_mem⟩ := iIndep_comap_mem_iff
theorem iIndepSets_singleton_iff {s : ι → Set Ω} :
iIndepSets (fun i ↦ {s i}) μ ↔ ∀ t, μ (⋂ i ∈ t, s i) = ∏ i ∈ t, μ (s i) := by
simp_rw [iIndepSets, Kernel.iIndepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
theorem iIndepSet.meas_biInter {f : ι → Set Ω} (h : iIndepSet f μ) (s : Finset ι) :
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simpa using Kernel.iIndepSet.meas_biInter h s
theorem iIndepSet_iff_iIndepSets_singleton {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f μ ↔ iIndepSets (fun i ↦ {f i}) μ :=
Kernel.iIndepSet_iff_iIndepSets_singleton hf
theorem iIndepSet_iff_meas_biInter {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f μ ↔ ∀ s, μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp_rw [iIndepSet, Kernel.iIndepSet_iff_meas_biInter hf, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
theorem iIndepSets.iIndepSet_of_mem {π : ι → Set (Set Ω)} {f : ι → Set Ω}
(hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i))
(hπ : iIndepSets π μ) : iIndepSet f μ :=
Kernel.iIndepSets.iIndepSet_of_mem hfπ hf hπ
end IndepSet
section IndepFun
/-! ### Independence of random variables
-/
variable {β β' γ γ' : Type*} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → β} {g : Ω → β'}
theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} :
f ⟂ᵢ[μ] g ↔
∀ s t, MeasurableSet s → MeasurableSet t
→ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) := by
simp only [IndepFun, Kernel.indepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq,
Filter.eventually_pure, Kernel.const_apply]
alias ⟨IndepFun.measure_inter_preimage_eq_mul, _⟩ := indepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} :
iIndepFun f μ ↔
∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)),
μ (⋂ i ∈ S, f i ⁻¹' sets i) = ∏ i ∈ S, μ (f i ⁻¹' sets i) := by
simp only [iIndepFun, Kernel.iIndepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq,
Filter.eventually_pure, Kernel.const_apply]
alias ⟨iIndepFun.measure_inter_preimage_eq_mul, _⟩ := iIndepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_congr {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{f g : Π i, Ω → β i} (h : ∀ i, f i =ᵐ[μ] g i) :
iIndepFun f μ ↔ iIndepFun g μ := Kernel.iIndepFun_congr' (by simp [h])
alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr
nonrec lemma iIndepFun.comp {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f μ) (g : ∀ i, β i → γ i) (hg : ∀ i, Measurable (g i)) :
iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp _ hg
nonrec lemma iIndepFun.comp₀ {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f μ) (g : ∀ i, β i → γ i)
(hf : ∀ i, AEMeasurable (f i) μ) (hg : ∀ i, AEMeasurable (g i) (μ.map (f i))) :
iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp₀ _ (by simp [hf]) (by simp [hg])
theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrProbabilityMeasure μ] (hf : Measurable f) (hg : Measurable g) :
f ⟂ᵢ[μ] g ↔
∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) μ := by
simp only [IndepFun, IndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg]
theorem indepFun_iff_map_prod_eq_prod_map_map' {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) :
f ⟂ᵢ[μ] g ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by
rw [indepFun_iff_measure_inter_preimage_eq_mul]
have h₀ {s : Set β} {t : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t) :
μ (f ⁻¹' s) * μ (g ⁻¹' t) = μ.map f s * μ.map g t ∧
μ (f ⁻¹' s ∩ g ⁻¹' t) = μ.map (fun ω ↦ (f ω, g ω)) (s ×ˢ t) :=
⟨by rw [Measure.map_apply_of_aemeasurable hf hs, Measure.map_apply_of_aemeasurable hg ht],
(Measure.map_apply_of_aemeasurable (hf.prodMk hg) (hs.prod ht)).symm⟩
constructor
· refine fun h ↦ (Measure.prod_eq fun s t hs ht ↦ ?_).symm
rw [← (h₀ hs ht).1, ← (h₀ hs ht).2, h s t hs ht]
· intro h s t hs ht
rw [(h₀ hs ht).1, (h₀ hs ht).2, h, Measure.prod_prod]
theorem indepFun_iff_map_prod_eq_prod_map_map {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsFiniteMeasure μ] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
f ⟂ᵢ[μ] g ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by
apply indepFun_iff_map_prod_eq_prod_map_map' hf hg <;> apply IsFiniteMeasure.toSigmaFinite
theorem iIndepFun_iff_map_fun_eq_pi_map [Fintype ι] {β : ι → Type*}
{m : ∀ i, MeasurableSpace (β i)} {f : Π i, Ω → β i} [IsProbabilityMeasure μ]
(hf : ∀ i, AEMeasurable (f i) μ) :
iIndepFun f μ ↔ μ.map (fun ω i ↦ f i ω) = Measure.pi (fun i ↦ μ.map (f i)) := by
classical
rw [iIndepFun_iff_measure_inter_preimage_eq_mul]
have h₀ {s : ∀ i, Set (β i)} (hm : ∀ (i : ι), MeasurableSet (s i)) :
∏ i : ι, μ (f i ⁻¹' s i) = ∏ i : ι, μ.map (f i) (s i) ∧
μ (⋂ i : ι, (f i ⁻¹' s i)) = μ.map (fun ω i ↦ f i ω) (univ.pi s) := by
constructor
· congr with x
rw [Measure.map_apply_of_aemeasurable (hf x) (hm x)]
· rw [Measure.map_apply_of_aemeasurable (aemeasurable_pi_lambda _ fun x ↦ hf x)
(.univ_pi hm)]
congr with x
simp
constructor
· refine fun hS ↦ (Measure.pi_eq fun h hm ↦ ?_).symm
rw [← (h₀ hm).1, ← (h₀ hm).2]
simpa [hm] using hS Finset.univ (sets := h)
· intro h S s hs
specialize h₀ (s := fun i ↦ if i ∈ S then s i else univ)
fun i ↦ by beta_reduce; split_ifs with hiS <;> simp [hiS, hs]
simp only [apply_ite, preimage_univ, measure_univ, Finset.prod_ite_mem, Finset.univ_inter,
Finset.prod_ite, Finset.filter_univ_mem, iInter_ite, iInter_univ, inter_univ, h,
Measure.pi_pi] at h₀
rw [h₀.2, ← h₀.1]
@[symm]
nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'}
(hfg : f ⟂ᵢ[μ] g) : g ⟂ᵢ[μ] f := hfg.symm
theorem IndepFun.congr {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{f' : Ω → β} {g' : Ω → β'} (hfg : f ⟂ᵢ[μ] g) (hf : f =ᵐ[μ] f') (hg : g =ᵐ[μ] g') :
f' ⟂ᵢ[μ] g' := by
refine Kernel.IndepFun.congr' hfg ?_ ?_ <;> simpa
section Prod
variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'}
{μ : Measure Ω} {ν : Measure Ω'} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]
{𝓧 𝓨 : Type*} [MeasurableSpace 𝓧] [MeasurableSpace 𝓨] {X : Ω → 𝓧} {Y : Ω' → 𝓨}
/-- Given random variables `X : Ω → 𝓧` and `Y : Ω' → 𝓨`, they are independent when viewed as random
variables defined on the product space `Ω × Ω'`. -/
lemma indepFun_prod (mX : Measurable X) (mY : Measurable Y) :
(fun ω ↦ X ω.1) ⟂ᵢ[μ.prod ν] (fun ω ↦ Y ω.2) := by
refine indepFun_iff_map_prod_eq_prod_map_map (by fun_prop) (by fun_prop) |>.2 ?_
convert Measure.map_prod_map μ ν mX mY |>.symm
· rw [← Function.comp_def, ← Measure.map_map mX measurable_fst, Measure.map_fst_prod,
measure_univ, one_smul]
· rw [← Function.comp_def, ← Measure.map_map mY measurable_snd, Measure.map_snd_prod,
measure_univ, one_smul]
/-- Given random variables `X : Ω → 𝓧` and `Y : Ω' → 𝓨`, they are independent when viewed as random
variables defined on the product space `Ω × Ω'`. -/
lemma indepFun_prod₀ (mX : AEMeasurable X μ) (mY : AEMeasurable Y ν) :
(fun ω ↦ X ω.1) ⟂ᵢ[μ.prod ν] (fun ω ↦ Y ω.2) := by
have : (fun ω ↦ mX.mk X ω.1) ⟂ᵢ[μ.prod ν] (fun ω ↦ mY.mk Y ω.2) :=
indepFun_prod mX.measurable_mk mY.measurable_mk
refine this.congr ?_ ?_
· rw [← Function.comp_def, ← Function.comp_def]
apply ae_eq_comp
· exact measurable_fst.aemeasurable
· rw [measurePreserving_fst.map_eq]
exact (AEMeasurable.ae_eq_mk mX).symm
· rw [← Function.comp_def, ← Function.comp_def]
apply ae_eq_comp
· exact measurable_snd.aemeasurable
· rw [measurePreserving_snd.map_eq]
exact (AEMeasurable.ae_eq_mk mY).symm
variable {ι : Type*} [Fintype ι] {Ω : ι → Type*} {mΩ : ∀ i, MeasurableSpace (Ω i)}
{μ : (i : ι) → Measure (Ω i)} [∀ i, IsProbabilityMeasure (μ i)]
{𝓧 : ι → Type*} [∀ i, MeasurableSpace (𝓧 i)] {X : (i : ι) → Ω i → 𝓧 i}
/-- Given random variables `X i : Ω i → 𝓧 i`, they are independent when viewed as random
variables defined on the product space `Π i, Ω i`. -/
lemma iIndepFun_pi (mX : ∀ i, AEMeasurable (X i) (μ i)) :
iIndepFun (fun i ω ↦ X i (ω i)) (Measure.pi μ) := by
refine iIndepFun_iff_map_fun_eq_pi_map ?_ |>.2 ?_
· exact fun i ↦ (mX i).comp_quasiMeasurePreserving (Measure.quasiMeasurePreserving_eval _ i)
rw [Measure.pi_map_pi mX]
congr
ext i : 1
rw [← (measurePreserving_eval μ i).map_eq, AEMeasurable.map_map_of_aemeasurable,
Function.comp_def]
· rw [(measurePreserving_eval μ i).map_eq]
exact mX i
· exact (measurable_pi_apply i).aemeasurable
end Prod
theorem IndepFun.comp {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'}
{_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : f ⟂ᵢ[μ] g) (hφ : Measurable φ) (hψ : Measurable ψ) :
(φ ∘ f) ⟂ᵢ[μ] ψ ∘ g :=
Kernel.IndepFun.comp hfg hφ hψ
theorem IndepFun.comp₀ {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'}
{_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : f ⟂ᵢ[μ] g) (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hφ : AEMeasurable φ (μ.map f)) (hψ : AEMeasurable ψ (μ.map g)) :
(φ ∘ f) ⟂ᵢ[μ] (ψ ∘ g) :=
Kernel.IndepFun.comp₀ hfg (by simp [hf]) (by simp [hg]) (by simp [hφ]) (by simp [hψ])
lemma indepFun_const_left {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrProbabilityMeasure μ] (c : β) (X : Ω → β') :
(fun _ ↦ c) ⟂ᵢ[μ] X :=
Kernel.indepFun_const_left c X
lemma indepFun_const_right {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrProbabilityMeasure μ] (X : Ω → β) (c : β') :
X ⟂ᵢ[μ] (fun _ ↦ c) :=
Kernel.indepFun_const_right X c
theorem IndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β']
[MeasurableNeg β'] (hfg : f ⟂ᵢ[μ] g) :
f ⟂ᵢ[μ] (-g) := hfg.comp measurable_id measurable_neg
theorem IndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β]
[MeasurableNeg β] (hfg : f ⟂ᵢ[μ] g) :
(-f) ⟂ᵢ[μ] g := hfg.comp measurable_neg measurable_id
section iIndepFun
variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i}
lemma iIndepFun.isProbabilityMeasure (h : iIndepFun f μ) : IsProbabilityMeasure μ :=
⟨by simpa using h.meas_biInter (S := ∅) (s := fun _ ↦ univ)⟩
/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma iIndepFun.indepFun_finset (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) :
IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) μ :=
Kernel.iIndepFun.indepFun_finset S T hST hf_Indep hf_meas
/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma iIndepFun.indepFun_finset₀ (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) :
IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) μ :=
Kernel.iIndepFun.indepFun_finset₀ S T hST hf_Indep (by simp [hf_meas])
lemma iIndepFun.indepFun_prodMk (hf_Indep : iIndepFun f μ) (hf_meas : ∀ i, Measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a => (f i a, f j a)) (f k) μ :=
Kernel.iIndepFun.indepFun_prodMk hf_Indep hf_meas i j k hik hjk
lemma iIndepFun.indepFun_prodMk₀ (hf_Indep : iIndepFun f μ) (hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a => (f i a, f j a)) (f k) μ :=
Kernel.iIndepFun.indepFun_prodMk₀ hf_Indep (by simp [hf_meas]) i j k hik hjk
lemma iIndepFun.indepFun_prodMk_prodMk (h_indep : iIndepFun f μ) (hf : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ :=
Kernel.iIndepFun.indepFun_prodMk_prodMk h_indep hf i j k l hik hil hjk hjl
lemma iIndepFun.indepFun_prodMk_prodMk₀ (h_indep : iIndepFun f μ) (hf : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ :=
Kernel.iIndepFun.indepFun_prodMk_prodMk₀ h_indep (by simp [hf]) i j k l hik hil hjk hjl
variable {ι' : Type*} {α : ι → Type*} [∀ i, MeasurableSpace (α i)]
open Function in
lemma iIndepFun.precomp {g : ι' → ι} (hg : g.Injective) (h : iIndepFun f μ) :
iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ := by
have : IsProbabilityMeasure μ := h.isProbabilityMeasure
nontriviality ι'
have A (x) : Function.invFun g (g x) = x := Function.leftInverse_invFun hg x
rw [iIndepFun_iff] at h ⊢
intro t s' hs'
simpa [A] using h (t.map ⟨g, hg⟩) (f' := fun i ↦ s' (invFun g i)) (by simpa [A] using hs')
lemma iIndepFun_iff_finset : iIndepFun f μ ↔ ∀ s : Finset ι, iIndepFun (s.restrict f) μ where
mp h s := h.precomp (g := ((↑) : s → ι)) Subtype.val_injective
mpr h := by
rw [iIndepFun_iff]
intro s f hs
have : ⋂ i ∈ s, f i = ⋂ i : s, f i := by ext; simp
rw [← Finset.prod_coe_sort, this]
exact (h s).meas_iInter fun i ↦ hs i i.2
lemma iIndepFun.of_precomp {g : ι' → ι} (hg : g.Surjective)
(h : iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ) : iIndepFun f μ := by
have : IsProbabilityMeasure μ := h.isProbabilityMeasure
nontriviality ι
have := hg.nontrivial
classical
rw [iIndepFun_iff] at h ⊢
intro t s hs
have A (x) : g (Function.invFun g x) = x := Function.rightInverse_invFun hg x
have : ∀ i ∈ Finset.image (Function.invFun g) t,
@MeasurableSet _ (MeasurableSpace.comap (f <| g i) (m <| g i)) (s <| g i) := by
intro i hi
obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hi
simpa [A] using (A j).symm ▸ hs j hj
have eq : ∏ i ∈ Finset.image (Function.invFun g) t, μ (s (g i)) = ∏ i ∈ t, μ (s i) := by
rw [Finset.prod_image (fun x hx y hy h => ?_), Finset.prod_congr rfl (fun x _ => by rw [A])]
rw [← A x, ← A y, h]
simpa [A, eq] using h (t.image (Function.invFun g)) (f' := fun i ↦ s (g i)) this
lemma iIndepFun_precomp_of_bijective {g : ι' → ι} (hg : g.Bijective) :
iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ ↔ iIndepFun f μ where
mp := .of_precomp hg.surjective
mpr := .precomp hg.injective
end iIndepFun
section Mul
variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_mul_left (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) μ :=
Kernel.iIndepFun.indepFun_mul_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_mul_left₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) μ :=
Kernel.iIndepFun.indepFun_mul_left₀ hf_indep (by simp [hf_meas]) i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_mul_right (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) μ :=
Kernel.iIndepFun.indepFun_mul_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_mul_right₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) μ :=
Kernel.iIndepFun.indepFun_mul_right₀ hf_indep (by simp [hf_meas]) i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_mul_mul (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) μ :=
Kernel.iIndepFun.indepFun_mul_mul hf_indep hf_meas i j k l hik hil hjk hjl
@[to_additive]
lemma iIndepFun.indepFun_mul_mul₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) μ :=
Kernel.iIndepFun.indepFun_mul_mul₀ hf_indep (by simp [hf_meas]) i j k l hik hil hjk hjl
end Mul
section Div
variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_div_left (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) μ :=
Kernel.iIndepFun.indepFun_div_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_div_left₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) μ :=
Kernel.iIndepFun.indepFun_div_left₀ hf_indep (by simp [hf_meas]) i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_div_right (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) μ :=
Kernel.iIndepFun.indepFun_div_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_div_right₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) μ :=
Kernel.iIndepFun.indepFun_div_right₀ hf_indep (by simp [hf_meas]) i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_div_div (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) μ :=
Kernel.iIndepFun.indepFun_div_div hf_indep hf_meas i j k l hik hil hjk hjl
@[to_additive]
lemma iIndepFun.indepFun_div_div₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) μ :=
Kernel.iIndepFun.indepFun_div_div₀ hf_indep (by simp [hf_meas]) i j k l hik hil hjk hjl
end Div
section CommMonoid
variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_finset_prod_of_notMem (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) μ :=
Kernel.iIndepFun.indepFun_finset_prod_of_notMem hf_Indep hf_meas hi
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem := iIndepFun.indepFun_finset_sum_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem := iIndepFun.indepFun_finset_prod_of_notMem
@[to_additive]
lemma iIndepFun.indepFun_finset_prod_of_notMem₀ (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) μ :=
Kernel.iIndepFun.indepFun_finset_prod_of_notMem₀ hf_Indep (by simp [hf_meas]) hi
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem₀ := iIndepFun.indepFun_finset_sum_of_notMem₀
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem₀ := iIndepFun.indepFun_finset_prod_of_notMem₀
@[to_additive]
lemma iIndepFun.indepFun_prod_range_succ {f : ℕ → Ω → β} (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (n : ℕ) : IndepFun (∏ j ∈ Finset.range n, f j) (f n) μ :=
Kernel.iIndepFun.indepFun_prod_range_succ hf_Indep hf_meas n
@[to_additive]
lemma iIndepFun.indepFun_prod_range_succ₀ {f : ℕ → Ω → β} (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (n : ℕ) :
IndepFun (∏ j ∈ Finset.range n, f j) (f n) μ :=
hf_Indep.indepFun_finset_prod_of_notMem₀ hf_meas (by simp)
end CommMonoid
theorem iIndepSet.iIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω}
(hs : iIndepSet s μ) :
iIndepFun (fun n => (s n).indicator fun _ω => (1 : β)) μ :=
Kernel.iIndepSet.iIndepFun_indicator hs
end IndepFun
variable {ι Ω α β : Type*} {mΩ : MeasurableSpace Ω} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} {μ : Measure Ω} {X : ι → Ω → α} {Y : ι → Ω → β} {f : _ → Set Ω}
{t : ι → Set β} {s : Finset ι}
/-- The probability of an intersection of preimages conditioning on another intersection factors
into a product. -/
lemma cond_iInter [Finite ι] (hY : ∀ i, Measurable (Y i))
(hindep : iIndepFun (fun i ω ↦ (X i ω, Y i ω)) μ)
(hf : ∀ i ∈ s, MeasurableSet[mα.comap (X i)] (f i))
(hy : ∀ i ∉ s, μ (Y i ⁻¹' t i) ≠ 0) (ht : ∀ i, MeasurableSet (t i)) :
μ[⋂ i ∈ s, f i | ⋂ i, Y i ⁻¹' t i] = ∏ i ∈ s, μ[f i | Y i in t i] := by
have : IsProbabilityMeasure (μ : Measure Ω) := hindep.isProbabilityMeasure
classical
cases nonempty_fintype ι
let g (i' : ι) := if i' ∈ s then Y i' ⁻¹' t i' ∩ f i' else Y i' ⁻¹' t i'
calc
_ = (μ (⋂ i, Y i ⁻¹' t i))⁻¹ * μ ((⋂ i, Y i ⁻¹' t i) ∩ ⋂ i ∈ s, f i) := by
rw [cond_apply]; exact .iInter fun i ↦ hY i (ht i)
_ = (μ (⋂ i, Y i ⁻¹' t i))⁻¹ * μ (⋂ i, g i) := by
congr
calc
_ = (⋂ i, Y i ⁻¹' t i) ∩ ⋂ i, if i ∈ s then f i else .univ := by
simp only [Set.iInter_ite, Set.iInter_univ, Set.inter_univ]
_ = ⋂ i, Y i ⁻¹' t i ∩ (if i ∈ s then f i else .univ) := by rw [Set.iInter_inter_distrib]
_ = _ := Set.iInter_congr fun i ↦ by by_cases hi : i ∈ s <;> simp [hi, g]
_ = (∏ i, μ (Y i ⁻¹' t i))⁻¹ * μ (⋂ i, g i) := by
rw [hindep.meas_iInter]
exact fun i ↦ ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
_ = (∏ i, μ (Y i ⁻¹' t i))⁻¹ * ∏ i, μ (g i) := by
rw [hindep.meas_iInter]
intro i
by_cases hi : i ∈ s <;> simp only [hi, ↓reduceIte, g]
· obtain ⟨A, hA, hA'⟩ := hf i hi
exact .inter ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
⟨A ×ˢ Set.univ, hA.prod .univ, by ext; simp [← hA']⟩
· exact ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
_ = ∏ i, (μ (Y i ⁻¹' t i))⁻¹ * μ (g i) := by
rw [Finset.prod_mul_distrib, ENNReal.prod_inv_distrib]
exact fun _ _ i _ _ ↦ .inr <| measure_ne_top _ _
_ = ∏ i, if i ∈ s then μ[f i | Y i ⁻¹' t i] else 1 := by
refine Finset.prod_congr rfl fun i _ ↦ ?_
by_cases hi : i ∈ s
· simp only [hi, ↓reduceIte, g, cond_apply (hY i (ht i))]
· simp only [hi, ↓reduceIte, g, ENNReal.inv_mul_cancel (hy i hi) (measure_ne_top μ _)]
_ = _ := by simp
lemma iIndepFun.cond [Finite ι] (hY : ∀ i, Measurable (Y i))
(hindep : iIndepFun (fun i ω ↦ (X i ω, Y i ω)) μ)
(hy : ∀ i, μ (Y i ⁻¹' t i) ≠ 0) (ht : ∀ i, MeasurableSet (t i)) :
iIndepFun X μ[|⋂ i, Y i ⁻¹' t i] := by
rw [iIndepFun_iff]
intro s f hf
convert cond_iInter hY hindep hf (fun i _ ↦ hy _) ht using 2 with i hi
simpa using cond_iInter hY hindep (fun j hj ↦ hf _ <| Finset.mem_singleton.1 hj ▸ hi)
(fun i _ ↦ hy _) ht
section Monoid
variable {M : Type*} [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M]
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map₀'
{f g : Ω → M} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) (hfg : f ⟂ᵢ[μ] g) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) := by
conv in f * g => change (fun x ↦ x.1 * x.2) ∘ (fun ω ↦ (f ω, g ω))
rw [← measurable_mul.aemeasurable.map_map_of_aemeasurable (hf.prodMk hg),
(indepFun_iff_map_prod_eq_prod_map_map' hf hg σf σg).mp hfg, Measure.mconv]
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map'
{f g : Ω → M} (hf : Measurable f) (hg : Measurable g)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) (hfg : f ⟂ᵢ[μ] g) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) :=
hfg.map_mul_eq_map_mconv_map₀' hf.aemeasurable hg.aemeasurable σf σg
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map₀
[IsFiniteMeasure μ] {f g : Ω → M} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hfg : f ⟂ᵢ[μ] g) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) := by
apply hfg.map_mul_eq_map_mconv_map₀' hf hg
<;> apply IsFiniteMeasure.toSigmaFinite
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map
[IsFiniteMeasure μ] {f g : Ω → M} (hf : Measurable f) (hg : Measurable g)
(hfg : f ⟂ᵢ[μ] g) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) :=
hfg.map_mul_eq_map_mconv_map₀ hf.aemeasurable hg.aemeasurable
end Monoid
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/Conditional.lean | import Mathlib.Probability.Independence.Kernel
import Mathlib.Probability.Kernel.CompProdEqIff
import Mathlib.Probability.Kernel.Composition.Lemmas
import Mathlib.Probability.Kernel.Condexp
/-!
# Conditional Independence
We define conditional independence of sets/σ-algebras/functions with respect to a σ-algebra.
Two σ-algebras `m₁` and `m₂` are conditionally independent given a third σ-algebra `m'` if for all
`m₁`-measurable sets `t₁` and `m₂`-measurable sets `t₂`,
`μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`.
On standard Borel spaces, the conditional expectation with respect to `m'` defines a kernel
`ProbabilityTheory.condExpKernel`, and the definition above is equivalent to
`∀ᵐ ω ∂μ, condExpKernel μ m' ω (t₁ ∩ t₂) = condExpKernel μ m' ω t₁ * condExpKernel μ m' ω t₂`.
We use this property as the definition of conditional independence.
## Main definitions
We provide four definitions of conditional independence:
* `iCondIndepSets`: conditional independence of a family of sets of sets `pi : ι → Set (Set Ω)`.
This is meant to be used with π-systems.
* `iCondIndep`: conditional independence of a family of measurable space structures
`m : ι → MeasurableSpace Ω`,
* `iCondIndepSet`: conditional independence of a family of sets `s : ι → Set Ω`,
* `iCondIndepFun`: conditional independence of a family of functions. For measurable spaces
`m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`.
Additionally, we provide four corresponding statements for two measurable space structures (resp.
sets of sets, sets, functions) instead of a family. These properties are denoted by the same names
as for a family, but without the starting `i`, for example `CondIndepFun` is the version of
`iCondIndepFun` for two functions.
## Main statements
* `ProbabilityTheory.iCondIndepSets.iCondIndep`: if π-systems are conditionally independent as sets
of sets, then the measurable space structures they generate are conditionally independent.
* `ProbabilityTheory.condIndepSets.condIndep`: variant with two π-systems.
## Notation
* `X ⟂ᵢ[Z, hZ; μ] Y` for `CondIndepFun (MeasurableSpace.comap Z inferInstance) hZ.comap_le X Y μ`,
independence of `X` and `Y` given `Z`.
* `X ⟂ᵢ[Z, hZ] Y` for the cases of `μ = volume`.
These notations are scoped in the `ProbabilityTheory` namespace.
## Implementation notes
The definitions of conditional independence in this file are a particular case of independence with
respect to a kernel and a measure, as defined in the file `Probability/Independence/Kernel.lean`.
The kernel used is `ProbabilityTheory.condExpKernel`.
-/
open MeasureTheory MeasurableSpace
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory
variable {Ω ι : Type*}
section Definitions
section
variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ)
/-- A family of sets of sets `π : ι → Set (Set Ω)` is conditionally independent given `m'` with
respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧`.
See `ProbabilityTheory.iCondIndepSets_iff`.
It will be used for families of pi_systems. -/
def iCondIndepSets (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] :
Prop :=
Kernel.iIndepSets π (condExpKernel μ m') (μ.trim hm')
/-- Two sets of sets `s₁, s₂` are conditionally independent given `m'` with respect to a measure
`μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`.
See `ProbabilityTheory.condIndepSets_iff`. -/
def CondIndepSets (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] :
Prop :=
Kernel.IndepSets s1 s2 (condExpKernel μ m') (μ.trim hm')
/-- A family of measurable space structures (i.e. of σ-algebras) is conditionally independent given
`m'` with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of
measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is conditionally independent
given `m'` with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for
any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then
`μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧ `.
See `ProbabilityTheory.iCondIndep_iff`. -/
def iCondIndep (m : ι → MeasurableSpace Ω)
(μ : @Measure Ω mΩ := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.iIndep m (condExpKernel (mΩ := mΩ) μ m') (μ.trim hm')
end
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are conditionally independent given
`m'` with respect to a measure `μ` (defined on a third σ-algebra) if for any sets
`t₁ ∈ m₁, t₂ ∈ m₂`, `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`.
See `ProbabilityTheory.condIndep_iff`. -/
def CondIndep (m' m₁ m₂ : MeasurableSpace Ω)
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
(hm' : m' ≤ mΩ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.Indep m₁ m₂ (condExpKernel μ m') (μ.trim hm')
section
variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
(hm' : m' ≤ mΩ)
/-- A family of sets is conditionally independent if the family of measurable space structures they
generate is conditionally independent. For a set `s`, the generated measurable space has measurable
sets `∅, s, sᶜ, univ`.
See `ProbabilityTheory.iCondIndepSet_iff`. -/
def iCondIndepSet (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.iIndepSet s (condExpKernel μ m') (μ.trim hm')
/-- Two sets are conditionally independent if the two measurable space structures they generate are
conditionally independent. For a set `s`, the generated measurable space structure has measurable
sets `∅, s, sᶜ, univ`.
See `ProbabilityTheory.condIndepSet_iff`. -/
def CondIndepSet (s t : Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.IndepSet s t (condExpKernel μ m') (μ.trim hm')
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is conditionally independent if the family of
measurable space structures they generate on `Ω` is conditionally independent. For a function `g`
with codomain having measurable space structure `m`, the generated measurable space structure is
`m.comap g`.
See `ProbabilityTheory.iCondIndepFun_iff`. -/
def iCondIndepFun {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)]
(f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.iIndepFun f (condExpKernel μ m') (μ.trim hm')
/-- Two functions are conditionally independent if the two measurable space structures they generate
are conditionally independent. For a function `f` with codomain having measurable space structure
`m`, the generated measurable space structure is `m.comap f`.
See `ProbabilityTheory.condIndepFun_iff`.
We use the notation `X ⟂ᵢ[Z, hZ; μ] Y` to write that `X` and `Y` are conditionally independent
given (the σ-algebra generated by) `Z` (scoped in `ProbabilityTheory`). -/
def CondIndepFun {β γ : Type*} [MeasurableSpace β] [MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop :=
Kernel.IndepFun f g (condExpKernel μ m') (μ.trim hm')
end
end Definitions
@[inherit_doc ProbabilityTheory.CondIndepFun]
scoped[ProbabilityTheory] notation3 X:50 " ⟂ᵢ[" Z ", " hZ "; " μ "] " Y:50 =>
ProbabilityTheory.CondIndepFun (MeasurableSpace.comap Z inferInstance) (Measurable.comap_le hZ)
X Y μ
@[inherit_doc ProbabilityTheory.CondIndepFun]
scoped[ProbabilityTheory] notation3 X:50 " ⟂ᵢ[" Z ", " hZ "] " Y:50 =>
ProbabilityTheory.CondIndepFun (MeasurableSpace.comap Z inferInstance) (Measurable.comap_le hZ)
X Y volume
section DefinitionLemmas
section
variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ)
lemma iCondIndepSets_iff (π : ι → Set (Set Ω)) (hπ : ∀ i s (_hs : s ∈ π i), MeasurableSet s)
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepSets m' hm' π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i),
μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by
simp only [iCondIndepSets, Kernel.iIndepSets]
have h_eq' : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i) i (_hi : i ∈ s),
(fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (f i))) =ᵐ[μ] μ⟦f i | m'⟧ :=
fun s f H i hi ↦ condExpKernel_ae_eq_condExp hm' (hπ i (f i) (H i hi))
have h_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ ω ∂μ,
∀ i ∈ s, ENNReal.toReal (condExpKernel μ m' ω (f i)) = (μ⟦f i | m'⟧) ω := by
intro s f H
simp_rw [← Finset.mem_coe]
rw [ae_ball_iff (Finset.countable_toSet s)]
exact h_eq' s f H
have h_inter_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i),
(fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (⋂ i ∈ s, f i)))
=ᵐ[μ] μ⟦⋂ i ∈ s, f i | m'⟧ := by
refine fun s f H ↦ condExpKernel_ae_eq_condExp hm' ?_
exact MeasurableSet.biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (H i hi))
refine ⟨fun h s f hf ↦ ?_, fun h s f hf ↦ ?_⟩ <;> specialize h s hf
· have h' := ae_eq_of_ae_eq_trim h
filter_upwards [h_eq s f hf, h_inter_eq s f hf, h'] with ω h_eq h_inter_eq h'
rw [← h_inter_eq, h', ENNReal.toReal_prod, Finset.prod_apply]
exact Finset.prod_congr rfl h_eq
· refine ((stronglyMeasurable_condExpKernel ?_).ae_eq_trim_iff hm' ?_).mpr ?_
· exact .biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (hf i hi))
· refine Measurable.stronglyMeasurable ?_
exact Finset.measurable_fun_prod s (fun i hi ↦ measurable_condExpKernel (hπ i _ (hf i hi)))
filter_upwards [h_eq s f hf, h_inter_eq s f hf, h] with ω h_eq h_inter_eq h
have h_ne_top : condExpKernel μ m' ω (⋂ i ∈ s, f i) ≠ ∞ :=
(measure_ne_top (condExpKernel μ m' ω) _)
have : (∏ i ∈ s, condExpKernel μ m' ω (f i)) ≠ ∞ :=
ENNReal.prod_ne_top fun _ _ ↦ measure_ne_top (condExpKernel μ m' ω) _
rw [← ENNReal.ofReal_toReal h_ne_top, h_inter_eq, h, Finset.prod_apply,
← ENNReal.ofReal_toReal this, ENNReal.toReal_prod]
congr 1
exact Finset.prod_congr rfl (fun i hi ↦ (h_eq i hi).symm)
lemma condIndepSets_iff (s1 s2 : Set (Set Ω)) (hs1 : ∀ s ∈ s1, MeasurableSet s)
(hs2 : ∀ s ∈ s2, MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepSets m' hm' s1 s2 μ ↔ ∀ (t1 t2 : Set Ω) (_ : t1 ∈ s1) (_ : t2 ∈ s2),
(μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by
simp only [CondIndepSets, Kernel.IndepSets]
have hs1_eq : ∀ s ∈ s1, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ :=
fun s hs ↦ condExpKernel_ae_eq_condExp hm' (hs1 s hs)
have hs2_eq : ∀ s ∈ s2, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ :=
fun s hs ↦ condExpKernel_ae_eq_condExp hm' (hs2 s hs)
have hs12_eq : ∀ s ∈ s1, ∀ t ∈ s2, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (s ∩ t)))
=ᵐ[μ] μ⟦s ∩ t | m'⟧ :=
fun s hs t ht ↦ condExpKernel_ae_eq_condExp hm' ((hs1 s hs).inter ((hs2 t ht)))
refine ⟨fun h s t hs ht ↦ ?_, fun h s t hs ht ↦ ?_⟩ <;> specialize h s t hs ht
· have h' := ae_eq_of_ae_eq_trim h
filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h'] with ω hs_eq ht_eq hst_eq h'
rw [← hst_eq, Pi.mul_apply, ← hs_eq, ← ht_eq, h', ENNReal.toReal_mul]
· refine ((stronglyMeasurable_condExpKernel ((hs1 s hs).inter (hs2 t ht))).ae_eq_trim_iff hm'
((measurable_condExpKernel (hs1 s hs)).mul
(measurable_condExpKernel (hs2 t ht))).stronglyMeasurable).mpr ?_
filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h] with ω hs_eq ht_eq hst_eq h
have h_ne_top : condExpKernel μ m' ω (s ∩ t) ≠ ∞ := measure_ne_top (condExpKernel μ m' ω) _
rw [← ENNReal.ofReal_toReal h_ne_top, hst_eq, h, Pi.mul_apply, ← hs_eq, ← ht_eq,
← ENNReal.toReal_mul, ENNReal.ofReal_toReal]
exact ENNReal.mul_ne_top (measure_ne_top (condExpKernel μ m' ω) s)
(measure_ne_top (condExpKernel μ m' ω) t)
lemma iCondIndepSets_singleton_iff (s : ι → Set Ω) (hπ : ∀ i, MeasurableSet (s i))
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepSets m' hm' (fun i ↦ {s i}) μ ↔ ∀ S : Finset ι,
μ⟦⋂ i ∈ S, s i | m'⟧ =ᵐ[μ] ∏ i ∈ S, (μ⟦s i | m'⟧) := by
rw [iCondIndepSets_iff]
· simp_all only [Set.mem_singleton_iff]
constructor
· intros
simp [*]
· grind
· simpa
theorem condIndepSets_singleton_iff {μ : Measure Ω} [IsFiniteMeasure μ]
{s t : Set Ω} (hs : MeasurableSet s) (ht : MeasurableSet t) :
CondIndepSets m' hm' {s} {t} μ ↔ (μ⟦s ∩ t | m'⟧) =ᵐ[μ] (μ⟦s | m'⟧) * (μ⟦t | m'⟧) := by
rw [condIndepSets_iff _ _ _ _ ?_ ?_]
· simp only [Set.mem_singleton_iff, forall_eq_apply_imp_iff, forall_eq]
· intro s' hs'
rw [Set.mem_singleton_iff] at hs'
rwa [hs']
· intro s' hs'
rw [Set.mem_singleton_iff] at hs'
rwa [hs']
lemma iCondIndep_iff_iCondIndepSets (m : ι → MeasurableSpace Ω)
(μ : @Measure Ω mΩ) [IsFiniteMeasure μ] :
iCondIndep m' hm' m μ ↔ iCondIndepSets m' hm' (fun x ↦ {s | MeasurableSet[m x] s}) μ := by
simp only [iCondIndep, iCondIndepSets, Kernel.iIndep]
lemma iCondIndep_iff (m : ι → MeasurableSpace Ω) (hm : ∀ i, m i ≤ mΩ)
(μ : @Measure Ω mΩ) [IsFiniteMeasure μ] :
iCondIndep m' hm' m μ
↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)),
μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by
rw [iCondIndep_iff_iCondIndepSets, iCondIndepSets_iff]
· rfl
· exact hm
end
section CondIndep
lemma condIndep_iff_condIndepSets (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω}
[StandardBorelSpace Ω] (hm' : m' ≤ mΩ) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndep m' m₁ m₂ hm' μ
↔ CondIndepSets m' hm' {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by
simp only [CondIndep, CondIndepSets, Kernel.Indep]
lemma condIndep_iff (m' m₁ m₂ : MeasurableSpace Ω)
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
(hm' : m' ≤ mΩ) (hm₁ : m₁ ≤ mΩ) (hm₂ : m₂ ≤ mΩ) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndep m' m₁ m₂ hm' μ
↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2
→ (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by
rw [condIndep_iff_condIndepSets, condIndepSets_iff]
· rfl
· exact hm₁
· exact hm₂
end CondIndep
variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
(hm' : m' ≤ mΩ)
lemma iCondIndepSet_iff_iCondIndep (s : ι → Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepSet m' hm' s μ ↔ iCondIndep m' hm' (fun i ↦ generateFrom {s i}) μ := by
simp only [iCondIndepSet, iCondIndep, Kernel.iIndepSet]
theorem iCondIndepSet_iff_iCondIndepSets_singleton (s : ι → Set Ω) (hs : ∀ i, MeasurableSet (s i))
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepSet m' hm' s μ ↔ iCondIndepSets m' hm' (fun i ↦ {s i}) μ :=
Kernel.iIndepSet_iff_iIndepSets_singleton hs
lemma iCondIndepSet_iff (s : ι → Set Ω) (hs : ∀ i, MeasurableSet (s i))
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepSet m' hm' s μ ↔
∀ S : Finset ι, μ⟦⋂ i ∈ S, s i | m'⟧ =ᵐ[μ] ∏ i ∈ S, μ⟦s i | m'⟧ := by
rw [iCondIndepSet_iff_iCondIndepSets_singleton _ _ _ hs, iCondIndepSets_singleton_iff _ _ _ hs]
lemma condIndepSet_iff_condIndep (s t : Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepSet m' hm' s t μ ↔ CondIndep m' (generateFrom {s}) (generateFrom {t}) hm' μ := by
simp only [CondIndepSet, CondIndep, Kernel.IndepSet]
theorem condIndepSet_iff_condIndepSets_singleton {s t : Set Ω} (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepSet m' hm' s t μ ↔ CondIndepSets m' hm' {s} {t} μ :=
Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _
lemma condIndepSet_iff (s t : Set Ω) (hs : MeasurableSet s) (ht : MeasurableSet t)
(μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepSet m' hm' s t μ ↔ (μ⟦s ∩ t | m'⟧) =ᵐ[μ] (μ⟦s | m'⟧) * (μ⟦t | m'⟧) := by
rw [condIndepSet_iff_condIndepSets_singleton _ _ hs ht μ, condIndepSets_singleton_iff _ _ hs ht]
lemma iCondIndepFun_iff_iCondIndep {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x)
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepFun m' hm' f μ
↔ iCondIndep m' hm' (fun x ↦ MeasurableSpace.comap (f x) (m x)) μ := by
simp only [iCondIndepFun, iCondIndep, Kernel.iIndepFun]
lemma iCondIndepFun_iff {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (hf : ∀ i, Measurable (f i))
(μ : Measure Ω) [IsFiniteMeasure μ] :
iCondIndepFun m' hm' f μ
↔ ∀ (s : Finset ι) {g : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (g i)),
μ⟦⋂ i ∈ s, g i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦g i | m'⟧) := by
simp only [iCondIndepFun_iff_iCondIndep]
rw [iCondIndep_iff]
exact fun i ↦ (hf i).comap_le
lemma condIndepFun_iff_condIndep {β γ : Type*} [mβ : MeasurableSpace β]
[mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepFun m' hm' f g μ
↔ CondIndep m' (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) hm' μ := by
simp only [CondIndepFun, CondIndep, Kernel.IndepFun]
lemma condIndepFun_iff {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (hf : Measurable f) (hg : Measurable g)
(μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndepFun m' hm' f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1
→ MeasurableSet[MeasurableSpace.comap g mγ] t2
→ (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by
rw [condIndepFun_iff_condIndep, condIndep_iff _ _ _ _ hf.comap_le hg.comap_le]
end DefinitionLemmas
section CondIndepSets
variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
@[symm]
theorem CondIndepSets.symm {s₁ s₂ : Set (Set Ω)}
(h : CondIndepSets m' hm' s₁ s₂ μ) : CondIndepSets m' hm' s₂ s₁ μ :=
Kernel.IndepSets.symm h
theorem condIndepSets_of_condIndepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : CondIndepSets m' hm' s₁ s₂ μ) (h31 : s₃ ⊆ s₁) :
CondIndepSets m' hm' s₃ s₂ μ :=
Kernel.indepSets_of_indepSets_of_le_left h_indep h31
theorem condIndepSets_of_condIndepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : CondIndepSets m' hm' s₁ s₂ μ) (h32 : s₃ ⊆ s₂) :
CondIndepSets m' hm' s₁ s₃ μ :=
Kernel.indepSets_of_indepSets_of_le_right h_indep h32
theorem CondIndepSets.union {s₁ s₂ s' : Set (Set Ω)}
(h₁ : CondIndepSets m' hm' s₁ s' μ) (h₂ : CondIndepSets m' hm' s₂ s' μ) :
CondIndepSets m' hm' (s₁ ∪ s₂) s' μ :=
Kernel.IndepSets.union h₁ h₂
@[simp]
theorem CondIndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} :
CondIndepSets m' hm' (s₁ ∪ s₂) s' μ
↔ CondIndepSets m' hm' s₁ s' μ ∧ CondIndepSets m' hm' s₂ s' μ :=
Kernel.IndepSets.union_iff
theorem CondIndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(hyp : ∀ n, CondIndepSets m' hm' (s n) s' μ) :
CondIndepSets m' hm' (⋃ n, s n) s' μ :=
Kernel.IndepSets.iUnion hyp
theorem CondIndepSets.biUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (hyp : ∀ n ∈ u, CondIndepSets m' hm' (s n) s' μ) :
CondIndepSets m' hm' (⋃ n ∈ u, s n) s' μ :=
Kernel.IndepSets.biUnion hyp
@[deprecated (since := "2025-11-02")] alias CondIndepSets.bUnion := CondIndepSets.biUnion
theorem CondIndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω))
(h₁ : CondIndepSets m' hm' s₁ s' μ) :
CondIndepSets m' hm' (s₁ ∩ s₂) s' μ :=
Kernel.IndepSets.inter s₂ h₁
theorem CondIndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(h : ∃ n, CondIndepSets m' hm' (s n) s' μ) :
CondIndepSets m' hm' (⋂ n, s n) s' μ :=
Kernel.IndepSets.iInter h
theorem CondIndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (h : ∃ n ∈ u, CondIndepSets m' hm' (s n) s' μ) :
CondIndepSets m' hm' (⋂ n ∈ u, s n) s' μ :=
Kernel.IndepSets.bInter h
end CondIndepSets
section CondIndepSet
variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
theorem condIndepSet_empty_right (s : Set Ω) : CondIndepSet m' hm' s ∅ μ :=
Kernel.indepSet_empty_right s
theorem condIndepSet_empty_left (s : Set Ω) : CondIndepSet m' hm' ∅ s μ :=
Kernel.indepSet_empty_left s
end CondIndepSet
section CondIndep
@[symm]
theorem CondIndep.symm {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω}
[StandardBorelSpace Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
(h : CondIndep m' m₁ m₂ hm' μ) :
CondIndep m' m₂ m₁ hm' μ :=
CondIndepSets.symm h
theorem condIndep_bot_right (m₁ : MeasurableSpace Ω) {m' : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] :
CondIndep m' m₁ ⊥ hm' μ :=
Kernel.indep_bot_right m₁
theorem condIndep_bot_left (m₁ : MeasurableSpace Ω) {m' : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] :
CondIndep m' ⊥ m₁ hm' μ :=
(Kernel.indep_bot_right m₁).symm
theorem condIndep_of_condIndep_of_le_left {m' m₁ m₂ m₃ : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
(h_indep : CondIndep m' m₁ m₂ hm' μ) (h31 : m₃ ≤ m₁) :
CondIndep m' m₃ m₂ hm' μ :=
Kernel.indep_of_indep_of_le_left h_indep h31
theorem condIndep_of_condIndep_of_le_right {m' m₁ m₂ m₃ : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
(h_indep : CondIndep m' m₁ m₂ hm' μ) (h32 : m₃ ≤ m₂) :
CondIndep m' m₁ m₃ hm' μ :=
Kernel.indep_of_indep_of_le_right h_indep h32
end CondIndep
/-! ### Deducing `CondIndep` from `iCondIndep` -/
section FromiCondIndepToCondIndep
variable {m' : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
theorem iCondIndepSets.condIndepSets {s : ι → Set (Set Ω)}
(h_indep : iCondIndepSets m' hm' s μ) {i j : ι} (hij : i ≠ j) :
CondIndepSets m' hm' (s i) (s j) μ :=
Kernel.iIndepSets.indepSets h_indep hij
theorem iCondIndep.condIndep {m : ι → MeasurableSpace Ω}
(h_indep : iCondIndep m' hm' m μ) {i j : ι} (hij : i ≠ j) :
CondIndep m' (m i) (m j) hm' μ :=
Kernel.iIndep.indep h_indep hij
theorem iCondIndepFun.condIndepFun {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i}
(hf_Indep : iCondIndepFun m' hm' f μ) {i j : ι} (hij : i ≠ j) :
CondIndepFun m' hm' (f i) (f j) μ :=
Kernel.iIndepFun.indepFun hf_Indep hij
end FromiCondIndepToCondIndep
/-!
## π-system lemma
Conditional independence of measurable spaces is equivalent to conditional independence of
generating π-systems.
-/
section FromMeasurableSpacesToSetsOfSets
/-! ### Conditional independence of σ-algebras implies conditional independence of
generating π-systems -/
variable {m' : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
theorem iCondIndep.iCondIndepSets {m : ι → MeasurableSpace Ω}
{s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n))
(h_indep : iCondIndep m' hm' m μ) :
iCondIndepSets m' hm' s μ :=
Kernel.iIndep.iIndepSets hms h_indep
theorem CondIndep.condIndepSets {s1 s2 : Set (Set Ω)}
(h_indep : CondIndep m' (generateFrom s1) (generateFrom s2) hm' μ) :
CondIndepSets m' hm' s1 s2 μ :=
Kernel.Indep.indepSets h_indep
end FromMeasurableSpacesToSetsOfSets
section FromPiSystemsToMeasurableSpaces
/-! ### Conditional independence of generating π-systems implies conditional independence of
σ-algebras -/
variable {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
theorem CondIndepSets.condIndep
{p1 p2 : Set (Set Ω)} (h1 : m₁ ≤ mΩ) (h2 : m₂ ≤ mΩ)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2)
(hpm1 : m₁ = generateFrom p1) (hpm2 : m₂ = generateFrom p2)
(hyp : CondIndepSets m' hm' p1 p2 μ) :
CondIndep m' m₁ m₂ hm' μ :=
Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp
theorem CondIndepSets.condIndep'
{p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : CondIndepSets m' hm' p1 p2 μ) :
CondIndep m' (generateFrom p1) (generateFrom p2) hm' μ :=
Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp
theorem condIndepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)}
{S T : Set ι} (h_indep : iCondIndepSets m' hm' s μ) (hST : Disjoint S T) :
CondIndepSets m' hm' (piiUnionInter s S) (piiUnionInter s T) μ :=
Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST
theorem iCondIndepSet.condIndep_generateFrom_of_disjoint {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (S T : Set ι)
(hST : Disjoint S T) :
CondIndep m' (generateFrom { t | ∃ n ∈ S, s n = t })
(generateFrom { t | ∃ k ∈ T, s k = t }) hm' μ :=
Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST
theorem condIndep_iSup_of_disjoint {m : ι → MeasurableSpace Ω}
(h_le : ∀ i, m i ≤ mΩ) (h_indep : iCondIndep m' hm' m μ) {S T : Set ι} (hST : Disjoint S T) :
CondIndep m' (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) hm' μ :=
Kernel.indep_iSup_of_disjoint h_le h_indep hST
theorem condIndep_iSup_of_directed_le {m : ι → MeasurableSpace Ω}
(h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ)
(h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ) (hm : Directed (· ≤ ·) m) :
CondIndep m' (⨆ i, m i) m₁ hm' μ :=
Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm
theorem iCondIndepSet.condIndep_generateFrom_lt [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (i : ι) :
CondIndep m' (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) hm' μ :=
Kernel.iIndepSet.indep_generateFrom_lt hsm hs i
theorem iCondIndepSet.condIndep_generateFrom_le [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (i : ι) {k : ι} (hk : i < k) :
CondIndep m' (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) hm' μ :=
Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk
theorem iCondIndepSet.condIndep_generateFrom_le_nat {s : ℕ → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (n : ℕ) :
CondIndep m' (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) hm' μ :=
Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n
theorem condIndep_iSup_of_monotone [SemilatticeSup ι] {m : ι → MeasurableSpace Ω}
(h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ) (h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ)
(hm : Monotone m) :
CondIndep m' (⨆ i, m i) m₁ hm' μ :=
Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm
theorem condIndep_iSup_of_antitone [SemilatticeInf ι] {m : ι → MeasurableSpace Ω}
(h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ) (h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ)
(hm : Antitone m) :
CondIndep m' (⨆ i, m i) m₁ hm' μ :=
Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm
theorem iCondIndepSets.piiUnionInter_of_notMem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι}
(hp_ind : iCondIndepSets m' hm' π μ) (haS : a ∉ S) :
CondIndepSets m' hm' (piiUnionInter π S) (π a) μ :=
Kernel.iIndepSets.piiUnionInter_of_notMem hp_ind haS
@[deprecated (since := "2025-05-23")]
alias iCondIndepSets.piiUnionInter_of_not_mem := iCondIndepSets.piiUnionInter_of_notMem
/-- The σ-algebras generated by conditionally independent pi-systems are conditionally independent.
-/
theorem iCondIndepSets.iCondIndep (m : ι → MeasurableSpace Ω)
(h_le : ∀ i, m i ≤ mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n))
(h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iCondIndepSets m' hm' π μ) :
iCondIndep m' hm' m μ :=
Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind
end FromPiSystemsToMeasurableSpaces
section CondIndepSet
/-! ### Conditional independence of measurable sets
-/
variable {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ}
{s t : Set Ω} (S T : Set (Set Ω))
theorem CondIndepSets.condIndepSet_of_mem (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω) [IsFiniteMeasure μ]
(h_indep : CondIndepSets m' hm' S T μ) :
CondIndepSet m' hm' s t μ :=
Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep
theorem CondIndep.condIndepSet_of_measurableSet {μ : Measure Ω} [IsFiniteMeasure μ]
(h_indep : CondIndep m' m₁ m₂ hm' μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s)
(ht : MeasurableSet[m₂] t) :
CondIndepSet m' hm' s t μ :=
Kernel.Indep.indepSet_of_measurableSet h_indep hs ht
theorem condIndep_iff_forall_condIndepSet (μ : Measure Ω) [IsFiniteMeasure μ] :
CondIndep m' m₁ m₂ hm' μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t
→ CondIndepSet m' hm' s t μ :=
Kernel.indep_iff_forall_indepSet m₁ m₂ _ _
end CondIndepSet
section CondIndepFun
/-! ### Conditional independence of random variables
-/
variable {β β' : Type*} {m' : MeasurableSpace Ω}
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω]
{hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ]
{f : Ω → β} {g : Ω → β'}
theorem condIndepFun_iff_condExp_inter_preimage_eq_mul {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} (hf : Measurable f) (hg : Measurable g) :
CondIndepFun m' hm' f g μ ↔
∀ s t, MeasurableSet s → MeasurableSet t
→ (μ⟦f ⁻¹' s ∩ g ⁻¹' t | m'⟧) =ᵐ[μ] fun ω ↦ (μ⟦f ⁻¹' s | m'⟧) ω * (μ⟦g ⁻¹' t | m'⟧) ω := by
rw [condIndepFun_iff _ _ _ _ hf hg]
refine ⟨fun h s t hs ht ↦ ?_, fun h s t ↦ ?_⟩
· exact h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩
· rintro ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩
exact h s t hs ht
theorem iCondIndepFun_iff_condExp_inter_preimage_eq_mul {β : ι → Type*}
(m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) (hf : ∀ i, Measurable (f i)) :
iCondIndepFun m' hm' f μ ↔
∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)),
(μ⟦⋂ i ∈ S, f i ⁻¹' sets i | m'⟧) =ᵐ[μ] ∏ i ∈ S, (μ⟦f i ⁻¹' sets i | m'⟧) := by
rw [iCondIndepFun_iff]
swap
· exact hf
refine ⟨fun h s sets h_sets ↦ ?_, fun h s sets h_sets ↦ ?_⟩
· refine h s (g := fun i ↦ f i ⁻¹' (sets i)) (fun i hi ↦ ?_)
exact ⟨sets i, h_sets i hi, rfl⟩
· classical
let g := fun i ↦ if hi : i ∈ s then (h_sets i hi).choose else Set.univ
specialize h s (sets := g) (fun i hi ↦ ?_)
· simp only [g, dif_pos hi]
exact (h_sets i hi).choose_spec.1
· have hg : ∀ i ∈ s, sets i = f i ⁻¹' g i := by
intro i hi
rw [(h_sets i hi).choose_spec.2.symm]
simp only [g, dif_pos hi]
convert h with i hi i hi <;> exact hg i hi
theorem condIndepFun_iff_condIndepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
(hf : Measurable f) (hg : Measurable g) :
CondIndepFun m' hm' f g μ ↔
∀ s t, MeasurableSet s → MeasurableSet t → CondIndepSet m' hm' (f ⁻¹' s) (g ⁻¹' t) μ := by
simp only [CondIndepFun, CondIndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg]
@[symm]
nonrec theorem CondIndepFun.symm {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{f : Ω → β} {g : Ω → β'} (hfg : CondIndepFun m' hm' f g μ) :
CondIndepFun m' hm' g f μ :=
hfg.symm
theorem CondIndepFun.comp {γ γ' : Type*} {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'}
{_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : CondIndepFun m' hm' f g μ) (hφ : Measurable φ) (hψ : Measurable ψ) :
CondIndepFun m' hm' (φ ∘ f) (ψ ∘ g) μ :=
Kernel.IndepFun.comp hfg hφ hψ
lemma condIndepFun_const_left {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
(c : β) (X : Ω → β') :
CondIndepFun m' hm' (fun _ ↦ c) X μ :=
Kernel.indepFun_const_left c X
lemma condIndepFun_const_right {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
(X : Ω → β) (c : β') :
CondIndepFun m' hm' X (fun _ ↦ c) μ :=
Kernel.indepFun_const_right X c
theorem CondIndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β']
[MeasurableNeg β'] (hfg : CondIndepFun m' hm' f g μ) :
CondIndepFun m' hm' f (-g) μ := hfg.comp measurable_id measurable_neg
theorem CondIndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β]
[MeasurableNeg β] (hfg : CondIndepFun m' hm' f g μ) :
CondIndepFun m' hm' (-f) g μ := hfg.comp measurable_neg measurable_id
lemma condIndepFun_of_measurable_left {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{X : Ω → β} {Y : Ω → β'} (hX : Measurable[m'] X) (hY : Measurable Y) :
CondIndepFun m' hm' X Y μ := by
rw [condIndepFun_iff _ hm' _ _ (hX.mono hm' le_rfl) hY]
rintro _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩
rw [show (fun ω : Ω ↦ (1 : ℝ)) = 1 from rfl, Set.inter_indicator_one]
calc μ[(X ⁻¹' s).indicator 1 * (Y ⁻¹' t).indicator 1|m']
_ =ᵐ[μ] (X ⁻¹' s).indicator 1 * μ[(Y ⁻¹' t).indicator 1|m'] := by
refine condExp_stronglyMeasurable_mul_of_bound hm' (stronglyMeasurable_const.indicator (hX hs))
((integrable_indicator_iff (hY ht)).2 integrableOn_const) 1 (ae_of_all μ fun ω ↦ ?_)
rw [Set.indicator]
split_ifs with h <;> simp
_ =ᵐ[μ] μ[(X ⁻¹' s).indicator 1|m'] * μ[(Y ⁻¹' t).indicator 1|m'] := by
nth_rw 2 [condExp_of_stronglyMeasurable hm']
· exact stronglyMeasurable_const.indicator (hX hs)
· exact (integrable_indicator_iff ((hX.le hm') hs)).2 integrableOn_const
lemma condIndepFun_of_measurable_right {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{X : Ω → β} {Y : Ω → β'} (hX : Measurable X) (hY : Measurable[m'] Y) :
CondIndepFun m' hm' X Y μ :=
(condIndepFun_of_measurable_left hY hX).symm
lemma condIndepFun_self_left {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{X : Ω → β} {Z : Ω → β'} (hX : Measurable X) (hZ : Measurable Z) :
Z ⟂ᵢ[Z, hZ; μ] X :=
condIndepFun_of_measurable_left (comap_measurable Z) hX
lemma condIndepFun_self_right {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{X : Ω → β} {Z : Ω → β'} (hX : Measurable X) (hZ : Measurable Z) :
X ⟂ᵢ[Z, hZ; μ] Z :=
condIndepFun_of_measurable_right hX (comap_measurable Z)
/-- Two random variables are conditionally independent iff they satisfy the almost sure equality
of conditional expectations `μ⟦f ⁻¹' s ∩ g ⁻¹' t | m'⟧ =ᵐ[μ] μ⟦f ⁻¹' s | m'⟧ * μ⟦g ⁻¹' t | m'⟧`
for all measurable sets `s` and `t` (see `condIndepFun_iff_condExp_inter_preimage_eq_mul`).
Here, this is phrased with Markov kernels associated to the conditional expectations, and the
almost sure equality is expressed as equality of the composition-product with the measure, which is
equivalent to a.e. equality. See `condIndepFun_iff_map_prod_eq_prod_map_map` for the a.e. equality
version with kernels.
For a random variable `f`, `(condExpKernel μ m').map f` is the law of the conditional expectation
of `f` given `m'`: almost surely, `(condExpKernel μ m').map f ω s = μ⟦f ⁻¹' s | m'⟧ ω`. -/
theorem condIndepFun_iff_compProd_map_prod_eq_compProd_prod_map_map
{mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} (hf : Measurable f) (hg : Measurable g) :
CondIndepFun m' hm' f g μ
↔ (μ.trim hm') ⊗ₘ (condExpKernel μ m').map (fun ω ↦ (f ω, g ω))
= (μ.trim hm') ⊗ₘ ((condExpKernel μ m').map f ×ₖ (condExpKernel μ m').map g) :=
Kernel.indepFun_iff_compProd_map_prod_eq_compProd_prod_map_map hf hg
/-- Two random variables are conditionally independent iff they satisfy the almost sure equality
of conditional expectations `μ⟦f ⁻¹' s ∩ g ⁻¹' t | m'⟧ =ᵐ[μ] μ⟦f ⁻¹' s | m'⟧ * μ⟦g ⁻¹' t | m'⟧`
for all measurable sets `s` and `t` (see `condIndepFun_iff_condExp_inter_preimage_eq_mul`).
Here, this is phrased with Markov kernels associated to the conditional expectations.
For a random variable `f`, `(condExpKernel μ m').map f` is the law of the conditional expectation
of `f` given `m'`: almost surely, `(condExpKernel μ m').map f ω s = μ⟦f ⁻¹' s | m'⟧ ω`. -/
theorem condIndepFun_iff_map_prod_eq_prod_map_map
{mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [CountableOrCountablyGenerated Ω (β × β')]
(hf : Measurable f) (hg : Measurable g) :
CondIndepFun m' hm' f g μ
↔ (condExpKernel μ m').map (fun ω ↦ (f ω, g ω))
=ᵐ[μ.trim hm'] (condExpKernel μ m').map f ×ₖ (condExpKernel μ m').map g := by
rw [condIndepFun_iff_compProd_map_prod_eq_compProd_prod_map_map hf hg, ← Kernel.compProd_eq_iff]
/-- Two random variables are conditionally independent with respect to `m'` iff the law of
`(id, f, g)` under `μ`, in which the identity is to the space with σ-algebra `m'`, can be written
as a product involving the conditional expectations of `f` and `g` given `m'`.
For a random variable `f`, `(condExpKernel μ m').map f` is the law of the conditional expectation
of `f` given `m'`: almost surely, `(condExpKernel μ m').map f ω s = μ⟦f ⁻¹' s | m'⟧ ω`. -/
lemma condIndepFun_iff_map_prod_eq_prod_comp_trim
{mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} (hf : Measurable f) (hg : Measurable g) :
CondIndepFun m' hm' f g μ
↔ @Measure.map _ _ _ (m'.prod _) (fun ω ↦ (ω, f ω, g ω)) μ
= (Kernel.id ×ₖ ((condExpKernel μ m').map f ×ₖ (condExpKernel μ m').map g))
∘ₘ μ.trim hm' := by
rw [condIndepFun_iff_compProd_map_prod_eq_compProd_prod_map_map hf hg]
congr!
· rw [Measure.compProd_map (by fun_prop), compProd_trim_condExpKernel,
Measure.map_map (by fun_prop) ((measurable_id.mono le_rfl hm').prodMk measurable_id)]
rfl
· rw [Measure.compProd_eq_comp_prod]
/-- Two random variables `f, g` are conditionally independent given a third `k` iff the
joint distribution of `k, f, g` factors into a product of their conditional distributions
given `k`. -/
theorem condIndepFun_iff_map_prod_eq_prod_condDistrib_prod_condDistrib
{γ : Type*} {mγ : MeasurableSpace γ} {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[StandardBorelSpace β] [Nonempty β] [StandardBorelSpace β'] [Nonempty β']
(hf : Measurable f) (hg : Measurable g) {k : Ω → γ} (hk : Measurable k) :
f ⟂ᵢ[k, hk; μ] g ↔
μ.map (fun ω ↦ (k ω, f ω, g ω)) =
(Kernel.id ×ₖ (condDistrib f k μ ×ₖ condDistrib g k μ)) ∘ₘ μ.map k := by
rw [condIndepFun_iff_map_prod_eq_prod_comp_trim hf hg]
simp_rw [Measure.ext_prod₃_iff]
have hk_meas {s : Set γ} (hs : MeasurableSet s) : MeasurableSet[mγ.comap k] (k ⁻¹' s) :=
⟨s, hs, rfl⟩
have h_left {s : Set γ} {t : Set β} {u : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t)
(hu : MeasurableSet u) :
(μ.map (fun ω ↦ (k ω, f ω, g ω))) (s ×ˢ t ×ˢ u) =
(@Measure.map _ _ _ ((mγ.comap k).prod inferInstance)
(fun ω ↦ (ω, f ω, g ω)) μ) ((k ⁻¹' s) ×ˢ t ×ˢ u) := by
rw [Measure.map_apply (by fun_prop) (hs.prod (ht.prod hu)),
Measure.map_apply _ ((hk_meas hs).prod (ht.prod hu))]
· simp [Set.mk_preimage_prod]
· exact (measurable_id.mono le_rfl hk.comap_le).prodMk (by fun_prop)
have h_right {s : Set γ} {t : Set β} {u : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t)
(hu : MeasurableSet u) :
((Kernel.id ×ₖ (condDistrib f k μ ×ₖ condDistrib g k μ)) ∘ₘ μ.map k) (s ×ˢ t ×ˢ u) =
((Kernel.id ×ₖ
((condExpKernel μ (mγ.comap k)).map f ×ₖ (condExpKernel μ (mγ.comap k)).map g)) ∘ₘ
μ.trim hk.comap_le) ((k ⁻¹' s) ×ˢ t ×ˢ u) := by
rw [Measure.bind_apply ((hk_meas hs).prod (ht.prod hu)) (by fun_prop),
Measure.bind_apply (hs.prod (ht.prod hu)) (by fun_prop), lintegral_map ?_ (by fun_prop),
lintegral_trim]
rotate_left
· exact Kernel.measurable_coe _ ((hk_meas hs).prod (ht.prod hu))
· exact Kernel.measurable_coe _ (hs.prod (ht.prod hu))
refine lintegral_congr_ae ?_
filter_upwards [condDistrib_apply_ae_eq_condExpKernel_map hf hk ht,
condDistrib_apply_ae_eq_condExpKernel_map hg hk hu] with a haX haT
simp only [Kernel.prod_apply_prod, Kernel.id_apply, Measure.dirac_apply' _ hs]
rw [@Measure.dirac_apply' _ (mγ.comap k) _ _ (hk_meas hs)]
congr
refine ⟨fun h s t u hs ht hu ↦ ?_, fun h ↦ ?_⟩
· convert h (hk_meas hs) ht hu
· exact h_left hs ht hu
· exact h_right hs ht hu
· rintro - t u ⟨s, hs, rfl⟩ ht hu
convert h hs ht hu
· exact (h_left hs ht hu).symm
· exact (h_right hs ht hu).symm
/-- Two random variables `f, g` are conditionally independent given a third `k` iff the
conditional distribution of `f` given `k` and `g` is equal to the conditional distribution of `f`
given `k`. -/
theorem condIndepFun_iff_condDistrib_prod_ae_eq_prodMkRight
{γ : Type*} {mγ : MeasurableSpace γ} {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[StandardBorelSpace β] [Nonempty β] [StandardBorelSpace β'] [Nonempty β']
(hf : Measurable f) (hg : Measurable g) {k : Ω → γ} (hk : Measurable k) :
g ⟂ᵢ[k, hk; μ] f ↔
condDistrib f (fun ω ↦ (k ω, g ω)) μ =ᵐ[μ.map (fun ω ↦ (k ω, g ω))]
(condDistrib f k μ).prodMkRight _ := by
rw [condDistrib_ae_eq_iff_measure_eq_compProd (μ := μ) _ hf.aemeasurable,
condIndepFun_iff_map_prod_eq_prod_condDistrib_prod_condDistrib hg hf hk,
Measure.compProd_eq_comp_prod]
let e : γ × β' × β ≃ᵐ (γ × β') × β := MeasurableEquiv.prodAssoc.symm
have h_eq : ((Kernel.id ×ₖ condDistrib g k μ) ×ₖ condDistrib f k μ) ∘ₘ μ.map k =
(Kernel.id ×ₖ (condDistrib f k μ).prodMkRight _) ∘ₘ μ.map (fun a ↦ (k a, g a)) := by
calc ((Kernel.id ×ₖ condDistrib g k μ) ×ₖ condDistrib f k μ) ∘ₘ μ.map k
_ = (Kernel.id ×ₖ (condDistrib f k μ).prodMkRight _) ∘ₘ (μ.map k ⊗ₘ condDistrib g k μ) := by
rw [Measure.compProd_eq_comp_prod, Measure.comp_assoc]
congr 2
have h := Kernel.prod_prodMkRight_comp_deterministic_prod (condDistrib g k μ)
(condDistrib f k μ) Kernel.id measurable_id
rw [← Kernel.id] at h
simpa using h.symm
_ = (Kernel.id ×ₖ (condDistrib f k μ).prodMkRight _) ∘ₘ μ.map (fun a ↦ (k a, g a)) := by
rw [compProd_map_condDistrib hg.aemeasurable]
rw [← h_eq]
have h1 : μ.map (fun x ↦ ((k x, g x), f x)) = (μ.map (fun a ↦ (k a , g a, f a))).map e := by
rw [Measure.map_map (by fun_prop) (by fun_prop)]
rfl
have h1_symm : μ.map (fun a ↦ (k a , g a, f a)) =
(μ.map (fun x ↦ ((k x, g x), f x))).map e.symm := by
rw [h1, Measure.map_map (by fun_prop) (by fun_prop), MeasurableEquiv.symm_comp_self,
Measure.map_id]
have h2 : ((Kernel.id ×ₖ condDistrib g k μ) ×ₖ condDistrib f k μ) ∘ₘ μ.map k =
((Kernel.id ×ₖ (condDistrib g k μ ×ₖ condDistrib f k μ)) ∘ₘ μ.map k).map e := by
rw [← Measure.deterministic_comp_eq_map e.measurable, Measure.comp_assoc]
congr 2
unfold e
rw [Kernel.deterministic_comp_eq_map, Kernel.prodAssoc_symm_prod]
have h2_symm : (Kernel.id ×ₖ (condDistrib g k μ ×ₖ condDistrib f k μ)) ∘ₘ μ.map k =
(((Kernel.id ×ₖ condDistrib g k μ) ×ₖ condDistrib f k μ) ∘ₘ μ.map k).map e.symm := by
rw [h2, Measure.map_map (by fun_prop) (by fun_prop), MeasurableEquiv.symm_comp_self,
Measure.map_id]
rw [h1, h2]
exact ⟨fun h ↦ by rw [h], fun h ↦ by rw [h1_symm, h1, h2_symm, h2, h]⟩
@[deprecated (since := "2025-10-14")] alias condIndepFun_iff_condDistrib_prod_ae_eq_prodMkLeft :=
condIndepFun_iff_condDistrib_prod_ae_eq_prodMkRight
section iCondIndepFun
variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i}
@[nontriviality]
lemma iCondIndepFun.of_subsingleton [Subsingleton ι] : iCondIndepFun m' hm' f μ :=
Kernel.iIndepFun.of_subsingleton
/-- If `f` is a family of mutually conditionally independent random variables
(`iCondIndepFun m' hm' m f μ`) and `S, T` are two disjoint finite index sets, then the tuple formed
by `f i` for `i ∈ S` is conditionally independent of the tuple `(f i)_i` for `i ∈ T`. -/
theorem iCondIndepFun.condIndepFun_finset {β : ι → Type*}
{m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} (S T : Finset ι) (hST : Disjoint S T)
(hf_Indep : iCondIndepFun m' hm' f μ) (hf_meas : ∀ i, Measurable (f i)) :
CondIndepFun m' hm' (fun a (i : S) => f i a) (fun a (i : T) => f i a) μ :=
Kernel.iIndepFun.indepFun_finset S T hST hf_Indep hf_meas
theorem iCondIndepFun.condIndepFun_prodMk {β : ι → Type*}
{m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} (hf_Indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
CondIndepFun m' hm' (fun a => (f i a, f j a)) (f k) μ :=
Kernel.iIndepFun.indepFun_prodMk hf_Indep hf_meas i j k hik hjk
open Finset in
lemma iCondIndepFun.condIndepFun_prodMk_prodMk (h_indep : iCondIndepFun m' hm' f μ)
(hf : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
CondIndepFun m' hm' (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ := by
classical
let g (i j : ι) (v : Π x : ({i, j} : Finset ι), β x) : β i × β j :=
⟨v ⟨i, mem_insert_self _ _⟩, v ⟨j, mem_insert_of_mem <| mem_singleton_self _⟩⟩
have hg (i j : ι) : Measurable (g i j) := by fun_prop
exact (h_indep.indepFun_finset {i, j} {k, l} (by aesop) hf).comp (hg i j) (hg k l)
end iCondIndepFun
section Mul
variable {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iCondIndepFun.indepFun_mul_left (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
CondIndepFun m' hm' (f i * f j) (f k) μ :=
Kernel.iIndepFun.indepFun_mul_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iCondIndepFun.indepFun_mul_right (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
CondIndepFun m' hm' (f i) (f j * f k) μ :=
Kernel.iIndepFun.indepFun_mul_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iCondIndepFun.indepFun_mul_mul (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
CondIndepFun m' hm' (f i * f j) (f k * f l) μ :=
Kernel.iIndepFun.indepFun_mul_mul hf_indep hf_meas i j k l hik hil hjk hjl
end Mul
section Div
variable {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iCondIndepFun.indepFun_div_left (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
CondIndepFun m' hm' (f i / f j) (f k) μ :=
Kernel.iIndepFun.indepFun_div_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iCondIndepFun.indepFun_div_right (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
CondIndepFun m' hm' (f i) (f j / f k) μ :=
Kernel.iIndepFun.indepFun_div_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iCondIndepFun.indepFun_div_div (hf_indep : iCondIndepFun m' hm' f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
CondIndepFun m' hm' (f i / f j) (f k / f l) μ :=
Kernel.iIndepFun.indepFun_div_div hf_indep hf_meas i j k l hik hil hjk hjl
end Div
section CommMonoid
variable {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
theorem iCondIndepFun.condIndepFun_finset_prod_of_notMem
(hf_Indep : iCondIndepFun m' hm' f μ) (hf_meas : ∀ i, Measurable (f i))
{s : Finset ι} {i : ι} (hi : i ∉ s) :
CondIndepFun m' hm' (∏ j ∈ s, f j) (f i) μ :=
Kernel.iIndepFun.indepFun_finset_prod_of_notMem hf_Indep hf_meas hi
@[deprecated (since := "2025-05-24")]
alias iCondIndepFun.condIndepFun_finset_sum_of_not_mem :=
iCondIndepFun.condIndepFun_finset_sum_of_notMem
@[to_additive existing, deprecated (since := "2025-05-24")]
alias iCondIndepFun.condIndepFun_finset_prod_of_not_mem :=
iCondIndepFun.condIndepFun_finset_prod_of_notMem
@[to_additive]
theorem iCondIndepFun.condIndepFun_prod_range_succ {f : ℕ → Ω → β}
(hf_Indep : iCondIndepFun m' hm' f μ) (hf_meas : ∀ i, Measurable (f i)) (n : ℕ) :
CondIndepFun m' hm' (∏ j ∈ Finset.range n, f j) (f n) μ :=
Kernel.iIndepFun.indepFun_prod_range_succ hf_Indep hf_meas n
end CommMonoid
theorem iCondIndepSet.iCondIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β}
{s : ι → Set Ω} (hs : iCondIndepSet m' hm' s μ) :
iCondIndepFun m' hm' (fun n => (s n).indicator fun _ω => (1 : β)) μ :=
Kernel.iIndepSet.iIndepFun_indicator hs
end CondIndepFun
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Independence/Kernel.lean | import Mathlib.Probability.ConditionalProbability
import Mathlib.Probability.Kernel.Basic
import Mathlib.Probability.Kernel.Composition.MeasureComp
import Mathlib.Tactic.Peel
import Mathlib.MeasureTheory.MeasurableSpace.Pi
/-!
# Independence with respect to a kernel and a measure
A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel
`κ : Kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`,
for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`,
`κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`.
This notion of independence is a generalization of both independence and conditional independence.
For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condExpKernel` and
`μ` is the ambient measure. For (non-conditional) independence, `κ = Kernel.const Unit μ` and the
measure is the Dirac measure on `Unit`.
The main purpose of this file is to prove only once the properties that hold for both conditional
and non-conditional independence.
## Main definitions
* `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets.
Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`.
* `ProbabilityTheory.Kernel.iIndep`: independence of a family of σ-algebras. Variant for two
σ-algebras: `Indep`.
* `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets:
`ProbabilityTheory.Kernel.IndepSet`.
* `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables).
Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`.
See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these
definitions in the particular case of the usual independence notion.
## Main statements
* `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets,
then the measurable space structures they generate are independent.
* `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two π-systems.
-/
open Set MeasureTheory MeasurableSpace
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory.Kernel
variable {α Ω ι : Type*}
section Definitions
variable {_mα : MeasurableSpace α}
/-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and
a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`.
It will be used for families of pi_systems. -/
def iIndepSets {_mΩ : MeasurableSpace Ω}
(π : ι → Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop :=
∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i),
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i)
/-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for
any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/
def IndepSets {_mΩ : MeasurableSpace Ω}
(s1 s2 : Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop :=
∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2)
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/
def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/
def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndep (m := fun i ↦ generateFrom {s i}) κ μ
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
Indep (generateFrom {s}) (generateFrom {t}) κ μ
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/
def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)]
(f : ∀ x : ι, Ω → β x) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndep (m := fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `MeasurableSpace.comap f m`. -/
def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ
end Definitions
section ByDefinition
variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ η : Kernel α Ω} {μ : Measure α}
{π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x}
{s1 s2 : Set (Set Ω)}
@[simp] lemma iIndepSets_zero_right : iIndepSets π κ 0 := by simp [iIndepSets]
@[simp] lemma indepSets_zero_right : IndepSets s1 s2 κ 0 := by simp [IndepSets]
@[simp] lemma indepSets_zero_left : IndepSets s1 s2 (0 : Kernel α Ω) μ := by simp [IndepSets]
@[simp] lemma iIndep_zero_right : iIndep m κ 0 := by simp [iIndep]
@[simp] lemma indep_zero_right {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} : Indep m₁ m₂ κ 0 := by simp [Indep]
@[simp] lemma indep_zero_left {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} :
Indep m₁ m₂ (0 : Kernel α Ω) μ := by simp [Indep]
@[simp] lemma iIndepSet_zero_right : iIndepSet s κ 0 := by simp [iIndepSet]
@[simp] lemma indepSet_zero_right {s t : Set Ω} : IndepSet s t κ 0 := by simp [IndepSet]
@[simp] lemma indepSet_zero_left {s t : Set Ω} : IndepSet s t (0 : Kernel α Ω) μ := by
simp [IndepSet]
@[simp] lemma iIndepFun_zero_right {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)}
{f : ∀ x : ι, Ω → β x} : iIndepFun f κ 0 := by simp [iIndepFun]
@[simp] lemma indepFun_zero_right {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} : IndepFun f g κ 0 := by simp [IndepFun]
@[simp] lemma indepFun_zero_left {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} : IndepFun f g (0 : Kernel α Ω) μ := by simp [IndepFun]
lemma iIndepSets_congr (h : κ =ᵐ[μ] η) : iIndepSets π κ μ ↔ iIndepSets π η μ := by
peel 3
refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;>
· filter_upwards [h, h'] with a ha h'a
simpa [ha] using h'a
alias ⟨iIndepSets.congr, _⟩ := iIndepSets_congr
lemma indepSets_congr (h : κ =ᵐ[μ] η) : IndepSets s1 s2 κ μ ↔ IndepSets s1 s2 η μ := by
peel 4
refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;>
· filter_upwards [h, h'] with a ha h'a
simpa [ha] using h'a
alias ⟨IndepSets.congr, _⟩ := indepSets_congr
lemma iIndep_congr (h : κ =ᵐ[μ] η) : iIndep m κ μ ↔ iIndep m η μ :=
iIndepSets_congr h
alias ⟨iIndep.congr, _⟩ := iIndep_congr
lemma indep_congr {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ η : Kernel α Ω} (h : κ =ᵐ[μ] η) : Indep m₁ m₂ κ μ ↔ Indep m₁ m₂ η μ :=
indepSets_congr h
alias ⟨Indep.congr, _⟩ := indep_congr
lemma iIndepSet_congr (h : κ =ᵐ[μ] η) : iIndepSet s κ μ ↔ iIndepSet s η μ :=
iIndep_congr h
alias ⟨iIndepSet.congr, _⟩ := iIndepSet_congr
lemma indepSet_congr {s t : Set Ω} (h : κ =ᵐ[μ] η) : IndepSet s t κ μ ↔ IndepSet s t η μ :=
indep_congr h
alias ⟨indepSet.congr, _⟩ := indepSet_congr
lemma iIndepFun_congr {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)}
{f : ∀ x : ι, Ω → β x} (h : κ =ᵐ[μ] η) : iIndepFun f κ μ ↔ iIndepFun f η μ :=
iIndep_congr h
alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr
lemma indepFun_congr {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} (h : κ =ᵐ[μ] η) : IndepFun f g κ μ ↔ IndepFun f g η μ :=
indep_congr h
alias ⟨IndepFun.congr, _⟩ := indepFun_congr
lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι)
{f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf
lemma iIndepSets.ae_isProbabilityMeasure (h : iIndepSets π κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := by
filter_upwards [h.meas_biInter ∅ (f := fun _ ↦ Set.univ) (by simp)] with a ha
exact ⟨by simpa using ha⟩
lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by
filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha]
lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) :
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ
lemma iIndep.ae_isProbabilityMeasure (h : iIndep m κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) :=
h.iIndepSets'.ae_isProbabilityMeasure
lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs
lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by
filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha
simp [← ha]
@[nontriviality, simp]
lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} {κ : Kernel α Ω}
[IsMarkovKernel κ] : iIndepSets m κ μ := by
rintro s f hf
obtain rfl | ⟨i, rfl⟩ : s = ∅ ∨ ∃ i, s = {i} := by
simpa using (subsingleton_of_subsingleton (s := (s : Set ι))).eq_empty_or_singleton
all_goals simp
@[nontriviality, simp]
lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} {κ : Kernel α Ω}
[IsMarkovKernel κ] : iIndep m κ μ := by simp [iIndep]
@[nontriviality, simp]
lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)}
{f : ∀ i, Ω → β i} [IsMarkovKernel κ] : iIndepFun f κ μ := by
simp [iIndepFun]
protected lemma iIndepFun.iIndep (hf : iIndepFun f κ μ) :
iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf
lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun f κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) :=
h.iIndep.ae_isProbabilityMeasure
lemma iIndepFun.meas_biInter (hf : iIndepFun f κ μ)
(hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs
lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun f κ μ)
(hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs
lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ)
{s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) :
∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht
end ByDefinition
section Indep
variable {_mα : MeasurableSpace α}
@[symm]
theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
{s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) :
IndepSets s₂ s₁ κ μ := by
intro t1 t2 ht1 ht2
filter_upwards [h t2 t1 ht2 ht1] with a ha
rwa [Set.inter_comm, mul_comm]
@[symm]
theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} (h : Indep m₁ m₂ κ μ) :
Indep m₂ m₁ κ μ :=
IndepSets.symm h
theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] :
Indep m' ⊥ κ μ := by
intro s t _ ht
rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp
refine Filter.Eventually.of_forall (fun a ↦ ?_)
rcases ht with ht | ht
· rw [ht, Set.inter_empty, measure_empty, mul_zero]
· rw [ht, Set.inter_univ, measure_univ, mul_one]
theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] :
Indep ⊥ m' κ μ := (indep_bot_right m').symm
theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) :
IndepSet s ∅ κ μ := by
simp only [IndepSet, generateFrom_singleton_empty]
exact indep_bot_right _
theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) :
IndepSet ∅ s κ μ :=
(indepSet_empty_right s).symm
theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) :
IndepSets s₃ s₂ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2
theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) :
IndepSets s₁ s₃ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2)
theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) :
Indep m₃ m₂ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2
theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) :
Indep m₁ m₃ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2)
theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α}
(h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) :
IndepSets (s₁ ∪ s₂) s' κ μ := by
intro t1 t2 ht1 ht2
rcases (Set.mem_union _ _ _).mp ht1 with ht1₁ | ht1₂
· exact h₁ t1 t2 ht1₁ ht2
· exact h₂ t1 t2 ht1₂ ht2
@[simp]
theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ :=
⟨fun h =>
⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left,
indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩,
fun h => IndepSets.union h.left h.right⟩
theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) :
IndepSets (⋃ n, s n) s' κ μ := by
intro t1 t2 ht1 ht2
rw [Set.mem_iUnion] at ht1
obtain ⟨n, ht1⟩ := ht1
exact hyp n t1 t2 ht1 ht2
theorem IndepSets.biUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) :
IndepSets (⋃ n ∈ u, s n) s' κ μ := by
intro t1 t2 ht1 ht2
simp_rw [Set.mem_iUnion] at ht1
rcases ht1 with ⟨n, hpn, ht1⟩
exact hyp n hpn t1 t2 ht1 ht2
@[deprecated (since := "2025-11-02")] alias IndepSets.bUnion := IndepSets.biUnion
theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) :
IndepSets (s₁ ∩ s₂) s' κ μ :=
fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2
theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) :
IndepSets (⋂ n, s n) s' κ μ := by
intro t1 t2 ht1 ht2; obtain ⟨n, h⟩ := h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2
theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) :
IndepSets (⋂ n ∈ u, s n) s' κ μ := by
intro t1 t2 ht1 ht2
rcases h with ⟨n, hn, h⟩
exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2
theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by
simp_rw [← generateFrom_singleton, iIndepSet]
theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
iIndepSets (fun i ↦ {s i}) κ μ ↔
∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by
refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩
filter_upwards [h S] with a ha
have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi]
rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf]
theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
⟨fun h ↦ h s t rfl rfl,
fun h s1 t1 hs1 ht1 ↦ by rwa [Set.mem_singleton_iff.mp hs1, Set.mem_singleton_iff.mp ht1]⟩
end Indep
/-! ### Deducing `Indep` from `iIndep` -/
section FromiIndepToIndep
variable {_mα : MeasurableSpace α}
theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndepSets s κ μ) {i j : ι} (hij : i ≠ j) :
IndepSets (s i) (s j) κ μ := by
classical
intro t₁ t₂ ht₁ ht₂
have hf_m : ∀ x : ι, x ∈ ({i, j} : Finset ι) → ite (x = i) t₁ t₂ ∈ s x := by
intro x hx
rcases Finset.mem_insert.mp hx with hx | hx
· simp [hx, ht₁]
· simp [Finset.mem_singleton.mp hx, hij.symm, ht₂]
have h_inter : ⋂ (t : ι) (_ : t ∈ ({i, j} : Finset ι)), ite (t = i) t₁ t₂ =
ite (i = i) t₁ t₂ ∩ ite (j = i) t₁ t₂ := by
simp only [Finset.set_biInter_singleton, Finset.set_biInter_insert]
filter_upwards [h_indep {i, j} hf_m] with a h_indep'
grind
theorem iIndep.indep {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α}
(h_indep : iIndep m κ μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) κ μ :=
iIndepSets.indepSets h_indep hij
theorem iIndepFun.indepFun {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f κ μ) {i j : ι}
(hij : i ≠ j) : IndepFun (f i) (f j) κ μ :=
hf_Indep.indep hij
end FromiIndepToIndep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section FromMeasurableSpacesToSetsOfSets
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
variable {_mα : MeasurableSpace α}
theorem iIndep.iIndepSets {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {m : ι → MeasurableSpace Ω}
{s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m κ μ) :
iIndepSets s κ μ :=
fun S f hfs =>
h_indep S fun x hxS =>
((hms x).symm ▸ measurableSet_generateFrom (hfs x hxS) : MeasurableSet[m x] (f x))
theorem Indep.indepSets {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {s1 s2 : Set (Set Ω)}
(h_indep : Indep (generateFrom s1) (generateFrom s2) κ μ) :
IndepSets s1 s2 κ μ :=
fun t1 t2 ht1 ht2 =>
h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2)
end FromMeasurableSpacesToSetsOfSets
section FromPiSystemsToMeasurableSpaces
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
variable {_mα : MeasurableSpace α}
theorem IndepSets.indep_aux {m₂ m : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h2 : m₂ ≤ m)
(hp2 : IsPiSystem p2) (hpm2 : m₂ = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) {t1 t2 : Set Ω}
(ht1 : t1 ∈ p1) (ht1m : MeasurableSet[m] t1) (ht2m : MeasurableSet[m₂] t2) :
∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2 := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp
induction t2, ht2m using induction_on_inter hpm2 hp2 with
| empty => simp
| basic u hu => exact hyp t1 u ht1 hu
| compl u hu ihu =>
filter_upwards [ihu] with a ha
rw [← Set.diff_eq, ← Set.diff_self_inter,
measure_diff inter_subset_left (ht1m.inter (h2 _ hu)).nullMeasurableSet (measure_ne_top _ _),
ha, measure_compl (h2 _ hu) (measure_ne_top _ _), measure_univ, ENNReal.mul_sub, mul_one]
exact fun _ _ ↦ measure_ne_top _ _
| iUnion f hfd hfm ihf =>
rw [← ae_all_iff] at ihf
filter_upwards [ihf] with a ha
rw [inter_iUnion, measure_iUnion, measure_iUnion hfd fun i ↦ h2 _ (hfm i)]
· simp only [ENNReal.tsum_mul_left, ha]
· exact hfd.mono fun i j h ↦ (h.inter_left' _).inter_right' _
· exact fun i ↦ .inter ht1m (h2 _ <| hfm i)
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem IndepSets.indep {m1 m2 m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
[IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m) (hp1 : IsPiSystem p1)
(hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2)
(hyp : IndepSets p1 p2 κ μ) :
Indep m1 m2 κ μ := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp
intro t1 t2 ht1 ht2
induction t1, ht1 using induction_on_inter hpm1 hp1 with
| empty =>
simp only [Set.empty_inter, measure_empty, zero_mul, Filter.eventually_true]
| basic t ht =>
refine IndepSets.indep_aux h2 hp2 hpm2 hyp ht (h1 _ ?_) ht2
rw [hpm1]
exact measurableSet_generateFrom ht
| compl t ht iht =>
filter_upwards [iht] with a ha
have : tᶜ ∩ t2 = t2 \ (t ∩ t2) := by
rw [Set.inter_comm t, Set.diff_self_inter, Set.diff_eq_compl_inter]
rw [this, Set.inter_comm t t2,
measure_diff Set.inter_subset_left ((h2 _ ht2).inter (h1 _ ht)).nullMeasurableSet
(measure_ne_top (κ a) _),
Set.inter_comm, ha, measure_compl (h1 _ ht) (measure_ne_top (κ a) t), measure_univ,
mul_comm (1 - κ a t), ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, mul_comm]
| iUnion f hf_disj hf_meas h =>
rw [← ae_all_iff] at h
filter_upwards [h] with a ha
rw [Set.inter_comm, Set.inter_iUnion, measure_iUnion]
· rw [measure_iUnion hf_disj (fun i ↦ h1 _ (hf_meas i))]
rw [← ENNReal.tsum_mul_right]
congr 1 with i
rw [Set.inter_comm t2, ha i]
· intro i j hij
rw [Function.onFun, Set.inter_comm t2, Set.inter_comm t2]
exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij))
· exact fun i ↦ (h2 _ ht2).inter (h1 _ (hf_meas i))
theorem IndepSets.indep' {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
{p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 κ μ) :
Indep (generateFrom p1) (generateFrom p2) κ μ :=
hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl
variable {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)}
{S T : Set ι} (h_indep : iIndepSets s κ μ) (hST : Disjoint S T) :
IndepSets (piiUnionInter s S) (piiUnionInter s T) κ μ := by
rintro t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩
classical
let g i := ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ
have h_P_inter : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = ∏ n ∈ p1 ∪ p2, κ a (g n) := by
have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i := by
intro i hi_mem_union
rw [Finset.mem_union] at hi_mem_union
rcases hi_mem_union with hi1 | hi2
· have hi2 : i ∉ p2 := fun hip2 => Set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2)
simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ]
exact ht1_m i hi1
· have hi1 : i ∉ p1 := fun hip1 => Set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1)
simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter]
exact ht2_m i hi2
have h_p1_inter_p2 :
((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x) =
⋂ i ∈ p1 ∪ p2, ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ := by
ext1 x
simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union]
exact
⟨fun h i _ => ⟨h.1 i, h.2 i⟩, fun h =>
⟨fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi⟩⟩
filter_upwards [h_indep _ hgm] with a ha
rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← ha]
filter_upwards [h_P_inter, h_indep p1 ht1_m, h_indep p2 ht2_m, h_indep.ae_isProbabilityMeasure]
with a h_P_inter ha1 ha2 h'
have h_μg : ∀ n, κ a (g n) = (ite (n ∈ p1) (κ a (f1 n)) 1) * (ite (n ∈ p2) (κ a (f2 n)) 1) := by
intro n
dsimp only [g]
split_ifs with h1 h2
· exact absurd rfl (Set.disjoint_iff_forall_ne.mp hST (hp1 h1) (hp2 h2))
all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter]
simp_rw [h_P_inter, h_μg, Finset.prod_mul_distrib,
Finset.prod_ite_mem (p1 ∪ p2) p1 (fun x ↦ κ a (f1 x)), Finset.union_inter_cancel_left,
Finset.prod_ite_mem (p1 ∪ p2) p2 (fun x => κ a (f2 x)), Finset.union_inter_cancel_right, ht1_eq,
← ha1, ht2_eq, ← ha2]
theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (S T : Set ι) (hST : Disjoint S T) :
Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel hs.ae_isProbabilityMeasure hμ
apply Indep.congr (Filter.EventuallyEq.symm η_eq)
rw [← generateFrom_piiUnionInter_singleton_left, ← generateFrom_piiUnionInter_singleton_left]
refine
IndepSets.indep'
(fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht))
(fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) ?_ ?_ ?_
· exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k
· exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k
· exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _
· exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _
· exact indepSets_piiUnionInter_of_disjoint (iIndep.iIndepSets (fun n => rfl) (hs.congr η_eq)) hST
theorem indep_iSup_of_disjoint {m : ι → MeasurableSpace Ω}
(h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m κ μ) {S T : Set ι} (hST : Disjoint S T) :
Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hμ
apply Indep.congr (Filter.EventuallyEq.symm η_eq)
refine
IndepSets.indep (iSup₂_le fun i _ => h_le i) (iSup₂_le fun i _ => h_le i) ?_ ?_
(generateFrom_piiUnionInter_measurableSet m S).symm
(generateFrom_piiUnionInter_measurableSet m T).symm ?_
· exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _
· exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _
· exact indepSets_piiUnionInter_of_disjoint (h_indep.congr η_eq) hST
theorem indep_iSup_of_directed_le {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ)
(h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Directed (· ≤ ·) m) :
Indep (⨆ i, m i) m' κ μ := by
let p : ι → Set (Set Ω) := fun n => { t | MeasurableSet[m n] t }
have hp : ∀ n, IsPiSystem (p n) := fun n => @isPiSystem_measurableSet Ω (m n)
have h_gen_n : ∀ n, m n = generateFrom (p n) := fun n =>
(@generateFrom_measurableSet Ω (m n)).symm
have hp_supr_pi : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp hm
let p' := { t : Set Ω | MeasurableSet[m'] t }
have hp'_pi : IsPiSystem p' := @isPiSystem_measurableSet Ω m'
have h_gen' : m' = generateFrom p' := (@generateFrom_measurableSet Ω m').symm
-- the π-systems defined are independent
have h_pi_system_indep : IndepSets (⋃ n, p n) p' κ μ := by
refine IndepSets.iUnion ?_
conv at h_indep =>
intro i
rw [h_gen_n i, h_gen']
exact fun n => (h_indep n).indepSets
-- now go from π-systems to σ-algebras
refine IndepSets.indep (iSup_le h_le) h_le' hp_supr_pi hp'_pi ?_ h_gen' h_pi_system_indep
exact (generateFrom_iUnion_measurableSet _).symm
theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) :
Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) κ μ := by
convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {i} { j | j < i }
(Set.disjoint_singleton_left.mpr (lt_irrefl _)) using 1
simp only [Set.mem_singleton_iff, exists_eq_left, Set.setOf_eq_eq_singleton']
theorem iIndepSet.indep_generateFrom_le [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) {k : ι} (hk : i < k) :
Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) κ μ := by
convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {k} { j | j ≤ i }
(Set.disjoint_singleton_left.mpr hk.not_ge) using 1
simp only [Set.mem_singleton_iff, exists_eq_left, Set.setOf_eq_eq_singleton']
theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (n : ℕ) :
Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) κ μ :=
iIndepSet.indep_generateFrom_le hsm hs _ n.lt_succ_self
theorem indep_iSup_of_monotone [SemilatticeSup ι] {Ω} {m : ι → MeasurableSpace Ω}
{m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
(h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0)
(hm : Monotone m) :
Indep (⨆ i, m i) m' κ μ :=
indep_iSup_of_directed_le h_indep h_le h_le' (Monotone.directed_le hm)
theorem indep_iSup_of_antitone [SemilatticeInf ι] {Ω} {m : ι → MeasurableSpace Ω}
{m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
(h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0)
(hm : Antitone m) :
Indep (⨆ i, m i) m' κ μ :=
indep_iSup_of_directed_le h_indep h_le h_le' hm.directed_le
theorem iIndepSets.piiUnionInter_of_notMem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι}
(hp_ind : iIndepSets π κ μ) (haS : a ∉ S) :
IndepSets (piiUnionInter π S) (π a) κ μ := by
rintro t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia
rw [Finset.coe_subset] at hs_mem
classical
let f := fun n => ite (n = a) t2 (ite (n ∈ s) (ft1 n) Set.univ)
have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n := by
intro n hn_mem_insert
dsimp only [f]
rcases Finset.mem_insert.mp hn_mem_insert with hn_mem | hn_mem
· simp [hn_mem, ht2_mem_pia]
· grind
have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n := fun x hxS => h_f_mem x (by simp [hxS])
have h_t1 : t1 = ⋂ n ∈ s, f n := by
suffices h_forall : ∀ n ∈ s, f n = ft1 n by grind
intro n hnS
have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hnS)
simp_rw [f, if_pos hnS, if_neg hn_ne_a]
have h_μ_t1 : ∀ᵐ a' ∂μ, κ a' t1 = ∏ n ∈ s, κ a' (f n) := by
filter_upwards [hp_ind s h_f_mem_pi] with a' ha'
rw [h_t1, ← ha']
have h_t2 : t2 = f a := by simp [f]
have h_μ_inter : ∀ᵐ a' ∂μ, κ a' (t1 ∩ t2) = ∏ n ∈ insert a s, κ a' (f n) := by
have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n := by
rw [h_t1, h_t2, Finset.set_biInter_insert, Set.inter_comm]
filter_upwards [hp_ind (insert a s) h_f_mem] with a' ha'
rw [h_t1_inter_t2, ← ha']
have has : a ∉ s := fun has_mem => haS (hs_mem has_mem)
filter_upwards [h_μ_t1, h_μ_inter] with a' ha1 ha2
rw [ha2, Finset.prod_insert has, h_t2, mul_comm, ha1]
@[deprecated (since := "2025-05-23")]
alias iIndepSets.piiUnionInter_of_not_mem := iIndepSets.piiUnionInter_of_notMem
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem iIndepSets.iIndep (m : ι → MeasurableSpace Ω)
(h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n))
(h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π κ μ) :
iIndep m κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel h_ind.ae_isProbabilityMeasure hμ
apply iIndep.congr (Filter.EventuallyEq.symm η_eq)
intro s f
refine Finset.induction ?_ ?_ s
· simp only [Finset.notMem_empty, Set.mem_setOf_eq, IsEmpty.forall_iff, implies_true,
Set.iInter_of_empty, Set.iInter_univ, measure_univ, Finset.prod_empty,
Filter.eventually_true]
· intro a S ha_notin_S h_rec hf_m
have hf_m_S : ∀ x ∈ S, MeasurableSet[m x] (f x) := fun x hx => hf_m x (by simp [hx])
let p := piiUnionInter π S
set m_p := generateFrom p with hS_eq_generate
have h_indep : Indep m_p (m a) η μ := by
have hp : IsPiSystem p := isPiSystem_piiUnionInter π h_pi S
have h_le' : ∀ i, generateFrom (π i) ≤ _mΩ := fun i ↦ (h_generate i).symm.trans_le (h_le i)
have hm_p : m_p ≤ _mΩ := generateFrom_piiUnionInter_le π h_le' S
exact IndepSets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)
(iIndepSets.piiUnionInter_of_notMem (h_ind.congr η_eq) ha_notin_S)
have h := h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (Finset.mem_insert_self a S)) ?_
· filter_upwards [h_rec hf_m_S, h] with a' ha' h'
rwa [Finset.set_biInter_insert, Finset.prod_insert ha_notin_S, ← ha']
· have h_le_p : ∀ i ∈ S, m i ≤ m_p := by
intro n hn
rw [hS_eq_generate, h_generate n]
exact le_generateFrom_piiUnionInter (S : Set ι) hn
have h_S_f : ∀ i ∈ S, MeasurableSet[m_p] (f i) :=
fun i hi ↦ (h_le_p i hi) (f i) (hf_m_S i hi)
exact S.measurableSet_biInter h_S_f
end FromPiSystemsToMeasurableSpaces
section IndepSet
/-! ### Independence of measurable sets
We prove the following equivalences on `IndepSet`, for measurable sets `s, t`.
* `IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t`,
* `IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ`.
-/
variable {_mα : MeasurableSpace α}
theorem iIndepSet_iff_iIndepSets_singleton {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f κ μ ↔ iIndepSets (fun i ↦ {f i}) κ μ :=
⟨iIndep.iIndepSets fun _ ↦ rfl,
iIndepSets.iIndep _ (fun i ↦ generateFrom_le <| by rintro t (rfl : t = _); exact hf _) _
(fun _ ↦ IsPiSystem.singleton _) fun _ ↦ rfl⟩
theorem iIndepSet.meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (h : iIndepSet f κ μ) (s : Finset ι) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) :=
iIndep.iIndepSets (fun _ ↦ rfl) h _ (by simp)
theorem iIndepSet_iff_meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f κ μ ↔ ∀ s, ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) :=
(iIndepSet_iff_iIndepSets_singleton hf).trans iIndepSets_singleton_iff
theorem iIndepSets.iIndepSet_of_mem {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {π : ι → Set (Set Ω)} {f : ι → Set Ω}
(hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i)) (hπ : iIndepSets π κ μ) :
iIndepSet f κ μ :=
(iIndepSet_iff_meas_biInter hf).2 fun _t ↦ hπ.meas_biInter _ fun _i _ ↦ hfπ _
variable {s t : Set Ω} (S T : Set (Set Ω))
theorem indepSet_iff_indepSets_singleton {m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α)
[IsZeroOrMarkovKernel κ] :
IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ :=
⟨Indep.indepSets, fun h =>
IndepSets.indep
(generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu])
(generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu])
(IsPiSystem.singleton s) (IsPiSystem.singleton t) rfl rfl h⟩
theorem indepSet_iff_measure_inter_eq_mul {_m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α)
[IsZeroOrMarkovKernel κ] :
IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
(indepSet_iff_indepSets_singleton hs_meas ht_meas κ μ).trans indepSets_singleton_iff
theorem IndepSet.measure_inter_eq_mul {_m0 : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α)
(h : IndepSet s t κ μ) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
Indep.indepSets h _ _ (by simp) (by simp)
theorem IndepSets.indepSet_of_mem {_m0 : MeasurableSpace Ω} (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t)
(κ : Kernel α Ω) (μ : Measure α) [IsZeroOrMarkovKernel κ]
(h_indep : IndepSets S T κ μ) :
IndepSet s t κ μ :=
(indepSet_iff_measure_inter_eq_mul hs_meas ht_meas κ μ).mpr (h_indep s t hs ht)
theorem Indep.indepSet_of_measurableSet {m₁ m₂ _ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α}
(h_indep : Indep m₁ m₂ κ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s)
(ht : MeasurableSet[m₂] t) :
IndepSet s t κ μ := by
refine fun s' t' hs' ht' => h_indep s' t' ?_ ?_
· induction s', hs' using generateFrom_induction with
| hC t ht => exact ht ▸ hs
| empty => exact @MeasurableSet.empty _ m₁
| compl u _ hu => exact hu.compl
| iUnion f _ hf => exact .iUnion hf
· induction t', ht' using generateFrom_induction with
| hC s hs => exact hs ▸ ht
| empty => exact @MeasurableSet.empty _ m₂
| compl u _ hu => exact hu.compl
| iUnion f _ hf => exact .iUnion hf
theorem indep_iff_forall_indepSet (m₁ m₂ : MeasurableSpace Ω) {_m0 : MeasurableSpace Ω}
(κ : Kernel α Ω) (μ : Measure α) :
Indep m₁ m₂ κ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t κ μ :=
⟨fun h => fun _s _t hs ht => h.indepSet_of_measurableSet hs ht, fun h s t hs ht =>
h s t hs ht s t (measurableSet_generateFrom (Set.mem_singleton s))
(measurableSet_generateFrom (Set.mem_singleton t))⟩
end IndepSet
section IndepFun
/-! ### Independence of random variables
-/
variable {β β' γ γ' : Type*} {_mα : MeasurableSpace α} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {f : Ω → β} {g : Ω → β'}
theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} :
IndepFun f g κ μ ↔
∀ s t, MeasurableSet s → MeasurableSet t
→ ∀ᵐ a ∂μ, κ a (f ⁻¹' s ∩ g ⁻¹' t) = κ a (f ⁻¹' s) * κ a (g ⁻¹' t) := by
constructor <;> intro h
· refine fun s t hs ht => h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩
· rintro _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩; exact h s t hs ht
alias ⟨IndepFun.measure_inter_preimage_eq_mul, _⟩ := indepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
(m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) :
iIndepFun f κ μ ↔
∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)),
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, (f i) ⁻¹' (sets i)) = ∏ i ∈ S, κ a ((f i) ⁻¹' (sets i)) := by
refine ⟨fun h S sets h_meas => h _ fun i hi_mem => ⟨sets i, h_meas i hi_mem, rfl⟩, ?_⟩
intro h S setsΩ h_meas
classical
let setsβ : ∀ i : ι, Set (β i) := fun i =>
dite (i ∈ S) (fun hi_mem => (h_meas i hi_mem).choose) fun _ => Set.univ
have h_measβ : ∀ i ∈ S, MeasurableSet[m i] (setsβ i) := by
intro i hi_mem
simp_rw [setsβ, dif_pos hi_mem]
exact (h_meas i hi_mem).choose_spec.1
have h_preim : ∀ i ∈ S, setsΩ i = f i ⁻¹' setsβ i := by
intro i hi_mem
simp_rw [setsβ, dif_pos hi_mem]
exact (h_meas i hi_mem).choose_spec.2.symm
simp_all
alias ⟨iIndepFun.measure_inter_preimage_eq_mul, _⟩ := iIndepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun.congr' {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{f g : Π i, Ω → β i} (hf : iIndepFun f κ μ)
(h : ∀ i, ∀ᵐ a ∂μ, f i =ᵐ[κ a] g i) :
iIndepFun g κ μ := by
rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at hf ⊢
intro S sets hmeas
have : ∀ᵐ a ∂μ, ∀ i ∈ S, f i =ᵐ[κ a] g i :=
(ae_ball_iff (Finset.countable_toSet S)).2 (fun i hi ↦ h i)
filter_upwards [this, hf S hmeas] with a ha h'a
have A i (hi : i ∈ S) : (κ a) (g i ⁻¹' sets i) = (κ a) (f i ⁻¹' sets i) := by
apply measure_congr
filter_upwards [ha i hi] with ω hω
change (g i ω ∈ sets i) = (f i ω ∈ sets i)
simp [hω]
have B : (κ a) (⋂ i ∈ S, g i ⁻¹' sets i) = (κ a) (⋂ i ∈ S, f i ⁻¹' sets i) := by
apply measure_congr
filter_upwards [(ae_ball_iff (Finset.countable_toSet S)).2 ha] with ω hω
change (ω ∈ ⋂ i ∈ S, g i ⁻¹' sets i) = (ω ∈ ⋂ i ∈ S, f i ⁻¹' sets i)
simp +contextual [hω]
convert h'a using 2 with i hi
exact A i hi
theorem iIndepFun_congr' {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{f g : Π i, Ω → β i} (h : ∀ i, ∀ᵐ a ∂μ, f i =ᵐ[κ a] g i) :
iIndepFun f κ μ ↔ iIndepFun g κ μ where
mp h' := h'.congr' h
mpr h' := by
refine h'.congr' fun i ↦ ?_
filter_upwards [h i] with a ha using ha.symm
lemma iIndepFun.comp {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f κ μ) (g : ∀ i, β i → γ i) (hg : ∀ i, Measurable (g i)) :
iIndepFun (fun i ↦ g i ∘ f i) κ μ := by
rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at h ⊢
refine fun t s hs ↦ ?_
have := h t (sets := fun i ↦ g i ⁻¹' (s i)) (fun i a ↦ hg i (hs i a))
filter_upwards [this] with a ha
simp_rw [Set.preimage_comp]
exact ha
lemma iIndepFun.comp₀ {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f κ μ) (g : ∀ i, β i → γ i)
(hf : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (hg : ∀ i, AEMeasurable (g i) ((κ ∘ₘ μ).map (f i))) :
iIndepFun (fun i ↦ g i ∘ f i) κ μ := by
have h : iIndepFun (fun i ↦ ((hg i).mk (g i)) ∘ f i) κ μ :=
iIndepFun.comp h (fun i ↦ (hg i).mk (g i)) fun i ↦ (hg i).measurable_mk
have h_ae i := ae_of_ae_map (hf i) (hg i).ae_eq_mk.symm
exact iIndepFun.congr' h fun i ↦ Measure.ae_ae_of_ae_comp (h_ae i)
theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrMarkovKernel κ] (hf : Measurable f) (hg : Measurable g) :
IndepFun f g κ μ ↔
∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) κ μ := by
refine indepFun_iff_measure_inter_preimage_eq_mul.trans ?_
constructor <;> intro h s t hs ht <;> specialize h s t hs ht
· rwa [indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ]
· rwa [← indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ]
@[symm]
nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'}
(hfg : IndepFun f g κ μ) : IndepFun g f κ μ := hfg.symm
theorem IndepFun.congr' {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{f' : Ω → β} {g' : Ω → β'} (hfg : IndepFun f g κ μ)
(hf : ∀ᵐ a ∂μ, f =ᵐ[κ a] f') (hg : ∀ᵐ a ∂μ, g =ᵐ[κ a] g') :
IndepFun f' g' κ μ := by
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩
filter_upwards [hf, hg, hfg _ _ ⟨_, hA, rfl⟩ ⟨_, hB, rfl⟩] with a hf' hg' hfg'
have h1 : f ⁻¹' A =ᵐ[κ a] f' ⁻¹' A := hf'.fun_comp A
have h2 : g ⁻¹' B =ᵐ[κ a] g' ⁻¹' B := hg'.fun_comp B
rwa [← measure_congr h1, ← measure_congr h2, ← measure_congr (h1.inter h2)]
theorem IndepFun.comp {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{mγ : MeasurableSpace γ} {mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : IndepFun f g κ μ) (hφ : Measurable φ) (hψ : Measurable ψ) :
IndepFun (φ ∘ f) (ψ ∘ g) κ μ := by
rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩
apply hfg
· exact ⟨φ ⁻¹' A, hφ hA, Set.preimage_comp.symm⟩
· exact ⟨ψ ⁻¹' B, hψ hB, Set.preimage_comp.symm⟩
theorem IndepFun.comp₀ {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{mγ : MeasurableSpace γ} {mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : IndepFun f g κ μ)
(hf : AEMeasurable f (κ ∘ₘ μ)) (hg : AEMeasurable g (κ ∘ₘ μ))
(hφ : AEMeasurable φ ((κ ∘ₘ μ).map f)) (hψ : AEMeasurable ψ ((κ ∘ₘ μ).map g)) :
IndepFun (φ ∘ f) (ψ ∘ g) κ μ := by
have h : IndepFun ((hφ.mk φ) ∘ f) ((hψ.mk ψ) ∘ g) κ μ := by
refine IndepFun.comp hfg hφ.measurable_mk hψ.measurable_mk
have hφ_ae := ae_of_ae_map hf hφ.ae_eq_mk
have hψ_ae := ae_of_ae_map hg hψ.ae_eq_mk
refine IndepFun.congr' h ?_ ?_
· filter_upwards [Measure.ae_ae_of_ae_comp (hφ_ae)] with a haφ
filter_upwards [haφ] with ω hωφ
simp [hωφ]
· filter_upwards [Measure.ae_ae_of_ae_comp (hψ_ae)] with a haψ
filter_upwards [haψ] with ω hωψ
simp [hωψ]
lemma indepFun_const_left {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrMarkovKernel κ] (c : β') (X : Ω → β) :
IndepFun (fun _ ↦ c) X κ μ := by
rw [IndepFun, MeasurableSpace.comap_const]
exact indep_bot_left _
lemma indepFun_const_right {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrMarkovKernel κ] (X : Ω → β) (c : β') :
IndepFun X (fun _ ↦ c) κ μ :=
(indepFun_const_left c X).symm
theorem IndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β']
[MeasurableNeg β'] (hfg : IndepFun f g κ μ) :
IndepFun f (-g) κ μ := hfg.comp measurable_id measurable_neg
theorem IndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β]
[MeasurableNeg β] (hfg : IndepFun f g κ μ) :
IndepFun (-f) g κ μ := hfg.comp measurable_neg measurable_id
/-- Two random variables `f, g` are independent given a kernel `κ` and a measure `μ` iff
`μ ⊗ₘ κ.map (fun ω ↦ (f ω, g ω)) = μ ⊗ₘ (κ.map f ×ₖ κ.map g)`. -/
theorem indepFun_iff_compProd_map_prod_eq_compProd_prod_map_map
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
[IsFiniteMeasure μ] [IsFiniteKernel κ] {f : Ω → β} {g : Ω → γ}
(hf : Measurable f) (hg : Measurable g) :
IndepFun f g κ μ ↔ μ ⊗ₘ κ.map (fun ω ↦ (f ω, g ω)) = μ ⊗ₘ (κ.map f ×ₖ κ.map g) := by
classical
rw [indepFun_iff_measure_inter_preimage_eq_mul]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [Measure.ext_prod₃_iff]
intro u s t hu hs ht
rw [Measure.compProd_apply (hu.prod (hs.prod ht)),
Measure.compProd_apply (hu.prod (hs.prod ht))]
refine lintegral_congr_ae ?_
have h_set_eq ω : Prod.mk ω ⁻¹' u ×ˢ s ×ˢ t = if ω ∈ u then s ×ˢ t else ∅ := by ext; simp
simp_rw [h_set_eq]
filter_upwards [h s t hs ht] with ω hω
by_cases hωu : ω ∈ u
swap; · simp [hωu]
simp only [hωu, ↓reduceIte]
rw [map_apply _ (by fun_prop), Measure.map_apply (by fun_prop) (hs.prod ht),
mk_preimage_prod, hω, prod_apply_prod, map_apply' _ (by fun_prop), map_apply' _ (by fun_prop)]
exacts [ht, hs]
· intro s t hs ht
rw [Measure.ext_prod₃_iff] at h
refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite ?_ ?_ ?_
· exact Kernel.measurable_coe _ ((hf hs).inter (hg ht))
· exact (Kernel.measurable_coe _ (hf hs)).mul (Kernel.measurable_coe _ (hg ht))
intro u hu hμu
specialize h hu hs ht
rw [Measure.compProd_apply_prod hu (hs.prod ht),
Measure.compProd_apply_prod hu (hs.prod ht)] at h
convert h with ω ω
· rw [map_apply' _ (by fun_prop) _ (hs.prod ht), mk_preimage_prod]
· rw [prod_apply_prod, map_apply' _ (by fun_prop) _ hs, map_apply' _ (by fun_prop) _ ht]
section iIndepFun
variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i}
/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
theorem iIndepFun.indepFun_finset (S T : Finset ι) (hST : Disjoint S T)
(hf_Indep : iIndepFun f κ μ) (hf_meas : ∀ i, Measurable (f i)) :
IndepFun (fun a (i : S) => f i a) (fun a (i : T) => f i a) κ μ := by
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel hf_Indep.ae_isProbabilityMeasure hμ
apply IndepFun.congr (Filter.EventuallyEq.symm η_eq)
-- We introduce π-systems, built from the π-system of boxes which generates `MeasurableSpace.pi`.
let πSβ := Set.pi (Set.univ : Set S) ''
Set.pi (Set.univ : Set S) fun i => { s : Set (β i) | MeasurableSet[m i] s }
let πS := { s : Set Ω | ∃ t ∈ πSβ, (fun a (i : S) => f i a) ⁻¹' t = s }
have hπS_pi : IsPiSystem πS := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _
have hπS_gen : (MeasurableSpace.pi.comap fun a (i : S) => f i a) = generateFrom πS := by
rw [generateFrom_pi.symm, comap_generateFrom]
congr
let πTβ := Set.pi (Set.univ : Set T) ''
Set.pi (Set.univ : Set T) fun i => { s : Set (β i) | MeasurableSet[m i] s }
let πT := { s : Set Ω | ∃ t ∈ πTβ, (fun a (i : T) => f i a) ⁻¹' t = s }
have hπT_pi : IsPiSystem πT := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _
have hπT_gen : (MeasurableSpace.pi.comap fun a (i : T) => f i a) = generateFrom πT := by
rw [generateFrom_pi.symm, comap_generateFrom]
congr
-- To prove independence, we prove independence of the generating π-systems.
refine IndepSets.indep (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i))
(Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i)) hπS_pi hπT_pi hπS_gen hπT_gen
?_
rintro _ _ ⟨s, ⟨sets_s, hs1, hs2⟩, rfl⟩ ⟨t, ⟨sets_t, ht1, ht2⟩, rfl⟩
simp only [Set.mem_univ_pi, Set.mem_setOf_eq] at hs1 ht1
rw [← hs2, ← ht2]
classical
let sets_s' : ∀ i : ι, Set (β i) := fun i =>
dite (i ∈ S) (fun hi => sets_s ⟨i, hi⟩) fun _ => Set.univ
have h_sets_s'_eq : ∀ {i} (hi : i ∈ S), sets_s' i = sets_s ⟨i, hi⟩ := by
intro i hi; simp_rw [sets_s', dif_pos hi]
have h_sets_s'_univ : ∀ {i} (_hi : i ∈ T), sets_s' i = Set.univ := by
intro i hi; simp_rw [sets_s', dif_neg (Finset.disjoint_right.mp hST hi)]
let sets_t' : ∀ i : ι, Set (β i) := fun i =>
dite (i ∈ T) (fun hi => sets_t ⟨i, hi⟩) fun _ => Set.univ
have h_sets_t'_univ : ∀ {i} (_hi : i ∈ S), sets_t' i = Set.univ := by
intro i hi; simp_rw [sets_t', dif_neg (Finset.disjoint_left.mp hST hi)]
have h_meas_s' : ∀ i ∈ S, MeasurableSet (sets_s' i) := by
intro i hi; rw [h_sets_s'_eq hi]; exact hs1 _
have h_meas_t' : ∀ i ∈ T, MeasurableSet (sets_t' i) := by
intro i hi; simp_rw [sets_t', dif_pos hi]; exact ht1 _
have h_eq_inter_S : (fun (ω : Ω) (i : ↥S) =>
f (↑i) ω) ⁻¹' Set.pi Set.univ sets_s = ⋂ i ∈ S, f i ⁻¹' sets_s' i := by
ext1 x
simp_rw [Set.mem_preimage, Set.mem_univ_pi, Set.mem_iInter]
grind
have h_eq_inter_T : (fun (ω : Ω) (i : ↥T) => f (↑i) ω) ⁻¹' Set.pi Set.univ sets_t
= ⋂ i ∈ T, f i ⁻¹' sets_t' i := by
ext1 x
simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_iInter]
constructor <;> intro h
· intro i hi; simp_rw [sets_t', dif_pos hi]; exact h ⟨i, hi⟩
· rintro ⟨i, hi⟩; specialize h i hi; simp_rw [sets_t', dif_pos hi] at h; exact h
replace hf_Indep := hf_Indep.congr η_eq
rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at hf_Indep
have h_Inter_inter :
((⋂ i ∈ S, f i ⁻¹' sets_s' i) ∩ ⋂ i ∈ T, f i ⁻¹' sets_t' i) =
⋂ i ∈ S ∪ T, f i ⁻¹' (sets_s' i ∩ sets_t' i) := by
ext1 x
simp_rw [Set.mem_inter_iff, Set.mem_iInter, Set.mem_preimage, Finset.mem_union]
constructor <;> intro h
· grind
· exact ⟨fun i hi => (h i (Or.inl hi)).1, fun i hi => (h i (Or.inr hi)).2⟩
have h_meas_inter : ∀ i ∈ S ∪ T, MeasurableSet (sets_s' i ∩ sets_t' i) := by
intro i hi_mem
rw [Finset.mem_union] at hi_mem
rcases hi_mem with hi_mem | hi_mem
· rw [h_sets_t'_univ hi_mem, Set.inter_univ]
exact h_meas_s' i hi_mem
· rw [h_sets_s'_univ hi_mem, Set.univ_inter]
exact h_meas_t' i hi_mem
filter_upwards [hf_Indep S h_meas_s', hf_Indep T h_meas_t', hf_Indep (S ∪ T) h_meas_inter]
with a h_indepS h_indepT h_indepST
rw [h_eq_inter_S, h_eq_inter_T, h_indepS, h_indepT, h_Inter_inter, h_indepST,
Finset.prod_union hST]
congr 1
· refine Finset.prod_congr rfl fun i hi => ?_
rw [h_sets_t'_univ hi, Set.inter_univ]
· refine Finset.prod_congr rfl fun i hi => ?_
rw [h_sets_s'_univ hi, Set.univ_inter]
theorem iIndepFun.indepFun_finset₀ (S T : Finset ι) (hST : Disjoint S T)
(hf_Indep : iIndepFun f κ μ) (hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) :
IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) κ μ := by
have h : IndepFun (fun a (i : S) ↦ (hf_meas i).mk (f i) a)
(fun a (i : T) ↦ (hf_meas i).mk (f i) a) κ μ := by
refine iIndepFun.indepFun_finset S T hST ?_ fun i ↦ (hf_meas i).measurable_mk
exact iIndepFun.congr' hf_Indep fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
refine IndepFun.congr' h ?_ ?_
· have : ∀ᵐ (a : α) ∂μ, ∀ (i : S), f i =ᵐ[κ a] (hf_meas i).mk := by
rw [ae_all_iff]
exact fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
filter_upwards [this] with a ha
filter_upwards [ae_all_iff.2 ha] with b hb
ext i
exact (hb i).symm
· have : ∀ᵐ (a : α) ∂μ, ∀ (i : T), f i =ᵐ[κ a] (hf_meas i).mk := by
rw [ae_all_iff]
exact fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
filter_upwards [this] with a ha
filter_upwards [ae_all_iff.2 ha] with b hb
ext i
exact (hb i).symm
theorem iIndepFun.indepFun_prodMk (hf_Indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a => (f i a, f j a)) (f k) κ μ := by
classical
have h_right :
f k = (fun p : ∀ j : ({k} : Finset ι), β j => p ⟨k, Finset.mem_singleton_self k⟩) ∘
fun a (j : ({k} : Finset ι)) => f j a :=
rfl
have h_meas_right : Measurable fun p : ∀ j : ({k} : Finset ι),
β j => p ⟨k, Finset.mem_singleton_self k⟩ :=
measurable_pi_apply _
let s : Finset ι := {i, j}
have h_left : (fun ω => (f i ω, f j ω)) = (fun p : ∀ l : s, β l =>
(p ⟨i, Finset.mem_insert_self i _⟩,
p ⟨j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)⟩)) ∘
fun a (j : s) => f j a := by
ext1 a
simp only
constructor
have h_meas_left : Measurable fun p : ∀ l : s, β l =>
(p ⟨i, Finset.mem_insert_self i _⟩,
p ⟨j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)⟩) :=
Measurable.prod (measurable_pi_apply _) (measurable_pi_apply _)
rw [h_left, h_right]
refine (hf_Indep.indepFun_finset s {k} ?_ hf_meas).comp h_meas_left h_meas_right
rw [Finset.disjoint_singleton_right]
simp only [s, Finset.mem_insert, Finset.mem_singleton, not_or]
exact ⟨hik.symm, hjk.symm⟩
theorem iIndepFun.indepFun_prodMk₀ (hf_Indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a ↦ (f i a, f j a)) (f k) κ μ := by
have h : IndepFun (fun a ↦ ((hf_meas i).mk (f i) a, (hf_meas j).mk (f j) a))
((hf_meas k).mk (f k)) κ μ := by
refine iIndepFun.indepFun_prodMk ?_ (fun i ↦ (hf_meas i).measurable_mk) _ _ _ hik hjk
exact iIndepFun.congr' hf_Indep fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
refine IndepFun.congr' h ?_ ?_
· filter_upwards [Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk,
Measure.ae_ae_of_ae_comp (hf_meas j).ae_eq_mk] with a hi hj
filter_upwards [hi, hj] with ω hωi hωj
rw [← hωi, ← hωj]
· exact Measure.ae_ae_of_ae_comp (hf_meas k).ae_eq_mk.symm
open Finset in
lemma iIndepFun.indepFun_prodMk_prodMk (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) κ μ := by
classical
let g (i j : ι) (v : Π x : ({i, j} : Finset ι), β x) : β i × β j :=
⟨v ⟨i, mem_insert_self _ _⟩, v ⟨j, mem_insert_of_mem <| mem_singleton_self _⟩⟩
have hg (i j : ι) : Measurable (g i j) := by fun_prop
exact (hf_indep.indepFun_finset {i, j} {k, l} (by aesop) hf_meas).comp (hg i j) (hg k l)
theorem iIndepFun.indepFun_prodMk_prodMk₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) κ μ := by
have h : IndepFun (fun a ↦ ((hf_meas i).mk (f i) a, (hf_meas j).mk (f j) a))
(fun a ↦ ((hf_meas k).mk (f k) a, (hf_meas l).mk (f l) a)) κ μ := by
refine iIndepFun.indepFun_prodMk_prodMk ?_ (fun i ↦ (hf_meas i).measurable_mk) _ _ _ _ hik hil
hjk hjl
exact iIndepFun.congr' hf_indep fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
refine IndepFun.congr' h ?_ ?_
· filter_upwards [Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk,
Measure.ae_ae_of_ae_comp (hf_meas j).ae_eq_mk] with a hi hj
filter_upwards [hi, hj] with ω hωi hωj
rw [← hωi, ← hωj]
· filter_upwards [Measure.ae_ae_of_ae_comp (hf_meas k).ae_eq_mk,
Measure.ae_ae_of_ae_comp (hf_meas l).ae_eq_mk] with a hk hl
filter_upwards [hk, hl] with ω hωk hωl
rw [← hωk, ← hωl]
end iIndepFun
section Mul
variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_mul_left (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) κ μ := by
have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ :=
hf_indep.indepFun_prodMk hf_meas i j k hik hjk
simpa using this.comp (measurable_fst.mul measurable_snd) measurable_id
@[to_additive]
lemma iIndepFun.indepFun_mul_left₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) κ μ := by
have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ :=
hf_indep.indepFun_prodMk₀ hf_meas i j k hik hjk
simpa using this.comp (measurable_fst.mul measurable_snd) measurable_id
@[to_additive]
lemma iIndepFun.indepFun_mul_right (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) κ μ :=
(hf_indep.indepFun_mul_left hf_meas _ _ _ hij.symm hik.symm).symm
@[to_additive]
lemma iIndepFun.indepFun_mul_right₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) κ μ :=
(hf_indep.indepFun_mul_left₀ hf_meas _ _ _ hij.symm hik.symm).symm
@[to_additive]
lemma iIndepFun.indepFun_mul_mul (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) κ μ :=
(hf_indep.indepFun_prodMk_prodMk hf_meas i j k l hik hil hjk hjl).comp
measurable_mul measurable_mul
@[to_additive]
lemma iIndepFun.indepFun_mul_mul₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) κ μ :=
(hf_indep.indepFun_prodMk_prodMk₀ hf_meas i j k l hik hil hjk hjl).comp
measurable_mul measurable_mul
end Mul
section Div
variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_div_left (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) κ μ := by
have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ :=
hf_indep.indepFun_prodMk hf_meas i j k hik hjk
simpa using this.comp (measurable_fst.div measurable_snd) measurable_id
@[to_additive]
lemma iIndepFun.indepFun_div_left₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) κ μ := by
have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ :=
hf_indep.indepFun_prodMk₀ hf_meas i j k hik hjk
simpa using this.comp (measurable_fst.div measurable_snd) measurable_id
@[to_additive]
lemma iIndepFun.indepFun_div_right (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) κ μ :=
(hf_indep.indepFun_div_left hf_meas _ _ _ hij.symm hik.symm).symm
@[to_additive]
lemma iIndepFun.indepFun_div_right₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) κ μ :=
(hf_indep.indepFun_div_left₀ hf_meas _ _ _ hij.symm hik.symm).symm
@[to_additive]
lemma iIndepFun.indepFun_div_div (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) κ μ :=
(hf_indep.indepFun_prodMk_prodMk hf_meas i j k l hik hil hjk hjl).comp
measurable_div measurable_div
@[to_additive]
lemma iIndepFun.indepFun_div_div₀ (hf_indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) κ μ :=
(hf_indep.indepFun_prodMk_prodMk₀ hf_meas i j k l hik hil hjk hjl).comp
measurable_div measurable_div
end Div
section CommMonoid
variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
theorem iIndepFun.indepFun_finset_prod_of_notMem (hf_Indep : iIndepFun f κ μ)
(hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) κ μ := by
classical
have h_right : f i =
(fun p : ({i} : Finset ι) → β => p ⟨i, Finset.mem_singleton_self i⟩) ∘
fun a (j : ({i} : Finset ι)) => f j a := rfl
have h_meas_right : Measurable fun p : ({i} : Finset ι) → β =>
p ⟨i, Finset.mem_singleton_self i⟩ := measurable_pi_apply _
have h_left : ∏ j ∈ s, f j = (fun p : s → β => ∏ j, p j) ∘ fun a (j : s) => f j a := by
ext1 a
simp only [Function.comp_apply]
have : (∏ j : ↥s, f (↑j) a) = (∏ j : ↥s, f ↑j) a := by rw [Finset.prod_apply]
rw [this, Finset.prod_coe_sort]
have h_meas_left : Measurable fun p : s → β => ∏ j, p j :=
Finset.univ.measurable_fun_prod fun (j : ↥s) (_H : j ∈ Finset.univ) => measurable_pi_apply j
rw [h_left, h_right]
exact
(hf_Indep.indepFun_finset s {i} (Finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp
h_meas_left h_meas_right
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem := iIndepFun.indepFun_finset_sum_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem := iIndepFun.indepFun_finset_prod_of_notMem
@[to_additive]
theorem iIndepFun.indepFun_finset_prod_of_notMem₀ (hf_Indep : iIndepFun f κ μ)
(hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) κ μ := by
have h : IndepFun (∏ j ∈ s, (hf_meas j).mk (f j)) ((hf_meas i).mk (f i)) κ μ := by
refine iIndepFun.indepFun_finset_prod_of_notMem ?_ (fun i ↦ (hf_meas i).measurable_mk) hi
exact iIndepFun.congr' hf_Indep fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
refine IndepFun.congr' h ?_ ?_
· have : ∀ᵐ a ∂μ, ∀ (i : s), f i =ᵐ[κ a] (hf_meas i).mk := by
rw [ae_all_iff]
exact fun i ↦ Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk
filter_upwards [this] with a ha
filter_upwards [ae_all_iff.2 ha] with ω hω
simp only [Finset.prod_apply]
exact Finset.prod_congr rfl fun i hi ↦ (hω ⟨i, hi⟩).symm
· exact Measure.ae_ae_of_ae_comp (hf_meas i).ae_eq_mk.symm
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem₀ := iIndepFun.indepFun_finset_sum_of_notMem₀
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem₀ := iIndepFun.indepFun_finset_prod_of_notMem₀
@[to_additive]
theorem iIndepFun.indepFun_prod_range_succ {f : ℕ → Ω → β}
(hf_Indep : iIndepFun f κ μ) (hf_meas : ∀ i, Measurable (f i)) (n : ℕ) :
IndepFun (∏ j ∈ Finset.range n, f j) (f n) κ μ :=
hf_Indep.indepFun_finset_prod_of_notMem hf_meas Finset.notMem_range_self
@[to_additive]
theorem iIndepFun.indepFun_prod_range_succ₀ {f : ℕ → Ω → β}
(hf_Indep : iIndepFun f κ μ) (hf_meas : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (n : ℕ) :
IndepFun (∏ j ∈ Finset.range n, f j) (f n) κ μ :=
hf_Indep.indepFun_finset_prod_of_notMem₀ hf_meas Finset.notMem_range_self
end CommMonoid
theorem iIndepSet.iIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω}
(hs : iIndepSet s κ μ) :
iIndepFun (fun n => (s n).indicator fun _ω => (1 : β)) κ μ := by
classical
rw [iIndepFun_iff_measure_inter_preimage_eq_mul]
rintro S π _hπ
simp_rw [Set.indicator_const_preimage_eq_union]
apply hs _ fun i _hi ↦ ?_
have hsi : MeasurableSet[generateFrom {s i}] (s i) :=
measurableSet_generateFrom (Set.mem_singleton _)
refine
MeasurableSet.union (MeasurableSet.ite' (fun _ => hsi) fun _ => ?_)
(MeasurableSet.ite' (fun _ => hsi.compl) fun _ => ?_)
· exact @MeasurableSet.empty _ (generateFrom {s i})
· exact @MeasurableSet.empty _ (generateFrom {s i})
end IndepFun
variable {ι Ω α β : Type*} {mΩ : MeasurableSpace Ω} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} {κ : Kernel α Ω} {μ : Measure α} {X : ι → Ω → α} {Y : ι → Ω → β}
{f : _ → Set Ω} {t : ι → Set β} {s : Finset ι}
/-- The probability of an intersection of preimages conditioning on another intersection factors
into a product. -/
lemma iIndepFun.cond_iInter [Finite ι] (hY : ∀ i, Measurable (Y i))
(hindep : iIndepFun (fun i ω ↦ (X i ω, Y i ω)) κ μ)
(hf : ∀ i ∈ s, MeasurableSet[mα.comap (X i)] (f i))
(hy : ∀ᵐ a ∂μ, ∀ i ∉ s, κ a (Y i ⁻¹' t i) ≠ 0) (ht : ∀ i, MeasurableSet (t i)) :
∀ᵐ a ∂μ, (κ a)[⋂ i ∈ s, f i | ⋂ i, Y i ⁻¹' t i] = ∏ i ∈ s, (κ a)[f i | Y i in t i] := by
classical
cases nonempty_fintype ι
let g (i' : ι) := if i' ∈ s then Y i' ⁻¹' t i' ∩ f i' else Y i' ⁻¹' t i'
have hYt i : MeasurableSet[(mα.prod mβ).comap fun ω ↦ (X i ω, Y i ω)] (Y i ⁻¹' t i) :=
⟨.univ ×ˢ t i, .prod .univ (ht _), by ext; simp⟩
have hg i : MeasurableSet[(mα.prod mβ).comap fun ω ↦ (X i ω, Y i ω)] (g i) := by
by_cases hi : i ∈ s <;> simp only [hi, ↓reduceIte, g]
· obtain ⟨A, hA, hA'⟩ := hf i hi
exact (hYt _).inter ⟨A ×ˢ .univ, hA.prod .univ, by ext; simp [← hA']⟩
· exact hYt _
filter_upwards [hy, hindep.ae_isProbabilityMeasure, hindep.meas_iInter hYt, hindep.meas_iInter hg]
with a hy _ hYt hg
calc
_ = (κ a (⋂ i, Y i ⁻¹' t i))⁻¹ * κ a ((⋂ i, Y i ⁻¹' t i) ∩ ⋂ i ∈ s, f i) := by
rw [cond_apply]; exact .iInter fun i ↦ hY i (ht i)
_ = (κ a (⋂ i, Y i ⁻¹' t i))⁻¹ * κ a (⋂ i, g i) := by
congr 2
calc
_ = (⋂ i, Y i ⁻¹' t i) ∩ ⋂ i, if i ∈ s then f i else .univ := by
congr 1
simp only [Set.iInter_ite, Set.iInter_univ, Set.inter_univ]
_ = ⋂ i, Y i ⁻¹' t i ∩ (if i ∈ s then f i else .univ) := by rw [Set.iInter_inter_distrib]
_ = _ := Set.iInter_congr fun i ↦ by by_cases hi : i ∈ s <;> simp [hi, g]
_ = (∏ i, κ a (Y i ⁻¹' t i))⁻¹ * κ a (⋂ i, g i) := by
rw [hYt]
_ = (∏ i, κ a (Y i ⁻¹' t i))⁻¹ * ∏ i, κ a (g i) := by
rw [hg]
_ = ∏ i, (κ a (Y i ⁻¹' t i))⁻¹ * κ a (g i) := by
rw [Finset.prod_mul_distrib, ENNReal.prod_inv_distrib]
exact fun _ _ i _ _ ↦ .inr <| measure_ne_top _ _
_ = ∏ i, if i ∈ s then (κ a)[f i | Y i ⁻¹' t i] else 1 := by
refine Finset.prod_congr rfl fun i _ ↦ ?_
by_cases hi : i ∈ s
· simp only [hi, ↓reduceIte, g, cond_apply (hY i (ht i))]
· simp only [hi, ↓reduceIte, g, ENNReal.inv_mul_cancel (hy i hi) (measure_ne_top _ _)]
_ = _ := by simp
-- TODO: We can't state `Kernel.iIndepFun.cond` (the `Kernel` analogue of
-- `ProbabilityTheory.iIndepFun.cond`) because we don't have a version of `ProbabilityTheory.cond`
-- for kernels
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Independence/Integrable.lean | import Mathlib.MeasureTheory.Function.L1Space.Integrable
import Mathlib.Probability.Independence.Basic
/-!
# Independence of functions implies that the measure is a probability measure
If a nonzero function belongs to `ℒ^p` (in particular if it is integrable) and is independent
of another function, then the space is a probability space.
-/
open Filter ProbabilityTheory
open scoped ENNReal NNReal Topology
namespace MeasureTheory
variable {Ω E F : Type*} [MeasurableSpace Ω] {μ : Measure Ω}
[NormedAddCommGroup E] [MeasurableSpace E] [OpensMeasurableSpace E]
[MeasurableSpace F]
/-- If a nonzero function belongs to `ℒ^p` and is independent of another function, then
the space is a probability space. -/
lemma MemLp.isProbabilityMeasure_of_indepFun
(f : Ω → E) (g : Ω → F) {p : ℝ≥0∞} (hp : p ≠ 0) (hp' : p ≠ ∞)
(hℒp : MemLp f p μ) (h'f : ¬ (∀ᵐ ω ∂μ, f ω = 0)) (hindep : f ⟂ᵢ[μ] g) :
IsProbabilityMeasure μ := by
obtain ⟨c, c_pos, hc⟩ : ∃ (c : ℝ≥0), 0 < c ∧ 0 < μ {ω | c ≤ ‖f ω‖₊} := by
contrapose! h'f
have A (c : ℝ≥0) (hc : 0 < c) : ∀ᵐ ω ∂μ, ‖f ω‖₊ < c := by simpa [ae_iff] using h'f c hc
obtain ⟨u, -, u_pos, u_lim⟩ : ∃ u, StrictAnti u ∧ (∀ (n : ℕ), 0 < u n)
∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ≥0)
filter_upwards [ae_all_iff.2 (fun n ↦ A (u n) (u_pos n))] with ω hω
simpa using ge_of_tendsto' u_lim (fun i ↦ (hω i).le)
have h'c : μ {ω | c ≤ ‖f ω‖₊} < ∞ := hℒp.meas_ge_lt_top hp hp' c_pos.ne'
have := hindep.measure_inter_preimage_eq_mul {x | c ≤ ‖x‖₊} Set.univ
(isClosed_le continuous_const continuous_nnnorm).measurableSet MeasurableSet.univ
simp only [Set.preimage_setOf_eq, Set.preimage_univ, Set.inter_univ] at this
exact ⟨(ENNReal.mul_eq_left hc.ne' h'c.ne).1 this.symm⟩
/-- If a nonzero function is integrable and is independent of another function, then
the space is a probability space. -/
lemma Integrable.isProbabilityMeasure_of_indepFun (f : Ω → E) (g : Ω → F)
(hf : Integrable f μ) (h'f : ¬ (∀ᵐ ω ∂μ, f ω = 0)) (hindep : f ⟂ᵢ[μ] g) :
IsProbabilityMeasure μ :=
MemLp.isProbabilityMeasure_of_indepFun f g one_ne_zero ENNReal.one_ne_top
(memLp_one_iff_integrable.mpr hf) h'f hindep
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Decision/Risk/Basic.lean | import Mathlib.Probability.Decision.Risk.Defs
import Mathlib.Probability.Kernel.Composition.MeasureComp
/-!
# Basic properties of the risk of an estimator
## Main statements
* `iSup_bayesRisk_le_minimaxRisk`: the maximal Bayes risk is less than or equal to the minimax risk.
* `bayesRisk_le_bayesRisk_comp`: data-processing inequality for the Bayes risk with respect to a
prior: if we compose the data generating kernel `P` with a Markov kernel, then the Bayes risk
increases.
* `bayesRisk_le_iInf`: for `P` a Markov kernel, the Bayes risk is less than `⨅ y, ∫⁻ θ, ℓ θ y ∂π`.
In several cases, there is no information in the data about the parameter and the Bayes risk takes
its maximal value.
* `bayesRisk_const`: if the data generating kernel is constant, then the Bayes risk is equal to
`⨅ y, ∫⁻ θ, ℓ θ y ∂π`.
* `bayesRisk_of_subsingleton`: if the observation space is a subsingleton, then the Bayes risk is
equal to `⨅ y, ∫⁻ θ, ℓ θ y ∂π`.
## TODO
In many cases, the maximal Bayes risk and the minimax risk are equal
(by a so-called minimax theorem).
-/
open MeasureTheory Function
open scoped ENNReal NNReal
namespace ProbabilityTheory
variable {Θ 𝓧 𝓧' 𝓨 : Type*} {mΘ : MeasurableSpace Θ}
{m𝓧 : MeasurableSpace 𝓧} {m𝓧' : MeasurableSpace 𝓧'} {m𝓨 : MeasurableSpace 𝓨}
{ℓ : Θ → 𝓨 → ℝ≥0∞} {P : Kernel Θ 𝓧} {κ : Kernel 𝓧 𝓨} {π : Measure Θ}
section BayesRiskLeMinimaxRisk
lemma avgRisk_le_iSup_risk (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (κ : Kernel 𝓧 𝓨)
(π : Measure Θ) [IsProbabilityMeasure π] :
avgRisk ℓ P κ π ≤ ⨆ θ, ∫⁻ y, ℓ θ y ∂((κ ∘ₖ P) θ) := lintegral_le_iSup _
lemma bayesRisk_le_avgRisk (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (κ : Kernel 𝓧 𝓨)
(π : Measure Θ) [hκ : IsMarkovKernel κ] :
bayesRisk ℓ P π ≤ avgRisk ℓ P κ π := iInf₂_le κ hκ
lemma bayesRisk_le_minimaxRisk (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧)
(π : Measure Θ) [IsProbabilityMeasure π] :
bayesRisk ℓ P π ≤ minimaxRisk ℓ P := iInf₂_mono fun _ _ ↦ avgRisk_le_iSup_risk _ _ _ _
/-- The maximal Bayes risk is less than or equal to the minimax risk. -/
lemma iSup_bayesRisk_le_minimaxRisk (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) :
⨆ (π : Measure Θ) (_ : IsProbabilityMeasure π), bayesRisk ℓ P π
≤ minimaxRisk ℓ P := iSup₂_le fun _ _ ↦ bayesRisk_le_minimaxRisk _ _ _
end BayesRiskLeMinimaxRisk
section Const
/-- See `avgRisk_const_left'` for a similar result with integrals swapped. -/
lemma avgRisk_const_left (ℓ : Θ → 𝓨 → ℝ≥0∞) (μ : Measure 𝓧) (κ : Kernel 𝓧 𝓨) (π : Measure Θ) :
avgRisk ℓ (Kernel.const Θ μ) κ π = ∫⁻ θ, ∫⁻ y, ℓ θ y ∂(κ ∘ₘ μ) ∂π := by
simp [avgRisk]
/-- See `avgRisk_const_left` for a similar result with integrals swapped. -/
lemma avgRisk_const_left' (hl : Measurable (uncurry ℓ)) (μ : Measure 𝓧) [SFinite μ]
(κ : Kernel 𝓧 𝓨) [IsSFiniteKernel κ] (π : Measure Θ) [SFinite π] :
avgRisk ℓ (Kernel.const Θ μ) κ π = ∫⁻ y, ∫⁻ θ, ℓ θ y ∂π ∂(κ ∘ₘ μ) := by
rw [avgRisk_const_left, lintegral_lintegral_swap (by fun_prop)]
/-- See `avgRisk_const_right` for a simpler result when `P` is a Markov kernel. -/
lemma avgRisk_const_right' (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (ν : Measure 𝓨) (π : Measure Θ) :
avgRisk ℓ P (Kernel.const 𝓧 ν) π = ∫⁻ θ, P θ .univ * ∫⁻ y, ℓ θ y ∂ν ∂π := by
simp [avgRisk, Kernel.const_comp]
/-- See `avgRisk_const_right'` for a similar result when `P` is not a Markov kernel. -/
lemma avgRisk_const_right (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) [IsMarkovKernel P]
(ν : Measure 𝓨) (π : Measure Θ) :
avgRisk ℓ P (Kernel.const 𝓧 ν) π = ∫⁻ θ, ∫⁻ y, ℓ θ y ∂ν ∂π := by
simp [avgRisk_const_right']
/-- See `bayesRisk_le_iInf` for a simpler result when `P` is a Markov kernel. -/
lemma bayesRisk_le_iInf' (hl : Measurable (uncurry ℓ)) (P : Kernel Θ 𝓧) (π : Measure Θ) :
bayesRisk ℓ P π ≤ ⨅ y, ∫⁻ θ, ℓ θ y * P θ .univ ∂π := by
simp_rw [le_iInf_iff, bayesRisk]
refine fun y ↦ iInf_le_of_le (Kernel.const _ (Measure.dirac y)) ?_
simp only [iInf_pos, avgRisk_const_right', mul_comm]
gcongr with θ
rw [lintegral_dirac' _ (by fun_prop)]
/-- See `bayesRisk_le_iInf'` for a similar result when `P` is not a Markov kernel. -/
lemma bayesRisk_le_iInf (hl : Measurable (uncurry ℓ)) (P : Kernel Θ 𝓧) [IsMarkovKernel P]
(π : Measure Θ) :
bayesRisk ℓ P π ≤ ⨅ y, ∫⁻ θ, ℓ θ y ∂π :=
(bayesRisk_le_iInf' hl P π).trans_eq (by simp)
lemma bayesRisk_const' (hl : Measurable (uncurry ℓ))
(μ : Measure 𝓧) [SFinite μ] (π : Measure Θ) [SFinite π]
(hl_pos : μ .univ = ∞ → ⨅ y, ∫⁻ θ, ℓ θ y ∂π = 0 → ∃ y, ∫⁻ θ, ℓ θ y ∂π = 0)
(h_zero : μ = 0 → Nonempty 𝓨) :
bayesRisk ℓ (Kernel.const Θ μ) π = ⨅ y, ∫⁻ θ, ℓ θ y * μ .univ ∂π := by
refine le_antisymm ((bayesRisk_le_iInf' hl _ _).trans_eq (by simp)) ?_
simp_rw [bayesRisk, le_iInf_iff]
intro κ hκ
rw [avgRisk_const_left' hl]
refine le_trans ?_ (iInf_mul_le_lintegral (fun y ↦ ∫⁻ θ, ℓ θ y ∂π))
rw [Measure.comp_apply_univ, ENNReal.iInf_mul' hl_pos (fun hμ ↦ h_zero (by simpa using hμ))]
gcongr with y
rw [lintegral_mul_const]
fun_prop
lemma bayesRisk_const_of_neZero (hl : Measurable (uncurry ℓ))
(μ : Measure 𝓧) [NeZero μ] [IsFiniteMeasure μ] (π : Measure Θ) [SFinite π] :
bayesRisk ℓ (Kernel.const Θ μ) π = ⨅ y, ∫⁻ θ, ℓ θ y * μ .univ ∂π :=
bayesRisk_const' hl μ π (by simp) (by simp [NeZero.out])
lemma bayesRisk_const_of_nonempty [Nonempty 𝓨] (hl : Measurable (uncurry ℓ))
(μ : Measure 𝓧) [IsFiniteMeasure μ] (π : Measure Θ) [SFinite π] :
bayesRisk ℓ (Kernel.const Θ μ) π = ⨅ y, ∫⁻ θ, ℓ θ y * μ .univ ∂π :=
bayesRisk_const' hl μ π (by simp) (fun _ ↦ inferInstance)
lemma bayesRisk_const (hl : Measurable (uncurry ℓ))
(μ : Measure 𝓧) [IsProbabilityMeasure μ] (π : Measure Θ) [SFinite π] :
bayesRisk ℓ (Kernel.const Θ μ) π = ⨅ y, ∫⁻ θ, ℓ θ y ∂π := by
simp [bayesRisk_const_of_neZero hl μ π]
end Const
section Bounds
/-- See `avgRisk_le_mul` for the usual case in which `π` is a probability measure and the kernels
are Markov. -/
lemma avgRisk_le_mul' (P : Kernel Θ 𝓧) (κ : Kernel 𝓧 𝓨) (π : Measure Θ)
{C : ℝ≥0} (hℓC : ∀ θ y, ℓ θ y ≤ C) :
avgRisk ℓ P κ π ≤ C * κ.bound * P.bound * π Set.univ :=
calc ∫⁻ θ, ∫⁻ y, ℓ θ y ∂(κ ∘ₖ P) θ ∂π
_ ≤ ∫⁻ θ, ∫⁻ y, C ∂(κ ∘ₖ P) θ ∂π := by gcongr with θ y; exact hℓC θ y
_ = ∫⁻ θ, C * ∫⁻ x, κ x .univ ∂P θ ∂π := by simp [Kernel.comp_apply' _ _ _ .univ]
_ ≤ ∫⁻ θ, C * ∫⁻ x, κ.bound ∂P θ ∂π := by
gcongr with θ x
exact Kernel.measure_le_bound κ x Set.univ
_ ≤ ∫⁻ θ, C * κ.bound * P.bound ∂π := by
conv_lhs => simp only [lintegral_const, ← mul_assoc]
gcongr with θ
exact Kernel.measure_le_bound P θ Set.univ
_ = C * κ.bound * P.bound * π Set.univ := by simp
lemma avgRisk_le_mul (P : Kernel Θ 𝓧) [IsMarkovKernel P] (κ : Kernel 𝓧 𝓨) [IsMarkovKernel κ]
(π : Measure Θ) [IsProbabilityMeasure π] {C : ℝ≥0} (hℓC : ∀ θ y, ℓ θ y ≤ C) :
avgRisk ℓ P κ π ≤ C := by
refine (avgRisk_le_mul' P κ π hℓC).trans ?_
rcases isEmpty_or_nonempty Θ
· simp
· rcases isEmpty_or_nonempty 𝓧 <;> simp
/-- For a bounded loss, the Bayes risk with respect to a prior is bounded by a constant.
See `bayesRisk_le_mul` for the usual cases where all measures are probability measures. -/
lemma bayesRisk_le_mul' [h𝓨 : Nonempty 𝓨] (P : Kernel Θ 𝓧) (π : Measure Θ)
{C : ℝ≥0} (hℓC : ∀ θ y, ℓ θ y ≤ C) :
bayesRisk ℓ P π ≤ C * P.bound * π Set.univ := by
refine (bayesRisk_le_avgRisk ℓ P (Kernel.const 𝓧 (Measure.dirac h𝓨.some)) π).trans ?_
refine (avgRisk_le_mul' P (Kernel.const 𝓧 (Measure.dirac h𝓨.some)) π hℓC).trans ?_
rcases isEmpty_or_nonempty 𝓧 <;> simp
/-- For a bounded loss, the Bayes risk with respect to a prior is bounded by a constant. -/
lemma bayesRisk_le_mul [Nonempty 𝓨] (P : Kernel Θ 𝓧) [IsMarkovKernel P]
(π : Measure Θ) [IsProbabilityMeasure π] {C : ℝ≥0} (hℓC : ∀ θ y, ℓ θ y ≤ C) :
bayesRisk ℓ P π ≤ C := by
refine (bayesRisk_le_mul' P π hℓC).trans ?_
rcases isEmpty_or_nonempty Θ <;> simp
/-- For a bounded loss, the Bayes risk with respect to a prior is finite. -/
lemma bayesRisk_lt_top [Nonempty 𝓨] (P : Kernel Θ 𝓧)
[IsFiniteKernel P] (π : Measure Θ) [IsFiniteMeasure π] {C : ℝ≥0} (hℓC : ∀ θ y, ℓ θ y ≤ C) :
bayesRisk ℓ P π < ∞ := by
refine (bayesRisk_le_mul' P π hℓC).trans_lt ?_
simp [ENNReal.mul_lt_top_iff, P.bound_lt_top]
end Bounds
lemma bayesRisk_discard (hl : Measurable (uncurry ℓ)) (π : Measure Θ) [SFinite π] :
bayesRisk ℓ (Kernel.discard Θ) π = ⨅ y, ∫⁻ θ, ℓ θ y ∂π := by
rw [Kernel.discard_eq_const, bayesRisk_const hl]
section Subsingleton
variable [Subsingleton 𝓧] [Nonempty 𝓨]
lemma bayesRisk_eq_iInf_measure_of_subsingleton :
bayesRisk ℓ P π
= ⨅ (μ : Measure 𝓨) (_ : IsProbabilityMeasure μ), avgRisk ℓ P (Kernel.const 𝓧 μ) π := by
rcases isEmpty_or_nonempty 𝓧 with hX | hX
· simp [iInf_subtype']
obtain x := hX.some
rw [bayesRisk, iInf_subtype', iInf_subtype']
let e : {κ : Kernel 𝓧 𝓨 // IsMarkovKernel κ} ≃ {μ : Measure 𝓨 // IsProbabilityMeasure μ} :=
{ toFun κ := ⟨κ.1 x, κ.2.isProbabilityMeasure x⟩
invFun μ := ⟨Kernel.const 𝓧 μ, ⟨fun _ ↦ μ.2⟩⟩
left_inv κ := by ext y; simp only [Kernel.const_apply, Subsingleton.elim x y]
right_inv μ := by simp }
rw [← Equiv.iInf_comp e.symm]
rfl
lemma bayesRisk_of_subsingleton' [SFinite π] (hl : Measurable (uncurry ℓ)) :
bayesRisk ℓ P π = ⨅ y, ∫⁻ θ, ℓ θ y * P θ .univ ∂π := by
refine le_antisymm (bayesRisk_le_iInf' hl _ _) ?_
rw [bayesRisk_eq_iInf_measure_of_subsingleton]
simp only [avgRisk_const_right', le_iInf_iff]
refine fun μ hμ ↦ (iInf_le_lintegral (μ := μ) _).trans_eq ?_
rw [lintegral_lintegral_swap]
· congr with θ
rw [lintegral_mul_const _ (by fun_prop), mul_comm]
· have := P.measurable_coe .univ
fun_prop
lemma bayesRisk_of_subsingleton [IsMarkovKernel P] [SFinite π] (hl : Measurable (uncurry ℓ)) :
bayesRisk ℓ P π = ⨅ y, ∫⁻ θ, ℓ θ y ∂π := by
simp [bayesRisk_of_subsingleton' hl]
end Subsingleton
section Compositions
/-- **Data processing inequality** for the Bayes risk with respect to a prior: composition of the
data generating kernel by a Markov kernel increases the risk. -/
lemma bayesRisk_le_bayesRisk_comp (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧)
(π : Measure Θ) (η : Kernel 𝓧 𝓧') [IsMarkovKernel η] :
bayesRisk ℓ P π ≤ bayesRisk ℓ (η ∘ₖ P) π := by
simp only [bayesRisk, avgRisk, le_iInf_iff]
intro κ hκ
rw [← κ.comp_assoc η]
exact iInf_le_of_le (κ ∘ₖ η) (iInf_le_of_le inferInstance le_rfl)
/-- **Data processing inequality** for the Bayes risk with respect to a prior: taking the map of
the data generating kernel by a function increases the risk. -/
lemma bayesRisk_le_bayesRisk_map (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧)
(π : Measure Θ) {f : 𝓧 → 𝓧'} (hf : Measurable f) :
bayesRisk ℓ P π ≤ bayesRisk ℓ (P.map f) π := by
rw [← Kernel.deterministic_comp_eq_map hf]
exact bayesRisk_le_bayesRisk_comp _ _ _ _
lemma bayesRisk_compProd_le_bayesRisk (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧)
[IsSFiniteKernel P] (π : Measure Θ) (η : Kernel (Θ × 𝓧) 𝓧') [IsMarkovKernel η] :
bayesRisk ℓ (P ⊗ₖ η) π ≤ bayesRisk ℓ P π := by
have : P = (Kernel.deterministic Prod.fst (by fun_prop)) ∘ₖ (P ⊗ₖ η) := by
rw [Kernel.deterministic_comp_eq_map, ← Kernel.fst_eq, Kernel.fst_compProd]
nth_rw 2 [this]
exact bayesRisk_le_bayesRisk_comp _ _ _ _
end Compositions
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Decision/Risk/Defs.lean | import Mathlib.Probability.Kernel.Composition.Comp
/-!
# Risk of an estimator
An estimation problem is defined by a parameter space `Θ`, a data generating kernel `P : Kernel Θ 𝓧`
and a loss function `ℓ : Θ → 𝓨 → ℝ≥0∞`.
A (randomized) estimator is a kernel `κ : Kernel 𝓧 𝓨` that maps data to estimates of a quantity
of interest that depends on the parameter. Often the quantity of interest is the parameter itself
and `𝓨 = Θ`.
The quality of an estimate `y` when data comes from the distribution with parameter `θ` is measured
by the value of the loss function `ℓ θ y` (lower is better).
## Main definitions
The risk is the average loss of the estimator `κ` on data generated by `P` with parameter `θ`,
equal to `∫⁻ y, ℓ θ y ∂((κ ∘ₖ P) θ)`. We do not introduce a definition for that risk, but we refer
to that integral as `risk` in lemma names.
* `avgRisk ℓ P κ π`: the average of the risk of the estimator with respect to
the prior `π : Measure Θ`.
* `bayesRisk ℓ P π`: the Bayes risk with respect to the prior `π`, minimum of the average
risks over all estimators, that is over all Markov kernels `κ : Kernel 𝓧 𝓨`.
* `minimaxRisk ℓ P`: minimax risk, infimum over all estimators of the maximum over `θ` of the risk.
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
variable {Θ 𝓧 𝓨 : Type*} {mΘ : MeasurableSpace Θ} {m𝓧 : MeasurableSpace 𝓧}
/-- The average risk of an estimator `κ` on an estimation task with loss `ℓ` and
data generating kernel `P` with respect to a prior `π`. -/
noncomputable
def avgRisk {m𝓨 : MeasurableSpace 𝓨}
(ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (κ : Kernel 𝓧 𝓨) (π : Measure Θ) : ℝ≥0∞ :=
∫⁻ θ, ∫⁻ y, ℓ θ y ∂((κ ∘ₖ P) θ) ∂π
/-- The Bayes risk with respect to a prior `π`, defined as the infimum of the average risks of all
estimators. -/
noncomputable
def bayesRisk [MeasurableSpace 𝓨] (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (π : Measure Θ) : ℝ≥0∞ :=
⨅ (κ : Kernel 𝓧 𝓨) (_ : IsMarkovKernel κ), avgRisk ℓ P κ π
/-- The minimax risk, defined as the infimum over estimators of the maximal risk of
the estimator. -/
noncomputable
def minimaxRisk [MeasurableSpace 𝓨] (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) : ℝ≥0∞ :=
⨅ (κ : Kernel 𝓧 𝓨) (_ : IsMarkovKernel κ), ⨆ θ, ∫⁻ y, ℓ θ y ∂((κ ∘ₖ P) θ)
variable {m𝓨 : MeasurableSpace 𝓨}
{ℓ : Θ → 𝓨 → ℝ≥0∞} {P : Kernel Θ 𝓧} {κ : Kernel 𝓧 𝓨} {π : Measure Θ}
section Zero
@[simp]
lemma avgRisk_zero_left (ℓ : Θ → 𝓨 → ℝ≥0∞) (κ : Kernel 𝓧 𝓨) (π : Measure Θ) :
avgRisk ℓ (0 : Kernel Θ 𝓧) κ π = 0 := by simp [avgRisk]
@[simp]
lemma avgRisk_zero_right (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (π : Measure Θ) :
avgRisk ℓ P (0 : Kernel 𝓧 𝓨) π = 0 := by simp [avgRisk]
@[simp]
lemma avgRisk_zero_prior (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) (κ : Kernel 𝓧 𝓨) :
avgRisk ℓ P κ 0 = 0 := by simp [avgRisk]
@[simp]
lemma bayesRisk_zero_left [Nonempty 𝓨] (ℓ : Θ → 𝓨 → ℝ≥0∞) (π : Measure Θ) :
bayesRisk ℓ (0 : Kernel Θ 𝓧) π = 0 := by simp [bayesRisk, iInf_subtype']
@[simp]
lemma bayesRisk_zero_right [Nonempty 𝓨] (ℓ : Θ → 𝓨 → ℝ≥0∞) (P : Kernel Θ 𝓧) :
bayesRisk ℓ P (0 : Measure Θ) = 0 := by simp [bayesRisk, iInf_subtype']
@[simp]
lemma minimaxRisk_zero [Nonempty 𝓨] (ℓ : Θ → 𝓨 → ℝ≥0∞) :
minimaxRisk ℓ (0 : Kernel Θ 𝓧) = 0 := by simp [minimaxRisk, iInf_subtype']
end Zero
section Empty
@[simp]
lemma avgRisk_of_isEmpty [IsEmpty 𝓧] : avgRisk ℓ P κ π = 0 := by
simp [Subsingleton.elim P 0]
@[simp]
lemma avgRisk_of_isEmpty' [IsEmpty 𝓨] : avgRisk ℓ P κ π = 0 := by
simp [Subsingleton.elim κ 0]
@[simp]
lemma avgRisk_of_isEmpty'' [IsEmpty Θ] : avgRisk ℓ P κ π = 0 := by
simp [avgRisk]
@[simp]
lemma bayesRisk_of_isEmpty [IsEmpty 𝓧] : bayesRisk ℓ P π = 0 := by
simp [bayesRisk]
@[simp]
lemma bayesRisk_of_isEmpty' [Nonempty 𝓧] [IsEmpty 𝓨] :
bayesRisk ℓ P π = ∞ := by
have : IsEmpty (Subtype (@IsMarkovKernel 𝓧 𝓨 m𝓧 m𝓨)) := by
simp only [isEmpty_subtype]
exact fun κ ↦ Subsingleton.elim κ 0 ▸ Kernel.not_isMarkovKernel_zero
simp [bayesRisk, iInf_subtype']
@[simp]
lemma bayesRisk_of_isEmpty'' [IsEmpty Θ] [Nonempty 𝓨] :
bayesRisk ℓ P π = 0 := by
simp [bayesRisk, iInf_subtype']
@[simp]
lemma minimaxRisk_of_isEmpty [IsEmpty 𝓧] : minimaxRisk ℓ P = 0 := by
simp [minimaxRisk, Subsingleton.elim P 0]
@[simp]
lemma minimaxRisk_of_isEmpty' [Nonempty 𝓧] [IsEmpty 𝓨] : minimaxRisk ℓ P = ∞ := by
have : IsEmpty (Subtype (@IsMarkovKernel 𝓧 𝓨 m𝓧 m𝓨)) := by
simp only [isEmpty_subtype]
exact fun κ ↦ Subsingleton.elim κ 0 ▸ Kernel.not_isMarkovKernel_zero
simp [minimaxRisk, iInf_subtype']
@[simp]
lemma minimaxRisk_of_isEmpty'' [Nonempty 𝓨] [IsEmpty Θ] : minimaxRisk ℓ P = 0 := by
simp [minimaxRisk, iInf_subtype']
end Empty
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/OptionalStopping.lean | import Mathlib.Probability.Process.HittingTime
import Mathlib.Probability.Martingale.Basic
/-! # Optional stopping theorem (fair game theorem)
The optional stopping theorem states that an adapted integrable process `f` is a submartingale if
and only if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the
stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`.
This file also contains Doob's maximal inequality: given a non-negative submartingale `f`, for all
`ε : ℝ≥0`, we have `ε • μ {ε ≤ f* n} ≤ ∫ ω in {ε ≤ f* n}, f n` where `f* n ω = max_{k ≤ n}, f k ω`.
### Main results
* `MeasureTheory.submartingale_iff_expected_stoppedValue_mono`: the optional stopping theorem.
* `MeasureTheory.Submartingale.stoppedProcess`: the stopped process of a submartingale with
respect to a stopping time is a submartingale.
* `MeasureTheory.maximal_ineq`: Doob's maximal inequality.
-/
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory
namespace MeasureTheory
variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {𝒢 : Filtration ℕ m0} {f : ℕ → Ω → ℝ}
{τ π : Ω → ℕ∞}
-- We may generalize the below lemma to functions taking value in a `NormedLatticeAddCommGroup`.
-- Similarly, generalize `(Super/Sub)martingale.setIntegral_le`.
/-- Given a submartingale `f` and bounded stopping times `τ` and `π` such that `τ ≤ π`, the
expectation of `stoppedValue f τ` is less than or equal to the expectation of `stoppedValue f π`.
This is the forward direction of the optional stopping theorem. -/
theorem Submartingale.expected_stoppedValue_mono [SigmaFiniteFiltration μ 𝒢]
(hf : Submartingale f 𝒢 μ) (hτ : IsStoppingTime 𝒢 τ) (hπ : IsStoppingTime 𝒢 π) (hle : τ ≤ π)
{N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : μ[stoppedValue f τ] ≤ μ[stoppedValue f π] := by
rw [← sub_nonneg, ← integral_sub', stoppedValue_sub_eq_sum' hle hbdd]
· simp only [Finset.sum_apply]
have : ∀ i, MeasurableSet[𝒢 i] {ω : Ω | τ ω ≤ i ∧ i < π ω} := by
intro i
refine (hτ i).inter ?_
convert (hπ i).compl using 1
ext x
simp; rfl
rw [integral_finset_sum]
· refine Finset.sum_nonneg fun i _ => ?_
rw [integral_indicator (𝒢.le _ _ (this _)), integral_sub', sub_nonneg]
· exact hf.setIntegral_le (Nat.le_succ i) (this _)
· exact (hf.integrable _).integrableOn
· exact (hf.integrable _).integrableOn
intro i _
exact Integrable.indicator (Integrable.sub (hf.integrable _) (hf.integrable _))
(𝒢.le _ _ (this _))
· exact hf.integrable_stoppedValue hπ hbdd
· exact hf.integrable_stoppedValue hτ fun ω => le_trans (hle ω) (hbdd ω)
/-- The converse direction of the optional stopping theorem, i.e. an adapted integrable process `f`
is a submartingale if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the
stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`. -/
theorem submartingale_of_expected_stoppedValue_mono [IsFiniteMeasure μ] (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ τ π : Ω → ℕ∞, IsStoppingTime 𝒢 τ → IsStoppingTime 𝒢 π →
τ ≤ π → (∃ N : ℕ, ∀ ω, π ω ≤ N) → μ[stoppedValue f τ] ≤ μ[stoppedValue f π]) :
Submartingale f 𝒢 μ := by
refine submartingale_of_setIntegral_le hadp hint fun i j hij s hs => ?_
classical
specialize hf (s.piecewise (fun _ => i) fun _ => j) _ (isStoppingTime_piecewise_const hij hs)
(isStoppingTime_const 𝒢 j) ?_
⟨j, fun _ => le_rfl⟩
· intro ω
simp only [Set.piecewise, ENat.some_eq_coe]
split_ifs with hω
· exact mod_cast hij
· norm_cast
· rwa [stoppedValue_const, ← ENat.some_eq_coe, stoppedValue_piecewise_const,
integral_piecewise (𝒢.le _ _ hs) (hint _).integrableOn (hint _).integrableOn, ←
integral_add_compl (𝒢.le _ _ hs) (hint j), add_le_add_iff_right] at hf
/-- **The optional stopping theorem** (fair game theorem): an adapted integrable process `f`
is a submartingale if and only if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the
stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`. -/
theorem submartingale_iff_expected_stoppedValue_mono [IsFiniteMeasure μ] (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ) :
Submartingale f 𝒢 μ ↔ ∀ τ π : Ω → ℕ∞, IsStoppingTime 𝒢 τ → IsStoppingTime 𝒢 π →
τ ≤ π → (∃ N : ℕ, ∀ x, π x ≤ N) → μ[stoppedValue f τ] ≤ μ[stoppedValue f π] :=
⟨fun hf _ _ hτ hπ hle ⟨_, hN⟩ => hf.expected_stoppedValue_mono hτ hπ hle hN,
submartingale_of_expected_stoppedValue_mono hadp hint⟩
/-- The stopped process of a submartingale with respect to a stopping time is a submartingale. -/
protected theorem Submartingale.stoppedProcess [IsFiniteMeasure μ] (h : Submartingale f 𝒢 μ)
(hτ : IsStoppingTime 𝒢 τ) : Submartingale (stoppedProcess f τ) 𝒢 μ := by
rw [submartingale_iff_expected_stoppedValue_mono]
· intro σ π hσ hπ hσ_le_π hπ_bdd
simp_rw [stoppedValue_stoppedProcess]
obtain ⟨n, hπ_le_n⟩ := hπ_bdd
have hπ_top ω : π ω ≠ ⊤ := ne_top_of_le_ne_top (by simp) (hπ_le_n ω)
have hσ_top ω : σ ω ≠ ⊤ := ne_top_of_le_ne_top (hπ_top ω) (hσ_le_π ω)
simp only [ne_eq, hσ_top, not_false_eq_true, ↓reduceIte, hπ_top, ge_iff_le]
exact h.expected_stoppedValue_mono (hσ.min hτ) (hπ.min hτ)
(fun ω => min_le_min (hσ_le_π ω) le_rfl) fun ω => (min_le_left _ _).trans (hπ_le_n ω)
· exact Adapted.stoppedProcess_of_discrete h.adapted hτ
· exact fun i =>
h.integrable_stoppedValue ((isStoppingTime_const _ i).min hτ) fun ω => min_le_left _ _
section Maximal
open Finset
theorem smul_le_stoppedValue_hittingBtwn [IsFiniteMeasure μ] (hsub : Submartingale f 𝒢 μ) {ε : ℝ≥0}
(n : ℕ) : ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω} ≤
ENNReal.ofReal
(∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω},
stoppedValue f (fun ω ↦ (hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω : ℕ)) ω ∂μ) := by
have hn : Set.Icc 0 n = {k | k ≤ n} := by ext x; simp
have : ∀ ω, ((ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω) →
(ε : ℝ) ≤ stoppedValue f (fun ω ↦ (hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω : ℕ)) ω := by
intro x hx
simp_rw [le_sup'_iff, mem_range, Nat.lt_succ_iff] at hx
refine stoppedValue_hittingBtwn_mem ?_
simp only [Set.mem_setOf_eq, hn]
exact
let ⟨j, hj₁, hj₂⟩ := hx
⟨j, hj₁, hj₂⟩
have h := setIntegral_ge_of_const_le_real (measurableSet_le measurable_const
(Finset.measurable_range_sup'' fun n _ => (hsub.stronglyMeasurable n).measurable.le (𝒢.le n)))
(measure_ne_top _ _) this (Integrable.integrableOn (hsub.integrable_stoppedValue
(hittingBtwn_isStoppingTime hsub.adapted measurableSet_Ici) (mod_cast hittingBtwn_le)))
rw [ENNReal.le_ofReal_iff_toReal_le, ENNReal.toReal_smul]
· exact h
· exact ENNReal.mul_ne_top (by simp) (measure_ne_top _ _)
· exact le_trans (mul_nonneg ε.coe_nonneg ENNReal.toReal_nonneg) h
@[deprecated (since := "2025-10-25")] alias smul_le_stoppedValue_hitting :=
smul_le_stoppedValue_hittingBtwn
/-- **Doob's maximal inequality**: Given a non-negative submartingale `f`, for all `ε : ℝ≥0`,
we have `ε • μ {ε ≤ f* n} ≤ ∫ ω in {ε ≤ f* n}, f n` where `f* n ω = max_{k ≤ n}, f k ω`.
In some literature, the Doob's maximal inequality refers to what we call Doob's Lp inequality
(which is a corollary of this lemma and will be proved in an upcoming PR). -/
theorem maximal_ineq [IsFiniteMeasure μ] (hsub : Submartingale f 𝒢 μ) (hnonneg : 0 ≤ f) {ε : ℝ≥0}
(n : ℕ) : ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω} ≤
ENNReal.ofReal
(∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω},
f n ω ∂μ) := by
suffices ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω} +
ENNReal.ofReal
(∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_add_one fun k => f k ω) < ε},
f n ω ∂μ) ≤
ENNReal.ofReal (μ[f n]) by
have hadd : ENNReal.ofReal (∫ ω, f n ω ∂μ) =
ENNReal.ofReal
(∫ ω in {ω | ↑ε ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω}, f n ω ∂μ) +
ENNReal.ofReal
(∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_add_one fun k => f k ω) < ↑ε},
f n ω ∂μ) := by
rw [← ENNReal.ofReal_add, ← setIntegral_union]
· rw [← setIntegral_univ]
convert rfl
ext ω
change (ε : ℝ) ≤ _ ∨ _ < (ε : ℝ) ↔ _
simp only [le_or_gt, Set.mem_univ]
· rw [disjoint_iff_inf_le]
rintro ω ⟨hω₁, hω₂⟩
change (ε : ℝ) ≤ _ at hω₁
change _ < (ε : ℝ) at hω₂
exact (not_le.2 hω₂) hω₁
· exact measurableSet_lt (Finset.measurable_range_sup'' fun n _ =>
(hsub.stronglyMeasurable n).measurable.le (𝒢.le n)) measurable_const
exacts [(hsub.integrable _).integrableOn, (hsub.integrable _).integrableOn,
integral_nonneg (hnonneg _), integral_nonneg (hnonneg _)]
rwa [hadd, ENNReal.add_le_add_iff_right ENNReal.ofReal_ne_top] at this
calc
ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω} +
ENNReal.ofReal
(∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_add_one fun k => f k ω) < ε},
f n ω ∂μ) ≤
ENNReal.ofReal
(∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_add_one fun k => f k ω},
stoppedValue f (fun ω ↦ (hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω : ℕ)) ω ∂μ) +
ENNReal.ofReal
(∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_add_one fun k => f k ω) < ε},
stoppedValue f (fun ω ↦ (hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω : ℕ)) ω ∂μ) := by
gcongr with ω hω
· exact smul_le_stoppedValue_hittingBtwn hsub n
· exact (hsub.integrable n).integrableOn
· refine Integrable.integrableOn ?_
refine hsub.integrable_stoppedValue ?_ (fun ω ↦ mod_cast hittingBtwn_le ω)
exact hittingBtwn_isStoppingTime hsub.adapted measurableSet_Ici
· exact nullMeasurableSet_lt (Finset.measurable_range_sup'' fun n _ ↦
(hsub.stronglyMeasurable n).measurable.le (𝒢.le n)).aemeasurable aemeasurable_const
rw [Set.mem_setOf_eq] at hω
have : hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω = n := by
classical simp only [hittingBtwn, Set.mem_setOf_eq,
ite_eq_right_iff, forall_exists_index, and_imp]
intro m hm hεm
exact False.elim
((not_le.2 hω) ((le_sup'_iff _).2 ⟨m, mem_range.2 (Nat.lt_succ_of_le hm.2), hεm⟩))
simp only [stoppedValue, this, ge_iff_le]
refine le_of_eq ?_
congr
_ = ENNReal.ofReal
(∫ ω, stoppedValue f (fun ω ↦ (hittingBtwn f {y : ℝ | ↑ε ≤ y} 0 n ω : ℕ)) ω ∂μ) := by
rw [← ENNReal.ofReal_add, ← setIntegral_union]
· rw [← setIntegral_univ (μ := μ)]
convert rfl
ext ω
change _ ↔ (ε : ℝ) ≤ _ ∨ _ < (ε : ℝ)
simp only [le_or_gt, Set.mem_univ]
· rw [disjoint_iff_inf_le]
rintro ω ⟨hω₁, hω₂⟩
change (ε : ℝ) ≤ _ at hω₁
change _ < (ε : ℝ) at hω₂
exact (not_le.2 hω₂) hω₁
· exact measurableSet_lt (Finset.measurable_range_sup'' fun n _ =>
(hsub.stronglyMeasurable n).measurable.le (𝒢.le n)) measurable_const
· exact Integrable.integrableOn (hsub.integrable_stoppedValue
(hittingBtwn_isStoppingTime hsub.adapted measurableSet_Ici)
(fun ω ↦ mod_cast hittingBtwn_le ω))
· exact Integrable.integrableOn (hsub.integrable_stoppedValue
(hittingBtwn_isStoppingTime hsub.adapted measurableSet_Ici)
(fun ω ↦ mod_cast hittingBtwn_le ω))
exacts [integral_nonneg fun x => hnonneg _ _, integral_nonneg fun x => hnonneg _ _]
_ ≤ ENNReal.ofReal (μ[f n]) := by
refine ENNReal.ofReal_le_ofReal ?_
rw [← stoppedValue_const f n]
refine hsub.expected_stoppedValue_mono
(hittingBtwn_isStoppingTime hsub.adapted measurableSet_Ici)
(isStoppingTime_const _ _) (fun ω ↦ ?_) (fun _ => mod_cast le_rfl)
simp [hittingBtwn_le]
end Maximal
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/BorelCantelli.lean | import Mathlib.Algebra.Order.Archimedean.IndicatorCard
import Mathlib.Probability.Martingale.Centering
import Mathlib.Probability.Martingale.Convergence
import Mathlib.Probability.Martingale.OptionalStopping
/-!
# Generalized Borel-Cantelli lemma
This file proves Lévy's generalized Borel-Cantelli lemma which is a generalization of the
Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas
by choosing appropriate filtrations. This file also contains the one sided martingale bound which
is required to prove the generalized Borel-Cantelli.
**Note**: the usual Borel-Cantelli lemmas are not in this file.
See `MeasureTheory.measure_limsup_atTop_eq_zero` for the first (which does not depend on
the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does).
## Main results
- `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given
a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost
everywhere equal to the set for which it is bounded.
- `MeasureTheory.ae_mem_limsup_atTop_iff`: Lévy's generalized Borel-Cantelli:
given a filtration `ℱ` and a sequence of sets `s` such that `s n ∈ ℱ n` for all `n`,
`limsup atTop s` is almost everywhere equal to the set for which `∑ ℙ[s (n + 1)∣ℱ n] = ∞`.
-/
open Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology
namespace MeasureTheory
variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ}
/-!
### One sided martingale bound
-/
/-- `leastGE f r` is the stopping time corresponding to the first time `f ≥ r`. -/
noncomputable def leastGE (f : ℕ → Ω → ℝ) (r : ℝ) : Ω → ℕ∞ :=
hittingAfter f (Set.Ici r) 0
theorem Adapted.isStoppingTime_leastGE (r : ℝ) (hf : Adapted ℱ f) :
IsStoppingTime ℱ (leastGE f r) :=
hittingAfter_isStoppingTime hf measurableSet_Ici
/-- The stopped process of `f` above `r` is the process that is equal to `f` until `leastGE f r`
(the first time `f` passes above `r`), and then is constant afterwards. -/
noncomputable def stoppedAbove (f : ℕ → Ω → ℝ) (r : ℝ) : ℕ → Ω → ℝ :=
stoppedProcess f (leastGE f r)
protected lemma Submartingale.stoppedAbove [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (r : ℝ) :
Submartingale (stoppedAbove f r) ℱ μ :=
hf.stoppedProcess (hf.adapted.isStoppingTime_leastGE r)
@[deprecated (since := "2025-10-25")] alias Submartingale.stoppedValue_leastGE :=
Submartingale.stoppedAbove
variable {r : ℝ} {R : ℝ≥0}
theorem stoppedAbove_le (hr : 0 ≤ r) (hf0 : f 0 = 0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) :
∀ᵐ ω ∂μ, stoppedAbove f r i ω ≤ r + R := by
filter_upwards [hbdd] with ω hbddω
rw [stoppedAbove, stoppedProcess, ENat.some_eq_coe]
by_cases h_zero : (min (i : ℕ∞) (leastGE f r ω)).untopA = 0
· simp only [h_zero, hf0, Pi.zero_apply]
positivity
obtain ⟨k, hk⟩ := Nat.exists_eq_add_one_of_ne_zero h_zero
rw [hk, add_comm r, ← sub_le_iff_le_add]
have := notMem_of_lt_hittingAfter (?_ : k < leastGE f r ω)
· simp only [zero_le, Set.mem_Ici, not_le, forall_const] at this
exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddω _))
· suffices (k : ℕ∞) < min (i : ℕ∞) (leastGE f r ω) from this.trans_le (min_le_right _ _)
have h_top : min (i : ℕ∞) (leastGE f r ω) ≠ ⊤ :=
ne_top_of_le_ne_top (by simp) (min_le_left _ _)
lift min (i : ℕ∞) (leastGE f r ω) to ℕ using h_top with p
simp only [untopD_coe_enat, Nat.cast_lt, gt_iff_lt] at *
omega
@[deprecated (since := "2025-10-25")] alias norm_stoppedValue_leastGE_le := stoppedAbove_le
theorem Submartingale.eLpNorm_stoppedAbove_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) :
eLpNorm (stoppedAbove f r i) 1 μ ≤ 2 * μ Set.univ * ENNReal.ofReal (r + R) := by
refine eLpNorm_one_le_of_le' ((hf.stoppedAbove r).integrable _) ?_
(stoppedAbove_le hr hf0 hbdd i)
rw [← setIntegral_univ]
refine le_trans ?_ ((hf.stoppedAbove r).setIntegral_le (zero_le _) MeasurableSet.univ)
simp [stoppedAbove, stoppedProcess, hf0]
@[deprecated (since := "2025-10-25")] alias Submartingale.stoppedValue_leastGE_eLpNorm_le :=
Submartingale.eLpNorm_stoppedAbove_le
theorem Submartingale.eLpNorm_stoppedAbove_le' [IsFiniteMeasure μ]
(hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) :
eLpNorm (stoppedAbove f r i) 1 μ
≤ ENNReal.toNNReal (2 * μ Set.univ * ENNReal.ofReal (r + R)) := by
refine (hf.eLpNorm_stoppedAbove_le hr hf0 hbdd i).trans ?_
simp [ENNReal.coe_toNNReal (measure_ne_top μ _), ENNReal.coe_toNNReal]
@[deprecated (since := "2025-10-25")] alias Submartingale.stoppedValue_leastGE_eLpNorm_le' :=
Submartingale.eLpNorm_stoppedAbove_le'
/-- This lemma is superseded by `Submartingale.bddAbove_iff_exists_tendsto`. -/
theorem Submartingale.exists_tendsto_of_abs_bddAbove_aux [IsFiniteMeasure μ]
(hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) → ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
have ht : ∀ᵐ ω ∂μ, ∀ i : ℕ, ∃ c, Tendsto (fun n => stoppedAbove f i n ω) atTop (𝓝 c) := by
rw [ae_all_iff]
exact fun i ↦ Submartingale.exists_ae_tendsto_of_bdd (hf.stoppedAbove i)
(hf.eLpNorm_stoppedAbove_le' i.cast_nonneg hf0 hbdd)
filter_upwards [ht] with ω hω hωb
rw [BddAbove] at hωb
obtain ⟨i, hi⟩ := exists_nat_gt hωb.some
have hib : ∀ n, f n ω < i := by
intro n
exact lt_of_le_of_lt ((mem_upperBounds.1 hωb.some_mem) _ ⟨n, rfl⟩) hi
have heq : ∀ n, stoppedAbove f i n ω = f n ω := by
intro n
rw [stoppedAbove, stoppedProcess, leastGE, hittingAfter_eq_top_iff.mpr]
· simp only [le_top, inf_of_le_left]
congr
· simp [hib]
simp only [← heq, hω i]
theorem Submartingale.bddAbove_iff_exists_tendsto_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
filter_upwards [hf.exists_tendsto_of_abs_bddAbove_aux hf0 hbdd] with ω hω using
⟨hω, fun ⟨c, hc⟩ => hc.bddAbove_range⟩
/-- One sided martingale bound: If `f` is a submartingale which has uniformly bounded differences,
then for almost every `ω`, `f n ω` is bounded above (in `n`) if and only if it converges. -/
theorem Submartingale.bddAbove_iff_exists_tendsto [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
set g : ℕ → Ω → ℝ := fun n ω => f n ω - f 0 ω
have hg : Submartingale g ℱ μ :=
hf.sub_martingale (martingale_const_fun _ _ (hf.adapted 0) (hf.integrable 0))
have hg0 : g 0 = 0 := by
ext ω
simp only [g, sub_self, Pi.zero_apply]
have hgbdd : ∀ᵐ ω ∂μ, ∀ i : ℕ, |g (i + 1) ω - g i ω| ≤ ↑R := by
simpa only [g, sub_sub_sub_cancel_right]
filter_upwards [hg.bddAbove_iff_exists_tendsto_aux hg0 hgbdd] with ω hω
convert hω using 1
· refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨b, hb⟩ := h <;>
refine ⟨b + |f 0 ω|, fun y hy => ?_⟩ <;> obtain ⟨n, rfl⟩ := hy
· simp_rw [g, sub_eq_add_neg]
exact add_le_add (hb ⟨n, rfl⟩) (neg_le_abs _)
· exact sub_le_iff_le_add.1 (le_trans (sub_le_sub_left (le_abs_self _) _) (hb ⟨n, rfl⟩))
· refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨c, hc⟩ := h
· exact ⟨c - f 0 ω, hc.sub_const _⟩
· refine ⟨c + f 0 ω, ?_⟩
have := hc.add_const (f 0 ω)
simpa only [g, sub_add_cancel]
/-!
### Lévy's generalization of the Borel-Cantelli lemma
Lévy's generalization of the Borel-Cantelli lemma states that: given a natural number indexed
filtration $(\mathcal{F}_n)$, and a sequence of sets $(s_n)$ such that for all
$n$, $s_n \in \mathcal{F}_n$, $limsup_n s_n$ is almost everywhere equal to the set for which
$\sum_n \mathbb{P}[s_n \mid \mathcal{F}_n] = \infty$.
The proof strategy follows by constructing a martingale satisfying the one sided martingale bound.
In particular, we define
$$
f_n := \sum_{k < n} \mathbf{1}_{s_{n + 1}} - \mathbb{P}[s_{n + 1} \mid \mathcal{F}_n].
$$
Then, as a martingale is both a sub and a super-martingale, the set for which it is unbounded from
above must agree with the set for which it is unbounded from below almost everywhere. Thus, it
can only converge to $\pm \infty$ with probability 0. Thus, by considering
$$
\limsup_n s_n = \{\sum_n \mathbf{1}_{s_n} = \infty\}
$$
almost everywhere, the result follows.
-/
theorem Martingale.bddAbove_range_iff_bddBelow_range [IsFiniteMeasure μ] (hf : Martingale f ℱ μ)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ BddBelow (Set.range fun n => f n ω) := by
have hbdd' : ∀ᵐ ω ∂μ, ∀ i, |(-f) (i + 1) ω - (-f) i ω| ≤ R := by
filter_upwards [hbdd] with ω hω i
erw [← abs_neg, neg_sub, sub_neg_eq_add, neg_add_eq_sub]
exact hω i
have hup := hf.submartingale.bddAbove_iff_exists_tendsto hbdd
have hdown := hf.neg.submartingale.bddAbove_iff_exists_tendsto hbdd'
filter_upwards [hup, hdown] with ω hω₁ hω₂
have : (∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c)) ↔
∃ c, Tendsto (fun n => (-f) n ω) atTop (𝓝 c) := by
constructor <;> rintro ⟨c, hc⟩
· exact ⟨-c, hc.neg⟩
· refine ⟨-c, ?_⟩
convert hc.neg
simp only [neg_neg, Pi.neg_apply]
rw [hω₁, this, ← hω₂]
constructor <;> rintro ⟨c, hc⟩ <;> refine ⟨-c, fun ω hω => ?_⟩
· rw [mem_upperBounds] at hc
refine neg_le.2 (hc _ ?_)
simpa only [Pi.neg_apply, Set.mem_range, neg_inj]
· rw [mem_lowerBounds] at hc
simp_rw [Set.mem_range, Pi.neg_apply, neg_eq_iff_eq_neg] at hω
refine le_neg.1 (hc _ ?_)
simpa only [Set.mem_range]
theorem Martingale.ae_not_tendsto_atTop_atTop [IsFiniteMeasure μ] (hf : Martingale f ℱ μ)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atTop := by
filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using
not_bddAbove_of_tendsto_atTop htop (hω.2 <| bddBelow_range_of_tendsto_atTop_atTop htop)
theorem Martingale.ae_not_tendsto_atTop_atBot [IsFiniteMeasure μ] (hf : Martingale f ℱ μ)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atBot := by
filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using
not_bddBelow_of_tendsto_atBot htop (hω.1 <| bddAbove_range_of_tendsto_atTop_atBot htop)
namespace BorelCantelli
/-- Auxiliary definition required to prove Lévy's generalization of the Borel-Cantelli lemmas for
which we will take the martingale part. -/
noncomputable def process (s : ℕ → Set Ω) (n : ℕ) : Ω → ℝ :=
∑ k ∈ Finset.range n, (s (k + 1)).indicator 1
variable {s : ℕ → Set Ω}
theorem process_zero : process s 0 = 0 := by rw [process, Finset.range_zero, Finset.sum_empty]
theorem adapted_process (hs : ∀ n, MeasurableSet[ℱ n] (s n)) : Adapted ℱ (process s) := fun _ =>
Finset.stronglyMeasurable_sum _ fun _ hk =>
stronglyMeasurable_one.indicator <| ℱ.mono (Finset.mem_range.1 hk) _ <| hs _
theorem martingalePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) :
martingalePart (process s) ℱ μ n =
∑ k ∈ Finset.range n, ((s (k + 1)).indicator 1 - μ[(s (k + 1)).indicator 1|ℱ k]) := by
simp only [martingalePart_eq_sum, process_zero, zero_add]
refine Finset.sum_congr rfl fun k _ => ?_
simp only [process, Finset.sum_range_succ_sub_sum]
theorem predictablePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω)
(n : ℕ) : predictablePart (process s) ℱ μ n =
∑ k ∈ Finset.range n, μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k] := by
have := martingalePart_process_ae_eq ℱ μ s n
simp_rw [martingalePart, process, Finset.sum_sub_distrib] at this
exact sub_right_injective this
theorem process_difference_le (s : ℕ → Set Ω) (ω : Ω) (n : ℕ) :
|process s (n + 1) ω - process s n ω| ≤ (1 : ℝ≥0) := by
norm_cast
rw [process, process, Finset.sum_apply, Finset.sum_apply,
Finset.sum_range_succ_sub_sum, ← Real.norm_eq_abs, norm_indicator_eq_indicator_norm]
refine Set.indicator_le' (fun _ _ => ?_) (fun _ _ => zero_le_one) _
rw [Pi.one_apply, norm_one]
theorem integrable_process (μ : Measure Ω) [IsFiniteMeasure μ] (hs : ∀ n, MeasurableSet[ℱ n] (s n))
(n : ℕ) : Integrable (process s n) μ :=
integrable_finset_sum' _ fun _ _ =>
IntegrableOn.integrable_indicator (integrable_const 1) <| ℱ.le _ _ <| hs _
end BorelCantelli
open BorelCantelli
/-- An a.e. monotone adapted process `f` with uniformly bounded differences converges to `+∞` if
and only if its predictable part also converges to `+∞`. -/
theorem tendsto_sum_indicator_atTop_iff [IsFiniteMeasure μ]
(hfmono : ∀ᵐ ω ∂μ, ∀ n, f n ω ≤ f (n + 1) ω) (hf : Adapted ℱ f) (hint : ∀ n, Integrable (f n) μ)
(hbdd : ∀ᵐ ω ∂μ, ∀ n, |f (n + 1) ω - f n ω| ≤ R) :
∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop atTop ↔
Tendsto (fun n => predictablePart f ℱ μ n ω) atTop atTop := by
have h₁ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atTop
(martingalePart_bdd_difference ℱ hbdd)
have h₂ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atBot
(martingalePart_bdd_difference ℱ hbdd)
have h₃ : ∀ᵐ ω ∂μ, ∀ n, 0 ≤ (μ[f (n + 1) - f n|ℱ n]) ω := by
refine ae_all_iff.2 fun n => condExp_nonneg ?_
filter_upwards [ae_all_iff.1 hfmono n] with ω hω using sub_nonneg.2 hω
filter_upwards [h₁, h₂, h₃, hfmono] with ω hω₁ hω₂ hω₃ hω₄
constructor <;> intro ht
· refine tendsto_atTop_atTop_of_monotone' ?_ ?_
· intro n m hnm
simp only [predictablePart, Finset.sum_apply]
exact Finset.sum_mono_set_of_nonneg hω₃ (Finset.range_mono hnm)
rintro ⟨b, hbdd⟩
rw [← tendsto_neg_atBot_iff] at ht
simp only [martingalePart, sub_eq_add_neg] at hω₁
exact hω₁ (tendsto_atTop_add_right_of_le _ (-b) (tendsto_neg_atBot_iff.1 ht) fun n =>
neg_le_neg (hbdd ⟨n, rfl⟩))
· refine tendsto_atTop_atTop_of_monotone' (monotone_nat_of_le_succ hω₄) ?_
rintro ⟨b, hbdd⟩
exact hω₂ ((tendsto_atBot_add_left_of_ge _ b fun n =>
hbdd ⟨n, rfl⟩) <| tendsto_neg_atBot_iff.2 ht)
open BorelCantelli
theorem tendsto_sum_indicator_atTop_iff' [IsFiniteMeasure μ] {s : ℕ → Set Ω}
(hs : ∀ n, MeasurableSet[ℱ n] (s n)) : ∀ᵐ ω ∂μ,
Tendsto (fun n => ∑ k ∈ Finset.range n,
(s (k + 1)).indicator (1 : Ω → ℝ) ω) atTop atTop ↔
Tendsto (fun n => ∑ k ∈ Finset.range n,
(μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := by
have := tendsto_sum_indicator_atTop_iff (Eventually.of_forall fun ω n => ?_) (adapted_process hs)
(integrable_process μ hs) (Eventually.of_forall <| process_difference_le s)
swap
· rw [process, process, ← sub_nonneg, Finset.sum_apply, Finset.sum_apply,
Finset.sum_range_succ_sub_sum]
exact Set.indicator_nonneg (fun _ _ => zero_le_one) _
simp_rw [process, predictablePart_process_ae_eq] at this
simpa using this
/-- **Lévy's generalization of the Borel-Cantelli lemma**: given a sequence of sets `s` and a
filtration `ℱ` such that for all `n`, `s n` is `ℱ n`-measurable, `limsup s atTop` is almost
everywhere equal to the set for which `∑ k, ℙ(s (k + 1) | ℱ k) = ∞`. -/
theorem ae_mem_limsup_atTop_iff (μ : Measure Ω) [IsFiniteMeasure μ] {s : ℕ → Set Ω}
(hs : ∀ n, MeasurableSet[ℱ n] (s n)) : ∀ᵐ ω ∂μ, ω ∈ limsup s atTop ↔
Tendsto (fun n => ∑ k ∈ Finset.range n,
(μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := by
rw [← limsup_nat_add s 1,
Set.limsup_eq_tendsto_sum_indicator_atTop (zero_lt_one (α := ℝ)) (fun n ↦ s (n + 1))]
exact tendsto_sum_indicator_atTop_iff' hs
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/Basic.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.Process.Stopping
import Mathlib.Probability.Process.Predictable
/-!
# Martingales
A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if every
`f i` is integrable, `f` is adapted with respect to `ℱ` and for all `i ≤ j`,
`μ[f j | ℱ i] =ᵐ[μ] f i`. On the other hand, `f : ι → Ω → E` is said to be a supermartingale
with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with respect to `ℱ`
and for all `i ≤ j`, `μ[f j | ℱ i] ≤ᵐ[μ] f i`. Finally, `f : ι → Ω → E` is said to be a
submartingale with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with
respect to `ℱ` and for all `i ≤ j`, `f i ≤ᵐ[μ] μ[f j | ℱ i]`.
The definitions of filtration and adapted can be found in `Probability.Process.Stopping`.
### Definitions
* `MeasureTheory.Martingale f ℱ μ`: `f` is a martingale with respect to filtration `ℱ` and
measure `μ`.
* `MeasureTheory.Supermartingale f ℱ μ`: `f` is a supermartingale with respect to
filtration `ℱ` and measure `μ`.
* `MeasureTheory.Submartingale f ℱ μ`: `f` is a submartingale with respect to filtration `ℱ` and
measure `μ`.
### Results
* `MeasureTheory.martingale_condExp f ℱ μ`: the sequence `fun i => μ[f | ℱ i, ℱ.le i])` is a
martingale with respect to `ℱ` and `μ`.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory
namespace MeasureTheory
variable {Ω E ι : Type*} [Preorder ι] {m0 : MeasurableSpace Ω} {μ : Measure Ω}
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f g : ι → Ω → E} {ℱ : Filtration ι m0}
/-- A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if `f`
is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] =ᵐ[μ] f i`. -/
def Martingale (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop :=
Adapted ℱ f ∧ ∀ i j, i ≤ j → μ[f j|ℱ i] =ᵐ[μ] f i
/-- A family of integrable functions `f : ι → Ω → E` is a supermartingale with respect to a
filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`,
`μ[f j | ℱ.le i] ≤ᵐ[μ] f i`. -/
def Supermartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop :=
Adapted ℱ f ∧ (∀ i j, i ≤ j → μ[f j|ℱ i] ≤ᵐ[μ] f i) ∧ ∀ i, Integrable (f i) μ
/-- A family of integrable functions `f : ι → Ω → E` is a submartingale with respect to a
filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`,
`f i ≤ᵐ[μ] μ[f j | ℱ.le i]`. -/
def Submartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop :=
Adapted ℱ f ∧ (∀ i j, i ≤ j → f i ≤ᵐ[μ] μ[f j|ℱ i]) ∧ ∀ i, Integrable (f i) μ
theorem martingale_const (ℱ : Filtration ι m0) (μ : Measure Ω) [IsFiniteMeasure μ] (x : E) :
Martingale (fun _ _ => x) ℱ μ :=
⟨adapted_const ℱ _, fun i j _ => by rw [condExp_const (ℱ.le _)]⟩
theorem martingale_const_fun [OrderBot ι] (ℱ : Filtration ι m0) (μ : Measure Ω)
[SigmaFiniteFiltration μ ℱ]
{f : Ω → E} (hf : StronglyMeasurable[ℱ ⊥] f) (hfint : Integrable f μ) :
Martingale (fun _ => f) ℱ μ := by
refine ⟨fun i => hf.mono <| ℱ.mono bot_le, fun i j _ => ?_⟩
rw [condExp_of_stronglyMeasurable (ℱ.le _) (hf.mono <| ℱ.mono bot_le) hfint]
variable (E) in
theorem martingale_zero (ℱ : Filtration ι m0) (μ : Measure Ω) : Martingale (0 : ι → Ω → E) ℱ μ :=
⟨adapted_zero E ℱ, fun i j _ => by simp⟩
namespace Martingale
protected theorem adapted (hf : Martingale f ℱ μ) : Adapted ℱ f :=
hf.1
protected theorem stronglyMeasurable (hf : Martingale f ℱ μ) (i : ι) :
StronglyMeasurable[ℱ i] (f i) :=
hf.adapted i
theorem condExp_ae_eq (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j) : μ[f j|ℱ i] =ᵐ[μ] f i :=
hf.2 i j hij
protected theorem integrable (hf : Martingale f ℱ μ) (i : ι) : Integrable (f i) μ :=
integrable_condExp.congr (hf.condExp_ae_eq (le_refl i))
theorem setIntegral_eq [SigmaFiniteFiltration μ ℱ] (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j)
{s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f i ω ∂μ = ∫ ω in s, f j ω ∂μ := by
rw [← setIntegral_condExp (ℱ.le i) (hf.integrable j) hs]
refine setIntegral_congr_ae (ℱ.le i s hs) ?_
filter_upwards [hf.2 i j hij] with _ heq _ using heq.symm
theorem add (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f + g) ℱ μ := by
refine ⟨hf.adapted.add hg.adapted, fun i j hij => ?_⟩
exact (condExp_add (hf.integrable j) (hg.integrable j) _).trans
((hf.2 i j hij).add (hg.2 i j hij))
theorem neg (hf : Martingale f ℱ μ) : Martingale (-f) ℱ μ :=
⟨hf.adapted.neg, fun i j hij => (condExp_neg ..).trans (hf.2 i j hij).neg⟩
theorem sub (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f - g) ℱ μ := by
rw [sub_eq_add_neg]; exact hf.add hg.neg
theorem smul (c : ℝ) (hf : Martingale f ℱ μ) : Martingale (c • f) ℱ μ := by
refine ⟨hf.adapted.smul c, fun i j hij => ?_⟩
refine (condExp_smul ..).trans ((hf.2 i j hij).mono fun x hx => ?_)
simp only [Pi.smul_apply, hx]
theorem supermartingale [Preorder E] (hf : Martingale f ℱ μ) : Supermartingale f ℱ μ :=
⟨hf.1, fun i j hij => (hf.2 i j hij).le, fun i => hf.integrable i⟩
theorem submartingale [Preorder E] (hf : Martingale f ℱ μ) : Submartingale f ℱ μ :=
⟨hf.1, fun i j hij => (hf.2 i j hij).symm.le, fun i => hf.integrable i⟩
end Martingale
theorem martingale_iff [PartialOrder E] :
Martingale f ℱ μ ↔ Supermartingale f ℱ μ ∧ Submartingale f ℱ μ :=
⟨fun hf => ⟨hf.supermartingale, hf.submartingale⟩, fun ⟨hf₁, hf₂⟩ =>
⟨hf₁.1, fun i j hij => (hf₁.2.1 i j hij).antisymm (hf₂.2.1 i j hij)⟩⟩
theorem martingale_condExp (f : Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω)
[SigmaFiniteFiltration μ ℱ] : Martingale (fun i => μ[f|ℱ i]) ℱ μ :=
⟨fun _ => stronglyMeasurable_condExp, fun _ j hij => condExp_condExp_of_le (ℱ.mono hij) (ℱ.le j)⟩
namespace Supermartingale
protected theorem adapted [LE E] (hf : Supermartingale f ℱ μ) : Adapted ℱ f :=
hf.1
protected theorem stronglyMeasurable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) :
StronglyMeasurable[ℱ i] (f i) :=
hf.adapted i
protected theorem integrable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) : Integrable (f i) μ :=
hf.2.2 i
theorem condExp_ae_le [LE E] (hf : Supermartingale f ℱ μ) {i j : ι} (hij : i ≤ j) :
μ[f j|ℱ i] ≤ᵐ[μ] f i :=
hf.2.1 i j hij
theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Supermartingale f ℱ μ)
{i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) :
∫ ω in s, f j ω ∂μ ≤ ∫ ω in s, f i ω ∂μ := by
rw [← setIntegral_condExp (ℱ.le i) (hf.integrable j) hs]
refine setIntegral_mono_ae integrable_condExp.integrableOn (hf.integrable i).integrableOn ?_
filter_upwards [hf.2.1 i j hij] with _ heq using heq
theorem add [Preorder E] [AddLeftMono E] (hf : Supermartingale f ℱ μ)
(hg : Supermartingale g ℱ μ) : Supermartingale (f + g) ℱ μ := by
refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩
refine (condExp_add (hf.integrable j) (hg.integrable j) _).le.trans ?_
filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij]
intros
refine add_le_add ?_ ?_ <;> assumption
theorem add_martingale [Preorder E] [AddLeftMono E]
(hf : Supermartingale f ℱ μ) (hg : Martingale g ℱ μ) : Supermartingale (f + g) ℱ μ :=
hf.add hg.supermartingale
theorem neg [Preorder E] [AddLeftMono E] (hf : Supermartingale f ℱ μ) :
Submartingale (-f) ℱ μ := by
refine ⟨hf.1.neg, fun i j hij => ?_, fun i => (hf.2.2 i).neg⟩
refine EventuallyLE.trans ?_ (condExp_neg ..).symm.le
filter_upwards [hf.2.1 i j hij] with _ _
simpa
end Supermartingale
namespace Submartingale
protected theorem adapted [LE E] (hf : Submartingale f ℱ μ) : Adapted ℱ f :=
hf.1
protected theorem stronglyMeasurable [LE E] (hf : Submartingale f ℱ μ) (i : ι) :
StronglyMeasurable[ℱ i] (f i) :=
hf.adapted i
protected theorem integrable [LE E] (hf : Submartingale f ℱ μ) (i : ι) : Integrable (f i) μ :=
hf.2.2 i
theorem ae_le_condExp [LE E] (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) :
f i ≤ᵐ[μ] μ[f j|ℱ i] :=
hf.2.1 i j hij
theorem add [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ)
(hg : Submartingale g ℱ μ) : Submartingale (f + g) ℱ μ := by
refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩
refine EventuallyLE.trans ?_ (condExp_add (hf.integrable j) (hg.integrable j) _).symm.le
filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij]
intros
refine add_le_add ?_ ?_ <;> assumption
theorem add_martingale [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ)
(hg : Martingale g ℱ μ) : Submartingale (f + g) ℱ μ :=
hf.add hg.submartingale
theorem neg [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) :
Supermartingale (-f) ℱ μ := by
refine ⟨hf.1.neg, fun i j hij => (condExp_neg ..).le.trans ?_, fun i => (hf.2.2 i).neg⟩
filter_upwards [hf.2.1 i j hij] with _ _
simpa
/-- The converse of this lemma is `MeasureTheory.submartingale_of_setIntegral_le`. -/
theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ)
{i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) :
∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f j ω ∂μ := by
rw [← neg_le_neg_iff, ← integral_neg, ← integral_neg]
exact Supermartingale.setIntegral_le hf.neg hij hs
theorem sub_supermartingale [Preorder E] [AddLeftMono E]
(hf : Submartingale f ℱ μ) (hg : Supermartingale g ℱ μ) : Submartingale (f - g) ℱ μ := by
rw [sub_eq_add_neg]; exact hf.add hg.neg
theorem sub_martingale [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ)
(hg : Martingale g ℱ μ) : Submartingale (f - g) ℱ μ :=
hf.sub_supermartingale hg.supermartingale
protected theorem sup {f g : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) (hg : Submartingale g ℱ μ) :
Submartingale (f ⊔ g) ℱ μ := by
refine ⟨fun i => @StronglyMeasurable.sup _ _ _ _ (ℱ i) _ _ _ (hf.adapted i) (hg.adapted i),
fun i j hij => ?_, fun i => Integrable.sup (hf.integrable _) (hg.integrable _)⟩
refine EventuallyLE.sup_le ?_ ?_
· exact EventuallyLE.trans (hf.2.1 i j hij)
(condExp_mono (hf.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j))
(Eventually.of_forall fun x => le_max_left _ _))
· exact EventuallyLE.trans (hg.2.1 i j hij)
(condExp_mono (hg.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j))
(Eventually.of_forall fun x => le_max_right _ _))
protected theorem pos {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) : Submartingale (f⁺) ℱ μ :=
hf.sup (martingale_zero _ _ _).submartingale
end Submartingale
section Submartingale
theorem submartingale_of_setIntegral_le [SigmaFiniteFiltration μ ℱ]
{f : ι → Ω → ℝ} (hadp : Adapted ℱ f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ i j : ι,
i ≤ j → ∀ s : Set Ω, MeasurableSet[ℱ i] s → ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f j ω ∂μ) :
Submartingale f ℱ μ := by
refine ⟨hadp, fun i j hij => ?_, hint⟩
suffices f i ≤ᵐ[μ.trim (ℱ.le i)] μ[f j|ℱ i] by exact ae_le_of_ae_le_trim this
suffices 0 ≤ᵐ[μ.trim (ℱ.le i)] μ[f j|ℱ i] - f i by
filter_upwards [this] with x hx
rwa [← sub_nonneg]
refine ae_nonneg_of_forall_setIntegral_nonneg
((integrable_condExp.sub (hint i)).trim _ (stronglyMeasurable_condExp.sub <| hadp i))
fun s hs _ => ?_
specialize hf i j hij s hs
rwa [← setIntegral_trim _ (stronglyMeasurable_condExp.sub <| hadp i) hs,
integral_sub' integrable_condExp.integrableOn (hint i).integrableOn, sub_nonneg,
setIntegral_condExp (ℱ.le i) (hint j) hs]
theorem submartingale_of_condExp_sub_nonneg [SigmaFiniteFiltration μ ℱ]
{f : ι → Ω → ℝ} (hadp : Adapted ℱ f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ i j, i ≤ j → 0 ≤ᵐ[μ] μ[f j - f i|ℱ i]) :
Submartingale f ℱ μ := by
refine ⟨hadp, fun i j hij => ?_, hint⟩
rw [← condExp_of_stronglyMeasurable (ℱ.le _) (hadp _) (hint _), ← eventually_sub_nonneg]
exact EventuallyLE.trans (hf i j hij) (condExp_sub (hint _) (hint _) _).le
theorem Submartingale.condExp_sub_nonneg {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) {i j : ι}
(hij : i ≤ j) : 0 ≤ᵐ[μ] μ[f j - f i|ℱ i] := by
by_cases h : SigmaFinite (μ.trim (ℱ.le i))
swap; · rw [condExp_of_not_sigmaFinite (ℱ.le i) h]
refine EventuallyLE.trans ?_ (condExp_sub (hf.integrable _) (hf.integrable _) _).symm.le
rw [eventually_sub_nonneg,
condExp_of_stronglyMeasurable (ℱ.le _) (hf.adapted _) (hf.integrable _)]
exact hf.2.1 i j hij
theorem submartingale_iff_condExp_sub_nonneg [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} :
Submartingale f ℱ μ ↔
Adapted ℱ f ∧ (∀ i, Integrable (f i) μ) ∧ ∀ i j, i ≤ j → 0 ≤ᵐ[μ] μ[f j - f i|ℱ i] :=
⟨fun h => ⟨h.adapted, h.integrable, fun _ _ => h.condExp_sub_nonneg⟩, fun ⟨hadp, hint, h⟩ =>
submartingale_of_condExp_sub_nonneg hadp hint h⟩
end Submartingale
namespace Supermartingale
theorem sub_submartingale [Preorder E] [AddLeftMono E]
(hf : Supermartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Supermartingale (f - g) ℱ μ := by
rw [sub_eq_add_neg]; exact hf.add hg.neg
theorem sub_martingale [Preorder E] [AddLeftMono E]
(hf : Supermartingale f ℱ μ) (hg : Martingale g ℱ μ) : Supermartingale (f - g) ℱ μ :=
hf.sub_submartingale hg.submartingale
section
variable {F : Type*} [NormedAddCommGroup F] [Lattice F] [NormedSpace ℝ F] [CompleteSpace F]
[IsOrderedModule ℝ F]
theorem smul_nonneg {f : ι → Ω → F} {c : ℝ} (hc : 0 ≤ c) (hf : Supermartingale f ℱ μ) :
Supermartingale (c • f) ℱ μ := by
refine ⟨hf.1.smul c, fun i j hij => ?_, fun i => (hf.2.2 i).smul c⟩
filter_upwards [condExp_smul c (f j) (ℱ i), hf.2.1 i j hij] with ω hω hle
simpa only [hω, Pi.smul_apply] using smul_le_smul_of_nonneg_left hle hc
theorem smul_nonpos [IsOrderedAddMonoid F] {f : ι → Ω → F} {c : ℝ}
(hc : c ≤ 0) (hf : Supermartingale f ℱ μ) :
Submartingale (c • f) ℱ μ := by
rw [← neg_neg c, neg_smul]
exact (hf.smul_nonneg <| neg_nonneg.2 hc).neg
end
end Supermartingale
namespace Submartingale
section
variable {F : Type*} [NormedAddCommGroup F] [Lattice F] [IsOrderedAddMonoid F]
[NormedSpace ℝ F] [CompleteSpace F] [IsOrderedModule ℝ F]
theorem smul_nonneg {f : ι → Ω → F} {c : ℝ} (hc : 0 ≤ c) (hf : Submartingale f ℱ μ) :
Submartingale (c • f) ℱ μ := by
rw [← neg_neg (c • f), ← smul_neg]
exact Supermartingale.neg (hf.neg.smul_nonneg hc)
theorem smul_nonpos {f : ι → Ω → F} {c : ℝ} (hc : c ≤ 0) (hf : Submartingale f ℱ μ) :
Supermartingale (c • f) ℱ μ := by
rw [← neg_neg c, neg_smul]
exact (hf.smul_nonneg <| neg_nonneg.2 hc).neg
end
end Submartingale
section Nat
variable {𝒢 : Filtration ℕ m0}
theorem submartingale_of_setIntegral_le_succ [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ}
(hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f (i + 1) ω ∂μ) :
Submartingale f 𝒢 μ := by
refine submartingale_of_setIntegral_le hadp hint fun i j hij s hs => ?_
induction hij with
| refl => rfl
| step hk₁ hk₂ => exact hk₂.trans (hf _ s (𝒢.mono hk₁ _ hs))
theorem supermartingale_of_setIntegral_succ_le [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ}
(hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f (i + 1) ω ∂μ ≤ ∫ ω in s, f i ω ∂μ) :
Supermartingale f 𝒢 μ := by
rw [← neg_neg f]
refine (submartingale_of_setIntegral_le_succ hadp.neg (fun i => (hint i).neg) ?_).neg
simpa only [integral_neg, Pi.neg_apply, neg_le_neg_iff]
theorem martingale_of_setIntegral_eq_succ [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f i ω ∂μ = ∫ ω in s, f (i + 1) ω ∂μ) :
Martingale f 𝒢 μ :=
martingale_iff.2 ⟨supermartingale_of_setIntegral_succ_le hadp hint fun i s hs => (hf i s hs).ge,
submartingale_of_setIntegral_le_succ hadp hint fun i s hs => (hf i s hs).le⟩
theorem submartingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, f i ≤ᵐ[μ] μ[f (i + 1)|𝒢 i]) :
Submartingale f 𝒢 μ := by
refine submartingale_of_setIntegral_le_succ hadp hint fun i s hs => ?_
have : ∫ ω in s, f (i + 1) ω ∂μ = ∫ ω in s, (μ[f (i + 1)|𝒢 i]) ω ∂μ :=
(setIntegral_condExp (𝒢.le i) (hint _) hs).symm
rw [this]
exact setIntegral_mono_ae (hint i).integrableOn integrable_condExp.integrableOn (hf i)
theorem supermartingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, μ[f (i + 1)|𝒢 i] ≤ᵐ[μ] f i) :
Supermartingale f 𝒢 μ := by
rw [← neg_neg f]
refine (submartingale_nat hadp.neg (fun i => (hint i).neg) fun i =>
EventuallyLE.trans ?_ (condExp_neg ..).symm.le).neg
filter_upwards [hf i] with x hx using neg_le_neg hx
theorem martingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f)
(hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, f i =ᵐ[μ] μ[f (i + 1)|𝒢 i]) : Martingale f 𝒢 μ :=
martingale_iff.2 ⟨supermartingale_nat hadp hint fun i => (hf i).symm.le,
submartingale_nat hadp hint fun i => (hf i).le⟩
theorem submartingale_of_condExp_sub_nonneg_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ}
(hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, 0 ≤ᵐ[μ] μ[f (i + 1) - f i|𝒢 i]) : Submartingale f 𝒢 μ := by
refine submartingale_nat hadp hint fun i => ?_
rw [← condExp_of_stronglyMeasurable (𝒢.le _) (hadp _) (hint _), ← eventually_sub_nonneg]
exact EventuallyLE.trans (hf i) (condExp_sub (hint _) (hint _) _).le
theorem supermartingale_of_condExp_sub_nonneg_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ}
(hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, 0 ≤ᵐ[μ] μ[f i - f (i + 1)|𝒢 i]) : Supermartingale f 𝒢 μ := by
rw [← neg_neg f]
refine (submartingale_of_condExp_sub_nonneg_nat hadp.neg (fun i => (hint i).neg) ?_).neg
simpa only [Pi.zero_apply, Pi.neg_apply, neg_sub_neg]
theorem martingale_of_condExp_sub_eq_zero_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ}
(hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ)
(hf : ∀ i, μ[f (i + 1) - f i|𝒢 i] =ᵐ[μ] 0) : Martingale f 𝒢 μ := by
refine martingale_iff.2 ⟨supermartingale_of_condExp_sub_nonneg_nat hadp hint fun i => ?_,
submartingale_of_condExp_sub_nonneg_nat hadp hint fun i => (hf i).symm.le⟩
rw [← neg_sub]
refine (EventuallyEq.trans ?_ (condExp_neg ..).symm).le
filter_upwards [hf i] with x hx
simpa only [Pi.zero_apply, Pi.neg_apply, zero_eq_neg]
-- Note that one cannot use `Submartingale.zero_le_of_predictable` to prove the other two
-- corresponding lemmas without imposing more restrictions to the ordering of `E`
/-- A predictable submartingale is a.e. greater equal than its initial state. -/
theorem Submartingale.zero_le_of_predictable [Preorder E] [SigmaFiniteFiltration μ 𝒢]
{f : ℕ → Ω → E} (hfmgle : Submartingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1)) (n : ℕ) :
f 0 ≤ᵐ[μ] f n := by
induction n with
| zero => rfl
| succ k ih =>
exact ih.trans ((hfmgle.2.1 k (k + 1) k.le_succ).trans_eq <| Germ.coe_eq.mp <|
congr_arg Germ.ofFun <| condExp_of_stronglyMeasurable (𝒢.le _) (hfadp _) <| hfmgle.integrable _)
/-- A predictable supermartingale is a.e. less equal than its initial state. -/
theorem Supermartingale.le_zero_of_predictable [Preorder E] [SigmaFiniteFiltration μ 𝒢]
{f : ℕ → Ω → E} (hfmgle : Supermartingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1))
(n : ℕ) : f n ≤ᵐ[μ] f 0 := by
induction n with
| zero => rfl
| succ k ih =>
exact ((Germ.coe_eq.mp <| congr_arg Germ.ofFun <| condExp_of_stronglyMeasurable (𝒢.le _)
(hfadp _) <| hfmgle.integrable _).symm.trans_le (hfmgle.2.1 k (k + 1) k.le_succ)).trans ih
/-- A predictable martingale is a.e. equal to its initial state. -/
theorem Martingale.eq_zero_of_predictable [SigmaFiniteFiltration μ 𝒢] {f : ℕ → Ω → E}
(hfmgle : Martingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1)) (n : ℕ) : f n =ᵐ[μ] f 0 := by
induction n with
| zero => rfl
| succ k ih =>
exact ((Germ.coe_eq.mp (congr_arg Germ.ofFun <| condExp_of_stronglyMeasurable (𝒢.le _) (hfadp _)
(hfmgle.integrable _))).symm.trans (hfmgle.2 k (k + 1) k.le_succ)).trans ih
section IsPredictable
variable [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E]
/-- A predictable submartingale is a.e. greater than or equal to its initial state.
In constrast to the non-primed version, this results require second countablility as `Adapted` is
defined using strong measurability while `IsPredictable` only provides measurable. -/
theorem Submartingale.zero_le_of_predictable' [Preorder E] [SigmaFiniteFiltration μ 𝒢]
{f : ℕ → Ω → E} (hfmgle : Submartingale f 𝒢 μ) (hf : IsPredictable 𝒢 f) (n : ℕ) :
f 0 ≤ᵐ[μ] f n :=
zero_le_of_predictable hfmgle (fun _ ↦ (hf.measurable_add_one _).stronglyMeasurable) n
/-- A predictable supermartingale is a.e. less equal than its initial state.
In constrast to the non-primed version, this results require second countablility as `Adapted` is
defined using strong measurability while `IsPredictable` only provides measurable. -/
theorem Supermartingale.le_zero_of_predictable' [Preorder E] [SigmaFiniteFiltration μ 𝒢]
{f : ℕ → Ω → E} (hfmgle : Supermartingale f 𝒢 μ) (hfadp : IsPredictable 𝒢 f)
(n : ℕ) : f n ≤ᵐ[μ] f 0 :=
le_zero_of_predictable hfmgle (fun _ ↦ (hfadp.measurable_add_one _).stronglyMeasurable) n
/-- A predictable martingale is a.e. equal to its initial state.
In constrast to the non-primed version, this results require second countablility as `Adapted` is
defined using strong measurability while `IsPredictable` only provides measurable. -/
theorem Martingale.eq_zero_of_predictable' [SigmaFiniteFiltration μ 𝒢] {f : ℕ → Ω → E}
(hfmgle : Martingale f 𝒢 μ) (hfadp : IsPredictable 𝒢 f) (n : ℕ) : f n =ᵐ[μ] f 0 :=
eq_zero_of_predictable hfmgle (fun _ ↦ (hfadp.measurable_add_one _).stronglyMeasurable) n
end IsPredictable
namespace Submartingale
protected theorem integrable_stoppedValue [LE E] {f : ℕ → Ω → E} (hf : Submartingale f 𝒢 μ)
{τ : Ω → ℕ∞} (hτ : IsStoppingTime 𝒢 τ) {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) :
Integrable (stoppedValue f τ) μ :=
integrable_stoppedValue ℕ hτ hf.integrable hbdd
end Submartingale
theorem Submartingale.sum_mul_sub [IsFiniteMeasure μ] {R : ℝ} {ξ f : ℕ → Ω → ℝ}
(hf : Submartingale f 𝒢 μ) (hξ : Adapted 𝒢 ξ) (hbdd : ∀ n ω, ξ n ω ≤ R)
(hnonneg : ∀ n ω, 0 ≤ ξ n ω) :
Submartingale (fun n => ∑ k ∈ Finset.range n, ξ k * (f (k + 1) - f k)) 𝒢 μ := by
have hξbdd : ∀ i, ∃ C, ∀ ω, |ξ i ω| ≤ C := fun i =>
⟨R, fun ω => (abs_of_nonneg (hnonneg i ω)).trans_le (hbdd i ω)⟩
have hint : ∀ m, Integrable (∑ k ∈ Finset.range m, ξ k * (f (k + 1) - f k)) μ := fun m =>
integrable_finset_sum' _ fun i _ => Integrable.bdd_mul ((hf.integrable _).sub (hf.integrable _))
hξ.stronglyMeasurable.aestronglyMeasurable (hξbdd _)
have hadp : Adapted 𝒢 fun n => ∑ k ∈ Finset.range n, ξ k * (f (k + 1) - f k) := by
intro m
refine Finset.stronglyMeasurable_sum _ fun i hi => ?_
rw [Finset.mem_range] at hi
exact (hξ.stronglyMeasurable_le hi.le).mul
((hf.adapted.stronglyMeasurable_le (Nat.succ_le_of_lt hi)).sub
(hf.adapted.stronglyMeasurable_le hi.le))
refine submartingale_of_condExp_sub_nonneg_nat hadp hint fun i => ?_
simp only [← Finset.sum_Ico_eq_sub _ (Nat.le_succ _),
Nat.Ico_succ_singleton, Finset.sum_singleton]
exact EventuallyLE.trans (EventuallyLE.mul_nonneg (Eventually.of_forall (hnonneg _))
(hf.condExp_sub_nonneg (Nat.le_succ _))) (condExp_mul_of_stronglyMeasurable_left (hξ _)
(((hf.integrable _).sub (hf.integrable _)).bdd_mul
hξ.stronglyMeasurable.aestronglyMeasurable (hξbdd _))
((hf.integrable _).sub (hf.integrable _))).symm.le
/-- Given a discrete submartingale `f` and a predictable process `ξ` (i.e. `ξ (n + 1)` is adapted)
the process defined by `fun n => ∑ k ∈ Finset.range n, ξ (k + 1) * (f (k + 1) - f k)` is also a
submartingale. -/
theorem Submartingale.sum_mul_sub' [IsFiniteMeasure μ] {R : ℝ} {ξ f : ℕ → Ω → ℝ}
(hf : Submartingale f 𝒢 μ) (hξ : Adapted 𝒢 fun n => ξ (n + 1)) (hbdd : ∀ n ω, ξ n ω ≤ R)
(hnonneg : ∀ n ω, 0 ≤ ξ n ω) :
Submartingale (fun n => ∑ k ∈ Finset.range n, ξ (k + 1) * (f (k + 1) - f k)) 𝒢 μ :=
hf.sum_mul_sub hξ (fun _ => hbdd _) fun _ => hnonneg _
end Nat
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/OptionalSampling.lean | import Mathlib.Order.SuccPred.LinearLocallyFinite
import Mathlib.Probability.Martingale.Basic
/-!
# Optional sampling theorem
If `τ` is a bounded stopping time and `σ` is another stopping time, then the value of a martingale
`f` at the stopping time `min τ σ` is almost everywhere equal to
`μ[stoppedValue f τ | hσ.measurableSpace]`.
## Main results
* `stoppedValue_ae_eq_condExp_of_le_const`: the value of a martingale `f` at a stopping time `τ`
bounded by `n` is the conditional expectation of `f n` with respect to the σ-algebra generated by
`τ`.
* `stoppedValue_ae_eq_condExp_of_le`: if `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is
bounded, then the value of a martingale `f` at `σ` is the conditional expectation of its value at
`τ` with respect to the σ-algebra generated by `σ`.
* `stoppedValue_min_ae_eq_condExp`: the optional sampling theorem. If `τ` is a bounded stopping
time and `σ` is another stopping time, then the value of a martingale `f` at the stopping time
`min τ σ` is almost everywhere equal to the conditional expectation of `f` stopped at `τ`
with respect to the σ-algebra generated by `σ`.
-/
open scoped MeasureTheory ENNReal
open TopologicalSpace
namespace MeasureTheory
namespace Martingale
variable {Ω E : Type*} {m : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E]
section FirstCountableTopology
variable {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι]
[FirstCountableTopology ι] {ℱ : Filtration ι m} [SigmaFiniteFiltration μ ℱ] {τ σ : Ω → WithTop ι}
{f : ι → Ω → E} {i n : ι}
theorem condExp_stopping_time_ae_eq_restrict_eq_const (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le)] (hin : i ≤ n) :
μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by
refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condExp_ae_eq hin))
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i)
(hτ.measurableSet_eq' i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
theorem condExp_stopping_time_ae_eq_restrict_eq_const_of_le_const (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n)
[SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] (i : ι) :
μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by
by_cases hin : i ≤ n
· refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condExp_ae_eq hin))
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_le hτ_le)
(ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
· suffices {x : Ω | τ x = i} = ∅ by simp [this]; norm_cast
ext1 x
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
contrapose! hin
exact_mod_cast hin ▸ hτ_le x
variable [Nonempty ι]
theorem stoppedValue_ae_eq_restrict_eq (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ)
(hτ_le : ∀ x, τ x ≤ n) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] (i : ι) :
stoppedValue f τ =ᵐ[μ.restrict {x | τ x = i}] μ[f n|hτ.measurableSpace] := by
refine Filter.EventuallyEq.trans ?_
(condExp_stopping_time_ae_eq_restrict_eq_const_of_le_const h hτ hτ_le i).symm
rw [Filter.EventuallyEq, ae_restrict_iff' (ℱ.le _ _ (hτ.measurableSet_eq i))]
refine Filter.Eventually.of_forall fun x hx => ?_
rw [Set.mem_setOf_eq] at hx
simp [stoppedValue, hx]
/-- The value of a martingale `f` at a stopping time `τ` bounded by `n` is the conditional
expectation of `f n` with respect to the σ-algebra generated by `τ`. -/
theorem stoppedValue_ae_eq_condExp_of_le_const_of_countable_range (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n) (h_countable_range : (Set.range τ).Countable)
[SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] :
stoppedValue f τ =ᵐ[μ] μ[f n|hτ.measurableSpace] := by
have : Set.univ = ⋃ i ∈ Set.range τ, {x | τ x = i} := by
ext1 x
simp only [Set.mem_univ, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq',
Set.mem_iUnion, Set.mem_setOf_eq, exists_apply_eq_apply']
nth_rw 1 [← @Measure.restrict_univ Ω _ μ]
rw [this, ae_eq_restrict_biUnion_iff _ h_countable_range]
intro i hi
have h_top : i ≠ ⊤ := fun h ↦ by
simp only [h, Set.mem_range] at hi
obtain ⟨ω , hω⟩ := hi
specialize hτ_le ω
simp [hω] at hτ_le
lift i to ι using h_top with i
exact stoppedValue_ae_eq_restrict_eq h _ hτ_le i
/-- The value of a martingale `f` at a stopping time `τ` bounded by `n` is the conditional
expectation of `f n` with respect to the σ-algebra generated by `τ`. -/
theorem stoppedValue_ae_eq_condExp_of_le_const [Countable ι] (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n)
[SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] :
stoppedValue f τ =ᵐ[μ] μ[f n|hτ.measurableSpace] :=
h.stoppedValue_ae_eq_condExp_of_le_const_of_countable_range hτ hτ_le (Set.to_countable _)
/-- If `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is bounded, then the value of a
martingale `f` at `σ` is the conditional expectation of its value at `τ` with respect to the
σ-algebra generated by `σ`. -/
theorem stoppedValue_ae_eq_condExp_of_le_of_countable_range (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) (hσ_le_τ : σ ≤ τ) (hτ_le : ∀ x, τ x ≤ n)
(hτ_countable_range : (Set.range τ).Countable) (hσ_countable_range : (Set.range σ).Countable)
[SigmaFinite (μ.trim (hσ.measurableSpace_le_of_le fun x => (hσ_le_τ x).trans (hτ_le x)))] :
stoppedValue f σ =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] := by
have : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) :=
sigmaFiniteTrim_mono _ (IsStoppingTime.measurableSpace_mono hσ hτ hσ_le_τ)
have : μ[stoppedValue f τ|hσ.measurableSpace] =ᵐ[μ]
μ[μ[f n|hτ.measurableSpace]|hσ.measurableSpace] := condExp_congr_ae
(h.stoppedValue_ae_eq_condExp_of_le_const_of_countable_range hτ hτ_le hτ_countable_range)
refine (Filter.EventuallyEq.trans ?_
(condExp_condExp_of_le ?_ (hτ.measurableSpace_le_of_le hτ_le)).symm).trans this.symm
· exact h.stoppedValue_ae_eq_condExp_of_le_const_of_countable_range hσ
(fun x => (hσ_le_τ x).trans (hτ_le x)) hσ_countable_range
· exact hσ.measurableSpace_mono hτ hσ_le_τ
/-- If `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is bounded, then the value of a
martingale `f` at `σ` is the conditional expectation of its value at `τ` with respect to the
σ-algebra generated by `σ`. -/
theorem stoppedValue_ae_eq_condExp_of_le [Countable ι] (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) (hσ_le_τ : σ ≤ τ) (hτ_le : ∀ x, τ x ≤ n)
[SigmaFinite (μ.trim hσ.measurableSpace_le)] :
stoppedValue f σ =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] :=
h.stoppedValue_ae_eq_condExp_of_le_of_countable_range hτ hσ hσ_le_τ hτ_le (Set.to_countable _)
(Set.to_countable _)
end FirstCountableTopology
section SubsetOfNat
/-! In the following results the index set verifies
`[LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι]`, which means that it is order-isomorphic to
a subset of `ℕ`. `ι` is equipped with the discrete topology, which is also the order topology,
and is a measurable space with the Borel σ-algebra. -/
variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [TopologicalSpace ι]
[DiscreteTopology ι] [MeasurableSpace ι] [BorelSpace ι] [MeasurableSpace E] [BorelSpace E]
[SecondCountableTopology E] {ℱ : Filtration ι m} {τ σ : Ω → WithTop ι} {f : ι → Ω → E} {i : ι}
theorem condExp_stoppedValue_stopping_time_ae_eq_restrict_le (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) [SigmaFinite (μ.trim hσ.measurableSpace_le)]
(hτ_le : ∀ x, τ x ≤ i) :
μ[stoppedValue f τ|hσ.measurableSpace] =ᵐ[μ.restrict {x : Ω | τ x ≤ σ x}] stoppedValue f τ := by
rw [ae_eq_restrict_iff_indicator_ae_eq
(hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ))]
refine (condExp_indicator (integrable_stoppedValue ι hτ h.integrable hτ_le)
(hτ.measurableSet_stopping_time_le hσ)).symm.trans ?_
have h_int :
Integrable ({ω : Ω | τ ω ≤ σ ω}.indicator (stoppedValue (fun n : ι => f n) τ)) μ := by
refine (integrable_stoppedValue ι hτ h.integrable hτ_le).indicator ?_
exact hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ)
have h_meas : AEStronglyMeasurable[hσ.measurableSpace]
({ω : Ω | τ ω ≤ σ ω}.indicator (stoppedValue (fun n : ι => f n) τ)) μ := by
refine StronglyMeasurable.aestronglyMeasurable ?_
refine StronglyMeasurable.stronglyMeasurable_of_measurableSpace_le_on
(hτ.measurableSet_le_stopping_time hσ) ?_ ?_ ?_
· intro t ht
rw [Set.inter_comm _ t] at ht ⊢
rw [hτ.measurableSet_inter_le_iff hσ, IsStoppingTime.measurableSet_min_iff hτ hσ] at ht
exact ht.2
· refine StronglyMeasurable.indicator ?_ (hτ.measurableSet_le_stopping_time hσ)
refine Measurable.stronglyMeasurable ?_
exact measurable_stoppedValue h.adapted.progMeasurable_of_discrete hτ
· intro x hx
simp only [hx, Set.indicator_of_notMem, not_false_iff]
exact condExp_of_aestronglyMeasurable' hσ.measurableSpace_le h_meas h_int
/-- **Optional Sampling theorem**. If `τ` is a bounded stopping time and `σ` is another stopping
time, then the value of a martingale `f` at the stopping time `min τ σ` is almost everywhere equal
to the conditional expectation of `f` stopped at `τ` with respect to the σ-algebra generated
by `σ`. -/
theorem stoppedValue_min_ae_eq_condExp [SigmaFiniteFiltration μ ℱ] (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) {n : ι} (hτ_le : ∀ x, τ x ≤ n)
[h_sf_min : SigmaFinite (μ.trim (hτ.min hσ).measurableSpace_le)] :
(stoppedValue f fun x => min (σ x) (τ x)) =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] := by
refine
(h.stoppedValue_ae_eq_condExp_of_le hτ (hσ.min hτ) (fun x => min_le_right _ _) hτ_le).trans ?_
refine ae_of_ae_restrict_of_ae_restrict_compl {x | σ x ≤ τ x} ?_ ?_
· exact condExp_min_stopping_time_ae_eq_restrict_le hσ hτ
· suffices μ[stoppedValue f τ|(hσ.min hτ).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ σ x}]
μ[stoppedValue f τ|hσ.measurableSpace] by
rw [ae_restrict_iff' (hσ.measurableSpace_le _ (hσ.measurableSet_le_stopping_time hτ).compl)]
rw [Filter.EventuallyEq, ae_restrict_iff'] at this
swap; · exact hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ)
filter_upwards [this] with x hx hx_mem
simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx_mem
exact hx hx_mem.le
apply Filter.EventuallyEq.trans _ ((condExp_min_stopping_time_ae_eq_restrict_le hτ hσ).trans _)
· exact stoppedValue f τ
· rw [IsStoppingTime.measurableSpace_min hσ hτ,
IsStoppingTime.measurableSpace_min hτ hσ, inf_comm]
· have h1 : μ[stoppedValue f τ|hτ.measurableSpace] = stoppedValue f τ := by
apply condExp_of_stronglyMeasurable hτ.measurableSpace_le
· exact Measurable.stronglyMeasurable <|
measurable_stoppedValue h.adapted.progMeasurable_of_discrete hτ
· exact integrable_stoppedValue ι hτ h.integrable hτ_le
rw [h1]
exact (condExp_stoppedValue_stopping_time_ae_eq_restrict_le h hτ hσ hτ_le).symm
end SubsetOfNat
end Martingale
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/Centering.lean | import Mathlib.Probability.Martingale.Basic
/-!
# Centering lemma for stochastic processes
Any `ℕ`-indexed stochastic process which is adapted and integrable can be written as the sum of a
martingale and a predictable process. This result is also known as **Doob's decomposition theorem**.
From a process `f`, a filtration `ℱ` and a measure `μ`, we define two processes
`martingalePart f ℱ μ` and `predictablePart f ℱ μ`.
## Main definitions
* `MeasureTheory.predictablePart f ℱ μ`: a predictable process such that
`f = predictablePart f ℱ μ + martingalePart f ℱ μ`
* `MeasureTheory.martingalePart f ℱ μ`: a martingale such that
`f = predictablePart f ℱ μ + martingalePart f ℱ μ`
## Main statements
* `MeasureTheory.adapted_predictablePart`: `(fun n => predictablePart f ℱ μ (n+1))` is adapted.
That is, `predictablePart` is predictable.
* `MeasureTheory.martingale_martingalePart`: `martingalePart f ℱ μ` is a martingale.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory
namespace MeasureTheory
variable {Ω E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] {f : ℕ → Ω → E} {ℱ : Filtration ℕ m0}
/-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable
process. This is the predictable process. See `martingalePart` for the martingale. -/
noncomputable def predictablePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0)
(μ : Measure Ω) : ℕ → Ω → E := fun n => ∑ i ∈ Finset.range n, μ[f (i + 1) - f i|ℱ i]
@[simp]
theorem predictablePart_zero : predictablePart f ℱ μ 0 = 0 := by
simp_rw [predictablePart, Finset.range_zero, Finset.sum_empty]
theorem adapted_predictablePart : Adapted ℱ fun n => predictablePart f ℱ μ (n + 1) := fun _ =>
Finset.stronglyMeasurable_sum _ fun _ hin =>
stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_succ_iff.mp hin))
theorem adapted_predictablePart' : Adapted ℱ fun n => predictablePart f ℱ μ n := fun _ =>
Finset.stronglyMeasurable_sum _ fun _ hin =>
stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_le hin))
/-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable
process. This is the martingale. See `predictablePart` for the predictable process. -/
noncomputable def martingalePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0)
(μ : Measure Ω) : ℕ → Ω → E := fun n => f n - predictablePart f ℱ μ n
theorem martingalePart_add_predictablePart (ℱ : Filtration ℕ m0) (μ : Measure Ω) (f : ℕ → Ω → E) :
martingalePart f ℱ μ + predictablePart f ℱ μ = f :=
sub_add_cancel _ _
theorem martingalePart_eq_sum : martingalePart f ℱ μ = fun n =>
f 0 + ∑ i ∈ Finset.range n, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]) := by
unfold martingalePart predictablePart
ext1 n
rw [Finset.eq_sum_range_sub f n, ← add_sub, ← Finset.sum_sub_distrib]
theorem adapted_martingalePart (hf : Adapted ℱ f) : Adapted ℱ (martingalePart f ℱ μ) :=
Adapted.sub hf adapted_predictablePart'
theorem integrable_martingalePart (hf_int : ∀ n, Integrable (f n) μ) (n : ℕ) :
Integrable (martingalePart f ℱ μ n) μ := by
rw [martingalePart_eq_sum]
fun_prop
theorem martingale_martingalePart (hf : Adapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ)
[SigmaFiniteFiltration μ ℱ] : Martingale (martingalePart f ℱ μ) ℱ μ := by
refine ⟨adapted_martingalePart hf, fun i j hij => ?_⟩
-- ⊢ μ[martingalePart f ℱ μ j | ℱ i] =ᵐ[μ] martingalePart f ℱ μ i
have h_eq_sum : μ[martingalePart f ℱ μ j|ℱ i] =ᵐ[μ]
f 0 + ∑ k ∈ Finset.range j, (μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i]) := by
rw [martingalePart_eq_sum]
refine (condExp_add (hf_int 0) (by fun_prop) _).trans ?_
refine (EventuallyEq.rfl.add (condExp_finset_sum (fun i _ => by fun_prop) _)).trans ?_
refine EventuallyEq.add ?_ ?_
· rw [condExp_of_stronglyMeasurable (ℱ.le _) _ (hf_int 0)]
· exact (hf 0).mono (ℱ.mono (zero_le i))
· exact eventuallyEq_sum fun k _ => condExp_sub (by fun_prop) integrable_condExp _
refine h_eq_sum.trans ?_
have h_ge : ∀ k, i ≤ k → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] 0 := by
intro k hk
have : μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] μ[f (k + 1) - f k|ℱ i] :=
condExp_condExp_of_le (ℱ.mono hk) (ℱ.le k)
filter_upwards [this] with x hx
rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self]
have h_lt : ∀ k, k < i → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ]
f (k + 1) - f k - μ[f (k + 1) - f k|ℱ k] := by
refine fun k hk => EventuallyEq.sub ?_ ?_
· rw [condExp_of_stronglyMeasurable]
· exact ((hf (k + 1)).mono (ℱ.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (ℱ.mono hk.le))
· exact (hf_int _).sub (hf_int _)
· rw [condExp_of_stronglyMeasurable]
· exact stronglyMeasurable_condExp.mono (ℱ.mono hk.le)
· exact integrable_condExp
rw [martingalePart_eq_sum]
refine EventuallyEq.add EventuallyEq.rfl ?_
rw [← Finset.sum_range_add_sum_Ico _ hij, ←
add_zero (∑ i ∈ Finset.range i, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]))]
refine (eventuallyEq_sum fun k hk => h_lt k (Finset.mem_range.mp hk)).add ?_
refine (eventuallyEq_sum fun k hk => h_ge k (Finset.mem_Ico.mp hk).1).trans ?_
simp only [Finset.sum_const_zero]
rfl
-- The following two lemmas demonstrate the essential uniqueness of the decomposition
theorem martingalePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E}
(hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0)
(hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : martingalePart (f + g) ℱ μ n =ᵐ[μ] f n := by
set h := f - martingalePart (f + g) ℱ μ with hhdef
have hh : h = predictablePart (f + g) ℱ μ - g := by
rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictablePart (f + g) ℱ μ),
martingalePart_add_predictablePart]
have hhpred : Adapted ℱ fun n => h (n + 1) := by
rw [hh]
exact adapted_predictablePart.sub hg
have hhmgle : Martingale h ℱ μ := hf.sub (martingale_martingalePart
(hf.adapted.add <| Predictable.adapted hg <| hg0.symm ▸ stronglyMeasurable_zero) fun n =>
(hf.integrable n).add <| hgint n)
refine (eventuallyEq_iff_sub.2 ?_).symm
filter_upwards [hhmgle.eq_zero_of_predictable hhpred n] with ω hω
unfold h at hω
rw [Pi.sub_apply] at hω
rw [hω, Pi.sub_apply, martingalePart]
simp [hg0]
theorem predictablePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E}
(hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0)
(hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : predictablePart (f + g) ℱ μ n =ᵐ[μ] g n := by
filter_upwards [martingalePart_add_ae_eq hf hg hg0 hgint n] with ω hω
rw [← add_right_inj (f n ω)]
conv_rhs => rw [← Pi.add_apply, ← Pi.add_apply, ← martingalePart_add_predictablePart ℱ μ (f + g)]
rw [Pi.add_apply, Pi.add_apply, hω]
section Difference
theorem predictablePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ∀ i, |predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω| ≤ R := by
simp_rw [predictablePart, Finset.sum_apply, Finset.sum_range_succ_sub_sum]
exact ae_all_iff.2 fun i => ae_bdd_condExp_of_ae_bdd <| ae_all_iff.1 hbdd i
theorem martingalePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ∀ i, |martingalePart f ℱ μ (i + 1) ω - martingalePart f ℱ μ i ω| ≤ ↑(2 * R) := by
filter_upwards [hbdd, predictablePart_bdd_difference ℱ hbdd] with ω hω₁ hω₂ i
simp only [two_mul, martingalePart, Pi.sub_apply]
have : |f (i + 1) ω - predictablePart f ℱ μ (i + 1) ω - (f i ω - predictablePart f ℱ μ i ω)| =
|f (i + 1) ω - f i ω - (predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω)| := by
ring_nf -- `ring` suggests `ring_nf` despite proving the goal
rw [this]
exact (abs_sub _ _).trans (add_le_add (hω₁ i) (hω₂ i))
end Difference
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/Convergence.lean | import Mathlib.MeasureTheory.Constructions.Polish.Basic
import Mathlib.MeasureTheory.Function.UniformIntegrable
import Mathlib.Probability.Martingale.Upcrossing
/-!
# Martingale convergence theorems
The martingale convergence theorems are a collection of theorems characterizing the convergence
of a martingale provided it satisfies some boundedness conditions. This file contains the
almost everywhere martingale convergence theorem which provides an almost everywhere limit to
an L¹ bounded submartingale. It also contains the L¹ martingale convergence theorem which provides
an L¹ limit to a uniformly integrable submartingale. Finally, it also contains the Lévy upwards
theorems.
## Main results
* `MeasureTheory.Submartingale.ae_tendsto_limitProcess`: the almost everywhere martingale
convergence theorem: an L¹-bounded submartingale adapted to the filtration `ℱ` converges almost
everywhere to its limit process.
* `MeasureTheory.Submartingale.memLp_limitProcess`: the limit process of an Lᵖ-bounded
submartingale is Lᵖ.
* `MeasureTheory.Submartingale.tendsto_eLpNorm_one_limitProcess`: part a of the L¹ martingale
convergence theorem: a uniformly integrable submartingale adapted to the filtration `ℱ` converges
almost everywhere and in L¹ to an integrable function which is measurable with respect to
the σ-algebra `⨆ n, ℱ n`.
* `MeasureTheory.Martingale.ae_eq_condExp_limitProcess`: part b the L¹ martingale convergence
theorem: if `f` is a uniformly integrable martingale adapted to the filtration `ℱ`, then
`f n` equals `𝔼[g | ℱ n]` almost everywhere where `g` is the limiting process of `f`.
* `MeasureTheory.Integrable.tendsto_ae_condExp`: part c the L¹ martingale convergence theorem:
given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges
almost everywhere to `g`.
* `MeasureTheory.Integrable.tendsto_eLpNorm_condExp`: part c the L¹ martingale convergence theorem:
given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges in
L¹ to `g`.
-/
open TopologicalSpace Filter MeasureTheory.Filtration
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology
namespace MeasureTheory
variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0}
variable {a b : ℝ} {f : ℕ → Ω → ℝ} {ω : Ω} {R : ℝ≥0}
section AeConvergence
/-!
### Almost everywhere martingale convergence theorem
We will now prove the almost everywhere martingale convergence theorem.
The a.e. martingale convergence theorem states: if `f` is an L¹-bounded `ℱ`-submartingale, then
it converges almost everywhere to an integrable function which is measurable with respect to
the σ-algebra `ℱ∞ := ⨆ n, ℱ n`.
Mathematically, we proceed by first noting that a real sequence $(x_n)$ converges if
(a) $\limsup_{n \to \infty} |x_n| < \infty$, (b) for all $a < b \in \mathbb{Q}$ we have the
number of upcrossings of $(x_n)$ from below $a$ to above $b$ is finite.
Thus, for all $\omega$ satisfying $\limsup_{n \to \infty} |f_n(\omega)| < \infty$ and the number of
upcrossings of $(f_n(\omega))$ from below $a$ to above $b$ is finite for all $a < b \in \mathbb{Q}$,
we have $(f_n(\omega))$ is convergent.
Hence, assuming $(f_n)$ is L¹-bounded, using Fatou's lemma, we have
$$
\mathbb{E} \limsup_{n \to \infty} |f_n| \le \limsup_{n \to \infty} \mathbb{E}|f_n| < \infty
$$
implying $\limsup_{n \to \infty} |f_n| < \infty$ a.e. Furthermore, by the upcrossing estimate,
the number of upcrossings is finite almost everywhere implying $f$ converges pointwise almost
everywhere.
Thus, denoting $g$ the a.e. limit of $(f_n)$, $g$ is $\mathcal{F}_\infty$-measurable as for all
$n$, $f_n$ is $\mathcal{F}_n$-measurable and $\mathcal{F}_n \le \mathcal{F}_\infty$. Finally, $g$
is integrable as $|g| \le \liminf_{n \to \infty} |f_n|$ so
$$
\mathbb{E}|g| \le \mathbb{E} \limsup_{n \to \infty} |f_n| \le
\limsup_{n \to \infty} \mathbb{E}|f_n| < \infty
$$
as required.
In terms of implementation, we have `tendsto_of_no_upcrossings` which shows that
a bounded sequence converges if it does not visit below $a$ and above $b$ infinitely often
for all $a, b ∈ s$ for some dense set $s$. So, we may skip the first step provided we can prove
that the realizations are bounded almost everywhere. Indeed, suppose $|f_n(\omega)|$ is not
bounded, then either $f_n(\omega) \to \pm \infty$ or one of $\limsup f_n(\omega)$ or
$\liminf f_n(\omega)$ equals $\pm \infty$ while the other is finite. But the first case
contradicts $\liminf |f_n(\omega)| < \infty$ while the second case contradicts finite upcrossings.
Furthermore, we introduce `Filtration.limitProcess` which chooses the limiting random variable
of a stochastic process if it exists, otherwise returning 0. Hence, instead of showing an
existence statement, we phrase the a.e. martingale convergence theorem by showing that a
submartingale converges to its `limitProcess` almost everywhere.
-/
/-- If a stochastic process has bounded upcrossing from below `a` to above `b`,
then it does not frequently visit both below `a` and above `b`. -/
theorem not_frequently_of_upcrossings_lt_top (hab : a < b) (hω : upcrossings a b f ω ≠ ∞) :
¬((∃ᶠ n in atTop, f n ω < a) ∧ ∃ᶠ n in atTop, b < f n ω) := by
rw [← lt_top_iff_ne_top, upcrossings_lt_top_iff] at hω
replace hω : ∃ k, ∀ N, upcrossingsBefore a b f N ω < k := by
obtain ⟨k, hk⟩ := hω
exact ⟨k + 1, fun N => lt_of_le_of_lt (hk N) k.lt_succ_self⟩
rintro ⟨h₁, h₂⟩
rw [frequently_atTop] at h₁ h₂
refine Classical.not_not.2 hω ?_
push_neg
intro k
induction k with
| zero => simp only [zero_le, exists_const]
| succ k ih =>
obtain ⟨N, hN⟩ := ih
obtain ⟨N₁, hN₁, hN₁'⟩ := h₁ N
obtain ⟨N₂, hN₂, hN₂'⟩ := h₂ N₁
exact ⟨N₂ + 1, Nat.succ_le_of_lt <|
lt_of_le_of_lt hN (upcrossingsBefore_lt_of_exists_upcrossing hab hN₁ hN₁' hN₂ hN₂')⟩
/-- A stochastic process that frequently visits below `a` and above `b` has infinite upcrossings. -/
theorem upcrossings_eq_top_of_frequently_lt (hab : a < b) (h₁ : ∃ᶠ n in atTop, f n ω < a)
(h₂ : ∃ᶠ n in atTop, b < f n ω) : upcrossings a b f ω = ∞ :=
by_contradiction fun h => not_frequently_of_upcrossings_lt_top hab h ⟨h₁, h₂⟩
/-- A realization of a stochastic process with bounded upcrossings and bounded limit inferiors is
convergent.
We use the spelling `< ∞` instead of the standard `≠ ∞` in the assumptions since it is not as easy
to change `<` to `≠` under binders. -/
theorem tendsto_of_uncrossing_lt_top (hf₁ : liminf (fun n => (‖f n ω‖₊ : ℝ≥0∞)) atTop < ∞)
(hf₂ : ∀ a b : ℚ, a < b → upcrossings a b f ω < ∞) :
∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
by_cases h : IsBoundedUnder (· ≤ ·) atTop fun n => |f n ω|
· rw [isBoundedUnder_le_abs] at h
refine tendsto_of_no_upcrossings Rat.denseRange_cast ?_ h.1 h.2
rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ hab
exact not_frequently_of_upcrossings_lt_top hab (hf₂ a b (Rat.cast_lt.1 hab)).ne
· obtain ⟨a, b, hab, h₁, h₂⟩ := ENNReal.exists_upcrossings_of_not_bounded_under hf₁.ne h
exact
False.elim ((hf₂ a b hab).ne (upcrossings_eq_top_of_frequently_lt (Rat.cast_lt.2 hab) h₁ h₂))
/-- An L¹-bounded submartingale has bounded upcrossings almost everywhere. -/
theorem Submartingale.upcrossings_ae_lt_top' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) (hab : a < b) : ∀ᵐ ω ∂μ, upcrossings a b f ω < ∞ := by
refine ae_lt_top (hf.adapted.measurable_upcrossings hab) ?_
have := hf.mul_lintegral_upcrossings_le_lintegral_pos_part a b
rw [mul_comm, ← ENNReal.le_div_iff_mul_le] at this
· refine (lt_of_le_of_lt this (ENNReal.div_lt_top ?_ ?_)).ne
· have hR' : ∀ n, ∫⁻ ω, ‖f n ω - a‖₊ ∂μ ≤ R + ‖a‖₊ * μ Set.univ := by
simp_rw [eLpNorm_one_eq_lintegral_enorm] at hbdd
intro n
refine (lintegral_mono ?_ : ∫⁻ ω, ‖f n ω - a‖₊ ∂μ ≤ ∫⁻ ω, ‖f n ω‖₊ + ‖a‖₊ ∂μ).trans ?_
· intro ω
simp_rw [sub_eq_add_neg, ← nnnorm_neg a, ← ENNReal.coe_add, ENNReal.coe_le_coe]
exact nnnorm_add_le _ _
· simp_rw [lintegral_add_right _ measurable_const, lintegral_const]
exact add_le_add (hbdd _) le_rfl
refine ne_of_lt (iSup_lt_iff.2 ⟨R + ‖a‖₊ * μ Set.univ, ENNReal.add_lt_top.2
⟨ENNReal.coe_lt_top, by finiteness⟩,
fun n => le_trans ?_ (hR' n)⟩)
refine lintegral_mono fun ω => ?_
rw [ENNReal.ofReal_le_iff_le_toReal, ENNReal.coe_toReal, coe_nnnorm]
· by_cases! hnonneg : 0 ≤ f n ω - a
· rw [posPart_eq_self.2 hnonneg, Real.norm_eq_abs, abs_of_nonneg hnonneg]
· rw [posPart_eq_zero.2 hnonneg.le]
exact norm_nonneg _
· finiteness
· simp only [hab, Ne, ENNReal.ofReal_eq_zero, sub_nonpos, not_le]
· left; simp only [hab, Ne, ENNReal.ofReal_eq_zero, sub_nonpos, not_le]
· left; finiteness
theorem Submartingale.upcrossings_ae_lt_top [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ, ∀ a b : ℚ, a < b → upcrossings a b f ω < ∞ := by
simp only [ae_all_iff, eventually_imp_distrib_left]
rintro a b hab
exact hf.upcrossings_ae_lt_top' hbdd (Rat.cast_lt.2 hab)
/-- An L¹-bounded submartingale converges almost everywhere. -/
theorem Submartingale.exists_ae_tendsto_of_bdd [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ, ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
filter_upwards [hf.upcrossings_ae_lt_top hbdd, ae_bdd_liminf_atTop_of_eLpNorm_bdd one_ne_zero
(fun n => (hf.stronglyMeasurable n).measurable.mono (ℱ.le n) le_rfl) hbdd] with ω h₁ h₂
exact tendsto_of_uncrossing_lt_top h₂ h₁
theorem Submartingale.exists_ae_trim_tendsto_of_bdd [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) :
∀ᵐ ω ∂μ.trim (sSup_le fun _ ⟨_, hn⟩ => hn ▸ ℱ.le _ : ⨆ n, ℱ n ≤ m0),
∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by
letI := (⨆ n, ℱ n)
rw [ae_iff, trim_measurableSet_eq]
· exact hf.exists_ae_tendsto_of_bdd hbdd
· exact MeasurableSet.compl <| measurableSet_exists_tendsto
fun n => (hf.stronglyMeasurable n).measurable.mono (le_sSup ⟨n, rfl⟩) le_rfl
/-- **Almost everywhere martingale convergence theorem**: An L¹-bounded submartingale converges
almost everywhere to a `⨆ n, ℱ n`-measurable function. -/
theorem Submartingale.ae_tendsto_limitProcess [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) :
∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (ℱ.limitProcess f μ ω)) := by
classical
suffices
∃ g, StronglyMeasurable[⨆ n, ℱ n] g ∧ ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) by
rw [limitProcess, dif_pos this]
exact (Classical.choose_spec this).2
set g' : Ω → ℝ := fun ω => if h : ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) then h.choose else 0
have hle : ⨆ n, ℱ n ≤ m0 := sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _
have hg' : ∀ᵐ ω ∂μ.trim hle, Tendsto (fun n => f n ω) atTop (𝓝 (g' ω)) := by
filter_upwards [hf.exists_ae_trim_tendsto_of_bdd hbdd] with ω hω
simp_rw [g', dif_pos hω]
exact hω.choose_spec
have hg'm : AEStronglyMeasurable[⨆ n, ℱ n] g' (μ.trim hle) :=
(@aemeasurable_of_tendsto_metrizable_ae' _ _ (⨆ n, ℱ n) _ _ _ _ _ _ _
(fun n => ((hf.stronglyMeasurable n).measurable.mono (le_sSup ⟨n, rfl⟩ : ℱ n ≤ ⨆ n, ℱ n)
le_rfl).aemeasurable) hg').aestronglyMeasurable
obtain ⟨g, hgm, hae⟩ := hg'm
have hg : ∀ᵐ ω ∂μ.trim hle, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) := by
filter_upwards [hae, hg'] with ω hω hg'ω
exact hω ▸ hg'ω
exact ⟨g, hgm, measure_eq_zero_of_trim_eq_zero hle hg⟩
/-- The limiting process of an Lᵖ-bounded submartingale is Lᵖ. -/
theorem Submartingale.memLp_limitProcess {p : ℝ≥0∞} (hf : Submartingale f ℱ μ)
(hbdd : ∀ n, eLpNorm (f n) p μ ≤ R) : MemLp (ℱ.limitProcess f μ) p μ :=
memLp_limitProcess_of_eLpNorm_bdd
(fun n => ((hf.stronglyMeasurable n).mono (ℱ.le n)).aestronglyMeasurable) hbdd
end AeConvergence
section L1Convergence
variable [IsFiniteMeasure μ] {g : Ω → ℝ}
/-!
### L¹ martingale convergence theorem
We will now prove the L¹ martingale convergence theorems.
The L¹ martingale convergence theorem states that:
(a) if `f` is a uniformly integrable (in the probability sense) submartingale adapted to the
filtration `ℱ`, it converges in L¹ to an integrable function `g` which is measurable with
respect to `ℱ∞ := ⨆ n, ℱ n` and
(b) if `f` is actually a martingale, `f n = 𝔼[g | ℱ n]` almost everywhere.
(c) Finally, if `h` is integrable and measurable with respect to `ℱ∞`, `(𝔼[h | ℱ n])ₙ` is a
uniformly integrable martingale which converges to `h` almost everywhere and in L¹.
The proof is quite simple. (a) follows directly from the a.e. martingale convergence theorem
and the Vitali convergence theorem as our definition of uniform integrability (in the probability
sense) directly implies L¹-uniform boundedness. We note that our definition of uniform
integrability is slightly non-standard but is equivalent to the usual literary definition. This
equivalence is provided by `MeasureTheory.uniformIntegrable_iff`.
(b) follows since given $n$, we have for all $m \ge n$,
$$
\|f_n - \mathbb{E}[g \mid \mathcal{F}_n]\|_1 =
\|\mathbb{E}[f_m - g \mid \mathcal{F}_n]\|_1 \le \|\|f_m - g\|_1.
$$
Thus, taking $m \to \infty$ provides the almost everywhere equality.
Finally, to prove (c), we define $f_n := \mathbb{E}[h \mid \mathcal{F}_n]$. It is clear that
$(f_n)_n$ is a martingale by the tower property for conditional expectations. Furthermore,
$(f_n)_n$ is uniformly integrable in the probability sense. Indeed, as a single function is
uniformly integrable in the measure theory sense, for all $\epsilon > 0$, there exists some
$\delta > 0$ such that for all measurable set $A$ with $\mu(A) < δ$, we have
$\mathbb{E}|h|\mathbf{1}_A < \epsilon$. So, since for sufficiently large $\lambda$, by the Markov
inequality, we have for all $n$,
$$
\mu(|f_n| \ge \lambda) \le \lambda^{-1}\mathbb{E}|f_n| \le \lambda^{-1}\mathbb|g| < \delta,
$$
we have for sufficiently large $\lambda$, for all $n$,
$$
\mathbb{E}|f_n|\mathbf{1}_{|f_n| \ge \lambda} \le
\mathbb|g|\mathbf{1}_{|f_n| \ge \lambda} < \epsilon,
$$
implying $(f_n)_n$ is uniformly integrable. Now, to prove $f_n \to h$ almost everywhere and in
L¹, it suffices to show that $h = g$ almost everywhere where $g$ is the almost everywhere and L¹
limit of $(f_n)_n$ from part (b) of the theorem. By noting that, for all $s \in \mathcal{F}_n$,
we have
$$
\mathbb{E}g\mathbf{1}_s = \mathbb{E}[\mathbb{E}[g \mid \mathcal{F}_n]\mathbf{1}_s] =
\mathbb{E}[\mathbb{E}[h \mid \mathcal{F}_n]\mathbf{1}_s] = \mathbb{E}h\mathbf{1}_s
$$
where $\mathbb{E}[g \mid \mathcal{F}_n = \mathbb{E}[h \mid \mathcal{F}_n]$ almost everywhere
by part (b); the equality also holds for all $s \in \mathcal{F}_\infty$ by Dynkin's theorem.
Thus, as both $h$ and $g$ are $\mathcal{F}_\infty$-measurable, $h = g$ almost everywhere as
required.
Similar to the a.e. martingale convergence theorem, rather than showing the existence of the
limiting process, we phrase the L¹-martingale convergence theorem by proving that a submartingale
does converge in L¹ to its `limitProcess`. However, in contrast to the a.e. martingale convergence
theorem, we do not need to introduce an L¹ version of `Filtration.limitProcess` as the L¹ limit
and the a.e. limit of a submartingale coincide.
-/
/-- Part a of the **L¹ martingale convergence theorem**: a uniformly integrable submartingale
adapted to the filtration `ℱ` converges a.e. and in L¹ to an integrable function which is
measurable with respect to the σ-algebra `⨆ n, ℱ n`. -/
theorem Submartingale.tendsto_eLpNorm_one_limitProcess (hf : Submartingale f ℱ μ)
(hunif : UniformIntegrable f 1 μ) :
Tendsto (fun n => eLpNorm (f n - ℱ.limitProcess f μ) 1 μ) atTop (𝓝 0) := by
obtain ⟨R, hR⟩ := hunif.2.2
have hmeas : ∀ n, AEStronglyMeasurable (f n) μ := fun n =>
((hf.stronglyMeasurable n).mono (ℱ.le _)).aestronglyMeasurable
exact tendsto_Lp_finite_of_tendstoInMeasure le_rfl ENNReal.one_ne_top hmeas
(memLp_limitProcess_of_eLpNorm_bdd hmeas hR) hunif.2.1
(tendstoInMeasure_of_tendsto_ae hmeas <| hf.ae_tendsto_limitProcess hR)
theorem Submartingale.ae_tendsto_limitProcess_of_uniformIntegrable (hf : Submartingale f ℱ μ)
(hunif : UniformIntegrable f 1 μ) :
∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (ℱ.limitProcess f μ ω)) :=
let ⟨_, hR⟩ := hunif.2.2
hf.ae_tendsto_limitProcess hR
/-- If a martingale `f` adapted to `ℱ` converges in L¹ to `g`, then for all `n`, `f n` is almost
everywhere equal to `𝔼[g | ℱ n]`. -/
theorem Martingale.eq_condExp_of_tendsto_eLpNorm {μ : Measure Ω} (hf : Martingale f ℱ μ)
(hg : Integrable g μ) (hgtends : Tendsto (fun n => eLpNorm (f n - g) 1 μ) atTop (𝓝 0)) (n : ℕ) :
f n =ᵐ[μ] μ[g|ℱ n] := by
rw [← sub_ae_eq_zero, ← eLpNorm_eq_zero_iff (((hf.stronglyMeasurable n).mono (ℱ.le _)).sub
(stronglyMeasurable_condExp.mono (ℱ.le _))).aestronglyMeasurable one_ne_zero]
have ht : Tendsto (fun m => eLpNorm (μ[f m - g|ℱ n]) 1 μ) atTop (𝓝 0) :=
haveI hint : ∀ m, Integrable (f m - g) μ := fun m => (hf.integrable m).sub hg
tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hgtends (fun m => zero_le _)
fun m => eLpNorm_one_condExp_le_eLpNorm _
have hev : ∀ m ≥ n, eLpNorm (μ[f m - g|ℱ n]) 1 μ = eLpNorm (f n - μ[g|ℱ n]) 1 μ := by
refine fun m hm => eLpNorm_congr_ae ((condExp_sub (hf.integrable m) hg _).trans ?_)
filter_upwards [hf.2 n m hm] with x hx
simp only [hx, Pi.sub_apply]
exact tendsto_nhds_unique (tendsto_atTop_of_eventually_const hev) ht
/-- Part b of the **L¹ martingale convergence theorem**: if `f` is a uniformly integrable martingale
adapted to the filtration `ℱ`, then for all `n`, `f n` is almost everywhere equal to the conditional
expectation of its limiting process w.r.t. `ℱ n`. -/
theorem Martingale.ae_eq_condExp_limitProcess (hf : Martingale f ℱ μ)
(hbdd : UniformIntegrable f 1 μ) (n : ℕ) : f n =ᵐ[μ] μ[ℱ.limitProcess f μ|ℱ n] :=
let ⟨_, hR⟩ := hbdd.2.2
hf.eq_condExp_of_tendsto_eLpNorm ((memLp_limitProcess_of_eLpNorm_bdd hbdd.1 hR).integrable le_rfl)
(hf.submartingale.tendsto_eLpNorm_one_limitProcess hbdd) n
/-- Part c of the **L¹ martingale convergence theorem**: Given an integrable function `g` which
is measurable with respect to `⨆ n, ℱ n` where `ℱ` is a filtration, the martingale defined by
`𝔼[g | ℱ n]` converges almost everywhere to `g`.
This martingale also converges to `g` in L¹ and this result is provided by
`MeasureTheory.Integrable.tendsto_eLpNorm_condExp` -/
theorem Integrable.tendsto_ae_condExp (hg : Integrable g μ)
(hgmeas : StronglyMeasurable[⨆ n, ℱ n] g) :
∀ᵐ x ∂μ, Tendsto (fun n => (μ[g|ℱ n]) x) atTop (𝓝 (g x)) := by
have hle : ⨆ n, ℱ n ≤ m0 := sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _
have hunif : UniformIntegrable (fun n => μ[g|ℱ n]) 1 μ :=
hg.uniformIntegrable_condExp_filtration
obtain ⟨R, hR⟩ := hunif.2.2
have hlimint : Integrable (ℱ.limitProcess (fun n => μ[g|ℱ n]) μ) μ :=
(memLp_limitProcess_of_eLpNorm_bdd hunif.1 hR).integrable le_rfl
suffices g =ᵐ[μ] ℱ.limitProcess (fun n x => (μ[g|ℱ n]) x) μ by
filter_upwards [this, (martingale_condExp g ℱ μ).submartingale.ae_tendsto_limitProcess hR] with
x heq ht
rwa [heq]
have : ∀ n s, MeasurableSet[ℱ n] s →
∫ x in s, g x ∂μ = ∫ x in s, ℱ.limitProcess (fun n x => (μ[g|ℱ n]) x) μ x ∂μ := by
intro n s hs
rw [← setIntegral_condExp (ℱ.le n) hg hs, ← setIntegral_condExp (ℱ.le n) hlimint hs]
refine setIntegral_congr_ae (ℱ.le _ _ hs) ?_
filter_upwards [(martingale_condExp g ℱ μ).ae_eq_condExp_limitProcess hunif n] with x hx _
rw [hx]
refine ae_eq_of_forall_setIntegral_eq_of_sigmaFinite' hle (fun s _ _ => hg.integrableOn)
(fun s _ _ => hlimint.integrableOn) (fun s hs _ => ?_) hgmeas.aestronglyMeasurable
stronglyMeasurable_limitProcess.aestronglyMeasurable
have hpi : IsPiSystem {s | ∃ n, MeasurableSet[ℱ n] s} := by
rw [Set.setOf_exists]
exact isPiSystem_iUnion_of_monotone _ (fun n ↦ (ℱ n).isPiSystem_measurableSet) fun _ _ ↦ ℱ.mono
induction s, hs
using MeasurableSpace.induction_on_inter (MeasurableSpace.measurableSpace_iSup_eq ℱ) hpi with
| empty =>
simp only [Measure.restrict_empty, integral_zero_measure]
| basic s hs =>
rcases hs with ⟨n, hn⟩
exact this n _ hn
| compl t htmeas ht =>
have hgeq := @setIntegral_compl _ _ (⨆ n, ℱ n) _ _ _ _ _ htmeas (hg.trim hle hgmeas)
have hheq := @setIntegral_compl _ _ (⨆ n, ℱ n) _ _ _ _ _ htmeas
(hlimint.trim hle stronglyMeasurable_limitProcess)
rw [setIntegral_trim hle hgmeas htmeas.compl,
setIntegral_trim hle stronglyMeasurable_limitProcess htmeas.compl, hgeq, hheq, ←
setIntegral_trim hle hgmeas htmeas, ←
setIntegral_trim hle stronglyMeasurable_limitProcess htmeas, ← integral_trim hle hgmeas, ←
integral_trim hle stronglyMeasurable_limitProcess, ← setIntegral_univ,
this 0 _ MeasurableSet.univ, setIntegral_univ, ht (measure_lt_top _ _)]
| iUnion f hf hfmeas heq =>
rw [integral_iUnion (fun n => hle _ (hfmeas n)) hf hg.integrableOn,
integral_iUnion (fun n => hle _ (hfmeas n)) hf hlimint.integrableOn]
exact tsum_congr fun n => heq _ (measure_lt_top _ _)
/-- Part c of the **L¹ martingale convergence theorem**: Given an integrable function `g` which
is measurable with respect to `⨆ n, ℱ n` where `ℱ` is a filtration, the martingale defined by
`𝔼[g | ℱ n]` converges in L¹ to `g`.
This martingale also converges to `g` almost everywhere and this result is provided by
`MeasureTheory.Integrable.tendsto_ae_condExp` -/
theorem Integrable.tendsto_eLpNorm_condExp (hg : Integrable g μ)
(hgmeas : StronglyMeasurable[⨆ n, ℱ n] g) :
Tendsto (fun n => eLpNorm (μ[g|ℱ n] - g) 1 μ) atTop (𝓝 0) :=
tendsto_Lp_finite_of_tendstoInMeasure le_rfl ENNReal.one_ne_top
(fun n => (stronglyMeasurable_condExp.mono (ℱ.le n)).aestronglyMeasurable)
(memLp_one_iff_integrable.2 hg) hg.uniformIntegrable_condExp_filtration.2.1
(tendstoInMeasure_of_tendsto_ae
(fun n => (stronglyMeasurable_condExp.mono (ℱ.le n)).aestronglyMeasurable)
(hg.tendsto_ae_condExp hgmeas))
/-- **Lévy's upward theorem**, almost everywhere version: given a function `g` and a filtration
`ℱ`, the sequence defined by `𝔼[g | ℱ n]` converges almost everywhere to `𝔼[g | ⨆ n, ℱ n]`. -/
theorem tendsto_ae_condExp (g : Ω → ℝ) :
∀ᵐ x ∂μ, Tendsto (fun n => (μ[g|ℱ n]) x) atTop (𝓝 ((μ[g|⨆ n, ℱ n]) x)) := by
have ht : ∀ᵐ x ∂μ, Tendsto (fun n => (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x) atTop (𝓝 ((μ[g|⨆ n, ℱ n]) x)) :=
integrable_condExp.tendsto_ae_condExp stronglyMeasurable_condExp
have heq : ∀ n, ∀ᵐ x ∂μ, (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x = (μ[g|ℱ n]) x := fun n =>
condExp_condExp_of_le (le_iSup _ n) (iSup_le fun n => ℱ.le n)
rw [← ae_all_iff] at heq
filter_upwards [heq, ht] with x hxeq hxt
exact hxt.congr hxeq
/-- **Lévy's upward theorem**, L¹ version: given a function `g` and a filtration `ℱ`, the
sequence defined by `𝔼[g | ℱ n]` converges in L¹ to `𝔼[g | ⨆ n, ℱ n]`. -/
theorem tendsto_eLpNorm_condExp (g : Ω → ℝ) :
Tendsto (fun n => eLpNorm (μ[g|ℱ n] - μ[g|⨆ n, ℱ n]) 1 μ) atTop (𝓝 0) := by
have ht : Tendsto (fun n => eLpNorm (μ[μ[g|⨆ n, ℱ n]|ℱ n] - μ[g|⨆ n, ℱ n]) 1 μ) atTop (𝓝 0) :=
integrable_condExp.tendsto_eLpNorm_condExp stronglyMeasurable_condExp
have heq : ∀ n, ∀ᵐ x ∂μ, (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x = (μ[g|ℱ n]) x := fun n =>
condExp_condExp_of_le (le_iSup _ n) (iSup_le fun n => ℱ.le n)
refine ht.congr fun n => eLpNorm_congr_ae ?_
filter_upwards [heq n] with x hxeq
simp only [hxeq, Pi.sub_apply]
end L1Convergence
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Martingale/Upcrossing.lean | import Mathlib.Order.Interval.Set.Monotone
import Mathlib.Probability.Process.HittingTime
import Mathlib.Probability.Martingale.Basic
import Mathlib.Tactic.AdaptationNote
/-!
# Doob's upcrossing estimate
Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the
number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing
estimate (also known as Doob's inequality) states that
$$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$
Doob's upcrossing estimate is an important inequality and is central in proving the martingale
convergence theorems.
## Main definitions
* `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f`
crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is
taken to be `N`).
* `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f`
crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is
taken to be `N`).
* `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is
between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively
one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process
crosses below `a` for the first time after selling and selling 1 share whenever the process
crosses above `b` for the first time after buying.
* `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to
above `b` before time `N`.
* `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above
`b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`.
## Main results
* `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a
stopping time whenever the process it is associated to is adapted.
* `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a
stopping time whenever the process it is associated to is adapted.
* `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's
upcrossing estimate.
* `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality
obtained by taking the supremum on both sides of Doob's upcrossing estimate.
### References
We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021]
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology
namespace MeasureTheory
variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω}
/-!
## Proof outline
In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$
to above $b$ before time $N$.
To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses
below $a$ and above $b$. Namely, we define
$$
\sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N;
$$
$$
\tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N.
$$
These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined
using `MeasureTheory.hittingBtwn` allowing us to specify a starting and ending time.
Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$.
Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that
$0 \le f_0$ and $a \le f_N$. In particular, we will show
$$
(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N].
$$
This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization.
To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$
(i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is
a submartingale if $(f_n)$ is.
Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that
$(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$,
$(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property,
$0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying
$$
\mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0].
$$
Furthermore,
\begin{align}
(C \bullet f)_N & =
\sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\
& = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\
& = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1}
+ \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\
& = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k})
\ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b)
\end{align}
where the inequality follows since for all $k < U_N(a, b)$,
$f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$,
$f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and
$f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have
$$
(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N]
\le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N],
$$
as required.
To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$.
-/
/-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before
time `N`. -/
noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) :
Ω → ι :=
hittingBtwn f (Set.Iic a) c N
/-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches
above `b` after `f` reached below `a` for the `n - 1`-th time. -/
noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)
(N : ι) : ℕ → Ω → ι
| 0 => ⊥
| n + 1 => fun ω =>
hittingBtwn f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω
/-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches
below `a` after `f` reached above `b` for the `n`-th time. -/
noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)
(N : ι) (n : ℕ) : Ω → ι :=
fun ω => hittingBtwn f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω
section
variable [Preorder ι] [OrderBot ι] [InfSet ι]
variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n : ℕ} {ω : Ω}
@[simp]
theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ :=
rfl
@[simp]
theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hittingBtwn f (Set.Iic a) ⊥ N :=
rfl
theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω =
hittingBtwn f (Set.Ici b)
(lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by
rw [upperCrossingTime]
theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω =
hittingBtwn f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by
simp only [upperCrossingTime_succ]
rfl
end
section ConditionallyCompleteLinearOrderBot
variable [ConditionallyCompleteLinearOrderBot ι]
variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω}
theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N := by
cases n
· simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le]
· simp only [upperCrossingTime_succ, hittingBtwn_le]
@[simp]
theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ :=
eq_bot_iff.2 upperCrossingTime_le
theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by
simp only [lowerCrossingTime, hittingBtwn_le ω]
theorem upperCrossingTime_le_lowerCrossingTime :
upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by
simp only [lowerCrossingTime, le_hittingBtwn upperCrossingTime_le ω]
theorem lowerCrossingTime_le_upperCrossingTime_succ :
lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω := by
rw [upperCrossingTime_succ]
exact le_hittingBtwn lowerCrossingTime_le ω
theorem lowerCrossingTime_mono (hnm : n ≤ m) :
lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω := by
suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm
exact monotone_nat_of_le_succ fun n =>
le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime
theorem upperCrossingTime_mono (hnm : n ≤ m) :
upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω := by
suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm
exact monotone_nat_of_le_succ fun n =>
le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ
end ConditionallyCompleteLinearOrderBot
variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω}
theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) :
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N n ω : ℕ)) ω ≤ a := by
obtain ⟨j, hj₁, hj₂⟩ :=
(hittingBtwn_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl
exact stoppedValue_hittingBtwn_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩
theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) :
b ≤ stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (n + 1) ω : ℕ)) ω := by
obtain ⟨j, hj₁, hj₂⟩ :=
(hittingBtwn_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl
exact stoppedValue_hittingBtwn_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hittingBtwn_le _)⟩, hj₂⟩
theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b)
(hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) :
upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by
refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h =>
not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn)
simp only [stoppedValue]
rw [← h]
exact stoppedValue_upperCrossingTime (h.symm ▸ hn)
theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b)
(hn : upperCrossingTime a b f N (n + 1) ω ≠ N) :
lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by
refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h =>
not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_
simp only [stoppedValue]
rw [← h]
exact stoppedValue_lowerCrossingTime (h.symm ▸ hn)
theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) :
upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω :=
lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime
(lowerCrossingTime_lt_upperCrossingTime hab hn)
theorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) :
lowerCrossingTime a b f N m ω = N :=
le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm))
theorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) :
upperCrossingTime a b f N m ω = N :=
le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm))
theorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) :
lowerCrossingTime a b f N m ω = N :=
lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn)
theorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) :
upperCrossingTime a b f N m ω = N :=
upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn)
-- `upperCrossingTime_bound_eq` provides an explicit bound
theorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :
∃ n, upperCrossingTime a b f N n ω = N := by
by_contra! h
have : StrictMono fun n => upperCrossingTime a b f N n ω :=
strictMono_nat_of_lt_succ fun n => upperCrossingTime_lt_succ hab (h _)
obtain ⟨_, ⟨k, rfl⟩, hk⟩ :
∃ (m : _) (_ : m ∈ Set.range fun n => upperCrossingTime a b f N n ω), N < m :=
⟨upperCrossingTime a b f N (N + 1) ω, ⟨N + 1, rfl⟩,
lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩
exact not_le.2 hk upperCrossingTime_le
theorem upperCrossingTime_lt_bddAbove (hab : a < b) :
BddAbove {n | upperCrossingTime a b f N n ω < N} := by
obtain ⟨k, hk⟩ := exists_upperCrossingTime_eq f N ω hab
refine ⟨k, fun n (hn : upperCrossingTime a b f N n ω < N) => ?_⟩
by_contra hn'
exact hn.ne (upperCrossingTime_stabilize (not_le.1 hn').le hk)
theorem upperCrossingTime_lt_nonempty (hN : 0 < N) :
{n | upperCrossingTime a b f N n ω < N}.Nonempty :=
⟨0, hN⟩
theorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :
upperCrossingTime a b f N N ω = N := by
by_cases hN' : N < Nat.find (exists_upperCrossingTime_eq f N ω hab)
· refine le_antisymm upperCrossingTime_le ?_
have hmono : StrictMonoOn (fun n => upperCrossingTime a b f N n ω)
(Set.Iic (Nat.find (exists_upperCrossingTime_eq f N ω hab)).pred) := by
refine strictMonoOn_Iic_of_lt_succ fun m hm => upperCrossingTime_lt_succ hab ?_
rw [Nat.lt_pred_iff] at hm
convert Nat.find_min _ hm
convert StrictMonoOn.Iic_id_le hmono N (Nat.le_sub_one_of_lt hN')
· rw [not_lt] at hN'
exact upperCrossingTime_stabilize hN' (Nat.find_spec (exists_upperCrossingTime_eq f N ω hab))
theorem upperCrossingTime_eq_of_bound_le (hab : a < b) (hn : N ≤ n) :
upperCrossingTime a b f N n ω = N :=
le_antisymm upperCrossingTime_le
(le_trans (upperCrossingTime_bound_eq f N ω hab).symm.le (upperCrossingTime_mono hn))
variable {ℱ : Filtration ℕ m0}
theorem Adapted.isStoppingTime_crossing (hf : Adapted ℱ f) :
IsStoppingTime ℱ (fun ω ↦ (upperCrossingTime a b f N n ω : ℕ)) ∧
IsStoppingTime ℱ (fun ω ↦ (lowerCrossingTime a b f N n ω : ℕ)) := by
induction n with
| zero =>
refine ⟨isStoppingTime_const _ 0, ?_⟩
simp only [lowerCrossingTime_zero, Nat.bot_eq_zero]
exact hittingBtwn_isStoppingTime hf measurableSet_Iic
| succ k ih =>
have : IsStoppingTime ℱ (fun ω ↦ (upperCrossingTime a b f N (k + 1) ω : ℕ)) := by
intro n
simp_rw [upperCrossingTime_succ_eq]
refine isStoppingTime_hittingBtwn_isStoppingTime ih.2 ?_ measurableSet_Ici hf _
simp [lowerCrossingTime_le]
refine ⟨this, fun n ↦ ?_⟩
refine isStoppingTime_hittingBtwn_isStoppingTime this ?_ measurableSet_Iic hf _
simp [upperCrossingTime_le]
theorem Adapted.isStoppingTime_upperCrossingTime (hf : Adapted ℱ f) :
IsStoppingTime ℱ (fun ω ↦ (upperCrossingTime a b f N n ω : ℕ)) :=
hf.isStoppingTime_crossing.1
theorem Adapted.isStoppingTime_lowerCrossingTime (hf : Adapted ℱ f) :
IsStoppingTime ℱ (fun ω ↦ (lowerCrossingTime a b f N n ω : ℕ)) :=
hf.isStoppingTime_crossing.2
/-- `upcrossingStrat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper
crossings and is 0 otherwise. `upcrossingStrat` is shifted by one index so that it is adapted
rather than predictable. -/
noncomputable def upcrossingStrat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ :=
∑ k ∈ Finset.range N,
(Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator 1 n
theorem upcrossingStrat_nonneg : 0 ≤ upcrossingStrat a b f N n ω :=
Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _
theorem upcrossingStrat_le_one : upcrossingStrat a b f N n ω ≤ 1 := by
rw [upcrossingStrat, ← Finset.indicator_biUnion_apply]
· exact Set.indicator_le_self' (fun _ _ => zero_le_one) _
intro i _ j _ hij
simp only [Set.Ico_disjoint_Ico]
obtain hij' | hij' := lt_or_gt_of_ne hij
· rw [min_eq_left (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) :
upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω),
max_eq_right (lowerCrossingTime_mono hij'.le :
lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)]
refine le_trans upperCrossingTime_le_lowerCrossingTime
(lowerCrossingTime_mono (Nat.succ_le_of_lt hij'))
· rw [min_eq_right (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) :
upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω),
max_eq_left (lowerCrossingTime_mono hij'.le :
lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)]
refine le_trans upperCrossingTime_le_lowerCrossingTime
(lowerCrossingTime_mono (Nat.succ_le_of_lt hij'))
theorem Adapted.upcrossingStrat_adapted (hf : Adapted ℱ f) :
Adapted ℱ (upcrossingStrat a b f N) := by
intro n
change StronglyMeasurable[ℱ n] fun ω =>
∑ k ∈ Finset.range N, ({n | lowerCrossingTime a b f N k ω ≤ n} ∩
{n | n < upperCrossingTime a b f N (k + 1) ω}).indicator 1 n
refine Finset.stronglyMeasurable_fun_sum _ fun i _ =>
stronglyMeasurable_const.indicator ?_
have hl := hf.isStoppingTime_lowerCrossingTime (a := a) (b := b) (N := N) (n := i) n
have hu := hf.isStoppingTime_upperCrossingTime (a := a) (b := b) (N := N) (n := i + 1) n
simp only [ENat.some_eq_coe, Nat.cast_le] at hl hu
simp_rw [← not_le]
exact hl.inter hu.compl
theorem Submartingale.sum_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ =>
∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)) ℱ μ :=
hf.sum_mul_sub hf.adapted.upcrossingStrat_adapted (fun _ _ => upcrossingStrat_le_one) fun _ _ =>
upcrossingStrat_nonneg
theorem Submartingale.sum_sub_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ =>
∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)) ℱ μ := by
refine hf.sum_mul_sub (fun n => (adapted_const ℱ 1 n).sub (hf.adapted.upcrossingStrat_adapted n))
(?_ : ∀ n ω, (1 - upcrossingStrat a b f N n) ω ≤ 1) ?_
· exact fun n ω => sub_le_self _ upcrossingStrat_nonneg
· intro n ω
simp [upcrossingStrat_le_one]
theorem Submartingale.sum_mul_upcrossingStrat_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) :
μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] ≤ μ[f n] - μ[f 0] := by
have h₁ : (0 : ℝ) ≤
μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] := by
have := (hf.sum_sub_upcrossingStrat_mul a b N).setIntegral_le (zero_le n) MeasurableSet.univ
rw [setIntegral_univ, setIntegral_univ] at this
refine le_trans ?_ this
simp only [Finset.range_zero, Finset.sum_empty, integral_zero', le_refl]
have h₂ : μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] =
μ[∑ k ∈ Finset.range n, (f (k + 1) - f k)] -
μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by
simp only [sub_mul, one_mul, Finset.sum_sub_distrib, Pi.sub_apply, Finset.sum_apply,
Pi.mul_apply]
refine integral_sub (Integrable.sub (integrable_finset_sum _ fun i _ => hf.integrable _)
(integrable_finset_sum _ fun i _ => hf.integrable _)) ?_
convert (hf.sum_upcrossingStrat_mul a b N).integrable n using 1
ext; simp
rw [h₂, sub_nonneg] at h₁
refine le_trans h₁ ?_
simp_rw [Finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _), le_refl]
/-- The number of upcrossings (strictly) before time `N`. -/
noncomputable def upcrossingsBefore [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)
(N : ι) (ω : Ω) : ℕ :=
sSup {n | upperCrossingTime a b f N n ω < N}
@[simp]
theorem upcrossingsBefore_bot [Preorder ι] [OrderBot ι] [InfSet ι] {a b : ℝ} {f : ι → Ω → ℝ}
{ω : Ω} : upcrossingsBefore a b f ⊥ ω = ⊥ := by simp [upcrossingsBefore]
theorem upcrossingsBefore_zero : upcrossingsBefore a b f 0 ω = 0 := by simp [upcrossingsBefore]
@[simp]
theorem upcrossingsBefore_zero' : upcrossingsBefore a b f 0 = 0 := by
ext ω; exact upcrossingsBefore_zero
theorem upperCrossingTime_lt_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b)
(hn : n ≤ upcrossingsBefore a b f N ω) : upperCrossingTime a b f N n ω < N :=
haveI : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N :=
(upperCrossingTime_lt_nonempty hN).csSup_mem
((OrderBot.bddBelow _).finite_of_bddAbove (upperCrossingTime_lt_bddAbove hab))
lt_of_le_of_lt (upperCrossingTime_mono hn) this
theorem upperCrossingTime_eq_of_upcrossingsBefore_lt (hab : a < b)
(hn : upcrossingsBefore a b f N ω < n) : upperCrossingTime a b f N n ω = N := by
refine le_antisymm upperCrossingTime_le (not_lt.1 ?_)
convert notMem_of_csSup_lt hn (upperCrossingTime_lt_bddAbove hab) using 1
theorem upcrossingsBefore_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) :
upcrossingsBefore a b f N ω ≤ N := by
by_cases hN : N = 0
· subst hN
rw [upcrossingsBefore_zero]
· refine csSup_le ⟨0, zero_lt_iff.2 hN⟩ fun n (hn : _ < N) => ?_
by_contra hnN
exact hn.ne (upperCrossingTime_eq_of_bound_le hab (not_le.1 hnN).le)
theorem crossing_eq_crossing_of_lowerCrossingTime_lt {M : ℕ} (hNM : N ≤ M)
(h : lowerCrossingTime a b f N n ω < N) :
upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω ∧
lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by
have h' : upperCrossingTime a b f N n ω < N :=
lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime h
induction n with
| zero =>
simp only [upperCrossingTime_zero, bot_eq_zero',
lowerCrossingTime_zero, true_and, eq_comm]
refine hittingBtwn_eq_hittingBtwn_of_exists hNM ?_
rw [lowerCrossingTime, hittingBtwn_lt_iff] at h
· obtain ⟨j, hj₁, hj₂⟩ := h
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩
· exact le_rfl
| succ k ih =>
specialize ih (lt_of_le_of_lt (lowerCrossingTime_mono (Nat.le_succ _)) h)
(lt_of_le_of_lt (upperCrossingTime_mono (Nat.le_succ _)) h')
have : upperCrossingTime a b f M k.succ ω = upperCrossingTime a b f N k.succ ω := by
rw [upperCrossingTime_succ_eq, hittingBtwn_lt_iff] at h'
· simp only [upperCrossingTime_succ_eq]
obtain ⟨j, hj₁, hj₂⟩ := h'
rw [eq_comm, ih.2]
exact hittingBtwn_eq_hittingBtwn_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩
· exact le_rfl
refine ⟨this, ?_⟩
simp only [lowerCrossingTime, eq_comm, this, Nat.succ_eq_add_one]
refine hittingBtwn_eq_hittingBtwn_of_exists hNM ?_
rw [lowerCrossingTime, hittingBtwn_lt_iff _ le_rfl] at h
obtain ⟨j, hj₁, hj₂⟩ := h
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩
theorem crossing_eq_crossing_of_upperCrossingTime_lt {M : ℕ} (hNM : N ≤ M)
(h : upperCrossingTime a b f N (n + 1) ω < N) :
upperCrossingTime a b f M (n + 1) ω = upperCrossingTime a b f N (n + 1) ω ∧
lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by
have := (crossing_eq_crossing_of_lowerCrossingTime_lt hNM
(lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ h)).2
refine ⟨?_, this⟩
rw [upperCrossingTime_succ_eq, upperCrossingTime_succ_eq, eq_comm, this]
refine hittingBtwn_eq_hittingBtwn_of_exists hNM ?_
rw [upperCrossingTime_succ_eq, hittingBtwn_lt_iff] at h
· obtain ⟨j, hj₁, hj₂⟩ := h
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩
· exact le_rfl
theorem upperCrossingTime_eq_upperCrossingTime_of_lt {M : ℕ} (hNM : N ≤ M)
(h : upperCrossingTime a b f N n ω < N) :
upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω := by
cases n
· simp
· exact (crossing_eq_crossing_of_upperCrossingTime_lt hNM h).1
theorem upcrossingsBefore_mono (hab : a < b) : Monotone fun N ω => upcrossingsBefore a b f N ω := by
intro N M hNM ω
simp only [upcrossingsBefore]
gcongr sSup {n | ?_} with n
· exact upperCrossingTime_lt_bddAbove hab
intro hn
rw [upperCrossingTime_eq_upperCrossingTime_of_lt hNM hn]
exact lt_of_lt_of_le hn hNM
theorem upcrossingsBefore_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ} (hN₁ : N ≤ N₁)
(hN₁' : f N₁ ω < a) (hN₂ : N₁ ≤ N₂) (hN₂' : b < f N₂ ω) :
upcrossingsBefore a b f N ω < upcrossingsBefore a b f (N₂ + 1) ω := by
refine lt_of_lt_of_le (Nat.lt_succ_self _) (le_csSup (upperCrossingTime_lt_bddAbove hab) ?_)
rw [Set.mem_setOf_eq, upperCrossingTime_succ_eq, hittingBtwn_lt_iff _ le_rfl]
refine ⟨N₂, ⟨?_, Nat.lt_succ_self _⟩, hN₂'.le⟩
rw [lowerCrossingTime, hittingBtwn_le_iff_of_lt _ (Nat.lt_succ_self _)]
refine ⟨N₁, ⟨le_trans ?_ hN₁, hN₂⟩, hN₁'.le⟩
by_cases! hN : 0 < N
· have : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N :=
Nat.sSup_mem (upperCrossingTime_lt_nonempty hN) (upperCrossingTime_lt_bddAbove hab)
rw [upperCrossingTime_eq_upperCrossingTime_of_lt (hN₁.trans (hN₂.trans <| Nat.le_succ _))
this]
exact this.le
· rw [Nat.le_zero] at hN
rw [hN, upcrossingsBefore_zero, upperCrossingTime_zero, Pi.bot_apply, bot_eq_zero']
theorem lowerCrossingTime_lt_of_lt_upcrossingsBefore (hN : 0 < N) (hab : a < b)
(hn : n < upcrossingsBefore a b f N ω) : lowerCrossingTime a b f N n ω < N :=
lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ
(upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn)
theorem le_sub_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b)
(hn : n < upcrossingsBefore a b f N ω) :
b - a ≤ stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (n + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N n ω : ℕ)) ω :=
sub_le_sub
(stoppedValue_upperCrossingTime (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn).ne)
(stoppedValue_lowerCrossingTime (lowerCrossingTime_lt_of_lt_upcrossingsBefore hN hab hn).ne)
theorem sub_eq_zero_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) :
stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (n + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N n ω : ℕ)) ω = 0 := by
have : N ≤ upperCrossingTime a b f N n ω := by
rw [upcrossingsBefore] at hn
rw [← not_lt]
exact fun h => not_le.2 hn (le_csSup (upperCrossingTime_lt_bddAbove hab) h)
simp [stoppedValue, upperCrossingTime_stabilize' (Nat.le_succ n) this,
lowerCrossingTime_stabilize' le_rfl (le_trans this upperCrossingTime_le_lowerCrossingTime)]
theorem mul_upcrossingsBefore_le (hf : a ≤ f N ω) (hab : a < b) :
(b - a) * upcrossingsBefore a b f N ω ≤
∑ k ∈ Finset.range N, upcrossingStrat a b f N k ω * (f (k + 1) - f k) ω := by
classical
by_cases hN : N = 0
· simp [hN]
simp_rw [upcrossingStrat, Finset.sum_mul, ←
Set.indicator_mul_left _ _ (fun x ↦ (f (x + 1) - f x) ω), Pi.one_apply, Pi.sub_apply, one_mul]
rw [Finset.sum_comm]
have h₁ : ∀ k, ∑ n ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω)
(upperCrossingTime a b f N (k + 1) ω)).indicator (fun m => f (m + 1) ω - f m ω) n =
stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (k + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N k ω : ℕ)) ω := by
intro k
rw [Finset.sum_indicator_eq_sum_filter, (_ : Finset.filter (fun i => i ∈ Set.Ico
(lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)) (Finset.range N) =
Finset.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)),
Finset.sum_Ico_eq_add_neg _ lowerCrossingTime_le_upperCrossingTime_succ,
Finset.sum_range_sub fun n => f n ω, Finset.sum_range_sub fun n => f n ω, neg_sub,
sub_add_sub_cancel]
· rfl
· ext i
simp only [Set.mem_Ico, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico,
and_iff_right_iff_imp, and_imp]
exact fun _ h => lt_of_lt_of_le h upperCrossingTime_le
simp_rw [h₁]
have h₂ : ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤
∑ k ∈ Finset.range N, (stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (k + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N k ω : ℕ)) ω) := by
calc
∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤
∑ k ∈ Finset.range (upcrossingsBefore a b f N ω),
(stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (k + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N k ω : ℕ)) ω) := by
gcongr ∑ k ∈ _, ?_ with i hi
refine le_sub_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab ?_
rwa [Finset.mem_range] at hi
_ ≤ ∑ k ∈ Finset.range N,
(stoppedValue f (fun ω ↦ (upperCrossingTime a b f N (k + 1) ω : ℕ)) ω -
stoppedValue f (fun ω ↦ (lowerCrossingTime a b f N k ω : ℕ)) ω) := by
refine Finset.sum_le_sum_of_subset_of_nonneg
(Finset.range_subset_range.2 (upcrossingsBefore_le f ω hab)) fun i _ hi => ?_
by_cases hi' : i = upcrossingsBefore a b f N ω
· subst hi'
simp only [stoppedValue]
rw [upperCrossingTime_eq_of_upcrossingsBefore_lt hab (Nat.lt_succ_self _)]
by_cases heq : lowerCrossingTime a b f N (upcrossingsBefore a b f N ω) ω = N
· rw [heq, sub_self]
· rw [sub_nonneg]
exact le_trans (stoppedValue_lowerCrossingTime heq) hf
· rw [sub_eq_zero_of_upcrossingsBefore_lt hab]
rw [Finset.mem_range, not_lt] at hi
exact lt_of_le_of_ne hi (Ne.symm hi')
refine le_trans ?_ h₂
rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_comm]
theorem integral_mul_upcrossingsBefore_le_integral [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)
(hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) :
(b - a) * μ[upcrossingsBefore a b f N] ≤ μ[f N] :=
calc
(b - a) * μ[upcrossingsBefore a b f N] ≤
μ[∑ k ∈ Finset.range N, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by
rw [← integral_const_mul]
refine integral_mono_of_nonneg ?_ ((hf.sum_upcrossingStrat_mul a b N).integrable N) ?_
· exact Eventually.of_forall fun ω => mul_nonneg (sub_nonneg.2 hab.le) (Nat.cast_nonneg _)
· filter_upwards with ω
simpa using mul_upcrossingsBefore_le (hfN ω) hab
_ ≤ μ[f N] - μ[f 0] := hf.sum_mul_upcrossingStrat_le
_ ≤ μ[f N] := (sub_le_self_iff _).2 (integral_nonneg hfzero)
theorem crossing_pos_eq (hab : a < b) :
upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = upperCrossingTime a b f N n ∧
lowerCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = lowerCrossingTime a b f N n := by
have hab' : 0 < b - a := sub_pos.2 hab
have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω := by
intro i ω
refine ⟨fun h => ?_, fun h => ?_⟩
· rwa [← sub_le_sub_iff_right a, ←
posPart_eq_of_posPart_pos (lt_of_lt_of_le hab' h)]
· rw [← sub_le_sub_iff_right a] at h
rwa [posPart_eq_self.2 (le_trans hab'.le h)]
have hf' (ω i) : (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a := by rw [posPart_nonpos, sub_nonpos]
induction n with
| zero =>
refine ⟨rfl, ?_⟩
simp +unfoldPartialApp only [lowerCrossingTime_zero, hittingBtwn,
Set.mem_Icc, Set.mem_Iic]
simp_all
| succ k ih =>
have : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N (k + 1) =
upperCrossingTime a b f N (k + 1) := by
ext ω
simp only [upperCrossingTime_succ_eq, ← ih.2, hittingBtwn, Set.mem_Ici, tsub_le_iff_right]
split_ifs with h₁ h₂ h₂
· simp_rw [← sub_le_iff_le_add, hf ω]
· refine False.elim (h₂ ?_)
simp_all only [Set.mem_Ici, not_true_eq_false]
· refine False.elim (h₁ ?_)
simp_all only [Set.mem_Ici]
· rfl
refine ⟨this, ?_⟩
ext ω
simp only [lowerCrossingTime, this, hittingBtwn, Set.mem_Iic]
split_ifs with h₁ h₂ h₂
· simp_rw [hf' ω]
· refine False.elim (h₂ ?_)
simp_all only [Set.mem_Iic, not_true_eq_false]
· refine False.elim (h₁ ?_)
simp_all only [Set.mem_Iic]
· rfl
theorem upcrossingsBefore_pos_eq (hab : a < b) :
upcrossingsBefore 0 (b - a) (fun n ω => (f n ω - a)⁺) N ω = upcrossingsBefore a b f N ω := by
simp_rw [upcrossingsBefore, (crossing_pos_eq hab).1]
theorem mul_integral_upcrossingsBefore_le_integral_pos_part_aux [IsFiniteMeasure μ]
(hf : Submartingale f ℱ μ) (hab : a < b) :
(b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by
refine le_trans (le_of_eq ?_)
(integral_mul_upcrossingsBefore_le_integral (hf.sub_martingale (martingale_const _ _ _)).pos
(fun ω => posPart_nonneg _)
(fun ω => posPart_nonneg _) (sub_pos.2 hab))
simp_rw [sub_zero, ← upcrossingsBefore_pos_eq hab]
rfl
/-- **Doob's upcrossing estimate**: given a real-valued discrete submartingale `f` and real
values `a` and `b`, we have `(b - a) * 𝔼[upcrossingsBefore a b f N] ≤ 𝔼[(f N - a)⁺]` where
`upcrossingsBefore a b f N` is the number of times the process `f` crossed from below `a` to above
`b` before the time `N`. -/
theorem Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part [IsFiniteMeasure μ]
(a b : ℝ) (hf : Submartingale f ℱ μ) (N : ℕ) :
(b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by
by_cases! hab : a < b
· exact mul_integral_upcrossingsBefore_le_integral_pos_part_aux hf hab
· rw [← sub_nonpos] at hab
exact le_trans (mul_nonpos_of_nonpos_of_nonneg hab (by positivity))
(integral_nonneg fun ω => posPart_nonneg _)
/-!
### Variant of the upcrossing estimate
Now, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum
over $N$ of the original upcrossing estimate. Namely, we want the inequality
$$
(b - a) \sup_N \mathbb{E}[U_N(a, b)] \le \sup_N \mathbb{E}[f_N].
$$
This inequality is central for the martingale convergence theorem as it provides a uniform bound
for the upcrossings.
We note that on top of taking the supremum on both sides of the inequality, we had also used
the monotone convergence theorem on the left-hand side to take the supremum outside of the
integral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability
is easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by
noting that
$$
U_N(a, b) = \sum_{i = 1}^N \mathbf{1}_{\{U_N(a, b) < N\}}
$$
$U_N(a, b)$ is measurable as $\{U_N(a, b) < N\}$ is a measurable set since $U_N(a, b)$ is a
stopping time.
-/
theorem upcrossingsBefore_eq_sum (hab : a < b) : upcrossingsBefore a b f N ω =
∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by
by_cases hN : N = 0
· simp [hN]
rw [← Finset.sum_Ico_consecutive _ (Nat.succ_le_succ zero_le')
(Nat.succ_le_succ (upcrossingsBefore_le f ω hab))]
have h₁ : ∀ k ∈ Finset.Ico 1 (upcrossingsBefore a b f N ω + 1),
{n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 1 := by
rintro k hk
rw [Finset.mem_Ico] at hk
rw [Set.indicator_of_mem]
· rfl
· exact upperCrossingTime_lt_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab
(Nat.lt_succ_iff.1 hk.2)
have h₂ : ∀ k ∈ Finset.Ico (upcrossingsBefore a b f N ω + 1) (N + 1),
{n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 0 := by
rintro k hk
rw [Finset.mem_Ico, Nat.succ_le_iff] at hk
rw [Set.indicator_of_notMem]
simp only [Set.mem_setOf_eq, not_lt]
exact (upperCrossingTime_eq_of_upcrossingsBefore_lt hab hk.1).symm.le
rw [Finset.sum_congr rfl h₁, Finset.sum_congr rfl h₂, Finset.sum_const, Finset.sum_const,
smul_eq_mul, mul_one, smul_eq_mul, mul_zero, Nat.card_Ico, Nat.add_succ_sub_one,
add_zero, add_zero]
theorem Adapted.measurable_upcrossingsBefore (hf : Adapted ℱ f) (hab : a < b) :
Measurable (upcrossingsBefore a b f N) := by
have : upcrossingsBefore a b f N = fun ω =>
∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by
ext ω
exact upcrossingsBefore_eq_sum hab
rw [this]
refine Finset.measurable_fun_sum _ fun i _ => Measurable.indicator measurable_const <|
ℱ.le N _ ?_
simpa only [ENat.some_eq_coe, Nat.cast_lt] using
hf.isStoppingTime_upperCrossingTime.measurableSet_lt_of_pred N
theorem Adapted.integrable_upcrossingsBefore [IsFiniteMeasure μ] (hf : Adapted ℱ f) (hab : a < b) :
Integrable (fun ω => (upcrossingsBefore a b f N ω : ℝ)) μ :=
haveI : ∀ᵐ ω ∂μ, ‖(upcrossingsBefore a b f N ω : ℝ)‖ ≤ N := by
filter_upwards with ω
rw [Real.norm_eq_abs, Nat.abs_cast, Nat.cast_le]
exact upcrossingsBefore_le _ _ hab
⟨Measurable.aestronglyMeasurable (measurable_from_top.comp (hf.measurable_upcrossingsBefore hab)),
.of_bounded this⟩
/-- The number of upcrossings of a realization of a stochastic process (`upcrossings` takes value
in `ℝ≥0∞` and so is allowed to be `∞`). -/
noncomputable def upcrossings [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)
(ω : Ω) : ℝ≥0∞ :=
⨆ N, (upcrossingsBefore a b f N ω : ℝ≥0∞)
theorem Adapted.measurable_upcrossings (hf : Adapted ℱ f) (hab : a < b) :
Measurable (upcrossings a b f) :=
.iSup fun _ => measurable_from_top.comp (hf.measurable_upcrossingsBefore hab)
theorem upcrossings_lt_top_iff :
upcrossings a b f ω < ∞ ↔ ∃ k, ∀ N, upcrossingsBefore a b f N ω ≤ k := by
have : upcrossings a b f ω < ∞ ↔ ∃ k : ℝ≥0, upcrossings a b f ω ≤ k := by
constructor
· intro h
lift upcrossings a b f ω to ℝ≥0 using h.ne with r hr
exact ⟨r, le_rfl⟩
· rintro ⟨k, hk⟩
exact lt_of_le_of_lt hk ENNReal.coe_lt_top
simp_rw [this, upcrossings, iSup_le_iff]
constructor <;> rintro ⟨k, hk⟩
· obtain ⟨m, hm⟩ := exists_nat_ge k
refine ⟨m, fun N => Nat.cast_le.1 ((hk N).trans ?_)⟩
rwa [← ENNReal.coe_natCast, ENNReal.coe_le_coe]
· refine ⟨k, fun N => ?_⟩
simp only [ENNReal.coe_natCast, Nat.cast_le, hk N]
/-- A variant of Doob's upcrossing estimate obtained by taking the supremum on both sides. -/
theorem Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part [IsFiniteMeasure μ] (a b : ℝ)
(hf : Submartingale f ℱ μ) : ENNReal.ofReal (b - a) * ∫⁻ ω, upcrossings a b f ω ∂μ ≤
⨆ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ := by
by_cases! hab : a < b
· simp_rw [upcrossings]
have : ∀ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ = ENNReal.ofReal (∫ ω, (f N ω - a)⁺ ∂μ) := by
intro N
rw [ofReal_integral_eq_lintegral_ofReal]
· exact (hf.sub_martingale (martingale_const _ _ _)).pos.integrable _
· exact Eventually.of_forall fun ω => posPart_nonneg _
rw [lintegral_iSup']
· simp_rw [this, ENNReal.mul_iSup, iSup_le_iff]
intro N
rw [(by simp :
∫⁻ ω, upcrossingsBefore a b f N ω ∂μ = ∫⁻ ω, ↑(upcrossingsBefore a b f N ω : ℝ≥0) ∂μ),
lintegral_coe_eq_integral, ← ENNReal.ofReal_mul (sub_pos.2 hab).le]
· simp_rw [NNReal.coe_natCast]
exact (ENNReal.ofReal_le_ofReal
(hf.mul_integral_upcrossingsBefore_le_integral_pos_part a b N)).trans
(le_iSup (α := ℝ≥0∞) _ N)
· simp only [NNReal.coe_natCast, hf.adapted.integrable_upcrossingsBefore hab]
· exact fun n => measurable_from_top.comp_aemeasurable
(hf.adapted.measurable_upcrossingsBefore hab).aemeasurable
· filter_upwards with ω N M hNM
rw [Nat.cast_le]
exact upcrossingsBefore_mono hab hNM ω
· rw [← sub_nonpos] at hab
rw [ENNReal.ofReal_of_nonpos hab, zero_mul]
exact zero_le _
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Gamma.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.CDF
import Mathlib.Analysis.SpecialFunctions.Gamma.Basic
/-! # Gamma distributions over ℝ
Define the gamma measure over the reals.
## Main definitions
* `gammaPDFReal`: the function `a r x ↦ r ^ a / (Gamma a) * x ^ (a - 1) * exp (-(r * x))`
for `0 ≤ x` or `0` else, which is the probability density function of a gamma distribution with
shape `a` and rate `r` (when `ha : 0 < a ` and `hr : 0 < r`).
* `gammaPDF`: `ℝ≥0∞`-valued pdf,
`gammaPDF a r = ENNReal.ofReal (gammaPDFReal a r)`.
* `gammaMeasure`: a gamma measure on `ℝ`, parametrized by its shape `a` and rate `r`.
-/
open scoped ENNReal NNReal
open MeasureTheory Real Set Filter Topology
/-- A Lebesgue Integral from -∞ to y can be expressed as the sum of one from -∞ to 0 and 0 to x -/
lemma lintegral_Iic_eq_lintegral_Iio_add_Icc {y z : ℝ} (f : ℝ → ℝ≥0∞) (hzy : z ≤ y) :
∫⁻ x in Iic y, f x = (∫⁻ x in Iio z, f x) + ∫⁻ x in Icc z y, f x := by
rw [← Iio_union_Icc_eq_Iic hzy, lintegral_union measurableSet_Icc]
simp_rw [Set.disjoint_iff_forall_ne, mem_Iio, mem_Icc]
intros
linarith
namespace ProbabilityTheory
section GammaPDF
/-- The pdf of the gamma distribution depending on its scale and rate -/
noncomputable
def gammaPDFReal (a r x : ℝ) : ℝ :=
if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a - 1) * exp (-(r * x)) else 0
/-- The pdf of the gamma distribution, as a function valued in `ℝ≥0∞` -/
noncomputable
def gammaPDF (a r x : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (gammaPDFReal a r x)
lemma gammaPDF_eq (a r x : ℝ) :
gammaPDF a r x =
ENNReal.ofReal (if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a - 1) * exp (-(r * x)) else 0) :=
rfl
lemma gammaPDF_of_neg {a r x : ℝ} (hx : x < 0) : gammaPDF a r x = 0 := by
simp only [gammaPDF_eq, if_neg (not_le.mpr hx), ENNReal.ofReal_zero]
lemma gammaPDF_of_nonneg {a r x : ℝ} (hx : 0 ≤ x) :
gammaPDF a r x = ENNReal.ofReal (r ^ a / (Gamma a) * x ^ (a - 1) * exp (-(r * x))) := by
simp only [gammaPDF_eq, if_pos hx]
/-- The Lebesgue integral of the gamma pdf over nonpositive reals equals 0 -/
lemma lintegral_gammaPDF_of_nonpos {x a r : ℝ} (hx : x ≤ 0) :
∫⁻ y in Iio x, gammaPDF a r y = 0 := by
rw [setLIntegral_congr_fun (g := fun _ ↦ 0) measurableSet_Iio]
· rw [lintegral_zero, ← ENNReal.ofReal_zero]
· intro a (_ : a < _)
simp only [gammaPDF_eq, ENNReal.ofReal_eq_zero]
rw [if_neg (by linarith)]
/-- The gamma pdf is measurable. -/
@[fun_prop, measurability]
lemma measurable_gammaPDFReal (a r : ℝ) : Measurable (gammaPDFReal a r) :=
Measurable.ite measurableSet_Ici (((measurable_id'.pow_const _).const_mul _).mul
(measurable_id'.const_mul _).neg.exp) measurable_const
/-- The gamma pdf is strongly measurable -/
@[fun_prop, measurability]
lemma stronglyMeasurable_gammaPDFReal (a r : ℝ) :
StronglyMeasurable (gammaPDFReal a r) :=
(measurable_gammaPDFReal a r).stronglyMeasurable
/-- The gamma pdf is positive for all positive reals -/
lemma gammaPDFReal_pos {x a r : ℝ} (ha : 0 < a) (hr : 0 < r) (hx : 0 < x) :
0 < gammaPDFReal a r x := by
simp only [gammaPDFReal, if_pos hx.le]
positivity
/-- The gamma pdf is nonnegative -/
lemma gammaPDFReal_nonneg {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) :
0 ≤ gammaPDFReal a r x := by
unfold gammaPDFReal
split_ifs <;> positivity
open Measure
/-- The pdf of the gamma distribution integrates to 1 -/
@[simp]
lemma lintegral_gammaPDF_eq_one {a r : ℝ} (ha : 0 < a) (hr : 0 < r) :
∫⁻ x, gammaPDF a r x = 1 := by
have leftSide : ∫⁻ x in Iio 0, gammaPDF a r x = 0 := by
rw [setLIntegral_congr_fun measurableSet_Iio
(fun x (hx : x < 0) ↦ gammaPDF_of_neg hx), lintegral_zero]
have rightSide : ∫⁻ x in Ici 0, gammaPDF a r x =
∫⁻ x in Ici 0, ENNReal.ofReal (r ^ a / Gamma a * x ^ (a - 1) * exp (-(r * x))) :=
setLIntegral_congr_fun measurableSet_Ici (fun _ ↦ gammaPDF_of_nonneg)
rw [← ENNReal.toReal_eq_one_iff, ← lintegral_add_compl _ measurableSet_Ici, compl_Ici,
leftSide, rightSide, add_zero, ← integral_eq_lintegral_of_nonneg_ae]
· simp_rw [integral_Ici_eq_integral_Ioi, mul_assoc]
rw [integral_const_mul, integral_rpow_mul_exp_neg_mul_Ioi ha hr, div_mul_eq_mul_div,
← mul_assoc, mul_div_assoc, div_self (Gamma_pos_of_pos ha).ne', mul_one,
div_rpow zero_le_one hr.le, one_rpow, mul_one_div, div_self (rpow_pos_of_pos hr _).ne']
· rw [EventuallyLE, ae_restrict_iff' measurableSet_Ici]
exact ae_of_all _ (fun x (hx : 0 ≤ x) ↦ by positivity)
· apply (measurable_gammaPDFReal a r).aestronglyMeasurable.congr
refine (ae_restrict_iff' measurableSet_Ici).mpr <| ae_of_all _ fun x (hx : 0 ≤ x) ↦ ?_
simp_rw [gammaPDFReal, eq_true_intro hx, ite_true]
end GammaPDF
open MeasureTheory
/-- Measure defined by the gamma distribution -/
noncomputable
def gammaMeasure (a r : ℝ) : Measure ℝ :=
volume.withDensity (gammaPDF a r)
lemma isProbabilityMeasure_gammaMeasure {a r : ℝ} (ha : 0 < a) (hr : 0 < r) :
IsProbabilityMeasure (gammaMeasure a r) where
measure_univ := by simp [gammaMeasure, lintegral_gammaPDF_eq_one ha hr]
@[deprecated (since := "2025-08-28")] alias isProbabilityMeasureGamma :=
isProbabilityMeasure_gammaMeasure
section GammaCDF
/-- CDF of the gamma distribution -/
@[deprecated "Use `cdf (gammaMeasure a r)` instead." (since := "2025-08-28")]
noncomputable
def gammaCDFReal (a r : ℝ) : StieltjesFunction :=
cdf (gammaMeasure a r)
lemma cdf_gammaMeasure_eq_integral {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) :
cdf (gammaMeasure a r) x = ∫ x in Iic x, gammaPDFReal a r x := by
have : IsProbabilityMeasure (gammaMeasure a r) := isProbabilityMeasure_gammaMeasure ha hr
rw [cdf_eq_real, gammaMeasure, measureReal_def, withDensity_apply _ measurableSet_Iic]
refine (integral_eq_lintegral_of_nonneg_ae ?_ ?_).symm
· exact ae_of_all _ fun b ↦ by simp [gammaPDFReal_nonneg ha hr]
· fun_prop
@[deprecated (since := "2025-08-28")] alias gammaCDFReal_eq_integral :=
cdf_gammaMeasure_eq_integral
lemma cdf_gammaMeasure_eq_lintegral {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) :
cdf (gammaMeasure a r) x = ENNReal.toReal (∫⁻ x in Iic x, gammaPDF a r x) := by
have : IsProbabilityMeasure (gammaMeasure a r) := isProbabilityMeasure_gammaMeasure ha hr
simp only [gammaPDF, cdf_eq_real]
simp [gammaMeasure, gammaPDF, measureReal_def]
@[deprecated (since := "2025-08-28")] alias gammaCDFReal_eq_lintegral :=
cdf_gammaMeasure_eq_lintegral
end GammaCDF
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Gaussian.lean | import Mathlib.Probability.Distributions.Gaussian.Real
deprecated_module (since := "2025-05-16") |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Uniform.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.Density
import Mathlib.Probability.ConditionalProbability
import Mathlib.Probability.ProbabilityMassFunction.Constructions
/-!
# Uniform distributions and probability mass functions
This file defines two related notions of uniform distributions, which will be unified in the future.
## Uniform distributions
Defines the uniform distribution for any set with finite measure.
### Main definitions
* `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the
push-forward measure agrees with the rescaled restricted measure `μ`.
## Uniform probability mass functions
This file defines a number of uniform `PMF` distributions from various inputs,
uniformly drawing from the corresponding object.
### Main definitions
`PMF.uniformOfFinset` gives each element in the set equal probability,
with `0` probability for elements not in the set.
`PMF.uniformOfFintype` gives all elements equal probability,
equal to the inverse of the size of the `Fintype`.
`PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct.
Each probability is given by the count of the element divided by the size of the `Multiset`
## TODO
* Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`.
-/
open scoped Finset MeasureTheory NNReal ENNReal
-- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` scope :(
open TopologicalSpace MeasureTheory.Measure PMF
noncomputable section
namespace MeasureTheory
variable {E : Type*} [MeasurableSpace E] {μ : Measure E}
namespace pdf
variable {Ω : Type*}
variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
/-- A random variable `X` has uniform distribution on `s` if its push-forward measure is
`(μ s)⁻¹ • μ.restrict s`. -/
def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :=
map X ℙ = ProbabilityTheory.cond μ s
namespace IsUniform
theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by
dsimp [IsUniform, ProbabilityTheory.cond] at hu
by_contra h
rw [map_of_not_aemeasurable h] at hu
apply zero_ne_one' ℝ≥0∞
calc
0 = (0 : Measure E) Set.univ := rfl
_ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ,
Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt]
theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by
rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous
theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) :
ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by
rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply',
ENNReal.div_eq_inv_mul]
theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ :=
⟨by
have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ
rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ,
ENNReal.div_self hns hnt]⟩
theorem toMeasurable_iff {X : Ω → E} {s : Set E} :
IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by
unfold IsUniform
rw [ProbabilityTheory.cond_toMeasurable_eq]
protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) :
IsUniform X (toMeasurable μ s) ℙ μ := by
unfold IsUniform at *
rwa [ProbabilityTheory.cond_toMeasurable_eq]
theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
let t := toMeasurable μ s
apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <|
(measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s)
rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one,
withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond]
theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E}
(hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by
rcases hμs with H|H
· simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H,
smul_zero] at hu
simp [pdf, hu]
· simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu
simp [pdf, hu]
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
(hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
by_cases hnt : μ s = ∞
· simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt]
by_cases hns : μ s = 0
· filter_upwards [measure_eq_zero_iff_ae_notMem.mp hns,
pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x
simp [hx, h'x, hns]
have : HasPDF X ℙ μ := hasPDF hns hnt hu
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
apply (eq_of_map_eq_withDensity _ _).mp
· rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one,
ProbabilityTheory.cond]
· exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
(hX : IsUniform X s ℙ μ) :
(fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x =>
(s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal :=
Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal
variable {X : Ω → ℝ} {s : Set ℝ}
theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
by_cases hnt : volume s = 0 ∨ volume s = ∞
· have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp
apply I.congr
filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx
simp [hx]
simp only [not_or] at hnt
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX
constructor
· exact aestronglyMeasurable_id.mul
(measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_
set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
have : ∀ x, ‖x‖ₑ * s.indicator ind x = s.indicator (fun x => ‖x‖ₑ * ind x) x := fun x =>
(s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
simp only [ind, this, lintegral_indicator hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul,
Pi.one_apply, Pi.smul_apply]
rw [lintegral_mul_const _ measurable_enorm]
exact ENNReal.mul_ne_top (setLIntegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne
(ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
rw [← smul_eq_mul, ← integral_smul_measure]
dsimp only [IsUniform, ProbabilityTheory.cond] at huX
rw [← huX]
by_cases hX : AEMeasurable X ℙ
· exact (integral_map hX aestronglyMeasurable_id).symm
· rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable]
rwa [aestronglyMeasurable_iff_aemeasurable]
end IsUniform
variable {X : Ω → E}
lemma IsUniform.cond {s : Set E} :
IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by
unfold IsUniform
rw [Measure.map_id]
/-- The density of the uniform measure on a set with respect to itself. This allows us to abstract
away the choice of random variable and probability space. -/
def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ :=
s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x
/-- Check that indeed any uniform random variable has the uniformPDF. -/
lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) :
(fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by
unfold uniformPDF
exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _)
open scoped Classical in
/-- Alternative way of writing the uniformPDF. -/
lemma uniformPDF_ite {s : Set E} {x : E} :
uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by
unfold uniformPDF
unfold Set.indicator
simp only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one]
end pdf
end MeasureTheory
namespace PMF
variable {α : Type*}
open scoped NNReal ENNReal
section UniformOfFinset
/-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/
def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by
classical
refine ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s ?_ ?_
· simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul]
have : (s.card : ℝ≥0∞) ≠ 0 := by
simpa only [Ne, Nat.cast_eq_zero, Finset.card_eq_zero] using
Finset.nonempty_iff_ne_empty.1 hs
exact ENNReal.mul_inv_cancel this <| ENNReal.natCast_ne_top s.card
· exact fun x hx => by simp only [hx, if_false]
variable {s : Finset α} (hs : s.Nonempty) {a : α}
open scoped Classical in
@[simp]
theorem uniformOfFinset_apply (a : α) :
uniformOfFinset s hs a = if a ∈ s then (s.card : ℝ≥0∞)⁻¹ else 0 :=
rfl
theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by
simp [ha]
theorem uniformOfFinset_apply_of_notMem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by simp [ha]
@[deprecated (since := "2025-05-23")]
alias uniformOfFinset_apply_of_not_mem := uniformOfFinset_apply_of_notMem
@[simp]
theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s :=
Set.ext
(by
let ⟨a, ha⟩ := hs
simp [mem_support_iff])
theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by
simp
section Measure
variable (t : Set α)
open scoped Classical in
@[simp]
theorem toOuterMeasure_uniformOfFinset_apply :
(uniformOfFinset s hs).toOuterMeasure t = #{x ∈ s | x ∈ t} / #s :=
calc
(uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 :=
toOuterMeasure_apply (uniformOfFinset s hs) t
_ = ∑' x, if x ∈ s ∧ x ∈ t then (#s : ℝ≥0∞)⁻¹ else 0 :=
tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm]
_ = ∑ x ∈ s with x ∈ t, if x ∈ s ∧ x ∈ t then (#s : ℝ≥0∞)⁻¹ else 0 :=
tsum_eq_sum fun _ hx => if_neg fun h => hx (Finset.mem_filter.2 h)
_ = ∑ x ∈ s with x ∈ t, (#s : ℝ≥0∞)⁻¹ :=
Finset.sum_congr rfl fun x hx => by
have this : x ∈ s ∧ x ∈ t := by simpa using hx
simp only [this, and_self_iff, if_true]
_ = #{x ∈ s | x ∈ t} / #s := by
simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul]
open scoped Classical in
@[simp]
theorem toMeasure_uniformOfFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) :
(uniformOfFinset s hs).toMeasure t = #{x ∈ s | x ∈ t} / #s :=
(toMeasure_apply_eq_toOuterMeasure_apply _ ht).trans (toOuterMeasure_uniformOfFinset_apply hs t)
end Measure
end UniformOfFinset
section UniformOfFintype
/-- The uniform pmf taking the same uniform value on all of the fintype `α` -/
def uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : PMF α :=
uniformOfFinset Finset.univ Finset.univ_nonempty
variable [Fintype α] [Nonempty α]
@[simp]
theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by
simp [uniformOfFintype, Finset.mem_univ, uniformOfFinset_apply]
@[simp]
theorem support_uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] :
(uniformOfFintype α).support = ⊤ :=
Set.ext fun x => by simp [mem_support_iff]
theorem mem_support_uniformOfFintype (a : α) : a ∈ (uniformOfFintype α).support := by simp
section Measure
variable (s : Set α)
theorem toOuterMeasure_uniformOfFintype_apply [Fintype s] :
(uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by
classical
rw [uniformOfFintype, toOuterMeasure_uniformOfFinset_apply, Fintype.card_subtype,
Finset.card_univ]
theorem toMeasure_uniformOfFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) [Fintype s] :
(uniformOfFintype α).toMeasure s = Fintype.card s / Fintype.card α := by
classical
simp [uniformOfFintype, Fintype.card_subtype, hs]
end Measure
end UniformOfFintype
section OfMultiset
open scoped Classical in
/-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of
elements in `s` that are `a`. -/
def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α :=
⟨fun a => s.count a / (Multiset.card s),
ENNReal.summable.hasSum_iff.2
(calc
(∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s))
= (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by
simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left]
_ = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑ b ∈ s.toFinset, (s.count b : ℝ≥0∞) :=
(congr_arg (fun x => (Multiset.card s : ℝ≥0∞)⁻¹ * x)
(tsum_eq_sum fun a ha =>
Nat.cast_eq_zero.2 <| by rwa [Multiset.count_eq_zero, ← Multiset.mem_toFinset]))
_ = 1 := by
rw [← Nat.cast_sum, Multiset.toFinset_sum_count_eq s,
ENNReal.inv_mul_cancel (Nat.cast_ne_zero.2 (hs ∘ Multiset.card_eq_zero.1))
(ENNReal.natCast_ne_top _)]
)⟩
variable {s : Multiset α} (hs : s ≠ 0)
open scoped Classical in
@[simp]
theorem ofMultiset_apply (a : α) : ofMultiset s hs a = s.count a / (Multiset.card s) :=
rfl
open scoped Classical in
@[simp]
theorem support_ofMultiset : (ofMultiset s hs).support = s.toFinset :=
Set.ext (by simp [mem_support_iff])
open scoped Classical in
theorem mem_support_ofMultiset_iff (a : α) : a ∈ (ofMultiset s hs).support ↔ a ∈ s.toFinset := by
simp
theorem ofMultiset_apply_of_notMem {a : α} (ha : a ∉ s) : ofMultiset s hs a = 0 := by
simpa only [ofMultiset_apply, ENNReal.div_eq_zero_iff, Nat.cast_eq_zero, Multiset.count_eq_zero,
ENNReal.natCast_ne_top, or_false] using ha
@[deprecated (since := "2025-05-23")]
alias ofMultiset_apply_of_not_mem := ofMultiset_apply_of_notMem
section Measure
variable (t : Set α)
open scoped Classical in
@[simp]
theorem toOuterMeasure_ofMultiset_apply :
(ofMultiset s hs).toOuterMeasure t =
(∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by
simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply]
refine tsum_congr fun x => ?_
by_cases hx : x ∈ t <;> simp [Set.indicator, hx, div_eq_mul_inv]
open scoped Classical in
@[simp]
theorem toMeasure_ofMultiset_apply [MeasurableSpace α] (ht : MeasurableSet t) :
(ofMultiset s hs).toMeasure t = (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) :=
(toMeasure_apply_eq_toOuterMeasure_apply _ ht).trans (toOuterMeasure_ofMultiset_apply hs t)
end Measure
end OfMultiset
end PMF |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Pareto.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.CDF
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
/-! # Pareto distributions over ℝ
Define the Pareto measure over the reals.
## Main definitions
* `paretoPDFReal`: the function `t r x ↦ r * t ^ r * x ^ -(r + 1)`
for `t ≤ x` or `0` else, which is the probability density function of a Pareto distribution with
scale `t` and shape `r` (when `ht : 0 < t` and `hr : 0 < r`).
* `paretoPDF`: `ℝ≥0∞`-valued pdf,
`paretoPDF t r = ENNReal.ofReal (paretoPDFReal t r)`.
* `paretoMeasure`: a Pareto measure on `ℝ`, parametrized by its scale `t` and shape `r`.
-/
open scoped ENNReal NNReal
open MeasureTheory Real Set Filter Topology
namespace ProbabilityTheory
variable {t r x : ℝ}
section ParetoPDF
/-- The pdf of the Pareto distribution depending on its scale `t` and rate `r`. -/
noncomputable def paretoPDFReal (t r x : ℝ) : ℝ :=
if t ≤ x then r * t ^ r * x ^ (-(r + 1)) else 0
/-- The pdf of the Pareto distribution, as a function valued in `ℝ≥0∞`. -/
noncomputable def paretoPDF (t r x : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (paretoPDFReal t r x)
lemma paretoPDF_eq (t r x : ℝ) :
paretoPDF t r x = ENNReal.ofReal (if t ≤ x then r * t ^ r * x ^ (-(r + 1)) else 0) := rfl
lemma paretoPDF_of_lt (hx : x < t) : paretoPDF t r x = 0 := by
simp only [paretoPDF_eq, if_neg (not_le.mpr hx), ENNReal.ofReal_zero]
lemma paretoPDF_of_le (hx : t ≤ x) :
paretoPDF t r x = ENNReal.ofReal (r * t ^ r * x ^ (-(r + 1))) := by
simp only [paretoPDF_eq, if_pos hx]
/-- The Lebesgue integral of the Pareto pdf over reals `≤ t` equals `0`. -/
lemma lintegral_paretoPDF_of_le (hx : x ≤ t) :
∫⁻ y in Iio x, paretoPDF t r y = 0 := by
rw [setLIntegral_congr_fun (g := fun _ ↦ 0) measurableSet_Iio]
· rw [lintegral_zero, ← ENNReal.ofReal_zero]
· intro a (_ : a < _)
simp only [paretoPDF_eq, ENNReal.ofReal_eq_zero]
rw [if_neg (by linarith)]
/-- The Pareto pdf is measurable. -/
@[measurability, fun_prop]
lemma measurable_paretoPDFReal (t r : ℝ) : Measurable (paretoPDFReal t r) :=
Measurable.ite measurableSet_Ici ((measurable_id.pow_const _).const_mul _) measurable_const
/-- The Pareto pdf is strongly measurable. -/
@[fun_prop, measurability]
lemma stronglyMeasurable_paretoPDFReal (t r : ℝ) :
StronglyMeasurable (paretoPDFReal t r) :=
(measurable_paretoPDFReal t r).stronglyMeasurable
/-- The Pareto pdf is positive for all reals `>= t`. -/
lemma paretoPDFReal_pos (ht : 0 < t) (hr : 0 < r) (hx : t ≤ x) :
0 < paretoPDFReal t r x := by
rw [paretoPDFReal, if_pos hx]
have _ : 0 < x := by linarith
positivity
/-- The Pareto pdf is nonnegative. -/
lemma paretoPDFReal_nonneg (ht : 0 ≤ t) (hr : 0 ≤ r) (x : ℝ) :
0 ≤ paretoPDFReal t r x := by
unfold paretoPDFReal
split_ifs with h
· cases le_iff_eq_or_lt.1 ht with
| inl ht0 =>
rw [← ht0] at h
positivity
| inr htp =>
positivity [lt_of_lt_of_le htp h]
· positivity
open Measure
/-- The pdf of the Pareto distribution integrates to `1`. -/
@[simp]
lemma lintegral_paretoPDF_eq_one (ht : 0 < t) (hr : 0 < r) :
∫⁻ x, paretoPDF t r x = 1 := by
have leftSide : ∫⁻ x in Iio t, paretoPDF t r x = 0 := lintegral_paretoPDF_of_le (le_refl t)
have rightSide : ∫⁻ x in Ici t, paretoPDF t r x =
∫⁻ x in Ici t, ENNReal.ofReal (r * t ^ r * x ^ (-(r + 1))) :=
setLIntegral_congr_fun measurableSet_Ici (fun _ ↦ paretoPDF_of_le)
rw [← ENNReal.toReal_eq_one_iff, ← lintegral_add_compl _ measurableSet_Ici, compl_Ici,
leftSide, rightSide, add_zero, ← integral_eq_lintegral_of_nonneg_ae]
· rw [integral_Ici_eq_integral_Ioi, integral_const_mul, integral_Ioi_rpow_of_lt _ ht]
· simp [field, ← rpow_add ht]
linarith
· rw [EventuallyLE, ae_restrict_iff' measurableSet_Ici]
filter_upwards with x hx using by positivity [lt_of_lt_of_le ht hx]
· apply (measurable_paretoPDFReal t r).aestronglyMeasurable.congr
refine (ae_restrict_iff' measurableSet_Ici).mpr <| ae_of_all _ fun x (hx : t ≤ x) ↦ ?_
simp_rw [paretoPDFReal, eq_true_intro hx, ite_true]
end ParetoPDF
open MeasureTheory
/-- Measure defined by the Pareto distribution. -/
noncomputable def paretoMeasure (t r : ℝ) : Measure ℝ :=
volume.withDensity (paretoPDF t r)
lemma isProbabilityMeasure_paretoMeasure (ht : 0 < t) (hr : 0 < r) :
IsProbabilityMeasure (paretoMeasure t r) where
measure_univ := by simp [paretoMeasure, lintegral_paretoPDF_eq_one ht hr]
section ParetoCDF
/-- CDF of the Pareto distribution equals the integral of the PDF. -/
lemma cdf_paretoMeasure_eq_integral (ht : 0 < t) (hr : 0 < r) (x : ℝ) :
cdf (paretoMeasure t r) x = ∫ x in Iic x, paretoPDFReal t r x := by
have : IsProbabilityMeasure (paretoMeasure t r) := isProbabilityMeasure_paretoMeasure ht hr
rw [cdf_eq_real, paretoMeasure, measureReal_def, withDensity_apply _ measurableSet_Iic]
refine (integral_eq_lintegral_of_nonneg_ae ?_ ?_).symm
· exact ae_of_all _ fun _ ↦ by simp only [Pi.zero_apply, paretoPDFReal_nonneg ht.le hr.le]
· fun_prop
@[deprecated (since := "2025-08-28")] alias paretoCDFReal_eq_integral :=
cdf_paretoMeasure_eq_integral
lemma cdf_paretoMeasure_eq_lintegral (ht : 0 < t) (hr : 0 < r) (x : ℝ) :
cdf (paretoMeasure t r) x = ENNReal.toReal (∫⁻ x in Iic x, paretoPDF t r x) := by
have : IsProbabilityMeasure (paretoMeasure t r) := isProbabilityMeasure_paretoMeasure ht hr
rw [cdf_eq_real, paretoMeasure, measureReal_def, withDensity_apply _ measurableSet_Iic]
@[deprecated (since := "2025-08-28")] alias paretoCDFReal_eq_lintegral :=
cdf_paretoMeasure_eq_lintegral
end ParetoCDF
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Exponential.lean | import Mathlib.Probability.Notation
import Mathlib.Probability.CDF
import Mathlib.Probability.Distributions.Gamma
/-! # Exponential distributions over ℝ
Define the Exponential measure over the reals.
## Main definitions
* `exponentialPDFReal`: the function `r x ↦ r * exp (-(r * x)` for `0 ≤ x`
or `0` else, which is the probability density function of a exponential distribution with
rate `r` (when `hr : 0 < r`).
* `exponentialPDF`: `ℝ≥0∞`-valued pdf,
`exponentialPDF r = ENNReal.ofReal (exponentialPDFReal r)`.
* `expMeasure`: an exponential measure on `ℝ`, parametrized by its rate `r`.
## Main results
* `cdf_expMeasure_eq`: Proof that the CDF of the exponential measure equals the
known function given as `r x ↦ 1 - exp (- (r * x))` for `0 ≤ x` or `0` else.
-/
open scoped ENNReal NNReal
open MeasureTheory Real Set Filter Topology
namespace ProbabilityTheory
section ExponentialPDF
/-- The pdf of the exponential distribution depending on its rate -/
noncomputable
def exponentialPDFReal (r x : ℝ) : ℝ :=
gammaPDFReal 1 r x
/-- The pdf of the exponential distribution, as a function valued in `ℝ≥0∞` -/
noncomputable
def exponentialPDF (r x : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (exponentialPDFReal r x)
lemma exponentialPDF_eq (r x : ℝ) :
exponentialPDF r x = ENNReal.ofReal (if 0 ≤ x then r * exp (-(r * x)) else 0) := by
rw [exponentialPDF, exponentialPDFReal, gammaPDFReal]
simp only [rpow_one, Gamma_one, div_one, sub_self, rpow_zero, mul_one]
lemma exponentialPDF_of_neg {r x : ℝ} (hx : x < 0) : exponentialPDF r x = 0 := gammaPDF_of_neg hx
lemma exponentialPDF_of_nonneg {r x : ℝ} (hx : 0 ≤ x) :
exponentialPDF r x = ENNReal.ofReal (r * rexp (-(r * x))) := by
simp only [exponentialPDF_eq, if_pos hx]
/-- The Lebesgue integral of the exponential pdf over nonpositive reals equals 0 -/
lemma lintegral_exponentialPDF_of_nonpos {x r : ℝ} (hx : x ≤ 0) :
∫⁻ y in Iio x, exponentialPDF r y = 0 := lintegral_gammaPDF_of_nonpos hx
/-- The exponential pdf is measurable. -/
@[fun_prop, measurability]
lemma measurable_exponentialPDFReal (r : ℝ) : Measurable (exponentialPDFReal r) :=
measurable_gammaPDFReal 1 r
-- The exponential pdf is strongly measurable -/
@[fun_prop, measurability]
lemma stronglyMeasurable_exponentialPDFReal (r : ℝ) :
StronglyMeasurable (exponentialPDFReal r) := stronglyMeasurable_gammaPDFReal 1 r
/-- The exponential pdf is positive for all positive reals -/
lemma exponentialPDFReal_pos {x r : ℝ} (hr : 0 < r) (hx : 0 < x) :
0 < exponentialPDFReal r x := gammaPDFReal_pos zero_lt_one hr hx
/-- The exponential pdf is nonnegative -/
lemma exponentialPDFReal_nonneg {r : ℝ} (hr : 0 < r) (x : ℝ) :
0 ≤ exponentialPDFReal r x := gammaPDFReal_nonneg zero_lt_one hr x
open Measure
/-- The pdf of the exponential distribution integrates to 1 -/
@[simp]
lemma lintegral_exponentialPDF_eq_one {r : ℝ} (hr : 0 < r) : ∫⁻ x, exponentialPDF r x = 1 :=
lintegral_gammaPDF_eq_one zero_lt_one hr
end ExponentialPDF
open MeasureTheory
/-- Measure defined by the exponential distribution -/
noncomputable
def expMeasure (r : ℝ) : Measure ℝ := gammaMeasure 1 r
lemma isProbabilityMeasure_expMeasure {r : ℝ} (hr : 0 < r) :
IsProbabilityMeasure (expMeasure r) := isProbabilityMeasure_gammaMeasure zero_lt_one hr
@[deprecated (since := "2025-08-29")] alias isProbabilityMeasureExponential :=
isProbabilityMeasure_expMeasure
section ExponentialCDF
/-- CDF of the exponential distribution -/
@[deprecated "Use `cdf (expMeasure r)` instead." (since := "2025-08-28")]
noncomputable
def exponentialCDFReal (r : ℝ) : StieltjesFunction :=
cdf (expMeasure r)
lemma cdf_expMeasure_eq_integral {r : ℝ} (hr : 0 < r) (x : ℝ) :
cdf (expMeasure r) x = ∫ x in Iic x, exponentialPDFReal r x :=
cdf_gammaMeasure_eq_integral zero_lt_one hr x
@[deprecated (since := "2025-08-28")] alias exponentialCDFReal_eq_integral :=
cdf_expMeasure_eq_integral
lemma cdf_expMeasure_eq_lintegral {r : ℝ} (hr : 0 < r) (x : ℝ) :
cdf (expMeasure r) x = ENNReal.toReal (∫⁻ x in Iic x, exponentialPDF r x) :=
cdf_gammaMeasure_eq_lintegral zero_lt_one hr x
@[deprecated (since := "2025-08-28")] alias exponentialCDFReal_eq_lintegral :=
cdf_expMeasure_eq_lintegral
open Topology
lemma hasDerivAt_neg_exp_mul_exp {r x : ℝ} :
HasDerivAt (fun a ↦ -exp (-(r * a))) (r * exp (-(r * x))) x := by
convert (((hasDerivAt_id x).const_mul (-r)).exp.const_mul (-1)) using 1
· simp only [one_mul, id_eq, neg_mul]
simp only [id_eq, neg_mul, mul_one, mul_neg, one_mul, neg_neg, mul_comm]
/-- A negative exponential function is integrable on intervals in `R≥0` -/
lemma exp_neg_integrableOn_Ioc {b x : ℝ} (hb : 0 < b) :
IntegrableOn (fun x ↦ rexp (-(b * x))) (Ioc 0 x) := by
simp only [neg_mul_eq_neg_mul]
exact (exp_neg_integrableOn_Ioi _ hb).mono_set Ioc_subset_Ioi_self
lemma lintegral_exponentialPDF_eq_antiDeriv {r : ℝ} (hr : 0 < r) (x : ℝ) :
∫⁻ y in Iic x, exponentialPDF r y
= ENNReal.ofReal (if 0 ≤ x then 1 - exp (-(r * x)) else 0) := by
split_ifs with h
case neg =>
simp only [exponentialPDF_eq]
rw [setLIntegral_congr_fun measurableSet_Iic, lintegral_zero, ENNReal.ofReal_zero]
exact fun a (_ : a ≤ _) ↦ by rw [if_neg (by linarith), ENNReal.ofReal_eq_zero]
case pos =>
rw [lintegral_Iic_eq_lintegral_Iio_add_Icc _ h, lintegral_exponentialPDF_of_nonpos (le_refl 0),
zero_add]
simp only [exponentialPDF_eq]
rw [setLIntegral_congr_fun measurableSet_Icc (g := fun x ↦ ENNReal.ofReal (r * rexp (-(r * x))))
(by intro a ha; simp [ha.1])]
rw [← ENNReal.toReal_eq_toReal_iff' _ ENNReal.ofReal_ne_top,
← integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall fun _ ↦ le_of_lt
(mul_pos hr (exp_pos _)))]
· have : ∫ a in uIoc 0 x, r * rexp (-(r * a)) = ∫ a in 0..x, r * rexp (-(r * a)) := by
rw [intervalIntegral.intervalIntegral_eq_integral_uIoc, smul_eq_mul, if_pos h, one_mul]
rw [integral_Icc_eq_integral_Ioc, ← uIoc_of_le h, this]
rw [intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le h
(f := fun a ↦ -1 * rexp (-(r * a))) _ _]
· rw [ENNReal.toReal_ofReal_eq_iff.2 (by simp; positivity)]
norm_num; ring
· simp only [intervalIntegrable_iff, uIoc_of_le h]
exact Integrable.const_mul (exp_neg_integrableOn_Ioc hr) _
· have : Continuous (fun a ↦ rexp (-(r * a))) := by
simp only [← neg_mul]; exact (continuous_mul_left (-r)).rexp
exact Continuous.continuousOn (Continuous.comp' (continuous_mul_left (-1)) this)
· simp only [neg_mul, one_mul]
exact fun _ _ ↦ HasDerivAt.hasDerivWithinAt hasDerivAt_neg_exp_mul_exp
· refine Integrable.aestronglyMeasurable (Integrable.const_mul ?_ _)
rw [← IntegrableOn, integrableOn_Icc_iff_integrableOn_Ioc]
exact exp_neg_integrableOn_Ioc hr
· refine ne_of_lt (IntegrableOn.setLIntegral_lt_top ?_)
rw [integrableOn_Icc_iff_integrableOn_Ioc]
exact Integrable.const_mul (exp_neg_integrableOn_Ioc hr) _
/-- The CDF of the exponential distribution equals ``1 - exp (-(r * x))`` -/
lemma cdf_expMeasure_eq {r : ℝ} (hr : 0 < r) (x : ℝ) :
cdf (expMeasure r) x = if 0 ≤ x then 1 - exp (-(r * x)) else 0 := by
rw [cdf_expMeasure_eq_lintegral hr, lintegral_exponentialPDF_eq_antiDeriv hr x,
ENNReal.toReal_ofReal_eq_iff]
split_ifs with h
· simp only [sub_nonneg, exp_le_one_iff, Left.neg_nonpos_iff]
exact mul_nonneg hr.le h
· exact le_rfl
@[deprecated (since := "2025-08-28")] alias exponentialCDFReal_eq := cdf_expMeasure_eq
end ExponentialCDF
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Fernique.lean | import Mathlib.Analysis.SpecificLimits.ArithmeticGeometric
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.MeasureTheory.Function.L1Space.Integrable
import Mathlib.Topology.MetricSpace.Polish
/-!
# Fernique's theorem for rotation-invariant measures
Let `μ` be a finite measure on a second-countable normed space `E` such that the product measure
`μ.prod μ` on `E × E` is invariant by rotation of angle `-π/4`.
Then there exists a constant `C > 0` such that the function `x ↦ exp (C * ‖x‖ ^ 2)` is integrable
with respect to `μ`.
## Sketch of the proof
The main case of the proof is for `μ` a probability measure such that there exists a positive
`a : ℝ` such that `2⁻¹ < μ {x | ‖x‖ ≤ a} < 1`. If `μ` is a probability measure and `a` does not
exist then we can show that there is a ball with finite radius of measure 1, and the result is true
for `C = 1` (for example), since `x ↦ exp (‖x‖ ^ 2)` is almost surely bounded.
We then choose such an `a`.
In order to show the existence of `C` such that `x ↦ exp (C * ‖x‖ ^ 2)` is integrable, we prove as
intermediate result that for `a, c` with `2⁻¹ < c ≤ μ {x | ‖x‖ ≤ a}`,
the integral `∫⁻ x, exp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2) ∂μ` is bounded by a finite quantity
(`logRatio c` is a multiple of `log (c / (1 - c))`). We can then take `C = logRatio c * a⁻¹ ^ 2`.
We now turn to the proof of the intermediate result.
First in `measure_le_mul_measure_gt_le_of_map_rotation_eq_self` we prove that if a measure `μ` is
such that `μ.prod μ` is invariant by rotation of angle `-π/4` then
`μ {x | ‖x‖ ≤ a} * μ {x | b < ‖x‖} ≤ μ {x | (b - a) / √2 < ‖x‖} ^ 2`.
The rotation invariance is used only through that inequality.
We define a sequence of thresholds `t n` inductively by `t 0 = a` and `t (n + 1) = √2 * t n + a`.
They are chosen such that the invariance by rotation gives
`μ {x | ‖x‖ ≤ a} * μ {x | t (n + 1) < ‖x‖} ≤ μ {x | t n < ‖x‖} ^ 2`.
Thanks to that inequality we can show that `μ {x | t n < ‖x‖}` decreases fast with `n`:
for `mₐ = μ {x | ‖x‖ ≤ a}`, `μ {x | t n < ‖x‖} ≤ mₐ * exp (- log (mₐ / (1 - mₐ)) * 2 ^ n)`.
We cut the space into annuli `{x | t n < ‖x‖ ≤ t n + 1}` and bound the integral separately on
each annulus. On that set the function `exp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2)` is bounded by
`exp (logRatio c * a⁻¹ ^ 2 * t (n + 1) ^ 2)`, which is in turn less than
`exp (2⁻¹ * log (c / (1 - c)) * 2 ^ n)` (from the definition of the threshold `t` and `logRatio c`).
The measure of the annulus is bounded by `μ {x | t n < ‖x‖}`, for which we derived an upper bound
above. The function gets exponentially large, but `μ {x | t n < ‖x‖}` decreases even faster, so the
integral is bounded by a quantity of the form `exp (- u * 2 ^ n)` for `u>0`.
Summing over all annuli (over `n`) gives a finite value for the integral.
## Main statements
* `lintegral_exp_mul_sq_norm_le_of_map_rotation_eq_self`: for `μ` a probability measure
whose product with itself is invariant by rotation and for `a, c` with
`2⁻¹ < c ≤ μ {x | ‖x‖ ≤ a}`, the integral `∫⁻ x, exp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2) ∂μ`
is bounded by a quantity that does not depend on `a`.
* `exists_integrable_exp_sq_of_map_rotation_eq_self`: Fernique's theorem for finite measures
whose product is invariant by rotation.
## References
* [Xavier Fernique, *Intégrabilité des vecteurs gaussiens*][fernique1970integrabilite]
* [Martin Hairer, *An introduction to stochastic PDEs*][hairer2009introduction]
## TODO
From the intermediate result `lintegral_exp_mul_sq_norm_le_of_map_rotation_eq_self`,
we can deduce bounds on all the moments of the measure `μ` as function of powers of
the first moment.
-/
open MeasureTheory ProbabilityTheory Complex NormedSpace Filter
open scoped ENNReal NNReal Real Topology
section Aux
lemma StrictMono.exists_between_of_tendsto_atTop {β : Type*} [LinearOrder β] {t : ℕ → β}
(ht_mono : StrictMono t) (ht_tendsto : Tendsto t atTop atTop) {x : β} (hx : t 0 < x) :
∃ n, t n < x ∧ x ≤ t (n + 1) := by
have h : ∃ n, x ≤ t n := by
simp only [tendsto_atTop_atTop_iff_of_monotone ht_mono.monotone] at ht_tendsto
exact ht_tendsto x
have h' m := Nat.find_min h (m := m)
simp only [not_le] at h'
exact ⟨Nat.find h - 1, h' _ (by simp [hx]), by simp [Nat.find_spec h, hx]⟩
end Aux
namespace ProbabilityTheory
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E]
/-- The rotation in `E × E` with angle `θ`, as a continuous linear map. -/
noncomputable
def _root_.ContinuousLinearMap.rotation (θ : ℝ) : E × E →L[ℝ] E × E where
toFun := fun x ↦ (Real.cos θ • x.1 + Real.sin θ • x.2, - Real.sin θ • x.1 + Real.cos θ • x.2)
map_add' x y := by
simp only [Prod.fst_add, smul_add, Prod.snd_add, neg_smul, Prod.mk_add_mk]
abel_nf
map_smul' c x := by simp [smul_comm c]
cont := by fun_prop
lemma _root_.ContinuousLinearMap.rotation_apply (θ : ℝ) (x : E × E) :
ContinuousLinearMap.rotation θ x
= (Real.cos θ • x.1 + Real.sin θ • x.2, -Real.sin θ • x.1 + Real.cos θ • x.2) := rfl
variable [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {μ : Measure E} {a : ℝ}
/-- If a measure `μ` is such that `μ.prod μ` is invariant by rotation of angle `-π/4` then
`μ {x | ‖x‖ ≤ a} * μ {x | b < ‖x‖} ≤ μ {x | (b - a) / √2 < ‖x‖} ^ 2`. -/
lemma measure_le_mul_measure_gt_le_of_map_rotation_eq_self [SFinite μ]
(h : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
(a b : ℝ) :
μ {x | ‖x‖ ≤ a} * μ {x | b < ‖x‖} ≤ μ {x | (b - a) / √2 < ‖x‖} ^ 2 := by
calc μ {x | ‖x‖ ≤ a} * μ {x | b < ‖x‖}
_ = (μ.prod μ) ({x | ‖x‖ ≤ a} ×ˢ {y | b < ‖y‖}) := by rw [Measure.prod_prod]
-- This is the measure of two bands in the plane (draw a picture!)
_ = (μ.prod μ) {p | ‖p.1‖ ≤ a ∧ b < ‖p.2‖} := rfl
_ = ((μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4)))) {p | ‖p.1‖ ≤ a ∧ b < ‖p.2‖} := by
-- We can rotate the bands since `μ.prod μ` is invariant under rotation
rw [h]
_ = (μ.prod μ) {p | ‖p.1 - p.2‖ / √2 ≤ a ∧ b < ‖p.1 + p.2‖ / √2} := by
rw [Measure.map_apply (by fun_prop)]
swap
· refine MeasurableSet.inter ?_ ?_
· change MeasurableSet {p : E × E | ‖p.1‖ ≤ a}
exact measurableSet_le (by fun_prop) (by fun_prop)
· change MeasurableSet {p : E × E | b < ‖p.2‖}
exact measurableSet_lt (by fun_prop) (by fun_prop)
congr 1
simp only [Set.preimage_setOf_eq, ContinuousLinearMap.rotation_apply, Real.cos_neg,
Real.cos_pi_div_four, Real.sin_neg, Real.sin_pi_div_four, neg_smul, neg_neg]
have h_twos : ‖2⁻¹ * √2‖ = (√2)⁻¹ := by
simp only [norm_mul, norm_inv, Real.norm_ofNat, Real.norm_eq_abs]
rw [abs_of_nonneg (by positivity)]
nth_rw 1 [← Real.sq_sqrt (by simp : (0 : ℝ) ≤ 2)]
rw [pow_two, mul_inv, mul_assoc, inv_mul_cancel₀ (by positivity), mul_one]
congr! with p
· rw [← sub_eq_add_neg, ← smul_sub, norm_smul, div_eq_inv_mul, div_eq_inv_mul, h_twos]
· rw [← smul_add, norm_smul, div_eq_inv_mul, div_eq_inv_mul, h_twos]
_ ≤ (μ.prod μ) {p | (b - a) / √2 < ‖p.1‖ ∧ (b - a) / √2 < ‖p.2‖} := by
-- The rotated bands are contained in quadrants.
refine measure_mono fun p ↦ ?_
simp only [Set.mem_setOf_eq, and_imp]
intro hp1 hp2
suffices (b - a) / √2 < min ‖p.1‖ ‖p.2‖ from lt_min_iff.mp this
calc (b - a) / √2
_ < (‖p.1 + p.2‖ - ‖p.1 - p.2‖) / 2 := by
suffices b - a < ‖p.1 + p.2‖ / √2 - ‖p.1 - p.2‖ / √2 by
calc (b - a) / √2 < (‖p.1 + p.2‖ / √2 - ‖p.1 - p.2‖ / √2) / √2 := by gcongr
_ = (‖p.1 + p.2‖ - ‖p.1 - p.2‖) / 2 := by
field_simp; rw [Real.sq_sqrt (by positivity)]; ring
calc b - a < ‖p.1 + p.2‖ / √2 - a := by gcongr
_ ≤ ‖p.1 + p.2‖ / √2 - ‖p.1 - p.2‖ / √2 := by gcongr
_ ≤ min ‖p.1‖ ‖p.2‖ := by
have := norm_add_sub_norm_sub_le_two_mul_min p.1 p.2
linarith
_ = (μ.prod μ) ({x | (b - a) / √2 < ‖x‖} ×ˢ {y | (b - a) / √2 < ‖y‖}) := rfl
_ ≤ μ {x | (b - a) / √2 < ‖x‖} ^ 2 := by rw [Measure.prod_prod, pow_two]
namespace Fernique
/-- A sequence of real thresholds that will be used to cut the space into annuli.
Chosen such that for a rotation invariant measure, an application of lemma
`measure_le_mul_measure_gt_le_of_map_rotation_eq_self` gives
`μ {x | ‖x‖ ≤ a} * μ {x | normThreshold a (n + 1) < ‖x‖} ≤ μ {x | normThreshold a n < ‖x‖} ^ 2`. -/
noncomputable def normThreshold (a : ℝ) : ℕ → ℝ := arithGeom √2 a a
lemma normThreshold_zero : normThreshold a 0 = a := rfl
lemma normThreshold_add_one (n : ℕ) : normThreshold a (n + 1) = √2 * normThreshold a n + a := rfl
lemma measure_le_mul_measure_gt_normThreshold_le_of_map_rotation_eq_self [SFinite μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ) (a : ℝ) (n : ℕ) :
μ {x | ‖x‖ ≤ a} * μ {x | normThreshold a (n + 1) < ‖x‖}
≤ μ {x | normThreshold a n < ‖x‖} ^ 2 := by
convert measure_le_mul_measure_gt_le_of_map_rotation_eq_self h_rot _ _
simp [normThreshold_add_one]
lemma lt_normThreshold_zero (ha_pos : 0 < a) : a / (1 - √2) < normThreshold a 0 := by
simp only [normThreshold_zero]
calc a / (1 - √2)
_ ≤ 0 := div_nonpos_of_nonneg_of_nonpos ha_pos.le (by simp)
_ < a := ha_pos
lemma normThreshold_strictMono (ha_pos : 0 < a) : StrictMono (normThreshold a) :=
arithGeom_strictMono Real.one_lt_sqrt_two (lt_normThreshold_zero ha_pos)
lemma tendsto_normThreshold_atTop (ha_pos : 0 < a) : Tendsto (normThreshold a) atTop atTop :=
tendsto_arithGeom_atTop_of_one_lt Real.one_lt_sqrt_two (lt_normThreshold_zero ha_pos)
lemma normThreshold_eq (n : ℕ) : normThreshold a n = a * (1 + √2) * (√2 ^ (n + 1) - 1) := by
rw [normThreshold, arithGeom_same_eq_mul_div (by simp), div_eq_mul_inv, Real.inv_sqrt_two_sub_one]
ring
lemma sq_normThreshold_add_one_le (n : ℕ) :
normThreshold a (n + 1) ^ 2 ≤ a ^ 2 * (1 + √2) ^ 2 * 2 ^ (n + 2) := by
simp_rw [normThreshold_eq, mul_pow, mul_assoc]
gcongr
calc (√2 ^ (n + 2) - 1) ^ 2
_ ≤ (√2 ^ (n + 2)) ^ 2 := by
gcongr
· calc 0 ≤ √2 ^ (0 + 2) - 1 := by simp
_ ≤ √2 ^ (n + 2) - 1 := by gcongr <;> simp
· exact sub_le_self _ (by simp)
_ = 2 ^ (n + 2) := by rw [← pow_mul, mul_comm, pow_mul, Real.sq_sqrt (by positivity)]
lemma measure_gt_normThreshold_le_rpow [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
(ha_gt : 2⁻¹ < μ {x | ‖x‖ ≤ a}) (n : ℕ) :
μ {x | normThreshold a n < ‖x‖}
≤ μ {x | ‖x‖ ≤ a} * ((1 - μ {x | ‖x‖ ≤ a}) / μ {x | ‖x‖ ≤ a}) ^ (2 ^ n) := by
let c := μ {x | ‖x‖ ≤ a}
replace hc_gt : 2⁻¹ < c := ha_gt
have hc_pos : 0 < c := lt_of_lt_of_le (by simp) hc_gt.le
have hc_lt_top : c < ∞ := measure_lt_top _ _
induction n with
| zero =>
simp only [pow_zero, pow_one, normThreshold_zero]
rw [ENNReal.mul_div_cancel hc_pos.ne' hc_lt_top.ne]
refine le_of_eq ?_
rw [← prob_compl_eq_one_sub (measurableSet_le (by fun_prop) (by fun_prop))]
congr with x
simp
| succ n hn =>
have h_mul_le : c * μ {x | normThreshold a (n + 1) < ‖x‖}
≤ μ {x | normThreshold a n < ‖x‖} ^ 2 :=
measure_le_mul_measure_gt_normThreshold_le_of_map_rotation_eq_self h_rot _ _
calc μ {x | normThreshold a (n + 1) < ‖x‖}
_ = c⁻¹ * (c * μ {x | normThreshold a (n + 1) < ‖x‖}) := by
rw [← mul_assoc, ENNReal.inv_mul_cancel hc_pos.ne' hc_lt_top.ne, one_mul]
_ ≤ c⁻¹ * μ {x | normThreshold a n < ‖x‖} ^ 2 := by gcongr
_ ≤ c⁻¹ * (c * ((1 - c) / c) ^ 2 ^ n) ^ 2 := by gcongr
_ = c * ((1 - c) / c) ^ 2 ^ (n + 1) := by
rw [mul_pow, ← pow_mul, ← mul_assoc, pow_two, ← mul_assoc,
ENNReal.inv_mul_cancel hc_pos.ne' hc_lt_top.ne, one_mul, pow_add, pow_one]
lemma measure_gt_normThreshold_le_exp [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
(ha_gt : 2⁻¹ < μ {x | ‖x‖ ≤ a}) (ha_lt : μ {x | ‖x‖ ≤ a} < 1) (n : ℕ) :
μ {x | normThreshold a n < ‖x‖}
≤ μ {x | ‖x‖ ≤ a} * .ofReal (rexp
(-Real.log (μ {x | ‖x‖ ≤ a} / (1 - μ {x | ‖x‖ ≤ a})).toReal * 2 ^ n)) := by
let c := μ {x | ‖x‖ ≤ a}
have hc_pos : 0 < c := lt_of_lt_of_le (by simp) ha_gt.le
replace hc_lt : c < 1 := ha_lt
have hc_lt_top : c < ∞ := measure_lt_top _ _
have hc_one_sub_lt_top : 1 - c < ∞ := lt_top_of_lt (b := 2) (tsub_le_self.trans_lt (by simp))
have hc_ratio_pos : 0 < (c / (1 - c)).toReal := by
rw [ENNReal.toReal_div, div_pos_iff_of_pos_right]
· simp [ENNReal.toReal_pos_iff, hc_pos, hc_lt_top]
· simp [ENNReal.toReal_pos_iff, tsub_pos_iff_lt, hc_lt, hc_one_sub_lt_top]
refine (measure_gt_normThreshold_le_rpow h_rot ha_gt n).trans_eq ?_
congr
rw [← Real.log_inv, mul_comm (Real.log _), ← Real.log_rpow (by positivity),
Real.exp_log (by positivity), ← ENNReal.ofReal_rpow_of_nonneg (by positivity) (by positivity),
ENNReal.toReal_div, inv_div, ← ENNReal.toReal_div, ENNReal.ofReal_toReal]
· norm_cast
· exact ENNReal.div_ne_top (by finiteness) (lt_trans (by simp) ha_gt).ne'
/-- A quantity that appears in exponentials in the proof of Fernique's theorem. -/
noncomputable def logRatio (c : ℝ≥0∞) : ℝ :=
Real.log (c.toReal / (1 - c).toReal) / (8 * (1 + √2) ^ 2)
lemma logRatio_pos {c : ℝ≥0∞} (hc_gt : (2 : ℝ≥0∞)⁻¹ < c) (hc_lt : c < 1) : 0 < logRatio c := by
refine div_pos (Real.log_pos ?_) (by positivity)
rw [one_lt_div_iff]
refine Or.inl ⟨?_, ?_⟩
· simp only [ENNReal.toReal_pos_iff, tsub_pos_iff_lt, hc_lt, true_and]
finiteness
· refine (ENNReal.toReal_lt_toReal (by finiteness) (by finiteness)).mpr ?_
refine ENNReal.sub_lt_of_lt_add hc_lt.le ?_
rw [← two_mul]
rwa [inv_eq_one_div, ENNReal.div_lt_iff (by simp) (by simp), mul_comm] at hc_gt
lemma logRatio_nonneg {c : ℝ≥0∞} (hc_ge : (2 : ℝ≥0∞)⁻¹ ≤ c) (hc_le : c ≤ 1) : 0 ≤ logRatio c := by
cases hc_ge.eq_or_lt'
· simp [logRatio, *]
cases hc_le.eq_or_lt'
· simp [logRatio, *]
exact (logRatio_pos ‹_› ‹_›).le
lemma logRatio_mono {c d : ℝ≥0∞} (hc : (2 : ℝ≥0∞)⁻¹ < c) (hd : d < 1) (h : c ≤ d) :
logRatio c ≤ logRatio d := by
unfold logRatio
gcongr
· refine div_pos ?_ ?_
· rw [ENNReal.toReal_pos_iff]
exact ⟨lt_trans (by norm_num) hc, h.trans_lt (by finiteness)⟩
· simp only [ENNReal.toReal_pos_iff, tsub_pos_iff_lt]
exact ⟨h.trans_lt hd, by finiteness⟩
· simp only [ENNReal.toReal_pos_iff, tsub_pos_iff_lt, hd, true_and]
finiteness
· finiteness
· finiteness
lemma logRatio_mul_normThreshold_add_one_le {c : ℝ≥0∞}
(hc_gt : (2 : ℝ≥0∞)⁻¹ < c) (hc_lt : c < 1) (n : ℕ) :
logRatio c * normThreshold a (n + 1) ^ 2 * a⁻¹ ^ 2
≤ 2⁻¹ * Real.log (c.toReal / (1 - c).toReal) * 2 ^ n := by
by_cases ha : a = 0
· simp only [ha, inv_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_zero,
Nat.ofNat_pos, pow_pos, mul_nonneg_iff_of_pos_right, inv_pos, mul_nonneg_iff_of_pos_left]
refine Real.log_nonneg ?_
rw [one_le_div]
· refine (ENNReal.toReal_le_toReal (by finiteness) (by finiteness)).mpr ?_
refine tsub_le_iff_left.mpr ?_
rw [← two_mul]
rw [inv_eq_one_div, ENNReal.div_lt_iff (by simp) (by simp), mul_comm] at hc_gt
exact hc_gt.le
· simp only [ENNReal.toReal_pos_iff, tsub_pos_iff_lt, hc_lt, true_and]
finiteness
calc logRatio c * normThreshold a (n + 1) ^ 2 * a⁻¹ ^ 2
_ ≤ logRatio c * (a ^ 2 * (1 + √2) ^ 2 * 2 ^ (n + 2)) * a⁻¹ ^ 2 := by
gcongr
· exact (logRatio_pos hc_gt hc_lt).le
· exact sq_normThreshold_add_one_le n
_ = 2⁻¹ * Real.log (c.toReal / (1 - c).toReal) * 2 ^ n := by
unfold logRatio
field
open Metric in
/-- Auxiliary lemma for `lintegral_exp_mul_sq_norm_le_mul`, in which we find an upper bound on an
integral by dealing separately with the contribution of each set in a sequence of annuli.
This is the bound of the integral over one of those annuli. -/
lemma lintegral_closedBall_diff_exp_logRatio_mul_sq_le [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
(ha_gt : 2⁻¹ < μ {x | ‖x‖ ≤ a}) (ha_lt : μ {x | ‖x‖ ≤ a} < 1) (n : ℕ) :
∫⁻ x in (closedBall 0 (normThreshold a (n + 1)) \ closedBall 0 (normThreshold a n)),
.ofReal (rexp (logRatio (μ {x | ‖x‖ ≤ a}) * a⁻¹ ^ 2 * ‖x‖ ^ 2)) ∂μ
≤ μ {x | ‖x‖ ≤ a} * .ofReal (rexp
(-2⁻¹ * Real.log (μ {x | ‖x‖ ≤ a} / (1 - μ {x | ‖x‖ ≤ a})).toReal * 2 ^ n)) :=
let t := normThreshold a
let c := μ {x | ‖x‖ ≤ a}
let C := logRatio c * a⁻¹ ^ 2
calc ∫⁻ x in (closedBall 0 (t (n + 1)) \ closedBall 0 (t n)), .ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ
-- We bound the function on the set by its maximal value, at the outer boundary of the annulus
_ ≤ ∫⁻ x in (closedBall 0 (t (n + 1)) \ closedBall 0 (t n)),
.ofReal (rexp (C * t (n + 1) ^ 2)) ∂μ := by
refine setLIntegral_mono (by fun_prop) fun x hx ↦ ?_
gcongr
· exact mul_nonneg (logRatio_pos ha_gt ha_lt).le (by positivity)
· simp only [Set.mem_diff, mem_closedBall, dist_zero_right, not_le] at hx
exact hx.1
-- The integral of a constant is the constant times the measure of the set
_ = .ofReal (rexp (C * t (n + 1) ^ 2)) * μ (closedBall 0 (t (n + 1)) \ closedBall 0 (t n)) := by
simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, C, t]
_ ≤ .ofReal (rexp (C * t (n + 1) ^ 2)) * μ {x | t n < ‖x‖} := by
gcongr
intro x
simp
-- We obtained an upper bound on the measure of that annulus in a previous lemma
_ ≤ .ofReal (rexp (C * t (n + 1) ^ 2))
* c * .ofReal (rexp (-Real.log (c / (1 - c)).toReal * 2 ^ n)) := by
conv_rhs => rw [mul_assoc]
gcongr
exact measure_gt_normThreshold_le_exp h_rot ha_gt ha_lt n
_ ≤ .ofReal (rexp (2⁻¹ * Real.log (c.toReal / (1 - c).toReal) * 2 ^ n))
* c * .ofReal (rexp (-Real.log (c / (1 - c)).toReal * 2 ^ n)) := by
gcongr ENNReal.ofReal (rexp ?_) * _ * _
convert logRatio_mul_normThreshold_add_one_le ha_gt ha_lt n (a := a) using 1
ring
_ = c * .ofReal (rexp (-2⁻¹ * Real.log (c / (1 - c)).toReal * 2 ^ n)) := by
rw [mul_comm _ c, mul_assoc, ← ENNReal.ofReal_mul (by positivity), ← Real.exp_add]
congr
norm_cast
simp only [Nat.cast_pow, Nat.cast_ofNat, ENNReal.toReal_div]
ring
open Metric in
lemma lintegral_exp_mul_sq_norm_le_mul [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
(ha_pos : 0 < a)
{c' : ℝ≥0∞} (hc' : c' ≤ μ {x | ‖x‖ ≤ a}) (hc'_gt : 2⁻¹ < c') :
∫⁻ x, .ofReal (rexp (logRatio c' * a⁻¹ ^ 2 * ‖x‖ ^ 2)) ∂μ
≤ μ {x | ‖x‖ ≤ a} *
(.ofReal (rexp (logRatio c'))
+ ∑' n, .ofReal (rexp (-2⁻¹ * Real.log (c' / (1 - c')).toReal * 2 ^ n))) := by
let t := normThreshold a
let c := μ {x | ‖x‖ ≤ a}
let C := logRatio c' * a⁻¹ ^ 2
have hc'_le : c' ≤ 1 := hc'.trans prob_le_one
-- We want to bound an integral
change ∫⁻ x, .ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ
≤ c * (.ofReal (rexp (logRatio c'))
+ ∑' n, .ofReal (rexp (-2⁻¹ * Real.log (c' / (1 - c')).toReal * 2 ^ n)))
-- We will cut the space into a ball of radius `a` and annuli defined from the thresholds `t n`
-- and bound the integral on each piece.
-- First, we bound the integral on the ball of radius `a`
have ht_int_zero : ∫⁻ x in closedBall 0 a, .ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ
≤ μ {x | ‖x‖ ≤ a} * .ofReal (rexp (logRatio c')) := by
calc ∫⁻ x in closedBall 0 a, .ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ
_ ≤ ∫⁻ x in closedBall 0 a, .ofReal (rexp (C * a ^ 2)) ∂μ := by
refine setLIntegral_mono (by fun_prop) fun x hx ↦ ?_
gcongr
· exact mul_nonneg (logRatio_nonneg hc'_gt.le hc'_le) (by positivity)
· simpa using hx
_ = μ {x | ‖x‖ ≤ a} * .ofReal (rexp (logRatio c')) := by
simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter]
rw [mul_comm]
simp only [inv_pow, C]
field_simp
congr with x
simp
-- We dispense with an edge case. If `μ {x | ‖x‖ ≤ a} = 1`, then the integral over
-- the complement of the ball is zero and we are done.
by_cases ha : μ {x | ‖x‖ ≤ a} = 1
· simp [c, ha] at ht_int_zero ⊢
refine le_add_right ((le_of_eq ?_).trans ht_int_zero)
rw [← setLIntegral_univ]
refine setLIntegral_congr ?_
rw [← ae_iff_prob_eq_one ?_] at ha
· rw [eventuallyEq_comm, ae_eq_univ]
change μ {x | ¬ x ∈ closedBall 0 a} = 0
rw [← ae_iff]
filter_upwards [ha] with x hx using by simp [hx]
· refine measurable_to_prop ?_
rw [show (fun x : E ↦ ‖x‖ ≤ a) ⁻¹' {True} = {x : E | ‖x‖ ≤ a} by ext; simp]
exact measurableSet_le (by fun_prop) (by fun_prop)
-- So we can assume `μ {x | ‖x‖ ≤ a} < 1`, which implies `c' < 1`
have ha_lt : μ {x | ‖x‖ ≤ a} < 1 := lt_of_le_of_ne prob_le_one ha
have hc'_lt : c' < 1 := lt_of_le_of_lt hc' ha_lt
-- We cut the space into a ball and a sequence of annuli between the thresholds `t n`
have h_iUnion : (Set.univ : Set E)
= closedBall 0 a ∪ ⋃ n, closedBall 0 (t (n + 1)) \ closedBall 0 (t n) := by
ext x
simp only [Set.mem_univ, Set.mem_union, Metric.mem_closedBall, dist_zero_right, Set.mem_iUnion,
Set.mem_diff, not_le, true_iff]
simp_rw [and_comm (b := t _ < ‖x‖)]
rcases le_or_gt (‖x‖) a with ha' | ha'
· exact Or.inl ha'
· exact Or.inr <| (normThreshold_strictMono ha_pos).exists_between_of_tendsto_atTop
(tendsto_normThreshold_atTop ha_pos) ha'
-- The integral over the union is at most the sum of the integrals
rw [← setLIntegral_univ, h_iUnion]
have : ∫⁻ x in closedBall 0 (t 0) ∪ ⋃ n, closedBall 0 (t (n + 1)) \ closedBall 0 (t n),
.ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ
≤ ∫⁻ x in closedBall 0 (t 0), .ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ +
∑' i, ∫⁻ x in closedBall 0 (t (i + 1)) \ closedBall 0 (t i),
.ofReal (rexp (C * ‖x‖ ^ 2)) ∂μ := by
refine (lintegral_union_le _ _ _).trans ?_
gcongr
exact lintegral_iUnion_le _ _
-- Each of the integrals in the sum correspond to the terms in the goal
refine this.trans ?_
rw [mul_add]
gcongr
-- We already proved the upper bound for the ball
· exact ht_int_zero
rw [← ENNReal.tsum_mul_left]
gcongr with n
-- Now we prove the bound for each annulus, by calling a previous lemma
refine (le_trans ?_ (lintegral_closedBall_diff_exp_logRatio_mul_sq_le h_rot
(hc'_gt.trans_le hc') ha_lt n)).trans ?_
· gcongr
simp only [inv_pow, C]
field_simp
exact logRatio_mono hc'_gt ha_lt hc'
gcongr _ * ENNReal.ofReal (rexp ?_)
simp only [ENNReal.toReal_div, neg_mul, neg_le_neg_iff]
gcongr
· refine div_pos ?_ ?_
all_goals rw [ENNReal.toReal_pos_iff]
· exact ⟨lt_trans (by norm_num) hc'_gt, by finiteness⟩
· simp only [tsub_pos_iff_lt, hc'_lt, true_and]
finiteness
· simp only [ENNReal.toReal_pos_iff, tsub_pos_iff_lt]
exact ⟨ha_lt, by finiteness⟩
· finiteness
· finiteness
end Fernique
open Fernique
/-- For `μ` a probability measure whose product with itself is invariant by rotation and for `a, c`
with `2⁻¹ < c ≤ μ {x | ‖x‖ ≤ a}`, the integral `∫⁻ x, exp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2) ∂μ`
is bounded by a quantity that does not depend on `a`. -/
theorem lintegral_exp_mul_sq_norm_le_of_map_rotation_eq_self [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
{c : ℝ≥0∞} (hc : c ≤ μ {x | ‖x‖ ≤ a}) (hc_gt : 2⁻¹ < c) :
∫⁻ x, .ofReal (rexp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2)) ∂μ
≤ .ofReal (rexp (logRatio c))
+ ∑' n, .ofReal (rexp (-2⁻¹ * Real.log (c / (1 - c)).toReal * 2 ^ n)) := by
have ha : 0 ≤ a := by
by_contra! h_neg
have : {x : E | ‖x‖ ≤ a} = ∅ := by
ext x
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false, not_le]
exact h_neg.trans_le (norm_nonneg _)
simp only [this, measure_empty, nonpos_iff_eq_zero] at hc
simp [hc] at hc_gt
cases ha.eq_or_lt' with
| inl ha =>
simp only [ha, inv_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_zero,
zero_mul, Real.exp_zero, ENNReal.ofReal_one, lintegral_const, measure_univ, mul_one,
ENNReal.toReal_div, neg_mul]
refine le_add_right ?_
rw [← ENNReal.ofReal_one]
gcongr
simp only [Real.one_le_exp_iff]
exact logRatio_nonneg hc_gt.le (hc.trans prob_le_one)
| inr ha_pos =>
refine (lintegral_exp_mul_sq_norm_le_mul h_rot ha_pos hc hc_gt).trans ?_
conv_rhs => rw [← one_mul (ENNReal.ofReal _ + _)]
gcongr
exact prob_le_one
/-- Auxiliary lemma for `exists_integrable_exp_sq_of_map_rotation_eq_self`.
The assumptions on `a` and `μ {x | ‖x‖ ≤ a}` are not needed and will be removed in that more
general theorem. -/
lemma exists_integrable_exp_sq_of_map_rotation_eq_self' [IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ)
{a : ℝ} (ha_pos : 0 < a) (ha_gt : 2⁻¹ < μ {x | ‖x‖ ≤ a}) (ha_lt : μ {x | ‖x‖ ≤ a} < 1) :
∃ C, 0 < C ∧ Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2)) μ := by
let c := μ {x | ‖x‖ ≤ a}
replace hc_lt : c < 1 := ha_lt
have hc_lt_top : c < ∞ := measure_lt_top _ _
have hc_one_sub_lt_top : 1 - c < ∞ := lt_top_of_lt (b := 2) (tsub_le_self.trans_lt (by simp))
have h_one_sub_lt_self : 1 - c < c := by
refine ENNReal.sub_lt_of_lt_add hc_lt.le ?_
rw [← two_mul]
rwa [inv_eq_one_div, ENNReal.div_lt_iff (by simp) (by simp), mul_comm] at ha_gt
have h_pos : 0 < logRatio c * a⁻¹ ^ 2 := mul_pos (logRatio_pos ha_gt hc_lt) (by positivity)
refine ⟨logRatio c * a⁻¹ ^ 2, h_pos, ⟨by fun_prop, ?_⟩⟩
simp only [HasFiniteIntegral, ← ofReal_norm_eq_enorm, Real.norm_eq_abs, Real.abs_exp]
-- `⊢ ∫⁻ x, ENNReal.ofReal (rexp (logRatio c * a⁻¹ ^ 2 * ‖x‖ ^ 2)) ∂μ < ∞`
refine (lintegral_exp_mul_sq_norm_le_of_map_rotation_eq_self h_rot le_rfl ha_gt).trans_lt ?_
refine ENNReal.add_lt_top.mpr ⟨ENNReal.ofReal_lt_top, ?_⟩
refine Summable.tsum_ofReal_lt_top <|
Real.summable_exp_nat_mul_of_ge ?_ (fun i ↦ mod_cast (Nat.lt_pow_self (by simp)).le)
refine mul_neg_of_neg_of_pos (by simp) (Real.log_pos ?_)
change 1 < (c / (1 - c)).toReal
simp only [ENNReal.toReal_div, one_lt_div_iff, ENNReal.toReal_pos_iff, tsub_pos_iff_lt, hc_lt,
hc_one_sub_lt_top, and_self, true_and]
rw [ENNReal.toReal_lt_toReal hc_one_sub_lt_top.ne hc_lt_top.ne]
exact .inl h_one_sub_lt_self
/-- Auxiliary lemma for `exists_integrable_exp_sq_of_map_rotation_eq_self`, in which we will replace
the assumption `IsProbabilityMeasure μ` by the weaker `IsFiniteMeasure μ`. -/
lemma exists_integrable_exp_sq_of_map_rotation_eq_self_of_isProbabilityMeasure
[IsProbabilityMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ) :
∃ C, 0 < C ∧ Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2)) μ := by
-- If there exists `a > 0` such that `2⁻¹ < μ {x | ‖x‖ ≤ a} < 1`, we can call the previous lemma.
by_cases h_meas_Ioo : ∃ a, 0 < a ∧ 2⁻¹ < μ {x | ‖x‖ ≤ a} ∧ μ {x | ‖x‖ ≤ a} < 1
· obtain ⟨a, ha_pos, ha_gt, ha_lt⟩ : ∃ a, 0 < a ∧ 2⁻¹ < μ {x | ‖x‖ ≤ a} ∧ μ {x | ‖x‖ ≤ a} < 1 :=
h_meas_Ioo
exact exists_integrable_exp_sq_of_map_rotation_eq_self' h_rot ha_pos ha_gt ha_lt
-- Otherwise, we can find `b > 0` such that the ball of radius `b` has full measure
obtain ⟨b, hb⟩ : ∃ b, μ {x | ‖x‖ ≤ b} = 1 := by
by_contra h_ne
push_neg at h_meas_Ioo h_ne
suffices μ .univ ≤ 2⁻¹ by simp at this
have h_le a : μ {x | ‖x‖ ≤ a} ≤ 2⁻¹ := by
have h_of_pos a' (ha : 0 < a') : μ {x | ‖x‖ ≤ a'} ≤ 2⁻¹ := by
by_contra h_lt
refine h_ne a' ?_
exact le_antisymm prob_le_one (h_meas_Ioo a' ha (not_le.mp h_lt))
rcases le_or_gt a 0 with ha | ha
· calc μ {x | ‖x‖ ≤ a}
_ ≤ μ {x | ‖x‖ ≤ 1} := measure_mono fun x hx ↦ hx.trans (ha.trans (by positivity))
_ ≤ 2⁻¹ := h_of_pos _ (by positivity)
· exact h_of_pos a ha
have h_univ : (Set.univ : Set E) = ⋃ a : ℕ, {x | ‖x‖ ≤ a} := by
ext x
simp only [Set.mem_univ, Set.mem_iUnion, Set.mem_setOf_eq, true_iff]
exact exists_nat_ge _
rw [h_univ, Monotone.measure_iUnion]
· simp [h_le]
· intro a b hab x hx
simp only [Set.mem_setOf_eq] at hx ⊢
exact hx.trans (mod_cast hab)
-- So we can take `C = 1` and show that `x ↦ exp (‖x‖ ^ 2)` is integrable, since it is bounded.
have hb' : ∀ᵐ x ∂μ, ‖x‖ ≤ b := by
rwa [ae_iff_prob_eq_one]
refine measurable_to_prop ?_
rw [show (fun x : E ↦ ‖x‖ ≤ b) ⁻¹' {True} = {x : E | ‖x‖ ≤ b} by ext; simp]
exact measurableSet_le (by fun_prop) (by fun_prop)
refine ⟨1, by positivity, ?_⟩
refine integrable_of_le_of_le (g₁ := 0) (g₂ := fun _ ↦ rexp (b ^ 2)) (by fun_prop)
?_ ?_ (integrable_const _) (integrable_const _)
· exact ae_of_all _ fun _ ↦ by positivity
· filter_upwards [hb'] with x hx
simp only [one_mul]
gcongr
/-- **Fernique's theorem** for finite measures whose product is invariant by rotation: there exists
`C > 0` such that the function `x ↦ exp (C * ‖x‖ ^ 2)` is integrable. -/
theorem exists_integrable_exp_sq_of_map_rotation_eq_self [IsFiniteMeasure μ]
(h_rot : (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) = μ.prod μ) :
∃ C, 0 < C ∧ Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2)) μ := by
by_cases hμ_zero : μ = 0
· exact ⟨1, by positivity, by simp [hμ_zero]⟩
let μ' := cond μ .univ
have hμ'_eq : μ' = (μ .univ)⁻¹ • μ := by simp [μ', cond]
have hμ' : IsProbabilityMeasure μ' := cond_isProbabilityMeasure <| by simp [hμ_zero]
have h_rot : (μ'.prod μ').map (ContinuousLinearMap.rotation (-(π / 4))) = μ'.prod μ' := by
calc (μ'.prod μ').map (ContinuousLinearMap.rotation (-(π / 4)))
_ = ((μ Set.univ)⁻¹ * (μ Set.univ)⁻¹)
• (μ.prod μ).map (ContinuousLinearMap.rotation (-(π / 4))) := by
simp [hμ'_eq, Measure.prod_smul_left, Measure.prod_smul_right, smul_smul]
_ = ((μ Set.univ)⁻¹ * (μ Set.univ)⁻¹) • (μ.prod μ) := by rw [h_rot]
_ = μ'.prod μ' := by
simp [hμ'_eq, Measure.prod_smul_left, Measure.prod_smul_right, smul_smul]
obtain ⟨C, hC_pos, hC⟩ :=
exists_integrable_exp_sq_of_map_rotation_eq_self_of_isProbabilityMeasure (μ := μ') h_rot
refine ⟨C, hC_pos, ?_⟩
rwa [hμ'_eq, integrable_smul_measure] at hC
· simp
· simp [hμ_zero]
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Geometric.lean | import Mathlib.Probability.ProbabilityMassFunction.Basic
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic
/-! # Geometric distributions over ℕ
Define the geometric measure over the natural numbers
## Main definitions
* `geometricPMFReal`: the function `p n ↦ (1-p) ^ n * p`
for `n ∈ ℕ`, which is the probability density function of a geometric distribution with
success probability `p ∈ (0,1]`.
* `geometricPMF`: `ℝ≥0∞`-valued pmf,
`geometricPMF p = ENNReal.ofReal (geometricPMFReal p)`.
* `geometricMeasure`: a geometric measure on `ℕ`, parametrized by its success probability `p`.
-/
open scoped ENNReal NNReal
open MeasureTheory Real Set Filter Topology
namespace ProbabilityTheory
variable {p : ℝ}
section GeometricPMF
/-- The pmf of the geometric distribution depending on its success probability. -/
noncomputable
def geometricPMFReal (p : ℝ) (n : ℕ) : ℝ := (1 - p) ^ n * p
lemma geometricPMFRealSum (hp_pos : 0 < p) (hp_le_one : p ≤ 1) :
HasSum (fun n ↦ geometricPMFReal p n) 1 := by
unfold geometricPMFReal
have := hasSum_geometric_of_lt_one (sub_nonneg.mpr hp_le_one) (sub_lt_self 1 hp_pos)
apply (hasSum_mul_right_iff (hp_pos.ne')).mpr at this
simp only [sub_sub_cancel] at this
rw [inv_mul_eq_div, div_self hp_pos.ne'] at this
exact this
/-- The geometric pmf is positive for all natural numbers -/
lemma geometricPMFReal_pos {n : ℕ} (hp_pos : 0 < p) (hp_lt_one : p < 1) :
0 < geometricPMFReal p n := by
rw [geometricPMFReal]
positivity [sub_pos.mpr hp_lt_one]
lemma geometricPMFReal_nonneg {n : ℕ} (hp_pos : 0 < p) (hp_le_one : p ≤ 1) :
0 ≤ geometricPMFReal p n := by
rw [geometricPMFReal]
positivity [sub_nonneg.mpr hp_le_one]
/-- Geometric distribution with success probability `p`. -/
noncomputable
def geometricPMF (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : PMF ℕ :=
⟨fun n ↦ ENNReal.ofReal (geometricPMFReal p n), by
apply ENNReal.hasSum_coe.mpr
rw [← toNNReal_one]
exact (geometricPMFRealSum hp_pos hp_le_one).toNNReal
(fun n ↦ geometricPMFReal_nonneg hp_pos hp_le_one)⟩
/-- The geometric pmf is measurable. -/
@[fun_prop, measurability]
lemma measurable_geometricPMFReal : Measurable (geometricPMFReal p) := by
fun_prop
@[fun_prop, measurability]
lemma stronglyMeasurable_geometricPMFReal : StronglyMeasurable (geometricPMFReal p) :=
stronglyMeasurable_iff_measurable.mpr measurable_geometricPMFReal
end GeometricPMF
/-- Measure defined by the geometric distribution -/
noncomputable
def geometricMeasure (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : Measure ℕ :=
(geometricPMF hp_pos hp_le_one).toMeasure
lemma isProbabilityMeasure_geometricMeasure (hp_pos : 0 < p) (hp_le_one : p ≤ 1) :
IsProbabilityMeasure (geometricMeasure hp_pos hp_le_one) :=
PMF.toMeasure.isProbabilityMeasure (geometricPMF hp_pos hp_le_one)
@[deprecated (since := "2025-08-28")] alias isProbabilityMeasureGeometric :=
isProbabilityMeasure_geometricMeasure
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Beta.lean | import Mathlib.Analysis.SpecialFunctions.Gamma.Beta
/-! # Beta distributions over ℝ
Define the beta distribution over the reals.
## Main definitions
* `betaPDFReal`: the function `α β x ↦ (1 / beta α β) * x ^ (α - 1) * (1 - x) ^ (β - 1)`
for `0 < x ∧ x < 1` or `0` else, which is the probability density function of a beta distribution
with shape parameters `α` and `β` (when `0 < α` and `0 < β`).
* `betaPDF`: `ℝ≥0∞`-valued pdf,
`betaPDF α β = ENNReal.ofReal (betaPDFReal α β)`.
-/
open scoped ENNReal NNReal
open MeasureTheory Complex Set
namespace ProbabilityTheory
section BetaPDF
/-- The normalizing constant in the beta distribution. -/
noncomputable def beta (α β : ℝ) : ℝ :=
Real.Gamma α * Real.Gamma β / Real.Gamma (α + β)
lemma beta_pos {α β : ℝ} (hα : 0 < α) (hβ : 0 < β) : 0 < beta α β :=
div_pos (mul_pos (Real.Gamma_pos_of_pos hα) (Real.Gamma_pos_of_pos hβ))
(Real.Gamma_pos_of_pos (add_pos hα hβ))
/-- Relation between the beta function and the gamma function over the reals. -/
theorem beta_eq_betaIntegralReal (α β : ℝ) (hα : 0 < α) (hβ : 0 < β) :
beta α β = (betaIntegral α β).re := by
rw [betaIntegral_eq_Gamma_mul_div]
· simp_rw [beta, ← ofReal_add α β, Gamma_ofReal]
norm_cast
all_goals simpa
/-- The probability density function of the beta distribution with shape parameters `α` and `β`.
Returns `(1 / beta α β) * x ^ (α - 1) * (1 - x) ^ (β - 1)`
when `0 < x < 1` and `0` otherwise. -/
noncomputable def betaPDFReal (α β x : ℝ) : ℝ :=
if 0 < x ∧ x < 1 then
(1 / beta α β) * x ^ (α - 1) * (1 - x) ^ (β - 1)
else
0
/-- The pdf of the beta distribution, as a function valued in `ℝ≥0∞`. -/
noncomputable def betaPDF (α β x : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (betaPDFReal α β x)
lemma betaPDF_eq (α β x : ℝ) :
betaPDF α β x =
ENNReal.ofReal (if 0 < x ∧ x < 1 then
(1 / beta α β) * x ^ (α - 1) * (1 - x) ^ (β - 1) else 0) := rfl
lemma betaPDF_eq_zero_of_nonpos {α β x : ℝ} (hx : x ≤ 0) :
betaPDF α β x = 0 := by
simp [betaPDF_eq, hx.not_gt]
lemma betaPDF_eq_zero_of_one_le {α β x : ℝ} (hx : 1 ≤ x) :
betaPDF α β x = 0 := by
simp [betaPDF_eq, hx.not_gt]
lemma betaPDF_of_pos_lt_one {α β x : ℝ} (hx_pos : 0 < x) (hx_lt : x < 1) :
betaPDF α β x = ENNReal.ofReal ((1 / beta α β) * x ^ (α - 1) * (1 - x) ^ (β - 1)) := by
rw [betaPDF_eq, if_pos ⟨hx_pos, hx_lt⟩]
lemma lintegral_betaPDF {α β : ℝ} :
∫⁻ x, betaPDF α β x =
∫⁻ (x : ℝ) in Ioo 0 1, ENNReal.ofReal (1 / beta α β * x ^ (α - 1) * (1 - x) ^ (β - 1)) := by
rw [← lintegral_add_compl _ measurableSet_Iic,
setLIntegral_eq_zero measurableSet_Iic (fun x (hx : x ≤ 0) ↦ betaPDF_eq_zero_of_nonpos hx),
zero_add, compl_Iic, ← lintegral_add_compl _ measurableSet_Ici,
setLIntegral_eq_zero measurableSet_Ici (fun x (hx : 1 ≤ x) ↦ betaPDF_eq_zero_of_one_le hx),
zero_add, compl_Ici, Measure.restrict_restrict measurableSet_Iio, Iio_inter_Ioi,
setLIntegral_congr_fun measurableSet_Ioo
(fun x ⟨hx_pos, hx_lt⟩ ↦ betaPDF_of_pos_lt_one hx_pos hx_lt)]
/-- The beta pdf is positive for all positive reals with positive parameters. -/
lemma betaPDFReal_pos {α β x : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hα : 0 < α) (hβ : 0 < β) :
0 < betaPDFReal α β x := by
rw [betaPDFReal, if_pos ⟨hx1, hx2⟩]
exact mul_pos (mul_pos (one_div_pos.2 (beta_pos hα hβ)) (Real.rpow_pos_of_pos hx1 (α - 1)))
(Real.rpow_pos_of_pos (by linarith) (β - 1))
/-- The beta pdf is measurable. -/
@[fun_prop, measurability]
lemma measurable_betaPDFReal (α β : ℝ) : Measurable (betaPDFReal α β) :=
Measurable.ite measurableSet_Ioo (by fun_prop) (by fun_prop)
/-- The beta pdf is strongly measurable. -/
@[measurability]
lemma stronglyMeasurable_betaPDFReal (α β : ℝ) :
StronglyMeasurable (betaPDFReal α β) := (measurable_betaPDFReal α β).stronglyMeasurable
/-- The pdf of the beta distribution integrates to 1. -/
@[simp]
lemma lintegral_betaPDF_eq_one {α β : ℝ} (hα : 0 < α) (hβ : 0 < β) :
∫⁻ x, betaPDF α β x = 1 := by
rw [lintegral_betaPDF, ← ENNReal.toReal_eq_one_iff, ← integral_eq_lintegral_of_nonneg_ae]
· simp_rw [mul_assoc, integral_const_mul]
field_simp
rw [div_eq_one_iff_eq (ne_of_gt (beta_pos hα hβ)), beta_eq_betaIntegralReal α β hα hβ,
betaIntegral, intervalIntegral.integral_of_le (by norm_num),
← integral_Ioc_eq_integral_Ioo, ← RCLike.re_to_complex, ← integral_re]
· refine setIntegral_congr_fun measurableSet_Ioc fun x ⟨hx1, hx₂⟩ ↦ ?_
norm_cast
rw [← Complex.ofReal_cpow, ← Complex.ofReal_cpow, RCLike.re_to_complex,
Complex.re_mul_ofReal, Complex.ofReal_re]
all_goals linarith
convert betaIntegral_convergent (u := α) (v := β) (by simpa) (by simpa)
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le (by simp), IntegrableOn]
· refine ae_restrict_of_forall_mem measurableSet_Ioo (fun x hx ↦ ?_)
convert betaPDFReal_pos hx.1 hx.2 hα hβ |>.le using 1
rw [betaPDFReal, if_pos ⟨hx.1, hx.2⟩]
· exact Measurable.aestronglyMeasurable (by fun_prop)
end BetaPDF
/-- Measure defined by the beta distribution. -/
noncomputable
def betaMeasure (α β : ℝ) : Measure ℝ :=
volume.withDensity (betaPDF α β)
lemma isProbabilityMeasureBeta {α β : ℝ} (hα : 0 < α) (hβ : 0 < β) :
IsProbabilityMeasure (betaMeasure α β) where
measure_univ := by simp [betaMeasure, lintegral_betaPDF_eq_one hα hβ]
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Poisson.lean | import Mathlib.Analysis.SpecialFunctions.Exponential
import Mathlib.Probability.ProbabilityMassFunction.Basic
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic
/-! # Poisson distributions over ℕ
Define the Poisson measure over the natural numbers
## Main definitions
* `poissonPMFReal`: the function `fun n ↦ exp (- λ) * λ ^ n / n!`
for `n ∈ ℕ`, which is the probability density function of a Poisson distribution with
rate `λ > 0`.
* `poissonPMF`: `ℝ≥0∞`-valued pdf,
`poissonPMF λ = ENNReal.ofReal (poissonPMFReal λ)`.
* `poissonMeasure`: a Poisson measure on `ℕ`, parametrized by its rate `λ`.
-/
open scoped ENNReal NNReal Nat
open MeasureTheory Real Set Filter Topology
namespace ProbabilityTheory
section PoissonPMF
/-- The pmf of the Poisson distribution depending on its rate, as a function to ℝ -/
noncomputable
def poissonPMFReal (r : ℝ≥0) (n : ℕ) : ℝ := exp (-r) * r ^ n / n !
lemma poissonPMFRealSum (r : ℝ≥0) : HasSum (fun n ↦ poissonPMFReal r n) 1 := by
let r := r.toReal
unfold poissonPMFReal
apply (hasSum_mul_left_iff (exp_ne_zero r)).mp
simp only [mul_one]
have : (fun i ↦ rexp r * (rexp (-r) * r ^ i / ↑(Nat.factorial i))) =
fun i ↦ r ^ i / ↑(Nat.factorial i) := by
ext n
rw [mul_div_assoc, exp_neg, ← mul_assoc, ← div_eq_mul_inv, div_self (exp_ne_zero r), one_mul]
rw [this, exp_eq_exp_ℝ]
exact NormedSpace.expSeries_div_hasSum_exp ℝ r
/-- The Poisson pmf is positive for all natural numbers -/
lemma poissonPMFReal_pos {r : ℝ≥0} {n : ℕ} (hr : 0 < r) : 0 < poissonPMFReal r n := by
rw [poissonPMFReal]
positivity
lemma poissonPMFReal_nonneg {r : ℝ≥0} {n : ℕ} : 0 ≤ poissonPMFReal r n := by
unfold poissonPMFReal
positivity
/-- The pmf of the Poisson distribution depending on its rate, as a PMF. -/
noncomputable
def poissonPMF (r : ℝ≥0) : PMF ℕ := by
refine ⟨fun n ↦ ENNReal.ofReal (poissonPMFReal r n), ?_⟩
apply ENNReal.hasSum_coe.mpr
rw [← toNNReal_one]
exact (poissonPMFRealSum r).toNNReal (fun n ↦ poissonPMFReal_nonneg)
/-- The Poisson pmf is measurable. -/
@[fun_prop, measurability]
lemma measurable_poissonPMFReal (r : ℝ≥0) : Measurable (poissonPMFReal r) := by fun_prop
@[fun_prop, measurability]
lemma stronglyMeasurable_poissonPMFReal (r : ℝ≥0) : StronglyMeasurable (poissonPMFReal r) :=
stronglyMeasurable_iff_measurable.mpr (measurable_poissonPMFReal r)
end PoissonPMF
/-- Measure defined by the Poisson distribution -/
noncomputable
def poissonMeasure (r : ℝ≥0) : Measure ℕ := (poissonPMF r).toMeasure
instance isProbabilityMeasurePoisson (r : ℝ≥0) :
IsProbabilityMeasure (poissonMeasure r) := PMF.toMeasure.isProbabilityMeasure (poissonPMF r)
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Gaussian/Basic.lean | import Mathlib.Probability.Distributions.Gaussian.Real
/-!
# Gaussian distributions in Banach spaces
We introduce a predicate `IsGaussian` for measures on a Banach space `E` such that the map by
any continuous linear form is a Gaussian measure on `ℝ`.
For Gaussian distributions in `ℝ`, see the file `Mathlib.Probability.Distributions.Gaussian.Real`.
## Main definitions
* `IsGaussian`: a measure `μ` is Gaussian if its map by every continuous linear form
`L : Dual ℝ E` is a real Gaussian measure.
That is, `μ.map L = gaussianReal (μ[L]) (Var[L; μ]).toNNReal`.
## Main statements
* `isGaussian_iff_charFunDual_eq`: a finite measure `μ` is Gaussian if and only if
its characteristic function has value `exp (μ[L] * I - Var[L; μ] / 2)` for every
continuous linear form `L : Dual ℝ E`.
## References
* [Martin Hairer, *An introduction to stochastic PDEs*][hairer2009introduction]
-/
open MeasureTheory Complex NormedSpace
open scoped ENNReal NNReal
namespace ProbabilityTheory
/-- A measure is Gaussian if its map by every continuous linear form is a real Gaussian measure. -/
class IsGaussian {E : Type*} [TopologicalSpace E] [AddCommMonoid E] [Module ℝ E]
{mE : MeasurableSpace E} (μ : Measure E) : Prop where
map_eq_gaussianReal (L : StrongDual ℝ E) : μ.map L = gaussianReal (μ[L]) (Var[L; μ]).toNNReal
/-- A Gaussian measure is a probability measure. -/
instance IsGaussian.toIsProbabilityMeasure {E : Type*} [TopologicalSpace E] [AddCommMonoid E]
[Module ℝ E] {mE : MeasurableSpace E} (μ : Measure E) [IsGaussian μ] :
IsProbabilityMeasure μ where
measure_univ := by
have : μ.map (0 : StrongDual ℝ E) Set.univ = 1 := by simp [IsGaussian.map_eq_gaussianReal]
simpa [Measure.map_apply (by fun_prop : Measurable (0 : StrongDual ℝ E)) .univ] using this
/-- A real Gaussian measure is Gaussian. -/
instance isGaussian_gaussianReal (m : ℝ) (v : ℝ≥0) : IsGaussian (gaussianReal m v) where
map_eq_gaussianReal L := by
rw [gaussianReal_map_continuousLinearMap]
simp only [integral_continuousLinearMap_gaussianReal, variance_continuousLinearMap_gaussianReal,
Real.coe_toNNReal']
congr
rw [Real.toNNReal_mul (by positivity), Real.toNNReal_coe]
congr
simp only [left_eq_sup]
positivity
variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [MeasurableSpace F] [BorelSpace F]
{μ : Measure E} [IsGaussian μ]
/-- Dirac measures are Gaussian. -/
instance {x : E} : IsGaussian (Measure.dirac x) where
map_eq_gaussianReal L := by rw [Measure.map_dirac (by fun_prop)]; simp
lemma IsGaussian.memLp_dual (μ : Measure E) [IsGaussian μ] (L : StrongDual ℝ E)
(p : ℝ≥0∞) (hp : p ≠ ∞) :
MemLp L p μ := by
suffices MemLp (id ∘ L) p μ from this
rw [← memLp_map_measure_iff (by fun_prop) (by fun_prop), IsGaussian.map_eq_gaussianReal L]
convert memLp_id_gaussianReal p.toNNReal
simp [hp]
@[fun_prop]
lemma IsGaussian.integrable_dual (μ : Measure E) [IsGaussian μ] (L : StrongDual ℝ E) :
Integrable L μ := by
rw [← memLp_one_iff_integrable]
exact IsGaussian.memLp_dual μ L 1 (by simp)
/-- The map of a Gaussian measure by a continuous linear map is Gaussian. -/
instance isGaussian_map (L : E →L[ℝ] F) : IsGaussian (μ.map L) where
map_eq_gaussianReal L' := by
rw [Measure.map_map (by fun_prop) (by fun_prop)]
change Measure.map (L'.comp L) μ = _
rw [IsGaussian.map_eq_gaussianReal (L'.comp L)]
congr
· rw [integral_map (by fun_prop) (by fun_prop)]
simp
· rw [← variance_id_map (by fun_prop)]
conv_rhs => rw [← variance_id_map (by fun_prop)]
rw [Measure.map_map (by fun_prop) (by fun_prop)]
simp
instance isGaussian_map_equiv (L : E ≃L[ℝ] F) : IsGaussian (μ.map L) :=
isGaussian_map (L : E →L[ℝ] F)
lemma isGaussian_map_equiv_iff {μ : Measure E} (L : E ≃L[ℝ] F) :
IsGaussian (μ.map L) ↔ IsGaussian μ := by
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
suffices μ = (μ.map L).map L.symm by rw [this]; infer_instance
rw [Measure.map_map (by fun_prop) (by fun_prop)]
simp
section charFunDual
/-- The characteristic function of a Gaussian measure `μ` has value
`exp (μ[L] * I - Var[L; μ] / 2)` at `L : Dual ℝ E`. -/
lemma IsGaussian.charFunDual_eq (L : StrongDual ℝ E) :
charFunDual μ L = exp (μ[L] * I - Var[L; μ] / 2) := by
calc charFunDual μ L
_ = charFun (μ.map L) 1 := by rw [charFunDual_eq_charFun_map_one]
_ = charFun (gaussianReal (μ[L]) (Var[L; μ]).toNNReal) 1 := by
rw [IsGaussian.map_eq_gaussianReal L]
_ = exp (μ[L] * I - Var[L; μ] / 2) := by
rw [charFun_gaussianReal]
simp only [ofReal_one, one_mul, Real.coe_toNNReal', one_pow, mul_one]
congr
· rw [integral_complex_ofReal]
· simp only [sup_eq_left]
exact variance_nonneg _ _
/-- A finite measure is Gaussian iff its characteristic function has value
`exp (μ[L] * I - Var[L; μ] / 2)` for every `L : Dual ℝ E`. -/
theorem isGaussian_iff_charFunDual_eq {μ : Measure E} [IsFiniteMeasure μ] :
IsGaussian μ ↔ ∀ L : StrongDual ℝ E, charFunDual μ L = exp (μ[L] * I - Var[L; μ] / 2) := by
refine ⟨fun h ↦ h.charFunDual_eq, fun h ↦ ⟨fun L ↦ Measure.ext_of_charFun ?_⟩⟩
ext u
rw [charFun_map_eq_charFunDual_smul L u, h (u • L), charFun_gaussianReal]
simp only [ContinuousLinearMap.coe_smul', Pi.smul_apply, smul_eq_mul, ofReal_mul,
Real.coe_toNNReal']
congr
· rw [integral_const_mul, integral_complex_ofReal]
· rw [max_eq_left (variance_nonneg _ _), mul_comm, ← ofReal_pow, ← ofReal_mul, ← variance_mul]
congr
alias ⟨_, isGaussian_of_charFunDual_eq⟩ := isGaussian_iff_charFunDual_eq
end charFunDual
instance isGaussian_conv [SecondCountableTopology E]
{μ ν : Measure E} [IsGaussian μ] [IsGaussian ν] :
IsGaussian (μ ∗ ν) where
map_eq_gaussianReal L := by
have : (μ ∗ ν)[L] = ∫ x, x ∂((μ.map L).conv (ν.map L)) := by
rw [← Measure.map_conv_continuousLinearMap L,
integral_map (φ := L) (by fun_prop) (by fun_prop)]
rw [Measure.map_conv_continuousLinearMap L, this, ← variance_id_map (by fun_prop),
Measure.map_conv_continuousLinearMap L, IsGaussian.map_eq_gaussianReal L,
IsGaussian.map_eq_gaussianReal L, gaussianReal_conv_gaussianReal]
congr <;> simp [variance_nonneg]
instance (c : E) : IsGaussian (μ.map (fun x ↦ x + c)) := by
refine isGaussian_of_charFunDual_eq fun L ↦ ?_
rw [charFunDual_map_add_const, IsGaussian.charFunDual_eq, ← exp_add]
have hL_comp : L ∘ (fun x ↦ x + c) = fun x ↦ L x + L c := by ext; simp
rw [variance_map (by fun_prop) (by fun_prop), integral_map (by fun_prop) (by fun_prop),
hL_comp, variance_add_const (by fun_prop), integral_complex_ofReal, integral_complex_ofReal]
simp only [map_add]
rw [integral_add (by fun_prop) (by fun_prop)]
congr
simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, one_mul, ofReal_add]
ring
instance (c : E) : IsGaussian (μ.map (fun x ↦ c + x)) := by simp_rw [add_comm c]; infer_instance
instance (c : E) : IsGaussian (μ.map (fun x ↦ x - c)) := by simp_rw [sub_eq_add_neg]; infer_instance
instance : IsGaussian (μ.map (fun x ↦ -x)) := by
change IsGaussian (μ.map (ContinuousLinearEquiv.neg ℝ))
infer_instance
instance (c : E) : IsGaussian (μ.map (fun x ↦ c - x)) := by
simp_rw [sub_eq_add_neg]
suffices IsGaussian ((μ.map (fun x ↦ -x)).map (fun x ↦ c + x)) by
rwa [Measure.map_map (by fun_prop) (by fun_prop), Function.comp_def] at this
infer_instance
/-- A product of Gaussian distributions is Gaussian. -/
instance [SecondCountableTopologyEither E F] {ν : Measure F} [IsGaussian ν] :
IsGaussian (μ.prod ν) := by
refine isGaussian_of_charFunDual_eq fun L ↦ ?_
rw [charFunDual_prod, IsGaussian.charFunDual_eq, IsGaussian.charFunDual_eq, ← Complex.exp_add]
congr
let (eq := hL₁) L₁ := L.comp (.inl ℝ E F)
let (eq := hL₂) L₂ := L.comp (.inr ℝ E F)
rw [← hL₁, ← hL₂, sub_add_sub_comm, ← add_mul]
congr
· simp_rw [integral_complex_ofReal]
rw [integral_continuousLinearMap_prod' (IsGaussian.integrable_dual μ (L.comp (.inl ℝ E F)))
(IsGaussian.integrable_dual ν (L.comp (.inr ℝ E F)))]
norm_cast
· field_simp
rw [variance_dual_prod' (IsGaussian.memLp_dual μ (L.comp (.inl ℝ E F)) 2 (by simp))
(IsGaussian.memLp_dual ν (L.comp (.inr ℝ E F)) 2 (by simp))]
norm_cast
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Gaussian/Fernique.lean | import Mathlib.Probability.Distributions.Fernique
import Mathlib.Probability.Distributions.Gaussian.Basic
/-!
# Fernique's theorem for Gaussian measures
We show that the product of two identical Gaussian measures is invariant under rotation.
We then deduce Fernique's theorem, which states that for a Gaussian measure `μ`, there exists
`C > 0` such that the function `x ↦ exp (C * ‖x‖ ^ 2)` is integrable with respect to `μ`.
As a consequence, a Gaussian measure has finite moments of all orders.
## Main statements
* `IsGaussian.exists_integrable_exp_sq`: **Fernique's theorem**. For a Gaussian measure on a
second-countable normed space, there exists `C > 0` such that the function
`x ↦ exp (C * ‖x‖ ^ 2)` is integrable.
* `IsGaussian.memLp_id`: a Gaussian measure in a second-countable Banach space has finite moments
of all orders.
## References
* [Martin Hairer, *An introduction to stochastic PDEs*][hairer2009introduction]
-/
open MeasureTheory ProbabilityTheory Complex NormedSpace
open scoped ENNReal NNReal Real Topology
namespace ProbabilityTheory.IsGaussian
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
{μ : Measure E} [IsGaussian μ]
section Rotation
/-- Characteristic function of a centered Gaussian measure.
For a Gaussian measure, the hypothesis `∀ L : StrongDual ℝ E, μ[L] = 0` is equivalent to the simpler
`μ[id] = 0`, but at this point we don't know yet that `μ` has a first moment so we can't use it.
See `charFunDual_eq_of_integral_eq_zero` -/
lemma charFunDual_eq_of_forall_strongDual_eq_zero (hμ : ∀ L : StrongDual ℝ E, μ[L] = 0)
(L : StrongDual ℝ E) :
charFunDual μ L = exp (- Var[L; μ] / 2) := by
simp [charFunDual_eq L, integral_complex_ofReal, hμ L, neg_div]
/-- For a centered Gaussian measure `μ`, the product measure `μ.prod μ` is invariant under rotation.
The hypothesis `∀ L : StrongDual ℝ E, μ[L] = 0` is equivalent to the simpler
`μ[id] = 0`, but at this point we don't know yet that `μ` has a first moment so we can't use it.
See `map_rotation_eq_self`. -/
lemma map_rotation_eq_self_of_forall_strongDual_eq_zero
[SecondCountableTopology E] [CompleteSpace E]
(hμ : ∀ L : StrongDual ℝ E, μ[L] = 0) (θ : ℝ) :
(μ.prod μ).map (ContinuousLinearMap.rotation θ) = μ.prod μ := by
refine Measure.ext_of_charFunDual ?_
ext L
simp_rw [charFunDual_map, charFunDual_prod, charFunDual_eq_of_forall_strongDual_eq_zero hμ,
← Complex.exp_add]
rw [← add_div, ← add_div, ← neg_add, ← neg_add]
congr 3
norm_cast
have h1 : (L.comp (.rotation θ)).comp (.inl ℝ E E)
= Real.cos θ • L.comp (.inl ℝ E E) - Real.sin θ • L.comp (.inr ℝ E E) := by
ext x
simp only [ContinuousLinearMap.coe_comp', Function.comp_apply, ContinuousLinearMap.inl_apply,
ContinuousLinearMap.rotation_apply, smul_zero, add_zero]
rw [← L.comp_inl_add_comp_inr]
simp [- neg_smul, sub_eq_add_neg]
have h2 : (L.comp (.rotation θ)).comp (.inr ℝ E E)
= Real.sin θ • L.comp (.inl ℝ E E) + Real.cos θ • L.comp (.inr ℝ E E) := by
ext x
simp only [ContinuousLinearMap.coe_comp', Function.comp_apply, ContinuousLinearMap.inr_apply,
ContinuousLinearMap.rotation_apply, smul_zero, zero_add, ContinuousLinearMap.add_apply,
ContinuousLinearMap.coe_smul', Pi.smul_apply, ContinuousLinearMap.inl_apply, smul_eq_mul]
rw [← L.comp_inl_add_comp_inr]
simp
rw [h1, h2]
simp only [ContinuousLinearMap.coe_sub', ContinuousLinearMap.coe_smul',
ContinuousLinearMap.coe_add']
rw [variance_sub, variance_smul, variance_add, variance_smul, variance_smul, covariance_smul_left,
covariance_smul_right, variance_smul, covariance_smul_left, covariance_smul_right]
· have h := Real.cos_sq_add_sin_sq θ
grind
all_goals exact (memLp_dual _ _ _ (by simp)).const_smul _
end Rotation
section Fernique
variable [SecondCountableTopology E]
/-- The convolution of a Gaussian measure `μ` and its map by `x ↦ -x` is centered. -/
lemma integral_dual_conv_map_neg_eq_zero (L : StrongDual ℝ E) :
(μ ∗ (μ.map (ContinuousLinearEquiv.neg ℝ)))[L] = 0 := by
rw [integral_conv (by fun_prop)]
simp only [map_add]
calc ∫ x, ∫ y, L x + L y ∂μ.map (ContinuousLinearEquiv.neg ℝ) ∂μ
_ = ∫ x, L x + ∫ y, L y ∂μ.map (ContinuousLinearEquiv.neg ℝ) ∂μ := by
congr with x
rw [integral_add (by fun_prop) (by fun_prop)]
simp [- ContinuousLinearEquiv.coe_neg, integral_const, smul_eq_mul]
_ = ∫ x, L x ∂μ + ∫ y, L y ∂μ.map (ContinuousLinearEquiv.neg ℝ) := by
rw [integral_add (by fun_prop) (by fun_prop)]
simp
_ = 0 := by
rw [integral_map (by fun_prop) (by fun_prop)]
simp [integral_neg]
/-- If `x ↦ exp (C * ‖x‖ ^ 2)` is integrable with respect to the centered Gaussian
`μ ∗ (μ.map (ContinuousLinearEquiv.neg ℝ))`, then for all `C' < C`, `x ↦ exp (C' * ‖x‖ ^ 2)`
is integrable with respect to `μ`. -/
lemma integrable_exp_sq_of_conv_neg (μ : Measure E) [IsGaussian μ] {C C' : ℝ}
(hint : Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2))
(μ ∗ (μ.map (ContinuousLinearEquiv.neg ℝ))))
(hC'_pos : 0 < C') (hC'_lt : C' < C) :
Integrable (fun x ↦ rexp (C' * ‖x‖ ^ 2)) μ := by
have h_int : ∀ᵐ y ∂μ, Integrable (fun x ↦ rexp (C * ‖x - y‖^2)) μ := by
rw [integrable_conv_iff (by fun_prop)] at hint
replace hC := hint.1
simp only [ContinuousLinearEquiv.coe_neg] at hC
filter_upwards [hC] with y hy
rw [integrable_map_measure (by fun_prop) (by fun_prop)] at hy
convert hy with x
simp only [Function.comp_apply, Pi.neg_apply, id_eq, Real.exp_eq_exp, mul_eq_mul_left_iff,
norm_nonneg, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, pow_left_inj₀]
left
simp_rw [← sub_eq_add_neg, norm_sub_rev]
obtain ⟨y, hy⟩ : ∃ y, Integrable (fun x ↦ rexp (C * ‖x - y‖ ^ 2)) μ := h_int.exists
let ε := (C - C') / C'
have hε : 0 < ε := div_pos (by rwa [sub_pos]) (by positivity)
suffices ∀ x, rexp (C' * ‖x‖ ^ 2) ≤ rexp (C/ε * ‖y‖ ^ 2) * rexp (C * ‖x - y‖ ^ 2) by
refine integrable_of_le_of_le (g₁ := 0)
(g₂ := fun x ↦ rexp (C/ε * ‖y‖ ^ 2) * rexp (C * ‖x - y‖ ^ 2)) (by fun_prop) ?_ ?_
(integrable_const _) (hy.const_mul _)
· exact ae_of_all _ fun _ ↦ by positivity
· exact ae_of_all _ this
intro x
rw [← Real.exp_add]
gcongr -- `⊢ C' * ‖x‖ ^ 2 ≤ C / ε * ‖y‖ ^ 2 + C * ‖x - y‖ ^ 2` with `ε = (C - C') / C'`
have h_le : ‖x‖ ^ 2 ≤ (1 + ε) * ‖x - y‖ ^ 2 + (1 + 1 / ε) * ‖y‖ ^ 2 := by
calc ‖x‖ ^ 2
_ = ‖x - y + y‖ ^ 2 := by simp
_ ≤ (‖x - y‖ + ‖y‖) ^ 2 := by grw [norm_add_le (x - y) y]
_ = ‖x - y‖ ^ 2 + ‖y‖ ^ 2 + 2 * ‖x - y‖ * ‖y‖ := by ring
_ ≤ ‖x - y‖ ^ 2 + ‖y‖ ^ 2 + ε * ‖x - y‖ ^ 2 + ε⁻¹ * ‖y‖ ^ 2 := by
simp_rw [add_assoc]
gcongr
exact two_mul_le_add_mul_sq (by positivity)
_ = (1 + ε) * ‖x - y‖ ^ 2 + (1 + 1 / ε) * ‖y‖ ^ 2 := by ring
calc C' * ‖x‖ ^ 2
_ ≤ C' * ((1 + ε) * ‖x - y‖ ^ 2 + (1 + 1 / ε) * ‖y‖ ^ 2) := by gcongr
_ = C / ε * ‖y‖ ^ 2 + C * ‖x - y‖ ^ 2 := by grind
/-- **Fernique's theorem**: for a Gaussian measure, there exists `C > 0` such that the function
`x ↦ exp (C * ‖x‖ ^ 2)` is integrable. -/
theorem exists_integrable_exp_sq [CompleteSpace E] (μ : Measure E) [IsGaussian μ] :
∃ C, 0 < C ∧ Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2)) μ := by
-- Since `μ ∗ μ.map (ContinuousLinearEquiv.neg ℝ)` is a centered Gaussian measure, it is invariant
-- under rotation. We can thus apply a version of Fernique's theorem to it.
obtain ⟨C, hC_pos, hC⟩ : ∃ C, 0 < C
∧ Integrable (fun x ↦ rexp (C * ‖x‖ ^ 2)) (μ ∗ μ.map (ContinuousLinearEquiv.neg ℝ)) :=
exists_integrable_exp_sq_of_map_rotation_eq_self
(map_rotation_eq_self_of_forall_strongDual_eq_zero
(integral_dual_conv_map_neg_eq_zero (μ := μ)) _)
-- We must now prove that the integrability with respect to
-- `μ ∗ μ.map (ContinuousLinearEquiv.neg ℝ)` implies integrability with respect to `μ` for
-- another constant `C' < C`.
refine ⟨C / 2, by positivity, ?_⟩
exact integrable_exp_sq_of_conv_neg μ hC (by positivity) (by simp [hC_pos])
end Fernique
section FiniteMoments
variable [CompleteSpace E] [SecondCountableTopology E]
/-- A Gaussian measure has moments of all orders.
That is, the identity is in L^p for all finite `p`. -/
lemma memLp_id (μ : Measure E) [IsGaussian μ] (p : ℝ≥0∞) (hp : p ≠ ∞) : MemLp id p μ := by
suffices MemLp (fun x ↦ ‖x‖ ^ 2) (p / 2) μ by
rw [← memLp_norm_rpow_iff (q := 2) (by fun_prop) (by simp) (by simp)]
simpa using this
lift p to ℝ≥0 using hp
convert memLp_of_mem_interior_integrableExpSet ?_ (p / 2)
· simp
obtain ⟨C, hC_pos, hC⟩ := exists_integrable_exp_sq μ
have hC_neg : Integrable (fun x ↦ rexp (-C * ‖x‖ ^ 2)) μ := by -- `-C` could be any negative
refine integrable_of_le_of_le (g₁ := 0) (g₂ := 1) (by fun_prop)
(ae_of_all _ fun _ ↦ by positivity) ?_ (integrable_const _) (integrable_const _)
filter_upwards with x
simp only [neg_mul, Pi.one_apply, Real.exp_le_one_iff, Left.neg_nonpos_iff]
positivity
have h_subset : Set.Ioo (-C) C ⊆ interior (integrableExpSet (fun x ↦ ‖x‖ ^ 2) μ) := by
rw [IsOpen.subset_interior_iff isOpen_Ioo]
exact fun x hx ↦ integrable_exp_mul_of_le_of_le hC_neg hC hx.1.le hx.2.le
exact h_subset ⟨by simp [hC_pos], hC_pos⟩
lemma integrable_id : Integrable id μ :=
memLp_one_iff_integrable.1 <| memLp_id μ 1 (by norm_num)
lemma integrable_fun_id : Integrable (fun x ↦ x) μ := integrable_id
lemma memLp_two_id : MemLp id 2 μ := memLp_id μ 2 (by norm_num)
lemma memLp_two_fun_id : MemLp (fun x ↦ x) 2 μ := memLp_two_id
lemma integral_dual (L : StrongDual ℝ E) : μ[L] = L (∫ x, x ∂μ) :=
L.integral_comp_comm ((memLp_id μ 1 (by simp)).integrable le_rfl)
/-- A Gaussian measure with variance zero is a Dirac. -/
lemma eq_dirac_of_variance_eq_zero (h : ∀ L : StrongDual ℝ E, Var[L; μ] = 0) :
μ = Measure.dirac (∫ x, x ∂μ) := by
refine Measure.ext_of_charFunDual ?_
ext L
rw [charFunDual_dirac, charFunDual_eq L, h L, integral_complex_ofReal, integral_dual L]
simp
/-- If a Gaussian measure is not a Dirac, then it has no atoms. -/
lemma noAtoms (h : ∀ x, μ ≠ Measure.dirac x) : NoAtoms μ where
measure_singleton x := by
obtain ⟨L, hL⟩ : ∃ L : StrongDual ℝ E, Var[L; μ] ≠ 0 := by
contrapose! h
exact ⟨_, eq_dirac_of_variance_eq_zero h⟩
have hL_zero : μ.map L {L x} = 0 := by
have : NoAtoms (μ.map L) := by
rw [map_eq_gaussianReal L]
refine noAtoms_gaussianReal ?_
simp only [ne_eq, Real.toNNReal_eq_zero, not_le]
exact lt_of_le_of_ne (variance_nonneg _ _) hL.symm
rw [measure_singleton]
rw [Measure.map_apply (by fun_prop) (measurableSet_singleton _)] at hL_zero
refine measure_mono_null ?_ hL_zero
exact fun ⦃a⦄ ↦ congrArg ⇑L
/-- Characteristic function of a centered Gaussian measure. -/
lemma charFunDual_eq_of_integral_eq_zero (hμ : μ[id] = 0) (L : StrongDual ℝ E) :
charFunDual μ L = exp (- Var[L; μ] / 2) := by
refine charFunDual_eq_of_forall_strongDual_eq_zero (fun L ↦ ?_) L
simp only [id_eq] at hμ
simp [integral_dual, hμ]
/-- For a centered Gaussian measure `μ`, the product measure `μ.prod μ` is invariant under
rotation. -/
lemma map_rotation_eq_self (hμ : μ[id] = 0) (θ : ℝ) :
(μ.prod μ).map (ContinuousLinearMap.rotation θ) = μ.prod μ := by
refine map_rotation_eq_self_of_forall_strongDual_eq_zero (fun L ↦ ?_) θ
simp only [id_eq] at hμ
simp [integral_dual, hμ]
end FiniteMoments
end ProbabilityTheory.IsGaussian |
.lake/packages/mathlib/Mathlib/Probability/Distributions/Gaussian/Real.lean | import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform
import Mathlib.MeasureTheory.Group.Convolution
import Mathlib.Probability.Moments.MGFAnalytic
import Mathlib.Probability.Independence.Basic
/-!
# Gaussian distributions over ℝ
We define a Gaussian measure over the reals.
## Main definitions
* `gaussianPDFReal`: the function `μ v x ↦ (1 / (sqrt (2 * pi * v))) * exp (- (x - μ)^2 / (2 * v))`,
which is the probability density function of a Gaussian distribution with mean `μ` and
variance `v` (when `v ≠ 0`).
* `gaussianPDF`: `ℝ≥0∞`-valued pdf, `gaussianPDF μ v x = ENNReal.ofReal (gaussianPDFReal μ v x)`.
* `gaussianReal`: a Gaussian measure on `ℝ`, parametrized by its mean `μ` and variance `v`.
If `v = 0`, this is `dirac μ`, otherwise it is defined as the measure with density
`gaussianPDF μ v` with respect to the Lebesgue measure.
## Main results
* `gaussianReal_add_const`: if `X` is a random variable with Gaussian distribution with mean `μ` and
variance `v`, then `X + y` is Gaussian with mean `μ + y` and variance `v`.
* `gaussianReal_const_mul`: if `X` is a random variable with Gaussian distribution with mean `μ` and
variance `v`, then `c * X` is Gaussian with mean `c * μ` and variance `c^2 * v`.
-/
open scoped ENNReal NNReal Real Complex
open MeasureTheory
namespace ProbabilityTheory
section GaussianPDF
/-- Probability density function of the Gaussian distribution with mean `μ` and variance `v`. -/
noncomputable
def gaussianPDFReal (μ : ℝ) (v : ℝ≥0) (x : ℝ) : ℝ :=
(√(2 * π * v))⁻¹ * rexp (-(x - μ) ^ 2 / (2 * v))
lemma gaussianPDFReal_def (μ : ℝ) (v : ℝ≥0) :
gaussianPDFReal μ v =
fun x ↦ (√(2 * π * v))⁻¹ * rexp (-(x - μ) ^ 2 / (2 * v)) := rfl
@[simp]
lemma gaussianPDFReal_zero_var (m : ℝ) : gaussianPDFReal m 0 = 0 := by
ext1 x
simp [gaussianPDFReal]
/-- The Gaussian pdf is positive when the variance is not zero. -/
lemma gaussianPDFReal_pos (μ : ℝ) (v : ℝ≥0) (x : ℝ) (hv : v ≠ 0) : 0 < gaussianPDFReal μ v x := by
rw [gaussianPDFReal]
positivity
/-- The Gaussian pdf is nonnegative. -/
lemma gaussianPDFReal_nonneg (μ : ℝ) (v : ℝ≥0) (x : ℝ) : 0 ≤ gaussianPDFReal μ v x := by
rw [gaussianPDFReal]
positivity
/-- The Gaussian pdf is measurable. -/
@[fun_prop]
lemma measurable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDFReal μ v) :=
(((measurable_id.add_const _).pow_const _).neg.div_const _).exp.const_mul _
/-- The Gaussian pdf is strongly measurable. -/
@[fun_prop]
lemma stronglyMeasurable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) :
StronglyMeasurable (gaussianPDFReal μ v) :=
(measurable_gaussianPDFReal μ v).stronglyMeasurable
@[fun_prop]
lemma integrable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) :
Integrable (gaussianPDFReal μ v) := by
rw [gaussianPDFReal_def]
by_cases hv : v = 0
· simp [hv]
let g : ℝ → ℝ := fun x ↦ (√(2 * π * v))⁻¹ * rexp (-x ^ 2 / (2 * v))
have hg : Integrable g := by
suffices g = fun x ↦ (√(2 * π * v))⁻¹ * rexp (-(2 * v)⁻¹ * x ^ 2) by
rw [this]
refine (integrable_exp_neg_mul_sq ?_).const_mul (√(2 * π * v))⁻¹
simp [lt_of_le_of_ne (zero_le _) (Ne.symm hv)]
ext x
simp only [g, NNReal.zero_le_coe, Real.sqrt_mul',
mul_inv_rev, NNReal.coe_mul, NNReal.coe_inv, NNReal.coe_ofNat, neg_mul, mul_eq_mul_left_iff,
Real.exp_eq_exp, mul_eq_zero, inv_eq_zero, Real.sqrt_eq_zero, NNReal.coe_eq_zero, hv,
false_or]
rw [mul_comm]
left
field
exact Integrable.comp_sub_right hg μ
/-- The Gaussian distribution pdf integrates to 1 when the variance is not zero. -/
lemma lintegral_gaussianPDFReal_eq_one (μ : ℝ) {v : ℝ≥0} (h : v ≠ 0) :
∫⁻ x, ENNReal.ofReal (gaussianPDFReal μ v x) = 1 := by
rw [← ENNReal.toReal_eq_one_iff]
have hfm : AEStronglyMeasurable (gaussianPDFReal μ v) volume := by fun_prop
have hf : 0 ≤ₐₛ gaussianPDFReal μ v := ae_of_all _ (gaussianPDFReal_nonneg μ v)
rw [← integral_eq_lintegral_of_nonneg_ae hf hfm]
simp only [gaussianPDFReal,
integral_const_mul]
rw [integral_sub_right_eq_self (μ := volume) (fun a ↦ rexp (-a ^ 2 / ((2 : ℝ) * v))) μ]
simp only [div_eq_inv_mul, mul_inv_rev,
mul_neg]
simp_rw [← neg_mul]
rw [neg_mul, integral_gaussian, ← Real.sqrt_inv, ← Real.sqrt_mul]
· simp [field]
· positivity
/-- The Gaussian distribution pdf integrates to 1 when the variance is not zero. -/
lemma integral_gaussianPDFReal_eq_one (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) :
∫ x, gaussianPDFReal μ v x = 1 := by
have h := lintegral_gaussianPDFReal_eq_one μ hv
rw [← ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal _ _)
(ae_of_all _ (gaussianPDFReal_nonneg _ _)), ← ENNReal.ofReal_one] at h
rwa [← ENNReal.ofReal_eq_ofReal_iff (integral_nonneg (gaussianPDFReal_nonneg _ _)) zero_le_one]
lemma gaussianPDFReal_sub {μ : ℝ} {v : ℝ≥0} (x y : ℝ) :
gaussianPDFReal μ v (x - y) = gaussianPDFReal (μ + y) v x := by
simp only [gaussianPDFReal]
rw [sub_add_eq_sub_sub_swap]
lemma gaussianPDFReal_add {μ : ℝ} {v : ℝ≥0} (x y : ℝ) :
gaussianPDFReal μ v (x + y) = gaussianPDFReal (μ - y) v x := by
rw [sub_eq_add_neg, ← gaussianPDFReal_sub, sub_eq_add_neg, neg_neg]
lemma gaussianPDFReal_inv_mul {μ : ℝ} {v : ℝ≥0} {c : ℝ} (hc : c ≠ 0) (x : ℝ) :
gaussianPDFReal μ v (c⁻¹ * x) = |c| * gaussianPDFReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) x := by
simp only [gaussianPDFReal.eq_1, NNReal.zero_le_coe,
Real.sqrt_mul', mul_inv_rev, NNReal.coe_mul, NNReal.coe_mk]
rw [← mul_assoc]
refine congr_arg₂ _ ?_ ?_
· simp (disch := positivity) only [Real.sqrt_mul, mul_inv_rev, field]
rw [Real.sqrt_sq_eq_abs]
· congr 1
field
lemma gaussianPDFReal_mul {μ : ℝ} {v : ℝ≥0} {c : ℝ} (hc : c ≠ 0) (x : ℝ) :
gaussianPDFReal μ v (c * x)
= |c⁻¹| * gaussianPDFReal (c⁻¹ * μ) (⟨(c^2)⁻¹, inv_nonneg.mpr (sq_nonneg _)⟩ * v) x := by
conv_lhs => rw [← inv_inv c, gaussianPDFReal_inv_mul (inv_ne_zero hc)]
simp
/-- The pdf of a Gaussian distribution on ℝ with mean `μ` and variance `v`. -/
noncomputable
def gaussianPDF (μ : ℝ) (v : ℝ≥0) (x : ℝ) : ℝ≥0∞ := ENNReal.ofReal (gaussianPDFReal μ v x)
lemma gaussianPDF_def (μ : ℝ) (v : ℝ≥0) :
gaussianPDF μ v = fun x ↦ ENNReal.ofReal (gaussianPDFReal μ v x) := rfl
@[simp]
lemma gaussianPDF_zero_var (μ : ℝ) : gaussianPDF μ 0 = 0 := by ext; simp [gaussianPDF]
@[simp]
lemma toReal_gaussianPDF {μ : ℝ} {v : ℝ≥0} (x : ℝ) :
(gaussianPDF μ v x).toReal = gaussianPDFReal μ v x := by
rw [gaussianPDF, ENNReal.toReal_ofReal (gaussianPDFReal_nonneg μ v x)]
lemma gaussianPDF_pos (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (x : ℝ) : 0 < gaussianPDF μ v x := by
rw [gaussianPDF, ENNReal.ofReal_pos]
exact gaussianPDFReal_pos _ _ _ hv
lemma gaussianPDF_lt_top {μ : ℝ} {v : ℝ≥0} {x : ℝ} : gaussianPDF μ v x < ∞ := by simp [gaussianPDF]
lemma gaussianPDF_ne_top {μ : ℝ} {v : ℝ≥0} {x : ℝ} : gaussianPDF μ v x ≠ ∞ := by simp [gaussianPDF]
@[simp]
lemma support_gaussianPDF {μ : ℝ} {v : ℝ≥0} (hv : v ≠ 0) :
Function.support (gaussianPDF μ v) = Set.univ := by
ext x
simp only [Set.mem_univ, iff_true]
exact (gaussianPDF_pos _ hv x).ne'
@[measurability, fun_prop]
lemma measurable_gaussianPDF (μ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDF μ v) :=
(measurable_gaussianPDFReal _ _).ennreal_ofReal
@[simp]
lemma lintegral_gaussianPDF_eq_one (μ : ℝ) {v : ℝ≥0} (h : v ≠ 0) :
∫⁻ x, gaussianPDF μ v x = 1 :=
lintegral_gaussianPDFReal_eq_one μ h
end GaussianPDF
section GaussianReal
/-- A Gaussian distribution on `ℝ` with mean `μ` and variance `v`. -/
noncomputable
def gaussianReal (μ : ℝ) (v : ℝ≥0) : Measure ℝ :=
if v = 0 then Measure.dirac μ else volume.withDensity (gaussianPDF μ v)
lemma gaussianReal_of_var_ne_zero (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) :
gaussianReal μ v = volume.withDensity (gaussianPDF μ v) := if_neg hv
@[simp]
lemma gaussianReal_zero_var (μ : ℝ) : gaussianReal μ 0 = Measure.dirac μ := if_pos rfl
instance instIsProbabilityMeasureGaussianReal (μ : ℝ) (v : ℝ≥0) :
IsProbabilityMeasure (gaussianReal μ v) where
measure_univ := by by_cases h : v = 0 <;> simp [gaussianReal_of_var_ne_zero, h]
lemma noAtoms_gaussianReal {μ : ℝ} {v : ℝ≥0} (h : v ≠ 0) : NoAtoms (gaussianReal μ v) := by
rw [gaussianReal_of_var_ne_zero _ h]
infer_instance
lemma gaussianReal_apply (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (s : Set ℝ) :
gaussianReal μ v s = ∫⁻ x in s, gaussianPDF μ v x := by
rw [gaussianReal_of_var_ne_zero _ hv, withDensity_apply' _ s]
lemma gaussianReal_apply_eq_integral (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (s : Set ℝ) :
gaussianReal μ v s = ENNReal.ofReal (∫ x in s, gaussianPDFReal μ v x) := by
rw [gaussianReal_apply _ hv s, ofReal_integral_eq_lintegral_ofReal]
· rfl
· exact (integrable_gaussianPDFReal _ _).restrict
· exact ae_of_all _ (gaussianPDFReal_nonneg _ _)
lemma gaussianReal_absolutelyContinuous (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) :
gaussianReal μ v ≪ volume := by
rw [gaussianReal_of_var_ne_zero _ hv]
exact withDensity_absolutelyContinuous _ _
lemma gaussianReal_absolutelyContinuous' (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) :
volume ≪ gaussianReal μ v := by
rw [gaussianReal_of_var_ne_zero _ hv]
refine withDensity_absolutelyContinuous' ?_ ?_
· exact (measurable_gaussianPDF _ _).aemeasurable
· exact ae_of_all _ (fun _ ↦ (gaussianPDF_pos _ hv _).ne')
lemma rnDeriv_gaussianReal (μ : ℝ) (v : ℝ≥0) :
∂(gaussianReal μ v)/∂volume =ₐₛ gaussianPDF μ v := by
by_cases hv : v = 0
· simp only [hv, gaussianReal_zero_var, gaussianPDF_zero_var]
refine (Measure.eq_rnDeriv measurable_zero (mutuallySingular_dirac μ volume) ?_).symm
rw [withDensity_zero, add_zero]
· rw [gaussianReal_of_var_ne_zero _ hv]
exact Measure.rnDeriv_withDensity _ (measurable_gaussianPDF μ v)
lemma integral_gaussianReal_eq_integral_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{μ : ℝ} {v : ℝ≥0} {f : ℝ → E} (hv : v ≠ 0) :
∫ x, f x ∂(gaussianReal μ v) = ∫ x, gaussianPDFReal μ v x • f x := by
simp [gaussianReal, hv,
integral_withDensity_eq_integral_toReal_smul (measurable_gaussianPDF _ _)
(ae_of_all _ fun _ ↦ gaussianPDF_lt_top)]
section Transformations
variable {μ : ℝ} {v : ℝ≥0}
lemma _root_.MeasurableEmbedding.gaussianReal_comap_apply (hv : v ≠ 0)
{f : ℝ → ℝ} (hf : MeasurableEmbedding f)
{f' : ℝ → ℝ} (h_deriv : ∀ x, HasDerivAt f (f' x) x) {s : Set ℝ} (hs : MeasurableSet s) :
(gaussianReal μ v).comap f s
= ENNReal.ofReal (∫ x in s, |f' x| * gaussianPDFReal μ v (f x)) := by
rw [gaussianReal_of_var_ne_zero _ hv, gaussianPDF_def]
exact hf.withDensity_ofReal_comap_apply_eq_integral_abs_deriv_mul' hs h_deriv
(ae_of_all _ (gaussianPDFReal_nonneg _ _)) (integrable_gaussianPDFReal _ _)
lemma _root_.MeasurableEquiv.gaussianReal_map_symm_apply (hv : v ≠ 0) (f : ℝ ≃ᵐ ℝ) {f' : ℝ → ℝ}
(h_deriv : ∀ x, HasDerivAt f (f' x) x) {s : Set ℝ} (hs : MeasurableSet s) :
(gaussianReal μ v).map f.symm s
= ENNReal.ofReal (∫ x in s, |f' x| * gaussianPDFReal μ v (f x)) := by
rw [gaussianReal_of_var_ne_zero _ hv, gaussianPDF_def]
exact f.withDensity_ofReal_map_symm_apply_eq_integral_abs_deriv_mul' hs h_deriv
(ae_of_all _ (gaussianPDFReal_nonneg _ _)) (integrable_gaussianPDFReal _ _)
/-- The map of a Gaussian distribution by addition of a constant is a Gaussian. -/
lemma gaussianReal_map_add_const (y : ℝ) :
(gaussianReal μ v).map (· + y) = gaussianReal (μ + y) v := by
by_cases hv : v = 0
· simp only [hv, gaussianReal_zero_var]
exact Measure.map_dirac (measurable_id'.add_const _) _
let e : ℝ ≃ᵐ ℝ := (Homeomorph.addRight y).symm.toMeasurableEquiv
have he' : ∀ x, HasDerivAt e ((fun _ ↦ 1) x) x := fun _ ↦ (hasDerivAt_id _).sub_const y
change (gaussianReal μ v).map e.symm = gaussianReal (μ + y) v
ext s' hs'
rw [MeasurableEquiv.gaussianReal_map_symm_apply hv e he' hs']
simp only [abs_one, one_mul]
rw [gaussianReal_apply_eq_integral _ hv s']
simp [e, gaussianPDFReal_sub _ y, Homeomorph.addRight, ← sub_eq_add_neg]
/-- The map of a Gaussian distribution by addition of a constant is a Gaussian. -/
lemma gaussianReal_map_const_add (y : ℝ) :
(gaussianReal μ v).map (y + ·) = gaussianReal (μ + y) v := by
simp_rw [add_comm y]
exact gaussianReal_map_add_const y
/-- The map of a Gaussian distribution by multiplication by a constant is a Gaussian. -/
lemma gaussianReal_map_const_mul (c : ℝ) :
(gaussianReal μ v).map (c * ·) = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by
by_cases hv : v = 0
· simp only [hv, mul_zero, gaussianReal_zero_var]
exact Measure.map_dirac (measurable_id'.const_mul c) μ
by_cases hc : c = 0
· simp only [hc, zero_mul]
rw [Measure.map_const]
simp only [measure_univ, one_smul]
convert (gaussianReal_zero_var 0).symm
simp only [ne_eq, zero_pow, mul_eq_zero, hv, or_false, not_false_eq_true, reduceCtorEq,
NNReal.mk_zero]
let e : ℝ ≃ᵐ ℝ := (Homeomorph.mulLeft₀ c hc).symm.toMeasurableEquiv
have he' : ∀ x, HasDerivAt e ((fun _ ↦ c⁻¹) x) x := by
suffices ∀ x, HasDerivAt (fun x => c⁻¹ * x) (c⁻¹ * 1) x by rwa [mul_one] at this
exact fun _ ↦ HasDerivAt.const_mul _ (hasDerivAt_id _)
change (gaussianReal μ v).map e.symm = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v)
ext s' hs'
rw [MeasurableEquiv.gaussianReal_map_symm_apply hv e he' hs',
gaussianReal_apply_eq_integral _ _ s']
swap
· simp only [ne_eq, mul_eq_zero, hv, or_false]
rw [← NNReal.coe_inj]
simp [hc]
simp only [e, Homeomorph.mulLeft₀,
Equiv.mulLeft₀_symm_apply, Homeomorph.toMeasurableEquiv_coe, Homeomorph.homeomorph_mk_coe_symm,
gaussianPDFReal_inv_mul hc]
congr with x
suffices |c⁻¹| * |c| = 1 by rw [← mul_assoc, this, one_mul]
rw [abs_inv, inv_mul_cancel₀]
rwa [ne_eq, abs_eq_zero]
/-- The map of a Gaussian distribution by multiplication by a constant is a Gaussian. -/
lemma gaussianReal_map_mul_const (c : ℝ) :
(gaussianReal μ v).map (· * c) = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by
simp_rw [mul_comm _ c]
exact gaussianReal_map_const_mul c
lemma gaussianReal_map_neg : (gaussianReal μ v).map (fun x ↦ -x) = gaussianReal (-μ) v := by
simpa using gaussianReal_map_const_mul (μ := μ) (v := v) (-1)
lemma gaussianReal_map_sub_const (y : ℝ) :
(gaussianReal μ v).map (· - y) = gaussianReal (μ - y) v := by
simp_rw [sub_eq_add_neg, gaussianReal_map_add_const]
lemma gaussianReal_map_const_sub (y : ℝ) :
(gaussianReal μ v).map (y - ·) = gaussianReal (y - μ) v := by
simp_rw [sub_eq_add_neg]
have : (fun x ↦ y + -x) = (fun x ↦ y + x) ∘ fun x ↦ -x := by ext; simp
rw [this, ← Measure.map_map (by fun_prop) (by fun_prop), gaussianReal_map_neg,
gaussianReal_map_const_add, add_comm]
variable {Ω : Type} [MeasureSpace Ω]
/-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `X + y`
has Gaussian law with mean `μ + y` and variance `v`. -/
lemma gaussianReal_add_const {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (y : ℝ) :
Measure.map (fun ω ↦ X ω + y) ℙ = gaussianReal (μ + y) v := by
have hXm : AEMeasurable X := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
change Measure.map ((fun ω ↦ ω + y) ∘ X) ℙ = gaussianReal (μ + y) v
rw [← AEMeasurable.map_map_of_aemeasurable (measurable_id'.add_const _).aemeasurable hXm, hX,
gaussianReal_map_add_const y]
/-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `y + X`
has Gaussian law with mean `μ + y` and variance `v`. -/
lemma gaussianReal_const_add {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (y : ℝ) :
Measure.map (fun ω ↦ y + X ω) ℙ = gaussianReal (μ + y) v := by
simp_rw [add_comm y]
exact gaussianReal_add_const hX y
/-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `c * X`
has Gaussian law with mean `c * μ` and variance `c^2 * v`. -/
lemma gaussianReal_const_mul {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (c : ℝ) :
Measure.map (fun ω ↦ c * X ω) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by
have hXm : AEMeasurable X := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
change Measure.map ((fun ω ↦ c * ω) ∘ X) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v)
rw [← AEMeasurable.map_map_of_aemeasurable (measurable_id'.const_mul c).aemeasurable hXm, hX]
exact gaussianReal_map_const_mul c
/-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `X * c`
has Gaussian law with mean `c * μ` and variance `c^2 * v`. -/
lemma gaussianReal_mul_const {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (c : ℝ) :
Measure.map (fun ω ↦ X ω * c) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by
simp_rw [mul_comm _ c]
exact gaussianReal_const_mul hX c
end Transformations
section CharacteristicFunction
open Real Complex
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {p : Measure Ω} {μ : ℝ} {v : ℝ≥0} {X : Ω → ℝ}
-- see https://github.com/leanprover-community/mathlib4/issues/29041
set_option linter.unusedSimpArgs false in
/-- The complex moment-generating function of a Gaussian distribution with mean `μ` and variance `v`
is given by `z ↦ exp (z * μ + v * z ^ 2 / 2)`. -/
theorem complexMGF_id_gaussianReal (z : ℂ) :
complexMGF id (gaussianReal μ v) z = cexp (z * μ + v * z ^ 2 / 2) := by
by_cases hv : v = 0
· simp [complexMGF, hv]
calc ∫ x, cexp (z * x) ∂gaussianReal μ v
_ = ∫ x, gaussianPDFReal μ v x * cexp (z * x) ∂ℙ := by
simp_rw [integral_gaussianReal_eq_integral_smul hv, Complex.real_smul]
_ = (√(2 * π * v))⁻¹
* ∫ x : ℝ, cexp (-(2 * v)⁻¹ * x ^ 2 + (z + μ / v) * x + -μ ^ 2 / (2 * v)) ∂ℙ := by
unfold gaussianPDFReal
push_cast
simp_rw [mul_assoc, integral_const_mul, ← Complex.exp_add]
congr with x
congr 1
ring
_ = (√(2 * π * v))⁻¹ * (π / - -(2 * v)⁻¹) ^ (1 / 2 : ℂ)
* cexp (-μ ^ 2 / (2 * v) - (z + μ / v) ^ 2 / (4 * -(2 * v)⁻¹)) := by
rw [integral_cexp_quadratic (by simpa using pos_iff_ne_zero.mpr hv), ← mul_assoc]
_ = 1 * cexp (-μ ^ 2 / (2 * v) - (z + μ / v) ^ 2 / (4 * -(2 * v)⁻¹)) := by
congr 1
simp only [field, sqrt_eq_rpow, one_div, ofReal_inv, NNReal.coe_inv, NNReal.coe_mul,
NNReal.coe_ofNat, ofReal_mul, ofReal_ofNat, neg_neg, div_inv_eq_mul,
ne_eq, ofReal_eq_zero, rpow_eq_zero, not_false_eq_true]
rw [Complex.ofReal_cpow (by positivity)]
push_cast
ring_nf
_ = cexp (z * μ + v * z ^ 2 / 2) := by
rw [one_mul]
congr 1
have : (v : ℂ) ≠ 0 := by simpa
simp [field]
ring
/-- The complex moment-generating function of a random variable with Gaussian distribution
with mean `μ` and variance `v` is given by `z ↦ exp (z * μ + v * z ^ 2 / 2)`. -/
theorem complexMGF_gaussianReal (hX : p.map X = gaussianReal μ v) (z : ℂ) :
complexMGF X p z = cexp (z * μ + v * z ^ 2 / 2) := by
have hX_meas : AEMeasurable X p := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
rw [← complexMGF_id_map hX_meas, hX, complexMGF_id_gaussianReal]
/-- The characteristic function of a Gaussian distribution with mean `μ` and variance `v`
is given by `t ↦ exp (t * μ - v * t ^ 2 / 2)`. -/
theorem charFun_gaussianReal (t : ℝ) :
charFun (gaussianReal μ v) t = cexp (t * μ * I - v * t ^ 2 / 2) := by
rw [← complexMGF_id_mul_I, complexMGF_id_gaussianReal]
congr
simp only [mul_pow, I_sq, mul_neg, mul_one, sub_eq_add_neg]
ring_nf
/-- The moment-generating function of a random variable with Gaussian distribution
with mean `μ` and variance `v` is given by `t ↦ exp (μ * t + v * t ^ 2 / 2)`. -/
theorem mgf_gaussianReal (hX : p.map X = gaussianReal μ v) (t : ℝ) :
mgf X p t = rexp (μ * t + v * t ^ 2 / 2) := by
suffices (mgf X p t : ℂ) = rexp (μ * t + ↑v * t ^ 2 / 2) from mod_cast this
have hX_meas : AEMeasurable X p := aemeasurable_of_map_neZero (by rw [hX]; infer_instance)
rw [← mgf_id_map hX_meas, ← complexMGF_ofReal, hX, complexMGF_id_gaussianReal, mul_comm μ]
norm_cast
theorem mgf_fun_id_gaussianReal :
mgf (fun x ↦ x) (gaussianReal μ v) = fun t ↦ rexp (μ * t + v * t ^ 2 / 2) := by
ext t
rw [mgf_gaussianReal]
simp
theorem mgf_id_gaussianReal : mgf id (gaussianReal μ v) = fun t ↦ rexp (μ * t + v * t ^ 2 / 2) :=
mgf_fun_id_gaussianReal
/-- The cumulant-generating function of a random variable with Gaussian distribution
with mean `μ` and variance `v` is given by `t ↦ μ * t + v * t ^ 2 / 2`. -/
theorem cgf_gaussianReal (hX : p.map X = gaussianReal μ v) (t : ℝ) :
cgf X p t = μ * t + v * t ^ 2 / 2 := by
rw [cgf, mgf_gaussianReal hX t, Real.log_exp]
lemma integrable_exp_mul_gaussianReal (t : ℝ) :
Integrable (fun x ↦ rexp (t * x)) (gaussianReal μ v) := by
rw [← mgf_pos_iff, mgf_gaussianReal (μ := μ) (v := v) (by simp)]
exact Real.exp_pos _
@[simp]
lemma integrableExpSet_id_gaussianReal : integrableExpSet id (gaussianReal μ v) = Set.univ := by
ext
simpa [integrableExpSet] using integrable_exp_mul_gaussianReal _
@[simp]
lemma integrableExpSet_fun_id_gaussianReal :
integrableExpSet (fun x ↦ x) (gaussianReal μ v) = Set.univ :=
integrableExpSet_id_gaussianReal
end CharacteristicFunction
section Moments
variable {μ : ℝ} {v : ℝ≥0}
/-- The mean of a real Gaussian distribution `gaussianReal μ v` is its mean parameter `μ`. -/
@[simp]
lemma integral_id_gaussianReal : ∫ x, x ∂gaussianReal μ v = μ := by
rw [← deriv_mgf_zero (by simp), mgf_fun_id_gaussianReal, _root_.deriv_exp (by fun_prop)]
simp only [mul_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, zero_div,
add_zero, Real.exp_zero, one_mul]
rw [deriv_fun_add (by fun_prop) (by fun_prop), deriv_fun_mul (by fun_prop) (by fun_prop)]
simp
/-- The variance of a real Gaussian distribution `gaussianReal μ v` is
its variance parameter `v`. -/
@[simp]
lemma variance_fun_id_gaussianReal : Var[fun x ↦ x; gaussianReal μ v] = v := by
rw [variance_eq_integral measurable_id'.aemeasurable]
simp only [integral_id_gaussianReal]
calc ∫ ω, (ω - μ) ^ 2 ∂gaussianReal μ v
_ = ∫ ω, ω ^ 2 ∂(gaussianReal μ v).map (fun x ↦ x - μ) := by
rw [integral_map (by fun_prop) (by fun_prop)]
_ = ∫ ω, ω ^ 2 ∂(gaussianReal 0 v) := by simp [gaussianReal_map_sub_const]
_ = iteratedDeriv 2 (mgf (fun x ↦ x) (gaussianReal 0 v)) 0 := by
rw [iteratedDeriv_mgf_zero] <;> simp
_ = v := by
rw [mgf_fun_id_gaussianReal, iteratedDeriv_succ, iteratedDeriv_one]
simp only [zero_mul, zero_add]
have : deriv (fun t ↦ rexp (v * t ^ 2 / 2)) = fun t ↦ v * t * rexp (v * t ^ 2 / 2) := by
ext t
rw [_root_.deriv_exp (by fun_prop)]
simp only [deriv_div_const, differentiableAt_const, differentiableAt_fun_id, Nat.cast_ofNat,
DifferentiableAt.fun_pow, deriv_fun_mul, deriv_const', zero_mul, deriv_fun_pow,
Nat.add_one_sub_one, pow_one, deriv_id'', mul_one, zero_add]
ring
rw [this, deriv_fun_mul (by fun_prop) (by fun_prop), deriv_fun_mul (by fun_prop) (by fun_prop)]
simp
/-- The variance of a real Gaussian distribution `gaussianReal μ v` is
its variance parameter `v`. -/
@[simp]
lemma variance_id_gaussianReal : Var[id; gaussianReal μ v] = v :=
variance_fun_id_gaussianReal
/-- All the moments of a real Gaussian distribution are finite. That is, the identity is in Lp for
all finite `p`. -/
lemma memLp_id_gaussianReal (p : ℝ≥0) : MemLp id p (gaussianReal μ v) :=
memLp_of_mem_interior_integrableExpSet (by simp) p
/-- All the moments of a real Gaussian distribution are finite. That is, the identity is in Lp for
all finite `p`. -/
lemma memLp_id_gaussianReal' (p : ℝ≥0∞) (hp : p ≠ ∞) : MemLp id p (gaussianReal μ v) := by
lift p to ℝ≥0 using hp
exact memLp_id_gaussianReal p
end Moments
/-- Two real Gaussian distributions are equal iff they have the same mean and variance. -/
lemma gaussianReal_ext_iff {μ₁ μ₂ : ℝ} {v₁ v₂ : ℝ≥0} :
gaussianReal μ₁ v₁ = gaussianReal μ₂ v₂ ↔ μ₁ = μ₂ ∧ v₁ = v₂ := by
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
rw [← integral_id_gaussianReal (μ := μ₁) (v := v₁),
← integral_id_gaussianReal (μ := μ₂) (v := v₂), h]
simp only [integral_id_gaussianReal, true_and]
suffices (v₁ : ℝ) = v₂ by simpa
rw [← variance_id_gaussianReal (μ := μ₁) (v := v₁),
← variance_id_gaussianReal (μ := μ₂) (v := v₂), h]
section LinearMap
variable {μ : ℝ} {v : ℝ≥0}
lemma gaussianReal_map_linearMap (L : ℝ →ₗ[ℝ] ℝ) :
(gaussianReal μ v).map L = gaussianReal (L μ) ((L 1 ^ 2).toNNReal * v) := by
have : (L : ℝ → ℝ) = fun x ↦ L 1 * x := by
ext x
have : x = x • 1 := by simp
conv_lhs => rw [this, L.map_smul, smul_eq_mul, mul_comm]
rw [this, gaussianReal_map_const_mul]
congr
simp only [mul_one, left_eq_sup]
positivity
lemma gaussianReal_map_continuousLinearMap (L : ℝ →L[ℝ] ℝ) :
(gaussianReal μ v).map L = gaussianReal (L μ) ((L 1 ^ 2).toNNReal * v) :=
gaussianReal_map_linearMap L
@[simp]
lemma integral_linearMap_gaussianReal (L : ℝ →ₗ[ℝ] ℝ) :
∫ x, L x ∂(gaussianReal μ v) = L μ := by
have : ∫ x, L x ∂(gaussianReal μ v) = ∫ x, x ∂((gaussianReal μ v).map L) := by
rw [integral_map (φ := L) (by fun_prop) (by fun_prop)]
simp [this, gaussianReal_map_linearMap]
@[simp]
lemma integral_continuousLinearMap_gaussianReal (L : ℝ →L[ℝ] ℝ) :
∫ x, L x ∂(gaussianReal μ v) = L μ := integral_linearMap_gaussianReal L
@[simp]
lemma variance_linearMap_gaussianReal (L : ℝ →ₗ[ℝ] ℝ) :
Var[L; gaussianReal μ v] = (L 1 ^ 2).toNNReal * v := by
rw [← variance_id_map, gaussianReal_map_linearMap, variance_id_gaussianReal]
· simp only [NNReal.coe_mul, Real.coe_toNNReal']
· fun_prop
@[simp]
lemma variance_continuousLinearMap_gaussianReal (L : ℝ →L[ℝ] ℝ) :
Var[L; gaussianReal μ v] = (L 1 ^ 2).toNNReal * v :=
variance_linearMap_gaussianReal L
end LinearMap
/-- The convolution of two real Gaussian distributions with means `m₁, m₂` and variances `v₁, v₂`
is a real Gaussian distribution with mean `m₁ + m₂` and variance `v₁ + v₂`. -/
lemma gaussianReal_conv_gaussianReal {m₁ m₂ : ℝ} {v₁ v₂ : ℝ≥0} :
(gaussianReal m₁ v₁) ∗ (gaussianReal m₂ v₂) = gaussianReal (m₁ + m₂) (v₁ + v₂) := by
refine Measure.ext_of_charFun ?_
ext t
simp_rw [charFun_conv, charFun_gaussianReal]
rw [← Complex.exp_add]
simp only [Complex.ofReal_add, NNReal.coe_add]
ring_nf
/- The sum of two real Gaussian variables with means `m₁, m₂` and variances `v₁, v₂` is a real
Gaussian distribution with mean `m₁ + m₂` and variance `v_1 + v_2`. -/
lemma gaussianReal_add_gaussianReal_of_indepFun {Ω} {mΩ : MeasurableSpace Ω} {P : Measure Ω}
{m₁ m₂ : ℝ} {v₁ v₂ : ℝ≥0} {X Y : Ω → ℝ} (hXY : IndepFun X Y P)
(hX : P.map X = gaussianReal m₁ v₁) (hY : P.map Y = gaussianReal m₂ v₂) :
P.map (X + Y) = gaussianReal (m₁ + m₂) (v₁ + v₂) := by
rw [hXY.map_add_eq_map_conv_map₀', hX, hY, gaussianReal_conv_gaussianReal]
· apply AEMeasurable.of_map_ne_zero; simp [NeZero.ne, hX]
· apply AEMeasurable.of_map_ne_zero; simp [NeZero.ne, hY]
· rw [hX]; apply IsFiniteMeasure.toSigmaFinite
· rw [hY]; apply IsFiniteMeasure.toSigmaFinite
end GaussianReal
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/MeasurableIntegral.lean | import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.Probability.Kernel.MeasurableLIntegral
/-!
# Measurability of the integral against a kernel
The Bochner integral of a strongly measurable function against a kernel is strongly measurable.
## Main statements
* `MeasureTheory.StronglyMeasurable.integral_kernel_prod_right`: the function
`a ↦ ∫ b, f a b ∂(κ a)` is measurable, for an s-finite kernel `κ : Kernel α β` and a function
`f : α → β → E` such that `uncurry f` is measurable.
-/
open MeasureTheory ProbabilityTheory Function Set Filter
open scoped MeasureTheory ENNReal Topology
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{κ : Kernel α β} {η : Kernel β γ} {a : α} {E : Type*} [NormedAddCommGroup E]
theorem ProbabilityTheory.measurableSet_integrable ⦃f : β → E⦄ (hf : StronglyMeasurable f) :
MeasurableSet {a | Integrable f (κ a)} := by
simp_rw [Integrable, hf.aestronglyMeasurable, true_and]
exact measurableSet_lt hf.enorm.lintegral_kernel measurable_const
variable [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η]
theorem ProbabilityTheory.measurableSet_kernel_integrable ⦃f : α → β → E⦄
(hf : StronglyMeasurable (uncurry f)) :
MeasurableSet {x | Integrable (f x) (κ x)} := by
simp_rw [Integrable, hf.of_uncurry_left.aestronglyMeasurable, true_and]
exact measurableSet_lt (Measurable.lintegral_kernel_prod_right hf.enorm) measurable_const
open ProbabilityTheory.Kernel
namespace MeasureTheory
variable [NormedSpace ℝ E]
omit [IsSFiniteKernel κ] in
theorem StronglyMeasurable.integral_kernel ⦃f : β → E⦄
(hf : StronglyMeasurable f) : StronglyMeasurable fun x ↦ ∫ y, f y ∂κ x := by
classical
by_cases hE : CompleteSpace E; swap
· simp [integral, hE, stronglyMeasurable_const]
borelize E
have : TopologicalSpace.SeparableSpace (range f ∪ {0} : Set E) :=
hf.separableSpace_range_union_singleton
let s : ℕ → SimpleFunc β E := SimpleFunc.approxOn _ hf.measurable (range f ∪ {0}) 0 (by simp)
let f' n : α → E := {x | Integrable f (κ x)}.indicator fun x ↦ (s n).integral (κ x)
refine stronglyMeasurable_of_tendsto (f := f') atTop (fun n ↦ ?_) ?_
· refine StronglyMeasurable.indicator ?_ (measurableSet_integrable hf)
simp_rw [SimpleFunc.integral_eq]
refine Finset.stronglyMeasurable_fun_sum _ fun _ _ ↦ ?_
refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _
exact κ.measurable_coe ((s n).measurableSet_fiber _)
· rw [tendsto_pi_nhds]; intro x
by_cases hfx : Integrable f (κ x)
· simp only [mem_setOf_eq, hfx, indicator_of_mem, f']
apply tendsto_integral_approxOn_of_measurable_of_range_subset _ hfx
exact subset_rfl
· simp [f', hfx, integral_undef]
theorem StronglyMeasurable.integral_kernel_prod_right ⦃f : α → β → E⦄
(hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun x => ∫ y, f x y ∂κ x := by
classical
by_cases hE : CompleteSpace E; swap
· simp [integral, hE, stronglyMeasurable_const]
borelize E
haveI : TopologicalSpace.SeparableSpace (range (uncurry f) ∪ {0} : Set E) :=
hf.separableSpace_range_union_singleton
let s : ℕ → SimpleFunc (α × β) E :=
SimpleFunc.approxOn _ hf.measurable (range (uncurry f) ∪ {0}) 0 (by simp)
let s' : ℕ → α → SimpleFunc β E := fun n x => (s n).comp (Prod.mk x) measurable_prodMk_left
let f' : ℕ → α → E := fun n =>
{x | Integrable (f x) (κ x)}.indicator fun x => (s' n x).integral (κ x)
have hf' : ∀ n, StronglyMeasurable (f' n) := by
intro n; refine StronglyMeasurable.indicator ?_ (measurableSet_kernel_integrable hf)
have : ∀ x, ((s' n x).range.filter fun x => x ≠ 0) ⊆ (s n).range := by
intro x; refine Finset.Subset.trans (Finset.filter_subset _ _) ?_; intro y
simp_rw [SimpleFunc.mem_range]; rintro ⟨z, rfl⟩; exact ⟨(x, z), rfl⟩
simp only [SimpleFunc.integral_eq_sum_of_subset (this _)]
refine Finset.stronglyMeasurable_fun_sum _ fun x _ => ?_
refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _
simp only [s', SimpleFunc.coe_comp, preimage_comp]
apply Kernel.measurable_kernel_prodMk_left
exact (s n).measurableSet_fiber x
have h2f' : Tendsto f' atTop (𝓝 fun x : α => ∫ y : β, f x y ∂κ x) := by
rw [tendsto_pi_nhds]; intro x
by_cases hfx : Integrable (f x) (κ x)
· have (n : _) : Integrable (s' n x) (κ x) := by
apply (hfx.norm.add hfx.norm).mono' (s' n x).aestronglyMeasurable
filter_upwards with y
simp_rw [s', SimpleFunc.coe_comp]; exact SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n
simp only [f', hfx, SimpleFunc.integral_eq_integral _ (this _), indicator_of_mem,
mem_setOf_eq]
refine
tendsto_integral_of_dominated_convergence (fun y => ‖f x y‖ + ‖f x y‖)
(fun n => (s' n x).aestronglyMeasurable) (hfx.norm.add hfx.norm) ?_ ?_
· -- Porting note: was
-- exact fun n => Eventually.of_forall fun y =>
-- SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n
exact fun n => Eventually.of_forall fun y =>
SimpleFunc.norm_approxOn_zero_le hf.measurable (by simp) (x, y) n
· refine Eventually.of_forall fun y => SimpleFunc.tendsto_approxOn hf.measurable (by simp) ?_
apply subset_closure
simp [-uncurry_apply_pair]
· simp [f', hfx, integral_undef]
exact stronglyMeasurable_of_tendsto _ hf' h2f'
theorem StronglyMeasurable.integral_kernel_prod_right' ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) :
StronglyMeasurable fun x => ∫ y, f (x, y) ∂κ x := by
rw [← uncurry_curry f] at hf
exact hf.integral_kernel_prod_right
theorem StronglyMeasurable.integral_kernel_prod_right'' {f : β × γ → E}
(hf : StronglyMeasurable f) : StronglyMeasurable fun x => ∫ y, f (x, y) ∂η (a, x) := by
change
StronglyMeasurable
((fun x => ∫ y, (fun u : (α × β) × γ => f (u.1.2, u.2)) (x, y) ∂η x) ∘ fun x => (a, x))
apply StronglyMeasurable.comp_measurable _ (measurable_prodMk_left (m := mα))
· have := MeasureTheory.StronglyMeasurable.integral_kernel_prod_right' (κ := η)
(hf.comp_measurable (measurable_fst.snd.prodMk measurable_snd))
simpa using this
theorem StronglyMeasurable.integral_kernel_prod_left ⦃f : β → α → E⦄
(hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun y => ∫ x, f x y ∂κ y :=
(hf.comp_measurable measurable_swap).integral_kernel_prod_right'
theorem StronglyMeasurable.integral_kernel_prod_left' ⦃f : β × α → E⦄ (hf : StronglyMeasurable f) :
StronglyMeasurable fun y => ∫ x, f (x, y) ∂κ y :=
(hf.comp_measurable measurable_swap).integral_kernel_prod_right'
theorem StronglyMeasurable.integral_kernel_prod_left'' {f : γ × β → E} (hf : StronglyMeasurable f) :
StronglyMeasurable fun y => ∫ x, f (x, y) ∂η (a, y) := by
change
StronglyMeasurable
((fun y => ∫ x, (fun u : γ × α × β => f (u.1, u.2.2)) (x, y) ∂η y) ∘ fun x => (a, x))
apply StronglyMeasurable.comp_measurable _ (measurable_prodMk_left (m := mα))
· have := MeasureTheory.StronglyMeasurable.integral_kernel_prod_left' (κ := η)
(hf.comp_measurable (measurable_fst.prodMk measurable_snd.snd))
simpa using this
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Integral.lean | import Mathlib.MeasureTheory.Integral.Bochner.Basic
import Mathlib.Probability.Kernel.Basic
/-!
# Bochner integrals of kernels
-/
open MeasureTheory
namespace ProbabilityTheory
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {κ : Kernel α β}
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} {a : α}
namespace Kernel
lemma IsFiniteKernel.integrable (μ : Measure α) [IsFiniteMeasure μ]
(κ : Kernel α β) [IsFiniteKernel κ] {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x ↦ (κ x).real s) μ := by
refine Integrable.mono' (integrable_const κ.bound.toReal)
((κ.measurable_coe hs).ennreal_toReal.aestronglyMeasurable)
(ae_of_all μ fun x ↦ ?_)
rw [Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg]
exact ENNReal.toReal_mono (Kernel.bound_ne_top _) (Kernel.measure_le_bound _ _ _)
lemma IsMarkovKernel.integrable (μ : Measure α) [IsFiniteMeasure μ]
(κ : Kernel α β) [IsMarkovKernel κ] {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x => (κ x).real s) μ :=
IsFiniteKernel.integrable μ κ hs
lemma integral_congr_ae₂ {f g : α → β → E} {μ : Measure α} (h : ∀ᵐ a ∂μ, f a =ᵐ[κ a] g a) :
∫ a, ∫ b, f a b ∂(κ a) ∂μ = ∫ a, ∫ b, g a b ∂(κ a) ∂μ := by
apply integral_congr_ae
filter_upwards [h] with _ ha
apply integral_congr_ae
filter_upwards [ha] with _ hb using hb
lemma integral_indicator₂ (f : α → β → E) (s : Set α) (a : α) :
∫ y, s.indicator (f · y) a ∂κ a = s.indicator (fun x ↦ ∫ y, f x y ∂κ x) a := by
by_cases ha : a ∈ s <;> simp [ha]
section Deterministic
variable [CompleteSpace E] {g : α → β}
theorem integral_deterministic' (hg : Measurable g) (hf : StronglyMeasurable f) :
∫ x, f x ∂deterministic g hg a = f (g a) := by
rw [deterministic_apply, integral_dirac' _ _ hf]
@[simp]
theorem integral_deterministic [MeasurableSingletonClass β] (hg : Measurable g) :
∫ x, f x ∂deterministic g hg a = f (g a) := by
rw [deterministic_apply, integral_dirac _ (g a)]
theorem setIntegral_deterministic' (hg : Measurable g)
(hf : StronglyMeasurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] :
∫ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [deterministic_apply, setIntegral_dirac' hf _ hs]
@[simp]
theorem setIntegral_deterministic [MeasurableSingletonClass β] (hg : Measurable g)
(s : Set β) [Decidable (g a ∈ s)] :
∫ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [deterministic_apply, setIntegral_dirac f _ s]
end Deterministic
section Const
@[simp]
theorem integral_const {μ : Measure β} : ∫ x, f x ∂const α μ a = ∫ x, f x ∂μ := by
rw [const_apply]
@[simp]
theorem setIntegral_const {μ : Measure β} {s : Set β} :
∫ x in s, f x ∂const α μ a = ∫ x in s, f x ∂μ := by rw [const_apply]
end Const
section Restrict
variable {s : Set β}
@[simp]
theorem integral_restrict (hs : MeasurableSet s) :
∫ x, f x ∂κ.restrict hs a = ∫ x in s, f x ∂κ a := by
rw [restrict_apply]
@[simp]
theorem setIntegral_restrict (hs : MeasurableSet s) (t : Set β) :
∫ x in t, f x ∂κ.restrict hs a = ∫ x in t ∩ s, f x ∂κ a := by
rw [restrict_apply, Measure.restrict_restrict' hs]
end Restrict
section Piecewise
variable {η : Kernel α β} {s : Set α} {hs : MeasurableSet s} [DecidablePred (· ∈ s)]
theorem integral_piecewise (a : α) (g : β → E) :
∫ b, g b ∂piecewise hs κ η a = if a ∈ s then ∫ b, g b ∂κ a else ∫ b, g b ∂η a := by
simp_rw [piecewise_apply]; split_ifs <;> rfl
theorem setIntegral_piecewise (a : α) (g : β → E) (t : Set β) :
∫ b in t, g b ∂piecewise hs κ η a =
if a ∈ s then ∫ b in t, g b ∂κ a else ∫ b in t, g b ∂η a := by
simp_rw [piecewise_apply]; split_ifs <;> rfl
end Piecewise
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Condexp.lean | import Mathlib.Probability.Kernel.Composition.MeasureComp
import Mathlib.Probability.Kernel.CondDistrib
import Mathlib.Probability.ConditionalProbability
/-!
# Kernel associated with a conditional expectation
We define `condExpKernel μ m`, a kernel from `Ω` to `Ω` such that for all integrable functions `f`,
`μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
This kernel is defined if `Ω` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable
set `s` to a function `Ω → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all
`a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a
measure, but the fact that the `μ`-null set depends on `s` can prevent us from finding versions of
the conditional expectation that combine into a true measure. The standard Borel space assumption
on `Ω` allows us to do so.
## Main definitions
* `condExpKernel μ m`: kernel such that `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
## Main statements
* `condExp_ae_eq_integral_condExpKernel`: `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped ENNReal MeasureTheory ProbabilityTheory
namespace ProbabilityTheory
section AuxLemmas
variable {Ω F : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → F}
theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F]
(hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable[m.prod mΩ] (fun x : Ω × Ω => f x.2)
(@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by
rw [← aestronglyMeasurable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf
simp_rw [id] at hf ⊢
exact hf
theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_id [NormedAddCommGroup F] (hm : m ≤ mΩ)
(hf : Integrable f μ) : Integrable (fun x : Ω × Ω => f x.2)
(@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by
rw [← integrable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf
simp_rw [id] at hf ⊢
exact hf
end AuxLemmas
variable {Ω F : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω]
[StandardBorelSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ]
open Classical in
/-- Kernel associated with the conditional expectation with respect to a σ-algebra. It satisfies
`μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
It is defined as the conditional distribution of the identity given the identity, where the second
identity is understood as a map from `Ω` with the σ-algebra `mΩ` to `Ω` with σ-algebra `m ⊓ mΩ`.
We use `m ⊓ mΩ` instead of `m` to ensure that it is a sub-σ-algebra of `mΩ`. We then use
`Kernel.comap` to get a kernel from `m` to `mΩ` instead of from `m ⊓ mΩ` to `mΩ`. -/
noncomputable irreducible_def condExpKernel (μ : Measure Ω) [IsFiniteMeasure μ]
(m : MeasurableSpace Ω) : @Kernel Ω Ω m mΩ :=
if _h : Nonempty Ω then
Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id
(measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m))
else 0
lemma condExpKernel_eq (μ : Measure Ω) [IsFiniteMeasure μ] [h : Nonempty Ω]
(m : MeasurableSpace Ω) :
condExpKernel (mΩ := mΩ) μ m = Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id
(measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) := by
simp [condExpKernel, h]
lemma condExpKernel_apply_eq_condDistrib [Nonempty Ω] {ω : Ω} :
condExpKernel μ m ω = @condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _ (id ω) := by
simp [condExpKernel_eq, Kernel.comap_apply]
instance : IsMarkovKernel (condExpKernel μ m) := by
rcases isEmpty_or_nonempty Ω with h | h
· exact ⟨fun a ↦ (IsEmpty.false a).elim⟩
· simpa [condExpKernel, h] using by infer_instance
lemma compProd_trim_condExpKernel (hm : m ≤ mΩ) :
(μ.trim hm) ⊗ₘ condExpKernel μ m
= @Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω ↦ (id ω, id ω)) μ := by
rcases isEmpty_or_nonempty Ω with h | h
· simp [Measure.eq_zero_of_isEmpty μ]
rw [condExpKernel_eq]
have : m ⊓ mΩ = m := inf_of_le_left hm
have h := compProd_map_condDistrib (mβ := m) (μ := μ) (X := id) measurable_id.aemeasurable
rw [← h, trim_eq_map hm]
congr 1
ext a s hs
simp only [Kernel.coe_comap, Function.comp_apply, id_eq]
congr
lemma condExpKernel_comp_trim (hm : m ≤ mΩ) : condExpKernel μ m ∘ₘ μ.trim hm = μ := by
rw [← Measure.snd_compProd, compProd_trim_condExpKernel, @Measure.snd_map_prodMk, Measure.map_id]
exact measurable_id'' hm
section Measurability
variable [NormedAddCommGroup F] {f : Ω → F}
theorem measurable_condExpKernel {s : Set Ω} (hs : MeasurableSet s) :
Measurable[m] fun ω => condExpKernel μ m ω s :=
(condExpKernel μ m).measurable_coe hs
theorem stronglyMeasurable_condExpKernel {s : Set Ω} (hs : MeasurableSet s) :
StronglyMeasurable[m] fun ω => condExpKernel μ m ω s :=
Measurable.stronglyMeasurable (measurable_condExpKernel hs)
theorem _root_.MeasureTheory.StronglyMeasurable.integral_condExpKernel' [NormedSpace ℝ F]
(hf : StronglyMeasurable f) :
StronglyMeasurable[m ⊓ mΩ] (fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω) := by
nontriviality Ω
simp_rw [condExpKernel_apply_eq_condDistrib]
exact (hf.comp_measurable measurable_snd).integral_condDistrib
theorem _root_.MeasureTheory.StronglyMeasurable.integral_condExpKernel [NormedSpace ℝ F]
(hf : StronglyMeasurable f) :
StronglyMeasurable[m] (fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω) :=
hf.integral_condExpKernel'.mono inf_le_left
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condExpKernel [NormedSpace ℝ F]
(hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable (fun ω => ∫ y, f y ∂condExpKernel μ m ω) μ := by
nontriviality Ω
simp_rw [condExpKernel_apply_eq_condDistrib]
exact AEStronglyMeasurable.integral_condDistrib
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf.comp_snd_map_prod_id inf_le_right)
theorem aestronglyMeasurable_integral_condExpKernel [NormedSpace ℝ F]
(hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable[m] (fun ω => ∫ y, f y ∂condExpKernel μ m ω) μ := by
nontriviality Ω
rw [condExpKernel_eq]
have h := aestronglyMeasurable_integral_condDistrib
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ))
rw [MeasurableSpace.comap_id] at h
exact h.mono inf_le_left
lemma aestronglyMeasurable_trim_condExpKernel (hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) :
∀ᵐ ω ∂(μ.trim hm), f =ᵐ[condExpKernel μ m ω] hf.mk f := by
refine Measure.ae_ae_of_ae_comp ?_
rw [condExpKernel_comp_trim hm]
exact hf.ae_eq_mk
end Measurability
section Integrability
variable [NormedAddCommGroup F] {f : Ω → F}
theorem _root_.MeasureTheory.Integrable.condExpKernel_ae (hf_int : Integrable f μ) :
∀ᵐ ω ∂μ, Integrable f (condExpKernel μ m ω) := by
nontriviality Ω
rw [condExpKernel_eq]
convert Integrable.condDistrib_ae
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1
theorem _root_.MeasureTheory.Integrable.integral_norm_condExpKernel (hf_int : Integrable f μ) :
Integrable (fun ω => ∫ y, ‖f y‖ ∂condExpKernel μ m ω) μ := by
nontriviality Ω
rw [condExpKernel_eq]
convert Integrable.integral_norm_condDistrib
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1
theorem _root_.MeasureTheory.Integrable.norm_integral_condExpKernel [NormedSpace ℝ F]
(hf_int : Integrable f μ) :
Integrable (fun ω => ‖∫ y, f y ∂condExpKernel μ m ω‖) μ := by
nontriviality Ω
rw [condExpKernel_eq]
convert Integrable.norm_integral_condDistrib
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1
theorem _root_.MeasureTheory.Integrable.integral_condExpKernel [NormedSpace ℝ F]
(hf_int : Integrable f μ) :
Integrable (fun ω => ∫ y, f y ∂condExpKernel μ m ω) μ := by
nontriviality Ω
rw [condExpKernel_eq]
convert Integrable.integral_condDistrib
(aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id
(hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1
theorem integrable_toReal_condExpKernel {s : Set Ω} (hs : MeasurableSet s) :
Integrable (fun ω => (condExpKernel μ m ω).real s) μ := by
nontriviality Ω
rw [condExpKernel_eq]
exact integrable_toReal_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) hs
end Integrability
lemma condExpKernel_ae_eq_condExp' {s : Set Ω} (hs : MeasurableSet s) :
(fun ω ↦ (condExpKernel μ m ω).real s) =ᵐ[μ] μ⟦s|m ⊓ mΩ⟧ := by
rcases isEmpty_or_nonempty Ω with h | h
· have : μ = 0 := Measure.eq_zero_of_isEmpty μ
simpa [this] using trivial
have h := condDistrib_ae_eq_condExp (μ := μ)
(measurable_id'' (inf_le_right : m ⊓ mΩ ≤ mΩ)) measurable_id hs
simp only [id_eq, MeasurableSpace.comap_id, preimage_id_eq] at h
simp_rw [condExpKernel_apply_eq_condDistrib]
exact h
lemma condExpKernel_ae_eq_condExp
(hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) :
(fun ω ↦ (condExpKernel μ m ω).real s) =ᵐ[μ] μ⟦s|m⟧ :=
(condExpKernel_ae_eq_condExp' hs).trans (by rw [inf_of_le_left hm])
lemma condExpKernel_ae_eq_trim_condExp
(hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) :
(fun ω ↦ (condExpKernel μ m ω).real s) =ᵐ[μ.trim hm] μ⟦s|m⟧ := by
simp_rw [measureReal_def]
rw [(measurable_condExpKernel hs).ennreal_toReal.stronglyMeasurable.ae_eq_trim_iff hm
stronglyMeasurable_condExp]
exact condExpKernel_ae_eq_condExp hm hs
lemma condDistrib_apply_ae_eq_condExpKernel_map {β γ : Type*} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} [StandardBorelSpace β] [Nonempty β] {X : Ω → β} {Y : Ω → γ}
(hX : Measurable X) (hY : Measurable Y) {s : Set β} (hs : MeasurableSet s) :
(fun a ↦ condDistrib X Y μ (Y a) s)
=ᵐ[μ] fun a ↦ (condExpKernel μ (mγ.comap Y)).map X a s := by
simp_rw [Kernel.map_apply' _ hX _ hs]
filter_upwards [condDistrib_ae_eq_condExp hY hX (μ := μ) hs,
condExpKernel_ae_eq_condExp hY.comap_le (μ := μ) (hX hs)] with a ha₁ ha₂
rw [← measureReal_eq_measureReal_iff, ha₁, ha₂]
theorem condExp_ae_eq_integral_condExpKernel' [NormedAddCommGroup F] {f : Ω → F}
[NormedSpace ℝ F] [CompleteSpace F] (hf_int : Integrable f μ) :
μ[f|m ⊓ mΩ] =ᵐ[μ] fun ω => ∫ y, f y ∂condExpKernel μ m ω := by
rcases isEmpty_or_nonempty Ω with h | h
· have : μ = 0 := Measure.eq_zero_of_isEmpty μ
simpa [this] using trivial
have hX : @Measurable Ω Ω mΩ (m ⊓ mΩ) id := measurable_id.mono le_rfl (inf_le_right : m ⊓ mΩ ≤ mΩ)
simp_rw [condExpKernel_apply_eq_condDistrib]
have h := condExp_ae_eq_integral_condDistrib_id hX hf_int
simpa only [MeasurableSpace.comap_id, id_eq] using h
/-- The conditional expectation of `f` with respect to a σ-algebra `m` is almost everywhere equal to
the integral `∫ y, f y ∂(condExpKernel μ m ω)`. -/
theorem condExp_ae_eq_integral_condExpKernel [NormedAddCommGroup F] {f : Ω → F}
[NormedSpace ℝ F] [CompleteSpace F] (hm : m ≤ mΩ) (hf_int : Integrable f μ) :
μ[f|m] =ᵐ[μ] fun ω => ∫ y, f y ∂condExpKernel μ m ω :=
((condExp_ae_eq_integral_condExpKernel' hf_int).symm.trans (by rw [inf_of_le_left hm])).symm
/-- Auxiliary lemma for `condExp_ae_eq_trim_integral_condExpKernel`. -/
theorem condExp_ae_eq_trim_integral_condExpKernel_of_stronglyMeasurable
[NormedAddCommGroup F] {f : Ω → F} [NormedSpace ℝ F] [CompleteSpace F]
(hm : m ≤ mΩ) (hf : StronglyMeasurable f) (hf_int : Integrable f μ) :
μ[f|m] =ᵐ[μ.trim hm] fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω := by
refine StronglyMeasurable.ae_eq_trim_of_stronglyMeasurable hm ?_ ?_ ?_
· exact stronglyMeasurable_condExp
· exact hf.integral_condExpKernel
· exact condExp_ae_eq_integral_condExpKernel hm hf_int
/-- The conditional expectation of `f` with respect to a σ-algebra `m` is
(`μ.trim hm`)-almost everywhere equal to the integral `∫ y, f y ∂(condExpKernel μ m ω)`. -/
theorem condExp_ae_eq_trim_integral_condExpKernel [NormedAddCommGroup F] {f : Ω → F}
[NormedSpace ℝ F] [CompleteSpace F] (hm : m ≤ mΩ) (hf_int : Integrable f μ) :
μ[f|m] =ᵐ[μ.trim hm] fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω := by
refine (condExp_congr_ae_trim hm hf_int.1.ae_eq_mk).trans ?_
refine (condExp_ae_eq_trim_integral_condExpKernel_of_stronglyMeasurable hm
hf_int.1.stronglyMeasurable_mk ?_).trans ?_
· rwa [integrable_congr hf_int.1.ae_eq_mk.symm]
filter_upwards [aestronglyMeasurable_trim_condExpKernel hm hf_int.1] with ω hω
rw [integral_congr_ae hω]
section Cond
/-! ### Relation between conditional expectation, conditional kernel and the conditional measure. -/
open MeasurableSpace
variable {s t : Set Ω} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]
omit [StandardBorelSpace Ω]
lemma condExp_generateFrom_singleton (hs : MeasurableSet s) {f : Ω → F} (hf : Integrable f μ) :
μ[f|generateFrom {s}] =ᵐ[μ.restrict s] fun _ ↦ ∫ x, f x ∂μ[|s] := by
by_cases hμs : μ s = 0
· rw [Measure.restrict_eq_zero.2 hμs]
rfl
refine ae_eq_trans (condExp_restrict_ae_eq_restrict
(generateFrom_singleton_le hs)
(measurableSet_generateFrom rfl) hf).symm ?_
· refine (ae_eq_condExp_of_forall_setIntegral_eq (generateFrom_singleton_le hs) hf.restrict ?_ ?_
stronglyMeasurable_const.aestronglyMeasurable).symm
· rintro t - -
rw [integrableOn_const_iff]
exact Or.inr <| measure_lt_top (μ.restrict s) t
· rintro t ht -
obtain (h | h | h | h) := measurableSet_generateFrom_singleton_iff.1 ht
· simp [h]
· simp only [h, cond, integral_smul_measure, ENNReal.toReal_inv, integral_const,
MeasurableSet.univ, measureReal_restrict_apply, univ_inter, measureReal_restrict_apply_self,
← measureReal_def]
rw [smul_inv_smul₀, Measure.restrict_restrict hs, inter_self]
exact ENNReal.toReal_ne_zero.2 ⟨hμs, measure_ne_top _ _⟩
· simp only [h, integral_const, MeasurableSet.univ, measureReal_restrict_apply, univ_inter,
measureReal_restrict_apply hs.compl, compl_inter_self, measureReal_empty, zero_smul,
((Measure.restrict_apply_eq_zero hs.compl).2 <| compl_inter_self s ▸ measure_empty),
setIntegral_measure_zero]
· simp only [h, Measure.restrict_univ, cond, integral_smul_measure, ENNReal.toReal_inv, ←
measureReal_def, integral_const, MeasurableSet.univ, measureReal_restrict_apply, univ_inter]
rw [smul_inv_smul₀]
exact (measureReal_ne_zero_iff (by finiteness)).2 hμs
lemma condExp_set_generateFrom_singleton (hs : MeasurableSet s) (ht : MeasurableSet t) :
μ⟦t|generateFrom {s}⟧ =ᵐ[μ.restrict s] fun _ ↦ μ[|s].real t := by
rw [← integral_indicator_one ht]
exact condExp_generateFrom_singleton hs <| Integrable.indicator (integrable_const 1) ht
lemma condExpKernel_singleton_ae_eq_cond [StandardBorelSpace Ω] (hs : MeasurableSet s)
(ht : MeasurableSet t) :
∀ᵐ ω ∂μ.restrict s,
condExpKernel μ (generateFrom {s}) ω t = μ[t|s] := by
have : (fun ω ↦ (condExpKernel μ (generateFrom {s}) ω).real t) =ᵐ[μ.restrict s]
μ⟦t|generateFrom {s}⟧ :=
ae_restrict_le <| condExpKernel_ae_eq_condExp
(generateFrom_singleton_le hs) ht
filter_upwards [condExp_set_generateFrom_singleton hs ht, this] with ω hω₁ hω₂
rwa [hω₁, measureReal_def, measureReal_def,
ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ t) (measure_ne_top _ t)] at hω₂
end Cond
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/CondDistrib.lean | import Mathlib.Probability.Kernel.Composition.Lemmas
import Mathlib.Probability.Kernel.Disintegration.Unique
/-!
# Regular conditional probability distribution
We define the regular conditional probability distribution of `Y : α → Ω` given `X : α → β`, where
`Ω` is a standard Borel space. This is a `Kernel β Ω` such that for almost all `a`, `condDistrib`
evaluated at `X a` and a measurable set `s` is equal to the conditional expectation
`μ⟦Y ⁻¹' s | mβ.comap X⟧` evaluated at `a`.
`μ⟦Y ⁻¹' s | mβ.comap X⟧` maps a measurable set `s` to a function `α → ℝ≥0∞`, and for all `s` that
map is unique up to a `μ`-null set. For all `a`, the map from sets to `ℝ≥0∞` that we obtain that way
verifies some of the properties of a measure, but in general the fact that the `μ`-null set depends
on `s` can prevent us from finding versions of the conditional expectation that combine into a true
measure. The standard Borel space assumption on `Ω` allows us to do so.
The case `Y = X = id` is developed in more detail in `Probability/Kernel/Condexp.lean`: here `X` is
understood as a map from `Ω` with a sub-σ-algebra `m` to `Ω` with its default σ-algebra and the
conditional distribution defines a kernel associated with the conditional expectation with respect
to `m`.
## Main definitions
* `condDistrib Y X μ`: regular conditional probability distribution of `Y : α → Ω` given
`X : α → β`, where `Ω` is a standard Borel space.
## Main statements
* `condDistrib_ae_eq_condExp`: for almost all `a`, `condDistrib` evaluated at `X a` and a
measurable set `s` is equal to the conditional expectation `μ⟦Y ⁻¹' s | mβ.comap X⟧ a`.
* `condExp_prod_ae_eq_integral_condDistrib`: the conditional expectation
`μ[(fun a => f (X a, Y a)) | X; mβ]` is almost everywhere equal to the integral
`∫ y, f (X a, y) ∂(condDistrib Y X μ (X a))`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped ENNReal MeasureTheory ProbabilityTheory
namespace ProbabilityTheory
variable {α β Ω F : Type*} [MeasurableSpace Ω] [StandardBorelSpace Ω]
[Nonempty Ω] [NormedAddCommGroup F] {mα : MeasurableSpace α} {μ : Measure α} [IsFiniteMeasure μ]
{X : α → β} {Y : α → Ω}
/-- **Regular conditional probability distribution**: kernel associated with the conditional
expectation of `Y` given `X`.
For almost all `a`, `condDistrib Y X μ` evaluated at `X a` and a measurable set `s` is equal to
the conditional expectation `μ⟦Y ⁻¹' s | mβ.comap X⟧ a`. It also satisfies the equality
`μ[(fun a => f (X a, Y a)) | mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂(condDistrib Y X μ (X a))`
for all integrable functions `f`. -/
noncomputable irreducible_def condDistrib {_ : MeasurableSpace α} [MeasurableSpace β] (Y : α → Ω)
(X : α → β) (μ : Measure α) [IsFiniteMeasure μ] : Kernel β Ω :=
(μ.map fun a => (X a, Y a)).condKernel
instance [MeasurableSpace β] : IsMarkovKernel (condDistrib Y X μ) := by
rw [condDistrib]; infer_instance
variable {mβ : MeasurableSpace β} {s : Set Ω} {t : Set β} {f : β × Ω → F}
/-- If the singleton `{x}` has non-zero mass for `μ.map X`, then for all `s : Set Ω`,
`condDistrib Y X μ x s = (μ.map X {x})⁻¹ * μ.map (fun a => (X a, Y a)) ({x} ×ˢ s)` . -/
lemma condDistrib_apply_of_ne_zero [MeasurableSingletonClass β]
(hY : Measurable Y) (x : β) (hX : μ.map X {x} ≠ 0) (s : Set Ω) :
condDistrib Y X μ x s = (μ.map X {x})⁻¹ * μ.map (fun a => (X a, Y a)) ({x} ×ˢ s) := by
rw [condDistrib, Measure.condKernel_apply_of_ne_zero _ s]
· rw [Measure.fst_map_prodMk hY]
· rwa [Measure.fst_map_prodMk hY]
lemma compProd_map_condDistrib (hY : AEMeasurable Y μ) :
(μ.map X) ⊗ₘ condDistrib Y X μ = μ.map fun a ↦ (X a, Y a) := by
rw [condDistrib, ← Measure.fst_map_prodMk₀ hY, Measure.disintegrate]
lemma condDistrib_comp_map (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) :
condDistrib Y X μ ∘ₘ (μ.map X) = μ.map Y := by
rw [← Measure.snd_compProd, compProd_map_condDistrib hY, Measure.snd_map_prodMk₀ hX]
lemma condDistrib_congr {X' : α → β} {Y' : α → Ω} (hY : Y =ᵐ[μ] Y') (hX : X =ᵐ[μ] X') :
condDistrib Y X μ = condDistrib Y' X' μ := by
rw [condDistrib, condDistrib]
congr 1
rw [Measure.map_congr]
filter_upwards [hX, hY] with a ha hb using by rw [ha, hb]
lemma condDistrib_congr_right {X' : α → β} (hX : X =ᵐ[μ] X') :
condDistrib Y X μ = condDistrib Y X' μ :=
condDistrib_congr (by rfl) hX
lemma condDistrib_congr_left {Y' : α → Ω} (hY : Y =ᵐ[μ] Y') :
condDistrib Y X μ = condDistrib Y' X μ :=
condDistrib_congr hY (by rfl)
section Measurability
theorem measurable_condDistrib (hs : MeasurableSet s) :
Measurable[mβ.comap X] fun a => condDistrib Y X μ (X a) s :=
(Kernel.measurable_coe _ hs).comp (Measurable.of_comap_le le_rfl)
theorem _root_.MeasureTheory.AEStronglyMeasurable.ae_integrable_condDistrib_map_iff
(hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) :
(∀ᵐ a ∂μ.map X, Integrable (fun ω => f (a, ω)) (condDistrib Y X μ a)) ∧
Integrable (fun a => ∫ ω, ‖f (a, ω)‖ ∂condDistrib Y X μ a) (μ.map X) ↔
Integrable f (μ.map fun a => (X a, Y a)) := by
rw [condDistrib, ← hf.ae_integrable_condKernel_iff, Measure.fst_map_prodMk₀ hY]
variable [NormedSpace ℝ F]
theorem _root_.MeasureTheory.StronglyMeasurable.integral_condDistrib (hf : StronglyMeasurable f) :
StronglyMeasurable (fun x ↦ ∫ y, f (x, y) ∂condDistrib Y X μ x) := by
rw [condDistrib]; exact hf.integral_kernel_prod_right'
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condDistrib_map
(hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) :
AEStronglyMeasurable (fun x => ∫ y, f (x, y) ∂condDistrib Y X μ x) (μ.map X) := by
rw [← Measure.fst_map_prodMk₀ hY, condDistrib]; exact hf.integral_condKernel
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condDistrib (hX : AEMeasurable X μ)
(hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) :
AEStronglyMeasurable (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ :=
(hf.integral_condDistrib_map hY).comp_aemeasurable hX
theorem stronglyMeasurable_integral_condDistrib (hf : StronglyMeasurable f) :
StronglyMeasurable[mβ.comap X] (fun a ↦ ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) :=
(hf.integral_condDistrib).comp_measurable <| Measurable.of_comap_le le_rfl
theorem aestronglyMeasurable_integral_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ)
(hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) :
AEStronglyMeasurable[mβ.comap X] (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ :=
(hf.integral_condDistrib_map hY).comp_ae_measurable' hX
end Measurability
/-- `condDistrib` is a.e. uniquely defined as the kernel satisfying the defining property of
`condKernel`. -/
theorem condDistrib_ae_eq_of_measure_eq_compProd_of_measurable
(hX : Measurable X) (hY : Measurable Y)
{κ : Kernel β Ω} [IsFiniteKernel κ] (hκ : μ.map (fun x => (X x, Y x)) = μ.map X ⊗ₘ κ) :
condDistrib Y X μ =ᵐ[μ.map X] κ := by
have heq : μ.map X = (μ.map (fun x ↦ (X x, Y x))).fst := by
ext s hs
rw [Measure.map_apply hX hs, Measure.fst_apply hs, Measure.map_apply]
exacts [rfl, Measurable.prod hX hY, measurable_fst hs]
rw [heq, condDistrib]
symm
refine eq_condKernel_of_measure_eq_compProd _ ?_
convert hκ
exact heq.symm
/-- `condDistrib` is a.e. uniquely defined as the kernel satisfying the defining property of
`condKernel`. -/
lemma condDistrib_ae_eq_of_measure_eq_compProd
(X : α → β) (hY : AEMeasurable Y μ) {κ : Kernel β Ω} [IsFiniteKernel κ]
(hκ : μ.map (fun x => (X x, Y x)) = μ.map X ⊗ₘ κ) :
condDistrib Y X μ =ᵐ[μ.map X] κ := by
by_cases hX : AEMeasurable X μ
swap; · simp [Measure.map_of_not_aemeasurable hX, Filter.EventuallyEq]
suffices condDistrib (hY.mk Y) (hX.mk X) μ =ᵐ[μ.map (hX.mk X)] κ by
rwa [Measure.map_congr hX.ae_eq_mk, condDistrib_congr hY.ae_eq_mk hX.ae_eq_mk]
refine condDistrib_ae_eq_of_measure_eq_compProd_of_measurable (μ := μ)
hX.measurable_mk hY.measurable_mk ((Eq.trans ?_ hκ).trans ?_)
· refine Measure.map_congr ?_
filter_upwards [hX.ae_eq_mk, hY.ae_eq_mk] with a haX haY using by rw [haX, haY]
· rw [Measure.map_congr hX.ae_eq_mk]
lemma condDistrib_ae_eq_iff_measure_eq_compProd
(X : α → β) (hY : AEMeasurable Y μ) (κ : Kernel β Ω) [IsFiniteKernel κ] :
(condDistrib Y X μ =ᵐ[μ.map X] κ) ↔ μ.map (fun x => (X x, Y x)) = μ.map X ⊗ₘ κ := by
refine ⟨fun h ↦ ?_, condDistrib_ae_eq_of_measure_eq_compProd X hY⟩
rw [Measure.compProd_congr h.symm, compProd_map_condDistrib hY]
lemma condDistrib_comp {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} [StandardBorelSpace Ω']
[Nonempty Ω'] (X : α → β) (hY : AEMeasurable Y μ) {f : Ω → Ω'} (hf : Measurable f) :
condDistrib (f ∘ Y) X μ =ᵐ[μ.map X] (condDistrib Y X μ).map f := by
by_cases hX : AEMeasurable X μ
swap; · simp [Measure.map_of_not_aemeasurable hX, Filter.EventuallyEq]
refine condDistrib_ae_eq_of_measure_eq_compProd X (by fun_prop) ?_
calc μ.map (fun x ↦ (X x, (f ∘ Y) x))
_ = (μ.map (fun x ↦ (X x, Y x))).map (Prod.map id f) := by
rw [AEMeasurable.map_map_of_aemeasurable (by fun_prop) (by fun_prop)]
simp [Function.comp_def]
_ = (μ.map X ⊗ₘ condDistrib Y X μ).map (Prod.map id f) := by rw [compProd_map_condDistrib hY]
_ = μ.map X ⊗ₘ (condDistrib Y X μ).map f := by rw [Measure.compProd_map hf]
lemma condDistrib_comp_self (X : α → β) {f : β → Ω} (hf : Measurable f) :
condDistrib (f ∘ X) X μ =ᵐ[μ.map X] Kernel.deterministic f hf := by
by_cases hX : AEMeasurable X μ
swap; · simp [Measure.map_of_not_aemeasurable hX, Filter.EventuallyEq]
refine condDistrib_ae_eq_of_measure_eq_compProd X (by fun_prop) ?_
rw [Measure.compProd_deterministic, AEMeasurable.map_map_of_aemeasurable (by fun_prop) hX]
simp [Function.comp_def]
lemma condDistrib_self (Y : α → Ω) : condDistrib Y Y μ =ᵐ[μ.map Y] Kernel.id := by
simpa using condDistrib_comp_self Y measurable_id
lemma condDistrib_const (X : α → β) (c : Ω) :
condDistrib (fun _ ↦ c) X μ =ᵐ[μ.map X] Kernel.deterministic (fun _ ↦ c) (by fun_prop) := by
have : (fun _ : α ↦ c) = (fun _ : β ↦ c) ∘ X := rfl
rw [this]
filter_upwards [condDistrib_comp_self X (measurable_const (a := c))] with b hb
rw [hb]
lemma condDistrib_map {γ : Type*} {mγ : MeasurableSpace γ}
{ν : Measure γ} [IsFiniteMeasure ν] {f : γ → α}
(hX : AEMeasurable X (ν.map f)) (hY : AEMeasurable Y (ν.map f)) (hf : AEMeasurable f ν) :
condDistrib Y X (ν.map f) =ᵐ[ν.map (X ∘ f)] condDistrib (Y ∘ f) (X ∘ f) ν := by
rw [← AEMeasurable.map_map_of_aemeasurable hX hf]
refine condDistrib_ae_eq_of_measure_eq_compProd (μ := ν.map f) X hY ?_
rw [AEMeasurable.map_map_of_aemeasurable hX hf, compProd_map_condDistrib (by fun_prop),
AEMeasurable.map_map_of_aemeasurable (by fun_prop) hf]
simp [Function.comp_def]
lemma condDistrib_fst_prod {γ : Type*} {mγ : MeasurableSpace γ}
(X : α → β) (hY : AEMeasurable Y μ) (ν : Measure γ) [IsProbabilityMeasure ν] :
condDistrib (fun ω ↦ Y ω.1) (fun ω ↦ X ω.1) (μ.prod ν) =ᵐ[μ.map X] condDistrib Y X μ := by
by_cases hX : AEMeasurable X μ
swap; · simp [Measure.map_of_not_aemeasurable hX, Filter.EventuallyEq]
have : μ = (μ.prod ν).map (fun ω ↦ ω.1) := by simp [Measure.map_fst_prod]
have h_map := condDistrib_map (X := X) (Y := Y) (f := Prod.fst (α := α) (β := γ))
(ν := μ.prod ν) (mα := inferInstance) (mβ := inferInstance)
(by simpa) (by simpa) (by fun_prop)
rw [← AEMeasurable.map_map_of_aemeasurable (by simpa) (by fun_prop)] at h_map
simp only [Measure.map_fst_prod, measure_univ, one_smul] at h_map
exact h_map.symm
lemma condDistrib_snd_prod {γ : Type*} {mγ : MeasurableSpace γ}
(X : α → β) (hY : AEMeasurable Y μ) (ν : Measure γ) [IsProbabilityMeasure ν] :
condDistrib (fun ω ↦ Y ω.2) (fun ω ↦ X ω.2) (ν.prod μ) =ᵐ[μ.map X] condDistrib Y X μ := by
by_cases hX : AEMeasurable X μ
swap; · simp [Measure.map_of_not_aemeasurable hX, Filter.EventuallyEq]
have : μ = (μ.prod ν).map (fun ω ↦ ω.1) := by simp [Measure.map_fst_prod]
have h_map := condDistrib_map (X := X) (Y := Y) (f := Prod.snd (β := α) (α := γ))
(ν := ν.prod μ) (mα := inferInstance) (mβ := inferInstance)
(by simpa) (by simpa) (by fun_prop)
rw [← AEMeasurable.map_map_of_aemeasurable (by simpa) (by fun_prop)] at h_map
simp only [Measure.map_snd_prod, measure_univ, one_smul] at h_map
exact h_map.symm
section Integrability
theorem integrable_toReal_condDistrib (hX : AEMeasurable X μ) (hs : MeasurableSet s) :
Integrable (fun a => (condDistrib Y X μ (X a)).real s) μ := by
refine integrable_toReal_of_lintegral_ne_top ?_ ?_
· exact Measurable.comp_aemeasurable (Kernel.measurable_coe _ hs) hX
· refine ne_of_lt ?_
calc
∫⁻ a, condDistrib Y X μ (X a) s ∂μ ≤ ∫⁻ _, 1 ∂μ := lintegral_mono fun a => prob_le_one
_ = μ univ := lintegral_one
_ < ∞ := measure_lt_top _ _
theorem _root_.MeasureTheory.Integrable.condDistrib_ae_map
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
∀ᵐ b ∂μ.map X, Integrable (fun ω => f (b, ω)) (condDistrib Y X μ b) := by
rw [condDistrib, ← Measure.fst_map_prodMk₀ (X := X) hY]; exact hf_int.condKernel_ae
theorem _root_.MeasureTheory.Integrable.condDistrib_ae (hX : AEMeasurable X μ)
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
∀ᵐ a ∂μ, Integrable (fun ω => f (X a, ω)) (condDistrib Y X μ (X a)) :=
ae_of_ae_map hX (hf_int.condDistrib_ae_map hY)
theorem _root_.MeasureTheory.Integrable.integral_norm_condDistrib_map
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂condDistrib Y X μ x) (μ.map X) := by
rw [condDistrib, ← Measure.fst_map_prodMk₀ (X := X) hY]; exact hf_int.integral_norm_condKernel
theorem _root_.MeasureTheory.Integrable.integral_norm_condDistrib (hX : AEMeasurable X μ)
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun a => ∫ y, ‖f (X a, y)‖ ∂condDistrib Y X μ (X a)) μ :=
(hf_int.integral_norm_condDistrib_map hY).comp_aemeasurable hX
variable [NormedSpace ℝ F]
theorem _root_.MeasureTheory.Integrable.norm_integral_condDistrib_map
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun x => ‖∫ y, f (x, y) ∂condDistrib Y X μ x‖) (μ.map X) := by
rw [condDistrib, ← Measure.fst_map_prodMk₀ (X := X) hY]; exact hf_int.norm_integral_condKernel
theorem _root_.MeasureTheory.Integrable.norm_integral_condDistrib (hX : AEMeasurable X μ)
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun a => ‖∫ y, f (X a, y) ∂condDistrib Y X μ (X a)‖) μ :=
(hf_int.norm_integral_condDistrib_map hY).comp_aemeasurable hX
theorem _root_.MeasureTheory.Integrable.integral_condDistrib_map
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun x => ∫ y, f (x, y) ∂condDistrib Y X μ x) (μ.map X) :=
(integrable_norm_iff (hf_int.1.integral_condDistrib_map hY)).mp
(hf_int.norm_integral_condDistrib_map hY)
theorem _root_.MeasureTheory.Integrable.integral_condDistrib (hX : AEMeasurable X μ)
(hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
Integrable (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ :=
(hf_int.integral_condDistrib_map hY).comp_aemeasurable hX
end Integrability
theorem setLIntegral_preimage_condDistrib (hX : Measurable X) (hY : AEMeasurable Y μ)
(hs : MeasurableSet s) (ht : MeasurableSet t) :
∫⁻ a in X ⁻¹' t, condDistrib Y X μ (X a) s ∂μ = μ (X ⁻¹' t ∩ Y ⁻¹' s) := by
rw [← lintegral_map (Kernel.measurable_coe _ hs) hX, condDistrib, ← Measure.restrict_map hX ht,
← Measure.fst_map_prodMk₀ hY, Measure.setLIntegral_condKernel_eq_measure_prod ht hs,
Measure.map_apply_of_aemeasurable (hX.aemeasurable.prodMk hY) (ht.prod hs), mk_preimage_prod]
theorem setLIntegral_condDistrib_of_measurableSet (hX : Measurable X) (hY : AEMeasurable Y μ)
(hs : MeasurableSet s) {t : Set α} (ht : MeasurableSet[mβ.comap X] t) :
∫⁻ a in t, condDistrib Y X μ (X a) s ∂μ = μ (t ∩ Y ⁻¹' s) := by
obtain ⟨t', ht', rfl⟩ := ht
rw [setLIntegral_preimage_condDistrib hX hY hs ht']
/-- For almost every `a : α`, the `condDistrib Y X μ` kernel applied to `X a` and a measurable set
`s` is equal to the conditional expectation of the indicator of `Y ⁻¹' s`. -/
theorem condDistrib_ae_eq_condExp (hX : Measurable X) (hY : Measurable Y) (hs : MeasurableSet s) :
(fun a => (condDistrib Y X μ (X a)).real s) =ᵐ[μ] μ⟦Y ⁻¹' s|mβ.comap X⟧ := by
refine ae_eq_condExp_of_forall_setIntegral_eq hX.comap_le ?_ ?_ ?_ ?_
· exact (integrable_const _).indicator (hY hs)
· exact fun t _ _ => (integrable_toReal_condDistrib hX.aemeasurable hs).integrableOn
· intro t ht _
simp_rw [measureReal_def]
rw [integral_toReal ((measurable_condDistrib hs).mono hX.comap_le le_rfl).aemeasurable
(Eventually.of_forall fun ω => measure_lt_top (condDistrib Y X μ (X ω)) _),
integral_indicator_const _ (hY hs), measureReal_restrict_apply (hY hs), smul_eq_mul, mul_one,
inter_comm, setLIntegral_condDistrib_of_measurableSet hX hY.aemeasurable hs ht,
measureReal_def]
· exact (measurable_condDistrib hs).ennreal_toReal.aestronglyMeasurable
/-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal
to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/
theorem condExp_prod_ae_eq_integral_condDistrib' [NormedSpace ℝ F] [CompleteSpace F]
(hX : Measurable X) (hY : AEMeasurable Y μ)
(hf_int : Integrable f (μ.map fun a => (X a, Y a))) :
μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ]
fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a) := by
have hf_int' : Integrable (fun a => f (X a, Y a)) μ :=
(integrable_map_measure hf_int.1 (hX.aemeasurable.prodMk hY)).mp hf_int
refine (ae_eq_condExp_of_forall_setIntegral_eq hX.comap_le hf_int' (fun s _ _ => ?_) ?_ ?_).symm
· exact (hf_int.integral_condDistrib hX.aemeasurable hY).integrableOn
· rintro s ⟨t, ht, rfl⟩ _
change ∫ a in X ⁻¹' t, ((fun x' => ∫ y, f (x', y) ∂(condDistrib Y X μ) x') ∘ X) a ∂μ =
∫ a in X ⁻¹' t, f (X a, Y a) ∂μ
simp only [Function.comp_apply]
rw [← integral_map hX.aemeasurable (f := fun x' => ∫ y, f (x', y) ∂(condDistrib Y X μ) x')]
swap
· rw [← Measure.restrict_map hX ht]
exact (hf_int.1.integral_condDistrib_map hY).restrict
rw [← Measure.restrict_map hX ht, ← Measure.fst_map_prodMk₀ hY, condDistrib,
Measure.setIntegral_condKernel_univ_right ht hf_int.integrableOn,
setIntegral_map (ht.prod MeasurableSet.univ) hf_int.1 (hX.aemeasurable.prodMk hY),
mk_preimage_prod, preimage_univ, inter_univ]
· exact aestronglyMeasurable_integral_condDistrib hX.aemeasurable hY hf_int.1
/-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal
to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/
theorem condExp_prod_ae_eq_integral_condDistrib₀ [NormedSpace ℝ F] [CompleteSpace F]
(hX : Measurable X) (hY : AEMeasurable Y μ)
(hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a)))
(hf_int : Integrable (fun a => f (X a, Y a)) μ) :
μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a) :=
have hf_int' : Integrable f (μ.map fun a => (X a, Y a)) := by
rwa [integrable_map_measure hf (hX.aemeasurable.prodMk hY)]
condExp_prod_ae_eq_integral_condDistrib' hX hY hf_int'
/-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal
to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/
theorem condExp_prod_ae_eq_integral_condDistrib [NormedSpace ℝ F] [CompleteSpace F]
(hX : Measurable X) (hY : AEMeasurable Y μ) (hf : StronglyMeasurable f)
(hf_int : Integrable (fun a => f (X a, Y a)) μ) :
μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a) :=
have hf_int' : Integrable f (μ.map fun a => (X a, Y a)) := by
rwa [integrable_map_measure hf.aestronglyMeasurable (hX.aemeasurable.prodMk hY)]
condExp_prod_ae_eq_integral_condDistrib' hX hY hf_int'
theorem condExp_ae_eq_integral_condDistrib [NormedSpace ℝ F] [CompleteSpace F] (hX : Measurable X)
(hY : AEMeasurable Y μ) {f : Ω → F} (hf : StronglyMeasurable f)
(hf_int : Integrable (fun a => f (Y a)) μ) :
μ[fun a => f (Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f y ∂condDistrib Y X μ (X a) :=
condExp_prod_ae_eq_integral_condDistrib hX hY (hf.comp_measurable measurable_snd) hf_int
/-- The conditional expectation of `Y` given `X` is almost everywhere equal to the integral
`∫ y, y ∂(condDistrib Y X μ (X a))`. -/
theorem condExp_ae_eq_integral_condDistrib' {Ω} [NormedAddCommGroup Ω] [NormedSpace ℝ Ω]
[CompleteSpace Ω] [MeasurableSpace Ω] [BorelSpace Ω] [SecondCountableTopology Ω] {Y : α → Ω}
(hX : Measurable X) (hY_int : Integrable Y μ) :
μ[Y|mβ.comap X] =ᵐ[μ] fun a => ∫ y, y ∂condDistrib Y X μ (X a) :=
condExp_ae_eq_integral_condDistrib hX hY_int.1.aemeasurable stronglyMeasurable_id hY_int
open MeasureTheory
theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prodMk {Ω F} {mΩ : MeasurableSpace Ω}
(X : Ω → β) {μ : Measure Ω} [TopologicalSpace F] {f : Ω → F} (hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) := by
refine ⟨fun x => hf.mk f x.2, hf.stronglyMeasurable_mk.comp_measurable measurable_snd, ?_⟩
suffices h : Measure.QuasiMeasurePreserving Prod.snd (μ.map fun ω ↦ (X ω, ω)) μ from
Measure.QuasiMeasurePreserving.ae_eq h hf.ae_eq_mk
refine ⟨measurable_snd, Measure.AbsolutelyContinuous.mk fun s hs hμs => ?_⟩
rw [Measure.map_apply measurable_snd hs]
by_cases hX : AEMeasurable X μ
· rw [Measure.map_apply_of_aemeasurable]
· rw [← univ_prod, mk_preimage_prod, preimage_univ, univ_inter, preimage_id']
exact hμs
· exact hX.prodMk aemeasurable_id
· exact measurable_snd hs
· rw [Measure.map_of_not_aemeasurable]
· simp
· contrapose! hX; exact measurable_fst.comp_aemeasurable hX
theorem _root_.MeasureTheory.Integrable.comp_snd_map_prodMk
{Ω} {mΩ : MeasurableSpace Ω} (X : Ω → β) {μ : Measure Ω} {f : Ω → F} (hf_int : Integrable f μ) :
Integrable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) := by
by_cases hX : AEMeasurable X μ
· have hf := hf_int.1.comp_snd_map_prodMk X (mΩ := mΩ) (mβ := mβ)
refine ⟨hf, ?_⟩
rw [hasFiniteIntegral_iff_enorm, lintegral_map' hf.enorm (hX.prodMk aemeasurable_id)]
exact hf_int.2
· rw [Measure.map_of_not_aemeasurable]
· simp
· contrapose! hX; exact measurable_fst.comp_aemeasurable hX
theorem aestronglyMeasurable_comp_snd_map_prodMk_iff {Ω F} {_ : MeasurableSpace Ω}
[TopologicalSpace F] {X : Ω → β} {μ : Measure Ω} (hX : Measurable X) {f : Ω → F} :
AEStronglyMeasurable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) ↔
AEStronglyMeasurable f μ :=
⟨fun h => h.comp_measurable (hX.prodMk measurable_id), fun h => h.comp_snd_map_prodMk X⟩
theorem integrable_comp_snd_map_prodMk_iff {Ω} {_ : MeasurableSpace Ω} {X : Ω → β} {μ : Measure Ω}
(hX : Measurable X) {f : Ω → F} :
Integrable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) ↔ Integrable f μ :=
⟨fun h => h.comp_measurable (hX.prodMk measurable_id), fun h => h.comp_snd_map_prodMk X⟩
theorem condExp_ae_eq_integral_condDistrib_id [NormedSpace ℝ F] [CompleteSpace F] {X : Ω → β}
{μ : Measure Ω} [IsFiniteMeasure μ] (hX : Measurable X) {f : Ω → F} (hf_int : Integrable f μ) :
μ[f|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f y ∂condDistrib id X μ (X a) :=
condExp_prod_ae_eq_integral_condDistrib' hX aemeasurable_id (hf_int.comp_snd_map_prodMk X)
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/SetIntegral.lean | import Mathlib.MeasureTheory.Integral.Bochner.Set
import Mathlib.Probability.Kernel.Integral
/-! # Integral against a kernel over a set
This file contains lemmas about the integral against a kernel and over a set.
-/
open MeasureTheory ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {X Y E : Type*} {mX : MeasurableSpace X} {mY : MeasurableSpace Y}
[NormedAddCommGroup E] [NormedSpace ℝ E] (κ : Kernel X Y)
lemma integral_integral_indicator (μ : Measure X) (f : X → Y → E) {s : Set X}
(hs : MeasurableSet s) :
∫ x, ∫ y, s.indicator (f · y) x ∂κ x ∂μ = ∫ x in s, ∫ y, f x y ∂κ x ∂μ := by
simp_rw [← integral_indicator hs, Kernel.integral_indicator₂]
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/MeasurableLIntegral.lean | import Mathlib.MeasureTheory.MeasurableSpace.Prod
import Mathlib.Probability.Kernel.Basic
/-!
# Measurability of the integral against a kernel
The Lebesgue integral of a measurable function against a kernel is measurable.
## Main statements
* `Measurable.lintegral_kernel_prod_right`: the function `a ↦ ∫⁻ b, f a b ∂(κ a)` is measurable,
for an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` such that `uncurry f`
is measurable.
-/
open MeasureTheory ProbabilityTheory Function Set Filter
open scoped MeasureTheory ENNReal Topology
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{κ : Kernel α β} {η : Kernel (α × β) γ} {a : α}
namespace ProbabilityTheory
namespace Kernel
/-- This is an auxiliary lemma for `measurable_kernel_prodMk_left`. -/
theorem measurable_kernel_prodMk_left_of_finite {t : Set (α × β)} (ht : MeasurableSet t)
(hκs : ∀ a, IsFiniteMeasure (κ a)) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by
-- `t` is a measurable set in the product `α × β`: we use that the product σ-algebra is generated
-- by boxes to prove the result by induction.
induction t, ht
using MeasurableSpace.induction_on_inter generateFrom_prod.symm isPiSystem_prod with
| empty => simp only [preimage_empty, measure_empty, measurable_const]
| basic t ht =>
simp only [Set.mem_image2, Set.mem_setOf_eq] at ht
obtain ⟨t₁, ht₁, t₂, ht₂, rfl⟩ := ht
classical
simp_rw [mk_preimage_prod_right_eq_if]
have h_eq_ite : (fun a => κ a (ite (a ∈ t₁) t₂ ∅)) = fun a => ite (a ∈ t₁) (κ a t₂) 0 := by
ext1 a
split_ifs
exacts [rfl, measure_empty]
rw [h_eq_ite]
exact Measurable.ite ht₁ (Kernel.measurable_coe κ ht₂) measurable_const
| compl t htm iht =>
have h_eq_sdiff : ∀ a, Prod.mk a ⁻¹' tᶜ = Set.univ \ Prod.mk a ⁻¹' t := by
intro a
ext1 b
simp only [mem_compl_iff, mem_preimage, mem_diff, mem_univ, true_and]
simp_rw [h_eq_sdiff]
have : (fun a => κ a (Set.univ \ Prod.mk a ⁻¹' t)) =
fun a => κ a Set.univ - κ a (Prod.mk a ⁻¹' t) := by
ext1 a
rw [← Set.diff_inter_self_eq_diff, Set.inter_univ, measure_diff (Set.subset_univ _)]
· exact (measurable_prodMk_left htm).nullMeasurableSet
· exact measure_ne_top _ _
rw [this]
exact Measurable.sub (Kernel.measurable_coe κ MeasurableSet.univ) iht
| iUnion f h_disj hf_meas hf =>
have (a : α) : κ a (Prod.mk a ⁻¹' ⋃ i, f i) = ∑' i, κ a (Prod.mk a ⁻¹' f i) := by
rw [preimage_iUnion, measure_iUnion]
· exact h_disj.mono fun _ _ ↦ .preimage _
· exact fun i ↦ measurable_prodMk_left (hf_meas i)
simpa only [this] using Measurable.ennreal_tsum hf
theorem measurable_kernel_prodMk_left [IsSFiniteKernel κ] {t : Set (α × β)}
(ht : MeasurableSet t) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by
rw [← Kernel.kernel_sum_seq κ]
have (a : _) : Kernel.sum (Kernel.seq κ) a (Prod.mk a ⁻¹' t) =
∑' n, Kernel.seq κ n a (Prod.mk a ⁻¹' t) :=
Kernel.sum_apply' _ _ (measurable_prodMk_left ht)
simp_rw [this]
refine Measurable.ennreal_tsum fun n => ?_
exact measurable_kernel_prodMk_left_of_finite ht inferInstance
theorem measurable_kernel_prodMk_left' [IsSFiniteKernel η] {s : Set (β × γ)} (hs : MeasurableSet s)
(a : α) : Measurable fun b => η (a, b) (Prod.mk b ⁻¹' s) := by
have (b : _) : Prod.mk b ⁻¹' s = {c | ((a, b), c) ∈ {p : (α × β) × γ | (p.1.2, p.2) ∈ s}} := rfl
simp_rw [this]
refine (measurable_kernel_prodMk_left ?_).comp measurable_prodMk_left
exact (measurable_fst.snd.prodMk measurable_snd) hs
theorem measurable_kernel_prodMk_right [IsSFiniteKernel κ] {s : Set (β × α)}
(hs : MeasurableSet s) : Measurable fun y => κ y ((fun x => (x, y)) ⁻¹' s) :=
measurable_kernel_prodMk_left (measurableSet_swap_iff.mpr hs)
end Kernel
open ProbabilityTheory.Kernel
section Lintegral
variable [IsSFiniteKernel κ] [IsSFiniteKernel η]
/-- Auxiliary lemma for `Measurable.lintegral_kernel_prod_right`. -/
theorem Kernel.measurable_lintegral_indicator_const {t : Set (α × β)} (ht : MeasurableSet t)
(c : ℝ≥0∞) : Measurable fun a => ∫⁻ b, t.indicator (Function.const (α × β) c) (a, b) ∂κ a := by
unfold Function.const
simp_rw [lintegral_indicator_const_comp measurable_prodMk_left ht _]
exact Measurable.const_mul (measurable_kernel_prodMk_left ht) c
/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is measurable when seen as a
map from `α × β` (hypothesis `Measurable (uncurry f)`), the integral `a ↦ ∫⁻ b, f a b ∂(κ a)` is
measurable. -/
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel_prod_right {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun a => ∫⁻ b, f a b ∂κ a := by
let F : ℕ → SimpleFunc (α × β) ℝ≥0∞ := SimpleFunc.eapprox (uncurry f)
have h : ∀ a, ⨆ n, F n a = uncurry f a := SimpleFunc.iSup_eapprox_apply hf
simp only [Prod.forall, uncurry_apply_pair] at h
simp_rw [← h]
have : ∀ a, (∫⁻ b, ⨆ n, F n (a, b) ∂κ a) = ⨆ n, ∫⁻ b, F n (a, b) ∂κ a := by
intro a
rw [lintegral_iSup]
· exact fun n => (F n).measurable.comp measurable_prodMk_left
· exact fun i j hij b => SimpleFunc.monotone_eapprox (uncurry f) hij _
simp_rw [this]
refine .iSup fun n => ?_
refine SimpleFunc.induction
(motive := fun f => Measurable (fun (a : α) => ∫⁻ (b : β), f (a, b) ∂κ a)) ?_ ?_ (F n)
· intro c t ht
simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const,
SimpleFunc.coe_zero, Set.piecewise_eq_indicator]
exact Kernel.measurable_lintegral_indicator_const (κ := κ) ht c
· intro g₁ g₂ _ hm₁ hm₂
simp only [SimpleFunc.coe_add, Pi.add_apply]
have h_add :
(fun a => ∫⁻ b, g₁ (a, b) + g₂ (a, b) ∂κ a) =
(fun a => ∫⁻ b, g₁ (a, b) ∂κ a) + fun a => ∫⁻ b, g₂ (a, b) ∂κ a := by
ext1 a
rw [Pi.add_apply, lintegral_add_left (g₁.measurable.comp' measurable_prodMk_left)]
rw [h_add]
exact Measurable.add hm₁ hm₂
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel_prod_right' {f : α × β → ℝ≥0∞} (hf : Measurable f) :
Measurable fun a => ∫⁻ b, f (a, b) ∂κ a := by fun_prop
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel_prod_right'' {f : β × γ → ℝ≥0∞} (hf : Measurable f) :
Measurable fun x => ∫⁻ y, f (x, y) ∂η (a, x) := by
change
Measurable
((fun x => ∫⁻ y, (fun u : (α × β) × γ => f (u.1.2, u.2)) (x, y) ∂η x) ∘ fun x => (a, x))
-- Porting note: specified `κ`, `f`.
refine (Measurable.lintegral_kernel_prod_right' (κ := η)
(f := (fun u ↦ f (u.fst.snd, u.snd))) ?_).comp measurable_prodMk_left
fun_prop
theorem _root_.Measurable.setLIntegral_kernel_prod_right {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) :
Measurable fun a => ∫⁻ b in s, f a b ∂κ a := by
simp_rw [← lintegral_restrict κ hs]; fun_prop
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel_prod_left' {f : β × α → ℝ≥0∞} (hf : Measurable f) :
Measurable fun y => ∫⁻ x, f (x, y) ∂κ y := by fun_prop
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel_prod_left {f : β → α → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun y => ∫⁻ x, f x y ∂κ y := by fun_prop
theorem _root_.Measurable.setLIntegral_kernel_prod_left {f : β → α → ℝ≥0∞}
(hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) :
Measurable fun b => ∫⁻ a in s, f a b ∂κ b := by
simp_rw [← lintegral_restrict κ hs]; fun_prop
@[fun_prop]
theorem _root_.Measurable.lintegral_kernel {κ : Kernel α β} {f : β → ℝ≥0∞} (hf : Measurable f) :
Measurable fun a => ∫⁻ b, f b ∂κ a := by fun_prop
theorem _root_.Measurable.setLIntegral_kernel {f : β → ℝ≥0∞} (hf : Measurable f) {s : Set β}
(hs : MeasurableSet s) : Measurable fun a => ∫⁻ b in s, f b ∂κ a :=
Measurable.setLIntegral_kernel_prod_right (by fun_prop) hs
end Lintegral
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Basic.lean | import Mathlib.Probability.Kernel.Defs
/-!
# Basic kernels
This file contains basic results about kernels in general and definitions of some particular
kernels.
## Main definitions
* `ProbabilityTheory.Kernel.deterministic (f : α → β) (hf : Measurable f)`:
kernel `a ↦ Measure.dirac (f a)`.
* `ProbabilityTheory.Kernel.id`: the identity kernel, deterministic kernel for
the identity function.
* `ProbabilityTheory.Kernel.copy α`: the deterministic kernel that maps `x : α` to
the Dirac measure at `(x, x) : α × α`.
* `ProbabilityTheory.Kernel.discard α`: the Markov kernel to the type `Unit`.
* `ProbabilityTheory.Kernel.swap α β`: the deterministic kernel that maps `(x, y)` to
the Dirac measure at `(y, x)`.
* `ProbabilityTheory.Kernel.const α (μβ : measure β)`: constant kernel `a ↦ μβ`.
* `ProbabilityTheory.Kernel.restrict κ (hs : MeasurableSet s)`: kernel for which the image of
`a : α` is `(κ a).restrict s`.
Integral: `∫⁻ b, f b ∂(κ.restrict hs a) = ∫⁻ b in s, f b ∂(κ a)`
* `ProbabilityTheory.Kernel.comapRight`: Kernel with value `(κ a).comap f`,
for a measurable embedding `f`. That is, for a measurable set `t : Set β`,
`ProbabilityTheory.Kernel.comapRight κ hf a t = κ a (f '' t)`
* `ProbabilityTheory.Kernel.piecewise (hs : MeasurableSet s) κ η`: the kernel equal to `κ`
on the measurable set `s` and to `η` on its complement.
## Main statements
-/
assert_not_exists MeasureTheory.integral
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {κ : Kernel α β}
namespace Kernel
section Deterministic
/-- Kernel which to `a` associates the dirac measure at `f a`. This is a Markov kernel. -/
noncomputable def deterministic (f : α → β) (hf : Measurable f) : Kernel α β where
toFun a := Measure.dirac (f a)
measurable' := by
refine Measure.measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [Measure.dirac_apply' _ hs]
exact measurable_one.indicator (hf hs)
theorem deterministic_apply {f : α → β} (hf : Measurable f) (a : α) :
deterministic f hf a = Measure.dirac (f a) :=
rfl
theorem deterministic_apply' {f : α → β} (hf : Measurable f) (a : α) {s : Set β}
(hs : MeasurableSet s) : deterministic f hf a s = s.indicator (fun _ => 1) (f a) := by
rw [deterministic]
change Measure.dirac (f a) s = s.indicator 1 (f a)
simp_rw [Measure.dirac_apply' _ hs]
/-- Because of the measurability field in `Kernel.deterministic`, `rw [h]` will not rewrite
`deterministic f hf` to `deterministic g ⋯`. Instead one can do `rw [deterministic_congr h]`. -/
theorem deterministic_congr {f g : α → β} {hf : Measurable f} (h : f = g) :
deterministic f hf = deterministic g (h ▸ hf) := by
grind
instance isMarkovKernel_deterministic {f : α → β} (hf : Measurable f) :
IsMarkovKernel (deterministic f hf) :=
⟨fun a => by rw [deterministic_apply hf]; infer_instance⟩
theorem lintegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
(hf : Measurable f) : ∫⁻ x, f x ∂deterministic g hg a = f (g a) := by
rw [deterministic_apply, lintegral_dirac' _ hf]
@[simp]
theorem lintegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] : ∫⁻ x, f x ∂deterministic g hg a = f (g a) := by
rw [deterministic_apply, lintegral_dirac (g a) f]
theorem setLIntegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
(hf : Measurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] :
∫⁻ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [deterministic_apply, setLIntegral_dirac' hf hs]
@[simp]
theorem setLIntegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] (s : Set β) [Decidable (g a ∈ s)] :
∫⁻ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [deterministic_apply, setLIntegral_dirac f s]
end Deterministic
section Id
/-- The identity kernel, that maps `x : α` to the Dirac measure at `x`. -/
protected noncomputable
def id : Kernel α α := Kernel.deterministic id measurable_id
instance : IsMarkovKernel (Kernel.id : Kernel α α) := by rw [Kernel.id]; infer_instance
lemma id_apply (a : α) : Kernel.id a = Measure.dirac a := by
rw [Kernel.id, deterministic_apply, id_def]
lemma lintegral_id' {f : α → ℝ≥0∞} (hf : Measurable f) (a : α) :
∫⁻ a, f a ∂(@Kernel.id α mα a) = f a := by
rw [id_apply, lintegral_dirac' _ hf]
lemma lintegral_id [MeasurableSingletonClass α] {f : α → ℝ≥0∞} (a : α) :
∫⁻ a, f a ∂(@Kernel.id α mα a) = f a := by
rw [id_apply, lintegral_dirac]
end Id
section Copy
/-- The deterministic kernel that maps `x : α` to the Dirac measure at `(x, x) : α × α`. -/
noncomputable
def copy (α : Type*) [MeasurableSpace α] : Kernel α (α × α) :=
Kernel.deterministic (fun x ↦ (x, x)) (measurable_id.prod measurable_id)
instance : IsMarkovKernel (copy α) := by rw [copy]; infer_instance
lemma copy_apply (a : α) : copy α a = Measure.dirac (a, a) := by simp [copy, deterministic_apply]
end Copy
section Discard
/-- The Markov kernel to the `Unit` type. -/
noncomputable
def discard (α : Type*) [MeasurableSpace α] : Kernel α Unit :=
Kernel.deterministic (fun _ ↦ ()) measurable_const
instance : IsMarkovKernel (discard α) := by rw [discard]; infer_instance
@[simp]
lemma discard_apply (a : α) : discard α a = Measure.dirac () := deterministic_apply _ _
end Discard
section Swap
/-- The deterministic kernel that maps `(x, y)` to the Dirac measure at `(y, x)`. -/
noncomputable
def swap (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] : Kernel (α × β) (β × α) :=
Kernel.deterministic Prod.swap measurable_swap
instance : IsMarkovKernel (swap α β) := by rw [swap]; infer_instance
/-- See `swap_apply'` for a fully applied version of this lemma. -/
lemma swap_apply (ab : α × β) : swap α β ab = Measure.dirac ab.swap := by
rw [swap, deterministic_apply]
/-- See `swap_apply` for a partially applied version of this lemma. -/
lemma swap_apply' (ab : α × β) {s : Set (β × α)} (hs : MeasurableSet s) :
swap α β ab s = s.indicator 1 ab.swap := by
rw [swap_apply, Measure.dirac_apply' _ hs]
end Swap
section Const
/-- Constant kernel, which always returns the same measure. -/
def const (α : Type*) {β : Type*} [MeasurableSpace α] {_ : MeasurableSpace β} (μβ : Measure β) :
Kernel α β where
toFun _ := μβ
measurable' := measurable_const
@[simp]
theorem const_apply (μβ : Measure β) (a : α) : const α μβ a = μβ :=
rfl
@[simp]
lemma const_zero : const α (0 : Measure β) = 0 := by
ext x s _; simp [const_apply]
lemma const_add (β : Type*) [MeasurableSpace β] (μ ν : Measure α) :
const β (μ + ν) = const β μ + const β ν := by ext; simp
lemma sum_const [Countable ι] (μ : ι → Measure β) :
Kernel.sum (fun n ↦ const α (μ n)) = const α (Measure.sum μ) := rfl
instance const.instIsFiniteKernel {μβ : Measure β} [IsFiniteMeasure μβ] :
IsFiniteKernel (const α μβ) :=
⟨⟨μβ Set.univ, measure_lt_top _ _, fun _ => le_rfl⟩⟩
instance const.instIsSFiniteKernel {μβ : Measure β} [SFinite μβ] :
IsSFiniteKernel (const α μβ) :=
⟨fun n ↦ const α (sfiniteSeq μβ n), fun n ↦ inferInstance, by rw [sum_const, sum_sfiniteSeq]⟩
instance const.instIsMarkovKernel {μβ : Measure β} [hμβ : IsProbabilityMeasure μβ] :
IsMarkovKernel (const α μβ) :=
⟨fun _ => hμβ⟩
instance const.instIsZeroOrMarkovKernel {μβ : Measure β} [hμβ : IsZeroOrProbabilityMeasure μβ] :
IsZeroOrMarkovKernel (const α μβ) := by
rcases eq_zero_or_isProbabilityMeasure μβ with rfl | h
· simp only [const_zero]
infer_instance
· infer_instance
lemma isSFiniteKernel_const [Nonempty α] {μβ : Measure β} :
IsSFiniteKernel (const α μβ) ↔ SFinite μβ :=
⟨fun h ↦ h.sFinite (Classical.arbitrary α), fun _ ↦ inferInstance⟩
instance [Nonempty β] : Nonempty {κ : Kernel α β // IsMarkovKernel κ} :=
nonempty_subtype.2 ⟨Kernel.const _ (Measure.dirac Classical.ofNonempty), inferInstance⟩
@[simp]
theorem lintegral_const {f : β → ℝ≥0∞} {μ : Measure β} {a : α} :
∫⁻ x, f x ∂const α μ a = ∫⁻ x, f x ∂μ := by rw [const_apply]
@[simp]
theorem setLIntegral_const {f : β → ℝ≥0∞} {μ : Measure β} {a : α} {s : Set β} :
∫⁻ x in s, f x ∂const α μ a = ∫⁻ x in s, f x ∂μ := by rw [const_apply]
lemma discard_eq_const : discard α = const α (Measure.dirac ()) := rfl
end Const
/-- In a countable space with measurable singletons, every function `α → MeasureTheory.Measure β`
defines a kernel. -/
def ofFunOfCountable [MeasurableSpace α] {_ : MeasurableSpace β} [Countable α]
[MeasurableSingletonClass α] (f : α → Measure β) : Kernel α β where
toFun := f
measurable' := measurable_of_countable f
section Restrict
variable {s t : Set β}
/-- Kernel given by the restriction of the measures in the image of a kernel to a set. -/
protected noncomputable def restrict (κ : Kernel α β) (hs : MeasurableSet s) : Kernel α β where
toFun a := (κ a).restrict s
measurable' := by
refine Measure.measurable_of_measurable_coe _ fun t ht => ?_
simp_rw [Measure.restrict_apply ht]
exact Kernel.measurable_coe κ (ht.inter hs)
theorem restrict_apply (κ : Kernel α β) (hs : MeasurableSet s) (a : α) :
κ.restrict hs a = (κ a).restrict s :=
rfl
theorem restrict_apply' (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (ht : MeasurableSet t) :
κ.restrict hs a t = (κ a) (t ∩ s) := by
rw [restrict_apply κ hs a, Measure.restrict_apply ht]
@[simp]
theorem restrict_univ : κ.restrict MeasurableSet.univ = κ := by
ext1 a
rw [Kernel.restrict_apply, Measure.restrict_univ]
@[simp]
theorem lintegral_restrict (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (f : β → ℝ≥0∞) :
∫⁻ b, f b ∂κ.restrict hs a = ∫⁻ b in s, f b ∂κ a := by rw [restrict_apply]
@[simp]
theorem setLIntegral_restrict (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (f : β → ℝ≥0∞)
(t : Set β) : ∫⁻ b in t, f b ∂κ.restrict hs a = ∫⁻ b in t ∩ s, f b ∂κ a := by
rw [restrict_apply, Measure.restrict_restrict' hs]
instance IsFiniteKernel.restrict (κ : Kernel α β) [IsFiniteKernel κ] (hs : MeasurableSet s) :
IsFiniteKernel (κ.restrict hs) := by
refine ⟨⟨κ.bound, κ.bound_lt_top, fun a => ?_⟩⟩
rw [restrict_apply' κ hs a MeasurableSet.univ]
exact measure_le_bound κ a _
instance IsSFiniteKernel.restrict (κ : Kernel α β) [IsSFiniteKernel κ] (hs : MeasurableSet s) :
IsSFiniteKernel (κ.restrict hs) := by
refine ⟨⟨fun n => Kernel.restrict (seq κ n) hs, inferInstance, ?_⟩⟩
ext1 a
simp_rw [sum_apply, restrict_apply, ← Measure.restrict_sum _ hs, ← sum_apply, kernel_sum_seq]
end Restrict
section ComapRight
variable {γ : Type*} {mγ : MeasurableSpace γ} {f : γ → β}
/-- Kernel with value `(κ a).comap f`, for a measurable embedding `f`. That is, for a measurable set
`t : Set β`, `ProbabilityTheory.Kernel.comapRight κ hf a t = κ a (f '' t)`. -/
noncomputable def comapRight (κ : Kernel α β) (hf : MeasurableEmbedding f) : Kernel α γ where
toFun a := (κ a).comap f
measurable' := by
refine Measure.measurable_measure.mpr fun t ht => ?_
have : (fun a => Measure.comap f (κ a) t) = fun a => κ a (f '' t) := by
ext1 a
rw [Measure.comap_apply _ hf.injective _ _ ht]
exact fun s' hs' ↦ hf.measurableSet_image.mpr hs'
rw [this]
exact Kernel.measurable_coe _ (hf.measurableSet_image.mpr ht)
theorem comapRight_apply (κ : Kernel α β) (hf : MeasurableEmbedding f) (a : α) :
comapRight κ hf a = Measure.comap f (κ a) :=
rfl
theorem comapRight_apply' (κ : Kernel α β) (hf : MeasurableEmbedding f) (a : α) {t : Set γ}
(ht : MeasurableSet t) : comapRight κ hf a t = κ a (f '' t) := by
rw [comapRight_apply,
Measure.comap_apply _ hf.injective (fun s => hf.measurableSet_image.mpr) _ ht]
@[simp]
lemma comapRight_id (κ : Kernel α β) : comapRight κ MeasurableEmbedding.id = κ := by
ext _ _ hs; rw [comapRight_apply' _ _ _ hs]; simp
theorem IsMarkovKernel.comapRight (κ : Kernel α β) (hf : MeasurableEmbedding f)
(hκ : ∀ a, κ a (Set.range f) = 1) : IsMarkovKernel (comapRight κ hf) := by
refine ⟨fun a => ⟨?_⟩⟩
rw [comapRight_apply' κ hf a MeasurableSet.univ]
simp only [Set.image_univ]
exact hκ a
instance IsFiniteKernel.comapRight (κ : Kernel α β) [IsFiniteKernel κ]
(hf : MeasurableEmbedding f) : IsFiniteKernel (comapRight κ hf) := by
refine ⟨⟨κ.bound, κ.bound_lt_top, fun a => ?_⟩⟩
rw [comapRight_apply' κ hf a .univ]
exact measure_le_bound κ a _
protected instance IsSFiniteKernel.comapRight (κ : Kernel α β) [IsSFiniteKernel κ]
(hf : MeasurableEmbedding f) : IsSFiniteKernel (comapRight κ hf) := by
refine ⟨⟨fun n => comapRight (seq κ n) hf, inferInstance, ?_⟩⟩
ext1 a
rw [sum_apply]
simp_rw [comapRight_apply _ hf]
have :
(Measure.sum fun n => Measure.comap f (seq κ n a)) =
Measure.comap f (Measure.sum fun n => seq κ n a) := by
ext1 t ht
rw [Measure.comap_apply _ hf.injective (fun s' => hf.measurableSet_image.mpr) _ ht,
Measure.sum_apply _ ht, Measure.sum_apply _ (hf.measurableSet_image.mpr ht)]
congr with n : 1
rw [Measure.comap_apply _ hf.injective (fun s' => hf.measurableSet_image.mpr) _ ht]
rw [this, measure_sum_seq]
end ComapRight
section Piecewise
variable {η : Kernel α β} {s : Set α} {hs : MeasurableSet s} [DecidablePred (· ∈ s)]
/-- `ProbabilityTheory.Kernel.piecewise hs κ η` is the kernel equal to `κ` on the measurable set `s`
and to `η` on its complement. -/
def piecewise (hs : MeasurableSet s) (κ η : Kernel α β) : Kernel α β where
toFun a := if a ∈ s then κ a else η a
measurable' := κ.measurable.piecewise hs η.measurable
theorem piecewise_apply (a : α) : piecewise hs κ η a = if a ∈ s then κ a else η a :=
rfl
theorem piecewise_apply' (a : α) (t : Set β) :
piecewise hs κ η a t = if a ∈ s then κ a t else η a t := by
rw [piecewise_apply]; split_ifs <;> rfl
instance IsMarkovKernel.piecewise [IsMarkovKernel κ] [IsMarkovKernel η] :
IsMarkovKernel (piecewise hs κ η) := by
refine ⟨fun a => ⟨?_⟩⟩
rw [piecewise_apply', measure_univ, measure_univ, ite_self]
instance IsFiniteKernel.piecewise [IsFiniteKernel κ] [IsFiniteKernel η] :
IsFiniteKernel (piecewise hs κ η) := by
refine ⟨⟨max κ.bound η.bound, max_lt κ.bound_lt_top η.bound_lt_top, fun a => ?_⟩⟩
rw [piecewise_apply']
exact (ite_le_sup _ _ _).trans (sup_le_sup (measure_le_bound _ _ _) (measure_le_bound _ _ _))
protected instance IsSFiniteKernel.piecewise [IsSFiniteKernel κ] [IsSFiniteKernel η] :
IsSFiniteKernel (piecewise hs κ η) := by
refine ⟨⟨fun n => piecewise hs (seq κ n) (seq η n), inferInstance, ?_⟩⟩
ext1 a
simp_rw [sum_apply, Kernel.piecewise_apply]
split_ifs <;> exact (measure_sum_seq _ a).symm
theorem lintegral_piecewise (a : α) (g : β → ℝ≥0∞) :
∫⁻ b, g b ∂piecewise hs κ η a = if a ∈ s then ∫⁻ b, g b ∂κ a else ∫⁻ b, g b ∂η a := by
simp_rw [piecewise_apply]; split_ifs <;> rfl
theorem setLIntegral_piecewise (a : α) (g : β → ℝ≥0∞) (t : Set β) :
∫⁻ b in t, g b ∂piecewise hs κ η a =
if a ∈ s then ∫⁻ b in t, g b ∂κ a else ∫⁻ b in t, g b ∂η a := by
simp_rw [piecewise_apply]; split_ifs <;> rfl
end Piecewise
lemma exists_ae_eq_isMarkovKernel {μ : Measure α}
(h : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a)) (h' : μ ≠ 0) :
∃ (η : Kernel α β), (κ =ᵐ[μ] η) ∧ IsMarkovKernel η := by
classical
obtain ⟨s, s_meas, μs, hs⟩ : ∃ s, MeasurableSet s ∧ μ s = 0
∧ ∀ a ∉ s, IsProbabilityMeasure (κ a) := by
refine ⟨toMeasurable μ {a | ¬ IsProbabilityMeasure (κ a)}, measurableSet_toMeasurable _ _,
by simpa [measure_toMeasurable] using h, ?_⟩
intro a ha
contrapose! ha
exact subset_toMeasurable _ _ ha
obtain ⟨a, ha⟩ : sᶜ.Nonempty := by
contrapose! h'; simpa [μs, h'] using measure_univ_le_add_compl s (μ := μ)
refine ⟨Kernel.piecewise s_meas (Kernel.const _ (κ a)) κ, ?_, ?_⟩
· filter_upwards [measure_eq_zero_iff_ae_notMem.1 μs] with b hb
simp [hb, piecewise]
· refine ⟨fun b ↦ ?_⟩
by_cases hb : b ∈ s
· simpa [hb, piecewise] using hs _ ha
· simpa [hb, piecewise] using hs _ hb
section Bool
variable {μ ν : Measure α}
/-- The kernel from `Bool` that sends `false` to `μ` and `true` to `ν`. -/
def boolKernel (μ ν : Measure α) : Kernel Bool α where
toFun := fun b ↦ if b then ν else μ
measurable' := .of_discrete
lemma boolKernel_false : boolKernel μ ν false = μ := rfl
lemma boolKernel_true : boolKernel μ ν true = ν := rfl
@[simp] lemma boolKernel_apply (b : Bool) : boolKernel μ ν b = if b then ν else μ := rfl
instance [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteKernel (boolKernel μ ν) :=
⟨max (μ .univ) (ν .univ), max_lt (measure_lt_top _ _) (measure_lt_top _ _),
fun b ↦ by cases b <;> simp⟩
instance [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : IsMarkovKernel (boolKernel μ ν) where
isProbabilityMeasure b := by
cases b
<;> simp only [boolKernel_apply, Bool.false_eq_true, ↓reduceIte]
<;> infer_instance
instance [SFinite μ] [SFinite ν] : IsSFiniteKernel (boolKernel μ ν) where
tsum_finite := by
refine ⟨fun n ↦ boolKernel (sfiniteSeq μ n) (sfiniteSeq ν n), fun n ↦ inferInstance, ?_⟩
ext b
rw [Kernel.sum_apply]
cases b <;> simp [sum_sfiniteSeq]
lemma eq_boolKernel (κ : Kernel Bool α) : κ = boolKernel (κ false) (κ true) := by
ext (_ | _) <;> simp
end Bool
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/RadonNikodym.lean | import Mathlib.Probability.Kernel.Disintegration.Density
import Mathlib.Probability.Kernel.WithDensity
/-!
# Radon-Nikodym derivative and Lebesgue decomposition for kernels
Let `α` and `γ` be two measurable space, where either `α` is countable or `γ` is
countably generated. Let `κ, η : Kernel α γ` be finite kernels.
Then there exists a function `Kernel.rnDeriv κ η : α → γ → ℝ≥0∞` jointly measurable on `α × γ`
and a kernel `Kernel.singularPart κ η : Kernel α γ` such that
* `κ = Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η`,
* for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a`,
* for all `a : α`, `Kernel.singularPart κ η a = 0 ↔ κ a ≪ η a`,
* for all `a : α`, `Kernel.withDensity η (Kernel.rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a`.
Furthermore, the sets `{a | κ a ≪ η a}` and `{a | κ a ⟂ₘ η a}` are measurable.
When `γ` is countably generated, the construction of the derivative starts from `Kernel.density`:
for two finite kernels `κ' : Kernel α (γ × β)` and `η' : Kernel α γ` with `fst κ' ≤ η'`,
the function `density κ' η' : α → γ → Set β → ℝ` is jointly measurable in the first two arguments
and satisfies that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`,
`∫ x in A, density κ' η' a x s ∂(η' a) = (κ' a (A ×ˢ s)).toReal`.
We use that definition for `β = Unit` and `κ' = map κ (fun a ↦ (a, ()))`. We can't choose `η' = η`
in general because we might not have `κ ≤ η`, but if we could, we would get a measurable function
`f` with the property `κ = withDensity η f`, which is the decomposition we want for `κ ≤ η`.
To circumvent that difficulty, we take `η' = κ + η` and thus define `rnDerivAux κ η`.
Finally, `rnDeriv κ η a x` is given by
`ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)`.
Up to some conversions between `ℝ` and `ℝ≥0`, the singular part is
`withDensity (κ + η) (rnDerivAux κ (κ + η) - (1 - rnDerivAux κ (κ + η)) * rnDeriv κ η)`.
The countably generated measurable space assumption is not needed to have a decomposition for
measures, but the additional difficulty with kernels is to obtain joint measurability of the
derivative. This is why we can't simply define `rnDeriv κ η` by `a ↦ (κ a).rnDeriv (ν a)`
everywhere unless `α` is countable (although `rnDeriv κ η` has that value almost everywhere).
See the construction of `Kernel.density` for details on how the countably generated hypothesis
is used.
## Main definitions
* `ProbabilityTheory.Kernel.rnDeriv`: a function `α → γ → ℝ≥0∞` jointly measurable on `α × γ`
* `ProbabilityTheory.Kernel.singularPart`: a `Kernel α γ`
## Main statements
* `ProbabilityTheory.Kernel.mutuallySingular_singularPart`: for all `a : α`,
`Kernel.singularPart κ η a ⟂ₘ η a`
* `ProbabilityTheory.Kernel.rnDeriv_add_singularPart`:
`Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η = κ`
* `ProbabilityTheory.Kernel.measurableSet_absolutelyContinuous` : the set `{a | κ a ≪ η a}`
is Measurable
* `ProbabilityTheory.Kernel.measurableSet_mutuallySingular` : the set `{a | κ a ⟂ₘ η a}`
is Measurable
Uniqueness results: if `κ = η.withDensity f + ξ` for measurable `f` and `ξ` is such that
`ξ a ⟂ₘ η a` for some `a : α` then
* `ProbabilityTheory.Kernel.eq_rnDeriv`: `f a =ᵐ[η a] Kernel.rnDeriv κ η a`
* `ProbabilityTheory.Kernel.eq_singularPart`: `ξ a = Kernel.singularPart κ η a`
## References
Theorem 1.28 in [O. Kallenberg, Random Measures, Theory and Applications][kallenberg2017].
-/
open MeasureTheory Set Filter ENNReal
open scoped NNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {α γ : Type*} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} {κ η : Kernel α γ}
[hαγ : MeasurableSpace.CountableOrCountablyGenerated α γ]
open Classical in
/-- Auxiliary function used to define `ProbabilityTheory.Kernel.rnDeriv` and
`ProbabilityTheory.Kernel.singularPart`.
This has the properties we want for a Radon-Nikodym derivative only if `κ ≪ ν`. The definition of
`rnDeriv κ η` will be built from `rnDerivAux κ (κ + η)`. -/
noncomputable
def rnDerivAux (κ η : Kernel α γ) (a : α) (x : γ) : ℝ :=
if hα : Countable α then ((κ a).rnDeriv (η a) x).toReal
else haveI := hαγ.countableOrCountablyGenerated.resolve_left hα
density (map κ (fun a ↦ (a, ()))) η a x univ
lemma rnDerivAux_nonneg (hκη : κ ≤ η) {a : α} {x : γ} : 0 ≤ rnDerivAux κ η a x := by
rw [rnDerivAux]
split_ifs with hα
· exact ENNReal.toReal_nonneg
· have := hαγ.countableOrCountablyGenerated.resolve_left hα
exact density_nonneg ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _
lemma rnDerivAux_le_one [IsFiniteKernel η] (hκη : κ ≤ η) {a : α} :
rnDerivAux κ η a ≤ᵐ[η a] 1 := by
filter_upwards [Measure.rnDeriv_le_one_of_le (hκη a)] with x hx_le_one
simp_rw [rnDerivAux]
split_ifs with hα
· refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_
simp only [Pi.one_apply, ENNReal.ofReal_one]
exact hx_le_one
· have := hαγ.countableOrCountablyGenerated.resolve_left hα
exact density_le_one ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _
@[fun_prop]
lemma measurable_rnDerivAux (κ η : Kernel α γ) :
Measurable (fun p : α × γ ↦ Kernel.rnDerivAux κ η p.1 p.2) := by
simp_rw [rnDerivAux]
split_ifs with hα
· refine Measurable.ennreal_toReal <| measurable_from_prod_countable_right'
(fun a ↦ Measure.measurable_rnDeriv (κ a) (η a)) fun a a' c ha'_mem_a ↦ ?_
have h_eq : ∀ κ : Kernel α γ, κ a' = κ a := fun κ ↦ by
ext s hs
exact mem_of_mem_measurableAtom ha'_mem_a
(Kernel.measurable_coe κ hs (measurableSet_singleton (κ a s))) rfl
rw [h_eq κ, h_eq η]
· have := hαγ.countableOrCountablyGenerated.resolve_left hα
exact measurable_density _ η MeasurableSet.univ
@[fun_prop]
lemma measurable_rnDerivAux_right (κ η : Kernel α γ) (a : α) :
Measurable (fun x : γ ↦ rnDerivAux κ η a x) := by fun_prop
lemma setLIntegral_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η]
(a : α) {s : Set γ} (hs : MeasurableSet s) :
∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a = κ a s := by
have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le
simp_rw [rnDerivAux]
split_ifs with hα
· have h_ac : κ a ≪ (κ + η) a := Measure.absolutelyContinuous_of_le (h_le a)
rw [← Measure.setLIntegral_rnDeriv h_ac]
refine setLIntegral_congr_fun_ae hs ?_
filter_upwards [Measure.rnDeriv_lt_top (κ a) ((κ + η) a)] with x hx_lt _
rw [ENNReal.ofReal_toReal hx_lt.ne]
· have := hαγ.countableOrCountablyGenerated.resolve_left hα
rw [setLIntegral_density ((fst_map_id_prod _ measurable_const).trans_le h_le) _
MeasurableSet.univ hs, map_apply' _ (by fun_prop) _ (hs.prod MeasurableSet.univ)]
congr 1 with x
simp
lemma withDensity_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ := by
ext a s hs
rw [Kernel.withDensity_apply']
swap; · fun_prop
simp_rw [ofNNReal_toNNReal]
exact setLIntegral_rnDerivAux κ η a hs
lemma withDensity_one_sub_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) = η := by
have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le
suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x))
+ withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x))
= κ + η by
ext a s
have h : (withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x))
+ withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x))) a s
= κ a s + η a s := by
rw [this]
simp
simp only [coe_add, Pi.add_apply, Measure.coe_add] at h
rwa [withDensity_rnDerivAux, add_comm, ENNReal.add_right_inj (measure_ne_top _ _)] at h
simp_rw [ofNNReal_toNNReal, ENNReal.ofReal_sub _ (rnDerivAux_nonneg h_le), ENNReal.ofReal_one]
rw [withDensity_sub_add_cancel]
· rw [withDensity_one']
· exact measurable_const
· fun_prop
· intro a
filter_upwards [rnDerivAux_le_one h_le] with x hx
simp only [ENNReal.ofReal_le_one]
exact hx
/-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of
`κ` and `η`. -/
def mutuallySingularSet (κ η : Kernel α γ) : Set (α × γ) := {p | 1 ≤ rnDerivAux κ (κ + η) p.1 p.2}
/-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of
`κ` and `η`. That is,
* `withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0`,
* `singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0`.
-/
def mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : Set γ :=
{x | 1 ≤ rnDerivAux κ (κ + η) a x}
lemma mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) :
x ∈ mutuallySingularSetSlice κ η a ↔ 1 ≤ rnDerivAux κ (κ + η) a x := by
rw [mutuallySingularSetSlice, mem_setOf]
lemma notMem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) :
x ∉ mutuallySingularSetSlice κ η a ↔ rnDerivAux κ (κ + η) a x < 1 := by
simp [mutuallySingularSetSlice]
@[deprecated (since := "2025-05-23")]
alias not_mem_mutuallySingularSetSlice := notMem_mutuallySingularSetSlice
lemma measurableSet_mutuallySingularSet (κ η : Kernel α γ) :
MeasurableSet (mutuallySingularSet κ η) :=
measurable_rnDerivAux κ (κ + η) measurableSet_Ici
lemma measurableSet_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) :
MeasurableSet (mutuallySingularSetSlice κ η a) :=
measurable_prodMk_left (measurableSet_mutuallySingularSet κ η)
lemma measure_mutuallySingularSetSlice (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η]
(a : α) :
η a (mutuallySingularSetSlice κ η a) = 0 := by
suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal
(1 - rnDerivAux κ (κ + η) a x)) a {x | 1 ≤ rnDerivAux κ (κ + η) a x} = 0 by
rwa [withDensity_one_sub_rnDerivAux κ η] at this
simp_rw [ofNNReal_toNNReal]
rw [Kernel.withDensity_apply', lintegral_eq_zero_iff, EventuallyEq, ae_restrict_iff]
rotate_left
· exact (measurableSet_singleton 0).preimage (by fun_prop)
· fun_prop
· fun_prop
refine ae_of_all _ (fun x hx ↦ ?_)
simp only [mem_setOf_eq] at hx
simp [hx]
/-- Radon-Nikodym derivative of the kernel `κ` with respect to the kernel `η`. -/
noncomputable
irreducible_def rnDeriv (κ η : Kernel α γ) (a : α) (x : γ) : ℝ≥0∞ :=
ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)
lemma rnDeriv_def' (κ η : Kernel α γ) :
rnDeriv κ η = fun a x ↦ ENNReal.ofReal (rnDerivAux κ (κ + η) a x)
/ ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x) := by ext; rw [rnDeriv_def]
@[fun_prop]
lemma measurable_rnDeriv (κ η : Kernel α γ) :
Measurable (fun p : α × γ ↦ rnDeriv κ η p.1 p.2) := by
simp_rw [rnDeriv_def]
exact (measurable_rnDerivAux κ _).ennreal_ofReal.div
(measurable_const.sub (measurable_rnDerivAux κ _)).ennreal_ofReal
@[fun_prop]
lemma measurable_rnDeriv_right (κ η : Kernel α γ) (a : α) :
Measurable (fun x : γ ↦ rnDeriv κ η a x) := by fun_prop
lemma rnDeriv_eq_top_iff (κ η : Kernel α γ) (a : α) (x : γ) :
rnDeriv κ η a x = ∞ ↔ (a, x) ∈ mutuallySingularSet κ η := by
simp only [rnDeriv, ENNReal.div_eq_top, ne_eq, ENNReal.ofReal_eq_zero, not_le,
tsub_le_iff_right, zero_add, ENNReal.ofReal_ne_top, not_false_eq_true, and_true, or_false,
mutuallySingularSet, mem_setOf_eq, and_iff_right_iff_imp]
exact fun h ↦ zero_lt_one.trans_le h
lemma rnDeriv_eq_top_iff' (κ η : Kernel α γ) (a : α) (x : γ) :
rnDeriv κ η a x = ∞ ↔ x ∈ mutuallySingularSetSlice κ η a := by
rw [rnDeriv_eq_top_iff, mutuallySingularSet, mutuallySingularSetSlice, mem_setOf, mem_setOf]
/-- Singular part of the kernel `κ` with respect to the kernel `η`. -/
noncomputable
irreducible_def singularPart (κ η : Kernel α γ) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
Kernel α γ :=
withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)
- Real.toNNReal (1 - rnDerivAux κ (κ + η) a x) * rnDeriv κ η a x)
lemma measurable_singularPart_fun (κ η : Kernel α γ) :
Measurable (fun p : α × γ ↦ Real.toNNReal (rnDerivAux κ (κ + η) p.1 p.2)
- Real.toNNReal (1 - rnDerivAux κ (κ + η) p.1 p.2) * rnDeriv κ η p.1 p.2) := by fun_prop
lemma measurable_singularPart_fun_right (κ η : Kernel α γ) (a : α) :
Measurable (fun x : γ ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)
- Real.toNNReal (1 - rnDerivAux κ (κ + η) a x) * rnDeriv κ η a x) := by
change Measurable ((Function.uncurry fun a b ↦
ENNReal.ofReal (rnDerivAux κ (κ + η) a b)
- ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a b) * rnDeriv κ η a b) ∘ (fun b ↦ (a, b)))
exact (measurable_singularPart_fun κ η).comp measurable_prodMk_left
lemma singularPart_compl_mutuallySingularSetSlice (κ η : Kernel α γ) [IsSFiniteKernel κ]
[IsSFiniteKernel η] (a : α) :
singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by
rw [singularPart, Kernel.withDensity_apply', lintegral_eq_zero_iff, EventuallyEq,
ae_restrict_iff]
all_goals simp_rw [ofNNReal_toNNReal]
rotate_left
· exact measurableSet_preimage (measurable_singularPart_fun_right κ η a)
(measurableSet_singleton _)
· exact measurable_singularPart_fun_right κ η a
· exact measurable_singularPart_fun κ η
refine ae_of_all _ (fun x hx ↦ ?_)
simp only [mem_compl_iff, mutuallySingularSetSlice, mem_setOf, not_le] at hx
simp_rw [rnDeriv]
rw [← ENNReal.ofReal_div_of_pos, div_eq_inv_mul, ← ENNReal.ofReal_mul, ← mul_assoc,
mul_inv_cancel₀, one_mul, tsub_self, Pi.zero_apply]
· simp only [ne_eq, sub_eq_zero, hx.ne', not_false_eq_true]
· simp only [sub_nonneg, hx.le]
· simp only [sub_pos, hx]
lemma singularPart_of_subset_compl_mutuallySingularSetSlice [IsSFiniteKernel κ]
[IsFiniteKernel η] {a : α} {s : Set γ} (hs : s ⊆ (mutuallySingularSetSlice κ η a)ᶜ) :
singularPart κ η a s = 0 :=
measure_mono_null hs (singularPart_compl_mutuallySingularSetSlice κ η a)
lemma singularPart_of_subset_mutuallySingularSetSlice [IsFiniteKernel κ]
[IsFiniteKernel η] {a : α} {s : Set γ} (hsm : MeasurableSet s)
(hs : s ⊆ mutuallySingularSetSlice κ η a) :
singularPart κ η a s = κ a s := by
have hs' : ∀ x ∈ s, 1 ≤ rnDerivAux κ (κ + η) a x := fun _ hx ↦ hs hx
rw [singularPart, Kernel.withDensity_apply']
swap; · exact measurable_singularPart_fun κ η
calc
∫⁻ x in s, ↑(Real.toNNReal (rnDerivAux κ (κ + η) a x)) -
↑(Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) * rnDeriv κ η a x
∂(κ + η) a
= ∫⁻ _ in s, 1 ∂(κ + η) a := by
refine setLIntegral_congr_fun_ae hsm ?_
have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le
filter_upwards [rnDerivAux_le_one h_le] with x hx hxs
have h_eq_one : rnDerivAux κ (κ + η) a x = 1 := le_antisymm hx (hs' x hxs)
simp [h_eq_one]
_ = (κ + η) a s := by simp
_ = κ a s := by
suffices η a s = 0 by simp [this]
exact measure_mono_null hs (measure_mutuallySingularSetSlice κ η a)
lemma withDensity_rnDeriv_mutuallySingularSetSlice (κ η : Kernel α γ) [IsFiniteKernel κ]
[IsFiniteKernel η] (a : α) :
withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0 := by
rw [Kernel.withDensity_apply']
· exact setLIntegral_measure_zero _ _ (measure_mutuallySingularSetSlice κ η a)
· exact measurable_rnDeriv κ η
lemma withDensity_rnDeriv_of_subset_mutuallySingularSetSlice [IsFiniteKernel κ]
[IsFiniteKernel η] {a : α} {s : Set γ}
(hs : s ⊆ mutuallySingularSetSlice κ η a) :
withDensity η (rnDeriv κ η) a s = 0 :=
measure_mono_null hs (withDensity_rnDeriv_mutuallySingularSetSlice κ η a)
lemma withDensity_rnDeriv_of_subset_compl_mutuallySingularSetSlice
[IsFiniteKernel κ] [IsFiniteKernel η] {a : α} {s : Set γ} (hsm : MeasurableSet s)
(hs : s ⊆ (mutuallySingularSetSlice κ η a)ᶜ) :
withDensity η (rnDeriv κ η) a s = κ a s := by
have : withDensity η (rnDeriv κ η)
= withDensity (withDensity (κ + η)
(fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x))) (rnDeriv κ η) := by
rw [rnDeriv_def']
congr
exact (withDensity_one_sub_rnDerivAux κ η).symm
rw [this, ← withDensity_mul, Kernel.withDensity_apply']
rotate_left
· fun_prop
· fun_prop
· exact measurable_rnDeriv _ _
simp_rw [rnDeriv]
have hs' : ∀ x ∈ s, rnDerivAux κ (κ + η) a x < 1 := by
simp_rw [← notMem_mutuallySingularSetSlice]
exact fun x hx hx_mem ↦ hs hx hx_mem
calc
∫⁻ x in s, ↑(Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) *
(ENNReal.ofReal (rnDerivAux κ (κ + η) a x) /
ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)) ∂(κ + η) a
_ = ∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a := by
refine setLIntegral_congr_fun hsm (fun x hx ↦ ?_)
rw [ofNNReal_toNNReal, ← ENNReal.ofReal_div_of_pos, div_eq_inv_mul, ← ENNReal.ofReal_mul,
← mul_assoc, mul_inv_cancel₀, one_mul]
· rw [ne_eq, sub_eq_zero]
exact (hs' x hx).ne'
· simp [(hs' x hx).le]
· simp [hs' x hx]
_ = κ a s := setLIntegral_rnDerivAux κ η a hsm
/-- The singular part of `κ` with respect to `η` is mutually singular with `η`. -/
lemma mutuallySingular_singularPart (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η]
(a : α) :
singularPart κ η a ⟂ₘ η a := by
symm
exact ⟨mutuallySingularSetSlice κ η a, measurableSet_mutuallySingularSetSlice κ η a,
measure_mutuallySingularSetSlice κ η a, singularPart_compl_mutuallySingularSetSlice κ η a⟩
/-- Lebesgue decomposition of a finite kernel `κ` with respect to another one `η`.
`κ` is the sum of an absolutely continuous part `withDensity η (rnDeriv κ η)` and a singular part
`singularPart κ η`. -/
lemma rnDeriv_add_singularPart (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
withDensity η (rnDeriv κ η) + singularPart κ η = κ := by
ext a s hs
rw [← inter_union_diff s (mutuallySingularSetSlice κ η a)]
simp only [coe_add, Pi.add_apply, Measure.coe_add]
have hm := measurableSet_mutuallySingularSetSlice κ η a
simp only [measure_union (Disjoint.mono inter_subset_right le_rfl disjoint_sdiff_right)
(hs.diff hm)]
rw [singularPart_of_subset_mutuallySingularSetSlice (hs.inter hm) inter_subset_right,
singularPart_of_subset_compl_mutuallySingularSetSlice (diff_subset_iff.mpr (by simp)),
add_zero, withDensity_rnDeriv_of_subset_mutuallySingularSetSlice inter_subset_right,
zero_add, withDensity_rnDeriv_of_subset_compl_mutuallySingularSetSlice (hs.diff hm)
(diff_subset_iff.mpr (by simp)), add_comm]
section EqZeroIff
lemma singularPart_eq_zero_iff_apply_eq_zero (κ η : Kernel α γ) [IsSFiniteKernel κ]
[IsSFiniteKernel η] (a : α) :
singularPart κ η a = 0 ↔ singularPart κ η a (mutuallySingularSetSlice κ η a) = 0 := by
rw [← Measure.measure_univ_eq_zero]
have : univ = (mutuallySingularSetSlice κ η a) ∪ (mutuallySingularSetSlice κ η a)ᶜ := by simp
rw [this, measure_union disjoint_compl_right (measurableSet_mutuallySingularSetSlice κ η a).compl,
singularPart_compl_mutuallySingularSetSlice, add_zero]
lemma withDensity_rnDeriv_eq_zero_iff_apply_eq_zero (κ η : Kernel α γ) [IsFiniteKernel κ]
[IsFiniteKernel η] (a : α) :
withDensity η (rnDeriv κ η) a = 0
↔ withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by
rw [← Measure.measure_univ_eq_zero]
have : univ = (mutuallySingularSetSlice κ η a) ∪ (mutuallySingularSetSlice κ η a)ᶜ := by simp
rw [this, measure_union disjoint_compl_right (measurableSet_mutuallySingularSetSlice κ η a).compl,
withDensity_rnDeriv_mutuallySingularSetSlice, zero_add]
lemma singularPart_eq_zero_iff_absolutelyContinuous (κ η : Kernel α γ)
[IsFiniteKernel κ] [IsFiniteKernel η] (a : α) :
singularPart κ η a = 0 ↔ κ a ≪ η a := by
conv_rhs => rw [← rnDeriv_add_singularPart κ η, coe_add, Pi.add_apply]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [h, add_zero]
exact withDensity_absolutelyContinuous _ _
rw [Measure.AbsolutelyContinuous.add_left_iff] at h
exact Measure.eq_zero_of_absolutelyContinuous_of_mutuallySingular h.2
(mutuallySingular_singularPart _ _ _)
lemma withDensity_rnDeriv_eq_zero_iff_mutuallySingular (κ η : Kernel α γ)
[IsFiniteKernel κ] [IsFiniteKernel η] (a : α) :
withDensity η (rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a := by
conv_rhs => rw [← rnDeriv_add_singularPart κ η, coe_add, Pi.add_apply]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [h, zero_add]
exact mutuallySingular_singularPart _ _ _
rw [Measure.MutuallySingular.add_left_iff] at h
rw [← Measure.MutuallySingular.self_iff]
exact h.1.mono_ac Measure.AbsolutelyContinuous.rfl
(withDensity_absolutelyContinuous (κ := η) (rnDeriv κ η) a)
lemma singularPart_eq_zero_iff_measure_eq_zero (κ η : Kernel α γ)
[IsFiniteKernel κ] [IsFiniteKernel η] (a : α) :
singularPart κ η a = 0 ↔ κ a (mutuallySingularSetSlice κ η a) = 0 := by
have h_eq_add := rnDeriv_add_singularPart κ η
simp_rw [Kernel.ext_iff, Measure.ext_iff] at h_eq_add
specialize h_eq_add a (mutuallySingularSetSlice κ η a)
(measurableSet_mutuallySingularSetSlice κ η a)
simp only [coe_add, Pi.add_apply, Measure.coe_add,
withDensity_rnDeriv_mutuallySingularSetSlice κ η, zero_add] at h_eq_add
rw [← h_eq_add]
exact singularPart_eq_zero_iff_apply_eq_zero κ η a
lemma withDensity_rnDeriv_eq_zero_iff_measure_eq_zero (κ η : Kernel α γ)
[IsFiniteKernel κ] [IsFiniteKernel η] (a : α) :
withDensity η (rnDeriv κ η) a = 0 ↔ κ a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by
have h_eq_add := rnDeriv_add_singularPart κ η
simp_rw [Kernel.ext_iff, Measure.ext_iff] at h_eq_add
specialize h_eq_add a (mutuallySingularSetSlice κ η a)ᶜ
(measurableSet_mutuallySingularSetSlice κ η a).compl
simp only [coe_add, Pi.add_apply, Measure.coe_add,
singularPart_compl_mutuallySingularSetSlice κ η, add_zero] at h_eq_add
rw [← h_eq_add]
exact withDensity_rnDeriv_eq_zero_iff_apply_eq_zero κ η a
end EqZeroIff
/-- The set of points `a : α` such that `κ a ≪ η a` is measurable. -/
@[measurability]
lemma measurableSet_absolutelyContinuous (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
MeasurableSet {a | κ a ≪ η a} := by
simp_rw [← singularPart_eq_zero_iff_absolutelyContinuous,
singularPart_eq_zero_iff_measure_eq_zero]
exact measurable_kernel_prodMk_left (measurableSet_mutuallySingularSet κ η)
(measurableSet_singleton 0)
/-- The set of points `a : α` such that `κ a ⟂ₘ η a` is measurable. -/
@[measurability]
lemma measurableSet_mutuallySingular (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
MeasurableSet {a | κ a ⟂ₘ η a} := by
simp_rw [← withDensity_rnDeriv_eq_zero_iff_mutuallySingular,
withDensity_rnDeriv_eq_zero_iff_measure_eq_zero]
exact measurable_kernel_prodMk_left (measurableSet_mutuallySingularSet κ η).compl
(measurableSet_singleton 0)
@[simp]
lemma singularPart_self (κ : Kernel α γ) [IsFiniteKernel κ] : κ.singularPart κ = 0 := by
ext : 1; rw [zero_apply, singularPart_eq_zero_iff_absolutelyContinuous]
section Unique
variable {ξ : Kernel α γ} {f : α → γ → ℝ≥0∞} [IsFiniteKernel η]
omit hαγ in
lemma eq_rnDeriv_measure (h : κ = η.withDensity f + ξ)
(hf : Measurable (Function.uncurry f)) (a : α) (hξ : ξ a ⟂ₘ η a) :
f a =ᵐ[η a] ∂(κ a)/∂(η a) := by
have : κ a = ξ a + (η a).withDensity (f a) := by
rw [h, coe_add, Pi.add_apply, η.withDensity_apply hf, add_comm]
exact (κ a).eq_rnDeriv₀ (hf.comp measurable_prodMk_left).aemeasurable hξ this
omit hαγ in
lemma eq_singularPart_measure (h : κ = η.withDensity f + ξ)
(hf : Measurable (Function.uncurry f)) (a : α) (hξ : ξ a ⟂ₘ η a) :
ξ a = (κ a).singularPart (η a) := by
have : κ a = ξ a + (η a).withDensity (f a) := by
rw [h, coe_add, Pi.add_apply, η.withDensity_apply hf, add_comm]
exact (κ a).eq_singularPart (hf.comp measurable_prodMk_left) hξ this
variable [IsFiniteKernel κ] {a : α}
lemma rnDeriv_eq_rnDeriv_measure : rnDeriv κ η a =ᵐ[η a] ∂(κ a)/∂(η a) :=
eq_rnDeriv_measure (rnDeriv_add_singularPart κ η).symm (measurable_rnDeriv κ η) a
(mutuallySingular_singularPart κ η a)
lemma singularPart_eq_singularPart_measure : singularPart κ η a = (κ a).singularPart (η a) :=
eq_singularPart_measure (rnDeriv_add_singularPart κ η).symm (measurable_rnDeriv κ η) a
(mutuallySingular_singularPart κ η a)
lemma eq_rnDeriv (h : κ = η.withDensity f + ξ)
(hf : Measurable (Function.uncurry f)) (a : α) (hξ : ξ a ⟂ₘ η a) :
f a =ᵐ[η a] rnDeriv κ η a :=
(eq_rnDeriv_measure h hf a hξ).trans rnDeriv_eq_rnDeriv_measure.symm
lemma eq_singularPart (h : κ = η.withDensity f + ξ)
(hf : Measurable (Function.uncurry f)) (a : α) (hξ : ξ a ⟂ₘ η a) :
ξ a = singularPart κ η a :=
(eq_singularPart_measure h hf a hξ).trans singularPart_eq_singularPart_measure.symm
end Unique
instance [hκ : IsFiniteKernel κ] [IsFiniteKernel η] :
IsFiniteKernel (withDensity η (rnDeriv κ η)) := by
refine ⟨κ.bound, κ.bound_lt_top, fun a ↦ ?_⟩
rw [Kernel.withDensity_apply', setLIntegral_univ]
swap; · exact measurable_rnDeriv κ η
rw [lintegral_congr_ae rnDeriv_eq_rnDeriv_measure]
exact Measure.lintegral_rnDeriv_le.trans (measure_le_bound _ _ _)
instance [hκ : IsFiniteKernel κ] [IsFiniteKernel η] : IsFiniteKernel (singularPart κ η) := by
refine ⟨κ.bound, κ.bound_lt_top, fun a ↦ ?_⟩
have h : withDensity η (rnDeriv κ η) a univ + singularPart κ η a univ = κ a univ := by
conv_rhs => rw [← rnDeriv_add_singularPart κ η]
simp
exact (self_le_add_left _ _).trans (h.le.trans (measure_le_bound _ _ _))
/-- For two kernels `κ, η`, the singular part of `κ a` with respect to `η a` is a measurable
function of `a`. -/
lemma measurable_singularPart (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] :
Measurable (fun a ↦ (κ a).singularPart (η a)) := by
refine Measure.measurable_of_measurable_coe _ (fun s hs ↦ ?_)
simp_rw [← κ.singularPart_eq_singularPart_measure, κ.singularPart_def η]
exact Kernel.measurable_coe _ hs
lemma rnDeriv_self (κ : Kernel α γ) [IsFiniteKernel κ] (a : α) : rnDeriv κ κ a =ᵐ[κ a] 1 :=
(κ.rnDeriv_eq_rnDeriv_measure).trans (κ a).rnDeriv_self
lemma rnDeriv_singularPart (κ ν : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) :
rnDeriv (singularPart κ ν) ν a =ᵐ[ν a] 0 := by
filter_upwards [(singularPart κ ν).rnDeriv_eq_rnDeriv_measure,
(Measure.rnDeriv_eq_zero _ _).mpr (mutuallySingular_singularPart κ ν a)] with x h1 h2
rw [h1, h2]
lemma rnDeriv_lt_top (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} :
∀ᵐ x ∂(η a), rnDeriv κ η a x < ∞ := by
filter_upwards [κ.rnDeriv_eq_rnDeriv_measure, (κ a).rnDeriv_ne_top _]
with x heq htop using heq ▸ htop.lt_top
lemma rnDeriv_ne_top (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} :
∀ᵐ x ∂(η a), rnDeriv κ η a x ≠ ∞ := by
filter_upwards [κ.rnDeriv_lt_top η] with a h using h.ne
lemma rnDeriv_pos [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} (ha : κ a ≪ η a) :
∀ᵐ x ∂(κ a), 0 < rnDeriv κ η a x := by
filter_upwards [ha.ae_le κ.rnDeriv_eq_rnDeriv_measure, Measure.rnDeriv_pos ha]
with x heq hpos using heq ▸ hpos
lemma rnDeriv_toReal_pos [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} (h : κ a ≪ η a) :
∀ᵐ x ∂(κ a), 0 < (rnDeriv κ η a x).toReal := by
filter_upwards [rnDeriv_pos h, h.ae_le (rnDeriv_ne_top κ _)] with x h0 htop
simp_all only [pos_iff_ne_zero, ne_eq, ENNReal.toReal_pos, not_false_eq_true]
lemma rnDeriv_add (κ ν η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel ν] [IsFiniteKernel η]
(a : α) :
rnDeriv (κ + ν) η a =ᵐ[η a] rnDeriv κ η a + rnDeriv ν η a := by
filter_upwards [(κ + ν).rnDeriv_eq_rnDeriv_measure, κ.rnDeriv_eq_rnDeriv_measure,
ν.rnDeriv_eq_rnDeriv_measure, (κ a).rnDeriv_add (ν a) (η a)] with x h1 h2 h3 h4
rw [h1, Pi.add_apply, h2, h3, coe_add, Pi.add_apply, h4, Pi.add_apply]
lemma setLIntegral_rnDeriv_le {κ η : Kernel α γ} [IsFiniteKernel κ] [IsFiniteKernel η]
{a : α} {s : Set γ} (hs : MeasurableSet s) :
∫⁻ c in s, κ.rnDeriv η a c ∂η a ≤ κ a s := by
rw [setLIntegral_congr_fun_ae hs ((κ.rnDeriv_eq_rnDeriv_measure).mono (fun x hx _ ↦ hx)),
← withDensity_apply' _ s]
exact (κ a).withDensity_rnDeriv_le _ _
lemma setLIntegral_rnDeriv {κ η : Kernel α γ} [IsFiniteKernel κ] [IsFiniteKernel η]
{a : α} (h : κ a ≪ η a) {s : Set γ} (hs : MeasurableSet s) :
∫⁻ c in s, κ.rnDeriv η a c ∂η a = κ a s := by
rw [setLIntegral_congr_fun_ae hs ((κ.rnDeriv_eq_rnDeriv_measure).mono (fun x hx _ ↦ hx)),
← withDensity_apply _ hs, (κ a).withDensity_rnDeriv_eq _ h]
lemma lintegral_rnDeriv {κ η : Kernel α γ} [IsFiniteKernel κ] [IsFiniteKernel η]
{a : α} (h : κ a ≪ η a) :
∫⁻ c, κ.rnDeriv η a c ∂η a = κ a univ := by
rw [← setLIntegral_univ, setLIntegral_rnDeriv h MeasurableSet.univ]
lemma withDensity_rnDeriv_le (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) :
η.withDensity (κ.rnDeriv η) a ≤ κ a := by
refine Measure.le_intro (fun s hs _ ↦ ?_)
rw [Kernel.withDensity_apply']
· exact setLIntegral_rnDeriv_le hs
· exact κ.measurable_rnDeriv _
lemma withDensity_rnDeriv_eq [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} (h : κ a ≪ η a) :
η.withDensity (κ.rnDeriv η) a = κ a := by
rw [Kernel.withDensity_apply]
swap; · exact κ.measurable_rnDeriv _
have h_ae := κ.rnDeriv_eq_rnDeriv_measure (η := η) (a := a)
rw [MeasureTheory.withDensity_congr_ae h_ae, (κ a).withDensity_rnDeriv_eq _ h]
lemma rnDeriv_withDensity [IsFiniteKernel κ] {f : α → γ → ℝ≥0∞} [IsFiniteKernel (withDensity κ f)]
(hf : Measurable (Function.uncurry f)) (a : α) :
(κ.withDensity f).rnDeriv κ a =ᵐ[κ a] f a := by
have h_ae := (κ.withDensity f).rnDeriv_eq_rnDeriv_measure (η := κ) (a := a)
have hf' : ∀ a, Measurable (f a) := fun _ ↦ hf.of_uncurry_left
filter_upwards [h_ae, (κ a).rnDeriv_withDensity (hf' a)] with x hx1 hx2
rw [hx1, κ.withDensity_apply hf, hx2]
lemma rnDeriv_eq_one_iff_eq [IsFiniteKernel κ] [IsFiniteKernel η] {a : α}
(h_ac : κ a ≪ η a) :
(∀ᵐ b ∂(η a), κ.rnDeriv η a b = 1) ↔ κ a = η a := by
rw [← Measure.rnDeriv_eq_one_iff_eq h_ac]
refine eventually_congr ?_
filter_upwards [rnDeriv_eq_rnDeriv_measure (κ := κ) (η := η) (a := a)] with c hc
rw [hc, Pi.one_apply]
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/CompProdEqIff.lean | import Mathlib.Probability.Kernel.Composition.AbsolutelyContinuous
/-!
# Condition for two kernels to be equal almost everywhere
We prove that two finite kernels `κ, η : Kernel α β` are `μ`-a.e. equal for a finite measure `μ` iff
the composition-products `μ ⊗ₘ κ` and `μ ⊗ₘ η` are equal.
The result requires `α` to be countable or `β` to be a countably generated measurable space.
## Main statements
* `compProd_withDensity`: `μ ⊗ₘ (κ.withDensity f) = (μ ⊗ₘ κ).withDensity (fun p ↦ f p.1 p.2)`
* `compProd_eq_iff`: `μ ⊗ₘ κ = μ ⊗ₘ η ↔ κ =ᵐ[μ] η`
-/
open ProbabilityTheory MeasureTheory
open scoped ENNReal
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{μ : Measure α} {κ : Kernel α β}
{f : α → β → ℝ≥0∞}
namespace MeasureTheory.Measure
/-- A composition-product of a measure with a kernel defined with `withDensity` is equal to the
`withDensity` of the composition-product. -/
lemma compProd_withDensity [SFinite μ] [IsSFiniteKernel κ] [IsSFiniteKernel (κ.withDensity f)]
(hf : Measurable (Function.uncurry f)) :
μ ⊗ₘ (κ.withDensity f) = (μ ⊗ₘ κ).withDensity (fun p ↦ f p.1 p.2) := by
ext s hs
rw [compProd_apply hs, withDensity_apply _ hs, ← lintegral_indicator hs,
lintegral_compProd]
· congr with a
rw [Kernel.withDensity_apply' _ hf, ← lintegral_indicator (measurable_prodMk_left hs)]
rfl
· exact hf.indicator hs
end MeasureTheory.Measure
namespace ProbabilityTheory.Kernel
variable {η : Kernel α β} [MeasurableSpace.CountableOrCountablyGenerated α β]
lemma ae_eq_of_compProd_eq [IsFiniteMeasure μ] [IsFiniteKernel κ] [IsFiniteKernel η]
(h : μ ⊗ₘ κ = μ ⊗ₘ η) :
κ =ᵐ[μ] η := by
have h_ac : ∀ᵐ a ∂μ, κ a ≪ η a := (Measure.absolutelyContinuous_of_eq h).kernel_of_compProd
have hκ_eq : ∀ᵐ a ∂μ, κ a = η.withDensity (κ.rnDeriv η) a := by
filter_upwards [h_ac] with a ha using (Kernel.withDensity_rnDeriv_eq ha).symm
suffices ∀ᵐ a ∂μ, ∀ᵐ b ∂(η a), κ.rnDeriv η a b = 1 by
filter_upwards [h_ac, this] with a h_ac h using (rnDeriv_eq_one_iff_eq h_ac).mp h
refine Measure.ae_ae_of_ae_compProd (p := fun x ↦ κ.rnDeriv η x.1 x.2 = 1) ?_
refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite (by fun_prop) (by fun_prop) fun s hs _ ↦ ?_
simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply,
Set.univ_inter, one_mul]
calc ∫⁻ x in s, κ.rnDeriv η x.1 x.2 ∂μ ⊗ₘ η
_ = (μ ⊗ₘ κ) s := by
rw [Measure.compProd_congr hκ_eq, Measure.compProd_withDensity, withDensity_apply _ hs]
fun_prop
_ = (μ ⊗ₘ η) s := by rw [h]
/-- Two finite kernels `κ` and `η` are `μ`-a.e. equal iff the composition-products `μ ⊗ₘ κ`
and `μ ⊗ₘ η` are equal. -/
lemma compProd_eq_iff [IsFiniteMeasure μ] [IsFiniteKernel κ] [IsFiniteKernel η] :
μ ⊗ₘ κ = μ ⊗ₘ η ↔ κ =ᵐ[μ] η :=
⟨Kernel.ae_eq_of_compProd_eq, Measure.compProd_congr⟩
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/WithDensity.lean | import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
import Mathlib.Probability.Kernel.MeasurableLIntegral
/-!
# With Density
For an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` which is finite
everywhere, we define `withDensity κ f` as the kernel `a ↦ (κ a).withDensity (f a)`. This is
an s-finite kernel.
## Main definitions
* `ProbabilityTheory.Kernel.withDensity κ (f : α → β → ℝ≥0∞)`:
kernel `a ↦ (κ a).withDensity (f a)`. It is defined if `κ` is s-finite. If `f` is finite
everywhere, then this is also an s-finite kernel. The class of s-finite kernels is the smallest
class of kernels that contains finite kernels and which is stable by `withDensity`.
Integral: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)`
## Main statements
* `ProbabilityTheory.Kernel.lintegral_withDensity`:
`∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)`
-/
open MeasureTheory ProbabilityTheory
open scoped MeasureTheory ENNReal NNReal
namespace ProbabilityTheory.Kernel
variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
variable {κ : Kernel α β} {f : α → β → ℝ≥0∞}
/-- Kernel with image `(κ a).withDensity (f a)` if `Function.uncurry f` is measurable, and
with image 0 otherwise. If `Function.uncurry f` is measurable, it satisfies
`∫⁻ b, g b ∂(withDensity κ f hf a) = ∫⁻ b, f a b * g b ∂(κ a)`. -/
noncomputable def withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) :
Kernel α β :=
@dite _ (Measurable (Function.uncurry f)) (Classical.dec _) (fun hf =>
(⟨fun a => (κ a).withDensity (f a),
by
refine Measure.measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [withDensity_apply _ hs]
exact hf.setLIntegral_kernel_prod_right hs⟩ : Kernel α β)) fun _ => 0
theorem withDensity_of_not_measurable (κ : Kernel α β) [IsSFiniteKernel κ]
(hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf
protected theorem withDensity_apply (κ : Kernel α β) [IsSFiniteKernel κ]
(hf : Measurable (Function.uncurry f)) (a : α) :
withDensity κ f a = (κ a).withDensity (f a) := by
classical
rw [withDensity, dif_pos hf]
rfl
protected theorem withDensity_apply' (κ : Kernel α β) [IsSFiniteKernel κ]
(hf : Measurable (Function.uncurry f)) (a : α) (s : Set β) :
withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by
rw [Kernel.withDensity_apply κ hf, withDensity_apply' _ s]
nonrec lemma withDensity_congr_ae (κ : Kernel α β) [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
(hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g))
(hfg : ∀ a, f a =ᵐ[κ a] g a) :
withDensity κ f = withDensity κ g := by
ext a
rw [Kernel.withDensity_apply _ hf, Kernel.withDensity_apply _ hg, withDensity_congr_ae (hfg a)]
nonrec lemma withDensity_absolutelyContinuous [IsSFiniteKernel κ]
(f : α → β → ℝ≥0∞) (a : α) :
Kernel.withDensity κ f a ≪ κ a := by
by_cases hf : Measurable (Function.uncurry f)
· rw [Kernel.withDensity_apply _ hf]
exact withDensity_absolutelyContinuous _ _
· rw [withDensity_of_not_measurable _ hf]
simp [Measure.AbsolutelyContinuous.zero]
@[simp]
lemma withDensity_one (κ : Kernel α β) [IsSFiniteKernel κ] :
Kernel.withDensity κ 1 = κ := by
ext; rw [Kernel.withDensity_apply _ measurable_const]; simp
@[simp]
lemma withDensity_one' (κ : Kernel α β) [IsSFiniteKernel κ] :
Kernel.withDensity κ (fun _ _ ↦ 1) = κ := Kernel.withDensity_one _
@[simp]
lemma withDensity_zero (κ : Kernel α β) [IsSFiniteKernel κ] :
Kernel.withDensity κ 0 = 0 := by
ext; rw [Kernel.withDensity_apply _ measurable_const]; simp
@[simp]
lemma withDensity_zero' (κ : Kernel α β) [IsSFiniteKernel κ] :
Kernel.withDensity κ (fun _ _ ↦ 0) = 0 := Kernel.withDensity_zero _
theorem lintegral_withDensity (κ : Kernel α β) [IsSFiniteKernel κ]
(hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a := by
rw [Kernel.withDensity_apply _ hf,
lintegral_withDensity_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg]
simp_rw [Pi.mul_apply]
theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0}
(hg : Measurable (Function.uncurry g)) :
∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by
rw [Kernel.withDensity_apply, integral_withDensity_eq_integral_smul]
· fun_prop
· fun_prop
theorem withDensity_add_left (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η]
(f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f := by
by_cases hf : Measurable (Function.uncurry f)
· ext a s
simp only [Kernel.withDensity_apply _ hf, coe_add, Pi.add_apply, withDensity_add_measure,
Measure.add_apply]
· simp_rw [withDensity_of_not_measurable _ hf]
rw [zero_add]
theorem withDensity_kernel_sum [Countable ι] (κ : ι → Kernel α β) (hκ : ∀ i, IsSFiniteKernel (κ i))
(f : α → β → ℝ≥0∞) :
withDensity (Kernel.sum κ) f = Kernel.sum fun i => withDensity (κ i) f := by
by_cases hf : Measurable (Function.uncurry f)
· ext1 a
simp_rw [sum_apply, Kernel.withDensity_apply _ hf, sum_apply,
withDensity_sum (fun n => κ n a) (f a)]
· simp_rw [withDensity_of_not_measurable _ hf]
exact sum_zero.symm
lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
(hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) :
withDensity κ (f + g) = withDensity κ f + withDensity κ g := by
ext a
rw [coe_add, Pi.add_apply, Kernel.withDensity_apply _ hf, Kernel.withDensity_apply _ hg,
Kernel.withDensity_apply, Pi.add_apply, MeasureTheory.withDensity_add_right]
· fun_prop
· exact hf.add hg
lemma withDensity_sub_add_cancel [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞}
(hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g))
(hfg : ∀ a, g a ≤ᵐ[κ a] f a) :
withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f := by
rw [← withDensity_add_right _ hg]
swap; · exact hf.sub hg
refine withDensity_congr_ae κ ((hf.sub hg).add hg) hf (fun a ↦ ?_)
filter_upwards [hfg a] with x hx
rwa [Pi.add_apply, Pi.add_apply, tsub_add_cancel_iff_le]
theorem withDensity_tsum [Countable ι] (κ : Kernel α β) [IsSFiniteKernel κ] {f : ι → α → β → ℝ≥0∞}
(hf : ∀ i, Measurable (Function.uncurry (f i))) :
withDensity κ (∑' n, f n) = Kernel.sum fun n => withDensity κ (f n) := by
have h_sum_a : ∀ a, Summable fun n => f n a := fun a => Pi.summable.mpr fun b => ENNReal.summable
have h_sum : Summable fun n => f n := Pi.summable.mpr h_sum_a
ext a s hs
rw [sum_apply' _ a hs, Kernel.withDensity_apply' κ _ a s]
swap
· have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) := by
ext1 p
simp only [Function.uncurry_def]
rw [tsum_apply h_sum, tsum_apply (h_sum_a _), tsum_apply]
exact Pi.summable.mpr fun p => ENNReal.summable
rw [this]
fun_prop
have : ∫⁻ b in s, (∑' n, f n) a b ∂κ a = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a := by
congr with b
rw [tsum_apply h_sum, tsum_apply (h_sum_a a)]
rw [this, lintegral_tsum fun n => by fun_prop]
congr with n
rw [Kernel.withDensity_apply' _ (hf n) a s]
/-- If a kernel `κ` is finite and a function `f : α → β → ℝ≥0∞` is bounded, then `withDensity κ f`
is finite. -/
theorem isFiniteKernel_withDensity_of_bounded (κ : Kernel α β) [IsFiniteKernel κ] {B : ℝ≥0∞}
(hB_top : B ≠ ∞) (hf_B : ∀ a b, f a b ≤ B) : IsFiniteKernel (withDensity κ f) := by
by_cases hf : Measurable (Function.uncurry f)
· exact ⟨⟨B * κ.bound, ENNReal.mul_lt_top hB_top.lt_top κ.bound_lt_top, fun a => by
rw [Kernel.withDensity_apply' κ hf a Set.univ]
calc
∫⁻ b in Set.univ, f a b ∂κ a ≤ ∫⁻ _ in Set.univ, B ∂κ a := lintegral_mono (hf_B a)
_ = B * κ a Set.univ := by
simp only [Measure.restrict_univ, MeasureTheory.lintegral_const]
_ ≤ B * κ.bound := by grw [measure_le_bound]⟩⟩
· rw [withDensity_of_not_measurable _ hf]
infer_instance
/-- Auxiliary lemma for `IsSFiniteKernel.withDensity`.
If a kernel `κ` is finite, then `withDensity κ f` is s-finite. -/
theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : Kernel α β) [IsFiniteKernel κ]
(hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by
-- We already have that for `f` bounded from above and a `κ` a finite kernel,
-- `withDensity κ f` is finite. We write any function as a countable sum of bounded
-- functions, and decompose an s-finite kernel as a sum of finite kernels. We then use that
-- `withDensity` commutes with sums for both arguments and get a sum of finite kernels.
by_cases hf : Measurable (Function.uncurry f)
swap; · rw [withDensity_of_not_measurable _ hf]; infer_instance
let fs : ℕ → α → β → ℝ≥0∞ := fun n a b => min (f a b) (n + 1) - min (f a b) n
have h_le : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → f a b ≤ n := by
intro a b n hn
have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn
rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this
· refine this.trans (le_of_eq ?_)
rw [ENNReal.ofReal_natCast]
· norm_cast
exact zero_le _
have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 := by
intro a b n hn
suffices min (f a b) (n + 1) = f a b ∧ min (f a b) n = f a b by
simp_rw [fs, this.1, this.2, tsub_self (f a b)]
exact ⟨min_eq_left ((h_le a b n hn).trans (le_add_of_nonneg_right zero_le_one)),
min_eq_left (h_le a b n hn)⟩
have hf_eq_tsum : f = ∑' n, fs n := by
have h_sum_a : ∀ a, Summable fun n => fs n a := by
refine fun a => Pi.summable.mpr fun b => ?_
suffices ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0 from
summable_of_ne_finset_zero this
intro n hn_notMem
rw [Finset.mem_range, not_lt] at hn_notMem
exact h_zero a b n hn_notMem
ext a b : 2
rw [tsum_apply (Pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a),
ENNReal.tsum_eq_liminf_sum_nat]
have h_finset_sum : ∀ n, ∑ i ∈ Finset.range n, fs i a b = min (f a b) n := fun n ↦ by
induction n with
| zero => simp
| succ n hn =>
rw [Finset.sum_range_succ, hn]
simp [fs]
simp_rw [h_finset_sum]
refine (Filter.Tendsto.liminf_eq ?_).symm
refine Filter.Tendsto.congr' ?_ tendsto_const_nhds
rw [Filter.EventuallyEq, Filter.eventually_atTop]
exact ⟨⌈(f a b).toReal⌉₊, fun n hn => (min_eq_left (h_le a b n hn)).symm⟩
rw [hf_eq_tsum, withDensity_tsum _ fun n : ℕ => _]
swap; · fun_prop
refine isSFiniteKernel_sum (hκs := fun n => ?_)
suffices IsFiniteKernel (withDensity κ (fs n)) by infer_instance
refine isFiniteKernel_withDensity_of_bounded _ (ENNReal.coe_ne_top : ↑n + 1 ≠ ∞) fun a b => ?_
-- After https://github.com/leanprover/lean4/pull/2734, we need to do beta reduction before `norm_cast`
beta_reduce
norm_cast
calc
fs n a b ≤ min (f a b) (n + 1) := tsub_le_self
_ ≤ n + 1 := min_le_right _ _
_ = ↑(n + 1) := by norm_cast
/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite,
`withDensity κ f` is s-finite. -/
nonrec theorem IsSFiniteKernel.withDensity (κ : Kernel α β) [IsSFiniteKernel κ]
(hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by
have h_eq_sum : withDensity κ f = Kernel.sum fun i => withDensity (seq κ i) f := by
rw [← withDensity_kernel_sum _ _]
congr
exact (kernel_sum_seq κ).symm
rw [h_eq_sum]
exact isSFiniteKernel_sum (hκs := fun n =>
isSFiniteKernel_withDensity_of_isFiniteKernel (seq κ n) hf_ne_top)
/-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `withDensity κ f` is s-finite. -/
instance (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) :
IsSFiniteKernel (withDensity κ fun a b => f a b) :=
IsSFiniteKernel.withDensity κ fun _ _ => ENNReal.coe_ne_top
nonrec lemma withDensity_mul [IsSFiniteKernel κ] {f : α → β → ℝ≥0} {g : α → β → ℝ≥0∞}
(hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) :
withDensity κ (fun a x ↦ f a x * g a x)
= withDensity (withDensity κ fun a x ↦ f a x) g := by
ext a : 1
rw [Kernel.withDensity_apply]
swap; · fun_prop
change (Measure.withDensity (κ a) ((fun x ↦ (f a x : ℝ≥0∞)) * (fun x ↦ (g a x : ℝ≥0∞)))) =
(withDensity (withDensity κ fun a x ↦ f a x) g) a
rw [withDensity_mul]
· rw [Kernel.withDensity_apply _ hg, Kernel.withDensity_apply]
exact measurable_coe_nnreal_ennreal.comp hf
· fun_prop
· fun_prop
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Proper.lean | import Mathlib.Probability.Kernel.Composition.CompNotation
/-!
# Proper kernels
This file defines properness of measure kernels.
For two σ-algebras `𝓑 ≤ 𝓧`, a `𝓑, 𝓧`-kernel `π : X → Measure X` is proper if
`∫ x, g x * f x ∂(π x₀) = g x₀ * ∫ x, f x ∂(π x₀)` for all `x₀ : X`, `𝓧`-measurable function `f`
and `𝓑`-measurable function `g`.
By the standard machine, this is equivalent to having that, for all `B ∈ 𝓑`, `π` restricted to `B`
is the same as `π` times the indicator of `B`.
This should be thought of as the condition under which one can meaningfully restrict a kernel to an
event.
## TODO
Prove the `integral` versions of the `lintegral` lemmas below
-/
open MeasureTheory ENNReal NNReal Set
open scoped ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {X : Type*} {𝓑 𝓧 : MeasurableSpace X} {π : Kernel[𝓑, 𝓧] X X} {A B : Set X}
{f g : X → ℝ≥0∞} {x₀ : X}
/-- For two σ-algebras `𝓑 ≤ 𝓧` on a space `X`, a `𝓑, 𝓧`-kernel `π : X → Measure X` is proper if
`∫ x, g x * f x ∂(π x₀) = g x₀ * ∫ x, f x ∂(π x₀)` for all `x₀ : X`, `𝓧`-measurable function `f`
and `𝓑`-measurable function `g`.
By the standard machine, this is equivalent to having that, for all `B ∈ 𝓑`, `π` restricted to `B`
is the same as `π` times the indicator of `B`.
To avoid assuming `𝓑 ≤ 𝓧` in the definition, we replace `𝓑` by `𝓑 ⊓ 𝓧` in the restriction. -/
structure IsProper (π : Kernel[𝓑, 𝓧] X X) : Prop where
restrict_eq_indicator_smul' :
∀ ⦃B : Set X⦄ (hB : MeasurableSet[𝓑 ⊓ 𝓧] B) (x : X),
π.restrict (inf_le_right (b := 𝓧) _ hB) x = B.indicator (fun _ ↦ (1 : ℝ≥0∞)) x • π x
lemma isProper_iff_restrict_eq_indicator_smul (h𝓑𝓧 : 𝓑 ≤ 𝓧) :
IsProper π ↔ ∀ ⦃B : Set X⦄ (hB : MeasurableSet[𝓑] B) (x : X),
π.restrict (h𝓑𝓧 _ hB) x = B.indicator (fun _ ↦ (1 : ℝ≥0∞)) x • π x := by
refine ⟨fun ⟨h⟩ ↦ ?_, fun h ↦ ⟨?_⟩⟩ <;> simpa only [inf_eq_left.2 h𝓑𝓧] using h
lemma isProper_iff_inter_eq_indicator_mul (h𝓑𝓧 : 𝓑 ≤ 𝓧) :
IsProper π ↔
∀ ⦃A : Set X⦄ (_hA : MeasurableSet[𝓧] A) ⦃B : Set X⦄ (_hB : MeasurableSet[𝓑] B) (x : X),
π x (A ∩ B) = B.indicator 1 x * π x A := by
calc
_ ↔ ∀ ⦃A : Set X⦄ (_hA : MeasurableSet[𝓧] A) ⦃B : Set X⦄ (hB : MeasurableSet[𝓑] B) (x : X),
π.restrict (h𝓑𝓧 _ hB) x A = B.indicator 1 x * π x A := by
simp [isProper_iff_restrict_eq_indicator_smul h𝓑𝓧, Measure.ext_iff]; aesop
_ ↔ _ := by congr! 5 with A hA B hB x; rw [restrict_apply, Measure.restrict_apply hA]
alias ⟨IsProper.restrict_eq_indicator_smul, IsProper.of_restrict_eq_indicator_smul⟩ :=
isProper_iff_restrict_eq_indicator_smul
alias ⟨IsProper.inter_eq_indicator_mul, IsProper.of_inter_eq_indicator_mul⟩ :=
isProper_iff_inter_eq_indicator_mul
lemma IsProper.setLIntegral_eq_comp (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧) {μ : Measure[𝓧] X}
(hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) :
∫⁻ a in B, π a A ∂μ = (π ∘ₘ μ) (A ∩ B) := by
rw [Measure.bind_apply (by measurability) (π.measurable.mono h𝓑𝓧 le_rfl).aemeasurable]
simp only [hπ.inter_eq_indicator_mul h𝓑𝓧 hA hB, ← indicator_mul_const, Pi.one_apply, one_mul]
rw [← lintegral_indicator (h𝓑𝓧 _ hB)]
rfl
/-- Auxiliary lemma for `IsProper.lintegral_mul` and
`IsProper.setLIntegral_eq_indicator_mul_lintegral`. -/
private lemma IsProper.lintegral_indicator_mul_indicator (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) :
∫⁻ x, B.indicator 1 x * A.indicator 1 x ∂(π x₀) =
B.indicator 1 x₀ * ∫⁻ x, A.indicator 1 x ∂(π x₀) := by
simp_rw [← inter_indicator_mul]
rw [lintegral_indicator ((h𝓑𝓧 _ hB).inter hA), lintegral_indicator hA]
simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter,
Pi.one_apply, one_mul]
rw [← hπ.inter_eq_indicator_mul h𝓑𝓧 hA hB, inter_comm]
set_option linter.style.multiGoal false in -- false positive
/-- Auxiliary lemma for `IsProper.lintegral_mul` and
`IsProper.setLIntegral_eq_indicator_mul_lintegral`. -/
private lemma IsProper.lintegral_indicator_mul (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hB : MeasurableSet[𝓑] B) :
∫⁻ x, B.indicator 1 x * f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x, f x ∂(π x₀) := by
refine hf.ennreal_induction ?_ ?_ ?_
· rintro c A hA
simp_rw [← smul_indicator_one_apply, mul_smul_comm, smul_eq_mul]
rw [lintegral_const_mul, lintegral_const_mul, hπ.lintegral_indicator_mul_indicator h𝓑𝓧 hA hB,
mul_left_comm] <;> measurability
· rintro f₁ f₂ - _ _ hf₁ hf₂
simp only [Pi.add_apply, mul_add]
rw [lintegral_add_right, lintegral_add_right, hf₁, hf₂, mul_add] <;> measurability
· rintro f' hf'_meas hf'_mono hf'
simp_rw [ENNReal.mul_iSup]
rw [lintegral_iSup (by measurability), lintegral_iSup hf'_meas hf'_mono, ENNReal.mul_iSup]
simp_rw [hf']
· exact hf'_mono.const_mul (zero_le _)
lemma IsProper.setLIntegral_eq_indicator_mul_lintegral (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hB : MeasurableSet[𝓑] B) (x₀ : X) :
∫⁻ x in B, f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x, f x ∂(π x₀) := by
simp [← hπ.lintegral_indicator_mul h𝓑𝓧 hf hB, ← indicator_mul_left,
lintegral_indicator (h𝓑𝓧 _ hB)]
lemma IsProper.setLIntegral_inter_eq_indicator_mul_setLIntegral (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) (x₀ : X) :
∫⁻ x in A ∩ B, f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x in A, f x ∂(π x₀) := by
rw [← lintegral_indicator hA, ← hπ.setLIntegral_eq_indicator_mul_lintegral h𝓑𝓧 _ hB,
setLIntegral_indicator] <;> measurability
lemma IsProper.lintegral_mul (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧) (hf : Measurable[𝓧] f)
(hg : Measurable[𝓑] g) (x₀ : X) :
∫⁻ x, g x * f x ∂(π x₀) = g x₀ * ∫⁻ x, f x ∂(π x₀) := by
refine hg.ennreal_induction ?_ ?_ ?_
· rintro c A hA
simp_rw [← smul_indicator_one_apply, smul_mul_assoc, smul_eq_mul]
rw [lintegral_const_mul, hπ.lintegral_indicator_mul h𝓑𝓧 hf hA]
· measurability
· rintro g₁ g₂ - _ hg₂_meas hg₁ hg₂
simp only [Pi.add_apply, add_mul]
rw [lintegral_add_right, hg₁, hg₂]
· exact (hg₂_meas.mono h𝓑𝓧 le_rfl).mul hf
· rintro g' hg'_meas hg'_mono hg'
simp_rw [ENNReal.iSup_mul]
rw [lintegral_iSup (fun n ↦ ((hg'_meas _).mono h𝓑𝓧 le_rfl).mul hf)
(hg'_mono.mul_const (zero_le _))]
simp_rw [hg']
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Defs.lean | import Mathlib.MeasureTheory.Measure.GiryMonad
/-!
# Markov Kernels
A kernel from a measurable space `α` to another measurable space `β` is a measurable map
`α → MeasureTheory.Measure β`, where the measurable space instance on `measure β` is the one defined
in `MeasureTheory.Measure.instMeasurableSpace`. That is, a kernel `κ` verifies that for all
measurable sets `s` of `β`, `a ↦ κ a s` is measurable.
## Main definitions
Classes of kernels:
* `ProbabilityTheory.Kernel α β`: kernels from `α` to `β`.
* `ProbabilityTheory.IsMarkovKernel κ`: a kernel from `α` to `β` is said to be a Markov kernel
if for all `a : α`, `k a` is a probability measure.
* `ProbabilityTheory.IsZeroOrMarkovKernel κ`: a kernel from `α` to `β` which is zero or
a Markov kernel.
* `ProbabilityTheory.IsFiniteKernel κ`: a kernel from `α` to `β` is said to be finite if there
exists `C : ℝ≥0∞` such that `C < ∞` and for all `a : α`, `κ a univ ≤ C`. This implies in
particular that all measures in the image of `κ` are finite, but is stronger since it requires a
uniform bound. This stronger condition is necessary to ensure that the composition of two finite
kernels is finite.
* `ProbabilityTheory.IsSFiniteKernel κ`: a kernel is called s-finite if it is a countable
sum of finite kernels.
## Main statements
* `ProbabilityTheory.Kernel.ext_fun`: if `∫⁻ b, f b ∂(κ a) = ∫⁻ b, f b ∂(η a)` for all measurable
functions `f` and all `a`, then the two kernels `κ` and `η` are equal.
-/
assert_not_exists MeasureTheory.integral
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
/-- A kernel from a measurable space `α` to another measurable space `β` is a measurable function
`κ : α → Measure β`. The measurable space structure on `MeasureTheory.Measure β` is given by
`MeasureTheory.Measure.instMeasurableSpace`. A map `κ : α → MeasureTheory.Measure β` is measurable
iff `∀ s : Set β, MeasurableSet s → Measurable (fun a ↦ κ a s)`. -/
structure Kernel (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] where
/-- The underlying function of a kernel.
Do not use this function directly. Instead use the coercion coming from the `DFunLike`
instance. -/
toFun : α → Measure β
/-- A kernel is a measurable map.
Do not use this lemma directly. Use `Kernel.measurable` instead. -/
measurable' : Measurable toFun
/-- Notation for `Kernel` with respect to a non-standard σ-algebra in the domain. -/
scoped notation "Kernel[" mα "] " α:arg β:arg => @Kernel α β mα _
/-- Notation for `Kernel` with respect to a non-standard σ-algebra in the domain and codomain. -/
scoped notation "Kernel[" mα ", " mβ "] " α:arg β:arg => @Kernel α β mα mβ
variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
namespace Kernel
instance instFunLike : FunLike (Kernel α β) α (Measure β) where
coe := toFun
coe_injective' f g h := by cases f; cases g; congr
@[fun_prop]
lemma measurable (κ : Kernel α β) : Measurable κ := κ.measurable'
lemma aemeasurable (κ : Kernel α β) {μ : Measure α} : AEMeasurable κ μ := κ.measurable.aemeasurable
@[simp, norm_cast] lemma coe_mk (f : α → Measure β) (hf) : mk f hf = f := rfl
initialize_simps_projections Kernel (toFun → apply)
instance instZero : Zero (Kernel α β) where zero := ⟨0, measurable_zero⟩
noncomputable instance instAdd : Add (Kernel α β) where add κ η := ⟨κ + η, κ.2.add η.2⟩
noncomputable instance instSMulNat : SMul ℕ (Kernel α β) where
smul n κ := ⟨n • κ, (measurable_const (a := n)).smul κ.2⟩
@[simp, norm_cast] lemma coe_zero : ⇑(0 : Kernel α β) = 0 := rfl
@[simp, norm_cast] lemma coe_add (κ η : Kernel α β) : ⇑(κ + η) = κ + η := rfl
@[simp, norm_cast] lemma coe_nsmul (n : ℕ) (κ : Kernel α β) : ⇑(n • κ) = n • κ := rfl
@[simp] lemma zero_apply (a : α) : (0 : Kernel α β) a = 0 := rfl
@[simp] lemma add_apply (κ η : Kernel α β) (a : α) : (κ + η) a = κ a + η a := rfl
@[simp] lemma nsmul_apply (n : ℕ) (κ : Kernel α β) (a : α) : (n • κ) a = n • κ a := rfl
noncomputable instance instAddCommMonoid : AddCommMonoid (Kernel α β) :=
DFunLike.coe_injective.addCommMonoid _ coe_zero coe_add (by intros; rfl)
instance instPartialOrder : PartialOrder (Kernel α β) := .lift _ DFunLike.coe_injective
instance {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
AddLeftMono (Kernel α β) :=
⟨fun _ _ _ hμ a ↦ add_le_add_left (hμ a) _⟩
noncomputable
instance instOrderBot {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
OrderBot (Kernel α β) where
bot := 0
bot_le κ a := by simp only [coe_zero, Pi.zero_apply, Measure.zero_le]
/-- Coercion to a function as an additive monoid homomorphism. -/
noncomputable def coeAddHom (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] :
Kernel α β →+ α → Measure β where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
@[simp]
theorem coeAddHom_apply (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] (κ : Kernel α β) :
coeAddHom α β κ = ⇑κ := rfl
@[simp]
theorem coe_finset_sum (I : Finset ι) (κ : ι → Kernel α β) : ⇑(∑ i ∈ I, κ i) = ∑ i ∈ I, ⇑(κ i) :=
map_sum (coeAddHom α β) _ _
theorem finset_sum_apply (I : Finset ι) (κ : ι → Kernel α β) (a : α) :
(∑ i ∈ I, κ i) a = ∑ i ∈ I, κ i a := by rw [coe_finset_sum, Finset.sum_apply]
theorem finset_sum_apply' (I : Finset ι) (κ : ι → Kernel α β) (a : α) (s : Set β) :
(∑ i ∈ I, κ i) a s = ∑ i ∈ I, κ i a s := by rw [finset_sum_apply, Measure.finset_sum_apply]
end Kernel
/-- A kernel is a Markov kernel if every measure in its image is a probability measure. -/
class IsMarkovKernel (κ : Kernel α β) : Prop where
isProbabilityMeasure : ∀ a, IsProbabilityMeasure (κ a)
/-- A class for kernels which are zero or a Markov kernel. -/
class IsZeroOrMarkovKernel (κ : Kernel α β) : Prop where
eq_zero_or_isMarkovKernel' : κ = 0 ∨ IsMarkovKernel κ
/-- A kernel is finite if every measure in its image is finite, with a uniform bound. -/
class IsFiniteKernel (κ : Kernel α β) : Prop where
exists_univ_le : ∃ C : ℝ≥0∞, C < ∞ ∧ ∀ a, κ a Set.univ ≤ C
theorem eq_zero_or_isMarkovKernel
(κ : Kernel α β) [h : IsZeroOrMarkovKernel κ] :
κ = 0 ∨ IsMarkovKernel κ :=
h.eq_zero_or_isMarkovKernel'
/-- A constant `C : ℝ≥0∞` such that `C < ∞` for a finite kernel
(`ProbabilityTheory.IsFiniteKernel.bound_lt_top κ`) and for all `a : α` and `s : Set β`,
`κ a s ≤ C` (`ProbabilityTheory.Kernel.measure_le_bound κ a s`). -/
noncomputable def Kernel.bound (κ : Kernel α β) : ℝ≥0∞ :=
⨆ a, κ a Set.univ
@[deprecated (since := "2025-09-13")] alias IsFiniteKernel.bound := Kernel.bound
namespace Kernel
theorem bound_lt_top (κ : Kernel α β) [h : IsFiniteKernel κ] : κ.bound < ∞ := by
obtain ⟨C, hC, hle⟩ := h.exists_univ_le
refine lt_of_le_of_lt ?_ hC
simp [bound, hle]
@[deprecated (since := "2025-09-13")] alias _root_.ProbabilityTheory.IsFiniteKernel.bound_lt_top :=
bound_lt_top
theorem bound_ne_top (κ : Kernel α β) [IsFiniteKernel κ] :
κ.bound ≠ ∞ := κ.bound_lt_top.ne
@[deprecated (since := "2025-09-13")] alias _root_.ProbabilityTheory.IsFiniteKernel.bound_ne_top :=
bound_ne_top
theorem measure_le_bound (κ : Kernel α β) (a : α) (s : Set β) :
κ a s ≤ κ.bound :=
(measure_mono (Set.subset_univ s)).trans <| le_iSup (f := fun a ↦ κ a .univ) a
@[simp]
lemma bound_eq_zero_of_isEmpty [IsEmpty α] (κ : Kernel α β) :
κ.bound = 0 := by simp [bound]
@[deprecated (since := "2025-09-13")] alias
_root_.ProbabilityTheory.IsFiniteKernel.bound_eq_zero_of_isEmpty := bound_eq_zero_of_isEmpty
@[simp]
lemma bound_eq_zero_of_isEmpty' [IsEmpty β] (κ : Kernel α β) :
κ.bound = 0 := by simp [bound, Subsingleton.elim _ (0 : Measure β)]
@[deprecated (since := "2025-09-13")] alias
_root_.ProbabilityTheory.IsFiniteKernel.bound_eq_zero_of_isEmpty' := bound_eq_zero_of_isEmpty'
@[simp]
lemma bound_zero : bound (0 : Kernel α β) = 0 := by
simp [bound]
@[deprecated (since := "2025-09-13")] alias
_root_.ProbabilityTheory.IsFiniteKernel.bound_zero := bound_zero
end Kernel
instance isFiniteKernel_zero (α β : Type*) {_ : MeasurableSpace α} {_ : MeasurableSpace β} :
IsFiniteKernel (0 : Kernel α β) :=
⟨⟨0, ENNReal.coe_lt_top, fun _ => by
simp only [Kernel.zero_apply, Measure.coe_zero, Pi.zero_apply, le_zero_iff]⟩⟩
instance IsFiniteKernel.add (κ η : Kernel α β) [IsFiniteKernel κ] [IsFiniteKernel η] :
IsFiniteKernel (κ + η) := by
refine ⟨⟨κ.bound + η.bound, ENNReal.add_lt_top.mpr ⟨κ.bound_lt_top, η.bound_lt_top⟩, fun a => ?_⟩⟩
exact add_le_add (Kernel.measure_le_bound _ _ _) (Kernel.measure_le_bound _ _ _)
lemma isFiniteKernel_of_le {κ ν : Kernel α β} [hν : IsFiniteKernel ν] (hκν : κ ≤ ν) :
IsFiniteKernel κ :=
⟨ν.bound, ν.bound_lt_top, fun a ↦ (hκν _ _).trans (ν.measure_le_bound a Set.univ)⟩
variable {κ η : Kernel α β}
instance IsMarkovKernel.is_probability_measure' [IsMarkovKernel κ] (a : α) :
IsProbabilityMeasure (κ a) :=
IsMarkovKernel.isProbabilityMeasure a
instance : IsZeroOrMarkovKernel (0 : Kernel α β) := ⟨Or.inl rfl⟩
instance (priority := 100) IsMarkovKernel.IsZeroOrMarkovKernel [h : IsMarkovKernel κ] :
IsZeroOrMarkovKernel κ := ⟨Or.inr h⟩
instance (priority := 100) IsZeroOrMarkovKernel.isZeroOrProbabilityMeasure
[IsZeroOrMarkovKernel κ] (a : α) : IsZeroOrProbabilityMeasure (κ a) := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h'
· simp only [Kernel.zero_apply]
infer_instance
· infer_instance
instance IsFiniteKernel.isFiniteMeasure [IsFiniteKernel κ] (a : α) : IsFiniteMeasure (κ a) :=
⟨(κ.measure_le_bound a Set.univ).trans_lt κ.bound_lt_top⟩
instance (priority := 100) IsZeroOrMarkovKernel.isFiniteKernel [h : IsZeroOrMarkovKernel κ] :
IsFiniteKernel κ := by
rcases eq_zero_or_isMarkovKernel κ with rfl | _h'
· infer_instance
· exact ⟨⟨1, ENNReal.one_lt_top, fun _ => prob_le_one⟩⟩
namespace Kernel
@[simp]
lemma bound_eq_one [Nonempty α] (κ : Kernel α β) [IsMarkovKernel κ] :
κ.bound = 1 := by simp [bound]
@[deprecated (since := "2025-09-13")] alias _root_.ProbabilityTheory.IsMarkovKernel.bound_eq_one :=
bound_eq_one
@[simp]
lemma bound_le_one (κ : Kernel α β) [IsZeroOrMarkovKernel κ] :
κ.bound ≤ 1 := by
rcases isEmpty_or_nonempty α
· simp
· rcases eq_zero_or_isMarkovKernel κ with rfl | _ <;> simp
@[deprecated (since := "2025-09-13")] alias
_root_.ProbabilityTheory.IsZeroOrMarkovKernel.bound_le_one := bound_le_one
@[ext]
theorem ext (h : ∀ a, κ a = η a) : κ = η := DFunLike.ext _ _ h
theorem ext_iff' : κ = η ↔ ∀ a s, MeasurableSet s → κ a s = η a s := by
simp_rw [Kernel.ext_iff, Measure.ext_iff]
theorem ext_fun (h : ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a) :
κ = η := by
ext a s hs
specialize h a (s.indicator fun _ => 1) (Measurable.indicator measurable_const hs)
simp_rw [lintegral_indicator_const hs, one_mul] at h
rw [h]
theorem ext_fun_iff : κ = η ↔ ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a :=
⟨fun h a f _ => by rw [h], ext_fun⟩
section IsEmptyNonempty
instance [IsEmpty β] : Subsingleton (Kernel α β) where
allEq κ η := by ext a s; simp [Set.eq_empty_of_isEmpty s]
instance [IsEmpty α] (κ : Kernel α β) : IsMarkovKernel κ where
isProbabilityMeasure := by simp
instance [IsEmpty β] (κ : Kernel α β) : IsZeroOrMarkovKernel κ where
eq_zero_or_isMarkovKernel' := by
left
ext a s
simp [Set.eq_empty_of_isEmpty s]
lemma not_isMarkovKernel_zero [Nonempty α] : ¬ IsMarkovKernel (0 : Kernel α β) := by
by_contra h
let x : α := Nonempty.some inferInstance
have h1 : (0 : Measure β) .univ = 1 := (h.isProbabilityMeasure x).measure_univ
simp at h1
end IsEmptyNonempty
protected theorem measurable_coe (κ : Kernel α β) {s : Set β} (hs : MeasurableSet s) :
Measurable fun a => κ a s :=
(Measure.measurable_coe hs).comp κ.measurable
lemma apply_congr_of_mem_measurableAtom (κ : Kernel α β) {y' y : α} (hy' : y' ∈ measurableAtom y) :
κ y' = κ y := by
ext s hs
exact mem_of_mem_measurableAtom hy' (κ.measurable_coe hs (measurableSet_singleton (κ y s))) rfl
@[nontriviality]
lemma eq_zero_of_isEmpty_left (κ : Kernel α β) [h : IsEmpty α] : κ = 0 := by
ext a
exact h.elim a
@[nontriviality]
lemma eq_zero_of_isEmpty_right (κ : Kernel α β) [IsEmpty β] : κ = 0 := by
ext a
simp [Measure.eq_zero_of_isEmpty (κ a)]
section Sum
/-- Sum of an indexed family of kernels. -/
protected noncomputable def sum [Countable ι] (κ : ι → Kernel α β) : Kernel α β where
toFun a := Measure.sum fun n => κ n a
measurable' := by
refine Measure.measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [Measure.sum_apply _ hs]
exact Measurable.ennreal_tsum fun n => Kernel.measurable_coe (κ n) hs
theorem sum_apply [Countable ι] (κ : ι → Kernel α β) (a : α) :
Kernel.sum κ a = Measure.sum fun n => κ n a :=
rfl
theorem sum_apply' [Countable ι] (κ : ι → Kernel α β) (a : α) {s : Set β} (hs : MeasurableSet s) :
Kernel.sum κ a s = ∑' n, κ n a s := by rw [sum_apply κ a, Measure.sum_apply _ hs]
@[simp]
theorem sum_zero [Countable ι] : (Kernel.sum fun _ : ι => (0 : Kernel α β)) = 0 := by
ext a s hs
rw [sum_apply' _ a hs]
simp only [zero_apply, Measure.coe_zero, Pi.zero_apply, tsum_zero]
theorem sum_comm [Countable ι] (κ : ι → ι → Kernel α β) :
(Kernel.sum fun n => Kernel.sum (κ n)) = Kernel.sum fun m => Kernel.sum fun n => κ n m := by
ext a s; simp_rw [sum_apply]; rw [Measure.sum_comm]
@[simp]
theorem sum_fintype [Fintype ι] (κ : ι → Kernel α β) : Kernel.sum κ = ∑ i, κ i := by
ext a s hs
simp only [sum_apply' κ a hs, finset_sum_apply' _ κ a s, tsum_fintype]
theorem sum_add [Countable ι] (κ η : ι → Kernel α β) :
(Kernel.sum fun n => κ n + η n) = Kernel.sum κ + Kernel.sum η := by
ext a s hs
simp only [coe_add, Pi.add_apply, sum_apply, Measure.sum_apply _ hs, Pi.add_apply,
Measure.coe_add, ENNReal.summable.tsum_add ENNReal.summable]
end Sum
section SFinite
/-- A kernel is s-finite if it can be written as the sum of countably many finite kernels. -/
class _root_.ProbabilityTheory.IsSFiniteKernel (κ : Kernel α β) : Prop where
tsum_finite : ∃ κs : ℕ → Kernel α β, (∀ n, IsFiniteKernel (κs n)) ∧ κ = Kernel.sum κs
instance (priority := 100) IsFiniteKernel.isSFiniteKernel [h : IsFiniteKernel κ] :
IsSFiniteKernel κ :=
⟨⟨fun n => if n = 0 then κ else 0, fun n => by
simp only; split_ifs
· exact h
· infer_instance, by
ext a s hs
rw [Kernel.sum_apply' _ _ hs]
have : (fun i => ((ite (i = 0) κ 0) a) s) = fun i => ite (i = 0) (κ a s) 0 := by
ext1 i; split_ifs <;> rfl
rw [this, tsum_ite_eq]⟩⟩
/-- A sequence of finite kernels such that `κ = ProbabilityTheory.Kernel.sum (seq κ)`. See
`ProbabilityTheory.Kernel.isFiniteKernel_seq` and `ProbabilityTheory.Kernel.kernel_sum_seq`. -/
noncomputable def seq (κ : Kernel α β) [h : IsSFiniteKernel κ] : ℕ → Kernel α β :=
h.tsum_finite.choose
theorem kernel_sum_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] : Kernel.sum (seq κ) = κ :=
h.tsum_finite.choose_spec.2.symm
theorem measure_sum_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] (a : α) :
(Measure.sum fun n => seq κ n a) = κ a := by rw [← Kernel.sum_apply, kernel_sum_seq κ]
instance isFiniteKernel_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] (n : ℕ) :
IsFiniteKernel (Kernel.seq κ n) :=
h.tsum_finite.choose_spec.1 n
instance _root_.ProbabilityTheory.IsSFiniteKernel.sFinite [IsSFiniteKernel κ] (a : α) :
SFinite (κ a) :=
⟨⟨fun n ↦ seq κ n a, inferInstance, (measure_sum_seq κ a).symm⟩⟩
instance IsSFiniteKernel.add (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
IsSFiniteKernel (κ + η) := by
refine ⟨⟨fun n => seq κ n + seq η n, fun n => inferInstance, ?_⟩⟩
rw [sum_add, kernel_sum_seq κ, kernel_sum_seq η]
theorem IsSFiniteKernel.finset_sum {κs : ι → Kernel α β} (I : Finset ι)
(h : ∀ i ∈ I, IsSFiniteKernel (κs i)) : IsSFiniteKernel (∑ i ∈ I, κs i) := by
classical
induction I using Finset.induction with
| empty => rw [Finset.sum_empty]; infer_instance
| insert i I hi_notMem_I h_ind =>
rw [Finset.sum_insert hi_notMem_I]
haveI : IsSFiniteKernel (κs i) := h i (Finset.mem_insert_self _ _)
have : IsSFiniteKernel (∑ x ∈ I, κs x) :=
h_ind fun i hiI => h i (Finset.mem_insert_of_mem hiI)
exact IsSFiniteKernel.add _ _
theorem isSFiniteKernel_sum_of_denumerable [Denumerable ι] {κs : ι → Kernel α β}
(hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (Kernel.sum κs) := by
let e : ℕ ≃ ι × ℕ := (Denumerable.eqv (ι × ℕ)).symm
refine ⟨⟨fun n => seq (κs (e n).1) (e n).2, inferInstance, ?_⟩⟩
have hκ_eq : Kernel.sum κs = Kernel.sum fun n => Kernel.sum (seq (κs n)) := by
simp_rw [kernel_sum_seq]
ext a s hs
rw [hκ_eq]
simp_rw [Kernel.sum_apply' _ _ hs]
change (∑' i, ∑' m, seq (κs i) m a s) = ∑' n, (fun im : ι × ℕ => seq (κs im.fst) im.snd a s) (e n)
rw [e.tsum_eq (fun im : ι × ℕ => seq (κs im.fst) im.snd a s),
ENNReal.summable.tsum_prod' fun _ => ENNReal.summable]
instance isSFiniteKernel_sum [Countable ι] {κs : ι → Kernel α β}
[hκs : ∀ n, IsSFiniteKernel (κs n)] : IsSFiniteKernel (Kernel.sum κs) := by
cases fintypeOrInfinite ι
· rw [sum_fintype]
exact IsSFiniteKernel.finset_sum Finset.univ fun i _ => hκs i
cases nonempty_denumerable ι
exact isSFiniteKernel_sum_of_denumerable hκs
end SFinite
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Invariance.lean | import Mathlib.Probability.Kernel.Composition.MeasureComp
/-!
# Invariance of measures along a kernel
We say that a measure `μ` is invariant with respect to a kernel `κ` if its push-forward along the
kernel `μ.bind κ` is the same measure.
## Main definitions
* `ProbabilityTheory.Kernel.Invariant`: invariance of a given measure with respect to a kernel.
-/
open MeasureTheory
open scoped MeasureTheory ENNReal ProbabilityTheory
namespace ProbabilityTheory
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
namespace Kernel
/-! ### Push-forward of measures along a kernel -/
@[deprecated comp_const (since := "2025-08-06")]
theorem const_bind_eq_comp_const (κ : Kernel α β) (μ : Measure α) :
const α (μ.bind κ) = κ ∘ₖ const α μ := by
ext a s hs
simp_rw [comp_apply' _ _ _ hs, const_apply, Measure.bind_apply hs (Kernel.aemeasurable _)]
@[deprecated comp_const (since := "2025-08-06")]
theorem comp_const_apply_eq_bind (κ : Kernel α β) (μ : Measure α) (a : α) :
(κ ∘ₖ const α μ) a = μ.bind κ := by
rw [← const_apply (μ.bind κ) a, comp_const κ μ]
/-! ### Invariant measures of kernels -/
/-- A measure `μ` is invariant with respect to the kernel `κ` if the push-forward measure of `μ`
along `κ` equals `μ`. -/
def Invariant (κ : Kernel α α) (μ : Measure α) : Prop :=
μ.bind κ = μ
variable {κ η : Kernel α α} {μ : Measure α}
theorem Invariant.def (hκ : Invariant κ μ) : μ.bind κ = μ :=
hκ
nonrec theorem Invariant.comp_const (hκ : Invariant κ μ) : κ ∘ₖ const α μ = const α μ := by
rw [comp_const κ μ, hκ.def]
theorem Invariant.comp (hκ : Invariant κ μ) (hη : Invariant η μ) :
Invariant (κ ∘ₖ η) μ := by
rcases isEmpty_or_nonempty α with _ | hα
· exact Subsingleton.elim _ _
· rw [Invariant, ← Measure.comp_assoc, hη, hκ]
/-! ### Reversibility of kernels -/
/-- Reversibility (detailed balance) of a Markov kernel `κ` w.r.t. a measure `π`:
for all measurable sets `A B`, the mass flowing from `A` to `B` equals that from `B` to `A`. -/
def IsReversible (κ : Kernel α α) (π : Measure α) : Prop :=
∀ ⦃A B⦄, MeasurableSet A → MeasurableSet B →
∫⁻ x in A, κ x B ∂π = ∫⁻ x in B, κ x A ∂π
/-- A reversible Markov kernel leaves the measure `π` invariant. -/
theorem IsReversible.invariant
{κ : Kernel α α} [IsMarkovKernel κ] {π : Measure α}
(h_rev : IsReversible κ π) : Invariant κ π := by
ext s hs
calc
(κ ∘ₘ π) s = ∫⁻ x, κ x s ∂π := by rw [Measure.bind_apply hs (Kernel.aemeasurable _)]
_ = ∫⁻ x in s, κ x Set.univ ∂π := by simpa [restrict_univ] using (h_rev hs .univ).symm
_ = π s := by simp
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Posterior.lean | import Mathlib.Probability.Kernel.CompProdEqIff
import Mathlib.Probability.Kernel.Composition.Lemmas
import Mathlib.Probability.Kernel.Disintegration.StandardBorel
/-!
# Posterior kernel
For `μ : Measure Ω` (called prior measure), seen as a measure on a parameter, and a kernel
`κ : Kernel Ω 𝓧` that gives the conditional distribution of "data" in `𝓧` given the prior parameter,
we can get the distribution of the data with `κ ∘ₘ μ`, and the joint distribution of parameter and
data with `μ ⊗ₘ κ : Measure (Ω × 𝓧)`.
The posterior distribution of the parameter given the data is a Markov kernel `κ†μ : Kernel 𝓧 Ω`
such that `(κ ∘ₘ μ) ⊗ₘ κ†μ = (μ ⊗ₘ κ).map Prod.swap`. That is, the joint distribution of parameter
and data can be recovered from the distribution of the data and the posterior.
## Main definitions
* `posterior κ μ`: posterior of a kernel `κ` for a prior measure `μ`.
## Main statements
* `compProd_posterior_eq_map_swap`: the main property of the posterior,
`(κ ∘ₘ μ) ⊗ₘ κ†μ = (μ ⊗ₘ κ).map Prod.swap`.
* `ae_eq_posterior_of_compProd_eq`
* `posterior_comp_self`: `κ†μ ∘ₘ κ ∘ₘ μ = μ`
* `posterior_posterior`: `(κ†μ)†(κ ∘ₘ μ) =ᵐ[μ] κ`
* `posterior_comp`: `(η ∘ₖ κ)†μ =ᵐ[η ∘ₘ κ ∘ₘ μ] κ†μ ∘ₖ η†(κ ∘ₘ μ)`
* `posterior_eq_withDensity`: If `κ ω ≪ κ ∘ₘ μ` for `μ`-almost every `ω`,
then for `κ ∘ₘ μ`-almost every `x`,
`κ†μ x = μ.withDensity (fun ω ↦ κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) ω x)`.
The condition is true for countable `Ω`: see `absolutelyContinuous_comp_of_countable`.
## Notation
`κ†μ` denotes the posterior of `κ` with respect to `μ`, `posterior κ μ`.
`†` can be typed as `\dag` or `\dagger`.
This notation emphasizes that the posterior is a kind of inverse of `κ`, which we would want to
denote `κ†`, but we have to also specify the measure `μ`.
-/
open scoped ENNReal
open MeasureTheory
namespace ProbabilityTheory
variable {Ω 𝓧 𝓨 𝓩 : Type*} {mΩ : MeasurableSpace Ω} {m𝓧 : MeasurableSpace 𝓧}
{m𝓨 : MeasurableSpace 𝓨} {m𝓩 : MeasurableSpace 𝓩}
{κ : Kernel Ω 𝓧} {μ : Measure Ω} [IsFiniteMeasure μ] [IsFiniteKernel κ]
variable [StandardBorelSpace Ω] [Nonempty Ω]
/-- Posterior of the kernel `κ` with respect to the measure `μ`. -/
noncomputable
def posterior (κ : Kernel Ω 𝓧) (μ : Measure Ω) [IsFiniteMeasure μ] [IsFiniteKernel κ] :
Kernel 𝓧 Ω :=
((μ ⊗ₘ κ).map Prod.swap).condKernel
/-- Posterior of the kernel `κ` with respect to the measure `μ`. -/
scoped[ProbabilityTheory] infix:arg "†" => ProbabilityTheory.posterior
/-- The posterior is a Markov kernel. -/
instance : IsMarkovKernel κ†μ := by rw [posterior]; infer_instance
/-- The main property of the posterior. -/
lemma compProd_posterior_eq_map_swap : (κ ∘ₘ μ) ⊗ₘ κ†μ = (μ ⊗ₘ κ).map Prod.swap := by
simpa using ((μ ⊗ₘ κ).map Prod.swap).disintegrate ((μ ⊗ₘ κ).map Prod.swap).condKernel
lemma compProd_posterior_eq_swap_comp : (κ ∘ₘ μ) ⊗ₘ κ†μ = Kernel.swap Ω 𝓧 ∘ₘ μ ⊗ₘ κ := by
rw [compProd_posterior_eq_map_swap, Measure.swap_comp]
lemma swap_compProd_posterior : Kernel.swap 𝓧 Ω ∘ₘ (κ ∘ₘ μ) ⊗ₘ κ†μ = μ ⊗ₘ κ := by
rw [compProd_posterior_eq_swap_comp, Measure.comp_assoc, Kernel.swap_swap, Measure.id_comp]
/-- The main property of the posterior, as equality of the following diagrams:
```
-- id -- κ
μ -- κ -| = μ -|
-- κ†μ -- id
``` -/
lemma parallelProd_posterior_comp_copy_comp :
(Kernel.id ∥ₖ κ†μ) ∘ₘ Kernel.copy 𝓧 ∘ₘ κ ∘ₘ μ
= (κ ∥ₖ Kernel.id) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
calc (Kernel.id ∥ₖ κ†μ) ∘ₘ Kernel.copy 𝓧 ∘ₘ κ ∘ₘ μ
_ = (κ ∘ₘ μ) ⊗ₘ κ†μ := by rw [← Measure.compProd_eq_parallelComp_comp_copy_comp]
_ = Kernel.swap _ _ ∘ₘ (μ ⊗ₘ κ) := by rw [compProd_posterior_eq_swap_comp]
_ = Kernel.swap _ _ ∘ₘ (Kernel.id ∥ₖ κ) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
rw [Measure.compProd_eq_parallelComp_comp_copy_comp]
_ = (κ ∥ₖ Kernel.id) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
rw [Measure.comp_assoc, Kernel.swap_parallelComp, Measure.comp_assoc, Kernel.comp_assoc,
Kernel.swap_copy, Measure.comp_assoc]
lemma posterior_prod_id_comp : (κ†μ ×ₖ Kernel.id) ∘ₘ κ ∘ₘ μ = μ ⊗ₘ κ := by
rw [← Kernel.swap_prod, ← Measure.comp_assoc, ← Measure.compProd_eq_comp_prod,
compProd_posterior_eq_swap_comp, Measure.comp_assoc, Kernel.swap_swap, Measure.id_comp]
/-- The posterior is unique up to a `κ ∘ₘ μ`-null set. -/
lemma ae_eq_posterior_of_compProd_eq {η : Kernel 𝓧 Ω} [IsFiniteKernel η]
(h : (κ ∘ₘ μ) ⊗ₘ η = (μ ⊗ₘ κ).map Prod.swap) :
η =ᵐ[κ ∘ₘ μ] κ†μ :=
(Kernel.ae_eq_of_compProd_eq (compProd_posterior_eq_map_swap.trans h.symm)).symm
/-- The posterior is unique up to a `κ ∘ₘ μ`-null set. -/
lemma ae_eq_posterior_of_compProd_eq_swap_comp (η : Kernel 𝓧 Ω) [IsFiniteKernel η]
(h : ((κ ∘ₘ μ) ⊗ₘ η) = Kernel.swap Ω 𝓧 ∘ₘ μ ⊗ₘ κ) :
η =ᵐ[κ ∘ₘ μ] κ†μ :=
ae_eq_posterior_of_compProd_eq <| by rw [h, Measure.swap_comp]
@[simp]
lemma posterior_comp_self [IsMarkovKernel κ] : κ†μ ∘ₘ κ ∘ₘ μ = μ := by
rw [← Measure.snd_compProd, compProd_posterior_eq_map_swap, Measure.snd_map_swap,
Measure.fst_compProd]
/-- The posterior of the identity kernel is the identity kernel. -/
lemma posterior_id (μ : Measure Ω) [IsFiniteMeasure μ] : Kernel.id†μ =ᵐ[μ] Kernel.id := by
suffices Kernel.id =ᵐ[Kernel.id ∘ₘ μ] (Kernel.id : Kernel Ω Ω)†μ by
rw [Measure.id_comp] at this
filter_upwards [this] with a ha using ha.symm
refine ae_eq_posterior_of_compProd_eq_swap_comp Kernel.id ?_
rw [Measure.id_comp, Measure.compProd_id_eq_copy_comp, Measure.comp_assoc, Kernel.swap_copy]
/-- For a deterministic kernel `κ`, `κ ∘ₖ κ†μ` is `μ.map f`-a.e. equal to the identity kernel. -/
lemma deterministic_comp_posterior [MeasurableSpace.CountablyGenerated 𝓧]
{f : Ω → 𝓧} (hf : Measurable f) :
Kernel.deterministic f hf ∘ₖ (Kernel.deterministic f hf)†μ =ᵐ[μ.map f] Kernel.id := by
refine Kernel.ae_eq_of_compProd_eq ?_
calc μ.map f ⊗ₘ (Kernel.deterministic f hf ∘ₖ (Kernel.deterministic f hf)†μ)
_ = (Kernel.deterministic f hf ∘ₘ μ)
⊗ₘ (Kernel.deterministic f hf ∘ₖ (Kernel.deterministic f hf)†μ) := by
rw [Measure.deterministic_comp_eq_map]
_ = (Kernel.id ∥ₖ Kernel.deterministic f hf) ∘ₘ (Kernel.id ∥ₖ (Kernel.deterministic f hf)†μ) ∘ₘ
Kernel.copy 𝓧 ∘ₘ Kernel.deterministic f hf ∘ₘ μ := by
rw [Measure.compProd_eq_parallelComp_comp_copy_comp,
← Kernel.parallelComp_id_left_comp_parallelComp, ← Measure.comp_assoc]
_ = (Kernel.id ∥ₖ Kernel.deterministic f hf) ∘ₘ (Kernel.deterministic f hf ∥ₖ Kernel.id) ∘ₘ
Kernel.copy Ω ∘ₘ μ := by rw [parallelProd_posterior_comp_copy_comp]
_ = (Kernel.deterministic f hf ∥ₖ Kernel.deterministic f hf) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
rw [Measure.comp_assoc, Kernel.parallelComp_comp_parallelComp, Kernel.id_comp, Kernel.comp_id]
_ = (Kernel.copy 𝓧 ∘ₖ Kernel.deterministic f hf) ∘ₘ μ := by -- `deterministic` is used here
rw [Measure.comp_assoc, Kernel.deterministic_comp_copy]
_ = μ.map f ⊗ₘ Kernel.id := by
rw [Measure.compProd_id_eq_copy_comp, ← Measure.comp_assoc,
Measure.deterministic_comp_eq_map]
lemma absolutelyContinuous_posterior {ν : Measure 𝓧} [SFinite ν] (h_ac : ∀ᵐ ω ∂μ, κ ω ≪ ν) :
∀ᵐ b ∂(κ ∘ₘ μ), (κ†μ) b ≪ μ := by
suffices (κ ∘ₘ μ) ⊗ₘ (κ†μ) ≪ ν.prod μ by
rw [← Measure.compProd_const] at this
simpa using this.kernel_of_compProd
suffices μ ⊗ₘ κ ≪ μ.prod ν by
rw [compProd_posterior_eq_map_swap, ← Measure.prod_swap]
exact this.map measurable_swap
rw [← Measure.compProd_const]
refine Measure.AbsolutelyContinuous.compProd_right ?_
simpa
section StandardBorelSpace
variable [StandardBorelSpace 𝓧] [Nonempty 𝓧]
/-- The posterior is involutive (up to `μ`-a.e. equality). -/
lemma posterior_posterior [IsMarkovKernel κ] : (κ†μ)†(κ ∘ₘ μ) =ᵐ[μ] κ := by
suffices κ =ᵐ[κ†μ ∘ₘ κ ∘ₘ μ] (κ†μ)†(κ ∘ₘ μ) by
rw [posterior_comp_self] at this
filter_upwards [this] with a h using h.symm
refine ae_eq_posterior_of_compProd_eq_swap_comp κ ?_
rw [posterior_comp_self, compProd_posterior_eq_swap_comp, Measure.comp_assoc,
Kernel.swap_swap, Measure.id_comp]
/-- The posterior is contravariant. -/
lemma posterior_comp {η : Kernel 𝓧 𝓨} [IsFiniteKernel η] :
(η ∘ₖ κ)†μ =ᵐ[η ∘ₘ κ ∘ₘ μ] κ†μ ∘ₖ η†(κ ∘ₘ μ) := by
rw [Measure.comp_assoc]
refine (ae_eq_posterior_of_compProd_eq_swap_comp ((κ†μ) ∘ₖ η†(κ ∘ₘ μ)) ?_).symm
simp_rw [Measure.compProd_eq_comp_prod, ← Kernel.parallelComp_comp_copy,
← Kernel.parallelComp_id_left_comp_parallelComp, ← Measure.comp_assoc]
calc (Kernel.id ∥ₖ κ†μ) ∘ₘ (Kernel.id ∥ₖ η†(κ ∘ₘ μ)) ∘ₘ (Kernel.copy 𝓨) ∘ₘ η ∘ₘ κ ∘ₘ μ
_ = (Kernel.id ∥ₖ κ†μ) ∘ₘ (η ∥ₖ Kernel.id) ∘ₘ Kernel.copy 𝓧 ∘ₘ κ ∘ₘ μ := by
rw [parallelProd_posterior_comp_copy_comp]
_ = (η ∥ₖ Kernel.id) ∘ₘ (Kernel.id ∥ₖ κ†μ) ∘ₘ Kernel.copy 𝓧 ∘ₘ κ ∘ₘ μ := by
rw [Measure.comp_assoc, Kernel.parallelComp_comm, ← Measure.comp_assoc]
_ = (η ∥ₖ Kernel.id) ∘ₘ (κ ∥ₖ Kernel.id) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
rw [parallelProd_posterior_comp_copy_comp]
_ = (Kernel.swap _ _) ∘ₘ (Kernel.id ∥ₖ η) ∘ₘ (Kernel.id ∥ₖ κ) ∘ₘ Kernel.copy Ω ∘ₘ μ := by
simp_rw [Measure.comp_assoc]
conv_rhs => rw [← Kernel.comp_assoc]
rw [Kernel.swap_parallelComp, Kernel.comp_assoc, ← Kernel.comp_assoc (Kernel.swap Ω 𝓧),
Kernel.swap_parallelComp, Kernel.comp_assoc, Kernel.swap_copy]
end StandardBorelSpace
section CountableOrCountablyGenerated
variable [MeasurableSpace.CountableOrCountablyGenerated Ω 𝓧]
lemma absolutelyContinuous_of_posterior (h_ac : ∀ᵐ b ∂(κ ∘ₘ μ), (κ†μ) b ≪ μ) :
∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ := by
suffices μ ⊗ₘ κ ≪ μ.prod (κ ∘ₘ μ) by
rw [← Measure.compProd_const] at this
simpa using this.kernel_of_compProd
suffices (κ ∘ₘ μ) ⊗ₘ κ†μ ≪ (κ ∘ₘ μ).prod μ by
rw [← swap_compProd_posterior, ← Measure.prod_swap, Measure.swap_comp]
exact this.map measurable_swap
rw [← Measure.compProd_const]
refine Measure.AbsolutelyContinuous.compProd_right ?_
simpa
lemma absolutelyContinuous_posterior_iff : (∀ᵐ b ∂(κ ∘ₘ μ), (κ†μ) b ≪ μ) ↔ ∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ :=
⟨absolutelyContinuous_of_posterior, absolutelyContinuous_posterior⟩
lemma Kernel.absolutelyContinuous_comp_of_absolutelyContinuous {ν : Measure 𝓧} [SFinite ν]
(h_ac : ∀ᵐ ω ∂μ, κ ω ≪ ν) :
∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ := by
rw [← absolutelyContinuous_posterior_iff]
exact absolutelyContinuous_posterior h_ac
lemma rnDeriv_posterior_ae_prod (h_ac : ∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ) :
∀ᵐ p ∂(μ.prod (κ ∘ₘ μ)),
(κ†μ).rnDeriv (Kernel.const _ μ) p.2 p.1 = κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) p.1 p.2 := by
-- We prove the a.e. equality by showing that integrals on the π-system of rectangles are equal.
-- First, the integral of the left-hand side on `s ×ˢ t` is `(μ ⊗ₘ κ) (s ×ˢ t)`, which we prove
-- by showing that it's equal to `((κ ∘ₘ μ) ⊗ κ†μ) (t ×ˢ s)` and using the main property of the
-- posterior.
have h1 {s : Set Ω} {t : Set 𝓧} (hs : MeasurableSet s) (ht : MeasurableSet t) :
∫⁻ x in s ×ˢ t, (κ†μ).rnDeriv (Kernel.const _ μ) x.2 x.1 ∂μ.prod (⇑κ ∘ₘ μ)
= (μ ⊗ₘ κ) (s ×ˢ t) := by
rw [setLIntegral_prod_symm _ (by fun_prop), ← swap_compProd_posterior, Measure.swap_comp,
Measure.map_apply measurable_swap (hs.prod ht), Set.preimage_swap_prod,
Measure.compProd_apply_prod ht hs]
refine lintegral_congr_ae <| ae_restrict_of_ae ?_
filter_upwards [absolutelyContinuous_posterior h_ac] with x h_ac'
change ∫⁻ ω in s, (κ†μ).rnDeriv (Kernel.const 𝓧 μ) x ω ∂(Kernel.const 𝓧 μ x) = _
rw [Kernel.setLIntegral_rnDeriv h_ac' hs]
have h2 {s : Set Ω} {t : Set 𝓧} (hs : MeasurableSet s) (ht : MeasurableSet t) :
-- Second, the integral of the right-hand side on `s ×ˢ t` is `(μ ⊗ₘ κ) (s ×ˢ t)`.
∫⁻ x in s ×ˢ t, κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) x.1 x.2 ∂μ.prod (⇑κ ∘ₘ μ)
= (μ ⊗ₘ κ) (s ×ˢ t) := by
rw [setLIntegral_prod _ (by fun_prop), Measure.compProd_apply_prod hs ht]
refine lintegral_congr_ae <| ae_restrict_of_ae ?_
filter_upwards [h_ac] with ω h_ac
change ∫⁻ x in t, κ.rnDeriv (Kernel.const Ω (κ ∘ₘ μ)) ω x ∂(Kernel.const Ω (κ ∘ₘ μ) ω) = _
rw [Kernel.setLIntegral_rnDeriv h_ac ht]
-- We extend from the π-system to the σ-algebra.
refine ae_eq_of_setLIntegral_prod_eq (by fun_prop) (by fun_prop) ?_ ?_
· refine ne_of_lt ?_
calc ∫⁻ x, (κ†μ).rnDeriv (Kernel.const _ μ) x.2 x.1 ∂μ.prod (κ ∘ₘ μ)
_ = (μ ⊗ₘ κ) Set.univ := by rw [← setLIntegral_univ, ← Set.univ_prod_univ, h1 .univ .univ]
_ < ⊤ := measure_lt_top _ _
· intro s hs t ht
rw [h1 hs ht, h2 hs ht]
lemma rnDeriv_posterior (h_ac : ∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ) :
∀ᵐ ω ∂μ, ∀ᵐ x ∂(κ ∘ₘ μ),
(κ†μ).rnDeriv (Kernel.const _ μ) x ω = κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) ω x := by
convert Measure.ae_ae_of_ae_prod (rnDeriv_posterior_ae_prod h_ac) -- much faster than `exact`
lemma rnDeriv_posterior_symm (h_ac : ∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ) :
∀ᵐ x ∂(κ ∘ₘ μ), ∀ᵐ ω ∂μ,
(κ†μ).rnDeriv (Kernel.const _ μ) x ω = κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) ω x := by
rw [Measure.ae_ae_comm]
· exact rnDeriv_posterior h_ac
· exact measurableSet_eq_fun' (by fun_prop) (by fun_prop)
/-- If `κ ω ≪ κ ∘ₘ μ` for `μ`-almost every `ω`, then for `κ ∘ₘ μ`-almost every `x`,
`κ†μ x = μ.withDensity (fun ω ↦ κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) ω x)`.
This is a form of **Bayes' theorem**.
The condition is true for example for countable `Ω`. -/
lemma posterior_eq_withDensity (h_ac : ∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ) :
∀ᵐ x ∂(κ ∘ₘ μ), (κ†μ) x = μ.withDensity (fun ω ↦ κ.rnDeriv (Kernel.const _ (κ ∘ₘ μ)) ω x) := by
filter_upwards [rnDeriv_posterior_symm h_ac, absolutelyContinuous_posterior h_ac] with x h h_ac'
ext s hs
rw [← Measure.setLIntegral_rnDeriv h_ac', withDensity_apply _ hs]
refine setLIntegral_congr_fun_ae hs ?_
filter_upwards [h, Kernel.rnDeriv_eq_rnDeriv_measure (κ := κ†μ) (η := Kernel.const 𝓧 μ) (a := x)]
with ω h h_eq hωs
rw [← h, h_eq, Kernel.const_apply]
lemma posterior_eq_withDensity_of_countable {Ω : Type*} [Countable Ω] [MeasurableSpace Ω]
[Nonempty Ω] [StandardBorelSpace Ω] (κ : Kernel Ω 𝓧) [IsFiniteKernel κ]
(μ : Measure Ω) [IsFiniteMeasure μ] :
∀ᵐ x ∂(κ ∘ₘ μ), (κ†μ) x = μ.withDensity (fun ω ↦ (κ ω).rnDeriv (κ ∘ₘ μ) x) := by
have h_rnDeriv ω := Kernel.rnDeriv_eq_rnDeriv_measure (κ := κ) (η := Kernel.const Ω (κ ∘ₘ μ))
(a := ω)
simp only [Filter.EventuallyEq, Kernel.const_apply] at h_rnDeriv
rw [← ae_all_iff] at h_rnDeriv
filter_upwards [posterior_eq_withDensity Measure.absolutelyContinuous_comp_of_countable,
h_rnDeriv] with x hx hx_all
simp_rw [hx, hx_all]
end CountableOrCountablyGenerated
section Bool
lemma posterior_boolKernel_apply_false (μ ν : Measure 𝓧) [IsFiniteMeasure μ] [IsFiniteMeasure ν]
(π : Measure Bool) [IsFiniteMeasure π] :
∀ᵐ x ∂Kernel.boolKernel μ ν ∘ₘ π, ((Kernel.boolKernel μ ν)†π) x {false}
= π {false} * μ.rnDeriv (Kernel.boolKernel μ ν ∘ₘ π) x := by
filter_upwards [posterior_eq_withDensity_of_countable (Kernel.boolKernel μ ν) π] with x hx
rw [hx]
simp
lemma posterior_boolKernel_apply_true (μ ν : Measure 𝓧) [IsFiniteMeasure μ] [IsFiniteMeasure ν]
(π : Measure Bool) [IsFiniteMeasure π] :
∀ᵐ x ∂Kernel.boolKernel μ ν ∘ₘ π, ((Kernel.boolKernel μ ν)†π) x {true}
= π {true} * ν.rnDeriv (Kernel.boolKernel μ ν ∘ₘ π) x := by
filter_upwards [posterior_eq_withDensity_of_countable (Kernel.boolKernel μ ν) π] with x hx
rw [hx]
simp
end Bool
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/IonescuTulcea/Maps.lean | import Mathlib.MeasureTheory.MeasurableSpace.Embedding
import Mathlib.Order.Restriction
/-! # Auxiliary maps for Ionescu-Tulcea theorem
This file contains auxiliary maps which are used to prove the Ionescu-Tulcea theorem.
-/
open Finset Preorder
section Definitions
section LinearOrder
variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [DecidableLE ι] {X : ι → Type*}
/-- Gluing `Ioc a b` and `Ioc b c` into `Ioc a c`. -/
def IocProdIoc (a b c : ι) (x : (Π i : Ioc a b, X i) × (Π i : Ioc b c, X i)) (i : Ioc a c) : X i :=
if h : i ≤ b
then x.1 ⟨i, mem_Ioc.2 ⟨(mem_Ioc.1 i.2).1, h⟩⟩
else x.2 ⟨i, mem_Ioc.2 ⟨not_le.1 h, (mem_Ioc.1 i.2).2⟩⟩
@[measurability, fun_prop]
lemma measurable_IocProdIoc [∀ i, MeasurableSpace (X i)] {a b c : ι} :
Measurable (IocProdIoc (X := X) a b c) := by
refine measurable_pi_lambda _ (fun i ↦ ?_)
by_cases h : i ≤ b
· simpa [IocProdIoc, h] using measurable_fst.eval
· simpa [IocProdIoc, h] using measurable_snd.eval
variable [LocallyFiniteOrderBot ι]
/-- Gluing `Iic a` and `Ioc a b` into `Iic b`. If `b < a`, this is just a projection on the first
coordinate followed by a restriction, see `IicProdIoc_le`. -/
def IicProdIoc (a b : ι) (x : (Π i : Iic a, X i) × (Π i : Ioc a b, X i)) (i : Iic b) : X i :=
if h : i ≤ a
then x.1 ⟨i, mem_Iic.2 h⟩
else x.2 ⟨i, mem_Ioc.2 ⟨not_le.1 h, mem_Iic.1 i.2⟩⟩
/-- When `IicProdIoc` is only partially applied (i.e. `IicProdIoc a b x` but not
`IicProdIoc a b x i`) `simp [IicProdIoc]` won't unfold the definition.
This lemma allows to unfold it by writing `simp [IicProdIoc_def]`. -/
lemma IicProdIoc_def (a b : ι) :
IicProdIoc (X := X) a b = fun x i ↦ if h : i.1 ≤ a then x.1 ⟨i, mem_Iic.2 h⟩
else x.2 ⟨i, mem_Ioc.2 ⟨not_le.1 h, mem_Iic.1 i.2⟩⟩ := rfl
lemma frestrictLe₂_comp_IicProdIoc {a b : ι} (hab : a ≤ b) :
(frestrictLe₂ hab) ∘ (IicProdIoc (X := X) a b) = Prod.fst := by
ext x i
simp [IicProdIoc, mem_Iic.1 i.2]
lemma restrict₂_comp_IicProdIoc (a b : ι) :
(restrict₂ Ioc_subset_Iic_self) ∘ (IicProdIoc (X := X) a b) = Prod.snd := by
ext x i
simp [IicProdIoc, not_le.2 (mem_Ioc.1 i.2).1]
@[simp]
lemma IicProdIoc_self (a : ι) : IicProdIoc (X := X) a a = Prod.fst := by
ext x i
simp [IicProdIoc, mem_Iic.1 i.2]
lemma IicProdIoc_le {a b : ι} (hba : b ≤ a) :
IicProdIoc (X := X) a b = (frestrictLe₂ hba) ∘ Prod.fst := by
ext x i
simp [IicProdIoc, (mem_Iic.1 i.2).trans hba]
lemma IicProdIoc_comp_restrict₂ {a b : ι} :
(restrict₂ Ioc_subset_Iic_self) ∘ (IicProdIoc (X := X) a b) = Prod.snd := by
ext x i
simp [IicProdIoc, not_le.2 (mem_Ioc.1 i.2).1]
variable [∀ i, MeasurableSpace (X i)]
@[measurability, fun_prop]
lemma measurable_IicProdIoc {m n : ι} : Measurable (IicProdIoc (X := X) m n) := by
refine measurable_pi_lambda _ (fun i ↦ ?_)
by_cases h : i ≤ m
· simpa [IicProdIoc, h] using measurable_fst.eval
· simpa [IicProdIoc, h] using measurable_snd.eval
namespace MeasurableEquiv
/-- Gluing `Iic a` and `Ioc a b` into `Iic b`. This version requires `a ≤ b` to get a measurable
equivalence. -/
def IicProdIoc {a b : ι} (hab : a ≤ b) :
((Π i : Iic a, X i) × (Π i : Ioc a b, X i)) ≃ᵐ Π i : Iic b, X i where
toFun x i := if h : i ≤ a then x.1 ⟨i, mem_Iic.2 h⟩
else x.2 ⟨i, mem_Ioc.2 ⟨not_le.1 h, mem_Iic.1 i.2⟩⟩
invFun x := ⟨fun i ↦ x ⟨i.1, Iic_subset_Iic.2 hab i.2⟩, fun i ↦ x ⟨i.1, Ioc_subset_Iic_self i.2⟩⟩
left_inv := fun x ↦ by
ext i
· simp [mem_Iic.1 i.2]
· simp [not_le.2 (mem_Ioc.1 i.2).1]
right_inv := fun x ↦ funext fun i ↦ by
by_cases hi : i.1 ≤ a <;> simp [hi]
measurable_toFun := by
refine measurable_pi_lambda _ (fun x ↦ ?_)
by_cases h : x ≤ a
· simpa [h] using measurable_fst.eval
· simpa [h] using measurable_snd.eval
measurable_invFun := by dsimp; fun_prop
lemma coe_IicProdIoc {a b : ι} (hab : a ≤ b) :
⇑(IicProdIoc (X := X) hab) = _root_.IicProdIoc a b := rfl
lemma coe_IicProdIoc_symm {a b : ι} (hab : a ≤ b) :
⇑(IicProdIoc (X := X) hab).symm =
fun x ↦ (frestrictLe₂ hab x, restrict₂ Ioc_subset_Iic_self x) := rfl
/-- Gluing `Iic a` and `Ioi a` into `ℕ`, version as a measurable equivalence
on dependent functions. -/
def IicProdIoi (a : ι) :
((Π i : Iic a, X i) × (Π i : Set.Ioi a, X i)) ≃ᵐ (Π n, X n) where
toFun := fun x i ↦ if hi : i ≤ a
then x.1 ⟨i, mem_Iic.2 hi⟩
else x.2 ⟨i, Set.mem_Ioi.2 (not_le.1 hi)⟩
invFun := fun x ↦ (fun i ↦ x i, fun i ↦ x i)
left_inv := fun x ↦ by
ext i
· simp [mem_Iic.1 i.2]
· simp [not_le.2 <| Set.mem_Ioi.1 i.2]
right_inv := fun x ↦ by simp
measurable_toFun := by
refine measurable_pi_lambda _ (fun i ↦ ?_)
by_cases hi : i ≤ a <;> simp only [Equiv.coe_fn_mk, hi, ↓reduceDIte]
· exact measurable_fst.eval
· exact measurable_snd.eval
measurable_invFun := Measurable.prodMk (measurable_restrict _) (Set.measurable_restrict _)
end MeasurableEquiv
end LinearOrder
section Nat
variable {X : ℕ → Type*} [∀ n, MeasurableSpace (X n)]
/-- Identifying `{a + 1}` with `Ioc a (a + 1)`, as a measurable equiv on dependent functions. -/
def MeasurableEquiv.piSingleton (a : ℕ) : X (a + 1) ≃ᵐ Π i : Ioc a (a + 1), X i where
toFun x i := (Nat.mem_Ioc_succ.1 i.2).symm ▸ x
invFun x := x ⟨a + 1, right_mem_Ioc.2 a.lt_succ_self⟩
left_inv := fun x ↦ by simp
right_inv := fun x ↦ funext fun i ↦ by cases Nat.mem_Ioc_succ' i; rfl
measurable_toFun := by
simp_rw [eqRec_eq_cast]
refine measurable_pi_lambda _ (fun i ↦ (MeasurableEquiv.cast _ ?_).measurable)
cases Nat.mem_Ioc_succ' i; rfl
measurable_invFun := measurable_pi_apply _
end Nat
end Definitions
section Lemmas
variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [DecidableLE ι] {X : ι → Type*}
lemma _root_.IocProdIoc_preimage {a b c : ι} (hab : a ≤ b) (hbc : b ≤ c)
(s : (i : Ioc a c) → Set (X i)) :
IocProdIoc a b c ⁻¹' (Set.univ.pi s) =
(Set.univ.pi <| restrict₂ (π := (fun n ↦ Set (X n))) (Ioc_subset_Ioc_right hbc) s) ×ˢ
(Set.univ.pi <| restrict₂ (π := (fun n ↦ Set (X n))) (Ioc_subset_Ioc_left hab) s) := by
ext x
simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, IocProdIoc, forall_const, Subtype.forall,
mem_Ioc, Set.mem_prod, restrict₂]
refine ⟨fun h ↦ ⟨fun i ⟨hi1, hi2⟩ ↦ ?_, fun i ⟨hi1, hi2⟩ ↦ ?_⟩, fun ⟨h1, h2⟩ i ⟨hi1, hi2⟩ ↦ ?_⟩
· convert h i ⟨hi1, hi2.trans hbc⟩
rw [dif_pos hi2]
· convert h i ⟨lt_of_le_of_lt hab hi1, hi2⟩
rw [dif_neg (not_le.2 hi1)]
· split_ifs with hi3
· exact h1 i ⟨hi1, hi3⟩
· exact h2 i ⟨not_le.1 hi3, hi2⟩
variable [LocallyFiniteOrderBot ι]
lemma _root_.IicProdIoc_preimage {a b : ι} (hab : a ≤ b) (s : (i : Iic b) → Set (X i)) :
IicProdIoc a b ⁻¹' (Set.univ.pi s) =
(Set.univ.pi <| frestrictLe₂ (π := (fun n ↦ Set (X n))) hab s) ×ˢ
(Set.univ.pi <| restrict₂ (π := (fun n ↦ Set (X n))) Ioc_subset_Iic_self s) := by
ext x
simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, IicProdIoc_def, forall_const,
Subtype.forall, mem_Iic, Set.mem_prod, frestrictLe₂_apply, restrict₂, mem_Ioc]
refine ⟨fun h ↦ ⟨fun i hi ↦ ?_, fun i ⟨hi1, hi2⟩ ↦ ?_⟩, fun ⟨h1, h2⟩ i hi ↦ ?_⟩
· convert h i (hi.trans hab)
rw [dif_pos hi]
· convert h i hi2
rw [dif_neg (not_le.2 hi1)]
· split_ifs with hi3
· exact h1 i hi3
· exact h2 i ⟨not_le.1 hi3, hi⟩
end Lemmas |
.lake/packages/mathlib/Mathlib/Probability/Kernel/IonescuTulcea/Traj.lean | import Mathlib.MeasureTheory.Constructions.ProjectiveFamilyContent
import Mathlib.MeasureTheory.Function.FactorsThrough
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
import Mathlib.MeasureTheory.OuterMeasure.OfAddContent
import Mathlib.Probability.Kernel.Composition.IntegralCompProd
import Mathlib.Probability.Kernel.IonescuTulcea.PartialTraj
import Mathlib.Probability.Kernel.SetIntegral
/-!
# Ionescu-Tulcea theorem
This file proves the *Ionescu-Tulcea theorem*. The idea of the statement is as follows:
consider a family of kernels `κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))`.
One can interpret `κ n` as a kernel which takes as an input the trajectory of a point started in
`X 0` and moving `X 0 → X 1 → X 2 → ... → X n` and which outputs the distribution of the next
position of the point in `X (n + 1)`. If `a b : ℕ` and `a < b`, we can compose the kernels,
and `κ a ⊗ₖ κ (a + 1) ⊗ₖ ... ⊗ₖ κ b` will take the trajectory up to time `a` as input and outputs
the distribution of the trajectory on `X (a + 1) × ... × X (b + 1)`.
The Ionescu-Tulcea theorem tells us that these compositions can be extended into a
`Kernel (Π i : Iic a, X i) (Π n > a, X n)` which given the trajectory up to time `a` outputs
the distribution of the infinite trajectory started in `X (a + 1)`. In other words this theorem
makes sense of composing infinitely many kernels together.
In this file we construct this "limit" kernel given the family `κ`. More precisely, for any `a : ℕ`,
we construct the kernel `traj κ a : Kernel (Π i : Iic a, X i) (Π n, X n)`, which takes as input
the trajectory in `X 0 × ... × X a` and outputs the distribution of the whole trajectory. The name
`traj` thus stands for "trajectory". We build a kernel with output in `Π n, X n` instead of
`Π i > a, X i` to make manipulations easier. The first coordinates are deterministic.
We also provide tools to compute integrals against `traj κ a` and an expression for the conditional
expectation.
## Main definition
* `traj κ a`: a kernel from `Π i : Iic a, X i` to `Π n, X n` which takes as input a trajectory
up to time `a` and outputs the distribution of the trajectory obtained by iterating the kernels
`κ`. Its existence is given by the Ionescu-Tulcea theorem.
## Main statements
* `eq_traj`: Uniqueness of `traj`: to check that `η = traj κ a` it is enough to show that
the restriction of `η` to variables `≤ b` is `partialTraj κ a b`.
* `traj_comp_partialTraj`: Given the distribution up to time `a`, `partialTraj κ a b`
gives the distribution of the trajectory up to time `b`, and composing this with
`traj κ b` gives the distribution of the whole trajectory.
* `condExp_traj`: If `a ≤ b`, the conditional expectation of `f` with respect to `traj κ a`
given the information up to time `b` is obtained by integrating `f` against `traj κ b`.
## Implementation notes
The kernel `traj κ a` is built using the Carathéodory extension theorem. First we build a projective
family of measures using `inducedFamily` and `partialTraj κ a`. Then we build a
`MeasureTheory.AddContent` on `MeasureTheory.measurableCylinders` called `trajContent` using
`projectiveFamilyContent`. Finally we prove `trajContent_tendsto_zero` which implies the
`σ`-additivity of the content, allowing to turn it into a measure.
## References
We follow the proof of Theorem 8.24 in
[O. Kallenberg, *Foundations of Modern Probability*][kallenberg2021]. For a more detailed proof
in the case of constant kernels (i.e. measures),
see Proposition 10.6.1 in [D. L. Cohn, *Measure Theory*][cohn2013measure].
## Tags
Ionescu-Tulcea theorem
-/
open Filter Finset Function MeasurableEquiv MeasurableSpace MeasureTheory Preorder ProbabilityTheory
open scoped ENNReal Topology
variable {X : ℕ → Type*}
section castLemmas
private lemma Iic_pi_eq {a b : ℕ} (h : a = b) :
(Π i : Iic a, X i) = (Π i : Iic b, X i) := by cases h; rfl
private lemma cast_pi {s t : Set ℕ} (h : s = t) (x : (i : s) → X i) (i : t) :
cast (congrArg (fun u : Set ℕ ↦ (Π i : u, X i)) h) x i = x ⟨i.1, h.symm ▸ i.2⟩ := by
cases h; rfl
variable [∀ n, MeasurableSpace (X n)]
private lemma measure_cast {a b : ℕ} (h : a = b) (μ : (n : ℕ) → Measure (Π i : Iic n, X i)) :
(μ a).map (cast (Iic_pi_eq h)) = μ b := by
cases h
exact Measure.map_id
private lemma heq_measurableSpace_Iic_pi {a b : ℕ} (h : a = b) :
(inferInstance : MeasurableSpace (Π i : Iic a, X i)) ≍
(inferInstance : MeasurableSpace (Π i : Iic b, X i)) := by cases h; rfl
end castLemmas
section iterateInduction
/-- This function takes as input a tuple `(x_₀, ..., x_ₐ)` and `ind` a function which
given `(y_₀, ...,y_ₙ)` outputs `x_{n+1} : X (n + 1)`, and it builds an element of `Π n, X n`
by starting with `(x_₀, ..., x_ₐ)` and then iterating `ind`. -/
def iterateInduction {a : ℕ} (x : Π i : Iic a, X i)
(ind : (n : ℕ) → (Π i : Iic n, X i) → X (n + 1)) : Π n, X n
| 0 => x ⟨0, mem_Iic.2 <| zero_le a⟩
| k + 1 => if h : k + 1 ≤ a
then x ⟨k + 1, mem_Iic.2 h⟩
else ind k (fun i ↦ iterateInduction x ind i)
decreasing_by exact Nat.lt_succ.2 (mem_Iic.1 i.2)
lemma frestrictLe_iterateInduction {a : ℕ} (x : Π i : Iic a, X i)
(ind : (n : ℕ) → (Π i : Iic n, X i) → X (n + 1)) :
frestrictLe a (iterateInduction x ind) = x := by
ext i
simp only [frestrictLe_apply]
obtain ⟨(zero | j), hj⟩ := i <;> rw [iterateInduction]
rw [dif_pos (mem_Iic.1 hj)]
end iterateInduction
variable [∀ n, MeasurableSpace (X n)]
section ProjectiveFamily
namespace MeasureTheory
/-! ### Projective families indexed by `Finset ℕ` -/
variable {μ : (n : ℕ) → Measure (Π i : Iic n, X i)}
/-- To check that a measure `ν` is the projective limit of a projective family of measures indexed
by `Finset ℕ`, it is enough to check on intervals of the form `Iic n`, where `n` is larger than
a given integer. -/
theorem isProjectiveLimit_nat_iff' {μ : (I : Finset ℕ) → Measure (Π i : I, X i)}
(hμ : IsProjectiveMeasureFamily μ) (ν : Measure (Π n, X n)) (a : ℕ) :
IsProjectiveLimit ν μ ↔ ∀ ⦃n⦄, a ≤ n → ν.map (frestrictLe n) = μ (Iic n) := by
refine ⟨fun h n _ ↦ h (Iic n), fun h I ↦ ?_⟩
have := (I.subset_Iic_sup_id.trans (Iic_subset_Iic.2 (le_max_left (I.sup id) a)))
rw [← restrict₂_comp_restrict this, ← Measure.map_map, ← frestrictLe, h (le_max_right _ _), ← hμ]
all_goals fun_prop
/-- To check that a measure `ν` is the projective limit of a projective family of measures indexed
by `Finset ℕ`, it is enough to check on intervals of the form `Iic n`. -/
theorem isProjectiveLimit_nat_iff {μ : (I : Finset ℕ) → Measure (Π i : I, X i)}
(hμ : IsProjectiveMeasureFamily μ) (ν : Measure (Π n, X n)) :
IsProjectiveLimit ν μ ↔ ∀ n, ν.map (frestrictLe n) = μ (Iic n) := by
rw [isProjectiveLimit_nat_iff' hμ _ 0]
simp
variable (μ : (n : ℕ) → Measure (Π i : Iic n, X i))
/-- Given a family of measures `μ : (n : ℕ) → Measure (Π i : Iic n, X i)`, we can define a family
of measures indexed by `Finset ℕ` by projecting the measures. -/
noncomputable def inducedFamily (S : Finset ℕ) : Measure ((k : S) → X k) :=
(μ (S.sup id)).map (restrict₂ S.subset_Iic_sup_id)
instance [∀ n, SFinite (μ n)] (I : Finset ℕ) :
SFinite (inducedFamily μ I) := by rw [inducedFamily]; infer_instance
instance [∀ n, IsFiniteMeasure (μ n)] (I : Finset ℕ) :
IsFiniteMeasure (inducedFamily μ I) := by rw [inducedFamily]; infer_instance
instance [∀ n, IsZeroOrProbabilityMeasure (μ n)] (I : Finset ℕ) :
IsZeroOrProbabilityMeasure (inducedFamily μ I) := by rw [inducedFamily]; infer_instance
instance [∀ n, IsProbabilityMeasure (μ n)] (I : Finset ℕ) :
IsProbabilityMeasure (inducedFamily μ I) := by
rw [inducedFamily]
exact Measure.isProbabilityMeasure_map (measurable_restrict₂ _).aemeasurable
/-- Given a family of measures `μ : (n : ℕ) → Measure (Π i : Iic n, X i)`, the induced family
equals `μ` over the intervals `Iic n`. -/
theorem inducedFamily_Iic (n : ℕ) : inducedFamily μ (Iic n) = μ n := by
rw [inducedFamily, ← measure_cast (sup_Iic n) μ]
congr with x i
rw [restrict₂, cast_pi (by rw [sup_Iic n])]
/-- Given a family of measures `μ : (n : ℕ) → Measure (Π i : Iic n, X i)`, the induced family
will be projective only if `μ` is projective, in the sense that if `a ≤ b`, then projecting
`μ b` gives `μ a`. -/
theorem isProjectiveMeasureFamily_inducedFamily
(h : ∀ a b : ℕ, ∀ hab : a ≤ b, (μ b).map (frestrictLe₂ hab) = μ a) :
IsProjectiveMeasureFamily (inducedFamily μ) := by
intro I J hJI
have sls : J.sup id ≤ I.sup id := sup_mono hJI
simp only [inducedFamily]
rw [Measure.map_map, restrict₂_comp_restrict₂,
← restrict₂_comp_restrict₂ J.subset_Iic_sup_id (Iic_subset_Iic.2 sls), ← Measure.map_map,
← frestrictLe₂.eq_def sls, h (J.sup id) (I.sup id) sls]
all_goals fun_prop
end MeasureTheory
end ProjectiveFamily
variable {κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))} [∀ n, IsMarkovKernel (κ n)]
namespace ProbabilityTheory.Kernel
section definition
/-! ### Definition and basic properties of `traj` -/
variable (κ)
lemma isProjectiveMeasureFamily_partialTraj {a : ℕ} (x₀ : Π i : Iic a, X i) :
IsProjectiveMeasureFamily (inducedFamily (fun b ↦ partialTraj κ a b x₀)) :=
isProjectiveMeasureFamily_inducedFamily _
(fun _ _ ↦ partialTraj_map_frestrictLe₂_apply (κ := κ) x₀)
/-- Given a family of kernels `κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))`, and the
trajectory up to time `a` we can construct an additive content over cylinders. It corresponds
to composing the kernels, starting at time `a + 1`. -/
noncomputable def trajContent {a : ℕ} (x₀ : Π i : Iic a, X i) :
AddContent (measurableCylinders X) :=
projectiveFamilyContent (isProjectiveMeasureFamily_partialTraj κ x₀)
variable {κ}
/-- The `trajContent κ x₀` of a cylinder indexed by first coordinates is given by `partialTraj`. -/
theorem trajContent_cylinder {a b : ℕ} {S : Set (Π i : Iic b, X i)} (mS : MeasurableSet S)
(x₀ : Π i : Iic a, X i) :
trajContent κ x₀ (cylinder (Iic b) S) = partialTraj κ a b x₀ S := by
rw [trajContent, projectiveFamilyContent_cylinder _ mS, inducedFamily_Iic]
/-- The `trajContent` of a cylinder is equal to the integral of its indicator function against
`partialTraj`. -/
theorem trajContent_eq_lmarginalPartialTraj {b : ℕ} {S : Set (Π i : Iic b, X i)}
(mS : MeasurableSet S) (x₀ : Π n, X n) (a : ℕ) :
trajContent κ (frestrictLe a x₀) (cylinder (Iic b) S) =
lmarginalPartialTraj κ a b ((cylinder (Iic b) S).indicator 1) x₀ := by
rw [trajContent_cylinder mS, ← lintegral_indicator_one mS, lmarginalPartialTraj]
congr with x
apply Set.indicator_const_eq_indicator_const
rw [mem_cylinder]
congrm (fun i ↦ ?_) ∈ S
simp [updateFinset, i.2]
lemma trajContent_ne_top {a : ℕ} {x : Π i : Iic a, X i} {s : Set (Π n, X n)} :
trajContent κ x s ≠ ∞ :=
projectiveFamilyContent_ne_top (isProjectiveMeasureFamily_partialTraj κ x)
/-- This is an auxiliary result for `trajContent_tendsto_zero`. Consider `f` a sequence of bounded
measurable functions such that `f n` depends only on the first coordinates up to `a n`.
Assume that when integrating `f n` against `partialTraj (k + 1) (a n)`, one gets a non-increasing
sequence of functions which converges to `l`.
Assume then that there exists `ε` and `y : Π i : Iic k, X i` such that
when integrating `f n` against `partialTraj k (a n) y`, you get something at least
`ε` for all `n`. Then there exists `z` such that this remains true when integrating
`f` against `partialTraj (k + 1) (a n) (update y (k + 1) z)`. -/
theorem le_lmarginalPartialTraj_succ {f : ℕ → (Π n, X n) → ℝ≥0∞} {a : ℕ → ℕ}
(hcte : ∀ n, DependsOn (f n) (Iic (a n))) (mf : ∀ n, Measurable (f n))
{bound : ℝ≥0∞} (fin_bound : bound ≠ ∞) (le_bound : ∀ n x, f n x ≤ bound) {k : ℕ}
(anti : ∀ x, Antitone (fun n ↦ lmarginalPartialTraj κ (k + 1) (a n) (f n) x))
{l : (Π n, X n) → ℝ≥0∞}
(htendsto : ∀ x, Tendsto (fun n ↦ lmarginalPartialTraj κ (k + 1) (a n) (f n) x) atTop (𝓝 (l x)))
(ε : ℝ≥0∞) (y : Π i : Iic k, X i)
(hpos : ∀ x n, ε ≤ lmarginalPartialTraj κ k (a n) (f n) (updateFinset x (Iic k) y)) :
∃ z, ∀ x n,
ε ≤ lmarginalPartialTraj κ (k + 1) (a n) (f n)
(update (updateFinset x (Iic k) y) (k + 1) z) := by
have _ n : Nonempty (X n) := by
induction n using Nat.case_strong_induction_on with
| hz => exact ⟨y ⟨0, mem_Iic.2 (zero_le _)⟩⟩
| hi m hm =>
have : Nonempty (Π i : Iic m, X i) :=
⟨fun i ↦ @Classical.ofNonempty _ (hm i.1 (mem_Iic.1 i.2))⟩
exact ProbabilityMeasure.nonempty ⟨κ m Classical.ofNonempty, inferInstance⟩
-- `Fₙ` is the integral of `fₙ` from time `k + 1` to `aₙ`.
let F n : (Π n, X n) → ℝ≥0∞ := lmarginalPartialTraj κ (k + 1) (a n) (f n)
-- `Fₙ` converges to `l` by hypothesis.
have tendstoF x : Tendsto (F · x) atTop (𝓝 (l x)) := htendsto x
-- Integrating `fₙ` between time `k` and `aₙ` is the same as integrating
-- `Fₙ` between time `k` and time `k + 1`.
have f_eq x n : lmarginalPartialTraj κ k (a n) (f n) x =
lmarginalPartialTraj κ k (k + 1) (F n) x := by
simp_rw [F]
obtain h | h | h := lt_trichotomy (k + 1) (a n)
· rw [← lmarginalPartialTraj_self k.le_succ h.le (mf n)]
· rw [← h, lmarginalPartialTraj_le _ le_rfl (mf n)]
· rw [lmarginalPartialTraj_le _ _ (mf n), (hcte n).lmarginalPartialTraj_of_le _ (mf n),
(hcte n).lmarginalPartialTraj_of_le _ (mf n)]
all_goals cutsat
-- `F` is also a bounded sequence.
have F_le n x : F n x ≤ bound := by
simpa [F, lmarginalPartialTraj] using lintegral_le_const (ae_of_all _ fun z ↦ le_bound _ _)
-- By dominated convergence, the integral of `fₙ` between time `k` and time `a n` converges
-- to the integral of `l` between time `k` and time `k + 1`.
have tendsto_int x : Tendsto (fun n ↦ lmarginalPartialTraj κ k (a n) (f n) x) atTop
(𝓝 (lmarginalPartialTraj κ k (k + 1) l x)) := by
simp_rw [f_eq, lmarginalPartialTraj]
exact tendsto_lintegral_of_dominated_convergence (fun _ ↦ bound)
(fun n ↦ (measurable_lmarginalPartialTraj _ _ (mf n)).comp measurable_updateFinset)
(fun n ↦ Eventually.of_forall <| fun y ↦ F_le n _)
(by simp [fin_bound]) (Eventually.of_forall (fun _ ↦ tendstoF _))
-- By hypothesis, we have `ε ≤ lmarginalPartialTraj κ k (k + 1) (F n) (updateFinset x _ y)`,
-- so this is also true for `l`.
have ε_le_lint x : ε ≤ lmarginalPartialTraj κ k (k + 1) l (updateFinset x _ y) :=
ge_of_tendsto (tendsto_int _) (by simp [hpos])
let x_ : Π n, X n := Classical.ofNonempty
-- We now have that the integral of `l` with respect to a probability measure is greater than `ε`,
-- therefore there exists `x` such that `ε ≤ l(y, x)`.
obtain ⟨x, hx⟩ : ∃ x, ε ≤ l (update (updateFinset x_ _ y) (k + 1) x) := by
have : ∫⁻ x, l (update (updateFinset x_ _ y) (k + 1) x) ∂(κ k y) ≠ ∞ :=
ne_top_of_le_ne_top fin_bound <| lintegral_le_const <| ae_of_all _
fun y ↦ le_of_tendsto' (tendstoF _) <| fun _ ↦ F_le _ _
obtain ⟨x, hx⟩ := exists_lintegral_le this
refine ⟨x, (ε_le_lint x_).trans ?_⟩
rwa [lmarginalPartialTraj_succ, frestrictLe_updateFinset]
exact ENNReal.measurable_of_tendsto (by fun_prop) (tendsto_pi_nhds.2 htendsto)
refine ⟨x, fun x' n ↦ ?_⟩
-- As `F` is a non-increasing sequence, we have `ε ≤ Fₙ(y, x)` for any `n`.
have := le_trans hx ((anti _).le_of_tendsto (tendstoF _) n)
-- This part below is just to say that this is true for any `x : (i : ι) → X i`,
-- as `Fₙ` technically depends on all the variables, but really depends only on the first `k + 1`.
convert this using 1
refine (hcte n).dependsOn_lmarginalPartialTraj _ (mf n) fun i hi ↦ ?_
simp only [update, updateFinset, mem_Iic]
split_ifs with h1 h2 <;> try rfl
rw [mem_coe, mem_Iic] at hi
cutsat
/-- This is the key theorem to prove the existence of the `traj`:
the `trajContent` of a decreasing sequence of cylinders with empty intersection
converges to `0`.
This implies the `σ`-additivity of `trajContent`
(see `addContent_iUnion_eq_sum_of_tendsto_zero`),
which allows to extend it to the `σ`-algebra by Carathéodory's theorem. -/
theorem trajContent_tendsto_zero {A : ℕ → Set (Π n, X n)}
(A_mem : ∀ n, A n ∈ measurableCylinders X) (A_anti : Antitone A) (A_inter : ⋂ n, A n = ∅)
{p : ℕ} (x₀ : Π i : Iic p, X i) :
Tendsto (fun n ↦ trajContent κ x₀ (A n)) atTop (𝓝 0) := by
have _ n : Nonempty (X n) := by
induction n using Nat.case_strong_induction_on with
| hz => exact ⟨x₀ ⟨0, mem_Iic.2 (zero_le _)⟩⟩
| hi m hm =>
have : Nonempty (Π i : Iic m, X i) :=
⟨fun i ↦ @Classical.ofNonempty _ (hm i.1 (mem_Iic.1 i.2))⟩
exact ProbabilityMeasure.nonempty ⟨κ m Classical.ofNonempty, inferInstance⟩
-- `Aₙ` is a cylinder, it can be written as `cylinder (Iic (a n)) Sₙ`.
have A_cyl n : ∃ a S, MeasurableSet S ∧ A n = cylinder (Iic a) S := by
simpa [measurableCylinders_nat] using A_mem n
choose a S mS A_eq using A_cyl
-- We write `χₙ` for the indicator function of `Aₙ`.
let χ n := (A n).indicator (1 : (Π n, X n) → ℝ≥0∞)
-- `χₙ` is measurable.
have mχ n : Measurable (χ n) := by
simp_rw [χ, A_eq]
exact (measurable_indicator_const_iff 1).2 <| (mS n).cylinder
-- `χₙ` only depends on the first coordinates.
have χ_dep n : DependsOn (χ n) (Iic (a n)) := by
simp_rw [χ, A_eq]
exact dependsOn_cylinder_indicator_const ..
-- Therefore its integral against `partialTraj κ k (a n)` is constant.
have lma_const x y n :
lmarginalPartialTraj κ p (a n) (χ n) (updateFinset x _ x₀) =
lmarginalPartialTraj κ p (a n) (χ n) (updateFinset y _ x₀) := by
refine (χ_dep n).dependsOn_lmarginalPartialTraj p (mχ n) fun i hi ↦ ?_
rw [mem_coe, mem_Iic] at hi
simp [updateFinset, hi]
-- As `(Aₙ)` is non-increasing, so is `(χₙ)`.
have χ_anti : Antitone χ := fun m n hmn y ↦ by
apply Set.indicator_le fun a ha ↦ ?_
simp [χ, A_anti hmn ha]
-- Integrating `χₙ` further than the last coordinate it depends on does nothing.
-- This is used to then show that the integral of `χₙ` from time `k` is non-increasing.
have lma_inv k M n (h : a n ≤ M) :
lmarginalPartialTraj κ k M (χ n) = lmarginalPartialTraj κ k (a n) (χ n) :=
(χ_dep n).lmarginalPartialTraj_const_right (mχ n) h le_rfl
-- the integral of `χₙ` from time `k` is non-increasing.
have anti_lma k x : Antitone fun n ↦ lmarginalPartialTraj κ k (a n) (χ n) x := by
intro m n hmn
simp only
rw [← lma_inv k ((a n).max (a m)) n (le_max_left _ _),
← lma_inv k ((a n).max (a m)) m (le_max_right _ _)]
exact lmarginalPartialTraj_mono _ _ (χ_anti hmn) _
-- Therefore it converges to some function `lₖ`.
have this k x : ∃ l, Tendsto (fun n ↦ lmarginalPartialTraj κ k (a n) (χ n) x) atTop (𝓝 l) := by
obtain h | h := tendsto_of_antitone (anti_lma k x)
· rw [OrderBot.atBot_eq] at h
exact ⟨0, h.mono_right <| pure_le_nhds 0⟩
· exact h
choose l hl using this
-- `lₚ` is constant because it is the limit of constant functions: we call it `ε`.
have l_const x y : l p (updateFinset x _ x₀) = l p (updateFinset y _ x₀) := by
have := hl p (updateFinset x _ x₀)
simp_rw [lma_const x y] at this
exact tendsto_nhds_unique this (hl p _)
obtain ⟨ε, hε⟩ : ∃ ε, ∀ x, l p (updateFinset x _ x₀) = ε :=
⟨l p (updateFinset Classical.ofNonempty _ x₀), fun x ↦ l_const _ _⟩
-- As the sequence is decreasing, `ε ≤ ∫ χₙ`.
have hpos x n : ε ≤ lmarginalPartialTraj κ p (a n) (χ n) (updateFinset x _ x₀) :=
hε x ▸ ((anti_lma p _).le_of_tendsto (hl p _)) n
-- Also, the indicators are bounded by `1`.
have χ_le n x : χ n x ≤ 1 := by
apply Set.indicator_le
simp
-- We have all the conditions to apply `le_lmarginalPartialTraj_succ`.
-- This allows us to recursively build a sequence `z` with the following property:
-- for any `k ≥ p` and `n`, integrating `χ n` from time `k` to time `a n`
-- with the trajectory up to `k` being equal to `z` gives something greater than `ε`.
choose! ind hind using
fun k y h ↦ le_lmarginalPartialTraj_succ χ_dep mχ (by simp : (1 : ℝ≥0∞) ≠ ∞)
χ_le (anti_lma (k + 1)) (hl (k + 1)) ε y h
let z := iterateInduction x₀ ind
have main k (hk : p ≤ k) : ∀ x n,
ε ≤ lmarginalPartialTraj κ k (a n) (χ n) (updateFinset x _ (frestrictLe k z)) := by
induction k, hk using Nat.le_induction with
| base => exact fun x n ↦ by simpa [z, frestrictLe_iterateInduction] using hpos x n
| succ k hn h =>
intro x n
convert hind k (fun i ↦ z i.1) h x n
ext i
simp only [updateFinset, mem_Iic, frestrictLe_apply, dite_eq_ite, update, z]
split_ifs with h1 h2 h3 h4 h5
any_goals cutsat
cases h2
rw [iterateInduction, dif_neg (by cutsat)]
-- We now want to prove that the integral of `χₙ`, which is equal to the `trajContent`
-- of `Aₙ`, converges to `0`.
have aux x n :
trajContent κ x₀ (A n) = lmarginalPartialTraj κ p (a n) (χ n) (updateFinset x _ x₀) := by
simp_rw [χ, A_eq]
nth_rw 1 [← frestrictLe_updateFinset x x₀]
exact trajContent_eq_lmarginalPartialTraj (mS n) ..
simp_rw [aux z]
convert hl p _
rw [hε]
-- Which means that we want to prove that `ε = 0`. But if `ε > 0`, then for any `n`,
-- choosing `k > aₙ` we get `ε ≤ χₙ(z₀, ..., z_{aₙ})` and therefore `z ∈ Aₙ`.
-- This contradicts the fact that `(Aₙ)` has an empty intersection.
by_contra!
have mem n : z ∈ A n := by
have : 0 < χ n z := by
rw [← lmarginalPartialTraj_le κ (le_max_right p (a n)) (mχ n),
← updateFinset_frestrictLe (a := a n) z]
simpa using lt_of_lt_of_le this.symm.bot_lt (main _ (le_max_left _ _) z n)
exact Set.mem_of_indicator_ne_zero (ne_of_lt this).symm
exact (A_inter ▸ Set.mem_iInter.2 mem).elim
variable (κ)
/-- The `trajContent` is sigma-subadditive. -/
theorem isSigmaSubadditive_trajContent {a : ℕ} (x₀ : Π i : Iic a, X i) :
(trajContent κ x₀).IsSigmaSubadditive := by
refine isSigmaSubadditive_of_addContent_iUnion_eq_tsum
isSetRing_measurableCylinders (fun f hf hf_Union hf' ↦ ?_)
refine addContent_iUnion_eq_sum_of_tendsto_zero isSetRing_measurableCylinders
(trajContent κ x₀) (fun _ _ ↦ trajContent_ne_top) ?_ hf hf_Union hf'
exact fun s hs anti_s inter_s ↦ trajContent_tendsto_zero hs anti_s inter_s x₀
/-- This function is the kernel given by the Ionescu-Tulcea theorem. It is shown below that it
is measurable and turned into a true kernel in `Kernel.traj`. -/
noncomputable def trajFun (a : ℕ) (x₀ : Π i : Iic a, X i) : Measure (Π n, X n) :=
(trajContent κ x₀).measure isSetSemiring_measurableCylinders generateFrom_measurableCylinders.ge
(isSigmaSubadditive_trajContent κ x₀)
theorem isProbabilityMeasure_trajFun (a : ℕ) (x₀ : Π i : Iic a, X i) :
IsProbabilityMeasure (trajFun κ a x₀) where
measure_univ := by
rw [← cylinder_univ (Iic 0), trajFun, AddContent.measure_eq, trajContent_cylinder .univ,
measure_univ]
· exact generateFrom_measurableCylinders.symm
· exact cylinder_mem_measurableCylinders _ _ .univ
theorem isProjectiveLimit_trajFun (a : ℕ) (x₀ : Π i : Iic a, X i) :
IsProjectiveLimit (trajFun κ a x₀) (inducedFamily (fun n ↦ partialTraj κ a n x₀)) := by
refine isProjectiveLimit_nat_iff (isProjectiveMeasureFamily_partialTraj κ x₀) _ |>.2 fun n ↦ ?_
ext s ms
rw [Measure.map_apply (measurable_frestrictLe n) ms, trajFun, AddContent.measure_eq, trajContent,
projectiveFamilyContent_congr _ (frestrictLe n ⁻¹' s) rfl ms]
· exact generateFrom_measurableCylinders.symm
· exact cylinder_mem_measurableCylinders _ _ ms
variable {κ} in
theorem measurable_trajFun (a : ℕ) : Measurable (trajFun κ a) := by
apply Measure.measurable_of_measurable_coe
refine MeasurableSpace.induction_on_inter
(C := fun t ht ↦ Measurable (fun x₀ ↦ trajFun κ a x₀ t))
(s := measurableCylinders X) generateFrom_measurableCylinders.symm
isPiSystem_measurableCylinders (by simp) (fun t ht ↦ ?cylinder) (fun t mt ht ↦ ?compl)
(fun f disf mf hf ↦ ?union)
· obtain ⟨N, S, mS, t_eq⟩ : ∃ N S, MeasurableSet S ∧ t = cylinder (Iic N) S := by
simpa [measurableCylinders_nat] using ht
simp_rw [trajFun, AddContent.measure_eq _ _ generateFrom_measurableCylinders.symm _ ht,
trajContent, projectiveFamilyContent_congr _ t t_eq mS, inducedFamily]
refine Measure.measurable_measure.1 ?_ _ mS
exact (Measure.measurable_map _ (measurable_restrict₂ _)).comp (measurable _)
· have := isProbabilityMeasure_trajFun κ a
simpa [measure_compl mt (measure_ne_top _ _)] using Measurable.const_sub ht _
· simpa [measure_iUnion disf mf] using Measurable.ennreal_tsum hf
/-- *Ionescu-Tulcea Theorem* : Given a family of kernels `κ n` taking variables in `Iic n` with
value in `X (n + 1)`, the kernel `traj κ a` takes a variable `x` depending on the
variables `i ≤ a` and associates to it a kernel on trajectories depending on all variables,
where the entries with index `≤ a` are those of `x`, and then one follows iteratively the
kernels `κ a`, then `κ (a + 1)`, and so on.
The fact that such a kernel exists on infinite trajectories is not obvious, and is the content of
the Ionescu-Tulcea theorem. -/
noncomputable def traj (a : ℕ) : Kernel (Π i : Iic a, X i) (Π n, X n) where
toFun := trajFun κ a
measurable' := measurable_trajFun a
end definition
section basic
lemma traj_apply (a : ℕ) (x : Π i : Iic a, X i) : traj κ a x = trajFun κ a x := rfl
instance (a : ℕ) : IsMarkovKernel (traj κ a) := ⟨fun _ ↦ isProbabilityMeasure_trajFun ..⟩
lemma traj_map_frestrictLe (a b : ℕ) : (traj κ a).map (frestrictLe b) = partialTraj κ a b := by
ext x
rw [map_apply, traj_apply, frestrictLe, isProjectiveLimit_trajFun, inducedFamily_Iic]
fun_prop
lemma traj_map_frestrictLe_apply (a b : ℕ) (x : Π i : Iic a, X i) :
(traj κ a x).map (frestrictLe b) = partialTraj κ a b x := by
rw [← map_apply _ (measurable_frestrictLe b), traj_map_frestrictLe]
lemma traj_map_frestrictLe_of_le {a b : ℕ} (hab : a ≤ b) :
(traj κ b).map (frestrictLe a) =
deterministic (frestrictLe₂ hab) (measurable_frestrictLe₂ _) := by
rw [traj_map_frestrictLe, partialTraj_le]
variable (κ)
/-- To check that `η = traj κ a` it is enough to show that the restriction of `η` to variables `≤ b`
is `partialTraj κ a b` for any `b ≥ n`. -/
theorem eq_traj' {a : ℕ} (n : ℕ) (η : Kernel (Π i : Iic a, X i) (Π n, X n))
(hη : ∀ b ≥ n, η.map (frestrictLe b) = partialTraj κ a b) : η = traj κ a := by
ext x : 1
refine ((isProjectiveLimit_trajFun _ _ _).unique ?_).symm
rw [isProjectiveLimit_nat_iff' _ _ n]
· intro k hk
rw [inducedFamily_Iic, ← map_apply _ (measurable_frestrictLe k), hη k hk]
· exact isProjectiveMeasureFamily_partialTraj κ x
/-- To check that `η = traj κ a` it is enough to show that the restriction of `η` to variables `≤ b`
is `partialTraj κ a b`. -/
theorem eq_traj {a : ℕ} (η : Kernel (Π i : Iic a, X i) (Π n, X n))
(hη : ∀ b, η.map (frestrictLe b) = partialTraj κ a b) : η = traj κ a :=
eq_traj' κ 0 η fun b _ ↦ hη b
variable {κ}
/-- Given the distribution up to tome `a`, `partialTraj κ a b` gives the distribution
of the trajectory up to time `b`, and composing this with `traj κ b` gives the distribution
of the whole trajectory. -/
theorem traj_comp_partialTraj {a b : ℕ} (hab : a ≤ b) :
(traj κ b) ∘ₖ (partialTraj κ a b) = traj κ a := by
refine eq_traj _ _ fun n ↦ ?_
rw [map_comp, traj_map_frestrictLe, partialTraj_comp_partialTraj' _ hab]
/-- This theorem shows that `traj κ n` is, up to an equivalence, the product of
a deterministic kernel with another kernel. This is an intermediate result to compute integrals
with respect to this kernel. -/
theorem traj_eq_prod (a : ℕ) :
traj κ a = (Kernel.id ×ₖ (traj κ a).map (Set.Ioi a).restrict).map (IicProdIoi a) := by
refine (eq_traj' _ (a + 1) _ fun b hb ↦ ?_).symm
rw [← map_comp_right]
conv_lhs => enter [2]; change (IicProdIoc a b) ∘
(Prod.map id (fun x i ↦ x ⟨i.1, Set.mem_Ioi.2 (mem_Ioc.1 i.2).1⟩))
· rw [map_comp_right, ← map_prod_map, ← map_comp_right]
· conv_lhs => enter [1, 2, 2]; change (Ioc a b).restrict
rw [← restrict₂_comp_restrict Ioc_subset_Iic_self, ← frestrictLe, map_comp_right,
traj_map_frestrictLe, map_id, ← partialTraj_eq_prod]
all_goals fun_prop
all_goals fun_prop
all_goals fun_prop
theorem traj_map_updateFinset {n : ℕ} (x : Π i : Iic n, X i) :
(traj κ n x).map (updateFinset · (Iic n) x) = traj κ n x := by
nth_rw 2 [traj_eq_prod]
have : (updateFinset · _ x) = IicProdIoi n ∘ (Prod.mk x) ∘ (Set.Ioi n).restrict := by
ext; simp [IicProdIoi, updateFinset]
rw [this, ← Function.comp_assoc, ← Measure.map_map, ← Measure.map_map, map_apply, prod_apply,
map_apply, id_apply, Measure.dirac_prod]
all_goals fun_prop
end basic
section integral
/-! ### Integrals and `traj` -/
theorem lintegral_traj₀ {a : ℕ} (x₀ : Π i : Iic a, X i) {f : (Π n, X n) → ℝ≥0∞}
(mf : AEMeasurable f (traj κ a x₀)) :
∫⁻ x, f x ∂traj κ a x₀ = ∫⁻ x, f (updateFinset x (Iic a) x₀) ∂traj κ a x₀ := by
nth_rw 1 [← traj_map_updateFinset, MeasureTheory.lintegral_map']
· convert mf
exact traj_map_updateFinset x₀
· exact measurable_updateFinset_left.aemeasurable
theorem lintegral_traj {a : ℕ} (x₀ : Π i : Iic a, X i) {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) :
∫⁻ x, f x ∂traj κ a x₀ = ∫⁻ x, f (updateFinset x (Iic a) x₀) ∂traj κ a x₀ :=
lintegral_traj₀ x₀ mf.aemeasurable
variable {E : Type*} [NormedAddCommGroup E]
theorem integrable_traj {a b : ℕ} (hab : a ≤ b) {f : (Π n, X n) → E}
(x₀ : Π i : Iic a, X i) (i_f : Integrable f (traj κ a x₀)) :
∀ᵐ x ∂traj κ a x₀, Integrable f (traj κ b (frestrictLe b x)) := by
rw [← traj_comp_partialTraj hab, integrable_comp_iff] at i_f
· apply ae_of_ae_map (p := fun x ↦ Integrable f (traj κ b x))
· fun_prop
· convert i_f.1
rw [← traj_map_frestrictLe, Kernel.map_apply _ (measurable_frestrictLe _)]
· exact i_f.aestronglyMeasurable
theorem aestronglyMeasurable_traj {a b : ℕ} (hab : a ≤ b) {f : (Π n, X n) → E}
{x₀ : Π i : Iic a, X i} (hf : AEStronglyMeasurable f (traj κ a x₀)) :
∀ᵐ x ∂partialTraj κ a b x₀, AEStronglyMeasurable f (traj κ b x) := by
rw [← traj_comp_partialTraj hab] at hf
exact hf.comp
variable [NormedSpace ℝ E]
/-- When computing `∫ x, f x ∂traj κ n x₀`, because the trajectory up to time `n` is
determined by `x₀` we can replace `x` by `updateFinset x (Iic a) x₀`. -/
theorem integral_traj {a : ℕ} (x₀ : Π i : Iic a, X i) {f : (Π n, X n) → E}
(mf : AEStronglyMeasurable f (traj κ a x₀)) :
∫ x, f x ∂traj κ a x₀ = ∫ x, f (updateFinset x (Iic a) x₀) ∂traj κ a x₀ := by
nth_rw 1 [← traj_map_updateFinset, integral_map]
· exact measurable_updateFinset_left.aemeasurable
· convert mf
rw [traj_map_updateFinset]
lemma partialTraj_compProd_traj {a b : ℕ} (hab : a ≤ b) (u : Π i : Iic a, X i) :
(partialTraj κ a b u) ⊗ₘ (traj κ b) = (traj κ a u).map (fun x ↦ (frestrictLe b x, x)) := by
ext s ms
rw [Measure.map_apply, Measure.compProd_apply, ← traj_comp_partialTraj hab, comp_apply']
· congr 1 with x
rw [← traj_map_updateFinset, Measure.map_apply, Measure.map_apply]
· congr 1 with y
simp only [Set.mem_preimage]
congrm (fun i ↦ ?_, fun i ↦ ?_) ∈ s <;> simp [updateFinset]
any_goals fun_prop
all_goals exact ms.preimage (by fun_prop)
any_goals exact ms.preimage (by fun_prop)
fun_prop
theorem integral_traj_partialTraj' {a b : ℕ} (hab : a ≤ b) {x₀ : Π i : Iic a, X i}
{f : (Π i : Iic b, X i) → (Π n : ℕ, X n) → E}
(hf : Integrable f.uncurry ((partialTraj κ a b x₀) ⊗ₘ (traj κ b))) :
∫ x, ∫ y, f x y ∂traj κ b x ∂partialTraj κ a b x₀ =
∫ x, f (frestrictLe b x) x ∂traj κ a x₀ := by
have hf' := hf
rw [partialTraj_compProd_traj hab] at hf'
simp_rw [← uncurry_apply_pair f, ← Measure.integral_compProd hf,
partialTraj_compProd_traj hab, integral_map (by fun_prop) hf'.1]
theorem integral_traj_partialTraj {a b : ℕ} (hab : a ≤ b) {x₀ : Π i : Iic a, X i}
{f : (Π n : ℕ, X n) → E} (hf : Integrable f (traj κ a x₀)) :
∫ x, ∫ y, f y ∂traj κ b x ∂partialTraj κ a b x₀ = ∫ x, f x ∂traj κ a x₀ := by
apply integral_traj_partialTraj' hab
rw [← traj_comp_partialTraj hab, comp_apply, ← Measure.snd_compProd] at hf
exact hf.comp_measurable measurable_snd
theorem setIntegral_traj_partialTraj' {a b : ℕ} (hab : a ≤ b) {u : (Π i : Iic a, X i)}
{f : (Π i : Iic b, X i) → (Π n : ℕ, X n) → E}
(hf : Integrable f.uncurry ((partialTraj κ a b u) ⊗ₘ (traj κ b)))
{A : Set (Π i : Iic b, X i)} (hA : MeasurableSet A) :
∫ x in A, ∫ y, f x y ∂traj κ b x ∂partialTraj κ a b u =
∫ y in frestrictLe b ⁻¹' A, f (frestrictLe b y) y ∂traj κ a u := by
rw [← integral_integral_indicator _ _ _ hA, integral_traj_partialTraj' hab]
· simp_rw [← Set.indicator_comp_right, ← integral_indicator (measurable_frestrictLe b hA)]
rfl
convert hf.indicator (hA.prod .univ)
ext ⟨x, y⟩
by_cases hx : x ∈ A <;> simp [uncurry_def, hx]
theorem setIntegral_traj_partialTraj {a b : ℕ} (hab : a ≤ b) {x₀ : (Π i : Iic a, X i)}
{f : (Π n : ℕ, X n) → E} (hf : Integrable f (traj κ a x₀))
{A : Set (Π i : Iic b, X i)} (hA : MeasurableSet A) :
∫ x in A, ∫ y, f y ∂traj κ b x ∂partialTraj κ a b x₀ =
∫ y in frestrictLe b ⁻¹' A, f y ∂traj κ a x₀ := by
refine setIntegral_traj_partialTraj' hab ?_ hA
rw [← traj_comp_partialTraj hab, comp_apply, ← Measure.snd_compProd] at hf
exact hf.comp_measurable measurable_snd
variable [CompleteSpace E]
open Filtration
theorem condExp_traj {a b : ℕ} (hab : a ≤ b) {x₀ : Π i : Iic a, X i}
{f : (Π n, X n) → E} (i_f : Integrable f (traj κ a x₀)) :
(traj κ a x₀)[f|piLE b] =ᵐ[traj κ a x₀]
fun x ↦ ∫ y, f y ∂traj κ b (frestrictLe b x) := by
have i_f' : Integrable (fun x ↦ ∫ y, f y ∂(traj κ b) x)
(((traj κ a) x₀).map (frestrictLe b)) := by
rw [← map_apply _ (measurable_frestrictLe _), traj_map_frestrictLe _ _]
rw [← traj_comp_partialTraj hab] at i_f
exact i_f.integral_comp
refine ae_eq_condExp_of_forall_setIntegral_eq (piLE.le _) i_f
(fun s _ _ ↦ i_f'.comp_aemeasurable (measurable_frestrictLe b).aemeasurable |>.integrableOn)
?_ ?_ |>.symm <;> rw [piLE_eq_comap_frestrictLe]
· rintro - ⟨t, mt, rfl⟩ -
simp_rw [Function.comp_apply]
rw [← setIntegral_map mt i_f'.1, ← map_apply, traj_map_frestrictLe,
setIntegral_traj_partialTraj hab i_f mt]
all_goals fun_prop
· exact (i_f'.1.comp_ae_measurable' (measurable_frestrictLe b).aemeasurable)
theorem condExp_traj' {a b c : ℕ} (hab : a ≤ b) (hbc : b ≤ c)
(x₀ : Π i : Iic a, X i) (f : (Π n, X n) → E) :
(traj κ a x₀)[f|piLE b] =ᵐ[traj κ a x₀]
fun x ↦ ∫ y, ((traj κ a x₀)[f|piLE c]) (updateFinset x (Iic c) y)
∂partialTraj κ b c (frestrictLe b x) := by
have i_cf : Integrable ((traj κ a x₀)[f|piLE c]) (traj κ a x₀) :=
integrable_condExp
have mcf : StronglyMeasurable ((traj κ a x₀)[f|piLE c]) :=
stronglyMeasurable_condExp.mono (piLE.le c)
filter_upwards [piLE.condExp_condExp f hbc, condExp_traj hab i_cf] with x h1 h2
rw [← h1, h2, ← traj_map_frestrictLe, Kernel.map_apply, integral_map]
· congr with y
apply stronglyMeasurable_condExp.dependsOn_of_piLE
simp only [Set.mem_Iic, updateFinset, mem_Iic, frestrictLe_apply, dite_eq_ite]
exact fun i hi ↦ (if_pos hi).symm
any_goals fun_prop
exact (mcf.comp_measurable measurable_updateFinset).aestronglyMeasurable
end integral
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/IonescuTulcea/PartialTraj.lean | import Mathlib.MeasureTheory.MeasurableSpace.PreorderRestrict
import Mathlib.Probability.Kernel.Composition.Prod
import Mathlib.Probability.Kernel.IonescuTulcea.Maps
/-!
# Consecutive composition of kernels
This file is the first step towards Ionescu-Tulcea theorem, which allows for instance to construct
the product of an infinite family of probability measures. The idea of the statement is as follows:
consider a family of kernels `κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))`.
One can interpret `κ n` as a kernel which takes as an input the trajectory of a point started in
`X 0` and moving `X 0 → X 1 → X 2 → ... → X n` and which outputs the distribution of the next
position of the point in `X (n + 1)`. If `a b : ℕ` and `a < b`, we can compose the kernels,
and `κ a ⊗ₖ κ (a + 1) ⊗ₖ ... ⊗ₖ κ b` takes the trajectory up to time `a` as input and outputs
the distribution of the trajectory in `X (a + 1) × ... × X (b + 1)`.
The Ionescu-Tulcea theorem then tells us that these compositions can be extended into a kernel
`η : Kernel (Π i : Iic a, X i) → Π n > a, X n` which given the trajectory up to time `a` outputs
the distribution of the infinite trajectory started in `X (a + 1)`. In other words this theorem
makes sense of composing infinitely many kernels together.
To be able to even state the theorem we want to take the composition-product
(see `ProbabilityTheory.Kernel.compProd`) of consecutive kernels.
This however is not straightforward.
Consider `n : ℕ`. We cannot write `(κ n) ⊗ₖ (κ (n + 1))` directly, we need to first
introduce an equivalence to see `κ (n + 1)` as a kernel with codomain
`(Π i : Iic n, X i) × X (n + 1)`, and we get a `Kernel (Π i : Iic n, X i) (X (n + 1) × (X (n + 2))`.
However we want to do multiple composition at ones, i.e. write
`(κ n) ⊗ₖ ... ⊗ₖ (κ m)` for `n < m`. This requires even more equivalences to make sense of, and at
the end of the day we get kernels which still cannot be composed together.
To tackle this issue, we decide here to only consider kernels of the form
`Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)`. In other words these kernels take as input
a trajectory up to time `a` and output the distribution of the full trajectory up to time `b`.
This is captured in the definition `partialTraj κ a b`
(`partialTraj` stands for "partial trajectory").
The advantage of this approach is that it allows us to write for instance
`partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c` (see `partialTraj_comp_partialTraj`.)
In this file we therefore define this family of kernels and prove some properties of it.
In particular we provide at the end of the file some results to compute the integral of a function
against `partialTraj κ a b`, taking inspiration from `MeasureTheory.lmarginal`.
## Main definitions
* `partialTraj κ a b`: Given the trajectory of a point up to time `a`, returns the distribution
of the trajectory up to time `b`.
* `lmarginalPartialTraj κ a b f`: The integral of `f` against `partialTraj κ a b`.
This is essentially the integral of `f` against `κ (a + 1) ⊗ₖ ... ⊗ₖ κ b` but seen as depending
on all the variables, mimicking `MeasureTheory.lmarginal`. This allows to write
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f)`.
## Main statements
* `partialTraj_comp_partialTraj`: if `a ≤ b` and `b ≤ c` then
`partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c`.
* `lmarginalPartialTraj_self` : if `a ≤ b` and `b ≤ c` then
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f) = lmarginalPartialTraj κ a c`.
## Tags
Ionescu-Tulcea theorem, composition of kernels
-/
open Finset Function MeasureTheory Preorder ProbabilityTheory
open scoped ENNReal
variable {X : ℕ → Type*} {mX : ∀ n, MeasurableSpace (X n)} {a b c : ℕ}
{κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))}
section partialTraj
/-! ### Definition of `partialTraj` -/
namespace ProbabilityTheory.Kernel
open MeasurableEquiv
variable (κ) in
/-- Given a family of kernels `κ n` from `X 0 × ... × X n` to `X (n + 1)` for all `n`,
construct a kernel from `X 0 × ... × X a` to `X 0 × ... × X b` by iterating `κ`.
The idea is that the input is some trajectory up to time `a`, and the output is the distribution
of the trajectory up to time `b`. In particular if `b ≤ a`, this is just a deterministic kernel
(see `partialTraj_le`). The name `partialTraj` stands for "partial trajectory".
This kernel can be extended into a kernel with codomain `Π n, X n` via the Ionescu-Tulcea theorem.
-/
noncomputable def partialTraj (a b : ℕ) : Kernel (Π i : Iic a, X i) (Π i : Iic b, X i) :=
if h : b ≤ a then deterministic (frestrictLe₂ h) (measurable_frestrictLe₂ h)
else @Nat.leRec a (fun b _ ↦ Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)) Kernel.id
(fun k _ κ_k ↦ ((Kernel.id ×ₖ ((κ k).map (piSingleton k))) ∘ₖ κ_k).map (IicProdIoc k (k + 1)))
b (Nat.le_of_not_ge h)
section Basic
/-- If `b ≤ a`, given the trajectory up to time `a`, the trajectory up to time `b` is
deterministic and is equal to the restriction of the trajectory up to time `a`. -/
lemma partialTraj_le (hba : b ≤ a) :
partialTraj κ a b = deterministic (frestrictLe₂ hba) (measurable_frestrictLe₂ _) := by
rw [partialTraj, dif_pos hba]
@[simp]
lemma partialTraj_self (a : ℕ) : partialTraj κ a a = Kernel.id := by rw [partialTraj_le le_rfl]; rfl
@[simp]
lemma partialTraj_zero :
partialTraj κ a 0 = deterministic (frestrictLe₂ (zero_le a)) (measurable_frestrictLe₂ _) := by
rw [partialTraj_le (zero_le a)]
lemma partialTraj_le_def (hab : a ≤ b) : partialTraj κ a b =
@Nat.leRec a (fun b _ ↦ Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)) Kernel.id
(fun k _ κ_k ↦ ((Kernel.id ×ₖ ((κ k).map (piSingleton k))) ∘ₖ κ_k).map (IicProdIoc k (k + 1)))
b hab := by
obtain rfl | hab := eq_or_lt_of_le hab
· simp
· rw [partialTraj, dif_neg (not_le.2 hab)]
lemma partialTraj_succ_of_le (hab : a ≤ b) : partialTraj κ a (b + 1) =
((Kernel.id ×ₖ ((κ b).map (piSingleton b))) ∘ₖ partialTraj κ a b).map
(IicProdIoc b (b + 1)) := by
rw [partialTraj, dif_neg (by cutsat)]
induction b, hab using Nat.le_induction with
| base => simp
| succ k hak hk => rw [Nat.leRec_succ, ← partialTraj_le_def]; cutsat
instance (a b : ℕ) : IsSFiniteKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsFiniteKernel (κ n)] (a b : ℕ) : IsFiniteKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsZeroOrMarkovKernel (κ n)] (a b : ℕ) :
IsZeroOrMarkovKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsMarkovKernel (κ n)] (a b : ℕ) :
IsMarkovKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak =>
rw [partialTraj_succ_of_le hak]
have := IsMarkovKernel.map (κ k) (piSingleton k).measurable
exact IsMarkovKernel.map _ measurable_IicProdIoc
· rw [partialTraj_le hba]; infer_instance
lemma partialTraj_succ_self (a : ℕ) :
partialTraj κ a (a + 1) =
(Kernel.id ×ₖ ((κ a).map (piSingleton a))).map (IicProdIoc a (a + 1)) := by
rw [partialTraj_succ_of_le le_rfl, partialTraj_self, comp_id]
lemma partialTraj_succ_eq_comp (hab : a ≤ b) :
partialTraj κ a (b + 1) = partialTraj κ b (b + 1) ∘ₖ partialTraj κ a b := by
rw [partialTraj_succ_self, ← map_comp, partialTraj_succ_of_le hab]
/-- Given the trajectory up to time `a`, `partialTraj κ a b` gives the distribution of
the trajectory up to time `b`. Then plugging this into `partialTraj κ b c` gives
the distribution of the trajectory up to time `c`. -/
theorem partialTraj_comp_partialTraj (hab : a ≤ b) (hbc : b ≤ c) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
induction c, hbc using Nat.le_induction with
| base => simp
| succ k h hk => rw [partialTraj_succ_eq_comp h, comp_assoc, hk,
← partialTraj_succ_eq_comp (hab.trans h)]
/-- This is a specific lemma used in the proof of `partialTraj_eq_prod`. It is the main rewrite step
and stating it as a separate lemma avoids using extensionality of kernels, which would generate
a lot of measurability subgoals. -/
private lemma fst_prod_comp_id_prod {X Y Z : Type*} {mX : MeasurableSpace X}
{mY : MeasurableSpace Y} {mZ : MeasurableSpace Z} (κ : Kernel X Y) [IsSFiniteKernel κ]
(η : Kernel (X × Y) Z) [IsSFiniteKernel η] :
((deterministic Prod.fst measurable_fst) ×ₖ η) ∘ₖ (Kernel.id ×ₖ κ) =
Kernel.id ×ₖ (η ∘ₖ (Kernel.id ×ₖ κ)) := by
ext x s ms
simp_rw [comp_apply' _ _ _ ms, lintegral_id_prod (Kernel.measurable_coe _ ms),
deterministic_prod_apply' _ _ _ ms, id_prod_apply' _ _ ms,
comp_apply' _ _ _ (measurable_prodMk_left ms),
lintegral_id_prod (η.measurable_coe (measurable_prodMk_left ms))]
/-- This is a technical lemma saying that `partialTraj κ a b` consists of two independent parts, the
first one being the identity. It allows to compute integrals. -/
lemma partialTraj_eq_prod [∀ n, IsSFiniteKernel (κ n)] (a b : ℕ) :
partialTraj κ a b =
(Kernel.id ×ₖ (partialTraj κ a b).map (restrict₂ Ioc_subset_Iic_self)).map
(IicProdIoc a b) := by
obtain hba | hab := le_total b a
· rw [partialTraj_le hba, IicProdIoc_le hba, map_comp_right, ← fst_eq, deterministic_map,
fst_prod, id_map]
all_goals fun_prop
induction b, hab using Nat.le_induction with
| base =>
ext1 x
rw [partialTraj_self, id_map, map_apply, prod_apply, IicProdIoc_self, ← Measure.fst,
Measure.fst_prod]
all_goals fun_prop
| succ k h hk =>
have : (IicProdIoc (X := X) k (k + 1)) ∘ (Prod.map (IicProdIoc a k) id) =
(IicProdIoc (h.trans k.le_succ) ∘ (Prod.map id (IocProdIoc a k (k + 1)))) ∘
prodAssoc := by
ext x i
simp only [IicProdIoc_def, MeasurableEquiv.IicProdIoc, MeasurableEquiv.coe_mk,
Equiv.coe_fn_mk, Function.comp_apply, Prod.map_fst, Prod.map_snd, id_eq,
Nat.succ_eq_add_one, IocProdIoc]
split_ifs <;> try rfl
omega
nth_rw 1 [← partialTraj_comp_partialTraj h k.le_succ, hk, partialTraj_succ_self, comp_map,
comap_map_comm, comap_prod, id_comap, ← id_map, map_prod_eq, ← map_comp_right, this,
map_comp_right, id_prod_eq, prodAssoc_prod, map_comp_right, ← map_prod_map, map_id,
← map_comp, map_apply_eq_iff_map_symm_apply_eq, fst_prod_comp_id_prod, ← map_comp_right,
← coe_IicProdIoc (h.trans k.le_succ), symm_comp_self, map_id,
deterministic_congr IicProdIoc_comp_restrict₂.symm, ← deterministic_comp_deterministic,
comp_deterministic_eq_comap, ← comap_prod, ← map_comp, ← comp_map, ← hk,
← partialTraj_comp_partialTraj h k.le_succ, partialTraj_succ_self, map_comp, map_comp,
← map_comp_right, ← id_map, map_prod_eq, ← map_comp_right]
· rfl
all_goals fun_prop
variable [∀ n, IsMarkovKernel (κ n)]
lemma partialTraj_succ_map_frestrictLe₂ (a b : ℕ) :
(partialTraj κ a (b + 1)).map (frestrictLe₂ b.le_succ) = partialTraj κ a b := by
obtain hab | hba := le_or_gt a b
· have := IsMarkovKernel.map (κ b) (piSingleton b).measurable
rw [partialTraj_succ_eq_comp hab, map_comp, partialTraj_succ_self, ← map_comp_right,
frestrictLe₂_comp_IicProdIoc, ← fst_eq, fst_prod, id_comp]
all_goals fun_prop
· rw [partialTraj_le (Nat.succ_le.2 hba), partialTraj_le hba.le, deterministic_map]
· rfl
· fun_prop
/-- If we restrict the distribution of the trajectory up to time `c` to times `≤ b` we get
the trajectory up to time `b`. -/
theorem partialTraj_map_frestrictLe₂ (a : ℕ) (hbc : b ≤ c) :
(partialTraj κ a c).map (frestrictLe₂ hbc) = partialTraj κ a b := by
induction c, hbc using Nat.le_induction with
| base => exact map_id ..
| succ k h hk =>
rw [← hk, ← frestrictLe₂_comp_frestrictLe₂ h k.le_succ, map_comp_right,
partialTraj_succ_map_frestrictLe₂]
all_goals fun_prop
lemma partialTraj_map_frestrictLe₂_apply (x₀ : Π i : Iic a, X i) (hbc : b ≤ c) :
(partialTraj κ a c x₀).map (frestrictLe₂ hbc) = partialTraj κ a b x₀ := by
rw [← map_apply _ (by fun_prop), partialTraj_map_frestrictLe₂]
/-- Same as `partialTraj_comp_partialTraj` but only assuming `a ≤ b`. It requires Markov kernels. -/
lemma partialTraj_comp_partialTraj' (c : ℕ) (hab : a ≤ b) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
obtain hbc | hcb := le_total b c
· rw [partialTraj_comp_partialTraj hab hbc]
· rw [partialTraj_le hcb, deterministic_comp_eq_map, partialTraj_map_frestrictLe₂]
/-- Same as `partialTraj_comp_partialTraj` but only assuming `b ≤ c`. It requires Markov kernels. -/
lemma partialTraj_comp_partialTraj'' {b c : ℕ} (hcb : c ≤ b) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
rw [partialTraj_le hcb, deterministic_comp_eq_map, partialTraj_map_frestrictLe₂]
end Basic
section lmarginalPartialTraj
/-! ### Integrating against `partialTraj` -/
variable (κ)
/-- This function computes the integral of a function `f` against `partialTraj`,
and allows to view it as a function depending on all the variables.
This is inspired by `MeasureTheory.lmarginal`, to be able to write
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f) = lmarginalPartialTraj κ a c`. -/
noncomputable def lmarginalPartialTraj (a b : ℕ) (f : (Π n, X n) → ℝ≥0∞) (x₀ : Π n, X n) : ℝ≥0∞ :=
∫⁻ z : (i : Iic b) → X i, f (updateFinset x₀ _ z) ∂(partialTraj κ a b (frestrictLe a x₀))
/-- If `b ≤ a`, then integrating `f` against `partialTraj κ a b` does nothing. -/
lemma lmarginalPartialTraj_le (hba : b ≤ a) {f : (Π n, X n) → ℝ≥0∞} (mf : Measurable f) :
lmarginalPartialTraj κ a b f = f := by
ext x₀
rw [lmarginalPartialTraj, partialTraj_le hba, Kernel.lintegral_deterministic']
· congr with i
simp [updateFinset]
· exact mf.comp measurable_updateFinset
variable {κ}
lemma lmarginalPartialTraj_mono (a b : ℕ) {f g : (Π n, X n) → ℝ≥0∞} (hfg : f ≤ g) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a b f x₀ ≤ lmarginalPartialTraj κ a b g x₀ :=
lintegral_mono fun _ ↦ hfg _
/-- Integrating `f` against `partialTraj κ a b x` is the same as integrating only over the variables
from `x_{a+1}` to `x_b`. -/
lemma lmarginalPartialTraj_eq_lintegral_map [∀ n, IsSFiniteKernel (κ n)] {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a b f x₀ =
∫⁻ x : (Π i : Ioc a b, X i), f (updateFinset x₀ _ x)
∂(partialTraj κ a b).map (restrict₂ Ioc_subset_Iic_self) (frestrictLe a x₀) := by
nth_rw 1 [lmarginalPartialTraj, partialTraj_eq_prod, lintegral_map, lintegral_id_prod]
· congrm ∫⁻ _, f (fun i ↦ ?_) ∂_
simp only [updateFinset, mem_Iic, IicProdIoc_def,
frestrictLe_apply, mem_Ioc]
split_ifs <;> try rfl
all_goals cutsat
all_goals fun_prop
/-- Integrating `f` against `partialTraj κ a (a + 1)` is the same as integrating against `κ a`. -/
lemma lmarginalPartialTraj_succ [∀ n, IsSFiniteKernel (κ n)] (a : ℕ)
{f : (Π n, X n) → ℝ≥0∞} (mf : Measurable f) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a (a + 1) f x₀ =
∫⁻ x : X (a + 1), f (update x₀ _ x) ∂κ a (frestrictLe a x₀) := by
rw [lmarginalPartialTraj, partialTraj_succ_self, lintegral_map, lintegral_id_prod, lintegral_map]
· congrm ∫⁻ x, f (fun i ↦ ?_) ∂_
simp only [updateFinset, mem_Iic, IicProdIoc_def, frestrictLe_apply, piSingleton,
MeasurableEquiv.coe_mk, Equiv.coe_fn_mk, update]
split_ifs with h1 h2 h3 <;> try rfl
all_goals cutsat
all_goals fun_prop
@[measurability, fun_prop]
lemma measurable_lmarginalPartialTraj (a b : ℕ) {f : (Π n, X n) → ℝ≥0∞} (hf : Measurable f) :
Measurable (lmarginalPartialTraj κ a b f) := by
unfold lmarginalPartialTraj
let g : ((i : Iic b) → X i) × (Π n, X n) → ℝ≥0∞ := fun c ↦ f (updateFinset c.2 _ c.1)
let η : Kernel (Π n, X n) (Π i : Iic b, X i) :=
(partialTraj κ a b).comap (frestrictLe a) (measurable_frestrictLe _)
change Measurable fun x₀ ↦ ∫⁻ z : (i : Iic b) → X i, g (z, x₀) ∂η x₀
refine Measurable.lintegral_kernel_prod_left' <| hf.comp ?_
simp only [updateFinset, measurable_pi_iff]
intro i
by_cases h : i ∈ Iic b <;> simp only [h, ↓reduceDIte] <;> fun_prop
/-- Integrating `f` against `partialTraj κ a b` and then against `partialTraj κ b c` is the same
as integrating `f` against `partialTraj κ a c`. -/
theorem lmarginalPartialTraj_self (hab : a ≤ b) (hbc : b ≤ c)
{f : (Π n, X n) → ℝ≥0∞} (hf : Measurable f) :
lmarginalPartialTraj κ a b (lmarginalPartialTraj κ b c f) = lmarginalPartialTraj κ a c f := by
ext x₀
obtain rfl | hab := eq_or_lt_of_le hab <;> obtain rfl | hbc := eq_or_lt_of_le hbc
· rw [lmarginalPartialTraj_le κ le_rfl (measurable_lmarginalPartialTraj _ _ hf)]
· rw [lmarginalPartialTraj_le κ le_rfl (measurable_lmarginalPartialTraj _ _ hf)]
· rw [lmarginalPartialTraj_le κ le_rfl hf]
simp_rw [lmarginalPartialTraj, frestrictLe, restrict_updateFinset,
updateFinset_updateFinset_of_subset (Iic_subset_Iic.2 hbc.le)]
rw [← lintegral_comp, partialTraj_comp_partialTraj hab.le hbc.le]
fun_prop
end lmarginalPartialTraj
end ProbabilityTheory.Kernel
open ProbabilityTheory Kernel
namespace DependsOn
/-! ### Lemmas about `lmarginalPartialTraj` and `DependsOn` -/
/-- If `f` only depends on the variables up to rank `a` and `a ≤ b`, integrating `f` against
`partialTraj κ b c` does nothing. -/
theorem lmarginalPartialTraj_of_le [∀ n, IsMarkovKernel (κ n)] (c : ℕ) {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (hf : DependsOn f (Iic a)) (hab : a ≤ b) :
lmarginalPartialTraj κ b c f = f := by
ext x
rw [lmarginalPartialTraj_eq_lintegral_map mf]
refine @lintegral_eq_const _ _ _ ?_ _ _ (ae_of_all _ fun y ↦ hf fun i hi ↦ ?_)
· refine @IsMarkovKernel.isProbabilityMeasure _ _ _ _ _ ?_ _
exact IsMarkovKernel.map _ (by fun_prop)
· simp_all only [coe_Iic, Set.mem_Iic, Function.updateFinset, mem_Ioc, dite_eq_right_iff]
cutsat
/-- If `f` only depends on the variables uo to rank `a`, integrating beyond rank `a` is the same
as integrating up to rank `a`. -/
theorem lmarginalPartialTraj_const_right [∀ n, IsMarkovKernel (κ n)] {d : ℕ} {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (hf : DependsOn f (Iic a)) (hac : a ≤ c) (had : a ≤ d) :
lmarginalPartialTraj κ b c f = lmarginalPartialTraj κ b d f := by
wlog hcd : c ≤ d generalizing c d
· rw [this had hac (le_of_not_ge hcd)]
obtain hbc | hcb := le_total b c
· rw [← lmarginalPartialTraj_self hbc hcd mf, hf.lmarginalPartialTraj_of_le d mf hac]
· rw [hf.lmarginalPartialTraj_of_le c mf (hac.trans hcb),
hf.lmarginalPartialTraj_of_le d mf (hac.trans hcb)]
/-- If `f` only depends on variables up to rank `b`, its integral from `a` to `b` only depends on
variables up to rank `a`. -/
theorem dependsOn_lmarginalPartialTraj [∀ n, IsSFiniteKernel (κ n)] (a : ℕ) {f : (Π n, X n) → ℝ≥0∞}
(hf : DependsOn f (Iic b)) (mf : Measurable f) :
DependsOn (lmarginalPartialTraj κ a b f) (Iic a) := by
intro x y hxy
obtain hba | hab := le_total b a
· rw [Kernel.lmarginalPartialTraj_le κ hba mf]
exact hf fun i hi ↦ hxy i (Iic_subset_Iic.2 hba hi)
rw [lmarginalPartialTraj_eq_lintegral_map mf, lmarginalPartialTraj_eq_lintegral_map mf]
congrm ∫⁻ z : _, ?_ ∂(partialTraj κ a b).map _ (fun i ↦ ?_)
· exact hxy i.1 i.2
· refine hf.updateFinset _ ?_
rwa [← coe_sdiff, Iic_diff_Ioc_self_of_le hab]
end DependsOn
end partialTraj |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/CDFToKernel.lean | import Mathlib.MeasureTheory.Function.AEEqOfIntegral
import Mathlib.Probability.Kernel.Composition.CompProd
import Mathlib.Probability.Kernel.Disintegration.MeasurableStieltjes
/-!
# Building a Markov kernel from a conditional cumulative distribution function
Let `κ : Kernel α (β × ℝ)` and `ν : Kernel α β` be two finite kernels.
A function `f : α × β → StieltjesFunction` is called a conditional kernel CDF of `κ` with respect
to `ν` if it is measurable, tends to 0 at -∞ and to 1 at +∞ for all `p : α × β`,
`fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all measurable
sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a).real (s ×ˢ Iic x)`.
From such a function with property `hf : IsCondKernelCDF f κ ν`, we can build a `Kernel (α × β) ℝ`
denoted by `hf.toKernel f` such that `κ = ν ⊗ₖ hf.toKernel f`.
## Main definitions
Let `κ : Kernel α (β × ℝ)` and `ν : Kernel α β`.
* `ProbabilityTheory.IsCondKernelCDF`: a function `f : α × β → StieltjesFunction` is called
a conditional kernel CDF of `κ` with respect to `ν` if it is measurable, tends to 0 at -∞ and
to 1 at +∞ for all `p : α × β`, if `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and
`x : ℝ` and for all measurable sets `s : Set β`,
`∫ b in s, f (a, b) x ∂(ν a) = (κ a).real (s ×ˢ Iic x)`.
* `ProbabilityTheory.IsCondKernelCDF.toKernel`: from a function `f : α × β → StieltjesFunction`
with the property `hf : IsCondKernelCDF f κ ν`, build a `Kernel (α × β) ℝ` such that
`κ = ν ⊗ₖ hf.toKernel f`.
* `ProbabilityTheory.IsRatCondKernelCDF`: a function `f : α × β → ℚ → ℝ` is called a rational
conditional kernel CDF of `κ` with respect to `ν` if is measurable and satisfies the same
integral conditions as in the definition of `IsCondKernelCDF`, and the `ℚ → ℝ` function `f (a, b)`
satisfies the properties of a Stieltjes function for `(ν a)`-almost all `b : β`.
## Main statements
* `ProbabilityTheory.isCondKernelCDF_stieltjesOfMeasurableRat`: if `f : α × β → ℚ → ℝ` has the
property `IsRatCondKernelCDF`, then `stieltjesOfMeasurableRat f` is a function
`α × β → StieltjesFunction` with the property `IsCondKernelCDF`.
* `ProbabilityTheory.compProd_toKernel`: for `hf : IsCondKernelCDF f κ ν`, `ν ⊗ₖ hf.toKernel f = κ`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{κ : Kernel α (β × ℝ)} {ν : Kernel α β}
section stieltjesOfMeasurableRat
variable {f : α × β → ℚ → ℝ}
/-- a function `f : α × β → ℚ → ℝ` is called a rational conditional kernel CDF of `κ` with respect
to `ν` if is measurable, if `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ`
and for all measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a).real (s ×ˢ Iic x)`.
Also the `ℚ → ℝ` function `f (a, b)` should satisfy the properties of a Stieltjes function for
`(ν a)`-almost all `b : β`. -/
structure IsRatCondKernelCDF (f : α × β → ℚ → ℝ) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) :
Prop where
measurable : Measurable f
isRatStieltjesPoint_ae (a : α) : ∀ᵐ b ∂(ν a), IsRatStieltjesPoint f (a, b)
integrable (a : α) (q : ℚ) : Integrable (fun b ↦ f (a, b) q) (ν a)
setIntegral (a : α) {s : Set β} (_hs : MeasurableSet s) (q : ℚ) :
∫ b in s, f (a, b) q ∂(ν a) = (κ a).real (s ×ˢ Iic (q : ℝ))
lemma IsRatCondKernelCDF.mono (hf : IsRatCondKernelCDF f κ ν) (a : α) :
∀ᵐ b ∂(ν a), Monotone (f (a, b)) := by
filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.mono
lemma IsRatCondKernelCDF.tendsto_atTop_one (hf : IsRatCondKernelCDF f κ ν) (a : α) :
∀ᵐ b ∂(ν a), Tendsto (f (a, b)) atTop (𝓝 1) := by
filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.tendsto_atTop_one
lemma IsRatCondKernelCDF.tendsto_atBot_zero (hf : IsRatCondKernelCDF f κ ν) (a : α) :
∀ᵐ b ∂(ν a), Tendsto (f (a, b)) atBot (𝓝 0) := by
filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.tendsto_atBot_zero
lemma IsRatCondKernelCDF.iInf_rat_gt_eq (hf : IsRatCondKernelCDF f κ ν) (a : α) :
∀ᵐ b ∂(ν a), ∀ q, ⨅ r : Ioi q, f (a, b) r = f (a, b) q := by
filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.iInf_rat_gt_eq
lemma stieltjesOfMeasurableRat_ae_eq (hf : IsRatCondKernelCDF f κ ν) (a : α) (q : ℚ) :
(fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) q) =ᵐ[ν a] fun b ↦ f (a, b) q := by
filter_upwards [hf.isRatStieltjesPoint_ae a] with a ha
rw [stieltjesOfMeasurableRat_eq, toRatCDF_of_isRatStieltjesPoint ha]
lemma setIntegral_stieltjesOfMeasurableRat_rat (hf : IsRatCondKernelCDF f κ ν) (a : α) (q : ℚ)
{s : Set β} (hs : MeasurableSet s) :
∫ b in s, stieltjesOfMeasurableRat f hf.measurable (a, b) q ∂(ν a)
= (κ a).real (s ×ˢ Iic (q : ℝ)) := by
rw [setIntegral_congr_ae hs (g := fun b ↦ f (a, b) q) ?_, hf.setIntegral a hs]
filter_upwards [stieltjesOfMeasurableRat_ae_eq hf a q] with b hb using fun _ ↦ hb
lemma setLIntegral_stieltjesOfMeasurableRat_rat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (q : ℚ) {s : Set β} (hs : MeasurableSet s) :
∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) q) ∂(ν a)
= κ a (s ×ˢ Iic (q : ℝ)) := by
rw [← ofReal_integral_eq_lintegral_ofReal]
· rw [setIntegral_stieltjesOfMeasurableRat_rat hf a q hs, ofReal_measureReal]
· refine Integrable.restrict ?_
rw [integrable_congr (stieltjesOfMeasurableRat_ae_eq hf a q)]
exact hf.integrable a q
· exact ae_of_all _ (fun x ↦ stieltjesOfMeasurableRat_nonneg _ _ _)
lemma setLIntegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) :
∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a)
= κ a (s ×ˢ Iic x) := by
-- We have the result for `x : ℚ` thanks to `setLIntegral_stieltjesOfMeasurableRat_rat`.
-- We use a monotone convergence argument to extend it to the reals.
by_cases hρ_zero : (ν a).restrict s = 0
· rw [hρ_zero, lintegral_zero_measure]
have ⟨q, hq⟩ := exists_rat_gt x
suffices κ a (s ×ˢ Iic (q : ℝ)) = 0 by
symm
refine measure_mono_null (fun p ↦ ?_) this
simp only [mem_prod, mem_Iic, and_imp]
exact fun h1 h2 ↦ ⟨h1, h2.trans hq.le⟩
suffices (κ a).real (s ×ˢ Iic (q : ℝ)) = 0 by
rw [measureReal_eq_zero_iff] at this
simpa [measure_ne_top] using this
rw [← hf.setIntegral a hs q]
simp [hρ_zero]
have h : ∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a)
= ∫⁻ b in s, ⨅ r : { r' : ℚ // x < r' },
ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) r) ∂(ν a) := by
congr with b : 1
simp_rw [← measure_stieltjesOfMeasurableRat_Iic]
rw [← Monotone.measure_iInter]
· congr with y : 1
simp only [mem_Iic, mem_iInter, Subtype.forall]
refine ⟨fun h a ha ↦ h.trans ?_, fun h ↦ ?_⟩
· exact mod_cast ha.le
· refine le_of_forall_lt_rat_imp_le fun q hq ↦ h q ?_
exact mod_cast hq
· exact fun r r' hrr' ↦ Iic_subset_Iic.mpr <| mod_cast hrr'
· exact fun _ ↦ nullMeasurableSet_Iic
· obtain ⟨q, hq⟩ := exists_rat_gt x
exact ⟨⟨q, hq⟩, measure_ne_top _ _⟩
have h_nonempty : Nonempty { r' : ℚ // x < ↑r' } := by
obtain ⟨r, hrx⟩ := exists_rat_gt x
exact ⟨⟨r, hrx⟩⟩
rw [h, lintegral_iInf_directed_of_measurable hρ_zero fun q : { r' : ℚ // x < ↑r' } ↦ ?_]
rotate_left
· intro b
rw [setLIntegral_stieltjesOfMeasurableRat_rat hf a _ hs]
exact measure_ne_top _ _
· refine Monotone.directed_ge fun i j hij b ↦ ?_
simp_rw [← measure_stieltjesOfMeasurableRat_Iic]
refine measure_mono (Iic_subset_Iic.mpr ?_)
exact mod_cast hij
· refine Measurable.ennreal_ofReal ?_
exact (measurable_stieltjesOfMeasurableRat hf.measurable _).comp measurable_prodMk_left
simp_rw [setLIntegral_stieltjesOfMeasurableRat_rat hf _ _ hs]
rw [← Monotone.measure_iInter]
· rw [← prod_iInter]
congr with y
simp only [mem_iInter, mem_Iic, Subtype.forall]
exact ⟨le_of_forall_lt_rat_imp_le, fun hyx q hq ↦ hyx.trans hq.le⟩
· exact fun i j hij ↦ prod_mono_right (by gcongr)
· exact fun i ↦ (hs.prod measurableSet_Iic).nullMeasurableSet
· exact ⟨h_nonempty.some, measure_ne_top _ _⟩
lemma lintegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (x : ℝ) :
∫⁻ b, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a)
= κ a (univ ×ˢ Iic x) := by
rw [← setLIntegral_univ, setLIntegral_stieltjesOfMeasurableRat hf _ _ MeasurableSet.univ]
lemma integrable_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (x : ℝ) :
Integrable (fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) x) (ν a) := by
have : (fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) x)
= fun b ↦ (ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x)).toReal := by
ext t
rw [ENNReal.toReal_ofReal]
exact stieltjesOfMeasurableRat_nonneg _ _ _
rw [this]
refine integrable_toReal_of_lintegral_ne_top ?_ ?_
· refine (Measurable.ennreal_ofReal ?_).aemeasurable
exact (measurable_stieltjesOfMeasurableRat hf.measurable x).comp measurable_prodMk_left
· rw [lintegral_stieltjesOfMeasurableRat hf]
exact measure_ne_top _ _
lemma setIntegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) :
∫ b in s, stieltjesOfMeasurableRat f hf.measurable (a, b) x ∂(ν a)
= (κ a).real (s ×ˢ Iic x) := by
rw [← ENNReal.ofReal_eq_ofReal_iff, ofReal_measureReal]
rotate_left
· exact setIntegral_nonneg hs (fun _ _ ↦ stieltjesOfMeasurableRat_nonneg _ _ _)
· exact ENNReal.toReal_nonneg
rw [ofReal_integral_eq_lintegral_ofReal, setLIntegral_stieltjesOfMeasurableRat hf _ _ hs]
· exact (integrable_stieltjesOfMeasurableRat hf _ _).restrict
· exact ae_of_all _ (fun _ ↦ stieltjesOfMeasurableRat_nonneg _ _ _)
lemma integral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν)
(a : α) (x : ℝ) :
∫ b, stieltjesOfMeasurableRat f hf.measurable (a, b) x ∂(ν a)
= (κ a).real (univ ×ˢ Iic x) := by
rw [← setIntegral_univ, setIntegral_stieltjesOfMeasurableRat hf _ _ MeasurableSet.univ]
end stieltjesOfMeasurableRat
section isRatCondKernelCDFAux
variable {f : α × β → ℚ → ℝ}
/-- This property implies `IsRatCondKernelCDF`. The measurability, integrability and integral
conditions are the same, but the limit properties of `IsRatCondKernelCDF` are replaced by
limits of integrals. -/
structure IsRatCondKernelCDFAux (f : α × β → ℚ → ℝ) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) :
Prop where
measurable : Measurable f
mono' (a : α) {q r : ℚ} (_hqr : q ≤ r) : ∀ᵐ c ∂(ν a), f (a, c) q ≤ f (a, c) r
nonneg' (a : α) (q : ℚ) : ∀ᵐ c ∂(ν a), 0 ≤ f (a, c) q
le_one' (a : α) (q : ℚ) : ∀ᵐ c ∂(ν a), f (a, c) q ≤ 1
/- Same as `Tendsto (fun q : ℚ ↦ ∫ c, f (a, c) q ∂(ν a)) atBot (𝓝 0)` but slightly easier
to prove in the current applications of this definition (some integral convergence lemmas
currently apply only to `ℕ`, not `ℚ`) -/
tendsto_integral_of_antitone (a : α) (seq : ℕ → ℚ) (_hs : Antitone seq)
(_hs_tendsto : Tendsto seq atTop atBot) :
Tendsto (fun m ↦ ∫ c, f (a, c) (seq m) ∂(ν a)) atTop (𝓝 0)
/- Same as `Tendsto (fun q : ℚ ↦ ∫ c, f (a, c) q ∂(ν a)) atTop (𝓝 ((ν a).real univ))` but
slightly easier to prove in the current applications of this definition (some integral convergence
lemmas currently apply only to `ℕ`, not `ℚ`) -/
tendsto_integral_of_monotone (a : α) (seq : ℕ → ℚ) (_hs : Monotone seq)
(_hs_tendsto : Tendsto seq atTop atTop) :
Tendsto (fun m ↦ ∫ c, f (a, c) (seq m) ∂(ν a)) atTop (𝓝 ((ν a).real univ))
integrable (a : α) (q : ℚ) : Integrable (fun c ↦ f (a, c) q) (ν a)
setIntegral (a : α) {A : Set β} (_hA : MeasurableSet A) (q : ℚ) :
∫ c in A, f (a, c) q ∂(ν a) = (κ a).real (A ×ˢ Iic ↑q)
lemma IsRatCondKernelCDFAux.measurable_right (hf : IsRatCondKernelCDFAux f κ ν) (a : α) (q : ℚ) :
Measurable (fun t ↦ f (a, t) q) := by
let h := hf.measurable
rw [measurable_pi_iff] at h
exact (h q).comp measurable_prodMk_left
lemma IsRatCondKernelCDFAux.mono (hf : IsRatCondKernelCDFAux f κ ν) (a : α) :
∀ᵐ c ∂(ν a), Monotone (f (a, c)) := by
unfold Monotone
simp_rw [ae_all_iff]
exact fun _ _ hqr ↦ hf.mono' a hqr
lemma IsRatCondKernelCDFAux.nonneg (hf : IsRatCondKernelCDFAux f κ ν) (a : α) :
∀ᵐ c ∂(ν a), ∀ q, 0 ≤ f (a, c) q := ae_all_iff.mpr <| hf.nonneg' a
lemma IsRatCondKernelCDFAux.le_one (hf : IsRatCondKernelCDFAux f κ ν) (a : α) :
∀ᵐ c ∂(ν a), ∀ q, f (a, c) q ≤ 1 := ae_all_iff.mpr <| hf.le_one' a
lemma IsRatCondKernelCDFAux.tendsto_zero_of_antitone (hf : IsRatCondKernelCDFAux f κ ν)
[IsFiniteKernel ν] (a : α) (seq : ℕ → ℚ) (hseq : Antitone seq)
(hseq_tendsto : Tendsto seq atTop atBot) :
∀ᵐ c ∂(ν a), Tendsto (fun m ↦ f (a, c) (seq m)) atTop (𝓝 0) := by
refine tendsto_of_integral_tendsto_of_antitone ?_ (integrable_const _) ?_ ?_ ?_
· exact fun n ↦ hf.integrable a (seq n)
· rw [integral_zero]
exact hf.tendsto_integral_of_antitone a seq hseq hseq_tendsto
· filter_upwards [hf.mono a] with t ht using fun n m hnm ↦ ht (hseq hnm)
· filter_upwards [hf.nonneg a] with c hc using fun i ↦ hc (seq i)
lemma IsRatCondKernelCDFAux.tendsto_one_of_monotone (hf : IsRatCondKernelCDFAux f κ ν)
[IsFiniteKernel ν] (a : α) (seq : ℕ → ℚ) (hseq : Monotone seq)
(hseq_tendsto : Tendsto seq atTop atTop) :
∀ᵐ c ∂(ν a), Tendsto (fun m ↦ f (a, c) (seq m)) atTop (𝓝 1) := by
refine tendsto_of_integral_tendsto_of_monotone ?_ (integrable_const _) ?_ ?_ ?_
· exact fun n ↦ hf.integrable a (seq n)
· rw [MeasureTheory.integral_const, smul_eq_mul, mul_one]
exact hf.tendsto_integral_of_monotone a seq hseq hseq_tendsto
· filter_upwards [hf.mono a] with t ht using fun n m hnm ↦ ht (hseq hnm)
· filter_upwards [hf.le_one a] with c hc using fun i ↦ hc (seq i)
lemma IsRatCondKernelCDFAux.tendsto_atTop_one (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν]
(a : α) :
∀ᵐ t ∂(ν a), Tendsto (f (a, t)) atTop (𝓝 1) := by
suffices ∀ᵐ t ∂(ν a), Tendsto (fun (n : ℕ) ↦ f (a, t) n) atTop (𝓝 1) by
filter_upwards [this, hf.mono a] with t ht h_mono
rw [tendsto_iff_tendsto_subseq_of_monotone h_mono tendsto_natCast_atTop_atTop]
exact ht
filter_upwards [hf.tendsto_one_of_monotone a Nat.cast Nat.mono_cast tendsto_natCast_atTop_atTop]
with x hx using hx
lemma IsRatCondKernelCDFAux.tendsto_atBot_zero (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν]
(a : α) :
∀ᵐ t ∂(ν a), Tendsto (f (a, t)) atBot (𝓝 0) := by
suffices ∀ᵐ t ∂(ν a), Tendsto (fun q : ℚ ↦ f (a, t) (-q)) atTop (𝓝 0) by
filter_upwards [this] with t ht
have h_eq_neg : f (a, t) = fun q : ℚ ↦ f (a, t) (- -q) := by
simp_rw [neg_neg]
rw [h_eq_neg]
convert ht.comp tendsto_neg_atBot_atTop
simp
suffices ∀ᵐ t ∂(ν a), Tendsto (fun (n : ℕ) ↦ f (a, t) (-n)) atTop (𝓝 0) by
filter_upwards [this, hf.mono a] with t ht h_mono
have h_anti : Antitone (fun q ↦ f (a, t) (-q)) := h_mono.comp_antitone monotone_id.neg
exact (tendsto_iff_tendsto_subseq_of_antitone h_anti tendsto_natCast_atTop_atTop).mpr ht
exact hf.tendsto_zero_of_antitone _ _ Nat.mono_cast.neg
(tendsto_neg_atBot_iff.mpr tendsto_natCast_atTop_atTop)
lemma IsRatCondKernelCDFAux.bddBelow_range (hf : IsRatCondKernelCDFAux f κ ν) (a : α) :
∀ᵐ t ∂(ν a), ∀ q : ℚ, BddBelow (range fun (r : Ioi q) ↦ f (a, t) r) := by
filter_upwards [hf.nonneg a] with c hc
refine fun q ↦ ⟨0, ?_⟩
simp [mem_lowerBounds, hc]
lemma IsRatCondKernelCDFAux.integrable_iInf_rat_gt (hf : IsRatCondKernelCDFAux f κ ν)
[IsFiniteKernel ν] (a : α) (q : ℚ) :
Integrable (fun t ↦ ⨅ r : Ioi q, f (a, t) r) (ν a) := by
rw [← memLp_one_iff_integrable]
refine ⟨(Measurable.iInf fun i ↦ hf.measurable_right a _).aestronglyMeasurable, ?_⟩
refine (?_ : _ ≤ (ν a univ : ℝ≥0∞)).trans_lt (measure_lt_top _ _)
refine (eLpNorm_le_of_ae_bound (C := 1) ?_).trans (by simp)
filter_upwards [hf.bddBelow_range a, hf.nonneg a, hf.le_one a]
with t hbdd_below h_nonneg h_le_one
rw [Real.norm_eq_abs, abs_of_nonneg]
· refine ciInf_le_of_le ?_ ?_ ?_
· exact hbdd_below _
· exact ⟨q + 1, by simp⟩
· exact h_le_one _
· exact le_ciInf fun r ↦ h_nonneg _
lemma _root_.MeasureTheory.Measure.iInf_rat_gt_prod_Iic {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ]
{s : Set α} (hs : MeasurableSet s) (t : ℚ) :
⨅ r : { r' : ℚ // t < r' }, ρ (s ×ˢ Iic (r : ℝ)) = ρ (s ×ˢ Iic (t : ℝ)) := by
rw [← Monotone.measure_iInter]
· rw [← prod_iInter]
congr with x : 1
simp only [mem_iInter, mem_Iic, Subtype.forall]
refine ⟨fun h ↦ ?_, fun h a hta ↦ h.trans ?_⟩
· refine le_of_forall_lt_rat_imp_le fun q htq ↦ h q ?_
exact mod_cast htq
· exact mod_cast hta.le
· exact fun r r' hrr' ↦ prod_mono_right <| by gcongr
· exact fun _ => (hs.prod measurableSet_Iic).nullMeasurableSet
· exact ⟨⟨t + 1, lt_add_one _⟩, measure_ne_top ρ _⟩
lemma IsRatCondKernelCDFAux.setIntegral_iInf_rat_gt (hf : IsRatCondKernelCDFAux f κ ν)
[IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) (q : ℚ) {A : Set β} (hA : MeasurableSet A) :
∫ t in A, ⨅ r : Ioi q, f (a, t) r ∂(ν a) = (κ a).real (A ×ˢ Iic (q : ℝ)) := by
refine le_antisymm ?_ ?_
· have h : ∀ r : Ioi q, ∫ t in A, ⨅ r' : Ioi q, f (a, t) r' ∂(ν a)
≤ (κ a).real (A ×ˢ Iic (r : ℝ)) := by
intro r
rw [← hf.setIntegral a hA]
refine setIntegral_mono_ae ?_ ?_ ?_
· exact (hf.integrable_iInf_rat_gt _ _).integrableOn
· exact (hf.integrable _ _).integrableOn
· filter_upwards [hf.bddBelow_range a] with t ht using ciInf_le (ht _) r
calc ∫ t in A, ⨅ r : Ioi q, f (a, t) r ∂(ν a)
≤ ⨅ r : Ioi q, (κ a).real (A ×ˢ Iic (r : ℝ)) := le_ciInf h
_ = (κ a).real (A ×ˢ Iic (q : ℝ)) := by
rw [measureReal_def, ← Measure.iInf_rat_gt_prod_Iic hA q]
exact (ENNReal.toReal_iInf (fun r ↦ measure_ne_top _ _)).symm
· rw [← hf.setIntegral a hA]
refine setIntegral_mono_ae ?_ ?_ ?_
· exact (hf.integrable _ _).integrableOn
· exact (hf.integrable_iInf_rat_gt _ _).integrableOn
· filter_upwards [hf.mono a] with c h_mono using le_ciInf (fun r ↦ h_mono (le_of_lt r.prop))
lemma IsRatCondKernelCDFAux.iInf_rat_gt_eq (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ]
[IsFiniteKernel ν] (a : α) :
∀ᵐ t ∂(ν a), ∀ q : ℚ, ⨅ r : Ioi q, f (a, t) r = f (a, t) q := by
rw [ae_all_iff]
refine fun q ↦ ae_eq_of_forall_setIntegral_eq_of_sigmaFinite (μ := ν a) ?_ ?_ ?_
· exact fun _ _ _ ↦ (hf.integrable_iInf_rat_gt _ _).integrableOn
· exact fun _ _ _ ↦ (hf.integrable a _).integrableOn
· intro s hs _
rw [hf.setIntegral _ hs, hf.setIntegral_iInf_rat_gt _ _ hs]
lemma IsRatCondKernelCDFAux.isRatStieltjesPoint_ae (hf : IsRatCondKernelCDFAux f κ ν)
[IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) :
∀ᵐ t ∂(ν a), IsRatStieltjesPoint f (a, t) := by
filter_upwards [hf.tendsto_atTop_one a, hf.tendsto_atBot_zero a,
hf.iInf_rat_gt_eq a, hf.mono a] with t ht_top ht_bot ht_iInf h_mono
exact ⟨h_mono, ht_top, ht_bot, ht_iInf⟩
lemma IsRatCondKernelCDFAux.isRatCondKernelCDF (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ]
[IsFiniteKernel ν] :
IsRatCondKernelCDF f κ ν where
measurable := hf.measurable
isRatStieltjesPoint_ae := hf.isRatStieltjesPoint_ae
integrable := hf.integrable
setIntegral := hf.setIntegral
end isRatCondKernelCDFAux
section IsCondKernelCDF
variable {f : α × β → StieltjesFunction}
/-- A function `f : α × β → StieltjesFunction` is called a conditional kernel CDF of `κ` with
respect to `ν` if it is measurable, tends to 0 at -∞ and to 1 at +∞ for all `p : α × β`,
`fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all
measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a).real (s ×ˢ Iic x)`. -/
structure IsCondKernelCDF (f : α × β → StieltjesFunction) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) :
Prop where
measurable (x : ℝ) : Measurable fun p ↦ f p x
integrable (a : α) (x : ℝ) : Integrable (fun b ↦ f (a, b) x) (ν a)
tendsto_atTop_one (p : α × β) : Tendsto (f p) atTop (𝓝 1)
tendsto_atBot_zero (p : α × β) : Tendsto (f p) atBot (𝓝 0)
setIntegral (a : α) {s : Set β} (_hs : MeasurableSet s) (x : ℝ) :
∫ b in s, f (a, b) x ∂(ν a) = (κ a).real (s ×ˢ Iic x)
lemma IsCondKernelCDF.nonneg (hf : IsCondKernelCDF f κ ν) (p : α × β) (x : ℝ) : 0 ≤ f p x :=
Monotone.le_of_tendsto (f p).mono (hf.tendsto_atBot_zero p) x
lemma IsCondKernelCDF.le_one (hf : IsCondKernelCDF f κ ν) (p : α × β) (x : ℝ) : f p x ≤ 1 :=
Monotone.ge_of_tendsto (f p).mono (hf.tendsto_atTop_one p) x
lemma IsCondKernelCDF.integral
{f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν) (a : α) (x : ℝ) :
∫ b, f (a, b) x ∂(ν a) = (κ a).real (univ ×ˢ Iic x) := by
rw [← hf.setIntegral _ MeasurableSet.univ, Measure.restrict_univ]
lemma IsCondKernelCDF.setLIntegral [IsFiniteKernel κ]
{f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν)
(a : α) {s : Set β} (hs : MeasurableSet s) (x : ℝ) :
∫⁻ b in s, ENNReal.ofReal (f (a, b) x) ∂(ν a) = κ a (s ×ˢ Iic x) := by
rw [← ofReal_integral_eq_lintegral_ofReal (hf.integrable a x).restrict
(ae_of_all _ (fun _ ↦ hf.nonneg _ _)), hf.setIntegral a hs x, ofReal_measureReal]
lemma IsCondKernelCDF.lintegral [IsFiniteKernel κ]
{f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν) (a : α) (x : ℝ) :
∫⁻ b, ENNReal.ofReal (f (a, b) x) ∂(ν a) = κ a (univ ×ˢ Iic x) := by
rw [← hf.setLIntegral _ MeasurableSet.univ, Measure.restrict_univ]
lemma isCondKernelCDF_stieltjesOfMeasurableRat {f : α × β → ℚ → ℝ} (hf : IsRatCondKernelCDF f κ ν)
[IsFiniteKernel κ] :
IsCondKernelCDF (stieltjesOfMeasurableRat f hf.measurable) κ ν where
measurable := measurable_stieltjesOfMeasurableRat hf.measurable
integrable := integrable_stieltjesOfMeasurableRat hf
tendsto_atTop_one := tendsto_stieltjesOfMeasurableRat_atTop hf.measurable
tendsto_atBot_zero := tendsto_stieltjesOfMeasurableRat_atBot hf.measurable
setIntegral a _ hs x := setIntegral_stieltjesOfMeasurableRat hf a x hs
end IsCondKernelCDF
section ToKernel
variable {_ : MeasurableSpace β} {f : α × β → StieltjesFunction}
{κ : Kernel α (β × ℝ)} {ν : Kernel α β}
/-- A function `f : α × β → StieltjesFunction` with the property `IsCondKernelCDF f κ ν` gives a
Markov kernel from `α × β` to `ℝ`, by taking for each `p : α × β` the measure defined by `f p`. -/
noncomputable
def IsCondKernelCDF.toKernel (f : α × β → StieltjesFunction) (hf : IsCondKernelCDF f κ ν) :
Kernel (α × β) ℝ where
toFun p := (f p).measure
measurable' := StieltjesFunction.measurable_measure hf.measurable
hf.tendsto_atBot_zero hf.tendsto_atTop_one
lemma IsCondKernelCDF.toKernel_apply {hf : IsCondKernelCDF f κ ν} (p : α × β) :
hf.toKernel f p = (f p).measure := rfl
instance instIsMarkovKernel_toKernel {hf : IsCondKernelCDF f κ ν} :
IsMarkovKernel (hf.toKernel f) :=
⟨fun _ ↦ (f _).isProbabilityMeasure (hf.tendsto_atBot_zero _) (hf.tendsto_atTop_one _)⟩
lemma IsCondKernelCDF.toKernel_Iic {hf : IsCondKernelCDF f κ ν} (p : α × β) (x : ℝ) :
hf.toKernel f p (Iic x) = ENNReal.ofReal (f p x) := by
rw [IsCondKernelCDF.toKernel_apply p, (f p).measure_Iic (hf.tendsto_atBot_zero p)]
simp
end ToKernel
section
variable {f : α × β → StieltjesFunction}
lemma setLIntegral_toKernel_Iic [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν)
(a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) :
∫⁻ b in s, hf.toKernel f (a, b) (Iic x) ∂(ν a) = κ a (s ×ˢ Iic x) := by
simp_rw [IsCondKernelCDF.toKernel_Iic]
exact hf.setLIntegral _ hs _
lemma setLIntegral_toKernel_univ [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν)
(a : α) {s : Set β} (hs : MeasurableSet s) :
∫⁻ b in s, hf.toKernel f (a, b) univ ∂(ν a) = κ a (s ×ˢ univ) := by
rw [← Real.iUnion_Iic_rat, prod_iUnion]
have h_dir : Directed (fun x y ↦ x ⊆ y) fun q : ℚ ↦ Iic (q : ℝ) := by
refine Monotone.directed_le fun r r' hrr' ↦ Iic_subset_Iic.mpr ?_
exact mod_cast hrr'
have h_dir_prod : Directed (fun x y ↦ x ⊆ y) fun q : ℚ ↦ s ×ˢ Iic (q : ℝ) := by
refine Monotone.directed_le fun i j hij ↦ ?_
refine prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, Iic_subset_Iic.mpr ?_⟩)
exact mod_cast hij
simp_rw [h_dir.measure_iUnion, h_dir_prod.measure_iUnion]
rw [lintegral_iSup_directed]
· simp_rw [setLIntegral_toKernel_Iic hf _ _ hs]
· refine fun q ↦ Measurable.aemeasurable ?_
exact (Kernel.measurable_coe _ measurableSet_Iic).comp measurable_prodMk_left
· refine Monotone.directed_le fun i j hij t ↦ measure_mono (Iic_subset_Iic.mpr ?_)
exact mod_cast hij
lemma lintegral_toKernel_univ [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) :
∫⁻ b, hf.toKernel f (a, b) univ ∂(ν a) = κ a univ := by
rw [← setLIntegral_univ, setLIntegral_toKernel_univ hf a MeasurableSet.univ, univ_prod_univ]
lemma setLIntegral_toKernel_prod [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν)
(a : α) {s : Set β} (hs : MeasurableSet s) {t : Set ℝ} (ht : MeasurableSet t) :
∫⁻ b in s, hf.toKernel f (a, b) t ∂(ν a) = κ a (s ×ˢ t) := by
-- `setLIntegral_toKernel_Iic` gives the result for `t = Iic x`. These sets form a
-- π-system that generates the Borel σ-algebra, hence we can get the same equality for any
-- measurable set `t`.
induction t, ht
using MeasurableSpace.induction_on_inter (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic with
| empty => simp only [measure_empty, lintegral_const, zero_mul, prod_empty]
| basic t ht =>
obtain ⟨q, rfl⟩ := ht
exact setLIntegral_toKernel_Iic hf a _ hs
| compl t ht iht =>
calc ∫⁻ b in s, hf.toKernel f (a, b) tᶜ ∂(ν a)
= ∫⁻ b in s, hf.toKernel f (a, b) univ - hf.toKernel f (a, b) t ∂(ν a) := by
congr with x; rw [measure_compl ht (measure_ne_top (hf.toKernel f (a, x)) _)]
_ = ∫⁻ b in s, hf.toKernel f (a, b) univ ∂(ν a)
- ∫⁻ b in s, hf.toKernel f (a, b) t ∂(ν a) := by
rw [lintegral_sub]
· exact (Kernel.measurable_coe (hf.toKernel f) ht).comp measurable_prodMk_left
· rw [iht]
exact measure_ne_top _ _
· exact Eventually.of_forall fun a ↦ measure_mono (subset_univ _)
_ = κ a (s ×ˢ univ) - κ a (s ×ˢ t) := by
rw [setLIntegral_toKernel_univ hf a hs, iht]
_ = κ a (s ×ˢ tᶜ) := by
rw [← measure_diff _ (hs.prod ht).nullMeasurableSet (measure_ne_top _ _)]
· rw [prod_diff_prod, compl_eq_univ_diff]
simp only [diff_self, empty_prod, union_empty]
· rw [prod_subset_prod_iff]
exact Or.inl ⟨subset_rfl, subset_univ t⟩
| iUnion f hf_disj hf_meas ihf =>
simp_rw [measure_iUnion hf_disj hf_meas]
rw [lintegral_tsum, prod_iUnion, measure_iUnion]
· simp_rw [ihf]
· exact hf_disj.mono fun i j h ↦ h.set_prod_right _ _
· exact fun i ↦ MeasurableSet.prod hs (hf_meas i)
· exact fun i ↦
((Kernel.measurable_coe _ (hf_meas i)).comp measurable_prodMk_left).aemeasurable.restrict
open scoped Function in -- required for scoped `on` notation
lemma lintegral_toKernel_mem [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν)
(a : α) {s : Set (β × ℝ)} (hs : MeasurableSet s) :
∫⁻ b, hf.toKernel f (a, b) (Prod.mk b ⁻¹' s) ∂(ν a) = κ a s := by
-- `setLIntegral_toKernel_prod` gives the result for sets of the form `t₁ × t₂`. These
-- sets form a π-system that generates the product σ-algebra, hence we can get the same equality
-- for any measurable set `s`.
induction s, hs
using MeasurableSpace.induction_on_inter generateFrom_prod.symm isPiSystem_prod with
| empty =>
simp only [preimage_empty, measure_empty, lintegral_const, zero_mul]
| basic s hs =>
rcases hs with ⟨t₁, ht₁, t₂, ht₂, rfl⟩
simp only [mem_setOf_eq] at ht₁ ht₂
rw [← lintegral_add_compl _ ht₁]
have h_eq1 : ∫⁻ x in t₁, hf.toKernel f (a, x) (Prod.mk x ⁻¹' t₁ ×ˢ t₂) ∂(ν a)
= ∫⁻ x in t₁, hf.toKernel f (a, x) t₂ ∂(ν a) := by
refine setLIntegral_congr_fun ht₁ (fun a ha ↦ ?_)
rw [mk_preimage_prod_right ha]
have h_eq2 :
∫⁻ x in t₁ᶜ, hf.toKernel f (a, x) (Prod.mk x ⁻¹' t₁ ×ˢ t₂) ∂(ν a) = 0 := by
suffices h_eq_zero :
∀ x ∈ t₁ᶜ, hf.toKernel f (a, x) (Prod.mk x ⁻¹' t₁ ×ˢ t₂) = 0 by
rw [setLIntegral_congr_fun ht₁.compl h_eq_zero]
simp only [lintegral_const, zero_mul]
intro a hat₁
rw [mem_compl_iff] at hat₁
simp only [hat₁, not_false_eq_true, mk_preimage_prod_right_eq_empty, measure_empty]
rw [h_eq1, h_eq2, add_zero]
exact setLIntegral_toKernel_prod hf a ht₁ ht₂
| compl t ht ht_eq =>
calc ∫⁻ b, hf.toKernel f (a, b) (Prod.mk b ⁻¹' tᶜ) ∂(ν a)
= ∫⁻ b, hf.toKernel f (a, b) (Prod.mk b ⁻¹' t)ᶜ ∂(ν a) := rfl
_ = ∫⁻ b, hf.toKernel f (a, b) univ
- hf.toKernel f (a, b) (Prod.mk b ⁻¹' t) ∂(ν a) := by
congr with x : 1
exact measure_compl (measurable_prodMk_left ht)
(measure_ne_top (hf.toKernel f (a, x)) _)
_ = ∫⁻ x, hf.toKernel f (a, x) univ ∂(ν a) -
∫⁻ x, hf.toKernel f (a, x) (Prod.mk x ⁻¹' t) ∂(ν a) := by
have h_le : (fun x ↦ hf.toKernel f (a, x) (Prod.mk x ⁻¹' t))
≤ᵐ[ν a] fun x ↦ hf.toKernel f (a, x) univ :=
Eventually.of_forall fun _ ↦ measure_mono (subset_univ _)
rw [lintegral_sub _ _ h_le]
· exact Kernel.measurable_kernel_prodMk_left' ht a
refine ((lintegral_mono_ae h_le).trans_lt ?_).ne
rw [lintegral_toKernel_univ hf]
exact measure_lt_top _ univ
_ = κ a univ - κ a t := by rw [ht_eq, lintegral_toKernel_univ hf]
_ = κ a tᶜ := (measure_compl ht (measure_ne_top _ _)).symm
| iUnion f' hf_disj hf_meas hf_eq =>
have h_eq : ∀ a, Prod.mk a ⁻¹' ⋃ i, f' i = ⋃ i, Prod.mk a ⁻¹' f' i := by
simp only [preimage_iUnion, implies_true]
simp_rw [h_eq]
have h_disj : ∀ a, Pairwise (Disjoint on fun i ↦ Prod.mk a ⁻¹' f' i) := by
intro a i j hij
have h_disj := hf_disj hij
rw [Function.onFun, disjoint_iff_inter_eq_empty] at h_disj ⊢
ext1 x
simp only [mem_inter_iff, mem_empty_iff_false, iff_false]
intro h_mem_both
suffices (a, x) ∈ ∅ by rwa [mem_empty_iff_false] at this
rwa [← h_disj, mem_inter_iff]
calc ∫⁻ b, hf.toKernel f (a, b) (⋃ i, Prod.mk b ⁻¹' f' i) ∂(ν a)
= ∫⁻ b, ∑' i, hf.toKernel f (a, b) (Prod.mk b ⁻¹' f' i) ∂(ν a) := by
congr with x : 1
rw [measure_iUnion (h_disj x) fun i ↦ measurable_prodMk_left (hf_meas i)]
_ = ∑' i, ∫⁻ b, hf.toKernel f (a, b) (Prod.mk b ⁻¹' f' i) ∂(ν a) :=
lintegral_tsum fun i ↦ (Kernel.measurable_kernel_prodMk_left' (hf_meas i) a).aemeasurable
_ = ∑' i, κ a (f' i) := by simp_rw [hf_eq]
_ = κ a (iUnion f') := (measure_iUnion hf_disj hf_meas).symm
lemma compProd_toKernel [IsFiniteKernel κ] [IsSFiniteKernel ν] (hf : IsCondKernelCDF f κ ν) :
ν ⊗ₖ hf.toKernel f = κ := by
ext a s hs
rw [Kernel.compProd_apply hs, lintegral_toKernel_mem hf a hs]
end
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/MeasurableStieltjes.lean | import Mathlib.MeasureTheory.Measure.GiryMonad
import Mathlib.MeasureTheory.Measure.Stieltjes
import Mathlib.Analysis.Normed.Order.Lattice
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic
/-!
# Measurable parametric Stieltjes functions
We provide tools to build a measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at
+∞ for all `a : α` from a measurable function `f : α → ℚ → ℝ`. These measurable parametric Stieltjes
functions are cumulative distribution functions (CDF) of transition kernels.
The reason for going through `ℚ` instead of defining directly a Stieltjes function is that since
`ℚ` is countable, building a measurable function is easier and we can obtain properties of the
form `∀ᵐ (a : α) ∂μ, ∀ (q : ℚ), ...` (for some measure `μ` on `α`) by proving the weaker
`∀ (q : ℚ), ∀ᵐ (a : α) ∂μ, ...`.
This construction will be possible if `f a : ℚ → ℝ` satisfies a package of properties for all `a`:
monotonicity, limits at +-∞ and a continuity property. We define `IsRatStieltjesPoint f a` to state
that this is the case at `a` and define the property `IsMeasurableRatCDF f` that `f` is measurable
and `IsRatStieltjesPoint f a` for all `a`.
The function `α → StieltjesFunction` obtained by extending `f` by continuity from the right is then
called `IsMeasurableRatCDF.stieltjesFunction`.
In applications, we will often only have `IsRatStieltjesPoint f a` almost surely with respect to
some measure. In order to turn that almost everywhere property into an everywhere property we define
`toRatCDF (f : α → ℚ → ℝ) := fun a q ↦ if IsRatStieltjesPoint f a then f a q else defaultRatCDF q`,
which satisfies the property `IsMeasurableRatCDF (toRatCDF f)`.
Finally, we define `stieltjesOfMeasurableRat`, composition of `toRatCDF` and
`IsMeasurableRatCDF.stieltjesFunction`.
## Main definitions
* `stieltjesOfMeasurableRat`: turn a measurable function `f : α → ℚ → ℝ` into a measurable
function `α → StieltjesFunction`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped NNReal ENNReal MeasureTheory Topology
/-- A measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at +∞ gives a measurable
function `α → Measure ℝ` by taking `StieltjesFunction.measure` at each point. -/
lemma StieltjesFunction.measurable_measure {α : Type*} {_ : MeasurableSpace α}
{f : α → StieltjesFunction} (hf : ∀ q, Measurable fun a ↦ f a q)
(hf_bot : ∀ a, Tendsto (f a) atBot (𝓝 0))
(hf_top : ∀ a, Tendsto (f a) atTop (𝓝 1)) :
Measurable fun a ↦ (f a).measure :=
have : ∀ a, IsProbabilityMeasure (f a).measure :=
fun a ↦ (f a).isProbabilityMeasure (hf_bot a) (hf_top a)
.measure_of_isPiSystem_of_isProbabilityMeasure (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic <| by
simp_rw [forall_mem_range, StieltjesFunction.measure_Iic (f _) (hf_bot _), sub_zero]
exact fun _ ↦ (hf _).ennreal_ofReal
namespace ProbabilityTheory
variable {α : Type*}
section IsMeasurableRatCDF
variable {f : α → ℚ → ℝ}
/-- `a : α` is a Stieltjes point for `f : α → ℚ → ℝ` if `f a` is monotone with limit 0 at -∞
and 1 at +∞ and satisfies a continuity property. -/
structure IsRatStieltjesPoint (f : α → ℚ → ℝ) (a : α) : Prop where
mono : Monotone (f a)
tendsto_atTop_one : Tendsto (f a) atTop (𝓝 1)
tendsto_atBot_zero : Tendsto (f a) atBot (𝓝 0)
iInf_rat_gt_eq : ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t
lemma isRatStieltjesPoint_unit_prod_iff (f : α → ℚ → ℝ) (a : α) :
IsRatStieltjesPoint (fun p : Unit × α ↦ f p.2) ((), a)
↔ IsRatStieltjesPoint f a := by
constructor <;>
exact fun h ↦ ⟨h.mono, h.tendsto_atTop_one, h.tendsto_atBot_zero, h.iInf_rat_gt_eq⟩
lemma measurableSet_isRatStieltjesPoint [MeasurableSpace α] (hf : Measurable f) :
MeasurableSet {a | IsRatStieltjesPoint f a} := by
have h1 : MeasurableSet {a | Monotone (f a)} := by
change MeasurableSet {a | ∀ q r (_ : q ≤ r), f a q ≤ f a r}
simp_rw [Set.setOf_forall]
refine MeasurableSet.iInter (fun q ↦ ?_)
refine MeasurableSet.iInter (fun r ↦ ?_)
refine MeasurableSet.iInter (fun _ ↦ ?_)
exact measurableSet_le hf.eval hf.eval
have h2 : MeasurableSet {a | Tendsto (f a) atTop (𝓝 1)} :=
measurableSet_tendsto _ (fun q ↦ hf.eval)
have h3 : MeasurableSet {a | Tendsto (f a) atBot (𝓝 0)} :=
measurableSet_tendsto _ (fun q ↦ hf.eval)
have h4 : MeasurableSet {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t} := by
rw [Set.setOf_forall]
refine MeasurableSet.iInter (fun q ↦ ?_)
exact measurableSet_eq_fun (.iInf fun _ ↦ hf.eval) hf.eval
suffices {a | IsRatStieltjesPoint f a}
= ({a | Monotone (f a)} ∩ {a | Tendsto (f a) atTop (𝓝 1)} ∩ {a | Tendsto (f a) atBot (𝓝 0)}
∩ {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t}) by
rw [this]
exact (((h1.inter h2).inter h3).inter h4)
ext a
simp only [mem_setOf_eq, mem_inter_iff]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· exact ⟨⟨⟨h.mono, h.tendsto_atTop_one⟩, h.tendsto_atBot_zero⟩, h.iInf_rat_gt_eq⟩
· exact ⟨h.1.1.1, h.1.1.2, h.1.2, h.2⟩
lemma IsRatStieltjesPoint.ite {f g : α → ℚ → ℝ} {a : α} (p : α → Prop) [DecidablePred p]
(hf : p a → IsRatStieltjesPoint f a) (hg : ¬ p a → IsRatStieltjesPoint g a) :
IsRatStieltjesPoint (fun a ↦ if p a then f a else g a) a where
mono := by split_ifs with h; exacts [(hf h).mono, (hg h).mono]
tendsto_atTop_one := by
split_ifs with h; exacts [(hf h).tendsto_atTop_one, (hg h).tendsto_atTop_one]
tendsto_atBot_zero := by
split_ifs with h; exacts [(hf h).tendsto_atBot_zero, (hg h).tendsto_atBot_zero]
iInf_rat_gt_eq := by split_ifs with h; exacts [(hf h).iInf_rat_gt_eq, (hg h).iInf_rat_gt_eq]
variable [MeasurableSpace α]
/-- A function `f : α → ℚ → ℝ` is a (kernel) rational cumulative distribution function if it is
measurable in the first argument and if `f a` satisfies a list of properties for all `a : α`:
monotonicity between 0 at -∞ and 1 at +∞ and a form of continuity.
A function with these properties can be extended to a measurable function `α → StieltjesFunction`.
See `ProbabilityTheory.IsMeasurableRatCDF.stieltjesFunction`.
-/
structure IsMeasurableRatCDF (f : α → ℚ → ℝ) : Prop where
isRatStieltjesPoint : ∀ a, IsRatStieltjesPoint f a
measurable : Measurable f
lemma IsMeasurableRatCDF.nonneg {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) :
0 ≤ f a q :=
Monotone.le_of_tendsto (hf.isRatStieltjesPoint a).mono
(hf.isRatStieltjesPoint a).tendsto_atBot_zero q
lemma IsMeasurableRatCDF.le_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) :
f a q ≤ 1 :=
Monotone.ge_of_tendsto (hf.isRatStieltjesPoint a).mono
(hf.isRatStieltjesPoint a).tendsto_atTop_one q
lemma IsMeasurableRatCDF.tendsto_atTop_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) :
Tendsto (f a) atTop (𝓝 1) := (hf.isRatStieltjesPoint a).tendsto_atTop_one
lemma IsMeasurableRatCDF.tendsto_atBot_zero {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) :
Tendsto (f a) atBot (𝓝 0) := (hf.isRatStieltjesPoint a).tendsto_atBot_zero
lemma IsMeasurableRatCDF.iInf_rat_gt_eq {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α)
(q : ℚ) :
⨅ r : Ioi q, f a r = f a q := (hf.isRatStieltjesPoint a).iInf_rat_gt_eq q
end IsMeasurableRatCDF
section DefaultRatCDF
/-- A function with the property `IsMeasurableRatCDF`.
Used in a piecewise construction to convert a function which only satisfies the properties
defining `IsMeasurableRatCDF` on some set into a true `IsMeasurableRatCDF`. -/
def defaultRatCDF (q : ℚ) := if q < 0 then (0 : ℝ) else 1
lemma monotone_defaultRatCDF : Monotone defaultRatCDF := by
unfold defaultRatCDF
intro x y hxy
dsimp only
split_ifs with h_1 h_2 h_2
exacts [le_rfl, zero_le_one, absurd (hxy.trans_lt h_2) h_1, le_rfl]
lemma defaultRatCDF_nonneg (q : ℚ) : 0 ≤ defaultRatCDF q := by
unfold defaultRatCDF
split_ifs
exacts [le_rfl, zero_le_one]
lemma defaultRatCDF_le_one (q : ℚ) : defaultRatCDF q ≤ 1 := by
unfold defaultRatCDF
split_ifs <;> simp
lemma tendsto_defaultRatCDF_atTop : Tendsto defaultRatCDF atTop (𝓝 1) := by
refine (tendsto_congr' ?_).mp tendsto_const_nhds
rw [EventuallyEq, eventually_atTop]
exact ⟨0, fun q hq => (if_neg (not_lt.mpr hq)).symm⟩
lemma tendsto_defaultRatCDF_atBot : Tendsto defaultRatCDF atBot (𝓝 0) := by
refine (tendsto_congr' ?_).mp tendsto_const_nhds
rw [EventuallyEq, eventually_atBot]
refine ⟨-1, fun q hq => (if_pos (hq.trans_lt ?_)).symm⟩
linarith
lemma iInf_rat_gt_defaultRatCDF (t : ℚ) :
⨅ r : Ioi t, defaultRatCDF r = defaultRatCDF t := by
simp only [defaultRatCDF]
have h_bdd : BddBelow (range fun r : ↥(Ioi t) ↦ ite ((r : ℚ) < 0) (0 : ℝ) 1) := by
refine ⟨0, fun x hx ↦ ?_⟩
obtain ⟨y, rfl⟩ := mem_range.mpr hx
dsimp only
split_ifs
exacts [le_rfl, zero_le_one]
split_ifs with h
· refine le_antisymm ?_ (le_ciInf fun x ↦ ?_)
· obtain ⟨q, htq, hq_neg⟩ : ∃ q, t < q ∧ q < 0 := ⟨t / 2, by linarith, by linarith⟩
refine (ciInf_le h_bdd ⟨q, htq⟩).trans ?_
rw [if_pos]
rwa [Subtype.coe_mk]
· split_ifs
exacts [le_rfl, zero_le_one]
· refine le_antisymm ?_ ?_
· refine (ciInf_le h_bdd ⟨t + 1, lt_add_one t⟩).trans ?_
split_ifs
exacts [zero_le_one, le_rfl]
· refine le_ciInf fun x ↦ ?_
rw [if_neg]
rw [not_lt] at h ⊢
exact h.trans (mem_Ioi.mp x.prop).le
lemma isRatStieltjesPoint_defaultRatCDF (a : α) :
IsRatStieltjesPoint (fun (_ : α) ↦ defaultRatCDF) a where
mono := monotone_defaultRatCDF
tendsto_atTop_one := tendsto_defaultRatCDF_atTop
tendsto_atBot_zero := tendsto_defaultRatCDF_atBot
iInf_rat_gt_eq := iInf_rat_gt_defaultRatCDF
lemma IsMeasurableRatCDF_defaultRatCDF (α : Type*) [MeasurableSpace α] :
IsMeasurableRatCDF (fun (_ : α) (q : ℚ) ↦ defaultRatCDF q) where
isRatStieltjesPoint := isRatStieltjesPoint_defaultRatCDF
measurable := measurable_const
end DefaultRatCDF
section ToRatCDF
variable {f : α → ℚ → ℝ}
open scoped Classical in
/-- Turn a function `f : α → ℚ → ℝ` into another with the property `IsRatStieltjesPoint f a`
everywhere. At `a` that does not satisfy that property, `f a` is replaced by an arbitrary suitable
function.
Mainly useful when `f` satisfies the property `IsRatStieltjesPoint f a` almost everywhere with
respect to some measure. -/
noncomputable
def toRatCDF (f : α → ℚ → ℝ) : α → ℚ → ℝ := fun a ↦
if IsRatStieltjesPoint f a then f a else defaultRatCDF
lemma toRatCDF_of_isRatStieltjesPoint {a : α} (h : IsRatStieltjesPoint f a) (q : ℚ) :
toRatCDF f a q = f a q := by
rw [toRatCDF, if_pos h]
lemma toRatCDF_unit_prod (a : α) :
toRatCDF (fun (p : Unit × α) ↦ f p.2) ((), a) = toRatCDF f a := by
unfold toRatCDF
rw [isRatStieltjesPoint_unit_prod_iff]
variable [MeasurableSpace α]
lemma measurable_toRatCDF (hf : Measurable f) : Measurable (toRatCDF f) :=
Measurable.ite (measurableSet_isRatStieltjesPoint hf) hf measurable_const
lemma isMeasurableRatCDF_toRatCDF (hf : Measurable f) :
IsMeasurableRatCDF (toRatCDF f) where
isRatStieltjesPoint a := by
classical
exact IsRatStieltjesPoint.ite (IsRatStieltjesPoint f) id
(fun _ ↦ isRatStieltjesPoint_defaultRatCDF a)
measurable := measurable_toRatCDF hf
end ToRatCDF
section IsMeasurableRatCDF.stieltjesFunction
/-- Auxiliary definition for `IsMeasurableRatCDF.stieltjesFunction`: turn `f : α → ℚ → ℝ` into
a function `α → ℝ → ℝ` by assigning to `f a x` the infimum of `f a q` over `q : ℚ` with `x < q`. -/
noncomputable irreducible_def IsMeasurableRatCDF.stieltjesFunctionAux (f : α → ℚ → ℝ) :
α → ℝ → ℝ :=
fun a x ↦ ⨅ q : { q' : ℚ // x < q' }, f a q
lemma IsMeasurableRatCDF.stieltjesFunctionAux_def' (f : α → ℚ → ℝ) (a : α) :
IsMeasurableRatCDF.stieltjesFunctionAux f a
= fun (t : ℝ) ↦ ⨅ r : { r' : ℚ // t < r' }, f a r := by
ext t; exact IsMeasurableRatCDF.stieltjesFunctionAux_def f a t
lemma IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod {f : α → ℚ → ℝ} (a : α) :
IsMeasurableRatCDF.stieltjesFunctionAux (fun (p : Unit × α) ↦ f p.2) ((), a)
= IsMeasurableRatCDF.stieltjesFunctionAux f a := by
simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def']
variable {f : α → ℚ → ℝ} [MeasurableSpace α] (hf : IsMeasurableRatCDF f)
include hf
lemma IsMeasurableRatCDF.stieltjesFunctionAux_eq (a : α) (r : ℚ) :
IsMeasurableRatCDF.stieltjesFunctionAux f a r = f a r := by
rw [← hf.iInf_rat_gt_eq a r, IsMeasurableRatCDF.stieltjesFunctionAux]
refine Equiv.iInf_congr ?_ ?_
· exact
{ toFun := fun t ↦ ⟨t.1, mod_cast t.2⟩
invFun := fun t ↦ ⟨t.1, mod_cast t.2⟩
left_inv := fun t ↦ by simp only [Subtype.coe_eta]
right_inv := fun t ↦ by simp only [Subtype.coe_eta] }
· intro t
simp only [Equiv.coe_fn_mk, Subtype.coe_mk]
lemma IsMeasurableRatCDF.stieltjesFunctionAux_nonneg (a : α) (r : ℝ) :
0 ≤ IsMeasurableRatCDF.stieltjesFunctionAux f a r := by
have : Nonempty { r' : ℚ // r < ↑r' } := by
obtain ⟨r, hrx⟩ := exists_rat_gt r
exact ⟨⟨r, hrx⟩⟩
rw [IsMeasurableRatCDF.stieltjesFunctionAux_def]
exact le_ciInf fun r' ↦ hf.nonneg a _
lemma IsMeasurableRatCDF.monotone_stieltjesFunctionAux (a : α) :
Monotone (IsMeasurableRatCDF.stieltjesFunctionAux f a) := by
intro x y hxy
have : Nonempty { r' : ℚ // y < ↑r' } := by
obtain ⟨r, hrx⟩ := exists_rat_gt y
exact ⟨⟨r, hrx⟩⟩
simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def]
refine le_ciInf fun r ↦ (ciInf_le ?_ ?_).trans_eq ?_
· refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _
· exact ⟨r.1, hxy.trans_lt r.prop⟩
· rfl
lemma IsMeasurableRatCDF.continuousWithinAt_stieltjesFunctionAux_Ici (a : α) (x : ℝ) :
ContinuousWithinAt (IsMeasurableRatCDF.stieltjesFunctionAux f a) (Ici x) x := by
rw [← continuousWithinAt_Ioi_iff_Ici]
convert Monotone.tendsto_nhdsGT (monotone_stieltjesFunctionAux hf a) x
rw [sInf_image']
have h' : ⨅ r : Ioi x, stieltjesFunctionAux f a r
= ⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r := by
refine Real.iInf_Ioi_eq_iInf_rat_gt x ?_ (monotone_stieltjesFunctionAux hf a)
refine ⟨0, fun z ↦ ?_⟩
rintro ⟨u, -, rfl⟩
exact stieltjesFunctionAux_nonneg hf a u
have h'' :
⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r =
⨅ r : { r' : ℚ // x < r' }, f a r := by
congr with r
exact stieltjesFunctionAux_eq hf a r
rw [h', h'', ContinuousWithinAt]
congr!
rw [stieltjesFunctionAux_def]
/-- Extend a function `f : α → ℚ → ℝ` with property `IsMeasurableRatCDF` from `ℚ` to `ℝ`,
to a function `α → StieltjesFunction`. -/
noncomputable def IsMeasurableRatCDF.stieltjesFunction (a : α) : StieltjesFunction where
toFun := stieltjesFunctionAux f a
mono' := monotone_stieltjesFunctionAux hf a
right_continuous' x := continuousWithinAt_stieltjesFunctionAux_Ici hf a x
lemma IsMeasurableRatCDF.stieltjesFunction_eq (a : α) (r : ℚ) : hf.stieltjesFunction a r = f a r :=
stieltjesFunctionAux_eq hf a r
lemma IsMeasurableRatCDF.stieltjesFunction_nonneg (a : α) (r : ℝ) : 0 ≤ hf.stieltjesFunction a r :=
stieltjesFunctionAux_nonneg hf a r
lemma IsMeasurableRatCDF.stieltjesFunction_le_one (a : α) (x : ℝ) :
hf.stieltjesFunction a x ≤ 1 := by
obtain ⟨r, hrx⟩ := exists_rat_gt x
rw [← StieltjesFunction.iInf_rat_gt_eq]
simp_rw [IsMeasurableRatCDF.stieltjesFunction_eq]
refine ciInf_le_of_le ?_ ?_ (hf.le_one _ _)
· refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _
· exact ⟨r, hrx⟩
lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atBot (a : α) :
Tendsto (hf.stieltjesFunction a) atBot (𝓝 0) := by
have h_exists : ∀ x : ℝ, ∃ q : ℚ, x < q ∧ ↑q < x + 1 := fun x ↦ exists_rat_btwn (lt_add_one x)
let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose
have hqs_tendsto : Tendsto qs atBot atBot := by
rw [tendsto_atBot_atBot]
refine fun q ↦ ⟨q - 1, fun y hy ↦ ?_⟩
have h_le : ↑(qs y) ≤ (q : ℝ) - 1 + 1 :=
(h_exists y).choose_spec.2.le.trans (add_le_add hy le_rfl)
rw [sub_add_cancel] at h_le
exact mod_cast h_le
refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
((hf.tendsto_atBot_zero a).comp hqs_tendsto) (stieltjesFunction_nonneg hf a) fun x ↦ ?_
rw [Function.comp_apply, ← stieltjesFunction_eq hf]
exact (hf.stieltjesFunction a).mono (h_exists x).choose_spec.1.le
lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atTop (a : α) :
Tendsto (hf.stieltjesFunction a) atTop (𝓝 1) := by
have h_exists : ∀ x : ℝ, ∃ q : ℚ, x - 1 < q ∧ ↑q < x := fun x ↦ exists_rat_btwn (sub_one_lt x)
let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose
have hqs_tendsto : Tendsto qs atTop atTop := by
rw [tendsto_atTop_atTop]
refine fun q ↦ ⟨q + 1, fun y hy ↦ ?_⟩
have h_le : y - 1 ≤ qs y := (h_exists y).choose_spec.1.le
rw [sub_le_iff_le_add] at h_le
exact_mod_cast le_of_add_le_add_right (hy.trans h_le)
refine tendsto_of_tendsto_of_tendsto_of_le_of_le ((hf.tendsto_atTop_one a).comp hqs_tendsto)
tendsto_const_nhds ?_ (stieltjesFunction_le_one hf a)
intro x
rw [Function.comp_apply, ← stieltjesFunction_eq hf]
exact (hf.stieltjesFunction a).mono (le_of_lt (h_exists x).choose_spec.2)
lemma IsMeasurableRatCDF.measurable_stieltjesFunction (x : ℝ) :
Measurable fun a ↦ hf.stieltjesFunction a x := by
have : (fun a ↦ hf.stieltjesFunction a x) = fun a ↦ ⨅ r : { r' : ℚ // x < r' }, f a ↑r := by
ext1 a
rw [← StieltjesFunction.iInf_rat_gt_eq]
congr with q
rw [stieltjesFunction_eq]
rw [this]
exact .iInf (fun q ↦ hf.measurable.eval)
lemma IsMeasurableRatCDF.stronglyMeasurable_stieltjesFunction (x : ℝ) :
StronglyMeasurable fun a ↦ hf.stieltjesFunction a x :=
(measurable_stieltjesFunction hf x).stronglyMeasurable
section Measure
lemma IsMeasurableRatCDF.measure_stieltjesFunction_Iic (a : α) (x : ℝ) :
(hf.stieltjesFunction a).measure (Iic x) = ENNReal.ofReal (hf.stieltjesFunction a x) := by
rw [← sub_zero (hf.stieltjesFunction a x)]
exact (hf.stieltjesFunction a).measure_Iic (tendsto_stieltjesFunction_atBot hf a) _
lemma IsMeasurableRatCDF.measure_stieltjesFunction_univ (a : α) :
(hf.stieltjesFunction a).measure univ = 1 := by
rw [← ENNReal.ofReal_one, ← sub_zero (1 : ℝ)]
exact StieltjesFunction.measure_univ _ (tendsto_stieltjesFunction_atBot hf a)
(tendsto_stieltjesFunction_atTop hf a)
instance IsMeasurableRatCDF.instIsProbabilityMeasure_stieltjesFunction (a : α) :
IsProbabilityMeasure (hf.stieltjesFunction a).measure :=
⟨measure_stieltjesFunction_univ hf a⟩
lemma IsMeasurableRatCDF.measurable_measure_stieltjesFunction :
Measurable fun a ↦ (hf.stieltjesFunction a).measure := by
apply_rules [StieltjesFunction.measurable_measure, measurable_stieltjesFunction,
tendsto_stieltjesFunction_atBot, tendsto_stieltjesFunction_atTop]
end Measure
end IsMeasurableRatCDF.stieltjesFunction
section stieltjesOfMeasurableRat
variable {f : α → ℚ → ℝ} [MeasurableSpace α]
/-- Turn a measurable function `f : α → ℚ → ℝ` into a measurable function `α → StieltjesFunction`.
Composition of `toRatCDF` and `IsMeasurableRatCDF.stieltjesFunction`. -/
noncomputable
def stieltjesOfMeasurableRat (f : α → ℚ → ℝ) (hf : Measurable f) : α → StieltjesFunction :=
(isMeasurableRatCDF_toRatCDF hf).stieltjesFunction
lemma stieltjesOfMeasurableRat_eq (hf : Measurable f) (a : α) (r : ℚ) :
stieltjesOfMeasurableRat f hf a r = toRatCDF f a r :=
IsMeasurableRatCDF.stieltjesFunction_eq _ a r
lemma stieltjesOfMeasurableRat_unit_prod (hf : Measurable f) (a : α) :
stieltjesOfMeasurableRat (fun (p : Unit × α) ↦ f p.2) (hf.comp measurable_snd) ((), a)
= stieltjesOfMeasurableRat f hf a := by
simp_rw [stieltjesOfMeasurableRat, IsMeasurableRatCDF.stieltjesFunction,
← IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod a]
congr 1 with x
congr 1 with p : 1
cases p with
| mk _ b => rw [← toRatCDF_unit_prod b]
lemma stieltjesOfMeasurableRat_nonneg (hf : Measurable f) (a : α) (r : ℝ) :
0 ≤ stieltjesOfMeasurableRat f hf a r := IsMeasurableRatCDF.stieltjesFunction_nonneg _ a r
lemma stieltjesOfMeasurableRat_le_one (hf : Measurable f) (a : α) (x : ℝ) :
stieltjesOfMeasurableRat f hf a x ≤ 1 := IsMeasurableRatCDF.stieltjesFunction_le_one _ a x
lemma tendsto_stieltjesOfMeasurableRat_atBot (hf : Measurable f) (a : α) :
Tendsto (stieltjesOfMeasurableRat f hf a) atBot (𝓝 0) :=
IsMeasurableRatCDF.tendsto_stieltjesFunction_atBot _ a
lemma tendsto_stieltjesOfMeasurableRat_atTop (hf : Measurable f) (a : α) :
Tendsto (stieltjesOfMeasurableRat f hf a) atTop (𝓝 1) :=
IsMeasurableRatCDF.tendsto_stieltjesFunction_atTop _ a
lemma measurable_stieltjesOfMeasurableRat (hf : Measurable f) (x : ℝ) :
Measurable fun a ↦ stieltjesOfMeasurableRat f hf a x :=
IsMeasurableRatCDF.measurable_stieltjesFunction _ x
lemma stronglyMeasurable_stieltjesOfMeasurableRat (hf : Measurable f) (x : ℝ) :
StronglyMeasurable fun a ↦ stieltjesOfMeasurableRat f hf a x :=
IsMeasurableRatCDF.stronglyMeasurable_stieltjesFunction _ x
section Measure
lemma measure_stieltjesOfMeasurableRat_Iic (hf : Measurable f) (a : α) (x : ℝ) :
(stieltjesOfMeasurableRat f hf a).measure (Iic x)
= ENNReal.ofReal (stieltjesOfMeasurableRat f hf a x) :=
IsMeasurableRatCDF.measure_stieltjesFunction_Iic _ _ _
lemma measure_stieltjesOfMeasurableRat_univ (hf : Measurable f) (a : α) :
(stieltjesOfMeasurableRat f hf a).measure univ = 1 :=
IsMeasurableRatCDF.measure_stieltjesFunction_univ _ _
instance instIsProbabilityMeasure_stieltjesOfMeasurableRat
(hf : Measurable f) (a : α) :
IsProbabilityMeasure (stieltjesOfMeasurableRat f hf a).measure :=
IsMeasurableRatCDF.instIsProbabilityMeasure_stieltjesFunction _ _
lemma measurable_measure_stieltjesOfMeasurableRat (hf : Measurable f) :
Measurable fun a ↦ (stieltjesOfMeasurableRat f hf a).measure :=
IsMeasurableRatCDF.measurable_measure_stieltjesFunction _
end Measure
end stieltjesOfMeasurableRat
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/Integral.lean | import Mathlib.Probability.Kernel.Composition.IntegralCompProd
import Mathlib.Probability.Kernel.Disintegration.StandardBorel
/-!
# Lebesgue and Bochner integrals of conditional kernels
Integrals of `ProbabilityTheory.Kernel.condKernel` and `MeasureTheory.Measure.condKernel`.
## Main statements
* `ProbabilityTheory.setIntegral_condKernel`: the integral
`∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)` is equal to
`∫ x in s ×ˢ t, f x ∂(κ a)`.
* `MeasureTheory.Measure.setIntegral_condKernel`:
`∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ`
Corresponding statements for the Lebesgue integral and/or without the sets `s` and `t` are also
provided.
-/
open MeasureTheory ProbabilityTheory MeasurableSpace
open scoped ENNReal
namespace ProbabilityTheory
variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
[MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω]
section Lintegral
variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ]
{f : β × Ω → ℝ≥0∞}
lemma lintegral_condKernel_mem (a : α) {s : Set (β × Ω)} (hs : MeasurableSet s) :
∫⁻ x, Kernel.condKernel κ (a, x) (Prod.mk x ⁻¹' s) ∂(Kernel.fst κ a) = κ a s := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
simp_rw [Kernel.compProd_apply hs]
lemma setLIntegral_condKernel_eq_measure_prod (a : α) {s : Set β} (hs : MeasurableSet s)
{t : Set Ω} (ht : MeasurableSet t) :
∫⁻ b in s, Kernel.condKernel κ (a, b) t ∂(Kernel.fst κ a) = κ a (s ×ˢ t) := by
have : κ a (s ×ˢ t) = (Kernel.fst κ ⊗ₖ Kernel.condKernel κ) a (s ×ˢ t) := by
congr; exact (κ.disintegrate _).symm
rw [this, Kernel.compProd_apply (hs.prod ht)]
classical
have : ∀ b, Kernel.condKernel κ (a, b) {c | (b, c) ∈ s ×ˢ t}
= s.indicator (fun b ↦ Kernel.condKernel κ (a, b) t) b := by
intro b
by_cases hb : b ∈ s <;> simp [hb]
simp_rw [Set.preimage, this]
rw [lintegral_indicator hs]
lemma lintegral_condKernel (hf : Measurable f) (a : α) :
∫⁻ b, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x, f x ∂(κ a) := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
rw [Kernel.lintegral_compProd _ _ _ hf]
lemma setLIntegral_condKernel (hf : Measurable f) (a : α) {s : Set β}
(hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) :
∫⁻ b in s, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫⁻ x in s ×ˢ t, f x ∂(κ a) := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
rw [Kernel.setLIntegral_compProd _ _ _ hf hs ht]
lemma setLIntegral_condKernel_univ_right (hf : Measurable f) (a : α) {s : Set β}
(hs : MeasurableSet s) :
∫⁻ b in s, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫⁻ x in s ×ˢ Set.univ, f x ∂(κ a) := by
rw [← setLIntegral_condKernel hf a hs MeasurableSet.univ]; simp_rw [Measure.restrict_univ]
lemma setLIntegral_condKernel_univ_left (hf : Measurable f) (a : α) {t : Set Ω}
(ht : MeasurableSet t) :
∫⁻ b, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫⁻ x in Set.univ ×ˢ t, f x ∂(κ a) := by
rw [← setLIntegral_condKernel hf a MeasurableSet.univ ht]; simp_rw [Measure.restrict_univ]
end Lintegral
section Integral
variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ]
{E : Type*} {f : β × Ω → E} [NormedAddCommGroup E] [NormedSpace ℝ E]
lemma _root_.MeasureTheory.AEStronglyMeasurable.integral_kernel_condKernel (a : α)
(hf : AEStronglyMeasurable f (κ a)) :
AEStronglyMeasurable (fun x ↦ ∫ y, f (x, y) ∂(Kernel.condKernel κ (a, x)))
(Kernel.fst κ a) := by
rw [← κ.disintegrate κ.condKernel] at hf
exact AEStronglyMeasurable.integral_kernel_compProd hf
lemma integral_condKernel (a : α) (hf : Integrable f (κ a)) :
∫ b, ∫ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫ x, f x ∂(κ a) := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
rw [← κ.disintegrate κ.condKernel] at hf
rw [integral_compProd hf]
lemma setIntegral_condKernel (a : α) {s : Set β} (hs : MeasurableSet s)
{t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) (κ a)) :
∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫ x in s ×ˢ t, f x ∂(κ a) := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
rw [← κ.disintegrate κ.condKernel] at hf
rw [setIntegral_compProd hs ht hf]
lemma setIntegral_condKernel_univ_right (a : α) {s : Set β} (hs : MeasurableSet s)
(hf : IntegrableOn f (s ×ˢ Set.univ) (κ a)) :
∫ b in s, ∫ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫ x in s ×ˢ Set.univ, f x ∂(κ a) := by
rw [← setIntegral_condKernel a hs MeasurableSet.univ hf]; simp_rw [Measure.restrict_univ]
lemma setIntegral_condKernel_univ_left (a : α) {t : Set Ω} (ht : MeasurableSet t)
(hf : IntegrableOn f (Set.univ ×ˢ t) (κ a)) :
∫ b, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)
= ∫ x in Set.univ ×ˢ t, f x ∂(κ a) := by
rw [← setIntegral_condKernel a MeasurableSet.univ ht hf]; simp_rw [Measure.restrict_univ]
end Integral
end ProbabilityTheory
namespace MeasureTheory.Measure
variable {β Ω : Type*} {mβ : MeasurableSpace β}
[MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω]
section Lintegral
variable {ρ : Measure (β × Ω)} [IsFiniteMeasure ρ]
{f : β × Ω → ℝ≥0∞}
lemma lintegral_condKernel_mem {s : Set (β × Ω)} (hs : MeasurableSet s) :
∫⁻ x, ρ.condKernel x {y | (x, y) ∈ s} ∂ρ.fst = ρ s := by
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
simp_rw [compProd_apply hs]
rfl
lemma setLIntegral_condKernel_eq_measure_prod {s : Set β} (hs : MeasurableSet s) {t : Set Ω}
(ht : MeasurableSet t) :
∫⁻ b in s, ρ.condKernel b t ∂ρ.fst = ρ (s ×ˢ t) := by
have : ρ (s ×ˢ t) = (ρ.fst ⊗ₘ ρ.condKernel) (s ×ˢ t) := by
congr; exact (ρ.disintegrate _).symm
rw [this, compProd_apply (hs.prod ht)]
classical
have : ∀ b, ρ.condKernel b (Prod.mk b ⁻¹' s ×ˢ t)
= s.indicator (fun b ↦ ρ.condKernel b t) b := by
intro b
by_cases hb : b ∈ s <;> simp [hb]
simp_rw [this]
rw [lintegral_indicator hs]
lemma lintegral_condKernel (hf : Measurable f) :
∫⁻ b, ∫⁻ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫⁻ x, f x ∂ρ := by
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
rw [lintegral_compProd hf]
lemma setLIntegral_condKernel (hf : Measurable f) {s : Set β}
(hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) :
∫⁻ b in s, ∫⁻ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst
= ∫⁻ x in s ×ˢ t, f x ∂ρ := by
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
rw [setLIntegral_compProd hf hs ht]
lemma setLIntegral_condKernel_univ_right (hf : Measurable f) {s : Set β}
(hs : MeasurableSet s) :
∫⁻ b in s, ∫⁻ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst
= ∫⁻ x in s ×ˢ Set.univ, f x ∂ρ := by
rw [← setLIntegral_condKernel hf hs MeasurableSet.univ]; simp_rw [Measure.restrict_univ]
lemma setLIntegral_condKernel_univ_left (hf : Measurable f) {t : Set Ω}
(ht : MeasurableSet t) :
∫⁻ b, ∫⁻ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst
= ∫⁻ x in Set.univ ×ˢ t, f x ∂ρ := by
rw [← setLIntegral_condKernel hf MeasurableSet.univ ht]; simp_rw [Measure.restrict_univ]
end Lintegral
section Integral
variable {ρ : Measure (β × Ω)} [IsFiniteMeasure ρ]
{E : Type*} {f : β × Ω → E} [NormedAddCommGroup E] [NormedSpace ℝ E]
lemma _root_.MeasureTheory.AEStronglyMeasurable.integral_condKernel
(hf : AEStronglyMeasurable f ρ) :
AEStronglyMeasurable (fun x ↦ ∫ y, f (x, y) ∂ρ.condKernel x) ρ.fst := by
rw [← ρ.disintegrate ρ.condKernel] at hf
exact AEStronglyMeasurable.integral_kernel_compProd hf
lemma integral_condKernel (hf : Integrable f ρ) :
∫ b, ∫ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x, f x ∂ρ := by
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
rw [← ρ.disintegrate ρ.condKernel] at hf
rw [integral_compProd hf]
lemma setIntegral_condKernel {s : Set β} (hs : MeasurableSet s)
{t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) ρ) :
∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ := by
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
rw [← ρ.disintegrate ρ.condKernel] at hf
rw [setIntegral_compProd hs ht hf]
lemma setIntegral_condKernel_univ_right {s : Set β} (hs : MeasurableSet s)
(hf : IntegrableOn f (s ×ˢ Set.univ) ρ) :
∫ b in s, ∫ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ Set.univ, f x ∂ρ := by
rw [← setIntegral_condKernel hs MeasurableSet.univ hf]; simp_rw [Measure.restrict_univ]
lemma setIntegral_condKernel_univ_left {t : Set Ω} (ht : MeasurableSet t)
(hf : IntegrableOn f (Set.univ ×ˢ t) ρ) :
∫ b, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in Set.univ ×ˢ t, f x ∂ρ := by
rw [← setIntegral_condKernel MeasurableSet.univ ht hf]; simp_rw [Measure.restrict_univ]
end Integral
end MeasureTheory.Measure
namespace MeasureTheory
/-! ### Integrability
We place these lemmas in the `MeasureTheory` namespace to enable dot notation. -/
open ProbabilityTheory
variable {α Ω E F : Type*} {mα : MeasurableSpace α} [MeasurableSpace Ω]
[StandardBorelSpace Ω] [Nonempty Ω] [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ]
theorem AEStronglyMeasurable.ae_integrable_condKernel_iff {f : α × Ω → F}
(hf : AEStronglyMeasurable f ρ) :
(∀ᵐ a ∂ρ.fst, Integrable (fun ω ↦ f (a, ω)) (ρ.condKernel a)) ∧
Integrable (fun a ↦ ∫ ω, ‖f (a, ω)‖ ∂ρ.condKernel a) ρ.fst ↔ Integrable f ρ := by
rw [← ρ.disintegrate ρ.condKernel] at hf
conv_rhs => rw [← ρ.disintegrate ρ.condKernel]
rw [Measure.integrable_compProd_iff hf]
theorem Integrable.condKernel_ae {f : α × Ω → F} (hf_int : Integrable f ρ) :
∀ᵐ a ∂ρ.fst, Integrable (fun ω ↦ f (a, ω)) (ρ.condKernel a) := by
have hf_ae : AEStronglyMeasurable f ρ := hf_int.1
rw [← hf_ae.ae_integrable_condKernel_iff] at hf_int
exact hf_int.1
theorem Integrable.integral_norm_condKernel {f : α × Ω → F} (hf_int : Integrable f ρ) :
Integrable (fun x ↦ ∫ y, ‖f (x, y)‖ ∂ρ.condKernel x) ρ.fst := by
have hf_ae : AEStronglyMeasurable f ρ := hf_int.1
rw [← hf_ae.ae_integrable_condKernel_iff] at hf_int
exact hf_int.2
theorem Integrable.norm_integral_condKernel {f : α × Ω → E} (hf_int : Integrable f ρ) :
Integrable (fun x ↦ ‖∫ y, f (x, y) ∂ρ.condKernel x‖) ρ.fst := by
refine hf_int.integral_norm_condKernel.mono hf_int.1.integral_condKernel.norm ?_
refine Filter.Eventually.of_forall fun x ↦ ?_
rw [norm_norm]
refine (norm_integral_le_integral_norm _).trans_eq (Real.norm_of_nonneg ?_).symm
exact integral_nonneg_of_ae (Filter.Eventually.of_forall fun y ↦ norm_nonneg _)
theorem Integrable.integral_condKernel {f : α × Ω → E} (hf_int : Integrable f ρ) :
Integrable (fun x ↦ ∫ y, f (x, y) ∂ρ.condKernel x) ρ.fst :=
(integrable_norm_iff hf_int.1.integral_condKernel).mp hf_int.norm_integral_condKernel
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/Density.lean | import Mathlib.Probability.Kernel.Composition.MapComap
import Mathlib.Probability.Martingale.Convergence
import Mathlib.Probability.Process.PartitionFiltration
/-!
# Kernel density
Let `κ : Kernel α (γ × β)` and `ν : Kernel α γ` be two finite kernels with `Kernel.fst κ ≤ ν`,
where `γ` has a countably generated σ-algebra (true in particular for standard Borel spaces).
We build a function `density κ ν : α → γ → Set β → ℝ` jointly measurable in the first two arguments
such that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`,
`∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
There are two main applications of this construction.
* Disintegration of kernels: for `κ : Kernel α (γ × β)`, we want to build a kernel
`η : Kernel (α × γ) β` such that `κ = fst κ ⊗ₖ η`. For `β = ℝ`, we can use the density of `κ`
with respect to `fst κ` for intervals to build a kernel cumulative distribution function for `η`.
The construction can then be extended to `β` standard Borel.
* Radon-Nikodym theorem for kernels: for `κ ν : Kernel α γ`, we can use the density to build a
Radon-Nikodym derivative of `κ` with respect to `ν`. We don't need `β` here but we can apply the
density construction to `β = Unit`. The derivative construction will use `density` but will not
be exactly equal to it because we will want to remove the `fst κ ≤ ν` assumption.
## Main definitions
* `ProbabilityTheory.Kernel.density`: for `κ : Kernel α (γ × β)` and `ν : Kernel α γ` two finite
kernels, `Kernel.density κ ν` is a function `α → γ → Set β → ℝ`.
## Main statements
* `ProbabilityTheory.Kernel.setIntegral_density`: for all measurable sets `A : Set γ` and
`s : Set β`, `∫ x in A, Kernel.density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
* `ProbabilityTheory.Kernel.measurable_density`: the function
`p : α × γ ↦ Kernel.density κ ν p.1 p.2 s` is measurable.
## Construction of the density
If we were interested only in a fixed `a : α`, then we could use the Radon-Nikodym derivative to
build the density function `density κ ν`, as follows.
```
def density' (κ : Kernel α (γ × β)) (ν : kernel a γ) (a : α) (x : γ) (s : Set β) : ℝ :=
(((κ a).restrict (univ ×ˢ s)).fst.rnDeriv (ν a) x).toReal
```
However, we can't turn those functions for each `a` into a measurable function of the pair `(a, x)`.
In order to obtain measurability through countability, we use the fact that the measurable space `γ`
is countably generated. For each `n : ℕ`, we define (in the file
`Mathlib/Probability/Process/PartitionFiltration.lean`) a finite partition of `γ`, such that those
partitions are finer as `n` grows, and the σ-algebra generated by the union of all partitions is the
σ-algebra of `γ`. For `x : γ`, `countablePartitionSet n x` denotes the set in the partition such
that `x ∈ countablePartitionSet n x`.
For a given `n`, the function `densityProcess κ ν n : α → γ → Set β → ℝ` defined by
`fun a x s ↦ (κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal` has
the desired property that `∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal` for
all `A` in the σ-algebra generated by the partition at scale `n` and is measurable in `(a, x)`.
`countableFiltration γ` is the filtration of those σ-algebras for all `n : ℕ`.
The functions `densityProcess κ ν n` described here are a bounded `ν`-martingale for the filtration
`countableFiltration γ`. By Doob's martingale L1 convergence theorem, that martingale converges to
a limit, which has a product-measurable version and satisfies the integral equality for all `A` in
`⨆ n, countableFiltration γ n`. Finally, the partitions were chosen so that the supremum is equal
to the σ-algebra on `γ`, hence the equality holds for all measurable sets.
We have obtained the desired density function.
## References
The construction of the density process in this file follows the proof of Theorem 9.27 in
[O. Kallenberg, Foundations of modern probability][kallenberg2021], adapted to use a countably
generated hypothesis instead of specializing to `ℝ`.
-/
open MeasureTheory Set Filter MeasurableSpace
open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
[CountablyGenerated γ] {κ : Kernel α (γ × β)} {ν : Kernel α γ}
section DensityProcess
/-- An `ℕ`-indexed martingale that is a density for `κ` with respect to `ν` on the sets in
`countablePartition γ n`. Used to define its limit `ProbabilityTheory.Kernel.density`, which is
a density for those kernels for all measurable sets. -/
noncomputable
def densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) (s : Set β) :
ℝ :=
(κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal
lemma densityProcess_def (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (s : Set β) :
(fun t ↦ densityProcess κ ν n a t s)
= fun t ↦ (κ a (countablePartitionSet n t ×ˢ s) / ν a (countablePartitionSet n t)).toReal :=
rfl
lemma measurable_densityProcess_countableFiltration_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ)
(n : ℕ) {s : Set β} (hs : MeasurableSet s) :
Measurable[mα.prod (countableFiltration γ n)] (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
change Measurable[mα.prod (countableFiltration γ n)]
((fun (p : α × countablePartition γ n) ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2)
∘ (fun (p : α × γ) ↦ (p.1, ⟨countablePartitionSet n p.2, countablePartitionSet_mem n p.2⟩)))
have h1 : @Measurable _ _ (mα.prod ⊤) _
(fun p : α × countablePartition γ n ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2) := by
refine Measurable.div ?_ ?_
· refine measurable_from_prod_countable_left (fun t ↦ ?_)
exact Kernel.measurable_coe _ ((measurableSet_countablePartition _ t.prop).prod hs)
· refine measurable_from_prod_countable_left ?_
rintro ⟨t, ht⟩
exact Kernel.measurable_coe _ (measurableSet_countablePartition _ ht)
refine h1.comp (measurable_fst.prodMk ?_)
change @Measurable (α × γ) (countablePartition γ n) (mα.prod (countableFiltration γ n)) ⊤
((fun c ↦ ⟨countablePartitionSet n c, countablePartitionSet_mem n c⟩) ∘ (fun p : α × γ ↦ p.2))
exact (measurable_countablePartitionSet_subtype n ⊤).comp measurable_snd
lemma measurable_densityProcess_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
refine Measurable.mono (measurable_densityProcess_countableFiltration_aux κ ν n hs) ?_ le_rfl
exact sup_le_sup le_rfl (comap_mono ((countableFiltration γ).le _))
lemma measurable_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦ densityProcess κ ν n p.1 p.2 s) :=
(measurable_densityProcess_aux κ ν n hs).ennreal_toReal
-- The following two lemmas also work without the `( :)`, but they are slow.
lemma measurable_densityProcess_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(x : γ) {s : Set β} (hs : MeasurableSet s) :
Measurable (fun a ↦ densityProcess κ ν n a x s) :=
((measurable_densityProcess κ ν n hs).comp (measurable_id.prodMk measurable_const):)
lemma measurable_densityProcess_right (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (a : α) (hs : MeasurableSet s) :
Measurable (fun x ↦ densityProcess κ ν n a x s) :=
((measurable_densityProcess κ ν n hs).comp (measurable_const.prodMk measurable_id):)
lemma measurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(a : α) {s : Set β} (hs : MeasurableSet s) :
Measurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) := by
refine @Measurable.ennreal_toReal _ (countableFiltration γ n) _ ?_
-- The exact also works without the `( :)`, but is a bit slow.
exact ((measurable_densityProcess_countableFiltration_aux κ ν n hs).comp measurable_prodMk_left :)
lemma stronglyMeasurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ)
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) :
StronglyMeasurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) :=
(measurable_countableFiltration_densityProcess κ ν n a hs).stronglyMeasurable
lemma adapted_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α)
{s : Set β} (hs : MeasurableSet s) :
Adapted (countableFiltration γ) (fun n x ↦ densityProcess κ ν n a x s) :=
fun n ↦ stronglyMeasurable_countableFiltration_densityProcess κ ν n a hs
lemma densityProcess_nonneg (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(a : α) (x : γ) (s : Set β) :
0 ≤ densityProcess κ ν n a x s :=
ENNReal.toReal_nonneg
lemma meas_countablePartitionSet_le_of_fst_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ)
(s : Set β) :
κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) := by
calc κ a (countablePartitionSet n x ×ˢ s)
≤ fst κ a (countablePartitionSet n x) := by
rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)]
refine measure_mono (fun x ↦ ?_)
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
_ ≤ ν a (countablePartitionSet n x) := hκν a _
lemma densityProcess_le_one (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν n a x s ≤ 1 := by
refine ENNReal.toReal_le_of_le_ofReal zero_le_one (ENNReal.div_le_of_le_mul ?_)
rw [ENNReal.ofReal_one, one_mul]
exact meas_countablePartitionSet_le_of_fst_le hκν n a x s
lemma eLpNorm_densityProcess_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (s : Set β) :
eLpNorm (fun x ↦ densityProcess κ ν n a x s) 1 (ν a) ≤ ν a univ := by
refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun x ↦ ?_))).trans ?_
· simp only [Real.norm_eq_abs, abs_of_nonneg (densityProcess_nonneg κ ν n a x s),
densityProcess_le_one hκν n a x s]
· simp
lemma integrable_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ)
(a : α) {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x ↦ densityProcess κ ν n a x s) (ν a) := by
rw [← memLp_one_iff_integrable]
refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩
· exact measurable_densityProcess_right κ ν n a hs
· exact (eLpNorm_densityProcess_le hκν n a s).trans_lt (measure_lt_top _ _)
lemma setIntegral_densityProcess_of_mem (hκν : fst κ ≤ ν) [hν : IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {u : Set γ}
(hu : u ∈ countablePartition γ n) :
∫ x in u, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (u ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
have hu_meas : MeasurableSet u := measurableSet_countablePartition n hu
simp_rw [densityProcess]
rw [integral_toReal]
rotate_left
· refine Measurable.aemeasurable ?_
change Measurable ((fun (p : α × _) ↦ κ p.1 (countablePartitionSet n p.2 ×ˢ s)
/ ν p.1 (countablePartitionSet n p.2)) ∘ (fun x ↦ (a, x)))
exact (measurable_densityProcess_aux κ ν n hs).comp measurable_prodMk_left
· refine ae_of_all _ (fun x ↦ ?_)
by_cases h0 : ν a (countablePartitionSet n x) = 0
· suffices κ a (countablePartitionSet n x ×ˢ s) = 0 by simp [h0, this]
have h0' : fst κ a (countablePartitionSet n x) = 0 :=
le_antisymm ((hκν a _).trans h0.le) zero_le'
rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h0'
refine measure_mono_null (fun x ↦ ?_) h0'
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
· finiteness
congr
have : ∫⁻ x in u, κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x) ∂(ν a)
= ∫⁻ _ in u, κ a (u ×ˢ s) / ν a u ∂(ν a) := by
refine setLIntegral_congr_fun hu_meas (fun t ht ↦ ?_)
rw [countablePartitionSet_of_mem hu ht]
rw [this]
simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter]
by_cases h0 : ν a u = 0
· simp only [h0, mul_zero]
have h0' : fst κ a u = 0 := le_antisymm ((hκν a _).trans h0.le) zero_le'
rw [fst_apply' _ _ hu_meas] at h0'
refine (measure_mono_null ?_ h0').symm
intro p
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
rw [div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel h0, mul_one]
exact measure_ne_top _ _
open scoped Function in -- required for scoped `on` notation
lemma setIntegral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ}
(hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
obtain ⟨S, hS_subset, rfl⟩ := (measurableSet_generateFrom_countablePartition_iff _ _).mp hA
simp_rw [sUnion_eq_iUnion]
have h_disj : Pairwise (Disjoint on fun i : S ↦ (i : Set γ)) := by
intro u v huv
simp only [Function.onFun]
refine disjoint_countablePartition (hS_subset (by simp)) (hS_subset (by simp)) ?_
rwa [ne_eq, ← Subtype.ext_iff]
rw [integral_iUnion, iUnion_prod_const, measureReal_def, measure_iUnion,
ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)]
· congr with u
rw [setIntegral_densityProcess_of_mem hκν _ _ hs (hS_subset (by simp))]
rfl
· intro u v huv
simp only [Finset.coe_sort_coe, Set.disjoint_prod, disjoint_self, bot_eq_empty]
exact Or.inl (h_disj huv)
· exact fun _ ↦ (measurableSet_countablePartition n (hS_subset (by simp))).prod hs
· exact fun _ ↦ measurableSet_countablePartition n (hS_subset (by simp))
· exact h_disj
· exact (integrable_densityProcess hκν _ _ hs).integrableOn
lemma integral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) :
∫ x, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (univ ×ˢ s) := by
rw [← setIntegral_univ, setIntegral_densityProcess hκν _ _ hs MeasurableSet.univ]
lemma setIntegral_densityProcess_of_le (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] {n m : ℕ} (hnm : n ≤ m) (a : α) {s : Set β} (hs : MeasurableSet s)
{A : Set γ} (hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, densityProcess κ ν m a x s ∂(ν a) = (κ a).real (A ×ˢ s) :=
setIntegral_densityProcess hκν m a hs ((countableFiltration γ).mono hnm A hA)
lemma condExp_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
{i j : ℕ} (hij : i ≤ j) (a : α) {s : Set β} (hs : MeasurableSet s) :
(ν a)[fun x ↦ densityProcess κ ν j a x s|countableFiltration γ i]
=ᵐ[ν a] fun x ↦ densityProcess κ ν i a x s := by
refine (ae_eq_condExp_of_forall_setIntegral_eq ?_ ?_ ?_ ?_ ?_).symm
· exact integrable_densityProcess hκν j a hs
· exact fun _ _ _ ↦ (integrable_densityProcess hκν _ _ hs).integrableOn
· intro x hx _
rw [setIntegral_densityProcess hκν i a hs hx,
setIntegral_densityProcess_of_le hκν hij a hs hx]
· exact StronglyMeasurable.aestronglyMeasurable
(stronglyMeasurable_countableFiltration_densityProcess κ ν i a hs)
lemma martingale_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Martingale (fun n x ↦ densityProcess κ ν n a x s) (countableFiltration γ) (ν a) :=
⟨adapted_densityProcess κ ν a hs, fun _ _ h ↦ condExp_densityProcess hκν h a hs⟩
lemma densityProcess_mono_set (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ)
{s s' : Set β} (h : s ⊆ s') :
densityProcess κ ν n a x s ≤ densityProcess κ ν n a x s' := by
unfold densityProcess
obtain h₀ | h₀ := eq_or_ne (ν a (countablePartitionSet n x)) 0
· simp [h₀]
· gcongr
simp only [ne_eq, ENNReal.div_eq_top, h₀, and_false, false_or, not_and, not_not]
exact eq_top_mono (meas_countablePartitionSet_le_of_fst_le hκν n a x s')
lemma densityProcess_mono_kernel_left {κ' : Kernel α (γ × β)} (hκκ' : κ ≤ κ')
(hκ'ν : fst κ' ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν n a x s ≤ densityProcess κ' ν n a x s := by
unfold densityProcess
by_cases h0 : ν a (countablePartitionSet n x) = 0
· rw [h0, ENNReal.toReal_div, ENNReal.toReal_div]
simp
have h_le : κ' a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) :=
meas_countablePartitionSet_le_of_fst_le hκ'ν n a x s
gcongr
· simp only [ne_eq, ENNReal.div_eq_top, h0, and_false, false_or, not_and, not_not]
exact fun h_top ↦ eq_top_mono h_le h_top
· apply hκκ'
lemma densityProcess_antitone_kernel_right {ν' : Kernel α γ}
(hνν' : ν ≤ ν') (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν' n a x s ≤ densityProcess κ ν n a x s := by
unfold densityProcess
have h_le : κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) :=
meas_countablePartitionSet_le_of_fst_le hκν n a x s
by_cases h0 : ν a (countablePartitionSet n x) = 0
· simp [le_antisymm (h_le.trans h0.le) zero_le', h0]
gcongr
· simp only [ne_eq, ENNReal.div_eq_top, h0, and_false, false_or, not_and, not_not]
exact fun h_top ↦ eq_top_mono h_le h_top
· apply hνν'
@[simp]
lemma densityProcess_empty (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) :
densityProcess κ ν n a x ∅ = 0 := by
simp [densityProcess]
lemma tendsto_densityProcess_atTop_empty_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ)
[IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop
(𝓝 (densityProcess κ ν n a x ∅)) := by
simp_rw [densityProcess]
by_cases h0 : ν a (countablePartitionSet n x) = 0
· simp_rw [h0, ENNReal.toReal_div]
simp
refine (ENNReal.tendsto_toReal ?_).comp ?_
· rw [ne_eq, ENNReal.div_eq_top]
push_neg
simp
refine ENNReal.Tendsto.div_const ?_ (.inr h0)
have : Tendsto (fun m ↦ κ a (countablePartitionSet n x ×ˢ seq m)) atTop
(𝓝 ((κ a) (⋂ n_1, countablePartitionSet n x ×ˢ seq n_1))) := by
apply tendsto_measure_iInter_atTop
· measurability
· exact fun _ _ h ↦ prod_mono_right <| hseq h
· exact ⟨0, measure_ne_top _ _⟩
simpa only [← prod_iInter, hseq_iInter] using this
lemma tendsto_densityProcess_atTop_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ)
[IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop (𝓝 0) := by
rw [← densityProcess_empty κ ν n a x]
exact tendsto_densityProcess_atTop_empty_of_antitone κ ν n a x seq hseq hseq_iInter hseq_meas
lemma tendsto_densityProcess_limitProcess (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) :
∀ᵐ x ∂(ν a), Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop
(𝓝 ((countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a) x)) := by
refine Submartingale.ae_tendsto_limitProcess (martingale_densityProcess hκν a hs).submartingale
(R := (ν a univ).toNNReal) (fun n ↦ ?_)
refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_
rw [ENNReal.coe_toNNReal]
exact measure_ne_top _ _
lemma memL1_limitProcess_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
MemLp ((countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a)) 1 (ν a) := by
refine Submartingale.memLp_limitProcess (martingale_densityProcess hκν a hs).submartingale
(R := (ν a univ).toNNReal) (fun n ↦ ?_)
refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_
rw [ENNReal.coe_toNNReal]
exact measure_ne_top _ _
lemma tendsto_eLpNorm_one_densityProcess_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s)
- (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a))
1 (ν a)) atTop (𝓝 0) := by
refine Submartingale.tendsto_eLpNorm_one_limitProcess ?_ ?_
· exact (martingale_densityProcess hκν a hs).submartingale
· refine uniformIntegrable_of le_rfl ENNReal.one_ne_top ?_ ?_
· exact fun n ↦ (measurable_densityProcess_right κ ν n a hs).aestronglyMeasurable
· refine fun ε _ ↦ ⟨2, fun n ↦ le_of_eq_of_le ?_ (?_ : 0 ≤ ENNReal.ofReal ε)⟩
· suffices {x | 2 ≤ ‖densityProcess κ ν n a x s‖₊} = ∅ by simp [this]
ext x
simp only [mem_setOf_eq, mem_empty_iff_false, iff_false, not_le]
refine (?_ : _ ≤ (1 : ℝ≥0)).trans_lt one_lt_two
rw [Real.nnnorm_of_nonneg (densityProcess_nonneg _ _ _ _ _ _)]
exact mod_cast (densityProcess_le_one hκν _ _ _ _)
· simp
lemma tendsto_eLpNorm_one_restrict_densityProcess_limitProcess [IsFiniteKernel ν]
(hκν : fst κ ≤ ν) (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) :
Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s)
- (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a))
1 ((ν a).restrict A)) atTop (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs) (fun _ ↦ zero_le')
(fun _ ↦ eLpNorm_restrict_le _ _ _ _)
end DensityProcess
section Density
/-- Density of the kernel `κ` with respect to `ν`. This is a function `α → γ → Set β → ℝ` which
is measurable on `α × γ` for all measurable sets `s : Set β` and satisfies that
`∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)` for all measurable `A : Set γ`. -/
noncomputable
def density (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α) (x : γ) (s : Set β) : ℝ :=
limsup (fun n ↦ densityProcess κ ν n a x s) atTop
lemma density_ae_eq_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
(fun x ↦ density κ ν a x s)
=ᵐ[ν a] (countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a) := by
filter_upwards [tendsto_densityProcess_limitProcess hκν a hs] with t ht using ht.limsup_eq
lemma tendsto_m_density (hκν : fst κ ≤ ν) (a : α) [IsFiniteKernel ν]
{s : Set β} (hs : MeasurableSet s) :
∀ᵐ x ∂(ν a),
Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop (𝓝 (density κ ν a x s)) := by
filter_upwards [tendsto_densityProcess_limitProcess hκν a hs, density_ae_eq_limitProcess hκν a hs]
with t h1 h2 using h2 ▸ h1
lemma measurable_density (κ : Kernel α (γ × β)) (ν : Kernel α γ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦ density κ ν p.1 p.2 s) :=
.limsup (fun n ↦ measurable_densityProcess κ ν n hs)
lemma measurable_density_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (x : γ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun a ↦ density κ ν a x s) := by
change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun a ↦ (a, x)))
exact (measurable_density κ ν hs).comp measurable_prodMk_right
lemma measurable_density_right (κ : Kernel α (γ × β)) (ν : Kernel α γ)
{s : Set β} (hs : MeasurableSet s) (a : α) :
Measurable (fun x ↦ density κ ν a x s) := by
change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun x ↦ (a, x)))
exact (measurable_density κ ν hs).comp measurable_prodMk_left
lemma density_mono_set (hκν : fst κ ≤ ν) (a : α) (x : γ) {s s' : Set β} (h : s ⊆ s') :
density κ ν a x s ≤ density κ ν a x s' := by
refine limsup_le_limsup ?_ ?_ ?_
· exact Eventually.of_forall (fun n ↦ densityProcess_mono_set hκν n a x h)
· exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩
lemma density_nonneg (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) :
0 ≤ density κ ν a x s := by
refine le_limsup_of_frequently_le ?_ ?_
· exact Frequently.of_forall (fun n ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩
lemma density_le_one (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) :
density κ ν a x s ≤ 1 := by
refine limsup_le_of_le ?_ ?_
· exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact Eventually.of_forall (fun n ↦ densityProcess_le_one hκν _ _ _ _)
section Integral
lemma eLpNorm_density_le (hκν : fst κ ≤ ν) (a : α) (s : Set β) :
eLpNorm (fun x ↦ density κ ν a x s) 1 (ν a) ≤ ν a univ := by
refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun t ↦ ?_))).trans ?_
· simp only [Real.norm_eq_abs, abs_of_nonneg (density_nonneg hκν a t s),
density_le_one hκν a t s]
· simp
lemma integrable_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x ↦ density κ ν a x s) (ν a) := by
rw [← memLp_one_iff_integrable]
refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩
· exact measurable_density_right κ ν hs a
· exact (eLpNorm_density_le hκν a s).trans_lt (measure_lt_top _ _)
lemma tendsto_setIntegral_densityProcess (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) :
Tendsto (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop
(𝓝 (∫ x in A, density κ ν a x s ∂(ν a))) := by
refine tendsto_setIntegral_of_L1' (μ := ν a) (fun x ↦ density κ ν a x s)
(integrable_density hκν a hs) (F := fun i x ↦ densityProcess κ ν i a x s) (l := atTop)
(Eventually.of_forall (fun n ↦ integrable_densityProcess hκν _ _ hs)) ?_ A
refine (tendsto_congr fun n ↦ ?_).mp (tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs)
refine eLpNorm_congr_ae ?_
exact EventuallyEq.rfl.sub (density_ae_eq_limitProcess hκν a hs).symm
/-- Auxiliary lemma for `setIntegral_density`. -/
lemma setIntegral_density_of_measurableSet (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ}
(hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
suffices ∫ x in A, density κ ν a x s ∂(ν a) = ∫ x in A, densityProcess κ ν n a x s ∂(ν a) by
exact this ▸ setIntegral_densityProcess hκν _ _ hs hA
suffices ∫ x in A, density κ ν a x s ∂(ν a)
= limsup (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop by
rw [this, ← limsup_const (α := ℕ) (f := atTop) (∫ x in A, densityProcess κ ν n a x s ∂(ν a)),
limsup_congr]
simp only [eventually_atTop]
refine ⟨n, fun m hnm ↦ ?_⟩
rw [setIntegral_densityProcess_of_le hκν hnm _ hs hA,
setIntegral_densityProcess hκν _ _ hs hA]
-- use L1 convergence
have h := tendsto_setIntegral_densityProcess hκν a hs A
rw [h.limsup_eq]
lemma integral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
∫ x, density κ ν a x s ∂(ν a) = (κ a).real (univ ×ˢ s) := by
rw [← setIntegral_univ, setIntegral_density_of_measurableSet hκν 0 a hs MeasurableSet.univ]
lemma setIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) :
∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
have hgen : ‹MeasurableSpace γ› =
.generateFrom {s | ∃ n, MeasurableSet[countableFiltration γ n] s} := by
rw [setOf_exists, generateFrom_iUnion_measurableSet (countableFiltration γ),
iSup_countableFiltration]
have hpi : IsPiSystem {s | ∃ n, MeasurableSet[countableFiltration γ n] s} := by
rw [setOf_exists]
exact isPiSystem_iUnion_of_monotone _
(fun n ↦ @isPiSystem_measurableSet _ (countableFiltration γ n))
fun _ _ ↦ (countableFiltration γ).mono
induction A, hA using induction_on_inter hgen hpi with
| empty => simp
| basic s hs =>
rcases hs with ⟨n, hn⟩
exact setIntegral_density_of_measurableSet hκν n a hs hn
| compl A hA hA_eq =>
have h := integral_add_compl hA (integrable_density hκν a hs)
rw [hA_eq, integral_density hκν a hs] at h
have : Aᶜ ×ˢ s = univ ×ˢ s \ A ×ˢ s := by
rw [prod_diff_prod, compl_eq_univ_diff]
simp
rw [this, measureReal_def,
measure_diff (by intro; simp) (hA.prod hs).nullMeasurableSet (measure_ne_top (κ a) _),
ENNReal.toReal_sub_of_le (measure_mono (by intro x; simp)) (measure_ne_top _ _)]
rw [eq_tsub_iff_add_eq_of_le, add_comm]
· exact h
· gcongr <;> simp
| iUnion f hf_disj hf h_eq =>
rw [integral_iUnion hf hf_disj (integrable_density hκν _ hs).integrableOn]
simp_rw [h_eq, measureReal_def]
rw [← ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)]
congr
rw [iUnion_prod_const, measure_iUnion]
· exact hf_disj.mono fun _ _ h ↦ h.set_prod_left _ _
· exact fun i ↦ (hf i).prod hs
lemma setLIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) :
∫⁻ x in A, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
rw [← ofReal_integral_eq_lintegral_ofReal]
· rw [setIntegral_density hκν a hs hA, measureReal_def,
ENNReal.ofReal_toReal (measure_ne_top _ _)]
· exact (integrable_density hκν a hs).restrict
· exact ae_of_all _ (fun _ ↦ density_nonneg hκν _ _ _)
lemma lintegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
∫⁻ x, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (univ ×ˢ s) := by
rw [← setLIntegral_univ]
exact setLIntegral_density hκν a hs MeasurableSet.univ
end Integral
lemma tendsto_integral_density_of_monotone (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 ((κ a).real univ)) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
simp_rw [integral_density hκν a (hseq_meas _)]
have h_cont := ENNReal.continuousOn_toReal.continuousAt (x := κ a univ) ?_
swap
· rw [mem_nhds_iff]
refine ⟨Iio (κ a univ + 1), fun x hx ↦ ne_top_of_lt (?_ : x < κ a univ + 1), isOpen_Iio, ?_⟩
· simpa using hx
· simp only [mem_Iio]
exact ENNReal.lt_add_right (measure_ne_top _ _) one_ne_zero
refine h_cont.tendsto.comp ?_
convert tendsto_measure_iUnion_atTop (monotone_const.set_prod hseq)
rw [← prod_iUnion, hseq_iUnion, univ_prod_univ]
lemma tendsto_integral_density_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 0) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
simp_rw [integral_density hκν a (hseq_meas _)]
rw [← ENNReal.toReal_zero]
have h_cont := ENNReal.continuousAt_toReal ENNReal.zero_ne_top
refine h_cont.tendsto.comp ?_
have h : Tendsto (fun m ↦ κ a (univ ×ˢ seq m)) atTop
(𝓝 ((κ a) (⋂ n, (fun m ↦ univ ×ˢ seq m) n))) := by
apply tendsto_measure_iInter_atTop
· measurability
· exact antitone_const.set_prod hseq
· exact ⟨0, measure_ne_top _ _⟩
simpa [← prod_iInter, hseq_iInter] using h
lemma tendsto_density_atTop_ae_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
∀ᵐ x ∂(ν a), Tendsto (fun m ↦ density κ ν a x (seq m)) atTop (𝓝 0) := by
refine tendsto_of_integral_tendsto_of_antitone ?_ (integrable_const _) ?_ ?_ ?_
· exact fun m ↦ integrable_density hκν _ (hseq_meas m)
· rw [integral_zero]
exact tendsto_integral_density_of_antitone hκν a seq hseq hseq_iInter hseq_meas
· exact ae_of_all _ (fun c n m hnm ↦ density_mono_set hκν a c (hseq hnm))
· exact ae_of_all _ (fun x m ↦ density_nonneg hκν a x (seq m))
section UnivFst
/-! We specialize to `ν = fst κ`, for which `density κ (fst κ) a t univ = 1` almost everywhere. -/
lemma densityProcess_fst_univ [IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ) :
densityProcess κ (fst κ) n a x univ
= if fst κ a (countablePartitionSet n x) = 0 then 0 else 1 := by
rw [densityProcess]
split_ifs with h
· simp only [h]
by_cases h' : κ a (countablePartitionSet n x ×ˢ univ) = 0
· simp [h']
· simp
· rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)]
have : countablePartitionSet n x ×ˢ univ = {p : γ × β | p.1 ∈ countablePartitionSet n x} := by
ext x
simp
rw [this, ENNReal.div_self]
· simp
· rwa [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h
· exact measure_ne_top _ _
lemma densityProcess_fst_univ_ae (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (n : ℕ) (a : α) :
∀ᵐ x ∂(fst κ a), densityProcess κ (fst κ) n a x univ = 1 := by
rw [ae_iff]
have : {x | ¬ densityProcess κ (fst κ) n a x univ = 1}
⊆ {x | fst κ a (countablePartitionSet n x) = 0} := by
intro x hx
simp only [mem_setOf_eq] at hx ⊢
rw [densityProcess_fst_univ] at hx
simpa using hx
refine measure_mono_null this ?_
have : {x | fst κ a (countablePartitionSet n x) = 0}
⊆ ⋃ (u) (_ : u ∈ countablePartition γ n) (_ : fst κ a u = 0), u := by
intro t ht
simp only [mem_setOf_eq, mem_iUnion, exists_prop] at ht ⊢
exact ⟨countablePartitionSet n t, countablePartitionSet_mem _ _, ht,
mem_countablePartitionSet _ _⟩
refine measure_mono_null this ?_
rw [measure_biUnion]
· simp
· exact (finite_countablePartition _ _).countable
· intro s hs t ht hst
simp only [disjoint_iUnion_right, disjoint_iUnion_left]
exact fun _ _ ↦ disjoint_countablePartition hs ht hst
· intro s hs
by_cases h : fst κ a s = 0
· simp [h, measurableSet_countablePartition n hs]
· simp [h]
lemma tendsto_densityProcess_fst_atTop_univ_of_monotone (κ : Kernel α (γ × β)) (n : ℕ) (a : α)
(x : γ) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) :
Tendsto (fun m ↦ densityProcess κ (fst κ) n a x (seq m)) atTop
(𝓝 (densityProcess κ (fst κ) n a x univ)) := by
simp_rw [densityProcess]
refine (ENNReal.tendsto_toReal ?_).comp ?_
· rw [ne_eq, ENNReal.div_eq_top]
push_neg
simp_rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)]
constructor
· refine fun h h0 ↦ h (measure_mono_null (fun x ↦ ?_) h0)
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
· refine fun h_top ↦ eq_top_mono (measure_mono (fun x ↦ ?_)) h_top
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
by_cases h0 : fst κ a (countablePartitionSet n x) = 0
· rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h0 ⊢
suffices ∀ m, κ a (countablePartitionSet n x ×ˢ seq m) = 0 by
simp only [this, h0, ENNReal.zero_div, tendsto_const_nhds_iff]
suffices κ a (countablePartitionSet n x ×ˢ univ) = 0 by
simp only [this, ENNReal.zero_div]
convert h0
ext x
simp only [mem_prod, mem_univ, and_true, mem_setOf_eq]
refine fun m ↦ measure_mono_null (fun x ↦ ?_) h0
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
refine ENNReal.Tendsto.div_const ?_ ?_
· convert tendsto_measure_iUnion_atTop (monotone_const.set_prod hseq)
rw [← prod_iUnion, hseq_iUnion]
· exact Or.inr h0
lemma tendsto_densityProcess_fst_atTop_ae_of_monotone (κ : Kernel α (γ × β)) [IsFiniteKernel κ]
(n : ℕ) (a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) :
∀ᵐ x ∂(fst κ a), Tendsto (fun m ↦ densityProcess κ (fst κ) n a x (seq m)) atTop (𝓝 1) := by
filter_upwards [densityProcess_fst_univ_ae κ n a] with x hx
rw [← hx]
exact tendsto_densityProcess_fst_atTop_univ_of_monotone κ n a x seq hseq hseq_iUnion
lemma density_fst_univ (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (a : α) :
∀ᵐ x ∂(fst κ a), density κ (fst κ) a x univ = 1 := by
have h := fun n ↦ densityProcess_fst_univ_ae κ n a
rw [← ae_all_iff] at h
filter_upwards [h] with x hx
simp [density, hx]
lemma tendsto_density_fst_atTop_ae_of_monotone [IsFiniteKernel κ]
(a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
∀ᵐ x ∂(fst κ a), Tendsto (fun m ↦ density κ (fst κ) a x (seq m)) atTop (𝓝 1) := by
refine tendsto_of_integral_tendsto_of_monotone ?_ (integrable_const _) ?_ ?_ ?_
· exact fun m ↦ integrable_density le_rfl _ (hseq_meas m)
· rw [MeasureTheory.integral_const, smul_eq_mul, mul_one]
convert tendsto_integral_density_of_monotone (κ := κ) le_rfl a seq hseq hseq_iUnion hseq_meas
simp only [measureReal_def]
rw [fst_apply' _ _ MeasurableSet.univ]
simp only [mem_univ, setOf_true]
· exact ae_of_all _ (fun c n m hnm ↦ density_mono_set le_rfl a c (hseq hnm))
· exact ae_of_all _ (fun x m ↦ density_le_one le_rfl a x (seq m))
end UnivFst
end Density
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/Basic.lean | import Mathlib.MeasureTheory.Function.AEEqOfLIntegral
import Mathlib.Probability.Kernel.Composition.MeasureCompProd
/-!
# Disintegration of measures and kernels
This file defines predicates for a kernel to "disintegrate" a measure or a kernel. This kernel is
also called the "conditional kernel" of the measure or kernel.
A measure `ρ : Measure (α × Ω)` is disintegrated by a kernel `ρCond : Kernel α Ω` if
`ρ.fst ⊗ₘ ρCond = ρ`.
A kernel `ρ : Kernel α (β × Ω)` is disintegrated by a kernel `κCond : Kernel (α × β) Ω` if
`κ.fst ⊗ₖ κCond = κ`.
## Main definitions
* `MeasureTheory.Measure.IsCondKernel ρ ρCond`: Predicate for the kernel `ρCond` to disintegrate the
measure `ρ`.
* `ProbabilityTheory.Kernel.IsCondKernel κ κCond`: Predicate for the kernel `κ Cond` to disintegrate
the kernel `κ`.
Further, if `κ` is an s-finite kernel from a countable `α` such that each measure `κ a` is
disintegrated by some kernel, then `κ` itself is disintegrated by a kernel, namely
`ProbabilityTheory.Kernel.condKernelCountable`.
## See also
`Mathlib/Probability/Kernel/Disintegration/StandardBorel.lean` for a **construction** of
disintegrating kernels.
-/
open MeasureTheory Set Filter MeasurableSpace ProbabilityTheory
open scoped ENNReal MeasureTheory Topology
variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mΩ : MeasurableSpace Ω}
/-!
### Disintegration of measures
This section provides a predicate for a kernel to disintegrate a measure.
-/
namespace MeasureTheory.Measure
variable (ρ : Measure (α × Ω)) (ρCond : Kernel α Ω)
/-- A kernel `ρCond` is a conditional kernel for a measure `ρ` if it disintegrates it in the sense
that `ρ.fst ⊗ₘ ρCond = ρ`. -/
class IsCondKernel : Prop where
disintegrate : ρ.fst ⊗ₘ ρCond = ρ
variable [ρ.IsCondKernel ρCond]
lemma disintegrate : ρ.fst ⊗ₘ ρCond = ρ := IsCondKernel.disintegrate
lemma IsCondKernel.isSFiniteKernel (hρ : ρ ≠ 0) : IsSFiniteKernel ρCond := by
contrapose! hρ; rwa [← ρ.disintegrate ρCond, Measure.compProd_of_not_isSFiniteKernel]
variable [IsFiniteMeasure ρ]
/-- Auxiliary lemma for `IsCondKernel.apply_of_ne_zero`. -/
private lemma IsCondKernel.apply_of_ne_zero_of_measurableSet [MeasurableSingletonClass α] {x : α}
(hx : ρ.fst {x} ≠ 0) {s : Set Ω} (hs : MeasurableSet s) :
ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by
have := isSFiniteKernel ρ ρCond (by rintro rfl; simp at hx)
nth_rewrite 2 [← ρ.disintegrate ρCond]
rw [Measure.compProd_apply (measurableSet_prod.mpr (Or.inl ⟨measurableSet_singleton x, hs⟩))]
classical
have (a : _) : ρCond a (Prod.mk a ⁻¹' {x} ×ˢ s) = ({x} : Set α).indicator (ρCond · s) a := by
obtain rfl | hax := eq_or_ne a x
· simp only [singleton_prod, mem_singleton_iff, indicator_of_mem]
congr with y
simp
· simp only [singleton_prod, mem_singleton_iff, hax, not_false_eq_true, indicator_of_notMem]
have : Prod.mk a ⁻¹' (Prod.mk x '' s) = ∅ := by ext y; simp [Ne.symm hax]
simp only [this, measure_empty]
simp_rw [this]
rw [MeasureTheory.lintegral_indicator (measurableSet_singleton x)]
simp only [Measure.restrict_singleton, lintegral_smul_measure, lintegral_dirac, smul_eq_mul]
rw [← mul_assoc, ENNReal.inv_mul_cancel hx (measure_ne_top _ _), one_mul]
/-- If the singleton `{x}` has non-zero mass for `ρ.fst`, then for all `s : Set Ω`,
`ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s)` . -/
lemma IsCondKernel.apply_of_ne_zero [MeasurableSingletonClass α] {x : α}
(hx : ρ.fst {x} ≠ 0) (s : Set Ω) : ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by
have : ρCond x s = ((ρ.fst {x})⁻¹ • ρ).comap (fun (y : Ω) ↦ (x, y)) s := by
congr 2 with s hs
simp [IsCondKernel.apply_of_ne_zero_of_measurableSet _ _ hx hs,
(measurableEmbedding_prodMk_left x).comap_apply, Set.singleton_prod]
simp [this, (measurableEmbedding_prodMk_left x).comap_apply, Set.singleton_prod]
lemma IsCondKernel.isProbabilityMeasure [MeasurableSingletonClass α] {a : α} (ha : ρ.fst {a} ≠ 0) :
IsProbabilityMeasure (ρCond a) := by
constructor
rw [IsCondKernel.apply_of_ne_zero _ _ ha, prod_univ, ← Measure.fst_apply
(measurableSet_singleton _), ENNReal.inv_mul_cancel ha (measure_ne_top _ _)]
lemma IsCondKernel.isMarkovKernel [MeasurableSingletonClass α] (hρ : ∀ a, ρ.fst {a} ≠ 0) :
IsMarkovKernel ρCond := ⟨fun _ ↦ isProbabilityMeasure _ _ (hρ _)⟩
end MeasureTheory.Measure
/-!
### Disintegration of kernels
This section provides a predicate for a kernel to disintegrate a kernel. It also proves that if `κ`
is an s-finite kernel from a countable `α` such that each measure `κ a` is disintegrated by some
kernel, then `κ` itself is disintegrated by a kernel, namely
`ProbabilityTheory.Kernel.condKernelCountable`.
-/
namespace ProbabilityTheory.Kernel
variable (κ : Kernel α (β × Ω)) (κCond : Kernel (α × β) Ω)
/-! #### Predicate for a kernel to disintegrate a kernel -/
/-- A kernel `κCond` is a conditional kernel for a kernel `κ` if it disintegrates it in the sense
that `κ.fst ⊗ₖ κCond = κ`. -/
class IsCondKernel : Prop where
protected disintegrate : κ.fst ⊗ₖ κCond = κ
instance instIsCondKernel_zero (κCond : Kernel (α × β) Ω) : IsCondKernel 0 κCond where
disintegrate := by simp
lemma disintegrate [κ.IsCondKernel κCond] : κ.fst ⊗ₖ κCond = κ := IsCondKernel.disintegrate
/-- A conditional kernel is almost everywhere a probability measure. -/
lemma IsCondKernel.isProbabilityMeasure_ae [IsFiniteKernel κ.fst] [κ.IsCondKernel κCond] (a : α) :
∀ᵐ b ∂(κ.fst a), IsProbabilityMeasure (κCond (a, b)) := by
have h := disintegrate κ κCond
by_cases h_sfin : IsSFiniteKernel κCond
swap; · rw [Kernel.compProd_of_not_isSFiniteKernel_right _ _ h_sfin] at h; simp [h.symm]
suffices ∀ᵐ b ∂(κ.fst a), κCond (a, b) Set.univ = 1 by
convert this with b
exact ⟨fun _ ↦ measure_univ, fun h ↦ ⟨h⟩⟩
suffices (∀ᵐ b ∂(κ.fst a), κCond (a, b) Set.univ ≤ 1)
∧ (∀ᵐ b ∂(κ.fst a), 1 ≤ κCond (a, b) Set.univ) by
filter_upwards [this.1, this.2] with b h1 h2 using le_antisymm h1 h2
have h_eq s (hs : MeasurableSet s) :
∫⁻ b, s.indicator (fun b ↦ κCond (a, b) Set.univ) b ∂κ.fst a = κ.fst a s := by
conv_rhs => rw [← h]
rw [fst_compProd_apply _ _ _ hs]
have h_meas : Measurable fun b ↦ κCond (a, b) Set.univ :=
(κCond.measurable_coe MeasurableSet.univ).comp measurable_prodMk_left
constructor
· rw [ae_le_const_iff_forall_gt_measure_zero]
intro r hr
let s := {b | r ≤ κCond (a, b) Set.univ}
have hs : MeasurableSet s := h_meas measurableSet_Ici
have h_2_le : s.indicator (fun _ ↦ r) ≤ s.indicator (fun b ↦ (κCond (a, b)) Set.univ) := by
intro b
by_cases hbs : b ∈ s
· simpa [hbs]
· simp [hbs]
have : ∫⁻ b, s.indicator (fun _ ↦ r) b ∂(κ.fst a) ≤ κ.fst a s :=
(lintegral_mono h_2_le).trans_eq (h_eq s hs)
rw [lintegral_indicator_const hs] at this
contrapose! this with h_ne_zero
conv_lhs => rw [← one_mul (κ.fst a s)]
gcongr
finiteness
· rw [ae_const_le_iff_forall_lt_measure_zero]
intro r hr
let s := {b | κCond (a, b) Set.univ ≤ r}
have hs : MeasurableSet s := h_meas measurableSet_Iic
have h_2_le : s.indicator (fun b ↦ (κCond (a, b)) Set.univ) ≤ s.indicator (fun _ ↦ r) := by
intro b
by_cases hbs : b ∈ s
· simpa [hbs]
· simp [hbs]
have : κ.fst a s ≤ ∫⁻ b, s.indicator (fun _ ↦ r) b ∂(κ.fst a) :=
(h_eq s hs).symm.trans_le (lintegral_mono h_2_le)
rw [lintegral_indicator_const hs] at this
contrapose! this with h_ne_zero
conv_rhs => rw [← one_mul (κ.fst a s)]
gcongr
finiteness
/-! #### Existence of a disintegrating kernel in a countable space -/
section Countable
variable [Countable α] (κCond : α → Kernel β Ω)
/-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel α (β × Ω)` where `α` is countable and `Ω` is a measurable
space. -/
noncomputable def condKernelCountable (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) :
Kernel (α × β) Ω where
toFun p := κCond p.1 p.2
measurable' := by
refine measurable_from_prod_countable_right' (fun a ↦ (κCond a).measurable) fun x y hx hy ↦ ?_
simpa using DFunLike.congr (h_atom _ _ hy) rfl
lemma condKernelCountable_apply (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y)
(p : α × β) : condKernelCountable κCond h_atom p = κCond p.1 p.2 := rfl
instance condKernelCountable.instIsMarkovKernel [∀ a, IsMarkovKernel (κCond a)]
(h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) :
IsMarkovKernel (condKernelCountable κCond h_atom) where
isProbabilityMeasure p := (‹∀ a, IsMarkovKernel (κCond a)› p.1).isProbabilityMeasure p.2
instance condKernelCountable.instIsCondKernel [∀ a, IsMarkovKernel (κCond a)]
(h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) (κ : Kernel α (β × Ω))
[IsSFiniteKernel κ] [∀ a, (κ a).IsCondKernel (κCond a)] :
κ.IsCondKernel (condKernelCountable κCond h_atom) := by
constructor
ext a s hs
conv_rhs => rw [← (κ a).disintegrate (κCond a)]
simp_rw [compProd_apply hs, condKernelCountable_apply, Measure.compProd_apply hs]
congr
end Countable
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/Unique.lean | import Mathlib.Probability.Kernel.Disintegration.Integral
/-!
# Uniqueness of the conditional kernel
We prove that the conditional kernels `ProbabilityTheory.Kernel.condKernel` and
`MeasureTheory.Measure.condKernel` are almost everywhere unique.
## Main statements
* `ProbabilityTheory.eq_condKernel_of_kernel_eq_compProd`: a.e. uniqueness of
`ProbabilityTheory.Kernel.condKernel`
* `ProbabilityTheory.eq_condKernel_of_measure_eq_compProd`: a.e. uniqueness of
`MeasureTheory.Measure.condKernel`
* `ProbabilityTheory.Kernel.condKernel_apply_eq_condKernel`: the kernel `condKernel` is almost
everywhere equal to the measure `condKernel`.
-/
open MeasureTheory Set Filter MeasurableSpace
open scoped ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory
variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
[MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω]
section Measure
variable {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ]
/-! ### Uniqueness of `Measure.condKernel`
The conditional kernel of a measure is unique almost everywhere. -/
/-- A s-finite kernel which satisfy the disintegration property of the given measure `ρ` is almost
everywhere equal to the disintegration kernel of `ρ` when evaluated on a measurable set.
This theorem in the case of finite kernels is weaker than `eq_condKernel_of_measure_eq_compProd`
which asserts that the kernels are equal almost everywhere and not just on a given measurable
set. -/
theorem eq_condKernel_of_measure_eq_compProd' (κ : Kernel α Ω) [IsSFiniteKernel κ]
(hκ : ρ = ρ.fst ⊗ₘ κ) {s : Set Ω} (hs : MeasurableSet s) :
∀ᵐ x ∂ρ.fst, κ x s = ρ.condKernel x s := by
refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite
(Kernel.measurable_coe κ hs) (Kernel.measurable_coe ρ.condKernel hs) (fun t ht _ ↦ ?_)
conv_rhs => rw [Measure.setLIntegral_condKernel_eq_measure_prod ht hs, hκ]
simp only [Measure.compProd_apply (ht.prod hs), ← lintegral_indicator ht]
congr with x
by_cases hx : x ∈ t <;> simp [hx]
/-- Auxiliary lemma for `eq_condKernel_of_measure_eq_compProd`.
Uniqueness of the disintegration kernel on ℝ. -/
lemma eq_condKernel_of_measure_eq_compProd_real {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ]
(κ : Kernel α ℝ) [IsFiniteKernel κ] (hκ : ρ = ρ.fst ⊗ₘ κ) :
∀ᵐ x ∂ρ.fst, κ x = ρ.condKernel x := by
have huniv : ∀ᵐ x ∂ρ.fst, κ x Set.univ = ρ.condKernel x Set.univ :=
eq_condKernel_of_measure_eq_compProd' κ hκ MeasurableSet.univ
suffices ∀ᵐ x ∂ρ.fst, ∀ ⦃t⦄, MeasurableSet t → κ x t = ρ.condKernel x t by
filter_upwards [this] with x hx
ext t ht; exact hx ht
apply MeasurableSpace.ae_induction_on_inter Real.borel_eq_generateFrom_Iic_rat
Real.isPiSystem_Iic_rat
· simp
· simp only [iUnion_singleton_eq_range, mem_range, forall_exists_index, forall_apply_eq_imp_iff]
exact ae_all_iff.2 fun q ↦ eq_condKernel_of_measure_eq_compProd' κ hκ measurableSet_Iic
· filter_upwards [huniv] with x hxuniv t ht heq
rw [measure_compl ht <| measure_ne_top _ _, heq, hxuniv, measure_compl ht <| measure_ne_top _ _]
· refine ae_of_all _ (fun x f hdisj hf heq ↦ ?_)
rw [measure_iUnion hdisj hf, measure_iUnion hdisj hf]
exact tsum_congr heq
/-- A finite kernel which satisfies the disintegration property is almost everywhere equal to the
disintegration kernel. -/
theorem eq_condKernel_of_measure_eq_compProd (κ : Kernel α Ω) [IsFiniteKernel κ]
(hκ : ρ = ρ.fst ⊗ₘ κ) :
∀ᵐ x ∂ρ.fst, κ x = ρ.condKernel x := by
-- The idea is to transport the question to `ℝ` from `Ω` using `embeddingReal`
-- and then construct a measure on `α × ℝ`
let f := embeddingReal Ω
have hf := measurableEmbedding_embeddingReal Ω
set ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f) with hρ'def
have hρ' : ρ'.fst = ρ.fst := by
ext s hs
rw [hρ'def, Measure.fst_apply, Measure.fst_apply, Measure.map_apply]
exacts [rfl, Measurable.prod measurable_fst <| hf.measurable.comp measurable_snd,
measurable_fst hs, hs, hs]
have hρ'' : ∀ᵐ x ∂ρ.fst, Kernel.map κ f x = ρ'.condKernel x := by
rw [← hρ']
refine eq_condKernel_of_measure_eq_compProd_real (Kernel.map κ f) ?_
ext s hs
conv_lhs => rw [hρ'def, hκ]
rw [Measure.map_apply (measurable_id.prodMap hf.measurable) hs, hρ',
Measure.compProd_apply hs, Measure.compProd_apply (measurable_id.prodMap hf.measurable hs)]
congr with a
rw [Kernel.map_apply' _ hf.measurable]
exacts [rfl, measurable_prodMk_left hs]
suffices ∀ᵐ x ∂ρ.fst, ∀ s, MeasurableSet s → ρ'.condKernel x s = ρ.condKernel x (f ⁻¹' s) by
filter_upwards [hρ'', this] with x hx h
rw [Kernel.map_apply _ hf.measurable] at hx
ext s hs
rw [← Set.preimage_image_eq s hf.injective,
← Measure.map_apply hf.measurable <| hf.measurableSet_image.2 hs, hx,
h _ <| hf.measurableSet_image.2 hs]
suffices ρ.map (Prod.map id f) = (ρ.fst ⊗ₘ (Kernel.map ρ.condKernel f)) by
rw [← hρ'] at this
have heq := eq_condKernel_of_measure_eq_compProd_real _ this
rw [hρ'] at heq
filter_upwards [heq] with x hx s hs
rw [← hx, Kernel.map_apply _ hf.measurable, Measure.map_apply hf.measurable hs]
ext s hs
conv_lhs => rw [← ρ.disintegrate ρ.condKernel]
rw [Measure.compProd_apply hs, Measure.map_apply (measurable_id.prodMap hf.measurable) hs,
Measure.compProd_apply]
· congr with a
rw [Kernel.map_apply' _ hf.measurable]
exacts [rfl, measurable_prodMk_left hs]
· exact measurable_id.prodMap hf.measurable hs
lemma condKernel_compProd (μ : Measure α) [IsFiniteMeasure μ] (κ : Kernel α Ω) [IsMarkovKernel κ] :
(μ ⊗ₘ κ).condKernel =ᵐ[μ] κ := by
suffices κ =ᵐ[(μ ⊗ₘ κ).fst] (μ ⊗ₘ κ).condKernel by symm; rwa [Measure.fst_compProd] at this
refine eq_condKernel_of_measure_eq_compProd _ ?_
rw [Measure.fst_compProd]
end Measure
section KernelAndMeasure
lemma Kernel.apply_eq_measure_condKernel_of_compProd_eq
{ρ : Kernel α (β × Ω)} [IsFiniteKernel ρ] {κ : Kernel (α × β) Ω} [IsFiniteKernel κ]
(hκ : Kernel.fst ρ ⊗ₖ κ = ρ) (a : α) :
(fun b ↦ κ (a, b)) =ᵐ[Kernel.fst ρ a] (ρ a).condKernel := by
have : ρ a = (ρ a).fst ⊗ₘ Kernel.comap κ (fun b ↦ (a, b)) measurable_prodMk_left := by
ext s hs
conv_lhs => rw [← hκ]
rw [Measure.compProd_apply hs, Kernel.compProd_apply hs]
rfl
have h := eq_condKernel_of_measure_eq_compProd _ this
rw [Kernel.fst_apply]
filter_upwards [h] with b hb
rw [← hb, Kernel.comap_apply]
/-- For `fst κ a`-almost all `b`, the conditional kernel `Kernel.condKernel κ` applied to `(a, b)`
is equal to the conditional kernel of the measure `κ a` applied to `b`. -/
lemma Kernel.condKernel_apply_eq_condKernel [CountableOrCountablyGenerated α β]
(κ : Kernel α (β × Ω)) [IsFiniteKernel κ] (a : α) :
(fun b ↦ Kernel.condKernel κ (a, b)) =ᵐ[Kernel.fst κ a] (κ a).condKernel :=
Kernel.apply_eq_measure_condKernel_of_compProd_eq (κ.disintegrate _) a
lemma condKernel_const [CountableOrCountablyGenerated α β] (ρ : Measure (β × Ω)) [IsFiniteMeasure ρ]
(a : α) :
(fun b ↦ Kernel.condKernel (Kernel.const α ρ) (a, b)) =ᵐ[ρ.fst] ρ.condKernel := by
have h := Kernel.condKernel_apply_eq_condKernel (Kernel.const α ρ) a
simp_rw [Kernel.fst_apply, Kernel.const_apply] at h
filter_upwards [h] with b hb using hb
end KernelAndMeasure
section Kernel
/-! ### Uniqueness of `Kernel.condKernel`
The conditional kernel is unique almost everywhere. -/
/-- A finite kernel which satisfies the disintegration property is almost everywhere equal to the
disintegration kernel. -/
theorem eq_condKernel_of_kernel_eq_compProd [CountableOrCountablyGenerated α β]
{ρ : Kernel α (β × Ω)} [IsFiniteKernel ρ] {κ : Kernel (α × β) Ω} [IsFiniteKernel κ]
(hκ : Kernel.fst ρ ⊗ₖ κ = ρ) (a : α) :
∀ᵐ x ∂(Kernel.fst ρ a), κ (a, x) = Kernel.condKernel ρ (a, x) := by
filter_upwards [Kernel.condKernel_apply_eq_condKernel ρ a,
Kernel.apply_eq_measure_condKernel_of_compProd_eq hκ a] with a h1 h2
rw [h1, h2]
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/CondCDF.lean | import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Probability.Kernel.Disintegration.CDFToKernel
/-!
# Conditional cumulative distribution function
Given `ρ : Measure (α × ℝ)`, we define the conditional cumulative distribution function
(conditional cdf) of `ρ`. It is a function `condCDF ρ : α → ℝ → ℝ` such that if `ρ` is a finite
measure, then for all `a : α` `condCDF ρ a` is monotone and right-continuous with limit 0 at -∞
and limit 1 at +∞, and such that for all `x : ℝ`, `a ↦ condCDF ρ a x` is measurable. For all
`x : ℝ` and measurable set `s`, that function satisfies
`∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x)`.
`condCDF` is build from the more general tools about kernel CDFs developed in the file
`Probability.Kernel.Disintegration.CDFToKernel`. In that file, we build a function
`α × β → StieltjesFunction` (which is `α × β → ℝ → ℝ` with additional properties) from a function
`α × β → ℚ → ℝ`. The restriction to `ℚ` allows to prove some properties like measurability more
easily. Here we apply that construction to the case `β = Unit` and then drop `β` to build
`condCDF : α → StieltjesFunction`.
## Main definitions
* `ProbabilityTheory.condCDF ρ : α → StieltjesFunction`: the conditional cdf of
`ρ : Measure (α × ℝ)`. A `StieltjesFunction` is a function `ℝ → ℝ` which is monotone and
right-continuous.
## Main statements
* `ProbabilityTheory.setLIntegral_condCDF`: for all `a : α` and `x : ℝ`, all measurable set `s`,
`∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x)`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped NNReal ENNReal MeasureTheory Topology
namespace MeasureTheory.Measure
variable {α : Type*} {mα : MeasurableSpace α} (ρ : Measure (α × ℝ))
/-- Measure on `α` such that for a measurable set `s`, `ρ.IicSnd r s = ρ (s ×ˢ Iic r)`. -/
noncomputable def IicSnd (r : ℝ) : Measure α :=
(ρ.restrict (univ ×ˢ Iic r)).fst
theorem IicSnd_apply (r : ℝ) {s : Set α} (hs : MeasurableSet s) :
ρ.IicSnd r s = ρ (s ×ˢ Iic r) := by
rw [IicSnd, fst_apply hs, restrict_apply' (MeasurableSet.univ.prod measurableSet_Iic),
univ_prod, Set.prod_eq]
theorem IicSnd_univ (r : ℝ) : ρ.IicSnd r univ = ρ (univ ×ˢ Iic r) :=
IicSnd_apply ρ r MeasurableSet.univ
@[gcongr]
theorem IicSnd_mono {r r' : ℝ} (h_le : r ≤ r') : ρ.IicSnd r ≤ ρ.IicSnd r' := by
unfold IicSnd; gcongr
theorem IicSnd_le_fst (r : ℝ) : ρ.IicSnd r ≤ ρ.fst :=
fst_mono restrict_le_self
theorem IicSnd_ac_fst (r : ℝ) : ρ.IicSnd r ≪ ρ.fst :=
Measure.absolutelyContinuous_of_le (IicSnd_le_fst ρ r)
theorem IsFiniteMeasure.IicSnd {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ] (r : ℝ) :
IsFiniteMeasure (ρ.IicSnd r) :=
isFiniteMeasure_of_le _ (IicSnd_le_fst ρ _)
theorem iInf_IicSnd_gt (t : ℚ) {s : Set α} (hs : MeasurableSet s) [IsFiniteMeasure ρ] :
⨅ r : { r' : ℚ // t < r' }, ρ.IicSnd r s = ρ.IicSnd t s := by
simp_rw [ρ.IicSnd_apply _ hs, Measure.iInf_rat_gt_prod_Iic hs]
theorem tendsto_IicSnd_atTop {s : Set α} (hs : MeasurableSet s) :
Tendsto (fun r : ℚ ↦ ρ.IicSnd r s) atTop (𝓝 (ρ.fst s)) := by
simp_rw [ρ.IicSnd_apply _ hs, fst_apply hs, ← prod_univ]
rw [← Real.iUnion_Iic_rat, prod_iUnion]
apply tendsto_measure_iUnion_atTop
exact monotone_const.set_prod Rat.cast_mono.Iic
theorem tendsto_IicSnd_atBot [IsFiniteMeasure ρ] {s : Set α} (hs : MeasurableSet s) :
Tendsto (fun r : ℚ ↦ ρ.IicSnd r s) atBot (𝓝 0) := by
simp_rw [ρ.IicSnd_apply _ hs]
have h_empty : ρ (s ×ˢ ∅) = 0 := by simp only [prod_empty, measure_empty]
rw [← h_empty, ← Real.iInter_Iic_rat, prod_iInter]
suffices h_neg :
Tendsto (fun r : ℚ ↦ ρ (s ×ˢ Iic ↑(-r))) atTop (𝓝 (ρ (⋂ r : ℚ, s ×ˢ Iic ↑(-r)))) by
have h_inter_eq : ⋂ r : ℚ, s ×ˢ Iic ↑(-r) = ⋂ r : ℚ, s ×ˢ Iic (r : ℝ) := by
ext1 x
simp only [mem_iInter, mem_prod, mem_Iic]
refine ⟨fun h i ↦ ⟨(h i).1, ?_⟩, fun h i ↦ ⟨(h i).1, ?_⟩⟩ <;> have h' := h (-i)
· rw [neg_neg] at h'; exact h'.2
· exact h'.2
rw [h_inter_eq] at h_neg
have h_fun_eq : (fun r : ℚ ↦ ρ (s ×ˢ Iic (r : ℝ))) = fun r : ℚ ↦ ρ (s ×ˢ Iic ↑(- -r)) := by
simp_rw [neg_neg]
rw [h_fun_eq]
exact h_neg.comp tendsto_neg_atBot_atTop
refine tendsto_measure_iInter_atTop (fun q ↦ (hs.prod measurableSet_Iic).nullMeasurableSet)
?_ ⟨0, measure_ne_top ρ _⟩
refine fun q r hqr ↦ Set.prod_mono subset_rfl fun x hx ↦ ?_
simp only [Rat.cast_neg, mem_Iic] at hx ⊢
refine hx.trans (neg_le_neg ?_)
exact mod_cast hqr
end MeasureTheory.Measure
open MeasureTheory
namespace ProbabilityTheory
variable {α : Type*} {mα : MeasurableSpace α}
attribute [local instance] MeasureTheory.Measure.IsFiniteMeasure.IicSnd
/-! ### Auxiliary definitions
We build towards the definition of `ProbabilityTheory.condCDF`. We first define
`ProbabilityTheory.preCDF`, a function defined on `α × ℚ` with the properties of a cdf almost
everywhere. -/
/-- `preCDF` is the Radon-Nikodym derivative of `ρ.IicSnd` with respect to `ρ.fst` at each
`r : ℚ`. This function `ℚ → α → ℝ≥0∞` is such that for almost all `a : α`, the function `ℚ → ℝ≥0∞`
satisfies the properties of a cdf (monotone with limit 0 at -∞ and 1 at +∞, right-continuous).
We define this function on `ℚ` and not `ℝ` because `ℚ` is countable, which allows us to prove
properties of the form `∀ᵐ a ∂ρ.fst, ∀ q, P (preCDF q a)`, instead of the weaker
`∀ q, ∀ᵐ a ∂ρ.fst, P (preCDF q a)`. -/
noncomputable def preCDF (ρ : Measure (α × ℝ)) (r : ℚ) : α → ℝ≥0∞ :=
Measure.rnDeriv (ρ.IicSnd r) ρ.fst
theorem measurable_preCDF {ρ : Measure (α × ℝ)} {r : ℚ} : Measurable (preCDF ρ r) :=
Measure.measurable_rnDeriv _ _
lemma measurable_preCDF' {ρ : Measure (α × ℝ)} :
Measurable fun a r ↦ (preCDF ρ r a).toReal := by
rw [measurable_pi_iff]
exact fun _ ↦ measurable_preCDF.ennreal_toReal
theorem withDensity_preCDF (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] :
ρ.fst.withDensity (preCDF ρ r) = ρ.IicSnd r :=
Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq.mp (Measure.IicSnd_ac_fst ρ r)
theorem setLIntegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) {s : Set α} (hs : MeasurableSet s)
[IsFiniteMeasure ρ] : ∫⁻ x in s, preCDF ρ r x ∂ρ.fst = ρ.IicSnd r s := by
have : ∀ r, ∫⁻ x in s, preCDF ρ r x ∂ρ.fst = ∫⁻ x in s, (preCDF ρ r * 1) x ∂ρ.fst := by
simp only [mul_one, forall_const]
rw [this, ← setLIntegral_withDensity_eq_setLIntegral_mul _ measurable_preCDF _ hs]
· simp only [withDensity_preCDF ρ r, Pi.one_apply, lintegral_one, Measure.restrict_apply,
MeasurableSet.univ, univ_inter]
· rw [Pi.one_def]
exact measurable_const
lemma lintegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] :
∫⁻ x, preCDF ρ r x ∂ρ.fst = ρ.IicSnd r univ := by
rw [← setLIntegral_univ, setLIntegral_preCDF_fst ρ r MeasurableSet.univ]
theorem monotone_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] :
∀ᵐ a ∂ρ.fst, Monotone fun r ↦ preCDF ρ r a := by
simp_rw [Monotone, ae_all_iff]
refine fun r r' hrr' ↦ ae_le_of_forall_setLIntegral_le_of_sigmaFinite measurable_preCDF
fun s hs _ ↦ ?_
rw [setLIntegral_preCDF_fst ρ r hs, setLIntegral_preCDF_fst ρ r' hs]
exact Measure.IicSnd_mono ρ (mod_cast hrr') s
theorem preCDF_le_one (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] :
∀ᵐ a ∂ρ.fst, ∀ r, preCDF ρ r a ≤ 1 := by
rw [ae_all_iff]
refine fun r ↦ ae_le_of_forall_setLIntegral_le_of_sigmaFinite measurable_preCDF fun s hs _ ↦ ?_
rw [setLIntegral_preCDF_fst ρ r hs]
simp only [lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter]
exact Measure.IicSnd_le_fst ρ r s
lemma setIntegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) {s : Set α} (hs : MeasurableSet s)
[IsFiniteMeasure ρ] :
∫ x in s, (preCDF ρ r x).toReal ∂ρ.fst = (ρ.IicSnd r).real s := by
rw [integral_toReal]
· rw [setLIntegral_preCDF_fst _ _ hs, measureReal_def]
· exact measurable_preCDF.aemeasurable
· refine ae_restrict_of_ae ?_
filter_upwards [preCDF_le_one ρ] with a ha
exact (ha r).trans_lt ENNReal.one_lt_top
lemma integral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] :
∫ x, (preCDF ρ r x).toReal ∂ρ.fst = (ρ.IicSnd r).real univ := by
rw [← setIntegral_univ, setIntegral_preCDF_fst ρ _ MeasurableSet.univ]
lemma integrable_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℚ) :
Integrable (fun a ↦ (preCDF ρ x a).toReal) ρ.fst := by
refine integrable_of_forall_fin_meas_le _ (measure_lt_top ρ.fst univ) ?_ fun t _ _ ↦ ?_
· exact measurable_preCDF.ennreal_toReal.aestronglyMeasurable
· simp_rw [← ofReal_norm_eq_enorm, Real.norm_of_nonneg ENNReal.toReal_nonneg]
rw [← lintegral_one]
refine (setLIntegral_le_lintegral _ _).trans (lintegral_mono_ae ?_)
filter_upwards [preCDF_le_one ρ] with a ha using ENNReal.ofReal_toReal_le.trans (ha _)
lemma isRatCondKernelCDFAux_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] :
IsRatCondKernelCDFAux (fun p r ↦ (preCDF ρ r p.2).toReal)
(Kernel.const Unit ρ) (Kernel.const Unit ρ.fst) where
measurable := measurable_preCDF'.comp measurable_snd
mono' a r r' hrr' := by
filter_upwards [monotone_preCDF ρ, preCDF_le_one ρ] with a h₁ h₂
exact ENNReal.toReal_mono ((h₂ _).trans_lt ENNReal.one_lt_top).ne (h₁ hrr')
nonneg' _ q := by simp
le_one' a q := by
simp only [Kernel.const_apply]
filter_upwards [preCDF_le_one ρ] with a ha
refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_
simp [ha]
tendsto_integral_of_antitone a s _ hs_tendsto := by
simp_rw [Kernel.const_apply, integral_preCDF_fst ρ]
have h := ρ.tendsto_IicSnd_atBot MeasurableSet.univ
rw [← ENNReal.toReal_zero]
have h0 : Tendsto ENNReal.toReal (𝓝 0) (𝓝 0) :=
ENNReal.continuousAt_toReal ENNReal.zero_ne_top
exact h0.comp (h.comp hs_tendsto)
tendsto_integral_of_monotone a s _ hs_tendsto := by
simp_rw [Kernel.const_apply, integral_preCDF_fst ρ]
have h := ρ.tendsto_IicSnd_atTop MeasurableSet.univ
have h0 : Tendsto ENNReal.toReal (𝓝 (ρ.fst univ)) (𝓝 (ρ.fst.real univ)) :=
ENNReal.continuousAt_toReal (measure_ne_top _ _)
exact h0.comp (h.comp hs_tendsto)
integrable _ q := integrable_preCDF ρ q
setIntegral a s hs q := by rw [Kernel.const_apply, Kernel.const_apply,
setIntegral_preCDF_fst _ _ hs, measureReal_def, measureReal_def, Measure.IicSnd_apply _ _ hs]
lemma isRatCondKernelCDF_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] :
IsRatCondKernelCDF (fun p r ↦ (preCDF ρ r p.2).toReal)
(Kernel.const Unit ρ) (Kernel.const Unit ρ.fst) :=
(isRatCondKernelCDFAux_preCDF ρ).isRatCondKernelCDF
/-! ### Conditional cdf -/
/-- Conditional cdf of the measure given the value on `α`, as a Stieltjes function. -/
noncomputable def condCDF (ρ : Measure (α × ℝ)) (a : α) : StieltjesFunction :=
stieltjesOfMeasurableRat (fun a r ↦ (preCDF ρ r a).toReal) measurable_preCDF' a
lemma condCDF_eq_stieltjesOfMeasurableRat_unit_prod (ρ : Measure (α × ℝ)) (a : α) :
condCDF ρ a = stieltjesOfMeasurableRat (fun (p : Unit × α) r ↦ (preCDF ρ r p.2).toReal)
(measurable_preCDF'.comp measurable_snd) ((), a) := by
ext x
rw [condCDF, ← stieltjesOfMeasurableRat_unit_prod]
lemma isCondKernelCDF_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] :
IsCondKernelCDF (fun p : Unit × α ↦ condCDF ρ p.2) (Kernel.const Unit ρ)
(Kernel.const Unit ρ.fst) := by
simp_rw [condCDF_eq_stieltjesOfMeasurableRat_unit_prod ρ]
exact isCondKernelCDF_stieltjesOfMeasurableRat (isRatCondKernelCDF_preCDF ρ)
/-- The conditional cdf is non-negative for all `a : α`. -/
theorem condCDF_nonneg (ρ : Measure (α × ℝ)) (a : α) (r : ℝ) : 0 ≤ condCDF ρ a r :=
stieltjesOfMeasurableRat_nonneg _ a r
/-- The conditional cdf is lower or equal to 1 for all `a : α`. -/
theorem condCDF_le_one (ρ : Measure (α × ℝ)) (a : α) (x : ℝ) : condCDF ρ a x ≤ 1 :=
stieltjesOfMeasurableRat_le_one _ _ _
/-- The conditional cdf tends to 0 at -∞ for all `a : α`. -/
theorem tendsto_condCDF_atBot (ρ : Measure (α × ℝ)) (a : α) :
Tendsto (condCDF ρ a) atBot (𝓝 0) := tendsto_stieltjesOfMeasurableRat_atBot _ _
/-- The conditional cdf tends to 1 at +∞ for all `a : α`. -/
theorem tendsto_condCDF_atTop (ρ : Measure (α × ℝ)) (a : α) :
Tendsto (condCDF ρ a) atTop (𝓝 1) := tendsto_stieltjesOfMeasurableRat_atTop _ _
theorem condCDF_ae_eq (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (r : ℚ) :
(fun a ↦ condCDF ρ a r) =ᵐ[ρ.fst] fun a ↦ (preCDF ρ r a).toReal := by
simp_rw [condCDF_eq_stieltjesOfMeasurableRat_unit_prod ρ]
exact stieltjesOfMeasurableRat_ae_eq (isRatCondKernelCDF_preCDF ρ) () r
theorem ofReal_condCDF_ae_eq (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (r : ℚ) :
(fun a ↦ ENNReal.ofReal (condCDF ρ a r)) =ᵐ[ρ.fst] preCDF ρ r := by
filter_upwards [condCDF_ae_eq ρ r, preCDF_le_one ρ] with a ha ha_le_one
rw [ha, ENNReal.ofReal_toReal]
exact ((ha_le_one r).trans_lt ENNReal.one_lt_top).ne
/-- The conditional cdf is a measurable function of `a : α` for all `x : ℝ`. -/
theorem measurable_condCDF (ρ : Measure (α × ℝ)) (x : ℝ) : Measurable fun a ↦ condCDF ρ a x :=
measurable_stieltjesOfMeasurableRat _ _
/-- The conditional cdf is a strongly measurable function of `a : α` for all `x : ℝ`. -/
theorem stronglyMeasurable_condCDF (ρ : Measure (α × ℝ)) (x : ℝ) :
StronglyMeasurable fun a ↦ condCDF ρ a x := stronglyMeasurable_stieltjesOfMeasurableRat _ _
theorem setLIntegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) {s : Set α}
(hs : MeasurableSet s) :
∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x) :=
(isCondKernelCDF_condCDF ρ).setLIntegral () hs x
theorem lintegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) :
∫⁻ a, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (univ ×ˢ Iic x) :=
(isCondKernelCDF_condCDF ρ).lintegral () x
theorem integrable_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) :
Integrable (fun a ↦ condCDF ρ a x) ρ.fst :=
(isCondKernelCDF_condCDF ρ).integrable () x
theorem setIntegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) {s : Set α}
(hs : MeasurableSet s) : ∫ a in s, condCDF ρ a x ∂ρ.fst = ρ.real (s ×ˢ Iic x) :=
(isCondKernelCDF_condCDF ρ).setIntegral () hs x
theorem integral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) :
∫ a, condCDF ρ a x ∂ρ.fst = ρ.real (univ ×ˢ Iic x) :=
(isCondKernelCDF_condCDF ρ).integral () x
section Measure
theorem measure_condCDF_Iic (ρ : Measure (α × ℝ)) (a : α) (x : ℝ) :
(condCDF ρ a).measure (Iic x) = ENNReal.ofReal (condCDF ρ a x) := by
rw [← sub_zero (condCDF ρ a x)]
exact (condCDF ρ a).measure_Iic (tendsto_condCDF_atBot ρ a) _
theorem measure_condCDF_univ (ρ : Measure (α × ℝ)) (a : α) : (condCDF ρ a).measure univ = 1 := by
rw [← ENNReal.ofReal_one, ← sub_zero (1 : ℝ)]
exact StieltjesFunction.measure_univ _ (tendsto_condCDF_atBot ρ a) (tendsto_condCDF_atTop ρ a)
instance instIsProbabilityMeasureCondCDF (ρ : Measure (α × ℝ)) (a : α) :
IsProbabilityMeasure (condCDF ρ a).measure :=
⟨measure_condCDF_univ ρ a⟩
/-- The function `a ↦ (condCDF ρ a).measure` is measurable. -/
theorem measurable_measure_condCDF (ρ : Measure (α × ℝ)) :
Measurable fun a => (condCDF ρ a).measure :=
.measure_of_isPiSystem_of_isProbabilityMeasure (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic <| by
simp_rw [forall_mem_range, measure_condCDF_Iic]
exact fun u ↦ (measurable_condCDF ρ u).ennreal_ofReal
end Measure
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Disintegration/StandardBorel.lean | import Mathlib.Probability.Kernel.Composition.MeasureCompProd
import Mathlib.Probability.Kernel.Disintegration.Basic
import Mathlib.Probability.Kernel.Disintegration.CondCDF
import Mathlib.Probability.Kernel.Disintegration.Density
import Mathlib.Probability.Kernel.Disintegration.CDFToKernel
import Mathlib.MeasureTheory.Constructions.Polish.EmbeddingReal
/-!
# Existence of disintegration of measures and kernels for standard Borel spaces
Let `κ : Kernel α (β × Ω)` be a finite kernel, where `Ω` is a standard Borel space. Then if `α` is
countable or `β` has a countably generated σ-algebra (for example if it is standard Borel), then
there exists a `Kernel (α × β) Ω` called conditional kernel and denoted by `condKernel κ` such that
`κ = fst κ ⊗ₖ condKernel κ`.
We also define a conditional kernel for a measure `ρ : Measure (β × Ω)`, where `Ω` is a standard
Borel space. This is a `Kernel β Ω` denoted by `ρ.condKernel` such that `ρ = ρ.fst ⊗ₘ ρ.condKernel`.
In order to obtain a disintegration for any standard Borel space `Ω`, we use that these spaces embed
measurably into `ℝ`: it then suffices to define a suitable kernel for `Ω = ℝ`.
For `κ : Kernel α (β × ℝ)`, the construction of the conditional kernel proceeds as follows:
* Build a measurable function `f : (α × β) → ℚ → ℝ` such that for all measurable sets
`s` and all `q : ℚ`, `∫ x in s, f (a, x) q ∂(Kernel.fst κ a) = (κ a).real (s ×ˢ Iic (q : ℝ))`.
We restrict to `ℚ` here to be able to prove the measurability.
* Extend that function to `(α × β) → StieltjesFunction`. See the file `MeasurableStieltjes.lean`.
* Finally obtain from the measurable Stieltjes function a measure on `ℝ` for each element of `α × β`
in a measurable way: we have obtained a `Kernel (α × β) ℝ`.
See the file `CDFToKernel.lean` for that step.
The first step (building the measurable function on `ℚ`) is done differently depending on whether
`α` is countable or not.
* If `α` is countable, we can provide for each `a : α` a function `f : β → ℚ → ℝ` and proceed as
above to obtain a `Kernel β ℝ`. Since `α` is countable, measurability is not an issue and we can
put those together into a `Kernel (α × β) ℝ`. The construction of that `f` is done in
the `CondCDF.lean` file.
* If `α` is not countable, we can't proceed separately for each `a : α` and have to build a function
`f : α × β → ℚ → ℝ` which is measurable on the product. We are able to do so if `β` has a
countably generated σ-algebra (this is the case in particular for standard Borel spaces).
See the file `Density.lean`.
The conditional kernel is defined under the typeclass assumption
`CountableOrCountablyGenerated α β`, which encodes the property
`Countable α ∨ CountablyGenerated β`.
Properties of integrals involving `condKernel` are collated in the file `Integral.lean`.
The conditional kernel is unique (almost everywhere w.r.t. `fst κ`): this is proved in the file
`Unique.lean`.
## Main definitions
* `ProbabilityTheory.Kernel.condKernel κ : Kernel (α × β) Ω`: conditional kernel described above.
* `MeasureTheory.Measure.condKernel ρ : Kernel β Ω`: conditional kernel of a measure.
## Main statements
* `ProbabilityTheory.Kernel.compProd_fst_condKernel`: `fst κ ⊗ₖ condKernel κ = κ`
* `MeasureTheory.Measure.compProd_fst_condKernel`: `ρ.fst ⊗ₘ ρ.condKernel = ρ`
-/
open MeasureTheory Set Filter MeasurableSpace
open scoped ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {α β γ Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} [MeasurableSpace.CountablyGenerated γ]
{mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω]
section Real
/-! ### Disintegration of kernels from `α` to `γ × ℝ` for countably generated `γ` -/
lemma isRatCondKernelCDFAux_density_Iic (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] :
IsRatCondKernelCDFAux (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q)) κ (fst κ) where
measurable := measurable_pi_iff.mpr fun _ ↦ measurable_density κ (fst κ) measurableSet_Iic
mono' a q r hqr :=
ae_of_all _ fun c ↦ density_mono_set le_rfl a c (Iic_subset_Iic.mpr (by exact_mod_cast hqr))
nonneg' _ _ := ae_of_all _ fun _ ↦ density_nonneg le_rfl _ _ _
le_one' _ _ := ae_of_all _ fun _ ↦ density_le_one le_rfl _ _ _
tendsto_integral_of_antitone a s hs_anti hs_tendsto := by
let s' : ℕ → Set ℝ := fun n ↦ Iic (s n)
refine tendsto_integral_density_of_antitone le_rfl a s' ?_ ?_ (fun _ ↦ measurableSet_Iic)
· refine fun i j hij ↦ Iic_subset_Iic.mpr ?_
exact mod_cast hs_anti hij
· ext x
simp only [mem_iInter, mem_Iic, mem_empty_iff_false, iff_false, not_forall, not_le, s']
rw [tendsto_atTop_atBot] at hs_tendsto
have ⟨q, hq⟩ := exists_rat_lt x
obtain ⟨i, hi⟩ := hs_tendsto q
refine ⟨i, lt_of_le_of_lt ?_ hq⟩
exact mod_cast hi i le_rfl
tendsto_integral_of_monotone a s hs_mono hs_tendsto := by
rw [fst_real_apply _ _ MeasurableSet.univ]
let s' : ℕ → Set ℝ := fun n ↦ Iic (s n)
refine tendsto_integral_density_of_monotone (le_rfl : fst κ ≤ fst κ)
a s' ?_ ?_ (fun _ ↦ measurableSet_Iic)
· exact fun i j hij ↦ Iic_subset_Iic.mpr (by exact mod_cast hs_mono hij)
· ext x
simp only [mem_iUnion, mem_univ, iff_true]
rw [tendsto_atTop_atTop] at hs_tendsto
have ⟨q, hq⟩ := exists_rat_gt x
obtain ⟨i, hi⟩ := hs_tendsto q
refine ⟨i, hq.le.trans ?_⟩
exact mod_cast hi i le_rfl
integrable a _ := integrable_density le_rfl a measurableSet_Iic
setIntegral a _ hA _ := setIntegral_density le_rfl a measurableSet_Iic hA
/-- Taking the kernel density of intervals `Iic q` for `q : ℚ` gives a function with the property
`isRatCondKernelCDF`. -/
lemma isRatCondKernelCDF_density_Iic (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] :
IsRatCondKernelCDF (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q)) κ (fst κ) :=
(isRatCondKernelCDFAux_density_Iic κ).isRatCondKernelCDF
/-- The conditional kernel CDF of a kernel `κ : Kernel α (γ × ℝ)`, where `γ` is countably generated.
-/
noncomputable
def condKernelCDF (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : α × γ → StieltjesFunction :=
stieltjesOfMeasurableRat (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q))
(isRatCondKernelCDF_density_Iic κ).measurable
lemma isCondKernelCDF_condKernelCDF (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] :
IsCondKernelCDF (condKernelCDF κ) κ (fst κ) :=
isCondKernelCDF_stieltjesOfMeasurableRat (isRatCondKernelCDF_density_Iic κ)
/-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel α (γ × ℝ)` where `γ` is countably generated. -/
noncomputable
def condKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : Kernel (α × γ) ℝ :=
(isCondKernelCDF_condKernelCDF κ).toKernel
instance instIsMarkovKernelCondKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] :
IsMarkovKernel (condKernelReal κ) := by
rw [condKernelReal]
infer_instance
lemma compProd_fst_condKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] :
fst κ ⊗ₖ condKernelReal κ = κ := by
rw [condKernelReal, compProd_toKernel]
/-- Auxiliary definition for `MeasureTheory.Measure.condKernel` and
`ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel Unit (α × ℝ)`. -/
noncomputable
def condKernelUnitReal (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] : Kernel (Unit × α) ℝ :=
(isCondKernelCDF_condCDF (κ ())).toKernel
instance instIsMarkovKernelCondKernelUnitReal (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] :
IsMarkovKernel (condKernelUnitReal κ) := by
rw [condKernelUnitReal]
infer_instance
instance condKernelUnitReal.instIsCondKernel (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] :
κ.IsCondKernel κ.condKernelUnitReal where
disintegrate := by rw [condKernelUnitReal, compProd_toKernel]; ext; simp
end Real
section BorelSnd
/-! ### Disintegration of kernels on standard Borel spaces
Since every standard Borel space embeds measurably into `ℝ`, we can generalize a disintegration
property on `ℝ` to all these spaces. -/
open Classical in
/-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`.
A Borel space `Ω` embeds measurably into `ℝ` (with embedding `e`), hence we can get a `Kernel α Ω`
from a `Kernel α ℝ` by taking the comap by `e`.
Here we take the comap of a modification of `η : Kernel α ℝ`, useful when `η a` is a probability
measure with all its mass on `range e` almost everywhere with respect to some measure and we want to
ensure that the comap is a Markov kernel.
We thus take the comap by `e` of a kernel defined piecewise: `η` when
`η a (range (embeddingReal Ω))ᶜ = 0`, and an arbitrary deterministic kernel otherwise. -/
noncomputable
def borelMarkovFromReal (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω]
(η : Kernel α ℝ) :
Kernel α Ω :=
have he := measurableEmbedding_embeddingReal Ω
let x₀ := (range_nonempty (embeddingReal Ω)).choose
comapRight
(piecewise ((Kernel.measurable_coe η he.measurableSet_range.compl) (measurableSet_singleton 0) :
MeasurableSet {a | η a (range (embeddingReal Ω))ᶜ = 0})
η (deterministic (fun _ ↦ x₀) measurable_const)) he
lemma borelMarkovFromReal_apply (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω]
(η : Kernel α ℝ) (a : α) :
borelMarkovFromReal Ω η a
= if η a (range (embeddingReal Ω))ᶜ = 0 then (η a).comap (embeddingReal Ω)
else (Measure.dirac (range_nonempty (embeddingReal Ω)).choose).comap (embeddingReal Ω) := by
classical
rw [borelMarkovFromReal, comapRight_apply, piecewise_apply, deterministic_apply]
simp only [mem_preimage, mem_singleton_iff]
split_ifs <;> rfl
lemma borelMarkovFromReal_apply' (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω]
(η : Kernel α ℝ) (a : α) {s : Set Ω} (hs : MeasurableSet s) :
borelMarkovFromReal Ω η a s
= if η a (range (embeddingReal Ω))ᶜ = 0 then η a (embeddingReal Ω '' s)
else (embeddingReal Ω '' s).indicator 1 (range_nonempty (embeddingReal Ω)).choose := by
have he := measurableEmbedding_embeddingReal Ω
rw [borelMarkovFromReal_apply]
split_ifs with h
· rw [Measure.comap_apply _ he.injective he.measurableSet_image' _ hs]
· rw [Measure.comap_apply _ he.injective he.measurableSet_image' _ hs, Measure.dirac_apply]
/-- When `η` is an s-finite kernel, `borelMarkovFromReal Ω η` is an s-finite kernel. -/
instance instIsSFiniteKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsSFiniteKernel η] :
IsSFiniteKernel (borelMarkovFromReal Ω η) :=
IsSFiniteKernel.comapRight _ (measurableEmbedding_embeddingReal Ω)
/-- When `η` is a finite kernel, `borelMarkovFromReal Ω η` is a finite kernel. -/
instance instIsFiniteKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsFiniteKernel η] :
IsFiniteKernel (borelMarkovFromReal Ω η) :=
IsFiniteKernel.comapRight _ (measurableEmbedding_embeddingReal Ω)
/-- When `η` is a Markov kernel, `borelMarkovFromReal Ω η` is a Markov kernel. -/
instance instIsMarkovKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsMarkovKernel η] :
IsMarkovKernel (borelMarkovFromReal Ω η) := by
refine IsMarkovKernel.comapRight _ (measurableEmbedding_embeddingReal Ω) (fun a ↦ ?_)
classical
rw [piecewise_apply]
split_ifs with h
· rwa [← prob_compl_eq_zero_iff (measurableEmbedding_embeddingReal Ω).measurableSet_range]
· rw [deterministic_apply]
simp [(range_nonempty (embeddingReal Ω)).choose_spec]
/-- For `κ' := map κ (Prod.map (id : β → β) e)`, the hypothesis `hη` is `fst κ' ⊗ₖ η = κ'`.
The conclusion of the lemma is `fst κ ⊗ₖ borelMarkovFromReal Ω η = comapRight (fst κ' ⊗ₖ η) _`. -/
lemma compProd_fst_borelMarkovFromReal_eq_comapRight_compProd
(κ : Kernel α (β × Ω)) [IsSFiniteKernel κ] (η : Kernel (α × β) ℝ) [IsSFiniteKernel η]
(hη : (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω)))) ⊗ₖ η
= map κ (Prod.map (id : β → β) (embeddingReal Ω))) :
fst κ ⊗ₖ borelMarkovFromReal Ω η
= comapRight (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω))) ⊗ₖ η)
(MeasurableEmbedding.id.prodMap (measurableEmbedding_embeddingReal Ω)) := by
let e := embeddingReal Ω
let he := measurableEmbedding_embeddingReal Ω
let κ' := map κ (Prod.map (id : β → β) e)
have hη' : fst κ' ⊗ₖ η = κ' := hη
have h_prod_embed : MeasurableEmbedding (Prod.map (id : β → β) e) :=
MeasurableEmbedding.id.prodMap he
change fst κ ⊗ₖ borelMarkovFromReal Ω η = comapRight (fst κ' ⊗ₖ η) h_prod_embed
rw [comapRight_compProd_id_prod _ _ he]
have h_fst : fst κ' = fst κ := by
ext a u
unfold κ'
rw [fst_apply, map_apply _ (by fun_prop),
Measure.map_map measurable_fst h_prod_embed.measurable, fst_apply]
congr
rw [h_fst]
ext a t ht : 2
simp_rw [compProd_apply ht]
refine lintegral_congr_ae ?_
have h_ae : ∀ᵐ t ∂(fst κ a), (a, t) ∈ {p : α × β | η p (range e)ᶜ = 0} := by
rw [← h_fst]
have h_compProd : κ' a (univ ×ˢ range e)ᶜ = 0 := by
unfold κ'
rw [map_apply' _ (by fun_prop)]
swap; · exact (MeasurableSet.univ.prod he.measurableSet_range).compl
suffices Prod.map id e ⁻¹' (univ ×ˢ range e)ᶜ = ∅ by rw [this]; simp
ext x
simp
rw [← hη', compProd_null] at h_compProd
swap; · exact (MeasurableSet.univ.prod he.measurableSet_range).compl
simp only [preimage_compl, mem_univ, mk_preimage_prod_right] at h_compProd
exact h_compProd
filter_upwards [h_ae] with a ha
rw [borelMarkovFromReal, comapRight_apply', comapRight_apply']
rotate_left
· exact measurable_prodMk_left ht
· exact measurable_prodMk_left ht
classical
rw [piecewise_apply, if_pos]
exact ha
/-- For `κ' := map κ (Prod.map (id : β → β) e)`, the hypothesis `hη` is `fst κ' ⊗ₖ η = κ'`.
With that hypothesis, `fst κ ⊗ₖ borelMarkovFromReal κ η = κ`. -/
lemma compProd_fst_borelMarkovFromReal (κ : Kernel α (β × Ω)) [IsSFiniteKernel κ]
(η : Kernel (α × β) ℝ) [IsSFiniteKernel η]
(hη : (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω)))) ⊗ₖ η
= map κ (Prod.map (id : β → β) (embeddingReal Ω))) :
fst κ ⊗ₖ borelMarkovFromReal Ω η = κ := by
let e := embeddingReal Ω
let he := measurableEmbedding_embeddingReal Ω
let κ' := map κ (Prod.map (id : β → β) e)
have hη' : fst κ' ⊗ₖ η = κ' := hη
have h_prod_embed : MeasurableEmbedding (Prod.map (id : β → β) e) :=
MeasurableEmbedding.id.prodMap he
have : κ = comapRight κ' h_prod_embed := by
ext c t : 2
unfold κ'
rw [comapRight_apply, map_apply _ (by fun_prop), h_prod_embed.comap_map]
conv_rhs => rw [this, ← hη']
exact compProd_fst_borelMarkovFromReal_eq_comapRight_compProd κ η hη
end BorelSnd
section CountablyGenerated
open ProbabilityTheory.Kernel
/-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel α (γ × Ω)` where `γ` is countably generated and `Ω` is
standard Borel. -/
noncomputable
def condKernelBorel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] : Kernel (α × γ) Ω :=
let κ' := map κ (Prod.map (id : γ → γ) (embeddingReal Ω))
borelMarkovFromReal Ω (condKernelReal κ')
instance instIsMarkovKernelCondKernelBorel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] :
IsMarkovKernel (condKernelBorel κ) := by
rw [condKernelBorel]
infer_instance
instance condKernelBorel.instIsCondKernel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] :
κ.IsCondKernel κ.condKernelBorel where
disintegrate := by
rw [condKernelBorel, compProd_fst_borelMarkovFromReal _ _ (compProd_fst_condKernelReal _)]
end CountablyGenerated
section Unit
variable (κ : Kernel Unit (α × Ω)) [IsFiniteKernel κ]
/-- Auxiliary definition for `MeasureTheory.Measure.condKernel` and
`ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel Unit (α × Ω)` where `Ω` is standard Borel. -/
noncomputable
def condKernelUnitBorel : Kernel (Unit × α) Ω :=
let κ' := map κ (Prod.map (id : α → α) (embeddingReal Ω))
borelMarkovFromReal Ω (condKernelUnitReal κ')
instance instIsMarkovKernelCondKernelUnitBorel : IsMarkovKernel κ.condKernelUnitBorel := by
rw [condKernelUnitBorel]
infer_instance
instance condKernelUnitBorel.instIsCondKernel : κ.IsCondKernel κ.condKernelUnitBorel where
disintegrate := by
rw [condKernelUnitBorel, compProd_fst_borelMarkovFromReal _ _ (disintegrate _ _)]
end Unit
section Measure
variable {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ]
/-- Conditional kernel of a measure on a product space: a Markov kernel such that
`ρ = ρ.fst ⊗ₘ ρ.condKernel` (see `MeasureTheory.Measure.compProd_fst_condKernel`). -/
noncomputable
irreducible_def _root_.MeasureTheory.Measure.condKernel (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] :
Kernel α Ω :=
comap (condKernelUnitBorel (const Unit ρ)) (fun a ↦ ((), a)) measurable_prodMk_left
lemma _root_.MeasureTheory.Measure.condKernel_apply (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ]
(a : α) :
ρ.condKernel a = condKernelUnitBorel (const Unit ρ) ((), a) := by
rw [Measure.condKernel]; rfl
instance _root_.MeasureTheory.Measure.condKernel.instIsCondKernel (ρ : Measure (α × Ω))
[IsFiniteMeasure ρ] : ρ.IsCondKernel ρ.condKernel where
disintegrate := by
have h1 : const Unit (Measure.fst ρ) = fst (const Unit ρ) := by
ext
simp only [fst_apply, Measure.fst, const_apply]
have h2 : prodMkLeft Unit (Measure.condKernel ρ) = condKernelUnitBorel (const Unit ρ) := by
ext
simp only [prodMkLeft_apply, Measure.condKernel_apply]
rw [Measure.compProd, h1, h2, disintegrate]
simp
instance _root_.MeasureTheory.Measure.instIsMarkovKernelCondKernel
(ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] : IsMarkovKernel ρ.condKernel := by
rw [Measure.condKernel]
infer_instance
/-- If the singleton `{x}` has non-zero mass for `ρ.fst`, then for all `s : Set Ω`,
`ρ.condKernel x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s)` . -/
lemma _root_.MeasureTheory.Measure.condKernel_apply_of_ne_zero [MeasurableSingletonClass α]
{x : α} (hx : ρ.fst {x} ≠ 0) (s : Set Ω) :
ρ.condKernel x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) :=
Measure.IsCondKernel.apply_of_ne_zero _ _ hx _
end Measure
section CountableOrCountablyGenerated
variable [h : CountableOrCountablyGenerated α β] (κ : Kernel α (β × Ω)) [IsFiniteKernel κ]
open Classical in
/-- Conditional kernel of a kernel `κ : Kernel α (β × Ω)`: a Markov kernel such that
`fst κ ⊗ₖ condKernel κ = κ` (see `MeasureTheory.Measure.compProd_fst_condKernel`).
It exists whenever `Ω` is standard Borel and either `α` is countable
or `β` is countably generated. -/
noncomputable
irreducible_def condKernel : Kernel (α × β) Ω :=
if hα : Countable α then
condKernelCountable (fun a ↦ (κ a).condKernel)
fun x y h ↦ by simp [apply_congr_of_mem_measurableAtom _ h]
else letI := h.countableOrCountablyGenerated.resolve_left hα; condKernelBorel κ
/-- `condKernel κ` is a Markov kernel. -/
instance instIsMarkovKernelCondKernel : IsMarkovKernel (condKernel κ) := by
rw [condKernel_def]
split_ifs <;> infer_instance
instance condKernel.instIsCondKernel : κ.IsCondKernel κ.condKernel where
disintegrate := by rw [condKernel_def]; split_ifs with hα <;> exact disintegrate _ _
end CountableOrCountablyGenerated
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/Comp.lean | import Mathlib.Probability.Kernel.MeasurableLIntegral
/-!
# Composition of kernels
We define the composition `η ∘ₖ κ` of kernels `κ : Kernel α β` and `η : Kernel β γ`, which is
a kernel from `α` to `γ`.
## Main definitions
* `comp (η : Kernel β γ) (κ : Kernel α β) : Kernel α γ`: composition of 2 kernels.
We define a notation `η ∘ₖ κ = comp η κ`.
`∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)`
## Main statements
* `lintegral_comp`: Lebesgue integral of a function against a composition of kernels.
* Instances stating that `IsMarkovKernel`, `IsZeroOrMarkovKernel`, `IsFiniteKernel` and
`IsSFiniteKernel` are stable by composition.
## Notation
* `η ∘ₖ κ = ProbabilityTheory.Kernel.comp η κ`
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
/-- Composition of two kernels. -/
noncomputable def comp (η : Kernel β γ) (κ : Kernel α β) : Kernel α γ where
toFun a := (κ a).bind η
measurable' := (Measure.measurable_bind' η.measurable).comp κ.measurable
@[inherit_doc]
scoped[ProbabilityTheory] infixl:100 " ∘ₖ " => ProbabilityTheory.Kernel.comp
theorem comp_apply (η : Kernel β γ) (κ : Kernel α β) (a : α) : (η ∘ₖ κ) a = (κ a).bind η :=
rfl
theorem comp_apply' (η : Kernel β γ) (κ : Kernel α β) (a : α) {s : Set γ} (hs : MeasurableSet s) :
(η ∘ₖ κ) a s = ∫⁻ b, η b s ∂κ a := by
rw [comp_apply, Measure.bind_apply hs (Kernel.aemeasurable _)]
theorem comp_apply_univ_le (κ : Kernel α β) (η : Kernel β γ) (a : α) :
(η ∘ₖ κ) a Set.univ ≤ κ a Set.univ * η.bound := by
rw [comp_apply' _ _ _ .univ]
let Cη := η.bound
calc
∫⁻ b, η b Set.univ ∂κ a ≤ ∫⁻ _, Cη ∂κ a :=
lintegral_mono fun b => measure_le_bound η b Set.univ
_ = Cη * κ a Set.univ := MeasureTheory.lintegral_const Cη
_ = κ a Set.univ * Cη := mul_comm _ _
@[simp] lemma zero_comp (κ : Kernel α β) : (0 : Kernel β γ) ∘ₖ κ = 0 := by ext; simp [comp_apply]
@[simp] lemma comp_zero (κ : Kernel β γ) : κ ∘ₖ (0 : Kernel α β) = 0 := by ext; simp [comp_apply]
section Ae
/-! ### `ae` filter of the composition -/
variable {κ : Kernel α β} {η : Kernel β γ} {a : α} {s : Set γ}
theorem ae_lt_top_of_comp_ne_top (a : α) (hs : (η ∘ₖ κ) a s ≠ ∞) : ∀ᵐ b ∂κ a, η b s < ∞ := by
have h : ∀ᵐ b ∂κ a, η b (toMeasurable ((η ∘ₖ κ) a) s) < ∞ := by
refine ae_lt_top (Kernel.measurable_coe η (measurableSet_toMeasurable ..)) ?_
rwa [← Kernel.comp_apply' _ _ _ (measurableSet_toMeasurable ..), measure_toMeasurable]
filter_upwards [h] with b hb using (measure_mono (subset_toMeasurable _ _)).trans_lt hb
theorem comp_null (a : α) (hs : MeasurableSet s) :
(η ∘ₖ κ) a s = 0 ↔ (fun y ↦ η y s) =ᵐ[κ a] 0 := by
rw [comp_apply' _ _ _ hs, lintegral_eq_zero_iff (η.measurable_coe hs)]
theorem ae_null_of_comp_null (h : (η ∘ₖ κ) a s = 0) : (η · s) =ᵐ[κ a] 0 := by
obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h
simp_rw [comp_null a mt] at ht
rw [Filter.eventuallyLE_antisymm_iff]
exact ⟨Filter.EventuallyLE.trans_eq (ae_of_all _ fun _ ↦ measure_mono hst) ht,
ae_of_all _ fun _ ↦ zero_le _⟩
variable {p : γ → Prop}
theorem ae_ae_of_ae_comp (h : ∀ᵐ z ∂(η ∘ₖ κ) a, p z) :
∀ᵐ y ∂κ a, ∀ᵐ z ∂η y, p z := ae_null_of_comp_null h
lemma ae_comp_of_ae_ae (hp : MeasurableSet {z | p z})
(h : ∀ᵐ y ∂κ a, ∀ᵐ z ∂η y, p z) : ∀ᵐ z ∂(η ∘ₖ κ) a, p z := by
rwa [ae_iff, comp_null] at *
exact hp.compl
lemma ae_comp_iff (hp : MeasurableSet {z | p z}) :
(∀ᵐ z ∂(η ∘ₖ κ) a, p z) ↔ ∀ᵐ y ∂κ a, ∀ᵐ z ∂η y, p z :=
⟨ae_ae_of_ae_comp, ae_comp_of_ae_ae hp⟩
end Ae
section Restrict
variable {κ : Kernel α β} {η : Kernel β γ}
theorem comp_restrict {s : Set γ} (hs : MeasurableSet s) :
η.restrict hs ∘ₖ κ = (η ∘ₖ κ).restrict hs := by
ext a t ht
simp_rw [comp_apply' _ _ _ ht, restrict_apply' _ _ _ ht, comp_apply' _ _ _ (ht.inter hs)]
end Restrict
theorem lintegral_comp (η : Kernel β γ) (κ : Kernel α β) (a : α) {g : γ → ℝ≥0∞}
(hg : Measurable g) : ∫⁻ c, g c ∂(η ∘ₖ κ) a = ∫⁻ b, ∫⁻ c, g c ∂η b ∂κ a := by
rw [comp_apply, Measure.lintegral_bind (Kernel.aemeasurable _) hg.aemeasurable]
/-- Composition of kernels is associative. -/
theorem comp_assoc {δ : Type*} {mδ : MeasurableSpace δ} (ξ : Kernel γ δ)
(η : Kernel β γ) (κ : Kernel α β) : ξ ∘ₖ η ∘ₖ κ = ξ ∘ₖ (η ∘ₖ κ) := by
refine ext_fun fun a f hf => ?_
simp_rw [lintegral_comp _ _ _ hf, lintegral_comp _ _ _ hf.lintegral_kernel]
lemma comp_discard' (κ : Kernel α β) :
discard β ∘ₖ κ =
{ toFun a := κ a .univ • Measure.dirac ()
measurable' := (κ.measurable_coe .univ).smul_measure _ } := by
ext a s hs
simp [comp_apply' _ _ _ hs, mul_comm]
@[simp]
lemma comp_discard (κ : Kernel α β) [IsMarkovKernel κ] : discard β ∘ₖ κ = discard α := by
ext; simp [comp_discard']
@[simp]
lemma swap_copy : (swap α α) ∘ₖ (copy α) = copy α := by
ext a s hs
rw [comp_apply, copy_apply, Measure.dirac_bind (Kernel.measurable _), swap_apply' _ hs,
Measure.dirac_apply' _ hs]
congr
lemma const_comp (μ : Measure γ) (κ : Kernel α β) :
const β μ ∘ₖ κ = fun a ↦ (κ a) Set.univ • μ := by
ext _ _ hs
simp_rw [comp_apply' _ _ _ hs, const_apply, MeasureTheory.lintegral_const, Measure.smul_apply,
smul_eq_mul, mul_comm]
@[simp]
lemma const_comp' (μ : Measure γ) (κ : Kernel α β) [IsMarkovKernel κ] :
const β μ ∘ₖ κ = const α μ := by
ext; simp_rw [const_comp, measure_univ, one_smul, const_apply]
lemma comp_add_right (μ κ : Kernel α β) (η : Kernel β γ) :
η ∘ₖ (μ + κ) = η ∘ₖ μ + η ∘ₖ κ := by ext _ _ hs; simp [comp_apply' _ _ _ hs]
lemma comp_add_left (μ : Kernel α β) (κ η : Kernel β γ) :
(κ + η) ∘ₖ μ = κ ∘ₖ μ + η ∘ₖ μ := by
ext a s hs
simp_rw [comp_apply' _ _ _ hs, add_apply, Measure.add_apply, comp_apply' _ _ _ hs,
lintegral_add_left (Kernel.measurable_coe κ hs)]
lemma comp_sum_right {ι : Type*} [Countable ι] (κ : ι → Kernel α β) (η : Kernel β γ) :
η ∘ₖ Kernel.sum κ = Kernel.sum fun i ↦ η ∘ₖ (κ i) := by
ext _ _ hs
simp_rw [sum_apply, comp_apply' _ _ _ hs, Measure.sum_apply _ hs, sum_apply,
lintegral_sum_measure, comp_apply' _ _ _ hs]
lemma comp_sum_left {ι : Type*} [Countable ι] (κ : Kernel α β) (η : ι → Kernel β γ) :
(Kernel.sum η) ∘ₖ κ = Kernel.sum (fun i ↦ (η i) ∘ₖ κ) := by
ext _ _ hs
simp_rw [sum_apply, comp_apply' _ _ _ hs, sum_apply, Measure.sum_apply _ hs,
comp_apply' _ _ _ hs]
rw [lintegral_tsum]
exact fun _ ↦ (Kernel.measurable_coe _ hs).aemeasurable
instance IsMarkovKernel.comp (η : Kernel β γ) [IsMarkovKernel η] (κ : Kernel α β)
[IsMarkovKernel κ] : IsMarkovKernel (η ∘ₖ κ) where
isProbabilityMeasure a := by
rw [comp_apply]
constructor
rw [Measure.bind_apply .univ η.aemeasurable]
simp
instance IsZeroOrMarkovKernel.comp (κ : Kernel α β) [IsZeroOrMarkovKernel κ]
(η : Kernel β γ) [IsZeroOrMarkovKernel η] : IsZeroOrMarkovKernel (η ∘ₖ κ) := by
obtain rfl | _ := eq_zero_or_isMarkovKernel κ <;> obtain rfl | _ := eq_zero_or_isMarkovKernel η
all_goals simpa using by infer_instance
instance IsFiniteKernel.comp (η : Kernel β γ) [IsFiniteKernel η] (κ : Kernel α β)
[IsFiniteKernel κ] : IsFiniteKernel (η ∘ₖ κ) := by
refine ⟨⟨κ.bound * η.bound, ENNReal.mul_lt_top κ.bound_lt_top η.bound_lt_top, fun a ↦ ?_⟩⟩
calc (η ∘ₖ κ) a Set.univ
_ ≤ κ a Set.univ * η.bound := comp_apply_univ_le κ η a
_ ≤ κ.bound * η.bound := mul_le_mul (measure_le_bound κ a Set.univ) le_rfl zero_le' zero_le'
instance IsSFiniteKernel.comp (η : Kernel β γ) [IsSFiniteKernel η] (κ : Kernel α β)
[IsSFiniteKernel κ] : IsSFiniteKernel (η ∘ₖ κ) := by
simp_rw [← kernel_sum_seq κ, ← kernel_sum_seq η, comp_sum_left, comp_sum_right]
infer_instance
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/Lemmas.lean | import Mathlib.Probability.Kernel.Composition.MeasureComp
/-!
# Lemmas relating different ways to compose measures and kernels
This file contains lemmas about the composition of measures and kernels that do not fit in any of
the other files in this directory, because they involve several types of compositions/products.
-/
open MeasureTheory ProbabilityTheory
open scoped ENNReal
variable {α β γ δ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ}
{μ : Measure α} {ν : Measure β} {κ : Kernel α β}
namespace ProbabilityTheory.Kernel
/-- The composition of two product kernels `(ξ ×ₖ η') ∘ₖ (κ ×ₖ ζ)` is the product of the
compositions `(ξ ∘ₖ (κ ×ₖ ζ)) ×ₖ (η' ∘ₖ (κ ×ₖ ζ))`, if `ζ` is deterministic (of the form
`.deterministic f hf`) and `η'` does not depend on the output of `κ`.
That is, `η'` has the form `η.prodMkLeft β` for a kernel `η`.
If `κ` was deterministic, this would be true even if `η.prodMkLeft β` was a more general
kernel since `κ ×ₖ Kernel.deterministic f hf` would be deterministic and commute with copying.
Here `κ` is not deterministic, but it is discarded in one branch of the copy. -/
lemma prod_prodMkLeft_comp_prod_deterministic {β' ε : Type*}
{mβ' : MeasurableSpace β'} {mε : MeasurableSpace ε}
(κ : Kernel γ β) [IsSFiniteKernel κ] (η : Kernel ε β') [IsSFiniteKernel η]
(ξ : Kernel (β × ε) δ) [IsSFiniteKernel ξ] {f : γ → ε} (hf : Measurable f) :
(ξ ×ₖ η.prodMkLeft β) ∘ₖ (κ ×ₖ deterministic f hf)
= (ξ ∘ₖ (κ ×ₖ deterministic f hf)) ×ₖ (η ∘ₖ deterministic f hf) := by
ext ω s hs
rw [prod_apply' _ _ _ hs, comp_apply' _ _ _ hs, lintegral_prod_deterministic,
lintegral_comp, lintegral_prod_deterministic]
· congr with b
rw [prod_apply' _ _ _ hs, prodMkLeft_apply, comp_deterministic_eq_comap, comap_apply]
· exact (measurable_measure_prodMk_left hs).lintegral_kernel
· exact measurable_measure_prodMk_left hs
· exact Kernel.measurable_coe _ hs
/-- The composition of two product kernels `(ξ ×ₖ η') ∘ₖ (ζ ×ₖ κ)` is the product of the
compositions, `(ξ ∘ₖ (ζ ×ₖ κ)) ×ₖ (η' ∘ₖ (ζ ×ₖ κ))`, if `ζ` is deterministic (of the form
`.deterministic f hf`) and `η'` does not depend on the output of `κ`.
That is, `η'` has the form `η.prodMkRight β` for a kernel `η`.
If `κ` was deterministic, this would be true even if `η.prodMkRight β` was a more general
kernel since `Kernel.deterministic f hf ×ₖ κ` would be deterministic and commute with copying.
Here `κ` is not deterministic, but it is discarded in one branch of the copy. -/
lemma prod_prodMkRight_comp_deterministic_prod {β' ε : Type*}
{mβ' : MeasurableSpace β'} {mε : MeasurableSpace ε}
(κ : Kernel γ β) [IsSFiniteKernel κ] (η : Kernel ε β') [IsSFiniteKernel η]
(ξ : Kernel (ε × β) δ) [IsSFiniteKernel ξ] {f : γ → ε} (hf : Measurable f) :
(ξ ×ₖ η.prodMkRight β) ∘ₖ (deterministic f hf ×ₖ κ)
= (ξ ∘ₖ (deterministic f hf ×ₖ κ)) ×ₖ (η ∘ₖ deterministic f hf) := by
ext ω s hs
rw [prod_apply' _ _ _ hs, comp_apply' _ _ _ hs, lintegral_deterministic_prod,
lintegral_comp, lintegral_deterministic_prod]
· congr with b
rw [prod_apply' _ _ _ hs, prodMkRight_apply, comp_deterministic_eq_comap, comap_apply]
· exact (measurable_measure_prodMk_left hs).lintegral_kernel
· exact measurable_measure_prodMk_left hs
· exact Kernel.measurable_coe _ hs
end ProbabilityTheory.Kernel
namespace MeasureTheory.Measure
lemma compProd_eq_parallelComp_comp_copy_comp [SFinite μ] :
μ ⊗ₘ κ = (Kernel.id ∥ₖ κ) ∘ₘ Kernel.copy α ∘ₘ μ := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
rw [compProd_eq_comp_prod, ← Kernel.parallelComp_comp_copy, Measure.comp_assoc]
lemma prod_comp_right [SFinite ν] {κ : Kernel β γ} [IsSFiniteKernel κ] :
μ.prod (κ ∘ₘ ν) = (Kernel.id ∥ₖ κ) ∘ₘ (μ.prod ν) := by
ext s hs
rw [Measure.prod_apply hs, Measure.bind_apply hs (Kernel.aemeasurable _)]
simp_rw [Measure.bind_apply (measurable_prodMk_left hs) (Kernel.aemeasurable _)]
rw [MeasureTheory.lintegral_prod]
swap; · exact (Kernel.measurable_coe _ hs).aemeasurable
congr with a
congr with b
rw [Kernel.parallelComp_apply, Kernel.id_apply, Measure.prod_apply hs, lintegral_dirac']
exact measurable_measure_prodMk_left hs
lemma prod_comp_left [SFinite μ] [SFinite ν] {κ : Kernel α γ} [IsSFiniteKernel κ] :
(κ ∘ₘ μ).prod ν = (κ ∥ₖ Kernel.id) ∘ₘ (μ.prod ν) := by
have h1 : (κ ∘ₘ μ).prod ν = (ν.prod (κ ∘ₘ μ)).map Prod.swap := by rw [Measure.prod_swap]
have h2 : (κ ∥ₖ Kernel.id) ∘ₘ (μ.prod ν) = ((Kernel.id ∥ₖ κ) ∘ₘ (ν.prod μ)).map Prod.swap := by
calc (κ ∥ₖ Kernel.id) ∘ₘ (μ.prod ν)
_ = (κ ∥ₖ Kernel.id) ∘ₘ ((ν.prod μ).map Prod.swap) := by rw [Measure.prod_swap]
_ = (κ ∥ₖ Kernel.id) ∘ₘ ((Kernel.swap _ _) ∘ₘ (ν.prod μ)) := by
rw [Kernel.swap, Measure.deterministic_comp_eq_map]
_ = (Kernel.swap _ _) ∘ₘ ((Kernel.id ∥ₖ κ) ∘ₘ (ν.prod μ)) := by
rw [Measure.comp_assoc, Measure.comp_assoc, Kernel.swap_parallelComp]
_ = ((Kernel.id ∥ₖ κ) ∘ₘ (ν.prod μ)).map Prod.swap := by
rw [Kernel.swap, Measure.deterministic_comp_eq_map]
rw [← Measure.prod_comp_right, ← h1] at h2
exact h2.symm
lemma parallelComp_comp_compProd [IsSFiniteKernel κ] {η : Kernel β γ} [IsSFiniteKernel η] :
(Kernel.id ∥ₖ η) ∘ₘ (μ ⊗ₘ κ) = μ ⊗ₘ (η ∘ₖ κ) := by
by_cases hμ : SFinite μ
swap; · simp [hμ]
rw [Measure.compProd_eq_comp_prod, Measure.compProd_eq_comp_prod, Measure.comp_assoc,
Kernel.parallelComp_comp_prod, Kernel.id_comp]
lemma compProd_map [SFinite μ] [IsSFiniteKernel κ] {f : β → γ} (hf : Measurable f) :
μ ⊗ₘ (κ.map f) = (μ ⊗ₘ κ).map (Prod.map id f) := by
calc μ ⊗ₘ (κ.map f)
_ = (Kernel.id ∥ₖ Kernel.deterministic f hf) ∘ₘ (Kernel.id ×ₖ κ) ∘ₘ μ := by
rw [comp_assoc, Kernel.parallelComp_comp_prod, compProd_eq_comp_prod,
Kernel.id_comp, Kernel.deterministic_comp_eq_map]
_ = (Kernel.id ∥ₖ Kernel.deterministic f hf) ∘ₘ (μ ⊗ₘ κ) := by rw [compProd_eq_comp_prod]
_ = (μ ⊗ₘ κ).map (Prod.map id f) := by
rw [Kernel.id, Kernel.deterministic_parallelComp_deterministic, deterministic_comp_eq_map]
end MeasureTheory.Measure |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/Prod.lean | import Mathlib.Probability.Kernel.Composition.CompMap
import Mathlib.Probability.Kernel.Composition.ParallelComp
/-!
# Product and composition of kernels
We define the product `κ ×ₖ η` of s-finite kernels `κ : Kernel α β` and `η : Kernel α γ`, which is
a kernel from `α` to `β × γ`.
## Main definitions
* `prod (κ : Kernel α β) (η : Kernel α γ) : Kernel α (β × γ)`: product of 2 s-finite kernels.
`∫⁻ bc, f bc ∂((κ ×ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)`
## Main statements
* `lintegral_prod`: Lebesgue integral of a function against a product of kernels.
* Instances stating that `IsMarkovKernel`, `IsZeroOrMarkovKernel`, `IsFiniteKernel` and
`IsSFiniteKernel` are stable by product.
## Notation
* `κ ×ₖ η = ProbabilityTheory.Kernel.prod κ η`
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ}
/-- Product of two kernels. This is meaningful only when the kernels are s-finite. -/
noncomputable def prod (κ : Kernel α β) (η : Kernel α γ) : Kernel α (β × γ) :=
(κ ∥ₖ η) ∘ₖ copy α
@[inherit_doc]
scoped[ProbabilityTheory] infixl:100 " ×ₖ " => ProbabilityTheory.Kernel.prod
lemma parallelComp_comp_copy (κ : Kernel α β) (η : Kernel α γ) :
(κ ∥ₖ η) ∘ₖ copy α = κ ×ₖ η := rfl
@[simp]
lemma zero_prod (η : Kernel α γ) : (0 : Kernel α β) ×ₖ η = 0 := by simp [prod]
@[simp]
lemma prod_zero (κ : Kernel α β) : κ ×ₖ (0 : Kernel α γ) = 0 := by simp [prod]
@[simp]
lemma prod_of_not_isSFiniteKernel_left {κ : Kernel α β} (η : Kernel α γ) (h : ¬ IsSFiniteKernel κ) :
κ ×ₖ η = 0 := by
simp [prod, h]
@[simp]
lemma prod_of_not_isSFiniteKernel_right (κ : Kernel α β) {η : Kernel α γ}
(h : ¬ IsSFiniteKernel η) :
κ ×ₖ η = 0 := by
simp [prod, h]
theorem prod_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
(a : α) {s : Set (β × γ)} (hs : MeasurableSet s) :
(κ ×ₖ η) a s = ∫⁻ b : β, (η a) (Prod.mk b ⁻¹' s) ∂κ a := by
simp_rw [prod, comp_apply, copy_apply, Measure.dirac_bind (Kernel.measurable _) (a, a),
parallelComp_apply, Measure.prod_apply hs]
lemma prod_apply (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
(a : α) :
(κ ×ₖ η) a = (κ a).prod (η a) := by
ext s hs
rw [prod_apply' _ _ _ hs, Measure.prod_apply hs]
lemma prod_apply_prod {κ : Kernel α β} {η : Kernel α γ}
[IsSFiniteKernel κ] [IsSFiniteKernel η] {s : Set β} {t : Set γ} {a : α} :
(κ ×ₖ η) a (s ×ˢ t) = (κ a s) * (η a t) := by
rw [prod_apply, Measure.prod_prod]
lemma prod_const (μ : Measure β) [SFinite μ] (ν : Measure γ) [SFinite ν] :
const α μ ×ₖ const α ν = const α (μ.prod ν) := by
ext x
rw [const_apply, prod_apply, const_apply, const_apply]
theorem lintegral_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
(a : α) {g : β × γ → ℝ≥0∞} (hg : Measurable g) :
∫⁻ c, g c ∂(κ ×ₖ η) a = ∫⁻ b, ∫⁻ c, g (b, c) ∂η a ∂κ a := by
simp_rw [prod, lintegral_comp _ _ _ hg, copy_apply]
rw [lintegral_dirac' _ (by fun_prop)]
simp_rw [parallelComp_apply, MeasureTheory.lintegral_prod _ hg.aemeasurable]
theorem lintegral_prod_symm (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ)
[IsSFiniteKernel η] (a : α) {g : β × γ → ℝ≥0∞} (hg : Measurable g) :
∫⁻ c, g c ∂(κ ×ₖ η) a = ∫⁻ c, ∫⁻ b, g (b, c) ∂κ a ∂η a := by
rw [prod_apply, MeasureTheory.lintegral_prod_symm _ hg.aemeasurable]
theorem lintegral_deterministic_prod {f : α → β} (hf : Measurable f) (κ : Kernel α γ)
[IsSFiniteKernel κ] (a : α) {g : (β × γ) → ℝ≥0∞} (hg : Measurable g) :
∫⁻ p, g p ∂((deterministic f hf) ×ₖ κ) a = ∫⁻ c, g (f a, c) ∂κ a := by
rw [lintegral_prod _ _ _ hg, lintegral_deterministic' _ hg.lintegral_prod_right']
theorem lintegral_prod_deterministic {f : α → γ} (hf : Measurable f) (κ : Kernel α β)
[IsSFiniteKernel κ] (a : α) {g : (β × γ) → ℝ≥0∞} (hg : Measurable g) :
∫⁻ p, g p ∂(κ ×ₖ (deterministic f hf)) a = ∫⁻ b, g (b, f a) ∂κ a := by
rw [lintegral_prod_symm _ _ _ hg, lintegral_deterministic' _ hg.lintegral_prod_left']
theorem lintegral_id_prod {f : (α × β) → ℝ≥0∞} (hf : Measurable f) (κ : Kernel α β)
[IsSFiniteKernel κ] (a : α) :
∫⁻ p, f p ∂(Kernel.id ×ₖ κ) a = ∫⁻ b, f (a, b) ∂κ a := by
rw [Kernel.id, lintegral_deterministic_prod _ _ _ hf, id_eq]
theorem lintegral_prod_id {f : (α × β) → ℝ≥0∞} (hf : Measurable f) (κ : Kernel β α)
[IsSFiniteKernel κ] (b : β) :
∫⁻ p, f p ∂(κ ×ₖ Kernel.id) b = ∫⁻ a, f (a, b) ∂κ b := by
rw [Kernel.id, lintegral_prod_deterministic _ _ _ hf, id_eq]
theorem deterministic_prod_apply' {f : α → β} (mf : Measurable f) (κ : Kernel α γ)
[IsSFiniteKernel κ] (a : α) {s : Set (β × γ)} (hs : MeasurableSet s) :
((Kernel.deterministic f mf) ×ₖ κ) a s = κ a (Prod.mk (f a) ⁻¹' s) := by
rw [prod_apply' _ _ _ hs, lintegral_deterministic']
exact measurable_measure_prodMk_left hs
theorem id_prod_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (a : α) {s : Set (α × β)}
(hs : MeasurableSet s) : (Kernel.id ×ₖ κ) a s = κ a (Prod.mk a ⁻¹' s) := by
rw [Kernel.id, deterministic_prod_apply' _ _ _ hs, id_eq]
instance IsMarkovKernel.prod (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel α γ)
[IsMarkovKernel η] : IsMarkovKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance
nonrec instance IsZeroOrMarkovKernel.prod (κ : Kernel α β) [h : IsZeroOrMarkovKernel κ]
(η : Kernel α γ) [IsZeroOrMarkovKernel η] : IsZeroOrMarkovKernel (κ ×ₖ η) := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp only [prod]; infer_instance
rcases eq_zero_or_isMarkovKernel η with rfl | h'
· simp only [prod]; infer_instance
infer_instance
instance IsFiniteKernel.prod (κ : Kernel α β) [IsFiniteKernel κ] (η : Kernel α γ)
[IsFiniteKernel η] : IsFiniteKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance
instance IsSFiniteKernel.prod (κ : Kernel α β) (η : Kernel α γ) :
IsSFiniteKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance
@[simp] lemma fst_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsMarkovKernel η] :
fst (κ ×ₖ η) = κ := by
rw [prod, fst_comp]
ext a : 1
rw [comp_apply, copy_apply, Measure.dirac_bind (by fun_prop), fst_apply, parallelComp_apply]
simp
@[simp] lemma snd_prod (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel α γ) [IsSFiniteKernel η] :
snd (κ ×ₖ η) = η := by
ext x; simp [snd_apply, prod_apply]
lemma comap_prod (κ : Kernel β γ) [IsSFiniteKernel κ] (η : Kernel β δ) [IsSFiniteKernel η]
{f : α → β} (hf : Measurable f) :
(κ ×ₖ η).comap f hf = (κ.comap f hf) ×ₖ (η.comap f hf) := by
ext1 x
rw [comap_apply, prod_apply, prod_apply, comap_apply, comap_apply]
lemma map_prod_map {ε} {mε : MeasurableSpace ε} (κ : Kernel α β) [IsSFiniteKernel κ]
(η : Kernel α δ) [IsSFiniteKernel η] {f : β → γ} (hf : Measurable f) {g : δ → ε}
(hg : Measurable g) : (κ.map f) ×ₖ (η.map g) = (κ ×ₖ η).map (Prod.map f g) := by
ext1 x
rw [map_apply _ (hf.prodMap hg), prod_apply κ, ← Measure.map_prod_map _ _ hf hg, prod_apply,
map_apply _ hf, map_apply _ hg]
lemma map_prod_eq (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
{f : β → δ} (hf : Measurable f) : (κ.map f) ×ₖ η = (κ ×ₖ η).map (Prod.map f id) := by
rw [← map_prod_map _ _ hf measurable_id, map_id]
lemma comap_prod_swap (κ : Kernel α β) (η : Kernel γ δ) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
comap (prodMkRight α η ×ₖ prodMkLeft γ κ) Prod.swap measurable_swap
= map (prodMkRight γ κ ×ₖ prodMkLeft α η) Prod.swap := by
rw [ext_fun_iff]
intro x f hf
rw [lintegral_comap, lintegral_map _ measurable_swap _ hf, lintegral_prod _ _ _ hf,
lintegral_prod]
swap; · fun_prop
simp only [prodMkRight_apply, Prod.fst_swap, Prod.swap_prod_mk, lintegral_prodMkLeft,
Prod.snd_swap]
refine (lintegral_lintegral_swap ?_).symm
fun_prop
lemma map_prod_swap (κ : Kernel α β) (η : Kernel α γ) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
map (κ ×ₖ η) Prod.swap = η ×ₖ κ := by
rw [ext_fun_iff]
intro x f hf
rw [lintegral_map _ measurable_swap _ hf, lintegral_prod, lintegral_prod _ _ _ hf]
swap; · fun_prop
refine (lintegral_lintegral_swap ?_).symm
fun_prop
lemma prodComm_prod {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel α γ} [IsSFiniteKernel η] :
(κ ×ₖ η).map MeasurableEquiv.prodComm = η ×ₖ κ :=
map_prod_swap κ η
@[simp]
lemma swap_prod {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel α γ} [IsSFiniteKernel η] :
(swap β γ) ∘ₖ (κ ×ₖ η) = (η ×ₖ κ) := by
rw [swap_comp_eq_map, map_prod_swap]
lemma deterministic_prod_deterministic {f : α → β} {g : α → γ}
(hf : Measurable f) (hg : Measurable g) :
deterministic f hf ×ₖ deterministic g hg
= deterministic (fun a ↦ (f a, g a)) (hf.prodMk hg) := by
ext; simp_rw [prod_apply, deterministic_apply, Measure.dirac_prod_dirac]
lemma id_prod_eq : @Kernel.id (α × β) inferInstance =
(deterministic Prod.fst measurable_fst) ×ₖ (deterministic Prod.snd measurable_snd) := by
rw [deterministic_prod_deterministic]
rfl
lemma prodAssoc_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
(ξ : Kernel α δ) [IsSFiniteKernel ξ] :
((κ ×ₖ ξ) ×ₖ η).map MeasurableEquiv.prodAssoc = κ ×ₖ (ξ ×ₖ η) := by
ext1 a
rw [map_apply _ (by fun_prop), prod_apply, prod_apply, Measure.prodAssoc_prod, prod_apply,
prod_apply]
lemma prodAssoc_symm_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η]
(ξ : Kernel α δ) [IsSFiniteKernel ξ] :
(κ ×ₖ (ξ ×ₖ η)).map MeasurableEquiv.prodAssoc.symm = (κ ×ₖ ξ) ×ₖ η := by
rw [← prodAssoc_prod, ← Kernel.map_comp_right _ (by fun_prop) (by fun_prop)]
simp
lemma prod_const_comp {δ} {mδ : MeasurableSpace δ} (κ : Kernel α β) [IsSFiniteKernel κ]
(η : Kernel β γ) [IsSFiniteKernel η] (μ : Measure δ) [SFinite μ] :
(η ×ₖ (const β μ)) ∘ₖ κ = (η ∘ₖ κ) ×ₖ (const α μ) := by
ext x s ms
simp_rw [comp_apply' _ _ _ ms, prod_apply' _ _ _ ms, const_apply,
lintegral_comp _ _ _ (measurable_measure_prodMk_left ms)]
lemma const_prod_comp {δ} {mδ : MeasurableSpace δ} (κ : Kernel α β) [IsSFiniteKernel κ]
(μ : Measure γ) [SFinite μ] (η : Kernel β δ) [IsSFiniteKernel η] :
((const β μ) ×ₖ η) ∘ₖ κ = (const α μ) ×ₖ (η ∘ₖ κ) := by
ext x s ms
simp_rw [comp_apply' _ _ _ ms, prod_apply, Measure.prod_apply_symm ms, const_apply,
lintegral_comp _ _ _ (measurable_measure_prodMk_right ms)]
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/MeasureCompProd.lean | import Mathlib.MeasureTheory.Measure.Decomposition.Lebesgue
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Probability.Kernel.Composition.CompProd
/-!
# Composition-Product of a measure and a kernel
This operation, denoted by `⊗ₘ`, takes `μ : Measure α` and `κ : Kernel α β` and creates
`μ ⊗ₘ κ : Measure (α × β)`. The integral of a function against `μ ⊗ₘ κ` is
`∫⁻ x, f x ∂(μ ⊗ₘ κ) = ∫⁻ a, ∫⁻ b, f (a, b) ∂(κ a) ∂μ`.
`μ ⊗ₘ κ` is defined as `((Kernel.const Unit μ) ⊗ₖ (Kernel.prodMkLeft Unit κ)) ()`.
## Main definitions
* `Measure.compProd`: from `μ : Measure α` and `κ : Kernel α β`, get a `Measure (α × β)`.
## Notation
* `μ ⊗ₘ κ = μ.compProd κ`
-/
open scoped ENNReal
open ProbabilityTheory Set
namespace MeasureTheory.Measure
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{μ ν : Measure α} {κ η : Kernel α β}
/-- The composition-product of a measure and a kernel. -/
noncomputable
def compProd (μ : Measure α) (κ : Kernel α β) : Measure (α × β) :=
(Kernel.const Unit μ ⊗ₖ Kernel.prodMkLeft Unit κ) ()
@[inherit_doc]
scoped[ProbabilityTheory] infixl:100 " ⊗ₘ " => MeasureTheory.Measure.compProd
@[simp]
lemma compProd_of_not_sfinite (μ : Measure α) (κ : Kernel α β) (h : ¬ SFinite μ) :
μ ⊗ₘ κ = 0 := by
rw [compProd, Kernel.compProd_of_not_isSFiniteKernel_left, Kernel.zero_apply]
rwa [Kernel.isSFiniteKernel_const]
@[simp]
lemma compProd_of_not_isSFiniteKernel (μ : Measure α) (κ : Kernel α β) (h : ¬ IsSFiniteKernel κ) :
μ ⊗ₘ κ = 0 := by
rw [compProd, Kernel.compProd_of_not_isSFiniteKernel_right, Kernel.zero_apply]
rwa [Kernel.isSFiniteKernel_prodMkLeft_unit]
lemma compProd_apply [SFinite μ] [IsSFiniteKernel κ] {s : Set (α × β)} (hs : MeasurableSet s) :
(μ ⊗ₘ κ) s = ∫⁻ a, κ a (Prod.mk a ⁻¹' s) ∂μ := by
simp_rw [compProd, Kernel.compProd_apply hs, Kernel.const_apply, Kernel.prodMkLeft_apply']
@[simp]
lemma compProd_apply_univ [SFinite μ] [IsMarkovKernel κ] : (μ ⊗ₘ κ) univ = μ univ := by
simp [compProd]
lemma compProd_apply_prod [SFinite μ] [IsSFiniteKernel κ]
{s : Set α} {t : Set β} (hs : MeasurableSet s) (ht : MeasurableSet t) :
(μ ⊗ₘ κ) (s ×ˢ t) = ∫⁻ a in s, κ a t ∂μ := by
simp [compProd, Kernel.compProd_apply_prod hs ht]
lemma compProd_congr [IsSFiniteKernel κ] [IsSFiniteKernel η] (h : κ =ᵐ[μ] η) :
μ ⊗ₘ κ = μ ⊗ₘ η := by
rw [compProd, compProd]
congr 1
refine Kernel.compProd_congr ?_
simpa
@[simp] lemma compProd_zero_left (κ : Kernel α β) : (0 : Measure α) ⊗ₘ κ = 0 := by simp [compProd]
@[simp] lemma compProd_zero_right (μ : Measure α) : μ ⊗ₘ (0 : Kernel α β) = 0 := by simp [compProd]
lemma compProd_eq_zero_iff [SFinite μ] [IsSFiniteKernel κ] :
μ ⊗ₘ κ = 0 ↔ ∀ᵐ a ∂μ, κ a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp_rw [← measure_univ_eq_zero]
refine (lintegral_eq_zero_iff (Kernel.measurable_coe _ .univ)).mp ?_
rw [← setLIntegral_univ, ← compProd_apply_prod .univ .univ, h]
simp
· rw [← compProd_zero_right μ]
exact compProd_congr h
lemma _root_.ProbabilityTheory.Kernel.compProd_apply_eq_compProd_sectR {γ : Type*}
{mγ : MeasurableSpace γ} (κ : Kernel α β) (η : Kernel (α × β) γ)
[IsSFiniteKernel κ] [IsSFiniteKernel η] (a : α) :
(κ ⊗ₖ η) a = (κ a) ⊗ₘ (Kernel.sectR η a) := by
ext s hs
simp_rw [Kernel.compProd_apply hs, compProd_apply hs, Kernel.sectR_apply]
lemma compProd_id [SFinite μ] : μ ⊗ₘ Kernel.id = μ.map (fun x ↦ (x, x)) := by
ext s hs
rw [compProd_apply hs, map_apply (measurable_id.prod measurable_id) hs]
have h_meas a : MeasurableSet (Prod.mk a ⁻¹' s) := measurable_prodMk_left hs
simp_rw [Kernel.id_apply, dirac_apply' _ (h_meas _)]
calc ∫⁻ a, (Prod.mk a ⁻¹' s).indicator 1 a ∂μ
_ = ∫⁻ a, ((fun x ↦ (x, x)) ⁻¹' s).indicator 1 a ∂μ := rfl
_ = μ ((fun x ↦ (x, x)) ⁻¹' s) := by
rw [lintegral_indicator_one]
exact (measurable_id.prod measurable_id) hs
lemma ae_compProd_of_ae_ae {p : α × β → Prop}
(hp : MeasurableSet {x | p x}) (h : ∀ᵐ a ∂μ, ∀ᵐ b ∂(κ a), p (a, b)) :
∀ᵐ x ∂(μ ⊗ₘ κ), p x :=
Kernel.ae_compProd_of_ae_ae hp h
lemma ae_ae_of_ae_compProd [SFinite μ] [IsSFiniteKernel κ] {p : α × β → Prop}
(h : ∀ᵐ x ∂(μ ⊗ₘ κ), p x) :
∀ᵐ a ∂μ, ∀ᵐ b ∂κ a, p (a, b) := by
convert Kernel.ae_ae_of_ae_compProd h -- Much faster with `convert`
lemma ae_compProd_iff [SFinite μ] [IsSFiniteKernel κ] {p : α × β → Prop}
(hp : MeasurableSet {x | p x}) :
(∀ᵐ x ∂(μ ⊗ₘ κ), p x) ↔ ∀ᵐ a ∂μ, ∀ᵐ b ∂(κ a), p (a, b) :=
Kernel.ae_compProd_iff hp
/-- The composition product of a measure and a constant kernel is the product between the two
measures. -/
@[simp]
lemma compProd_const {ν : Measure β} [SFinite μ] [SFinite ν] :
μ ⊗ₘ (Kernel.const α ν) = μ.prod ν := by
ext s hs
simp_rw [compProd_apply hs, prod_apply hs, Kernel.const_apply]
lemma compProd_add_left (μ ν : Measure α) [SFinite μ] [SFinite ν] (κ : Kernel α β) :
(μ + ν) ⊗ₘ κ = μ ⊗ₘ κ + ν ⊗ₘ κ := by
by_cases hκ : IsSFiniteKernel κ
· simp_rw [Measure.compProd, Kernel.const_add, Kernel.compProd_add_left, Kernel.add_apply]
· simp [hκ]
lemma compProd_add_right (μ : Measure α) (κ η : Kernel α β)
[IsSFiniteKernel κ] [IsSFiniteKernel η] :
μ ⊗ₘ (κ + η) = μ ⊗ₘ κ + μ ⊗ₘ η := by
by_cases hμ : SFinite μ
· simp_rw [Measure.compProd, Kernel.prodMkLeft_add, Kernel.compProd_add_right, Kernel.add_apply]
· simp [hμ]
lemma compProd_sum_left {ι : Type*} [Countable ι] {μ : ι → Measure α} [∀ i, SFinite (μ i)] :
(sum μ) ⊗ₘ κ = sum (fun i ↦ (μ i) ⊗ₘ κ) := by
rw [compProd, ← Kernel.sum_const, Kernel.compProd_sum_left]
rfl
lemma compProd_sum_right {ι : Type*} [Countable ι] {κ : ι → Kernel α β}
[h : ∀ i, IsSFiniteKernel (κ i)] :
μ ⊗ₘ (Kernel.sum κ) = sum (fun i ↦ μ ⊗ₘ (κ i)) := by
rw [compProd, ← Kernel.sum_prodMkLeft, Kernel.compProd_sum_right]
rfl
@[simp]
lemma fst_compProd (μ : Measure α) [SFinite μ] (κ : Kernel α β) [IsMarkovKernel κ] :
(μ ⊗ₘ κ).fst = μ := by
ext s
rw [compProd, Measure.fst, ← Kernel.fst_apply, Kernel.fst_compProd, Kernel.const_apply]
lemma compProd_smul_left (a : ℝ≥0∞) [SFinite μ] [IsSFiniteKernel κ] :
(a • μ) ⊗ₘ κ = a • (μ ⊗ₘ κ) := by
ext s hs
simp only [compProd_apply hs, lintegral_smul_measure, smul_apply, smul_eq_mul]
section Integral
lemma lintegral_compProd [SFinite μ] [IsSFiniteKernel κ]
{f : α × β → ℝ≥0∞} (hf : Measurable f) :
∫⁻ x, f x ∂(μ ⊗ₘ κ) = ∫⁻ a, ∫⁻ b, f (a, b) ∂(κ a) ∂μ := by
rw [compProd, Kernel.lintegral_compProd _ _ _ hf]
simp
lemma setLIntegral_compProd [SFinite μ] [IsSFiniteKernel κ]
{f : α × β → ℝ≥0∞} (hf : Measurable f)
{s : Set α} (hs : MeasurableSet s) {t : Set β} (ht : MeasurableSet t) :
∫⁻ x in s ×ˢ t, f x ∂(μ ⊗ₘ κ) = ∫⁻ a in s, ∫⁻ b in t, f (a, b) ∂(κ a) ∂μ := by
rw [compProd, Kernel.setLIntegral_compProd _ _ _ hf hs ht]
simp
end Integral
lemma dirac_compProd_apply [MeasurableSingletonClass α] {a : α} [IsSFiniteKernel κ]
{s : Set (α × β)} (hs : MeasurableSet s) :
(Measure.dirac a ⊗ₘ κ) s = κ a (Prod.mk a ⁻¹' s) := by
rw [compProd_apply hs, lintegral_dirac]
lemma dirac_unit_compProd (κ : Kernel Unit β) [IsSFiniteKernel κ] :
Measure.dirac () ⊗ₘ κ = (κ ()).map (Prod.mk ()) := by
ext s hs; rw [dirac_compProd_apply hs, Measure.map_apply measurable_prodMk_left hs]
lemma dirac_unit_compProd_const (μ : Measure β) [SFinite μ] :
Measure.dirac () ⊗ₘ Kernel.const Unit μ = μ.map (Prod.mk ()) := by
rw [dirac_unit_compProd, Kernel.const_apply]
lemma snd_dirac_unit_compProd_const (μ : Measure β) [SFinite μ] :
snd (Measure.dirac () ⊗ₘ Kernel.const Unit μ) = μ := by simp
instance : SFinite (μ ⊗ₘ κ) := by rw [compProd]; infer_instance
instance [IsFiniteMeasure μ] [IsFiniteKernel κ] : IsFiniteMeasure (μ ⊗ₘ κ) := by
rw [compProd]; infer_instance
instance [IsProbabilityMeasure μ] [IsMarkovKernel κ] : IsProbabilityMeasure (μ ⊗ₘ κ) := by
rw [compProd]; infer_instance
instance [IsZeroOrProbabilityMeasure μ] [IsZeroOrMarkovKernel κ] :
IsZeroOrProbabilityMeasure (μ ⊗ₘ κ) := by
rw [compProd]
exact IsZeroOrMarkovKernel.isZeroOrProbabilityMeasure ()
/-- `Measure.compProd` is associative. We have to insert `MeasurableEquiv.prodAssoc`
because the products of types `α × β × γ` and `(α × β) × γ` are different. -/
@[simp]
lemma compProd_assoc {γ : Type*} {mγ : MeasurableSpace γ} {η : Kernel (α × β) γ} :
(μ ⊗ₘ (κ ⊗ₖ η)).map MeasurableEquiv.prodAssoc.symm = μ ⊗ₘ κ ⊗ₘ η := by
by_cases hμ : SFinite μ
swap; · simp [hμ]
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
by_cases hη : IsSFiniteKernel η
swap; · simp [hη]
ext s hs
rw [Measure.compProd_apply hs, Measure.map_apply (by fun_prop) hs,
Measure.compProd_apply (hs.preimage (by fun_prop)), Measure.lintegral_compProd]
swap; · exact Kernel.measurable_kernel_prodMk_left hs
congr with a
rw [Kernel.compProd_apply]
· congr
· exact hs.preimage (by fun_prop)
/-- `Measure.compProd` is associative. We have to insert `MeasurableEquiv.prodAssoc`
because the products of types `α × β × γ` and `(α × β) × γ` are different. -/
@[simp]
lemma compProd_assoc' {γ : Type*} {mγ : MeasurableSpace γ} {η : Kernel (α × β) γ} :
(μ ⊗ₘ κ ⊗ₘ η).map MeasurableEquiv.prodAssoc = μ ⊗ₘ (κ ⊗ₖ η) := by
simp [← Measure.compProd_assoc]
section AbsolutelyContinuous
lemma AbsolutelyContinuous.compProd_left [SFinite ν] (hμν : μ ≪ ν) (κ : Kernel α β) :
μ ⊗ₘ κ ≪ ν ⊗ₘ κ := by
by_cases hκ : IsSFiniteKernel κ
· have : SFinite μ := sFinite_of_absolutelyContinuous hμν
refine Measure.AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_
rw [Measure.compProd_apply hs, lintegral_eq_zero_iff (Kernel.measurable_kernel_prodMk_left hs)]
at hs_zero ⊢
exact hμν.ae_eq hs_zero
· simp [compProd_of_not_isSFiniteKernel _ _ hκ]
lemma AbsolutelyContinuous.compProd_right [SFinite μ] [IsSFiniteKernel η]
(hκη : ∀ᵐ a ∂μ, κ a ≪ η a) :
μ ⊗ₘ κ ≪ μ ⊗ₘ η := by
by_cases hκ : IsSFiniteKernel κ
· refine Measure.AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_
rw [Measure.compProd_apply hs, lintegral_eq_zero_iff (Kernel.measurable_kernel_prodMk_left hs)]
at hs_zero ⊢
filter_upwards [hs_zero, hκη] with a ha_zero ha_ac using ha_ac ha_zero
· simp [compProd_of_not_isSFiniteKernel _ _ hκ]
lemma AbsolutelyContinuous.compProd [SFinite ν] [IsSFiniteKernel η]
(hμν : μ ≪ ν) (hκη : ∀ᵐ a ∂μ, κ a ≪ η a) :
μ ⊗ₘ κ ≪ ν ⊗ₘ η :=
have : SFinite μ := sFinite_of_absolutelyContinuous hμν
(Measure.AbsolutelyContinuous.compProd_right hκη).trans (hμν.compProd_left _)
lemma absolutelyContinuous_of_compProd [SFinite μ] [IsSFiniteKernel κ] [h_zero : ∀ a, NeZero (κ a)]
(h : μ ⊗ₘ κ ≪ ν ⊗ₘ η) :
μ ≪ ν := by
refine Measure.AbsolutelyContinuous.mk (fun s hs hs0 ↦ ?_)
have h1 : (ν ⊗ₘ η) (s ×ˢ univ) = 0 := by
by_cases hν : SFinite ν
swap; · simp [compProd_of_not_sfinite _ _ hν]
by_cases hη : IsSFiniteKernel η
swap; · simp [compProd_of_not_isSFiniteKernel _ _ hη]
rw [Measure.compProd_apply_prod hs MeasurableSet.univ]
exact setLIntegral_measure_zero _ _ hs0
have h2 : (μ ⊗ₘ κ) (s ×ˢ univ) = 0 := h h1
rw [Measure.compProd_apply_prod hs MeasurableSet.univ, lintegral_eq_zero_iff] at h2
swap; · exact Kernel.measurable_coe _ MeasurableSet.univ
by_contra hμs
have : Filter.NeBot (ae (μ.restrict s)) := by simp [hμs]
obtain ⟨a, ha⟩ : ∃ a, κ a univ = 0 := h2.exists
refine absurd ha ?_
simp only [Measure.measure_univ_eq_zero]
exact (h_zero a).out
lemma absolutelyContinuous_compProd_left_iff [SFinite μ] [SFinite ν]
[IsSFiniteKernel κ] [∀ a, NeZero (κ a)] :
μ ⊗ₘ κ ≪ ν ⊗ₘ κ ↔ μ ≪ ν :=
⟨absolutelyContinuous_of_compProd, fun h ↦ h.compProd_left κ⟩
lemma AbsolutelyContinuous.compProd_of_compProd [SFinite ν] [IsSFiniteKernel η]
(hμν : μ ≪ ν) (hκη : μ ⊗ₘ κ ≪ μ ⊗ₘ η) :
μ ⊗ₘ κ ≪ ν ⊗ₘ η := by
by_cases hμ : SFinite μ
swap; · rw [compProd_of_not_sfinite _ _ hμ]; simp
refine AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_
suffices (μ ⊗ₘ η) s = 0 from hκη this
rw [measure_eq_zero_iff_ae_notMem, ae_compProd_iff hs.compl] at hs_zero ⊢
exact hμν.ae_le hs_zero
end AbsolutelyContinuous
section MutuallySingular
lemma MutuallySingular.compProd_of_left (hμν : μ ⟂ₘ ν) (κ η : Kernel α β) :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η := by
by_cases hμ : SFinite μ
swap; · rw [compProd_of_not_sfinite _ _ hμ]; simp
by_cases hν : SFinite ν
swap; · rw [compProd_of_not_sfinite _ _ hν]; simp
by_cases hκ : IsSFiniteKernel κ
swap; · rw [compProd_of_not_isSFiniteKernel _ _ hκ]; simp
by_cases hη : IsSFiniteKernel η
swap; · rw [compProd_of_not_isSFiniteKernel _ _ hη]; simp
refine ⟨hμν.nullSet ×ˢ univ, hμν.measurableSet_nullSet.prod .univ, ?_⟩
rw [compProd_apply_prod hμν.measurableSet_nullSet .univ, compl_prod_eq_union]
simp only [MutuallySingular.restrict_nullSet, lintegral_zero_measure, compl_univ,
prod_empty, union_empty, true_and]
rw [compProd_apply_prod hμν.measurableSet_nullSet.compl .univ]
simp
lemma mutuallySingular_of_mutuallySingular_compProd {ξ : Measure α}
[SFinite μ] [SFinite ν] [IsSFiniteKernel κ] [IsSFiniteKernel η]
(h : μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η) (hμ : ξ ≪ μ) (hν : ξ ≪ ν) :
∀ᵐ x ∂ξ, κ x ⟂ₘ η x := by
have hs : MeasurableSet h.nullSet := h.measurableSet_nullSet
have hμ_zero : (μ ⊗ₘ κ) h.nullSet = 0 := h.measure_nullSet
have hν_zero : (ν ⊗ₘ η) h.nullSetᶜ = 0 := h.measure_compl_nullSet
rw [compProd_apply, lintegral_eq_zero_iff'] at hμ_zero hν_zero
· filter_upwards [hμ hμ_zero, hν hν_zero] with x hxμ hxν
exact ⟨Prod.mk x ⁻¹' h.nullSet, measurable_prodMk_left hs, ⟨hxμ, hxν⟩⟩
· exact (Kernel.measurable_kernel_prodMk_left hs.compl).aemeasurable
· exact (Kernel.measurable_kernel_prodMk_left hs).aemeasurable
· exact hs.compl
· exact hs
lemma mutuallySingular_compProd_left_iff [SFinite μ] [SigmaFinite ν]
[IsSFiniteKernel κ] [hκ : ∀ x, NeZero (κ x)] :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ κ ↔ μ ⟂ₘ ν := by
refine ⟨fun h ↦ ?_, fun h ↦ h.compProd_of_left _ _⟩
rw [← withDensity_rnDeriv_eq_zero]
have hh := mutuallySingular_of_mutuallySingular_compProd h ?_ ?_
(ξ := ν.withDensity (μ.rnDeriv ν))
rotate_left
· exact absolutelyContinuous_of_le (μ.withDensity_rnDeriv_le ν)
· exact withDensity_absolutelyContinuous _ _
simp_rw [MutuallySingular.self_iff, (hκ _).ne] at hh
exact ae_eq_bot.mp (Filter.eventually_false_iff_eq_bot.mp hh)
lemma AbsolutelyContinuous.mutuallySingular_compProd_iff [SigmaFinite μ] [SigmaFinite ν]
(hμν : μ ≪ ν) :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η ↔ μ ⊗ₘ κ ⟂ₘ μ ⊗ₘ η := by
conv_lhs => rw [ν.haveLebesgueDecomposition_add μ]
rw [compProd_add_left, MutuallySingular.add_right_iff]
simp only [(mutuallySingular_singularPart ν μ).symm.compProd_of_left κ η, true_and]
refine ⟨fun h ↦ h.mono_ac .rfl ?_, fun h ↦ h.mono_ac .rfl ?_⟩
· exact (absolutelyContinuous_withDensity_rnDeriv hμν).compProd_left _
· exact (withDensity_absolutelyContinuous μ (ν.rnDeriv μ)).compProd_left _
lemma mutuallySingular_compProd_iff [SigmaFinite μ] [SigmaFinite ν] :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η ↔ ∀ ξ, SFinite ξ → ξ ≪ μ → ξ ≪ ν → ξ ⊗ₘ κ ⟂ₘ ξ ⊗ₘ η := by
conv_lhs => rw [μ.haveLebesgueDecomposition_add ν]
rw [compProd_add_left, MutuallySingular.add_left_iff]
simp only [(mutuallySingular_singularPart μ ν).compProd_of_left κ η, true_and]
rw [(withDensity_absolutelyContinuous ν (μ.rnDeriv ν)).mutuallySingular_compProd_iff]
refine ⟨fun h ξ hξ hξμ hξν ↦ ?_, fun h ↦ ?_⟩
· exact h.mono_ac ((hξμ.withDensity_rnDeriv hξν).compProd_left _)
((hξμ.withDensity_rnDeriv hξν).compProd_left _)
· refine h _ ?_ ?_ ?_
· infer_instance
· exact absolutelyContinuous_of_le (withDensity_rnDeriv_le _ _)
· exact withDensity_absolutelyContinuous ν (μ.rnDeriv ν)
end MutuallySingular
lemma absolutelyContinuous_compProd_of_compProd [SigmaFinite μ] [SigmaFinite ν]
(hκη : μ ⊗ₘ κ ≪ ν ⊗ₘ η) :
μ ⊗ₘ κ ≪ μ ⊗ₘ η := by
rw [ν.haveLebesgueDecomposition_add μ, compProd_add_left, add_comm] at hκη
have h := absolutelyContinuous_of_add_of_mutuallySingular hκη
((mutuallySingular_singularPart _ _).symm.compProd_of_left _ _)
refine h.trans (AbsolutelyContinuous.compProd_left ?_ _)
exact withDensity_absolutelyContinuous _ _
lemma absolutelyContinuous_compProd_iff
[SigmaFinite μ] [SigmaFinite ν] [IsSFiniteKernel κ] [IsSFiniteKernel η] [∀ x, NeZero (κ x)] :
μ ⊗ₘ κ ≪ ν ⊗ₘ η ↔ μ ≪ ν ∧ μ ⊗ₘ κ ≪ μ ⊗ₘ η :=
⟨fun h ↦ ⟨absolutelyContinuous_of_compProd h, absolutelyContinuous_compProd_of_compProd h⟩,
fun h ↦ h.1.compProd_of_compProd h.2⟩
end MeasureTheory.Measure |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/MapComap.lean | import Mathlib.Probability.Kernel.Basic
/-!
# Map of a kernel by a measurable function
We define the map and comap of a kernel along a measurable function, as well as some often useful
particular cases.
## Main definitions
Kernels built from other kernels:
* `map (κ : Kernel α β) (f : β → γ) : Kernel α γ`
`∫⁻ c, g c ∂(map κ f a) = ∫⁻ b, g (f b) ∂(κ a)`
* `comap (κ : Kernel α β) (f : γ → α) (hf : Measurable f) : Kernel γ β`
`∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))`
## Main statements
* `lintegral_map`, `lintegral_comap`: Lebesgue integral of a function against the map or comap of
a kernel.
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
section MapComap
/-! ### map, comap -/
variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : β → γ} {g : γ → α}
/-- The pushforward of a kernel along a measurable function. This is an implementation detail,
use `map κ f` instead. -/
noncomputable def mapOfMeasurable (κ : Kernel α β) (f : β → γ) (hf : Measurable f) :
Kernel α γ where
toFun a := (κ a).map f
measurable' := by fun_prop
open Classical in
/-- The pushforward of a kernel along a function.
If the function is not measurable, we use zero instead. This choice of junk
value ensures that typeclass inference can infer that the `map` of a kernel
satisfying `IsZeroOrMarkovKernel` again satisfies this property. -/
noncomputable def map [MeasurableSpace γ] (κ : Kernel α β) (f : β → γ) : Kernel α γ :=
if hf : Measurable f then mapOfMeasurable κ f hf else 0
theorem map_of_not_measurable (κ : Kernel α β) {f : β → γ} (hf : ¬(Measurable f)) :
map κ f = 0 := by
simp [map, hf]
@[simp] theorem mapOfMeasurable_eq_map (κ : Kernel α β) {f : β → γ} (hf : Measurable f) :
mapOfMeasurable κ f hf = map κ f := by
simp [map, hf]
theorem map_apply (κ : Kernel α β) (hf : Measurable f) (a : α) : map κ f a = (κ a).map f := by
simp only [map, hf, ↓reduceDIte, mapOfMeasurable, coe_mk]
theorem map_apply' (κ : Kernel α β) (hf : Measurable f) (a : α) {s : Set γ} (hs : MeasurableSet s) :
map κ f a s = κ a (f ⁻¹' s) := by rw [map_apply _ hf, Measure.map_apply hf hs]
lemma map_comp_right (κ : Kernel α β) {f : β → γ} (hf : Measurable f) {g : γ → δ}
(hg : Measurable g) : κ.map (g ∘ f) = (κ.map f).map g := by
ext1 x
rw [map_apply _ hg, map_apply _ hf, Measure.map_map hg hf, ← map_apply _ (hg.comp hf)]
@[simp]
lemma map_zero : Kernel.map (0 : Kernel α β) f = 0 := by
ext
by_cases hf : Measurable f
· simp [map_apply, hf]
· simp [map_of_not_measurable _ hf]
@[simp]
lemma map_id (κ : Kernel α β) : map κ id = κ := by
ext a
simp [map_apply, measurable_id]
@[simp]
lemma map_id' (κ : Kernel α β) : map κ (fun a ↦ a) = κ := map_id κ
nonrec theorem lintegral_map (κ : Kernel α β) (hf : Measurable f) (a : α) {g' : γ → ℝ≥0∞}
(hg : Measurable g') : ∫⁻ b, g' b ∂map κ f a = ∫⁻ a, g' (f a) ∂κ a := by
rw [map_apply _ hf, lintegral_map hg hf]
lemma map_apply_eq_iff_map_symm_apply_eq (κ : Kernel α β) {f : β ≃ᵐ γ} (η : Kernel α γ) :
κ.map f = η ↔ κ = η.map f.symm := by
simp_rw [Kernel.ext_iff, map_apply _ f.measurable, map_apply _ f.symm.measurable,
f.map_apply_eq_iff_map_symm_apply_eq]
theorem sum_map_seq (κ : Kernel α β) [IsSFiniteKernel κ] (f : β → γ) :
(Kernel.sum fun n => map (seq κ n) f) = map κ f := by
by_cases hf : Measurable f
· ext a s hs
rw [Kernel.sum_apply, map_apply' κ hf a hs, Measure.sum_apply _ hs, ← measure_sum_seq κ,
Measure.sum_apply _ (hf hs)]
simp_rw [map_apply' _ hf _ hs]
· simp [map_of_not_measurable _ hf]
lemma IsMarkovKernel.map (κ : Kernel α β) [IsMarkovKernel κ] (hf : Measurable f) :
IsMarkovKernel (map κ f) :=
⟨fun a => ⟨by rw [map_apply' κ hf a MeasurableSet.univ, Set.preimage_univ, measure_univ]⟩⟩
instance IsZeroOrMarkovKernel.map (κ : Kernel α β) [IsZeroOrMarkovKernel κ] (f : β → γ) :
IsZeroOrMarkovKernel (map κ f) := by
by_cases hf : Measurable f
· rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp only [map_zero]; infer_instance
· have := IsMarkovKernel.map κ hf; infer_instance
· simp only [map_of_not_measurable _ hf]; infer_instance
instance IsFiniteKernel.map (κ : Kernel α β) [IsFiniteKernel κ] (f : β → γ) :
IsFiniteKernel (map κ f) := by
refine ⟨⟨κ.bound, κ.bound_lt_top, fun a => ?_⟩⟩
by_cases hf : Measurable f
· rw [map_apply' κ hf a MeasurableSet.univ]
exact measure_le_bound κ a _
· simp [map_of_not_measurable _ hf]
instance IsSFiniteKernel.map (κ : Kernel α β) [IsSFiniteKernel κ] (f : β → γ) :
IsSFiniteKernel (map κ f) :=
⟨⟨fun n => Kernel.map (seq κ n) f, inferInstance, (sum_map_seq κ f).symm⟩⟩
@[simp]
lemma map_const (μ : Measure α) {f : α → β} (hf : Measurable f) :
map (const γ μ) f = const γ (μ.map f) := by
ext x s hs
rw [map_apply' _ hf _ hs, const_apply, const_apply, Measure.map_apply hf hs]
/-- Pullback of a kernel, such that for each set s `comap κ g hg c s = κ (g c) s`.
We include measurability in the assumptions instead of using junk values
to make sure that typeclass inference can infer that the `comap` of a Markov kernel
is again a Markov kernel. -/
def comap (κ : Kernel α β) (g : γ → α) (hg : Measurable g) : Kernel γ β where
toFun a := κ (g a)
measurable' := κ.measurable.comp hg
@[simp, norm_cast]
lemma coe_comap (κ : Kernel α β) (g : γ → α) (hg : Measurable g) : κ.comap g hg = κ ∘ g := rfl
theorem comap_apply (κ : Kernel α β) (hg : Measurable g) (c : γ) : comap κ g hg c = κ (g c) :=
rfl
theorem comap_apply' (κ : Kernel α β) (hg : Measurable g) (c : γ) (s : Set β) :
comap κ g hg c s = κ (g c) s :=
rfl
@[simp]
lemma comap_zero (hg : Measurable g) : Kernel.comap (0 : Kernel α β) g hg = 0 := by
ext; simp
@[simp]
lemma comap_id (κ : Kernel α β) : comap κ id measurable_id = κ := by ext; simp
@[simp]
lemma comap_id' (κ : Kernel α β) : comap κ (fun a ↦ a) measurable_id = κ := comap_id κ
theorem lintegral_comap (κ : Kernel α β) (hg : Measurable g) (c : γ) (g' : β → ℝ≥0∞) :
∫⁻ b, g' b ∂comap κ g hg c = ∫⁻ b, g' b ∂κ (g c) :=
rfl
theorem sum_comap_seq (κ : Kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) :
(Kernel.sum fun n => comap (seq κ n) g hg) = comap κ g hg := by
ext a s hs
rw [Kernel.sum_apply, comap_apply' κ hg a s, Measure.sum_apply _ hs, ← measure_sum_seq κ,
Measure.sum_apply _ hs]
simp_rw [comap_apply' _ hg _ s]
instance IsMarkovKernel.comap (κ : Kernel α β) [IsMarkovKernel κ] (hg : Measurable g) :
IsMarkovKernel (comap κ g hg) :=
⟨fun a => ⟨by rw [comap_apply' κ hg a Set.univ, measure_univ]⟩⟩
instance IsZeroOrMarkovKernel.comap (κ : Kernel α β) [IsZeroOrMarkovKernel κ] (hg : Measurable g) :
IsZeroOrMarkovKernel (comap κ g hg) := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp only [comap_zero]; infer_instance
· have := IsMarkovKernel.comap κ hg; infer_instance
instance IsFiniteKernel.comap (κ : Kernel α β) [IsFiniteKernel κ] (hg : Measurable g) :
IsFiniteKernel (comap κ g hg) := by
refine ⟨⟨κ.bound, κ.bound_lt_top, fun a => ?_⟩⟩
rw [comap_apply' κ hg a Set.univ]
exact measure_le_bound κ _ _
instance IsSFiniteKernel.comap (κ : Kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) :
IsSFiniteKernel (comap κ g hg) :=
⟨⟨fun n => Kernel.comap (seq κ n) g hg, inferInstance, (sum_comap_seq κ hg).symm⟩⟩
lemma comap_comp_right (κ : Kernel α β) {f : δ → γ} (hf : Measurable f) (hg : Measurable g) :
comap κ (g ∘ f) (hg.comp hf) = (comap κ g hg).comap f hf := by ext; simp
lemma comap_map_comm (κ : Kernel β γ) {f : α → β} {g : γ → δ}
(hf : Measurable f) (hg : Measurable g) :
comap (map κ g) f hf = map (comap κ f hf) g := by
ext x s _
rw [comap_apply, map_apply _ hg, map_apply _ hg, comap_apply]
end MapComap
@[simp]
lemma id_map {f : α → β} (hf : Measurable f) : Kernel.id.map f = deterministic f hf := by
ext
rw [Kernel.map_apply _ hf, Kernel.deterministic_apply, Kernel.id_apply, Measure.map_dirac hf]
@[simp]
lemma id_comap {f : α → β} (hf : Measurable f) : Kernel.id.comap f hf = deterministic f hf := by
ext
rw [Kernel.comap_apply _ hf, Kernel.deterministic_apply, Kernel.id_apply]
lemma deterministic_map {f : α → β} (hf : Measurable f) {g : β → γ} (hg : Measurable g) :
(deterministic f hf).map g = deterministic (g ∘ f) (hg.comp hf) := by
rw [← id_map, ← map_comp_right _ hf hg, id_map]
section FstSnd
variable {δ : Type*} {mδ : MeasurableSpace δ}
/-- Define a `Kernel (γ × α) β` from a `Kernel α β` by taking the comap of the projection. -/
def prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) : Kernel (γ × α) β :=
comap κ Prod.snd measurable_snd
/-- Define a `Kernel (α × γ) β` from a `Kernel α β` by taking the comap of the projection. -/
def prodMkRight (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) : Kernel (α × γ) β :=
comap κ Prod.fst measurable_fst
@[simp]
theorem prodMkLeft_apply (κ : Kernel α β) (ca : γ × α) : prodMkLeft γ κ ca = κ ca.snd :=
rfl
@[simp]
theorem prodMkRight_apply (κ : Kernel α β) (ca : α × γ) : prodMkRight γ κ ca = κ ca.fst := rfl
theorem prodMkLeft_apply' (κ : Kernel α β) (ca : γ × α) (s : Set β) :
prodMkLeft γ κ ca s = κ ca.snd s :=
rfl
theorem prodMkRight_apply' (κ : Kernel α β) (ca : α × γ) (s : Set β) :
prodMkRight γ κ ca s = κ ca.fst s := rfl
@[simp]
lemma prodMkLeft_zero : Kernel.prodMkLeft α (0 : Kernel β γ) = 0 := by
ext x s _; simp
@[simp]
lemma prodMkRight_zero : Kernel.prodMkRight α (0 : Kernel β γ) = 0 := by
ext x s _; simp
@[simp]
lemma prodMkLeft_add (κ η : Kernel α β) :
prodMkLeft γ (κ + η) = prodMkLeft γ κ + prodMkLeft γ η := by ext; simp
@[simp]
lemma prodMkRight_add (κ η : Kernel α β) :
prodMkRight γ (κ + η) = prodMkRight γ κ + prodMkRight γ η := by ext; simp
lemma sum_prodMkLeft {ι : Type*} [Countable ι] {κ : ι → Kernel α β} :
Kernel.sum (fun i ↦ Kernel.prodMkLeft γ (κ i)) = Kernel.prodMkLeft γ (Kernel.sum κ) := by
ext
simp_rw [sum_apply, prodMkLeft_apply, sum_apply]
lemma sum_prodMkRight {ι : Type*} [Countable ι] {κ : ι → Kernel α β} :
Kernel.sum (fun i ↦ Kernel.prodMkRight γ (κ i)) = Kernel.prodMkRight γ (Kernel.sum κ) := by
ext
simp_rw [sum_apply, prodMkRight_apply, sum_apply]
theorem lintegral_prodMkLeft (κ : Kernel α β) (ca : γ × α) (g : β → ℝ≥0∞) :
∫⁻ b, g b ∂prodMkLeft γ κ ca = ∫⁻ b, g b ∂κ ca.snd := rfl
theorem lintegral_prodMkRight (κ : Kernel α β) (ca : α × γ) (g : β → ℝ≥0∞) :
∫⁻ b, g b ∂prodMkRight γ κ ca = ∫⁻ b, g b ∂κ ca.fst := rfl
instance IsMarkovKernel.prodMkLeft (κ : Kernel α β) [IsMarkovKernel κ] :
IsMarkovKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance
instance IsMarkovKernel.prodMkRight (κ : Kernel α β) [IsMarkovKernel κ] :
IsMarkovKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance
instance IsZeroOrMarkovKernel.prodMkLeft (κ : Kernel α β) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance
instance IsZeroOrMarkovKernel.prodMkRight (κ : Kernel α β) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance
instance IsFiniteKernel.prodMkLeft (κ : Kernel α β) [IsFiniteKernel κ] :
IsFiniteKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance
instance IsFiniteKernel.prodMkRight (κ : Kernel α β) [IsFiniteKernel κ] :
IsFiniteKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance
instance IsSFiniteKernel.prodMkLeft (κ : Kernel α β) [IsSFiniteKernel κ] :
IsSFiniteKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance
instance IsSFiniteKernel.prodMkRight (κ : Kernel α β) [IsSFiniteKernel κ] :
IsSFiniteKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance
lemma isSFiniteKernel_prodMkLeft_unit {κ : Kernel α β} :
IsSFiniteKernel (prodMkLeft Unit κ) ↔ IsSFiniteKernel κ := by
refine ⟨fun _ ↦ ?_, fun _ ↦ inferInstance⟩
change IsSFiniteKernel ((prodMkLeft Unit κ).comap (fun a ↦ ((), a)) (by fun_prop))
infer_instance
lemma isSFiniteKernel_prodMkRight_unit {κ : Kernel α β} :
IsSFiniteKernel (prodMkRight Unit κ) ↔ IsSFiniteKernel κ := by
refine ⟨fun _ ↦ ?_, fun _ ↦ inferInstance⟩
change IsSFiniteKernel ((prodMkRight Unit κ).comap (fun a ↦ (a, ())) (by fun_prop))
infer_instance
lemma map_prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) (f : β → δ) :
map (prodMkLeft γ κ) f = prodMkLeft γ (map κ f) := by
by_cases hf : Measurable f
· simp only [map, hf, ↓reduceDIte]
rfl
· simp [map_of_not_measurable _ hf]
lemma map_prodMkRight (κ : Kernel α β) (γ : Type*) {mγ : MeasurableSpace γ} (f : β → δ) :
map (prodMkRight γ κ) f = prodMkRight γ (map κ f) := by
by_cases hf : Measurable f
· simp only [map, hf, ↓reduceDIte]
rfl
· simp [map_of_not_measurable _ hf]
/-- Define a `Kernel (β × α) γ` from a `Kernel (α × β) γ` by taking the comap of `Prod.swap`. -/
def swapLeft (κ : Kernel (α × β) γ) : Kernel (β × α) γ :=
comap κ Prod.swap measurable_swap
@[simp]
lemma swapLeft_zero : swapLeft (0 : Kernel (α × β) γ) = 0 := by simp [swapLeft]
@[simp]
theorem swapLeft_apply (κ : Kernel (α × β) γ) (a : β × α) : swapLeft κ a = κ a.swap := rfl
theorem swapLeft_apply' (κ : Kernel (α × β) γ) (a : β × α) (s : Set γ) :
swapLeft κ a s = κ a.swap s := rfl
theorem lintegral_swapLeft (κ : Kernel (α × β) γ) (a : β × α) (g : γ → ℝ≥0∞) :
∫⁻ c, g c ∂swapLeft κ a = ∫⁻ c, g c ∂κ a.swap := by
rw [swapLeft_apply]
instance IsMarkovKernel.swapLeft (κ : Kernel (α × β) γ) [IsMarkovKernel κ] :
IsMarkovKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance
instance IsFiniteKernel.swapLeft (κ : Kernel (α × β) γ) [IsFiniteKernel κ] :
IsFiniteKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance
instance IsSFiniteKernel.swapLeft (κ : Kernel (α × β) γ) [IsSFiniteKernel κ] :
IsSFiniteKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance
@[simp] lemma swapLeft_prodMkLeft (κ : Kernel α β) (γ : Type*) {_ : MeasurableSpace γ} :
swapLeft (prodMkLeft γ κ) = prodMkRight γ κ := rfl
@[simp] lemma swapLeft_prodMkRight (κ : Kernel α β) (γ : Type*) {_ : MeasurableSpace γ} :
swapLeft (prodMkRight γ κ) = prodMkLeft γ κ := rfl
/-- Define a `Kernel α (γ × β)` from a `Kernel α (β × γ)` by taking the map of `Prod.swap`.
We use `mapOfMeasurable` in the definition for better defeqs. -/
noncomputable def swapRight (κ : Kernel α (β × γ)) : Kernel α (γ × β) :=
mapOfMeasurable κ Prod.swap measurable_swap
lemma swapRight_eq (κ : Kernel α (β × γ)) : swapRight κ = map κ Prod.swap := by
simp [swapRight]
@[simp]
lemma swapRight_zero : swapRight (0 : Kernel α (β × γ)) = 0 := by simp [swapRight]
theorem swapRight_apply (κ : Kernel α (β × γ)) (a : α) : swapRight κ a = (κ a).map Prod.swap :=
rfl
theorem swapRight_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set (γ × β)} (hs : MeasurableSet s) :
swapRight κ a s = κ a {p | p.swap ∈ s} := by
rw [swapRight_apply, Measure.map_apply measurable_swap hs]; rfl
theorem lintegral_swapRight (κ : Kernel α (β × γ)) (a : α) {g : γ × β → ℝ≥0∞} (hg : Measurable g) :
∫⁻ c, g c ∂swapRight κ a = ∫⁻ bc : β × γ, g bc.swap ∂κ a := by
rw [swapRight_eq, lintegral_map _ measurable_swap a hg]
instance IsMarkovKernel.swapRight (κ : Kernel α (β × γ)) [IsMarkovKernel κ] :
IsMarkovKernel (swapRight κ) := by
rw [Kernel.swapRight_eq]; exact IsMarkovKernel.map _ measurable_swap
instance IsZeroOrMarkovKernel.swapRight (κ : Kernel α (β × γ)) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (swapRight κ) := by rw [Kernel.swapRight_eq]; infer_instance
instance IsFiniteKernel.swapRight (κ : Kernel α (β × γ)) [IsFiniteKernel κ] :
IsFiniteKernel (swapRight κ) := by rw [Kernel.swapRight_eq]; infer_instance
instance IsSFiniteKernel.swapRight (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] :
IsSFiniteKernel (swapRight κ) := by rw [Kernel.swapRight_eq]; infer_instance
/-- Define a `Kernel α β` from a `Kernel α (β × γ)` by taking the map of the first projection.
We use `mapOfMeasurable` for better defeqs. -/
noncomputable def fst (κ : Kernel α (β × γ)) : Kernel α β :=
mapOfMeasurable κ Prod.fst measurable_fst
theorem fst_eq (κ : Kernel α (β × γ)) : fst κ = map κ Prod.fst := by simp [fst]
theorem fst_apply (κ : Kernel α (β × γ)) (a : α) : fst κ a = (κ a).map Prod.fst :=
rfl
theorem fst_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set β} (hs : MeasurableSet s) :
fst κ a s = κ a {p | p.1 ∈ s} := by rw [fst_apply, Measure.map_apply measurable_fst hs]; rfl
theorem fst_real_apply (κ : Kernel α (β × γ)) (a : α) {s : Set β} (hs : MeasurableSet s) :
(fst κ a).real s = (κ a).real {p | p.1 ∈ s} := by
simp [fst_apply', hs, measureReal_def]
@[simp]
lemma fst_zero : fst (0 : Kernel α (β × γ)) = 0 := by simp [fst]
theorem lintegral_fst (κ : Kernel α (β × γ)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) :
∫⁻ c, g c ∂fst κ a = ∫⁻ bc : β × γ, g bc.fst ∂κ a := by
rw [fst_eq, lintegral_map _ measurable_fst a hg]
instance IsMarkovKernel.fst (κ : Kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (fst κ) := by
rw [Kernel.fst_eq]; exact IsMarkovKernel.map _ measurable_fst
instance IsZeroOrMarkovKernel.fst (κ : Kernel α (β × γ)) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (fst κ) := by
rw [Kernel.fst_eq]; infer_instance
instance IsFiniteKernel.fst (κ : Kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (fst κ) := by
rw [Kernel.fst_eq]; infer_instance
instance IsSFiniteKernel.fst (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] :
IsSFiniteKernel (fst κ) := by rw [Kernel.fst_eq]; infer_instance
instance (priority := 100) isFiniteKernel_of_isFiniteKernel_fst {κ : Kernel α (β × γ)}
[h : IsFiniteKernel (fst κ)] :
IsFiniteKernel κ := by
refine ⟨(fst κ).bound, (fst κ).bound_lt_top,
fun a ↦ le_trans ?_ (measure_le_bound (fst κ) a Set.univ)⟩
rw [fst_apply' _ _ MeasurableSet.univ]
simp
lemma fst_map_prod (κ : Kernel α β) {f : β → γ} {g : β → δ} (hg : Measurable g) :
fst (map κ (fun x ↦ (f x, g x))) = map κ f := by
by_cases hf : Measurable f
· ext x s hs
rw [fst_apply' _ _ hs, map_apply' _ (hf.prod hg) _, map_apply' _ hf _ hs]
· simp only [Set.preimage, Set.mem_setOf]
· exact measurable_fst hs
· have : ¬ Measurable (fun x ↦ (f x, g x)) := by
contrapose! hf; exact hf.fst
simp [map_of_not_measurable _ hf, map_of_not_measurable _ this]
lemma fst_map_id_prod (κ : Kernel α β) {f : β → γ} (hf : Measurable f) :
fst (map κ (fun a ↦ (a, f a))) = κ := by
rw [fst_map_prod _ hf, Kernel.map_id']
lemma fst_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : Kernel α (β × γ)) :
fst (prodMkLeft δ κ) = prodMkLeft δ (fst κ) := rfl
lemma fst_prodMkRight (κ : Kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] :
fst (prodMkRight δ κ) = prodMkRight δ (fst κ) := rfl
/-- Define a `Kernel α γ` from a `Kernel α (β × γ)` by taking the map of the second projection.
We use `mapOfMeasurable` for better defeqs. -/
noncomputable def snd (κ : Kernel α (β × γ)) : Kernel α γ :=
mapOfMeasurable κ Prod.snd measurable_snd
theorem snd_eq (κ : Kernel α (β × γ)) : snd κ = map κ Prod.snd := by simp [snd]
theorem snd_apply (κ : Kernel α (β × γ)) (a : α) : snd κ a = (κ a).map Prod.snd :=
rfl
theorem snd_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set γ} (hs : MeasurableSet s) :
snd κ a s = κ a (Prod.snd ⁻¹' s) := by rw [snd_apply, Measure.map_apply measurable_snd hs]
@[simp]
lemma snd_zero : snd (0 : Kernel α (β × γ)) = 0 := by simp [snd]
theorem lintegral_snd (κ : Kernel α (β × γ)) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) :
∫⁻ c, g c ∂snd κ a = ∫⁻ bc : β × γ, g bc.snd ∂κ a := by
rw [snd_eq, lintegral_map _ measurable_snd a hg]
instance IsMarkovKernel.snd (κ : Kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (snd κ) := by
rw [Kernel.snd_eq]; exact IsMarkovKernel.map _ measurable_snd
instance IsZeroOrMarkovKernel.snd (κ : Kernel α (β × γ)) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (snd κ) := by
rw [Kernel.snd_eq]; infer_instance
instance IsFiniteKernel.snd (κ : Kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (snd κ) := by
rw [Kernel.snd_eq]; infer_instance
instance IsSFiniteKernel.snd (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] :
IsSFiniteKernel (snd κ) := by rw [Kernel.snd_eq]; infer_instance
instance (priority := 100) isFiniteKernel_of_isFiniteKernel_snd {κ : Kernel α (β × γ)}
[h : IsFiniteKernel (snd κ)] :
IsFiniteKernel κ := by
refine ⟨(snd κ).bound, (snd κ).bound_lt_top,
fun a ↦ le_trans ?_ (measure_le_bound (snd κ) a Set.univ)⟩
rw [snd_apply' _ _ MeasurableSet.univ]
simp
lemma snd_map_prod (κ : Kernel α β) {f : β → γ} {g : β → δ} (hf : Measurable f) :
snd (map κ (fun x ↦ (f x, g x))) = map κ g := by
by_cases hg : Measurable g
· ext x s hs
rw [snd_apply' _ _ hs, map_apply' _ (hf.prod hg), map_apply' _ hg _ hs]
· simp only [Set.preimage, Set.mem_setOf]
· exact measurable_snd hs
· have : ¬ Measurable (fun x ↦ (f x, g x)) := by
contrapose! hg; exact hg.snd
simp [map_of_not_measurable _ hg, map_of_not_measurable _ this]
lemma snd_map_prod_id (κ : Kernel α β) {f : β → γ} (hf : Measurable f) :
snd (map κ (fun a ↦ (f a, a))) = κ := by
rw [snd_map_prod _ hf, Kernel.map_id']
lemma snd_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : Kernel α (β × γ)) :
snd (prodMkLeft δ κ) = prodMkLeft δ (snd κ) := rfl
lemma snd_prodMkRight (κ : Kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] :
snd (prodMkRight δ κ) = prodMkRight δ (snd κ) := rfl
@[simp]
lemma fst_swapRight (κ : Kernel α (β × γ)) : fst (swapRight κ) = snd κ := by
ext a s hs
rw [fst_apply' _ _ hs, swapRight_apply', snd_apply' _ _ hs]
· rfl
· exact measurable_fst hs
@[simp]
lemma snd_swapRight (κ : Kernel α (β × γ)) : snd (swapRight κ) = fst κ := by
ext a s hs
rw [snd_apply' _ _ hs, swapRight_apply', fst_apply' _ _ hs]
· rfl
· exact measurable_snd hs
end FstSnd
section sectLsectR
variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ}
/-- Define a `Kernel α γ` from a `Kernel (α × β) γ` by taking the comap of `fun a ↦ (a, b)` for
a given `b : β`. -/
noncomputable def sectL (κ : Kernel (α × β) γ) (b : β) : Kernel α γ :=
comap κ (fun a ↦ (a, b)) (measurable_id.prodMk measurable_const)
@[simp] theorem sectL_apply (κ : Kernel (α × β) γ) (b : β) (a : α) : sectL κ b a = κ (a, b) := rfl
@[simp] lemma sectL_zero (b : β) : sectL (0 : Kernel (α × β) γ) b = 0 := by simp [sectL]
instance (κ : Kernel (α × β) γ) (b : β) [IsMarkovKernel κ] : IsMarkovKernel (sectL κ b) := by
rw [sectL]; infer_instance
instance (κ : Kernel (α × β) γ) (b : β) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (sectL κ b) := by
rw [sectL]; infer_instance
instance (κ : Kernel (α × β) γ) (b : β) [IsFiniteKernel κ] : IsFiniteKernel (sectL κ b) := by
rw [sectL]; infer_instance
instance (κ : Kernel (α × β) γ) (b : β) [IsSFiniteKernel κ] : IsSFiniteKernel (sectL κ b) := by
rw [sectL]; infer_instance
instance (κ : Kernel (α × β) γ) (a : α) (b : β) [NeZero (κ (a, b))] : NeZero ((sectL κ b) a) := by
rw [sectL_apply]; infer_instance
instance (priority := 100) {κ : Kernel (α × β) γ} [∀ b, IsMarkovKernel (sectL κ b)] :
IsMarkovKernel κ := by
refine ⟨fun _ ↦ ⟨?_⟩⟩
rw [← sectL_apply, measure_univ]
--I'm not sure this lemma is actually useful
lemma comap_sectL (κ : Kernel (α × β) γ) (b : β) {f : δ → α} (hf : Measurable f) :
comap (sectL κ b) f hf = comap κ (fun d ↦ (f d, b)) (hf.prodMk measurable_const) := by
ext d s
rw [comap_apply, sectL_apply, comap_apply]
@[simp]
lemma sectL_prodMkLeft (α : Type*) [MeasurableSpace α] (κ : Kernel β γ) (a : α) {b : β} :
sectL (prodMkLeft α κ) b a = κ b := rfl
@[simp]
lemma sectL_prodMkRight (β : Type*) [MeasurableSpace β] (κ : Kernel α γ) (b : β) :
sectL (prodMkRight β κ) b = κ := rfl
/-- Define a `Kernel β γ` from a `Kernel (α × β) γ` by taking the comap of `fun b ↦ (a, b)` for
a given `a : α`. -/
noncomputable def sectR (κ : Kernel (α × β) γ) (a : α) : Kernel β γ :=
comap κ (fun b ↦ (a, b)) (measurable_const.prodMk measurable_id)
@[simp] theorem sectR_apply (κ : Kernel (α × β) γ) (b : β) (a : α) : sectR κ a b = κ (a, b) := rfl
@[simp] lemma sectR_zero (a : α) : sectR (0 : Kernel (α × β) γ) a = 0 := by simp [sectR]
instance (κ : Kernel (α × β) γ) (a : α) [IsMarkovKernel κ] : IsMarkovKernel (sectR κ a) := by
rw [sectR]; infer_instance
instance (κ : Kernel (α × β) γ) (a : α) [IsZeroOrMarkovKernel κ] :
IsZeroOrMarkovKernel (sectR κ a) := by
rw [sectR]; infer_instance
instance (κ : Kernel (α × β) γ) (a : α) [IsFiniteKernel κ] : IsFiniteKernel (sectR κ a) := by
rw [sectR]; infer_instance
instance (κ : Kernel (α × β) γ) (a : α) [IsSFiniteKernel κ] : IsSFiniteKernel (sectR κ a) := by
rw [sectR]; infer_instance
instance (κ : Kernel (α × β) γ) (a : α) (b : β) [NeZero (κ (a, b))] : NeZero ((sectR κ a) b) := by
rw [sectR_apply]; infer_instance
instance (priority := 100) {κ : Kernel (α × β) γ} [∀ b, IsMarkovKernel (sectR κ b)] :
IsMarkovKernel κ := by
refine ⟨fun _ ↦ ⟨?_⟩⟩
rw [← sectR_apply, measure_univ]
--I'm not sure this lemma is actually useful
lemma comap_sectR (κ : Kernel (α × β) γ) (a : α) {f : δ → β} (hf : Measurable f) :
comap (sectR κ a) f hf = comap κ (fun d ↦ (a, f d)) (measurable_const.prodMk hf) := by
ext d s
rw [comap_apply, sectR_apply, comap_apply]
@[simp]
lemma sectR_prodMkLeft (α : Type*) [MeasurableSpace α] (κ : Kernel β γ) (a : α) :
sectR (prodMkLeft α κ) a = κ := rfl
@[simp]
lemma sectR_prodMkRight (β : Type*) [MeasurableSpace β] (κ : Kernel α γ) (b : β) {a : α} :
sectR (prodMkRight β κ) a b = κ a := rfl
@[simp] lemma sectL_swapRight (κ : Kernel (α × β) γ) : sectL (swapLeft κ) = sectR κ := rfl
@[simp] lemma sectR_swapRight (κ : Kernel (α × β) γ) : sectR (swapLeft κ) = sectL κ := rfl
end sectLsectR
lemma isSFiniteKernel_prodMkLeft_iff [Nonempty γ] {κ : Kernel α β} :
IsSFiniteKernel (prodMkLeft γ κ) ↔ IsSFiniteKernel κ := by
inhabit γ
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [← sectR_prodMkLeft γ κ default]
infer_instance
lemma isSFiniteKernel_prodMkRight_iff [Nonempty γ] {κ : Kernel α β} :
IsSFiniteKernel (prodMkRight γ κ) ↔ IsSFiniteKernel κ := by
inhabit γ
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [← sectL_prodMkRight γ κ default]
infer_instance
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/IntegralCompProd.lean | import Mathlib.Probability.Kernel.Composition.MeasureComp
import Mathlib.Probability.Kernel.MeasurableIntegral
/-!
# Bochner integral of a function against the composition and the composition-products of two kernels
We prove properties of the composition and the composition-product of two kernels.
If `κ` is a kernel from `α` to `β` and `η` is a kernel from `β` to `γ`, we can form their
composition `η ∘ₖ κ : Kernel α γ`. We proved in `ProbabilityTheory.Kernel.lintegral_comp` that it
verifies `∫⁻ c, f c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, f c ∂(η b) ∂(κ a)`. In this file, we
prove the same equality for the Bochner integral.
If `κ` is an s-finite kernel from `α` to `β` and `η` is an s-finite kernel from `α × β` to `γ`,
we can form their composition-product `κ ⊗ₖ η : Kernel α (β × γ)`.
We proved in `ProbabilityTheory.Kernel.lintegral_compProd` that it
verifies `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`. In this file, we
prove the same equality for the Bochner integral.
## Main statements
* `ProbabilityTheory.integral_compProd`: the integral against the composition-product is
`∫ z, f z ∂((κ ⊗ₖ η) a) = ∫ x, ∫ y, f (x, y) ∂(η (a, x)) ∂(κ a)`.
* `ProbabilityTheory.integral_comp`: the integral against the composition is
`∫⁻ z, f z ∂((η ∘ₖ κ) a) = ∫⁻ x, ∫⁻ y, f y ∂(η x) ∂(κ a)`.
## Implementation details
This file is to a large extent a copy of part of `Mathlib/MeasureTheory/Integral/Prod.lean`.
The product of two measures is a particular case of composition-product of kernels and
it turns out that once the measurability of the Lebesgue integral of a kernel is proved,
almost all proofs about integrals against products of measures extend with minimal modifications
to the composition-product of two kernels.
The composition of kernels can also be expressed easily with the composition-product and therefore
the proofs about the composition are only simplified versions of the ones for the
composition-product. However it is necessary to do all the proofs once again because the
composition-product requires s-finiteness while the composition does not.
-/
noncomputable section
open Set Function Real ENNReal MeasureTheory Filter ProbabilityTheory ProbabilityTheory.Kernel
open scoped Topology ENNReal MeasureTheory
variable {α β γ E : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} [NormedAddCommGroup E] {a : α}
namespace ProbabilityTheory
section compProd
variable {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η]
theorem hasFiniteIntegral_prodMk_left (a : α) {s : Set (β × γ)} (h2s : (κ ⊗ₖ η) a s ≠ ∞) :
HasFiniteIntegral (fun b => (η (a, b)).real (Prod.mk b ⁻¹' s)) (κ a) := by
let t := toMeasurable ((κ ⊗ₖ η) a) s
simp_rw [hasFiniteIntegral_iff_enorm, measureReal_def, enorm_eq_ofReal toReal_nonneg]
calc
∫⁻ b, ENNReal.ofReal (η (a, b) (Prod.mk b ⁻¹' s)).toReal ∂κ a
_ ≤ ∫⁻ b, η (a, b) (Prod.mk b ⁻¹' t) ∂κ a := by
refine lintegral_mono_ae ?_
filter_upwards [ae_kernel_lt_top a h2s] with b hb
rw [ofReal_toReal hb.ne]
exact measure_mono (preimage_mono (subset_toMeasurable _ _))
_ ≤ (κ ⊗ₖ η) a t := le_compProd_apply _ _ _ _
_ = (κ ⊗ₖ η) a s := measure_toMeasurable s
_ < ⊤ := h2s.lt_top
theorem integrable_kernel_prodMk_left (a : α) {s : Set (β × γ)} (hs : MeasurableSet s)
(h2s : (κ ⊗ₖ η) a s ≠ ∞) : Integrable (fun b => (η (a, b)).real (Prod.mk b ⁻¹' s)) (κ a) := by
constructor
· exact (measurable_kernel_prodMk_left' hs a).ennreal_toReal.aestronglyMeasurable
· exact hasFiniteIntegral_prodMk_left a h2s
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_kernel_compProd [NormedSpace ℝ E]
⦃f : β × γ → E⦄ (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) :
AEStronglyMeasurable (fun x => ∫ y, f (x, y) ∂η (a, x)) (κ a) :=
⟨fun x => ∫ y, hf.mk f (x, y) ∂η (a, x), hf.stronglyMeasurable_mk.integral_kernel_prod_right'', by
filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with _ hx using integral_congr_ae hx⟩
theorem _root_.MeasureTheory.AEStronglyMeasurable.compProd_mk_left {δ : Type*} [TopologicalSpace δ]
{f : β × γ → δ} (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) :
∀ᵐ x ∂κ a, AEStronglyMeasurable (fun y => f (x, y)) (η (a, x)) := by
filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with x hx using
⟨fun y => hf.mk f (x, y), hf.stronglyMeasurable_mk.comp_measurable measurable_prodMk_left, hx⟩
/-! ### Integrability -/
theorem hasFiniteIntegral_compProd_iff ⦃f : β × γ → E⦄ (h1f : StronglyMeasurable f) :
HasFiniteIntegral f ((κ ⊗ₖ η) a) ↔
(∀ᵐ x ∂κ a, HasFiniteIntegral (fun y => f (x, y)) (η (a, x))) ∧
HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by
simp only [hasFiniteIntegral_iff_enorm]
rw [lintegral_compProd _ _ _ h1f.enorm]
have : ∀ x, ∀ᵐ y ∂η (a, x), 0 ≤ ‖f (x, y)‖ := fun x => Eventually.of_forall fun y => norm_nonneg _
simp_rw [integral_eq_lintegral_of_nonneg_ae (this _)
(h1f.norm.comp_measurable measurable_prodMk_left).aestronglyMeasurable,
enorm_eq_ofReal toReal_nonneg, ofReal_norm_eq_enorm]
have : ∀ {p q r : Prop} (_ : r → p), (r ↔ p ∧ q) ↔ p → (r ↔ q) := fun {p q r} h1 => by
rw [← and_congr_right_iff, and_iff_right_of_imp h1]
rw [this]
· intro h2f; rw [lintegral_congr_ae]
filter_upwards [h2f] with x hx
rw [ofReal_toReal]; finiteness
· intro h2f; refine ae_lt_top ?_ h2f.ne; exact h1f.enorm.lintegral_kernel_prod_right''
theorem hasFiniteIntegral_compProd_iff' ⦃f : β × γ → E⦄
(h1f : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) :
HasFiniteIntegral f ((κ ⊗ₖ η) a) ↔
(∀ᵐ x ∂κ a, HasFiniteIntegral (fun y => f (x, y)) (η (a, x))) ∧
HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by
rw [hasFiniteIntegral_congr h1f.ae_eq_mk,
hasFiniteIntegral_compProd_iff h1f.stronglyMeasurable_mk]
apply and_congr
· apply eventually_congr
filter_upwards [ae_ae_of_ae_compProd h1f.ae_eq_mk.symm] with x hx using
hasFiniteIntegral_congr hx
· apply hasFiniteIntegral_congr
filter_upwards [ae_ae_of_ae_compProd h1f.ae_eq_mk.symm] with _ hx using
integral_congr_ae (EventuallyEq.fun_comp hx _)
theorem integrable_compProd_iff ⦃f : β × γ → E⦄ (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) :
Integrable f ((κ ⊗ₖ η) a) ↔
(∀ᵐ x ∂κ a, Integrable (fun y => f (x, y)) (η (a, x))) ∧
Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by
simp only [Integrable, hasFiniteIntegral_compProd_iff' hf, hf.norm.integral_kernel_compProd,
hf, hf.compProd_mk_left, eventually_and, true_and]
theorem _root_.MeasureTheory.Integrable.ae_of_compProd ⦃f : β × γ → E⦄
(hf : Integrable f ((κ ⊗ₖ η) a)) : ∀ᵐ x ∂κ a, Integrable (fun y => f (x, y)) (η (a, x)) :=
((integrable_compProd_iff hf.aestronglyMeasurable).mp hf).1
theorem _root_.MeasureTheory.Integrable.integral_norm_compProd ⦃f : β × γ → E⦄
(hf : Integrable f ((κ ⊗ₖ η) a)) : Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) :=
((integrable_compProd_iff hf.aestronglyMeasurable).mp hf).2
theorem _root_.MeasureTheory.Integrable.integral_compProd [NormedSpace ℝ E]
⦃f : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) :
Integrable (fun x => ∫ y, f (x, y) ∂η (a, x)) (κ a) :=
Integrable.mono hf.integral_norm_compProd hf.aestronglyMeasurable.integral_kernel_compProd <|
Eventually.of_forall fun x =>
(norm_integral_le_integral_norm _).trans_eq <|
(norm_of_nonneg <|
integral_nonneg_of_ae <|
Eventually.of_forall fun y => (norm_nonneg (f (x, y)) :)).symm
/-! ### Bochner integral -/
variable [NormedSpace ℝ E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E']
theorem Kernel.integral_fn_integral_add ⦃f g : β × γ → E⦄ (F : E → E')
(hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, F (∫ y, f (x, y) + g (x, y) ∂η (a, x)) ∂κ a =
∫ x, F (∫ y, f (x, y) ∂η (a, x) + ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by
refine integral_congr_ae ?_
filter_upwards [hf.ae_of_compProd, hg.ae_of_compProd] with _ h2f h2g
simp [integral_add h2f h2g]
theorem Kernel.integral_fn_integral_sub ⦃f g : β × γ → E⦄ (F : E → E')
(hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, F (∫ y, f (x, y) - g (x, y) ∂η (a, x)) ∂κ a =
∫ x, F (∫ y, f (x, y) ∂η (a, x) - ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by
refine integral_congr_ae ?_
filter_upwards [hf.ae_of_compProd, hg.ae_of_compProd] with _ h2f h2g
simp [integral_sub h2f h2g]
theorem Kernel.lintegral_fn_integral_sub ⦃f g : β × γ → E⦄ (F : E → ℝ≥0∞)
(hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) :
∫⁻ x, F (∫ y, f (x, y) - g (x, y) ∂η (a, x)) ∂κ a =
∫⁻ x, F (∫ y, f (x, y) ∂η (a, x) - ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by
refine lintegral_congr_ae ?_
filter_upwards [hf.ae_of_compProd, hg.ae_of_compProd] with _ h2f h2g
simp [integral_sub h2f h2g]
theorem Kernel.integral_integral_add ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a))
(hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, ∫ y, f (x, y) + g (x, y) ∂η (a, x) ∂κ a =
∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a + ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a :=
(Kernel.integral_fn_integral_add id hf hg).trans <|
integral_add hf.integral_compProd hg.integral_compProd
theorem Kernel.integral_integral_add' ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a))
(hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, ∫ y, (f + g) (x, y) ∂η (a, x) ∂κ a =
∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a + ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a :=
Kernel.integral_integral_add hf hg
theorem Kernel.integral_integral_sub ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a))
(hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, ∫ y, f (x, y) - g (x, y) ∂η (a, x) ∂κ a =
∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a - ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a :=
(Kernel.integral_fn_integral_sub id hf hg).trans <|
integral_sub hf.integral_compProd hg.integral_compProd
theorem Kernel.integral_integral_sub' ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a))
(hg : Integrable g ((κ ⊗ₖ η) a)) :
∫ x, ∫ y, (f - g) (x, y) ∂η (a, x) ∂κ a =
∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a - ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a :=
Kernel.integral_integral_sub hf hg
theorem Kernel.continuous_integral_integral :
Continuous fun f : β × γ →₁[(κ ⊗ₖ η) a] E => ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by
rw [continuous_iff_continuousAt]; intro g
refine
tendsto_integral_of_L1 _ (L1.integrable_coeFn g).integral_compProd
(Eventually.of_forall fun h => (L1.integrable_coeFn h).integral_compProd) ?_
simp_rw [← lintegral_fn_integral_sub (‖·‖ₑ) (L1.integrable_coeFn _) (L1.integrable_coeFn g)]
apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds _ (fun i => zero_le _) _
· exact fun i => ∫⁻ x, ∫⁻ y, ‖i (x, y) - g (x, y)‖ₑ ∂η (a, x) ∂κ a
swap; · exact fun i => lintegral_mono fun x => enorm_integral_le_lintegral_enorm _
change
Tendsto
(fun i : β × γ →₁[(κ ⊗ₖ η) a] E => ∫⁻ x, ∫⁻ y : γ, ‖i (x, y) - g (x, y)‖ₑ ∂η (a, x) ∂κ a)
(𝓝 g) (𝓝 0)
have this (i : Lp (α := β × γ) E 1 (((κ ⊗ₖ η) a) : Measure (β × γ))) :
Measurable fun z => ‖i z - g z‖ₑ :=
((Lp.stronglyMeasurable i).sub (Lp.stronglyMeasurable g)).enorm
simp_rw [← lintegral_compProd _ _ _ (this _), ← L1.ofReal_norm_sub_eq_lintegral, ← ofReal_zero]
refine (continuous_ofReal.tendsto 0).comp ?_
rw [← tendsto_iff_norm_sub_tendsto_zero]
exact tendsto_id
theorem integral_compProd :
∀ {f : β × γ → E} (_ : Integrable f ((κ ⊗ₖ η) a)),
∫ z, f z ∂(κ ⊗ₖ η) a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by
by_cases hE : CompleteSpace E; swap
· simp [integral, hE]
apply Integrable.induction
· intro c s hs h2s
simp_rw [integral_indicator hs, ← indicator_comp_right, Function.comp_def,
integral_indicator (measurable_prodMk_left hs), MeasureTheory.setIntegral_const,
integral_smul_const, measureReal_def]
congr 1
rw [integral_toReal]
rotate_left
· exact (Kernel.measurable_kernel_prodMk_left' hs _).aemeasurable
· exact ae_kernel_lt_top a h2s.ne
rw [Kernel.compProd_apply hs]
· intro f g _ i_f i_g hf hg
simp_rw [integral_add' i_f i_g, Kernel.integral_integral_add' i_f i_g, hf, hg]
· exact isClosed_eq continuous_integral Kernel.continuous_integral_integral
· intro f g hfg _ hf
convert hf using 1
· exact integral_congr_ae hfg.symm
· apply integral_congr_ae
filter_upwards [ae_ae_of_ae_compProd hfg] with x hfgx using
integral_congr_ae (ae_eq_symm hfgx)
theorem setIntegral_compProd {f : β × γ → E} {s : Set β} {t : Set γ} (hs : MeasurableSet s)
(ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) ((κ ⊗ₖ η) a)) :
∫ z in s ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫ x in s, ∫ y in t, f (x, y) ∂η (a, x) ∂κ a := by
-- Porting note: `compProd_restrict` needed some explicit arguments
rw [← Kernel.restrict_apply (κ ⊗ₖ η) (hs.prod ht), ← compProd_restrict hs ht, integral_compProd]
· simp_rw [Kernel.restrict_apply]
· rw [compProd_restrict, Kernel.restrict_apply]; exact hf
theorem setIntegral_compProd_univ_right (f : β × γ → E) {s : Set β} (hs : MeasurableSet s)
(hf : IntegrableOn f (s ×ˢ univ) ((κ ⊗ₖ η) a)) :
∫ z in s ×ˢ univ, f z ∂(κ ⊗ₖ η) a = ∫ x in s, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by
simp_rw [setIntegral_compProd hs MeasurableSet.univ hf, Measure.restrict_univ]
theorem setIntegral_compProd_univ_left (f : β × γ → E) {t : Set γ} (ht : MeasurableSet t)
(hf : IntegrableOn f (univ ×ˢ t) ((κ ⊗ₖ η) a)) :
∫ z in univ ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫ x, ∫ y in t, f (x, y) ∂η (a, x) ∂κ a := by
simp_rw [setIntegral_compProd MeasurableSet.univ ht hf, Measure.restrict_univ]
end compProd
section comp
variable {κ : Kernel α β} {η : Kernel β γ}
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_kernel_comp [NormedSpace ℝ E]
⦃f : γ → E⦄ (hf : AEStronglyMeasurable f ((η ∘ₖ κ) a)) :
AEStronglyMeasurable (fun x ↦ ∫ y, f y ∂η x) (κ a) :=
⟨fun x ↦ ∫ y, hf.mk f y ∂η x, hf.stronglyMeasurable_mk.integral_kernel, by
filter_upwards [ae_ae_of_ae_comp hf.ae_eq_mk] with _ hx using integral_congr_ae hx⟩
theorem _root_.MeasureTheory.AEStronglyMeasurable.comp {δ : Type*} [TopologicalSpace δ]
{f : γ → δ} (hf : AEStronglyMeasurable f ((η ∘ₖ κ) a)) :
∀ᵐ x ∂κ a, AEStronglyMeasurable f (η x) := by
filter_upwards [ae_ae_of_ae_comp hf.ae_eq_mk] with x hx using
⟨hf.mk f, hf.stronglyMeasurable_mk, hx⟩
/-! ### Integrability with respect to composition -/
theorem hasFiniteIntegral_comp_iff ⦃f : γ → E⦄ (hf : StronglyMeasurable f) :
HasFiniteIntegral f ((η ∘ₖ κ) a) ↔
(∀ᵐ x ∂κ a, HasFiniteIntegral f (η x)) ∧ HasFiniteIntegral (fun x ↦ ∫ y, ‖f y‖ ∂η x) (κ a) := by
simp_rw [hasFiniteIntegral_iff_enorm, lintegral_comp _ _ _ hf.enorm]
simp_rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun y ↦ norm_nonneg _)
hf.norm.aestronglyMeasurable, enorm_eq_ofReal toReal_nonneg, ofReal_norm_eq_enorm]
have : ∀ {p q r : Prop} (_ : r → p), (r ↔ p ∧ q) ↔ p → (r ↔ q) := fun h ↦ by
rw [← and_congr_right_iff, and_iff_right_of_imp h]
rw [this]
· intro h
rw [lintegral_congr_ae]
filter_upwards [h] with x hx
rw [ofReal_toReal]
finiteness
· exact fun h ↦ ae_lt_top hf.enorm.lintegral_kernel h.ne
theorem hasFiniteIntegral_comp_iff' ⦃f : γ → E⦄ (hf : AEStronglyMeasurable f ((η ∘ₖ κ) a)) :
HasFiniteIntegral f ((η ∘ₖ κ) a) ↔
(∀ᵐ x ∂κ a, HasFiniteIntegral f (η x)) ∧ HasFiniteIntegral (fun x ↦ ∫ y, ‖f y‖ ∂η x) (κ a) := by
rw [hasFiniteIntegral_congr hf.ae_eq_mk, hasFiniteIntegral_comp_iff hf.stronglyMeasurable_mk]
refine and_congr (eventually_congr ?_) (hasFiniteIntegral_congr ?_)
· filter_upwards [ae_ae_of_ae_comp hf.ae_eq_mk.symm] with _ hx using
hasFiniteIntegral_congr hx
· filter_upwards [ae_ae_of_ae_comp hf.ae_eq_mk.symm] with _ hx using
integral_congr_ae (EventuallyEq.fun_comp hx _)
theorem integrable_comp_iff ⦃f : γ → E⦄ (hf : AEStronglyMeasurable f ((η ∘ₖ κ) a)) :
Integrable f ((η ∘ₖ κ) a) ↔
(∀ᵐ y ∂κ a, Integrable f (η y)) ∧ Integrable (fun y ↦ ∫ z, ‖f z‖ ∂η y) (κ a) := by
simp only [Integrable, hf, hasFiniteIntegral_comp_iff' hf, true_and, eventually_and, hf.comp,
hf.norm.integral_kernel_comp]
protected lemma _root_.MeasureTheory.Measure.integrable_comp_iff {μ : Measure α} {f : β → E}
(hf : AEStronglyMeasurable f (κ ∘ₘ μ)) :
Integrable f (κ ∘ₘ μ)
↔ (∀ᵐ x ∂μ, Integrable f (κ x)) ∧ Integrable (fun x ↦ ∫ y, ‖f y‖ ∂κ x) μ := by
rw [Measure.comp_eq_comp_const_apply, ProbabilityTheory.integrable_comp_iff]
· simp
· simpa [Kernel.comp_apply]
theorem _root_.MeasureTheory.Integrable.ae_of_comp ⦃f : γ → E⦄ (hf : Integrable f ((η ∘ₖ κ) a)) :
∀ᵐ x ∂κ a, Integrable f (η x) := ((integrable_comp_iff hf.1).1 hf).1
theorem _root_.MeasureTheory.Integrable.integral_norm_comp ⦃f : γ → E⦄
(hf : Integrable f ((η ∘ₖ κ) a)) : Integrable (fun x ↦ ∫ y, ‖f y‖ ∂η x) (κ a) :=
((integrable_comp_iff hf.1).1 hf).2
theorem _root_.MeasureTheory.Integrable.integral_comp [NormedSpace ℝ E] ⦃f : γ → E⦄
(hf : Integrable f ((η ∘ₖ κ) a)) : Integrable (fun x ↦ ∫ y, f y ∂η x) (κ a) :=
Integrable.mono hf.integral_norm_comp hf.1.integral_kernel_comp <|
ae_of_all _ fun _ ↦ (norm_integral_le_integral_norm _).trans_eq
(norm_of_nonneg <| integral_nonneg_of_ae <| ae_of_all _ fun _ ↦ norm_nonneg _).symm
/-! ### Bochner integral with respect to the composition -/
variable [NormedSpace ℝ E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E']
namespace Kernel
theorem integral_fn_integral_add_comp ⦃f g : γ → E⦄ (F : E → E')
(hf : Integrable f ((η ∘ₖ κ) a)) (hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, F (∫ y, f y + g y ∂η x) ∂κ a = ∫ x, F (∫ y, f y ∂η x + ∫ y, g y ∂η x) ∂κ a := by
refine integral_congr_ae ?_
filter_upwards [hf.ae_of_comp, hg.ae_of_comp] with _ h2f h2g
simp [integral_add h2f h2g]
theorem integral_fn_integral_sub_comp ⦃f g : γ → E⦄ (F : E → E')
(hf : Integrable f ((η ∘ₖ κ) a)) (hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, F (∫ y, f y - g y ∂η x) ∂κ a = ∫ x, F (∫ y, f y ∂η x - ∫ y, g y ∂η x) ∂κ a := by
refine integral_congr_ae ?_
filter_upwards [hf.ae_of_comp, hg.ae_of_comp] with _ h2f h2g
simp [integral_sub h2f h2g]
theorem lintegral_fn_integral_sub_comp ⦃f g : γ → E⦄ (F : E → ℝ≥0∞)
(hf : Integrable f ((η ∘ₖ κ) a)) (hg : Integrable g ((η ∘ₖ κ) a)) :
∫⁻ x, F (∫ y, f y - g y ∂η x) ∂κ a = ∫⁻ x, F (∫ y, f y ∂η x - ∫ y, g y ∂η x) ∂κ a := by
refine lintegral_congr_ae ?_
filter_upwards [hf.ae_of_comp, hg.ae_of_comp] with _ h2f h2g
simp [integral_sub h2f h2g]
theorem integral_integral_add_comp ⦃f g : γ → E⦄ (hf : Integrable f ((η ∘ₖ κ) a))
(hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, ∫ y, f y + g y ∂η x ∂κ a = ∫ x, ∫ y, f y ∂η x ∂κ a + ∫ x, ∫ y, g y ∂η x ∂κ a :=
(integral_fn_integral_add_comp id hf hg).trans <| integral_add hf.integral_comp hg.integral_comp
theorem integral_integral_add'_comp ⦃f g : γ → E⦄ (hf : Integrable f ((η ∘ₖ κ) a))
(hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, ∫ y, (f + g) y ∂η x ∂κ a = ∫ x, ∫ y, f y ∂η x ∂κ a + ∫ x, ∫ y, g y ∂η x ∂κ a :=
integral_integral_add_comp hf hg
theorem integral_integral_sub_comp ⦃f g : γ → E⦄ (hf : Integrable f ((η ∘ₖ κ) a))
(hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, ∫ y, f y - g y ∂η x ∂κ a = ∫ x, ∫ y, f y ∂η x ∂κ a - ∫ x, ∫ y, g y ∂η x ∂κ a :=
(integral_fn_integral_sub_comp id hf hg).trans <| integral_sub hf.integral_comp hg.integral_comp
theorem integral_integral_sub'_comp ⦃f g : γ → E⦄ (hf : Integrable f ((η ∘ₖ κ) a))
(hg : Integrable g ((η ∘ₖ κ) a)) :
∫ x, ∫ y, (f - g) y ∂η x ∂κ a = ∫ x, ∫ y, f y ∂η x ∂κ a - ∫ x, ∫ y, g y ∂η x ∂κ a :=
integral_integral_sub_comp hf hg
theorem continuous_integral_integral_comp :
Continuous fun f : γ →₁[(η ∘ₖ κ) a] E ↦ ∫ x, ∫ y, f y ∂η x ∂κ a := by
refine continuous_iff_continuousAt.2 fun g ↦ ?_
refine tendsto_integral_of_L1 _ (L1.integrable_coeFn g).integral_comp
(Eventually.of_forall fun h ↦ (L1.integrable_coeFn h).integral_comp) ?_
simp_rw [← lintegral_fn_integral_sub_comp (‖·‖ₑ) (L1.integrable_coeFn _) (L1.integrable_coeFn g)]
refine tendsto_of_tendsto_of_tendsto_of_le_of_le
(h := fun i ↦ ∫⁻ x, ∫⁻ y, ‖i y - g y‖ₑ ∂η x ∂κ a)
tendsto_const_nhds ?_ (fun _ ↦ zero_le _) ?_
swap; · exact fun _ ↦ lintegral_mono fun _ ↦ enorm_integral_le_lintegral_enorm _
have (i : γ →₁[(η ∘ₖ κ) a] E) : Measurable fun z ↦ ‖i z - g z‖ₑ :=
((Lp.stronglyMeasurable i).sub (Lp.stronglyMeasurable g)).enorm
simp_rw [← lintegral_comp _ _ _ (this _), ← L1.ofReal_norm_sub_eq_lintegral, ← ofReal_zero]
exact (continuous_ofReal.tendsto 0).comp (tendsto_iff_norm_sub_tendsto_zero.1 tendsto_id)
theorem integral_comp : ∀ {f : γ → E} (_ : Integrable f ((η ∘ₖ κ) a)),
∫ z, f z ∂(η ∘ₖ κ) a = ∫ x, ∫ y, f y ∂η x ∂κ a := by
by_cases hE : CompleteSpace E; swap
· simp [integral, hE]
apply Integrable.induction
· intro c s hs ms
simp_rw [integral_indicator hs, MeasureTheory.setIntegral_const, integral_smul_const,
measureReal_def]
congr
rw [integral_toReal, Kernel.comp_apply' _ _ _ hs]
· exact (Kernel.measurable_coe _ hs).aemeasurable
· exact ae_lt_top_of_comp_ne_top a ms.ne
· rintro f g - i_f i_g hf hg
simp_rw [integral_add' i_f i_g, integral_integral_add'_comp i_f i_g, hf, hg]
· exact isClosed_eq continuous_integral Kernel.continuous_integral_integral_comp
· rintro f g hfg - hf
convert hf using 1
· exact integral_congr_ae hfg.symm
· apply integral_congr_ae
filter_upwards [ae_ae_of_ae_comp hfg] with x hfgx using integral_congr_ae (ae_eq_symm hfgx)
theorem setIntegral_comp {f : γ → E} {s : Set γ} (hs : MeasurableSet s)
(hf : IntegrableOn f s ((η ∘ₖ κ) a)) :
∫ z in s, f z ∂(η ∘ₖ κ) a = ∫ x, ∫ y in s, f y ∂η x ∂κ a := by
rw [← restrict_apply (η ∘ₖ κ) hs, ← comp_restrict hs, integral_comp]
· simp_rw [restrict_apply]
· rwa [comp_restrict, restrict_apply]
end Kernel
end comp
end ProbabilityTheory
namespace MeasureTheory
namespace Measure
variable {α β E : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
[NormedAddCommGroup E] {a : α} {κ : Kernel α β} {μ : Measure α} {f : β → E}
section Integral
lemma _root_.MeasureTheory.AEStronglyMeasurable.ae_of_compProd [SFinite μ] [IsSFiniteKernel κ]
{E : Type*} [NormedAddCommGroup E] {f : α → β → E}
(hf : AEStronglyMeasurable f.uncurry (μ ⊗ₘ κ)) :
∀ᵐ x ∂μ, AEStronglyMeasurable (f x) (κ x) := by
simpa using hf.compProd_mk_left
lemma integrable_compProd_iff [SFinite μ] [IsSFiniteKernel κ] {E : Type*} [NormedAddCommGroup E]
{f : α × β → E} (hf : AEStronglyMeasurable f (μ ⊗ₘ κ)) :
Integrable f (μ ⊗ₘ κ) ↔
(∀ᵐ x ∂μ, Integrable (fun y => f (x, y)) (κ x)) ∧
Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂(κ x)) μ := by
simp_rw [Measure.compProd, ProbabilityTheory.integrable_compProd_iff hf, Kernel.prodMkLeft_apply,
Kernel.const_apply]
lemma integral_compProd [SFinite μ] [IsSFiniteKernel κ] {E : Type*}
[NormedAddCommGroup E] [NormedSpace ℝ E]
{f : α × β → E} (hf : Integrable f (μ ⊗ₘ κ)) :
∫ x, f x ∂(μ ⊗ₘ κ) = ∫ a, ∫ b, f (a, b) ∂(κ a) ∂μ := by
rw [Measure.compProd, ProbabilityTheory.integral_compProd hf]
simp
lemma setIntegral_compProd [SFinite μ] [IsSFiniteKernel κ] {E : Type*}
[NormedAddCommGroup E] [NormedSpace ℝ E]
{s : Set α} (hs : MeasurableSet s) {t : Set β} (ht : MeasurableSet t)
{f : α × β → E} (hf : IntegrableOn f (s ×ˢ t) (μ ⊗ₘ κ)) :
∫ x in s ×ˢ t, f x ∂(μ ⊗ₘ κ) = ∫ a in s, ∫ b in t, f (a, b) ∂(κ a) ∂μ := by
rw [Measure.compProd, ProbabilityTheory.setIntegral_compProd hs ht hf]
simp
end Integral
section Integrable
lemma integrable_compProd_snd_iff [SFinite μ] [IsSFiniteKernel κ]
(hf : AEStronglyMeasurable f (κ ∘ₘ μ)) :
Integrable (fun p ↦ f p.2) (μ ⊗ₘ κ) ↔ Integrable f (κ ∘ₘ μ) := by
rw [← Measure.snd_compProd, Measure.snd, integrable_map_measure _ measurable_snd.aemeasurable,
Function.comp_def]
rwa [← Measure.snd, Measure.snd_compProd]
lemma ae_integrable_of_integrable_comp (h_int : Integrable f (κ ∘ₘ μ)) :
∀ᵐ x ∂μ, Integrable f (κ x) := by
rw [Measure.comp_eq_comp_const_apply, integrable_comp_iff h_int.1] at h_int
exact h_int.1
lemma integrable_integral_norm_of_integrable_comp (h_int : Integrable f (κ ∘ₘ μ)) :
Integrable (fun x ↦ ∫ y, ‖f y‖ ∂κ x) μ := by
rw [Measure.comp_eq_comp_const_apply, integrable_comp_iff h_int.1] at h_int
exact h_int.2
end Integrable
end Measure
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/AbsolutelyContinuous.lean | import Mathlib.Probability.Kernel.Composition.MeasureCompProd
import Mathlib.Probability.Kernel.RadonNikodym
/-!
# Absolute continuity of the composition of measures and kernels
This file contains some results about the absolute continuity of the composition of measures and
kernels which use an assumption `CountableOrCountablyGenerated α β` on the measurable spaces.
Results that hold without that assumption are in files about the definitions of compositions and
products, like `Mathlib/Probability/Kernel/Composition/MeasureCompProd.lean` and
`Mathlib/Probability/Kernel/Composition/MeasureComp.lean`.
The assumption ensures the measurability of the sets where two kernels are absolutely continuous
or mutually singular.
## Main statements
* `absolutelyContinuous_compProd_iff'`: `μ ⊗ₘ κ ≪ ν ⊗ₘ η ↔ μ ≪ ν ∧ ∀ᵐ a ∂μ, κ a ≪ η a`.
-/
open ProbabilityTheory Filter
open scoped ENNReal
namespace MeasureTheory.Measure
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{μ ν : Measure α} {κ η : Kernel α β} [IsFiniteKernel κ] [IsFiniteKernel η]
[MeasurableSpace.CountableOrCountablyGenerated α β]
lemma MutuallySingular.compProd_of_right (μ ν : Measure α) (hκη : ∀ᵐ a ∂μ, κ a ⟂ₘ η a) :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η := by
by_cases hμ : SFinite μ
swap; · rw [compProd_of_not_sfinite _ _ hμ]; simp
by_cases hν : SFinite ν
swap; · rw [compProd_of_not_sfinite _ _ hν]; simp
let s := κ.mutuallySingularSet η
have hs : MeasurableSet s := Kernel.measurableSet_mutuallySingularSet κ η
symm
refine ⟨s, hs, ?_⟩
rw [compProd_apply hs, compProd_apply hs.compl]
have h_eq a : Prod.mk a ⁻¹' s = Kernel.mutuallySingularSetSlice κ η a := rfl
have h1 a : η a (Prod.mk a ⁻¹' s) = 0 := by rw [h_eq, Kernel.measure_mutuallySingularSetSlice]
have h2 : ∀ᵐ a ∂μ, κ a (Prod.mk a ⁻¹' s)ᶜ = 0 := by
filter_upwards [hκη] with a ha
rwa [h_eq, ← Kernel.withDensity_rnDeriv_eq_zero_iff_measure_eq_zero κ η a,
Kernel.withDensity_rnDeriv_eq_zero_iff_mutuallySingular]
simp [h1, lintegral_congr_ae h2]
lemma MutuallySingular.compProd_of_right' (μ ν : Measure α) (hκη : ∀ᵐ a ∂ν, κ a ⟂ₘ η a) :
μ ⊗ₘ κ ⟂ₘ ν ⊗ₘ η := by
refine (MutuallySingular.compProd_of_right _ _ ?_).symm
simp_rw [MutuallySingular.comm, hκη]
lemma mutuallySingular_compProd_right_iff [SFinite μ] :
μ ⊗ₘ κ ⟂ₘ μ ⊗ₘ η ↔ ∀ᵐ a ∂μ, κ a ⟂ₘ η a :=
⟨fun h ↦ mutuallySingular_of_mutuallySingular_compProd h AbsolutelyContinuous.rfl
AbsolutelyContinuous.rfl, MutuallySingular.compProd_of_right _ _⟩
lemma AbsolutelyContinuous.kernel_of_compProd [SFinite μ] (h : μ ⊗ₘ κ ≪ ν ⊗ₘ η) :
∀ᵐ a ∂μ, κ a ≪ η a := by
suffices ∀ᵐ a ∂μ, κ.singularPart η a = 0 by
filter_upwards [this] with a ha
rwa [Kernel.singularPart_eq_zero_iff_absolutelyContinuous] at ha
rw [← κ.rnDeriv_add_singularPart η, compProd_add_right, AbsolutelyContinuous.add_left_iff] at h
have : μ ⊗ₘ κ.singularPart η ⟂ₘ ν ⊗ₘ η :=
MutuallySingular.compProd_of_right μ ν (.of_forall <| Kernel.mutuallySingular_singularPart _ _)
refine compProd_eq_zero_iff.mp ?_
exact eq_zero_of_absolutelyContinuous_of_mutuallySingular h.2 this
lemma absolutelyContinuous_compProd_iff' [SFinite μ] [SFinite ν] [∀ a, NeZero (κ a)] :
μ ⊗ₘ κ ≪ ν ⊗ₘ η ↔ μ ≪ ν ∧ ∀ᵐ a ∂μ, κ a ≪ η a :=
⟨fun h ↦ ⟨absolutelyContinuous_of_compProd h, h.kernel_of_compProd⟩, fun h ↦ h.1.compProd h.2⟩
lemma absolutelyContinuous_compProd_right_iff [SFinite μ] :
μ ⊗ₘ κ ≪ μ ⊗ₘ η ↔ ∀ᵐ a ∂μ, κ a ≪ η a :=
⟨AbsolutelyContinuous.kernel_of_compProd, AbsolutelyContinuous.compProd_right⟩
end MeasureTheory.Measure |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/KernelLemmas.lean | import Mathlib.Probability.Kernel.Composition.CompProd
import Mathlib.Probability.Kernel.Composition.Prod
/-!
# Lemmas relating different ways to compose kernels
This file contains lemmas about the composition of kernels that involve several types of
compositions/products.
## Main statements
* `comp_eq_snd_compProd`: `η ∘ₖ κ = snd (κ ⊗ₖ prodMkLeft X η)`
* `parallelComp_comp_parallelComp`: `(η ∥ₖ η') ∘ₖ (κ ∥ₖ κ') = (η ∘ₖ κ) ∥ₖ (η' ∘ₖ κ')`
* `deterministic_comp_copy`: for a deterministic kernel, copying then applying the kernel to
the two copies is the same as first applying the kernel then copying. That is, if `κ` is
a deterministic kernel, `(κ ∥ₖ κ) ∘ₖ copy X = copy Y ∘ₖ κ`.
-/
open MeasureTheory ProbabilityTheory
open scoped ENNReal
variable {X Y Z T : Type*} {mX : MeasurableSpace X} {mY : MeasurableSpace Y}
{mZ : MeasurableSpace Z} {mT : MeasurableSpace T}
{μ : Measure X} {ν : Measure Y} {κ : Kernel X Y} {η : Kernel Z T}
namespace ProbabilityTheory.Kernel
theorem comp_eq_snd_compProd (η : Kernel Y Z) [IsSFiniteKernel η] (κ : Kernel X Y)
[IsSFiniteKernel κ] : η ∘ₖ κ = snd (κ ⊗ₖ prodMkLeft X η) := by
ext a s hs
rw [comp_apply' _ _ _ hs, snd_apply' _ _ hs, compProd_apply (measurable_snd hs)]
simp [← Set.preimage_comp]
@[simp] lemma snd_compProd_prodMkLeft
(κ : Kernel X Y) (η : Kernel Y Z) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
snd (κ ⊗ₖ prodMkLeft X η) = η ∘ₖ κ := (comp_eq_snd_compProd η κ).symm
lemma compProd_prodMkLeft_eq_comp
(κ : Kernel X Y) [IsSFiniteKernel κ] (η : Kernel Y Z) [IsSFiniteKernel η] :
κ ⊗ₖ (prodMkLeft X η) = (Kernel.id ×ₖ η) ∘ₖ κ := by
ext a s hs
rw [comp_eq_snd_compProd, compProd_apply hs, snd_apply' _ _ hs, compProd_apply]
swap; · exact measurable_snd hs
simp only [prodMkLeft_apply, ← Set.preimage_comp, Prod.snd_comp_mk, Set.preimage_id_eq, id_eq,
prod_apply' _ _ _ hs, id_apply]
congr with b
rw [lintegral_dirac']
exact measurable_measure_prodMk_left hs
lemma swap_parallelComp : swap Y T ∘ₖ (κ ∥ₖ η) = η ∥ₖ κ ∘ₖ swap X Z := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
by_cases hη : IsSFiniteKernel η
swap; · simp [hη]
ext ac s hs
simp_rw [comp_apply, parallelComp_apply, Measure.bind_apply hs (Kernel.aemeasurable _),
swap_apply, lintegral_dirac' _ (Kernel.measurable_coe _ hs), parallelComp_apply' hs,
Prod.fst_swap, Prod.snd_swap]
rw [MeasureTheory.lintegral_prod_symm]
swap; · exact ((Kernel.id.measurable_coe hs).comp measurable_swap).aemeasurable
congr with d
simp_rw [Prod.swap_prod_mk, Measure.dirac_apply' _ hs, ← Set.indicator_comp_right,
lintegral_indicator (measurable_prodMk_left hs)]
simp
/-- For a deterministic kernel, copying then applying the kernel to the two copies is the same
as first applying the kernel then copying. -/
lemma deterministic_comp_copy {f : X → Y} (hf : Measurable f) :
(deterministic f hf ∥ₖ deterministic f hf) ∘ₖ copy X = copy Y ∘ₖ deterministic f hf := by
simp_rw [parallelComp_comp_copy, deterministic_prod_deterministic, copy,
deterministic_comp_deterministic, Function.comp_def]
section ParallelComp
variable {X' Y' Z' : Type*} {mX' : MeasurableSpace X'} {mY' : MeasurableSpace Y'}
{mZ' : MeasurableSpace Z'}
lemma parallelComp_id_left_comp_parallelComp
{η : Kernel X' Z} [IsSFiniteKernel η] {ξ : Kernel Z T} [IsSFiniteKernel ξ] :
(Kernel.id ∥ₖ ξ) ∘ₖ (κ ∥ₖ η) = κ ∥ₖ (ξ ∘ₖ η) := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
ext a s hs
rw [comp_apply' _ _ _ hs, parallelComp_apply,
MeasureTheory.lintegral_prod _ (Kernel.measurable_coe _ hs).aemeasurable]
rw [parallelComp_apply, Measure.prod_apply hs]
congr with x
rw [comp_apply' _ _ _ (measurable_prodMk_left hs)]
congr with y
rw [parallelComp_apply' hs, Kernel.id_apply,
lintegral_dirac' _ (measurable_measure_prodMk_left hs)]
lemma parallelComp_id_right_comp_parallelComp {η : Kernel X' Z} [IsSFiniteKernel η]
{ξ : Kernel Z T} [IsSFiniteKernel ξ] :
(ξ ∥ₖ Kernel.id) ∘ₖ (η ∥ₖ κ) = (ξ ∘ₖ η) ∥ₖ κ := by
suffices swap T Y ∘ₖ (ξ ∥ₖ Kernel.id) ∘ₖ (η ∥ₖ κ) = swap T Y ∘ₖ ((ξ ∘ₖ η) ∥ₖ κ) by
calc ξ ∥ₖ Kernel.id ∘ₖ (η ∥ₖ κ)
_ = swap Y T ∘ₖ (swap T Y ∘ₖ (ξ ∥ₖ Kernel.id) ∘ₖ (η ∥ₖ κ)) := by
simp_rw [← comp_assoc, swap_swap, id_comp]
_ = swap Y T ∘ₖ (swap T Y ∘ₖ ((ξ ∘ₖ η) ∥ₖ κ)) := by rw [this]
_ = ξ ∘ₖ η ∥ₖ κ := by simp_rw [← comp_assoc, swap_swap, id_comp]
simp_rw [swap_parallelComp, comp_assoc, swap_parallelComp, ← comp_assoc,
parallelComp_id_left_comp_parallelComp]
lemma parallelComp_comp_parallelComp [IsSFiniteKernel κ] {η : Kernel Y Z} [IsSFiniteKernel η]
{κ' : Kernel X' Y'} [IsSFiniteKernel κ'] {η' : Kernel Y' Z'} [IsSFiniteKernel η'] :
(η ∥ₖ η') ∘ₖ (κ ∥ₖ κ') = (η ∘ₖ κ) ∥ₖ (η' ∘ₖ κ') := by
rw [← parallelComp_id_left_comp_parallelComp, ← parallelComp_id_right_comp_parallelComp,
← comp_assoc, parallelComp_id_left_comp_parallelComp, comp_id]
lemma parallelComp_comp_prod [IsSFiniteKernel κ] {η : Kernel Y Z} [IsSFiniteKernel η]
{κ' : Kernel X Y'} [IsSFiniteKernel κ'] {η' : Kernel Y' Z'} [IsSFiniteKernel η'] :
(η ∥ₖ η') ∘ₖ (κ ×ₖ κ') = (η ∘ₖ κ) ×ₖ (η' ∘ₖ κ') := by
rw [← parallelComp_comp_copy, ← comp_assoc, parallelComp_comp_parallelComp,
← parallelComp_comp_copy]
lemma parallelComp_comm {η : Kernel Z T} :
(Kernel.id ∥ₖ κ) ∘ₖ (η ∥ₖ Kernel.id) = (η ∥ₖ Kernel.id) ∘ₖ (Kernel.id ∥ₖ κ) := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
by_cases hη : IsSFiniteKernel η
swap; · simp [hη]
rw [parallelComp_id_left_comp_parallelComp, parallelComp_id_right_comp_parallelComp,
comp_id, comp_id]
end ParallelComp
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/ParallelComp.lean | import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Probability.Kernel.Composition.MapComap
import Mathlib.Probability.Kernel.MeasurableLIntegral
/-!
# Parallel composition of kernels
Two kernels `κ : Kernel α β` and `η : Kernel γ δ` can be applied in parallel to give a kernel
`κ ∥ₖ η` from `α × γ` to `β × δ`: `(κ ∥ₖ η) (a, c) = (κ a).prod (η c)`.
## Main definitions
* `parallelComp (κ : Kernel α β) (η : Kernel γ δ) : Kernel (α × γ) (β × δ)`: parallel composition
of two s-finite kernels. We define a notation `κ ∥ₖ η = parallelComp κ η`.
`∫⁻ bd, g bd ∂(κ ∥ₖ η) ac = ∫⁻ b, ∫⁻ d, g (b, d) ∂η ac.2 ∂κ ac.1`
## Notation
* `κ ∥ₖ η = ProbabilityTheory.Kernel.parallelComp κ η`
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory.Kernel
variable {α β γ δ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ}
{κ : Kernel α β} {η : Kernel γ δ} {x : α × γ}
open Classical in
/-- Parallel product of two kernels. -/
noncomputable
irreducible_def parallelComp (κ : Kernel α β) (η : Kernel γ δ) : Kernel (α × γ) (β × δ) :=
if h : IsSFiniteKernel κ ∧ IsSFiniteKernel η then
{ toFun := fun x ↦ (κ x.1).prod (η x.2)
measurable' := by
have hκ := h.1
have hη := h.2
refine Measure.measurable_of_measurable_coe _ fun s hs ↦ ?_
simp_rw [Measure.prod_apply hs]
refine Measurable.lintegral_kernel_prod_right'
(f := fun y ↦ prodMkLeft α η y.1 (Prod.mk y.2 ⁻¹' s)) (κ := prodMkRight γ κ) ?_
have : (fun y ↦ prodMkLeft α η y.1 (Prod.mk y.2 ⁻¹' s))
= fun y ↦ prodMkRight β (prodMkLeft α η) y (Prod.mk y.2 ⁻¹' s) := rfl
rw [this]
exact measurable_kernel_prodMk_left (measurable_fst.snd.prodMk measurable_snd hs) }
else 0
@[inherit_doc]
scoped[ProbabilityTheory] infixl:100 " ∥ₖ " => ProbabilityTheory.Kernel.parallelComp
@[simp]
lemma parallelComp_of_not_isSFiniteKernel_left (η : Kernel γ δ) (h : ¬ IsSFiniteKernel κ) :
κ ∥ₖ η = 0 := by
rw [parallelComp, dif_neg (not_and_of_not_left _ h)]
@[simp]
lemma parallelComp_of_not_isSFiniteKernel_right (κ : Kernel α β) (h : ¬ IsSFiniteKernel η) :
κ ∥ₖ η = 0 := by
rw [parallelComp, dif_neg (not_and_of_not_right _ h)]
lemma parallelComp_apply (κ : Kernel α β) [IsSFiniteKernel κ]
(η : Kernel γ δ) [IsSFiniteKernel η] (x : α × γ) :
(κ ∥ₖ η) x = (κ x.1).prod (η x.2) := by
rw [parallelComp, dif_pos ⟨inferInstance, inferInstance⟩, coe_mk]
lemma parallelComp_apply' [IsSFiniteKernel κ] [IsSFiniteKernel η]
{s : Set (β × δ)} (hs : MeasurableSet s) :
(κ ∥ₖ η) x s = ∫⁻ b, η x.2 (Prod.mk b ⁻¹' s) ∂κ x.1 := by
rw [parallelComp_apply, Measure.prod_apply hs]
lemma parallelComp_apply_prod [IsSFiniteKernel κ] [IsSFiniteKernel η] (s : Set β) (t : Set δ) :
(κ ∥ₖ η) x (s ×ˢ t) = (κ x.1 s) * (η x.2 t) := by
rw [parallelComp_apply, Measure.prod_prod]
@[simp]
lemma parallelComp_apply_univ [IsSFiniteKernel κ] [IsSFiniteKernel η] :
(κ ∥ₖ η) x Set.univ = κ x.1 Set.univ * η x.2 Set.univ := by
rw [parallelComp_apply, Measure.prod_apply .univ, mul_comm]
simp
@[simp]
lemma parallelComp_zero_left (η : Kernel γ δ) : (0 : Kernel α β) ∥ₖ η = 0 := by
by_cases h : IsSFiniteKernel η
· ext; simp [parallelComp_apply]
· exact parallelComp_of_not_isSFiniteKernel_right _ h
@[simp]
lemma parallelComp_zero_right (κ : Kernel α β) : κ ∥ₖ (0 : Kernel γ δ) = 0 := by
by_cases h : IsSFiniteKernel κ
· ext; simp [parallelComp_apply]
· exact parallelComp_of_not_isSFiniteKernel_left _ h
lemma deterministic_parallelComp_deterministic
{f : α → γ} {g : β → δ} (hf : Measurable f) (hg : Measurable g) :
(deterministic f hf) ∥ₖ (deterministic g hg)
= deterministic (Prod.map f g) (hf.prodMap hg) := by
ext x : 1
simp_rw [parallelComp_apply, deterministic_apply, Prod.map, Measure.dirac_prod_dirac]
lemma lintegral_parallelComp [IsSFiniteKernel κ] [IsSFiniteKernel η]
(ac : α × γ) {g : β × δ → ℝ≥0∞} (hg : Measurable g) :
∫⁻ bd, g bd ∂(κ ∥ₖ η) ac = ∫⁻ b, ∫⁻ d, g (b, d) ∂η ac.2 ∂κ ac.1 := by
rw [parallelComp_apply, MeasureTheory.lintegral_prod _ hg.aemeasurable]
lemma lintegral_parallelComp_symm [IsSFiniteKernel κ] [IsSFiniteKernel η]
(ac : α × γ) {g : β × δ → ℝ≥0∞} (hg : Measurable g) :
∫⁻ bd, g bd ∂(κ ∥ₖ η) ac = ∫⁻ d, ∫⁻ b, g (b, d) ∂κ ac.1 ∂η ac.2 := by
rw [parallelComp_apply, MeasureTheory.lintegral_prod_symm _ hg.aemeasurable]
lemma parallelComp_sum_left {ι : Type*} [Countable ι] (κ : ι → Kernel α β)
[∀ i, IsSFiniteKernel (κ i)] (η : Kernel γ δ) :
Kernel.sum κ ∥ₖ η = Kernel.sum fun i ↦ κ i ∥ₖ η := by
by_cases h : IsSFiniteKernel η
swap; · simp [h]
ext x
simp_rw [Kernel.sum_apply, parallelComp_apply, Kernel.sum_apply, Measure.prod_sum_left]
lemma parallelComp_sum_right {ι : Type*} [Countable ι] (κ : Kernel α β)
(η : ι → Kernel γ δ) [∀ i, IsSFiniteKernel (η i)] :
κ ∥ₖ Kernel.sum η = Kernel.sum fun i ↦ κ ∥ₖ η i := by
by_cases h : IsSFiniteKernel κ
swap; · simp [h]
ext x
simp_rw [Kernel.sum_apply, parallelComp_apply, Kernel.sum_apply, Measure.prod_sum_right]
instance [IsMarkovKernel κ] [IsMarkovKernel η] : IsMarkovKernel (κ ∥ₖ η) :=
⟨fun x ↦ ⟨by simp [parallelComp_apply_univ]⟩⟩
instance [IsZeroOrMarkovKernel κ] [IsZeroOrMarkovKernel η] : IsZeroOrMarkovKernel (κ ∥ₖ η) := by
obtain rfl | _ := eq_zero_or_isMarkovKernel κ <;> obtain rfl | _ := eq_zero_or_isMarkovKernel η
all_goals simpa using by infer_instance
instance [IsFiniteKernel κ] [IsFiniteKernel η] : IsFiniteKernel (κ ∥ₖ η) := by
refine ⟨⟨κ.bound * η.bound, ENNReal.mul_lt_top κ.bound_lt_top η.bound_lt_top, fun a ↦ ?_⟩⟩
calc (κ ∥ₖ η) a Set.univ
_ = κ a.1 Set.univ * η a.2 Set.univ := parallelComp_apply_univ
_ ≤ κ.bound * η.bound := by
gcongr
· exact measure_le_bound κ a.1 Set.univ
· exact measure_le_bound η a.2 Set.univ
instance : IsSFiniteKernel (κ ∥ₖ η) := by
by_cases h : IsSFiniteKernel κ
swap
· simp only [h, not_false_eq_true, parallelComp_of_not_isSFiniteKernel_left]
infer_instance
by_cases h : IsSFiniteKernel η
swap
· simp only [h, not_false_eq_true, parallelComp_of_not_isSFiniteKernel_right]
infer_instance
simp_rw [← kernel_sum_seq κ, ← kernel_sum_seq η, parallelComp_sum_left, parallelComp_sum_right]
infer_instance
end ProbabilityTheory.Kernel |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/CompNotation.lean | import Mathlib.Probability.Kernel.Basic
/-!
# Notation for the composition of a measure and a kernel
This operation, for which we introduce the notation `∘ₘ`, takes `μ : Measure α` and
`κ : Kernel α β` and creates `κ ∘ₘ μ : Measure β`. The integral of a function against `κ ∘ₘ μ` is
`∫⁻ x, f x ∂(κ ∘ₘ μ) = ∫⁻ a, ∫⁻ b, f b ∂(κ a) ∂μ`.
This file does not define composition but only introduces notation for
`MeasureTheory.Measure.bind μ κ`.
## Notation
* `κ ∘ₘ μ = MeasureTheory.Measure.bind μ κ`, for `κ` a kernel.
-/
/- This file is only for lemmas that are direct specializations of `Measure.bind` to kernels,
anything more involved should go elsewhere (for example the `MeasureComp` file). -/
assert_not_exists ProbabilityTheory.Kernel.compProd
open ProbabilityTheory
namespace MeasureTheory.Measure
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{μ : Measure α} {κ : Kernel α β}
/-- Composition of a measure and a kernel.
Notation for `MeasureTheory.Measure.bind` -/
scoped[ProbabilityTheory] notation:100 κ:101 " ∘ₘ " μ:100 => MeasureTheory.Measure.bind μ κ
@[simp]
lemma comp_apply_univ [IsMarkovKernel κ] : (κ ∘ₘ μ) Set.univ = μ Set.univ := by
simp [bind_apply .univ κ.aemeasurable]
lemma deterministic_comp_eq_map {f : α → β} (hf : Measurable f) :
Kernel.deterministic f hf ∘ₘ μ = μ.map f :=
Measure.bind_dirac_eq_map μ hf
@[simp]
lemma id_comp : Kernel.id ∘ₘ μ = μ := by rw [Kernel.id, deterministic_comp_eq_map, Measure.map_id]
lemma swap_comp {μ : Measure (α × β)} : (Kernel.swap α β) ∘ₘ μ = μ.map Prod.swap :=
deterministic_comp_eq_map measurable_swap
@[simp]
lemma const_comp {ν : Measure β} : (Kernel.const α ν) ∘ₘ μ = μ Set.univ • ν := μ.bind_const
end MeasureTheory.Measure |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/CompProd.lean | import Mathlib.Probability.Kernel.Composition.Comp
import Mathlib.Probability.Kernel.Composition.ParallelComp
/-!
# Composition-product of kernels
We define the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : Kernel α β` and
`η : Kernel (α × β) γ`, a kernel from `α` to `β × γ`.
A note on names:
The composition-product `Kernel α β → Kernel (α × β) γ → Kernel α (β × γ)` is named composition in
[kallenberg2021] and product on the wikipedia article on transition kernels.
Most papers studying categories of kernels call composition the map we call composition. We adopt
that convention because it fits better with the use of the name `comp` elsewhere in mathlib.
## Main definitions
* `compProd (κ : Kernel α β) (η : Kernel (α × β) γ) : Kernel α (β × γ)`: composition-product of 2
s-finite kernels. We define a notation `κ ⊗ₖ η = compProd κ η`.
`∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`
## Main statements
* `lintegral_compProd`: Lebesgue integral of a function against a composition-product of kernels.
* Instances stating that `IsMarkovKernel`, `IsZeroOrMarkovKernel`, `IsFiniteKernel` and
`IsSFiniteKernel` are stable by composition-product.
## Notation
* `κ ⊗ₖ η = ProbabilityTheory.Kernel.compProd κ η`
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
section CompositionProduct
/-!
### Composition-Product of kernels
We define a kernel composition-product
`compProd : Kernel α β → Kernel (α × β) γ → Kernel α (β × γ)`.
-/
variable {s : Set (β × γ)}
/-- Composition-Product of kernels. For s-finite kernels, it satisfies
`∫⁻ bc, f bc ∂(compProd κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`
(see `ProbabilityTheory.Kernel.lintegral_compProd`).
If either of the kernels is not s-finite, `compProd` is given the junk value 0. -/
noncomputable irreducible_def compProd (κ : Kernel α β) (η : Kernel (α × β) γ) : Kernel α (β × γ) :=
swap γ β ∘ₖ (η ∥ₖ Kernel.id)
∘ₖ deterministic MeasurableEquiv.prodAssoc.symm (MeasurableEquiv.measurable _)
∘ₖ (Kernel.id ∥ₖ copy β) ∘ₖ (Kernel.id ∥ₖ κ) ∘ₖ copy α
@[inherit_doc]
scoped[ProbabilityTheory] infixl:100 " ⊗ₖ " => ProbabilityTheory.Kernel.compProd
@[simp]
theorem compProd_of_not_isSFiniteKernel_left (κ : Kernel α β) (η : Kernel (α × β) γ)
(h : ¬ IsSFiniteKernel κ) :
κ ⊗ₖ η = 0 := by
simp [compProd, h]
@[simp]
theorem compProd_of_not_isSFiniteKernel_right (κ : Kernel α β) (η : Kernel (α × β) γ)
(h : ¬ IsSFiniteKernel η) :
κ ⊗ₖ η = 0 := by
simp [compProd, h]
theorem compProd_apply (hs : MeasurableSet s) (κ : Kernel α β) [IsSFiniteKernel κ]
(η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) :
(κ ⊗ₖ η) a s = ∫⁻ b, η (a, b) (Prod.mk b ⁻¹' s) ∂κ a := by
rw [compProd, comp_apply, copy_apply, Measure.dirac_bind (by fun_prop), comp_apply,
parallelComp_apply, Kernel.id_apply, Measure.bind_apply hs (by fun_prop),
lintegral_prod _ (Kernel.measurable_coe _ hs).aemeasurable, lintegral_dirac']
swap
· suffices Measurable fun p : α × β ↦
(swap γ β ∘ₖ (η ∥ₖ Kernel.id)
∘ₖ deterministic MeasurableEquiv.prodAssoc.symm (MeasurableEquiv.measurable _)
∘ₖ (Kernel.id ∥ₖ copy β)) p s by fun_prop
exact Kernel.measurable_coe _ hs
congr with b
rw [comp_apply, parallelComp_apply, Kernel.id_apply, copy_apply, Measure.dirac_prod_dirac,
Measure.dirac_bind (by fun_prop), comp_apply, deterministic_apply (by fun_prop),
Measure.dirac_bind (by fun_prop), comp_apply]
simp only [MeasurableEquiv.prodAssoc, MeasurableEquiv.symm_mk, MeasurableEquiv.coe_mk,
Equiv.prodAssoc_symm_apply]
rw [parallelComp_apply, Kernel.id_apply, Measure.bind_apply hs (by fun_prop),
lintegral_prod _ (Kernel.measurable_coe _ hs).aemeasurable]
classical
have h_int x : ∫⁻ y, swap γ β (x, y) s ∂Measure.dirac b = (Prod.mk b ⁻¹' s).indicator 1 x := by
rw [lintegral_dirac']
· simp [swap_apply' _ hs, Set.indicator_apply]
· simpa [swap_apply' _ hs, Prod.swap_prod_mk] using
measurable_const.indicator (measurable_prodMk_right hs)
simp_rw [h_int]
rw [lintegral_indicator_one]
exact measurable_prodMk_left hs
theorem le_compProd_apply (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (s : Set (β × γ)) :
∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤ (κ ⊗ₖ η) a s :=
calc
∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤
∫⁻ b, η (a, b) {c | (b, c) ∈ toMeasurable ((κ ⊗ₖ η) a) s} ∂κ a :=
lintegral_mono fun _ => measure_mono fun _ h_mem => subset_toMeasurable _ _ h_mem
_ = (κ ⊗ₖ η) a (toMeasurable ((κ ⊗ₖ η) a) s) :=
(compProd_apply (measurableSet_toMeasurable _ _) κ η a).symm
_ = (κ ⊗ₖ η) a s := measure_toMeasurable s
@[simp]
lemma compProd_apply_univ {κ : Kernel α β} {η : Kernel (α × β) γ}
[IsSFiniteKernel κ] [IsMarkovKernel η] {a : α} :
(κ ⊗ₖ η) a Set.univ = κ a Set.univ := by
rw [compProd_apply MeasurableSet.univ]
simp
lemma compProd_apply_prod {κ : Kernel α β} {η : Kernel (α × β) γ}
[IsSFiniteKernel κ] [IsSFiniteKernel η] {a : α}
{s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) :
(κ ⊗ₖ η) a (s ×ˢ t) = ∫⁻ b in s, η (a, b) t ∂(κ a) := by
rw [compProd_apply (hs.prod ht), ← lintegral_indicator hs]
congr with a
by_cases ha : a ∈ s <;> simp [ha]
lemma compProd_congr {κ : Kernel α β} {η η' : Kernel (α × β) γ}
[IsSFiniteKernel η] [IsSFiniteKernel η'] (h : ∀ a, ∀ᵐ b ∂(κ a), η (a, b) = η' (a, b)) :
κ ⊗ₖ η = κ ⊗ₖ η' := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp_rw [compProd_of_not_isSFiniteKernel_left _ _ hκ]
ext a s hs
rw [compProd_apply hs, compProd_apply hs]
refine lintegral_congr_ae ?_
filter_upwards [h a] with b hb using by rw [hb]
@[simp]
lemma compProd_zero_left (κ : Kernel (α × β) γ) :
(0 : Kernel α β) ⊗ₖ κ = 0 := by
by_cases h : IsSFiniteKernel κ
· ext a s hs
rw [Kernel.compProd_apply hs]
simp
· rw [Kernel.compProd_of_not_isSFiniteKernel_right _ _ h]
@[simp]
lemma compProd_zero_right (κ : Kernel α β) (γ : Type*) {mγ : MeasurableSpace γ} :
κ ⊗ₖ (0 : Kernel (α × β) γ) = 0 := by
by_cases h : IsSFiniteKernel κ
· ext a s hs
rw [Kernel.compProd_apply hs]
simp
· rw [Kernel.compProd_of_not_isSFiniteKernel_left _ _ h]
lemma compProd_eq_zero_iff {κ : Kernel α β} {η : Kernel (α × β) γ}
[IsSFiniteKernel κ] [IsSFiniteKernel η] :
κ ⊗ₖ η = 0 ↔ ∀ a, ∀ᵐ b ∂(κ a), η (a, b) = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp_rw [← Measure.measure_univ_eq_zero]
refine fun a ↦ (lintegral_eq_zero_iff ?_).mp ?_
· exact (η.measurable_coe .univ).comp measurable_prodMk_left
· rw [← setLIntegral_univ, ← Kernel.compProd_apply_prod .univ .univ, h]
simp
· rw [← Kernel.compProd_zero_right κ]
exact Kernel.compProd_congr h
lemma compProd_preimage_fst {s : Set β} (hs : MeasurableSet s) (κ : Kernel α β)
(η : Kernel (α × β) γ) [IsSFiniteKernel κ] [IsMarkovKernel η] (x : α) :
(κ ⊗ₖ η) x (Prod.fst ⁻¹' s) = κ x s := by
classical
simp_rw [compProd_apply (measurable_fst hs), ← Set.preimage_comp, Prod.fst_comp_mk, Set.preimage,
Function.const_apply]
have : ∀ b : β, η (x, b) {_c | b ∈ s} = s.indicator (fun _ ↦ 1) b := by
intro b
by_cases hb : b ∈ s <;> simp [hb]
simp_rw [this]
rw [lintegral_indicator_const hs, one_mul]
lemma compProd_deterministic_apply [MeasurableSingletonClass γ] {f : α × β → γ} (hf : Measurable f)
{s : Set (β × γ)} (hs : MeasurableSet s) (κ : Kernel α β) [IsSFiniteKernel κ] (x : α) :
(κ ⊗ₖ deterministic f hf) x s = κ x {b | (b, f (x, b)) ∈ s} := by
classical
simp only [deterministic_apply, Measure.dirac_apply,
Set.indicator_apply, Pi.one_apply, compProd_apply hs]
let t := {b | (b, f (x, b)) ∈ s}
have ht : MeasurableSet t := (measurable_id.prodMk (hf.comp measurable_prodMk_left)) hs
rw [← lintegral_add_compl _ ht]
convert add_zero _
· suffices ∀ b ∈ tᶜ, (if f (x, b) ∈ Prod.mk b ⁻¹' s then (1 : ℝ≥0∞) else 0) = 0 by
rw [setLIntegral_congr_fun ht.compl this, lintegral_zero]
intro b hb
simp only [t, Set.mem_compl_iff, Set.mem_setOf_eq] at hb
simp [hb]
· suffices ∀ b ∈ t, (if f (x, b) ∈ Prod.mk b ⁻¹' s then (1 : ℝ≥0∞) else 0) = 1 by
rw [setLIntegral_congr_fun ht this, setLIntegral_one]
intro b hb
simp only [t, Set.mem_setOf_eq] at hb
simp [hb]
section Ae
/-! ### `ae` filter of the composition-product -/
variable {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η] {a : α}
theorem ae_kernel_lt_top (a : α) (h2s : (κ ⊗ₖ η) a s ≠ ∞) :
∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' s) < ∞ := by
let t := toMeasurable ((κ ⊗ₖ η) a) s
have : ∀ b : β, η (a, b) (Prod.mk b ⁻¹' s) ≤ η (a, b) (Prod.mk b ⁻¹' t) := fun b =>
measure_mono (Set.preimage_mono (subset_toMeasurable _ _))
have ht : MeasurableSet t := measurableSet_toMeasurable _ _
have h2t : (κ ⊗ₖ η) a t ≠ ∞ := by rwa [measure_toMeasurable]
have ht_lt_top : ∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' t) < ∞ := by
rw [Kernel.compProd_apply ht] at h2t
exact ae_lt_top (Kernel.measurable_kernel_prodMk_left' ht a) h2t
filter_upwards [ht_lt_top] with b hb
exact (this b).trans_lt hb
theorem compProd_null (a : α) (hs : MeasurableSet s) :
(κ ⊗ₖ η) a s = 0 ↔ (fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by
rw [Kernel.compProd_apply hs, lintegral_eq_zero_iff]
exact Kernel.measurable_kernel_prodMk_left' hs a
theorem ae_null_of_compProd_null (h : (κ ⊗ₖ η) a s = 0) :
(fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by
obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h
simp_rw [compProd_null a mt] at ht
rw [Filter.eventuallyLE_antisymm_iff]
exact
⟨Filter.EventuallyLE.trans_eq
(Filter.Eventually.of_forall fun x => measure_mono (Set.preimage_mono hst)) ht,
Filter.Eventually.of_forall fun x => zero_le _⟩
theorem ae_ae_of_ae_compProd {p : β × γ → Prop} (h : ∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) :
∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) :=
ae_null_of_compProd_null h
lemma ae_compProd_of_ae_ae {κ : Kernel α β} {η : Kernel (α × β) γ}
{p : β × γ → Prop} (hp : MeasurableSet {x | p x})
(h : ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c)) :
∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [compProd_of_not_isSFiniteKernel_left _ _ hκ]
by_cases hη : IsSFiniteKernel η
swap; · simp [compProd_of_not_isSFiniteKernel_right _ _ hη]
simp_rw [ae_iff] at h ⊢
rw [compProd_null]
· exact h
· exact hp.compl
lemma ae_compProd_iff {p : β × γ → Prop} (hp : MeasurableSet {x | p x}) :
(∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) ↔ ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) :=
⟨fun h ↦ ae_ae_of_ae_compProd h, fun h ↦ ae_compProd_of_ae_ae hp h⟩
end Ae
section Restrict
variable {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η]
theorem compProd_restrict {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) :
Kernel.restrict κ hs ⊗ₖ Kernel.restrict η ht = Kernel.restrict (κ ⊗ₖ η) (hs.prod ht) := by
ext a u hu
rw [compProd_apply hu, restrict_apply' _ _ _ hu, compProd_apply (hu.inter (hs.prod ht))]
simp only [restrict_apply, Set.preimage, Measure.restrict_apply' ht, Set.mem_inter_iff,
Set.mem_prod]
have (b : _) : η (a, b) {c : γ | (b, c) ∈ u ∧ b ∈ s ∧ c ∈ t} =
s.indicator (fun b => η (a, b) ({c : γ | (b, c) ∈ u} ∩ t)) b := by
classical
rw [Set.indicator_apply]
split_ifs with h
· simp only [h, true_and, Set.inter_def, Set.mem_setOf]
· simp only [h, false_and, and_false, Set.setOf_false, measure_empty]
simp_rw [this]
rw [lintegral_indicator hs]
theorem compProd_restrict_left {s : Set β} (hs : MeasurableSet s) :
Kernel.restrict κ hs ⊗ₖ η = Kernel.restrict (κ ⊗ₖ η) (hs.prod MeasurableSet.univ) := by
rw [← compProd_restrict hs MeasurableSet.univ]
congr; exact Kernel.restrict_univ.symm
theorem compProd_restrict_right {t : Set γ} (ht : MeasurableSet t) :
κ ⊗ₖ Kernel.restrict η ht = Kernel.restrict (κ ⊗ₖ η) (MeasurableSet.univ.prod ht) := by
rw [← compProd_restrict MeasurableSet.univ ht]
congr; exact Kernel.restrict_univ.symm
end Restrict
section Lintegral
/-! ### Lebesgue integral -/
/-- Lebesgue integral against the composition-product of two kernels. -/
theorem lintegral_compProd' (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β → γ → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) :
∫⁻ bc, f bc.1 bc.2 ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f b c ∂η (a, b) ∂κ a := by
let F : ℕ → SimpleFunc (β × γ) ℝ≥0∞ := SimpleFunc.eapprox (Function.uncurry f)
have h : ∀ a, ⨆ n, F n a = Function.uncurry f a := SimpleFunc.iSup_eapprox_apply hf
simp only [Prod.forall, Function.uncurry_apply_pair] at h
simp_rw [← h]
have h_mono : Monotone F := fun i j hij b =>
SimpleFunc.monotone_eapprox (Function.uncurry f) hij _
rw [lintegral_iSup (fun n => (F n).measurable) h_mono]
have : ∀ b, ∫⁻ c, ⨆ n, F n (b, c) ∂η (a, b) = ⨆ n, ∫⁻ c, F n (b, c) ∂η (a, b) := by
intro a
rw [lintegral_iSup]
· exact fun n => (F n).measurable.comp measurable_prodMk_left
· exact fun i j hij b => h_mono hij _
simp_rw [this]
have h_some_meas_integral :
∀ f' : SimpleFunc (β × γ) ℝ≥0∞, Measurable fun b => ∫⁻ c, f' (b, c) ∂η (a, b) := by
intro f'
have :
(fun b => ∫⁻ c, f' (b, c) ∂η (a, b)) =
(fun ab => ∫⁻ c, f' (ab.2, c) ∂η ab) ∘ fun b => (a, b) := by
ext1 ab; rfl
rw [this]
fun_prop
rw [lintegral_iSup]
rotate_left
· exact fun n => h_some_meas_integral (F n)
· exact fun i j hij b => lintegral_mono fun c => h_mono hij _
congr
ext1 n
refine SimpleFunc.induction ?_ ?_ (F n)
· intro c s hs
simp +unfoldPartialApp only [SimpleFunc.const_zero,
SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero,
Set.piecewise_eq_indicator, Function.const, lintegral_indicator_const hs]
rw [compProd_apply hs, ← lintegral_const_mul c _]
swap
· exact (measurable_kernel_prodMk_left ((measurable_fst.snd.prodMk measurable_snd) hs)).comp
measurable_prodMk_left
congr
ext1 b
rw [lintegral_indicator_const_comp measurable_prodMk_left hs]
· intro f f' _ hf_eq hf'_eq
simp_rw [SimpleFunc.coe_add, Pi.add_apply]
change
∫⁻ x, (f : β × γ → ℝ≥0∞) x + f' x ∂(κ ⊗ₖ η) a =
∫⁻ b, ∫⁻ c : γ, f (b, c) + f' (b, c) ∂η (a, b) ∂κ a
rw [lintegral_add_left (SimpleFunc.measurable _), hf_eq, hf'_eq, ← lintegral_add_left]
swap
· exact h_some_meas_integral f
congr with b
rw [lintegral_add_left]
exact (SimpleFunc.measurable _).comp measurable_prodMk_left
/-- Lebesgue integral against the composition-product of two kernels. -/
theorem lintegral_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) :
∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f (b, c) ∂η (a, b) ∂κ a := by
let g := Function.curry f
change ∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, g b c ∂η (a, b) ∂κ a
rw [← lintegral_compProd']
· simp_rw [g, Function.curry_apply]
· simp_rw [g, Function.uncurry_curry]; exact hf
/-- Lebesgue integral against the composition-product of two kernels. -/
theorem lintegral_compProd₀ (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : AEMeasurable f ((κ ⊗ₖ η) a)) :
∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by
have A : ∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ z, hf.mk f z ∂(κ ⊗ₖ η) a := lintegral_congr_ae hf.ae_eq_mk
have B : ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a = ∫⁻ x, ∫⁻ y, hf.mk f (x, y) ∂η (a, x) ∂κ a := by
apply lintegral_congr_ae
filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with _ ha using lintegral_congr_ae ha
rw [A, B, lintegral_compProd]
exact hf.measurable_mk
theorem setLIntegral_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {s : Set β} {t : Set γ}
(hs : MeasurableSet s) (ht : MeasurableSet t) :
∫⁻ z in s ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by
simp_rw [← Kernel.restrict_apply (κ ⊗ₖ η) (hs.prod ht), ← compProd_restrict hs ht,
lintegral_compProd _ _ _ hf, Kernel.restrict_apply]
theorem setLIntegral_compProd_univ_right (κ : Kernel α β) [IsSFiniteKernel κ]
(η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f)
{s : Set β} (hs : MeasurableSet s) :
∫⁻ z in s ×ˢ Set.univ, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by
simp_rw [setLIntegral_compProd κ η a hf hs MeasurableSet.univ, Measure.restrict_univ]
theorem setLIntegral_compProd_univ_left (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {t : Set γ}
(ht : MeasurableSet t) :
∫⁻ z in Set.univ ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by
simp_rw [setLIntegral_compProd κ η a hf MeasurableSet.univ ht, Measure.restrict_univ]
end Lintegral
theorem compProd_eq_sum_compProd_left (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) :
κ ⊗ₖ η = Kernel.sum fun n ↦ seq κ n ⊗ₖ η := by
simp_rw [compProd_def]
rw [← comp_sum_left, ← comp_sum_right, ← parallelComp_sum_right, kernel_sum_seq]
theorem compProd_eq_sum_compProd_right (κ : Kernel α β) (η : Kernel (α × β) γ)
[IsSFiniteKernel η] : κ ⊗ₖ η = Kernel.sum fun n => κ ⊗ₖ seq η n := by
simp_rw [compProd_def]
rw [← comp_sum_left, ← comp_sum_left, ← comp_sum_left, ← comp_sum_left, ← comp_sum_right,
← parallelComp_sum_left, kernel_sum_seq]
theorem compProd_eq_sum_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] : κ ⊗ₖ η = Kernel.sum fun n ↦ Kernel.sum fun m ↦ seq κ n ⊗ₖ seq η m := by
simp_rw [← compProd_eq_sum_compProd_right, ← compProd_eq_sum_compProd_left]
theorem compProd_eq_tsum_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) :
(κ ⊗ₖ η) a s = ∑' (n : ℕ) (m : ℕ), (seq κ n ⊗ₖ seq η m) a s := by
rw [compProd_eq_sum_compProd]
simp_rw [sum_apply' _ _ hs]
instance IsMarkovKernel.compProd (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel (α × β) γ)
[IsMarkovKernel η] : IsMarkovKernel (κ ⊗ₖ η) where
isProbabilityMeasure a := ⟨by simp [compProd_apply]⟩
instance IsZeroOrMarkovKernel.compProd (κ : Kernel α β) [IsZeroOrMarkovKernel κ]
(η : Kernel (α × β) γ) [IsZeroOrMarkovKernel η] : IsZeroOrMarkovKernel (κ ⊗ₖ η) := by
rw [compProd_def]
infer_instance
theorem compProd_apply_univ_le (κ : Kernel α β) (η : Kernel (α × β) γ) [IsFiniteKernel η] (a : α) :
(κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * η.bound := by
by_cases hκ : IsSFiniteKernel κ
swap
· rw [compProd_of_not_isSFiniteKernel_left _ _ hκ]
simp
rw [compProd_apply .univ]
let Cη := η.bound
calc
∫⁻ b, η (a, b) Set.univ ∂κ a ≤ ∫⁻ _, Cη ∂κ a :=
lintegral_mono fun b => measure_le_bound η (a, b) Set.univ
_ = Cη * κ a Set.univ := MeasureTheory.lintegral_const Cη
_ = κ a Set.univ * Cη := mul_comm _ _
instance IsFiniteKernel.compProd (κ : Kernel α β) [IsFiniteKernel κ] (η : Kernel (α × β) γ)
[IsFiniteKernel η] : IsFiniteKernel (κ ⊗ₖ η) := by
rw [compProd_def]
infer_instance
instance IsSFiniteKernel.compProd (κ : Kernel α β) (η : Kernel (α × β) γ) :
IsSFiniteKernel (κ ⊗ₖ η) := by
rw [compProd_def]
infer_instance
/-- `Kernel.compProd` is associative. We have to insert `MeasurableEquiv.prodAssoc` in two places
because the products of types `α × β × γ` and `(α × β) × γ` are different. -/
lemma compProd_assoc {δ : Type*} {mδ : MeasurableSpace δ}
{κ : Kernel α β} {η : Kernel (α × β) γ} {ξ : Kernel (α × β × γ) δ} :
(κ ⊗ₖ (η ⊗ₖ (ξ.comap MeasurableEquiv.prodAssoc (MeasurableEquiv.measurable _)))).map
MeasurableEquiv.prodAssoc.symm
= κ ⊗ₖ η ⊗ₖ ξ := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
by_cases hη : IsSFiniteKernel η
swap; · simp [hη]
by_cases hξ : IsSFiniteKernel ξ
swap
· have : ¬ IsSFiniteKernel
(ξ.comap MeasurableEquiv.prodAssoc (MeasurableEquiv.measurable _)) := by
refine fun h_sfin ↦ hξ ?_
have : ξ = (ξ.comap MeasurableEquiv.prodAssoc (MeasurableEquiv.measurable _)).comap
MeasurableEquiv.prodAssoc.symm (MeasurableEquiv.measurable _) := by
simp [← comap_comp_right]
rw [this]
infer_instance
simp [hξ, this]
ext a s hs
rw [compProd_apply hs, map_apply' _ (by fun_prop) _ hs,
compProd_apply (hs.preimage (by fun_prop)), lintegral_compProd]
swap; · exact measurable_kernel_prodMk_left' hs a
congr with b
rw [compProd_apply]
· congr
· exact hs.preimage (by fun_prop)
lemma compProd_add_left (μ κ : Kernel α β) (η : Kernel (α × β) γ)
[IsSFiniteKernel μ] [IsSFiniteKernel κ] :
(μ + κ) ⊗ₖ η = μ ⊗ₖ η + κ ⊗ₖ η := by
by_cases hη : IsSFiniteKernel η
· ext _ _ hs
simp [compProd_apply hs]
· simp [hη]
lemma compProd_add_right (μ : Kernel α β) (κ η : Kernel (α × β) γ)
[IsSFiniteKernel κ] [IsSFiniteKernel η] :
μ ⊗ₖ (κ + η) = μ ⊗ₖ κ + μ ⊗ₖ η := by
by_cases hμ : IsSFiniteKernel μ
swap; · simp [hμ]
ext a s hs
simp only [compProd_apply hs, coe_add, Pi.add_apply, Measure.coe_add]
rw [lintegral_add_left]
exact measurable_kernel_prodMk_left' hs a
lemma compProd_sum_left {ι : Type*} [Countable ι]
{κ : ι → Kernel α β} {η : Kernel (α × β) γ} [∀ i, IsSFiniteKernel (κ i)] :
Kernel.sum κ ⊗ₖ η = Kernel.sum (fun i ↦ (κ i) ⊗ₖ η) := by
by_cases hη : IsSFiniteKernel η
· ext a s hs
simp_rw [sum_apply, compProd_apply hs, sum_apply, lintegral_sum_measure, Measure.sum_apply _ hs,
compProd_apply hs]
· simp [hη]
lemma compProd_sum_right {ι : Type*} [Countable ι]
{κ : Kernel α β} {η : ι → Kernel (α × β) γ} [∀ i, IsSFiniteKernel (η i)] :
κ ⊗ₖ Kernel.sum η = Kernel.sum (fun i ↦ κ ⊗ₖ (η i)) := by
by_cases hκ : IsSFiniteKernel κ
swap; · simp [hκ]
ext a s hs
simp_rw [sum_apply, compProd_apply hs, Measure.sum_apply _ hs, sum_apply, compProd_apply hs]
rw [← lintegral_tsum]
· congr with i
rw [Measure.sum_apply]
exact measurable_prodMk_left hs
· exact fun _ ↦ (measurable_kernel_prodMk_left' hs a).aemeasurable
lemma comapRight_compProd_id_prod {δ : Type*} {mδ : MeasurableSpace δ}
(κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η]
{f : δ → γ} (hf : MeasurableEmbedding f) :
comapRight (κ ⊗ₖ η) (MeasurableEmbedding.id.prodMap hf) = κ ⊗ₖ (comapRight η hf) := by
ext a t ht
rw [comapRight_apply' _ _ _ ht, compProd_apply, compProd_apply ht]
· refine lintegral_congr fun b ↦ ?_
rw [comapRight_apply']
· congr with x
aesop
· exact measurable_prodMk_left ht
· exact (MeasurableEmbedding.id.prodMap hf).measurableSet_image.mpr ht
end CompositionProduct
open scoped ProbabilityTheory
section FstSnd
variable {δ : Type*} {mδ : MeasurableSpace δ}
/-- If `η` is a Markov kernel, use instead `fst_compProd` to get `(κ ⊗ₖ η).fst = κ`. -/
lemma fst_compProd_apply (κ : Kernel α β) (η : Kernel (α × β) γ)
[IsSFiniteKernel κ] [IsSFiniteKernel η] (x : α) {s : Set β} (hs : MeasurableSet s) :
(κ ⊗ₖ η).fst x s = ∫⁻ b, s.indicator (fun b ↦ η (x, b) Set.univ) b ∂(κ x) := by
rw [Kernel.fst_apply' _ _ hs, Kernel.compProd_apply]
swap; · exact measurable_fst hs
have h_eq b : η (x, b) {c | b ∈ s} = s.indicator (fun b ↦ η (x, b) Set.univ) b := by
by_cases hb : b ∈ s <;> simp [hb]
simp_rw [Set.preimage, Set.mem_setOf_eq, h_eq]
@[simp]
lemma fst_compProd (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel κ] [IsMarkovKernel η] :
fst (κ ⊗ₖ η) = κ := by
ext x s hs; simp [fst_compProd_apply, hs]
end FstSnd
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/CompMap.lean | import Mathlib.Probability.Kernel.Composition.Comp
import Mathlib.Probability.Kernel.Composition.MapComap
/-!
# Lemmas about compositions and maps of kernels
This file contains results that use both the composition of kernels and the map of a kernel by a
function.
Map and comap are particular cases of composition: they correspond to composition with
a deterministic kernel. See `deterministic_comp_eq_map` and `comp_deterministic_eq_comap`.
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : β → γ} {g : γ → α}
theorem deterministic_comp_eq_map (hf : Measurable f) (κ : Kernel α β) :
deterministic f hf ∘ₖ κ = map κ f := by
ext a s hs
simp_rw [map_apply' _ hf _ hs, comp_apply' _ _ _ hs, deterministic_apply' hf _ hs,
lintegral_indicator_const_comp hf hs, one_mul]
theorem comp_deterministic_eq_comap (κ : Kernel α β) (hg : Measurable g) :
κ ∘ₖ deterministic g hg = comap κ g hg := by
ext a s hs
simp_rw [comap_apply' _ _ _ s, comp_apply' _ _ _ hs, deterministic_apply hg a,
lintegral_dirac' _ (Kernel.measurable_coe κ hs)]
lemma deterministic_comp_deterministic (hf : Measurable f) (hg : Measurable g) :
(deterministic g hg) ∘ₖ (deterministic f hf) = deterministic (g ∘ f) (hg.comp hf) := by
ext; simp [comp_deterministic_eq_comap, comap_apply, deterministic_apply]
@[simp]
lemma comp_id (κ : Kernel α β) : κ ∘ₖ Kernel.id = κ := by
rw [Kernel.id, comp_deterministic_eq_comap, comap_id]
@[simp]
lemma id_comp (κ : Kernel α β) : Kernel.id ∘ₖ κ = κ := by
rw [Kernel.id, deterministic_comp_eq_map, map_id]
@[simp]
lemma swap_swap : (swap α β) ∘ₖ (swap β α) = Kernel.id := by
simp_rw [swap, Kernel.deterministic_comp_deterministic, Prod.swap_swap_eq, Kernel.id]
lemma swap_comp_eq_map {κ : Kernel α (β × γ)} : (swap β γ) ∘ₖ κ = κ.map Prod.swap := by
rw [swap, deterministic_comp_eq_map]
lemma map_comp (κ : Kernel α β) (η : Kernel β γ) (f : γ → δ) :
(η ∘ₖ κ).map f = (η.map f) ∘ₖ κ := by
by_cases hf : Measurable f
· ext a s hs
rw [map_apply' _ hf _ hs, comp_apply', comp_apply' _ _ _ hs]
· simp_rw [map_apply' _ hf _ hs]
· exact hf hs
· simp [map_of_not_measurable _ hf]
lemma comp_map (κ : Kernel α β) (η : Kernel γ δ) {f : β → γ} (hf : Measurable f) :
η ∘ₖ (κ.map f) = (η.comap f hf) ∘ₖ κ := by
ext x s ms
rw [comp_apply' _ _ _ ms, lintegral_map _ hf _ (η.measurable_coe ms), comp_apply' _ _ _ ms]
simp_rw [comap_apply']
lemma fst_comp (κ : Kernel α β) (η : Kernel β (γ × δ)) : (η ∘ₖ κ).fst = η.fst ∘ₖ κ := by
simp [fst_eq, map_comp κ η _]
lemma snd_comp (κ : Kernel α β) (η : Kernel β (γ × δ)) : (η ∘ₖ κ).snd = η.snd ∘ₖ κ := by
simp_rw [snd_eq, map_comp κ η _]
end Kernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Kernel/Composition/MeasureComp.lean | import Mathlib.Probability.Kernel.Composition.CompNotation
import Mathlib.Probability.Kernel.Composition.KernelLemmas
import Mathlib.Probability.Kernel.Composition.MeasureCompProd
/-!
# Lemmas about the composition of a measure and a kernel
Basic lemmas about the composition `κ ∘ₘ μ` of a kernel `κ` and a measure `μ`.
-/
open scoped ENNReal
open ProbabilityTheory MeasureTheory
namespace MeasureTheory.Measure
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{μ ν : Measure α} {κ η : Kernel α β}
lemma comp_assoc {η : Kernel β γ} : η ∘ₘ (κ ∘ₘ μ) = (η ∘ₖ κ) ∘ₘ μ :=
Measure.bind_bind κ.aemeasurable η.aemeasurable
/-- This lemma allows to rewrite the composition of a measure and a kernel as the composition
of two kernels, which allows to transfer properties of `∘ₖ` to `∘ₘ`. -/
lemma comp_eq_comp_const_apply : κ ∘ₘ μ = (κ ∘ₖ (Kernel.const Unit μ)) () := by
rw [Kernel.comp_apply, Kernel.const_apply]
lemma comp_eq_sum_of_countable [Countable α] [MeasurableSingletonClass α] :
κ ∘ₘ μ = Measure.sum (fun ω ↦ μ {ω} • κ ω) := by
ext s hs
rw [Measure.sum_apply _ hs, Measure.bind_apply hs (by fun_prop)]
simp [lintegral_countable', mul_comm]
@[simp]
lemma snd_compProd (μ : Measure α) [SFinite μ] (κ : Kernel α β) [IsSFiniteKernel κ] :
(μ ⊗ₘ κ).snd = κ ∘ₘ μ := by
ext s hs
rw [bind_apply hs κ.aemeasurable, snd_apply hs, compProd_apply]
· rfl
· exact measurable_snd hs
lemma comp_congr (h : ∀ᵐ a ∂μ, κ a = η a) : κ ∘ₘ μ = η ∘ₘ μ := bind_congr_right h
lemma ae_ae_of_ae_comp {p : β → Prop} (h : ∀ᵐ ω ∂(κ ∘ₘ μ), p ω) :
∀ᵐ ω' ∂μ, ∀ᵐ ω ∂(κ ω'), p ω := by
rw [comp_eq_comp_const_apply] at h
exact Kernel.ae_ae_of_ae_comp h
lemma ae_comp_of_ae_ae {p : β → Prop} (hp : MeasurableSet {z | p z})
(h : ∀ᵐ y ∂μ, ∀ᵐ z ∂κ y, p z) : ∀ᵐ z ∂(κ ∘ₘ μ), p z := by
rw [comp_eq_comp_const_apply]
exact Kernel.ae_comp_of_ae_ae hp h
lemma ae_comp_iff {p : β → Prop} (hp : MeasurableSet {z | p z}) :
(∀ᵐ z ∂(κ ∘ₘ μ), p z) ↔ ∀ᵐ y ∂μ, ∀ᵐ z ∂κ y, p z :=
⟨ae_ae_of_ae_comp, ae_comp_of_ae_ae hp⟩
instance [SFinite μ] [IsSFiniteKernel κ] : SFinite (κ ∘ₘ μ) := by
rw [← snd_compProd]; infer_instance
instance [IsFiniteMeasure μ] [IsFiniteKernel κ] : IsFiniteMeasure (κ ∘ₘ μ) := by
rw [← snd_compProd]; infer_instance
instance [IsProbabilityMeasure μ] [IsMarkovKernel κ] : IsProbabilityMeasure (κ ∘ₘ μ) := by
rw [← snd_compProd]; infer_instance
instance [IsZeroOrProbabilityMeasure μ] [IsZeroOrMarkovKernel κ] :
IsZeroOrProbabilityMeasure (κ ∘ₘ μ) := by
rw [← snd_compProd]; infer_instance
@[simp]
lemma _root_.ProbabilityTheory.Kernel.comp_const (κ : Kernel β γ) (μ : Measure β) :
κ ∘ₖ Kernel.const α μ = Kernel.const α (κ ∘ₘ μ) := rfl
lemma map_comp (μ : Measure α) (κ : Kernel α β) {f : β → γ} (hf : Measurable f) :
(κ ∘ₘ μ).map f = (κ.map f) ∘ₘ μ := by
ext s hs
rw [Measure.map_apply hf hs, Measure.bind_apply (hf hs) κ.aemeasurable,
Measure.bind_apply hs (Kernel.aemeasurable _)]
simp_rw [Kernel.map_apply' _ hf _ hs]
@[simp]
lemma discard_comp (μ : Measure α) : Kernel.discard α ∘ₘ μ = μ .univ • Measure.dirac () := by
ext s hs; simp [Measure.bind_apply hs (Kernel.aemeasurable _), mul_comm]
lemma copy_comp_map {f : α → β} (hf : AEMeasurable f μ) :
Kernel.copy β ∘ₘ (μ.map f) = μ.map (fun a ↦ (f a, f a)) := by
rw [Kernel.copy, deterministic_comp_eq_map, AEMeasurable.map_map_of_aemeasurable (by fun_prop) hf]
rfl
section CompProd
lemma compProd_eq_comp_prod (μ : Measure α) [SFinite μ] (κ : Kernel α β) [IsSFiniteKernel κ] :
μ ⊗ₘ κ = (Kernel.id ×ₖ κ) ∘ₘ μ := by
rw [compProd, Kernel.compProd_prodMkLeft_eq_comp]
rfl
lemma compProd_id_eq_copy_comp [SFinite μ] : μ ⊗ₘ Kernel.id = Kernel.copy α ∘ₘ μ := by
rw [compProd_id, Kernel.copy, deterministic_comp_eq_map]
lemma comp_compProd_comm {η : Kernel (α × β) γ} [SFinite μ] [IsSFiniteKernel η] :
η ∘ₘ (μ ⊗ₘ κ) = ((κ ⊗ₖ η) ∘ₘ μ).snd := by
by_cases hκ : IsSFiniteKernel κ; swap
· simp [compProd_of_not_isSFiniteKernel _ _ hκ,
Kernel.compProd_of_not_isSFiniteKernel_left _ _ hκ]
ext s hs
rw [Measure.bind_apply hs η.aemeasurable, Measure.snd_apply hs,
Measure.bind_apply _ (Kernel.aemeasurable _), Measure.lintegral_compProd (η.measurable_coe hs)]
swap; · exact measurable_snd hs
congr with a
rw [Kernel.compProd_apply]
· rfl
· exact measurable_snd hs
@[simp]
lemma prodMkLeft_comp_compProd {η : Kernel β γ} [SFinite μ] [IsSFiniteKernel κ] :
(η.prodMkLeft α) ∘ₘ μ ⊗ₘ κ = η ∘ₘ κ ∘ₘ μ := by
rw [← snd_compProd μ κ, Kernel.prodMkLeft, snd, ← deterministic_comp_eq_map measurable_snd,
comp_assoc, Kernel.comp_deterministic_eq_comap]
lemma compProd_deterministic [SFinite μ] {f : α → β} (hf : Measurable f) :
μ ⊗ₘ Kernel.deterministic f hf = μ.map (fun a ↦ (a, f a)) := by
rw [compProd_eq_comp_prod, Kernel.id, Kernel.deterministic_prod_deterministic,
deterministic_comp_eq_map]
rfl
end CompProd
section AddSMul
@[simp]
lemma comp_add : κ ∘ₘ (μ + ν) = κ ∘ₘ μ + κ ∘ₘ ν := by
simp_rw [comp_eq_comp_const_apply, Kernel.const_add, Kernel.comp_add_right, Kernel.add_apply]
lemma add_comp : (κ + η) ∘ₘ μ = κ ∘ₘ μ + η ∘ₘ μ := by
simp_rw [comp_eq_comp_const_apply, Kernel.comp_add_left, Kernel.add_apply]
/-- Same as `add_comp` except that it uses `⇑κ + ⇑η` instead of `⇑(κ + η)` in order to have
a simp-normal form on the left of the equality. -/
@[simp]
lemma add_comp' : (⇑κ + ⇑η) ∘ₘ μ = κ ∘ₘ μ + η ∘ₘ μ := by rw [← Kernel.coe_add, add_comp]
@[simp]
lemma comp_smul (a : ℝ≥0∞) : κ ∘ₘ (a • μ) = a • (κ ∘ₘ μ) := by
ext s hs
simp only [bind_apply hs κ.aemeasurable, lintegral_smul_measure, smul_apply, smul_eq_mul]
end AddSMul
section AbsolutelyContinuous
lemma AbsolutelyContinuous.comp_right (hμν : μ ≪ ν) (κ : Kernel α γ) :
κ ∘ₘ μ ≪ κ ∘ₘ ν := by
refine Measure.AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_
rw [Measure.bind_apply hs (Kernel.aemeasurable _),
lintegral_eq_zero_iff (Kernel.measurable_coe _ hs)] at hs_zero ⊢
exact hμν.ae_eq hs_zero
lemma AbsolutelyContinuous.comp_left (μ : Measure α) (hκη : ∀ᵐ a ∂μ, κ a ≪ η a) :
κ ∘ₘ μ ≪ η ∘ₘ μ := by
refine Measure.AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_
rw [Measure.bind_apply hs (Kernel.aemeasurable _),
lintegral_eq_zero_iff (Kernel.measurable_coe _ hs)] at hs_zero ⊢
filter_upwards [hs_zero, hκη] with a ha_zero ha_ac using ha_ac ha_zero
lemma AbsolutelyContinuous.comp (hμν : μ ≪ ν) (hκη : ∀ᵐ a ∂μ, κ a ≪ η a) :
κ ∘ₘ μ ≪ η ∘ₘ ν :=
(AbsolutelyContinuous.comp_left μ hκη).trans (hμν.comp_right η)
lemma absolutelyContinuous_comp_of_countable [Countable α] [MeasurableSingletonClass α] :
∀ᵐ ω ∂μ, κ ω ≪ κ ∘ₘ μ := by
rw [Measure.comp_eq_sum_of_countable, ae_iff_of_countable]
exact fun ω hμω ↦ Measure.absolutelyContinuous_sum_right ω (Measure.absolutelyContinuous_smul hμω)
end AbsolutelyContinuous
end MeasureTheory.Measure
namespace ProbabilityTheory
variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
section BoolKernel
variable {π : Measure Bool}
@[simp]
lemma Kernel.comp_boolKernel (κ : Kernel α β) (μ ν : Measure α) :
κ ∘ₖ (boolKernel μ ν) = boolKernel (κ ∘ₘ μ) (κ ∘ₘ ν) := by
ext b : 1
rw [comp_apply]
cases b <;> simp
lemma boolKernel_comp_measure (μ ν : Measure α) (π : Measure Bool) :
Kernel.boolKernel μ ν ∘ₘ π = π {true} • ν + π {false} • μ := by
ext s hs
rw [Measure.bind_apply hs (Kernel.aemeasurable _)]
simp [lintegral_fintype, mul_comm]
lemma absolutelyContinuous_boolKernel_comp_left (μ ν : Measure α) (hπ : π {false} ≠ 0) :
μ ≪ Kernel.boolKernel μ ν ∘ₘ π :=
boolKernel_comp_measure _ _ _ ▸ add_comm _ (π {true} • ν) ▸
(Measure.absolutelyContinuous_smul hπ).add_right _
lemma absolutelyContinuous_boolKernel_comp_right (μ ν : Measure α) (hπ : π {true} ≠ 0) :
ν ≪ Kernel.boolKernel μ ν ∘ₘ π :=
boolKernel_comp_measure _ _ _ ▸ (Measure.absolutelyContinuous_smul hπ).add_right _
end BoolKernel
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/Predictable.lean | import Mathlib.Probability.Process.Adapted
/-!
# Predictable σ-algebra
This file defines the predictable σ-algebra associated to a filtration, as well as the
notion of predictable processes. We prove that predictable processes are progressively measurable
and adapted. We also give an equivalent characterization of predictability for discrete processes.
## Main definitions
* `Filtration.predictable` : The predictable σ-algebra associated to a filtration.
* `IsPredictable` : A process is predictable if it is measurable with respect to the
predictable σ-algebra.
## Main results
* `IsPredictable.progMeasurable` : A predictable process is progressively measurable.
* `isPredictable_iff_measurable_add_one` : `u` is a discrete predictable process iff
`u (n + 1)` is `𝓕 n`-measurable and `u 0` is `𝓕 0`-measurable.
## Tags
predictable, previsible
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {E : Type*} [TopologicalSpace E]
section
variable [Preorder ι] [OrderBot ι]
namespace Filtration
/-- Given a filtration `𝓕`, the predictable σ-algebra is the σ-algebra on `ι × Ω` generated by
sets of the form `(t, ∞) × A` for `t ∈ ι` and `A ∈ 𝓕 t` and `{⊥} × A` for `A ∈ 𝓕 ⊥`. -/
def predictable (𝓕 : Filtration ι m) : MeasurableSpace (ι × Ω) :=
MeasurableSpace.generateFrom <|
{s | ∃ A, MeasurableSet[𝓕 ⊥] A ∧ s = {⊥} ×ˢ A} ∪
{s | ∃ i A, MeasurableSet[𝓕 i] A ∧ s = Set.Ioi i ×ˢ A}
end Filtration
/-- A process is said to be predictable if it is measurable with respect to the predictable
σ-algebra. -/
def IsPredictable (𝓕 : Filtration ι m) (u : ι → Ω → E) :=
StronglyMeasurable[𝓕.predictable] <| Function.uncurry u
end
lemma measurableSet_predictable_singleton_bot_prod [LinearOrder ι] [OrderBot ι]
{𝓕 : Filtration ι m} {s : Set Ω} (hs : MeasurableSet[𝓕 ⊥] s) :
MeasurableSet[𝓕.predictable] <| {⊥} ×ˢ s :=
MeasurableSpace.measurableSet_generateFrom <| Or.inl ⟨s, hs, rfl⟩
lemma measurableSet_predictable_Ioi_prod [LinearOrder ι] [OrderBot ι]
{𝓕 : Filtration ι m} {i : ι} {s : Set Ω} (hs : MeasurableSet[𝓕 i] s) :
MeasurableSet[𝓕.predictable] <| Set.Ioi i ×ˢ s :=
MeasurableSpace.measurableSet_generateFrom <| Or.inr ⟨i, s, hs, rfl⟩
/-- Sets of the form `(i, j] × A` for any `A ∈ 𝓕 i` are measurable with respect to the predictable
σ-algebra. -/
lemma measurableSet_predictable_Ioc_prod [LinearOrder ι] [OrderBot ι]
{𝓕 : Filtration ι m} (i j : ι) {s : Set Ω} (hs : MeasurableSet[𝓕 i] s) :
MeasurableSet[𝓕.predictable] <| Set.Ioc i j ×ˢ s := by
obtain hij | hij := le_total j i
· simp [hij]
· rw [← Set.Ioi_diff_Ioi, (by simp : (Set.Ioi i \ Set.Ioi j) ×ˢ s
= Set.Ioi i ×ˢ (s \ s) ∪ (Set.Ioi i \ Set.Ioi j) ×ˢ s), ← Set.prod_diff_prod]
exact (measurableSet_predictable_Ioi_prod hs).diff
(measurableSet_predictable_Ioi_prod <| 𝓕.mono hij _ hs)
lemma measurableSpace_le_predictable_of_measurableSet [Preorder ι] [OrderBot ι]
{𝓕 : Filtration ι m} {m' : MeasurableSpace (ι × Ω)}
(hm'bot : ∀ A, MeasurableSet[𝓕 ⊥] A → MeasurableSet[m'] ({⊥} ×ˢ A))
(hm' : ∀ i A, MeasurableSet[𝓕 i] A → MeasurableSet[m'] ((Set.Ioi i) ×ˢ A)) :
𝓕.predictable ≤ m' := by
refine MeasurableSpace.generateFrom_le ?_
rintro - (⟨A, hA, rfl⟩ | ⟨i, A, hA, rfl⟩)
· exact hm'bot A hA
· exact hm' i A hA
namespace IsPredictable
open Filtration
variable [LinearOrder ι] [OrderBot ι] [MeasurableSpace ι] [TopologicalSpace ι]
[OpensMeasurableSpace ι] [OrderClosedTopology ι]
[MetrizableSpace E] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E]
/-- A predictable process is progressively measurable. -/
lemma progMeasurable {𝓕 : Filtration ι m} {u : ι → Ω → E} (h𝓕 : IsPredictable 𝓕 u) :
ProgMeasurable 𝓕 u := by
refine fun i ↦ Measurable.stronglyMeasurable ?_
rw [IsPredictable, stronglyMeasurable_iff_measurable, measurable_iff_comap_le] at h𝓕
rw [measurable_iff_comap_le, (by aesop : (fun (p : Set.Iic i × Ω) ↦ u (p.1) p.2)
= Function.uncurry u ∘ (fun p ↦ (p.1, p.2))), ← MeasurableSpace.comap_comp]
refine (MeasurableSpace.comap_mono h𝓕).trans <| MeasurableSpace.comap_le_iff_le_map.2 <|
measurableSpace_le_predictable_of_measurableSet ?_ ?_
· intros A hA
simp only [MeasurableSpace.map_def,
(by aesop : (fun (p : Set.Iic i × Ω) ↦ ((p.1 : ι), p.2)) ⁻¹' ({⊥} ×ˢ A) = {⊥} ×ˢ A)]
exact (measurableSet_singleton _).prod <| 𝓕.mono bot_le _ hA
· intros j A hA
simp only [MeasurableSpace.map_def]
obtain hji | hij := le_total j i
· rw [(by grind : (fun (p : Set.Iic i × Ω) ↦ ((p.1 : ι), p.2)) ⁻¹' Set.Ioi j ×ˢ A
= (Subtype.val ⁻¹' (Set.Ioc j i)) ×ˢ A)]
exact (measurable_subtype_coe measurableSet_Ioc).prod (𝓕.mono hji _ hA)
· simp [(by grind : (fun (p : Set.Iic i × Ω) ↦ ((p.1 : ι), p.2)) ⁻¹' Set.Ioi j ×ˢ A = ∅)]
/-- A predictable process is adapted. -/
lemma adapted {𝓕 : Filtration ι m} {u : ι → Ω → E} (h𝓕 : IsPredictable 𝓕 u) :
Adapted 𝓕 u :=
h𝓕.progMeasurable.adapted
omit [SecondCountableTopology E] in
lemma measurableSet_prodMk_add_one_of_predictable {𝓕 : Filtration ℕ m} {s : Set (ℕ × Ω)}
(hs : MeasurableSet[𝓕.predictable] s) (n : ℕ) :
MeasurableSet[𝓕 n] {ω | (n + 1, ω) ∈ s} := by
rw [(by aesop : {ω | (n + 1, ω) ∈ s} = (Prod.mk (α := Set.singleton (n + 1)) (β := Ω)
⟨n + 1, rfl⟩) ⁻¹' ((fun (p : Set.singleton (n + 1) × Ω) ↦ ((p.1 : ℕ), p.2)) ⁻¹' s))]
refine measurableSet_preimage (mβ := Subtype.instMeasurableSpace.prod (𝓕 n))
measurable_prodMk_left <| measurableSet_preimage ?_ hs
rw [measurable_iff_comap_le, MeasurableSpace.comap_le_iff_le_map]
refine MeasurableSpace.generateFrom_le ?_
rintro - (⟨A, hA, rfl⟩ | ⟨i, A, hA, rfl⟩)
· rw [MeasurableSpace.map_def,
(_ : (fun (p : Set.singleton (n + 1) × Ω) ↦ ((p.1 : ℕ), p.2)) ⁻¹' ({⊥} ×ˢ A) = ∅)]
· simp
· ext p
simp only [Nat.bot_eq_zero, Set.mem_preimage, Set.mem_prod, Set.mem_singleton_iff,
Set.mem_empty_iff_false, iff_false, not_and]
exact fun hp1 ↦ False.elim <| Nat.succ_ne_zero n (hp1 ▸ p.1.2.symm)
· rw [MeasurableSpace.map_def]
obtain hni | hin := lt_or_ge n i
· rw [(_ : (fun (p : Set.singleton (n + 1) × Ω) ↦ ((p.1 : ℕ), p.2)) ⁻¹' (Set.Ioi i ×ˢ A) = ∅)]
· simp
· ext p
simp only [Set.mem_preimage, Set.mem_prod, Set.mem_Ioi, Set.mem_empty_iff_false,
iff_false, not_and]
rw [p.1.2]
grind
· rw [(_ : (fun (p : Set.singleton (n + 1) × Ω) ↦ ((p.1 : ℕ), p.2)) ⁻¹' (Set.Ioi i ×ˢ A)
= {⟨n + 1, rfl⟩} ×ˢ A)]
· exact MeasurableSet.prod (MeasurableSet.of_subtype_image trivial) (𝓕.mono hin _ hA)
· ext p
simp only [Set.mem_preimage, Set.mem_prod, Set.mem_Ioi, Set.mem_singleton_iff,
and_congr_left_iff]
intro hp2
rw [p.1.2]
exact ⟨fun _ ↦ by aesop, fun _ ↦ lt_add_one_iff.2 hin⟩
omit [SecondCountableTopology E] in
/-- If `u` is a discrete predictable process, then `u (n + 1)` is `𝓕 n`-measurable. -/
lemma measurable_add_one {𝓕 : Filtration ℕ m} {u : ℕ → Ω → E} (h𝓕 : IsPredictable 𝓕 u) (n : ℕ) :
Measurable[𝓕 n] (u (n + 1)) := by
intro s hs
rw [(by aesop : u (n + 1) ⁻¹' s = {ω | (n + 1, ω) ∈ (Function.uncurry u) ⁻¹' s})]
exact measurableSet_prodMk_add_one_of_predictable (h𝓕.measurable hs) n
end IsPredictable
section
variable [MetrizableSpace E] [MeasurableSpace E] [BorelSpace E]
lemma measurableSet_predictable_singleton_prod
{𝓕 : Filtration ℕ m} {n : ℕ} {s : Set Ω} (hs : MeasurableSet[𝓕 n] s) :
MeasurableSet[𝓕.predictable] <| {n + 1} ×ˢ s := by
rw [(_ : {n + 1} = Set.Ioc n (n + 1))]
· exact measurableSet_predictable_Ioc_prod _ _ hs
· ext m
simp only [Set.mem_singleton_iff, Set.mem_Ioc]
omega
lemma isPredictable_of_measurable_add_one [SecondCountableTopology E]
{𝓕 : Filtration ℕ m} {u : ℕ → Ω → E}
(h₀ : Measurable[𝓕 0] (u 0)) (h : ∀ n, Measurable[𝓕 n] (u (n + 1))) :
IsPredictable 𝓕 u := by
refine Measurable.stronglyMeasurable ?_
intro s hs
rw [(by aesop : Function.uncurry u ⁻¹' s = ⋃ n : ℕ, {n} ×ˢ (u n ⁻¹' s))]
refine MeasurableSet.iUnion <| fun n ↦ ?_
obtain (rfl | hn) := n.eq_zero_or_eq_succ_pred
· exact MeasurableSpace.measurableSet_generateFrom <| Or.inl ⟨u 0 ⁻¹' s, h₀ hs, rfl⟩
· rw [hn]
exact measurableSet_predictable_singleton_prod (h (n - 1) hs)
/-- A discrete process `u` is predictable iff `u (n + 1)` is `𝓕 n`-measurable for all `n` and
`u 0` is `𝓕 0`-measurable. -/
lemma isPredictable_iff_measurable_add_one [SecondCountableTopology E]
{𝓕 : Filtration ℕ m} {u : ℕ → Ω → E} :
IsPredictable 𝓕 u ↔ Measurable[𝓕 0] (u 0) ∧ ∀ n, Measurable[𝓕 n] (u (n + 1)) :=
⟨fun h𝓕 ↦ ⟨(h𝓕.adapted 0).measurable, fun n ↦ h𝓕.measurable_add_one (n)⟩,
fun h ↦ isPredictable_of_measurable_add_one h.1 h.2⟩
end
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/Adapted.lean | import Mathlib.Probability.Process.Filtration
import Mathlib.Topology.Instances.Discrete
/-!
# Adapted and progressively measurable processes
This file defines some standard definition from the theory of stochastic processes including
filtrations and stopping times. These definitions are used to model the amount of information
at a specific time and are the first step in formalizing stochastic processes.
## Main definitions
* `MeasureTheory.Adapted`: a sequence of functions `u` is said to be adapted to a
filtration `f` if at each point in time `i`, `u i` is `f i`-strongly measurable
* `MeasureTheory.ProgMeasurable`: a sequence of functions `u` is said to be progressively
measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to
`Set.Iic i × Ω` is strongly measurable with respect to the product `MeasurableSpace` structure
where the σ-algebra used for `Ω` is `f i`.
## Main results
* `Adapted.progMeasurable_of_continuous`: a continuous adapted process is progressively measurable.
## Tags
adapted, progressively measurable
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} [Preorder ι] {f : Filtration ι m}
section Adapted
variable {β : ι → Type*} [∀ i, TopologicalSpace (β i)] {u v : (i : ι) → Ω → β i}
/-- A sequence of functions `u` is adapted to a filtration `f` if for all `i`,
`u i` is `f i`-measurable. -/
def Adapted (f : Filtration ι m) (u : (i : ι) → Ω → β i) : Prop :=
∀ i : ι, StronglyMeasurable[f i] (u i)
namespace Adapted
@[to_additive]
protected theorem mul [∀ i, Mul (β i)] [∀ i, ContinuousMul (β i)]
(hu : Adapted f u) (hv : Adapted f v) :
Adapted f (u * v) := fun i => (hu i).mul (hv i)
@[to_additive]
protected theorem div [∀ i, Div (β i)] [∀ i, ContinuousDiv (β i)]
(hu : Adapted f u) (hv : Adapted f v) :
Adapted f (u / v) := fun i => (hu i).div (hv i)
@[to_additive]
protected theorem inv [∀ i, Group (β i)] [∀ i, ContinuousInv (β i)] (hu : Adapted f u) :
Adapted f u⁻¹ := fun i => (hu i).inv
protected theorem smul [∀ i, SMul ℝ (β i)] [∀ i, ContinuousConstSMul ℝ (β i)]
(c : ℝ) (hu : Adapted f u) :
Adapted f (c • u) := fun i => (hu i).const_smul c
protected theorem stronglyMeasurable {i : ι} (hf : Adapted f u) : StronglyMeasurable[m] (u i) :=
(hf i).mono (f.le i)
theorem stronglyMeasurable_le {i j : ι} (hf : Adapted f u) (hij : i ≤ j) :
StronglyMeasurable[f j] (u i) := (hf i).mono (f.mono hij)
end Adapted
theorem adapted_const' (f : Filtration ι m) (x : (i : ι) → β i) : Adapted f fun i _ ↦ x i :=
fun _ ↦ stronglyMeasurable_const
theorem adapted_const {β : Type*} [TopologicalSpace β] (f : Filtration ι m) (x : β) :
Adapted f fun _ _ ↦ x :=
adapted_const' _ _
variable (β) in
theorem adapted_zero' [∀ i, Zero (β i)] (f : Filtration ι m) : Adapted f (0 : (i : ι) → Ω → β i) :=
fun i ↦ @stronglyMeasurable_zero Ω (β i) (f i) _ _
theorem adapted_zero (β : Type*) [TopologicalSpace β] [Zero β] (f : Filtration ι m) :
Adapted f (0 : ι → Ω → β) :=
fun i ↦ @stronglyMeasurable_zero Ω β (f i) _ _
theorem Filtration.adapted_natural [∀ i, MetrizableSpace (β i)] [mβ : ∀ i, MeasurableSpace (β i)]
[∀ i, BorelSpace (β i)] (hum : ∀ i, StronglyMeasurable[m] (u i)) :
Adapted (Filtration.natural u hum) u := by
intro i
refine StronglyMeasurable.mono ?_ (le_iSup₂_of_le i (le_refl i) le_rfl)
rw [stronglyMeasurable_iff_measurable_separable]
exact ⟨measurable_iff_comap_le.2 le_rfl, (hum i).isSeparable_range⟩
end Adapted
variable {β : Type*} [TopologicalSpace β] {u v : ι → Ω → β}
/-- Progressively measurable process. A sequence of functions `u` is said to be progressively
measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to
`Set.Iic i × Ω` is measurable with respect to the product `MeasurableSpace` structure where the
σ-algebra used for `Ω` is `f i`.
The usual definition uses the interval `[0,i]`, which we replace by `Set.Iic i`. We recover the
usual definition for index types `ℝ≥0` or `ℕ`. -/
def ProgMeasurable [MeasurableSpace ι] (f : Filtration ι m) (u : ι → Ω → β) : Prop :=
∀ i, StronglyMeasurable[Subtype.instMeasurableSpace.prod (f i)] fun p : Set.Iic i × Ω => u p.1 p.2
theorem progMeasurable_const [MeasurableSpace ι] (f : Filtration ι m) (b : β) :
ProgMeasurable f (fun _ _ => b : ι → Ω → β) := fun i =>
@stronglyMeasurable_const _ _ (Subtype.instMeasurableSpace.prod (f i)) _ _
namespace ProgMeasurable
variable [MeasurableSpace ι]
protected theorem adapted (h : ProgMeasurable f u) : Adapted f u := by
intro i
have : u i = (fun p : Set.Iic i × Ω => u p.1 p.2) ∘ fun x => (⟨i, Set.mem_Iic.mpr le_rfl⟩, x) :=
rfl
rw [this]
exact (h i).comp_measurable measurable_prodMk_left
protected theorem comp {t : ι → Ω → ι} [TopologicalSpace ι] [BorelSpace ι] [PseudoMetrizableSpace ι]
(h : ProgMeasurable f u) (ht : ProgMeasurable f t) (ht_le : ∀ i ω, t i ω ≤ i) :
ProgMeasurable f fun i ω => u (t i ω) ω := by
intro i
have : (fun p : ↥(Set.Iic i) × Ω => u (t (p.fst : ι) p.snd) p.snd) =
(fun p : ↥(Set.Iic i) × Ω => u (p.fst : ι) p.snd) ∘ fun p : ↥(Set.Iic i) × Ω =>
(⟨t (p.fst : ι) p.snd, Set.mem_Iic.mpr ((ht_le _ _).trans p.fst.prop)⟩, p.snd) := rfl
rw [this]
exact (h i).comp_measurable ((ht i).measurable.subtype_mk.prodMk measurable_snd)
section Arithmetic
@[to_additive]
protected theorem mul [Mul β] [ContinuousMul β] (hu : ProgMeasurable f u)
(hv : ProgMeasurable f v) : ProgMeasurable f fun i ω => u i ω * v i ω := fun i =>
(hu i).mul (hv i)
@[to_additive]
protected theorem finset_prod' {γ} [CommMonoid β] [ContinuousMul β] {U : γ → ι → Ω → β}
{s : Finset γ} (h : ∀ c ∈ s, ProgMeasurable f (U c)) : ProgMeasurable f (∏ c ∈ s, U c) :=
Finset.prod_induction U (ProgMeasurable f) (fun _ _ => ProgMeasurable.mul)
(progMeasurable_const _ 1) h
@[to_additive]
protected theorem finset_prod {γ} [CommMonoid β] [ContinuousMul β] {U : γ → ι → Ω → β}
{s : Finset γ} (h : ∀ c ∈ s, ProgMeasurable f (U c)) :
ProgMeasurable f fun i a => ∏ c ∈ s, U c i a := by
convert ProgMeasurable.finset_prod' h using 1; ext (i a); simp only [Finset.prod_apply]
@[to_additive]
protected theorem inv [Group β] [ContinuousInv β] (hu : ProgMeasurable f u) :
ProgMeasurable f fun i ω => (u i ω)⁻¹ := fun i => (hu i).inv
@[to_additive]
protected theorem div [Group β] [ContinuousDiv β] (hu : ProgMeasurable f u)
(hv : ProgMeasurable f v) : ProgMeasurable f fun i ω => u i ω / v i ω := fun i =>
(hu i).div (hv i)
end Arithmetic
end ProgMeasurable
theorem progMeasurable_of_tendsto' {γ} [MeasurableSpace ι] [PseudoMetrizableSpace β]
(fltr : Filter γ) [fltr.NeBot] [fltr.IsCountablyGenerated] {U : γ → ι → Ω → β}
(h : ∀ l, ProgMeasurable f (U l)) (h_tendsto : Tendsto U fltr (𝓝 u)) : ProgMeasurable f u := by
intro i
apply @stronglyMeasurable_of_tendsto (Set.Iic i × Ω) β γ
(MeasurableSpace.prod _ (f i)) _ _ fltr _ _ _ _ fun l => h l i
rw [tendsto_pi_nhds] at h_tendsto ⊢
intro x
specialize h_tendsto x.fst
rw [tendsto_nhds] at h_tendsto ⊢
exact fun s hs h_mem => h_tendsto {g | g x.snd ∈ s} (hs.preimage (continuous_apply x.snd)) h_mem
theorem progMeasurable_of_tendsto [MeasurableSpace ι] [PseudoMetrizableSpace β] {U : ℕ → ι → Ω → β}
(h : ∀ l, ProgMeasurable f (U l)) (h_tendsto : Tendsto U atTop (𝓝 u)) : ProgMeasurable f u :=
progMeasurable_of_tendsto' atTop h h_tendsto
/-- A continuous and adapted process is progressively measurable. -/
theorem Adapted.progMeasurable_of_continuous [TopologicalSpace ι] [MetrizableSpace ι]
[SecondCountableTopology ι] [MeasurableSpace ι] [OpensMeasurableSpace ι]
[PseudoMetrizableSpace β] (h : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) :
ProgMeasurable f u := fun i =>
@stronglyMeasurable_uncurry_of_continuous_of_stronglyMeasurable _ _ (Set.Iic i) _ _ _ _ _ _ _
(f i) _ (fun ω => (hu_cont ω).comp continuous_induced_dom) fun j => (h j).mono (f.mono j.prop)
/-- For filtrations indexed by a discrete order, `Adapted` and `ProgMeasurable` are equivalent.
This lemma provides `Adapted f u → ProgMeasurable f u`.
See `ProgMeasurable.adapted` for the reverse direction, which is true more generally. -/
theorem Adapted.progMeasurable_of_discrete [TopologicalSpace ι] [DiscreteTopology ι]
[SecondCountableTopology ι] [MeasurableSpace ι] [OpensMeasurableSpace ι]
[PseudoMetrizableSpace β] (h : Adapted f u) : ProgMeasurable f u :=
h.progMeasurable_of_continuous fun _ => continuous_of_discreteTopology
-- this dot notation will make more sense once we have a more general definition for predictable
theorem Predictable.adapted {f : Filtration ℕ m} {u : ℕ → Ω → β} (hu : Adapted f fun n => u (n + 1))
(hu0 : StronglyMeasurable[f 0] (u 0)) : Adapted f u := fun n =>
match n with
| 0 => hu0
| n + 1 => (hu n).mono (f.mono n.le_succ)
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/Filtration.lean | import Mathlib.MeasureTheory.Constructions.Cylinders
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real
import Mathlib.MeasureTheory.MeasurableSpace.PreorderRestrict
/-!
# Filtrations
This file defines filtrations of a measurable space and σ-finite filtrations.
## Main definitions
* `MeasureTheory.Filtration`: a filtration on a measurable space. That is, a monotone sequence of
sub-σ-algebras.
* `MeasureTheory.SigmaFiniteFiltration`: a filtration `f` is σ-finite with respect to a measure
`μ` if for all `i`, `μ.trim (f.le i)` is σ-finite.
* `MeasureTheory.Filtration.natural`: the smallest filtration that makes a process adapted. That
notion `adapted` is not defined yet in this file. See `MeasureTheory.adapted`.
## Main results
* `MeasureTheory.Filtration.instCompleteLattice`: filtrations are a complete lattice.
## Tags
filtration, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
/-- A `Filtration` on a measurable space `Ω` with σ-algebra `m` is a monotone
sequence of sub-σ-algebras of `m`. -/
structure Filtration {Ω : Type*} (ι : Type*) [Preorder ι] (m : MeasurableSpace Ω) where
/-- The sequence of sub-σ-algebras of `m` -/
seq : ι → MeasurableSpace Ω
mono' : Monotone seq
le' : ∀ i : ι, seq i ≤ m
attribute [coe] Filtration.seq
variable {Ω ι : Type*} {m : MeasurableSpace Ω}
instance [Preorder ι] : CoeFun (Filtration ι m) fun _ => ι → MeasurableSpace Ω :=
⟨fun f => f.seq⟩
namespace Filtration
variable [Preorder ι]
protected theorem mono {i j : ι} (f : Filtration ι m) (hij : i ≤ j) : f i ≤ f j :=
f.mono' hij
protected theorem le (f : Filtration ι m) (i : ι) : f i ≤ m :=
f.le' i
@[ext]
protected theorem ext {f g : Filtration ι m} (h : (f : ι → MeasurableSpace Ω) = g) : f = g := by
cases f; cases g; congr
variable (ι) in
/-- The constant filtration which is equal to `m` for all `i : ι`. -/
def const (m' : MeasurableSpace Ω) (hm' : m' ≤ m) : Filtration ι m :=
⟨fun _ => m', monotone_const, fun _ => hm'⟩
@[simp]
theorem const_apply {m' : MeasurableSpace Ω} {hm' : m' ≤ m} (i : ι) : const ι m' hm' i = m' :=
rfl
instance : Inhabited (Filtration ι m) :=
⟨const ι m le_rfl⟩
instance : LE (Filtration ι m) :=
⟨fun f g => ∀ i, f i ≤ g i⟩
instance : Bot (Filtration ι m) :=
⟨const ι ⊥ bot_le⟩
instance : Top (Filtration ι m) :=
⟨const ι m le_rfl⟩
instance : Max (Filtration ι m) :=
⟨fun f g =>
{ seq := fun i => f i ⊔ g i
mono' := fun _ _ hij =>
sup_le ((f.mono hij).trans le_sup_left) ((g.mono hij).trans le_sup_right)
le' := fun i => sup_le (f.le i) (g.le i) }⟩
@[norm_cast]
theorem coeFn_sup {f g : Filtration ι m} : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
instance : Min (Filtration ι m) :=
⟨fun f g =>
{ seq := fun i => f i ⊓ g i
mono' := fun _ _ hij =>
le_inf (inf_le_left.trans (f.mono hij)) (inf_le_right.trans (g.mono hij))
le' := fun i => inf_le_left.trans (f.le i) }⟩
@[norm_cast]
theorem coeFn_inf {f g : Filtration ι m} : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
instance : SupSet (Filtration ι m) :=
⟨fun s =>
{ seq := fun i => sSup ((fun f : Filtration ι m => f i) '' s)
mono' := fun i j hij => by
refine sSup_le fun m' hm' => ?_
rw [Set.mem_image] at hm'
obtain ⟨f, hf_mem, hfm'⟩ := hm'
rw [← hfm']
refine (f.mono hij).trans ?_
have hfj_mem : f j ∈ (fun g : Filtration ι m => g j) '' s := ⟨f, hf_mem, rfl⟩
exact le_sSup hfj_mem
le' := fun i => by
refine sSup_le fun m' hm' => ?_
rw [Set.mem_image] at hm'
obtain ⟨f, _, hfm'⟩ := hm'
rw [← hfm']
exact f.le i }⟩
theorem sSup_def (s : Set (Filtration ι m)) (i : ι) :
sSup s i = sSup ((fun f : Filtration ι m => f i) '' s) :=
rfl
open scoped Classical in
noncomputable instance : InfSet (Filtration ι m) :=
⟨fun s =>
{ seq := fun i => if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m
mono' := fun i j hij => by
by_cases h_nonempty : Set.Nonempty s
swap; · simp only [h_nonempty, if_false, le_refl]
simp only [h_nonempty, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
refine fun f hf_mem => le_trans ?_ (f.mono hij)
have hfi_mem : f i ∈ (fun g : Filtration ι m => g i) '' s := ⟨f, hf_mem, rfl⟩
exact sInf_le hfi_mem
le' := fun i => by
by_cases h_nonempty : Set.Nonempty s
swap; · simp only [h_nonempty, if_false, le_refl]
simp only [h_nonempty, if_true]
obtain ⟨f, hf_mem⟩ := h_nonempty
exact le_trans (sInf_le ⟨f, hf_mem, rfl⟩) (f.le i) }⟩
open scoped Classical in
theorem sInf_def (s : Set (Filtration ι m)) (i : ι) :
sInf s i = if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m :=
rfl
noncomputable instance instCompleteLattice : CompleteLattice (Filtration ι m) where
le_refl _ _ := le_rfl
le_trans _ _ _ h_fg h_gh i := (h_fg i).trans (h_gh i)
le_antisymm _ _ h_fg h_gf := Filtration.ext <| funext fun i => (h_fg i).antisymm (h_gf i)
sup := (· ⊔ ·)
le_sup_left _ _ _ := le_sup_left
le_sup_right _ _ _ := le_sup_right
sup_le _ _ _ h_fh h_gh i := sup_le (h_fh i) (h_gh _)
inf := (· ⊓ ·)
inf_le_left _ _ _ := inf_le_left
inf_le_right _ _ _ := inf_le_right
le_inf _ _ _ h_fg h_fh i := le_inf (h_fg i) (h_fh i)
le_sSup _ f hf_mem _ := le_sSup ⟨f, hf_mem, rfl⟩
sSup_le s f h_forall i :=
sSup_le fun m' hm' => by
obtain ⟨g, hg_mem, hfm'⟩ := hm'
rw [← hfm']
exact h_forall g hg_mem i
sInf_le s f hf_mem i := by
have hs : s.Nonempty := ⟨f, hf_mem⟩
simp only [sInf_def, hs, if_true]
exact sInf_le ⟨f, hf_mem, rfl⟩
le_sInf s f h_forall i := by
by_cases hs : s.Nonempty
swap; · simp only [sInf_def, hs, if_false]; exact f.le i
simp only [sInf_def, hs, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
exact fun g hg_mem => h_forall g hg_mem i
le_top f i := f.le' i
bot_le _ _ := bot_le
end Filtration
theorem measurableSet_of_filtration [Preorder ι] {f : Filtration ι m} {s : Set Ω} {i : ι}
(hs : MeasurableSet[f i] s) : MeasurableSet[m] s :=
f.le i s hs
/-- A measure is σ-finite with respect to filtration if it is σ-finite with respect
to all the sub-σ-algebra of the filtration. -/
class SigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m) : Prop where
SigmaFinite : ∀ i : ι, SigmaFinite (μ.trim (f.le i))
instance sigmaFinite_of_sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m)
[hf : SigmaFiniteFiltration μ f] (i : ι) : SigmaFinite (μ.trim (f.le i)) :=
hf.SigmaFinite _
instance (priority := 100) IsFiniteMeasure.sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω)
(f : Filtration ι m) [IsFiniteMeasure μ] : SigmaFiniteFiltration μ f :=
⟨fun n => by infer_instance⟩
/-- Given an integrable function `g`, the conditional expectations of `g` with respect to a
filtration is uniformly integrable. -/
theorem Integrable.uniformIntegrable_condExp_filtration [Preorder ι] {μ : Measure Ω}
[IsFiniteMeasure μ] {f : Filtration ι m} {g : Ω → ℝ} (hg : Integrable g μ) :
UniformIntegrable (fun i => μ[g|f i]) 1 μ :=
hg.uniformIntegrable_condExp f.le
theorem Filtration.condExp_condExp [Preorder ι] {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] (f : Ω → E) {μ : Measure Ω} (ℱ : Filtration ι m)
{i j : ι} (hij : i ≤ j) [SigmaFinite (μ.trim (ℱ.le j))] :
μ[μ[f|ℱ j]|ℱ i] =ᵐ[μ] μ[f|ℱ i] := condExp_condExp_of_le (ℱ.mono hij) (ℱ.le j)
section OfSet
variable [Preorder ι]
/-- Given a sequence of measurable sets `(sₙ)`, `filtrationOfSet` is the smallest filtration
such that `sₙ` is measurable with respect to the `n`-th sub-σ-algebra in `filtrationOfSet`. -/
def filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet (s i)) : Filtration ι m where
seq i := MeasurableSpace.generateFrom {t | ∃ j ≤ i, s j = t}
mono' _ _ hnm := MeasurableSpace.generateFrom_mono fun _ ⟨k, hk₁, hk₂⟩ => ⟨k, hk₁.trans hnm, hk₂⟩
le' _ := MeasurableSpace.generateFrom_le fun _ ⟨k, _, hk₂⟩ => hk₂ ▸ hsm k
theorem measurableSet_filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) (i : ι)
{j : ι} (hj : j ≤ i) : MeasurableSet[filtrationOfSet hsm i] (s j) :=
MeasurableSpace.measurableSet_generateFrom ⟨j, hj, rfl⟩
theorem measurableSet_filtrationOfSet' {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet[m] (s n))
(i : ι) : MeasurableSet[filtrationOfSet hsm i] (s i) :=
measurableSet_filtrationOfSet hsm i le_rfl
end OfSet
namespace Filtration
variable {β : ι → Type*} [∀ i, TopologicalSpace (β i)] [∀ i, MetrizableSpace (β i)]
[mβ : ∀ i, MeasurableSpace (β i)] [∀ i, BorelSpace (β i)]
[Preorder ι]
/-- Given a sequence of functions, the natural filtration is the smallest sequence
of σ-algebras such that the sequence of functions is measurable with respect to
the filtration. -/
def natural (u : (i : ι) → Ω → β i) (hum : ∀ i, StronglyMeasurable (u i)) : Filtration ι m where
seq i := ⨆ j ≤ i, MeasurableSpace.comap (u j) (mβ j)
mono' _ _ hij := biSup_mono fun _ => ge_trans hij
le' i := by
refine iSup₂_le ?_
rintro j _ s ⟨t, ht, rfl⟩
exact (hum j).measurable ht
section
open MeasurableSpace
theorem filtrationOfSet_eq_natural [∀ i, MulZeroOneClass (β i)] [∀ i, Nontrivial (β i)]
{s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) :
filtrationOfSet hsm = natural (fun i => (s i).indicator (fun _ => 1 : Ω → β i)) fun i =>
stronglyMeasurable_one.indicator (hsm i) := by
simp only [filtrationOfSet, natural, measurableSpace_iSup_eq, exists_prop, mk.injEq]
ext1 i
refine le_antisymm (generateFrom_le ?_) (generateFrom_le ?_)
· rintro _ ⟨j, hij, rfl⟩
refine measurableSet_generateFrom ⟨j, measurableSet_generateFrom ⟨hij, ?_⟩⟩
rw [comap_eq_generateFrom]
refine measurableSet_generateFrom ⟨{1}, measurableSet_singleton 1, ?_⟩
ext x
simp
· rintro t ⟨n, ht⟩
suffices MeasurableSpace.generateFrom {t | n ≤ i ∧
MeasurableSet[MeasurableSpace.comap ((s n).indicator (fun _ => 1 : Ω → β n)) (mβ n)] t} ≤
MeasurableSpace.generateFrom {t | ∃ (j : ι), j ≤ i ∧ s j = t} by
exact this _ ht
refine generateFrom_le ?_
rintro t ⟨hn, u, _, hu'⟩
obtain heq | heq | heq | heq := Set.indicator_const_preimage (s n) u (1 : β n)
on_goal 4 => rw [Set.mem_singleton_iff] at heq
all_goals rw [heq] at hu'; rw [← hu']
exacts [MeasurableSet.univ, measurableSet_generateFrom ⟨n, hn, rfl⟩,
MeasurableSet.compl (measurableSet_generateFrom ⟨n, hn, rfl⟩), measurableSet_empty _]
end
section Limit
variable {E : Type*} [Zero E] [TopologicalSpace E] {ℱ : Filtration ι m} {f : ι → Ω → E}
{μ : Measure Ω}
open scoped Classical in
/-- Given a process `f` and a filtration `ℱ`, if `f` converges to some `g` almost everywhere and
`g` is `⨆ n, ℱ n`-measurable, then `limitProcess f ℱ μ` chooses said `g`, else it returns 0.
This definition is used to phrase the a.e. martingale convergence theorem
`Submartingale.ae_tendsto_limitProcess` where an L¹-bounded submartingale `f` adapted to `ℱ`
converges to `limitProcess f ℱ μ` `μ`-almost everywhere. -/
noncomputable def limitProcess (f : ι → Ω → E) (ℱ : Filtration ι m)
(μ : Measure Ω) :=
if h : ∃ g : Ω → E,
StronglyMeasurable[⨆ n, ℱ n] g ∧ ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) then
Classical.choose h else 0
theorem stronglyMeasurable_limitProcess : StronglyMeasurable[⨆ n, ℱ n] (limitProcess f ℱ μ) := by
rw [limitProcess]
split_ifs with h
exacts [(Classical.choose_spec h).1, stronglyMeasurable_zero]
theorem stronglyMeasurable_limit_process' : StronglyMeasurable[m] (limitProcess f ℱ μ) :=
stronglyMeasurable_limitProcess.mono (sSup_le fun _ ⟨_, hn⟩ => hn ▸ ℱ.le _)
theorem memLp_limitProcess_of_eLpNorm_bdd {R : ℝ≥0} {p : ℝ≥0∞} {F : Type*} [NormedAddCommGroup F]
{ℱ : Filtration ℕ m} {f : ℕ → Ω → F} (hfm : ∀ n, AEStronglyMeasurable (f n) μ)
(hbdd : ∀ n, eLpNorm (f n) p μ ≤ R) : MemLp (limitProcess f ℱ μ) p μ := by
rw [limitProcess]
split_ifs with h
· refine ⟨StronglyMeasurable.aestronglyMeasurable
((Classical.choose_spec h).1.mono (sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _)),
lt_of_le_of_lt (Lp.eLpNorm_lim_le_liminf_eLpNorm hfm _ (Classical.choose_spec h).2)
(lt_of_le_of_lt ?_ (ENNReal.coe_lt_top : ↑R < ∞))⟩
simp_rw [liminf_eq, eventually_atTop]
exact sSup_le fun b ⟨a, ha⟩ => (ha a le_rfl).trans (hbdd _)
· exact MemLp.zero
end Limit
section piLE
/-! ### Filtration of the first events -/
open MeasurableSpace Preorder
variable {X : ι → Type*} [∀ i, MeasurableSpace (X i)]
/-- The canonical filtration on the product space `Π i, X i`, where `piLE i`
consists of measurable sets depending only on coordinates `≤ i`. -/
def piLE : @Filtration (Π i, X i) ι _ pi where
seq i := pi.comap (restrictLe i)
mono' i j hij := by
simp only
rw [← restrictLe₂_comp_restrictLe hij, ← comap_comp]
exact comap_mono (measurable_restrictLe₂ _).comap_le
le' i := (measurable_restrictLe i).comap_le
variable [LocallyFiniteOrderBot ι]
lemma piLE_eq_comap_frestrictLe (i : ι) : piLE (X := X) i = pi.comap (frestrictLe i) := by
apply le_antisymm
· simp_rw [piLE, ← piCongrLeft_comp_frestrictLe, ← MeasurableEquiv.coe_piCongrLeft, ← comap_comp]
exact MeasurableSpace.comap_mono <| Measurable.comap_le (by fun_prop)
· rw [← piCongrLeft_comp_restrictLe, ← MeasurableEquiv.coe_piCongrLeft, ← comap_comp]
exact MeasurableSpace.comap_mono <| Measurable.comap_le (by fun_prop)
end piLE
section piFinset
open MeasurableSpace Finset
variable {ι : Type*} {X : ι → Type*} [∀ i, MeasurableSpace (X i)]
/-- The filtration of events which only depends on finitely many coordinates
on the product space `Π i, X i`, `piFinset s` consists of measurable sets depending only on
coordinates in `s`, where `s : Finset ι`. -/
def piFinset : @Filtration (Π i, X i) (Finset ι) _ pi where
seq s := pi.comap s.restrict
mono' s t hst := by
simp only
rw [← restrict₂_comp_restrict hst, ← comap_comp]
exact comap_mono (measurable_restrict₂ hst).comap_le
le' s := s.measurable_restrict.comap_le
lemma piFinset_eq_comap_restrict (s : Finset ι) :
piFinset (X := X) s = pi.comap (s : Set ι).restrict := rfl
end piFinset
variable {α : Type*}
/-- The exterior σ-algebras of finite sets of `α` form a cofiltration indexed by `Finset α`. -/
def cylinderEventsCompl : Filtration (Finset α)ᵒᵈ (.pi (X := fun _ : α ↦ Ω)) where
seq Λ := cylinderEvents (↑(OrderDual.ofDual Λ))ᶜ
mono' _ _ h := cylinderEvents_mono <| Set.compl_subset_compl_of_subset h
le' _ := cylinderEvents_le_pi
end Filtration
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/Stopping.lean | import Mathlib.Probability.Process.Adapted
import Mathlib.MeasureTheory.Constructions.BorelSpace.WithTop
/-!
# Stopping times, stopped processes and stopped values
Definition and properties of stopping times.
## Main definitions
* `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` on a
measurable space `Ω` is a function `τ : Ω → WithTop ι` such that for all `i : ι`,
the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable
* `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time
## Main results
* `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is
progressively measurable.
* `memLp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped
process belongs to `ℒp` as well.
## Implementation notes
For a filtration on a type `ι`, we define stopping times as functions from the measurable space `Ω`
to `WithTop ι`, which allows stopping times that can take an infinite value, represented by
`⊤ : WithTop ι`.
This means that if we have a process `X : ι → Ω → β` and a stopping time `τ : Ω → WithTop ι`, then
to consider the value of `X` at the stopping time `τ ω`, we need to write `X (τ ω).untopA ω`,
in which `(τ ω).untopA` is the value of `τ ω` in `ι` if `τ ω ≠ ⊤` and some arbitrary value if
`τ ω = ⊤`.
While indexing would be more convenient if we defined stopping times as functions from `Ω` to `ι`,
this would prevent us from using stopping times as in standard mathematical literature, where a
typical example of stopping time is the first time an event occurs, which may never happen.
Consider for example the first time a coin lands heads when flipping it infinitely many times:
this is almost surely finite, but possibly infinite. We could also not use a function `Ω → ι` with
arbitrary value for the infinite case, because this would be incompatible with the stopping time
property.
## Tags
stopping time, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ω β ι : Type*} {m : MeasurableSpace Ω}
/-! ### Stopping times -/
/-- A stopping time with respect to some filtration `f` is a function
`τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable
with respect to `f i`.
Intuitively, the stopping time `τ` describes some stopping rule such that at time
`i`, we may determine it with the information we have at time `i`. -/
def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → WithTop ι) :=
∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i}
theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) :
IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const]
section MeasurableSet
section Preorder
variable [Preorder ι] {f : Filtration ι m} {τ : Ω → WithTop ι}
protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω ≤ i} :=
hτ i
theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω < i} := by
by_cases hi_min : IsMin i
· suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 ω
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
rw [isMin_iff_forall_not_lt] at hi_min
cases τ ω with
| top => simp
| coe t => exact mod_cast hi_min t
have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i : ι) := by
ext ω
simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iic]
cases τ ω with
| top => simp
| coe t =>
simp only [WithTop.coe_lt_coe, WithTop.coe_le_coe]
rw [le_pred_iff_of_not_isMin hi_min]
rw [this]
exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i)
end Preorder
section CountableStoppingTime
namespace IsStoppingTime
variable [PartialOrder ι] {τ : Ω → WithTop ι} {f : Filtration ι m}
protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ)
(h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by
have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by
ext1 a
simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq',
Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and]
constructor <;> intro h
· simp only [h, lt_iff_le_not_ge, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff]
· exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl
rw [this]
refine (hτ.measurableSet_le i).diff ?_
refine MeasurableSet.biUnion h_countable fun j _ => ?_
classical
rw [Set.iUnion_eq_if]
split_ifs with hji
· lift j to ι using (ne_top_of_lt hji)
exact f.mono (mod_cast hji.le) _ (hτ.measurableSet_le j)
· exact @MeasurableSet.empty _ (f i)
protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω = i} :=
hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ)
(h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by
have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne]
rw [this]
exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i)
protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω < i} :=
hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → WithTop ι}
{f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) :
MeasurableSet[f i] {ω | i ≤ τ ω} := by
have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by
ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl
protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → WithTop ι}
{f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | i ≤ τ ω} :=
hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i
end IsStoppingTime
end CountableStoppingTime
section LinearOrder
variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → WithTop ι}
theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | i < τ ω} := by
have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by
ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le]
rw [this]
exact (hτ.measurableSet_le i).compl
section TopologicalSpace
variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι]
/-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/
theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι)
(h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by
by_cases hi_min : IsMin i
· suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 ω
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
cases τ ω with
| top => simp
| coe t => norm_cast; exact isMin_iff_forall_not_lt.mp hi_min t
obtain ⟨seq, -, -, h_tendsto, h_bound⟩ :
∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i :=
h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min)
have h_Iio_eq_Union : Set.Iio (i : WithTop ι) = ⋃ j, {k : WithTop ι | k ≤ seq j} := by
ext1 k
simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq]
refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩
· rw [tendsto_atTop'] at h_tendsto
cases k with
| top => simp at hk_lt_i
| coe k =>
norm_cast at hk_lt_i ⊢
have h_nhds : Set.Ici k ∈ 𝓝 i :=
mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩
obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds
exact ⟨a, ha a le_rfl⟩
· obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq
exact hk_seq_j.trans_lt (mod_cast h_bound j)
have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by
ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio]
rw [h_lt_eq_preimage, h_Iio_eq_Union]
simp only [Set.preimage_iUnion, Set.preimage_setOf_eq]
exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n))
theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω < i} := by
obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i
rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic
· rw [← hi'_eq_i] at hi'_lub ⊢
exact hτ.measurableSet_lt_of_isLUB i' hi'_lub
· have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl
have h_Iio_eq_Iic' : Set.Iio (i : WithTop ι) = Set.Iic (i' : WithTop ι) := by
rw [← WithTop.image_coe_Iio, ← WithTop.image_coe_Iic, h_Iio_eq_Iic]
rw [h_lt_eq_preimage, h_Iio_eq_Iic']
exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i')
theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | i ≤ τ ω} := by
have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by
ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hτ.measurableSet_lt i).compl
theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω = i} := by
have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by
ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff]
rw [this]
exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i)
theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) :
MeasurableSet[f j] {ω | τ ω = i} :=
f.mono hle _ <| hτ.measurableSet_eq i
theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) :
MeasurableSet[f j] {ω | τ ω < i} :=
f.mono hle _ <| hτ.measurableSet_lt i
end TopologicalSpace
end LinearOrder
section Countable
theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m}
{τ : Ω → WithTop ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by
intro i
have h_eq_iUnion : {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} := by
ext ω
simp only [Set.mem_setOf_eq, Set.mem_iUnion, exists_prop]
cases τ ω with
| top => simp
| coe a => norm_cast; simp
rw [h_eq_iUnion]
refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_
exact f.mono hk _ (hτ k)
end Countable
end MeasurableSet
namespace IsStoppingTime
protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → WithTop ι}
(hτ : IsStoppingTime f τ)
(hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by
intro i
simp_rw [max_le_iff, Set.setOf_and]
exact (hτ i).inter (hπ i)
protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → WithTop ι}
(hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i :=
hτ.max (isStoppingTime_const f i)
protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → WithTop ι}
(hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
IsStoppingTime f fun ω => min (τ ω) (π ω) := by
intro i
simp_rw [min_le_iff, Set.setOf_or]
exact (hτ i).union (hπ i)
protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → WithTop ι}
(hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i :=
hτ.min (isStoppingTime_const f i)
theorem add_const [AddGroup ι] [Preorder ι] [AddRightMono ι]
[AddLeftMono ι] {f : Filtration ι m} {τ : Ω → WithTop ι} (hτ : IsStoppingTime f τ)
{i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by
intro j
simp only
have h_eq : {ω | τ ω + i ≤ j} = {ω | τ ω ≤ j - i} := by
ext ω
simp only [Set.mem_setOf_eq, WithTop.coe_sub]
cases τ ω with
| top => simp
| coe a => norm_cast; simp_rw [← le_sub_iff_add_le]
rw [h_eq]
exact f.mono (sub_le_self j hi) _ (hτ (j - i))
theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → WithTop ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} :
IsStoppingTime f fun ω => τ ω + i := by
refine isStoppingTime_of_measurableSet_eq fun j => ?_
by_cases! hij : i ≤ j
· simp only [ENat.some_eq_coe]
have h_eq : {ω | τ ω + i = j} = {ω | τ ω = (j - i : ℕ)} := by
ext ω
simp only [Set.mem_setOf_eq]
cases τ ω with
| top => simp
| coe a =>
simp only [ENat.some_eq_coe, Nat.cast_inj]
norm_cast
simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm]
rw [h_eq]
exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i))
· convert @MeasurableSet.empty _ (f.1 j)
ext ω
simp only [Set.mem_empty_iff_false, iff_false, Set.mem_setOf]
cases τ ω with
| top => simp
| coe a => simp only [ENat.some_eq_coe]; norm_cast; cutsat
-- generalize to certain countable type?
theorem add {f : Filtration ℕ m} {τ π : Ω → WithTop ℕ}
(hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
IsStoppingTime f (τ + π) := by
intro i
simp only [ENat.some_eq_coe]
have h : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i} := by
ext ω
simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_and_left,
exists_prop]
cases τ ω with
| top => simp
| coe a =>
cases π ω with
| top => simp
| coe b =>
simp only [ENat.some_eq_coe, Nat.cast_inj, exists_eq_left', iff_and_self]
norm_cast
omega
rw [h]
exact MeasurableSet.iUnion fun k =>
MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i)
section Preorder
variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → WithTop ι}
/-- The associated σ-algebra with a stopping time. -/
protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where
MeasurableSet' s := MeasurableSet s ∧ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i})
measurableSet_empty := by simp
measurableSet_compl s hs := by
refine ⟨hs.1.compl, fun i ↦ ?_⟩
rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})]
· refine MeasurableSet.inter ?_ ?_
· rw [← Set.compl_inter]
exact (hs.2 i).compl
· exact hτ i
· rw [Set.union_inter_distrib_right]
simp only [Set.compl_inter_self, Set.union_empty]
measurableSet_iUnion s hs := by
refine ⟨MeasurableSet.iUnion fun i ↦ (hs i).1, fun i ↦ ?_⟩
replace hs := fun i ↦ (hs i).2
rw [forall_swap] at hs
rw [Set.iUnion_inter]
exact MeasurableSet.iUnion (hs i)
protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) :
MeasurableSet[hτ.measurableSpace] s
↔ MeasurableSet s ∧ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) :=
Iff.rfl
theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) :
hτ.measurableSpace ≤ hπ.measurableSpace := by
refine fun s hs ↦ ⟨hs.1, fun i ↦ ?_⟩
rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})]
· exact (hs.2 i).inter (hπ i)
· ext
simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq]
intro hle' _
exact le_trans (hle _) hle'
theorem measurableSpace_le (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := fun _ hs ↦ hs.1
@[deprecated (since := "2025-09-08")] alias measurableSpace_le_of_countable := measurableSpace_le
@[deprecated (since := "2025-09-08")] alias measurableSpace_le_of_countable_range :=
measurableSpace_le
@[simp]
theorem measurableSpace_const (f : Filtration ι m) (i : ι) :
(isStoppingTime_const f i).measurableSpace = f i := by
ext1 s
change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s
rw [IsStoppingTime.measurableSet]
constructor <;> intro h
· have h' := h.2 i
simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h'
· refine ⟨f.le i _ h, fun j ↦ ?_⟩
by_cases hij : i ≤ j
· norm_cast
simp only [hij, Set.setOf_true, Set.inter_univ]
exact f.mono hij _ h
· norm_cast
simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)]
theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) :
MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔
MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by
have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by
intro j
ext1 ω
simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff]
intro hxi
rw [hxi]
constructor <;> intro h
· simpa [Set.inter_assoc, this] using h.2 i
· refine ⟨f.le i _ h, fun j ↦ ?_⟩
rw [Set.inter_assoc, this]
by_cases hij : i ≤ j
· norm_cast
simp only [hij, Set.setOf_true, Set.inter_univ]
exact f.mono hij _ h
· simp [hij]
theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) :
hτ.measurableSpace ≤ f i :=
(measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le
theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) :
hτ.measurableSpace ≤ m :=
(hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n)
theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) :
f i ≤ hτ.measurableSpace :=
(measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le)
end Preorder
instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι]
{μ : Measure Ω} {f : Filtration ι m}
{τ : Ω → WithTop ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) :
SigmaFinite (μ.trim hτ.measurableSpace_le) := by
refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_
· exact f ⊥
· exact hτ.le_measurableSpace_of_const_le fun _ => bot_le
· infer_instance
instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω}
{f : Filtration ι m} {τ : Ω → WithTop ι} [SigmaFiniteFiltration μ f]
(hτ : IsStoppingTime f τ) {n : ι}
(hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by
refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_
· exact f ⊥
· exact hτ.le_measurableSpace_of_const_le fun _ => bot_le
· infer_instance
section LinearOrder
variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → WithTop ι}
protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by
refine ⟨f.le i _ (hτ i), fun j ↦ ?_⟩
have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by
ext1 ω
simp [Set.mem_inter_iff, Set.mem_setOf_eq]
rw [this]
exact f.mono (min_le_right i j) _ (hτ _)
protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by
have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp
rw [this]
exact (hτ.measurableSet_le' i).compl
protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι]
[FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by
rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter]
exact hτ.measurableSet_eq i
protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι]
[FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by
have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by
ext1 ω
simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union]
cases τ ω with
| top => simp
| coe a =>
norm_cast
rw [@eq_comm _ i, or_comm]
rw [this]
exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i)
protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι]
[FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by
have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by
ext1 ω
simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff]
rw [this]
exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i)
section Countable
protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ)
(h_countable : (Set.range τ).Countable) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by
rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter]
exact hτ.measurableSet_eq_of_countable_range h_countable i
protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} :=
hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i
protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ)
(h_countable : (Set.range τ).Countable) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by
have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by
ext1 ω
simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union]
cases τ ω with
| top => simp
| coe a =>
norm_cast
rw [@eq_comm _ i, or_comm]
rw [this]
exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i)
protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} :=
hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i
protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ)
(h_countable : (Set.range τ).Countable) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by
have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by
ext1 ω
simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff]
rw [this]
exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i)
protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} :=
hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i
end Countable
protected theorem measurable [TopologicalSpace ι]
[OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) :
Measurable[hτ.measurableSpace] τ := by
refine measurable_of_Iic fun i ↦ ?_
cases i with
| top => simp
| coe i => exact hτ.measurableSet_le' i
protected theorem measurable' [TopologicalSpace ι]
[OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) :
Measurable τ := hτ.measurable.mono (measurableSpace_le hτ) le_rfl
protected lemma measurableSet_eq_top [TopologicalSpace ι]
[OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) :
MeasurableSet {ω | τ ω = ⊤} :=
(measurableSet_singleton _).preimage hτ.measurable'
protected theorem measurable_of_le [TopologicalSpace ι]
[OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι}
(hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ :=
hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl
theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
(hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by
refine le_antisymm ?_ ?_
· exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _)
(measurableSpace_mono _ hπ fun _ => min_le_right _ _)
· intro s
change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s →
MeasurableSet[(hτ.min hπ).measurableSpace] s
simp_rw [IsStoppingTime.measurableSet]
have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by
intro i; ext1 ω; simp
simp_rw [this, Set.inter_union_distrib_left]
exact fun h ↦ ⟨h.1.1, fun i ↦ (h.left.2 i).union (h.right.2 i)⟩
theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) :
MeasurableSet[(hτ.min hπ).measurableSpace] s ↔
MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by
rw [measurableSpace_min hτ hπ]; rfl
theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} :
(hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by
rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const]
theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} :
MeasurableSet[(hτ.min_const i).measurableSpace] s ↔
MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by
rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf
theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι]
(hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π)
(s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) :
MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by
simp_rw [IsStoppingTime.measurableSet] at hs ⊢
have h_eq i : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} =
s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩
{ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by
ext ω
by_cases hτi : τ ω ≤ i <;> grind
simp_rw [h_eq]
refine ⟨hs.1.inter (measurableSet_le hτ.measurable' hπ.measurable'), fun i ↦ ?_⟩
refine ((hs.2 i).inter ((hτ.min hπ) i)).inter ?_
apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_
· exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _
· exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _
theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι]
[OrderTopology ι] (hτ : IsStoppingTime f τ)
(hπ : IsStoppingTime f π) (s : Set Ω) :
MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔
MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by
constructor <;> intro h
· have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by
rw [Set.inter_assoc, Set.inter_self]
rw [this]
exact measurableSet_inter_le _ hπ _ h
· rw [measurableSet_min_iff hτ hπ] at h
exact h.1
theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) :
MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔
MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by
rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i),
IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet]
refine ⟨fun h => ⟨h, ?_⟩, fun h ↦ h.1⟩
have h' := h.2 i
rwa [Set.inter_assoc, Set.inter_self] at h'
theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι]
[OrderTopology ι] (hτ : IsStoppingTime f τ)
(hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by
rw [hτ.measurableSet]
refine ⟨measurableSet_le hτ.measurable' hπ.measurable', fun j ↦ ?_⟩
have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by
ext1 ω
simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl,
and_congr_left_iff]
intro h
simp only [h, or_self_iff, and_true]
rw [Iff.comm, or_iff_left_iff_imp]
exact h.trans
rw [this]
refine MeasurableSet.inter ?_ (hτ.measurableSet_le j)
apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_
· exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _
· exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _
theorem measurableSet_stopping_time_le_min [TopologicalSpace ι] [SecondCountableTopology ι]
[OrderTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
MeasurableSet[(hτ.min hπ).measurableSpace] {ω | τ ω ≤ π ω} := by
rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter]
exact measurableSet_le_stopping_time hτ hπ
theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι]
[OrderTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by
have : MeasurableSet[(hτ.min hπ).measurableSpace] {ω | τ ω ≤ π ω} :=
measurableSet_stopping_time_le_min hτ hπ
rw [measurableSet_min_iff hτ hπ] at this; exact (this).2
theorem measurableSet_eq_stopping_time_min [TopologicalSpace ι]
[OrderTopology ι] [SecondCountableTopology ι]
(hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
MeasurableSet[(hτ.min hπ).measurableSpace] {ω | τ ω = π ω} := by
have : {ω | τ ω = π ω} = {ω | τ ω ≤ π ω} ∩ {ω | π ω ≤ τ ω} := by
ext; simp only [Set.mem_setOf_eq, le_antisymm_iff, Set.mem_inter_iff]
rw [this]
refine MeasurableSet.inter (measurableSet_stopping_time_le_min hτ hπ) ?_
convert (measurableSet_stopping_time_le_min hπ hτ) using 3
rw [min_comm]
theorem measurableSet_eq_stopping_time [TopologicalSpace ι] [OrderTopology ι]
[SecondCountableTopology ι]
(hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) :
MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by
have h := measurableSet_eq_stopping_time_min hτ hπ
rw [measurableSet_min_iff hτ hπ] at h
exact h.1
@[deprecated (since := "2025-09-08")] alias measurableSet_eq_stopping_time_of_countable :=
measurableSet_eq_stopping_time
end LinearOrder
end IsStoppingTime
section LinearOrder
/-! ## Stopped value and stopped process -/
variable [Nonempty ι]
/-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping
time `τ` is the map `x ↦ u (τ ω) ω`. -/
noncomputable
def stoppedValue (u : ι → Ω → β) (τ : Ω → WithTop ι) : Ω → β := fun ω => u (τ ω).untopA ω
theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i :=
rfl
variable [LinearOrder ι]
/-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if
`i ≤ τ ω`, and `u (τ ω) ω` otherwise.
Intuitively, the stopped process stops evolving once the stopping time has occurred. -/
noncomputable
def stoppedProcess (u : ι → Ω → β) (τ : Ω → WithTop ι) : ι → Ω → β :=
fun i ω => u (min (i : WithTop ι) (τ ω)).untopA ω
theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → WithTop ι} :
stoppedProcess u τ = fun i : ι => stoppedValue u fun ω => min i (τ ω) := rfl
theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → WithTop ι} :
stoppedValue (stoppedProcess u τ) σ =
fun ω ↦ if σ ω ≠ ⊤ then stoppedValue u (fun ω ↦ min (σ ω) (τ ω)) ω
else stoppedValue u (fun ω ↦ min (Classical.arbitrary ι) (τ ω)) ω := by
ext ω
simp only [stoppedValue, stoppedProcess, ne_eq, ite_not]
cases σ ω <;> cases τ ω <;> simp
theorem stoppedValue_stoppedProcess_ae_eq {u : ι → Ω → β} {τ σ : Ω → WithTop ι} {μ : Measure Ω}
(hσ : ∀ᵐ ω ∂μ, σ ω ≠ ⊤) :
stoppedValue (stoppedProcess u τ) σ =ᵐ[μ] stoppedValue u (fun ω ↦ min (σ ω) (τ ω)) := by
filter_upwards [hσ] with ω hσ using by simp [stoppedValue_stoppedProcess, hσ]
theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → WithTop ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) :
stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h]
theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → WithTop ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) :
stoppedProcess u τ i ω = u (τ ω).untopA ω := by simp [stoppedProcess, min_eq_right h]
section ProgMeasurable
variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι]
[BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → WithTop ι} {f : Filtration ι m}
theorem progMeasurable_min_stopping_time [PseudoMetrizableSpace ι] (hτ : IsStoppingTime f τ) :
ProgMeasurable f fun i ω ↦ (min (i : WithTop ι) (τ ω)).untopA := by
refine fun i ↦ (Measurable.untopA ?_).stronglyMeasurable
let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i)
let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ =>
@Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod
let s := {p : Set.Iic i × Ω | τ p.2 ≤ i}
have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i)
have h_meas_fst : ∀ t : Set (Set.Iic i × Ω),
Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) :=
fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val
refine measurable_of_restrict_of_restrict_compl hs ?_ ?_
· refine Measurable.min (h_meas_fst s).withTop_coe ?_
refine measurable_of_Iic fun j ↦ ?_
cases j with
| top => simp
| coe j =>
have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j =
(fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by
ext1 ω
simp only [Set.mem_preimage, Set.mem_Iic, WithTop.coe_min, le_inf_iff,
Set.preimage_setOf_eq, Set.mem_setOf_eq, iff_and_self]
exact fun _ => ω.prop
rw [h_set_eq]
suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from
h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j)))
exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _)
· letI sc := sᶜ
suffices h_min_eq_left :
(fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc =>
↑(x : Set.Iic i × Ω).fst by
simp +unfoldPartialApp only [sc, Set.restrict, h_min_eq_left]
exact (h_meas_fst _).withTop_coe
ext1 ω
rw [min_eq_left]
have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop
by_cases h : τ (ω : Set.Iic i × Ω).2 = ⊤
· simp [h]
· lift τ (ω : Set.Iic i × Ω).2 to ι using h with t ht
norm_cast
refine hx_fst_le.trans (le_of_lt ?_)
convert ω.prop
simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq, ← ht]
norm_cast
theorem ProgMeasurable.stoppedProcess [PseudoMetrizableSpace ι] (h : ProgMeasurable f u)
(hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) := by
have h_meas := progMeasurable_min_stopping_time hτ
refine h.comp h_meas fun i ω ↦ ?_
cases τ ω with
| top => simp
| coe t =>
rcases le_total i t with h_it | h_ti
· simp [(mod_cast h_it : (i : WithTop ι) ≤ t)]
· simpa [(mod_cast h_ti : t ≤ (i : WithTop ι))]
theorem ProgMeasurable.adapted_stoppedProcess [PseudoMetrizableSpace ι] (h : ProgMeasurable f u)
(hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) :=
(h.stoppedProcess hτ).adapted
theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [PseudoMetrizableSpace ι]
(hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) :=
(hu.adapted_stoppedProcess hτ i).mono (f.le _)
theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ)
{n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by
have hτ_le' ω : (τ ω).untopA ≤ n := WithTop.untopA_le (hτ_le ω)
have : stoppedValue u τ =
(fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨(τ ω).untopA, hτ_le' ω⟩, ω) := by
ext1 ω; simp only [stoppedValue, Function.comp_apply]
rw [this]
refine StronglyMeasurable.comp_measurable (h n) ?_
refine (Measurable.subtype_mk ?_).prodMk measurable_id
exact (hτ.measurable_of_le hτ_le).untopA
lemma measurableSet_preimage_stoppedValue_inter [PseudoMetrizableSpace β] [MeasurableSpace β]
[BorelSpace β]
(hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ)
{t : Set β} (ht : MeasurableSet t) (i : ι) :
MeasurableSet[f i] (stoppedValue u τ ⁻¹' t ∩ {ω | τ ω ≤ i}) := by
have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i =>
stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _
suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} =
(stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by
rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i)
ext1 ω
simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq,
and_congr_left_iff]
intro h
rw [min_eq_left h]
theorem measurable_stoppedValue [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) :
Measurable[hτ.measurableSpace] (stoppedValue u τ) := by
have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i =>
stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _
intro t ht
refine ⟨?_, fun i ↦ measurableSet_preimage_stoppedValue_inter hf_prog hτ ht i⟩
obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto
have : stoppedValue u τ ⁻¹' t
= (⋃ n, stoppedValue u τ ⁻¹' t ∩ {ω | τ ω ≤ seq n})
∪ (stoppedValue u τ ⁻¹' t ∩ {ω | τ ω = ⊤}) := by
ext1 ω
simp only [Set.mem_preimage, Set.mem_union, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq,
exists_and_left]
rw [← and_or_left, iff_self_and]
intro _
by_cases h : τ ω = ⊤
· exact .inr h
· lift τ ω to ι using h with t
simp only [WithTop.coe_le_coe, WithTop.coe_ne_top, or_false]
rw [tendsto_atTop] at h_seq_tendsto
exact (h_seq_tendsto t).exists
rw [this]
refine MeasurableSet.union ?_ ?_
· exact MeasurableSet.iUnion fun i ↦ f.le (seq i) _
(measurableSet_preimage_stoppedValue_inter hf_prog hτ ht (seq i))
· have : stoppedValue u τ ⁻¹' t ∩ {ω | τ ω = ⊤}
= (fun ω ↦ u (Classical.arbitrary ι) ω) ⁻¹' t ∩ {ω | τ ω = ⊤} := by
ext ω
simp only [Set.mem_inter_iff, Set.mem_preimage, stoppedValue, WithTop.untopA,
Set.mem_setOf_eq, and_congr_left_iff]
intro h
simp [h]
rw [this]
refine MeasurableSet.inter (ht.preimage ?_) hτ.measurableSet_eq_top
exact (hf_prog.adapted (Classical.arbitrary ι)).measurable.mono
(f.le (Classical.arbitrary ι)) le_rfl
end ProgMeasurable
end LinearOrder
section StoppedValueOfMemFinset
variable [Nonempty ι] {μ : Measure Ω} {τ : Ω → WithTop ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E}
theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι}
(hbdd : ∀ ω, τ ω ∈ (WithTop.some '' s)) :
stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by
ext y
classical
rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter]
suffices {i ∈ s | y ∈ {ω : Ω | τ ω = (i : ι)}} = ({(τ y).untopA} : Finset ι) by
rw [this, Finset.sum_singleton]
ext1 ω
simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton]
constructor <;> intro h
· simp [h.2]
· simp only [h]
specialize hbdd y
have : τ y ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at hbdd
lift τ y to ι using this with i hi
simpa using hbdd
theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι}
(hbdd : ∀ ω, τ ω ≤ N) :
stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) := by
refine stoppedValue_eq_of_mem_finset fun ω ↦ ?_
simp only [Finset.coe_Iic, Set.mem_image]
specialize hbdd ω
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at hbdd
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast hbdd, rfl⟩
theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι)
(hbdd : ∀ ω, τ ω < n → τ ω ∈ WithTop.some '' s) :
stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ s with i < n, Set.indicator {ω | τ ω = i} (u i) := by
ext ω
rw [Pi.add_apply, Finset.sum_apply]
rcases le_or_gt (n : WithTop ι) (τ ω) with h | h
· rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero]
· intro m hm
refine Set.indicator_of_notMem ?_ _
rw [Finset.mem_filter] at hm
simp only [Set.mem_setOf_eq]
refine (lt_of_lt_of_le ?_ h).ne'
exact mod_cast hm.2
· exact h
· rw [stoppedProcess_eq_of_ge (le_of_lt h)]
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at h
specialize hbdd ω h
lift τ ω to ι using h_top with i hi
rw [Finset.sum_eq_single_of_mem i]
· simp only [WithTop.untopD_coe]
rw [Set.indicator_of_notMem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf]
· exact hi.symm
· rw [← hi]
exact not_le.2 h
· rw [Finset.mem_filter]
simp only [Set.mem_image, Finset.mem_coe, WithTop.coe_eq_coe, exists_eq_right] at hbdd
exact ⟨hbdd, mod_cast h⟩
· intro b _ hneq
rw [Set.indicator_of_notMem]
rw [Set.mem_setOf, ← hi]
exact mod_cast hneq.symm
theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) :
stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by
have h_mem : ∀ ω, τ ω < n → τ ω ∈ WithTop.some '' (Finset.Iio n) := by
intro ω h
simp only [Finset.coe_Iio, Set.mem_image, Set.mem_Iio]
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at h
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast h, rfl⟩
rw [stoppedProcess_eq_of_mem_finset n h_mem]
congr with i
simp
section StoppedValue
variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E]
theorem memLp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ)
{s : Finset ι} (hbdd : ∀ ω, τ ω ∈ WithTop.some '' s) :
MemLp (stoppedValue u τ) p μ := by
rw [stoppedValue_eq_of_mem_finset hbdd]
refine memLp_finset_sum' _ fun i _ => MemLp.indicator ?_ (hu i)
refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i)
have : Set.range τ ⊆ WithTop.some '' s := by
rintro x ⟨y, rfl⟩
exact hbdd y
exact ((Finset.finite_toSet s).image _).subset this |>.countable
theorem memLp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, MemLp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : MemLp (stoppedValue u τ) p μ := by
refine memLp_stoppedValue_of_mem_finset hτ hu (s := Finset.Iic N) fun ω => ?_
simp only [Finset.coe_Iic, Set.mem_image, Set.mem_Iic]
specialize hbdd ω
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at hbdd
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast hbdd, rfl⟩
theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ WithTop.some '' s) :
Integrable (stoppedValue u τ) μ := by
simp_rw [← memLp_one_iff_integrable] at hu ⊢
exact memLp_stoppedValue_of_mem_finset hτ hu hbdd
variable (ι)
theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) :
Integrable (stoppedValue u τ) μ := by
refine integrable_stoppedValue_of_mem_finset hτ hu (s := Finset.Iic N) fun ω => ?_
simp only [Finset.coe_Iic, Set.mem_image, Set.mem_Iic]
specialize hbdd ω
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at hbdd
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast hbdd, rfl⟩
end StoppedValue
section StoppedProcess
variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι]
{ℱ : Filtration ι m} [NormedAddCommGroup E]
theorem memLp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ)
(n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ WithTop.some '' s) :
MemLp (stoppedProcess u τ n) p μ := by
rw [stoppedProcess_eq_of_mem_finset n hbdd]
refine MemLp.add ?_ ?_
· exact MemLp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n)
· suffices MemLp (fun ω => ∑ i ∈ s with i < n, {a : Ω | τ a = i}.indicator (u i) ω) p μ by
convert this using 1; ext1 ω; simp only [Finset.sum_apply]
refine memLp_finset_sum _ fun i _ => MemLp.indicator ?_ (hu i)
exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i)
theorem memLp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, MemLp (u n) p μ) (n : ι) :
MemLp (stoppedProcess u τ n) p μ := by
refine memLp_stoppedProcess_of_mem_finset hτ hu n (s := Finset.Iic n) fun ω h => ?_
simp only [Finset.coe_Iic, Set.mem_image, Set.mem_Iic]
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at h
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast h.le, rfl⟩
theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι}
(hbdd : ∀ ω, τ ω < n → τ ω ∈ WithTop.some '' s) :
Integrable (stoppedProcess u τ n) μ := by
simp_rw [← memLp_one_iff_integrable] at hu ⊢
exact memLp_stoppedProcess_of_mem_finset hτ hu n hbdd
theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ)
(hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ := by
refine integrable_stoppedProcess_of_mem_finset hτ hu n (s := Finset.Iic n) fun ω h => ?_
simp only [Finset.coe_Iic, Set.mem_image, Set.mem_Iic]
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at h
lift τ ω to ι using h_top with i hi
exact ⟨i, mod_cast h.le, rfl⟩
end StoppedProcess
end StoppedValueOfMemFinset
section AdaptedStoppedProcess
variable [TopologicalSpace β] [PseudoMetrizableSpace β] [Nonempty ι] [LinearOrder ι]
[TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι]
[MeasurableSpace ι] [BorelSpace ι]
{f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → WithTop ι}
/-- The stopped process of an adapted process with continuous paths is adapted. -/
theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u)
(hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) :
Adapted f (stoppedProcess u τ) :=
((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted
/-- If the indexing order has the discrete topology, then the stopped process of an adapted process
is adapted. -/
theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u)
(hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) :=
(hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted
theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u)
(hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) :=
(hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n
theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι]
(hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) :
StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) :=
hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n
end AdaptedStoppedProcess
section Nat
/-! ### Filtrations indexed by `ℕ` -/
open Filtration
variable {u : ℕ → Ω → β} {τ π : Ω → ℕ∞}
theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) (hπ : ∀ ω, π ω ≠ ∞) :
stoppedValue u π - stoppedValue u τ = fun ω =>
(∑ i ∈ Finset.Ico (τ ω).untopA (π ω).untopA, (u (i + 1) - u i)) ω := by
ext ω
have h_le' : (τ ω).untopA ≤ (π ω).untopA := WithTop.untopA_mono (mod_cast hπ ω) (hle ω)
rw [Finset.sum_Ico_eq_sub _ h_le', Finset.sum_range_sub, Finset.sum_range_sub]
simp [stoppedValue]
theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) :
stoppedValue u π - stoppedValue u τ = fun ω =>
(∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by
have hπ_top ω : π ω ≠ ⊤ := fun h ↦ by specialize hbdd ω; simp [h] at hbdd
have hτ_top ω : τ ω ≠ ⊤ := ne_top_of_le_ne_top (hπ_top ω) (mod_cast hle ω)
rw [stoppedValue_sub_eq_sum hle]
swap; · intro ω; exact mod_cast hπ_top ω
ext ω
simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter]
refine Finset.sum_congr ?_ fun _ _ => rfl
ext i
simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico]
specialize hbdd ω
lift τ ω to ℕ using hτ_top ω with t ht
lift π ω to ℕ using hπ_top ω with b hb
simp only [Nat.cast_le] at hbdd
simp
grind
section AddCommMonoid
variable [AddCommMonoid β]
theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x =>
(∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x := by
refine stoppedValue_eq_of_mem_finset fun ω ↦ ?_
specialize hbdd ω
have h_top : τ ω ≠ ⊤ := fun h_contra ↦ by simp [h_contra] at hbdd
lift τ ω to ℕ using h_top with t ht
simp only [Nat.cast_le] at hbdd
simp only [ENat.some_eq_coe, Finset.coe_range, Set.mem_image, Set.mem_Iio, Nat.cast_inj,
exists_eq_right, gt_iff_lt]
grind
theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) +
∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by
rw [stoppedProcess_eq'' n]
congr with i
rw [Finset.mem_Iio, Finset.mem_range]
theorem stoppedProcess_eq' (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n + 1 ≤ τ a} (u n) +
∑ i ∈ Finset.range (n + 1), Set.indicator {a | τ a = i} (u i) := by
have : {a | n ≤ τ a}.indicator (u n) =
{a | n + 1 ≤ τ a}.indicator (u n) + {a | τ a = n}.indicator (u n) := by
ext x
rw [add_comm, Pi.add_apply, ← Set.indicator_union_of_notMem_inter]
· simp_rw [@eq_comm _ _ (n : WithTop ℕ), @le_iff_eq_or_lt _ _ (n : WithTop ℕ)]
have : {a | ↑n + 1 ≤ τ a} = {a | ↑n < τ a} := by
ext ω
simp only [Set.mem_setOf_eq]
cases τ ω with
| top => simp
| coe t =>
simp only [Nat.cast_lt]
norm_cast
rw [this, Set.setOf_or]
· rintro ⟨h₁, h₂⟩
rw [Set.mem_setOf] at h₁ h₂
rw [h₁] at h₂
norm_cast at h₂
grind
rw [stoppedProcess_eq, this, Finset.sum_range_succ_comm, ← add_assoc]
end AddCommMonoid
end Nat
section PiecewiseConst
variable [Preorder ι] {𝒢 : Filtration ι m} {τ η : Ω → WithTop ι} {i j : ι} {s : Set Ω}
[DecidablePred (· ∈ s)]
/-- Given stopping times `τ` and `η` which are bounded below, `Set.piecewise s τ η` is also
a stopping time with respect to the same filtration. -/
theorem IsStoppingTime.piecewise_of_le (hτ_st : IsStoppingTime 𝒢 τ) (hη_st : IsStoppingTime 𝒢 η)
(hτ : ∀ ω, i ≤ τ ω) (hη : ∀ ω, i ≤ η ω) (hs : MeasurableSet[𝒢 i] s) :
IsStoppingTime 𝒢 (s.piecewise τ η) := by
intro n
have : {ω | s.piecewise τ η ω ≤ n} = s ∩ {ω | τ ω ≤ n} ∪ sᶜ ∩ {ω | η ω ≤ n} := by
ext1 ω
simp only [Set.piecewise, Set.mem_setOf_eq]
by_cases hx : ω ∈ s <;> simp [hx]
rw [this]
by_cases hin : i ≤ n
· have hs_n : MeasurableSet[𝒢 n] s := 𝒢.mono hin _ hs
exact (hs_n.inter (hτ_st n)).union (hs_n.compl.inter (hη_st n))
· have hτn : ∀ ω, ¬τ ω ≤ n := fun ω hτn => hin (mod_cast (hτ ω).trans hτn)
have hηn : ∀ ω, ¬η ω ≤ n := fun ω hηn => hin (mod_cast (hη ω).trans hηn)
simp [hτn, hηn, @MeasurableSet.empty _ _]
theorem isStoppingTime_piecewise_const (hij : i ≤ j) (hs : MeasurableSet[𝒢 i] s) :
IsStoppingTime 𝒢 (s.piecewise (fun _ => i) fun _ => j) :=
(isStoppingTime_const 𝒢 i).piecewise_of_le (isStoppingTime_const 𝒢 j) (fun _ => le_rfl)
(fun _ => mod_cast hij) hs
theorem stoppedValue_piecewise_const {ι' : Type*} [Nonempty ι'] {i j : ι'} {f : ι' → Ω → ℝ} :
stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.piecewise (f i) (f j) := by
ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx]
theorem stoppedValue_piecewise_const' {ι' : Type*} [Nonempty ι'] {i j : ι'} {f : ι' → Ω → ℝ} :
stoppedValue f (s.piecewise (fun _ => i) fun _ => j) =
s.indicator (f i) + sᶜ.indicator (f j) := by
ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx]
end PiecewiseConst
section Condexp
/-! ### Conditional expectation with respect to the σ-algebra generated by a stopping time -/
variable [LinearOrder ι] {μ : Measure Ω} {ℱ : Filtration ι m} {τ σ : Ω → WithTop ι} {E : Type*}
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : Ω → E}
theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable_range [SigmaFiniteFiltration μ ℱ]
(hτ : IsStoppingTime ℱ τ) (h_countable : (Set.range τ).Countable)
[SigmaFinite (μ.trim (hτ.measurableSpace_le))] (i : ι) :
μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on
(hτ.measurableSpace_le) (ℱ.le i)
(hτ.measurableSet_eq_of_countable_range' h_countable i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable [Countable ι]
[SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ)
[SigmaFinite (μ.trim hτ.measurableSpace_le)] (i : ι) :
μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] :=
condExp_stopping_time_ae_eq_restrict_eq_of_countable_range hτ (Set.to_countable _) i
theorem condExp_min_stopping_time_ae_eq_restrict_le_const (hτ : IsStoppingTime ℱ τ) (i : ι)
[SigmaFinite (μ.trim (hτ.min_const i).measurableSpace_le)] :
μ[f|(hτ.min_const i).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ i}] μ[f|hτ.measurableSpace] := by
have : SigmaFinite (μ.trim hτ.measurableSpace_le) :=
haveI h_le : (hτ.min_const i).measurableSpace ≤ hτ.measurableSpace := by
rw [IsStoppingTime.measurableSpace_min_const]
exact inf_le_left
sigmaFiniteTrim_mono _ h_le
refine (condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le
(hτ.min_const i).measurableSpace_le (hτ.measurableSet_le' i) fun t => ?_).symm
rw [Set.inter_comm _ t, hτ.measurableSet_inter_le_const_iff]
variable [TopologicalSpace ι] [OrderTopology ι]
theorem condExp_stopping_time_ae_eq_restrict_eq [FirstCountableTopology ι]
[SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ)
[SigmaFinite (μ.trim hτ.measurableSpace_le)] (i : ι) :
μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i)
(hτ.measurableSet_eq' i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
theorem condExp_min_stopping_time_ae_eq_restrict_le [SecondCountableTopology ι]
(hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ)
[SigmaFinite (μ.trim (hτ.min hσ).measurableSpace_le)] :
μ[f|(hτ.min hσ).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ σ x}] μ[f|hτ.measurableSpace] := by
have : SigmaFinite (μ.trim hτ.measurableSpace_le) :=
haveI h_le : (hτ.min hσ).measurableSpace ≤ hτ.measurableSpace := by
rw [IsStoppingTime.measurableSpace_min]
· exact inf_le_left
· simp_all only
sigmaFiniteTrim_mono _ h_le
refine (condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le
(hτ.min hσ).measurableSpace_le (hτ.measurableSet_le_stopping_time hσ) fun t => ?_).symm
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_le_iff]; simp_all only
end Condexp
end MeasureTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/PartitionFiltration.lean | import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
import Mathlib.Probability.Process.Filtration
/-!
# Filtration built from the finite partitions of a countably generated measurable space
In a countably generated measurable space `α`, we can build a sequence of finer and finer finite
measurable partitions of the space such that the measurable space is generated by the union of all
partitions.
This sequence of partitions is defined in `MeasureTheory.MeasurableSpace.CountablyGenerated`.
Here, we build the filtration of the measurable spaces generated by `countablePartition α n` for all
`n : ℕ`, which we call `countableFiltration α`.
Since each measurable space in the filtration is finite, we can easily build measurable functions on
those spaces. A potential application of `countableFiltration α` is to build a martingale with
respect to that filtration and use the martingale convergence theorems to define a measurable
function on `α`.
## Main definitions
* `ProbabilityTheory.partitionFiltration`: for a sequence of sets `t : ℕ → Set α`, a filtration
built from the measurable spaces generated by `memPartition t n` for all `n : ℕ`.
* `ProbabilityTheory.countableFiltration`: A filtration built from the measurable spaces generated
by `countablePartition α n` for all `n : ℕ`.
## Main statements
* `ProbabilityTheory.iSup_partitionFiltration`: `⨆ n, partitionFiltration α n` is the measurable
space on `α`.
-/
open MeasureTheory MeasurableSpace
namespace ProbabilityTheory
section MemPartition
variable {α : Type*} [m : MeasurableSpace α] {t : ℕ → Set α}
/-- A filtration built from the measurable spaces generated by the partitions `memPartition t n` for
all `n : ℕ`. -/
def partitionFiltration (ht : ∀ n, MeasurableSet (t n)) :
Filtration ℕ m where
seq n := generateFrom (memPartition t n)
mono' := monotone_nat_of_le_succ (generateFrom_memPartition_le_succ _)
le' := generateFrom_memPartition_le ht
lemma measurableSet_partitionFiltration_of_mem (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) {s : Set α}
(hs : s ∈ memPartition t n) :
MeasurableSet[partitionFiltration ht n] s :=
measurableSet_generateFrom hs
lemma measurableSet_partitionFiltration_memPartitionSet (ht : ∀ n, MeasurableSet (t n))
(n : ℕ) (a : α) :
MeasurableSet[partitionFiltration ht n] (memPartitionSet t n a) :=
measurableSet_partitionFiltration_of_mem ht n (memPartitionSet_mem t n a)
lemma measurable_memPartitionSet_subtype (ht : ∀ n, MeasurableSet (t n)) (n : ℕ)
(m : MeasurableSpace (memPartition t n)) :
@Measurable α (memPartition t n) (partitionFiltration ht n) m
(fun a ↦ ⟨memPartitionSet t n a, memPartitionSet_mem t n a⟩) := by
refine @measurable_to_countable' (memPartition t n) α m _
(partitionFiltration ht n) _ (fun s ↦ ?_)
rcases s with ⟨s, hs⟩
suffices MeasurableSet[partitionFiltration ht n] {x | memPartitionSet t n x = s} by
convert this
ext x
simp
simp_rw [memPartitionSet_eq_iff _ hs]
exact measurableSet_partitionFiltration_of_mem _ _ hs
lemma measurable_partitionFiltration_memPartitionSet (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) :
Measurable[partitionFiltration ht n] (memPartitionSet t n) :=
measurable_subtype_coe.comp (measurable_memPartitionSet_subtype ht _ _)
lemma measurable_memPartitionSet (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) :
Measurable (memPartitionSet t n) :=
(measurable_partitionFiltration_memPartitionSet ht n).mono ((partitionFiltration ht).le n) le_rfl
lemma iSup_partitionFiltration_eq_generateFrom_range (ht : ∀ n, MeasurableSet (t n)) :
⨆ n, partitionFiltration ht n = generateFrom (Set.range t) := by
conv_rhs => rw [← generateFrom_iUnion_memPartition t, ← iSup_generateFrom]
rfl
lemma iSup_partitionFiltration (ht : ∀ n, MeasurableSet (t n))
(ht_range : generateFrom (Set.range t) = m) :
⨆ n, partitionFiltration ht n = m := by
rw [iSup_partitionFiltration_eq_generateFrom_range ht, ht_range]
end MemPartition
section CountableFiltration
variable {α : Type*} [MeasurableSpace α] [CountablyGenerated α]
/-- A filtration built from the measurable spaces generated by `countablePartition α n` for
all `n : ℕ`. -/
def countableFiltration (α : Type*) [m : MeasurableSpace α] [CountablyGenerated α] :
Filtration ℕ m where
seq n := generateFrom (countablePartition α n)
mono' := monotone_nat_of_le_succ (generateFrom_countablePartition_le_succ _)
le' := generateFrom_countablePartition_le α
lemma measurableSet_countableFiltration_of_mem (n : ℕ) {s : Set α}
(hs : s ∈ countablePartition α n) :
MeasurableSet[countableFiltration α n] s :=
measurableSet_generateFrom hs
lemma measurableSet_countableFiltration_countablePartitionSet (n : ℕ) (t : α) :
MeasurableSet[countableFiltration α n] (countablePartitionSet n t) :=
measurableSet_countableFiltration_of_mem n (countablePartitionSet_mem n t)
lemma measurable_countablePartitionSet_subtype (n : ℕ)
(m : MeasurableSpace (countablePartition α n)) :
@Measurable α (countablePartition α n) (countableFiltration α n) m
(fun a ↦ ⟨countablePartitionSet n a, countablePartitionSet_mem n a⟩) :=
measurable_memPartitionSet_subtype
(measurableSet_enumerateCountable_countableGeneratingSet (α := α)) n m
lemma measurable_countableFiltration_countablePartitionSet (α : Type*)
[MeasurableSpace α] [CountablyGenerated α] (n : ℕ) :
Measurable[countableFiltration α n] (countablePartitionSet n) :=
measurable_subtype_coe.comp (measurable_countablePartitionSet_subtype _ _)
lemma measurable_countablePartitionSet (α : Type*) [MeasurableSpace α] [CountablyGenerated α]
(n : ℕ) :
Measurable (countablePartitionSet (α := α) n) :=
(measurable_countableFiltration_countablePartitionSet α n).mono ((countableFiltration α).le n)
le_rfl
lemma iSup_countableFiltration (α : Type*) [m : MeasurableSpace α] [CountablyGenerated α] :
⨆ n, countableFiltration α n = m := by
conv_rhs => rw [← generateFrom_iUnion_countablePartition α, ← iSup_generateFrom]
rfl
end CountableFiltration
end ProbabilityTheory |
.lake/packages/mathlib/Mathlib/Probability/Process/Kolmogorov.lean | import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable
import Mathlib.MeasureTheory.Integral.Lebesgue.Basic
/-!
# Stochastic processes satisfying the Kolmogorov condition
A stochastic process `X : T → Ω → E` on an index space `T` and a measurable space `Ω`
with measure `P` is said to satisfy the Kolmogorov condition with exponents `p, q` and constant `M`
if for all `s, t : T`, the pair `(X s, X t)` is measurable for the Borel sigma-algebra on `E × E`
and the following condition holds:
`∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q`.
This condition is the main assumption of the Kolmogorov-Chentsov theorem, which gives the existence
of a continuous modification of the process.
The measurability condition on pairs ensures that the distance `edist (X s ω) (X t ω)` is
measurable in `ω` for fixed `s, t`. In a space with second-countable topology, the measurability
of pairs can be obtained from measurability of each `X t`.
## Main definitions
* `IsKolmogorovProcess`: property of being a stochastic process that satisfies
the Kolmogorov condition.
* `IsAEKolmogorovProcess`: a stochastic process satisfies `IsAEKolmogorovProcess` if it is
a modification of a process satisfying the Kolmogorov condition.
## Main statements
* `IsKolmogorovProcess.mk_of_secondCountableTopology`: in a space with second-countable topology,
a process is a Kolmogorov process if each `X t` is measurable and the Kolmogorov condition holds.
-/
open MeasureTheory
open scoped ENNReal NNReal
namespace ProbabilityTheory
variable {T Ω E : Type*} [PseudoEMetricSpace T] {mΩ : MeasurableSpace Ω} [PseudoEMetricSpace E]
{p q : ℝ} {M : ℝ≥0} {P : Measure Ω} {X : T → Ω → E}
/-- A stochastic process `X : T → Ω → E` on an index space `T` and a measurable space `Ω`
with measure `P` is said to satisfy the Kolmogorov condition with exponents `p, q` and constant `M`
if for all `s, t : T`, the pair `(X s, X t)` is measurable for the Borel sigma-algebra on `E × E`
and the following condition holds: `∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q`. -/
structure IsKolmogorovProcess (X : T → Ω → E) (P : Measure Ω) (p q : ℝ) (M : ℝ≥0) : Prop where
measurablePair : ∀ s t : T, Measurable[_, borel (E × E)] fun ω ↦ (X s ω, X t ω)
kolmogorovCondition : ∀ s t : T, ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q
p_pos : 0 < p
q_pos : 0 < q
/-- Property of being a modification of a stochastic process that satisfies the Kolmogorov
condition (`IsKolmogorovProcess`). -/
def IsAEKolmogorovProcess (X : T → Ω → E) (P : Measure Ω) (p q : ℝ) (M : ℝ≥0) : Prop :=
∃ Y, IsKolmogorovProcess Y P p q M ∧ ∀ t, X t =ᵐ[P] Y t
lemma IsKolmogorovProcess.IsAEKolmogorovProcess (hX : IsKolmogorovProcess X P p q M) :
IsAEKolmogorovProcess X P p q M := ⟨X, hX, by simp⟩
namespace IsAEKolmogorovProcess
/-- A process with the property `IsKolmogorovProcess` such that `∀ t, X t =ᵐ[P] h.mk X t`. -/
protected noncomputable
def mk (X : T → Ω → E) (h : IsAEKolmogorovProcess X P p q M) : T → Ω → E :=
Classical.choose h
lemma IsKolmogorovProcess_mk (h : IsAEKolmogorovProcess X P p q M) :
IsKolmogorovProcess (h.mk X) P p q M := (Classical.choose_spec h).1
lemma ae_eq_mk (h : IsAEKolmogorovProcess X P p q M) : ∀ t, X t =ᵐ[P] h.mk X t :=
(Classical.choose_spec h).2
lemma kolmogorovCondition (hX : IsAEKolmogorovProcess X P p q M) (s t : T) :
∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P ≤ M * edist s t ^ q := by
convert hX.IsKolmogorovProcess_mk.kolmogorovCondition s t using 1
refine lintegral_congr_ae ?_
filter_upwards [hX.ae_eq_mk s, hX.ae_eq_mk t] with ω hω₁ hω₂
simp_rw [hω₁, hω₂]
lemma p_pos (hX : IsAEKolmogorovProcess X P p q M) : 0 < p := hX.IsKolmogorovProcess_mk.p_pos
lemma q_pos (hX : IsAEKolmogorovProcess X P p q M) : 0 < q := hX.IsKolmogorovProcess_mk.q_pos
lemma congr {Y : T → Ω → E} (hX : IsAEKolmogorovProcess X P p q M)
(h : ∀ t, X t =ᵐ[P] Y t) :
IsAEKolmogorovProcess Y P p q M := by
refine ⟨hX.mk X, hX.IsKolmogorovProcess_mk, fun t ↦ ?_⟩
filter_upwards [hX.ae_eq_mk t, h t] with ω hX hY using hY.symm.trans hX
end IsAEKolmogorovProcess
section Measurability
lemma IsKolmogorovProcess.stronglyMeasurable_edist
(hX : IsKolmogorovProcess X P p q M) {s t : T} :
StronglyMeasurable (fun ω ↦ edist (X s ω) (X t ω)) := by
borelize (E × E)
exact continuous_edist.stronglyMeasurable.comp_measurable (hX.measurablePair s t)
lemma IsAEKolmogorovProcess.aestronglyMeasurable_edist
(hX : IsAEKolmogorovProcess X P p q M) {s t : T} :
AEStronglyMeasurable (fun ω ↦ edist (X s ω) (X t ω)) P := by
refine ⟨(fun ω ↦ edist (hX.mk X s ω) (hX.mk X t ω)),
hX.IsKolmogorovProcess_mk.stronglyMeasurable_edist, ?_⟩
filter_upwards [hX.ae_eq_mk s, hX.ae_eq_mk t] with ω hω₁ hω₂ using by simp [hω₁, hω₂]
lemma IsKolmogorovProcess.measurable_edist (hX : IsKolmogorovProcess X P p q M) {s t : T} :
Measurable (fun ω ↦ edist (X s ω) (X t ω)) := hX.stronglyMeasurable_edist.measurable
lemma IsAEKolmogorovProcess.aemeasurable_edist (hX : IsAEKolmogorovProcess X P p q M) {s t : T} :
AEMeasurable (fun ω ↦ edist (X s ω) (X t ω)) P := hX.aestronglyMeasurable_edist.aemeasurable
variable [MeasurableSpace E] [BorelSpace E]
lemma IsKolmogorovProcess.measurable (hX : IsKolmogorovProcess X P p q M) (s : T) :
Measurable (X s) :=
(measurable_fst.mono prod_le_borel_prod le_rfl).comp (hX.measurablePair s s)
lemma IsAEKolmogorovProcess.aemeasurable (hX : IsAEKolmogorovProcess X P p q M) (s : T) :
AEMeasurable (X s) P := by
refine ⟨hX.mk X s, hX.IsKolmogorovProcess_mk.measurable s, ?_⟩
filter_upwards [hX.ae_eq_mk s] with ω hω using hω
lemma IsKolmogorovProcess.mk_of_secondCountableTopology [SecondCountableTopology E]
(h_meas : ∀ s, Measurable (X s))
(h_kol : ∀ s t : T, ∫⁻ ω, (edist (X s ω) (X t ω)) ^ p ∂P ≤ M * edist s t ^ q)
(hp : 0 < p) (hq : 0 < q) :
IsKolmogorovProcess X P p q M where
measurablePair s t := by
suffices Measurable (fun ω ↦ (X s ω, X t ω)) by
rwa [Prod.borelSpace.measurable_eq] at this
fun_prop
kolmogorovCondition := h_kol
p_pos := hp
q_pos := hq
end Measurability
section ZeroDist
lemma IsAEKolmogorovProcess.edist_eq_zero (hX : IsAEKolmogorovProcess X P p q M)
{s t : T} (h : edist s t = 0) :
∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := by
suffices ∀ᵐ ω ∂P, edist (X s ω) (X t ω) ^ p = 0 by
filter_upwards [this] with ω hω
simpa [hX.p_pos, not_lt_of_gt hX.p_pos] using hω
refine (lintegral_eq_zero_iff' (hX.aemeasurable_edist.pow_const p)).mp ?_
refine le_antisymm ?_ zero_le'
calc ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P
_ ≤ M * edist s t ^ q := hX.kolmogorovCondition s t
_ = 0 := by simp [h, hX.q_pos]
lemma IsKolmogorovProcess.edist_eq_zero (hX : IsKolmogorovProcess X P p q M)
{s t : T} (h : edist s t = 0) :
∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 :=
hX.IsAEKolmogorovProcess.edist_eq_zero h
lemma IsAEKolmogorovProcess.edist_eq_zero_of_const_eq_zero (hX : IsAEKolmogorovProcess X P p q 0)
(s t : T) :
∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 := by
suffices ∀ᵐ ω ∂P, edist (X s ω) (X t ω) ^ p = 0 by
filter_upwards [this] with ω hω
simpa [hX.p_pos, not_lt_of_gt hX.p_pos] using hω
refine (lintegral_eq_zero_iff' (hX.aemeasurable_edist.pow_const p)).mp ?_
refine le_antisymm ?_ zero_le'
calc ∫⁻ ω, edist (X s ω) (X t ω) ^ p ∂P
_ ≤ 0 * edist s t ^ q := hX.kolmogorovCondition s t
_ = 0 := by simp
lemma IsKolmogorovProcess.edist_eq_zero_of_const_eq_zero (hX : IsKolmogorovProcess X P p q 0)
(s t : T) :
∀ᵐ ω ∂P, edist (X s ω) (X t ω) = 0 :=
hX.IsAEKolmogorovProcess.edist_eq_zero_of_const_eq_zero s t
end ZeroDist
end ProbabilityTheory |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.