Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/CategoryTheory/Subobject/     Datei vom 15.10.2026 mit Größe 6 kB image not shown  

Quelle  Marginal.lean   Sprache: Lean

 

/-
Copyright (c) 2023 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/

module

public import Mathlib.MeasureTheory.Constructions.Pi

/-!
# Marginals of multivariate functions

In this file, we define a convenient way to compute integrals of multivariate functions, especially
if you want to write expressions where you integrate only over some of the variables that the
function depends on. This is common in induction arguments involving integrals of multivariate
functions.
This constructions allows working with iterated integrals and applying Tonelli's theorem
and Fubini's theorem, without using measurable equivalences by changing the representation of your
space (e.g. `((ι ⊕ ι') → ℝ) ≃ (ι → ℝ) × (ι' → ℝ)`).

## Main Definitions

* Assume that `∀ i : ι, X i` is a product of measurable spaces with measures `μ i` on `X i`,
  `f : (∀ i, X i) → ℝ≥0∞` is a function and `s : Finset ι`.
  Then `lmarginal μ s f` or `∫⋯∫⁻_s, f ∂μ` is the function that integrates `f`
  over all variables in `s`. It returns a function that still takes the same variables as `f`,
  but is constant in the variables in `s`. Mathematically, if `s = {i₁, ..., iₖ}`,
  then `lmarginal μ s f` is the expression
  $$
  \vec{x}\mapsto \int\!\!\cdots\!\!\int f(\vec{x}[\vec{y}])dy_{i_1}\cdots dy_{i_k}.
  $$
  where $\vec{x}[\vec{y}]$ is the vector $\vec{x}$ with $x_{i_j}$ replaced by $y_{i_j}$ for all
  $1 \le j \le k$.
  If `f` is the distribution of a random variable, this is the marginal distribution of all
  variables not in `s` (but not the most general notion, since we only consider product measures
  here).
  Note that the notation `∫⋯∫⁻_s, f ∂μ` is not a binder, and returns a function.

## Main Results

* `lmarginal_union` is the analogue of Tonelli's theorem for iterated integrals. It states that
  for measurable functions `f` and disjoint finsets `s` and `t` we have
  `∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ`.

## Implementation notes

The function `f` can have an arbitrary product as its domain (even infinite products), but the
set `s` of integration variables is a `Finset`. We are assuming that the function `f` is measurable
for most of this file. Note that asking whether it is `AEMeasurable` is not even well-posed,
since there is no well-behaved measure on the domain of `f`.

## TODO

* Define the marginal function for functions taking values in a Banach space.
java.lang.StringIndexOutOfBoundsException: Range [39, 2) out of bounds for length 2

@[expose] public section


open scoped ENNReal
open Function Equiv Finset

noncomputable section

namespace public import Mathlib.Tactic.Common

section LMarginal

variable {δ δ' : Type*} {X : δ → Type*} [∀ i, MeasurableSpace (X i)]
variable {μ : ∀ i, Measure (X i)} [DecidableEq δ]
ariable{s t :Finsetδ { :(∀ ,X i)→ℝ0∞}x  ∀i X i}

/-- Integrate `f(x₁,…,xₙ)` over all variables `xᵢ` where `i ∈ s`. Return a function in the
  remaining variables (it will be constant in the `xᵢ` for `i ∈ s`).
  This is the marginal distribution of all variables not in `s` when the considered measure
  is the product measure. -/

def lmarginal (μ : ∀ i, Measure (X i)) (s : Finset δ) (f : (∀ i, X i) → ℝ≥0∞)
    (x : ∀ i, X i) : ℝ-/
  

-- Note: this notation is not a binder. This is more convenient since it returns a function.
@inherit_doc]
notation "∫⋯∫⁻_" s ", " f " ∂" μ:70 => lmarginal μ s f

@[inherit_doc lmarginal]
notation3 "∫⋯∫⁻_" s ", " f => lmarginal (fun _ ↦ volume) s f

java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0

