import Mathlib.Analysis.Normed.Ring.Basic import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Order.Lattice import Mathlib.Probability.Kernel.Basic import Mathlib.Probability.Kernel.IonescuTulcea.Traj import Mathlib.Probability.Process.FiniteDimensionalLaws import Mathlib.Probability.HasCondDistrib import Mathlib.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.Probability.Independence.Basic import Mathlib.Probability.Independence.Conditional import Mathlib.MeasureTheory.Measure.SubFinite import Mathlib.Probability.Kernel.RadonNikodym import Mathlib.MeasureTheory.MeasurableSpace.Embedding import Mathlib.Order.Restriction import Mathlib.Probability.Kernel.IonescuTulcea.Maps /-! # Standalone extraction for `Learning.IsAlgEnvSeq.filtration_eq_comap` Definitions are copied verbatim; theorem proofs are replaced by `sorry`. Auto-generated by ChallengeGen. -/ set_option quotPrecheck false -- Namespace stubs (so later `open`s resolve). namespace Finset end Finset namespace MeasureTheory end MeasureTheory namespace ProbabilityTheory end ProbabilityTheory namespace ENNReal end ENNReal namespace Learning end Learning namespace Learning.IsAlgEnvSeq end Learning.IsAlgEnvSeq -- ═══ ForMathlib.MeasureTheory.Measurable ═══ section open Finset namespace MeasureTheory variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {μ : Measure α} lemma measurable_comp_comap (f : α → β) {g : β → γ} (hg : Measurable g) : Measurable[mβ.comap f] (g ∘ f) := sorry end MeasureTheory end -- ═══ ForMathlib.MeasureTheory.Order.Lattice ═══ section open Finset variable {α δ : Type*} [MeasurableSpace δ] [SemilatticeInf α] {m : MeasurableSpace α} [MeasurableInf₂ α] attribute [to_dual existing] MeasurableInf₂ end -- ═══ SequentialLearning.Algorithm ═══ section open MeasureTheory ProbabilityTheory Filter Real Finset open scoped ENNReal NNReal namespace Learning variable {𝓞 𝓐 𝓨 Ω : Type*} {m𝓞 : MeasurableSpace 𝓞} {m𝓐 : MeasurableSpace 𝓐} {m𝓨 : MeasurableSpace 𝓨} {mΩ : MeasurableSpace Ω} /-- One round of interaction: an observation, then an action, then a feedback. -/ abbrev Round (𝓞 𝓐 𝓨 : Type*) := 𝓞 × 𝓐 × 𝓨 /-- History of `n` complete rounds; `n = 0` is the empty history. -/ abbrev Hist (𝓞 𝓐 𝓨 : Type*) (n : ℕ) := Fin n → Round 𝓞 𝓐 𝓨 /-- A stochastic, sequential algorithm. At each round, it sees an observation in `𝓞`, then takes an action in `𝓐`, and finally receives feedback in `𝓨`. The action is a random function of the past rounds and the current observation. -/ @[ext] structure Algorithm (𝓞 𝓐 𝓨 : Type*) [MeasurableSpace 𝓞] [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where /-- Law of the action of round `n` given the past rounds and the current observation. -/ policy : (n : ℕ) → Kernel (Hist 𝓞 𝓐 𝓨 n × 𝓞) 𝓐 /-- The policy is a Markov kernel. -/ [isMarkovKernel_policy : ∀ n, IsMarkovKernel (policy n)] /-- A stochastic environment. At each round, an observation is drawn prior to the algorithm taking an action. Then the environment provides feedback based on the observation and the action. -/ @[ext] structure Environment (𝓞 𝓐 𝓨 : Type*) [MeasurableSpace 𝓞] [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where /-- Law of the observation of round `n` given the past rounds. -/ obs : (n : ℕ) → Kernel (Hist 𝓞 𝓐 𝓨 n) 𝓞 /-- Law of the feedback of round `n` given the past rounds, the observation and the action. -/ feedback : (n : ℕ) → Kernel ((Hist 𝓞 𝓐 𝓨 n × 𝓞) × 𝓐) 𝓨 /-- The observation kernel is a Markov kernel. -/ [isMarkovKernel_obs : ∀ n, IsMarkovKernel (obs n)] /-- The feedback kernel is a Markov kernel. -/ [isMarkovKernel_feedback : ∀ n, IsMarkovKernel (feedback n)] section IsAlgEnvSeq variable {O : ℕ → Ω → 𝓞} {A : ℕ → Ω → 𝓐} {Y : ℕ → Ω → 𝓨} {alg : Algorithm 𝓞 𝓐 𝓨} {env : Environment 𝓞 𝓐 𝓨} {P : Measure Ω} [IsFiniteMeasure P] {N : ℕ} /-- History of the algorithm-environment sequence before time `n`: the rounds at times `0, ..., n - 1`. -/ def history (O : ℕ → Ω → 𝓞) (A : ℕ → Ω → 𝓐) (Y : ℕ → Ω → 𝓨) (n : ℕ) (ω : Ω) : Hist 𝓞 𝓐 𝓨 n := fun i ↦ (O i ω, A i ω, Y i ω) @[fun_prop] lemma measurable_history (hO : ∀ n, Measurable (O n)) (hA : ∀ n, Measurable (A n)) (hY : ∀ n, Measurable (Y n)) (n : ℕ) : Measurable (history O A Y n) := sorry /-- The history before time `m` is a restriction of the history before time `n ≥ m`. -/ lemma history_eq_comp_history {m n : ℕ} (hmn : m ≤ n) : history O A Y m = (fun h (i : Fin m) ↦ h (Fin.castLE hmn i)) ∘ history O A Y n := sorry /-- An algorithm-environment sequence: a sequence of observations, actions and feedbacks generated by an algorithm interacting with an environment. -/ structure IsAlgEnvSeq (O : ℕ → Ω → 𝓞) (A : ℕ → Ω → 𝓐) (Y : ℕ → Ω → 𝓨) (alg : Algorithm 𝓞 𝓐 𝓨) (env : Environment 𝓞 𝓐 𝓨) (P : Measure Ω) [IsFiniteMeasure P] : Prop where /-- The observation sequence is measurable. -/ measurable_obs n : Measurable (O n) := sorry /-- The action sequence is measurable. -/ measurable_action n : Measurable (A n) := sorry /-- The feedback sequence is measurable. -/ measurable_feedback n : Measurable (Y n) := sorry /-- The observation at time `n` has the correct conditional distribution given the history. -/ hasCondDistrib_obs n : HasCondDistrib (O n) (history O A Y n) (env.obs n) P /-- The action at time `n` has the correct conditional distribution given the history and the observation at time `n`. -/ hasCondDistrib_action n : HasCondDistrib (A n) (fun ω ↦ (history O A Y n ω, O n ω)) (alg.policy n) P /-- The feedback at time `n` has the correct conditional distribution given the history, the observation and the action at time `n`. -/ hasCondDistrib_feedback n : HasCondDistrib (Y n) (fun ω ↦ ((history O A Y n ω, O n ω), A n ω)) (env.feedback n) P section Filtration namespace IsAlgEnvSeq /-- Filtration generated by the history up to time `n` (included): `h.filtration n` is the σ-algebra generated by `history O A Y (n + 1)`, that is by the rounds at times `0, ..., n`. -/ def filtration (h : IsAlgEnvSeq O A Y alg env P) : Filtration ℕ mΩ where seq n := MeasurableSpace.comap (history O A Y (n + 1)) inferInstance mono' i j hij := by simp only rw [← measurable_iff_comap_le, history_eq_comp_history (Nat.succ_le_succ hij)] exact measurable_comp_comap _ (by fun_prop) le' i := by rw [← measurable_iff_comap_le] exact Learning.measurable_history h.measurable_obs h.measurable_action h.measurable_feedback _ lemma filtration_eq_comap (h : IsAlgEnvSeq O A Y alg env P) (n : ℕ) : h.filtration n = MeasurableSpace.comap (history O A Y (n + 1)) inferInstance := sorry end IsAlgEnvSeq end Filtration end IsAlgEnvSeq end Learning end