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.

def IsTestSupermartingale reviewed
Causalean.Experimentation.Sequential

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)
Ω :
Type u_1
shared
M :
ℕ → Ω → ℝ
ℱ :
Filtration ℕ m0
μ :
IsTestSupermartingale M ℱ μ :
Prop
clause 1
clause 2
n :
0 ≤ M n
clause 3
μ[M 0] ≤ 1
Causalean.Experimentation.Sequential.IsTestSupermartingale · Causalean/Experimentation/Sequential/Ville.lean:35
theorem ville_inequality reviewed
Causalean.Experimentation.Sequential

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
Ω :
shared
ℱ :
Filtration ℕ m0
shared
M :
ℕ → Ω → ℝ
hM :
hnonneg :
∀ n, 0 ≤ M n
lam :
ℝ
hlam :
0 < lam
μ {ω | ∃ n, lam ≤ M n ω} ≤ ofReal (μ[M 0] / lam)
Proof (Lean source)
theorem ville_inequality [IsFiniteMeasure μ] {M : ℕ → Ω → ℝ} (hM : Supermartingale M ℱ μ) (hnonneg : ∀ n, 0 ≤ M n) {lam : ℝ} (hlam : 0 < lam) : μ {ω | ∃ n, lam ≤ M n ω} ≤ ofReal (μ[M 0] / lam) := by -- The "ever reaches lam" event is the increasing union of the finite-horizon events; apply the -- finite-horizon maximal inequality termwise. set A : ℕ → Set Ω := fun N => {ω | lam ≤ (range (N + 1)).sup' nonempty_range_add_one (fun k => M k ω)} with hA have hUnion : {ω | ∃ n, lam ≤ M n ω} = ⋃ N, A N := by ext ω simp only [hA, Set.mem_setOf_eq, Set.mem_iUnion] constructor · rintro ⟨n, hn⟩ exact ⟨n, Finset.le_sup'_of_le (f := fun k => M k ω) (Finset.self_mem_range_succ n) hn⟩ · rintro ⟨N, hN⟩ obtain ⟨k, _, hk⟩ := Finset.exists_mem_eq_sup' nonempty_range_add_one (fun k => M k ω) exact ⟨k, hN.trans hk.le⟩ have hmono : Monotone A := by intro a b hab ω hω simp only [hA, Set.mem_setOf_eq] at hω ⊢ have hsub : range (a + 1) ⊆ range (b + 1) := Finset.range_mono (Nat.succ_le_succ hab) exact le_trans hω (Finset.sup'_mono (fun k => M k ω) hsub nonempty_range_add_one) rw [hUnion, hmono.measure_iUnion] exact iSup_le (fun N => supermartingale_maximal_ineq hM hnonneg hlam N)
Causalean.Experimentation.Sequential.ville_inequality · Causalean/Experimentation/Sequential/Ville.lean:131
2 supporting declarations (lemmas, instances)
  • supermartingale_maximal_ineq theorem — 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₀] / λ.
    Ω :
    shared
    ℱ :
    Filtration ℕ m0
    shared
    M :
    ℕ → Ω → ℝ
    hM :
    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)
    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)
    Causalean.Experimentation.Sequential.supermartingale_maximal_ineq · Causalean/Experimentation/Sequential/Ville.lean:51
  • ville_test theorem — If M is a test supermartingale and the level α is positive, then the event that M ever reaches 1/α has measure at most α.
    Ω :
    shared
    ℱ :
    Filtration ℕ m0
    shared
    M :
    ℕ → Ω → ℝ
    hM :
    α :
    ℝ
    hα :
    0 < α
    μ {ω | ∃ 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 α
    Causalean.Experimentation.Sequential.ville_test · Causalean/Experimentation/Sequential/Ville.lean:162
Adaptive­Design 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.

structure AdaptiveExperiment reviewed
Causalean.Experimentation.Sequential

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)
Ω :
Type*
m0 :
The data-collection filtration: time `t` represents the information available after observing the time-`t` history and before the next assignment is made.
ℱ :
Filtration ℕ m0
The propensity process: `propensity t ω` is the probability of treating the time-`t` unit on history `ω`.
propensity :
ℕ → Ω → ℝ
The propensity is predictable: `propensity 0` is initial-information measurable, and `propensity (t + 1)` is determined by the information available at time `t`.
propensity_predictable :
IsPredictable ℱ propensity
Propensities are nonnegative.
propensity_nonneg :
∀ t ω, 0 ≤ propensity t ω
Propensities are at most one.
propensity_le_one :
∀ t ω, propensity t ω ≤ 1
Causalean.Experimentation.Sequential.AdaptiveExperiment · Causalean/Experimentation/Sequential/AdaptiveDesign.lean:31
def HasOverlap reviewed
Causalean.Experimentation.Sequential.AdaptiveExperiment

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)
Ω :
Type u_1
shared
E :
δ :
ℝ
HasOverlap E δ :
Prop
clause 1
0 < δ
clause 2
t ω :
δ ≤ E.propensity t ω
E.propensity t ω ≤ 1 - δ
Causalean.Experimentation.Sequential.AdaptiveExperiment.HasOverlap · Causalean/Experimentation/Sequential/AdaptiveDesign.lean:57 · uses AdaptiveExperiment
lemma propensity_pos_of_overlap reviewed
Causalean.Experimentation.Sequential.AdaptiveExperiment

