Experimentation.Sequential
The anytime-valid inference substrate for adaptive / sequential experiments, where the treatment-assignment rule evolves with the accumulating data.
Ville 2 core · 2 supporting Ville's inequality bounds, under a probability law, the probability that a nonnegative supermartingale ever crosses a positive level by its initial expected value divided by that level. ★ IsTestSupermartingale★ ville_inequality
Ville inequality
Ville's inequality bounds, under a probability law, the probability that a nonnegative supermartingale ever crosses a positive level by its initial expected value divided by that level. Because the bound holds simultaneously over time, it supports inference at data-dependent stopping times.
This file packages test supermartingales as nonnegative supermartingales with initial expected
wealth at most one. It proves the finite-horizon maximal inequality under a finite measure by
optional stopping at a hitting time, passes to the time-uniform probability bound, and specializes
the crossing level to 1/α for anytime-valid testing.
Given a sample space, a σ-algebra on that space, a real-valued process indexed by time, a filtration on that σ-algebra, and a measure on that measurable space, a test supermartingale is a supermartingale adapted to that filtration whose value is nonnegative at every time and sample point and whose expected initial value is at most one.
Definition (Lean source)
Ville's inequality (time-uniform maximal inequality). If M is a supermartingale under the measure, M is everywhere nonnegative, and the level λ is positive, then the measure of the event that M ever reaches λ is at most E[M₀] / λ.
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
supermartingale_maximal_ineqtheorem — Finite-horizon supermartingale maximal inequality. If M is a supermartingale under a finite measure, M is everywhere nonnegative, the level λ is positive, and the horizon is n, then the crossing event has measure at most E[M₀] / λ.hypothesesconclusion≤ ofReal (μ[M 0] / lam)Proof (Lean source)
theorem supermartingale_maximal_ineq [IsFiniteMeasure μ] {M : ℕ → Ω → ℝ} (hM : Supermartingale M ℱ μ) (hnonneg : ∀ n, 0 ≤ M n) {lam : ℝ} (hlam : 0 < lam) (n : ℕ) : μ {ω | lam ≤ (range (n + 1)).sup' nonempty_range_add_one (fun k => M k ω)} ≤ ofReal (μ[M 0] / lam) := by classical let τ : Ω → ℕ∞ := fun ω => (hittingBtwn M {y : ℝ | lam ≤ y} (0 : ℕ) n ω : ℕ) let A : Set Ω := {ω | lam ≤ (range (n + 1)).sup' nonempty_range_add_one (fun k => M k ω)} have hAmeas : MeasurableSet A := by exact measurableSet_le measurable_const (Finset.measurable_range_sup'' fun k _ => (hM.1.stronglyMeasurable (i := k)).measurable) have hτstop : IsStoppingTime ℱ τ := by exact hM.stronglyAdapted.adapted.isStoppingTime_hittingBtwn measurableSet_Ici have hτbdd : ∀ ω, τ ω ≤ n := by intro ω simpa [τ] using (show (((hittingBtwn M {y : ℝ | lam ≤ y} (0 : ℕ) n ω : ℕ) : ℕ∞) ≤ (n : ℕ∞)) from by exact WithTop.coe_le_coe.2 (hittingBtwn_le (u := M) (s := {y : ℝ | lam ≤ y}) (n := (0 : ℕ)) (m := n) (ω := ω))) have hτint : Integrable (stoppedValue M τ) μ := integrable_stoppedValue ℕ hτstop hM.2.2 hτbdd have hhit : ∀ ω ∈ A, lam ≤ stoppedValue M τ ω := by intro ω hω simp_rw [A, Set.mem_setOf_eq, Finset.le_sup'_iff, Finset.mem_range, Nat.lt_succ_iff] at hω refine stoppedValue_hittingBtwn_mem ?_ simpa only [Set.mem_setOf_eq, Set.mem_Icc, zero_le, true_and] using hω have hsetLower : lam * (μ A).toReal ≤ ∫ ω in A, stoppedValue M τ ω ∂μ := setIntegral_ge_of_const_le_real hAmeas (measure_ne_top _ _) hhit hτint.integrableOn have hstopped_nonneg : 0 ≤ stoppedValue M τ := by intro ω exact hnonneg _ ω have hset_le_total : ∫ ω in A, stoppedValue M τ ω ∂μ ≤ μ[stoppedValue M τ] := by have hcompl_nonneg : 0 ≤ ∫ ω in Aᶜ, stoppedValue M τ ω ∂μ := setIntegral_nonneg hAmeas.compl fun ω _ => hstopped_nonneg ω have hadd := integral_add_compl hAmeas hτint linarith have hτ_le_M0 : μ[stoppedValue M τ] ≤ μ[M 0] := by have hneg : Submartingale (fun k ω => -M k ω) ℱ μ := hM.neg have hopt : μ[stoppedValue (fun k ω => -M k ω) (fun _ : Ω => ((0 : ℕ) : ℕ∞))] ≤ μ[stoppedValue (fun k ω => -M k ω) τ] := by refine hneg.expected_stoppedValue_mono (isStoppingTime_const ℱ 0) hτstop ?_ hτbdd intro ω simp [τ] have hleft : μ[stoppedValue (fun k ω => -M k ω) (fun _ : Ω => ((0 : ℕ) : ℕ∞))] = - μ[M 0] := by rw [show stoppedValue (fun k ω => -M k ω) (fun _ : Ω => ((0 : ℕ) : ℕ∞)) = fun ω => -M 0 ω by funext ω simp only [stoppedValue] rfl] exact integral_neg (M 0) have hright : μ[stoppedValue (fun k ω => -M k ω) τ] = - μ[stoppedValue M τ] := by rw [show stoppedValue (fun k ω => -M k ω) τ = fun ω => - stoppedValue M τ ω by funext ω simp [stoppedValue]] exact integral_neg (stoppedValue M τ) rw [hleft, hright] at hopt linarith have hmul : lam * (μ A).toReal ≤ μ[M 0] := hsetLower.trans (hset_le_total.trans hτ_le_M0) have hM0_nonneg : 0 ≤ μ[M 0] := integral_nonneg (hnonneg 0) have hdiv_nonneg : 0 ≤ μ[M 0] / lam := div_nonneg hM0_nonneg hlam.le change μ A ≤ ofReal (μ[M 0] / lam) rw [ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) hdiv_nonneg] exact (le_div_iff₀ hlam).2 (by simpa [mul_comm] using hmul) -
ville_testtheorem — If M is a test supermartingale and the level α is positive, then the event that M ever reaches 1/α has measure at most α.hypothesesconclusionμ {ω | ∃ n, 1 / α ≤ M n ω} ≤ ofReal αProof (Lean source)
theorem ville_test [IsFiniteMeasure μ] {M : ℕ → Ω → ℝ} (hM : IsTestSupermartingale M ℱ μ) {α : ℝ} (hα : 0 < α) : μ {ω | ∃ n, 1 / α ≤ M n ω} ≤ ofReal α := by obtain ⟨hsuper, hnn, hM0⟩ := hM have hlam : (0 : ℝ) < 1 / α := by positivity refine le_trans (ville_inequality hsuper hnn hlam) ?_ apply ENNReal.ofReal_le_ofReal rw [div_div_eq_mul_div, div_one] calc μ[M 0] * α ≤ 1 * α := mul_le_mul_of_nonneg_right hM0 hα.le _ = α := one_mul α
AdaptiveDesign 3 core · 0 supporting Adaptive experiments allow each treatment probability to depend on the observed pre-assignment history. ★ AdaptiveExperiment★ propensity_pos_of_overlap
Adaptive sequential designs
Adaptive experiments allow each treatment probability to depend on the observed pre-assignment
history. Following Mathlib's discrete predictability convention, the initial propensity is
initial-information measurable and the propensity at time t + 1 is measurable from the
information available at time t.
The structure AdaptiveExperiment packages the filtration and predictable propensity process.
Its overlap predicate records a positive margin separating every propensity from zero and one,
as required by inverse-propensity weighting, and propensity_pos_of_overlap extracts strict
positivity. Sequential inference for such designs is developed through the martingale layer.
An adaptive sequential experiment: a time-indexed information flow ℱ on the outcome space together with a propensity process propensity recording the treatment probability of the unit arriving at each time, subject to three conditions — the process is predictable: the time-0 propensity is measurable with respect to the initial information, and the time-(t+1) propensity depends only on the information available at time t, every propensity is nonnegative, and every propensity is at most one.
Definition (Lean source)
For a measurable outcome space, an adaptive experiment on that space, and a real number serving as an overlap margin, the overlap condition with that margin holds precisely when the margin is strictly positive and at every time and on every outcome history, the experiment's treatment probability lies between the margin and one minus the margin.
Definition (Lean source)
Under overlap with margin δ, every propensity is at least δ, hence strictly positive — so inverse-propensity weights are finite.
Formal statement
Proof (Lean source)
AnytimeValid 6 core · 0 supporting This file turns Ville's inequality for test supermartingales into reusable sequential-inference objects under probability measures. ★ IsAnytimeValid★ isAnytimeValid_rejectionRegion★ isConfidenceSequence_confSeqOfWealth
Anytime-valid tests and confidence sequences
This file turns Ville's inequality for test supermartingales into reusable sequential-inference
objects under probability measures. An anytime-valid test rejects when wealth first reaches
1/α; Ville's inequality controls the probability of that event by α, regardless of when the
analyst stops. Dually, wealth inversion retains parameter values whose wealth remains below
1/α, producing simultaneous coverage at least 1 − α.
The file defines the crossing event, the anytime-validity and confidence-sequence predicates, and the two theorems that transfer Ville's probability bound to type-I error and miscoverage control.
For a sample space and a real-valued wealth process indexed by time and outcome, and a real-valued test level, the sequential-test rejection region is the event that the wealth reaches or exceeds at at least one time, with this quotient understood as zero when .
Definition (Lean source)
For a measurable sample space, an event on that space, a probability measure on the sample space, and a real-valued test level, anytime validity at that level means that the event has measure at most .
Definition (Lean source)
Anytime-valid type-I error control. If M is a test supermartingale under the probability measure and the level α is positive, then the crossing event has measure at most α.
Formal statement
Proof (Lean source)
For a measurable sample space, a time-indexed coverage predicate on that space, a probability measure on the sample space, and a real-valued level, the confidence-sequence property means that simultaneous miscoverage has measure at most .
Definition (Lean source)
For a sample space and a real-valued wealth process indexed by time and outcome and a real-valued level, the wealth-inverted coverage predicate holds at a given time and outcome exactly when the wealth at that time is strictly less than , with this quotient understood as zero when .
Definition (Lean source)
Confidence-sequence coverage. If M is a test supermartingale under the probability measure and the level α is positive, then wealth inversion fails to cover at some time with probability at most α.