The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V20. Probability

Mathlib.Probability.ConditionalProbability

36 declarations. Mathlib docs · Source

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

We can't use notation or notation3 as it does not support noWs, and so we have to write our own delaborators.

def ProbabilityTheory.cond E3 #

{Ω : Type u_1} → {m : MeasurableSpace Ω} → MeasureTheory.Measure Ω → Set Ω → MeasureTheory.Measure Ω

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 ProbabilityTheory.«term__[|_]» E1 #

Lean.TrailingParserDescr

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 ProbabilityTheory.«term__[_|_]» E1 #

Lean.TrailingParserDescr

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 ProbabilityTheory.condUnexpander E1 #

Lean.PrettyPrinter.Unexpander

Unexpander for μ[|s] notation.

def ProbabilityTheory.delabCondApplied E1 #

Lean.PrettyPrinter.Delaborator.Delab

Delaborator for μ[t | s] notation.

def ProbabilityTheory.«term__[|_In_]» E1 #

Lean.TrailingParserDescr

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}.

def ProbabilityTheory.«term__[_|_In_]» E1 #

Lean.TrailingParserDescr

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}.

def ProbabilityTheory.«term__[|_←_]» E1 #

Lean.TrailingParserDescr

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}.

def ProbabilityTheory.«term__[_|_←_]» E1 #

Lean.TrailingParserDescr

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}.

theorem ProbabilityTheory.cond_isProbabilityMeasure_of_finite E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  μ s ≠ 0 → μ s ≠ ⊤ → MeasureTheory.IsProbabilityMeasure μ[|s]

The conditional probability measure of any measure on any set of finite positive measure is a probability measure.

theorem ProbabilityTheory.cond_isProbabilityMeasure E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω} [MeasureTheory.IsFiniteMeasure μ],
  μ s ≠ 0 → MeasureTheory.IsProbabilityMeasure μ[|s]

The conditional probability measure of any finite measure on any set of positive measure is a probability measure.

instance ProbabilityTheory.instIsZeroOrProbabilityMeasureCond E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  MeasureTheory.IsZeroOrProbabilityMeasure μ[|s]

theorem ProbabilityTheory.cond_toMeasurable_eq E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} (μ : MeasureTheory.Measure Ω) {s : Set Ω},
  μ[|MeasureTheory.toMeasurable μ s] = μ[|s]

theorem ProbabilityTheory.cond_absolutelyContinuous E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω}, μ[|s].AbsolutelyContinuous μ

theorem ProbabilityTheory.absolutelyContinuous_cond_univ E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} [MeasureTheory.IsFiniteMeasure μ],
  μ.AbsolutelyContinuous μ[|Set.univ]

theorem ProbabilityTheory.ae_cond_of_forall_mem E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  MeasurableSet s → ∀ {p : Ω → Prop}, (∀ x ∈ s, p x) → ∀ᵐ (x : Ω) ∂μ[|s], p x

theorem ProbabilityTheory.ae_cond_mem₀ E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  MeasureTheory.NullMeasurableSet s μ → ∀ᵐ (x : Ω) ∂μ[|s], x ∈ s

theorem ProbabilityTheory.ae_cond_mem E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  MeasurableSet s → ∀ᵐ (x : Ω) ∂μ[|s], x ∈ s

theorem ProbabilityTheory.cond_empty E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} (μ : MeasureTheory.Measure Ω), μ[|∅] = 0

theorem ProbabilityTheory.cond_univ E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsProbabilityMeasure μ],
  μ[|Set.univ] = μ

theorem ProbabilityTheory.cond_eq_zero E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω}, μ[|s] = 0 ↔ μ s = ⊤ ∨ μ s = 0

theorem ProbabilityTheory.cond_eq_zero_of_meas_eq_zero E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω}, μ s = 0 → μ[|s] = 0

theorem ProbabilityTheory.cond_apply E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s : Set Ω},
  MeasurableSet s → ∀ (μ : MeasureTheory.Measure Ω) (t : Set Ω), μ[t | s] = (μ s)⁻¹ * μ (s ∩ t)