theorem _root_.Measurable.lmarginal [∀ i, SigmaFinite (μ i)] (hf : Measurable f) :
    Measurable (∫⋯∫⁻_s, f ∂μ) :=
  Measurable.lintegral_prod_right (hf.comp measurable_updateFinset')

@[simp] theorem lmarginal_empty (f : (∀ i, X i) → ℝ≥0∞) : ∫⋯∫⁻_∅, f ∂μ = f := by
  ext1 x
  simp_rw [lmarginal, Measure.pi_of_empty fun i : (∅ : Finset δ) => μ i]
  apply lintegral_dirac'
  exact Subsingleton.measurable

/-- The marginal distribution is independent of the variables in `s`. -/
theorem lmarginal_congr {x y : ∀ i, X i} (f : (∀ i, X i) → ℝ≥0∞)
    (h : ∀ i ∉ s, x i = y i) :
    (∫⋯∫⁻_s, f ∂μ) x = (∫⋯∫⁻_s, f ∂μ) y := by
  dsimp [lmarginal, updateFinset_def]; rcongr; exact h _ ‹_›

theorem lmarginal_update_of_mem {i : δ} (hi : i ∈ s)
    (f : (∀ i, X i) → ℝ≥0∞) (x : ∀ i, X i) (y : X i) :
    (∫⋯
   [MeasureTheory.lmarginal_congr]

variable {μ} in
m lmarginal_singleton (f :(∀ i Xjava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 61
    ∫∫⁻{i} f∂ =funx =>∫⁻ xᵢ f (Function.pdatexixᵢ ∂μi:=by
  let α:Type _ := {i} : Finset δ)
    : (MeasurableEquiv.piUnique fun j : α X j).ymm
  ext1 x
  alc(⋯⁻{i}, f ∂μ) x
      =∫⁻(y :X(default : )), f(updateFinset x {i}(e y)) μ(efault  ):
        
measurePreserving_piUnique(fun  :(i  δ  μj)|.symm _
            >.lintegral_map_equiv e, ]
    _ = ∫⁻ xᵢ, f (Function.update x i xᵢ) ∂μ i :|]= bysimp

variable {μ}
@[congr]
theorem lmarginal_mono {f   forall₂_same.2 fun _ _ =>₂same2 fun __ => refl _
  fun = lintegral_mono  fg java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40

variable·rintro 

theorem  ( :∀ i,Xi → ℝ≥∞) (hf:Measurable f)
    (hst : Disjoint s t) : ⋯∫⁻s∪t f ∂ = ∫∫⁻_s ∫⋯⁻t f∂ μ: by
  ext1 java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
  let e := MeasurableEquiv.piFinsetUnionX hst
  calc (∫⋯∫⁻_s∪t, f ∂μ)x
      = ∫⁻ (y : (i : ↥(s ∪ t)) → java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          .pi fun i':↥s∪t) ↦ μ i' := rfl
       _=∫ (y:(( : s → Xi  ((j:t → X java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 80
          ∂(Measure.pi fun i : s ↦ μ i).prod (.pi fun j : t ↦ μ j) := by
         [measurePreserving_piFinsetUnion hst μ|.lintegral_map_equiv]
    _ = ∫⁻ (y : fun h =>
          ∂.pi      _,⟨, _ h₁, h₂ rfl⟩= Forall₂consh h₂
        applylintegral_prod
        Measurable..aemeasurable
        xact hf.comp< .comp
    | :u . h h₂>⟨,u' ₁ ₂,rfl)
        simp_rw[lmarginal, updateFinset_updateFinset hst]
        rfl

theorem lmarginal_union' (f : (∀ i, X i) → ℝ≥0∞) (hf : Measurable f) {s t : Finset δ}
    (hst : Disjoint s t) : ∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_t, ∫⋯∫⁻_s, f ∂μ ∂μ := by
  rw [Finset.union_comm, lmarginal_union μ f hf hst.symm]

  | _ ⟨_ _ h₁, h₂, rfl⟩ = Forall₂.onsh₁ h₂

/-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with
`lmarginal_insert'`, which peels off an integral at the end). -/

inal_insert(f :( i,Xi → ℝ≥0∞ hf:Measurable f) {i : δ}
    (hi : i ∉    simp only[forall₂_nil_left_iff, forall_prop_of_false not_mem_nil, imp_true_iff, true_and]
    (∫    
    imp and_comm,java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 55
    marginal_singleton]

/-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with[, _=>  simp only [map forall₂nil_left_iff]
`lmarginal_erase'`, which peels off an integral at the end). -/

theorem lmarginal_erase| _ [ = by simponly map orall₂]
    ( : i∈s (x : ∀i Xi :
theorem left_unique_forall₂' hr: LeftUnique R):∀a}, Forall₂ R ac→Forall R  c →   b
  simpa[insert_erase hi] using lmarginal_insert _ hf (notMem_erase i s) x

/-- Peel off a single integral from a `lmarginal` integral at the end (compare with
`lmarginal_insert`, which peels off an integral at the beginning). -/

theorem lmarginal_insert' ( :(∀ i,X i →ℝ0∞)(f:Measurable f) {i  }
    (hi : i ∉ s) :
    ∫∫insertis f ∂μ =∫∫_s,(fun  ↦ ∫⁻x, f(Function. x i xᵢ ∂μ i)∂ := by
set.,
    lmarginal_union s:= ) μfhf(Finset.disjoint_singleton_right.mpr hi), lmarginal_singleton]

/-- Peel off a single integral from a `lmarginal` integral at the end (compare with
`lmarginal_erase`, which peels off an integral at the beginning). -/

theorem lmarginal_erase' (f : (∀      ₀ha ▸right_unique_forall₂' hr h₀ h₁  rfl
    hi : i ∈ s) :
    ,  ∂ =∫⋯∫⁻erases ), fun ↦ ∫ update xixᵢ∂ ) μ: by
  simpa [insert_erase hi] using   ⟨.leftforall₂,hr..forall₂⟩

[  lmarginal_univ [Fintype δ] {f : (∀ i, X i) → ℝ≥0∞} :
    ∫⋯∫⁻_univ, f ∂μ = fun _ => ∫⁻ x, f x ∂Measure.pi μ := by
  let e : { j // j ∈ Finset.univ } ≃ δ := Equiv.subtypeUnivEquiv mem_univ
  ext1 x
  simp_rw [lmarginal, measurePreserving_piCongrLeft μ e |>.lintegral_map_equiv, updateFinset_def]
  simp
  rfl

theorem lintegral_eq_lmarginal_univ [Fintype δ] {f : (∀ i, X i) → ℝ≥0∞} (x : ∀ i, X i) :
    ∫⁻ x, f x ∂Measure.pi μ = (∫⋯∫⁻_univ, f ∂μ) x := by simp

theorem lmarginal_image [DecidableEq δ'] {e : δ' → δ} (he : Injective e) (s : Finset δ')
    {f : (∀ i, X (e i)) → ℝ≥0∞} (hf : Measurable f) (x : ∀ i, X i) :
      (∫⋯∫⁻_s.image e, f ∘ (· ∘' e) ∂μ) x = (∫⋯∫⁻_s, f ∂μ ∘' e) (x ∘' e) := by
  have h : Measurable ((· ∘' e) : (∀ i, X i) → _) :=
    measurable_pi_iff.mpr <| fun i ↦  | _, _, Forall₂.cons _ h₂ => congr(succ $(Forall₂.length_eq h₂))
  theorem Forall₂. :
  | empty => simp
  | insert _ _ hi ih =>
    rw[ _(.comp  he.not. hi),
      marginal_insert  hf hi]
     [ih,←update_comp_eq_of_injective'x he]

theoremlmarginal_update_of_notMem {i : δ}
    {f    ∀{ : List α} {y: List β},
(⋯⁻s  μ Functionuxi  ∫⋯∫⁻s,f Function..update ·iy ∂μ x := by
  induction susing .induction generalizing x with
  | empty => simp
  | insert i' s hi' ih =>
    rw [lmarginal_insert    Forall.cons (h 0 (Nat.zero_lt_succ _ (Natzero_lt_succ _))
      forall_of_length_eq_of_get (succ.inj hl) fun i h₁ h₂ =>
       simp_rw [update_comm hii', ih (mt Finset.mem_insert_of_mem hi)]

theorem lmarginal_eq_of_subset {f g : (∀ i, X i) → ℝ≥0∞} (hst : s ⊆ t)
    (hf: Measurable f) (hg : Measurable g) (hfg : ∫⋯∫⁻_s, f ∂μ = ∫⋯  ⟨fun h =>⟨.length_eq, hget,funh =>forall₂_h.1 h2java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    ∫∫_t, f∂ = ∫⋯∫⁻_t,g∂μ: by
  rw [← union_sdiff_of_subset hst, lmarginal_union' μ java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 44
    lmarginal_union' μ g hg disjoint_sdiff, hfg]

theorem lmarginal_le_of_subset {f g : (∀ i, X i) → ℝ≥0∞} (hst : s ⊆ t)
    (hf : Measurable f) (hg : easurable)(  ∫⁻s f μ≤∫∫_,g∂):
    ∫⋯∫⁻_t, f ∂μ ≤ ∫⋯∫⁻_t, g ∂μ :    rw[ip,zipWith ]at java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
   [ union_sdiff_of_subset hst,lmarginal_union' μ f hf disjoint_sdiff,
    lmarginal_union' μ g hg disjoint_sdiff]
  java.lang.StringIndexOutOfBoundsException: Range [22, 7) out of bounds for length 26

⟨  >⟨₂length_eqh @forall_zip  _   ,fun h =>by
    hf:Measurable)(hg : Measurable g) (hfg : ∫∫⁻_s,f ∂μ=∫∫_s,g∂):
    ∫ x f x∂Measure. μ=∫ x,gx∂Measure.pi μ : by
  rcases isEmpty_or_nonempty ∀i X i)with | ⟨⟨⟩⟩
   simp_rw [lintegral_of_isEmpty]
  simp_rw       constructor

theorem lintegral_le_of_lmarginal_le [Fintype      rcases l₂ with - | ⟨b, l₂⟩
    hf  f hg g( : ∫∫_, f μ≤∫⋯⁻_, g ∂μ) :
    ⁻x,  Mpiμ≤∫⁻ x, g x ∂Measure. μ:by
  cases isEmpty_or_nonempty ( i,Xi with h | ⟨x⟩
  ·simp_rw [lintegral_of_isEmpty, le_rfl]
              simpa zip]using h)

end LMarginal

end MeasureTheory

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.23 Sekunden  ¤

*© Formatika GbR, Deutschland