math / data /lean /OAI /Probability /MatroidSecretary /Transport /GeneralSimulationModel.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.03 kB
import OAI.Probability.MatroidProphet.Main
import Mathlib.Probability.Independence.Basic
import Mathlib.MeasureTheory.Integral.Bochner.Basic
namespace OAI
namespace MatroidProphet.General
open MeasureTheory ProbabilityTheory
/-- A decision uses only the entire initial seed, the initially observed vector,
and the label/value history through the current arrival. -/
structure OnlineRule (n : β„•) (R : Type*) [MeasurableSpace R] where
decide : (k : Fin n) β†’ R β†’ Weights n β†’ History n k β†’ Bool
measurable_decide : βˆ€ k, Measurable
(fun x : R Γ— (Weights n Γ— History n k) => decide k x.1 x.2.1 x.2.2)
def decisionAt {n : β„•} {R : Type*} [MeasurableSpace R]
(A : OnlineRule n R) (r : R) (s v : Weights n)
(Ο€ : ArrivalOrder n) (k : Fin n) : Bool :=
A.decide k r s (history v Ο€ k)
noncomputable def acceptedThrough {n : β„•} {R : Type*} [MeasurableSpace R]
(A : OnlineRule n R) (r : R) (s v : Weights n)
(Ο€ : ArrivalOrder n) (t : β„•) : Finset (Fin n) := by
classical
exact Finset.univ.filter fun e =>
(Ο€.symm e).val < t ∧ decisionAt A r s v Ο€ (Ο€.symm e) = true
noncomputable def reward {n : β„•} {R : Type*} [MeasurableSpace R]
(A : OnlineRule n R) (r : R) (s v : Weights n) (Ο€ : ArrivalOrder n) : ℝ :=
βˆ‘ e ∈ acceptedThrough A r s v Ο€ n, v e
def Feasible {n : β„•} {R : Type*} [MeasurableSpace R]
(M : Matroid (Fin n)) (A : OnlineRule n R) : Prop :=
βˆ€ (r : R) (s v : Weights n) (Ο€ : ArrivalOrder n) (t : β„•),
(βˆ€ e, 0 ≀ s e) β†’ (βˆ€ e, 0 ≀ v e) β†’
M.Indep (acceptedThrough A r s v Ο€ t : Set (Fin n))
/-- The observation mask is a measurable function of the seed alone. -/
structure HiddenRule (n : β„•) (R : Type*) [MeasurableSpace R] where
mask : R β†’ Finset (Fin n)
measurable_mask : Measurable mask
core : OnlineRule n R
noncomputable def observed {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (r : R) (w : Weights n) : Weights n := by
classical
exact fun e => if e ∈ A.mask r then w e else 0
noncomputable def hiddenAcceptedThrough {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (r : R) (w : Weights n)
(Ο€ : ArrivalOrder n) (t : β„•) : Finset (Fin n) :=
acceptedThrough A.core r (observed A r w) w Ο€ t \ A.mask r
noncomputable def hiddenReward {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (r : R) (w : Weights n) (Ο€ : ArrivalOrder n) : ℝ :=
βˆ‘ e ∈ hiddenAcceptedThrough A r w Ο€ n, w e
noncomputable def hiddenWorstReward {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (w : Weights n) (r : R) : ℝ := by
classical
exact Finset.univ.inf' Finset.univ_nonempty (hiddenReward A r w)
def HiddenFeasible {n : β„•} {R : Type*} [MeasurableSpace R]
(M : Matroid (Fin n)) (A : HiddenRule n R) : Prop :=
βˆ€ (w : Weights n), (βˆ€ e, 0 ≀ w e) β†’
βˆ€ (r : R) (Ο€ : ArrivalOrder n) (t : β„•),
M.Indep (hiddenAcceptedThrough A r w Ο€ t : Set (Fin n))
/-- Sample values on the sacrificed mask, and realized values elsewhere. -/
noncomputable def glue {n : β„•} (mask : Finset (Fin n)) (s v : Weights n) : Weights n := by
classical
exact fun e => if e ∈ mask then s e else v e
noncomputable def simulationHistory {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (r : R) (s : Weights n)
{k : Fin n} (h : History n k) : History n k := by
classical
exact fun j => ((h j).1, if (h j).1 ∈ A.mask r then s (h j).1 else (h j).2)
noncomputable def simulationDecision {n : β„•} {R : Type*} [MeasurableSpace R]
(A : HiddenRule n R) (k : Fin n) (r : R) (s : Weights n)
(h : History n k) : Bool := by
classical
exact if (h ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask r then false
else A.core.decide k r (observed A r s) (simulationHistory A r s h)
/-- Full source contract for `lem:simulation`, with arbitrary measurable seed
and probability spaces. The simulator is constructed before the distributions
and adversary are supplied. Its decision function is specified concretely;
the conjunction includes exact execution, feasibility, the seed/glued-vector
joint law, integrability, and preservation of the same competitive ratio. -/
def SimulationContract.{u, v} : Prop :=
βˆ€ (n : β„•) (R : Type v) [MeasurableSpace R]
(M : Matroid (Fin n)) (A : HiddenRule n R)
(Ξ½ : Measure R), IsProbabilityMeasure Ξ½ β†’
βˆ€ (c : ℝ), HiddenFeasible M A β†’
(βˆ€ (w : Weights n), (βˆ€ e, 0 ≀ w e) β†’
c * optimum M w ≀ ∫ r, hiddenWorstReward A w r βˆ‚Ξ½) β†’
βˆƒ B : OnlineRule n R,
(βˆ€ (k : Fin n) (r : R) (s : Weights n) (h : History n k),
B.decide k r s h = simulationDecision A k r s h) ∧
Feasible M B ∧
(βˆ€ (r : R) (s v : Weights n) (Ο€ : ArrivalOrder n) (t : β„•),
acceptedThrough B r s v Ο€ t =
hiddenAcceptedThrough A r (glue (A.mask r) s v) Ο€ t) ∧
(βˆ€ (r : R) (s v : Weights n) (Ο€ : ArrivalOrder n),
reward B r s v Ο€ = hiddenReward A r (glue (A.mask r) s v) Ο€) ∧
βˆ€ {Ξ© : Type u} [MeasurableSpace Ξ©] (ΞΌ : Measure Ξ©) [IsProbabilityMeasure ΞΌ]
(S V : Ξ© β†’ Weights n) (seed : Ξ© β†’ R),
Measurable S β†’ Measurable V β†’ Measurable seed β†’
(βˆ€α΅ Ο‰ βˆ‚ΞΌ, βˆ€ e, 0 ≀ S Ο‰ e) β†’
(βˆ€α΅ Ο‰ βˆ‚ΞΌ, βˆ€ e, 0 ≀ V Ο‰ e) β†’
iIndepFun (pairedCoordinates S V) ΞΌ β†’
(βˆ€ e, ΞΌ.map (fun Ο‰ => S Ο‰ e) = ΞΌ.map (fun Ο‰ => V Ο‰ e)) β†’
IndepFun (fun Ο‰ => (S Ο‰, V Ο‰)) seed ΞΌ β†’ ΞΌ.map seed = Ξ½ β†’
Integrable (fun Ο‰ => optimum M (V Ο‰)) ΞΌ β†’
βˆ€ (Ο€ : Ξ© β†’ ArrivalOrder n), Measurable Ο€ β†’
MeasurePreserving (fun Ο‰ => (seed Ο‰, glue (A.mask (seed Ο‰)) (S Ο‰) (V Ο‰)))
μ (ν.prod (μ.map V)) ∧
Integrable (fun Ο‰ => reward B (seed Ο‰) (S Ο‰) (V Ο‰) (Ο€ Ο‰)) ΞΌ ∧
c * (∫ Ο‰, optimum M (V Ο‰) βˆ‚ΞΌ) ≀
∫ Ο‰, reward B (seed Ο‰) (S Ο‰) (V Ο‰) (Ο€ Ο‰) βˆ‚ΞΌ
end MatroidProphet.General
end OAI