The axiomatic definition of conditional probability derived from a measure-theoretic one.

theorem ProbabilityTheory.cond_apply' E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s t : Set Ω},
  MeasurableSet t → ∀ (μ : MeasureTheory.Measure Ω), μ[t | s] = (μ s)⁻¹ * μ (s ∩ t)

theorem ProbabilityTheory.cond_apply_self E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω}, μ s ≠ 0 → μ s ≠ ⊤ → μ[s | s] = 1

theorem ProbabilityTheory.cond_inter_self E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s : Set Ω},
  MeasurableSet s → ∀ (t : Set Ω) (μ : MeasureTheory.Measure Ω), μ[s ∩ t | s] = μ[t | s]

theorem ProbabilityTheory.inter_pos_of_cond_ne_zero E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s t : Set Ω},
  MeasurableSet s → μ[t | s] ≠ 0 → 0 < μ (s ∩ t)

theorem ProbabilityTheory.cond_pos_of_inter_ne_zero E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s t : Set Ω} [MeasureTheory.IsFiniteMeasure μ],
  MeasurableSet s → μ (s ∩ t) ≠ 0 → 0 < μ[t | s]

theorem ProbabilityTheory.cond_cond_eq_cond_inter' E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s t : Set Ω},
  MeasurableSet s → MeasurableSet t → μ s ≠ ⊤ → μ[|s][|t] = μ[|s ∩ t]

theorem ProbabilityTheory.cond_cond_eq_cond_inter E3 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s t : Set Ω},
  MeasurableSet s →
    MeasurableSet t → ∀ (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsFiniteMeasure μ], μ[|s][|t] = μ[|s ∩ t]

Conditioning first on s and then on t results in the same measure as conditioning on s ∩ t.

theorem ProbabilityTheory.cond_mul_eq_inter' E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {μ : MeasureTheory.Measure Ω} {s : Set Ω},
  MeasurableSet s → μ s ≠ ⊤ → ∀ (t : Set Ω), μ[t | s] * μ s = μ (s ∩ t)

theorem ProbabilityTheory.cond_mul_eq_inter E1 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s : Set Ω},
  MeasurableSet s →
    ∀ (t : Set Ω) (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsFiniteMeasure μ], μ[t | s] * μ s = μ (s ∩ t)

theorem ProbabilityTheory.cond_add_cond_compl_eq E0 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s t : Set Ω},
  MeasurableSet s →
    ∀ (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsFiniteMeasure μ], μ[t | s] * μ s + μ[t | sᶜ] * μ sᶜ = μ t

A version of the law of total probability.

theorem ProbabilityTheory.cond_eq_inv_mul_cond_mul E3 #

∀ {Ω : Type u_1} {m : MeasurableSpace Ω} {s t : Set Ω},
  MeasurableSet s →
    MeasurableSet t →
      ∀ (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsFiniteMeasure μ], μ[t | s] = (μ s)⁻¹ * μ[s | t] * μ t

Bayes' Theorem

theorem ProbabilityTheory.comap_cond E1 #

∀ {Ω : Type u_1} {Ω' : Type u_2} {m : MeasurableSpace Ω} {m' : MeasurableSpace Ω'} {μ : MeasureTheory.Measure Ω}
  {s : Set Ω} {i : Ω' → Ω},
  MeasurableEmbedding i →
    (∀ᵐ (ω : Ω) ∂μ, ω ∈ Set.range i) →
      MeasurableSet s → MeasureTheory.Measure.comap i μ[|s] = (MeasureTheory.Measure.comap i μ)[|i ⁻¹' s]

theorem ProbabilityTheory.sum_meas_smul_cond_fiber E1 #

∀ {Ω : Type u_1} {α : Type u_3} {m : MeasurableSpace Ω} [inst : Fintype α] [inst_1 : MeasurableSpace α]
  [DiscreteMeasurableSpace α] {X : Ω → α},
  Measurable X →
    ∀ (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsFiniteMeasure μ], ∑ x, μ (X ⁻¹' {x}) • μ[|X ⁻¹' {x}] = μ

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.