File size: 4,938 Bytes
b317718 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | import OAI.Probability.GaussianReplacement.StreamLearner
namespace OAI
open MeasureTheory ProbabilityTheory Set Filter
open scoped ENNReal NNReal RealInnerProductSpace Topology
noncomputable section
universe u
namespace CurrentProjection
namespace StreamKernel
open unitInterval
section BorelVersion
variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y]
[Nonempty Y] {μ : Measure X} (f : X → Measure Y)
(hf : AEMeasurable f μ) (hp : ∀ x, IsProbabilityMeasure (f x))
def borelKernel : Kernel X Y :=
⟨fun x => if hf.mk f x Set.univ = 1 then hf.mk f x
else Measure.dirac (Classical.choice ‹Nonempty Y›),
hf.measurable_mk.ite
(measurableSet_eq_fun ((Measure.measurable_coe MeasurableSet.univ).comp
hf.measurable_mk) measurable_const) measurable_const⟩
instance borelKernel_markov : IsMarkovKernel (borelKernel f hf) := by
constructor
intro x
dsimp [borelKernel]
split_ifs with h
· exact ⟨h⟩
· infer_instance
lemma borelKernel_ae (hp : ∀ x, IsProbabilityMeasure (f x)) : ∀ᵐ x ∂μ, borelKernel f hf x = f x := by
filter_upwards [hf.ae_eq_mk] with x hx
have h : hf.mk f x Set.univ = 1 := by
rw [← hx]
exact (hp x).measure_univ
change (if hf.mk f x Set.univ = 1 then hf.mk f x else _) = f x
rw [ite_eq_left h, ← hx]
end BorelVersion
abbrev Coins (n : ℕ) := Fin (n+1) → I
def coinLaw (n : ℕ) : Measure (Coins n) := Measure.pi fun _ => (volume : Measure I)
instance coinLaw_probability (n : ℕ) : IsProbabilityMeasure (coinLaw n) := by
unfold coinLaw
infer_instance
section Fold
variable {A : Type*} [MeasurableSpace A]
(initial : I → A) (step : ℕ → A → I → A)
def foldCoins : (n : ℕ) → Coins n → A
| 0, z => initial (z 0)
| n+1, z => step (n+1) (foldCoins n (Fin.init z)) (z (Fin.last (n+1)))
lemma measurable_foldCoins (hi : Measurable initial)
(hs : ∀ n, Measurable (Function.uncurry (step n))) (n : ℕ) :
Measurable (foldCoins initial step n) := by
induction n with
| zero => exact hi.comp (measurable_pi_apply 0)
| succ n ih =>
exact (hs (n+1)).comp
((ih.comp (Measurable.of_eval fun i => measurable_pi_apply i.castSucc)).prodMk
(measurable_pi_apply (Fin.last (n+1))))
lemma coinLaw_split (n : ℕ) :
(coinLaw (n+1)).map (fun z => (z (Fin.last (n+1)), Fin.init z)) =
(volume : Measure I).prod (coinLaw n) := by
have h := (measurePreserving_piFinSuccAbove
(fun _ : Fin (n+2) => (volume : Measure I)) (Fin.last (n+1))).map_eq
have he : (fun z : Coins (n+1) => (z (Fin.last (n+1)), Fin.init z)) =
(MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+2) => I) (Fin.last (n+1))) := by
funext z
simp [MeasurableEquiv.piFinSuccAbove, Fin.init_def]
rw [he]
exact h
lemma map_freshCoin {B : Type*} [MeasurableSpace B] (n : ℕ)
(state : Coins n → A) (out : A → I → B)
(hstate : Measurable state) (ho : Measurable (Function.uncurry out)) :
(coinLaw (n+1)).map (fun z => out (state (Fin.init z)) (z (Fin.last (n+1)))) =
((coinLaw n).map state).bind (fun a => (volume : Measure I).map (out a)) := by
have hk : Measurable (fun a => (volume : Measure I).map (out a)) :=
by
apply Measure.measurable_of_measurable_coe
intro s hs'
simp_rw [Measure.map_apply (ho).of_uncurry_left hs']
exact measurable_measure_prodMk_left ((ho) hs')
apply Measure.ext_of_lintegral
intro f hf
have hall : Measurable (fun z : Coins (n+1) =>
out (state (Fin.init z)) (z (Fin.last (n+1)))) :=
ho.comp ((hstate.comp (Measurable.of_eval fun i =>
measurable_pi_apply i.castSucc)).prodMk (measurable_pi_apply (Fin.last (n+1))))
rw [lintegral_map hf hall,
Measure.lintegral_bind hk.aemeasurable hf.aemeasurable,
lintegral_map _ hstate]
· have hfun : Measurable (fun z : I × Coins n =>
f (out (state z.2) z.1)) :=
hf.comp ((ho).comp ((hstate.comp measurable_snd).prodMk measurable_fst))
have he := lintegral_map (μ:=coinLaw (n+1)) hfun
(show Measurable (fun z : Coins (n+1) =>
(z (Fin.last (n+1)), Fin.init z)) from
(measurable_pi_apply _).prodMk
(Measurable.of_eval fun i => measurable_pi_apply i.castSucc))
rw [coinLaw_split] at he
rw [← he, lintegral_prod_symm _ hfun.aemeasurable]
apply lintegral_congr
intro z
rw [lintegral_map hf ((ho).of_uncurry_left)]
· exact (Measure.measurable_lintegral hf).comp hk
lemma map_foldCoins_succ (hi : Measurable initial)
(hs : ∀ n, Measurable (Function.uncurry (step n))) (n : ℕ) :
(coinLaw (n+1)).map (foldCoins initial step (n+1)) =
((coinLaw n).map (foldCoins initial step n)).bind
(fun a => (volume : Measure I).map (step (n+1) a)) := by
exact map_freshCoin n (foldCoins initial step n) (step (n+1))
(measurable_foldCoins initial step hi hs n) (hs (n+1))
end Fold
end StreamKernel
end CurrentProjection
end
end OAI
|