Under overlap with margin δ, every propensity is at least δ, hence strictly positive — so inverse-propensity weights are finite.

Formal statement
Ω :
shared
δ :
ℝ
h :
E.HasOverlap δ
t :
ℕ
ω :
Ω
0 < E.propensity t ω
Proof (Lean source)
lemma propensity_pos_of_overlap {E : AdaptiveExperiment Ω m0} {δ : ℝ} (h : E.HasOverlap δ) (t : ℕ) (ω : Ω) : 0 < E.propensity t ω := lt_of_lt_of_le h.1 (h.2 t ω).1
Causalean.Experimentation.Sequential.AdaptiveExperiment.propensity_pos_of_overlap · Causalean/Experimentation/Sequential/AdaptiveDesign.lean:68 · uses AdaptiveExperiment , HasOverlap
Anytime­Valid 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.

def rejectionRegion reviewed
Causalean.Experimentation.Sequential

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 1/α1/α at at least one time, with this quotient understood as zero when α=0α=0.

Definition (Lean source)
Ω :
Type u_1
shared
M :
ℕ → Ω → ℝ
α :
ℝ
rejectionRegion M α :
Set Ω
{ω | ∃ n, 1 / α ≤ M n ω}
Causalean.Experimentation.Sequential.rejectionRegion · Causalean/Experimentation/Sequential/AnytimeValid.lean:36
def IsAnytimeValid reviewed
Causalean.Experimentation.Sequential

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 max⁡{α,0}\max\{α,0\}.

Definition (Lean source)
Ω :
Type u_1
shared
R :
Set Ω
μ :
α :
ℝ
IsAnytimeValid R μ α :
Prop
μ R ≤ ofReal α
Causalean.Experimentation.Sequential.IsAnytimeValid · Causalean/Experimentation/Sequential/AnytimeValid.lean:42
theorem isAnytimeValid_rejectionRegion reviewed
Causalean.Experimentation.Sequential

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
Ω :
shared
ℱ :
Filtration ℕ m0
shared
M :
ℕ → Ω → ℝ
hM :
α :
ℝ
hα :
0 < α
Proof (Lean source)
theorem isAnytimeValid_rejectionRegion [IsFiniteMeasure μ] {M : ℕ → Ω → ℝ} (hM : IsTestSupermartingale M ℱ μ) {α : ℝ} (hα : 0 < α) : IsAnytimeValid (rejectionRegion M α) μ α := ville_test hM hα
Causalean.Experimentation.Sequential.isAnytimeValid_rejectionRegion · Causalean/Experimentation/Sequential/AnytimeValid.lean:49 · uses IsAnytimeValid , IsTestSupermartingale , rejectionRegion
def IsConfidenceSequence reviewed
Causalean.Experimentation.Sequential

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 max⁡{α,0}\max\{α,0\}.

Definition (Lean source)
Ω :
Type u_1
shared
cover :
ℕ → Ω → Prop
μ :
α :
ℝ
IsConfidenceSequence cover μ α :
Prop
μ {ω | ∃ n, ¬ cover n ω} ≤ ofReal α
Causalean.Experimentation.Sequential.IsConfidenceSequence · Causalean/Experimentation/Sequential/AnytimeValid.lean:60
def confSeqOfWealth reviewed
Causalean.Experimentation.Sequential

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 1/α1/α, with this quotient understood as zero when α=0α=0.

Definition (Lean source)
Ω :
Type u_1
shared
M :
ℕ → Ω → ℝ
α :
ℝ
confSeqOfWealth M α :
ℕ → Ω → Prop
fun n ω => M n ω < 1 / α
Causalean.Experimentation.Sequential.confSeqOfWealth · Causalean/Experimentation/Sequential/AnytimeValid.lean:68
theorem isConfidenceSequence_confSeqOfWealth reviewed
Causalean.Experimentation.Sequential

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 α.

Formal statement
Ω :
shared
ℱ :
Filtration ℕ m0
shared
M :
ℕ → Ω → ℝ
hM :
α :
ℝ
hα :
0 < α
Proof (Lean source)
theorem isConfidenceSequence_confSeqOfWealth [IsFiniteMeasure μ] {M : ℕ → Ω → ℝ} (hM : IsTestSupermartingale M ℱ μ) {α : ℝ} (hα : 0 < α) : IsConfidenceSequence (confSeqOfWealth M α) μ α := by have hset : {ω | ∃ n, ¬ confSeqOfWealth M α n ω} = {ω | ∃ n, 1 / α ≤ M n ω} := by ext ω; simp only [confSeqOfWealth, Set.mem_setOf_eq, not_lt] rw [IsConfidenceSequence, hset] exact ville_test hM hα
Causalean.Experimentation.Sequential.isConfidenceSequence_confSeqOfWealth · Causalean/Experimentation/Sequential/AnytimeValid.lean:75 · uses IsConfidenceSequence , IsTestSupermartingale , confSeqOfWealth