Introduction
Large language model (LLM) agents are increasingly used to solve complex tasks through multi-step reasoning, tool use, and interaction with external environments. Early agent systems such as ReAct (Yao et al., 2023) interleave reasoning and actions, while later work introduces explicit workflow states, memory management, and search over alternative decisions to improve long-horizon execution (Wu et al., 2024; Zhang et al., 2026; Wei et al., 2026). Recent work also studies how to allocate models, tools, and computation across agent pipelines, reflecting the growing cost and complexity of long-running agents (Hua et al., 2026a; Gao and Peng, 2025). As agents operate for longer horizons with less human supervision, failures may arise at intermediate steps and propagate through the remaining trajectory. It is therefore important to have a monitoring system that observes the evolving trajectory and decides when intervention is needed (Gao and Peng, 2025; Rabanser et al., 2026; Mittapalli et al., 2026; Modgil, 2026).
Existing work on runtime monitoring follows two main directions. One line takes a verifier or monitoring output as given and converts it into an online decision rule with statistical guarantees [13 ] (Sadhuka et al. 2026; Schirmer et al. 2026; Prinster et al. 2026). These guarantees specify conditions under which the supplied signal can support valid intervention and control false alarm risk. Some of these methods use calibration procedures similar to conformal methods [2 ] to provide finite-sample risk control conditional on the calibration set. Another line learns a monitor or a model of agent behavior from trajectory data and uses it to predict failures during execution (Wang et al., 2026b,a; Xiang et al., 2025; Chen et al., 2025). The training objective shapes the signal supplied to the decision rule, including its behavior on trajectories where intervention is unnecessary or needed, and the resulting signal can then be calibrated on a separate calibration set to control the false-positive probability. Together, these directions suggest incorporating the requirements for false-alarm control and detection power into the monitor’s learning objective, motivating the following question: Can the statistical requirements of reliable intervention guide the learning process?
In this paper, we answer this question through LeBet (Learn then Bet). We formulate agent intervention as a statistical learning problem over complete trajectories while requiring the learned monitor to operate only on the evolving trajectory prefix. Our contributions are as follows:
Learning formulation and algorithm design (Algorithm 1). Rather than first training a general verifier and then calibrating it, we use testing by betting (Ramdas and Wang, 2025) as an online decision framework to identify statistical conditions sufficient for reliable intervention. We formulate the search for a rule set satisfying these conditions as a learning problem. For interpretability, we restrict the learning class to OR-of-AND rule sets (Xin et al., 2022; Perreault et al., 2026). Due to the intractable combinatorial optimization problem for learning rule sets (Malioutov and Varshney, 2013), we adapt FastSRS (Molero-Río et al., 2026) to optimize the empirical separation underlying our intervention guarantees. The key insight is that Boolean identities and monotonicity guide the choice of rule modifications (Yang et al., 2021).
Training-conditional guarantees (Theorem 5 ). Standard sample-splitting approaches use separate training and calibration sets (Vovk, 2013). Following the approach of Liang and Barber (2025), we extend their stability argument to calibration within intervention classes, replacing independent and identically distributed (i.i.d.) sampling with a finite within-class exchangeable extension and leave-one-out stability averaged over training-sample exchanges. We prove finite-sample bounds of a Probably Approximately Correct (PAC) form for the conditional false-positive and missed-detection probabilities, using the same trajectories for learning and calibration. These bounds quantify the intuitive tradeoff between separation, instability, and the evidence required for detection. In particular, betting allows us to introduce an error budget that controls the trade-off between false intervention and detection. The underlying argument may be of independent interest for training-conditional inference under finite exchangeability.
Empirical illustration (§ 0.9 ). On SWE-bench Lite (Jimenez et al., 2024) with a Ministral 3 8B (Liu et al., 2026) coding agent, the learned monitor saves 34.46% of input-plus-output tokens and increases output precision from 18.33% to 21.59% with the false-positive rate 13.64%.
4. Lean 4 verification (Supplement). The formal proofs are machine-checked by Lean 4 (de Moura and Ullrich, 2021; de Moura et al., 2015). We encode the paper’s definitions and theorem statements as Challenges and use Comparator (Lean FRO) to check that Solutions do not weaken the claims or introduce additional assumptions.
Preliminaries
Throughout, N : = { 0 , 1 , … } \mathbb{N} := \{0,1,\ldots\} N := { 0 , 1 , … } , [ n ] : = { 1 , … , n } [n] := \{1,\ldots,n\} [ n ] := { 1 , … , n } , and [ a ] + : = max { a , 0 } [a]_{+} := \max\{a,0\} [ a ] + := max { a , 0 } . We write ∣ A ∣ |A| ∣ A ∣ for the cardinality of a finite set A A A , and ⌊ a ⌋ \lfloor a\rfloor ⌊ a ⌋ and ⌈ a ⌉ \lceil a\rceil ⌈ a ⌉ for the floor and ceiling of a a a . We use standard probabilistic notation (Chung, [15 ] ). The symbol = d \overset{d}{=} = d denotes equality in distribution. Let ( Ω , F ∞ , P ) (\Omega,\mathcal{F}_{\infty},\mathbb{P}) ( Ω , F ∞ , P ) be a probability space. We write σ ( Z ) \sigma(Z) σ ( Z ) for the σ \sigma σ -algebra generated by Z Z Z . A filtration F : = ( F t ) t ∈ N \mathcal{F} := (\mathcal{F}_{t})_{t\in\mathbb{N}} F := ( F t ) t ∈ N is an increasing sequence of sub-σ \sigma σ -algebras of F ∞ \mathcal{F}_{\infty} F ∞ . We write E P \mathbb{E}^{\mathbb{P}} E P and E P [ ⋅ ∣ F t ] \mathbb{E}^{\mathbb{P}}[\cdot\mid\mathcal{F}_{t}] E P [ ⋅ ∣ F t ] for expectation and conditional expectation under P \mathbb{P} P , respectively. A process ( X t ) t ∈ N (X_t)_{t\in\mathbb{N}} ( X t ) t ∈ N is adapted if X t X_t X t is F t \mathcal{F}_t F t -measurable for every t t t . When X t X_t X t is binary, E P [ X t ∣ F t − 1 ] = P ( X t = 1 ∣ F t − 1 ) \mathbb{E}^{\mathbb{P}}[X_t \mid\mathcal{F}_{t-1}] = \mathbb{P}(X_t = 1 \mid\mathcal{F}_{t-1}) E P [ X t ∣ F t − 1 ] = P ( X t = 1 ∣ F t − 1 ) for t ≥ 1 t \ge1 t ≥ 1 . A random variable τ \tau τ taking values in N ∪ { ∞ } \mathbb{N} \cup\{\infty\} N ∪ { ∞ } is a stopping time if { τ ≤ t } ∈ F t \{\tau\le t\} \in\mathcal{F}_t { τ ≤ t } ∈ F t for every t t t . For p ∈ [ 0 , 1 ] p \in[0,1] p ∈ [ 0 , 1 ] , Ber ( p ) \operatorname{Ber}(p) Ber ( p ) denotes the Bernoulli distribution with mean p p p . For p , q ∈ ( 0 , 1 ) p,q \in(0,1) p , q ∈ ( 0 , 1 ) , its Kullback–Leibler divergence is D K L ( Ber ( p ) ∥ Ber ( q ) ) : = p log ( p / q ) + ( 1 − p ) log ( ( 1 − p ) / ( 1 − q ) ) D_{\mathrm{KL}}(\operatorname{Ber}(p)\Vert\operatorname{Ber}(q)) := p\log(p/q) + (1-p)\log((1-p)/(1-q)) D KL ( Ber ( p ) ∥ Ber ( q )) := p log ( p / q ) + ( 1 − p ) log (( 1 − p ) / ( 1 − q )) . We write ∨ \lor ∨ and ∧ \land ∧ for logical OR and AND, respectively. An empty disjunction equals zero. We write 1 { A } \mathbf{1}\{A\} 1 { A } for the indicator of an event A A A and use the convention inf ∅ = ∞ \inf\varnothing= \infty inf ∅ = ∞ . All logarithms are natural. We use the endpoint conventions 0 log ( 0 / q ) = 0 0\log(0/q) = 0 0 log ( 0/ q ) = 0 , p log ( p / 0 ) = + ∞ p\log(p/0) = +\infty p log ( p /0 ) = + ∞ for p > 0 p > 0 p > 0 , and e − ∞ = 0 e^{-\infty} = 0 e − ∞ = 0 . For a finite family ( v i ) i ∈ I (v_i)_{i\in\mathcal{I}} ( v i ) i ∈ I of real values and k ∈ [ ∣ I ∣ ] k \in[|\mathcal{I}|] k ∈ [ ∣ I ∣ ] , v ( k : I ) v_{(k:\mathcal{I})} v ( k : I ) denotes the k k k th smallest value, counting repetitions. We write vectors in bold. For a vector V = ( v 1 , … , v N ) \mathbf{V} = (v_1,\ldots,v_N) V = ( v 1 , … , v N ) and an index vector I = ( i 1 , … , i r ) \mathbf{I} = (i_1,\ldots,i_r) I = ( i 1 , … , i r ) with distinct entries in [ N ] [N] [ N ] , write V I : = ( v i 1 , … , v i r ) \mathbf{V}_{\mathbf{I}} := (v_{i_1},\ldots,v_{i_r}) V I := ( v i 1 , … , v i r ) for the subvector ordered by I \mathbf{I} I . We use I : = { i 1 , … , i r } \mathcal{I} := \{i_1,\ldots,i_r\} I := { i 1 , … , i r } for the corresponding index set, ignoring order. We summarize additional notation in Appendix A. Appendix G collects auxiliary lemmas used in the proofs.
Problem Statement: Statistical Modeling of LLM Agents
An LLM agent is specified by a system prompt and a tool set (where skills, MCP servers, and other capabilities are special cases of tools) and interacts with an environment through a ReAct loop (Yao et al., 2023). Formally, let Z t \mathcal{Z}_t Z t denote the space of interaction histories of length t t t , and let Z : = ⋃ t ≥ 0 Z t \mathcal{Z} := \bigcup_{t\ge0}\mathcal{Z}_t Z := ⋃ t ≥ 0 Z t denote the space of all finite interaction histories, R t r a c e \mathcal{R}_{\mathrm{trace}} R trace the space of reasoning traces, A t o o l _ c a l l \mathcal{A}_{\mathrm{tool\_call}} A tool_call the space of tool-call actions, and O \mathcal{O} O the space of observations. The agent policy may be viewed as a map f : Z → R t r a c e × A t o o l _ c a l l f:\mathcal{Z}\to\mathcal{R}_{\mathrm{trace}}\times\mathcal{A}_{\mathrm{tool\_call}} f : Z → R trace × A tool_call , and executing an action produces an outcome in O \mathcal{O} O . Both the agent policy f f f and environment outputs may be deterministic. However, determinism of the underlying mechanism does not preclude statistical modeling. This perspective is standard in deterministic computer experiments ([7 ] (Sacks et al. 1989; Vaart 1998)), where repeated evaluation at the same input produces the same output, but the unknown response function is nevertheless modeled statistically for prediction and uncertainty quantification. We take the same view of agent–environment interactions. In particular, let ( Ω , F ∞ ) (\Omega,\mathcal{F}_{\infty}) ( Ω , F ∞ ) be a measurable sample space whose elements specify single agent–environment interactions. For ω ∈ Ω \omega\in\Omega ω ∈ Ω , let O 0 ( ω ) O_0(\omega) O 0 ( ω ) denote the initial request. At each step t ≥ 1 t\ge1 t ≥ 1 , the agent produces ( R t ( ω ) , A t ( ω ) ) = f ( Z t − 1 ( ω ) ) (R_t(\omega),A_t(\omega))=f(Z_{t-1}(\omega)) ( R t ( ω ) , A t ( ω )) = f ( Z t − 1 ( ω )) , and executing A t ( ω ) A_t(\omega) A t ( ω ) in the environment produces the observation O t ( ω ) O_t(\omega) O t ( ω ) . The resulting trajectory is
Z t ( ω ) = ( O 0 ( ω ) , R 1 ( ω ) , A 1 ( ω ) , O 1 ( ω ) , … , R t ( ω ) , A t ( ω ) , O t ( ω ) ) . Z_t(\omega) = (O_0(\omega), R_1(\omega), A_1(\omega), O_1(\omega), \ldots, R_t(\omega), A_t(\omega), O_t(\omega)). Z t ( ω ) = ( O 0 ( ω ) , R 1 ( ω ) , A 1 ( ω ) , O 1 ( ω ) , … , R t ( ω ) , A t ( ω ) , O t ( ω )) .
For a fixed ω \omega ω , the entire agent–environment interaction is fully deterministic. Since Z t Z_t Z t contains the history up to time t t t , the trajectory process ( Z t ) t ∈ N (Z_t)_{t\in\mathbb{N}} ( Z t ) t ∈ N is adapted to its natural filtration ( σ ( Z t ) ) t ∈ N (\sigma(Z_t))_{t\in\mathbb{N}} ( σ ( Z t ) ) t ∈ N . Let Z ∞ ( ω ) Z_\infty(\omega) Z ∞ ( ω ) denote the complete agent–environment trajectory in the absence of intervention. In hindsight, one can assess whether intervention was necessary for the agent to achieve an acceptable outcome. We encode this application-dependent judgment by the binary label Y : Ω → { 0 , 1 } Y:\Omega\to\{0,1\} Y : Ω → { 0 , 1 } , determined by Z ∞ ( ω ) Z_\infty(\omega) Z ∞ ( ω ) , with Y ( ω ) = 1 Y(\omega)=1 Y ( ω ) = 1 indicating that intervention was needed and Y ( ω ) = 0 Y(\omega)=0 Y ( ω ) = 0 indicating that the agent could have proceeded without intervention. All trajectory and label maps are assumed measurable.
We then formalize the finite-sample setting. For y ∈ { 0 , 1 } y\in\{0,1\} y ∈ { 0 , 1 } , let Ω y : = { ω ∈ Ω : Y ( ω ) = y } \Omega_y:=\{\omega\in\Omega:Y(\omega)=y\} Ω y := { ω ∈ Ω : Y ( ω ) = y } and fix integers n y ≥ 1 n_y\geq1 n y ≥ 1 and m y ≥ 1 m_y\geq1 m y ≥ 1 . Put n : = n 0 + n 1 n:=n_0+n_1 n := n 0 + n 1 and m : = m 0 + m 1 m:=m_0+m_1 m := m 0 + m 1 . We use a stratified sampling design on the space Ω : = Ω 0 n 0 + m 0 × Ω 1 n 1 + m 1 × Ω \Omega:=\Omega_0^{n_0+m_0}\times\Omega_1^{n_1+m_1}\times\Omega Ω := Ω 0 n 0 + m 0 × Ω 1 n 1 + m 1 × Ω , equipped with its product σ \sigma σ -algebra and a joint probability law P \mathbb{P} P . A sample is ω = ( ( ω i , 0 ) i = 1 n 0 + m 0 , ( ω i , 1 ) i = 1 n 1 + m 1 , ω ⋆ ) \omega=((\omega_{i,0})_{i=1}^{n_0+m_0},(\omega_{i,1})_{i=1}^{n_1+m_1},\omega_\star) ω = (( ω i , 0 ) i = 1 n 0 + m 0 , ( ω i , 1 ) i = 1 n 1 + m 1 , ω ⋆ ) . Thus Y ( ω i , y ) = y Y(\omega_{i,y})=y Y ( ω i , y ) = y by construction. The first n y n_y n y samples in each class are observed, the remaining m y m_y m y form a finite extension, and ω ⋆ \omega_\star ω ⋆ denotes the next trajectory. Reindex the class samples in a fixed order as ( ω 1 , … , ω n + m + 1 ) (\omega_1,\ldots,\omega_{n+m+1}) ( ω 1 , … , ω n + m + 1 ) , placing the observed trajectories first and ω ⋆ = ω n + m + 1 \omega_\star=\omega_{n+m+1} ω ⋆ = ω n + m + 1 last. Without loss of generality, I ⋆ : = [ n + m + 1 ] \mathcal{I}_\star:=[n+m+1] I ⋆ := [ n + m + 1 ] . Write D : = ( ω 1 , … , ω n + m + 1 ) D:=(\omega_1,\ldots,\omega_{n+m+1}) D := ( ω 1 , … , ω n + m + 1 ) for the full sample vector. For an index vector I = ( i 1 , … , i r ) I=(i_1,\ldots,i_r) I = ( i 1 , … , i r ) with entries in I ⋆ \mathcal{I}_\star I ⋆ , write D I D_I D I for the corresponding indexed sample. For I ⊆ I ⋆ I\subseteq\mathcal{I}_\star I ⊆ I ⋆ , let Π I \Pi_I Π I denote the group of permutations π : I ⋆ → I ⋆ \pi:\mathcal{I}_\star\to\mathcal{I}_\star π : I ⋆ → I ⋆ such that π ( i ) = i \pi(i)=i π ( i ) = i for every i ∈ I ⋆ ∖ I i\in\mathcal{I}_\star\setminus I i ∈ I ⋆ ∖ I . By abuse of notation, for any permutation π \pi π of I ⋆ \mathcal{I}_\star I ⋆ , write π ( D ) : = ( ω π ( 1 ) , … , ω π ( n + m + 1 ) ) \pi(D):=(\omega_{\pi(1)},\ldots,\omega_{\pi(n+m+1)}) π ( D ) := ( ω π ( 1 ) , … , ω π ( n + m + 1 ) ) . Write I i n : = ( 1 , … , n ) \mathcal{I}_{\mathrm{in}}:=(1,\ldots,n) I in := ( 1 , … , n ) , so D i n = D I i n D_{\mathrm{in}}=D_{\mathcal{I}_{\mathrm{in}}} D in = D I in . Write Z t , i : = Z t ( ω i ) Z_{t,i}:=Z_t(\omega_i) Z t , i := Z t ( ω i ) and Y i : = Y ( ω i ) Y_i:=Y(\omega_i) Y i := Y ( ω i ) for i ∈ I ⋆ i\in\mathcal{I}_\star i ∈ I ⋆ .
Hereafter, we treat the trajectory, label, and associated quantities as random variables under P \mathbb{P} P and suppress their sample arguments. When the trajectory index is clear from context, we suppress it; in particular, Y = Y ⋆ Y=Y_\star Y = Y ⋆ and Z t = Z t , ⋆ Z_t=Z_{t,\star} Z t = Z t , ⋆ for the next trajectory. Write I i n , y : = { i ∈ [ n ] : Y i = y } \mathcal{I}_{\mathrm{in},y}:=\{i\in[n]:Y_i=y\} I in , y := { i ∈ [ n ] : Y i = y } , I o u t , y : = { i ∈ [ n + m ] ∖ [ n ] : Y i = y } \mathcal{I}_{\mathrm{out},y}:=\{i\in[n+m]\setminus[n]:Y_i=y\} I out , y := { i ∈ [ n + m ] ∖ [ n ] : Y i = y } , and I i n / o u t , y : = I i n , y ∪ I o u t , y \mathcal{I}_{\mathrm{in/out},y}:=\mathcal{I}_{\mathrm{in},y}\cup\mathcal{I}_{\mathrm{out},y} I in/out , y := I in , y ∪ I out , y . For any indexed sample D D D , write D y D_y D y for its class-y y y subvector, preserving order and occurrences. We also write v ( k : D ) v_{(k:D)} v ( k : D ) for the order statistic over the occurrences in D D D . For each y y y with P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_\star=y)>0 P ( Y ⋆ = y ) > 0 , write P y : = P ( ⋅ ∣ Y ⋆ = y ) \mathbb{P}_y:=\mathbb{P}(\cdot\mid Y_\star=y) P y := P ( ⋅ ∣ Y ⋆ = y ) and E y : = E P y \mathbb{E}_y:=\mathbb{E}^{\mathbb{P}_y} E y := E P y . Rather than assuming i.i.d. trajectories, we impose exchangeability (Chow and Teicher, [14 ] ) under P y \mathbb{P}_y P y within each intervention class, including ω ⋆ \omega_\star ω ⋆ in class y y y . This assumption rules out systematic distribution shifts between observed and future trajectories within each class while allowing dependence both within and between classes:
Assumption 1 (Finite exchangeable extension) For each y y y with P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_\star=y)>0 P ( Y ⋆ = y ) > 0 , under P y \mathbb{P}_y P y ,
π ( D ) = d D , ∀ π ∈ Π I i n / o u t , y ∪ { ⋆ } ∪ Π I i n / o u t , 1 − y . \pi(D) \mathrel{\overset{d}{=}} D,\quad\forall\ \pi\in\Pi_{\mathcal{I}_{\mathrm{in/out},y}\cup\{\star\}}\cup\Pi_{\mathcal{I}_{\mathrm{in/out},1-y}}. π ( D ) = d D , ∀ π ∈ Π I in/out , y ∪ { ⋆ } ∪ Π I in/out , 1 − y .
Finite exchangeable extensions are discussed in Angelopoulos et al. [2 ] , Section 6.2.1. Our classwise formulation is related to label-conditional conformal prediction (Vovk, 2013; Xie et al., 2025), where calibration is performed separately within each class. See Appendix § 1.16 for further discussion.
Motivation: Learn then Bet
Although Y Y Y is assigned from the complete trajectory, an intervention decision at time t t t must depend only on the observed history Z t Z_t Z t (Li et al., 2025; Wang, 2026). Suppose we want to detect whether intervention is needed. Consider two adapted binary predicates: ξ t 1 : Z t → { 0 , 1 } \xi_t^1:Z_t\to\{0,1\} ξ t 1 : Z t → { 0 , 1 } , ξ t 1 = 1 { O t reports a tool failure } \xi_t^1=\mathbb{1}\{O_t\text{ reports a tool failure}\} ξ t 1 = 1 { O t reports a tool failure } , ξ t 2 = 1 { ∃ k < t : A t = A k } \xi_t^2=\mathbb{1}\{\exists k<t:A_t=A_k\} ξ t 2 = 1 { ∃ k < t : A t = A k } . The first predicate detects whether the current tool call fails, while the second detects whether the agent repeats a previous action. A simple monitor ξ t 1 ∧ ξ t 2 \xi_t^1 \land\xi_t^2 ξ t 1 ∧ ξ t 2 fires when the agent repeats an action and the resulting tool call fails, which may indicate the final status of Y Y Y . Neither predicate perfectly determines whether a trajectory should be stopped: A trajectory with Y = 0 Y = 0 Y = 0 may contain an occasional tool failure or repeated action, while a trajectory with Y = 1 Y = 1 Y = 1 may not exhibit these events at every step. We therefore do not require a monitor ξ t 1 ∧ ξ t 2 \xi_t^1 \land\xi_t^2 ξ t 1 ∧ ξ t 2 to identify Y Y Y deterministically. Appendix B.1 gives additional examples of monitors and possible interventions.
We now generalize this simple construction to a combinatorial selection problem. We aim to learn a monitor from the observed trajectories by combining basic adapted predicates. The monitor should detect when intervention is needed while controlling unnecessary intervention. We set D i n : = D ( 1 , … , n ) D_{\mathrm{in}} := D_{(1,\ldots,n)} D in := D ( 1 , … , n ) . Formally, let Ξ = { ξ t j : j ∈ [ d ] } \Xi= \{\xi_t^j : j \in[d]\} Ξ = { ξ t j : j ∈ [ d ]} be a collection of adapted binary predicates fixed before observing D i n D_{\mathrm{in}} D in . A nonempty R ⊆ [ d ] \mathcal{R} \subseteq[d] R ⊆ [ d ] defines a conjunction, and a collection S ⊆ 2 [ d ] \mathcal{S} \subseteq2^{[d]} S ⊆ 2 [ d ] of such sets defines a disjunction: ξ t R : = ⋀ j ∈ R ξ t j \xi_t^{\mathcal{R}} := \bigwedge_{j\in\mathcal{R}} \xi_t^j ξ t R := ⋀ j ∈ R ξ t j , X t ( S ) : Z t → { 0 , 1 } X_t(\mathcal{S}) : \mathcal{Z}_t \to\{0,1\} X t ( S ) : Z t → { 0 , 1 } , X t ( S ) : = ⋁ R ∈ S ξ t R X_t(\mathcal{S}) := \bigvee_{\mathcal{R}\in\mathcal{S}} \xi_t^{\mathcal{R}} X t ( S ) := ⋁ R ∈ S ξ t R . Note that we call each ξ t j \xi_t^j ξ t j a predicate and each conjunction ξ t R \xi_t^{\mathcal{R}} ξ t R a rule . Intuitively, a good monitor X t X_t X t should rarely fire when Y = 0 Y = 0 Y = 0 and fire persistently when Y = 1 Y = 1 Y = 1 . One could formalize this intuition by requiring the conditional probabilities at each step to be small under Y = 0 Y = 0 Y = 0 and large under Y = 1 Y = 1 Y = 1 . However, these conditional probabilities depend on the entire trajectory history and are difficult to estimate directly from finitely many trajectories. We therefore consider a weaker requirement based on the average conditional mean. For a binary monitor X X X adapted to F \mathcal{F} F , define μ t , y X ( Z t ; F ) : = t − 1 ∑ u = 1 t E y [ X u ( Z u ) ∣ F u − 1 ] \mu_{t,y}^X(Z_t;\mathcal{F}) := t^{-1}\sum_{u=1}^{t}\mathbb{E}_y[X_u(Z_u)\mid\mathcal{F}_{u-1}] μ t , y X ( Z t ; F ) := t − 1 ∑ u = 1 t E y [ X u ( Z u ) ∣ F u − 1 ] . We suppress arguments when clear from context. We aim to find S \mathcal{S} S whose average conditional mean μ t , y X \mu_{t,y}^X μ t , y X is small on most trajectories with Y = 0 Y = 0 Y = 0 and large on most trajectories with Y = 1 Y = 1 Y = 1 . Fix integers 1 < T 0 < T 1 1 < T_0 < T_1 1 < T 0 < T 1 and write W : = { T 0 , … , T 1 } \mathcal{W} := \{T_0,\ldots,T_1\} W := { T 0 , … , T 1 } for the monitoring window. Here T 0 T_0 T 0 sets the earliest intervention time, while T 1 T_1 T 1 specifies the maximum number of steps the agent may execute. For error budgets ϵ 0 , ϵ 1 ∈ [ 0 , 1 ) \epsilon_0,\epsilon_1 \in[0,1) ϵ 0 , ϵ 1 ∈ [ 0 , 1 ) , take F = ( σ ( Z s ) ) s ≥ 0 \mathcal{F} = (\sigma(Z_s))_{s\geq0} F = ( σ ( Z s ) ) s ≥ 0 and define
P ( S ) : = { ( p 0 , p 1 ) ∈ [ 0 , 1 ] 2 : ∀ y ∈ { 0 , 1 } , P y ( max t ∈ W ( − 1 ) y ( μ t , y X ( S ) ( Z t ) − p y ) ≤ 0 ) ≥ 1 − ϵ y } . \mathcal{P}(\mathcal{S}) := \left\{(p_0,p_1)\in[0,1]^2 : \forall y\in\{0,1\},\ \mathbb{P}_y\left(\max_{t\in\mathcal{W}}(-1)^y\left(\mu_{t,y}^{X(\mathcal{S})}(Z_t)-p_y\right)\leq0\right)\geq1-\epsilon_y\right\}. P ( S ) := { ( p 0 , p 1 ) ∈ [ 0 , 1 ] 2 : ∀ y ∈ { 0 , 1 } , P y ( t ∈ W max ( − 1 ) y ( μ t , y X ( S ) ( Z t ) − p y ) ≤ 0 ) ≥ 1 − ϵ y } .
For positive integers K R K_{\mathcal{R}} K R and K S K_{\mathcal{S}} K S , we seek to maximize the population separation
Δ : = sup ( p 0 , p 1 ) ∈ P ( S ) , S ∈ C [ p 1 − p 0 ] + , C : = { S ⊆ 2 [ d ] : ∣ S ∣ ≤ K S , 1 ≤ ∣ R ∣ ≤ K R ∀ R ∈ S } . (1) \Delta:= \sup_{(p_0,p_1)\in\mathcal{P}(\mathcal{S}),\mathcal{S}\in\mathcal{C}} [p_1-p_0]_+,\qquad\mathcal{C} := \left\{\mathcal{S}\subseteq2^{[d]} : |\mathcal{S}|\leq K_{\mathcal{S}},\ 1\leq|\mathcal{R}|\leq K_{\mathcal{R}}\ \forall\mathcal{R}\in\mathcal{S}\right\}. \tag*{(1)} Δ := ( p 0 , p 1 ) ∈ P ( S ) , S ∈ C sup [ p 1 − p 0 ] + , C := { S ⊆ 2 [ d ] : ∣ S ∣ ≤ K S , 1 ≤ ∣ R ∣ ≤ K R ∀ R ∈ S } . (1)
This formulation leads to several challenges.
How to construct an online intervention rule. The conditional means in equation (1) are not directly observable. In § 0.5 , we introduce a betting statistic and relate its evidence directly to observed averages.
How to ensure validity and detection. An intervention rule should control unnecessary interventions while detecting trajectories that require intervention. § 0.6 establishes sufficient conditions for both guarantees.
How to generalize to future trajectories. Even under exchangeability, a large empirical separation does not by itself guarantee the desired error rate on the next trajectory conditional on the observed data. In § 0.7 , we use stability to establish training-conditional guarantees without splitting the data into training and calibration sets.
Algorithm 1: LeBet
Input: Observed data D i n D_{\mathrm{in}} D in , predicate pool Ξ \Xi Ξ , window W \mathcal{W} W , parameters ϵ 0 , ϵ 1 , α \epsilon_0,\epsilon_1,\alpha ϵ 0 , ϵ 1 , α .
Output: Intervention time τ ^ ∈ W ∪ { ∞ } \hat{\tau} \in\mathcal{W} \cup\{\infty\} τ ^ ∈ W ∪ { ∞ } .
Learn
Obtain S ^ \hat{S} S ^ by optimizing equation 6 over C \mathcal{C} C in equation 1 using Algorithm 7
if Δ ^ D i n ϵ 0 , ϵ 1 ( S ^ ) > 0 \hat{\Delta}_{D_{\mathrm{in}}}^{\epsilon_0,\epsilon_1}(\hat{S}) > 0 Δ ^ D in ϵ 0 , ϵ 1 ( S ^ ) > 0 then return ( S ^ , p ^ , λ ^ ) (\hat{S},\hat{p},\hat{\lambda}) ( S ^ , p ^ , λ ^ ) with parameters from equation 10 else return ( ∅ , 1 , 1 ) (\varnothing,1,1) ( ∅ , 1 , 1 )
Bet ( X ( S ^ ) , p ^ , λ ^ ) (X(\hat{S}),\hat{p},\hat{\lambda}) ( X ( S ^ ) , p ^ , λ ^ )
E 0 ( λ ^ , p ^ ) ← 1 E_0(\hat{\lambda},\hat{p}) \leftarrow1 E 0 ( λ ^ , p ^ ) ← 1
for t = 1 , … , T 1 t=1,\ldots,T_1 t = 1 , … , T 1 do
Observe Z t Z_t Z t and update E t ( λ ^ , p ^ ) E_t(\hat{\lambda},\hat{p}) E t ( λ ^ , p ^ ) by equation 2, using X ( S ^ ) X(\hat{S}) X ( S ^ ) and p ^ \hat{p} p ^
if t ∈ W t \in\mathcal{W} t ∈ W and E t ( λ ^ , p ^ ) ≥ 1 / α E_t(\hat{\lambda},\hat{p}) \ge1/\alpha E t ( λ ^ , p ^ ) ≥ 1/ α then Intervene and return t t t
end
return ∞ \infty ∞
How to solve the combinatorial optimization problem. Exhaustive search over rule combinations is costly, while random edits can be inefficient. In Section 8, we use the effects of Boolean rule edits on the separation to guide a stochastic local search.
Together, these ingredients instantiate the Learn then Bet (LeBet ) principle: we first learn a monitor from historical trajectories, and then deploy the frozen monitor through a sequential betting rule for online intervention. Algorithm 1 summarizes our framework. In Section 9, we evaluate LeBet and demonstrate its effectiveness in stopping failed trajectories early and reducing token use. Section 10 reviews related work, and Section 11 concludes the paper.
Intervening by Betting
For a binary monitor X X X adapted to a filtration F \mathcal{F} F , we accumulate evidence for intervention through a betting process. Given a reference level p 0 ∈ [ 0 , 1 ] p_0 \in[0,1] p 0 ∈ [ 0 , 1 ] , a constant stake λ > 0 \lambda> 0 λ > 0 , and a threshold parameter α ∈ ( 0 , 1 ) \alpha\in(0,1) α ∈ ( 0 , 1 ) , consider the betting process and the corresponding stopping time: set E 0 ( λ , p 0 ) = 1 E_0(\lambda,p_0)=1 E 0 ( λ , p 0 ) = 1 and
E t ( λ , p 0 ) : = ∏ s = 1 t exp ( λ X s ) 1 − p 0 + p 0 exp ( λ ) , τ ( λ , p 0 ) : = inf { t ∈ W : E t ( λ , p 0 ) ≥ 1 α } . (2) E_t(\lambda,p_0) := \prod_{s=1}^{t} \frac{\exp(\lambda X_s)}{1-p_0+p_0\exp(\lambda)}, \qquad\tau(\lambda,p_0) := \inf\left\{t \in\mathcal{W}: E_t(\lambda,p_0) \ge\frac{1}{\alpha}\right\}. \tag*{(2)} E t ( λ , p 0 ) := s = 1 ∏ t 1 − p 0 + p 0 exp ( λ ) exp ( λ X s ) , τ ( λ , p 0 ) := inf { t ∈ W : E t ( λ , p 0 ) ≥ α 1 } . (2)
Here inf ∅ = ∞ \inf\varnothing=\infty inf ∅ = ∞ , so that τ ( λ , p 0 ) = ∞ \tau(\lambda,p_0)=\infty τ ( λ , p 0 ) = ∞ means no intervention is triggered in the monitoring window.
Each observation X t X_t X t updates the evidence relative to p 0 p_0 p 0 . The stake λ \lambda λ controls the difference between the log-evidence increments for X t = 1 X_t=1 X t = 1 and X t = 0 X_t=0 X t = 0 . Appendix E gives the betting interpretation and, for 0 < p 0 < 1 0<p_0<1 0 < p 0 < 1 , the equivalent Bernoulli likelihood-ratio form. Define the observed averages and their temporal extrema by
μ ^ t X ( Z t ) : = 1 t ∑ s = 1 t X s ( Z s ) , U ^ X ( Z ∞ ) : = max t ∈ W μ ^ t X ( Z t ) , L ^ X ( Z ∞ ) : = min t ∈ W μ ^ t X ( Z t ) . (3) \hat{\mu}_t^X(Z_t) := \frac{1}{t}\sum_{s=1}^{t}X_s(Z_s), \qquad\hat{U}^X(Z_\infty) := \max_{t\in\mathcal{W}}\hat{\mu}_t^X(Z_t), \qquad\hat{L}^X(Z_\infty) := \min_{t\in\mathcal{W}}\hat{\mu}_t^X(Z_t). \tag*{(3)} μ ^ t X ( Z t ) := t 1 s = 1 ∑ t X s ( Z s ) , U ^ X ( Z ∞ ) := t ∈ W max μ ^ t X ( Z t ) , L ^ X ( Z ∞ ) := t ∈ W min μ ^ t X ( Z t ) . (3)
The following proposition gives calibration and mean-estimation bounds.
Proposition 2. Put v ( p ) : = 1 / 4 − [ p − 1 / 2 ] 2 v(p) := 1/4 - [p - 1/2]^2 v ( p ) := 1/4 − [ p − 1/2 ] 2 , a t ( α ) : = 2 log ( 1 / α ) / t a_t(\alpha) := \sqrt{2\log(1/\alpha)/t} a t ( α ) := 2 log ( 1/ α ) / t . For p 0 ∈ [ 0 , 1 ] p_0 \in[0,1] p 0 ∈ [ 0 , 1 ] , λ > 0 \lambda> 0 λ > 0 ,
(1) For α ∈ ( 0 , 1 ) \alpha\in(0,1) α ∈ ( 0 , 1 ) , the stopping time satisfies U ^ X ≤ p 0 ⇒ τ ( λ , p 0 ) = ∞ \widehat{U}^{X} \le p_0 \Rightarrow\tau(\lambda,p_0) = \infty U X ≤ p 0 ⇒ τ ( λ , p 0 ) = ∞ and
L ^ X ≥ p 0 + ( v ( p 0 ) λ + λ − 1 a T 1 ( α ) 2 ) / 2 ⇒ τ ( λ , p 0 ) ≤ T 1 . (4) \widehat{L}^{X} \ge p_0 + \left(v(p_0)\lambda+ \lambda^{-1}a_{T_1}(\alpha)^2\right)/2 \Rightarrow\tau(\lambda,p_0) \le T_1. \tag*{(4)} L X ≥ p 0 + ( v ( p 0 ) λ + λ − 1 a T 1 ( α ) 2 ) /2 ⇒ τ ( λ , p 0 ) ≤ T 1 . (4) (2) With r t ( β ) : = min { ( 1 + T 0 / t ) a T 0 ( β / 2 ) / 2 , a t ( β / ( 2 ∣ W ∣ ) ) } / 2 r_t(\beta) := \min\{(1 + T_0/t)a_{T_0}(\beta/2)/2, a_t(\beta/(2|\mathcal{W}|))\}/2 r t ( β ) := min {( 1 + T 0 / t ) a T 0 ( β /2 ) /2 , a t ( β / ( 2∣ W ∣ ))} /2 , for every F 0 \mathcal{F}_0 F 0 -measurable β ∈ ( 0 , 1 ) \beta\in(0,1) β ∈ ( 0 , 1 ) and either fixed sign, P y ( ∃ t ∈ W : ± ( μ ^ t X − μ t , y X ) > r t ( β ) ∣ F 0 ) ≤ β \mathbb{P}_y(\exists t \in\mathcal{W} : \pm(\widehat{\mu}^{X}_t - \mu_{t,y}^{X}) > r_t(\beta) \mid\mathcal{F}_0) \le\beta P y ( ∃ t ∈ W : ± ( μ t X − μ t , y X ) > r t ( β ) ∣ F 0 ) ≤ β .
Proof. See Appendix H.
For p 0 < 1 p_0 < 1 p 0 < 1 , equation 4 is minimized by λ = a T 1 ( α ) / v ( p 0 ) \lambda= a_{T_1}(\alpha)/\sqrt{v(p_0)} λ = a T 1 ( α ) / v ( p 0 ) . § 0.7 uses this stake. Including the fitting sample in F 0 \mathcal{F}_0 F 0 gives conditional-mean bounds for trajectories excluded from fitting.
Validity and Detection
We extend guarantees from testing by betting and anytime-valid inference (Ramdas and Wang, 2025; Ramdas et al., 2023; Waudby-Smith and Ramdas, 2024; Howard et al., 2021) to allow imperfect calibration of the betting reference. Bounds on the monitor’s average conditional means yield false-intervention and detection guarantees. Put ψ λ ( u ) : = log ( 1 − u + u e λ ) \psi_\lambda(u) := \log(1-u+u e^\lambda) ψ λ ( u ) := log ( 1 − u + u e λ ) . For λ > 0 \lambda> 0 λ > 0 , p , q ∈ [ 0 , 1 ] p,q \in[0,1] p , q ∈ [ 0 , 1 ] , and α ∈ ( 0 , 1 ) \alpha\in(0,1) α ∈ ( 0 , 1 ) , write e 0 = e 0 ( p ; λ , q , α ) e_0 = e_0(p;\lambda,q,\alpha) e 0 = e 0 ( p ; λ , q , α ) and e 1 , t = e 1 , t ( p ; λ , q , α ) e_{1,t} = e_{1,t}(p;\lambda,q,\alpha) e 1 , t = e 1 , t ( p ; λ , q , α ) , where
e 0 : = α exp ( T 1 [ ψ λ ( p ) − ψ λ ( q ) ] + − T 0 [ ψ λ ( q ) − ψ λ ( p ) ] + ) , e_0 := \alpha\exp\left(T_1[\psi_\lambda(p)-\psi_\lambda(q)]_+ - T_0[\psi_\lambda(q)-\psi_\lambda(p)]_+\right), e 0 := α exp ( T 1 [ ψ λ ( p ) − ψ λ ( q ) ] + − T 0 [ ψ λ ( q ) − ψ λ ( p ) ] + ) ,
e 1 , t : = exp ( − t D K L ( Ber ( min { p , λ − 1 { ψ λ ( q ) + a t ( α ) / 2 } } ) ∥ Ber ( p ) ) ) . (5) e_{1,t} := \exp\left(-tD_{\mathrm{KL}}\left(\operatorname{Ber}\left(\min\left\{p,\lambda^{-1}\left\{\psi_\lambda(q)+a_t(\alpha)/2\right\}\right\}\right)\middle\|\operatorname{Ber}(p)\right)\right). \tag*{(5)} e 1 , t := exp ( − t D KL ( Ber ( min { p , λ − 1 { ψ λ ( q ) + a t ( α ) /2 } } ) Ber ( p ) ) ) . (5)
Proposition 3. For λ > 0 \lambda> 0 λ > 0 , p 0 , p 1 , q 0 ∈ [ 0 , 1 ] p_0,p_1,q_0 \in[0,1] p 0 , p 1 , q 0 ∈ [ 0 , 1 ] , t ∈ W t \in\mathcal{W} t ∈ W , and ϵ 0 , ϵ 1 ∈ [ 0 , 1 ) \epsilon_0,\epsilon_1 \in[0,1) ϵ 0 , ϵ 1 ∈ [ 0 , 1 ) , the following hold:
(1) If P 0 ( max t ∈ W μ t , 0 X ≤ p 0 ) ≥ 1 − ϵ 0 \mathbb{P}_0(\max_{t\in\mathcal{W}}\mu^X_{t,0} \le p_0) \ge1-\epsilon_0 P 0 ( max t ∈ W μ t , 0 X ≤ p 0 ) ≥ 1 − ϵ 0 , then P 0 ( τ ( λ , q 0 ) < ∞ ) ≤ ϵ 0 + e 0 ( p 0 ; λ , q 0 , α ) \mathbb{P}_0(\tau(\lambda,q_0)<\infty) \le\epsilon_0 + e_0(p_0;\lambda,q_0,\alpha) P 0 ( τ ( λ , q 0 ) < ∞ ) ≤ ϵ 0 + e 0 ( p 0 ; λ , q 0 , α ) .
(2) If P 1 ( min t ∈ W μ t , 1 X ≥ p 1 ) ≥ 1 − ϵ 1 \mathbb{P}_1(\min_{t\in\mathcal{W}}\mu^X_{t,1} \ge p_1) \ge1-\epsilon_1 P 1 ( min t ∈ W μ t , 1 X ≥ p 1 ) ≥ 1 − ϵ 1 , then P 1 ( τ ( λ , q 0 ) > t ) ≤ ϵ 1 + e 1 , t ( p 1 ; λ , q 0 , α ) \mathbb{P}_1(\tau(\lambda,q_0)>t) \le\epsilon_1 + e_{1,t}(p_1;\lambda,q_0,\alpha) P 1 ( τ ( λ , q 0 ) > t ) ≤ ϵ 1 + e 1 , t ( p 1 ; λ , q 0 , α ) .
Proof. See Appendix I.
Part (1) of Proposition 3 accounts for mismatch between p 0 p_0 p 0 and the betting reference q 0 q_0 q 0 , with α \alpha α controlling the betting contribution. When q 0 = p 0 q_0 = p_0 q 0 = p 0 , it recovers the bound α + ϵ 0 \alpha+ \epsilon_0 α + ϵ 0 . For any γ ∈ ( 0 , 1 ) \gamma\in(0,1) γ ∈ ( 0 , 1 ) , part (2) gives detection probability at least 1 − ϵ 1 − γ 1-\epsilon_1-\gamma 1 − ϵ 1 − γ whenever e 1 , t ( p 1 ; λ , q 0 , α ) ≤ γ e_{1,t}(p_1;\lambda,q_0,\alpha) \le\gamma e 1 , t ( p 1 ; λ , q 0 , α ) ≤ γ . For fixed λ \lambda λ , increasing q 0 q_0 q 0 raises the intervention threshold, weakening the detection bound in part (2). For 0 < q 0 < p 1 < 1 0 < q_0 < p_1 < 1 0 < q 0 < p 1 < 1 , Appendix E, with reference q 0 q_0 q 0 , gives max λ > 0 { λ p 1 − ψ λ ( q 0 ) } = D K L ( Ber ( p 1 ) ∥ Ber ( q 0 ) ) \max_{\lambda>0}\{\lambda p_1-\psi_\lambda(q_0)\} = D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\|\operatorname{Ber}(q_0)) max λ > 0 { λ p 1 − ψ λ ( q 0 )} = D KL ( Ber ( p 1 ) ∥ Ber ( q 0 )) , attained at λ = log { p 1 ( 1 − q 0 ) / [ q 0 ( 1 − p 1 ) ] } \lambda= \log\{p_1(1-q_0)/[q_0(1-p_1)]\} λ = log { p 1 ( 1 − q 0 ) / [ q 0 ( 1 − p 1 )]} .
Learned Intervention Guarantees
We now learn a rule set from D i n D_{\mathrm{in}} D in and establish intervention guarantees on the next trajectory ω ⋆ \omega_\star ω ⋆ conditional on this sample. To distinguish the observed trajectories, we restore the trajectory index i i i as a subscript and otherwise keep the preceding notation. For example, X t , i = X t ( Z t , i ) X_{t,i}=X_t(Z_{t,i}) X t , i = X t ( Z t , i ) , μ ^ t , i X = μ ^ t X ( Z t , i ) \widehat{\mu}^{X}_{t,i}=\widehat{\mu}^{X}_t(Z_{t,i}) μ t , i X = μ t X ( Z t , i ) , U ^ i X = U ^ X ( Z ∞ , i ) \widehat{U}^{X}_i=\widehat{U}^{X}(Z_{\infty,i}) U i X = U X ( Z ∞ , i ) , L ^ i X = L ^ X ( Z ∞ , i ) \widehat{L}^{X}_i=\widehat{L}^{X}(Z_{\infty,i}) L i X = L X ( Z ∞ , i ) . The same convention applies to the predicates. In this section, write U ^ ( k ) X : = U ^ ( k : Z i n , 0 ) X \widehat{U}^{X}_{(k)} := \widehat{U}^{X}_{(k:Z_{\mathrm{in},0})} U ( k ) X := U ( k : Z in , 0 ) X and L ^ ( k ) X : = L ^ ( k : Z i n , 1 ) X \widehat{L}^{X}_{(k)} := \widehat{L}^{X}_{(k:Z_{\mathrm{in},1})} L ( k ) X := L ( k : Z in , 1 ) X , suppressing the training index sets. For a fixed monitor X X X , U ^ i X \widehat{U}^{X}_{i} U i X and L ^ i X \widehat{L}^{X}_{i} L i X depend only on trajectory i i i , while their order statistics depend on the corresponding class samples. Put k y : = n y − ⌊ n y ϵ y ⌋ k_y := n_y - \lfloor n_y\epsilon_y\rfloor k y := n y − ⌊ n y ϵ y ⌋ . Replacing conditional means by observed averages and class-conditional probabilities by empirical frequencies in equation (1) gives the empirical separation
Δ ^ D i n ϵ 0 , ϵ 1 ( S ) : = [ L ^ ( n 1 − k 1 + 1 ) X ( S ) − U ^ ( k 0 ) X ( S ) ] + . (6) \widehat{\Delta}^{\epsilon_0,\epsilon_1}_{D_{\mathrm{in}}}(S) := \left[\widehat{L}^{X(S)}_{(n_1-k_1+1)}-\widehat{U}^{X(S)}_{(k_0)}\right]_{+}. \tag*{(6)} Δ D in ϵ 0 , ϵ 1 ( S ) := [ L ( n 1 − k 1 + 1 ) X ( S ) − U ( k 0 ) X ( S ) ] + . (6)
When this value is positive, the two order statistics attain the largest gap for which at most ⌊ n 0 ϵ 0 ⌋ \lfloor n_0\epsilon_0\rfloor ⌊ n 0 ϵ 0 ⌋ values of U ^ i X ( S ) \widehat{U}^{X(S)}_i U i X ( S ) in class 0 exceed p 0 p_0 p 0 and at most ⌊ n 1 ϵ 1 ⌋ \lfloor n_1\epsilon_1\rfloor ⌊ n 1 ϵ 1 ⌋ values of L ^ i X ( S ) \widehat{L}^{X(S)}_i L i X ( S ) in class 1 fall below p 1 p_1 p 1 . The positive part assigns zero when no positive gap is feasible. Let S ^ ( D ) ∈ C \widehat{S}(D)\in\mathcal{C} S ( D ) ∈ C denote the rule set obtained by optimizing max S ∈ C Δ ^ D ϵ 0 , ϵ 1 ( S ) \max_{S\in\mathcal{C}}\widehat{\Delta}^{\epsilon_0,\epsilon_1}_{D}(S) max S ∈ C Δ D ϵ 0 , ϵ 1 ( S ) with a fixed algorithm. Note that we do not require S ^ ( D ) \widehat{S}(D) S ( D ) to attain the maximum. We compare training samples with the fixed class sizes n 0 , n 1 n_0,n_1 n 0 , n 1 :
D i n / o u t : = { ( ω i 1 , … , ω i n ) : 1 ≤ i 1 < ⋯ < i n ≤ n + m , ∑ r = 1 n 1 { Y i r = y } = n y , y ∈ { 0 , 1 } } . \mathcal{D}_{\mathrm{in/out}} := \left\{(\omega_{i_1},\ldots,\omega_{i_n}):1\leq i_1<\cdots<i_n\leq n+m,\ \sum_{r=1}^{n}\mathbf{1}\{Y_{i_r}=y\}=n_y,\ y\in\{0,1\}\right\}. D in/out := { ( ω i 1 , … , ω i n ) : 1 ≤ i 1 < ⋯ < i n ≤ n + m , r = 1 ∑ n 1 { Y i r = y } = n y , y ∈ { 0 , 1 } } .
Write X ^ ( D ) : = X ( S ^ ( D ) ) \widehat{X}(D):=X(\widehat{S}(D)) X ( D ) := X ( S ( D )) . The key technical observation is as follows. Proposition 2 bounds average conditional means using observed averages. However, the full training sample already contains the complete trajectory being evaluated. Thus, for X = X ^ ( D i n ) X=\widehat{X}(D_{\mathrm{in}}) X = X ( D in ) and i ∈ I i n , y i\in\mathcal{I}_{\mathrm{in},y} i ∈ I in , y , t − 1 ∑ s = 1 t E y [ X s , i ∣ D i n , Z s − 1 , i ] = μ ^ t , i X t^{-1}\sum_{s=1}^{t}\mathbb{E}_y[X_{s,i}\mid D_{\mathrm{in}},Z_{s-1,i}]=\widehat{\mu}^{X}_{t,i} t − 1 ∑ s = 1 t E y [ X s , i ∣ D in , Z s − 1 , i ] = μ t , i X . We therefore use leave-one-out fits to keep the evaluated trajectory out of the conditioning sample. Let D − j D^{-j} D − j delete occurrence j j j from D D D if present, and equal D D D otherwise. Use the same learning procedure with the remaining class sizes, returning ∅ \varnothing ∅ if either class is absent. Write μ ^ t , i ( D ) : = μ ^ t , i X ^ ( D ) \widehat{\mu}_{t,i}(D):=\widehat{\mu}^{\widehat{X}(D)}_{t,i} μ t , i ( D ) := μ t , i X ( D ) and F i ( D ) : = ( σ ( D , Z u , i ) ) u ≥ 0 \mathcal{F}_i(D):=(\sigma(D,Z_{u,i}))_{u\geq0} F i ( D ) := ( σ ( D , Z u , i ) ) u ≥ 0 . For nonnegative r = ( r t ) t ∈ W r=(r_t)_{t\in\mathcal{W}} r = ( r t ) t ∈ W , define
s y , i , j ( D ; I , r ) : = max t ∈ W [ ( − 1 ) y μ ^ t , y X ^ ( D − j ) ( Z t , i ; F i ( D − j ) ) + r t ] , s_{y,i,j}(D;\mathcal{I},r):=\max_{t\in\mathcal{W}}\left[(-1)^y\widehat{\mu}^{\widehat{X}(D^{-j})}_{t,y}(Z_{t,i};\mathcal{F}_i(D^{-j}))+r_t\right], s y , i , j ( D ; I , r ) := t ∈ W max [ ( − 1 ) y μ t , y X ( D − j ) ( Z t , i ; F i ( D − j )) + r t ] ,
s ^ y , i , j ( D ; I , r ) : = max t ∈ W [ ( − 1 ) y μ ^ t , i ( D − j ) + r t ] . (7) \widehat{s}_{y,i,j}(D;\mathcal{I},r):=\max_{t\in\mathcal{W}}\left[(-1)^y\widehat{\mu}_{t,i}(D^{-j})+r_t\right]. \tag*{(7)} s y , i , j ( D ; I , r ) := t ∈ W max [ ( − 1 ) y μ t , i ( D − j ) + r t ] . (7)
Next, we impose leave-one-out stability on the conditional-mean extrema in equation (7) , following the stability arguments of Liang and Barber (2025, Sections 4.2–4.3. Stability transfers the conditional-mean bounds to the next trajectory, whose observed averages may still cross the reference; betting controls the resulting risk of false intervention. See Appendix § 1.16 for further discussion. For integers k ≥ 1 k\geq1 k ≥ 1 and h ≥ 0 h\geq0 h ≥ 0 , let
Q k , h : = Uniform ( { K ⊆ [ k + h ] : ∣ K ∣ = k } ) . (8) \mathcal{Q}_{k,h}:=\operatorname{Uniform}\left(\{K\subseteq[k+h]:|K|=k\}\right). \tag*{(8)} Q k , h := Uniform ( { K ⊆ [ k + h ] : ∣ K ∣ = k } ) . (8)
Let Q π \mathcal{Q}_{\pi} Q π be the uniform law on the group generated by Π I i n / o u t , 0 ∪ Π I i n / o u t , 1 \Pi_{\mathcal{I}_{\mathrm{in/out},0}}\cup\Pi_{\mathcal{I}_{\mathrm{in/out},1}} Π I in/out , 0 ∪ Π I in/out , 1 . For D ∼ P y D\sim\mathbb{P}_y D ∼ P y and an independent π ∼ Q π \pi\sim\mathcal{Q}_{\pi} π ∼ Q π , write P y , π : = P y ⊗ Q π \mathbb{P}_{y,\pi}:=\mathbb{P}_y\otimes\mathcal{Q}_{\pi} P y , π := P y ⊗ Q π for their joint law.
Assumption 4 (Leave-one-out stability) Write S y , i , j ( D ; I ) : = s y , i , j ( D ; I , 0 ) S_{y,i,j}(D;\mathcal{I}):=s_{y,i,j}(D;\mathcal{I},0) S y , i , j ( D ; I ) := s y , i , j ( D ; I , 0 ) . Let π ∼ Q π \pi\sim\mathcal{Q}_{\pi} π ∼ Q π be independent of D D D . There exist θ 0 , θ 1 , κ m ∈ [ 0 , 1 ) \theta_0,\theta_1,\kappa_m\in[0,1) θ 0 , θ 1 , κ m ∈ [ 0 , 1 ) such that E Q π P ( E π ( I i n ) , I i n m c ) ≤ κ m \mathbb{E}_{\mathcal{Q}_{\pi}}\mathbb{P}\left(\mathcal{E}^{m}_{\pi(\mathcal{I}_{\mathrm{in}}),\mathcal{I}_{\mathrm{in}}}{}^{c}\right)\leq\kappa_m E Q π P ( E π ( I in ) , I in m c ) ≤ κ m , where, for D I , D I ′ ∈ D i n / o u t D_{\mathcal{I}},D_{\mathcal{I}'}\in\mathcal{D}_{\mathrm{in/out}} D I , D I ′ ∈ D in/out ,
E I , I ′ m : = ⋂ y ∈ { 0 , 1 } { 1 n y + m y ∑ i ∈ I i n / o u t , y 1 { ∣ S y , i , i ( D ; I ) − S y , i , i ( D ; I ′ ) ∣ > B m } ≤ θ y } . (9) \mathcal{E}^{m}_{\mathcal{I},\mathcal{I}'}:=\bigcap_{y\in\{0,1\}}\left\{\frac{1}{n_y+m_y}\sum_{i\in\mathcal{I}_{\mathrm{in/out},y}}\mathbf{1}\left\{\left|S_{y,i,i}(D;\mathcal{I})-S_{y,i,i}(D;\mathcal{I}')\right|>B_m\right\}\leq\theta_y\right\}. \tag*{(9)} E I , I ′ m := y ∈ { 0 , 1 } ⋂ ⎩ ⎨ ⎧ n y + m y 1 i ∈ I in/out , y ∑ 1 { ∣ S y , i , i ( D ; I ) − S y , i , i ( D ; I ′ ) ∣ > B m } ≤ θ y ⎭ ⎬ ⎫ . (9)
Write Δ ^ ( D ) : = Δ ^ S ^ ( D ) ε 0 , ε 1 \widehat{\Delta}(D) := \widehat{\Delta}^{\varepsilon_0,\varepsilon_1}_{\widehat{S}(D)} Δ ( D ) := Δ S ( D ) ε 0 , ε 1 . For each D ∈ D i n / o u t D \in\mathcal{D}_{\mathrm{in/out}} D ∈ D in/out , suppress the argument D D D in the betting parameters. If Δ ^ ( D ) > 0 \widehat{\Delta}(D) > 0 Δ ( D ) > 0 , set
p ^ 0 : = U ^ ( k 0 : D 0 ) X ^ ( D ) , p ^ 1 : = L ^ ( n 1 − k 1 + 1 : D 1 ) X ^ ( D ) , p ^ : = ( p ^ 0 + p ^ 1 ) / 2 , λ ^ : = a T 1 ( α ) / v ( p ^ ) . (10) \widehat{p}_0 := \widehat{U}^{\widehat{X}(D)}_{(k_0:D_0)},\quad\widehat{p}_1 := \widehat{L}^{\widehat{X}(D)}_{(n_1-k_1+1:D_1)},\quad\widehat{p} := (\widehat{p}_0+\widehat{p}_1)/2,\quad\widehat{\lambda} := a_{T_1}(\alpha)/\sqrt{v(\widehat{p})}. \tag*{(10)} p 0 := U ( k 0 : D 0 ) X ( D ) , p 1 := L ( n 1 − k 1 + 1 : D 1 ) X ( D ) , p := ( p 0 + p 1 ) /2 , λ := a T 1 ( α ) / v ( p ) . (10)
Otherwise, set ( p ^ , λ ^ ) : = ( 1 , 1 ) (\widehat{p},\widehat{\lambda}) := (1,1) ( p , λ ) := ( 1 , 1 ) . The following theorem gives the intervention guarantees for LeBet.
Theorem 5 (Learned intervention guarantees) Suppose Assumptions 1 and 4 hold. Assume (1) P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_\star= y) > 0 P ( Y ⋆ = y ) > 0 for each y y y , (2) the selector S ^ \widehat{S} S is measurable and invariant under permutations of the training sample. Put b y : = ⌊ ( n y + m y ) θ y ⌋ b_y := \lfloor(n_y+m_y)\theta_y\rfloor b y := ⌊( n y + m y ) θ y ⌋ and let K y ∼ Q n y , m y K_y \sim Q_{n_y,m_y} K y ∼ Q n y , m y as in equation (8) . With J κ y a J^{a}_{\kappa_y} J κ y a from Lemma 15 , set W y : = min { 1 , ( J κ y n y − k y + b y + b y ) / m y } W_y := \min\{1,(J^{n_y-k_y+b_y}_{\kappa_y}+b_y)/m_y\} W y := min { 1 , ( J κ y n y − k y + b y + b y ) / m y } if b y < k y b_y < k_y b y < k y , and W y : = 1 W_y := 1 W y := 1 otherwise. For α , β ∈ ( 0 , 1 ) \alpha,\beta\in(0,1) α , β ∈ ( 0 , 1 ) , define
δ y ( β ) : = min 0 ≤ u ≤ 1 { u + E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) β } . (11) \delta_y(\beta) := \min_{0\le u\le1}\left\{u+\frac{\mathbb{E}_{Q_{n_y,m_y}}[(W_y-u)_+]+(1-u)\kappa_m/\mathbb{P}(Y_\star=y)}{\beta}\right\}. \tag*{(11)} δ y ( β ) := 0 ≤ u ≤ 1 min { u + β E Q n y , m y [( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) } . (11) For I = ( i 1 , … , i n ) I=(i_1,\ldots,i_n) I = ( i 1 , … , i n ) with D I ∈ D i n / o u t D_I \in\mathcal{D}_{\mathrm{in/out}} D I ∈ D in/out , and i ∈ I i n / o u t , y ∪ { ⋆ } i \in\mathcal{I}_{\mathrm{in/out},y}\cup\{\star\} i ∈ I in/out , y ∪ { ⋆ } , define
V y , i ( D ; I ) : = { S y , i , i ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y : ( D I ) y ) + 2 B m } , \mathcal{V}_{y,i}(D;I):=\left\{S_{y,i,i}(D;I)>(S_{y,i,i}(D;I))_{(k_y:(D_I)_y)}+2B_m\right\}, V y , i ( D ; I ) := { S y , i , i ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y : ( D I ) y ) + 2 B m } , C y ( D ; I ) : = ∑ i ∈ I i n / o u t , y ∖ I 1 { V y , i ( D ; I ) } . (12) C_y(D;I):=\sum_{i\in\mathcal{I}_{\mathrm{in/out},y}\setminus I}\mathbf{1}\{\mathcal{V}_{y,i}(D;I)\}. \tag*{(12)} C y ( D ; I ) := i ∈ I in/out , y ∖ I ∑ 1 { V y , i ( D ; I )} . (12) Here C y ( D ; I ) C_y(D;I) C y ( D ; I ) counts the class-y y y errors outside D I D_I D I . These definitions are unchanged by reordering I I I . Write r ( β ) : = ( r t ( β ) ) t ∈ W r(\beta):=(r_t(\beta))_{t\in\mathcal{W}} r ( β ) := ( r t ( β ) ) t ∈ W using Proposition 2 (2), and put
q ^ y : = min { 1 − y , ( s ^ y , i , i ( D ; I i n , r ( β 2 n y ) ) ) ( k y : D i n , y ) + 2 B m } . (13) \widehat{q}_y:=\min\left\{1-y,\left(\widehat{s}_{y,i,i}\left(D;I_{\mathrm{in}},r\left(\frac{\beta}{2n_y}\right)\right)\right)_{(k_y:D_{\mathrm{in},y})}+2B_m\right\}. \tag*{(13)} q y := min { 1 − y , ( s y , i , i ( D ; I in , r ( 2 n y β ) ) ) ( k y : D in , y ) + 2 B m } . (13) Let τ ^ : = τ ( λ ^ , p ^ ) \widehat{\tau}:=\tau(\widehat{\lambda},\widehat{p}) τ := τ ( λ , p ) in equation (2) for X ^ ( D i n ) \widehat{X}(D_{\mathrm{in}}) X ( D in ) . Then, for each y y y and s > 0 s>0 s > 0 :
(1) P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) = E y [ C y ( D ; I i n ) / m y ∣ D i n ] \mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})=\mathbb{E}_y[C_y(D;I_{\mathrm{in}})/m_y\mid D_{\mathrm{in}}] P y ( V y , ⋆ ( D ; I in ) ∣ D in ) = E y [ C y ( D ; I in ) / m y ∣ D in ] P y \mathbb{P}_y P y -almost surely.
(2) P y ( C y ( D ; I i n ) / m y > ϵ y + θ y ( n y + m y ) 2 n y m y + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + κ m / P ( Y ⋆ = y ) \mathbb{P}_y(C_y(D;I_{\mathrm{in}})/m_y>\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}+s)\le e^{-2n_ym_ys^2/(n_y+m_y+2)}+\kappa_m/\mathbb{P}(Y_\star=y) P y ( C y ( D ; I in ) / m y > ϵ y + θ y n y m y ( n y + m y ) 2 + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + κ m / P ( Y ⋆ = y ) .
(3) P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β ) ) ≤ β \mathbb{P}_y(\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})>\delta_y(\beta))\le\beta P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β )) ≤ β .
(4) P 0 ( P 0 ( τ ^ < ∞ ∣ D i n ) > δ 0 ( β / 2 ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) ) ≤ β \mathbb{P}_0(\mathbb{P}_0(\widehat{\tau}<\infty\mid D_{\mathrm{in}})>\delta_0(\beta/2)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha))\le\beta P 0 ( P 0 ( τ < ∞ ∣ D in ) > δ 0 ( β /2 ) + e 0 ( q 0 ; λ , p , α )) ≤ β .
(5) P 1 ( ∃ t ∈ W : P 1 ( τ ^ > t ∣ D i n ) > δ 1 ( β / 2 ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) ) ≤ β \mathbb{P}_1(\exists t\in\mathcal{W}:\mathbb{P}_1(\widehat{\tau}>t\mid D_{\mathrm{in}})>\delta_1(\beta/2)+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha))\le\beta P 1 ( ∃ t ∈ W : P 1 ( τ > t ∣ D in ) > δ 1 ( β /2 ) + e 1 , t ( − q 1 ; λ , p , α )) ≤ β .
Proof. See Appendix § 1.25 .
Parts (4) and (5) give finite-sample PAC bounds on next-trajectory errors conditional on the training sample. With the training quantities fixed and the default stake, the probability bounds, truncated at one, are nondecreasing in α \alpha α for false intervention and nonincreasing for missed detection at each fixed t t t . As α ↓ 0 \alpha\downarrow0 α ↓ 0 , e 0 → 0 e_0\to0 e 0 → 0 and e 1 , t → 1 e_{1,t}\to1 e 1 , t → 1 , so the false-intervention bound approaches δ 0 ( β / 2 ) \delta_0(\beta/2) δ 0 ( β /2 ) while the detection guarantee becomes vacuous. For example, if q ^ 0 ≤ p ^ \widehat{q}_0\le\widehat{p} q 0 ≤ p and δ 0 ( β / 2 ) = 0.02 \delta_0(\beta/2)=0.02 δ 0 ( β /2 ) = 0.02 , choosing α = 0.01 \alpha=0.01 α = 0.01 or 0.05 0.05 0.05 gives false-intervention bounds at most 0.03 0.03 0.03 or 0.07 0.07 0.07 , respectively; Appendix B.2 gives the proof and illustrations. When m y = 1 m_y = 1 m y = 1 and θ y = κ m = 0 \theta_y = \kappa_m = 0 θ y = κ m = 0 , equation (11) reduces to δ y ( β ) = min { 1 , ( ⌊ n y ϵ y ⌋ + 1 ) / ( β ( n y + 1 ) ) } \delta_y(\beta) = \min\{1,(\lfloor n_y\epsilon_y\rfloor+ 1)/(\beta(n_y + 1))\} δ y ( β ) = min { 1 , (⌊ n y ϵ y ⌋ + 1 ) / ( β ( n y + 1 ))} . In general, equation (113) gives
δ y ( β ) ≤ ϵ y + θ y ( n y + m y ) 2 n y m y + κ m β P ( Y ⋆ = y ) + n y + m y + 2 2 n y m y ( 1 + log 1 β ) . \delta_y(\beta) \le\epsilon_y + \theta_y \frac{(n_y + m_y)^2}{n_y m_y} + \frac{\kappa_m}{\beta\mathbb{P}(Y_\star= y)} + \sqrt{\frac{n_y + m_y + 2}{2n_y m_y}\left(1 + \log\frac{1}{\beta}\right)}. δ y ( β ) ≤ ϵ y + θ y n y m y ( n y + m y ) 2 + β P ( Y ⋆ = y ) κ m + 2 n y m y n y + m y + 2 ( 1 + log β 1 ) .
Theorem 5 allows changes in the selected rule set under training-sample exchanges, provided that the stated stability bounds for S y , i , i ( D ; I ) S_{y,i,i}(\mathbf{D}; I) S y , i , i ( D ; I ) hold. For a measurable, permutation-invariant objective over a finite rule class, a fixed, data-independent tie-breaking rule makes the optimizer measurable and permutation-invariant ((Liang et al., 2025)). The guarantee has no explicit dependence on ∣ C ∣ |\mathcal{C}| ∣ C ∣ ; selection enters through B m B_m B m , θ y \theta_y θ y , and κ m \kappa_m κ m , which may depend on the learning class and algorithm. A larger empirical separation need not improve the guarantee if instability also increases. Uniform bounds over a finite rule class may provide an alternative proof route.
Our proof follows the techniques and stability arguments of Liang and Barber (2025) but removes the i.i.d. assumption. The key observation for removing the i.i.d. assumption is that, within each class and conditional on the training data, every extension error indicator has the same mean as the next trajectory’s error indicator; their average therefore has this mean without requiring conditional independence (Theorem 5(1)). Part (2) bounds the extension error rate under finite within-class exchangeability, including the stability failure probability, and may be of independent interest for training-conditional guarantees in conformal prediction. This extension requires a finite within-class exchangeable extension and leave-one-out stability averaged over training-sample exchanges. At a high level, the proof combines three ingredients with distinct roles. Leave-one-out fitting keeps the evaluated trajectory out of the conditioning sample, so its conditional means need not equal its observed averages. Stability controls changes in the conditional-mean extrema under training-sample exchanges. The rank argument uses ordering and exchangeability to convert training thresholds into error bounds for the next trajectory.
Rule Learning
The Boolean representation gives a mixed-integer linear formulation, as in integer programming approaches to rule learning ([16 ] (Su et al. 2015)). As the predicate pool and rule-set capacity grow, this combinatorial problem can become costly to solve directly. We instead use a stochastic local search adapted from FastSRS ((Molero-Río et al., 2026)).
FastSRS shares an intuition with stochastic gradient descent for nonconvex optimization: sampled examples guide promising local updates. Unlike submodular formulations that support greedy approximation guarantees ([3 , 11 ] (Yang et al. 2021; Harshaw et al. 2019; Wolsey 1982)), our empirical separation is not generally submodular. However, the Boolean structure gives necessary conditions for an edit to change the monitor at a sampled step.
Lemma 6 (Structure of rule edits) Fix S , S ′ ∈ C \mathcal{S}, \mathcal{S}' \in\mathcal{C} S , S ′ ∈ C . For every i ∈ [ n ] i \in[n] i ∈ [ n ] and t ∈ [ T 1 ] t \in[T_1] t ∈ [ T 1 ] :
X t , i ( S ) = 1 ⟺ { R ∈ S : ξ t , i R = 1 } ≠ ∅ X_{t,i}(\mathcal{S}) = 1 \Longleftrightarrow\{\mathcal{R} \in\mathcal{S} : \xi_{t,i}^{\mathcal{R}} = 1\} \ne\varnothing X t , i ( S ) = 1 ⟺ { R ∈ S : ξ t , i R = 1 } = ∅ .
For R ∈ S \mathcal{R} \in\mathcal{S} R ∈ S and R ′ ⊆ [ d ] \mathcal{R}' \subseteq[d] R ′ ⊆ [ d ] with 1 ≤ ∣ R ′ ∣ ≤ K R 1 \le|\mathcal{R}'| \le K_{\mathcal{R}} 1 ≤ ∣ R ′ ∣ ≤ K R , let S ′ : = ( S ∖ { R } ) ∪ { R ′ } \mathcal{S}' := (\mathcal{S} \setminus\{\mathcal{R}\}) \cup\{\mathcal{R}'\} S ′ := ( S ∖ { R }) ∪ { R ′ } . Then
X t , i ( S ′ ) − X t , i ( S ) = ( 1 − X t , i ( S ∖ { R } ) ) ( ξ t , i R ′ − ξ t , i R ) . X_{t,i}(\mathcal{S}') - X_{t,i}(\mathcal{S}) = (1 - X_{t,i}(\mathcal{S} \setminus\{\mathcal{R}\}))(\xi_{t,i}^{\mathcal{R}'} - \xi_{t,i}^{\mathcal{R}}). X t , i ( S ′ ) − X t , i ( S ) = ( 1 − X t , i ( S ∖ { R })) ( ξ t , i R ′ − ξ t , i R ) . For R ∈ S \mathcal{R} \in\mathcal{S} R ∈ S and ℓ ∈ [ d ] \ell\in[d] ℓ ∈ [ d ] , ξ t , i R ∪ { ℓ } = ξ t , i R ξ t , i ℓ \xi_{t,i}^{\mathcal{R}\cup\{\ell\}} = \xi_{t,i}^{\mathcal{R}}\xi_{t,i}^{\ell} ξ t , i R ∪ { ℓ } = ξ t , i R ξ t , i ℓ and X t , i ( S ∪ { { ℓ } } ) − X t , i ( S ) = ( 1 − X t , i ( S ) ) ξ t , i ℓ X_{t,i}(\mathcal{S} \cup\{\{\ell\}\}) - X_{t,i}(\mathcal{S}) = (1 - X_{t,i}(\mathcal{S}))\xi_{t,i}^{\ell} X t , i ( S ∪ {{ ℓ }}) − X t , i ( S ) = ( 1 − X t , i ( S )) ξ t , i ℓ .
If X ^ s , i ( S ′ ) ≤ X s , i ( S ) \widehat{X}_{s,i}(S') \le X_{s,i}(S) X s , i ( S ′ ) ≤ X s , i ( S ) for every s ∈ [ T 1 ] s \in[T_1] s ∈ [ T 1 ] , then U ^ i X ( S ′ ) ≤ U ^ i X ( S ) \widehat{U}^{X}_i(S') \le\widehat{U}^{X}_i(S) U i X ( S ′ ) ≤ U i X ( S ) and L ^ i X ( S ′ ) ≤ L ^ i X ( S ) \widehat{L}^{X}_i(S') \le\widehat{L}^{X}_i(S) L i X ( S ′ ) ≤ L i X ( S ) . If this holds for every i ∈ [ n ] i \in[n] i ∈ [ n ] , then, for each valid rank k k k , U ^ ( k : I i n , 0 ) X ( S ′ ) ≤ U ^ ( k : I i n , 0 ) X ( S ) \widehat{U}^{X}_{(k:I_{in,0})}(S') \le\widehat{U}^{X}_{(k:I_{in,0})}(S) U ( k : I in , 0 ) X ( S ′ ) ≤ U ( k : I in , 0 ) X ( S ) and L ^ ( k : I i n , 1 ) X ( S ′ ) ≤ L ^ ( k : I i n , 1 ) X ( S ) \widehat{L}^{X}_{(k:I_{in,1})}(S') \le\widehat{L}^{X}_{(k:I_{in,1})}(S) L ( k : I in , 1 ) X ( S ′ ) ≤ L ( k : I in , 1 ) X ( S ) . These inequalities hold when adding an AND predicate or deleting a rule. They reverse when adding a rule or removing a predicate from a conjunction of length at least two.
If R ′ , R ∈ S R' , R \in\mathcal{S} R ′ , R ∈ S and R ′ ⊊ R R' \subsetneq R R ′ ⊊ R , then X t , i ( S ∖ { R ′ } ) = X t , i ( S ) X_{t,i}(\mathcal{S} \setminus\{R'\}) = X_{t,i}(\mathcal{S}) X t , i ( S ∖ { R ′ }) = X t , i ( S ) .
Proof See Appendix K.
Sampled trajectories guide local edits, while the Boolean conditions exclude edits that cannot produce the desired change. Appendices § 1.8 .3 and § 1.8 .§ 0.4 describe their use in rule trimming and candidate generation. An edit can move both endpoints and need not increase the signed training gap G ^ ( S ) \widehat{G}(\mathcal{S}) G ( S ) in equation (14) , so each candidate is evaluated on the full training sample. We allow equal-gap moves and temporary decreases while keeping the best candidate for final selection. With exploration probability χ ∈ [ 0 , 1 ] \chi\in[0,1] χ ∈ [ 0 , 1 ] , the algorithm proceeds as follows.
Initialize a random feasible rule set and include ∅ \varnothing ∅ as a baseline.
Sample trajectories with large U ^ i X ( S ) \widehat{U}^{X}_i(S) U i X ( S ) in class 0 and small L ^ i X ( S ) \widehat{L}^{X}_i(S) L i X ( S ) in class 1, together with relevant prefixes and steps.
Generate candidates by single additions or deletions of rules or predicates, with occasional proposals independent of the sampled trajectories for exploration. Trim redundant rules.
Evaluate candidates on the full training sample and keep the best candidate encountered under equation (15) . Move to the best candidate in the current batch with probability 1 − χ 1-\chi 1 − χ and to a uniformly sampled candidate with probability χ \chi χ .
Repeat for M M M rounds and return the best candidate encountered.
We repeat the search with multiple seeds and select the returned candidate with the largest signed training gap, breaking ties by equation (15) . Appendix § 1.8 gives the complete algorithm.
Empirical Illustration
Setup. Here Y = 0 Y=0 Y = 0 denotes baseline success and Y = 1 Y=1 Y = 1 baseline failure. We use a Ministral 3 8B coding agent on all 300 SWE-bench Lite tasks with 180 trajectories for learning and 120 for evaluation using random splitting. We implement the monitor using the hooks interface of an open-source agent SDK. We set K R = K S = 8 K_R=K_S=8 K R = K S = 8 , ( ϵ 0 , ϵ 1 ) = ( 0.1 , 0.6 ) (\epsilon_0,\epsilon_1)=(0.1,0.6) ( ϵ 0 , ϵ 1 ) = ( 0.1 , 0.6 ) , W = { 50 , … , 500 } \mathcal{W}=\{50,\ldots,500\} W = { 50 , … , 500 } , and α = 0.01 \alpha=0.01 α = 0.01 . We run the single-edit search with twenty seeds and select the candidate with the largest training gap. Appendix § 1.8 gives the search settings.
Predicate pool. We use an LLM to propose candidate predicates and construct Ξ \Xi Ξ from observable events, including tool errors, repeated actions, and edit calls. We threshold event counts over the observed prefix, initial segments, and recent windows, including lagged windows. We also include step thresholds and negations, yielding d = 5,356 d=5{,}356 d = 5 , 356 predicates. Appendix C.1 describes the proposal and expansion.
Result. Across twenty seeds and 200,000 rounds, the largest training gap is attained by seed 8. The selected monitor is an OR of seven rules with ten predicates. It combines conditions on repeated failed actions, tool errors, and edit and test activity across initial segments and recent windows. See Appendix C.§ 0.4 for the full rule definitions.
The selected candidate has U ^ X ( S ^ ( D i n ) ) ( 31 : I i n , 0 ) = 0.68 \widehat{U}^{X}(\widehat{S}(\mathcal{D}_{\mathrm{in}}))_{(31:\mathcal{I}_{\mathrm{in}},0)} = 0.68 U X ( S ( D in ) ) ( 31 : I in , 0 ) = 0.68 and L ^ X ( S ^ ( D i n ) ) ( 88 : I i n , 1 ) = 0.88 \widehat{L}^{X}(\widehat{S}(\mathcal{D}_{\mathrm{in}}))_{(88:\mathcal{I}_{\mathrm{in}},1)} = 0.88 L X ( S ( D in ) ) ( 88 : I in , 1 ) = 0.88 , giving Δ ^ = 0.20 \widehat{\Delta} = 0.20 Δ = 0.20 . We evaluate it using reference 0.78 and stake λ ^ = a T ( α ) / v ( p ^ ) ≈ 0.32764 \widehat{\lambda} = a_T(\alpha)/\sqrt{v(\widehat{p})} \approx0.32764 λ = a T ( α ) / v ( p ) ≈ 0.32764 . Table 1 reports intervention decisions and the fraction of baseline input-plus-output tokens saved. Appendix C gives more details and evidence trajectories. The policy stops 29 failed and 3 successful evaluation trajectories, with detection rate 29/98 = 29.59%, false-positive rate 3/22 = 13.64%, and token savings of 34.46%. Among trajectories that continue, output precision is 19/88 = 21.59%, compared with 22/120 = 18.33% without early stopping.
Table 1. Results for the candidate with the largest training gap across twenty seeds. TP/FP: stopped failures/successes; TN/FN: unstoppable successes/failures. TPR = TP/(TP + FN); Stop prec. = TP/(TP + FP); Output prec. = TN/(TN + FN). All rates are percentages.
Related Work
Monitoring LLM agents is important for detecting failures and enforcing safety requirements during execution ((Sadhuka et al., 2026; Wang et al., 2026a)), especially when autonomous actions carry financial risks ((Hua et al., 2026b)). LeBet studies how statistical requirements for intervention can guide monitor learning. Existing monitors enforce explicit specifications ((Wang et al., 2026a)) or predict violations from learned models of agent behavior ((Wang et al., 2026b)). Other work uses interventions for debugging and causal repair of agent failures ([8 ] (Ma et al. 2026)). Calibrated threshold rules and e-valuator turn verifier outputs into online decisions with error control ((Schirmer et al., 2026; Sadhuka et al., 2026)). Related sequential methods include learning betting strategies for a fixed testing horizon ((Taga et al., 2026)) and detecting distribution shifts with conditional conformal test martingales ((Shaer et al., 2026)). Betting methods have also been applied to financial risk backtesting ((Wang et al., 2026c)) and robot performance evaluation using simulations ((Mahboob et al., 2026)). Gauthier et al. (2026) construct betting processes from payoff differences or policy likelihood ratios to detect strategic deviations in multi-agent systems, with anytime-valid error control and detection-time guarantees. We connect a learned, composable binary signal to false-intervention control and detection through conditions on its average conditional mean. Interpretable rule learning provides the OR-of-AND class and methods for balancing classification accuracy against sparsity ([16 ] (Wang et al. 2017; Rudin et al. 2024)). Association rules have also been analyzed for sequential event prediction using algorithmic stability ((Rudin et al., 2013)). FastSRS searches this class by sampling misclassified examples and proposing local rule edits ((Molero-Río et al., 2026)). We adapt this idea to trajectories and prefixes that limit separation between classwise order statistics. FunSearch and subsequent work on mathematical discovery use LLMs to propose programs and evaluation feedback to guide search ((Romera-Paredes et al., 2024; Ellenberg et al., 2025)). We similarly use an LLM to propose candidate predicates for the fixed pool
Ξ \Xi Ξ , then evaluate their Boolean combinations using empirical separation. Learn then Test frames risk calibration as multiple hypothesis testing over a family of predictors [1 ] .
Discussion
Although motivated by agent intervention, LeBet addresses a broader problem in online decision-making: learning from complete trajectories while acting only on the observed history. Related work spans early time-series classification (Hartvigsen et al., 2019), anomaly prediction [10 ] , optimal stopping [5 ] , and portfolio management (Sutiene et al., 2024). Its central idea is to use statistical conditions for reliable decisions to guide what the monitor learns. The resulting intervention rule uses the betting error budget α \alpha α to control the trade-off between false intervention and detection. This approach may extend to software execution and automated workflows whenever retrospective outcomes provide suitable trajectory labels and the required statistical conditions hold.
AI Disclosure
The authors developed the main research topic, ideas, and insights, drafted the mathematical proofs, and selected and checked the literature references. We used AI agents extensively to help complete the manuscript and code, with careful review by the authors. We reviewed the Lean 4 Challenges against the paper’s definitions and theorem statements to ensure that the claims were not weakened and no assumptions were added by using Comparator (Lean FRO). The Solutions were generated by AI to follow the proofs in the paper and verified by Lean 4.
Notation
We collect the main notation in two tables: quantities and parameters, and sets and spaces. The third column gives key distinctions and definition locations. The indices t t t , i i i , and y y y refer to time, evaluated trajectories, and intervention classes. In s y , i , j s_{y,i,j} s y , i , j , j j j denotes the deleted occurrence; in ξ t j \xi_{t}^{j} ξ t j , it denotes a predicate. The trajectory index ⋆ = n + m + 1 \star= n + m + 1 ⋆ = n + m + 1 denotes the next trajectory and is suppressed when clear from context. Sample and index vectors are written in bold. Auxiliary variables introduced within a proof keep their stated local meanings.
Table 2. Quantities and parameters.
Table 2 (continued).
Table 2 (continued, PDF p. 25).
Table 3. Sets and spaces.
Table 3 (continued).
Table 3 (continued, PDF p. 27).
Additional Examples and Statistical Illustrations
Monitor and Intervention Examples
Note that our guarantees control false intervention and detection. The effect of the chosen action on the subsequent run is application dependent. The examples below pair binary monitors with possible interventions. Each monitor feeds the betting rule in equation (2) ; the associated action is taken at its stopping time τ ( λ , p 0 ) \tau(\lambda, p_0) τ ( λ , p 0 ) . Predicates involving step t − 1 t-1 t − 1 are set to zero at t = 1 t=1 t = 1 .
Example 1: resource inefficiency. Resource inefficiency may appear as a long trajectory, an expensive step, or repeated actions. Consider the monitor
X t ( 1 ) = 1 { t ≥ 100 } ∨ ( 1 { c t > 512 } ∧ 1 { A t = A t − 1 } ) X_t^{(1)} = \mathbb{1}\{t \ge100\} \lor\left(\mathbb{1}\{c_t > 512\} \land\mathbb{1}\{A_t = A_{t-1}\}\right) X t ( 1 ) = 1 { t ≥ 100 } ∨ ( 1 { c t > 512 } ∧ 1 { A t = A t − 1 } )
where c t c_t c t denotes the number of tokens consumed at step t t t . At intervention, the system can terminate the run and return the best available result, or assign the remaining work to a lower-cost model.
Example 2: repeated execution failure. Execution failure may appear as self-reported difficulty, consecutive tool errors, or a failed repeated action. A monitor could be
X t ( 2 ) = 1 { R t expresses difficulty } ∨ ( 1 { O t reports an error } ∧ 1 { O t − 1 reports an error } ) ∨ ( 1 { ∃ s < t : A s = A t } ∧ 1 { O t reports an error } ) . \begin{aligned}
X_t^{(2)} ={}& \mathbb{1}\{R_t\ \text{expresses difficulty}\}\\
&\lor\left(\mathbb{1}\{O_t\ \text{reports an error}\} \land\mathbb{1}\{O_{t-1}\ \text{reports an error}\}\right)\\
&\lor\left(\mathbb{1}\{\exists s < t : A_s = A_t\} \land\mathbb{1}\{O_t\ \text{reports an error}\}\right).
\end{aligned} X t ( 2 ) = 1 { R t expresses difficulty } ∨ ( 1 { O t reports an error } ∧ 1 { O t − 1 reports an error } ) ∨ ( 1 { ∃ s < t : A s = A t } ∧ 1 { O t reports an error } ) .
At intervention, the system can transfer the task, current state, and error history to a more capable model.
Example 3: failed retries and replanning. To detect repeated failures of the same action, define
X t ( 3 ) = 1 { ∃ s ∈ [ t − 1 ] : A s = A t , O s and O t report errors } . X_t^{(3)} = \mathbb{1}\{\exists s \in[t-1] : A_s = A_t,\ O_s\ \text{and}\ O_t\ \text{report errors}\}. X t ( 3 ) = 1 { ∃ s ∈ [ t − 1 ] : A s = A t , O s and O t report errors } .
At intervention, the system can pause the current plan and require a different next action.
Illustration of the Statistical Bounds
Betting Error Budget
Proposition 7 Fix the training quantities and β \beta β in Theorem 5 , and use the default stake for each α ∈ ( 0 , 1 ) \alpha\in(0,1) α ∈ ( 0 , 1 ) . Here e 0 e_0 e 0 and e 1 , t e_{1,t} e 1 , t have the arguments in parts (4) and (5). For each fixed t ∈ W t \in\mathcal{W} t ∈ W :
(1) The bounds min { 1 , δ 0 ( β / 2 ) + e 0 } \min\{1,\delta_0(\beta/2)+e_0\} min { 1 , δ 0 ( β /2 ) + e 0 } and min { 1 , δ 1 ( β / 2 ) + e 1 , t } \min\{1,\delta_1(\beta/2)+e_{1,t}\} min { 1 , δ 1 ( β /2 ) + e 1 , t } are respectively nondecreasing and nonincreasing in α \alpha α .
(2) As α ↓ 0 \alpha\downarrow0 α ↓ 0 , e 0 → 0 e_0 \to0 e 0 → 0 and e 1 , t → 1 e_{1,t} \to1 e 1 , t → 1 . On deployment, as α ↑ 1 \alpha\uparrow1 α ↑ 1 ,
e 0 → 1 , e 1 , t → exp { − t D K L ( Ber ( min { − q ^ 1 , p ^ } ) ∥ Ber ( − q ^ 1 ) ) } . e_0 \to1,\qquad e_{1,t} \to\exp\{-tD_{\mathrm{KL}}(\operatorname{Ber}(\min\{-\widehat{q}_1,\widehat{p}\})\mathbin{\|}\operatorname{Ber}(-\widehat{q}_1))\}. e 0 → 1 , e 1 , t → exp { − t D KL ( Ber ( min { − q 1 , p }) ∥ Ber ( − q 1 ))} .
Proof. For part (1), on deployment, 0 < p ^ < 1 0 < \widehat{p} < 1 0 < p < 1 and log ( 1 / α ) = T 1 v ( p ^ ) λ ^ 2 / 2 \log(1/\alpha)=T_1v(\widehat{p})\widehat{\lambda}^2/2 log ( 1/ α ) = T 1 v ( p ) λ 2 /2 , so λ ^ \widehat{\lambda} λ decreases with α \alpha α . For false intervention, if q ^ 0 ≤ p ^ \widehat{q}_0 \le\widehat{p} q 0 ≤ p , then e 0 = α exp { T 0 [ ψ λ ^ ( q ^ 0 ) − ψ λ ^ ( p ^ ) ] } e_0=\alpha\exp\{T_0[\psi_{\widehat{\lambda}}(\widehat{q}_0)-\psi_{\widehat{\lambda}}(\widehat{p})]\} e 0 = α exp { T 0 [ ψ λ ( q 0 ) − ψ λ ( p )]} . The difference in brackets is nonincreasing in λ ^ \widehat{\lambda} λ , so e 0 e_0 e 0 is nondecreasing in α \alpha α . Otherwise, put
g ( λ ) : = ψ λ ( q ^ 0 ) − ψ λ ( p ^ ) − v ( p ^ ) λ 2 / 2. g(\lambda):=\psi_{\lambda}(\widehat{q}_0)-\psi_{\lambda}(\widehat{p})-v(\widehat{p})\lambda^2/2. g ( λ ) := ψ λ ( q 0 ) − ψ λ ( p ) − v ( p ) λ 2 /2.
By equation (35) , for λ ≥ 0 \lambda\ge0 λ ≥ 0 ,
∂ λ 2 ψ λ ( q ^ 0 ) ≤ v ( q ^ 0 ) ≤ v ( p ^ ) , ∂ λ 2 ψ λ ( p ^ ) ≥ 0. \partial_{\lambda}^2\psi_{\lambda}(\widehat{q}_0)\le v(\widehat{q}_0)\le v(\widehat{p}),\qquad\partial_{\lambda}^2\psi_{\lambda}(\widehat{p})\ge0. ∂ λ 2 ψ λ ( q 0 ) ≤ v ( q 0 ) ≤ v ( p ) , ∂ λ 2 ψ λ ( p ) ≥ 0.
Thus g ( 0 ) = 0 g(0)=0 g ( 0 ) = 0 , g ′ ′ ( λ ) ≤ 0 g''(\lambda)\le0 g ′′ ( λ ) ≤ 0 , and g ′ ( λ ) ≤ g ( λ ) / λ < 0 g'(\lambda)\le g(\lambda)/\lambda<0 g ′ ( λ ) ≤ g ( λ ) / λ < 0 whenever g ( λ ) < 0 g(\lambda)<0 g ( λ ) < 0 . Since e 0 = exp ( T 1 g ( λ ^ ) ) e_0=\exp(T_1g(\widehat{\lambda})) e 0 = exp ( T 1 g ( λ )) , once the truncated bound falls below one, it decreases as λ ^ \widehat{\lambda} λ increases.
For detection, the threshold is
λ ^ − 1 { ψ λ ^ ( p ^ ) + a t ( α ) 2 / 2 } = λ ^ − 1 ψ λ ^ ( p ^ ) + T 1 v ( p ^ ) λ ^ / ( 2 t ) . \widehat{\lambda}^{-1}\{\psi_{\widehat{\lambda}}(\widehat{p})+a_t(\alpha)^2/2\}=\widehat{\lambda}^{-1}\psi_{\widehat{\lambda}}(\widehat{p})+T_1v(\widehat{p})\widehat{\lambda}/(2t). λ − 1 { ψ λ ( p ) + a t ( α ) 2 /2 } = λ − 1 ψ λ ( p ) + T 1 v ( p ) λ / ( 2 t ) .
Convexity of λ ↦ ψ λ ( p ^ ) \lambda\mapsto\psi_{\lambda}(\widehat{p}) λ ↦ ψ λ ( p ) and ψ 0 ( p ^ ) = 0 \psi_0(\widehat{p})=0 ψ 0 ( p ) = 0 imply that ψ λ ( p ^ ) / λ \psi_{\lambda}(\widehat{p})/\lambda ψ λ ( p ) / λ is nondecreasing. Thus the threshold is nondecreasing in λ ^ \widehat{\lambda} λ . Since D K L ( Ber ( h ) ∥ Ber ( p ) ) D_{\mathrm{KL}}(\operatorname{Ber}(h)\mathbin{\|}\operatorname{Ber}(p)) D KL ( Ber ( h ) ∥ Ber ( p )) is nonincreasing in h ≤ p h\le p h ≤ p , e 1 , t e_{1,t} e 1 , t is also nondecreasing in λ ^ \widehat{\lambda} λ .
For part (2), 0 ≤ ψ λ ( u ) ≤ λ 0\le\psi_{\lambda}(u)\le\lambda 0 ≤ ψ λ ( u ) ≤ λ for u ∈ [ 0 , 1 ] u\in[0,1] u ∈ [ 0 , 1 ] , so log e 0 ≤ − log ( 1 / α ) + T 1 λ ^ → − ∞ \log e_0\le-\log(1/\alpha)+T_1\widehat{\lambda}\to-\infty log e 0 ≤ − log ( 1/ α ) + T 1 λ → − ∞ as α ↓ 0 \alpha\downarrow0 α ↓ 0 . The threshold diverges as α ↓ 0 \alpha\downarrow0 α ↓ 0 and tends to p ^ \widehat{p} p as α ↑ 1 \alpha\uparrow1 α ↑ 1 , since ψ λ ( p ^ ) / λ → p ^ \psi_{\lambda}(\widehat{p})/\lambda\to\widehat{p} ψ λ ( p ) / λ → p as λ ↓ 0 \lambda\downarrow0 λ ↓ 0 . Also, ψ λ ^ ( u ) → 0 \psi_{\widehat{\lambda}}(u)\to0 ψ λ ( u ) → 0 as α ↑ 1 \alpha\uparrow1 α ↑ 1 , giving e 0 → 1 e_0\to1 e 0 → 1 .
Under the fallback ( p ^ , λ ^ ) = ( 1 , 1 ) (\widehat{p},\widehat{\lambda})=(1,1) ( p , λ ) = ( 1 , 1 ) , e 0 = α exp { T 0 [ ψ 1 ( q ^ 0 ) − 1 ] } e_0=\alpha\exp\{T_0[\psi_1(\widehat{q}_0)-1]\} e 0 = α exp { T 0 [ ψ 1 ( q 0 ) − 1 ]} and e 1 , t = 1 e_{1,t}=1 e 1 , t = 1 , so the monotonicity and the limits as α ↓ 0 \alpha\downarrow0 α ↓ 0 still hold.
The untruncated e 0 e_0 e 0 need not be monotone where it exceeds one. Figure 1 shows the truncated bounds for several conditional-mean bounds. Smaller q ^ 0 \widehat{q}_0 q 0 and larger − q ^ 1 -\widehat{q}_1 − q 1 improve the corresponding guarantees.
Figure 1. Effect of α \alpha α on the false-intervention and missed-detection bounds. The illustrative values are p ^ = 0.30 \hat{p}=0.30 p ^ = 0.30 , T 0 = 50 T_0=50 T 0 = 50 , T 1 = t = 100 T_1=t=100 T 1 = t = 100 , and δ 0 ( β / 2 ) = δ 1 ( β / 2 ) = 0.02 \delta_0(\beta/2)=\delta_1(\beta/2)=0.02 δ 0 ( β /2 ) = δ 1 ( β /2 ) = 0.02 . The stake is recomputed as λ ^ = a T 1 ( α ) / v ( p ^ ) \hat{\lambda}=aT_1(\alpha)/\sqrt{v(\hat{p})} λ ^ = a T 1 ( α ) / v ( p ^ ) at each α \alpha α . The left panel varies q ^ 0 \hat{q}_0 q ^ 0 ; the right varies − q ^ 1 -\hat{q}_1 − q ^ 1 . Dotted lines mark the fixed learning contribution.
Exact Rank Bound
Figure 2 compares the exact finite-sum bound δ y ( β ) \delta_y(\beta) δ y ( β ) in equation (11) with the closed-form upper bound in equation (113) , truncated at one. We evaluate the law in equation (42) and form W y W_y W y as in Theorem 5 . The objective in equation (11) is piecewise linear in u u u , so evaluating 0, 1, and the support values of W y W_y W y gives the minimum. The difference between the curves reflects the concentration and moment bounds used to obtain equation (113) .
Figure 2. Exact evaluation of equation (11) and its closed-form upper bound equation (12) . The illustrative parameters are m y = n y m_y=n_y m y = n y , ϵ y = 0.05 \epsilon_y=0.05 ϵ y = 0.05 , and θ y = κ m = 0 \theta_y=\kappa_m=0 θ y = κ m = 0 . The left panel varies n y n_y n y from 20 to 1000 in increments of 20, with β = 0.05 \beta=0.05 β = 0.05 . The right panel varies β \beta β , with n y = m y = 100 n_y=m_y=100 n y = m y = 100 . The dashed curve is the closed-form bound, truncated at one; the dotted line marks ϵ y \epsilon_y ϵ y .
Additional Experimental Details
We evaluate the selected monitor from § 0.9 on all 180 training and 120 evaluation trajectories. Each step corresponds to one tool call and its result. Both splits use the same frozen monitor, reference p ^ = 0.78 \hat{p}=0.78 p ^ = 0.78 , stake λ ^ ≈ 0.32764 \hat{\lambda}\approx0.32764 λ ^ ≈ 0.32764 , and threshold parameter α = 0.01 \alpha=0.01 α = 0.01 . Evidence follows equation (2) from the first step, with threshold checks restricted to W = { 50 , … , 500 } W=\{50,\ldots,500\} W = { 50 , … , 500 } .
The monitor stops before the next model call after the triggering tool batch has completed. We count an intervention only when a later model call is avoided, and charge all tokens used through the triggering batch. Thus, crossings after the final model call do not count as interventions; there are five such cases in training and none in evaluation. Trajectories ending before step 50 cannot trigger. Token savings are the fraction of total baseline input-plus-output tokens avoided, as reported in Table 1 .
LLM-Guided Predicate Proposal
The pool in § 0.9 contains 2,678 predicates and their negations, giving d = 5,356 d=5{,}356 d = 5 , 356 . Table 4 and Table 5 show only the unnegated forms. Each predicate is a Boolean function of the observed trajectory prefix.
Table 4. Observable patterns and example candidate rules. Each example is a conjunction of one or more predicates.
Table 5. Temporal constructions before negation.
Proposal. Given failure-mode descriptions and implemented predicate types, an LLM proposes parameterized predicates and candidate conjunctions. We validate the specification and return errors for correction.
Text and command predicates use fixed regular expressions. Repeated actions use the same tool name and input.
Expansion. We vary count, step, token, and error-fraction thresholds over fixed grids, add temporal conditions, and remove duplicate specifications.
Recent-window predicates are false until the full window is available, unless available-history evaluation is specified. Negation is applied after this check.
Visualizations
Figure 3 compares U ^ i X ^ ( D i n ) \widehat{U}_i^{\widehat{X}(D_{\mathrm{in}})} U i X ( D in ) and L ^ i X ^ ( D i n ) \widehat{L}_i^{\widehat{X}(D_{\mathrm{in}})} L i X ( D in ) . Both are computed on observed prefixes in W \mathcal{W} W and set to zero when a trajectory ends before step 50. The training endpoints are 0.68 and 0.88, giving Δ ^ = 0.20 \widehat{\Delta}=0.20 Δ = 0.20 , and are held fixed in the evaluation panel.
Figure 3. Empirical cumulative distributions of U ^ i X ^ ( D i n ) \hat{U}_i^{\hat{X}}(D_{\mathrm{in}}) U ^ i X ^ ( D in ) for baseline successes and L ^ i X ^ ( D i n ) \hat{L}_i^{\hat{X}}(D_{\mathrm{in}}) L ^ i X ^ ( D in ) for baseline failures. Each curve is normalized within its class. Dashed lines mark the training endpoints 0.68 and 0.88; the dotted line marks their midpoint p ^ = 0.78 \hat{p}=0.78 p ^ = 0.78 . The lower arrows span Δ ^ = 0.20 \hat{\Delta}=0.20 Δ ^ = 0.20 . The centered band and upper arrows span 2 v ( p ^ ) a T 1 ( α ) ≈ 0.112 2\sqrt{v(\hat{p})}\,a_{T_1}(\alpha)\approx0.112 2 v ( p ^ ) a T 1 ( α ) ≈ 0.112 .
Figure 4. Betting evidence on training (left) and evaluation (right) trajectories. Each curve represents one baseline trajectory, colored by its final outcome. The horizontal dashed line marks 1 / α = 100 1/\alpha=100 1/ α = 100 ; the shaded region precedes the monitoring window. Both panels use a linear vertical scale restricted to [ 0 , 150 ] [0,150] [ 0 , 150 ] ; values above 150 are not shown. Curves continue along the recorded baseline after a threshold crossing and are shown through the last observed step or t = 300 t=300 t = 300 , whichever comes first.
Case Studies
We select one evaluation case for each outcome: TP, FP, FN, and TN. Within each baseline class, stopped cases are closest to the median trigger time. Unstopped cases are closest to the median observed length among trajectories reaching step 50 without a threshold crossing. Ties are resolved by task identifier. Rule numbers in Figure 5 and Table 6 –Table 9 follow Appendix C.§ 0.4 . The tables summarize recorded reasoning, actions, and observations. A dash denotes no accompanying reasoning text or no firing rules. Values of E t E_t E t are rounded to two decimal places.
Figure 5. Rule values and evidence for four evaluation cases: TP (top left), FP (top right), FN (bottom left), and TN (bottom right). Within each panel, the monitor is the OR of the seven rules. Curves end at the threshold crossing for stopped cases and at the last observed step for unstopped cases. Vertical dashed lines mark threshold crossings; horizontal dashed lines mark 1 / α = 100 1/\alpha= 100 1/ α = 100 . Shading in the evidence plots precedes the monitoring window.
Table 6. Selected steps from django_django-11019: a baseline failure (Y = 1 Y = 1 Y = 1 ), correctly stopped (TP).
Table 9. Selected steps from sympy__sympy-23117: a baseline success (Y = 0 Y = 0 Y = 0 ), not stopped (TN).
Table 7. Selected steps from django_django-10914: a baseline success (Y = 0 Y = 0 Y = 0 ), falsely stopped (FP).
In the stopped failure, repeated edit attempts cannot find the source string. In the stopped success, the agent changes the default permissions, yet rules 6 and 7 remain active. Both stopped cases have X t = 1 X_t = 1 X t = 1 for every t ≤ 73 t \le73 t ≤ 73 , so their evidence curves are identical despite their different baseline outcomes.
Table 8. Selected steps from django__django-11283: a baseline failure (Y = 1 Y = 1 Y = 1 ), not stopped (FN).
The unstopped failure repeatedly rewrites a reproduction script, while the unstopped success fixes the initial empty-array error. Their evidence remains below 100 and ends at 9.72 and 2.36, respectively.
Selected Monitor
The selected monitor is an OR of seven rules with ten predicates:
At least 8 repeated failed actions occur in the last 50 steps.
All 8 steps in the window ending at step t − 8 t - 8 t − 8 match a fixed pattern indicating difficulty.
At least 2 repeated failed actions occur in the latest 5 observed steps, using available history.
The predicate for at most 2 tool errors in the window of 5 steps ending at step t − 8 t - 8 t − 8 is false.
Fewer than 3 edit events occur by step t − 8 t - 8 t − 8 .
Fewer than 32 repeated failed actions occur by step t − 2 t - 2 t − 2 , and fewer than 2 repeated actions occur in the first min { t , 50 } \min\{t, 50\} min { t , 50 } steps.
At least 2 tool errors occur in the first min { t , 20 } \min\{t, 20\} min { t , 20 } steps, at most 2 matching test or reproduction commands fail in the last 16 steps, and fewer than 8 such failures occur in the first min { t , 50 } \min\{t, 50\} min { t , 50 } steps.
Stochastic Local Search
Notation and objective. Fix Ξ = { ξ ℓ ℓ : ℓ ∈ [ d ] } \Xi= \{\xi_{\ell}^{\ell} : \ell\in[d]\} Ξ = { ξ ℓ ℓ : ℓ ∈ [ d ]} , D i n \mathcal{D}_{\mathrm{in}} D in , W \mathcal{W} W , and ϵ 0 , ϵ 1 \epsilon_0, \epsilon_1 ϵ 0 , ϵ 1 . We describe the search directly on S ∈ C S \in\mathcal{C} S ∈ C , using the rules R ∈ S \mathcal{R} \in S R ∈ S and monitor X ( S ) X(S) X ( S ) from the main text. Define the signed training gap
G ^ ( S ) : = L ^ ( n 1 − k 1 + 1 : I i n , 1 ) X ( S ) − U ^ ( k 0 : I i n , 0 ) X ( S ) . (14) \widehat{G}(S) := \widehat{L}^{X(S)}_{(n_1-k_1+1:I_{\mathrm{in},1})} - \widehat{U}^{X(S)}_{(k_0:I_{\mathrm{in},0})}. \tag*{(14)} G ( S ) := L ( n 1 − k 1 + 1 : I in , 1 ) X ( S ) − U ( k 0 : I in , 0 ) X ( S ) . (14)
Its positive part [ G ^ ( S ) ] + [\widehat{G}(S)]_+ [ G ( S ) ] + is the empirical separation in equation (6) . The signed gap distinguishes candidates even when their separation is zero. All candidates are evaluated on the same training sample. The preferred candidate maximizes, in lexicographic order,
( G ^ ( S ′ ) , − ∑ R ∈ S ′ ∣ R ∣ , − ∣ S ′ ∣ ) . (15) \left(\widehat{G}(S'),\;-\sum_{R\in S'}|\mathcal{R}|,\;-|S'|\right). \tag*{(15)} ( G ( S ′ ) , − R ∈ S ′ ∑ ∣ R ∣ , − ∣ S ′ ∣ ) . (15)
Thus ties favor fewer predicates, then fewer rules. For remaining ties, keep the first candidate encountered. Within each search run, A \mathcal{A} A keeps the preferred candidate under this ordering. Each run uses M M M rounds.
To describe the effects of rule edits, define coverage at fixed thresholds p 0 , p 1 ∈ [ 0 , 1 ] p_0,p_1 \in[0,1] p 0 , p 1 ∈ [ 0 , 1 ] by
coverage 0 ( S ; p 0 ) : = ∣ { i ∈ I i n , 0 : U ^ i X ( S ) ≤ p 0 } ∣ , coverage 1 ( S ; p 1 ) : = ∣ { i ∈ I i n , 1 : L ^ i X ( S ) ≥ p 1 } ∣ . (16) \begin{aligned}
\operatorname{coverage}_0(S;p_0) &:= \left|\left\{i \in\mathcal{I}_{\mathrm{in},0} : \widehat{U}^{X(S)}_i \le p_0\right\}\right|,\\
\operatorname{coverage}_1(S;p_1) &:= \left|\left\{i \in\mathcal{I}_{\mathrm{in},1} : \widehat{L}^{X(S)}_i \ge p_1\right\}\right|. \tag*{(16)}
\end{aligned} coverage 0 ( S ; p 0 ) coverage 1 ( S ; p 1 ) := { i ∈ I in , 0 : U i X ( S ) ≤ p 0 } , := { i ∈ I in , 1 : L i X ( S ) ≥ p 1 } . (16)
The first counts class 0 trajectories whose prefix average is at most p 0 p_0 p 0 throughout W \mathcal{W} W ; the second counts class 1 trajectories whose prefix average is at least p 1 p_1 p 1 throughout W \mathcal{W} W . The empirical error budgets require coverage y ( S ; p y ) ≥ k y \operatorname{coverage}_y(S;p_y) \ge k_y coverage y ( S ; p y ) ≥ k y for each class y y y .
The procedure uses five modules: initialization, target selection, rule trimming, candidate generation, and evaluation and update.
Initialization
Sample q q q uniformly from [ min { K S , d } ] [\min\{K_S,d\}] [ min { K S , d }] , then choose q q q distinct predicates uniformly to form singleton rules. Evaluate ∅ \varnothing ∅ first, followed by the initial rule set, and keep the preferred candidate under equation (15) .
Algorithm 2: Initialize Search ( d , K S ) (d,K_S) ( d , K S )
Input: Predicate pool size d ≥ 1 d \ge1 d ≥ 1 , and rule-set capacity K S ≥ 1 K_S \ge1 K S ≥ 1 .
Output: Initial ( S , A ) (\mathcal{S},\mathcal{A}) ( S , A ) .
q ∼ Uniform ( [ min { K S , d } ] ) q \sim\operatorname{Uniform}([\min\{K_S,d\}]) q ∼ Uniform ([ min { K S , d }])
J ∼ Uniform ( { J ⊆ [ d ] : ∣ J ∣ = q } ) J \sim\operatorname{Uniform}(\{J \subseteq[d] : |J| = q\}) J ∼ Uniform ({ J ⊆ [ d ] : ∣ J ∣ = q })
S ← { { ℓ } : ℓ ∈ J } \mathcal{S} \leftarrow\{\{\ell\} : \ell\in J\} S ← {{ ℓ } : ℓ ∈ J }
Compute and store G ^ ( ∅ ) = 0 \widehat{G}(\varnothing)=0 G ( ∅ ) = 0 and G ^ ( S ) \widehat{G}(\mathcal{S}) G ( S )
Set A \mathcal{A} A to the preferred candidate in { ∅ , S } \{\varnothing,\mathcal{S}\} { ∅ , S } under equation (15)
return ( S , A ) (\mathcal{S},\mathcal{A}) ( S , A )
Target Selection
Uniform sampling over all trajectories can waste proposals. Lowering the upper order statistic requires decreasing some U ^ i X ( S ) \widehat{U}^{X(\mathcal{S})}_i U i X ( S ) at or above its current value; raising the lower one requires increasing some L ^ i X ( S ) \widehat{L}^{X(\mathcal{S})}_i L i X ( S ) at or below its current value. We therefore target more promising trajectories by sampling from
J 0 ( S ) : = { i ∈ I i n , 0 : U ^ i X ( S ) ≥ U ^ ( k 0 : I i n , 0 ) X ( S ) } , \mathcal{J}_0(\mathcal{S}) := \left\{i \in\mathcal{I}_{\mathrm{in},0} : \widehat{U}^{X(\mathcal{S})}_i \ge\widehat{U}^{X(\mathcal{S})}_{(k_0:\mathcal{I}_{\mathrm{in},0})}\right\}, J 0 ( S ) := { i ∈ I in , 0 : U i X ( S ) ≥ U ( k 0 : I in , 0 ) X ( S ) } ,
J 1 ( S ) : = { i ∈ I i n , 1 : L ^ i X ( S ) ≤ L ^ ( n 1 − k 1 + 1 : I i n , 1 ) X ( S ) } . (17) \mathcal{J}_1(\mathcal{S}) := \left\{i \in\mathcal{I}_{\mathrm{in},1} : \widehat{L}^{X(\mathcal{S})}_i \le\widehat{L}^{X(\mathcal{S})}_{(n_1-k_1+1:\mathcal{I}_{\mathrm{in},1})}\right\}. \tag*{(17)} J 1 ( S ) := { i ∈ I in , 1 : L i X ( S ) ≤ L ( n 1 − k 1 + 1 : I in , 1 ) X ( S ) } . (17)
For each selected trajectory i i i , to lower U ^ i X ( S ) \widehat{U}^{X(\mathcal{S})}_i U i X ( S ) or raise L ^ i X ( S ) \widehat{L}^{X(\mathcal{S})}_i L i X ( S ) , we target times t t t at which the prefix average μ ^ t , i X ( S ) \widehat{\mu}^{X(\mathcal{S})}_{t,i} μ t , i X ( S ) attains the corresponding maximum or minimum. The extremum may be attained at multiple times. The eligible prefix endpoints form the sets
T 0 ( i , S ) : = { t ∈ W : μ ^ t , i X ( S ) = U ^ i X ( S ) } ∩ { t ∈ W : μ ^ t , i X ( S ) > 0 } , \mathcal{T}_0(i,\mathcal{S}) := \left\{t \in\mathcal{W} : \widehat{\mu}^{X(\mathcal{S})}_{t,i} = \widehat{U}^{X(\mathcal{S})}_i\right\} \cap\left\{t \in\mathcal{W} : \widehat{\mu}^{X(\mathcal{S})}_{t,i} > 0\right\}, T 0 ( i , S ) := { t ∈ W : μ t , i X ( S ) = U i X ( S ) } ∩ { t ∈ W : μ t , i X ( S ) > 0 } ,
T 1 ( i , S ) : = { t ∈ W : μ ^ t , i X ( S ) = L ^ i X ( S ) } ∩ { t ∈ W : μ ^ t , i X ( S ) < 1 } . (18) \mathcal{T}_1(i,\mathcal{S}) := \left\{t \in\mathcal{W} : \widehat{\mu}^{X(\mathcal{S})}_{t,i} = \widehat{L}^{X(\mathcal{S})}_i\right\} \cap\left\{t \in\mathcal{W} : \widehat{\mu}^{X(\mathcal{S})}_{t,i} < 1\right\}. \tag*{(18)} T 1 ( i , S ) := { t ∈ W : μ t , i X ( S ) = L i X ( S ) } ∩ { t ∈ W : μ t , i X ( S ) < 1 } . (18)
Since X s , i ( S ) ∈ { 0 , 1 } X_{s,i}(\mathcal{S}) \in\{0,1\} X s , i ( S ) ∈ { 0 , 1 } ,
μ ^ t , i X ( S ) > 0 ⟺ ∃ s ∈ [ t ] : X s , i ( S ) = 1 , \widehat{\mu}^{X(\mathcal{S})}_{t,i} > 0 \Longleftrightarrow\exists s \in[t] : X_{s,i}(\mathcal{S}) = 1, μ t , i X ( S ) > 0 ⟺ ∃ s ∈ [ t ] : X s , i ( S ) = 1 ,
μ ^ t , i X ( S ) < 1 ⟺ ∃ s ∈ [ t ] : X s , i ( S ) = 0. \widehat{\mu}^{X(\mathcal{S})}_{t,i} < 1 \Longleftrightarrow\exists s \in[t] : X_{s,i}(\mathcal{S}) = 0. μ t , i X ( S ) < 1 ⟺ ∃ s ∈ [ t ] : X s , i ( S ) = 0.
Thus the second set in each intersection ensures { s ∈ [ t ] : X s , i ( S ) = 1 − y } ≠ ∅ \{s \in[t] : X_{s,i}(\mathcal{S}) = 1-y\} \ne\varnothing { s ∈ [ t ] : X s , i ( S ) = 1 − y } = ∅ for t ∈ T y ( i , S ) t \in\mathcal{T}_y(i,\mathcal{S}) t ∈ T y ( i , S ) . For each class y y y , sample successively
i y ∼ Uniform ( { i ∈ J y ( S ) : T y ( i , S ) ≠ ∅ } ) , i_y \sim\operatorname{Uniform}\left(\{i \in\mathcal{J}_y(\mathcal{S}) : \mathcal{T}_y(i,\mathcal{S}) \ne\varnothing\}\right), i y ∼ Uniform ( { i ∈ J y ( S ) : T y ( i , S ) = ∅ } ) ,
t y ∼ Uniform ( T y ( i y , S ) ) , t_y \sim\operatorname{Uniform}(\mathcal{T}_y(i_y,\mathcal{S})), t y ∼ Uniform ( T y ( i y , S )) ,
s y ∼ Uniform ( { s ∈ [ t y ] : X s , i y ( S ) = 1 − y } ) . (19) s_y \sim\operatorname{Uniform}\left(\{s \in[t_y] : X_{s,i_y}(\mathcal{S}) = 1-y\}\right). \tag*{(19)} s y ∼ Uniform ( { s ∈ [ t y ] : X s , i y ( S ) = 1 − y } ) . (19)
This sampling targets trajectories and prefixes where edits may improve the corresponding order statistic.
Exploration. Let χ ∈ [ 0 , 1 ] \chi\in[0,1] χ ∈ [ 0 , 1 ] be the exploration probability. For each batch, sample e y ∼ Ber ( χ ) e_y \sim\operatorname{Ber}(\chi) e y ∼ Ber ( χ ) . When e y = 0 e_y = 0 e y = 0 , use the sampled ( i y , s y ) (i_y,s_y) ( i y , s y ) to guide edits; when e y = 1 e_y = 1 e y = 1 , sample edits without trajectory conditions. Algorithm 3 combines these choices and returns ( e y , i y , s y ) (e_y,i_y,s_y) ( e y , i y , s y ) .
Algorithm 3: SAMPLE TARGET ( S , y , χ ) (S,y,\chi) ( S , y , χ )
Input: Rule set S S S , class y y y , and exploration probability χ ∈ [ 0 , 1 ] \chi\in[0,1] χ ∈ [ 0 , 1 ] .
Output: ( e y , i y , s y ) (e_y,i_y,s_y) ( e y , i y , s y ) : e y = 1 e_y = 1 e y = 1 for exploration, e y = 0 e_y = 0 e y = 0 for a sampled target.
e y ∼ Ber ( χ ) e_y \sim\operatorname{Ber}(\chi) e y ∼ Ber ( χ )
if e y = 1 e_y = 1 e y = 1 then return ( 1 , 0 , 0 ) (1,0,0) ( 1 , 0 , 0 )
J ← { i ∈ J y ( S ) : T y ( i , S ) ≠ ∅ } \mathcal{J} \gets\{i \in\mathcal{J}_y(S) : T_y(i,S) \ne\varnothing\} J ← { i ∈ J y ( S ) : T y ( i , S ) = ∅ }
if J = ∅ \mathcal{J} = \varnothing J = ∅ then return ( 1 , 0 , 0 ) (1,0,0) ( 1 , 0 , 0 )
i y ∼ Uniform ( J ) i_y \sim\operatorname{Uniform}(\mathcal{J}) i y ∼ Uniform ( J )
t y ∼ Uniform ( T y ( i y , S ) ) t_y \sim\operatorname{Uniform}(T_y(i_y,S)) t y ∼ Uniform ( T y ( i y , S ))
s y ∼ Uniform ( { s ∈ [ t y ] : X s , i y ( S ) = 1 − y } ) s_y \sim\operatorname{Uniform}(\{s \in[t_y] : X_{s,i_y}(S) = 1-y\}) s y ∼ Uniform ({ s ∈ [ t y ] : X s , i y ( S ) = 1 − y })
return ( 0 , i y , s y ) (0,i_y,s_y) ( 0 , i y , s y )
Rule Trimming
We remove rules that strictly contain another selected rule to free capacity and avoid repeated evaluations. Define
Trim ( S ′ ) : = { R ∈ S ′ : ∄ R ′ ∈ S ′ with R ′ ⊊ R } . (20) \operatorname{Trim}(S') := \{R \in S' : \nexists R' \in S' \text{ with } R' \subsetneq R\}. \tag*{(20)} Trim ( S ′ ) := { R ∈ S ′ : ∄ R ′ ∈ S ′ with R ′ ⊊ R } . (20)
Repeated application of Lemma 6 (5) shows that this preserves the monitor. For a canonical ordering, sort rules by size and then by predicate indices. Algorithm 4 keeps a rule only if it contains no previously kept rule.
Algorithm 4: TRIM ( S ′ ) (S') ( S ′ )
Input: Proposed rule set S ′ S' S ′ .
Output: A rule set with the same monitor and no rule strictly containing another.
S ′ ′ ← ∅ S'' \gets\varnothing S ′′ ← ∅
foreach R ∈ S ′ R \in S' R ∈ S ′ in canonical order do
if ∄ R ′ ∈ S ′ ′ : R ′ ⊊ R \nexists R' \in S'' : R' \subsetneq R ∄ R ′ ∈ S ′′ : R ′ ⊊ R then S ′ ′ ← S ′ ′ ∪ { R } S'' \gets S'' \cup\{R\} S ′′ ← S ′′ ∪ { R }
return S ′ ′ S'' S ′′
Candidate Generation
Given a sampled trajectory and prefix, the Boolean structure constrains the direction of change under each edit. For example, adding an AND predicate cannot increase the monitor. These monotonicity properties and the necessary conditions in Lemma 6 let us exclude edits that cannot produce the desired change at the sampled step.
Four rule edits. Table 10 gives the candidate sets obtained by adding or deleting a rule or predicate. All edits satisfy the capacities in equation (1) . Lemma 6 gives their effects on the monitor, U ^ i X ( S ) \widehat{U}_i^X(S) U i X ( S ) , L ^ i X ( S ) \widehat{L}_i^X(S) L i X ( S ) , and their order statistics; its proof appears in Appendix K. The coverage inequalities follow from equation (16) with p 0 , p 1 p_0,p_1 p 0 , p 1 fixed. In the Effect column, we suppress coverage arguments and monitor superscripts. The effects on U ^ i \widehat{U}_i U i and L ^ i \widehat{L}_i L i hold for every trajectory i i i . The arrows ↓ \downarrow ↓ and ↑ \uparrow ↑ denote nonincrease and nondecrease, respectively.
Table 10. Effects of feasible rule edits on coverage, trajectory extrema, and order statistics.
Here ℓ ∈ [ d ] \ell\in[d] ℓ ∈ [ d ] throughout. Removing the last predicate is treated as deleting its rule. The expansion edit therefore requires ∣ R ∣ ≥ 2 |\mathcal{R}| \ge2 ∣ R ∣ ≥ 2 . An edit may leave the monitor unchanged because another rule fires at the same steps. Contractions can increase class 0 coverage while reducing class 1 coverage; expansions have the reverse effects. We therefore evaluate the signed gap after each edit.
Edits that decrease U ^ i X ( S ) \widehat{U}_{i}^{X(S)} U i X ( S ) . For e 0 = 0 e_{0}=0 e 0 = 0 , let ( i , s ) = ( i 0 , s 0 ) (i,s)=(i_{0},s_{0}) ( i , s ) = ( i 0 , s 0 ) and draw
R ∼ Uniform ( { R ∈ S : ξ s , i R = 1 } ) . (21) \mathcal{R} \sim\operatorname{Uniform}\left(\{\mathcal{R} \in S : \xi_{s,i}^{\mathcal{R}}=1\}\right). \tag*{(21)} R ∼ Uniform ( { R ∈ S : ξ s , i R = 1 } ) . (21)
Lemma 6 (1) ensures that this set is nonempty. A fair coin chooses between adding an AND predicate and deleting R \mathcal{R} R . For addition, draw
ℓ ∼ Uniform ( { ℓ ∈ [ d ] : ξ s , i ℓ = 0 } ) , S ′ = ( S ∖ { R } ) ∪ { R ∪ { ℓ } } . \ell\sim\operatorname{Uniform}\left(\{\ell\in[d] : \xi_{s,i}^{\ell}=0\}\right), \qquad S'=(S\setminus\{\mathcal{R}\})\cup\{\mathcal{R}\cup\{\ell\}\}. ℓ ∼ Uniform ( { ℓ ∈ [ d ] : ξ s , i ℓ = 0 } ) , S ′ = ( S ∖ { R }) ∪ { R ∪ { ℓ }} .
The sampled predicate is absent from R \mathcal{R} R because R \mathcal{R} R fires at ( s , i ) (s,i) ( s , i ) . If ∣ R ∣ = K R |\mathcal{R}|=K_{\mathcal{R}} ∣ R ∣ = K R or the predicate set is empty, delete R \mathcal{R} R instead. Deletion gives S ′ = S ∖ { R } S'=S\setminus\{\mathcal{R}\} S ′ = S ∖ { R } and is available whenever R ∈ S \mathcal{R}\in S R ∈ S .
For e 0 = 1 e_{0}=1 e 0 = 1 , sample R \mathcal{R} R uniformly from S S S and ℓ \ell ℓ uniformly from [ d ] [d] [ d ] . The same capacity fallback applies; an AND addition with ℓ ∈ R \ell\in\mathcal{R} ℓ ∈ R is discarded. If S = ∅ S=\varnothing S = ∅ , no contraction is available.
Edits that increase L ^ i X ( S ) \widehat{L}_{i}^{X(S)} L i X ( S ) . A fair coin chooses between adding a singleton OR rule and removing an AND predicate. For e 1 = 0 e_{1}=0 e 1 = 0 , let ( i , s ) = ( i 1 , s 1 ) (i,s)=(i_{1},s_{1}) ( i , s ) = ( i 1 , s 1 ) ; draw ℓ ∼ Uniform ( { ℓ ∈ [ d ] : ξ s , i ℓ = 1 } ) \ell\sim\operatorname{Uniform}(\{\ell\in[d]:\xi_{s,i}^{\ell}=1\}) ℓ ∼ Uniform ({ ℓ ∈ [ d ] : ξ s , i ℓ = 1 }) and propose S ′ = S ∪ { { ℓ } } S'=S\cup\{\{\ell\}\} S ′ = S ∪ {{ ℓ }} . By Lemma 6 (3), this makes the selected step covered. For e 1 = 1 e_{1}=1 e 1 = 1 , sample ℓ \ell ℓ from [ d ] [d] [ d ] . If ∣ S ∣ = K S |S|=K_{S} ∣ S ∣ = K S or no eligible predicate exists, attempt removal instead. Removal samples
R ∼ Uniform ( { R ∈ S : ∣ R ∣ ≥ 2 } ) , ℓ ∼ Uniform ( R ) , (22) \mathcal{R}\sim\operatorname{Uniform}(\{\mathcal{R}\in S:|\mathcal{R}|\ge2\}), \qquad\ell\sim\operatorname{Uniform}(\mathcal{R}), \tag*{(22)} R ∼ Uniform ({ R ∈ S : ∣ R ∣ ≥ 2 }) , ℓ ∼ Uniform ( R ) , (22)
and proposes S ′ = ( S ∖ { R } ) ∪ { R ∖ { ℓ } } S'=(S\setminus\{\mathcal{R}\})\cup\{\mathcal{R}\setminus\{\ell\}\} S ′ = ( S ∖ { R }) ∪ { R ∖ { ℓ }} . This removal is sampled independently of ( i , s ) (i,s) ( i , s ) . Discard the attempt if no rule has at least two predicates.
Batches. Given ( e y , i y , s y ) (e_y, i_y, s_y) ( e y , i y , s y ) , a target batch size B ≥ 1 B \ge1 B ≥ 1 , and a maximum number of attempts H ≥ 1 H \ge1 H ≥ 1 , Algorithm 5 repeats the class y y y edit sampler above. Each proposal is trimmed before checking whether it is unchanged or duplicates another proposal. Return B B B distinct candidates, or ∅ \varnothing ∅ if fewer than B B B are collected in H H H attempts. Candidates are kept in the order first generated.
Algorithm 5: GENERATE CANDIDATES(S , y , B , H ; e y , i y , s y S, y, B, H; e_y, i_y, s_y S , y , B , H ; e y , i y , s y )
Input: Current rule set S S S , class y y y , target batch size B ≥ 1 B \ge1 B ≥ 1 , maximum attempts H ≥ 1 H \ge1 H ≥ 1 , and ( e y , i y , s y ) (e_y, i_y, s_y) ( e y , i y , s y ) .
Output: B B B distinct candidates, or ∅ \varnothing ∅ .
Q y ← ∅ Q_y \leftarrow\varnothing Q y ← ∅ , h ← 0 h \leftarrow0 h ← 0
while ∣ Q y ∣ < B |Q_y| < B ∣ Q y ∣ < B do
if h = H h = H h = H then return ∅ \varnothing ∅
h ← h + 1 h \leftarrow h + 1 h ← h + 1
Attempt a class y y y edit of S S S using ( e y , i y , s y ) (e_y, i_y, s_y) ( e y , i y , s y )
if a proposal S ′ S' S ′ is produced then
S ′ ← Trim ( S ′ ) S' \leftarrow\operatorname{Trim}(S') S ′ ← Trim ( S ′ )
if S ′ ≠ S S' \ne S S ′ = S then Q y ← Q y ∪ { S ′ } Q_y \leftarrow Q_y \cup\{S'\} Q y ← Q y ∪ { S ′ }
end
end
return Q y Q_y Q y
Evaluation and Update
For each candidate S ′ ∈ Q S' \in Q S ′ ∈ Q , compute and store G ^ ( S ′ ) \widehat{G}(S') G ( S ′ ) on D i n D_{\mathrm{in}} D in . Keep the preferred candidate in { A } ∪ Q \{A\} \cup Q { A } ∪ Q under equation (15) . Then move to the preferred candidate in Q Q Q with probability 1 − χ 1-\chi 1 − χ , or to a uniformly sampled candidate with probability χ \chi χ . The selected move is taken even if the gap decreases. If Q = ∅ Q = \varnothing Q = ∅ , return the current state and sample new targets in the next round.
Prefix means include all steps from step 1. Comparisons for target trajectories and tied prefixes use absolute tolerance 10 − 12 10^{-12} 1 0 − 12 .
Algorithm 6: EVALUATE AND UPDATE(S , A , Q ; χ S, A, Q; \chi S , A , Q ; χ )
Input: Current rule set S S S , best rule set encountered A A A , proposals Q Q Q , and exploration probability χ ∈ [ 0 , 1 ] \chi\in[0,1] χ ∈ [ 0 , 1 ] .
Output: Updated ( S , A ) (S,A) ( S , A ) .
if Q = ∅ Q = \varnothing Q = ∅ then return ( S , A ) (S,A) ( S , A )
foreach S ′ ∈ Q S' \in Q S ′ ∈ Q in generation order do
Compute and store G ^ ( S ′ ) \widehat{G}(S') G ( S ′ )
end
Keep the preferred candidate in { A } ∪ Q \{A\} \cup Q { A } ∪ Q under equation (15) as A A A
e ∼ Ber ( χ ) e \sim\operatorname{Ber}(\chi) e ∼ Ber ( χ )
if e = 1 e = 1 e = 1 then
S ∼ Uniform ( Q ) S \sim\operatorname{Uniform}(Q) S ∼ Uniform ( Q )
else
Set S S S to the preferred candidate in Q Q Q under equation (15)
end
return ( S , A ) (S,A) ( S , A )
Stochastic Local Search
Algorithm 7 combines the five modules for one search seed. The target batch size B B B and maximum attempts H H H apply separately to each direction. Each candidate is obtained by one edit followed by trimming. Pass both batches to Algorithm 6, with contraction candidates first. After M M M rounds, return A \mathcal{A} A . Training trajectories are ordered by identifier before random draws.
Algorithm 7: STOCHASTIC LOCAL SEARCH (SLS)
Input: Ξ \Xi Ξ , D i n D_{\mathrm{in}} D in , W \mathcal{W} W , ( ϵ 0 , ϵ 1 ) (\epsilon_0,\epsilon_1) ( ϵ 0 , ϵ 1 ) , ( K R , K S ) (K_R,K_S) ( K R , K S ) ; M ≥ 1 M \ge1 M ≥ 1 rounds, target batch size B ≥ 1 B \ge1 B ≥ 1 per direction, maximum attempts H ≥ 1 H \ge1 H ≥ 1 , exploration probability χ ∈ [ 0 , 1 ] \chi\in[0,1] χ ∈ [ 0 , 1 ] , and a search seed.
Output: Best rule set encountered A \mathcal{A} A .
Initialize the random generator with the search seed
( S , A ) ← InitializeSearch ( d , K S ) (S,\mathcal{A}) \leftarrow\operatorname{InitializeSearch}(d,K_S) ( S , A ) ← InitializeSearch ( d , K S )
for h = 1 , … , M h = 1,\ldots,M h = 1 , … , M do
for y ∈ { 0 , 1 } y \in\{0,1\} y ∈ { 0 , 1 } do
( e y , i y , s y ) ← SampleTarget ( S , y , χ ) (e_y,i_y,s_y) \leftarrow\operatorname{SampleTarget}(S,y,\chi) ( e y , i y , s y ) ← SampleTarget ( S , y , χ )
Q y ← GenerateCandidates ( S , y , B , H ; e y , i y , s y ) Q_y \leftarrow\operatorname{GenerateCandidates}(S,y,B,H;e_y,i_y,s_y) Q y ← GenerateCandidates ( S , y , B , H ; e y , i y , s y )
end
( S , A ) ← EvaluateAndUpdate ( S , A , Q 0 ∪ Q 1 ; χ ) (S,\mathcal{A}) \leftarrow\operatorname{EvaluateAndUpdate}(S,\mathcal{A},Q_0 \cup Q_1;\chi) ( S , A ) ← EvaluateAndUpdate ( S , A , Q 0 ∪ Q 1 ; χ )
end
return A \mathcal{A} A
We run SLS with multiple seeds and select the candidate with the largest signed training gap across all runs, breaking ties by equation (15) .
Reported configuration. We use M = 10,000 M = 10{,}000 M = 10 , 000 rounds per search seed, seeds 1 , … , 20 1,\ldots,20 1 , … , 20 , target batch size B = 16 B = 16 B = 16 per direction, maximum attempts H = 256 H = 256 H = 256 , χ = 0.25 \chi= 0.25 χ = 0.25 . Reported runs stored ten candidates per seed; the additional candidates do not affect the search or final selection. All runs use ( ϵ 0 , ϵ 1 ) = ( 0.1 , 0.6 ) (\epsilon_0,\epsilon_1) = (0.1,0.6) ( ϵ 0 , ϵ 1 ) = ( 0.1 , 0.6 ) and the capacities and window in § 0.9 .
Betting Interpretation of the Monitor Evidence
In this appendix, we give two equivalent interpretations of the monitor evidence process in equation (2) . The first is a linear betting interpretation, while the second is a Bernoulli likelihood-ratio interpretation.
For any λ > 0 \lambda> 0 λ > 0 ,
e ψ λ ( p 0 ) = 1 − p 0 + p 0 exp ( λ ) = 1 + p 0 ( exp ( λ ) − 1 ) . (23) e^{\psi_\lambda(p_0)} = 1 - p_0 + p_0 \exp(\lambda) = 1 + p_0\left(\exp(\lambda)-1\right). \tag*{(23)} e ψ λ ( p 0 ) = 1 − p 0 + p 0 exp ( λ ) = 1 + p 0 ( exp ( λ ) − 1 ) . (23)
Let
b ( λ ) : = exp ( λ ) − 1 e ψ λ ( p 0 ) . (24) b(\lambda) := \frac{\exp(\lambda)-1}{e^{\psi_\lambda(p_0)}}. \tag*{(24)} b ( λ ) := e ψ λ ( p 0 ) exp ( λ ) − 1 . (24)
Since λ > 0 \lambda> 0 λ > 0 , we have exp ( λ ) − 1 > 0 \exp(\lambda)-1 > 0 exp ( λ ) − 1 > 0 and, therefore, b ( λ ) > 0 b(\lambda) > 0 b ( λ ) > 0 . Furthermore,
p 0 b ( λ ) = p 0 ( exp ( λ ) − 1 ) 1 + p 0 ( exp ( λ ) − 1 ) < 1. p_0b(\lambda) = \frac{p_0\left(\exp(\lambda)-1\right)}{1+p_0\left(\exp(\lambda)-1\right)} < 1. p 0 b ( λ ) = 1 + p 0 ( exp ( λ ) − 1 ) p 0 ( exp ( λ ) − 1 ) < 1.
Thus, both possible one-step multipliers 1 − p 0 b ( λ ) 1-p_0b(\lambda) 1 − p 0 b ( λ ) and 1 + ( 1 − p 0 ) b ( λ ) 1+(1-p_0)b(\lambda) 1 + ( 1 − p 0 ) b ( λ ) are strictly positive.
Since X s ∈ { 0 , 1 } X_s \in\{0,1\} X s ∈ { 0 , 1 } ,
exp ( λ X s ) e ψ λ ( p 0 ) = 1 + ( exp ( λ ) − 1 ) X s e ψ λ ( p 0 ) = eq. 23 1 + exp ( λ ) − 1 e ψ λ ( p 0 ) ( X s − p 0 ) = eq. 24 1 + b ( λ ) ( X s − p 0 ) . \frac{\exp(\lambda X_s)}{e^{\psi_\lambda(p_0)}} = \frac{1+\left(\exp(\lambda)-1\right)X_s}{e^{\psi_\lambda(p_0)}} \mathrel{\overset{\text{eq. 23}}{=}} 1+\frac{\exp(\lambda)-1}{e^{\psi_\lambda(p_0)}}(X_s-p_0) \mathrel{\overset{\text{eq. 24}}{=}} 1+b(\lambda)(X_s-p_0). e ψ λ ( p 0 ) exp ( λ X s ) = e ψ λ ( p 0 ) 1 + ( exp ( λ ) − 1 ) X s = eq. 23 1 + e ψ λ ( p 0 ) exp ( λ ) − 1 ( X s − p 0 ) = eq. 24 1 + b ( λ ) ( X s − p 0 ) .
It follows that
E t ( λ , p 0 ) = ∏ s = 1 t [ 1 + b ( λ ) ( X s − p 0 ) ] . E_t(\lambda,p_0)=\prod_{s=1}^{t}\left[1+b(\lambda)(X_s-p_0)\right]. E t ( λ , p 0 ) = s = 1 ∏ t [ 1 + b ( λ ) ( X s − p 0 ) ] .
Therefore, E t ( λ , p 0 ) E_t(\lambda,p_0) E t ( λ , p 0 ) can be viewed as the wealth process of a bettor (Waudby-Smith and Ramdas, 2024; Taga et al., 2026) who repeatedly bets against the reference level p 0 p_0 p 0 using the constant betting fraction b ( λ ) b(\lambda) b ( λ ) .
For 0 < p 0 < 1 0<p_0<1 0 < p 0 < 1 , we next give the likelihood-ratio interpretation. Define
q ( λ ) : = p 0 exp ( λ ) 1 − p 0 + p 0 exp ( λ ) = p 0 exp ( λ ) e ψ λ ( p 0 ) . (25) q(\lambda):=\frac{p_0\exp(\lambda)}{1-p_0+p_0\exp(\lambda)}
=\frac{p_0\exp(\lambda)}{e^{\psi_\lambda(p_0)}}. \tag*{(25)} q ( λ ) := 1 − p 0 + p 0 exp ( λ ) p 0 exp ( λ ) = e ψ λ ( p 0 ) p 0 exp ( λ ) . (25)
Then
q ( λ ) p 0 = exp ( λ ) e ψ λ ( p 0 ) , 1 − q ( λ ) 1 − p 0 = 1 e ψ λ ( p 0 ) . \frac{q(\lambda)}{p_0}=\frac{\exp(\lambda)}{e^{\psi_\lambda(p_0)}},\qquad
\frac{1-q(\lambda)}{1-p_0}=\frac{1}{e^{\psi_\lambda(p_0)}}. p 0 q ( λ ) = e ψ λ ( p 0 ) exp ( λ ) , 1 − p 0 1 − q ( λ ) = e ψ λ ( p 0 ) 1 .
Using X s ∈ { 0 , 1 } X_s\in\{0,1\} X s ∈ { 0 , 1 } , we thus obtain
exp ( λ X s ) 1 − p 0 + p 0 exp ( λ ) = ( q ( λ ) p 0 ) X s ( 1 − q ( λ ) 1 − p 0 ) 1 − X s . (26) \frac{\exp(\lambda X_s)}{1-p_0+p_0\exp(\lambda)}
=\left(\frac{q(\lambda)}{p_0}\right)^{X_s}
\left(\frac{1-q(\lambda)}{1-p_0}\right)^{1-X_s}. \tag*{(26)} 1 − p 0 + p 0 exp ( λ ) exp ( λ X s ) = ( p 0 q ( λ ) ) X s ( 1 − p 0 1 − q ( λ ) ) 1 − X s . (26)
Multiplying equation (26) from s = 1 s=1 s = 1 through s = t s=t s = t gives
E t ( λ , p 0 ) = ∏ s = 1 t ( q ( λ ) p 0 ) X s ( 1 − q ( λ ) 1 − p 0 ) 1 − X s . E_t(\lambda,p_0)=\prod_{s=1}^{t}
\left(\frac{q(\lambda)}{p_0}\right)^{X_s}
\left(\frac{1-q(\lambda)}{1-p_0}\right)^{1-X_s}. E t ( λ , p 0 ) = s = 1 ∏ t ( p 0 q ( λ ) ) X s ( 1 − p 0 1 − q ( λ ) ) 1 − X s .
Hence, E t ( λ , p 0 ) E_t(\lambda,p_0) E t ( λ , p 0 ) is algebraically identical to the likelihood ratio for t t t independent observations under Ber ( q ( λ ) ) \operatorname{Ber}(q(\lambda)) Ber ( q ( λ )) versus Ber ( p 0 ) \operatorname{Ber}(p_0) Ber ( p 0 ) .
For p 1 ∈ ( p 0 , 1 ) p_1\in(p_0,1) p 1 ∈ ( p 0 , 1 ) , the log-evidence growth satisfies
λ p 1 − ψ λ ( p 0 ) = p 1 log exp ( λ ) e ψ λ ( p 0 ) + ( 1 − p 1 ) log 1 e ψ λ ( p 0 ) = eq. 25 p 1 log q ( λ ) p 0 + ( 1 − p 1 ) log 1 − q ( λ ) 1 − p 0 = D K L ( Ber ( p 1 ) ∥ Ber ( p 0 ) ) − D K L ( Ber ( p 1 ) ∥ Ber ( q ( λ ) ) ) ≤ D K L ( Ber ( p 1 ) ∥ Ber ( p 0 ) ) . (27) \begin{aligned}
\lambda p_1-\psi_\lambda(p_0)
&=p_1\log\frac{\exp(\lambda)}{e^{\psi_\lambda(p_0)}}+(1-p_1)\log\frac{1}{e^{\psi_\lambda(p_0)}}\\
&\overset{\text{eq. 25}}{=}p_1\log\frac{q(\lambda)}{p_0}+(1-p_1)\log\frac{1-q(\lambda)}{1-p_0}\\
&=D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\mathbin\Vert\operatorname{Ber}(p_0))-D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\mathbin\Vert\operatorname{Ber}(q(\lambda)))\\
&\le D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\mathbin\Vert\operatorname{Ber}(p_0)). \tag*{(27)}
\end{aligned} λ p 1 − ψ λ ( p 0 ) = p 1 log e ψ λ ( p 0 ) exp ( λ ) + ( 1 − p 1 ) log e ψ λ ( p 0 ) 1 = eq. 25 p 1 log p 0 q ( λ ) + ( 1 − p 1 ) log 1 − p 0 1 − q ( λ ) = D KL ( Ber ( p 1 ) ∥ Ber ( p 0 )) − D KL ( Ber ( p 1 ) ∥ Ber ( q ( λ ))) ≤ D KL ( Ber ( p 1 ) ∥ Ber ( p 0 )) . (27)
The last inequality uses nonnegativity of KL divergence. Lemma 9 gives the maximizing stake λ ∗ = log { p 1 ( 1 − p 0 ) / ( p 0 ( 1 − p 1 ) ) } > 0 \lambda^*=\log\{p_1(1-p_0)/(p_0(1-p_1))\}>0 λ ∗ = log { p 1 ( 1 − p 0 ) / ( p 0 ( 1 − p 1 ))} > 0 . Substituting equation (32) and equation (33) into equation (25) gives q ( λ ∗ ) = p 1 q(\lambda^*)=p_1 q ( λ ∗ ) = p 1 . Therefore,
E t ( λ ∗ , p 0 ) = ∏ s = 1 t ( p 1 p 0 ) X s ( 1 − p 1 1 − p 0 ) 1 − X s . E_t(\lambda^*,p_0)=\prod_{s=1}^{t}
\left(\frac{p_1}{p_0}\right)^{X_s}
\left(\frac{1-p_1}{1-p_0}\right)^{1-X_s}. E t ( λ ∗ , p 0 ) = s = 1 ∏ t ( p 0 p 1 ) X s ( 1 − p 0 1 − p 1 ) 1 − X s .
Since q ( λ ∗ ) = p 1 q(\lambda^*)=p_1 q ( λ ∗ ) = p 1 , equality holds in equation (27) .
Exchangeability, Stability, and Generalization: A Discussion
We relate Assumptions 1 and 4 to exchangeability and stability conditions used in conformal prediction and learning theory.
Finite exchangeable extensions within classes. Angelopoulos et al. [2 ] (Section 6.2.1) use a finite exchangeable extension beyond the observed sample and one test point to sharpen marginal coverage guarantees for cross-conformal prediction; the additional points need not be observed. Label-conditional conformal prediction uses calibration observations from each class separately to control coverage conditional on the test label (Vovk, 2013, Section 4). Xie et al. (2025) assume joint exchangeability and use test–calibration swaps to establish validity under selective sample splitting. Their assumption also implies within-class symmetry after conditioning on the label vector. Assumption 1 combines a finite extension with within-class symmetry of complete trajectories. The extension does not follow from exchangeability of the observed trajectories and ω ⋆ \omega_\star ω ⋆ alone. Exchangeability alone does not generally ensure training-conditional coverage. Under i.i.d. sampling, Vovk (2013) establishes such guarantees for split conformal prediction, whereas Bian and Barber [6 ] show that they need not hold for full conformal and jackknife+ without further assumptions.
Stability and training-conditional generalization. Bousquet and Elisseeff [9 ] derive generalization bounds by controlling changes in a learner’s loss under changes in the training data. In conformal prediction, Liang and Barber (2025) establish training-conditional coverage for inflated versions of jackknife+ and full conformal under i.i.d. sampling and appropriate stability conditions. Liang and Barber (2025) (Sections 4.1–4.3) control prediction changes in expectation or probability, including swap comparisons that exclude the evaluated point from both fits. Assumption 4 uses the same exclusion but compares the conditional-mean extrema S y i , i , i ( D ; J ) S_{y_i,i,i}(D; \mathcal{J}) S y i , i , i ( D ; J ) , so changes in the conditioning data also enter the comparison. Their guarantees assume i.i.d. sampling; ours use within-class exchanges under Assumption 1 and average the stability failure probability over these exchanges.
Auxiliary Lemmas
Lemma 8 (Evidence bounds). For p 0 ∈ [ 0 , 1 ] p_0 \in[0,1] p 0 ∈ [ 0 , 1 ] , λ > 0 \lambda> 0 λ > 0 , and t ∈ W t \in\mathcal{W} t ∈ W ,
t { λ ( μ ^ t X − p 0 ) − v ( p 0 ) λ 2 2 } ≤ log E t ( λ , p 0 ) ≤ t λ ( μ ^ t X − p 0 ) . (28) t\left\{\lambda(\widehat{\mu}^{X}_t-p_0)-\frac{v(p_0)\lambda^2}{2}\right\}\le\log E_t(\lambda,p_0)\le t\lambda(\widehat{\mu}^{X}_t-p_0). \tag*{(28)} t { λ ( μ t X − p 0 ) − 2 v ( p 0 ) λ 2 } ≤ log E t ( λ , p 0 ) ≤ t λ ( μ t X − p 0 ) . (28)
Proof. The definitions give
log E t ( λ , p 0 ) = e q . 2 λ ∑ s = 1 t X s − t log ( 1 − p 0 + p 0 e λ ) = e q . 3 t λ μ ^ t X − t log ( 1 − p 0 + p 0 e λ ) . (29) \log E_t(\lambda,p_0)\overset{\mathrm{eq.}\ 2}{=}\lambda\sum_{s=1}^{t}X_s-t\log(1-p_0+p_0e^\lambda)\overset{\mathrm{eq.}\ 3}{=}t\lambda\widehat{\mu}^{X}_t-t\log(1-p_0+p_0e^\lambda). \tag*{(29)} log E t ( λ , p 0 ) = eq. 2 λ s = 1 ∑ t X s − t log ( 1 − p 0 + p 0 e λ ) = eq. 3 t λ μ t X − t log ( 1 − p 0 + p 0 e λ ) . (29)
Jensen’s inequality and Lemma 10 give
λ p 0 ≤ J e n s e n log ( 1 − p 0 + p 0 e λ ) ≤ e q . 36 λ p 0 + v ( p 0 ) λ 2 2 . (30) \lambda p_0\overset{\mathrm{Jensen}}{\le}\log(1-p_0+p_0e^\lambda)\overset{\mathrm{eq.}\ 36}{\le}\lambda p_0+\frac{v(p_0)\lambda^2}{2}. \tag*{(30)} λ p 0 ≤ Jensen log ( 1 − p 0 + p 0 e λ ) ≤ eq. 36 λ p 0 + 2 v ( p 0 ) λ 2 . (30)
log E t ( λ , p 0 ) = e q . 29 t λ μ ^ t X − t log ( 1 − p 0 + p 0 e λ ) ≥ e q . 30 t { λ ( μ ^ t X − p 0 ) − v ( p 0 ) λ 2 2 } , \log E_t(\lambda,p_0)\overset{\mathrm{eq.}\ 29}{=}t\lambda\widehat{\mu}^{X}_t-t\log(1-p_0+p_0e^\lambda)
\overset{\mathrm{eq.}\ 30}{\ge}t\left\{\lambda(\widehat{\mu}^{X}_t-p_0)-\frac{v(p_0)\lambda^2}{2}\right\}, log E t ( λ , p 0 ) = eq. 29 t λ μ t X − t log ( 1 − p 0 + p 0 e λ ) ≥ eq. 30 t { λ ( μ t X − p 0 ) − 2 v ( p 0 ) λ 2 } ,
log E t ( λ , p 0 ) ≤ e q . 30 t λ ( μ ^ t X − p 0 ) . \log E_t(\lambda,p_0)\overset{\mathrm{eq.}\ 30}{\le}t\lambda(\widehat{\mu}^{X}_t-p_0). log E t ( λ , p 0 ) ≤ eq. 30 t λ ( μ t X − p 0 ) .
Lemma 9 (Bernoulli KL duality). For 0 < p 0 , p 1 < 1 0 < p_0,p_1 < 1 0 < p 0 , p 1 < 1 , the maximum is attained at z ⋆ : = log { p 1 ( 1 − p 0 ) / ( p 0 ( 1 − p 1 ) ) } z^\star:= \log\{p_1(1-p_0)/(p_0(1-p_1))\} z ⋆ := log { p 1 ( 1 − p 0 ) / ( p 0 ( 1 − p 1 ))} , and
sup z ∈ R { z p 1 − ψ z ( p 0 ) } = D K L ( Ber ( p 1 ) ∥ Ber ( p 0 ) ) . (31) \sup_{z\in\mathbb{R}}\{zp_1-\psi_z(p_0)\}=D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\|\operatorname{Ber}(p_0)). \tag*{(31)} z ∈ R sup { z p 1 − ψ z ( p 0 )} = D KL ( Ber ( p 1 ) ∥ Ber ( p 0 )) . (31)
Proof. The objective is strictly concave, and
∂ z { z p 1 − ψ z ( p 0 ) } = p 1 − p 0 e z 1 − p 0 + p 0 e z = 0 ⟺ e z = p 1 ( 1 − p 0 ) p 0 ( 1 − p 1 ) . (32) \partial_z\{zp_1-\psi_z(p_0)\}=p_1-\frac{p_0e^z}{1-p_0+p_0e^z}=0\quad\Longleftrightarrow\quad e^z=\frac{p_1(1-p_0)}{p_0(1-p_1)}. \tag*{(32)} ∂ z { z p 1 − ψ z ( p 0 )} = p 1 − 1 − p 0 + p 0 e z p 0 e z = 0 ⟺ e z = p 0 ( 1 − p 1 ) p 1 ( 1 − p 0 ) . (32)
At z = z ⋆ z=z^\star z = z ⋆ ,
e ψ z ⋆ ( p 0 ) = eq. 32 1 − p 0 + p 1 ( 1 − p 0 ) 1 − p 1 = 1 − p 0 1 − p 1 . (33) e^{\psi_{z^\star}(p_0)} \mathrel{\mathop=^{\text{eq. 32}}} 1-p_0+\frac{p_1(1-p_0)}{1-p_1}=\frac{1-p_0}{1-p_1}. \tag*{(33)} e ψ z ⋆ ( p 0 ) = eq. 32 1 − p 0 + 1 − p 1 p 1 ( 1 − p 0 ) = 1 − p 1 1 − p 0 . (33)
Hence
z ⋆ p 1 − ψ z ⋆ ( p 0 ) = eq. 33 p 1 log p 1 p 0 + ( 1 − p 1 ) log 1 − p 1 1 − p 0 = D K L ( Ber ( p 1 ) ∥ Ber ( p 0 ) ) . z^\star p_1-\psi_{z^\star}(p_0) \mathrel{\mathop=^{\text{eq. 33}}} p_1\log\frac{p_1}{p_0}+(1-p_1)\log\frac{1-p_1}{1-p_0}=D_{\mathrm{KL}}(\operatorname{Ber}(p_1)\|\operatorname{Ber}(p_0)). z ⋆ p 1 − ψ z ⋆ ( p 0 ) = eq. 33 p 1 log p 0 p 1 + ( 1 − p 1 ) log 1 − p 0 1 − p 1 = D KL ( Ber ( p 1 ) ∥ Ber ( p 0 )) .
Hoeffding Bounds
Lemma 10 (Bernoulli case of Hoeffding’s lemma ([4 Lemma 1.3] ). For m ∈ [ 0 , 1 ] m\in[0,1] m ∈ [ 0 , 1 ] and z ∈ R z\in\mathbb{R} z ∈ R ,
( 1 − m + m e z ) e − z m ≤ e z 2 / 8 . (34) (1-m+me^z)e^{-zm}\le e^{z^2/8}. \tag*{(34)} ( 1 − m + m e z ) e − z m ≤ e z 2 /8 . (34) For z ≥ 0 z\ge0 z ≥ 0 ,
0 ≤ ∂ z 2 ψ z ( m ) ≤ v ( m ) , (35) 0\le\partial_z^2\psi_z(m)\le v(m), \tag*{(35)} 0 ≤ ∂ z 2 ψ z ( m ) ≤ v ( m ) , (35) and the bound sharpens to
( 1 − m + m e z ) e − z m ≤ e v ( m ) z 2 / 2 . (36) (1-m+me^z)e^{-zm}\le e^{v(m)z^2/2}. \tag*{(36)} ( 1 − m + m e z ) e − z m ≤ e v ( m ) z 2 /2 . (36) Note that we sharpen the standard bound for z > 0 z>0 z > 0 in equation (36) .
Proof [Proof of equation (35) and equation (36) ] Put f m ( z ) : = log ( 1 − m + m e z ) − m z f_m(z):=\log(1-m+me^z)-mz f m ( z ) := log ( 1 − m + m e z ) − m z and q m ( z ) : = m e z / ( 1 − m + m e z ) q_m(z):=me^z/(1-m+me^z) q m ( z ) := m e z / ( 1 − m + m e z ) . Then f m ( 0 ) = f m ′ ( 0 ) = 0 f_m(0)=f'_m(0)=0 f m ( 0 ) = f m ′ ( 0 ) = 0 . For z ≥ 0 z\ge0 z ≥ 0 , q m ( z ) ∈ [ m , 1 ] q_m(z)\in[m,1] q m ( z ) ∈ [ m , 1 ] , so
0 ≤ ∂ z 2 ψ z ( m ) = f m ′ ′ ( z ) = q m ( z ) ( 1 − q m ( z ) ) ≤ v ( m ) . 0\le\partial_z^2\psi_z(m)=f''_m(z)=q_m(z)(1-q_m(z))\le v(m). 0 ≤ ∂ z 2 ψ z ( m ) = f m ′′ ( z ) = q m ( z ) ( 1 − q m ( z )) ≤ v ( m ) . ( 1 − m + m e z ) e − z m = exp { ∫ 0 z ( z − u ) f m ′ ′ ( u ) d u } ≤ eq. 35 exp { v ( m ) z 2 / 2 } . (1-m+me^z)e^{-zm}=\exp\left\{\int_0^z(z-u)f''_m(u)\,\mathrm{d}u\right\}\mathrel{\mathop{\le}^{\text{eq. 35}}}\exp\{v(m)z^2/2\}. ( 1 − m + m e z ) e − z m = exp { ∫ 0 z ( z − u ) f m ′′ ( u ) d u } ≤ eq. 35 exp { v ( m ) z 2 /2 } .
Lemma 11 (Hoeffding–Serfling inequality ([4 Theorem 2.4] ). Let x 1 , … , x N ∈ [ a , b ] x_1,\ldots,x_N\in[a,b] x 1 , … , x N ∈ [ a , b ] , with N ≥ 2 N\ge2 N ≥ 2 and a < b a<b a < b , and let K ∼ Q k , N − k K\sim Q_{k,N-k} K ∼ Q k , N − k , where 1 ≤ k ≤ N 1\le k\le N 1 ≤ k ≤ N . Put μ : = N − 1 ∑ i = 1 N x i \mu:=N^{-1}\sum_{i=1}^N x_i μ := N − 1 ∑ i = 1 N x i and ρ k : = 1 − ( k − 1 ) / N \rho_k:=1-(k-1)/N ρ k := 1 − ( k − 1 ) / N . For every s > 0 s>0 s > 0 and either fixed sign,
Q k , N − k ( ± ( 1 k ∑ i ∈ K x i − μ ) ≥ s ) ≤ exp { − 2 k s 2 ρ k ( b − a ) 2 } . (37) Q_{k,N-k}\left(\pm\left(\frac{1}{k}\sum_{i\in K}x_i-\mu\right)\ge s\right)\le\exp\left\{-\frac{2ks^2}{\rho_k(b-a)^2}\right\}. \tag*{(37)} Q k , N − k ( ± ( k 1 i ∈ K ∑ x i − μ ) ≥ s ) ≤ exp { − ρ k ( b − a ) 2 2 k s 2 } . (37)
Lemma 12 (Weighted tail bound). Suppose R ≥ 0 R \ge0 R ≥ 0 satisfies P ( R > s ) ≤ e − c s 2 \mathbb{P}(R > s) \le e^{-cs^{2}} P ( R > s ) ≤ e − c s 2 for some c > 0 c > 0 c > 0 and every s > 0 s > 0 s > 0 . For any random variable h ∈ [ 0 , 1 ] h \in[0,1] h ∈ [ 0 , 1 ] with q : = E h > 0 q := \mathbb{E}h > 0 q := E h > 0 ,
E [ h R ] q ≤ log ( e / q ) c . (38) \frac{\mathbb{E}[hR]}{q} \le\sqrt{\frac{\log(e/q)}{c}}. \tag*{(38)} q E [ h R ] ≤ c log ( e / q ) . (38) Proof. Cauchy–Schwarz and tail integration (Vershynin, 2017, Eq. (2.2.10)) give
( E [ h R ] q ) 2 ≤ E [ h R 2 ] q = 1 q ∫ 0 ∞ E [ h 1 { R > u } ] d u \left(\frac{\mathbb{E}[hR]}{q}\right)^{2} \le\frac{\mathbb{E}[hR^{2}]}{q} = \frac{1}{q}\int_{0}^{\infty}\mathbb{E}\left[h\mathbf{1}\{R>\sqrt{u}\}\right]\,du ( q E [ h R ] ) 2 ≤ q E [ h R 2 ] = q 1 ∫ 0 ∞ E [ h 1 { R > u } ] d u ≤ 1 q ∫ 0 ∞ min { q , e − c u } d u = log ( e / q ) c . \le\frac{1}{q}\int_{0}^{\infty}\min\{q,e^{-cu}\}\,du = \frac{\log(e/q)}{c}. ≤ q 1 ∫ 0 ∞ min { q , e − c u } d u = c log ( e / q ) .
Order Statistics and Finite Averaging
Lemma 13 (Order-statistic budgets). Let a 1 , … , a N ∈ R a_1,\ldots,a_N \in\mathbb{R} a 1 , … , a N ∈ R , with N ≥ 1 N \ge1 N ≥ 1 . For p ∈ R p \in\mathbb{R} p ∈ R and an integer 0 ≤ r < N 0 \le r < N 0 ≤ r < N ,
∣ { i : a i > p } ∣ ≤ r ⟺ a ( N − r : [ N ] ) ≤ p , ∣ { i : a i < p } ∣ ≤ r ⟺ p ≤ a ( r + 1 : [ N ] ) . (39) \lvert\{i:a_i>p\}\rvert\le r \Longleftrightarrow a_{(N-r:[N])} \le p,\qquad\lvert\{i:a_i<p\}\rvert\le r \Longleftrightarrow p \le a_{(r+1:[N])}. \tag*{(39)} ∣{ i : a i > p }∣ ≤ r ⟺ a ( N − r : [ N ]) ≤ p , ∣{ i : a i < p }∣ ≤ r ⟺ p ≤ a ( r + 1 : [ N ]) . (39) For b 1 , … , b N ∈ R b_1,\ldots,b_N \in\mathbb{R} b 1 , … , b N ∈ R and k ∈ [ N ] k \in[N] k ∈ [ N ] ,
a i ≤ b i for every i ∈ [ N ] ⟹ a ( k : [ N ] ) ≤ b ( k : [ N ] ) . (40) a_i \le b_i\ \text{for every }i\in[N] \Longrightarrow a_{(k:[N])} \le b_{(k:[N])}. \tag*{(40)} a i ≤ b i for every i ∈ [ N ] ⟹ a ( k : [ N ]) ≤ b ( k : [ N ]) . (40) Proof. If a ( N − r : [ N ] ) ≤ p a_{(N-r:[N])} \le p a ( N − r : [ N ]) ≤ p , only the largest r r r values can exceed p p p . If a ( N − r : [ N ] ) > p a_{(N-r:[N])} > p a ( N − r : [ N ]) > p , the largest r + 1 r+1 r + 1 values exceed p p p . This proves the first equivalence. For the second, if p ≤ a ( r + 1 : [ N ] ) p \le a_{(r+1:[N])} p ≤ a ( r + 1 : [ N ]) , only the smallest r r r values can be below p p p ; otherwise, the smallest r + 1 r+1 r + 1 values are below p p p . These statements include ties because violations are strict. For equation (40) , put p : = b ( k : [ N ] ) p := b_{(k:[N])} p := b ( k : [ N ]) . Then
∣ { i : a i > p } ∣ ≤ ∣ { i : b i > p } ∣ ≤ N − k . \lvert\{i:a_i>p\}\rvert\le\lvert\{i:b_i>p\}\rvert\le N-k. ∣{ i : a i > p }∣ ≤ ∣{ i : b i > p }∣ ≤ N − k . Applying equation (39) again gives a ( k : [ N ] ) ≤ p = b ( k : [ N ] ) a_{(k:[N])} \le p = b_{(k:[N])} a ( k : [ N ]) ≤ p = b ( k : [ N ]) .
Lemma 14 (Finite averaging). Let σ 1 , … , σ M \sigma_1,\ldots,\sigma_M σ 1 , … , σ M be measurable transformations preserving a probability law P \mathbb{P} P , where M ≥ 1 M \ge1 M ≥ 1 . For every measurable event A A A ,
P ( A ) = E [ 1 M ∑ j = 1 M 1 { σ j ( ω ) ∈ A } ] . (41) \mathbb{P}(A)=\mathbb{E}\left[\frac{1}{M}\sum_{j=1}^{M}\mathbf{1}\{\sigma_j(\omega)\in A\}\right]. \tag*{(41)} P ( A ) = E [ M 1 j = 1 ∑ M 1 { σ j ( ω ) ∈ A } ] . (41) If the average inside the expectation is at most c c c for every ω \omega ω , then P ( A ) ≤ c \mathbb{P}(A) \le c P ( A ) ≤ c .
Proof. For every j j j , preservation of the law gives E [ 1 { σ j ( ω ) ∈ A } ] = P ( A ) \mathbb{E}[\mathbf{1}\{\sigma_j(\omega)\in A\}]=\mathbb{P}(A) E [ 1 { σ j ( ω ) ∈ A }] = P ( A ) . Average these equalities to prove equation (41) . Taking expectations preserves the bound by c c c .
Lemma 15 (A rank bound). Let K ∼ Q k , h \mathcal{K} \sim\mathbb{Q}_{k,h} K ∼ Q k , h , where k , h ≥ 1 k,h \ge1 k , h ≥ 1 . Write K = { i 1 , … , i k } \mathcal{K}=\{i_1,\ldots,i_k\} K = { i 1 , … , i k } with i 1 < ⋯ < i k i_1<\cdots<i_k i 1 < ⋯ < i k . For an integer 0 ≤ a < k 0\le a<k 0 ≤ a < k , define
J K a : = ∣ { i ∈ [ k + h ] ∖ K : i < i a + 1 } ∣ = i a + 1 − a − 1. \mathcal{J}_{\mathcal{K}}^a:=\left|\{i\in[k+h]\setminus\mathcal{K}:i<i_{a+1}\}\right|=i_{a+1}-a-1. J K a := ∣ { i ∈ [ k + h ] ∖ K : i < i a + 1 } ∣ = i a + 1 − a − 1. Its distribution is
Q k , h ( J K a = j ) = ( a + j a ) ( k + h − a − j − 1 k − a − 1 ) ( k + h k ) , 0 ≤ j ≤ h . (42) \mathbb{Q}_{k,h}\left(\mathcal{J}_{\mathcal{K}}^a=j\right)=\frac{\binom{a+j}{a}\binom{k+h-a-j-1}{k-a-1}}{\binom{k+h}{k}},\qquad0\le j\le h. \tag*{(42)} Q k , h ( J K a = j ) = ( k k + h ) ( a a + j ) ( k − a − 1 k + h − a − j − 1 ) , 0 ≤ j ≤ h . (42) For s > 0 s>0 s > 0 ,
Q k , h ( J K a > h ( a k + s ) ) ≤ exp { − 2 k h s 2 k + h + 2 } . (43) \mathbb{Q}_{k,h}\left(\mathcal{J}_{\mathcal{K}}^a>h\left(\frac{a}{k}+s\right)\right)\le\exp\left\{-\frac{2khs^2}{k+h+2}\right\}. \tag*{(43)} Q k , h ( J K a > h ( k a + s ) ) ≤ exp { − k + h + 2 2 k h s 2 } . (43) If h = 1 h=1 h = 1 , then
Q k , 1 ( J K a = 1 ) = a + 1 k + 1 . (44) \mathbb{Q}_{k,1}\left(\mathcal{J}_{\mathcal{K}}^a=1\right)=\frac{a+1}{k+1}. \tag*{(44)} Q k , 1 ( J K a = 1 ) = k + 1 a + 1 . (44)
Proof. The event J K a = j \mathcal{J}_{\mathcal{K}}^a=j J K a = j places the ( a + 1 ) (a+1) ( a + 1 ) st training index at a + j + 1 a+j+1 a + j + 1 . Choose its a a a predecessors from [ a + j ] [a+j] [ a + j ] and the remaining k − a − 1 k-a-1 k − a − 1 training indices from the k + h − a − j − 1 k+h-a-j-1 k + h − a − j − 1 subsequent positions. Dividing this count by ( k + h k ) \binom{k+h}{k} ( k k + h ) proves equation 42. Put j : = ⌊ h ( a / k + s ) ⌋ j:=\lfloor h(a/k+s)\rfloor j := ⌊ h ( a / k + s )⌋ and define
J : = { J K a > j } . \mathcal{J}:=\{\mathcal{J}_{\mathcal{K}}^a>j\}. J := { J K a > j } .
If j ≥ h j\ge h j ≥ h , then J = ∅ \mathcal{J}=\varnothing J = ∅ , so equation 43 holds. Otherwise, write K c : = [ k + h ] ∖ K \mathcal{K}^{c}:=[k+h]\setminus\mathcal{K} K c := [ k + h ] ∖ K . The definition of J K a \mathcal{J}_{\mathcal{K}}^a J K a gives
J = { J K a > h ( a k + s ) } = { ∣ K ∩ [ a + j + 1 ] ∣ ≤ a } . \mathcal{J}=\left\{\mathcal{J}_{\mathcal{K}}^a>h\left(\frac{a}{k}+s\right)\right\}=\left\{|\mathcal{K}\cap[a+j+1]|\le a\right\}. J = { J K a > h ( k a + s ) } = { ∣ K ∩ [ a + j + 1 ] ∣ ≤ a } .
On the event J \mathcal{J} J ,
∣ K ∩ [ a + j + 1 ] ∣ ≤ a , ∣ K c ∩ [ a + j + 1 ] ∣ = a + j + 1 − ∣ K ∩ [ a + j + 1 ] ∣ ≥ j + 1. |\mathcal{K}\cap[a+j+1]|\le a,\qquad|\mathcal{K}^{c}\cap[a+j+1]|=a+j+1-|\mathcal{K}\cap[a+j+1]|\ge j+1. ∣ K ∩ [ a + j + 1 ] ∣ ≤ a , ∣ K c ∩ [ a + j + 1 ] ∣ = a + j + 1 − ∣ K ∩ [ a + j + 1 ] ∣ ≥ j + 1.
Hence,
∣ K c ∩ [ a + j + 1 ] ∣ h − ∣ K ∩ [ a + j + 1 ] ∣ k ≥ j + 1 h − a k > s . (45) \frac{|\mathcal{K}^{c}\cap[a+j+1]|}{h}-\frac{|\mathcal{K}\cap[a+j+1]|}{k}\ge\frac{j+1}{h}-\frac{a}{k}>s. \tag*{(45)} h ∣ K c ∩ [ a + j + 1 ] ∣ − k ∣ K ∩ [ a + j + 1 ] ∣ ≥ h j + 1 − k a > s . (45)
Since ∣ K ∩ [ a + j + 1 ] ∣ + ∣ K c ∩ [ a + j + 1 ] ∣ = a + j + 1 |\mathcal{K}\cap[a+j+1]|+|\mathcal{K}^{c}\cap[a+j+1]|=a+j+1 ∣ K ∩ [ a + j + 1 ] ∣ + ∣ K c ∩ [ a + j + 1 ] ∣ = a + j + 1 ,
∣ K c ∩ [ a + j + 1 ] ∣ h − ∣ K ∩ [ a + j + 1 ] ∣ k = k + h h ( a + j + 1 k + h − ∣ K ∩ [ a + j + 1 ] ∣ k ) = k + h k ( ∣ K c ∩ [ a + j + 1 ] ∣ h − a + j + 1 k + h ) . (46) \begin{aligned}
\frac{|\mathcal{K}^{c}\cap[a+j+1]|}{h}-\frac{|\mathcal{K}\cap[a+j+1]|}{k}
=\frac{k+h}{h}\left(\frac{a+j+1}{k+h}-\frac{|\mathcal{K}\cap[a+j+1]|}{k}\right) \\
&=\frac{k+h}{k}\left(\frac{|\mathcal{K}^{c}\cap[a+j+1]|}{h}-\frac{a+j+1}{k+h}\right). \tag*{(46)}
\end{aligned} h ∣ K c ∩ [ a + j + 1 ] ∣ − k ∣ K ∩ [ a + j + 1 ] ∣ = h k + h ( k + h a + j + 1 − k ∣ K ∩ [ a + j + 1 ] ∣ ) = k k + h ( h ∣ K c ∩ [ a + j + 1 ] ∣ − k + h a + j + 1 ) . (46)
The population fraction of indices in [ a + j + 1 ] [a+j+1] [ a + j + 1 ] is ( a + j + 1 ) / ( k + h ) (a+j+1)/(k+h) ( a + j + 1 ) / ( k + h ) . By equation 45 and equation 46, on J \mathcal{J} J ,
∣ K ∩ [ a + j + 1 ] ∣ k < a + j + 1 k + h − h k + h s , \frac{|\mathcal{K}\cap[a+j+1]|}{k}<\frac{a+j+1}{k+h}-\frac{h}{k+h}s, k ∣ K ∩ [ a + j + 1 ] ∣ < k + h a + j + 1 − k + h h s ,
∣ K c ∩ [ a + j + 1 ] ∣ h > a + j + 1 k + h + k k + h s . (47) \frac{|\mathcal{K}^{c}\cap[a+j+1]|}{h}>\frac{a+j+1}{k+h}+\frac{k}{k+h}s. \tag*{(47)} h ∣ K c ∩ [ a + j + 1 ] ∣ > k + h a + j + 1 + k + h k s . (47)
Thus the fraction in K \mathcal{K} K is below the population fraction, while the fraction in K c \mathcal{K}^{c} K c is above it. We apply Lemma 11 to the indicators 1 { i ∈ [ a + j + 1 ] } \mathbb{1}\{i \in[a+j+1]\} 1 { i ∈ [ a + j + 1 ]} over the smaller sample: the lower tail for K \mathcal{K} K when k ≤ h k \le h k ≤ h , and the upper tail for K c \mathcal{K}^{c} K c when h < k h < k h < k . In either case, the finite-population correction gives
Q k , h ( J ) ≤ eq. 37 exp { − 2 k h k + h max { k , h } max { k , h } + 1 s 2 } ≤ exp { − 2 k h s 2 k + h + 2 } . (48) \mathbb{Q}_{k,h}(\mathcal{J}) \mathrel{\overset{\text{eq. 37}}{\le}} \exp\left\{-\frac{2kh}{k+h}\frac{\max\{k,h\}}{\max\{k,h\}+1}s^{2}\right\} \le\exp\left\{-\frac{2khs^{2}}{k+h+2}\right\}. \tag*{(48)} Q k , h ( J ) ≤ eq. 37 exp { − k + h 2 k h max { k , h } + 1 max { k , h } s 2 } ≤ exp { − k + h + 2 2 k h s 2 } . (48)
The last inequality uses 2 max { k , h } ≥ k + h 2\max\{k,h\} \ge k+h 2 max { k , h } ≥ k + h . This proves equation (43) . For equation (44) , the single element of K c \mathcal{K}^{c} K c is uniform on [ k + 1 ] [k+1] [ k + 1 ] ; it precedes the ( a + 1 ) (a+1) ( a + 1 ) st smallest element of K \mathcal{K} K exactly when its rank is at most a + 1 a+1 a + 1 .
Remark 16
The expectation in equation (11) is a finite sum using equation (42) .
For κ m = 0 \kappa_m=0 κ m = 0 , δ y ( β ) \delta_y(\beta) δ y ( β ) is the mean of the upper β \beta β fraction of the distribution of W y W_y W y , including fractional mass at its boundary (Rockafellar and Uryasev, 2002, Theorem 10).
Lemma 17 (Balanced prefix differences) Let K ∼ Q n , n \mathcal{K} \sim\mathbb{Q}_{n,n} K ∼ Q n , n and put D K : = n − 1 max 0 ≤ j ≤ 2 n ( ∣ K c ∩ [ j ] ∣ − ∣ K ∩ [ j ] ∣ ) D_{\mathcal{K}} := n^{-1}\max_{0\le j\le2n}(|\mathcal{K}^{c}\cap[j]|-|\mathcal{K}\cap[j]|) D K := n − 1 max 0 ≤ j ≤ 2 n ( ∣ K c ∩ [ j ] ∣ − ∣ K ∩ [ j ] ∣ ) , with [ 0 ] = ∅ [0]=\varnothing [ 0 ] = ∅ . For s > 0 s>0 s > 0 ,
Q n , n ( D K > s ) ≤ exp { − 2 n 2 s 2 2 n + 1 } . (49) \mathbb{Q}_{n,n}(D_{\mathcal{K}}>s)\le\exp\left\{-\frac{2n^{2}s^{2}}{2n+1}\right\}. \tag*{(49)} Q n , n ( D K > s ) ≤ exp { − 2 n + 1 2 n 2 s 2 } . (49)
Proof. We use the reflection formula and logarithmic bound in (Greene and Wellner, 2016, Section 3). The prefix differences form a walk with n n n steps of each sign. For 1 ≤ k ≤ n 1\le k\le n 1 ≤ k ≤ n , reflecting the steps after the first visit to k k k gives
Q n , n ( n D K ≥ k ) = ( 2 n n − k ) ( 2 n n ) = ∏ j = 1 k n − j + 1 n + j ≤ exp { − 2 k 2 2 n + 1 } . (50) \mathbb{Q}_{n,n}(nD_{\mathcal{K}}\ge k)=\frac{\binom{2n}{n-k}}{\binom{2n}{n}}=\prod_{j=1}^{k}\frac{n-j+1}{n+j}\le\exp\left\{-\frac{2k^{2}}{2n+1}\right\}. \tag*{(50)} Q n , n ( n D K ≥ k ) = ( n 2 n ) ( n − k 2 n ) = j = 1 ∏ k n + j n − j + 1 ≤ exp { − 2 n + 1 2 k 2 } . (50)
The inequality follows from log ( ( 1 − x ) / ( 1 + x ) ) ≤ − 2 x \log((1-x)/(1+x))\le-2x log (( 1 − x ) / ( 1 + x )) ≤ − 2 x at x = ( 2 j − 1 ) / ( 2 n + 1 ) x=(2j-1)/(2n+1) x = ( 2 j − 1 ) / ( 2 n + 1 ) and ∑ j = 1 k ( 2 j − 1 ) = k 2 \sum_{j=1}^{k}(2j-1)=k^{2} ∑ j = 1 k ( 2 j − 1 ) = k 2 . Take k = ⌊ n s ⌋ + 1 k=\lfloor ns\rfloor+1 k = ⌊ n s ⌋ + 1 ; if k > n k>n k > n , the event is empty.
Conditional Means and Stability
Lemma 18 (Conditional-mean equivariance) Suppose Assumption 1 holds and S ^ \widehat{S} S is measurable and invariant under permutations of its training sample. Fix y y y with P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_{\star}=y)>0 P ( Y ⋆ = y ) > 0 , and let Π \Pi Π be the group generated by the permutations for P y \mathcal{P}_y P y in that assumption. The one-step conditional means in equation (7) admit versions satisfying, simultaneously for π ∈ Π \pi\in\Pi π ∈ Π , index vectors I I I , and occurrence indices i , j i,j i , j ,
s y , i , j ( π ( D ) ; I , 0 ) = s y , π ( i ) , π ( j ) ( D ; π ( I ) , 0 ) . (51) s_{y,i,j}(\pi(D);I,0)=s_{y,\pi(i),\pi(j)}(D;\pi(I),0). \tag*{(51)} s y , i , j ( π ( D ) ; I , 0 ) = s y , π ( i ) , π ( j ) ( D ; π ( I ) , 0 ) . (51) Here π \pi π acts componentwise on I I I . The training values s y , i , i ( D ; I , 0 ) s_{y,i,i}(D;I,0) s y , i , i ( D ; I , 0 ) and their order statistics are σ ( D I ) \sigma(D_I) σ ( D I ) -measurable.
Proof. Work under P y \mathbb{P}_y P y on the joint sample space of D D D , where π \pi π also denotes the induced map. For a bounded random variable H H H and a σ \sigma σ -algebra H ⊆ σ ( D ) \mathcal{H} \subseteq\sigma(D) H ⊆ σ ( D ) , preservation of P y \mathbb{P}_y P y gives
E y [ H ∣ H ] ∘ π = E y [ H ∘ π ∣ π − 1 H ] . (52) \mathbb{E}_y[H \mid\mathcal{H}] \circ\pi= \mathbb{E}_y[H \circ\pi\mid\pi^{-1}\mathcal{H}]. \tag*{(52)} E y [ H ∣ H ] ∘ π = E y [ H ∘ π ∣ π − 1 H ] . (52)
Choose [ 0 , 1 ] [0,1] [ 0 , 1 ] -valued versions of the one-step conditional means. Since deletion commutes with permutation, replace each version by the average on the left:
1 ∣ Π ∣ ∑ ρ ∈ Π E y [ X t , ρ ( i ) ( S ^ ( D ρ ( I ) − ρ ( j ) ) | D ρ ( I ) − ρ ( j ) , Z t − 1 , ρ ( i ) ) ] ∘ ρ − 1 \frac{1}{|\Pi|} \sum_{\rho\in\Pi} \mathbb{E}_y\left[X_{t,\rho(i)}\left(\widehat{S}\left(D_{\rho(I)}^{-\rho(j)}\right) \,\middle|\, D_{\rho(I)}^{-\rho(j)}, Z_{t-1,\rho(i)}\right)\right] \circ\rho^{-1} ∣Π∣ 1 ρ ∈ Π ∑ E y [ X t , ρ ( i ) ( S ( D ρ ( I ) − ρ ( j ) ) D ρ ( I ) − ρ ( j ) , Z t − 1 , ρ ( i ) ) ] ∘ ρ − 1
= eq. x r e f ‘ 52 ‘ E y [ X t , i ( S ^ ( D I − j ) | D I − j , Z t − 1 , i ) ] . (53) \mathrel{\overset{\text{eq. }{xref}`52`}{=}} \mathbb{E}_y\left[X_{t,i}\left(\widehat{S}\left(D_I^{-j}\right) \,\middle|\, D_I^{-j}, Z_{t-1,i}\right)\right]. \tag*{(53)} = eq. x r e f ‘52‘ E y [ X t , i ( S ( D I − j ) D I − j , Z t − 1 , i ) ] . (53)
Reindexing the sum by ρ ↦ ρ ∘ π \rho\mapsto\rho\circ\pi ρ ↦ ρ ∘ π gives equivariance of these one-step versions. Time averaging and the signed maximum in equation (7) at r = 0 r=0 r = 0 then give equation (51) . For a training occurrence i i i ,
σ ( D I − i , Z t − 1 , i ) ⊆ σ ( D I ) , (54) \sigma\left(D_I^{-i}, Z_{t-1,i}\right) \subseteq\sigma(D_I), \tag*{(54)} σ ( D I − i , Z t − 1 , i ) ⊆ σ ( D I ) , (54)
so the training values and their order statistics are σ ( D I ) \sigma(D_I) σ ( D I ) -measurable.
Lemma 19 (Class-conditional stability failure). Suppose Assumption 4 holds and P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_\star= y) > 0 P ( Y ⋆ = y ) > 0 .
P y , π ( ( E π ( I i n ) , I i n m ) c ) ≤ E P π ( ( E π ( I i n ) , I i n m ) c ) P ( Y ⋆ = y ) ≤ κ m P ( Y ⋆ = y ) . (55) \mathbb{P}_{y,\pi}\left((\mathcal{E}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}^{m})^c\right) \leq\frac{\mathbb{E}_{\mathbb{P}_\pi}\left((\mathcal{E}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}^{m})^c\right)}{\mathbb{P}(Y_\star= y)} \leq\frac{\kappa_m}{\mathbb{P}(Y_\star= y)}. \tag*{(55)} P y , π ( ( E π ( I in ) , I in m ) c ) ≤ P ( Y ⋆ = y ) E P π ( ( E π ( I in ) , I in m ) c ) ≤ P ( Y ⋆ = y ) κ m . (55)
Proof. Conditioning on Y ⋆ = y Y_\star= y Y ⋆ = y and applying Assumption 4 gives the bound.
Lemma 20 (Training-sample averaging). Under the hypotheses and versions of Lemma 18, let π \pi π have the independent uniform law in Assumption 4. For every bounded measurable f f f ,
E y [ f ( D i n , C y ( D ; I i n ) ) ] = E P y , π [ f ( D π ( I i n ) , C y ( D ; π ( I i n ) ) ) ] . (56) \mathbb{E}_y[f(D_{\mathrm{in}}, C_y(D; I_{\mathrm{in}}))] = \mathbb{E}_{\mathbb{P}_{y,\pi}}[f(D_{\pi(I_{\mathrm{in}})}, C_y(D; \pi(I_{\mathrm{in}})))]. \tag*{(56)} E y [ f ( D in , C y ( D ; I in ))] = E P y , π [ f ( D π ( I in ) , C y ( D ; π ( I in )))] . (56)
Proof. Identify trajectories with their occurrence indices, keeping repeated values as distinct occurrences. For each fixed π \pi π , the permuted training sample is
π ( D ) i n = D π ( I i n ) . (57) \pi(D)_{\mathrm{in}} = D_{\pi(I_{\mathrm{in}})}. \tag*{(57)} π ( D ) in = D π ( I in ) . (57)
Assumption 1 gives, under P y \mathbb{P}_y P y ,
π ( D ) = d D . (58) \pi(D) \mathrel{\overset{d}{=}} D. \tag*{(58)} π ( D ) = d D . (58)
By equation (51) and equation (12) ,
C y ( π ( D ) ; I i n ) = ∑ i ∈ I o u t , y 1 { V y , π ( i ) ( D ; π ( I i n ) ) } = C y ( D ; π ( I i n ) ) . (59) C_y(\pi(D); I_{\mathrm{in}}) = \sum_{i \in I_{\mathrm{out},y}} \mathbf{1}\{V_{y,\pi(i)}(D; \pi(I_{\mathrm{in}}))\} = C_y(D; \pi(I_{\mathrm{in}})). \tag*{(59)} C y ( π ( D ) ; I in ) = i ∈ I out , y ∑ 1 { V y , π ( i ) ( D ; π ( I in ))} = C y ( D ; π ( I in )) . (59)
Using equation (58) ,
( D π ( I i n ) , C y ( D ; π ( I i n ) ) ) = eq. x r e f ‘ 59 ‘ ( π ( D ) i n , C y ( π ( D ) ; I i n ) ) (D_{\pi(I_{\mathrm{in}})}, C_y(D; \pi(I_{\mathrm{in}}))) \mathrel{\overset{\text{eq. }{xref}`59`}{=}} (\pi(D)_{\mathrm{in}}, C_y(\pi(D); I_{\mathrm{in}})) ( D π ( I in ) , C y ( D ; π ( I in ))) = eq. x r e f ‘59‘ ( π ( D ) in , C y ( π ( D ) ; I in ))
= d ( D i n , C y ( D ; I i n ) ) . (60) \mathrel{\overset{d}{=}} (D_{\mathrm{in}}, C_y(D; I_{\mathrm{in}})). \tag*{(60)} = d ( D in , C y ( D ; I in )) . (60)
Average equation (60) over π \pi π to obtain equation (56) .
Martingales and Concentration
The following lemmas state standard martingale and concentration results in our notation [14 ] (Waudby-Smith and Ramdas 2024). An ( F t ) (\mathcal{F}_t) ( F t ) -adapted process ( M t ) t ∈ N (M_t)_{t\in\mathbb{N}} ( M t ) t ∈ N is a martingale under P \mathbb{P} P if E ∣ M t ∣ < ∞ \mathbb{E}|M_t| < \infty E ∣ M t ∣ < ∞ for every t t t and E [ M t ∣ F t − 1 ] = M t − 1 \mathbb{E}[M_t \mid\mathcal{F}_{t-1}] = M_{t-1} E [ M t ∣ F t − 1 ] = M t − 1 almost surely for every t ≥ 1 t \ge1 t ≥ 1 . Throughout this subsection, fix a class y y y and work under P y = P ( ⋅ ∣ Y = y ) \mathbb{P}_y = \mathbb{P}(\cdot\mid Y = y) P y = P ( ⋅ ∣ Y = y ) . Let X X X be adapted to F \mathcal{F} F . Use the notation
S t : = ∑ s = 1 t X s , A y , t : = ∑ s = 1 t E y [ X s ∣ F s − 1 ] = t μ t , y X ( Z t ; F ) . (61) S_t := \sum_{s=1}^{t} X_s,\qquad A_{y,t} := \sum_{s=1}^{t} \mathbb{E}_y[X_s \mid\mathcal{F}_{s-1}] = t\mu^X_{t,y}(Z_t;\mathcal{F}). \tag*{(61)} S t := s = 1 ∑ t X s , A y , t := s = 1 ∑ t E y [ X s ∣ F s − 1 ] = t μ t , y X ( Z t ; F ) . (61)
Choose conditional-expectation versions in [ 0 , 1 ] [0,1] [ 0 , 1 ] . All statements involving conditional expectations hold almost surely under this same law.
Lemma 21 (Bernoulli exponential martingale and Ville’s inequality). Let λ ∈ R \lambda\in\mathbb{R} λ ∈ R be F 0 \mathcal{F}_0 F 0 -measurable.
M y , t ( λ ) : = exp { λ S t − ∑ s = 1 t ψ λ ( E y [ X s ∣ F s − 1 ] ) } , M y , 0 ( λ ) = 1 , (62) M_{y,t}(\lambda) := \exp\left\{\lambda S_t-\sum_{s=1}^{t}\psi_\lambda\left(\mathbb{E}_y[X_s \mid\mathcal{F}_{s-1}]\right)\right\},\qquad M_{y,0}(\lambda)=1, \tag*{(62)} M y , t ( λ ) := exp { λ S t − s = 1 ∑ t ψ λ ( E y [ X s ∣ F s − 1 ] ) } , M y , 0 ( λ ) = 1 , (62) is a positive martingale under P y \mathbb{P}_y P y . Any nonnegative supermartingale M M M with M 0 = 1 M_0=1 M 0 = 1 satisfies, for a positive F 0 \mathcal{F}_0 F 0 -measurable a a a and finite T T T ,
P y ( max 0 ≤ t ≤ T M t ≥ a | F 0 ) ≤ a − 1 . (63) \mathbb{P}_y\left(\max_{0\le t\le T} M_t \ge a \,\middle|\, \mathcal{F}_0\right)\le a^{-1}. \tag*{(63)} P y ( 0 ≤ t ≤ T max M t ≥ a F 0 ) ≤ a − 1 . (63) Note that we allow F 0 \mathcal{F}_0 F 0 -measurable λ \lambda λ and a a a in equation 62 and equation (63) .
Proof. Since X s ∈ { 0 , 1 } X_s \in\{0,1\} X s ∈ { 0 , 1 } and λ \lambda λ is F s − 1 \mathcal{F}_{s-1} F s − 1 -measurable,
E y [ e λ X s ∣ F s − 1 ] = 1 + ( e λ − 1 ) E y [ X s ∣ F s − 1 ] = e ψ λ ( E y [ X s ∣ F s − 1 ] ) . \mathbb{E}_y[e^{\lambda X_s}\mid\mathcal{F}_{s-1}]
=1+(e^\lambda-1)\mathbb{E}_y[X_s\mid\mathcal{F}_{s-1}]
=e^{\psi_\lambda(\mathbb{E}_y[X_s\mid\mathcal{F}_{s-1}])}. E y [ e λ X s ∣ F s − 1 ] = 1 + ( e λ − 1 ) E y [ X s ∣ F s − 1 ] = e ψ λ ( E y [ X s ∣ F s − 1 ]) .
Thus equation 62 gives E y [ M y , s ( λ ) ∣ F s − 1 ] = M y , s − 1 ( λ ) \mathbb{E}_y[M_{y,s}(\lambda)\mid\mathcal{F}_{s-1}]=M_{y,s-1}(\lambda) E y [ M y , s ( λ ) ∣ F s − 1 ] = M y , s − 1 ( λ ) and E y M y , s ( λ ) = 1 \mathbb{E}_yM_{y,s}(\lambda)=1 E y M y , s ( λ ) = 1 . For equation (63) , let σ : = inf { t ≥ 0 : M t ≥ a } ∧ T \sigma:=\inf\{t\ge0:M_t\ge a\}\wedge T σ := inf { t ≥ 0 : M t ≥ a } ∧ T . Conditional optional stopping (Ramdas and Wang, 2025, Section 7.4, Fact 7.5) gives
a P y ( max 0 ≤ t ≤ T M t ≥ a | F 0 ) ≤ E y [ M σ ∣ F 0 ] ≤ 1. a\mathbb{P}_y\left(\max_{0\le t\le T}M_t\ge a\,\middle|\,\mathcal{F}_0\right)
\le\mathbb{E}_y[M_\sigma\mid\mathcal{F}_0]\le1. a P y ( 0 ≤ t ≤ T max M t ≥ a F 0 ) ≤ E y [ M σ ∣ F 0 ] ≤ 1.
Lemma 22 (Conditional Bernoulli lower-tail bound). For t ≥ 1 t\ge1 t ≥ 1 and F 0 \mathcal{F}_0 F 0 -measurable 0 < h < p ≤ 1 0<h<p\le1 0 < h < p ≤ 1 ,
P y ( S t < t h , A y , t ≥ t p ∣ F 0 ) ≤ exp { − t D K L ( Ber ( h ) ∥ Ber ( p ) ) } . (64) \mathbb{P}_y(S_t<th,\ A_{y,t}\ge tp\mid\mathcal{F}_0)
\le\exp\{-tD_{\mathrm{KL}}(\operatorname{Ber}(h)\mathbin{\|}\operatorname{Ber}(p))\}. \tag*{(64)} P y ( S t < t h , A y , t ≥ tp ∣ F 0 ) ≤ exp { − t D KL ( Ber ( h ) ∥ Ber ( p ))} . (64) For p = 1 p=1 p = 1 , the bound is zero; for h ≤ 0 h\le0 h ≤ 0 , the event is empty.
Proof For a negative F 0 \mathcal{F}_0 F 0 -measurable z z z , ψ z \psi_z ψ z is decreasing and concave. On { S t < t h , A y , t ≥ t p } \{S_t < th,\ A_{y,t} \ge tp\} { S t < t h , A y , t ≥ tp } , Jensen’s inequality gives
log M y , t ( z ) = z S t − ∑ s = 1 t ψ z ( E y [ X s ∣ F s − 1 ] ) ≥ z S t − t ψ z ( A y , t / t ) > t { z h − ψ z ( p ) } . (65) \log M_{y,t}(z) = zS_t-\sum_{s=1}^{t}\psi_z\left(\mathbb{E}_y[X_s \mid\mathcal{F}_{s-1}]\right)
\ge zS_t-t\psi_z(A_{y,t}/t)>t\{zh-\psi_z(p)\}. \tag*{(65)} log M y , t ( z ) = z S t − s = 1 ∑ t ψ z ( E y [ X s ∣ F s − 1 ] ) ≥ z S t − t ψ z ( A y , t / t ) > t { z h − ψ z ( p )} . (65)
Conditional Markov’s inequality gives
P y ( S t < t h , A y , t ≥ t p ∣ F 0 ) ≤ e − t ( z h − ψ z ( p ) ) E y [ M y , t ( z ) ∣ F 0 ] = e − t ( z h − ψ z ( p ) ) . (66) \mathbb{P}_y(S_t < th,\ A_{y,t} \ge tp \mid\mathcal{F}_0) \le e^{-t(zh-\psi_z(p))}\mathbb{E}_y[M_{y,t}(z)\mid\mathcal{F}_0]
= e^{-t(zh-\psi_z(p))}. \tag*{(66)} P y ( S t < t h , A y , t ≥ tp ∣ F 0 ) ≤ e − t ( z h − ψ z ( p )) E y [ M y , t ( z ) ∣ F 0 ] = e − t ( z h − ψ z ( p )) . (66)
On { p < 1 } \{p < 1\} { p < 1 } , take z = log { h ( 1 − p ) / ( p ( 1 − h ) ) } < 0 z=\log\{h(1-p)/(p(1-h))\}<0 z = log { h ( 1 − p ) / ( p ( 1 − h ))} < 0 and apply equation (31) . On { p = 1 } \{p=1\} { p = 1 } , take z = − n z=-n z = − n ; the bound is e − t n ( 1 − h ) → 0 e^{-tn(1-h)}\to0 e − t n ( 1 − h ) → 0 as n → ∞ n\to\infty n → ∞ . ■
Lemma 23 (Martingale Hoeffding inequality) For a real-valued F 0 \mathcal{F}_0 F 0 -measurable z z z ,
E y [ e z ( X s − E y [ X s ∣ F s − 1 ] ) ∣ F s − 1 ] ≤ e z 2 / 8 . (67) \mathbb{E}_y[e^{z(X_s-\mathbb{E}_y[X_s\mid\mathcal{F}_{s-1}])}\mid\mathcal{F}_{s-1}]\le e^{z^2/8}. \tag*{(67)} E y [ e z ( X s − E y [ X s ∣ F s − 1 ]) ∣ F s − 1 ] ≤ e z 2 /8 . (67) For t ≥ 1 t\ge1 t ≥ 1 and a positive F 0 \mathcal{F}_0 F 0 -measurable u u u ,
P y ( ± ( S t − A y , t ) ≥ u ∣ F 0 ) ≤ e − 2 u 2 / t . (68) \mathbb{P}_y\left(\pm(S_t-A_{y,t})\ge u\mid\mathcal{F}_0\right)\le e^{-2u^2/t}. \tag*{(68)} P y ( ± ( S t − A y , t ) ≥ u ∣ F 0 ) ≤ e − 2 u 2 / t . (68) Note that we allow F 0 \mathcal{F}_0 F 0 -measurable z z z and u u u , with the tail bound equation (68) conditional on F 0 \mathcal{F}_0 F 0 .
Proof Substitute m = E y [ X s ∣ F s − 1 ] m=\mathbb{E}_y[X_s\mid\mathcal{F}_{s-1}] m = E y [ X s ∣ F s − 1 ] in equation (34) to obtain equation (67) . For z = 4 u / t z=4u/t z = 4 u / t , iterating equation (67) ((Ramdas et al., 2023, Section 5.1)) gives
E y [ e ± z ( S t − A y , t ) − t z 2 / 8 ∣ F 0 ] ≤ 1. \mathbb{E}_y[e^{\pm z(S_t-A_{y,t})-tz^2/8}\mid\mathcal{F}_0]\le1. E y [ e ± z ( S t − A y , t ) − t z 2 /8 ∣ F 0 ] ≤ 1. Conditional Markov’s inequality yields
P y ( ± ( S t − A y , t ) ≥ u ∣ F 0 ) ≤ e − z u + t z 2 / 8 = e − 2 u 2 / t . \mathbb{P}_y\left(\pm(S_t-A_{y,t})\ge u\mid\mathcal{F}_0\right)\le e^{-zu+tz^2/8}=e^{-2u^2/t}. P y ( ± ( S t − A y , t ) ≥ u ∣ F 0 ) ≤ e − z u + t z 2 /8 = e − 2 u 2 / t . ■
Intervention Events
Lemma 24 (Conditional intervention bounds) Let X X X be adapted to F \mathcal{F} F , and let H ⊆ F 0 \mathcal{H}\subseteq\mathcal{F}_0 H ⊆ F 0 be a σ \sigma σ -algebra. Let λ > 0 \lambda>0 λ > 0 and p 0 , p 1 , q 0 ∈ [ 0 , 1 ] p_0,p_1,q_0\in[0,1] p 0 , p 1 , q 0 ∈ [ 0 , 1 ] be H \mathcal{H} H -measurable. For α ∈ ( 0 , 1 ) \alpha\in(0,1) α ∈ ( 0 , 1 ) and t ∈ W t\in\mathcal{W} t ∈ W , the following hold almost surely under the corresponding class law:
P 0 ( τ ( λ , q 0 ) < ∞ ∣ H ) ≤ P 0 ( max s ∈ W μ s , 0 X > p 0 ∣ H ) + e 0 ( p 0 ; λ , q 0 , α ) , (69) \mathbb{P}_0(\tau(\lambda,q_0)<\infty\mid\mathcal{H})\le\mathbb{P}_0\left(\max_{s\in\mathcal{W}}\mu^X_{s,0}>p_0\mid\mathcal{H}\right)+e_0(p_0;\lambda,q_0,\alpha), \tag*{(69)} P 0 ( τ ( λ , q 0 ) < ∞ ∣ H ) ≤ P 0 ( s ∈ W max μ s , 0 X > p 0 ∣ H ) + e 0 ( p 0 ; λ , q 0 , α ) , (69) P 1 ( τ ( λ , q 0 ) > t ∣ H ) ≤ P 1 ( μ t , 1 X < p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) . (70) \mathbb{P}_1(\tau(\lambda,q_0)>t\mid\mathcal{H})\le\mathbb{P}_1(\mu^X_{t,1}<p_1\mid\mathcal{H})+e_{1,t}(p_1;\lambda,q_0,\alpha). \tag*{(70)} P 1 ( τ ( λ , q 0 ) > t ∣ H ) ≤ P 1 ( μ t , 1 X < p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) . (70) :::`
Proof. Use equation (61) . For equation (69) , put c : = T 1 [ ψ λ ( p 0 ) − ψ λ ( q 0 ) ] + − T 0 [ ψ λ ( q 0 ) − ψ λ ( p 0 ) ] + c := T_1[\psi_\lambda(p_0)-\psi_\lambda(q_0)]_+ - T_0[\psi_\lambda(q_0)-\psi_\lambda(p_0)]_+ c := T 1 [ ψ λ ( p 0 ) − ψ λ ( q 0 ) ] + − T 0 [ ψ λ ( q 0 ) − ψ λ ( p 0 ) ] + and let
G 0 : = { max s ∈ W 0 ≤ s ≤ T 0 X s , 0 X ≤ p 0 } . (71) G_0 := \left\{\max_{\substack{s\in\mathcal{W}\\0\le s\le T_0}} X^X_{s,0}\le p_0\right\}. \tag*{(71)} G 0 := ⎩ ⎨ ⎧ s ∈ W 0 ≤ s ≤ T 0 max X s , 0 X ≤ p 0 ⎭ ⎬ ⎫ . (71)
For λ > 0 \lambda>0 λ > 0 , ψ λ \psi_\lambda ψ λ is increasing and concave on [ 0 , 1 ] [0,1] [ 0 , 1 ] . Since s [ ψ λ ( p 0 ) − ψ λ ( q 0 ) ] ≤ c s[\psi_\lambda(p_0)-\psi_\lambda(q_0)]\le c s [ ψ λ ( p 0 ) − ψ λ ( q 0 )] ≤ c for s ∈ W s\in\mathcal{W} s ∈ W , on G 0 G_0 G 0 ,
∑ r = 1 s ψ λ ( E 0 [ X r ∣ F r − 1 ] ) ≤ Jensen s ψ λ ( A 0 , s / s ) ≤ eq. 70 s ψ λ ( p 0 ) ≤ s ψ λ ( q 0 ) + c . (72) \sum_{r=1}^{s}\psi_\lambda\left(\mathbb{E}_0[X_r\mid\mathcal{F}_{r-1}]\right)
\overset{\text{Jensen}}{\le}
s\psi_\lambda\left(A_{0,s}/s\right)
\overset{\text{eq. 70}}{\le}
s\psi_\lambda(p_0)\le s\psi_\lambda(q_0)+c. \tag*{(72)} r = 1 ∑ s ψ λ ( E 0 [ X r ∣ F r − 1 ] ) ≤ Jensen s ψ λ ( A 0 , s / s ) ≤ eq. 70 s ψ λ ( p 0 ) ≤ s ψ λ ( q 0 ) + c . (72)
Consequently,
log E s ( λ , q 0 ) − log M 0 , s ( λ ) = eq. 29 λ S s − s ψ λ ( q 0 ) − log M 0 , s ( λ ) = eq. 62 ∑ r = 1 s ψ λ ( E 0 [ X r ∣ F r − 1 ] ) − s ψ λ ( q 0 ) ≤ eq. 71 c . (73) \log E_s(\lambda,q_0)-\log M_{0,s}(\lambda)
\overset{\text{eq. 29}}{=}
\lambda S_s-s\psi_\lambda(q_0)-\log M_{0,s}(\lambda)
\overset{\text{eq. 62}}{=}
\sum_{r=1}^{s}\psi_\lambda\left(\mathbb{E}_0[X_r\mid\mathcal{F}_{r-1}]\right)-s\psi_\lambda(q_0)
\overset{\text{eq. 71}}{\le} c. \tag*{(73)} log E s ( λ , q 0 ) − log M 0 , s ( λ ) = eq. 29 λ S s − s ψ λ ( q 0 ) − log M 0 , s ( λ ) = eq. 62 r = 1 ∑ s ψ λ ( E 0 [ X r ∣ F r − 1 ] ) − s ψ λ ( q 0 ) ≤ eq. 71 c . (73)
The definition equation (2) gives { τ ( λ , q 0 ) < ∞ } ⊆ G 0 c ∪ { max 0 ≤ s ≤ T 1 M 0 , s ( λ ) ≥ e − c / α } \{\tau(\lambda,q_0)<\infty\}\subseteq G_0^c\cup\{\max_{0\le s\le T_1}M_{0,s}(\lambda)\ge e^{-c/\alpha}\} { τ ( λ , q 0 ) < ∞ } ⊆ G 0 c ∪ { max 0 ≤ s ≤ T 1 M 0 , s ( λ ) ≥ e − c / α } . The tower property and H \mathcal{H} H -measurability of c c c yield
P 0 ( τ ( λ , q 0 ) < ∞ ∣ H ) ≤ P 0 ( G 0 c ∣ H ) + E 0 [ P 0 ( max 0 ≤ s ≤ T 1 M 0 , s ( λ ) ≥ e − c / α ∣ F 0 ) | H ] \mathbb{P}_0(\tau(\lambda,q_0)<\infty\mid\mathcal{H})
\le\mathbb{P}_0(G_0^c\mid\mathcal{H})+\mathbb{E}_0\left[\mathbb{P}_0\left(\left.\max_{0\le s\le T_1}M_{0,s}(\lambda)\ge e^{-c/\alpha}\right|\mathcal{F}_0\right)\middle|\mathcal{H}\right] P 0 ( τ ( λ , q 0 ) < ∞ ∣ H ) ≤ P 0 ( G 0 c ∣ H ) + E 0 [ P 0 ( 0 ≤ s ≤ T 1 max M 0 , s ( λ ) ≥ e − c / α F 0 ) H ]
≤ eq. 63 P 0 ( G 0 c ∣ H ) + E 0 [ min { 1 , α e c } ∣ H ] ≤ P 0 ( G 0 c ∣ H ) + α e c = eq. 5 P 0 ( G 0 c ∣ H ) + e 0 ( p 0 ; λ , q 0 , α ) . \overset{\text{eq. 63}}{\le}
\mathbb{P}_0(G_0^c\mid\mathcal{H})+\mathbb{E}_0[\min\{1,\alpha e^c\}\mid\mathcal{H}]
\le\mathbb{P}_0(G_0^c\mid\mathcal{H})+\alpha e^c
\overset{\text{eq. 5}}{=}
\mathbb{P}_0(G_0^c\mid\mathcal{H})+e_0(p_0;\lambda,q_0,\alpha). ≤ eq. 63 P 0 ( G 0 c ∣ H ) + E 0 [ min { 1 , α e c } ∣ H ] ≤ P 0 ( G 0 c ∣ H ) + α e c = eq. 5 P 0 ( G 0 c ∣ H ) + e 0 ( p 0 ; λ , q 0 , α ) .
For equation (70) , put h : = λ − 1 { ψ λ ( q 0 ) + a t ( α ) 2 / 2 } h:=\lambda^{-1}\{\psi_\lambda(q_0)+a_t(\alpha)^2/2\} h := λ − 1 { ψ λ ( q 0 ) + a t ( α ) 2 /2 } . On { h ≥ p 1 } \{h\ge p_1\} { h ≥ p 1 } , e 1 , t ( p 1 ; λ , q 0 , α ) = 1 e_{1,t}(p_1;\lambda,q_0,\alpha)=1 e 1 , t ( p 1 ; λ , q 0 , α ) = 1 and the bound is immediate. On { h < p 1 } \{h<p_1\} { h < p 1 } , 0 < h < p 1 ≤ 1 0<h<p_1\le1 0 < h < p 1 ≤ 1 and equation (5) gives e 1 , t ( p 1 ; λ , q 0 , α ) = exp { − t D K L ( Ber ( h ) ∥ Ber ( p 1 ) ) } e_{1,t}(p_1;\lambda,q_0,\alpha)=\exp\{-tD_{\mathrm{KL}}(\operatorname{Ber}(h)\Vert\operatorname{Ber}(p_1))\} e 1 , t ( p 1 ; λ , q 0 , α ) = exp { − t D KL ( Ber ( h ) ∥ Ber ( p 1 ))} . By equation (29) ,
{ τ ( λ , q 0 ) > t , A 1 , t ≥ t p 1 } ⊆ { S t < t h , A 1 , t ≥ t p 1 } . \{\tau(\lambda,q_0)>t,\ A_{1,t}\ge tp_1\}\subseteq\{S_t<th,\ A_{1,t}\ge tp_1\}. { τ ( λ , q 0 ) > t , A 1 , t ≥ t p 1 } ⊆ { S t < t h , A 1 , t ≥ t p 1 } .
The tower property and H \mathcal{H} H -measurability of h , p 1 h,p_1 h , p 1 give
P 1 ( τ ( λ , q 0 ) > t , A 1 , t ≥ t p 1 ∣ H ) ≤ E 1 [ P 1 ( S t < t h , A 1 , t ≥ t p 1 ∣ F 0 ) ∣ H ] ≤ eq. 64 E 1 [ e 1 , t ( p 1 ; λ , q 0 , α ) ∣ H ] = e 1 , t ( p 1 ; λ , q 0 , α ) . (74) \mathbb{P}_1(\tau(\lambda,q_0)>t,\ A_{1,t}\ge tp_1\mid\mathcal{H})
\le\mathbb{E}_1\left[\mathbb{P}_1(S_t<th,\ A_{1,t}\ge tp_1\mid\mathcal{F}_0)\mid\mathcal{H}\right]
\overset{\text{eq. 64}}{\le}
\mathbb{E}_1[e_{1,t}(p_1;\lambda,q_0,\alpha)\mid\mathcal{H}]
=e_{1,t}(p_1;\lambda,q_0,\alpha). \tag*{(74)} P 1 ( τ ( λ , q 0 ) > t , A 1 , t ≥ t p 1 ∣ H ) ≤ E 1 [ P 1 ( S t < t h , A 1 , t ≥ t p 1 ∣ F 0 ) ∣ H ] ≤ eq. 64 E 1 [ e 1 , t ( p 1 ; λ , q 0 , α ) ∣ H ] = e 1 , t ( p 1 ; λ , q 0 , α ) . (74)
Thus
P 1 ( τ ( λ , q 0 ) > t ∣ H ) ≤ eq. 73 P 1 ( A 1 , t < t p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) = eq. 61 P 1 ( μ t , 1 X < p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) . \mathbb{P}_1(\tau(\lambda,q_0)>t\mid\mathcal{H})
\overset{\text{eq. 73}}{\le}
\mathbb{P}_1(A_{1,t}<tp_1\mid\mathcal{H})+e_{1,t}(p_1;\lambda,q_0,\alpha)
\overset{\text{eq. 61}}{=}
\mathbb{P}_1(\mu^X_{t,1}<p_1\mid\mathcal{H})+e_{1,t}(p_1;\lambda,q_0,\alpha). P 1 ( τ ( λ , q 0 ) > t ∣ H ) ≤ eq. 73 P 1 ( A 1 , t < t p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) = eq. 61 P 1 ( μ t , 1 X < p 1 ∣ H ) + e 1 , t ( p 1 ; λ , q 0 , α ) .
For every binary trajectory,
0 ≤ U ^ X ( Z ∞ ) ≤ 1 , 0 ≤ L ^ X ( Z ∞ ) ≤ 1. (75) 0 \le\widehat{U}^{X}(Z_{\infty}) \le1,\qquad0 \le\widehat{L}^{X}(Z_{\infty}) \le1. \tag*{(75)} 0 ≤ U X ( Z ∞ ) ≤ 1 , 0 ≤ L X ( Z ∞ ) ≤ 1. (75)
Moreover, for every t ∈ W t \in\mathcal{W} t ∈ W ,
L ^ X ( Z ∞ ) ≤ μ ^ t X ≤ U ^ X ( Z ∞ ) . (76) \widehat{L}^{X}(Z_{\infty}) \le\widehat{\mu}^{X}_{t} \le\widehat{U}^{X}(Z_{\infty}). \tag*{(76)} L X ( Z ∞ ) ≤ μ t X ≤ U X ( Z ∞ ) . (76)
These bounds follow because each μ ^ t X \widehat{\mu}^{X}_{t} μ t X is an average of binary values and U ^ X \widehat{U}^{X} U X , L ^ X \widehat{L}^{X} L X are their temporal extrema.
Write S t , ⋆ : = ∑ s = 1 t X s , ⋆ ( S ^ ( D i n ) ) S_{t,\star} := \sum_{s=1}^{t} X_{s,\star}(\widehat{S}(\mathcal{D}_{\mathrm{in}})) S t , ⋆ := ∑ s = 1 t X s , ⋆ ( S ( D in )) and B 0 : = { Δ ^ ( D i n ) > 0 } \mathcal{B}_{0} := \{\widehat{\Delta}(\mathcal{D}_{\mathrm{in}}) > 0\} B 0 := { Δ ( D in ) > 0 } .
Proof of Proposition 2
Proof For part (1), suppose U ^ X ≤ p 0 \widehat{U}^{X}\le p_{0} U X ≤ p 0 . For every t ∈ W t\in\mathcal{W} t ∈ W ,
log E t ( λ , p 0 ) ≤ eq. 28 t λ ( μ ^ t X − p 0 ) ≤ eq. 75 t λ ( U ^ X − p 0 ) ≤ 0 < log 1 α . (78) \log E_{t}(\lambda,p_{0}) \underset{\text{eq. }28}{\le} t\lambda(\widehat{\mu}^{X}_{t}-p_{0}) \underset{\text{eq. }75}{\le} t\lambda(\widehat{U}^{X}-p_{0})\le0<\log\frac{1}{\alpha}. \tag*{(78)} log E t ( λ , p 0 ) eq. 28 ≤ t λ ( μ t X − p 0 ) eq. 75 ≤ t λ ( U X − p 0 ) ≤ 0 < log α 1 . (78)
Thus equation (2) gives τ ( λ , p 0 ) = ∞ \tau(\lambda,p_{0})=\infty τ ( λ , p 0 ) = ∞ .
Now suppose L ^ X ≥ p 0 + ( v ( p 0 ) λ + λ − 1 a T 1 ( α ) 2 ) / 2 \widehat{L}^{X}\ge p_{0}+(v(p_{0})\lambda+\lambda^{-1}a_{T_{1}}(\alpha)^{2})/2 L X ≥ p 0 + ( v ( p 0 ) λ + λ − 1 a T 1 ( α ) 2 ) /2 . Then
log E T 1 ( λ , p 0 ) ≥ eq. 28 T 1 { λ ( μ ^ T 1 X − p 0 ) − ( v ( p 0 ) λ 2 ) / 2 } ≥ eq. 75 T 1 { λ ( L ^ X − p 0 ) − ( v ( p 0 ) λ 2 ) / 2 } ≥ T 1 a T 1 ( α ) 2 / 2 = log 1 α . (79) \begin{aligned}
\log E_{T_{1}}(\lambda,p_{0}) &\underset{\text{eq. }28}{\ge} T_{1}\{\lambda(\widehat{\mu}^{X}_{T_{1}}-p_{0})-(v(p_{0})\lambda^{2})/2\}\\
&\underset{\text{eq. }75}{\ge} T_{1}\{\lambda(\widehat{L}^{X}-p_{0})-(v(p_{0})\lambda^{2})/2\}\\
&\ge T_{1}a_{T_{1}}(\alpha)^{2}/2=\log\frac{1}{\alpha}. \tag*{(79)}
\end{aligned} log E T 1 ( λ , p 0 ) eq. 28 ≥ T 1 { λ ( μ T 1 X − p 0 ) − ( v ( p 0 ) λ 2 ) /2 } eq. 75 ≥ T 1 { λ ( L X − p 0 ) − ( v ( p 0 ) λ 2 ) /2 } ≥ T 1 a T 1 ( α ) 2 /2 = log α 1 . (79)
Since T 1 ∈ W T_{1}\in\mathcal{W} T 1 ∈ W , equation (2) gives τ ( λ , p 0 ) ≤ T 1 \tau(\lambda,p_{0})\le T_{1} τ ( λ , p 0 ) ≤ T 1 .
For part (2), use S t S_{t} S t and A y , t A_{y,t} A y , t from equation (61) with the stated filtration. For F 0 \mathcal{F}_{0} F 0 -measurable z z z , put
N t ( z ) : = exp { z ( S t − A y , t ) − t z 2 / 8 } , N 0 ( z ) = 1 , (80) N_{t}(z):=\exp\{z(S_{t}-A_{y,t})-tz^{2}/8\},\qquad N_{0}(z)=1, \tag*{(80)} N t ( z ) := exp { z ( S t − A y , t ) − t z 2 /8 } , N 0 ( z ) = 1 , (80)
so 0 < N t ( z ) ≤ exp { t ( ∣ z ∣ − z 2 / 8 ) } ≤ e 2 t 0<N_{t}(z)\le\exp\{t(|z|-z^{2}/8)\}\le e^{2t} 0 < N t ( z ) ≤ exp { t ( ∣ z ∣ − z 2 /8 )} ≤ e 2 t . By equation (61) ,
E y [ N t ( z ) ∣ F t − 1 ] = N t − 1 ( z ) e − z 2 / 8 E y [ e z ( X t − E y [ X t ∣ F t − 1 ] ) ∣ F t − 1 ] ≤ eq. 66 N t − 1 ( z ) . (81) \mathbb{E}_{y}[N_{t}(z)\mid\mathcal{F}_{t-1}]=N_{t-1}(z)e^{-z^{2}/8}\mathbb{E}_{y}[e^{z(X_{t}-\mathbb{E}_{y}[X_{t}\mid\mathcal{F}_{t-1}])}\mid\mathcal{F}_{t-1}]
\underset{\text{eq. }66}{\le}N_{t-1}(z). \tag*{(81)} E y [ N t ( z ) ∣ F t − 1 ] = N t − 1 ( z ) e − z 2 /8 E y [ e z ( X t − E y [ X t ∣ F t − 1 ]) ∣ F t − 1 ] eq. 66 ≤ N t − 1 ( z ) . (81)
For a positive, F 0 \mathcal{F}_0 F 0 -measurable a a a and either fixed sign, if ± ( μ ^ t X − μ t , y X ) > ( 1 + T 0 / t ) a / 2 \pm(\widehat{\mu}^{X}_t-\mu^{X}_{t,y})>(1+T_0/t)a/2 ± ( μ t X − μ t , y X ) > ( 1 + T 0 / t ) a /2 at some t ∈ W t\in\mathcal{W} t ∈ W , then
N t ( ± 4 a ) > exp { 2 ( t + T 0 ) a 2 − 2 t a 2 } = e 2 T 0 a 2 . N_t(\pm4a)>\exp\{2(t+T_0)a^2-2ta^2\}=e^{2T_0a^2}. N t ( ± 4 a ) > exp { 2 ( t + T 0 ) a 2 − 2 t a 2 } = e 2 T 0 a 2 .
Applying equation 63 gives
P y ( ∃ t ∈ W : ± ( μ ^ t X − μ t , y X ) > ( 1 + T 0 / t ) a / 2 ∣ F 0 ) ≤ e − 2 T 0 a 2 . (82) \mathbb{P}_y\left(\exists t\in\mathcal{W}:\pm(\widehat{\mu}^{X}_t-\mu^{X}_{t,y})>(1+T_0/t)a/2\mid\mathcal{F}_0\right)\le e^{-2T_0a^2}. \tag*{(82)} P y ( ∃ t ∈ W : ± ( μ t X − μ t , y X ) > ( 1 + T 0 / t ) a /2 ∣ F 0 ) ≤ e − 2 T 0 a 2 . (82)
For each fixed t t t , equation 67 gives
P y ( ± ( μ ^ t X − μ t , y X ) > a ∣ F 0 ) ≤ e − 2 t a 2 . (83) \mathbb{P}_y\left(\pm(\widehat{\mu}^{X}_t-\mu^{X}_{t,y})>a\mid\mathcal{F}_0\right)\le e^{-2ta^2}. \tag*{(83)} P y ( ± ( μ t X − μ t , y X ) > a ∣ F 0 ) ≤ e − 2 t a 2 . (83)
Use a = a T 0 ( β / 2 ) / 2 a=a_{T_0}(\beta/2)/2 a = a T 0 ( β /2 ) /2 in equation 81 and a = a t ( β / ( 2 ∣ W ∣ ) ) / 2 a=a_t(\beta/(2|\mathcal{W}|))/2 a = a t ( β / ( 2∣ W ∣ )) /2 in equation 82. Exceeding their minimum requires exceeding at least one of them, so a conditional union bound gives
P y ( ∃ t ∈ W : ± ( μ ^ t X − μ t , y X ) > r t ( β ) ∣ F 0 ) ≤ e q . 81 β 2 + ∑ t ∈ W P y ( ± ( μ ^ t X − μ t , y X ) > a t ( β / ( 2 ∣ W ∣ ) ) 2 ∣ F 0 ) ≤ e q . 82 β 2 + ∑ t ∈ W β 2 ∣ W ∣ = β . \begin{aligned}
\mathbb{P}_y\left(\exists t\in\mathcal{W}:\pm(\widehat{\mu}^{X}_t-\mu^{X}_{t,y})>r_t(\beta)\mid\mathcal{F}_0\right)
&\mathrel{\overset{\mathrm{eq.}\ 81}{\leq}} \frac{\beta}{2}+\sum_{t\in\mathcal{W}}\mathbb{P}_y\left(\pm(\widehat{\mu}^{X}_t-\mu^{X}_{t,y})>\frac{a_t(\beta/(2|\mathcal{W}|))}{2}\mid\mathcal{F}_0\right)\\
&\mathrel{\overset{\mathrm{eq.}\ 82}{\leq}} \frac{\beta}{2}+\sum_{t\in\mathcal{W}}\frac{\beta}{2|\mathcal{W}|}=\beta.
\end{aligned} P y ( ∃ t ∈ W : ± ( μ t X − μ t , y X ) > r t ( β ) ∣ F 0 ) ≤ eq. 81 2 β + t ∈ W ∑ P y ( ± ( μ t X − μ t , y X ) > 2 a t ( β / ( 2∣ W ∣ )) ∣ F 0 ) ≤ eq. 82 2 β + t ∈ W ∑ 2∣ W ∣ β = β .
Proof of Proposition 3
Proof Take H \mathcal{H} H to be the trivial σ \sigma σ -algebra in Lemma 24. For part (1),
P 0 ( τ ( λ , q 0 ) < ∞ ) ≤ e q . 68 P 0 ( max s ∈ W μ s , 0 X > p 0 ) + e 0 ( p 0 ; λ , q 0 , α ) ≤ ϵ 0 + e 0 ( p 0 ; λ , q 0 , α ) . (84) \mathbb{P}_0(\tau(\lambda,q_0)<\infty)\mathrel{\overset{\mathrm{eq.}\ 68}{\leq}}\mathbb{P}_0\left(\max_{s\in\mathcal{W}}\mu^{X}_{s,0}>p_0\right)+e_0(p_0;\lambda,q_0,\alpha)
\leq\epsilon_0+e_0(p_0;\lambda,q_0,\alpha). \tag*{(84)} P 0 ( τ ( λ , q 0 ) < ∞ ) ≤ eq. 68 P 0 ( s ∈ W max μ s , 0 X > p 0 ) + e 0 ( p 0 ; λ , q 0 , α ) ≤ ϵ 0 + e 0 ( p 0 ; λ , q 0 , α ) . (84)
For part (2), let
G 1 : = { min s ∈ W μ s , 1 X ≥ p 1 } , P 1 ( G 1 c ) ≤ ϵ 1 . (85) G_1:=\left\{\min_{s\in\mathcal{W}}\mu^{X}_{s,1}\geq p_1\right\},\qquad\mathbb{P}_1(G_1^{c})\leq\epsilon_1. \tag*{(85)} G 1 := { s ∈ W min μ s , 1 X ≥ p 1 } , P 1 ( G 1 c ) ≤ ϵ 1 . (85)
P 1 ( τ ( λ , q 0 ) > t ) ≤ e q . 69 P 1 ( μ t , 1 X < p 1 ) + e 1 , t ( p 1 ; λ , q 0 , α ) ≤ e q . 84 P 1 ( G 1 c ) + e 1 , t ( p 1 ; λ , q 0 , α ) ≤ ϵ 1 + e 1 , t ( p 1 ; λ , q 0 , α ) . (86) \begin{aligned}
\mathbb{P}_1(\tau(\lambda,q_0)>t)
&\mathrel{\overset{\mathrm{eq.}\ 69}{\leq}}\mathbb{P}_1(\mu^{X}_{t,1}<p_1)+e_{1,t}(p_1;\lambda,q_0,\alpha)\\
&\mathrel{\overset{\mathrm{eq.}\ 84}{\leq}}\mathbb{P}_1(G_1^c)+e_{1,t}(p_1;\lambda,q_0,\alpha)\\
&\leq\epsilon_1+e_{1,t}(p_1;\lambda,q_0,\alpha). \tag*{(86)}
\end{aligned} P 1 ( τ ( λ , q 0 ) > t ) ≤ eq. 69 P 1 ( μ t , 1 X < p 1 ) + e 1 , t ( p 1 ; λ , q 0 , α ) ≤ eq. 84 P 1 ( G 1 c ) + e 1 , t ( p 1 ; λ , q 0 , α ) ≤ ϵ 1 + e 1 , t ( p 1 ; λ , q 0 , α ) . (86)
Proof of Theorem 5
The proof has four steps:
Use exchangeability to express the conditional error on the next trajectory as the conditional mean of the extension error. Each extension indicator has the same conditional mean, so this step does not require conditional independence.
On the pairwise stability event, compare the values after a training exchange with those at D i n D_{\mathrm{in}} D in . Order the class-y y y trajectories by decreasing S y , i , i ( D ; I i n ) S_{y,i,i}(D;I_{\mathrm{in}}) S y , i , i ( D ; I in ) and use Lemma 15 and finite averaging to control the tail of the extension error. For balanced extensions, count training and extension exceptions under their shared budget and control all prefixes.
Apply the positive-part variational formula and conditional Jensen’s inequality, accounting for stability failure, to prove item (3). The exact rank law includes the single-extension case; tail integration gives a closed-form upper bound.
Use Proposition 2 (2) to bound the training conditional means with leave-one-out observed averages. Transfer their order statistics to the next trajectory and apply Proposition 3 .
For each y y y , work under P y \mathbb{P}_y P y on the joint sample space of D D D . Use the conditional-mean versions in Lemma 18 and the joint law P y , π \mathbb{P}_{y,\pi} P y , π .
Conditional Error
Lemma 26 (Conditional error) For each y y y , almost surely under P y \mathbb{P}_y P y ,
P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) = E y [ C y ( D ; I i n ) m y ∣ D i n ] . (87) \mathbb{P}_y\left(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}\right)
=
\mathbb{E}_y\left[\left.\frac{C_y(D;I_{\mathrm{in}})}{m_y}\right|D_{\mathrm{in}}\right]. \tag*{(87)} P y ( V y , ⋆ ( D ; I in ) ∣ D in ) = E y [ m y C y ( D ; I in ) D in ] . (87)
Proof For i ∈ I o u t , y i\in I_{\mathrm{out},y} i ∈ I out , y , let π \pi π exchange i i i and ⋆ \star ⋆ , so π ( I i n ) = I i n \pi(I_{\mathrm{in}})=I_{\mathrm{in}} π ( I in ) = I in . Assumption 1 gives, under P y \mathbb{P}_y P y ,
( D i n , ω i ) = d ( D i n , ω ⋆ ) . (88) (D_{\mathrm{in}},\omega_i)\mathrel{\overset{d}{=}}(D_{\mathrm{in}},\omega_\star). \tag*{(88)} ( D in , ω i ) = d ( D in , ω ⋆ ) . (88)
Since S y , i , i ( D ; I i n ) S_{y,i,i}(D;I_{\mathrm{in}}) S y , i , i ( D ; I in ) is σ ( D i n , ω i ) \sigma(D_{\mathrm{in}},\omega_i) σ ( D in , ω i ) -measurable, equation 87 gives
( D i n , S y , i , i ( D ; I i n ) ) = d ( D i n , S y , i , i ( π ( D ) ; I i n ) ) = e q . 51 ( D i n , S y , ⋆ , ⋆ ( D ; I i n ) ) . (89) (D_{\mathrm{in}},S_{y,i,i}(D;I_{\mathrm{in}}))
\mathrel{\overset{d}{=}}
(D_{\mathrm{in}},S_{y,i,i}(\pi(D);I_{\mathrm{in}}))
\mathrel{\overset{\mathrm{eq.\ }51}{=}}
(D_{\mathrm{in}},S_{y,\star,\star}(D;I_{\mathrm{in}})). \tag*{(89)} ( D in , S y , i , i ( D ; I in )) = d ( D in , S y , i , i ( π ( D ) ; I in )) = eq. 51 ( D in , S y , ⋆ , ⋆ ( D ; I in )) . (89)
The training order statistic is σ ( D i n ) \sigma(D_{\mathrm{in}}) σ ( D in ) -measurable, so
E y [ C y ( D ; I i n ) m y ∣ D i n ] = e q . 12 E y [ 1 m y ∑ i ∈ I o u t , y 1 { V y , i ( D ; I i n ) } ∣ D i n ] = 1 m y ∑ i ∈ I o u t , y P y ( V y , i ( D ; I i n ) ∣ D i n ) = e q . 88 1 m y ∑ i ∈ I o u t , y P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) = P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) . \begin{aligned}
\mathbb{E}_y\left[\left.\frac{C_y(D;I_{\mathrm{in}})}{m_y}\right|D_{\mathrm{in}}\right]
&\mathrel{\overset{\mathrm{eq.\ }12}{=}}
\mathbb{E}_y\left[\left.\frac{1}{m_y}\sum_{i\in I_{\mathrm{out},y}}\mathbf{1}\{\mathcal{V}_{y,i}(D;I_{\mathrm{in}})\}\right|D_{\mathrm{in}}\right] \\
&=
\frac{1}{m_y}\sum_{i\in I_{\mathrm{out},y}}
\mathbb{P}_y(\mathcal{V}_{y,i}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}) \\
&\mathrel{\overset{\mathrm{eq.\ }88}{=}}
\frac{1}{m_y}\sum_{i\in I_{\mathrm{out},y}}
\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}) \\
&=
\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}).
\end{aligned} E y [ m y C y ( D ; I in ) D in ] = eq. 12 E y m y 1 i ∈ I out , y ∑ 1 { V y , i ( D ; I in )} D in = m y 1 i ∈ I out , y ∑ P y ( V y , i ( D ; I in ) ∣ D in ) = eq. 88 m y 1 i ∈ I out , y ∑ P y ( V y , ⋆ ( D ; I in ) ∣ D in ) = P y ( V y , ⋆ ( D ; I in ) ∣ D in ) .
■
Extension Error under Stability
Lemma 27 (Extension error under stability). For each y y y and s > 0 s > 0 s > 0 ,
P y ( C y ( D ; I i n ) m y > ϵ y + θ y ( n y + m y ) 2 n y m y + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + κ m P ( Y ⋆ = y ) . (90) \mathbb{P}_y\left(\frac{C_y(D;I_{\mathrm{in}})}{m_y} > \epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_y m_y}+s\right) \le e^{-2n_y m_y s^2/(n_y+m_y+2)}+\frac{\kappa_m}{\mathbb{P}(Y_\star=y)}. \tag*{(90)} P y ( m y C y ( D ; I in ) > ϵ y + θ y n y m y ( n y + m y ) 2 + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + P ( Y ⋆ = y ) κ m . (90)
The proof has three steps:
Use finite exchangeability to average over training subsets in both classes while fixing the complete sample.
Order the class-y y y trajectories by decreasing S y , i , i ( D ; I i n ) S_{y,i,i}(D;I_{\mathrm{in}}) S y , i , i ( D ; I in ) and compare each array with the values at D i n D_{\mathrm{in}} D in . Stability and the training rank budget then bound the future error count by J K a J^a_{K} J K a from Lemma 15 plus the number of exceptional trajectories, even though the fitted threshold depends on the training subset.
Apply the tail bound for J K a J^a_{K} J K a and average over the complete sample, adding the average stability failure probability.
We use equation (56) to average over training samples.
Stability and Rank Domination
Without loss of generality, we can again write D = ( 1 , … , n + m + 1 ) D=(1,\ldots,n+m+1) D = ( 1 , … , n + m + 1 ) using occurrence labels. Fix this complete sample. For this fixed-sample calculation, number the class-y y y training and extension occurrences as 1 , … , n y + m y 1,\ldots,n_y+m_y 1 , … , n y + m y in decreasing order of their values at the fixed reference training sample D i n D_{\mathrm{in}} D in :
S y , 1 , 1 ( D ; I i n ) ≥ ⋯ ≥ S y , n y + m y , n y + m y ( D ; I i n ) . (91) S_{y,1,1}(D;I_{\mathrm{in}})\ge\cdots\ge S_{y,n_y+m_y,n_y+m_y}(D;I_{\mathrm{in}}). \tag*{(91)} S y , 1 , 1 ( D ; I in ) ≥ ⋯ ≥ S y , n y + m y , n y + m y ( D ; I in ) . (91)
Break ties by original indices. Carry I i n I_{\mathrm{in}} I in and the class index sets along with this relabeling: D I i n = D i n D_{I_{\mathrm{in}}}=D_{\mathrm{in}} D I in = D in still denotes the original training trajectories, and D π ( I i n ) D_{\pi(I_{\mathrm{in}})} D π ( I in ) denotes their images under π \pi π . Uniform averaging over π \pi π is unchanged. The class-y y y training indices after permutation are
K π : = π ( I i n , y ) = { i 1 , … , i n y } , 1 ≤ i 1 < ⋯ < i n y ≤ n y + m y , J K π a : = i a + 1 − a − 1 , 0 ≤ a < n y . (92) \begin{aligned}
K_\pi&:=\pi(I_{\mathrm{in},y})=\{i_1,\ldots,i_{n_y}\},\quad1\le i_1<\cdots<i_{n_y}\le n_y+m_y,\\
J^a_{K_\pi}&:=i_{a+1}-a-1,\quad0\le a<n_y. \tag*{(92)}
\end{aligned} K π J K π a := π ( I in , y ) = { i 1 , … , i n y } , 1 ≤ i 1 < ⋯ < i n y ≤ n y + m y , := i a + 1 − a − 1 , 0 ≤ a < n y . (92)
The corresponding extension indices are [ n y + m y ] ∖ K π [n_y+m_y]\setminus K_\pi [ n y + m y ] ∖ K π , so J K π a J^a_{K_\pi} J K π a counts those preceding the ( a + 1 ) (a+1) ( a + 1 ) st training occurrence. For each permutation of the other class, each n y n_y n y -subset of ranks arises from n y ! m y ! n_y!m_y! n y ! m y ! class-y y y permutations. Thus, for K ⊆ [ n y + m y ] K\subseteq[n_y+m_y] K ⊆ [ n y + m y ] with ∣ K ∣ = n y |K|=n_y ∣ K ∣ = n y ,
Q π ( K π = K ) = n y ! m y ! ( n y + m y ) ! = ( n y + m y n y ) − 1 . (93) \mathbb{Q}_\pi(K_\pi=K)=\frac{n_y!m_y!}{(n_y+m_y)!}=\binom{n_y+m_y}{n_y}^{-1}. \tag*{(93)} Q π ( K π = K ) = ( n y + m y )! n y ! m y ! = ( n y n y + m y ) − 1 . (93)
Lemma 15 therefore applies. The fitted level ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) (S_{y,i,i}(D;\pi(I_{\mathrm{in}})))_{(k_y:K_\pi)} ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) may still depend on π \pi π .
Lemma 28 (Rank domination under stability). If ⌊ ( n y + m y ) θ y ⌋ < k y \lfloor(n_y+m_y)\theta_y\rfloor<k_y ⌊( n y + m y ) θ y ⌋ < k y , then for every π \pi π ,
C y ( D ; π ( I i n ) ) ≤ J K π n y − k y + ⌊ ( n y + m y ) θ y ⌋ + ⌊ ( n y + m y ) θ y ⌋ on E π ( I i n ) , I i n m . (94) C_y(D;\pi(I_{\mathrm{in}}))\le J^{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}_{K_\pi}+\lfloor(n_y+m_y)\theta_y\rfloor\quad\text{on }\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}. \tag*{(94)} C y ( D ; π ( I in )) ≤ J K π n y − k y + ⌊( n y + m y ) θ y ⌋ + ⌊( n y + m y ) θ y ⌋ on E π ( I in ) , I in m . (94)
Proof. Fix π \pi π . The class-y y y training indices are K π \mathcal K_\pi K π , so
∑ i ∈ K π 1 { S y , i , i ( D ; π ( I i n ) ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) } ≤ n y − k y (95) \sum_{i\in\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}\right\}\le n_y-k_y \tag*{(95)} i ∈ K π ∑ 1 { S y , i , i ( D ; π ( I in )) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) } ≤ n y − k y (95)
On E π ( I i n ) , I i n m \mathcal E_{\pi(\mathcal I_{\mathrm{in}}),\mathcal I_{\mathrm{in}}}^{m} E π ( I in ) , I in m ,
∑ i ∈ [ n y + m y ] 1 { ∣ S y , i , i ( D ; π ( I i n ) ) − S y , i , i ( D ; I i n ) ∣ > B m } ≤ ⌊ ( n y + m y ) θ y ⌋ (96) \sum_{i\in[n_y+m_y]}\mathbf{1}\left\{\left|S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))-S_{y,i,i}(D;\mathcal I_{\mathrm{in}})\right|>B_m\right\}\le\left\lfloor(n_y+m_y)\theta_y\right\rfloor \tag*{(96)} i ∈ [ n y + m y ] ∑ 1 { ∣ S y , i , i ( D ; π ( I in )) − S y , i , i ( D ; I in ) ∣ > B m } ≤ ⌊ ( n y + m y ) θ y ⌋ (96)
For i ∈ [ n y + m y ] i\in[n_y+m_y] i ∈ [ n y + m y ] with ∣ S y , i , i ( D ; π ( I i n ) ) − S y , i , i ( D ; I i n ) ∣ ≤ B m \left|S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))-S_{y,i,i}(D;\mathcal I_{\mathrm{in}})\right|\le B_m ∣ S y , i , i ( D ; π ( I in )) − S y , i , i ( D ; I in ) ∣ ≤ B m ,
S y , i , i ( D ; π ( I i n ) ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + 2 B m ⟹ S y , i , i ( D ; I i n ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + B m ⟹ S y , i , i ( D ; π ( I i n ) ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) . (97) \begin{aligned}
S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))&>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+2B_m\\
&\Longrightarrow S_{y,i,i}(D;\mathcal I_{\mathrm{in}})>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+B_m\\
&\Longrightarrow S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}. \tag*{(97)}
\end{aligned} S y , i , i ( D ; π ( I in )) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + 2 B m ⟹ S y , i , i ( D ; I in ) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + B m ⟹ S y , i , i ( D ; π ( I in )) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) . (97)
Both comparisons use the level ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) \left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)} ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) from the same training sample. No stability of fitted levels is used.
On E π ( I i n ) , I i n m \mathcal E_{\pi(\mathcal I_{\mathrm{in}}),\mathcal I_{\mathrm{in}}}^{m} E π ( I in ) , I in m , the exceptional count in equation eq. (96) gives
∑ i ∈ K π 1 { S y , i , i ( D ; I i n ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + B m } ≤ ∑ i ∈ K π 1 { S y , i , i ( D ; π ( I i n ) ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) } + ⌊ ( n y + m y ) θ y ⌋ ≤ n y − k y + ⌊ ( n y + m y ) θ y ⌋ . (98) \begin{aligned}
\sum_{i\in\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\mathcal I_{\mathrm{in}})>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+B_m\right\}
&\le\sum_{i\in\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}\right\}\\
&\quad+\left\lfloor(n_y+m_y)\theta_y\right\rfloor\\
&\le n_y-k_y+\left\lfloor(n_y+m_y)\theta_y\right\rfloor. \tag*{(98)}
\end{aligned} i ∈ K π ∑ 1 { S y , i , i ( D ; I in ) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + B m } ≤ i ∈ K π ∑ 1 { S y , i , i ( D ; π ( I in )) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) } + ⌊ ( n y + m y ) θ y ⌋ ≤ n y − k y + ⌊ ( n y + m y ) θ y ⌋ . (98)
Put a : = n y − k y + ⌊ ( n y + m y ) θ y ⌋ < n y a:=n_y-k_y+\left\lfloor(n_y+m_y)\theta_y\right\rfloor<n_y a := n y − k y + ⌊ ( n y + m y ) θ y ⌋ < n y . By equation 97, at most a a a training values exceed ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + B m \left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+B_m ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + B m . Every reference value exceeding this threshold therefore precedes the ( a + 1 ) (a+1) ( a + 1 ) st training occurrence in equation 90. Consequently,
∑ i ∈ [ n y + m y ] ∖ K π 1 { S y , i , i ( D ; I i n ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + B m } ≤ J K π a . (99) \sum_{i\in[n_y+m_y]\setminus\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\mathcal I_{\mathrm{in}})>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+B_m\right\}\le J_{\mathcal K_\pi}^{a}. \tag*{(99)} i ∈ [ n y + m y ] ∖ K π ∑ 1 { S y , i , i ( D ; I in ) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + B m } ≤ J K π a . (99)
Using equation 96 and the exceptional count in equation 95 again,
C y ( D ; π ( I i n ) ) ≤ ∑ i ∈ [ n y + m y ] ∖ K π 1 { S y , i , i ( D ; π ( I i n ) ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + 2 B m } ≤ ∑ i ∈ [ n y + m y ] ∖ K π 1 { S y , i , i ( D ; I i n ) > ( S y , i , i ( D ; π ( I i n ) ) ) ( k y : K π ) + B m } + ⌊ ( n y + m y ) θ y ⌋ ≤ J K π a + ⌊ ( n y + m y ) θ y ⌋ . \begin{aligned}
C_y(D;\pi(\mathcal I_{\mathrm{in}}))
&\le\sum_{i\in[n_y+m_y]\setminus\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+2B_m\right\}\\
&\le\sum_{i\in[n_y+m_y]\setminus\mathcal K_\pi}\mathbf{1}\left\{S_{y,i,i}(D;\mathcal I_{\mathrm{in}})>\left(S_{y,i,i}(D;\pi(\mathcal I_{\mathrm{in}}))\right)_{(k_y:\mathcal K_\pi)}+B_m\right\}+\left\lfloor(n_y+m_y)\theta_y\right\rfloor\\
&\le J_{\mathcal K_\pi}^{a}+\left\lfloor(n_y+m_y)\theta_y\right\rfloor.
\end{aligned} C y ( D ; π ( I in )) ≤ i ∈ [ n y + m y ] ∖ K π ∑ 1 { S y , i , i ( D ; π ( I in )) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + 2 B m } ≤ i ∈ [ n y + m y ] ∖ K π ∑ 1 { S y , i , i ( D ; I in ) > ( S y , i , i ( D ; π ( I in )) ) ( k y : K π ) + B m } + ⌊ ( n y + m y ) θ y ⌋ ≤ J K π a + ⌊ ( n y + m y ) θ y ⌋ .
Strict exceedances preserve the bound at ties.
Proof of Lemma 27
For each fixed D D D , equation (94) and equation (43) bound the intersection of the extension tail event and the pairwise stability event. Lemma 20 and equation (55) then give the result under P y \mathbb{P}_y P y .
Proof Fix D D D and s > 0 s>0 s > 0 . On E π ( I i n ) , I i n m \mathcal{E}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}^{m} E π ( I in ) , I in m , if ⌊ ( n y + m y ) θ y ⌋ < k y \lfloor(n_y+m_y)\theta_y\rfloor<k_y ⌊( n y + m y ) θ y ⌋ < k y , then
C y ( D ; π ( I i n ) ) m y ≤ eq. 93 ∣ J κ π n y − k y + ⌊ ( n y + m y ) θ y ⌋ ∣ m y + ⌊ ( n y + m y ) θ y ⌋ m y \frac{C_y(D;\pi(I_{\mathrm{in}}))}{m_y}
\mathrel{\stackrel{\text{eq. 93}}{\leq}}
\frac{\left|J_{\kappa_\pi}^{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}\right|}{m_y}
+\frac{\lfloor(n_y+m_y)\theta_y\rfloor}{m_y} m y C y ( D ; π ( I in )) ≤ eq. 93 m y J κ π n y − k y + ⌊( n y + m y ) θ y ⌋ + m y ⌊( n y + m y ) θ y ⌋
n y − k y + ⌊ ( n y + m y ) θ y ⌋ n y + ⌊ ( n y + m y ) θ y ⌋ m y ≤ ϵ y + ⌊ ( n y + m y ) θ y ⌋ n y + ⌊ ( n y + m y ) θ y ⌋ m y ≤ ϵ y + θ y ( n y + m y ) 2 n y m y . (100) \begin{aligned}
\frac{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}{n_y}
+\frac{\lfloor(n_y+m_y)\theta_y\rfloor}{m_y}
\leq
\epsilon_y+\frac{\lfloor(n_y+m_y)\theta_y\rfloor}{n_y}
+\frac{\lfloor(n_y+m_y)\theta_y\rfloor}{m_y} \\
&\leq\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}. \tag*{(100)}
\end{aligned} n y n y − k y + ⌊( n y + m y ) θ y ⌋ + m y ⌊( n y + m y ) θ y ⌋ ≤ ϵ y + n y ⌊( n y + m y ) θ y ⌋ + m y ⌊( n y + m y ) θ y ⌋ ≤ ϵ y + θ y n y m y ( n y + m y ) 2 . (100)
Using the uniform law in equation (93) , for every fixed D D D and s > 0 s>0 s > 0 ,
Q π ( C y ( D ; π ( I i n ) ) m y > ϵ y + θ y ( n y + m y ) 2 n y m y + s , E π ( I i n ) , I i n m ) \mathbb{Q}_{\pi}\left(
\frac{C_y(D;\pi(I_{\mathrm{in}}))}{m_y}>
\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}+s,\,
\mathcal{E}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}^{m}
\right) Q π ( m y C y ( D ; π ( I in )) > ϵ y + θ y n y m y ( n y + m y ) 2 + s , E π ( I in ) , I in m )
≤ eq. 99 Q π ( ∣ J κ π n y − k y + ⌊ ( n y + m y ) θ y ⌋ ∣ > m y ( n y − k y + ⌊ ( n y + m y ) θ y ⌋ n y + s ) ) \mathrel{\stackrel{\text{eq. 99}}{\leq}}
\mathbb{Q}_{\pi}\left(
\left|J_{\kappa_\pi}^{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}\right|
>
m_y\left(
\frac{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}{n_y}+s
\right)
\right) ≤ eq. 99 Q π ( J κ π n y − k y + ⌊( n y + m y ) θ y ⌋ > m y ( n y n y − k y + ⌊( n y + m y ) θ y ⌋ + s ) )
≤ eq. 43 e − 2 n y m y s 2 / ( n y + m y + 2 ) . (101) \mathrel{\stackrel{\text{eq. 43}}{\leq}}
e^{-2n_ym_ys^2/(n_y+m_y+2)}. \tag*{(101)} ≤ eq. 43 e − 2 n y m y s 2 / ( n y + m y + 2 ) . (101)
If ⌊ ( n y + m y ) θ y ⌋ ≥ k y \lfloor(n_y+m_y)\theta_y\rfloor\geq k_y ⌊( n y + m y ) θ y ⌋ ≥ k y , then
1 ≤ n y − k y + ⌊ ( n y + m y ) θ y ⌋ n y ≤ ϵ y + ⌊ ( n y + m y ) θ y ⌋ n y ≤ ϵ y + θ y ( n y + m y ) 2 n y m y . 1\leq
\frac{n_y-k_y+\lfloor(n_y+m_y)\theta_y\rfloor}{n_y}
\leq
\epsilon_y+\frac{\lfloor(n_y+m_y)\theta_y\rfloor}{n_y}
\leq
\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}. 1 ≤ n y n y − k y + ⌊( n y + m y ) θ y ⌋ ≤ ϵ y + n y ⌊( n y + m y ) θ y ⌋ ≤ ϵ y + θ y n y m y ( n y + m y ) 2 .
Since C y ( D ; π ( I i n ) ) ≤ m y C_y(D;\pi(I_{\mathrm{in}}))\leq m_y C y ( D ; π ( I in )) ≤ m y , the event on the left of equation (101) is empty, so its final bound also holds. Taking expectations and using equation (56) ,
P y ( C y ( D ; I i n ) m y > ϵ y + θ y ( n y + m y ) 2 n y m y + s ) \mathbb{P}_y\left(
\frac{C_y(D;I_{\mathrm{in}})}{m_y}>
\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}+s
\right) P y ( m y C y ( D ; I in ) > ϵ y + θ y n y m y ( n y + m y ) 2 + s )
≤ eq. 100 e − 2 n y m y s 2 / ( n y + m y + 2 ) + P y , π ( ( E π ( I i n ) , I i n m ) c ) ≤ eq. 55 e − 2 n y m y s 2 / ( n y + m y + 2 ) + κ m P ( Y ⋆ = y ) . \mathrel{\stackrel{\text{eq. 100}}{\leq}}
e^{-2n_ym_ys^2/(n_y+m_y+2)}
+\mathbb{P}_{y,\pi}\left((\mathcal{E}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}^{m})^c\right)
\mathrel{\stackrel{\text{eq. 55}}{\leq}}
e^{-2n_ym_ys^2/(n_y+m_y+2)}
+\frac{\kappa_m}{\mathbb{P}(Y_\star=y)}. ≤ eq. 100 e − 2 n y m y s 2 / ( n y + m y + 2 ) + P y , π ( ( E π ( I in ) , I in m ) c ) ≤ eq. 55 e − 2 n y m y s 2 / ( n y + m y + 2 ) + P ( Y ⋆ = y ) κ m .
Balanced Extensions and Selected Quantiles
In this subsection, let m y = n y m_y=n_y m y = n y and allow the quantile rank to depend on the training data. Let k y ( D I ) ∈ [ n y ] k_y(D_I)\in[n_y] k y ( D I ) ∈ [ n y ] be measurable and permutation-invariant, and use it in V y , i ( D ; I ) V_{y,i}(D;I) V y , i ( D ; I ) and C y ( D ; I ) C_y(D;I) C y ( D ; I ) . For I = ( i 1 , … , i n ) I=(i_1,\ldots,i_n) I = ( i 1 , … , i n ) , put
ϵ ^ y ( D ; I ) : = 1 n y ∑ r ∈ [ n ] : Y i r = y 1 { S y , i r , i r ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y ( D I ) : ( D I ) y ) } . (102) \widehat{\epsilon}_y(D;I):=\frac{1}{n_y}
\sum_{r\in[n]:Y_{i_r}=y}
\mathbf{1}\left\{
S_{y,i_r,i_r}(D;I)>
\left(S_{y,i,i}(D;I)\right)_{(k_y(D_I):(D_I)_y)}
\right\}. \tag*{(102)} ϵ y ( D ; I ) := n y 1 r ∈ [ n ] : Y i r = y ∑ 1 { S y , i r , i r ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y ( D I ) : ( D I ) y ) } . (102)
The sum is over training occurrences, including repetitions. The original fixed rank gives ϵ ^ y ( D ; I ) ≤ ϵ y \widehat{\epsilon}_y(D;I)\leq\epsilon_y ϵ y ( D ; I ) ≤ ϵ y .
Lemma 29 (Balanced extension error). For s > 0 s>0 s > 0 ,
P y ( C y ( D ; I i n ) n y > ϵ ^ y ( D ; I i n ) + 2 θ y + s ) ≤ e − 2 n y 2 s 2 / ( 2 n y + 1 ) + κ m P ( Y ⋆ = y ) . (103) \mathbb{P}_y\left(\frac{C_y(D;I_{\mathrm{in}})}{n_y}>\widehat{\epsilon}_y(D;I_{\mathrm{in}})+2\theta_y+s\right)\le e^{-2n_y^2s^2/(2n_y+1)}+\frac{\kappa_m}{\mathbb{P}(Y_\star=y)}. \tag*{(103)} P y ( n y C y ( D ; I in ) > ϵ y ( D ; I in ) + 2 θ y + s ) ≤ e − 2 n y 2 s 2 / ( 2 n y + 1 ) + P ( Y ⋆ = y ) κ m . (103)
Proof. Fix the complete sample and use its ordering in equation (91) . For a training permutation π \pi π , abbreviate its fitted threshold by c π : = ( S y , i , i ( D ; π ( I i n ) ) ) ( k y ( D π ( I i n ) ) : K π ) c_\pi:= (S_{y,i,i}(D;\pi(I_{\mathrm{in}})))_{(k_y(D_{\pi(I_{\mathrm{in}})}):\mathcal{K}_\pi)} c π := ( S y , i , i ( D ; π ( I in )) ) ( k y ( D π ( I in ) ) : K π ) . The indices with S y , i , i ( D ; I i n ) > c π + B m S_{y,i,i}(D;I_{\mathrm{in}})>c_\pi+B_m S y , i , i ( D ; I in ) > c π + B m form a prefix, say [ j ] [j] [ j ] . Let b i n b_{\mathrm{in}} b in and b o u t b_{\mathrm{out}} b out count the exceptional training and extension occurrences in equation (96) . On E π ( I i n ) , I i n m \mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}} E π ( I in ) , I in m , the comparisons in equation (97) give
∣ K π ∩ [ j ] ∣ ≤ n y ϵ ^ y ( D ; π ( I i n ) ) + b i n , C y ( D ; π ( I i n ) ) ≤ ∣ K π c ∩ [ j ] ∣ + b o u t , b i n + b o u t ≤ b y . |\mathcal{K}_\pi\cap[j]|\le n_y\widehat{\epsilon}_y(D;\pi(I_{\mathrm{in}}))+b_{\mathrm{in}},\quad C_y(D;\pi(I_{\mathrm{in}}))\le|\mathcal{K}_\pi^c\cap[j]|+b_{\mathrm{out}},\quad b_{\mathrm{in}}+b_{\mathrm{out}}\le b_y. ∣ K π ∩ [ j ] ∣ ≤ n y ϵ y ( D ; π ( I in )) + b in , C y ( D ; π ( I in )) ≤ ∣ K π c ∩ [ j ] ∣ + b out , b in + b out ≤ b y .
Consequently,
C y ( D ; π ( I i n ) ) n y − ϵ ^ y ( D ; π ( I i n ) ) ≤ D K π + b y n y ≤ D K π + 2 θ y . (104) \frac{C_y(D;\pi(I_{\mathrm{in}}))}{n_y}-\widehat{\epsilon}_y(D;\pi(I_{\mathrm{in}}))\le D_{\mathcal{K}_\pi}+\frac{b_y}{n_y}\le D_{\mathcal{K}_\pi}+2\theta_y. \tag*{(104)} n y C y ( D ; π ( I in )) − ϵ y ( D ; π ( I in )) ≤ D K π + n y b y ≤ D K π + 2 θ y . (104)
Apply Lemma 17 and finite averaging as in Lemma 20, now to the difference on the left of equation (104) . Add the failure probability in equation (55) . The threshold may depend on the training sample because D K π D_{\mathcal{K}_\pi} D K π controls every prefix. Strict exceedances make the same argument valid at ties.
For ranks selected from the training data, put
δ y b a l ( D i n ) : = ϵ ^ y ( D ; I i n ) + 2 θ y + κ m β P ( Y ⋆ = y ) + 2 n y + 1 2 n y 2 log e β . (105) \delta_y^{\mathrm{bal}}(D_{\mathrm{in}}):=\widehat{\epsilon}_y(D;I_{\mathrm{in}})+2\theta_y+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}+\sqrt{\frac{2n_y+1}{2n_y^2}\log\frac{e}{\beta}}. \tag*{(105)} δ y bal ( D in ) := ϵ y ( D ; I in ) + 2 θ y + β P ( Y ⋆ = y ) κ m + 2 n y 2 2 n y + 1 log β e . (105)
Then
P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y b a l ( D i n ) ) ≤ β . (106) \mathbb{P}_y\left(\mathbb{P}_y(V_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})>\delta_y^{\mathrm{bal}}(D_{\mathrm{in}})\right)\le\beta. \tag*{(106)} P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y bal ( D in ) ) ≤ β . (106)
The selector, including any rank-dependent rule selection, must satisfy the same stability assumption. Formula equation (11) remains a fixed-rank guarantee. The training values in this subsection are latent; the intervention guarantees below additionally estimate them.
Proof. The conditional-error identity still holds because the selected threshold is training-measurable. Put c : = 2 n y 2 / ( 2 n y + 1 ) c:=2n_y^2/(2n_y+1) c := 2 n y 2 / ( 2 n y + 1 ) and R : = [ C y ( D ; π ( I i n ) ) / n y − ϵ ^ y ( D ; π ( I i n ) ) − 2 θ y ] + + 1 { E π ( I i n ) , I i n m } R:=\left[C_y(D;\pi(I_{\mathrm{in}}))/n_y-\widehat{\epsilon}_y(D;\pi(I_{\mathrm{in}}))-2\theta_y\right]_++\mathbf{1}\{\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}}\} R := [ C y ( D ; π ( I in )) / n y − ϵ y ( D ; π ( I in )) − 2 θ y ] + + 1 { E π ( I in ) , I in m } . For any event A ∈ σ ( D i n ) A\in\sigma(D_{\mathrm{in}}) A ∈ σ ( D in ) with q : = P y ( A ) > 0 q:=\mathbb{P}_y(A)>0 q := P y ( A ) > 0 , write A π : = π − 1 A A_\pi:=\pi^{-1}A A π := π − 1 A . By equation (60) , P y , π ( A π ) = q \mathbb{P}_{y,\pi}(A_\pi)=q P y , π ( A π ) = q . Lemma 17 and equation (104) give P y , π ( R > s ) ≤ e − c s 2 \mathbb{P}_{y,\pi}(R>s)\le e^{-cs^2} P y , π ( R > s ) ≤ e − c s 2 . Apply equation (38) with h = 1 { A π } h=\mathbf{1}\{A_\pi\} h = 1 { A π } :
E P y , π [ R ∣ A π ] = E P y , π [ 1 { A π } R ] q ≤ log ( e / q ) c . (107) \mathbb{E}^{\mathbb{P}_{y,\pi}}[R\mid A_\pi]=\frac{\mathbb{E}^{\mathbb{P}_{y,\pi}}[\mathbf{1}\{A_\pi\}R]}{q}\le\sqrt{\frac{\log(e/q)}{c}}. \tag*{(107)} E P y , π [ R ∣ A π ] = q E P y , π [ 1 { A π } R ] ≤ c log ( e / q ) . (107)
Write ρ y : = P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) \rho_y := \mathbb{P}_y(\mathcal{V}_{y,\star}(D; I_{\mathrm{in}}) \mid D_{\mathrm{in}}) ρ y := P y ( V y , ⋆ ( D ; I in ) ∣ D in ) and suppress the arguments of ϵ ^ y \widehat{\epsilon}_y ϵ y . Since A , ϵ ^ y A,\widehat{\epsilon}_y A , ϵ y are training-measurable,
E y [ ρ y − ϵ ^ y ∣ A ] = xref‘eq. 86‘ E y [ C y ( D ; I i n ) / n y − ϵ ^ y ∣ A ] ≤ xref‘eq. 56‘ 2 θ y + E P y , π [ R ∣ A π ] + P y , π ( ( E π ( I i n ) , I i n m ) c ) q ≤ xref‘eq. 106‘ 2 θ y + log ( e / q ) c + P y , π ( ( E π ( I i n ) , I i n m ) c ) q ≤ xref‘eq. 55‘ 2 θ y + log ( e / q ) c + κ m q P ( Y ⋆ = y ) . (108) \begin{aligned}
\mathbb{E}_y[\rho_y-\widehat{\epsilon}_y\mid A] &\overset{\text{{xref}`eq. 86`}}{=} \mathbb{E}_y[C_y(D;I_{\mathrm{in}})/n_y-\widehat{\epsilon}_y\mid A]\\
&\overset{\text{{xref}`eq. 56`}}{\leq} 2\theta_y+\mathbb{E}^{\mathbb{P}_{y,\pi}}[R\mid A_\pi]+\frac{\mathbb{P}_{y,\pi}((\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c)}{q}\\
&\overset{\text{{xref}`eq. 106`}}{\leq} 2\theta_y+\sqrt{\frac{\log(e/q)}{c}}+\frac{\mathbb{P}_{y,\pi}((\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c)}{q}\\
&\overset{\text{{xref}`eq. 55`}}{\leq} 2\theta_y+\sqrt{\frac{\log(e/q)}{c}}+\frac{\kappa_m}{q\mathbb{P}(Y_\star=y)}. \tag*{(108)}
\end{aligned} E y [ ρ y − ϵ y ∣ A ] = xref ‘eq. 86‘ E y [ C y ( D ; I in ) / n y − ϵ y ∣ A ] ≤ xref ‘eq. 56‘ 2 θ y + E P y , π [ R ∣ A π ] + q P y , π (( E π ( I in ) , I in m ) c ) ≤ xref ‘eq. 106‘ 2 θ y + c log ( e / q ) + q P y , π (( E π ( I in ) , I in m ) c ) ≤ xref ‘eq. 55‘ 2 θ y + c log ( e / q ) + q P ( Y ⋆ = y ) κ m . (108)
Take A : = { ρ y > δ y b a l ( D i n ) } A:=\{\rho_y>\delta_y^{\mathrm{bal}}(D_{\mathrm{in}})\} A := { ρ y > δ y bal ( D in )} . If q > β q>\beta q > β , then
0 < E y [ ρ y − δ y b a l ( D i n ) ∣ A ] 0<\mathbb{E}_y[\rho_y-\delta_y^{\mathrm{bal}}(D_{\mathrm{in}})\mid A] 0 < E y [ ρ y − δ y bal ( D in ) ∣ A ]
= xref‘eq. 104‘ E y [ ρ y − ϵ ^ y ∣ A ] − 2 θ y − κ m β P ( Y ⋆ = y ) − log ( e / β ) c ≤ xref‘eq. 107‘ log ( e / q ) c − log ( e / β ) c + κ m P ( Y ⋆ = y ) ( 1 q − 1 β ) ≤ 0. \begin{aligned}
&\overset{\text{{xref}`eq. 104`}}{=}\mathbb{E}_y[\rho_y-\widehat{\epsilon}_y\mid A]-2\theta_y-\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}-\sqrt{\frac{\log(e/\beta)}{c}}\\
&\overset{\text{{xref}`eq. 107`}}{\leq}\sqrt{\frac{\log(e/q)}{c}}-\sqrt{\frac{\log(e/\beta)}{c}}+\frac{\kappa_m}{\mathbb{P}(Y_\star=y)}\left(\frac{1}{q}-\frac{1}{\beta}\right)\leq0.
\end{aligned} = xref ‘eq. 104‘ E y [ ρ y − ϵ y ∣ A ] − 2 θ y − β P ( Y ⋆ = y ) κ m − c log ( e / β ) ≤ xref ‘eq. 107‘ c log ( e / q ) − c log ( e / β ) + P ( Y ⋆ = y ) κ m ( q 1 − β 1 ) ≤ 0.
Consequently,
P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y b a l ( D i n ) ) = P y ( A ) = q ≤ β . \mathbb{P}_y\left(\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})>\delta_y^{\mathrm{bal}}(D_{\mathrm{in}})\right)=\mathbb{P}_y(A)=q\leq\beta. P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y bal ( D in ) ) = P y ( A ) = q ≤ β .
Training-Conditional Coverage
We now prove item (3):
P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β ) ) ≤ β . (109) \mathbb{P}_y\left(\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})>\delta_y(\beta)\right)\leq\beta. \tag*{(109)} P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β ) ) ≤ β . (109)
We use the CVaR formula of Rockafellar and Uryasev (2002, Theorem 10, Eqs. (27)–(28)), with upper-tail mass β \beta β , and account separately for stability failure.
Proof Put H : = C y ( D ; I i n ) / m y H:=C_y(D;I_{\mathrm{in}})/m_y H := C y ( D ; I in ) / m y and ρ y : = E y [ H ∣ D i n ] \rho_y:=\mathbb{E}_y[H\mid D_{\mathrm{in}}] ρ y := E y [ H ∣ D in ] . Write W y ( K π ) W_y(K_\pi) W y ( K π ) for W y W_y W y evaluated at the training ranks K π K_\pi K π . For 0 ≤ u ≤ 1 0\leq u\leq1 0 ≤ u ≤ 1 , equation 93 and H ≤ 1 H\leq1 H ≤ 1 give, including by b y ≥ k y b_y\geq k_y b y ≥ k y where W y = 1 W_y=1 W y = 1 ,
( C y ( D ; π ( I i n ) ) m y − u ) + ≤ ( W y ( K π ) − u ) + + ( 1 − u ) 1 { ( E π ( I i n ) , I i n m ) c } . (110) \left(\frac{C_y(D;\pi(I_{\mathrm{in}}))}{m_y}-u\right)_+\leq(W_y(K_\pi)-u)_+ +(1-u)\mathbf{1}\{(\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c\}. \tag*{(110)} ( m y C y ( D ; π ( I in )) − u ) + ≤ ( W y ( K π ) − u ) + + ( 1 − u ) 1 {( E π ( I in ) , I in m ) c } . (110)
Conditional Jensen’s inequality and finite averaging now give
E y [ ( ρ y − u ) + ] ≤ J e n s e n E y [ ( H − u ) + ] = xref‘eq. 56‘ E P y , π [ ( C y ( D ; π ( I i n ) ) m y − u ) + ] ≤ xref‘eq. 109‘ E P y , π [ ( W y ( K π ) − u ) + ] + ( 1 − u ) P y , π ( ( E π ( I i n ) , I i n m ) c ) ≤ xref‘eq. 92‘ E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) P y , π ( ( E π ( I i n ) , I i n m ) c ) ≤ xref‘eq. 55‘ E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) κ m P ( Y ⋆ = y ) . (111) \begin{aligned}
\mathbb{E}_y[(\rho_y-u)_+] &\overset{\mathrm{Jensen}}{\leq}\mathbb{E}_y[(H-u)_+]\\
&\overset{\text{{xref}`eq. 56`}}{=}\mathbb{E}^{\mathbb{P}_{y,\pi}}\left[\left(\frac{C_y(D;\pi(I_{\mathrm{in}}))}{m_y}-u\right)_+\right]\\
&\overset{\text{{xref}`eq. 109`}}{\leq}\mathbb{E}^{\mathbb{P}_{y,\pi}}[(W_y(K_\pi)-u)_+]+(1-u)\mathbb{P}_{y,\pi}((\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c)\\
&\overset{\text{{xref}`eq. 92`}}{\leq}\mathbb{E}_{Q_{n_y,m_y}}[(W_y-u)_+]+(1-u)\mathbb{P}_{y,\pi}((\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c)\\
&\overset{\text{{xref}`eq. 55`}}{\leq}\mathbb{E}_{Q_{n_y,m_y}}[(W_y-u)_+]+(1-u)\frac{\kappa_m}{\mathbb{P}(Y_\star=y)}. \tag*{(111)}
\end{aligned} E y [( ρ y − u ) + ] ≤ Jensen E y [( H − u ) + ] = xref ‘eq. 56‘ E P y , π [ ( m y C y ( D ; π ( I in )) − u ) + ] ≤ xref ‘eq. 109‘ E P y , π [( W y ( K π ) − u ) + ] + ( 1 − u ) P y , π (( E π ( I in ) , I in m ) c ) ≤ xref ‘eq. 92‘ E Q n y , m y [( W y − u ) + ] + ( 1 − u ) P y , π (( E π ( I in ) , I in m ) c ) ≤ xref ‘eq. 55‘ E Q n y , m y [( W y − u ) + ] + ( 1 − u ) P ( Y ⋆ = y ) κ m . (111)
The objective in equation (11) is continuous on [ 0 , 1 ] [0,1] [ 0 , 1 ] , so choose a minimizer u u u . If δ y ( β ) > u \delta_y(\beta)>u δ y ( β ) > u , Markov’s inequality gives
P y ( ρ y > δ y ( β ) ) ≤ E y [ ( ρ y − u ) + ] δ y ( β ) − u ≤ E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) δ y ( β ) − u = eq. 11 β . \mathbb{P}_y(\rho_y>\delta_y(\beta)) \le\frac{\mathbb{E}_y[(\rho_y-u)_+]}{\delta_y(\beta)-u} \le\frac{\mathbb{E}_{Q_{n_y,m_y}}[(W_y-u)_+] +(1-u)\kappa_m/\mathbb{P}(Y_\star=y)}{\delta_y(\beta)-u} \overset{\text{eq. }11}{=} \beta. P y ( ρ y > δ y ( β )) ≤ δ y ( β ) − u E y [( ρ y − u ) + ] ≤ δ y ( β ) − u E Q n y , m y [( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) = eq. 11 β .
If δ y ( β ) = u \delta_y(\beta)=u δ y ( β ) = u , then
E y [ ( ρ y − u ) + ] ≤ eq. 110 E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) κ m P ( Y ⋆ = y ) = eq. 11 β ( δ y ( β ) − u ) = 0 , \mathbb{E}_y[(\rho_y-u)_+] \overset{\text{eq. }110}{\le} \mathbb{E}_{Q_{n_y,m_y}}[(W_y-u)_+] +(1-u)\frac{\kappa_m}{\mathbb{P}(Y_\star=y)} \overset{\text{eq. }11}{=} \beta(\delta_y(\beta)-u)=0, E y [( ρ y − u ) + ] ≤ eq. 110 E Q n y , m y [( W y − u ) + ] + ( 1 − u ) P ( Y ⋆ = y ) κ m = eq. 11 β ( δ y ( β ) − u ) = 0 ,
so P y ( ρ y > δ y ( β ) ) = 0 \mathbb{P}_y(\rho_y>\delta_y(\beta))=0 P y ( ρ y > δ y ( β )) = 0 . In both cases,
P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β ) ) = eq. 86 P y ( ρ y > δ y ( β ) ) ≤ β . \mathbb{P}_y\bigl(\mathbb{P}_y(\mathcal{V}_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}})>\delta_y(\beta)\bigr) \overset{\text{eq. }86}{=} \mathbb{P}_y(\rho_y>\delta_y(\beta))\le\beta. P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β ) ) = eq. 86 P y ( ρ y > δ y ( β )) ≤ β .
When m y = 1 m_y=1 m y = 1 and θ y = κ m = 0 \theta_y=\kappa_m=0 θ y = κ m = 0 , W y W_y W y is Bernoulli with mean
E Q n y , m y W y = eq. 44 n y − k y + 1 n y + 1 = ⌊ n y ϵ y ⌋ + 1 n y + 1 . (112) \mathbb{E}_{Q_{n_y,m_y}}W_y \overset{\text{eq. }44}{=} \frac{n_y-k_y+1}{n_y+1}=\frac{\lfloor n_y\epsilon_y\rfloor+1}{n_y+1}. \tag*{(112)} E Q n y , m y W y = eq. 44 n y + 1 n y − k y + 1 = n y + 1 ⌊ n y ϵ y ⌋ + 1 . (112)
Thus equation (11) equals min { 1 , ( ⌊ n y ϵ y ⌋ + 1 ) / ( β ( n y + 1 ) ) } \min\{1,(\lfloor n_y\epsilon_y\rfloor+1)/(\beta(n_y+1))\} min { 1 , (⌊ n y ϵ y ⌋ + 1 ) / ( β ( n y + 1 ))} , including the single-extension case without a separate definition.
The same rank law also gives the closed-form bound
δ y ( β ) ≤ ϵ y + θ y ( n y + m y ) 2 n y m y + κ m β P ( Y ⋆ = y ) + n y + m y + 2 2 n y m y log e β . (113) \delta_y(\beta)\le\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}+\sqrt{\frac{n_y+m_y+2}{2n_ym_y}\log\frac{e}{\beta}}. \tag*{(113)} δ y ( β ) ≤ ϵ y + θ y n y m y ( n y + m y ) 2 + β P ( Y ⋆ = y ) κ m + 2 n y m y n y + m y + 2 log β e . (113)
To see this, put b : = ϵ y + θ y ( n y + m y ) 2 / ( n y m y ) b:=\epsilon_y+\theta_y(n_y+m_y)^2/(n_ym_y) b := ϵ y + θ y ( n y + m y ) 2 / ( n y m y ) and c : = 2 n y m y / ( n y + m y + 2 ) c:=2n_ym_y/(n_y+m_y+2) c := 2 n y m y / ( n y + m y + 2 ) . If b y ≥ k y b_y\ge k_y b y ≥ k y , then b ≥ 1 b\ge1 b ≥ 1 and the bound is immediate. Otherwise, R : = [ W y − b ] + R:=[W_y-b]_+ R := [ W y − b ] + satisfies Q n y , m y ( R > s ) ≤ e − c s 2 Q_{n_y,m_y}(R>s)\le e^{-cs^2} Q n y , m y ( R > s ) ≤ e − c s 2 by Lemma 15. Choose weights h = h ( W y ) ∈ [ 0 , 1 ] h=h(W_y)\in[0,1] h = h ( W y ) ∈ [ 0 , 1 ] selecting the upper β \beta β fraction of the rank law, with Q n y , m y h = β Q_{n_y,m_y}h=\beta Q n y , m y h = β and fractional weight at the boundary atom. The variational formula gives
δ y ( β ) ≤ E Q n y , m y [ h W y ] β + κ m β P ( Y ⋆ = y ) ≤ b + E Q n y , m y [ h R ] β + κ m β P ( Y ⋆ = y ) . (114) \delta_y(\beta)\le\frac{\mathbb{E}_{Q_{n_y,m_y}}[hW_y]}{\beta}+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}\le b+\frac{\mathbb{E}_{Q_{n_y,m_y}}[hR]}{\beta}+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}. \tag*{(114)} δ y ( β ) ≤ β E Q n y , m y [ h W y ] + β P ( Y ⋆ = y ) κ m ≤ b + β E Q n y , m y [ h R ] + β P ( Y ⋆ = y ) κ m . (114)
Since E Q n y , m y h = β \mathbb{E}_{Q_{n_y,m_y}}h=\beta E Q n y , m y h = β ,
E Q n y , m y [ h R ] β ≤ eq. 38 log ( e / β ) c . (115) \frac{\mathbb{E}_{Q_{n_y,m_y}}[hR]}{\beta}\overset{\text{eq. }38}{\le}\sqrt{\frac{\log(e/\beta)}{c}}. \tag*{(115)} β E Q n y , m y [ h R ] ≤ eq. 38 c log ( e / β ) . (115)
δ y ( β ) ≤ eq. 113 b + E Q n y , m y [ h R ] β + κ m β P ( Y ⋆ = y ) ≤ eq. 114 ϵ y + θ y ( n y + m y ) 2 n y m y + n y + m y + 2 2 n y m y log e β + κ m β P ( Y ⋆ = y ) . \begin{aligned}
\delta_y(\beta)&\overset{\text{eq. }113}{\le}b+\frac{\mathbb{E}_{Q_{n_y,m_y}}[hR]}{\beta}+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}\\
&\overset{\text{eq. }114}{\le}\epsilon_y+\theta_y\frac{(n_y+m_y)^2}{n_ym_y}+\sqrt{\frac{n_y+m_y+2}{2n_ym_y}\log\frac{e}{\beta}}+\frac{\kappa_m}{\beta\mathbb{P}(Y_\star=y)}.
\end{aligned} δ y ( β ) ≤ eq. 113 b + β E Q n y , m y [ h R ] + β P ( Y ⋆ = y ) κ m ≤ eq. 114 ϵ y + θ y n y m y ( n y + m y ) 2 + 2 n y m y n y + m y + 2 log β e + β P ( Y ⋆ = y ) κ m .
For fixed ranks and m y = n y m_y=n_y m y = n y , equation (106) also permits the deterministic bound obtained from equation (105) by replacing ϵ ^ y \widehat{\epsilon}_y ϵ y with ϵ y \epsilon_y ϵ y . One may choose the smaller of that bound and equation (11) before observing the data, with the same confidence 1 − β 1-\beta 1 − β .
Intervention Guarantees
Proof. For training occurrence i i i , the monitor X ^ ( D i n − i ) \widehat{X}(D_{\mathrm{in}}^{-i}) X ( D in − i ) is measurable with respect to D i n − i D_{\mathrm{in}}^{-i} D in − i . Use F = F i ( D i n − i ) \mathcal{F}=\mathcal{F}_i(D_{\mathrm{in}}^{-i}) F = F i ( D in − i ) in Proposition 2 (2), with sign ( − 1 ) y + 1 (-1)^{y+1} ( − 1 ) y + 1 . Then
P y ( S y , i , i ( D ; I i n ) > s ^ y , i , i ( D ; I i n , r ( β / ( 2 n y ) ) ) ∣ F 0 ) ≤ P y ( ∃ t : ( − 1 ) y + 1 [ μ ^ t , i ( D i n − i ) − X ^ ( D i n − i ) ] > r t ( β / ( 2 n y ) ) ∣ F 0 ) ≤ β 2 n y . (116) \mathbb{P}_y\left(S_{y,i,i}(D;I_{\mathrm{in}})>\widehat{s}_{y,i,i}(D;I_{\mathrm{in}},r(\beta/(2n_y)))\mid F_0\right)
\leq\mathbb{P}_y\left(\exists t:\ (-1)^{y+1}\left[\widehat{\mu}_{t,i}(D_{\mathrm{in}}^{-i})-\widehat{X}(D_{\mathrm{in}}^{-i})\right]>r_t(\beta/(2n_y))\mid F_0\right)
\leq\frac{\beta}{2n_y}. \tag*{(116)} P y ( S y , i , i ( D ; I in ) > s y , i , i ( D ; I in , r ( β / ( 2 n y ))) ∣ F 0 ) ≤ P y ( ∃ t : ( − 1 ) y + 1 [ μ t , i ( D in − i ) − X ( D in − i ) ] > r t ( β / ( 2 n y )) ∣ F 0 ) ≤ 2 n y β . (116)
Define the training-measurable event
F y : = ⋂ i ∈ I i n , y { S y , i , i ( D ; I i n ) ≤ s ^ y , i , i ( D ; I i n , r ( β / ( 2 n y ) ) ) } . (117) F_y:=\bigcap_{i\in\mathcal{I}_{\mathrm{in},y}}\left\{S_{y,i,i}(D;I_{\mathrm{in}})\leq\widehat{s}_{y,i,i}(D;I_{\mathrm{in}},r(\beta/(2n_y)))\right\}. \tag*{(117)} F y := i ∈ I in , y ⋂ { S y , i , i ( D ; I in ) ≤ s y , i , i ( D ; I in , r ( β / ( 2 n y ))) } . (117)
Taking expectations in equation (116) and applying the union bound,
P y ( F y c ) ≤ ∑ i ∈ I i n , y P y ( S y , i , i ( D ; I i n ) > s ^ y , i , i ( D ; I i n , r ( β / ( 2 n y ) ) ) ) ≤ ∑ i ∈ I i n , y β 2 n y = β 2 . (118) \mathbb{P}_y(F_y^c)\leq\sum_{i\in\mathcal{I}_{\mathrm{in},y}}\mathbb{P}_y\left(S_{y,i,i}(D;I_{\mathrm{in}})>\widehat{s}_{y,i,i}(D;I_{\mathrm{in}},r(\beta/(2n_y)))\right)\leq\sum_{i\in\mathcal{I}_{\mathrm{in},y}}\frac{\beta}{2n_y}=\frac{\beta}{2}. \tag*{(118)} P y ( F y c ) ≤ i ∈ I in , y ∑ P y ( S y , i , i ( D ; I in ) > s y , i , i ( D ; I in , r ( β / ( 2 n y ))) ) ≤ i ∈ I in , y ∑ 2 n y β = 2 β . (118)
On F y F_y F y , equation (117) gives
min { 1 − y , ( S y , i , i ( D ; I i n ) ) ( k y : D i n , y ) + 2 B m } ≤ min { 1 − y , ( s ^ y , i , i ( D ; I i n , r ( β / ( 2 n y ) ) ) ) ( k y : D i n , y ) + 2 B m } = q ^ y . (119) \min\left\{1-y,\left(S_{y,i,i}(D;I_{\mathrm{in}})\right)_{(k_y:D_{\mathrm{in},y})}+2B_m\right\}
\leq\min\left\{1-y,\left(\widehat{s}_{y,i,i}(D;I_{\mathrm{in}},r(\beta/(2n_y)))\right)_{(k_y:D_{\mathrm{in},y})}+2B_m\right\}
=\widehat{q}_y. \tag*{(119)} min { 1 − y , ( S y , i , i ( D ; I in ) ) ( k y : D in , y ) + 2 B m } ≤ min { 1 − y , ( s y , i , i ( D ; I in , r ( β / ( 2 n y ))) ) ( k y : D in , y ) + 2 B m } = q y . (119)
Since S y , ⋆ , ⋆ ( D ; I i n ) ≤ 1 − y S_{y,\star,\star}(D;I_{\mathrm{in}})\leq1-y S y , ⋆ , ⋆ ( D ; I in ) ≤ 1 − y , equation (119) gives
{ S y , ⋆ , ⋆ ( D ; I i n ) > q ^ y } ∩ F y ⊆ V y , ⋆ ( D ; I i n ) ∩ F y . (120) \left\{S_{y,\star,\star}(D;I_{\mathrm{in}})>\widehat{q}_y\right\}\cap F_y\subseteq V_{y,\star}(D;I_{\mathrm{in}})\cap F_y. \tag*{(120)} { S y , ⋆ , ⋆ ( D ; I in ) > q y } ∩ F y ⊆ V y , ⋆ ( D ; I in ) ∩ F y . (120)
Put
G y : = F y ∩ { P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) ≤ δ y ( β / 2 ) } . (121) G_y:=F_y\cap\left\{\mathbb{P}_y\left(V_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}\right)\leq\delta_y(\beta/2)\right\}. \tag*{(121)} G y := F y ∩ { P y ( V y , ⋆ ( D ; I in ) ∣ D in ) ≤ δ y ( β /2 ) } . (121)
By item (3),
P y ( G y c ) ≤ P y ( F y c ) + P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β / 2 ) ) ≤ β 2 + P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β / 2 ) ) ≤ β 2 + β 2 = β . (122) \mathbb{P}_y(G_y^c)\leq\mathbb{P}_y(F_y^c)+\mathbb{P}_y\left(\mathbb{P}_y\left(V_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}\right)>\delta_y(\beta/2)\right)
\leq\frac{\beta}{2}+\mathbb{P}_y\left(\mathbb{P}_y\left(V_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}\right)>\delta_y(\beta/2)\right)
\leq\frac{\beta}{2}+\frac{\beta}{2}=\beta. \tag*{(122)} P y ( G y c ) ≤ P y ( F y c ) + P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β /2 ) ) ≤ 2 β + P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β /2 ) ) ≤ 2 β + 2 β = β . (122)
On G y G_y G y , training measurability gives
P y ( S y , ⋆ , ⋆ ( D ; I i n ) > q ^ y ∣ D i n ) ≤ P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) ≤ δ y ( β / 2 ) . (123) \mathbb{P}_y\left(S_{y,\star,\star}(D;I_{\mathrm{in}})>\widehat{q}_y\mid D_{\mathrm{in}}\right)\leq\mathbb{P}_y\left(V_{y,\star}(D;I_{\mathrm{in}})\mid D_{\mathrm{in}}\right)\leq\delta_y(\beta/2). \tag*{(123)} P y ( S y , ⋆ , ⋆ ( D ; I in ) > q y ∣ D in ) ≤ P y ( V y , ⋆ ( D ; I in ) ∣ D in ) ≤ δ y ( β /2 ) . (123)
For the next trajectory, D i n − ⋆ = D i n D_{\mathrm{in}}^{-\star}=D_{\mathrm{in}} D in −⋆ = D in , so use F = F ⋆ ( D i n ) \mathcal{F}=\mathcal{F}_{\star}(D_{\mathrm{in}}) F = F ⋆ ( D in ) and the deployed monitor X ^ = X ^ ( D i n ) \widehat{X}=\widehat{X}(D_{\mathrm{in}}) X = X ( D in ) . Then
S y , ⋆ , ⋆ ( D ; I i n ) = max t ∈ W ( − 1 ) y μ ^ t , y X ( Z t , ⋆ ; F ) . (124) S_{y,\star,\star}(D;I_{\mathrm{in}})=\max_{t\in\mathcal{W}}(-1)^y\widehat{\mu}^{X}_{t,y}(Z_{t,\star};\mathcal{F}). \tag*{(124)} S y , ⋆ , ⋆ ( D ; I in ) = t ∈ W max ( − 1 ) y μ t , y X ( Z t , ⋆ ; F ) . (124)
The bounds satisfy q ^ 0 , − q ^ 1 ∈ [ 0 , 1 ] \widehat{q}_0,-\widehat{q}_1\in[0,1] q 0 , − q 1 ∈ [ 0 , 1 ] . All fitted parameters are H : = σ ( D i n ) \mathcal{H}:=\sigma(D_{\mathrm{in}}) H := σ ( D in ) -measurable, with H ⊆ F 0 \mathcal{H}\subseteq\mathcal{F}_0 H ⊆ F 0 . Apply Lemma 24 on the training-measurable events G y G_y G y .
(a) False intervention. On G 0 G_0 G 0 , take p 0 = q ^ 0 p_0=\widehat{q}_0 p 0 = q 0 , q 0 = p ^ q_0=\widehat{p} q 0 = p , and λ = λ ^ \lambda=\widehat{\lambda} λ = λ :
P 0 ( τ ^ < ∞ ∣ D i n ) ≤ eq. 68 P 0 ( max s ∈ W μ ^ s , 0 X > q ^ 0 ∣ D i n ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) \mathbb{P}_0(\widehat{\tau}<\infty\mid D_{\mathrm{in}})\underset{\text{eq. 68}}{\leq}\mathbb{P}_0\left(\max_{s\in\mathcal{W}}\widehat{\mu}^{X}_{s,0}>\widehat{q}_0\mid D_{\mathrm{in}}\right)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha) P 0 ( τ < ∞ ∣ D in ) eq. 68 ≤ P 0 ( s ∈ W max μ s , 0 X > q 0 ∣ D in ) + e 0 ( q 0 ; λ , p , α )
= eq. 123 P 0 ( S 0 , ⋆ , ⋆ ( D ; I i n ) > q ^ 0 ∣ D i n ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) \underset{\text{eq. 123}}{=}\mathbb{P}_0\left(S_{0,\star,\star}(D;I_{\mathrm{in}})>\widehat{q}_0\mid D_{\mathrm{in}}\right)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha) eq. 123 = P 0 ( S 0 , ⋆ , ⋆ ( D ; I in ) > q 0 ∣ D in ) + e 0 ( q 0 ; λ , p , α )
≤ eq. 122 δ 0 ( β / 2 ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) . (125) \underset{\text{eq. 122}}{\leq}\delta_0(\beta/2)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha). \tag*{(125)} eq. 122 ≤ δ 0 ( β /2 ) + e 0 ( q 0 ; λ , p , α ) . (125)
Consequently,
P 0 ( P 0 ( τ ^ < ∞ ∣ D i n ) > δ 0 ( β / 2 ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) ) ≤ eq. 124 P 0 ( G 0 c ) ≤ eq. 121 β . \mathbb{P}_0\left(\mathbb{P}_0(\widehat{\tau}<\infty\mid D_{\mathrm{in}})>\delta_0(\beta/2)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha)\right)\underset{\text{eq. 124}}{\leq}\mathbb{P}_0(G_0^{\mathrm{c}})\underset{\text{eq. 121}}{\leq}\beta. P 0 ( P 0 ( τ < ∞ ∣ D in ) > δ 0 ( β /2 ) + e 0 ( q 0 ; λ , p , α ) ) eq. 124 ≤ P 0 ( G 0 c ) eq. 121 ≤ β .
(b) Detection. On G 1 G_1 G 1 , take p 1 = − q ^ 1 p_1=-\widehat{q}_1 p 1 = − q 1 , q 0 = p ^ q_0=\widehat{p} q 0 = p , and λ = λ ^ \lambda=\widehat{\lambda} λ = λ . For every t ∈ W t\in\mathcal{W} t ∈ W ,
P 1 ( τ ^ > t ∣ D i n ) ≤ eq. 69 P 1 ( μ ^ t , 1 X < − q ^ 1 ∣ D i n ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) \mathbb{P}_1(\widehat{\tau}>t\mid D_{\mathrm{in}})\underset{\text{eq. 69}}{\leq}\mathbb{P}_1(\widehat{\mu}^{X}_{t,1}<-\widehat{q}_1\mid D_{\mathrm{in}})+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha) P 1 ( τ > t ∣ D in ) eq. 69 ≤ P 1 ( μ t , 1 X < − q 1 ∣ D in ) + e 1 , t ( − q 1 ; λ , p , α )
≤ eq. 123 P 1 ( S 1 , ⋆ , ⋆ ( D ; I i n ) > q ^ 1 ∣ D i n ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) \underset{\text{eq. 123}}{\leq}\mathbb{P}_1\left(S_{1,\star,\star}(D;I_{\mathrm{in}})>\widehat{q}_1\mid D_{\mathrm{in}}\right)+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha) eq. 123 ≤ P 1 ( S 1 , ⋆ , ⋆ ( D ; I in ) > q 1 ∣ D in ) + e 1 , t ( − q 1 ; λ , p , α )
≤ eq. 122 δ 1 ( β / 2 ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) . (126) \underset{\text{eq. 122}}{\leq}\delta_1(\beta/2)+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha). \tag*{(126)} eq. 122 ≤ δ 1 ( β /2 ) + e 1 , t ( − q 1 ; λ , p , α ) . (126)
The same event G 1 G_1 G 1 works for every t t t , so
P 1 ( ∃ t ∈ W : P 1 ( τ ^ > t ∣ D i n ) > δ 1 ( β / 2 ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) ) ≤ eq. 125 P 1 ( G 1 c ) ≤ eq. 121 β . \mathbb{P}_1\left(\exists t\in\mathcal{W}:\mathbb{P}_1(\widehat{\tau}>t\mid D_{\mathrm{in}})>\delta_1(\beta/2)+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha)\right)\underset{\text{eq. 125}}{\leq}\mathbb{P}_1(G_1^{\mathrm{c}})\underset{\text{eq. 121}}{\leq}\beta. P 1 ( ∃ t ∈ W : P 1 ( τ > t ∣ D in ) > δ 1 ( β /2 ) + e 1 , t ( − q 1 ; λ , p , α ) ) eq. 125 ≤ P 1 ( G 1 c ) eq. 121 ≤ β .
On B 0 c \mathcal{B}_0^{\mathrm{c}} B 0 c , the fallback p ^ = λ ^ = 1 \widehat{p}=\widehat{\lambda}=1 p = λ = 1 gives τ ^ = ∞ \widehat{\tau}=\infty τ = ∞ and e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) = 1 e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha)=1 e 1 , t ( − q 1 ; λ , p , α ) = 1 .
The outer probabilities range over all training samples. If P y ( B 0 ) > 0 \mathbb{P}_y(\mathcal{B}_0)>0 P y ( B 0 ) > 0 , conditioning further gives only
P y ( G y c ∣ B 0 ) ≤ β P y ( B 0 ) . (127) \mathbb{P}_y(G_y^{\mathrm{c}}\mid\mathcal{B}_0)\leq\frac{\beta}{\mathbb{P}_y(\mathcal{B}_0)}. \tag*{(127)} P y ( G y c ∣ B 0 ) ≤ P y ( B 0 ) β . (127)
A known lower bound 0 < π y ≤ P y ( B 0 ) 0<\pi_y\leq\mathbb{P}_y(\mathcal{B}_0) 0 < π y ≤ P y ( B 0 ) permits conditional confidence 1 − β 1-\beta 1 − β by using β π y \beta\pi_y β π y in the corresponding error bound.
Proof of Lemma 6
Proof Fix S ∈ C S\in\mathcal{C} S ∈ C . The Boolean identities below hold for every i ∈ [ n ] i\in[n] i ∈ [ n ] and t ∈ [ T 1 ] t\in[T_1] t ∈ [ T 1 ] . For part (1), the definition gives
X t , i ( S ) = 1 ⟺ ⋁ R ∈ S ξ t , i R = 1 ⟺ { R ∈ S : ξ t , i R = 1 } ≠ ∅ . X_{t,i}(S)=1\Longleftrightarrow\bigvee_{R\in S}\xi^R_{t,i}=1\Longleftrightarrow\{R\in S:\xi^R_{t,i}=1\}\ne\varnothing. X t , i ( S ) = 1 ⟺ R ∈ S ⋁ ξ t , i R = 1 ⟺ { R ∈ S : ξ t , i R = 1 } = ∅ .
The empty disjunction is zero, so this includes S = ∅ S = \varnothing S = ∅ .
For part (2), let R ∈ S \mathcal{R} \in S R ∈ S , R ′ ⊆ [ d ] \mathcal{R}' \subseteq[d] R ′ ⊆ [ d ] with 1 ≤ ∣ R ′ ∣ ≤ K R 1 \le|\mathcal{R}'| \le K_{\mathcal{R}} 1 ≤ ∣ R ′ ∣ ≤ K R , and S ′ = ( S ∖ { R } ) ∪ { R ′ } S' = (S \setminus\{\mathcal{R}\}) \cup\{\mathcal{R}'\} S ′ = ( S ∖ { R }) ∪ { R ′ } . For a , b ∈ { 0 , 1 } a,b \in\{0,1\} a , b ∈ { 0 , 1 } , applying a ∨ b = a + ( 1 − a ) b a \lor b = a + (1-a)b a ∨ b = a + ( 1 − a ) b to the two disjunctions gives
X t , i ( S ) = X t , i ( S ∖ { R } ) + ( 1 − X t , i ( S ∖ { R } ) ) ξ t , i R , X_{t,i}(S) = X_{t,i}(S \setminus\{\mathcal{R}\}) + \left(1-X_{t,i}(S \setminus\{\mathcal{R}\})\right)\xi_{t,i}^{\mathcal{R}}, X t , i ( S ) = X t , i ( S ∖ { R }) + ( 1 − X t , i ( S ∖ { R }) ) ξ t , i R ,
X t , i ( S ′ ) = X t , i ( S ∖ { R } ) + ( 1 − X t , i ( S ∖ { R } ) ) ξ t , i R ′ . X_{t,i}(S') = X_{t,i}(S \setminus\{\mathcal{R}\}) + \left(1-X_{t,i}(S \setminus\{\mathcal{R}\})\right)\xi_{t,i}^{\mathcal{R}'}. X t , i ( S ′ ) = X t , i ( S ∖ { R }) + ( 1 − X t , i ( S ∖ { R }) ) ξ t , i R ′ .
Subtracting these identities gives
X t , i ( S ′ ) − X t , i ( S ) = ( 1 − X t , i ( S ∖ { R } ) ) ( ξ t , i R ′ − ξ t , i R ) . (128) X_{t,i}(S') - X_{t,i}(S) = \left(1-X_{t,i}(S \setminus\{\mathcal{R}\})\right)\left(\xi_{t,i}^{\mathcal{R}'}-\xi_{t,i}^{\mathcal{R}}\right). \tag*{(128)} X t , i ( S ′ ) − X t , i ( S ) = ( 1 − X t , i ( S ∖ { R }) ) ( ξ t , i R ′ − ξ t , i R ) . (128)
This includes R ′ ∈ S ∖ { R } \mathcal{R}' \in S \setminus\{\mathcal{R}\} R ′ ∈ S ∖ { R } , since a ∨ a = a a \lor a = a a ∨ a = a .
For part (3), conjunction is multiplication and a 2 = a a^2=a a 2 = a for a ∈ { 0 , 1 } a \in\{0,1\} a ∈ { 0 , 1 } , so
ξ t , i R ∪ { ℓ } = ∏ j ∈ R ∪ { ℓ } ξ t , i j = ( ∏ j ∈ R ξ t , i j ) ξ t , i ℓ = ξ t , i R ξ t , i ℓ . (129) \xi_{t,i}^{\mathcal{R}\cup\{\ell\}} = \prod_{j\in\mathcal{R}\cup\{\ell\}}\xi_{t,i}^{j} = \left(\prod_{j\in\mathcal{R}}\xi_{t,i}^{j}\right)\xi_{t,i}^{\ell} = \xi_{t,i}^{\mathcal{R}}\xi_{t,i}^{\ell}. \tag*{(129)} ξ t , i R ∪ { ℓ } = j ∈ R ∪ { ℓ } ∏ ξ t , i j = j ∈ R ∏ ξ t , i j ξ t , i ℓ = ξ t , i R ξ t , i ℓ . (129)
Also,
X t , i ( S ∪ { { ℓ } } ) − X t , i ( S ) = ( X t , i ( S ) ∨ ξ t , i ℓ ) − X t , i ( S ) = ( 1 − X t , i ( S ) ) ξ t , i ℓ . X_{t,i}(S \cup\{\{\ell\}\}) - X_{t,i}(S) = \left(X_{t,i}(S) \lor\xi_{t,i}^{\ell}\right) - X_{t,i}(S) = \left(1-X_{t,i}(S)\right)\xi_{t,i}^{\ell}. X t , i ( S ∪ {{ ℓ }}) − X t , i ( S ) = ( X t , i ( S ) ∨ ξ t , i ℓ ) − X t , i ( S ) = ( 1 − X t , i ( S ) ) ξ t , i ℓ .
For part (4), suppose X s , i ( S ′ ) ≤ X s , i ( S ) X_{s,i}(S') \le X_{s,i}(S) X s , i ( S ′ ) ≤ X s , i ( S ) for every s ∈ [ T 1 ] s \in[T_1] s ∈ [ T 1 ] . For every t ∈ W t \in\mathcal{W} t ∈ W ,
μ ^ t , i X ( S ′ ) ≤ xref‘eq. 3‘ 1 t ∑ s = 1 t X s , i ( S ′ ) ≤ 1 t ∑ s = 1 t X s , i ( S ) = μ ^ t , i X ( S ) . (130) \widehat{\mu}_{t,i}^{X(S')} \mathrel{\mathop{\le}^{\text{\scriptsize{xref}`eq. 3`}}} \frac{1}{t}\sum_{s=1}^{t}X_{s,i}(S') \le\frac{1}{t}\sum_{s=1}^{t}X_{s,i}(S) = \widehat{\mu}_{t,i}^{X(S)}. \tag*{(130)} μ t , i X ( S ′ ) ≤ xref ‘eq. 3‘ t 1 s = 1 ∑ t X s , i ( S ′ ) ≤ t 1 s = 1 ∑ t X s , i ( S ) = μ t , i X ( S ) . (130)
Taking maxima and minima preserves this order. Thus
U ^ i X ( S ′ ) ≤ U ^ i X ( S ) , L ^ i X ( S ′ ) ≤ L ^ i X ( S ) . (131) \widehat{U}_{i}^{X(S')} \le\widehat{U}_{i}^{X(S)}, \qquad\widehat{L}_{i}^{X(S')} \le\widehat{L}_{i}^{X(S)}. \tag*{(131)} U i X ( S ′ ) ≤ U i X ( S ) , L i X ( S ′ ) ≤ L i X ( S ) . (131)
If the pointwise ordering holds for every i ∈ [ n ] i \in[n] i ∈ [ n ] , then
U ^ ( k : I i n , 0 ) X ( S ′ ) ≤ xref‘eq. 40‘ U ^ ( k : I i n , 0 ) X ( S ) , k ∈ [ n 0 ] , L ^ ( k : I i n , 1 ) X ( S ′ ) ≤ xref‘eq. 40‘ L ^ ( k : I i n , 1 ) X ( S ) , k ∈ [ n 1 ] . \widehat{U}^{X(S')}_{(k:I_{\mathrm{in},0})} \mathrel{\mathop{\le}^{\text{\scriptsize{xref}`eq. 40`}}} \widehat{U}^{X(S)}_{(k:I_{\mathrm{in},0})}, \quad k \in[n_0], \qquad\widehat{L}^{X(S')}_{(k:I_{\mathrm{in},1})} \mathrel{\mathop{\le}^{\text{\scriptsize{xref}`eq. 40`}}} \widehat{L}^{X(S)}_{(k:I_{\mathrm{in},1})}, \quad k \in[n_1]. U ( k : I in , 0 ) X ( S ′ ) ≤ xref ‘eq. 40‘ U ( k : I in , 0 ) X ( S ) , k ∈ [ n 0 ] , L ( k : I in , 1 ) X ( S ′ ) ≤ xref ‘eq. 40‘ L ( k : I in , 1 ) X ( S ) , k ∈ [ n 1 ] .
For predicate addition,
ξ t , i R ∪ { ℓ } = xref‘eq. 128‘ ξ t , i R ξ t , i ℓ ≤ ξ t , i R , \xi_{t,i}^{\mathcal{R}\cup\{\ell\}} \mathrel{\mathop{=}^{\text{\scriptsize{xref}`eq. 128`}}} \xi_{t,i}^{\mathcal{R}}\xi_{t,i}^{\ell} \le\xi_{t,i}^{\mathcal{R}}, ξ t , i R ∪ { ℓ } = xref ‘eq. 128‘ ξ t , i R ξ t , i ℓ ≤ ξ t , i R ,
so equation (128) gives the required pointwise ordering. Deleting a rule also cannot increase the disjunction. Adding a rule cannot decrease the disjunction, and removing a predicate cannot decrease its conjunction, provided the conjunction remains nonempty. Interchanging S S S and S ′ S' S ′ in the preceding monotonicity argument gives the reversed inequalities.
For part (5), let R ′ , R ∈ S \mathcal{R}',\mathcal{R} \in S R ′ , R ∈ S with R ′ ⊊ R \mathcal{R}' \subsetneq\mathcal{R} R ′ ⊊ R . Then
ξ t , i R = ξ t , i R ′ ∏ j ∈ R ∖ R ′ ξ t , i j ≤ ξ t , i R ′ ≤ X t , i ( S ∖ { R } ) . \xi_{t,i}^{\mathcal{R}} = \xi_{t,i}^{\mathcal{R}'}\prod_{j\in\mathcal{R}\setminus\mathcal{R}'}\xi_{t,i}^{j} \le\xi_{t,i}^{\mathcal{R}'} \le X_{t,i}(S \setminus\{\mathcal{R}\}). ξ t , i R = ξ t , i R ′ j ∈ R ∖ R ′ ∏ ξ t , i j ≤ ξ t , i R ′ ≤ X t , i ( S ∖ { R }) .
Hence
X t , i ( S ) = X t , i ( S ∖ { R } ) ∨ ξ t , i R = X t , i ( S ∖ { R } ) . X_{t,i}(S) = X_{t,i}(S \setminus\{\mathcal{R}\}) \lor\xi_{t,i}^{\mathcal{R}} = X_{t,i}(S \setminus\{\mathcal{R}\}). X t , i ( S ) = X t , i ( S ∖ { R }) ∨ ξ t , i R = X t , i ( S ∖ { R }) .
Lean 4 Supplement
Lean 4 setup
Section 2, Challenge , pairs the paper’s assumptions and guarantees with their Lean statements. Section 3, Solution , presents the corresponding proofs and their supporting results.
A Challenge states the required proposition with sorry in place of its proof. The corresponding Solution supplies a proof checked by Lean. Comparator checks that the Solution has the same statement and definitions. The mathematical review therefore concerns the displayed assumptions, definitions, and conclusions.
The listings use the common Lean context:
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
open LeBet.StratifiedSample LeBet.SampleVector
For S ⊆ Ω S \subseteq\Omega S ⊆ Ω , Set.Elem S is the type of elements of S S S . It records an element ω \omega ω together with ω ∈ S \omega\in S ω ∈ S .
The proofs may use the following three axioms. Propositional extensionality identifies equivalent propositions:
( P ↔ Q ) ⟹ P = Q . (P \leftrightarrow Q) \Longrightarrow P = Q. ( P ↔ Q ) ⟹ P = Q .
#check propext
Classical choice selects an element of a nonempty type:
choice α : Nonempty ( α ) → α . \operatorname{choice}_{\alpha} : \operatorname{Nonempty}(\alpha) \to\alpha. choice α : Nonempty ( α ) → α .
#check Classical.choice
Quotient soundness identifies related representatives in the quotient:
r ( a , b ) ⟹ [ a ] r = [ b ] r . r(a,b) \Longrightarrow[a]_r = [b]_r. r ( a , b ) ⟹ [ a ] r = [ b ] r .
#check Quot.sound
These logical axioms are separate from the statistical assumptions stated in Challenge.
Challenge
The specification follows the main text. Each mathematical definition or statement is followed by its Lean formulation. Each Lean block states its namespace and variable context; proof lemmas are given in Section 3.
Notation
The Lean names sP, mD, gW, and gS represent P \mathbb{P} P , D D D , W W W , and S S S . Subscripts use underscores, and hats use quoted identifiers such as «ˆX». Vector Ω N represents Ω N \Omega^N Ω N ; Fin N indexes its entries by 0 , … , N − 1 0,\ldots,N-1 0 , … , N − 1 . sP.real A is P ( A ) \mathbb{P}(A) P ( A ) , =m [P] is almost-sure equality, and ⊤ \top ⊤ denotes ∞ \infty ∞ .
Sample space and observed data
Let ( Ω , F ∞ ) (\Omega,\mathcal{F}_{\infty}) ( Ω , F ∞ ) be a measurable space and Y : Ω → { 0 , 1 } Y:\Omega\to\{0,1\} Y : Ω → { 0 , 1 } measurable. Fix n y , m y ≥ 1 n_y,m_y\ge1 n y , m y ≥ 1 and set
Ω y : = { ω : Y ( ω ) = y } , Ω : = Ω 0 n 0 + m 0 × Ω 1 n 1 + m 1 × Ω . \Omega_y := \{\omega: Y(\omega)=y\}, \qquad\Omega:= \Omega_0^{n_0+m_0}\times\Omega_1^{n_1+m_1}\times\Omega. Ω y := { ω : Y ( ω ) = y } , Ω := Ω 0 n 0 + m 0 × Ω 1 n 1 + m 1 × Ω.
namespace LeBet.StratifiedSample
abbrev Ω_0 {Ω : Type*} (Y : Ω → Fin 2) : Set Ω := {ω | Y ω = 0}
abbrev Ω_1 {Ω : Type*} (Y : Ω → Fin 2) : Set Ω := {ω | Y ω = 1}
abbrev mΩ {Ω : Type*} (Y : Ω → Fin 2) (n_0 m_0 n_1 m_1 : N) :=
Vector (Set.Elem (Ω_0 Y)) (n_0 + m_0) ×
Vector (Set.Elem (Ω_1 Y)) (n_1 + m_1) × Ω
end LeBet.StratifiedSample
Put n = n 0 + n 1 n=n_0+n_1 n = n 0 + n 1 and m = m 0 + m 1 m=m_0+m_1 m = m 0 + m 1 . For D = ( ω 1 , … , ω n + m + 1 ) D=(\omega_1,\ldots,\omega_{n+m+1}) D = ( ω 1 , … , ω n + m + 1 ) , let D I D_I D I denote its indexed subvector. Write I i n = ( 1 , … , n ) I_{\mathrm{in}}=(1,\ldots,n) I in = ( 1 , … , n ) and
I i n , y : = { i ∈ [ n ] : Y i = y } , I o u t , y : = { i ∈ [ n + m ] ∖ [ n ] : Y i = y } , I i n / o u t , y : = I i n , y ∪ I o u t , y . I_{\mathrm{in},y}:=\{i\in[n]:Y_i=y\},\qquad I_{\mathrm{out},y}:=\{i\in[n+m]\setminus[n]:Y_i=y\},\qquad I_{\mathrm{in/out},y}:=I_{\mathrm{in},y}\cup I_{\mathrm{out},y}. I in , y := { i ∈ [ n ] : Y i = y } , I out , y := { i ∈ [ n + m ] ∖ [ n ] : Y i = y } , I in/out , y := I in , y ∪ I out , y .
Place the observed trajectories first and ω ⋆ \omega_{\star} ω ⋆ last:
D i n : = ( ω 1 , … , ω n ) , D_{\mathrm{in}} := (\omega_1,\ldots,\omega_n), D in := ( ω 1 , … , ω n ) ,
D o u t : = ( ω n + 1 , … , ω n + m ) , D_{\mathrm{out}} := (\omega_{n+1},\ldots,\omega_{n+m}), D out := ( ω n + 1 , … , ω n + m ) ,
D : = ( D i n , D o u t , ω ⋆ ) . D := (D_{\mathrm{in}},D_{\mathrm{out}},\omega_{\star}). D := ( D in , D out , ω ⋆ ) .
namespace LeBet.StratifiedSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
def mD_in (ω : mΩ Y n_0 m_0 n_1 m_1) : Vector Ω (n_0 + n_1) :=
let (sample_0, sample_1, _) := ω
(observed sample_0).map Subtype.val ++ (observed sample_1).map Subtype.val
def mD_out (ω : mΩ Y n_0 m_0 n_1 m_1) : Vector Ω (m_0 + m_1) :=
let (sample_0, sample_1, _) := ω
(extension sample_0).map Subtype.val ++ (extension sample_1).map Subtype.val
def mD (ω : mΩ Y n_0 m_0 n_1 m_1) :
Vector Ω ((n_0 + n_1) + (m_0 + m_1) + 1) :=
let (_, _, next) := ω
(mD_in ω ++ mD_out ω).push next
end LeBet.StratifiedSample
Equip Ω \Omega Ω with its product σ \sigma σ -algebra and probability law P \mathbb{P} P . For P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_{\star}=y)>0 P ( Y ⋆ = y ) > 0 , write P y : = P ( ⋅ ∣ Y ⋆ = y ) \mathbb{P}_y := \mathbb{P}(\mathord{\cdot}\mid Y_{\star}=y) P y := P ( ⋅ ∣ Y ⋆ = y ) .
Assumption 1: Finite exchangeable extension
Assumption. For each y y y with P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_{\star}=y)>0 P ( Y ⋆ = y ) > 0 ,
π ( D ) = d D under P y , π ∈ Π I i n / o u t , y ∪ { ⋆ } ∪ Π I i n / o u t , 1 − y , \pi(D) \mathrel{\stackrel{d}{=}} D \quad\text{under } \mathbb{P}_y,\qquad\pi\in\Pi_{I_{\mathrm{in/out},y\cup\{\star\}}}\cup\Pi_{I_{\mathrm{in/out},1-y}}, π ( D ) = d D under P y , π ∈ Π I in/out , y ∪ { ⋆ } ∪ Π I in/out , 1 − y ,
where Π I \Pi_I Π I fixes every index outside I I I . Here cond sP (classEvent y) is P y \mathbb{P}_y P y , and map is the pushforward by the indicated permutation.
namespace LeBet.StratifiedSample
variable {Ω : Type*} [MeasurableSpace Ω] {Y : Ω → Fin 2}
{n_0 m_0 n_1 m_1 : ℕ}
def FiniteExchangeableExtension (sP : Measure (mΩ Y n_0 m_0 n_1 m_1)) : Prop :=
(∀ e, (cond sP (JointSample.classEvent 0)).map (JointSample.permuteNext0 e)
= cond sP (JointSample.classEvent 0)) ∧
(∀ e, (cond sP (JointSample.classEvent 0)).map (JointSample.permute1 e) =
cond sP (JointSample.classEvent 0)) ∧
(∀ e, (cond sP (JointSample.classEvent 1)).map (JointSample.permuteNext1 e)
= cond sP (JointSample.classEvent 1)) ∧
(∀ e, (cond sP (JointSample.classEvent 1)).map (JointSample.permute0 e) =
``
cond sP (JointSample.classEvent 1))
end LeBet.StratifiedSample
Monitor and empirical levels
Let F = ( F t ) t ∈ N \mathcal{F} = (\mathcal{F}_t)_{t \in\mathbb{N}} F = ( F t ) t ∈ N be a filtration on Ω \Omega Ω . Fix 1 < T 0 < T 1 1 < T_0 < T_1 1 < T 0 < T 1 and W = { T 0 , … , T 1 } \mathcal{W} = \{T_0, \ldots, T_1\} W = { T 0 , … , T 1 } . A binary monitor is a process ( X t ) t ≥ 1 (X_t)_{t \ge1} ( X t ) t ≥ 1 with X t : Ω → { 0 , 1 } X_t : \Omega\to\{0,1\} X t : Ω → { 0 , 1 } measurable with respect to F t \mathcal{F}_t F t . Lean factor index s s s represents paper time s + 1 s+1 s + 1 . In the monitor blocks, the local variable m Ω \mathsf{m}\Omega m Ω has type MeasurableSpace Ω. It is the measurable structure on a single trajectory.
namespace LeBet
variable {Ω : Type*} {mΩ : MeasurableSpace Ω}
structure BinaryMonitor (gF : Filtration ℕ mΩ) where
X : ℕ → Ω → ℝ
adapted : ∀ s, StronglyMeasurable[gF (s + 1)] (X s)
binary : ∀ s ω, X s ω = 0 ∨ X s ω = 1
end LeBet
Fix the predicate pool Ξ = ( ξ j ) j ∈ [ d ] \Xi= (\xi^j)_{j \in[d]} Ξ = ( ξ j ) j ∈ [ d ] before observing D i n \boldsymbol{D}_{\mathrm{in}} D in . Each ξ j \xi^j ξ j is an adapted binary process. Lean indexes the predicates by 0 , … , d − 1 0,\ldots,d-1 0 , … , d − 1 ; ( Ξ j ) . X s ω (\Xi\ j).X\ s\ \omega ( Ξ j ) . X s ω is ξ s + 1 j + 1 ( ω ) \xi^{j+1}_{s+1}(\omega) ξ s + 1 j + 1 ( ω ) .
section PredicateNotation
variable {Ω : Type*} {mΩ : MeasurableSpace Ω}
{gF : Filtration ℕ mΩ} {d : ℕ}
(Ξ : Fin d → LeBet.BinaryMonitor gF)
local notation "ξ" => fun (j : Fin d) => LeBet.BinaryMonitor.X (Ξ j)
end PredicateNotation
For a nonempty rule R ⊆ [ d ] \mathcal{R} \subseteq[d] R ⊆ [ d ] , define
ξ t R ( ω ) : = ⋀ j ∈ R ξ t j ( ω ) = 1 { ∀ j ∈ R , ξ t j ( ω ) = 1 } . \xi^{\mathcal{R}}_t(\omega) := \bigwedge_{j \in\mathcal{R}} \xi^j_t(\omega) = \mathbb{1}\{\forall j \in\mathcal{R},\ \xi^j_t(\omega)=1\}. ξ t R ( ω ) := j ∈ R ⋀ ξ t j ( ω ) = 1 { ∀ j ∈ R , ξ t j ( ω ) = 1 } .
namespace LeBet.EmpiricalOptimization
variable {Z : Type*} {mZ : MeasurableSpace Z}
{gF : Filtration ℕ mZ} {d : ℕ}
noncomputable def conjunctionValue (Ξ : Fin d → BinaryMonitor gF)
(gR : Finset (Fin d)) (s : ℕ) (z : Z) : ℝ :=
if ∀ j ∈ gR, (Ξ j).X s z = 1 then 1 else 0
end LeBet.EmpiricalOptimization
For K R , K S ≥ 1 K_R, K_S \ge1 K R , K S ≥ 1 , the feasible rule sets form
C : = { S ⊆ 2 [ d ] : ∣ S ∣ ≤ K S , 1 ≤ ∣ R ∣ ≤ K R ∀ R ∈ S } . \mathcal{C} := \{\mathcal{S} \subseteq2^{[d]} : |\mathcal{S}| \le K_S,\ 1 \le|\mathcal{R}| \le K_R\ \forall\mathcal{R} \in\mathcal{S}\}. C := { S ⊆ 2 [ d ] : ∣ S ∣ ≤ K S , 1 ≤ ∣ R ∣ ≤ K R ∀ R ∈ S } .
namespace LeBet.EmpiricalOptimization
abbrev RuleClass (d K_gR K_gS : N) :=
{gS : Finset (Finset (Fin d)) // gS.card ≤ K_gS ∧
∀ gR ∈ gS, gR.Nonempty ∧ gR.card ≤ K_gR}
end LeBet.EmpiricalOptimization
For S ∈ C S \in C S ∈ C , combine the rules by disjunction:
X t ( S ) ( ω ) : = ⋁ R ∈ S ξ t R ( ω ) = 1 { ∃ R ∈ S , ∀ j ∈ R , ξ t j ( ω ) = 1 } . X_t(S)(\omega) := \bigvee_{R \in S} \xi_t^R(\omega) = \mathbf{1}\{\exists R \in S,\ \forall j \in R,\ \xi_t^j(\omega) = 1\}. X t ( S ) ( ω ) := R ∈ S ⋁ ξ t R ( ω ) = 1 { ∃ R ∈ S , ∀ j ∈ R , ξ t j ( ω ) = 1 } .
The empty rule set gives X t ( ∅ ) = 0 X_t(\varnothing) = 0 X t ( ∅ ) = 0 .
namespace LeBet.EmpiricalOptimization
variable {Z : Type*} {mZ : MeasurableSpace Z}
{gF : Filtration N mZ} {d K_gR K_gS : N}
noncomputable def ruleMonitor (Ξ : Fin d → BinaryMonitor gF)
(gS : RuleClass d K_gR K_gS) : BinaryMonitor gF where
X s z := if ∃ gR ∈ gS.val, ∀ i ∈ gR, (Ξ i).X s z = 1 then 1 else 0
adapted s := by
have he : MeasurableSet[gF (s + 1)]
{z | ∃ gR ∈ gS.val, ∀ i ∈ gR, (Ξ i).X s z = 1} := by
convert gS.val.measurableSet_biUnion (fun gR _ =>
gR.measurableSet_biInter (fun i _ =>
measurableSet_eq_fun ((Ξ i).adapted s).measurable
(measurable_const : Measurable[gF (s + 1)] (fun _ : Z => (1 : ℝ)))))
using 1
ext z
simp only [Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_iInter,
exists_prop]
exact (Measurable.ite he measurable_const
measurable_const).stronglyMeasurable
binary s z := by
split_ifs
· exact Or.inr rfl
· exact Or.inl rfl
end LeBet.EmpiricalOptimization
Order statistics count repetitions. For an indexed sample D D D , write v ( k : D ) v_{(k:D)} v ( k : D ) for its kth smallest value.
Leave-one-out fitting and conditional means
Let S ^ ( D ) ∈ C \widehat{S}(D) \in C S ( D ) ∈ C be measurable and invariant under permutations of the training sample, and write X ^ ( D ) : = X ( S ^ ( D ) ) \widehat{X}(D) := X(\widehat{S}(D)) X ( D ) := X ( S ( D )) . The same procedure applies to the remaining class sizes after deletion, returning ∅ \varnothing ∅ if either class is absent. Write D i n / o u t \mathcal{D}_{\mathrm{in/out}} D in/out for the indexed samples drawn from ω 1 , … , ω n + m \omega_1,\ldots,\omega_{n+m} ω 1 , … , ω n + m with n y n_y n y occurrences in each class y y y . Let D − j D^{-j} D − j delete occurrence j j j if present, and equal D D D otherwise.
Write
μ ^ t , i ( D ) : = μ ^ t , i X ( D ) , F i ( D ) : = ( σ ( D , Z u , i ) ) u ≥ 0 . \widehat{\mu}_{t,i}(D) := \widehat{\mu}^{X(D)}_{t,i}, \qquad\mathcal{F}_i(D) := (\sigma(D,Z_{u,i}))_{u\geq0}. μ t , i ( D ) := μ t , i X ( D ) , F i ( D ) := ( σ ( D , Z u , i ) ) u ≥ 0 .
The average conditional mean used in equation (7) is
μ ^ t , y X ( D I ) ( Z t , i ; F i ( D I ) ) = 1 t ∑ s = 1 t E y [ X ^ s ( D I ) ( Z s , i ) ∣ D I , Z s − 1 , i ] . \widehat{\mu}^{X(D_I)}_{t,y}(Z_{t,i};\mathcal{F}_i(D_I)) = \frac{1}{t}\sum_{s=1}^{t}\mathbb{E}_y[\widehat{X}_s(D_I)(Z_{s,i})\mid D_I,Z_{s-1,i}]. μ t , y X ( D I ) ( Z t , i ; F i ( D I )) = t 1 s = 1 ∑ t E y [ X s ( D I ) ( Z s , i ) ∣ D I , Z s − 1 , i ] .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O N)) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
noncomputable def mean (K : Finset (Fin N)) (i : Fin N) (t : ℕ) (ω : Sample Ω
O N) : ℝ :=
(∑ s ∈ range t, conditionalMeanVersion other ho learner rules sP hex s K i
ω) / t
end LeBet.LeaveOneOut
For r = ( r t ) t ∈ W ≥ 0 r=(r_t)_{t\in W}\geq0 r = ( r t ) t ∈ W ≥ 0 , define
s y , i , j ( D ; I , r ) : = max t ∈ W [ ( − 1 ) y μ ^ t , y X ( D I − j ) ( Z t , i ; F i ( D I − j ) ) + r t ] , s_{y,i,j}(D;I,r) := \max_{t\in W}[(-1)^y\widehat{\mu}^{X(D_I^{-j})}_{t,y}(Z_{t,i};\mathcal{F}_i(D_I^{-j}))+r_t], s y , i , j ( D ; I , r ) := t ∈ W max [( − 1 ) y μ t , y X ( D I − j ) ( Z t , i ; F i ( D I − j )) + r t ] ,
s ^ y , i , j ( D ; I , r ) : = max t ∈ W [ ( − 1 ) y μ ^ t , i ( D I − j ) + r t ] . \widehat{s}_{y,i,j}(D;I,r) := \max_{t\in W}[(-1)^y\widehat{\mu}_{t,i}(D_I^{-j})+r_t]. s y , i , j ( D ; I , r ) := t ∈ W max [( − 1 ) y μ t , i ( D I − j ) + r t ] .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O N)) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
noncomputable def s (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) (ω : Sample Ω O N) : ℝ :=
signedMeanValue d gW hne (fun t =>
mean other ho learner rules sP hex (K.erase j) i t ω) r
noncomputable def observedValue (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) (ω : Sample Ω O N) : ℝ :=
signedMeanValue d gW hne
(fun t => (monitor other ho learner rules (K.erase j) i).S t ω / t) r
end LeBet.LeaveOneOut
Leave-one-out stability and rank calibration
For integers k ≥ 1 k \ge1 k ≥ 1 and h ≥ 0 h \ge0 h ≥ 0 , equation 8 defines
Q k , h : = Uniform ( { K ⊆ [ k + h ] : ∣ K ∣ = k } ) . Q_{k,h} := \operatorname{Uniform}\left(\left\{K \subseteq[k+h] : |K| = k\right\}\right). Q k , h := Uniform ( { K ⊆ [ k + h ] : ∣ K ∣ = k } ) .
In Lean, this is subsetLaw on Fin (k + h) with sample size k k k .
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
variable {ι : Type*}
noncomputable def subsetLaw (s : Finset ι) (k : ℕ) (hk : k ≤ s.card) :
Measure[⊤] (Finset ι) := by
letI : MeasurableSpace (Finset ι) := ⊤
exact (PMF.uniformOfFinset (s.powersetCard k) (powersetCard_nonempty.mpr
hk)).toMeasure
end LeBet.FiniteSampling
Let Q π Q_\pi Q π be uniform on the group generated by Π i n / o u t , 0 ∪ Π i n / o u t , 1 \Pi_{\mathrm{in/out},0} \cup\Pi_{\mathrm{in/out},1} Π in/out , 0 ∪ Π in/out , 1 , and write P y , π : = P y ⊗ Q π P_{y,\pi} := P_y \otimes Q_\pi P y , π := P y ⊗ Q π for the independent joint law of ( D , π ) (D,\pi) ( D , π ) . The Lean product uses the coordinate order ( π , D ) (\pi,D) ( π , D ) .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical BigOperators
namespace LeBet.TruncatedCoverage
variable {Ω I : Type*} {mΩ : MeasurableSpace Ω}
[Fintype I] [Nonempty I] [MeasurableSpace I] [DiscreteMeasurableSpace I]
{P : Measure Ω} [IsProbabilityMeasure P]
noncomputable def exchangeLaw (P : Measure Ω) : Measure (I × Ω) :=
(PMF.uniformOfFintype I).toMeasure.prod P
end LeBet.TruncatedCoverage
Write S y , i , j ( D ; I ) : = s y , i , j ( D ; I , 0 ) S_{y,i,j}(\mathbf{D};\mathbf{I}) := s_{y,i,j}(\mathbf{D};\mathbf{I},0) S y , i , j ( D ; I ) := s y , i , j ( D ; I , 0 ) . Let ϵ y , θ y , κ m ∈ [ 0 , 1 ) \epsilon_y,\theta_y,\kappa_m \in[0,1) ϵ y , θ y , κ m ∈ [ 0 , 1 ) and α , β ∈ ( 0 , 1 ) \alpha,\beta\in(0,1) α , β ∈ ( 0 , 1 ) . For D I , D I ′ ∈ D i n / o u t D_I,D_{I'} \in\mathcal{D}_{\mathrm{in/out}} D I , D I ′ ∈ D in/out , define
E I , I ′ m : = ⋂ y ∈ { 0 , 1 } { 1 n y + m y ∑ i ∈ I i n / o u t , y 1 { ∣ S y , i , i ( D ; I ) − S y , i , i ( D ; I ′ ) ∣ > B m } ≤ θ y } . \mathcal{E}^{m}_{I,I'} := \bigcap_{y\in\{0,1\}} \left\{ \frac{1}{n_y+m_y}\sum_{i\in I_{\mathrm{in/out},y}} \mathbf{1}\left\{\left|S_{y,i,i}(\mathbf{D};\mathbf{I})-S_{y,i,i}(\mathbf{D};\mathbf{I}')\right|>B_m\right\}\leq\theta_y \right\}. E I , I ′ m := y ∈ { 0 , 1 } ⋂ ⎩ ⎨ ⎧ n y + m y 1 i ∈ I in/out , y ∑ 1 { ∣ S y , i , i ( D ; I ) − S y , i , i ( D ; I ′ ) ∣ > B m } ≤ θ y ⎭ ⎬ ⎫ .
Assumption 4 requires E Q π P ( ( E π ( I i n ) , I i n m ) c ) ≤ κ m \mathbb{E}^{\mathbb{Q}^\pi}\mathbb{P}\left((\mathcal{E}^{m}_{\pi(I_{\mathrm{in}}),I_{\mathrm{in}}})^c\right)\leq\kappa_m E Q π P ( ( E π ( I in ) , I in m ) c ) ≤ κ m . § 2.3.1 gives its classwise Lean formulation and equation 55.
Put k y = n y − ⌊ n y ϵ y ⌋ k_y=n_y-\lfloor n_y\epsilon_y\rfloor k y = n y − ⌊ n y ϵ y ⌋ and b y = ⌊ ( n y + m y ) θ y ⌋ b_y=\lfloor(n_y+m_y)\theta_y\rfloor b y = ⌊( n y + m y ) θ y ⌋ . For K y = { i 1 < ⋯ < i n y } ∼ Q n y , m y K_y=\{i_1<\cdots<i_{n_y}\}\sim\mathbb{Q}_{n_y,m_y} K y = { i 1 < ⋯ < i n y } ∼ Q n y , m y , set
J K y a = i a + 1 − a − 1 , W y = { min { 1 , ( J K y n y − k y + b y + b y ) / m y } , b y < k y , 1 , b y ≥ k y . J^{a}_{K_y}=i_{a+1}-a-1,\qquad W_y=\begin{cases}
\min\{1,(J^{n_y-k_y+b_y}_{K_y}+b_y)/m_y\}, & b_y<k_y,\\
1, & b_y\geq k_y.
\end{cases} J K y a = i a + 1 − a − 1 , W y = { min { 1 , ( J K y n y − k y + b y + b y ) / m y } , 1 , b y < k y , b y ≥ k y .
namespace LeBet.FiniteSampling
noncomputable def rankCount {N : N} (a : N) (K : Finset (Fin N)) : N :=
if ha : a < K.card then
(Kᶜ.filter fun i => i < K.orderEmbOfFin rfl ⟨a, ha⟩).card
else 0
noncomputable def rankErrorRate (n m r b : N) (K : Finset (Fin (n + m))) : ℝ :=
if r + b < n then min 1 ((rankCount (r + b) K + b : ℝ) / m) else 1
end LeBet.FiniteSampling
For β ∈ ( 0 , 1 ) \beta\in(0,1) β ∈ ( 0 , 1 ) , define
δ y ( β ) : = min 0 ≤ u ≤ 1 { u + E Q n y , m y [ ( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) β } . \delta_y(\beta):=\min_{0\leq u\leq1}\left\{u+\frac{\mathbb{E}_{\mathbb{Q}_{n_y,m_y}}[(W_y-u)_+]+(1-u)\kappa_m/\mathbb{P}(Y_\star=y)}{\beta}\right\}. δ y ( β ) := 0 ≤ u ≤ 1 min { u + β E Q n y , m y [( W y − u ) + ] + ( 1 − u ) κ m / P ( Y ⋆ = y ) } .
namespace LeBet.FiniteSampling
noncomputable def rankExcessMean (n m r b : N) (u : ℝ) : ℝ :=
(∑ K ∈ (univ : Finset (Fin (n + m))).powersetCard n,
max (rankErrorRate n m r b K - u) 0) / (n + m).choose n
noncomputable def rankObjective (n m r b : N) (β κ u : ℝ) : ℝ :=
u + (rankExcessMean n m r b u + (1 - u) * κ) / β
noncomputable def rankErrorBound (n m r b : N) (β κ : ℝ) : ℝ :=
sInf (rankObjective n m r b β κ '' Set.Icc 0 1)
end LeBet.FiniteSampling
Define the error events and counts by equation (12) :
V y , i ( D ; I ) : = { S y , i , i ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y : ( D I ) y ) + 2 B m } , V_{y,i}(D; I) := \left\{S_{y,i,i}(D; I) > \left(S_{y,i,i}(D; I)\right)_{\left(k_y:(D_I)_y\right)} + 2B_m\right\}, V y , i ( D ; I ) := { S y , i , i ( D ; I ) > ( S y , i , i ( D ; I ) ) ( k y : ( D I ) y ) + 2 B m } ,
C y ( D ; I ) : = ∑ i ∈ I i n / o u t , y ∖ I 1 { V y , i ( D ; I ) } . C_y(D; I) := \sum_{i\in\mathcal{I}_{\mathrm{in/out},y}\setminus I} \mathbf{1}\{V_{y,i}(D; I)\}. C y ( D ; I ) := i ∈ I in/out , y ∖ I ∑ 1 { V y , i ( D ; I )} .
Observable levels and betting parameters
Write a t ( ϵ ) : = 2 log ( 1 / ϵ ) / t a_t(\epsilon) := \sqrt{2\log(1/\epsilon)/t} a t ( ϵ ) := 2 log ( 1/ ϵ ) / t and r ( ϵ ) : = ( r t ( ϵ ) ) t ∈ W r(\epsilon) := (r_t(\epsilon))_{t\in W} r ( ϵ ) := ( r t ( ϵ ) ) t ∈ W , where
r t ( ϵ ) = min { 1 + T 0 / t 4 a T 0 ( ϵ / 2 ) , 1 2 a t ( ϵ / ( 2 ∣ W ∣ ) ) } . r_t(\epsilon) = \min\left\{\frac{1+T_0/t}{4}a_{T_0}(\epsilon/2),\frac{1}{2}a_t(\epsilon/(2|W|))\right\}. r t ( ϵ ) = min { 4 1 + T 0 / t a T 0 ( ϵ /2 ) , 2 1 a t ( ϵ / ( 2∣ W ∣ )) } .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
noncomputable def meanRadius (β : ℝ) (gW : Finset ℕ) (T₀ t : ℕ) : ℝ :=
min ((1 + (T₀ : ℝ) / t) / 2 * averageRadius (β / 2) T₀) (averageRadius (β /
(2 * gW.card)) t)
end LeBet
The observable bound in equation (13) is
q ^ y : = min { 1 − y , ( s ^ y , i , i ( D ; I i n , r ( β 2 n y ) ) ) ( k y : D i n , y ) + 2 B m } . \widehat{q}_y := \min\left\{1-y,\left(\widehat{s}_{y,i,i}\left(D; I_{\mathrm{in}},r\left(\frac{\beta}{2n_y}\right)\right)\right)_{\left(k_y:D_{\mathrm{in},y}\right)}+2B_m\right\}. q y := min { 1 − y , ( s y , i , i ( D ; I in , r ( 2 n y β ) ) ) ( k y : D in , y ) + 2 B m } .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : ℕ}
variable (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration ℕ (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : R) (gW : Finset ℕ) (hne : gW.Nonempty)
section Probability
variable (K₀ : Finset (Fin (n + m))) (hK₀ : K₀.card = n) (hm : 0 < m)
(r : N) (hr : r < n)
local notation "u" => values other ho learner rules sP hex d gW hne
local notation "v" => nextValue other ho learner rules sP hex d gW hne K₀
local notation "gFin" => information (Ω := Ω) other (pool K₀)
variable {A : Type*} [Fintype A] [Nonempty A]
(otherAct : A → Sample Ω O (n + m + 1) ≃ₘ Sample Ω O (n + m + 1))
(hother : ∀ a, MeasurePreserving (otherAct a) sP sP)
{B κ : ℝ} {b : ℕ} (hκ : 0 ≤ κ)
(hfail : OccurrenceCalibration.averageFailure (sP := sP)
(values other ho learner rules sP hex d gW hne) K₀ otherAct B b ≤ κ)
noncomputable def calibratedLevel (β cap B : ℝ) (T₀ : ℕ) :
Sample Ω O (n + m + 1) → ℝ :=
PredictableLearning.meanLevel (trainingMonitor other ho learner rules K₀ hK₀)
gW hne (T₀ := T₀) β d cap r hr B
end Probability
end LeBet.LeaveOneOut
The deployment parameters use the full-fit empirical extrema
U ^ i X ^ ( D ) = max t ∈ W μ ^ t , i ( D ) , L ^ i X ^ ( D ) = min t ∈ W μ ^ t , i ( D ) . \widehat{U}^{\widehat{X}(D)}_i = \max_{t\in W}\widehat{\mu}_{t,i}(D),\qquad
\widehat{L}^{\widehat{X}(D)}_i = \min_{t\in W}\widehat{\mu}_{t,i}(D). U i X ( D ) = t ∈ W max μ t , i ( D ) , L i X ( D ) = t ∈ W min μ t , i ( D ) .
namespace LeBet.BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration ℕ mΩ}
(X : BinaryMonitor gF)
noncomputable def «Û» (gW : Finset ℕ) (hne : gW.Nonempty) (ω : Ω) : ℝ :=
gW.sup’ hne fun t => X.S t ω / t
noncomputable def «L̂» (gW : Finset ℕ) (hne : gW.Nonempty) (ω : Ω) : ℝ :=
gW.inf’ hne fun t => X.S t ω / t
end LeBet.BinaryMonitor
Write Δ ^ ( D ) : = [ L ^ ( n 1 − k 1 + 1 : D 1 ) X ^ ( D ) − U ^ ( k 0 : D 0 ) X ^ ( D ) ] + \widehat{\Delta}(D) := [\widehat{L}^{\widehat{X}(D)}_{(n_1-k_1+1:D_1)}-\widehat{U}^{\widehat{X}(D)}_{(k_0:D_0)}]_+ Δ ( D ) := [ L ( n 1 − k 1 + 1 : D 1 ) X ( D ) − U ( k 0 : D 0 ) X ( D ) ] + . If Δ ^ ( D ) > 0 \widehat{\Delta}(D)>0 Δ ( D ) > 0 , set
p ^ 0 : = U ^ ( k 0 : D 0 ) X ^ ( D ) , p ^ 1 : = L ^ ( n 1 − k 1 + 1 : D 1 ) X ^ ( D ) , p ^ : = ( p ^ 0 + p ^ 1 ) / 2. \widehat{p}_0 := \widehat{U}^{\widehat{X}(D)}_{(k_0:D_0)},\qquad
\widehat{p}_1 := \widehat{L}^{\widehat{X}(D)}_{(n_1-k_1+1:D_1)},\qquad
\widehat{p} := (\widehat{p}_0+\widehat{p}_1)/2. p 0 := U ( k 0 : D 0 ) X ( D ) , p 1 := L ( n 1 − k 1 + 1 : D 1 ) X ( D ) , p := ( p 0 + p 1 ) /2.
namespace LeBet
noncomputable def empiricalGap (p_0 p_1 : ℝ) : ℝ := max (p_1 - p_0) 0
noncomputable def midpointReference (p_0 p_1 : ℝ) : ℝ := (p_0 + p_1) / 2
end LeBet
With v ( p ) : = 1 / 4 − [ p − 1 / 2 ] + 2 v(p) := 1/4 - [p - 1/2]^2_{+} v ( p ) := 1/4 − [ p − 1/2 ] + 2 , put λ ^ : = a T 1 ( α ) / v ( p ^ ) \hat{\lambda} := a_{T_1}(\alpha)/\sqrt{v(\hat{p})} λ ^ := a T 1 ( α ) / v ( p ^ ) . Otherwise, set ( p ^ , λ ^ ) : = ( 1 , 1 ) (\hat{p}, \hat{\lambda}) := (1,1) ( p ^ , λ ^ ) := ( 1 , 1 ) .
namespace LeBet
noncomputable def bernoulliVarianceBound (p : ℝ) : ℝ :=
1 / 4 - max (p - 1 / 2) 0 ^ 2
end LeBet
namespace LeBet
noncomputable def calibratedStake (p α : ℝ) (T : ℕ) : ℝ :=
Real.sqrt (2 * Real.log (1 / α) / T) / Real.sqrt (bernoulliVarianceBound p)
end LeBet
Write ψ λ ( p ) : = log ( 1 − p + p e λ ) \psi_{\lambda}(p) := \log(1 - p + p e^{\lambda}) ψ λ ( p ) := log ( 1 − p + p e λ ) and use the Bernoulli KL divergence.
namespace LeBet
noncomputable def psi («λ» u : ℝ) : ℝ := Real.log (1 - u + u * Real.exp «λ»)
noncomputable def kl (p q : ℝ) : ℝ :=
p * Real.log (p / q) + (1 - p) * Real.log ((1 - p) / (1 - q))
end LeBet
For the deployed monitor X ^ ( D i n ) \hat{X}(\mathcal{D}_{\mathrm{in}}) X ^ ( D in ) , set
E t ( λ , p ) : = exp { λ ∑ s = 1 t X s − t ψ λ ( p ) } , τ ( λ , p ) : = inf { t ∈ N : E t ( λ , p ) ≥ 1 / α } . E_t(\lambda,p) := \exp\left\{\lambda\sum_{s=1}^{t}X_s-t\psi_{\lambda}(p)\right\}, \qquad\tau(\lambda,p) := \inf\{t\in\mathbb{N}: E_t(\lambda,p)\ge1/\alpha\}. E t ( λ , p ) := exp { λ s = 1 ∑ t X s − t ψ λ ( p ) } , τ ( λ , p ) := inf { t ∈ N : E t ( λ , p ) ≥ 1/ α } .
namespace LeBet.BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration N mΩ}
(X : BinaryMonitor gF)
noncomputable def E («λ» p : R) (t : N) (ω : Ω) : R :=
∏ s ∈ range t, (1 + (Real.exp «λ» - 1) * X.X s ω) /
(1 + (Real.exp «λ» - 1) * p)
noncomputable def τ («λ» p α : R) (gW : Finset N) (ω : Ω) : WithTop N :=
(gW.filter fun t => 1 / α ≤ X.E «λ» p t ω).min
end LeBet.BinaryMonitor
The error terms are those of equation (5) :
e 0 ( p ; λ , q , α ) : = α exp ( T 1 [ ψ λ ( p ) − ψ λ ( q ) ] + − T 0 [ ψ λ ( q ) − ψ λ ( p ) ] + ) , e_0(p;\lambda,q,\alpha) := \alpha\exp\left(T_1[\psi_\lambda(p)-\psi_\lambda(q)]_+ - T_0[\psi_\lambda(q)-\psi_\lambda(p)]_+\right), e 0 ( p ; λ , q , α ) := α exp ( T 1 [ ψ λ ( p ) − ψ λ ( q ) ] + − T 0 [ ψ λ ( q ) − ψ λ ( p ) ] + ) ,
e 1 , t ( p ; λ , q , α ) : = exp ( − t D K L ( Ber ( min { p , λ − 1 { ψ λ ( q ) + a t ( α ) 2 / 2 } } ) ∥ Ber ( p ) ) ) . e_{1,t}(p;\lambda,q,\alpha) := \exp\left(-tD_{\mathrm{KL}}\left(\operatorname{Ber}\left(\min\{p,\lambda^{-1}\{\psi_\lambda(q)+a_t(\alpha)^2/2\}\}\right)\mathbin{\|}\operatorname{Ber}(p)\right)\right). e 1 , t ( p ; λ , q , α ) := exp ( − t D KL ( Ber ( min { p , λ − 1 { ψ λ ( q ) + a t ( α ) 2 /2 }} ) ∥ Ber ( p ) ) ) .
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
noncomputable def typeIError (p z q α : R) (T0 T1 : N) : R :=
α * Real.exp (T1 * max (psi z p - psi z q) 0 - T0 * max (psi z q - psi z p)
0)
noncomputable def bernoulliTailError (h p : R) (t : N) : R :=
if h ≤ 0 then 0 else if p ≤ h then 1 else if 1 ≤ p then 0 else Real.exp
(-(t : ℝ) * kl h p)
noncomputable def detectionError (p z q α : R) (t : N) : R :=
bernoulliTailError (z⁻¹
* (psi z q + Real.log (1 / α) / t)) p t
end LeBet
Learned intervention guarantees
Assume finite exchangeable extension, leave-one-out stability, P ( Y ⋆ = y ) > 0 \mathbb{P}(Y_\star= y) > 0 P ( Y ⋆ = y ) > 0 , and a measurable, permutation-invariant selector. Let τ ^ : = τ ( λ ^ , p ^ ) \widehat{\tau} := \tau(\widehat{\lambda},\widehat{p}) τ := τ ( λ , p ) . The following Lean context specifies the variables and hypotheses. § 2.3.1 gives the coordinate construction and notation correspondence.
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : N} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K₀ : Finset (Fin (n + m))) (hK₀ : K₀.card = n) (hm : 0 < m)
(r : ℕ) (hr : r < n)
local notation "u" => values other ho learner rules sP hex d gW hne
local notation "v" => nextValue other ho learner rules sP hex d gW hne K₀
local notation "gFin" => information (Ω := Ω) other (pool K₀)
variable {A : Type*} [Fintype A] [Nonempty A]
(otherAct : A → Sample Ω O (n + m + 1) ≃ᵐ Sample Ω O (n + m + 1))
(hother : ∀ a, MeasurePreserving (otherAct a) sP sP)
{B κ : ℝ} {b : ℕ} (hκ : 0 ≤ κ)
(hfail : OccurrenceCalibration.averageFailure (sP := sP)
(values other ho learner rules sP hex d gW hne) K₀ otherAct B b ≤ κ)
{z p : Sample Ω O (n + m + 1) → ℝ}
(hz : StronglyMeasurable[information other (pool K₀)] z)
(hp : StronglyMeasurable[information other (pool K₀)] p)
(hp0 : ∀ ω, 0 ≤ p ω)
{T₀ : ℕ} (hT₀ : 0 < T₀) (hW₀ : ∀ t ∈ gW, T₀ ≤ t)
Part (1) of Theorem 5 states
P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) = E y [ C y ( D ; I i n ) m y ∣ D i n ] P y -almost surely . \mathbb{P}_y\left(\mathcal{V}_{y,\star}(D; I_{\mathrm{in}}) \mid D_{\mathrm{in}}\right)
= \mathbb{E}_y\left[\frac{C_y(D; I_{\mathrm{in}})}{m_y} \mid D_{\mathrm{in}}\right]
\quad\mathbb{P}_y\text{-almost surely}. P y ( V y , ⋆ ( D ; I in ) ∣ D in ) = E y [ m y C y ( D ; I in ) ∣ D in ] P y -almost surely .
include hK₀ hm in
theorem challenge_conditional_error_identity (B : ℝ) :
sP[(fun ω => extensionErrorRate m (u ω) (OccurrenceCalibration.level u r
hr ω) B K₀) | gFin]
=ᵐ[sP] ConditionalCoverage.conditionalProbability sP gFin
{ω | OccurrenceCalibration.level u r hr ω K₀ + 2 * B < v ω} := by
sorry
Part (2), for s > 0 s > 0 s > 0 , states
P y ( C y ( D ; I i n ) m y > ϵ y + θ y ( n y + m y ) 2 n y m y + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + κ m P ( Y ⋆ = y ) . \mathbb{P}_y\left(
\frac{C_y(D; I_{\mathrm{in}})}{m_y}
> \epsilon_y + \theta_y \frac{(n_y + m_y)^2}{n_y m_y} + s
\right)
\le e^{-2n_y m_y s^2/(n_y+m_y+2)}
+ \frac{\kappa_m}{\mathbb{P}(Y_\star= y)}. P y ( m y C y ( D ; I in ) > ϵ y + θ y n y m y ( n y + m y ) 2 + s ) ≤ e − 2 n y m y s 2 / ( n y + m y + 2 ) + P ( Y ⋆ = y ) κ m .
include hK₀ hm hother hfail in
theorem challenge_extension_tail {ε θ z : ℝ}
(hrε : (r : ℝ) ≤ n * ε) (hbθ : (b : ℝ) ≤ (n + m) * θ) (hz : 0 < z) :
sP.real {ω | ε + θ * (n + m) ˆ 2 / (n * m) + z <
extensionErrorRate m (u ω) (OccurrenceCalibration.level u r hr ω) B K₀}
≤
Real.exp (-2 * n * m * z ˆ 2 / (n + m + 2)) + κ := by
sorry
Part (3) states P y ( P y ( V y , ⋆ ( D ; I i n ) ∣ D i n ) > δ y ( β ) ) ≤ β \mathbb{P}_y(\mathbb{P}_y(\mathcal{V}_{y,\star}(D; I_{\mathrm{in}}) \mid D_{\mathrm{in}}) > \delta_y(\beta)) \le\beta P y ( P y ( V y , ⋆ ( D ; I in ) ∣ D in ) > δ y ( β )) ≤ β .
include hK₀ hm hother hκ hfail in
theorem challenge_error_coverage {β : ℝ} (hb : 0 < β) :
sP.real {ω | rankErrorBound n m r b β κ <
ConditionalCoverage.conditionalProbability sP gFin
{ω | OccurrenceCalibration.level u r hr ω K₀ + 2 * B < v ω} ω} ≤ β := by
sorry
Part (4) states
P 0 ( P 0 ( τ ^ < ∞ ∣ D i n ) > δ 0 ( β / 2 ) + e 0 ( q ^ 0 ; λ ^ , p ^ , α ) ) ≤ β . \mathbb{P}_0\left(\mathbb{P}_0(\widehat{\tau}<\infty\mid D_{\mathrm{in}})>\delta_0(\beta/2)+e_0(\widehat{q}_0;\widehat{\lambda},\widehat{p},\alpha)\right)\leq\beta. P 0 ( P 0 ( τ < ∞ ∣ D in ) > δ 0 ( β /2 ) + e 0 ( q 0 ; λ , p , α ) ) ≤ β .
include hK₀ hm hother hκ hfail hz hp hp0 hT₀ hW₀ in
theorem challenge_false_intervention (hd : d = 1) {α β : ℝ} (ha : 0 < α)
(hb : 0 < β) (hb1 : β < 1) (hz0 : ∀ ω, 0 ≤ z ω)
(T₁ : ℕ) (hW₁ : ∀ t ∈ gW, t ≤ T₁) :
sP.real {ω | rankErrorBound n m r b (β / 2) κ +
typeIError (calibratedLevel other ho learner rules d gW hne K₀ hK₀ r hr β
1 B T₀ ω)
(z ω) (p ω) α T₀ T₁ <
ConditionalCoverage.conditionalProbability sP gFin
{ω | (deployedMonitor other ho learner rules K₀).τ (z ω) (p ω) α gW ω
< ⊤} ω} ≤ β := by
sorry
Part (5) states
P 1 ( ∃ t ∈ W : P 1 ( τ ^ > t ∣ D i n ) > δ 1 ( β / 2 ) + e 1 , t ( − q ^ 1 ; λ ^ , p ^ , α ) ) ≤ β . \mathbb{P}_1\left(\exists t\in\mathcal{W}:\mathbb{P}_1(\widehat{\tau}>t\mid D_{\mathrm{in}})>\delta_1(\beta/2)+e_{1,t}(-\widehat{q}_1;\widehat{\lambda},\widehat{p},\alpha)\right)\leq\beta. P 1 ( ∃ t ∈ W : P 1 ( τ > t ∣ D in ) > δ 1 ( β /2 ) + e 1 , t ( − q 1 ; λ , p , α ) ) ≤ β .
include hK₀ hm hother hκ hfail hz hp hp0 hT₀ hW₀ in
theorem challenge_detection (hd : d = -1) {α β : ℝ} (ha : 0 < α)
(hb : 0 < β) (hb1 : β < 1) (hz0 : ∀ ω, 0 < z ω) :
sP.real {ω | ∃ t ∈ gW, rankErrorBound n m r b (β / 2) κ +
detectionError (-(calibratedLevel other ho learner rules d gW hne K₀ hK₀
r hr β 0 B T₀ ω))
(z ω) (p ω) α t <
ConditionalCoverage.conditionalProbability sP gFin
{ω | ¬ (deployedMonitor other ho learner rules K₀).τ (z ω) (p ω) α gW
ω ≤ t} ω} ≤ β := by
sorry
Solution
The setup collects the coordinate definitions and interface conversions. The remaining proofs follow the main appendix.
Sample coordinates and leave-one-out setup
Coordinates carry the product measurable structure.
namespace LeBet.SampleVector
variable {α : Type*} {n : ℕ}
def coordinates (xs : Vector α n) : Fin n → α := fun i => xs[i.val]
instance vectorMeasurableSpace [MeasurableSpace α] : MeasurableSpace (Vector α n) :=
MeasurableSpace.comap coordinates inferInstance
end LeBet.SampleVector
The first class entries are observed; the remaining entries form the extension.
namespace LeBet.StratifiedSample
def gI_in_y (n_y m_y : ℕ) : Finset (Fin (n_y + m_y)) :=
univ.map (Fin.castAddEmb m_y)
end LeBet.StratifiedSample
The embeddings preserve training indices and offset extension indices.
section SampleIndexNotation
variable (n_y m_y : ℕ)
local notation "I_in_y" => gI_in_y n_y m_y
local notation "I_out_y" => I_in_yᶜ
local notation "I_y" => I_in_y ∪ I_out_y
end SampleIndexNotation
Extract the observed and extension vectors in their original order.
namespace LeBet.SampleVector
variable {α : Type*} {n m : ℕ}
def observed (xs : Vector α (n + m)) : Vector α n :=
(xs.take n).cast (by omega)
def extension (xs : Vector α (n + m)) : Vector α m :=
(xs.drop n).cast (by omega)
end LeBet.SampleVector
The next-label event is encoded by JointSample.classEvent.
namespace LeBet.StratifiedSample.JointSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
def classEvent (y : Fin 2) : Set (mΩ Y n_0 m_0 n_1 m_1) :=
{ω | Y ω.2.2 = y}
end LeBet.StratifiedSample.JointSample
The class-conditional law and training sigma-algebra are represented below.
section SampleLawNotation
variable {Ω : Type*} [MeasurableSpace Ω] {Y : Ω → Fin 2}
{n_0 m_0 n_1 m_1 : ℕ}
(sP : Measure (mΩ Y n_0 m_0 n_1 m_1)) [IsProbabilityMeasure sP]
(y : Fin 2)
local notation "π_y" => sP.real (JointSample.classEvent y)
local notation "sP_y" => cond sP (JointSample.classEvent y)
local notation "gF_in" =>
MeasurableSpace.comap
(mD_in (Y := Y) (n_0 := n_0) (m_0 := m_0)
(n_1 := n_1) (m_1 := m_1)) inferInstance
variable (hπ : 0 < π_y)
end SampleLawNotation
Permute one class and keep the other class and next trajectory fixed.
namespace LeBet.StratifiedSample.JointSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
def permute0 (e : Equiv.Perm (Fin (n_0 + m_0))) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 :=
let (sample_0, sample_1, next) := ω
(Vector.ofFn (fun i => sample_0[(e i).val]), sample_1, next)
def permute1 (e : Equiv.Perm (Fin (n_1 + m_1))) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 :=
let (sample_0, sample_1, next) := ω
(sample_0, Vector.ofFn (fun i => sample_1[(e i).val]), next)
end LeBet.StratifiedSample.JointSample
The next-trajectory permutation acts on the corresponding label event.
namespace LeBet.StratifiedSample.JointSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
noncomputable def permuteNext0 (e : Equiv.Perm (Fin (n_0 + m_0 + 1)))
(ω : mΩ Y n_0 m_0 n_1 m_1) : mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 0
· let next_0 : Set.Elem (Ω_0 Y) := ⟨next, mem_Ω_0.mpr h⟩
let pool := sample_0.push next_0
let updated := Vector.ofFn (fun i : Fin (n_0 + m_0) => pool[(e
i.castSucc).val])
let next := pool[(e (Fin.last (n_0 + m_0))).val]
exact (updated, sample_1, next.val)
· exact (sample_0, sample_1, next)
noncomputable def permuteNext1 (e : Equiv.Perm (Fin (n_1 + m_1 + 1)))
(ω : mΩ Y n_0 m_0 n_1 m_1) : mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 1
· let next_1 : Set.Elem (Ω_1 Y) := ⟨next, mem_Ω_1.mpr h⟩
let pool := sample_1.push next_1
let updated := Vector.ofFn (fun i : Fin (n_1 + m_1) => pool[(e
i.castSucc).val])
let next := pool[(e (Fin.last (n_1 + m_1))).val]
exact (sample_0, updated, next.val)
· exact (sample_0, sample_1, next)
end LeBet.StratifiedSample.JointSample
Sum the monitor observations up to the specified time.
namespace LeBet.BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration ℕ mΩ}
(X : BinaryMonitor gF)
noncomputable def S (t : ℕ) (ω : Ω) : ℝ := ∑ s ∈ range t, X.X s ω
end LeBet.BinaryMonitor
The Lean field BinaryMonitor.μ is a bounded one-step conditional mean. The manuscript uses its time average.
open MeasureTheory ProbabilityTheory Filter Finset
namespace LeBet
variable {Ω : Type*} {mΩ : MeasurableSpace Ω}
namespace BinaryMonitor
variable {gF : Filtration ℕ mΩ} (X : BinaryMonitor gF)
(sP : Measure Ω) [IsProbabilityMeasure sP]
noncomputable def μ (s : ℕ) (ω : Ω) : ℝ :=
max 0 (min 1 (sP[X.X s | gF s] ω))
end BinaryMonitor
end LeBet
The compensator sums these one-step conditional means.
open MeasureTheory ProbabilityTheory Filter Finset
namespace LeBet
variable {Ω : Type*} {mΩ : MeasurableSpace Ω}
namespace BinaryMonitor
variable {gF : Filtration ℕ mΩ} (X : BinaryMonitor gF)
(sP : Measure Ω) [IsProbabilityMeasure sP]
noncomputable def A (t : ℕ) (ω : Ω) : ℝ := ∑ s ∈ range t, X.μ sP s ω
end BinaryMonitor
end LeBet
Quantiles count repetitions and use the integer violation budget.
namespace LeBet.EmpiricalOptimization
noncomputable def upperQuantile {n : N} (a : Fin n → R) (r : N) (hr : r < n)
: R :=
a (Tuple.sort a ⟨n - r - 1, by omega⟩)
noncomputable def lowerQuantile {n : N} (a : Fin n → R) (r : N) (hr : r < n)
: R :=
a (Tuple.sort a ⟨r, hr⟩)
end LeBet.EmpiricalOptimization
The floor of the empirical error budget gives the permitted number of violations.
namespace LeBet
lemma floor_error_budget {k : N} (hk : 0 < k) {ε : R}
(he0 : 0 ≤ ε) (he1 : ε < 1) :
(Nat.floor ((k : R) * ε) : R) ≤ k * ε ∧
Nat.floor ((k : R) * ε) < k := by
have hk’ : (0 : R) < k := by exact_mod_cast hk
have hprod : 0 ≤ (k : R) * ε := mul_nonneg hk’.le he0
refine ⟨Nat.floor_le hprod, (Nat.floor_lt hprod).mpr ?_⟩
nlinarith
end LeBet
Classwise representation. Lean treats one class at a time. The types O and R store the other class and its training data. The map other extracts that training data. The learner is measurable and permutation-invariant at each reduced sample size.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : N}
abbrev Sample (Ω O : Type*) (N : N) := (Fin N → Ω) × O
structure Learner (Ω R C : Type*) [MeasurableSpace Ω] [MeasurableSpace R]
[MeasurableSpace C] where
fit : (k : N) → ((Fin k → Ω) × R) → C
measurable : ∀ k, Measurable (fit k)
invariant : ∀ k (e : Equiv.Perm (Fin k)) d,
fit k (d.1 ∘ e, d.2) = fit k d
end LeBet.LeaveOneOut
Permute one class and keep the other class fixed.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ}
def permute (e : Equiv.Perm (Fin N)) : Sample Ω O N ≃ᵐ Sample Ω O N where
toFun ω := (ω.1 ∘ e, ω.2)
invFun ω := (ω.1 ∘ e.symm, ω.2)
left_inv ω := by ext i <;> simp
right_inv ω := by ext i <;> simp
measurable_toFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e i)).comp
measurable_fst).prodMk
measurable_snd
measurable_invFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e.symm i)).comp
measurable_fst).prodMk
measurable_snd
end LeBet.LeaveOneOut
Append the next trajectory as the last coordinate of the evaluated class.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open StratifiedSample.JointSample (fixLast fixLast_castSucc fixLast_last)
variable {Ω O : Type*} [MeasurableSpace Ω] [MeasurableSpace O] {N : ℕ}
def appendNext : ((Fin N → Ω) × O × Ω) ≃ᵐ Sample Ω O (N + 1) where
toFun ω := (Fin.snoc ω.1 ω.2.2, ω.2.1)
invFun ω := ((fun i => ω.1 i.castSucc), ω.2, ω.1 (Fin.last N))
left_inv ω := by ext i <;> simp
right_inv ω := by
apply Prod.ext
· funext i
refine Fin.lastCases ?_ (fun i => ?_) i <;> simp
· rfl
measurable_toFun := by
refine (measurable_pi_iff.mpr ?_).prodMk measurable_snd.fst
intro i
refine Fin.lastCases ?_ (fun j => ?_) i
· simpa only [Fin.snoc_last] using
(measurable_snd.snd : Measurable fun ω : (Fin N → Ω) × O × Ω => ω
.2.2)
· simpa only [Fin.snoc_castSucc, Function.comp_def] using
(measurable_pi_apply j).comp
(measurable_fst : Measurable fun ω : (Fin N → Ω) × O × Ω => ω.1)
measurable_invFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply i.castSucc).comp
measurable_fst).prodMk
(measurable_snd.prodMk ((measurable_pi_apply (Fin.last N)).comp
measurable_fst))
end LeBet.LeaveOneOut
Separate the two class blocks and the next trajectory.
open MeasureTheory ProbabilityTheory Finset
open scoped Classical
open LeBet.SampleVector
namespace LeBet.StratifiedSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
section Measurability
variable [MeasurableSpace Ω]
end Measurability
namespace JointSample
def class0 (ω : mΩ Y n_0 m_0 n_1 m_1) :
(Fin (n_0 + m_0) → Ω) × (Fin (n_1 + m_1) → Ω) × Ω :=
(fun i => (ω.1[i.val]).val, fun i => (ω.2.1[i.val]).val, ω.2.2)
def class1 (ω : mΩ Y n_0 m_0 n_1 m_1) :
(Fin (n_1 + m_1) → Ω) × (Fin (n_0 + m_0) → Ω) × Ω :=
(fun i => (ω.2.1[i.val]).val, fun i => (ω.1[i.val]).val, ω.2.2)
end JointSample
end LeBet.StratifiedSample
The composed maps give the classwise sample used by the LOO proofs.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open StratifiedSample.JointSample (fixLast fixLast_castSucc fixLast_last)
variable {Ω O : Type*} [MeasurableSpace Ω] [MeasurableSpace O] {N : ℕ}
section Joint
open StratifiedSample
variable {Y : Ω → Fin 2} {n₀ m₀ n₁ m₁ : ℕ}
(P : Measure (mΩ Y n₀ m₀ n₁ m₁)) (hY : Measurable Y)
(hex : FiniteExchangeableExtension P)
def class0Coordinates (ω : mΩ Y n₀ m₀ n₁ m₁) :
Sample Ω (Fin (n₁ + m₁) → Ω) (n₀ + m₀ + 1) :=
appendNext (JointSample.class0 ω)
def class1Coordinates (ω : mΩ Y n₀ m₀ n₁ m₁) :
Sample Ω (Fin (n₀ + m₀) → Ω) (n₁ + m₁ + 1) :=
appendNext (JointSample.class1 ω)
end Joint
end LeBet.LeaveOneOut
The set K selects training occurrences in the evaluated class. Together with other, it determines the fitting sample and training information.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ}
variable (other : O → R) (ho : Measurable other)
noncomputable def training (K : Finset (Fin N)) (ω : Sample Ω O N) :
(Fin K.card → Ω) × R :=
((fun i ↦ ω.1 (K.orderEmbOfFin rfl i)), other ω.2)
def information (K : Finset (Fin N)) : MeasurableSpace (Sample Ω O N) :=
(⨆ i ∈ K, MeasurableSpace.comap (fun ω : Sample Ω O N => ω.1 i)
inferInstance) ⊔
MeasurableSpace.comap (fun ω : Sample Ω O N => other ω.2) inferInstance
end LeBet.LeaveOneOut
The filtration combines the fitting sample with the evaluated trajectory’s observed history.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : N}
variable (other : O → R) (ho : Measurable other)
variable (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
def filtration (K : Finset (Fin N)) (i : Fin N) :
Filtration N (inferInstance : MeasurableSpace (Sample Ω O N)) where
seq t := information other K ⊔
MeasurableSpace.comap (fun ω : Sample Ω O N => ω.1 i) (gF t)
mono’ _ _ h := sup_le_sup_left (MeasurableSpace.comap_mono (gF.mono h)) _
le’ t := sup_le (information_le other ho K)
((MeasurableSpace.comap_mono (gF.le t)).trans
((measurable_pi_apply i).comp measurable_fst).comap_le)
end LeBet.LeaveOneOut
Fit on the selected training sample and evaluate the specified trajectory.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : N}
variable (other : O → R) (ho : Measurable other)
variable (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
noncomputable def monitor (K : Finset (Fin N)) (i : Fin N) :
BinaryMonitor (filtration other ho (gF := gF) K i) where
X s ω := (rules (learner.fit K.card (training other K ω))).X s (ω.1 i)
adapted s := by
let M := (filtration other ho (gF := gF) K i) (s + 1)
have hfit : Measurable[M] (fun ω => learner.fit K.card (training other K ω
)) :=
((learner.measurable _).comp (training_information_measurable other
K)).mono le_sup_left le_rfl
have hx (c : C) : Measurable[M] (fun ω : Sample Ω O N => (rules c).X s
(ω.1 i)) :=
(((rules c).adapted s).measurable.comp (comap_measurable _)).mono
le_sup_right le_rfl
have he : @Measurable (Sample Ω O N × C) R (M.prod inferInstance)
inferInstance
(fun p => (rules p.2).X s (p.1.1 i)) :=
measurable_from_prod_countable_left hx
exact (he.comp (measurable_id.prodMk hfit)).stronglyMeasurable
binary s ω := (rules (learner.fit K.card (training other K ω))).binary s
(ω.1 i)
end LeBet.LeaveOneOut
Finite averaging constructs bounded conditional-mean versions with exact permutation symmetry.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O N)) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
noncomputable def conditionalMeanVersion (s : N) (K : Finset (Fin N)) (i :
Fin N) :
Sample Ω O N → R :=
Classical.choose (conditional_versions_exist other ho learner rules sP hex
s) (K, i)
end LeBet.LeaveOneOut
Take the temporal maximum of signed means with the supplied radius.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
noncomputable def signedMeanValue (d : R) (gW : Finset N) (hne : gW.Nonempty)
(µ r : N → R) : R :=
gW.sup’ hne fun t => d * µ t + r t
end LeBet
The training and extension pool excludes the last, next-trajectory coordinate.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : N}
def pool (K : Finset (Fin (n + m))) : Finset (Fin (n + m + 1)) :=
K.map Fin.castSuccEmb
end LeBet.LeaveOneOut
Relabel the selected training indices.
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
noncomputable def relabel {ι : Type*} (e : Equiv.Perm ι) (K : Finset ι) :
Finset ι :=
K.map e.toEmbedding
end LeBet.FiniteSampling
The array u contains the diagonal LOO conditional-mean extrema; v is the next-trajectory value under the deployed fit.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : N}
variable (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : R) (gW : Finset N) (hne : gW.Nonempty)
noncomputable def values (ω : Sample Ω O (n + m + 1))
(K : Finset (Fin (n + m))) (i : Fin (n + m)) : R :=
s other ho learner rules sP hex d gW hne (pool K) i.castSucc i.castSucc 0 ω
noncomputable def nextValue (K₀ : Finset (Fin (n + m))) (ω : Sample Ω O (n +
m + 1)) : R :=
s other ho learner rules sP hex d gW hne (pool K₀)
(Fin.last (n + m)) (Fin.last (n + m)) 0 ω
end LeBet.LeaveOneOut
The training quantile uses the integer violation budget r.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.OccurrenceCalibration
open FiniteSampling EmpiricalOptimization
variable {Ω : Type*} {N n : N}
noncomputable def level (u : Ω → Finset (Fin N) → Fin N → ℝ)
(r : N) (hr : r < n) (ω : Ω) (K : Finset (Fin N)) : ℝ :=
if hK : K.card = n then
upperQuantile (fun i => u ω K (K.orderEmbOfFin hK i)) r hr else 0
end LeBet.OccurrenceCalibration
Permute the other class while fixing the evaluated class.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open StratifiedSample.JointSample (fixLast fixLast_castSucc fixLast_last)
variable {Ω O : Type*} [MeasurableSpace Ω] [MeasurableSpace O] {N : N}
def permuteOther {M : N} (e : Equiv.Perm (Fin M)) :
Sample Ω (Fin M → Ω) N ≃ᵐ Sample Ω (Fin M → Ω) N where
toFun ω := (ω.1, ω.2 ∘ e)
invFun ω := (ω.1, ω.2 ∘ e.symm)
left_inv ω := by ext i <;> simp
right_inv ω := by ext i <;> simp
measurable_toFun := measurable_fst.prodMk
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e i)).comp
measurable_snd)
measurable_invFun := measurable_fst.prodMk
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e.symm i)).comp
measurable_snd)
end LeBet.LeaveOneOut
Average stability failure over training subsets and permutations of the other class. The class-conditioning lemma supplies the failure allowance.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical BigOperators
namespace LeBet.FiniteSampling
end LeBet.FiniteSampling
namespace LeBet.OccurrenceCalibration
open FiniteSampling
variable {Ω A : Type*} {mΩ : MeasurableSpace Ω} [Fintype A] [Nonempty A]
{sP : Measure Ω} [IsProbabilityMeasure sP] {n m : ℕ}
def pairStability (u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ)
(K₀ : Finset (Fin (n + m))) (otherAct : A → Ω ≃ᵐ Ω) (B : ℝ) (b : ℕ)
(a : A) (K : Finset (Fin (n + m))) : Set Ω :=
{ω | (univ.filter fun i => B < |u (otherAct a ω) K i - u ω K₀ i|).card ≤ b}
noncomputable def averageFailure
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ)
(K₀ : Finset (Fin (n + m))) (otherAct : A → Ω ≃ᵐ Ω) (B : ℝ) (b : ℕ) : ℝ
:=
𝔼 a, 𝔼 K ∈ (univ : Finset (Fin (n + m))).powersetCard n,
sP.real (pairStability u K₀ otherAct B b a K)ᶜ
end LeBet.OccurrenceCalibration
Average the strict extension violations above the adjusted training quantile.
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
noncomputable def extensionErrorRate {N : ℕ} (h : ℕ)
(u : Finset (Fin N) → Fin N → ℝ) (q : Finset (Fin N) → ℝ) (B : ℝ)
(K : Finset (Fin N)) : ℝ :=
((Kᶜ.filter fun i => q K + 2 * B < u K i).card : ℝ) / h
end LeBet.FiniteSampling
Conditional probabilities are conditional expectations of indicators.
namespace LeBet.ConditionalCoverage
variable {Ω : Type*} [MeasurableSpace Ω]
noncomputable def conditionalProbability (sP : Measure Ω) (m :
MeasurableSpace Ω)
(A : Set Ω) : Ω → ℝ := sP[A.indicator (fun _ => (1 : ℝ)) | m]
end LeBet.ConditionalCoverage
The LOO radius allocates the mean-estimation error across training occurrences. Its agreement with the manuscript radius is proved by leaveOneOutRadius_eq_meanRadius.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
noncomputable def averageRadius (ε : ℝ) (t : ℕ) : ℝ :=
Real.sqrt (Real.log (1 / ε) / (2 * t))
noncomputable def leaveOneOutRadius (β : ℝ) (n : ℕ) (gW : Finset ℕ)
(T₀ t : ℕ) : ℝ :=
min ((1 + (T0 : R) / t) / 2 * averageRadius (β / (4 * n)) T0)
(averageRadius (β / (4 * n * gW.card)) t)
end LeBet
Training monitors exclude the evaluated occurrence. The deployed monitor uses the full training sample.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : N}
variable (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : R) (gW : Finset N) (hne : gW.Nonempty)
section Probability
variable (K₀ : Finset (Fin (n + m))) (hK₀ : K₀.card = n) (hm : 0 < m)
(r : N) (hr : r < n)
local notation "u" => values other ho learner rules sP hex d gW hne
local notation "v" => nextValue other ho learner rules sP hex d gW hne K₀
local notation "gFin" => information (Ω := Ω) other (pool K₀)
variable {A : Type*} [Fintype A] [Nonempty A]
(otherAct : A → Sample Ω O (n + m + 1) ≃ᵐ Sample Ω O (n + m + 1))
(hother : ∀ a, MeasurePreserving (otherAct a) sP sP)
{B κ : R} {b : N} (hκ : 0 ≤ κ)
(hfail : OccurrenceCalibration.averageFailure (sP := sP)
(values other ho learner rules sP hex d gW hne) K₀ otherAct B b ≤ κ)
noncomputable def trainingMonitor (i : Fin n) :
BinaryMonitor (filtration other ho (gF := gF)
((pool K₀).erase (K₀.orderEmbOfFin hK₀ i).castSucc) (K₀.orderEmbOfFin
hK₀ i).castSucc) :=
monitor other ho learner rules _ _
noncomputable def deployedMonitor :=
monitor other ho learner rules (pool K₀) (Fin.last (n + m))
end Probability
end LeBet.LeaveOneOut
Add the stability allowance after taking the training quantile.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.PredictableLearning
open FiniteSampling EmpiricalOptimization PredictableValues
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {sP : Measure Ω}
[IsProbabilityMeasure sP] {n m : N}
noncomputable def upperLevel (a : Fin n → Ω → ℝ) (r : N) (hr : r < n)
(B : ℝ) (ω : Ω) : ℝ :=
upperQuantile (fun i => a i ω) r hr + 2 * B
end LeBet.PredictableLearning
Apply the confidence radius before temporal maximization and clip after taking the quantile.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.PredictableLearning
open FiniteSampling EmpiricalOptimization
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {sP : Measure Ω}
[IsProbabilityMeasure sP] {n m : N}
section Rank
variable {gFin : MeasurableSpace Ω} (hFin : gFin ≤ mΩ)
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ) (v : Ω → ℝ)
(r : N) (hr : r < n) (K₀ : Finset (Fin (n + m))) (hK₀ : K₀.card = n)
(hm : 0 < m) (hu : ∀ K i, Measurable[mΩ] fun ω => u ω K i) (hv :
Measurable[mΩ] v)
(htrain : ∀ i ∈ K₀, Measurable[gFin] fun ω => u ω K₀ i)
(act : Equiv.Perm (Fin (n + m)) → @MeasurableEquiv Ω Ω mΩ mΩ)
(hact : ∀ e, @MeasurePreserving Ω Ω mΩ mΩ (act e) sP sP)
(hperm : ∀ e ω K i, u (act e ω) K i = u ω (relabel e K) (e i))
(swap : {i // i ∈ K₀ᶜ} → @MeasurableEquiv Ω Ω mΩ mΩ)
(hswap : ∀ i, @MeasurePreserving Ω Ω mΩ mΩ (swap i) sP sP)
(hfix : ∀ i A, MeasurableSet[gFin] A → (swap i) ⁻¹' A = A)
(hnext : ∀ i ω, v (swap i ω) = u ω K₀ i)
{A : Type*} [Fintype A] [Nonempty A]
(otherAct : A → @MeasurableEquiv Ω Ω mΩ mΩ)
(hother : ∀ a, @MeasurePreserving Ω Ω mΩ mΩ (otherAct a) sP sP)
{B κ : ℝ} {b : N} (hκ : 0 ≤ κ)
(hfail : OccurrenceCalibration.averageFailure (mΩ := mΩ) (sP := sP) u K₀
otherAct B b ≤ κ)
section Estimation
variable {gF : Fin n → Filtration N mΩ} (X : (i : Fin n) → BinaryMonitor
(gF i))
(gW : Finset N) (hne : gW.Nonempty) {T0 : N}
noncomputable def meanUpper (β d : R) (i : Fin n) (ω : Ω) : R :=
signedMeanValue d gW hne (fun t ⇒ (X i).S t ω / t)
(leaveOneOutRadius β n gW T0)
noncomputable def meanLevel (β d cap : R) (r : N) (hr : r < n) (B : R) (ω : Ω
) : R :=
min cap (upperLevel (meanUpper X gW hne (T0 := T0) β d) r hr B ω)
end Estimation
end Rank
end LeBet.PredictableLearning
The following proofs establish the sample operations, measurability, and coordinate conversions.
import Mathlib.MeasureTheory.MeasurableSpace.Embedding
import Init.Data.Vector.OfFn
import Init.Data.Vector.Extract
open MeasureTheory
namespace LeBet.SampleVector
variable {α β : Type*} {n m : N}
/-- Coordinates for the finite-product probability interface. -/
def coordinates (xs : Vector α n) : Fin n → α := fun i ⇒ xs[i.val]
def coordinateEquiv (α : Type*) (n : N) : Vector α n ≃ (Fin n → α) where
toFun := coordinates
invFun := Vector.ofFn
left_inv xs := Vector.ofFn_getElem
right_inv f := by funext i; simp [coordinates]
/-- The sigma-algebra generated by the coordinates. -/
instance vectorMeasurableSpace [MeasurableSpace α] : MeasurableSpace (Vector α
n) :=
MeasurableSpace.comap coordinates inferInstance
@[fun_prop] lemma measurable_coordinates [MeasurableSpace α] :
Measurable (coordinates (α := α) (n := n)) :=
comap_measurable coordinates
lemma measurable_vector_iff {δ : Type*} [MeasurableSpace δ] [MeasurableSpace α]
{f : δ → Vector α n} : Measurable f ↔ ∀ i : Fin n, Measurable (fun x =>
(f x)[i.val]) := by
change Measurable[_, MeasurableSpace.comap coordinates inferInstance] f ↔ _
rw [measurable_comap_iff, measurable_pi_iff]
rfl
@[fun_prop] lemma measurable_ofFn [MeasurableSpace α] :
Measurable (Vector.ofFn (α := α) (n := n)) := by
rw [measurable_vector_iff]
intro i
simpa using (measurable_pi_apply i : Measurable (fun f : Fin n → α => f i))
def coordinateMeasurableEquiv (α : Type*) [MeasurableSpace α] (n : ℕ) :
Vector α n ≃ᵐ (Fin n → α) where
toEquiv := coordinateEquiv α n
measurable_toFun := measurable_coordinates
measurable_invFun := measurable_ofFn
lemma coordinate_information [MeasurableSpace α] :
MeasurableSpace.comap (coordinateMeasurableEquiv α n) inferInstance =
(inferInstance : MeasurableSpace (Vector α n)) :=
(coordinateMeasurableEquiv α n).measurableEmbedding.comap_eq
/-- Fixed observed and extension lengths avoid repeating casts in sample
definitions. -/
def observed (xs : Vector α (n + m)) : Vector α n :=
(xs.take n).cast (by omega)
def extension (xs : Vector α (n + m)) : Vector α m :=
(xs.drop n).cast (by omega)
@[simp] lemma coordinates_observed (xs : Vector α (n + m)) (i : Fin n) :
coordinates (observed xs) i = coordinates xs (i.castAdd m) := by
simpa only [coordinates, observed, Vector.getElem_cast, Fin.val_castAdd]
using
(Vector.getElem_take (xs := xs) (i := i.val) (j := n) (by omega))
@[simp] lemma coordinates_extension (xs : Vector α (n + m)) (i : Fin m) :
coordinates (extension xs) i = coordinates xs (i.natAdd n) := by
simp [coordinates, extension]
@[fun_prop] lemma measurable_observed [MeasurableSpace α] :
Measurable (observed (α := α) (n := n) (m := m)) := by
rw [measurable_vector_iff]
intro i
change Measurable (fun xs => coordinates (observed xs) i)
simpa only [coordinates_observed, Function.comp_def] using
(measurable_pi_apply (i.castAdd m)).comp measurable_coordinates
@[fun_prop] lemma measurable_extension [MeasurableSpace α] :
Measurable (extension (α := α) (n := n) (m := m)) := by
rw [measurable_vector_iff]
intro i
change Measurable (fun xs => coordinates (extension xs) i)
simpa only [coordinates_extension, Function.comp_def] using
(measurable_pi_apply (i.natAdd n)).comp measurable_coordinates
lemma coordinates_append (xs : Vector α n) (ys : Vector α m) :
coordinates (xs ++ ys) = Fin.append (coordinates xs) (coordinates ys) := by
funext i
refine Fin.addCases (fun i => ?_) (fun i => ?_) i
Measurability
· simp [coordinates, Vector.getElem_append_left]
· simp [coordinates, Vector.getElem_append_right]
lemma coordinates_map (f : α → β) (xs : Vector α n) :
coordinates (xs.map f) = f ∘ coordinates xs := by
funext i
simp [coordinates]
lemma coordinates_push (xs : Vector α n) (x : α) :
coordinates (xs.push x) = Fin.snoc (coordinates xs) x := by
funext i
refine Fin.lastCases ?_ (fun i => ?_) i
· simp [coordinates]
· simp [coordinates, Vector.getElem_push_lt]
lemma swapAt_eq (xs : Vector α n) (i : Fin n) (x : α) :
xs.swapAt i.val x i.isLt = (xs[i.val], xs.set i.val x i.isLt) := rfl
lemma coordinates_set (xs : Vector α n) (i : Fin n) (x : α) :
coordinates (xs.set i.val x i.isLt) = Function.update (coordinates xs) i
x := by
funext j
by_cases hij : i = j
· subst j
simp [coordinates]
· have hval : i.val ≠ j.val := fun he => hij (Fin.ext he)
simp [coordinates, hval, Ne.symm hij]
section Measurability
variable {δ : Type*} [MeasurableSpace δ] [MeasurableSpace α] [MeasurableSpace β]
@[fun_prop] lemma measurable_get (i : Fin n) :
Measurable (fun xs : Vector α n => xs[i.val]) :=
(measurable_pi_apply i).comp measurable_coordinates
@[fun_prop] lemma measurable_map {f : α → β} (hf : Measurable f) :
Measurable (fun xs : Vector α n => xs.map f) := by
rw [measurable_vector_iff]
intro i
simpa [Function.comp_def] using hf.comp (measurable_get i)
@[fun_prop] lemma measurable_append {f : δ → Vector α n} {g : δ → Vector α m}
(hf : Measurable f) (hg : Measurable g) : Measurable (fun x => f x ++ g
x) := by
rw [measurable_vector_iff]
intro i
change Measurable (fun x => coordinates (f x ++ g x) i)
simp only [coordinates_append]
refine Fin.addCases (fun i => ?_) (fun i => ?_) i
· simpa only [Fin.append_left, coordinates, Function.comp_def] using
(measurable_get i).comp hf
· simpa only [Fin.append_right, coordinates, Function.comp_def] using
(measurable_get i).comp hg
@[fun_prop] lemma measurable_push {f : δ → Vector α n} {g : δ → α}
(hf : Measurable f) (hg : Measurable g) : Measurable (fun x => (f x).push
(g x)) := by
rw [measurable_vector_iff]
intro i
change Measurable (fun x => coordinates ((f x).push (g x)) i)
simp only [coordinates_push]
refine Fin.lastCases ?_ (fun i => ?_) i
· simpa only [Fin.snoc_last] using hg
· simpa only [Fin.snoc_castSucc, coordinates, Function.comp_def] using
(measurable_get i).comp hf
@[fun_prop] lemma measurable_set {f : δ → Vector α n} {g : δ → α}
(hf : Measurable f) (hg : Measurable g) (i : Fin n) :
Measurable (fun x => (f x).set i.val (g x) i.isLt) := by
rw [measurable_vector_iff]
intro j
change Measurable (fun x => coordinates ((f x).set i.val (g x) i.isLt) j)
simp only [coordinates_set]
by_cases h : j = i
· subst j
simpa only [Function.update_self] using hg
· simpa only [Function.update_of_ne h, coordinates, Function.comp_def] using
(measurable_get j).comp hf
end Measurability
end LeBet.SampleVector
import LeBet.OrderStatistics
import LeBet.StratifiedCoverage
import LeBet.SampleVector
open MeasureTheory ProbabilityTheory Finset
open scoped Classical
namespace LeBet.StratifiedSample
/-- Interactions with label 0. -/
abbrev Ω_0 {Ω : Type*} (Y : Ω → Fin 2) : Set Ω := {ω | Y ω = 0}
/-- Interactions with label 1. -/
abbrev Ω_1 {Ω : Type*} (Y : Ω → Fin 2) : Set Ω := {ω | Y ω = 1}
/-- The joint sample space of both classes and the next trajectory. -/
abbrev mΩ {Ω : Type*} (Y : Ω → Fin 2) (n_0 m_0 n_1 m_1 : N) :=
Vector (Set.Elem (Ω_0 Y)) (n_0 + m_0) ×
Vector (Set.Elem (Ω_1 Y)) (n_1 + m_1) × Ω
variable {Ω OtherSample OtherTraining : Type*} [MeasurableSpace Ω]
[MeasurableSpace OtherSample]
[MeasurableSpace OtherTraining] {N n_y m_y : N}
/-- Reorder class coordinates, fixing the other class and the next
trajectory. -/
Lean 4 Supplement
def permute (e : Equiv.Perm (Fin N)) : ((Fin N → Ω) × OtherSample × Ω) ≃ᵐ
((Fin N → Ω) × OtherSample × Ω) where
toFun mD := (mD.1 ◦ e, mD.2)
invFun mD := (mD.1 ◦ e.symm, mD.2)
left_inv mD := by ext i <;> simp
right_inv mD := by ext i <;> simp
measurable_toFun := (measurable_pi_iff.mpr (fun i =>
(measurable_pi_apply (e i)).comp measurable_fst)).prodMk measurable_snd
measurable_invFun := (measurable_pi_iff.mpr (fun i =>
(measurable_pi_apply (e.symm i)).comp measurable_fst)).prodMk
measurable_snd
/-- Exchange one class coordinate with the separate next trajectory. -/
def swapNext (i : Fin N) : ((Fin N → Ω) × OtherSample × Ω) ≃ᵐ ((Fin N → Ω)
× OtherSample × Ω) where
toFun mD := (Function.update mD.1 i mD.2.2, mD.2.1, mD.1 i)
invFun mD := (Function.update mD.1 i mD.2.2, mD.2.1, mD.1 i)
left_inv mD := by
apply Prod.ext
· funext j
by_cases hj : j = i <;> simp [hj]
· simp
right_inv mD := by
apply Prod.ext
· funext j
by_cases hj : j = i <;> simp [hj]
· simp
measurable_toFun :=
(measurable_update’.comp (measurable_fst.prodMk
measurable_snd.snd)).prodMk
(measurable_snd.fst.prodMk ((measurable_pi_apply i).comp
measurable_fst))
measurable_invFun :=
(measurable_update’.comp (measurable_fst.prodMk
measurable_snd.snd)).prodMk
(measurable_snd.fst.prodMk ((measurable_pi_apply i).comp
measurable_fst))
def gI_in_y (n_y m_y : N) : Finset (Fin (n_y + m_y)) :=
univ.map (Fin.castAddEmb m_y)
lemma trainingIndices_card : (gI_in_y n_y m_y).card = n_y := by
simp [gI_in_y]
noncomputable def subtuple (K : Finset (Fin N)) (hK : K.card = n_y)
(z : Fin N → Ω) : Fin n_y → Ω :=
fun i => z (K.orderEmbOfFin hK i)
lemma subtuple_measurable (K : Finset (Fin N)) (hK : K.card = n_y) :
Measurable (subtuple (Ω := Ω) K hK) :=
measurable_pi_iff.mpr (fun i => measurable_pi_apply (K.orderEmbOfFin hK i))
noncomputable def relabelEquiv (e : Equiv.Perm (Fin N)) (K : Finset (Fin N)) :
K ≃ FiniteSampling.relabel e K where
toFun i := ⟨e i, by simpa only [FiniteSampling.mem_relabel,
e.symm_apply_apply] using i.2⟩
invFun i := ⟨e.symm i, (FiniteSampling.mem_relabel e K i).mp i.2⟩
left_inv i := by ext; simp
right_inv i := by ext; simp
omit [MeasurableSpace Ω] in
/-- Subsampling commutes with reordering, up to a permutation of the training
tuple. -/
lemma subtuple_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N))
(hK : K.card = n_y) (z : Fin N → Ω) :
∃ a : Equiv.Perm (Fin n_y),
subtuple K hK (z ∘ e) =
subtuple (FiniteSampling.relabel e K)
((FiniteSampling.relabel_card e K).trans hK) z ∘ a := by
let L := FiniteSampling.relabel e K
let hL : L.card = n_y := (FiniteSampling.relabel_card e K).trans hK
let a := (K.orderIsoOfFin hK).toEquiv.trans
((relabelEquiv e K).trans (L.orderIsoOfFin hL).toEquiv.symm)
refine ⟨a, ?_⟩
funext i
exact (congrArg (fun j : L => z j.val)
((L.orderIsoOfFin hL).apply_symm_apply
(relabelEquiv e K (K.orderIsoOfFin hK i)))).symm
/-- The complete observed training information, with the other class
extracted by ‘other‘. -/
noncomputable def classTraining (other : OtherSample → OtherTraining) (mD :
((Fin (n_y + m_y) → Ω) × OtherSample × Ω)) :
(Fin n_y → Ω) × OtherTraining :=
(subtuple (gI_in_y n_y m_y) trainingIndices_card mD.1, other mD.2.1)
lemma classTraining_measurable (other : OtherSample → OtherTraining) (ho :
Measurable other) :
Measurable (classTraining (n_y := n_y) (m_y := m_y) (Ω := Ω) other) :=
((subtuple_measurable _ _).comp measurable_fst).prodMk (ho.comp
measurable_snd.fst)
omit [MeasurableSpace OtherTraining] in
lemma classTraining_swapNext (other : OtherSample → OtherTraining)
(i : {i : Fin (n_y + m_y) // i ∈ (gI_in_y n_y m_y)ᶜ})
(mD : ((Fin (n_y + m_y) → Ω) × OtherSample × Ω)) :
classTraining other (swapNext i mD) = classTraining other mD := by
apply Prod.ext
· funext j
apply Function.update_of_ne
intro he
have hj := orderEmbOfFin_mem (gI_in_y n_y m_y) trainingIndices_card j
rw [he] at hj
exact (mem_compl.mp i.2) hj
· rfl
/-- The learner’s statistic is a measurable function of both training classes
and
one evaluated trajectory. Only values, not rule representations, are
symmetric. -/
structure Statistic (Ω OtherTraining : Type*) [MeasurableSpace Ω]
[MeasurableSpace OtherTraining] (n_y : ℕ) where
value : ((Fin n_y → Ω) × OtherTraining) × Ω → ℝ
measurable : Measurable value
symmetric : ∀ (a : Equiv.Perm (Fin n_y)) (mD : (Fin n_y → Ω) ×
OtherTraining) z,
value ((mD.1 ∘ a, mD.2), z) = value (mD, z)
namespace Statistic
variable (statistic : Statistic Ω OtherTraining n_y)
noncomputable def fitted (other : OtherSample → OtherTraining) (d : ((Fin N →
Ω) × OtherSample × Ω))
(K : Finset (Fin N)) (z : Ω) : ℝ :=
if hK : K.card = n_y then statistic.value ((subtuple K hK d.1, other
d.2.1), z) else 0
lemma fitted_permute (other : OtherSample → OtherTraining) (e : Equiv.Perm
(Fin N))
(d : ((Fin N → Ω) × OtherSample × Ω)) (K : Finset (Fin N)) (z : Ω) :
statistic.fitted other (permute e d) K z =
statistic.fitted other d (FiniteSampling.relabel e K) z := by
by_cases hK : K.card = n_y
· have hL := (FiniteSampling.relabel_card e K).trans hK
simp only [fitted, dite_eq_left hK, dite_eq_left hL]
obtain ⟨a, ha⟩ := subtuple_permute e K hK d.1
change statistic.value ((subtuple K hK (d.1 ∘ e), other d.2.1), z) = _
rw [ha]
exact statistic.symmetric a (subtuple (FiniteSampling.relabel e K) hL
d.1, other d.2.1) z
· have hL : (FiniteSampling.relabel e K).card ≠ n_y := by
simpa only [FiniteSampling.relabel_card] using hK
simp only [fitted, dite_eq_right hK, dite_eq_right hL]
lemma fitted_measurable (other : OtherSample → OtherTraining) (ho :
Measurable other)
(K : Finset (Fin N)) :
Measurable fun p : ((Fin N → Ω) × OtherSample × Ω) × Ω =>
statistic.fitted other p.1 K p.2 := by
by_cases hK : K.card = n_y
· simp only [fitted, dite_eq_left hK]
exact statistic.measurable.comp
((((subtuple_measurable K hK).comp measurable_fst.fst).prodMk
(ho.comp measurable_fst.snd.fst)).prodMk measurable_snd)
· simp only [fitted, dite_eq_right hK]
exact measurable_const
end Statistic
end LeBet.StratifiedSample
import LeBet.StratifiedSample
open MeasureTheory ProbabilityTheory Finset
open scoped Classical
open LeBet.SampleVector
namespace LeBet.StratifiedSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
lemma mem_Ω_0 {ω : Ω} : ω ∈ Ω_0 Y ↔ Y ω = 0 := Iff.rfl
lemma mem_Ω_1 {ω : Ω} : ω ∈ Ω_1 Y ↔ Y ω = 1 := Iff.rfl
/-- The observed trajectories, with class 0 followed by class 1. -/
def mD_in (ω : mΩ Y n_0 m_0 n_1 m_1) : Vector Ω (n_0 + n_1) :=
let (sample_0, sample_1, _) := ω
(observed sample_0).map Subtype.val ++ (observed sample_1).map Subtype.val
/-- The extension trajectories, in the same class order. -/
def mD_out (ω : mΩ Y n_0 m_0 n_1 m_1) : Vector Ω (m_0 + m_1) :=
let (sample_0, sample_1, _) := ω
(extension sample_0).map Subtype.val ++ (extension sample_1).map Subtype.val
/-- The full sample: observed data, extension, and next trajectory. -/
def mD (ω : mΩ Y n_0 m_0 n_1 m_1) :
Vector Ω ((n_0 + n_1) + (m_0 + m_1) + 1) :=
let (_, _, next) := ω
(mD_in ω ++ mD_out ω).push next
lemma coordinates_mD_in (ω : mΩ Y n_0 m_0 n_1 m_1) :
coordinates (mD_in ω) =
Fin.append (fun i => (ω.1[(i.castAdd m_0).val]).val)
(fun i => (ω.2.1[(i.castAdd m_1).val]).val) := by
unfold mD_in
rw [coordinates_append, coordinates_map, coordinates_map]
funext i
refine Fin.addCases (fun i => ?_) (fun i => ?_) i
· simp only [Fin.append_left, Function.comp_apply, coordinates_observed]
· simp only [Fin.append_right, Function.comp_apply, coordinates_observed]
lemma coordinates_mD_out (ω : mΩ Y n_0 m_0 n_1 m_1) :
coordinates (mD_out ω) =
Fin.append (fun i => (ω.1[(i.natAdd n_0).val]).val)
(fun i => (ω.2.1[(i.natAdd n_1).val]).val) := by
unfold mD_out
rw [coordinates_append, coordinates_map, coordinates_map]
funext i
refine Fin.addCases (fun i => ?_) (fun i => ?_) i
· simp only [Fin.append_left, Function.comp_apply, coordinates_extension]
· simp only [Fin.append_right, Function.comp_apply, coordinates_extension]
@[simp] lemma mD_observed (ω : mΩ Y n_0 m_0 n_1 m_1) (i : Fin (n_0 + n_1)) :
(mD ω)[i.val] = (mD_in ω)[i.val] := by
simp [mD, Vector.getElem_append_left]
@[simp] lemma mD_extension (ω : mΩ Y n_0 m_0 n_1 m_1) (i : Fin (m_0 + m_1)) :
(mD ω)[n_0 + n_1 + i.val] = (mD_out ω)[i.val] := by
simp [mD, Vector.getElem_push_lt, Vector.getElem_append_right]
@[simp] lemma mD_next (ω : mΩ Y n_0 m_0 n_1 m_1) :
(mD ω)[(n_0 + n_1) + (m_0 + m_1)] = ω.2.2 := by
simp [mD]
section Measurability
variable [MeasurableSpace Ω]
lemma measurable_append {α : Type*} [MeasurableSpace α] {n m : N}
{f : α → Fin n → Ω} {g : α → Fin m → Ω} (hf : Measurable f) (hg :
Measurable g) :
Measurable (fun a => Fin.append (f a) (g a)) := by
refine measurable_pi_iff.mpr fun i => ?_
refine Fin.addCases (fun i => ?_) (fun i => ?_) i
· simpa only [Fin.append_left, Function.comp_def] using (measurable_pi_apply
i).comp hf
· simpa only [Fin.append_right, Function.comp_def] using
(measurable_pi_apply i).comp hg
/-- Joining two ordered blocks preserves all their measurable information. -/
def appendEquiv (n m : N) : ((Fin n → Ω) × (Fin m → Ω)) ≃ᵐ (Fin (n + m) →
Ω) where
toFun d := Fin.append d.1 d.2
invFun z := (fun i => z (i.castAdd m), fun i => z (i.natAdd n))
left_inv d := by ext i <;> simp
right_inv z := by
funext i
exact Fin.addCases (fun i => by simp) (fun i => by simp) i
measurable_toFun := measurable_append measurable_fst measurable_snd
measurable_invFun := (measurable_pi_iff.mpr fun i => measurable_pi_apply
_).prodMk
(measurable_pi_iff.mpr fun i => measurable_pi_apply _)
lemma mD_in_measurable : Measurable (mD_in (Y := Y) (n_0 := n_0)
(m_0 := m_0) (n_1 := n_1) (m_1 := m_1)) := by
unfold mD_in
fun_prop
lemma mD_out_measurable : Measurable (mD_out (Y := Y) (n_0 := n_0)
(m_0 := m_0) (n_1 := n_1) (m_1 := m_1)) := by
unfold mD_out
fun_prop
lemma mD_measurable : Measurable (mD (Y := Y) (n_0 := n_0)
(m_0 := m_0) (n_1 := n_1) (m_1 := m_1)) :=
SampleVector.measurable_push
(SampleVector.measurable_append mD_in_measurable mD_out_measurable)
measurable_snd.snd
end Measurability
namespace JointSample
/-- Class 0 coordinates used by the general classwise proofs. -/
def class0 (ω : mΩ Y n_0 m_0 n_1 m_1) :
(Fin (n_0 + m_0) → Ω) × (Fin (n_1 + m_1) → Ω) × Ω :=
(fun i => (ω.1[i.val]).val, fun i => (ω.2.1[i.val]).val, ω.2.2)
/-- Class 1 coordinates, with the class under study placed first. -/
def class1 (ω : mΩ Y n_0 m_0 n_1 m_1) :
(Fin (n_1 + m_1) → Ω) × (Fin (n_0 + m_0) → Ω) × Ω :=
(fun i => (ω.2.1[i.val]).val, fun i => (ω.1[i.val]).val, ω.2.2)
/-- The first ‘n‘ entries of an observed-and-extension tuple. -/
def observed {n m : N} (z : Fin (n + m) → Ω) : Fin n → Ω :=
fun i => z (i.castAdd m)
lemma subtuple_training (z : Fin (n_0 + m_0) → Ω) :
subtuple (gI_in_y n_0 m_0) trainingIndices_card z = observed z := by
have h := orderEmbOfFin_unique (trainingIndices_card (n_y := n_0) (m_y :=
m_0))
(f := fun i : Fin n_0 => i.castAdd m_0)
(fun i => by simp [gI_in_y])
(by intro i j hij; exact hij)
funext i
exact congrArg z (congrFun h i).symm
lemma class0_training (ω : mΩ Y n_0 m_0 n_1 m_1) :
let d := classTraining (observed (n := n_1) (m := m_1)) (class0 ω)
Vector.ofFn (Fin.append d.1 d.2) = mD_in ω := by
apply (coordinateEquiv Ω _).injective
change coordinates (Vector.ofFn _) = coordinates (mD_in ω)
rw [coordinates_mD_in]
simp only [classTraining, subtuple_training]
funext i
simp only [coordinates, Vector.getElem_ofFn]
rfl
lemma class1_training (ω : mΩ Y n_0 m_0 n_1 m_1) :
let d := classTraining (observed (n := n_0) (m := m_0)) (class1 ω)
Vector.ofFn (Fin.append d.2 d.1) = mD_in ω := by
apply (coordinateEquiv Ω _).injective
change coordinates (Vector.ofFn _) = coordinates (mD_in ω)
rw [coordinates_mD_in]
simp only [classTraining, subtuple_training]
funext i
simp only [coordinates, Vector.getElem_ofFn]
rfl
/-- Permute the class 0 block. -/
def permute0 (e : Equiv.Perm (Fin (n_0 + m_0))) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 :=
let (sample_0, sample_1, next) := ω
(Vector.ofFn (fun i => sample_0[(e i).val]), sample_1, next)
/-- Permute the class 1 block. -/
def permute1 (e : Equiv.Perm (Fin (n_1 + m_1))) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 :=
let (sample_0, sample_1, next) := ω
(sample_0, Vector.ofFn (fun i => sample_1[(e i).val]), next)
/-- Exchange a class 0 entry with the next trajectory when its label is 0. -/
noncomputable def swapNext0 (i : Fin (n_0 + m_0)) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 0
· let next_0 : Set.Elem (Ω_0 Y) := ⟨next, mem_Ω_0.mpr h⟩
let (old, updated) := sample_0.swapAt i.val next_0 i.isLt
exact (updated, sample_1, old.val)
· exact (sample_0, sample_1, next)
/-- Exchange a class 1 entry with the next trajectory when its label is 1. -/
noncomputable def swapNext1 (i : Fin (n_1 + m_1)) (ω : mΩ Y n_0 m_0 n_1 m_1) :
mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 1
· let next_1 : Set.Elem (Ω_1 Y) := ⟨next, mem_Ω_1.mpr h⟩
let (old, updated) := sample_1.swapAt i.val next_1 i.isLt
exact (sample_0, updated, old.val)
· exact (sample_0, sample_1, next)
variable [MeasurableSpace Ω]
/-- Vectors and finite functions give the same joint measurable space. -/
def coordinateMeasurableEquiv : mΩ Y n_0 m_0 n_1 m_1 ≃ᵐ
((Fin (n_0 + m_0) → Set.Elem (Ω_0 Y)) ×
(Fin (n_1 + m_1) → Set.Elem (Ω_1 Y)) × Ω) :=
(SampleVector.coordinateMeasurableEquiv (Set.Elem (Ω_0 Y)) _).prodCongr
((SampleVector.coordinateMeasurableEquiv (Set.Elem (Ω_1 Y)) _).prodCongr
(MeasurableEquiv.refl Ω))
lemma coordinate_information :
MeasurableSpace.comap
(coordinateMeasurableEquiv (Y := Y) (n_0 := n_0) (m_0 := m_0)
(n_1 := n_1) (m_1 := m_1)) inferInstance =
(inferInstance : MeasurableSpace (mΩ Y n_0 m_0 n_1 m_1)) :=
coordinateMeasurableEquiv.measurableEmbedding.comap_eq
lemma class0_permute (e : Equiv.Perm (Fin (n_0 + m_0))) (ω : mΩ Y n_0 m_0 n_1
m_1) :
class0 (permute0 e ω) = permute e (class0 ω) := by
ext i <;> simp [class0, permute0, permute]
lemma class1_permute (e : Equiv.Perm (Fin (n_1 + m_1))) (ω : mΩ Y n_0 m_0 n_1
m_1) :
class1 (permute1 e ω) = permute e (class1 ω) := by
ext i <;> simp [class1, permute1, permute]
lemma class0_swapNext (i : Fin (n_0 + m_0)) (ω : mΩ Y n_0 m_0 n_1 m_1)
(h : Y ω.2.2 = 0) :
class0 (swapNext0 i ω) = swapNext i (class0 ω) := by
simp only [swapNext0, dite_eq_left h, swapAt_eq, class0, swapNext,
MeasurableEquiv.coe_mk]
ext j
· by_cases hj : j = i
· subst j; simp
· have hij : i.val ≠ j.val := fun he => hj (Fin.ext he).symm
simp [hj, hij]
· rfl
· rfl
lemma class1_swapNext (i : Fin (n_1 + m_1)) (ω : mΩ Y n_0 m_0 n_1 m_1)
(h : Y ω.2.2 = 1) :
class1 (swapNext1 i ω) = swapNext i (class1 ω) := by
simp only [swapNext1, dite_eq_left h, swapAt_eq, class1, swapNext,
MeasurableEquiv.coe_mk]
ext j
· by_cases hj : j = i
· subst j; simp
· have hij : i.val ≠ j.val := fun he => hj (Fin.ext he).symm
simp [hj, hij]
· rfl
· rfl
lemma class0_measurable : Measurable (class0 (Y := Y) (n_0 := n_0)
(m_0 := m_0) (n_1 := n_1) (m_1 := m_1)) :=
(measurable_pi_iff.mpr fun i =>
measurable_subtype_coe.comp ((measurable_get i).comp
measurable_fst)).prodMk
((measurable_pi_iff.mpr fun i =>
measurable_subtype_coe.comp ((measurable_get i).comp
measurable_snd.fst)).prodMk
measurable_snd.snd)
lemma class1_measurable : Measurable (class1 (Y := Y) (n_0 := n_0)
(m_0 := m_0) (n_1 := n_1) (m_1 := m_1)) :=
(measurable_pi_iff.mpr fun i =>
measurable_subtype_coe.comp ((measurable_get i).comp
measurable_snd.fst)).prodMk
((measurable_pi_iff.mpr fun i =>
measurable_subtype_coe.comp ((measurable_get i).comp
measurable_fst)).prodMk
measurable_snd.snd)
lemma class0_information :
MeasurableSpace.comap
(fun ω : mΩ Y n_0 m_0 n_1 m_1 =>
classTraining (observed (n := n_1) (m := m_1)) (class0 ω))
inferInstance =
MeasurableSpace.comap mD_in inferInstance := by
let f := fun ω : mΩ Y n_0 m_0 n_1 m_1 =>
classTraining (observed (n := n_1) (m := m_1)) (class0 ω)
let e := (appendEquiv n_0 n_1).trans
(SampleVector.coordinateMeasurableEquiv Ω (n_0 + n_1)).symm
calc
_ = MeasurableSpace.comap (e ◦ f) inferInstance := by
rw [← MeasurableSpace.comap_comp, e.measurableEmbedding.comap_eq]
_ = _ := by
congr 1
funext ω
exact class0_training ω
lemma class1_information :
MeasurableSpace.comap
(fun ω : mΩ Y n_0 m_0 n_1 m_1 =>
classTraining (observed (n := n_0) (m := m_0)) (class1 ω))
inferInstance =
MeasurableSpace.comap mD_in inferInstance := by
let f := fun ω : mΩ Y n_0 m_0 n_1 m_1 =>
classTraining (observed (n := n_0) (m := m_0)) (class1 ω)
let e := (MeasurableEquiv.prodComm :
((Fin n_1 → Ω) × (Fin n_0 → Ω)) ≃ᵐ ((Fin n_0 → Ω) × (Fin n_1 → Ω))).trans
((appendEquiv n_0 n_1).trans
(SampleVector.coordinateMeasurableEquiv Ω (n_0 + n_1)).symm)
calc
_ = MeasurableSpace.comap (e ◦ f) inferInstance := by
rw [← MeasurableSpace.comap_comp, e.measurableEmbedding.comap_eq]
_ = _ := by
congr 1
funext ω
exact class1_training ω
lemma observed_measurable {n m : N} :
Measurable (observed (Ω := Ω) (n := n) (m := m)) :=
measurable_pi_iff.mpr fun i => measurable_pi_apply (i.castAdd m)
lemma permute0_measurable (e : Equiv.Perm (Fin (n_0 + m_0))) :
Measurable (permute0 (Y := Y) (n_1 := n_1) (m_1 := m_1) e) := by
unfold permute0
exact (measurable_ofFn.comp (measurable_pi_iff.mpr fun i =>
(measurable_get (e i)).comp measurable_fst)).prodMk measurable_snd
lemma permute1_measurable (e : Equiv.Perm (Fin (n_1 + m_1))) :
Measurable (permute1 (Y := Y) (n_0 := n_0) (m_0 := m_0) e) := by
unfold permute1
exact measurable_fst.prodMk ((measurable_ofFn.comp (measurable_pi_iff.mpr
fun i =>
(measurable_get (e i)).comp measurable_snd.fst)).prodMk
measurable_snd.snd)
lemma swapNext0_measurable (hY : Measurable Y) (i : Fin (n_0 + m_0)) :
Measurable (swapNext0 (Y := Y) (n_1 := n_1) (m_1 := m_1) i) := by
unfold swapNext0
simp only [swapAt_eq]
refine Measurable.dite (s := {ω : mΩ Y n_0 m_0 n_1 m_1 | Y ω.2.2 = 0})
(f := fun ω => (ω.val.1.set i.val ⟨ω.val.2.2, ω.property⟩ i.isLt,
ω.val.2.1, (ω.val.1[i.val]).val)) (g := fun ω => ω.val) ?_
measurable_subtype_coe ?_
· refine Measurable.prodMk ?_ (Measurable.prodMk ?_ ?_)
· exact measurable_set (by fun_prop) (by fun_prop) i
· fun_prop
· exact measurable_subtype_coe.comp ((measurable_get i).comp (by fun_prop))
· exact (hY.comp measurable_snd.snd) (measurableSet_singleton 0)
lemma swapNext1_measurable (hY : Measurable Y) (i : Fin (n_1 + m_1)) :
Measurable (swapNext1 (Y := Y) (n_0 := n_0) (m_0 := m_0) i) := by
unfold swapNext1
simp only [swapAt_eq]
refine Measurable.dite (s := {ω : mΩ Y n_0 m_0 n_1 m_1 | Y ω.2.2 = 1})
(f := fun ω => (ω.val.1, ω.val.2.1.set i.val ⟨ω.val.2.2, ω.property⟩
i.isLt,
(ω.val.2.1[i.val]).val)) (g := fun ω => ω.val) ?_
measurable_subtype_coe ?_
· refine Measurable.prodMk ?_ (Measurable.prodMk ?_ ?_)
· fun_prop
· exact measurable_set (by fun_prop) (by fun_prop) i
· exact measurable_subtype_coe.comp ((measurable_get i).comp (by fun_prop))
· exact (hY.comp measurable_snd.snd) (measurableSet_singleton 1)
omit [MeasurableSpace Ω] in
lemma swapNext0_involutive (i : Fin (n_0 + m_0)) :
Function.Involutive (swapNext0 (Y := Y) (n_1 := n_1) (m_1 := m_1) i) := by
intro ω
by_cases h : Y ω.2.2 = 0
· have hi := mem_Ω_0.mp (ω.1[i.val]).property
simp [swapNext0, h, swapAt_eq, hi]
· simp [swapNext0, h]
omit [MeasurableSpace Ω] in
lemma swapNext1_involutive (i : Fin (n_1 + m_1)) :
Function.Involutive (swapNext1 (Y := Y) (n_0 := n_0) (m_0 := m_0) i) := by
intro ω
by_cases h : Y ω.2.2 = 1
· have hi := mem_Ω_1.mp (ω.2.1[i.val]).property
simp [swapNext1, h, swapAt_eq, hi]
· simp [swapNext1, h]
omit [MeasurableSpace Ω] in
lemma mD_in_swapNext0 (ω : mΩ Y n_0 m_0 n_1 m_1) (i : Fin m_0) :
mD_in (swapNext0 (i.natAdd n_0) ω) = mD_in ω := by
apply (coordinateEquiv Ω _).injective
change coordinates (mD_in _) = coordinates (mD_in _)
rw [coordinates_mD_in, coordinates_mD_in]
by_cases h : Y ω.2.2 = 0
· simp only [swapNext0, dite_eq_left h, swapAt_eq]
congr 1
funext j
have hij : (i.natAdd n_0).val ≠ (j.castAdd m_0).val := by
simp only [Fin.val_castAdd, Fin.val_natAdd]
omega
rw [Vector.getElem_set_ne _ _ hij]
· simp only [swapNext0, dite_eq_right h]
omit [MeasurableSpace Ω] in
lemma mD_in_swapNext1 (ω : mΩ Y n_0 m_0 n_1 m_1) (i : Fin m_1) :
mD_in (swapNext1 (i.natAdd n_1) ω) = mD_in ω := by
apply (coordinateEquiv Ω _).injective
change coordinates (mD_in _) = coordinates (mD_in _)
rw [coordinates_mD_in, coordinates_mD_in]
by_cases h : Y ω.2.2 = 1
· simp only [swapNext1, dite_eq_left h, swapAt_eq]
congr 1
funext j
have hij : (i.natAdd n_1).val ≠ (j.castAdd m_1).val := by
simp only [Fin.val_castAdd, Fin.val_natAdd]
omega
rw [Vector.getElem_set_ne _ _ hij]
· simp only [swapNext1, dite_eq_right h]
end JointSample
end LeBet.StratifiedSample
import LeBet.JointExperiment
import Mathlib.Probability.ConditionalProbability
open MeasureTheory ProbabilityTheory
open scoped Classical
namespace LeBet.StratifiedSample.JointSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : ℕ}
/-- Reorder the whole class 0 sample together with the next trajectory. -/
noncomputable def permuteNext0 (e : Equiv.Perm (Fin (n_0 + m_0 + 1)))
(ω : mΩ Y n_0 m_0 n_1 m_1) : mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 0
· let next_0 : Set.Elem (Ω_0 Y) := ⟨next, mem_Ω_0.mpr h⟩
let pool := sample_0.push next_0
let updated := Vector.ofFn (fun i : Fin (n_0 + m_0) => pool[(e
i.castSucc).val])
let next := pool[(e (Fin.last (n_0 + m_0))).val]
exact (updated, sample_1, next.val)
· exact (sample_0, sample_1, next)
/-- Reorder the whole class 1 sample together with the next trajectory. -/
noncomputable def permuteNext1 (e : Equiv.Perm (Fin (n_1 + m_1 + 1)))
(ω : mΩ Y n_0 m_0 n_1 m_1) : mΩ Y n_0 m_0 n_1 m_1 := by
rcases ω with ⟨sample_0, sample_1, next⟩
by_cases h : Y next = 1
· let next_1 : Set.Elem (Ω_1 Y) := ⟨next, mem_Ω_1.mpr h⟩
let pool := sample_1.push next_1
let updated := Vector.ofFn (fun i : Fin (n_1 + m_1) => pool[(e
i.castSucc).val])
let next := pool[(e (Fin.last (n_1 + m_1))).val]
exact (sample_0, updated, next.val)
· exact (sample_0, sample_1, next)
end LeBet.StratifiedSample.JointSample
import LeBet.SampleActions
open MeasureTheory ProbabilityTheory
namespace LeBet.StratifiedSample
variable {Ω : Type*} [MeasurableSpace Ω] {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : N}
/-- Assumption 1. Under each next-label law, the corresponding class together
with the next trajectory, and the other class separately, are exchangeable. -/
def FiniteExchangeableExtension (sP : Measure (mΩ Y n_0 m_0 n_1 m_1)) : Prop
:=
(∀ e, (cond sP (JointSample.classEvent 0)).map (JointSample.permuteNext0 e)
= cond sP (JointSample.classEvent 0)) ∧
(∀ e, (cond sP (JointSample.classEvent 0)).map (JointSample.permute1 e) =
cond sP (JointSample.classEvent 0)) ∧
(∀ e, (cond sP (JointSample.classEvent 1)).map (JointSample.permuteNext1 e)
= cond sP (JointSample.classEvent 1)) ∧
(∀ e, (cond sP (JointSample.classEvent 1)).map (JointSample.permute0 e) =
cond sP (JointSample.classEvent 1))
end LeBet.StratifiedSample
import LeBet.RuleEncoding
import LeBet.Monitor
open MeasureTheory ProbabilityTheory Finset
open scoped Classical
namespace LeBet.EmpiricalOptimization
variable {Z : Type*} {mZ : MeasurableSpace Z} {gF : Filtration N mZ}
{d K_gR K_gS : N}
/-- The conjunction used by `ruleMonitor`, evaluated at one trajectory and
step. -/
noncomputable def conjunctionValue (Ξ : Fin d → BinaryMonitor gF)
(gR : Finset (Fin d)) (s : N) (z : Z) : R :=
if ∀ j ∈ gR, (Ξ j).X s z = 1 then 1 else 0
/-- The same disjunction on arbitrary finite sets, used to express
intermediate edits. -/
noncomputable def ruleSetValue (Ξ : Fin d → BinaryMonitor gF)
(gS : Finset (Finset (Fin d))) (s : N) (z : Z) : R :=
if ∃ gR ∈ gS, ∀ j ∈ gR, (Ξ j).X s z = 1 then 1 else 0
/-- The actual disjunction of nonempty conjunctions; the empty rule set is
zero. -/
noncomputable def ruleMonitor (Ξ : Fin d → BinaryMonitor gF)
(gS : RuleClass d K_gR K_gS) : BinaryMonitor gF where
X s z := if ∃ gR ∈ gS.val, ∀ i ∈ gR, (Ξ i).X s z = 1 then 1 else 0
adapted s := by
have he : MeasurableSet[gF (s + 1)]
{z | ∃ gR ∈ gS.val, ∀ i ∈ gR, (Ξ i).X s z = 1} := by
convert gS.val.measurableSet_biUnion (fun gR _ =>
gR.measurableSet_biInter (fun i _ =>
measurableSet_eq_fun ((Ξ i).adapted s).measurable
(measurable_const : Measurable[gF (s + 1)] (fun _ : Z => (1 : R
))))) using 1
ext z
simp only [Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_iInter,
exists_prop]
exact (Measurable.ite he measurable_const
measurable_const).stronglyMeasurable
binary s z := by
split_ifs
· exact Or.inr rfl
· exact Or.inl rfl
end LeBet.EmpiricalOptimization
import LeBet.JointSample
import LeBet.LearningExperiment
open MeasureTheory ProbabilityTheory
namespace LeBet.StratifiedSample.JointSample
variable {Ω gC : Type*} [MeasurableSpace Ω] [MeasurableSpace gC]
{Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : N}
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
/-- The next trajectory has label ‘y‘. -/
def classEvent (y : Fin 2) : Set (mΩ Y n_0 m_0 n_1 m_1) :=
{ω | Y ω.2.2 = y}
lemma classEvent_measurable (hY : Measurable Y) (y : Fin 2) :
MeasurableSet (classEvent (Y := Y) (n_0 := n_0) (m_0 := m_0)
(n_1 := n_1) (m_1 := m_1) y) :=
(hY.comp measurable_snd.snd) (measurableSet_singleton y)
private lemma nextLabel_measurable {α β : Type*} [MeasurableSpace α]
[MeasurableSpace β]
(hY : Measurable Y) (y : Fin 2) : MeasurableSet {d : α × β × Ω | Y d.2.2
= y} :=
(hY.comp measurable_snd.snd) (measurableSet_singleton y)
private lemma map_cond {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]
(P : Measure α) {f : α → β} (hf : Measurable f) {A : Set β} (hA :
MeasurableSet A) :
(cond P (f ⁻¹' A)).map f = cond (P.map f) A := by
ext B hB
rw [Measure.map_apply hf hB, cond_apply (hf hA), cond_apply hA,
Measure.map_apply hf hA, Measure.map_apply hf (hA.inter hB)]
rfl
private lemma map_symmetry {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]
{P : Measure α} {f : α → β} {e : α → α} {g : β → β}
(hf : Measurable f) (hg : Measurable g) (he : MeasurePreserving e P P)
(h : (f ∘ e) =ᵐ[P] (g ∘ f)) :
MeasurePreserving g (P.map f) (P.map f) := by
refine ⟨hg, ?_⟩
calc
(P.map f).map g = P.map (g ∘ f) := Measure.map_map hg hf
_ = P.map (f ∘ e) := Measure.map_congr h.symm
_ = (P.map e).map f := (Measure.map_map hf he.measurable).symm
_ = P.map f := by rw [he.map_eq]
variable (sP : Measure (mΩ Y n_0 m_0 n_1 m_1)) [IsProbabilityMeasure sP]
(hY : Measurable Y)
(fit : Vector Ω (n_0 + n_1) → gC) (hfit : Measurable fit)
(X_rules : gC → BinaryMonitor gF)
/-- Build the class 0 proof interface from the joint law and the common learner. -/
noncomputable def experiment0
(hclass : sP (classEvent 0) ≠ 0)
(hperm : ∀ e, MeasurePreserving (permute0 e)
(cond sP (classEvent 0)) (cond sP (classEvent 0)))
(hswap : ∀ i : {i : Fin (n_0 + m_0) // i ∈ (gI_in_y n_0 m_0)ᶜ},
MeasurePreserving (swapNext0 i)
(cond sP (classEvent 0)) (cond sP (classEvent 0))) :
Experiment Ω (Fin (n_1 + m_1) → Ω) (Fin n_1 → Ω) gC n_0 m_0 gF where
X_rules := X_rules
«gˢ» := fun d => fit (Vector.ofFn (Fin.append d.1 d.2))
fit_measurable := hfit.comp (SampleVector.measurable_ofFn.comp
(measurable_append measurable_fst measurable_snd))
other := observed
other_measurable := observed_measurable
sP := sP.map class0
probability := inferInstance
classEvent := {d | Y d.2.2 = 0}
class_measurable := nextLabel_measurable hY 0
class_nonzero := by
rwa [Measure.map_apply class0_measurable
(nextLabel_measurable hY 0)]
permutes := by
intro e
rw [← map_cond sP class0_measurable
(nextLabel_measurable hY 0)]
exact map_symmetry class0_measurable (permute e).measurable (hperm e)
(Filter.Eventually.of_forall (class0_permute e))
swaps := by
intro i
rw [← map_cond sP class0_measurable
(nextLabel_measurable hY 0)]
apply map_symmetry class0_measurable (swapNext i).measurable (hswap i)
apply ae_cond_of_forall_mem (classEvent_measurable hY 0)
intro ω h
simpa only [Function.comp_apply] using class0_swapNext i.val ω h
/-- Build the class 1 interface, returning training blocks to the same
learner order. -/
noncomputable def experiment1
(hclass : sP (classEvent 1) ≠ 0)
(hperm : ∀ e, MeasurePreserving (permute1 e)
(cond sP (classEvent 1)) (cond sP (classEvent 1)))
(hswap : ∀ i : {i : Fin (n_1 + m_1) // i ∈ (gI_in_y n_1 m_1)ᶜ},
MeasurePreserving (swapNext1 i)
(cond sP (classEvent 1)) (cond sP (classEvent 1))) :
Experiment Ω (Fin (n_0 + m_0) → Ω) (Fin n_0 → Ω) gC n_1 m_1 gF where
X_rules := X_rules
«gˆS» := fun d => fit (Vector.ofFn (Fin.append d.2 d.1))
fit_measurable := hfit.comp (SampleVector.measurable_ofFn.comp
(measurable_append measurable_snd measurable_fst))
other := observed
other_measurable := observed_measurable
sP := sP.map class1
probability := inferInstance
classEvent := {d | Y d.2.2 = 1}
class_measurable := nextLabel_measurable hY 1
class_nonzero := by
rwa [Measure.map_apply class1_measurable
(nextLabel_measurable hY 1)]
permutes := by
intro e
rw [← map_cond sP class1_measurable
(nextLabel_measurable hY 1)]
exact map_symmetry class1_measurable (permute e).measurable (hperm e)
(Filter.Eventually.of_forall (class1_permute e))
swaps := by
intro i
rw [← map_cond sP class1_measurable
(nextLabel_measurable hY 1)]
apply map_symmetry class1_measurable (swapNext i).measurable (hswap i)
apply ae_cond_of_forall_mem (classEvent_measurable hY 1)
intro ω h
simpa only [Function.comp_apply] using class1_swapNext i.val ω h
section Class0
variable
(hclass : sP (classEvent 0) ≠ 0)
(hperm : ∀ e, MeasurePreserving (permute0 e)
(cond sP (classEvent 0)) (cond sP (classEvent 0)))
(hswap : ∀ i : {i : Fin (n_0 + m_0) // i ∈ (gI_in_y n_0 m_0)ᶜ},
MeasurePreserving (swapNext0 i) (cond sP (classEvent 0)) (cond sP
(classEvent 0)))
lemma experiment0_fitted (ω : mΩ Y n_0 m_0 n_1 m_1) :
let experiment := experiment0 sP hY fit hfit X_rules hclass hperm hswap
experiment.«gˆS» (experiment.mD_in (class0 ω)) = fit (mD_in ω) := by
exact congrArg fit (class0_training ω)
lemma experiment0_cond :
(experiment0 sP hY fit hfit X_rules hclass hperm hswap).sP_y =
(cond sP (classEvent 0)).map class0 :=
(map_cond sP class0_measurable (nextLabel_measurable hY 0)).symm
end Class0
section Class1
variable
(hclass : sP (classEvent 1) ≠ 0)
(hperm : ∀ e, MeasurePreserving (permute1 e)
(cond sP (classEvent 1)) (cond sP (classEvent 1)))
(hswap : ∀ i : {i : Fin (n_1 + m_1) // i ∈ (gI_in_y n_1 m_1)ᶜ},
MeasurePreserving (swapNext1 i) (cond sP (classEvent 1)) (cond sP
(classEvent 1)))
lemma experiment1_fitted (ω : mΩ Y n_0 m_0 n_1 m_1) :
let experiment := experiment1 sP hY fit hfit X_rules hclass hperm hswap
experiment.«gŜ» (experiment.mD_in (class1 ω)) = fit (mD_in ω) := by
exact congrArg fit (class1_training ω)
lemma experiment1_cond :
(experiment1 sP hY fit hfit X_rules hclass hperm hswap).sP_y =
(cond sP (classEvent 1)).map class1 :=
(map_cond sP class1_measurable (nextLabel_measurable hY 1)).symm
end Class1
end LeBet.StratifiedSample.JointSample
import LeBet.PaperAssumptions
import LeBet.JointExperiment
open MeasureTheory ProbabilityTheory
open scoped Classical
open LeBet.SampleVector
namespace LeBet.StratifiedSample.JointSample
variable {Ω : Type*} {Y : Ω → Fin 2} {n_0 m_0 n_1 m_1 : N}
/-- Extend a permutation while fixing the last coordinate. -/
def fixLast {n : N} (e : Equiv.Perm (Fin n)) : Equiv.Perm (Fin (n + 1)) where
toFun := Fin.lastCases (Fin.last n) (fun i => (e i).castSucc)
invFun := Fin.lastCases (Fin.last n) (fun i => (e.symm i).castSucc)
left_inv i := by
refine Fin.lastCases ?_ (fun i => ?_) i <;> simp
right_inv i := by
refine Fin.lastCases ?_ (fun i => ?_) i <;> simp
@[simp] lemma fixLast_castSucc {n : N} (e : Equiv.Perm (Fin n)) (i : Fin n) :
fixLast e i.castSucc = (e i).castSucc := by simp [fixLast]
@[simp] lemma fixLast_last {n : N} (e : Equiv.Perm (Fin n)) :
fixLast e (Fin.last n) = Fin.last n := by simp [fixLast]
lemma permuteNext0_fixLast (e : Equiv.Perm (Fin (n_0 + m_0)))
(ω : mΩ Y n_0 m_0 n_1 m_1) (h : Y ω.2.2 = 0) :
permuteNext0 (fixLast e) ω = permute0 e ω := by
simp only [permuteNext0, dite_eq_left h, permute0]
ext i <;> simp [Vector.getElem_push_lt]
lemma permuteNext1_fixLast (e : Equiv.Perm (Fin (n_1 + m_1)))
(ω : mΩ Y n_0 m_0 n_1 m_1) (h : Y ω.2.2 = 1) :
permuteNext1 (fixLast e) ω = permute1 e ω := by
simp only [permuteNext1, dite_eq_left h, permute1]
ext i <;> simp [Vector.getElem_push_lt]
lemma permuteNext0_swap (i : Fin (n_0 + m_0))
(ω : mΩ Y n_0 m_0 n_1 m_1) (h : Y ω.2.2 = 0) :
permuteNext0 (Equiv.swap i.castSucc (Fin.last _)) ω = swapNext0 i ω := by
simp only [permuteNext0, swapNext0, dite_eq_left h, swapAt_eq]
refine Prod.ext ?_ (Prod.ext rfl ?_)
· apply Vector.ext
intro j hj
by_cases he : j = i.val
· subst j
simp
· have hfin : (⟨j, hj⟩ : Fin (n_0 + m_0)).castSucc ̸= i.castSucc := by
intro heq
exact he (congrArg Fin.val heq)
simp only [Vector.getElem_ofFn]
simp only [Equiv.swap_apply_of_ne_of_ne hfin (Fin.castSucc_ne_last _)]
simp [hj, Ne.symm he]
· simp
lemma permuteNext1_swap (i : Fin (n_1 + m_1))
(ω : mΩ Y n_0 m_0 n_1 m_1) (h : Y ω.2.2 = 1) :
permuteNext1 (Equiv.swap i.castSucc (Fin.last _)) ω = swapNext1 i ω := by
simp only [permuteNext1, swapNext1, dite_eq_left h, swapAt_eq]
refine Prod.ext rfl (Prod.ext ?_ ?_)
· apply Vector.ext
intro j hj
by_cases he : j = i.val
· subst j
simp
· have hfin : (⟨j, hj⟩ : Fin (n_1 + m_1)).castSucc ̸= i.castSucc := by
intro heq
exact he (congrArg Fin.val heq)
simp only [Vector.getElem_ofFn]
simp only [Equiv.swap_apply_of_ne_of_ne hfin (Fin.castSucc_ne_last _)]
simp [hj, Ne.symm he]
· simp
variable [MeasurableSpace Ω] {sP : Measure (mΩ Y n_0 m_0 n_1 m_1)}
lemma permutes0_of_exchangeable (hY : Measurable Y) (h :
FiniteExchangeableExtension sP)
(e : Equiv.Perm (Fin (n_0 + m_0))) :
MeasurePreserving (permute0 e) (cond sP (classEvent 0)) (cond sP
(classEvent 0)) := by
refine ⟨permute0_measurable e, ?_⟩
calc
_ = (cond sP (classEvent 0)).map (permuteNext0 (fixLast e)) := by
apply Measure.map_congr
apply ae_cond_of_forall_mem (classEvent_measurable hY 0)
intro ω hω
exact (permuteNext0_fixLast e ω hω).symm
_ = _ := h.1 _
lemma permutes1_of_exchangeable (hY : Measurable Y) (h :
FiniteExchangeableExtension sP)
(e : Equiv.Perm (Fin (n_1 + m_1))) :
MeasurePreserving (permute1 e) (cond sP (classEvent 1)) (cond sP
(classEvent 1)) := by
refine ⟨permute1_measurable e, ?_⟩
calc
_ = (cond sP (classEvent 1)).map (permuteNext1 (fixLast e)) := by
apply Measure.map_congr
apply ae_cond_of_forall_mem (classEvent_measurable hY 1)
intro ω hω
exact (permuteNext1_fixLast e ω hω).symm
_ = _ := h.2.2.1 _
lemma swaps0_of_exchangeable (hY : Measurable Y) (h :
FiniteExchangeableExtension sP)
(i : Fin (n_0 + m_0)) :
MeasurePreserving (swapNext0 i) (cond sP (classEvent 0)) (cond sP
(classEvent 0)) := by
refine ⟨swapNext0_measurable hY i, ?_⟩
calc
_ = (cond sP (classEvent 0)).map (permuteNext0 (Equiv.swap i.castSucc
(Fin.last _))) := by
apply Measure.map_congr
apply ae_cond_of_forall_mem (classEvent_measurable hY 0)
intro ω hω
exact (permuteNext0_swap i ω hω).symm
_ = _ := h.1 _
lemma swaps1_of_exchangeable (hY : Measurable Y) (h :
FiniteExchangeableExtension sP)
(i : Fin (n_1 + m_1)) :
MeasurePreserving (swapNext1 i) (cond sP (classEvent 1)) (cond sP
(classEvent 1)) := by
refine ⟨swapNext1_measurable hY i, ?_⟩
calc
_ = (cond sP (classEvent 1)).map (permuteNext1 (Equiv.swap i.castSucc
(Fin.last _))) := by
apply Measure.map_congr
apply ae_cond_of_forall_mem (classEvent_measurable hY 1)
intro ω hω
exact (permuteNext1_swap i ω hω).symm
_ = _ := h.2.2.1 _
end LeBet.StratifiedSample.JointSample
import LeBet.ConditionalCoverage
open MeasureTheory
namespace LeBet
/-- Conditioning commutes with a measurable change of sample coordinates. -/
theorem condExp_map {α β : Type*} {m : MeasurableSpace β}
[mα : MeasurableSpace α] [mβ : MeasurableSpace β]
(P : Measure α) [IsProbabilityMeasure P] {f : α → β} (hf : Measurable f)
(hm : m ≤ mβ) {g : β → ℝ}
(hg : Integrable g (P.map f)) :
(fun x => (P.map f)[g | m] (f x)) =ᵐ[P]
P[g ∘ f | MeasurableSpace.comap f m] := by
have hmf : MeasurableSpace.comap f m ≤ mα :=
(MeasurableSpace.comap_mono hm).trans hf.comap_le
have hg' : Integrable (g ∘ f) P :=
(integrable_map_measure hg.aestronglyMeasurable hf.aemeasurable).mp hg
have hce : Integrable (fun x => (P.map f)[g | m] (f x)) P :=
(integrable_map_measure integrable_condExp.aestronglyMeasurable
hf.aemeasurable).mp
integrable_condExp
refine ae_eq_condExp_of_forall_setIntegral_eq hmf hg'
(fun _ _ _ => hce.integrableOn) ?_ ?_
· intro A hA _
obtain ⟨B, hB, rfl⟩ := hA
rw [← setIntegral_map (hm _ hB) integrable_condExp.aestronglyMeasurable
hf.aemeasurable,
setIntegral_condExp hm hg hB, setIntegral_map (hm _ hB)
hg.aestronglyMeasurable hf.aemeasurable]
· exact (stronglyMeasurable_condExp.comp_measurable (comap_measurable
f)).aestronglyMeasurable
/-- A conditional-mean identity is preserved by measurable sample
coordinates. -/
theorem condExp_map_eq {α β : Type*} {m : MeasurableSpace β}
[mα : MeasurableSpace α] [mβ : MeasurableSpace β]
(P : Measure α) [IsProbabilityMeasure P] {f : α → β} (hf : Measurable f)
(hm : m ≤ mβ) {g h : β → ℝ}
(hg : Integrable g (P.map f)) (hh : Integrable h (P.map f))
(heq : (P.map f)[g | m] =ᵐ[P.map f] (P.map f)[h | m]) :
P[g ∘ f | MeasurableSpace.comap f m] =ᵐ[P]
P[h ∘ f | MeasurableSpace.comap f m] := by
have heq' := ae_of_ae_map hf.aemeasurable heq
filter_upwards [condExp_map P hf hm hg, condExp_map P hf hm hh, heq'] with
ω hgω hhω heqω
exact hgω.symm.trans (heqω.trans hhω)
set_option maxHeartbeats 800000 in
/-- A conditional upper-tail bound is unchanged by measurable sample
coordinates. -/
theorem condExp_map_tail {α β : Type*} {m : MeasurableSpace β}
[mα : MeasurableSpace α] [mβ : MeasurableSpace β]
(P : Measure α) [IsProbabilityMeasure P] {f : α → β} (hf : Measurable f)
(hm : m ≤ mβ) {g : β → ℝ} (hg : Integrable g (P.map f)) (c : ℝ) :
P.real {x | c < P[g ∘ f | MeasurableSpace.comap f m] x} =
(P.map f).real {x | c < (P.map f)[g | m] x} := by
have h := condExp_map P hf hm hg
calc
_ = P.real (f ⁻¹' {x | c < (P.map f)[g | m] x}) := by
apply measureReal_congr
filter_upwards [h] with x hx
simp only [Set.mem_ofPred_eq, Set.mem_preimage, hx]
_ = _ := (map_measureReal_apply hf
(measurableSet_lt measurable_const (stronglyMeasurable_condExp.mono
hm).measurable)).symm
/-- Transfer a simultaneous conditional bound for a finite candidate class. -/
theorem condExp_map_exists {α β ι : Type*} [Fintype ι] {m : MeasurableSpace β}
[mα : MeasurableSpace α] [mβ : MeasurableSpace β]
(P : Measure α) [IsProbabilityMeasure P] {f : α → β} (hf : Measurable f)
(hm : m ≤ mβ) {g : ι → β → ℝ} (hg : ∀ i, Integrable (g i) (P.map f)) (c
: ℝ) :
P.real {x | ∃ i, c < P[g i ∘ f | MeasurableSpace.comap f m] x} =
(P.map f).real {x | ∃ i, c < (P.map f)[g i | m] x} := by
have hall : ∀ᵐ x ∂P, ∀ i, (P.map f)[g i | m] (f x) =
P[g i ∘ f | MeasurableSpace.comap f m] x :=
ae_all_iff.mpr (fun i => condExp_map P hf hm (hg i))
have hA : MeasurableSet {x | ∃ i, c < (P.map f)[g i | m] x} := by
simp only [Set.setOf_exists]
exact MeasurableSet.iUnion (fun i =>
measurableSet_lt measurable_const (stronglyMeasurable_condExp.mono
hm).measurable)
calc
_ = P.real (f ⁻¹' {x | ∃ i, c < (P.map f)[g i | m] x}) := by
apply measureReal_congr
filter_upwards [hall] with x hx
simp only [Set.mem_ofPred_eq, Set.mem_preimage]
apply propext
exact exists_congr (fun i => by rw [hx i])
_ = _ := (map_measureReal_apply hf hA).symm
end LeBet
Condition the average stability failure on the next label.
open Finset MeasureTheory ProbabilityTheory
open scoped Classical
namespace LeBet.ConditionalCoverage
variable {Ω : Type*} [MeasurableSpace Ω] {sP : Measure Ω}
[IsProbabilityMeasure sP]
lemma class_failure_bound {B G : Set Ω} (hB : MeasurableSet B) {delta : ℝ}
(hfail : sP.real Gᶜ ≤ delta) :
(cond sP B).real Gᶜ ≤ delta / sP.real B := by
have he : (cond sP B).real Gᶜ = sP.real (B ∩ Gᶜ) / sP.real B := by
simp only [Measure.real, cond_apply hB, ENNReal.toReal_mul,
ENNReal.toReal_inv,
div_eq_mul_inv, mul_comm]
rw [he]
apply div_le_div_of_nonneg_right _ ENNReal.toReal_nonneg
exact (measureReal_mono Set.inter_subset_right).trans hfail
end LeBet.ConditionalCoverage
open Finset MeasureTheory ProbabilityTheory
open scoped Classical
namespace LeBet.ConditionalCoverage
variable {Ω : Type*} [MeasurableSpace Ω] {sP : Measure Ω}
[IsProbabilityMeasure sP]
lemma class_average_failure_bound {ι : Type*} (S : Finset ι) (G : ι → Set Ω)
{B : Set Ω} (hB : MeasurableSet B) {delta : ℝ}
(hfail : Finset.expect S (fun i => sP.real (G i)ᶜ) ≤ delta) :
Finset.expect S (fun i => (cond sP B).real (G i)ᶜ) ≤ delta / sP.real B :=
by
calc
_ ≤ Finset.expect S (fun i => sP.real (G i)ᶜ / sP.real B) :=
Finset.expect_le_expect fun i _ => class_failure_bound hB le_rfl
_ = Finset.expect S (fun i => sP.real (G i)ᶜ) / sP.real B :=
(Finset.expect_div _ _ _).symm
_ ≤ _ := div_le_div_of_nonneg_right hfail ENNReal.toReal_nonneg
end LeBet.ConditionalCoverage
import LeBet.FittedScores
import LeBet.ScoreSymmetry
open MeasureTheory ProbabilityTheory Finset
open scoped Classical
namespace LeBet
variable {SampleSpace Ω TrainingSpace gC : Type*} [mSampleSpace :
MeasurableSpace SampleSpace] [mΩ : MeasurableSpace Ω]
[mTrainingSpace : MeasurableSpace TrainingSpace] [MeasurableSpace gC]
[Fintype gC] [MeasurableSingletonClass gC]
/-- Training is available initially; only the next trajectory’s history grows
with time. -/
def learnedFiltration (classTraining : SampleSpace → TrainingSpace) (ht :
Measurable classTraining)
(next : SampleSpace → Ω) (hn : Measurable next) (gF : Filtration ℕ mΩ) :
Filtration ℕ mSampleSpace where
seq t := mTrainingSpace.comap classTraining ⊔ (gF t).comap next
mono’ _ _ h := sup_le_sup_left (MeasurableSpace.comap_mono (gF.mono h)) _
le’ t := sup_le ht.comap_le ((MeasurableSpace.comap_mono (gF.le t)).trans
hn.comap_le)
lemma measurable_selected (g : gC → Ω → ℝ) (hg : ∀ c, Measurable (g c))
(«ĝS» : TrainingSpace → gC) (hf : Measurable «ĝS») :
Measurable fun p : TrainingSpace × Ω => g («ĝS» p.1) p.2 := by
have he : Measurable fun p : Ω × gC => g p.2 p.1 :=
measurable_from_prod_countable_left hg
exact he.comp (measurable_snd.prodMk (hf.comp measurable_fst))
/-- The deployed monitor, built from the actual measurable learner and next
trajectory. -/
def learnedMonitor {gF : Filtration N mΩ} (X : gC → BinaryMonitor gF)
(«gˆS» : TrainingSpace → gC) (hf : Measurable «gˆS») (classTraining :
SampleSpace → TrainingSpace) (ht : Measurable classTraining)
(next : SampleSpace → Ω) (hn : Measurable next) :
BinaryMonitor (learnedFiltration classTraining ht next hn gF) where
X s ω := (X («gˆS» (classTraining ω))).X s (next ω)
adapted s := by
let gG := learnedFiltration classTraining ht next hn gF
have hfit : Measurable[gG (s + 1)] (fun ω => «gˆS» (classTraining ω)) :=
(hf.comp (comap_measurable classTraining)).mono le_sup_left le_rfl
have hx (c : gC) : Measurable[gG (s + 1)] (fun ω => (X c).X s (next ω)) :=
(((X c).adapted s).measurable.comp (comap_measurable next)).mono
le_sup_right le_rfl
have he : @Measurable (SampleSpace × gC) R
((gG (s + 1)).prod inferInstance) inferInstance
(fun p => (X p.2).X s (next p.1)) :=
measurable_from_prod_countable_left hx
exact (he.comp (measurable_id.prodMk hfit)).stronglyMeasurable
binary s ω := (X («gˆS» (classTraining ω))).binary s (next ω)
lemma learnedMonitor_upperConfidenceBound {gF : Filtration N mΩ} (X : gC →
BinaryMonitor gF)
(«gˆS» : TrainingSpace → gC) (hf : Measurable «gˆS») (classTraining :
SampleSpace → TrainingSpace) (ht : Measurable classTraining)
(next : SampleSpace → Ω) (hn : Measurable next) (η γ : R)
(gW : Finset N) (hne : gW.Nonempty) (ω : SampleSpace) :
(learnedMonitor X «gˆS» hf classTraining ht next hn).upperConfidenceBound η
γ gW hne ω =
(X («gˆS» (classTraining ω))).upperConfidenceBound η γ gW hne (next ω)
:= rfl
lemma learnedMonitor_lowerConfidenceBound {gF : Filtration N mΩ} (X : gC →
BinaryMonitor gF)
(«gˆS» : TrainingSpace → gC) (hf : Measurable «gˆS») (classTraining :
SampleSpace → TrainingSpace) (ht : Measurable classTraining)
(next : SampleSpace → Ω) (hn : Measurable next) (η γ : R)
(gW : Finset N) (hne : gW.Nonempty) (ω : SampleSpace) :
(learnedMonitor X «gˆS» hf classTraining ht next hn).lowerConfidenceBound η
γ gW hne ω =
(X («gˆS» (classTraining ω))).lowerConfidenceBound η γ gW hne (next ω)
:= rfl
namespace StratifiedSample
variable {OtherTraining : Type*} [MeasurableSpace OtherTraining] {n_y : N}
{gF : Filtration N mΩ}
(X : gC → BinaryMonitor gF) («gˆS» : ((Fin n_y → Ω) × OtherTraining) → gC)
(hf : Measurable «gˆS»)
(η γ : R) (gW : Finset N) (hne : gW.Nonempty)
noncomputable def upperStatistic
(hsym : ∀ (a : Equiv.Perm (Fin n_y)) (d : (Fin n_y → Ω) × OtherTraining)
z,
(X («gŜ» (d.1 ◦ a, d.2))).upperConfidenceBound η γ gW hne z =
(X («gŜ» d)).upperConfidenceBound η γ gW hne z) : Statistic Ω
OtherTraining n_y where
value p := (X («gŜ» p.1)).upperConfidenceBound η γ gW hne p.2
measurable := measurable_selected _ (fun c => (X
c).upperConfidenceBound_measurable η γ gW hne) «gŜ» hf
symmetric := hsym
noncomputable def lowerStatistic
(hsym : ∀ (a : Equiv.Perm (Fin n_y)) (d : (Fin n_y → Ω) × OtherTraining)
z,
(X («gŜ» (d.1 ◦ a, d.2))).lowerConfidenceBound η γ gW hne z =
(X («gŜ» d)).lowerConfidenceBound η γ gW hne z) : Statistic Ω
OtherTraining n_y where
value p := −(X («gŜ» p.1)).lowerConfidenceBound η γ gW hne p.2
measurable :=
(measurable_selected _ (fun c => (X c).lowerConfidenceBound_measurable η γ
gW hne) «gŜ» hf).neg
symmetric a d z := congrArg Neg.neg (hsym a d z)
/-- The signed statistic uses exactly the paper’s lower empirical endpoint. -/
lemma lowerStatistic_quantile
(hsym : ∀ (a : Equiv.Perm (Fin n_y)) (d : (Fin n_y → Ω) × OtherTraining)
z,
(X («gŜ» (d.1 ◦ a, d.2))).lowerConfidenceBound η γ gW hne z =
(X («gŜ» d)).lowerConfidenceBound η γ gW hne z)
(d : (Fin n_y → Ω) × OtherTraining) (r : N) (hr : r < n_y) :
(lowerStatistic X «gŜ» hf η γ gW hne hsym).quantile d r hr =
−EmpiricalOptimization.lowerQuantile
(fun i => (X («gŜ» d)).lowerConfidenceBound η γ gW hne (d.1 i)) r hr
:=
EmpiricalOptimization.upperQuantile_neg _ r hr
end StratifiedSample
end LeBet
The fitted monitor is adapted to the sample-augmented filtration.
import LeBet.MeanLearning
import LeBet.LearnedMonitor
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : N}
/-- Classwise occurrence coordinates. The next trajectory is one of the
coordinates; the other class is retained in ‘O‘. -/
abbrev Sample (Ω O : Type*) (N : ℕ) := (Fin N → Ω) × O
/-- The same learner is defined on every reduced sample size. -/
structure Learner (Ω R C : Type*) [MeasurableSpace Ω] [MeasurableSpace R]
[MeasurableSpace C] where
fit : (k : ℕ) → ((Fin k → Ω) × R) → C
measurable : ∀ k, Measurable (fit k)
invariant : ∀ k (e : Equiv.Perm (Fin k)) d,
fit k (d.1 ∘ e, d.2) = fit k d
/-- Relabel occurrence coordinates while fixing the other class. -/
def permute (e : Equiv.Perm (Fin N)) : Sample Ω O N ≃ᵐ Sample Ω O N where
toFun ω := (ω.1 ∘ e, ω.2)
invFun ω := (ω.1 ∘ e.symm, ω.2)
left_inv ω := by ext i <;> simp
right_inv ω := by ext i <;> simp
measurable_toFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e i)).comp
measurable_fst).prodMk
measurable_snd
measurable_invFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e.symm i)).comp
measurable_fst).prodMk
measurable_snd
variable (other : O → R) (ho : Measurable other)
noncomputable def training (K : Finset (Fin N)) (ω : Sample Ω O N) :
(Fin K.card → Ω) × R :=
((fun i => ω.1 (K.orderEmbOfFin rfl i)), other ω.2)
include ho in
lemma training_measurable (K : Finset (Fin N)) : Measurable (training (Ω := Ω)
other K) :=
(measurable_pi_iff.mpr fun i =>
(measurable_pi_apply _).comp measurable_fst).prodMk (ho.comp
measurable_snd)
/-- The sigma-algebra of the retained training occurrences. -/
def information (K : Finset (Fin N)) : MeasurableSpace (Sample Ω O N) :=
(⨆ i ∈ K, MeasurableSpace.comap (fun ω : Sample Ω O N => ω.1 i)
inferInstance) ⊔
MeasurableSpace.comap (fun ω : Sample Ω O N => other ω.2) inferInstance
include ho in
lemma information_le (K : Finset (Fin N)) :
information other K ≤ (inferInstance : MeasurableSpace (Sample Ω O N)) :=
by
apply sup_le
· exact iSup_le fun i => iSup_le fun _ =>
((measurable_pi_apply i).comp measurable_fst).comap_le
· exact (ho.comp measurable_snd).comap_le
lemma coordinate_measurable (K : Finset (Fin N)) (i : Fin N) (hi : i ∈ K) :
Measurable[information other K] (fun ω : Sample Ω O N => ω.1 i) := by
rw [measurable_iff_comap_le]
unfold information
apply le_sup_of_le_left
apply le_iSup_of_le i
exact le_iSup_of_le hi le_rfl
lemma training_information_measurable (K : Finset (Fin N)) :
Measurable[information other K] (training (Ω := Ω) other K) := by
letI : MeasurableSpace (Sample Ω O N) := information other K
exact (measurable_pi_iff.mpr fun i =>
coordinate_measurable other K _ (orderEmbOfFin_mem K rfl i)).prodMk
((comap_measurable (fun ω : Sample Ω O N => other ω.2)).mono
le_sup_right le_rfl)
lemma information_eq (K : Finset (Fin N)) :
information (Ω := Ω) other K =
MeasurableSpace.comap (training other K) inferInstance := by
apply le_antisymm
· apply sup_le
· apply iSup_le
intro i
apply iSup_le
intro hi
obtain ⟨j, hj⟩ := (show i ∈ Set.range (K.orderEmbOfFin rfl) by
rw [range_orderEmbOfFin]
exact hi)
apply Measurable.comap_le
have h : Measurable[MeasurableSpace.comap (training other K)
inferInstance]
(fun ω => (training other K ω).1 j) :=
(measurable_pi_apply j).comp
(measurable_fst.comp (comap_measurable (training (Ω := Ω) other K)))
simpa only [training, hj] using h
· exact (measurable_snd.comp (comap_measurable (training other
K))).comap_le
· exact (training_information_measurable other K).comap_le
lemma information_mono {K L : Finset (Fin N)} (hKL : K ⊆ L) :
information (Ω := Ω) other K ≤ information other L := by
apply sup_le
· exact iSup_le fun i => iSup_le fun hi =>
(coordinate_measurable other L i (hKL hi)).comap_le
· exact le_sup_right
variable (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
/-- The filtration conditions on the retained data and the evaluated history.
-/
def filtration (K : Finset (Fin N)) (i : Fin N) :
Filtration N (inferInstance : MeasurableSpace (Sample Ω O N)) where
seq t := information other K ⊔
MeasurableSpace.comap (fun ω : Sample Ω O N => ω.1 i) (gF t)
mono’ _ _ h := sup_le_sup_left (MeasurableSpace.comap_mono (gF.mono h)) _
le’ t := sup_le (information_le other ho K)
((MeasurableSpace.comap_mono (gF.le t)).trans
((measurable_pi_apply i).comp measurable_fst).comap_le)
/-- The monitor is fitted on ‘K‘; use ‘K.erase i‘ for a leave-one-out fit. -/
noncomputable def monitor (K : Finset (Fin N)) (i : Fin N) :
BinaryMonitor (filtration other ho (gF := gF) K i) where
X s ω := (rules (learner.fit K.card (training other K ω))).X s (ω.1 i)
adapted s := by
let M := (filtration other ho (gF := gF) K i) (s + 1)
have hfit : Measurable[M] (fun ω => learner.fit K.card (training other K ω)) :=
((learner.measurable _).comp (training_information_measurable other
K)).mono le_sup_left le_rfl
have hx (c : C) : Measurable[M] (fun ω : Sample Ω O N => (rules c).X s
(ω.1 i)) :=
(((rules c).adapted s).measurable.comp (comap_measurable _)).mono
le_sup_right le_rfl
have he : @Measurable (Sample Ω O N × C) ℝ (M.prod inferInstance)
inferInstance
(fun p => (rules p.2).X s (p.1.1 i)) :=
measurable_from_prod_countable_left hx
exact (he.comp (measurable_id.prodMk hfit)).stronglyMeasurable
binary s ω := (rules (learner.fit K.card (training other K ω))).binary s
(ω.1 i)
lemma leave_one_out_filtration_le (K : Finset (Fin N)) (i : Fin N) (hi : i ∈
K)
(t : N) :
filtration other ho (gF := gF) (K.erase i) i t ≤ information other K :=
sup_le (information_mono other (erase_subset _ _))
((MeasurableSpace.comap_mono (gF.le t)).trans
(coordinate_measurable other K i hi).comap_le)
lemma next_filtration_initial (K : Finset (Fin N)) (i : Fin N) :
information other K ≤ filtration other ho (gF := gF) K i 0 := le_sup_left
end LeBet.LeaveOneOut
Finite averaging gives conditional means with exact permutation symmetry.
import LeBet.ConditionalPullback
import LeBet.Monitor
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.EquivariantConditionalMeans
variable {G J Ω : Type*} [Group G] [Fintype G] [MulAction G J] [MulAction G Ω]
/-- Average versions over the finite permutation group. Both the occurrence
index and the sample are relabelled. -/
noncomputable def average (f : J → Ω → ℝ) (j : J) (ω : Ω) : ℝ :=
(∑ g : G, f (g • j) (g • ω)) / Fintype.card G
lemma average_equivariant (f : J → Ω → R) (g : G) (j : J) (ω : Ω) :
average (G := G) f (g • j) (g • ω) = average (G := G) f j ω := by
unfold average
congr 1
exact Fintype.sum_equiv (Equiv.mulRight g) _ _
(fun h => by simp only [Equiv.coe_mulRight, mul_smul])
variable {mΩ : MeasurableSpace Ω} {sP : Measure Ω} [IsProbabilityMeasure sP]
omit [IsProbabilityMeasure sP] in
lemma average_ae (f : J → Ω → R)
(heq : ∀ (g : G) (j : J), (fun ω => f (g • j) (g • ω)) =ᵐ[sP] f j) (j :
J) :
average (G := G) f j =ᵐ[sP] f j := by
have hall := ae_all_iff.mpr (fun g : G => heq g j)
filter_upwards [hall] with ω hω
unfold average
simp_rw [hω]
have hc : (Fintype.card G : R) ≠ 0 := by exact_mod_cast Fintype.card_pos.ne'
simp [hc, nsmul_eq_mul]
lemma average_measurable (M : J → MeasurableSpace Ω) (f : J → Ω → R)
(hf : ∀ j, Measurable[M j] (f j))
(hmap : ∀ (g : G) (j : J), Measurable[M j, M (g • j)] (fun ω : Ω => g • ω
)) (j : J) :
Measurable[M j] (average (G := G) f j) :=
(Finset.measurable_sum univ (fun g _ => (hf (g • j)).comp (hmap g
j))).div_const _
lemma average_bounds (f : J → Ω → R)
(hf : ∀ j ω, 0 ≤ f j ω ∧ f j ω ≤ 1) (j : J) (ω : Ω) :
0 ≤ average (G := G) f j ω ∧ average (G := G) f j ω ≤ 1 := by
have hc : (0 : R) < Fintype.card G := by exact_mod_cast Fintype.card_pos
refine ⟨div_nonneg (sum_nonneg fun g _ => (hf (g • j) (g • ω)).1) hc.le, ?_⟩
apply (div_le_one hc).mpr
exact (sum_le_sum (fun g _ => (hf (g • j) (g • ω)).2)).trans_eq (by simp)
omit [Fintype G] in
/-- Conditional expectation respects relabelling almost surely. -/
lemma conditional_expectation_equivariant
(M : J → MeasurableSpace Ω) (hM : ∀ j, M j ≤ mΩ)
(act : G → @MeasurableEquiv Ω Ω mΩ mΩ)
(hact : ∀ g ω, act g ω = g • ω)
(hpres : ∀ g, @MeasurePreserving Ω Ω mΩ mΩ (act g) sP sP)
(hfield : ∀ (g : G) (j : J), MeasurableSpace.comap (act g) (M (g • j)) = M
j)
(f : J → Ω → R) (hf : ∀ j, Integrable (f j) sP)
(hperm : ∀ (g : G) (j : J) ω, f (g • j) (g • ω) = f j ω) (g : G) (j : J) :
(fun ω => sP[f (g • j) | M (g • j)] (g • ω)) =ᵐ[sP] sP[f j | M j] := by
have hi : Integrable (f (g • j)) (sP.map (act g)) := by
rw [(hpres g).map_eq]
exact hf _
have h := condExp_map sP (act g).measurable (hM (g • j)) hi
rw [(hpres g).map_eq, hfield g j] at h
have he : f (g • j) ∘ act g = f j := by
funext ω
exact (congrArg (f (g • j)) (hact g ω)).trans (hperm g j ω)
simpa only [he, hact] using h
/-- A clipped conditional expectation is a bounded version for a ‘[0,1]’
value. -/
lemma clipped_condExp_ae {m : MeasurableSpace Ω} (hm : m ≤ mΩ) {f : Ω → ℝ}
(hf : Integrable f sP) (hf0 : ∀ ω, 0 ≤ f ω) (hf1 : ∀ ω, f ω ≤ 1) :
(fun ω => max 0 (min 1 (sP[f | m] ω))) =ₘ[sP] sP[f | m] := by
have hlo := condExp_nonneg (m := m) (ae_of_all sP hf0)
have hhi := condExp_mono (m := m) hf (integrable_const 1) (ae_of_all sP hf1)
rw [condExp_const hm] at hhi
filter_upwards [hlo, hhi] with ω hlo hhi
change 0 ≤ sP[f | m] ω at hlo
simp only [min_eq_right hhi, max_eq_right hlo]
/-- The equivariant versions used before stating predictable-value stability
exist on the original probability space. This adds no distributional
assumption. -/
theorem versions_exist
(M : J → MeasurableSpace Ω) (hM : ∀ j, M j ≤ mΩ)
(act : G → @MeasurableEquiv Ω Ω mΩ mΩ)
(hact : ∀ g ω, act g ω = g • ω)
(hpres : ∀ g, @MeasurePreserving Ω Ω mΩ mΩ (act g) sP sP)
(hfield : ∀ (g : G) (j : J), MeasurableSpace.comap (act g) (M (g • j)) = M
(f : J → Ω → ℝ) (hf : ∀ j, Integrable (f j) sP)
(hbound : ∀ j ω, 0 ≤ f j ω ∧ f j ω ≤ 1)
(hperm : ∀ (g : G) (j : J) ω, f (g • j) (g • ω) = f j ω) :
∃ μ : J → Ω → ℝ,
(∀ j, Measurable[M j] (μ j)) ∧
(∀ j, μ j =ₘ[sP] sP[f j | M j]) ∧
(∀ (g : G) (j : J) ω, μ (g • j) (g • ω) = μ j ω) ∧
(∀ j ω, 0 ≤ μ j ω ∧ μ j ω ≤ 1) := by
let c : J → Ω → ℝ := fun j ω => max 0 (min 1 (sP[f j | M j] ω))
have hc : ∀ j, Measurable[M j] (c j) := fun j =>
measurable_const.max (measurable_const.min
stronglyMeasurable_condExp.measurable)
have hc_ae (j : J) : c j =ₘ[sP] sP[f j | M j] :=
clipped_condExp_ae (hM j) (hf j) (fun ω => (hbound j ω).1) (fun ω =>
(hbound j ω).2)
have hc_perm (g : G) (j : J) : (fun ω => c (g • j) (g • ω)) =ₘ[sP] c j := by
filter_upwards [conditional_expectation_equivariant M hM act hact hpres
hfield f hf hperm g j]
with ω hω
dsimp only [c]
rw [hω]
have hmap (g : G) (j : J) : Measurable[M j, M (g • j)] (fun ω : Ω => g • ω)
:= by
have he : (fun ω => g • ω) = (act g : Ω → Ω) := (funext (hact g)).symm
rw [he, ← hfield g j]
exact comap_measurable (m := M (g • j)) (act g)
refine ⟨average (G := G) c, average_measurable M c hc hmap,
(fun j => (average_ae c hc_perm j).trans (hc_ae j)), average_equivariant
c, ?_⟩
exact average_bounds c (fun _ _ => ⟨le_max_left _ _,
max_le zero_le_one (min_le_left _ _)⟩)
end LeBet.EquivariantConditionalMeans
import LeBet.LeaveOneOutModel
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : ℕ} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
lemma fit_training_eq {k : ℕ} (K : Finset (Fin N)) (hK : K.card = k)
(ω : Sample Ω O N) :
learner.fit K.card (training other K ω) =
learner.fit k (StratifiedSample.subtuple K hK ω.1, other ω.2) := by
subst k
rfl
lemma fit_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N)) (ω : Sample Ω
O N) :
learner.fit K.card (training other K (permute e ω)) =
learner.fit (relabel e K).card (training other (relabel e K) ω) := by
rw [fit_training_eq other learner K rfl,
fit_training_eq other learner (relabel e K) (relabel_card e K)]
obtain ⟨a, ha⟩ := StratifiedSample.subtuple_permute e K rfl ω.1
change learner.fit K.card (StratifiedSample.subtuple K rfl (ω.1 ∘ e), other
ω.2) = _
rw [ha]
exact learner.invariant K.card a
(StratifiedSample.subtuple (relabel e K) (relabel_card e K) ω.1, other ω
.2)
lemma information_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N)) :
MeasurableSpace.comap (permute (Ω := Ω) (O := O) e) (information other K)
= information other (relabel e K) := by
simp only [information, MeasurableSpace.comap_sup,
MeasurableSpace.comap_iSup,
MeasurableSpace.comap_comp, Function.comp_def, permute]
congr 1
apply le_antisymm
· apply iSup_le
intro i
apply iSup_le
intro hi
apply le_iSup_of_le (e i)
have hei : e i ∈ relabel e K := by simpa only [mem_relabel,
e.symm_apply_apply]
exact le_iSup_of_le hei le_rfl
· apply iSup_le
intro i
apply iSup_le
intro hi
apply le_iSup_of_le (e.symm i)
have hei : e.symm i ∈ K := (mem_relabel e K i).mp hi
apply le_iSup_of_le hei
simp
lemma filtration_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N))
(i : Fin N) (t : N) :
MeasurableSpace.comap (permute (Ω := Ω) (O := O) e)
(filtration other ho (gF := gF) K i t) =
filtration other ho (gF := gF) (relabel e K) (e i) t := by
change MeasurableSpace.comap (permute e)
(information other K ⊔ MeasurableSpace.comap (fun ω : Sample Ω O N => ω.1
i) (gF t)) = _
rw [MeasurableSpace.comap_sup, information_permute,
MeasurableSpace.comap_comp]
rfl
lemma monitor_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N))
(i : Fin N) (t : N) (ω : Sample Ω O N) :
(monitor other ho learner rules K i).X t (permute e ω) =
(monitor other ho learner rules (relabel e K) (e i)).X t ω := by
change (rules (learner.fit K.card (training other K (permute e ω)))).X t
(ω.1 (e i)) = _
rw [fit_permute]
rfl
noncomputable def sampleAction : MulAction (Equiv.Perm (Fin N)) (Sample Ω O
N) where
smul e ω := permute e.symm ω
one_smul ω := by ext i <;> rfl
mul_smul e f ω := by ext i <;> rfl
noncomputable def indexAction :
MulAction (Equiv.Perm (Fin N)) (Finset (Fin N) × Fin N) where
smul e j := (relabel e j.1, e j.2)
one_smul j := by
apply Prod.ext
· ext i
change i ∈ relabel 1 j.1 ↔ i ∈ j.1
simp only [mem_relabel]
· rfl
mul_smul e f j := by
apply Prod.ext
· ext i
change i ∈ relabel (e * f) j.1 ↔ i ∈ relabel e (relabel f j.1)
simp only [mem_relabel]
rfl
· rfl
noncomputable local instance : MulAction (Equiv.Perm (Fin N)) (Sample Ω O N)
:= sampleAction
noncomputable local instance : MulAction (Equiv.Perm (Fin N)) (Finset (Fin N)
× Fin N) := indexAction
variable (sP : Measure (Sample Ω O N)) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
include hex in
/-- Equivariant conditional-mean versions are constructed from the learner and
exchangeability; they are not additional assumptions. -/
theorem conditional_versions_exist (s : N) :
∃ μ : (Finset (Fin N) × Fin N) → Sample Ω O N → ℝ,
(∀ j, Measurable[filtration other ho (gF := gF) j.1 j.2 s] (μ j)) ∧
(∀ j, μ j =ᵐ[sP]
(monitor other ho learner rules j.1 j.2).μ sP s) ∧
(∀ e j ω, μ j (permute e ω) = μ (relabel e j.1, e j.2) ω) ∧
(∀ j ω, 0 ≤ μ j ω ∧ μ j ω ≤ 1) := by
let M (j : Finset (Fin N) × Fin N) := filtration other ho (gF := gF) j.1
j.2 s
let f (j : Finset (Fin N) × Fin N) := (monitor other ho learner rules j.1
j.2).X s
have hfield (e : Equiv.Perm (Fin N)) (j : Finset (Fin N) × Fin N) :
MeasurableSpace.comap (permute e.symm) (M (e • j)) = M j := by
change MeasurableSpace.comap (permute e.symm)
(filtration other ho (gF := gF) (relabel e j.1) (e j.2) s) = _
rw [filtration_permute, relabel_symm, e.symm_apply_apply]
have hfperm (e : Equiv.Perm (Fin N)) (j : Finset (Fin N) × Fin N) (ω :
Sample Ω O N) :
f (e • j) (e • ω) = f j ω := by
change (monitor other ho learner rules (relabel e j.1) (e j.2)).X s
(permute e.symm ω) = _
rw [monitor_permute, relabel_symm, e.symm_apply_apply]
obtain ⟨μ, hμm, hμa, hμe, hμb⟩ :=
EquivariantConditionalMeans.versions_exist M (fun j => (filtration other
ho j.1 j.2).le s)
(fun e => permute e.symm) (fun _ _ => rfl) (fun e => hex e.symm) hfield
(fun j => (monitor other ho learner rules j.1 j.2).integrable sP s)
(fun j ω => ⟨(monitor other ho learner rules j.1 j.2).nonneg s ω,
(monitor other ho learner rules j.1 j.2).le_one s ω⟩) hfperm
refine ⟨μ, hμm, (fun j => (hμa j).trans
((monitor other ho learner rules j.1 j.2).mean_ae sP s).symm), ?_, hμb⟩
intro e j ω
have h := hμe e j (permute e ω)
change μ (relabel e j.1, e j.2) (permute e.symm (permute e ω)) = μ j
(permute e ω) at h
have he : permute e.symm (permute e ω) = ω := by ext i <;> simp [permute]
simpa only [he] using h.symm
end LeBet.LeaveOneOut
import LeBet.LeaveOneOutSymmetry
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open FiniteSampling
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{N : N} (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O N)) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
/-- Bounded, equivariant versions of the one-step conditional expectations. -/
noncomputable def conditionalMeanVersion (s : N) (K : Finset (Fin N)) (i :
Fin N) :
Sample Ω O N → R :=
Classical.choose (conditional_versions_exist other ho learner rules sP hex
s) (K, i)
lemma conditionalMeanVersion_measurable (s : N) (K : Finset (Fin N)) (i : Fin
N) :
Measurable[filtration other ho (gF := gF) K i s]
(conditionalMeanVersion other ho learner rules sP hex s K i) :=
(Classical.choose_spec (conditional_versions_exist other ho learner rules
sP hex s)).1 (K, i)
lemma conditionalMeanVersion_ae (s : N) (K : Finset (Fin N)) (i : Fin N) :
conditionalMeanVersion other ho learner rules sP hex s K i =ᵐ[sP]
(monitor other ho learner rules K i).µ sP s :=
(Classical.choose_spec (conditional_versions_exist other ho learner rules
sP hex s)).2.1 (K, i)
lemma conditionalMeanVersion_permute (e : Equiv.Perm (Fin N)) (s : N)
(K : Finset (Fin N)) (i : Fin N) (ω : Sample Ω O N) :
conditionalMeanVersion other ho learner rules sP hex s K i (permute e ω) =
conditionalMeanVersion other ho learner rules sP hex s (relabel e K) (e
i) ω :=
(Classical.choose_spec (conditional_versions_exist other ho learner rules
sP hex s)).2.2.1 e (K, i) ω
/-- The average conditional mean ‘µ_t‘, using the chosen versions. -/
noncomputable def mean (K : Finset (Fin N)) (i : Fin N) (t : N) (ω : Sample Ω
O N) : R :=
(∑ s ∈ range t, conditionalMeanVersion other ho learner rules sP hex s K i
ω) / t
lemma mean_measurable (K : Finset (Fin N)) (i : Fin N) (t : N) :
Measurable[filtration other ho (gF := gF) K i t]
(mean other ho learner rules sP hex K i t) :=
(Finset.measurable_sum (range t) fun s hs =>
(conditionalMeanVersion_measurable other ho learner rules sP hex s K
i).mono
((filtration other ho K i).mono (Nat.le_of_lt (mem_range.mp hs)))
le_rfl).div_const t
lemma mean_ae (K : Finset (Fin N)) (i : Fin N) (t : ℕ) :
mean other ho learner rules sP hex K i t =ᵐ[sP]
fun ω => (monitor other ho learner rules K i).A sP t ω / t := by
filter_upwards [ae_all_iff.mpr fun s =>
conditionalMeanVersion_ae other ho learner rules sP hex s K i] with ω hω
unfold mean BinaryMonitor.A
simp_rw [hω]
lemma mean_permute (e : Equiv.Perm (Fin N)) (K : Finset (Fin N))
(i : Fin N) (t : ℕ) (ω : Sample Ω O N) :
mean other ho learner rules sP hex K i t (permute e ω) =
mean other ho learner rules sP hex (relabel e K) (e i) t ω := by
unfold mean
simp_rw [conditionalMeanVersion_permute]
/-- The conditional-mean value ‘sˆy_{i,j}(D,r)‘: evaluate ‘i‘, delete ‘j‘. -/
noncomputable def s (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) (ω : Sample Ω O N) : ℝ :=
signedMeanValue d gW hne (fun t =>
mean other ho learner rules sP hex (K.erase j) i t ω) r
/-- The observed value uses the same deleted occurrence and fitted monitor. -/
noncomputable def observedValue (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) (ω : Sample Ω O N) : ℝ :=
signedMeanValue d gW hne
(fun t => (monitor other ho learner rules (K.erase j) i).S t ω / t) r
lemma s_ae (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) :
s other ho learner rules sP hex d gW hne K i j r =ᵐ[sP] fun ω =>
signedMeanValue d gW hne
(fun t => (monitor other ho learner rules (K.erase j) i).A sP t ω /
t) r := by
filter_upwards [ae_all_iff.mpr fun t =>
mean_ae other ho learner rules sP hex (K.erase j) i t] with ω hω
exact signedMeanValue_congr d gW hne (fun t _ => hω t)
lemma s_measurable (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i j : Fin N) (r : ℕ → ℝ) :
Measurable (s other ho learner rules sP hex d gW hne K i j r) :=
signedMeanValue_measurable d gW hne _ r (fun t _ =>
(mean_measurable other ho learner rules sP hex (K.erase j) i t).mono
((filtration other ho (K.erase j) i).le t) le_rfl)
lemma training_s_measurable (d : ℝ) (gW : Finset ℕ) (hne : gW.Nonempty)
(K : Finset (Fin N)) (i : Fin N) (hi : i ∈ K) (r : ℕ → ℝ) :
Measurable[information other K] (s other ho learner rules sP hex d gW hne
K i i r) := by
letI : MeasurableSpace (Sample Ω O N) := information other K
exact signedMeanValue_measurable d gW hne _ r (fun t _ =>
(mean_measurable other ho learner rules sP hex (K.erase i) i t).mono
(leave_one_out_filtration_le other ho K i hi t) le_rfl)
lemma s_permute (d : ℝ) (gW : Finset N) (hne : gW.Nonempty)
(e : Equiv.Perm (Fin N)) (K : Finset (Fin N)) (i j : Fin N)
(r : N → ℝ) (ω : Sample Ω O N) :
s other ho learner rules sP hex d gW hne K i j r (permute e ω) =
s other ho learner rules sP hex d gW hne (relabel e K) (e i) (e j) r ω
:= by
unfold s
apply signedMeanValue_congr
intro t _
rw [mean_permute, OccurrenceCalibration.relabel_erase]
end LeBet.LeaveOneOut
Coordinate transport preserves the training information, conditional probabilities, and PAC events.
import LeBet.LeaveOneOutCalibration
import Mathlib.GroupTheory.Perm.Sign
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.LeaveOneOut
open StratifiedSample.JointSample (fixLast fixLast_castSucc fixLast_last)
variable {Ω O : Type*} [MeasurableSpace Ω] [MeasurableSpace O] {N : N}
/-- Move the separate next trajectory to the last occurrence coordinate. -/
def appendNext : ((Fin N → Ω) × O × Ω) ≃ᵐ Sample Ω O (N + 1) where
toFun ω := (Fin.snoc ω.1 ω.2.2, ω.2.1)
invFun ω := ((fun i => ω.1 i.castSucc), ω.2, ω.1 (Fin.last N))
left_inv ω := by ext i <;> simp
right_inv ω := by
apply Prod.ext
· funext i
refine Fin.lastCases ?_ (fun i => ?_) i <;> simp
· rfl
measurable_toFun := by
refine (measurable_pi_iff.mpr ?_).prodMk measurable_snd.fst
intro i
refine Fin.lastCases ?_ (fun j => ?_) i
· simpa only [Fin.snoc_last] using
(measurable_snd.snd : Measurable fun ω : (Fin N → Ω) × O × Ω => ω.2.2)
· simpa only [Fin.snoc_castSucc, Function.comp_def] using
(measurable_pi_apply j).comp
(measurable_fst : Measurable fun ω : (Fin N → Ω) × O × Ω => ω.1)
measurable_invFun :=
(measurable_pi_iff.mpr fun i => (measurable_pi_apply i.castSucc).comp
measurable_fst).prodMk
```.
(measurable_snd.prodMk ((measurable_pi_apply (Fin.last N)).comp
measurable_fst))
lemma appendNext_permute (e : Equiv.Perm (Fin N)) (ω : (Fin N → Ω) × O × Ω) :
appendNext (StratifiedSample.permute e ω) = permute (fixLast e)
(appendNext ω) := by
apply Prod.ext
· funext i
refine Fin.lastCases ?_ (fun j => ?_) i <;> simp [appendNext, permute,
StratifiedSample.permute]
· rfl
lemma appendNext_swap (i : Fin N) (ω : (Fin N → Ω) × O × Ω) :
appendNext (StratifiedSample.swapNext i ω) =
permute (Equiv.swap i.castSucc (Fin.last N)) (appendNext ω) := by
apply Prod.ext
· funext j
refine Fin.lastCases ?_ (fun j => ?_) j
· simp [appendNext, permute, StratifiedSample.swapNext,
(Fin.castSucc_ne_last i).symm]
· by_cases h : j = i
· subst j
simp [appendNext, permute, StratifiedSample.swapNext]
· simp [appendNext, permute, StratifiedSample.swapNext, h,
Equiv.swap_apply_of_ne_of_ne (fun he => h (Fin.castSucc_inj.mp he))
(Fin.castSucc_ne_last j)]
· rfl
lemma fixLast_swap (i j : Fin N) :
fixLast (Equiv.swap i j) = Equiv.swap i.castSucc j.castSucc := by
apply Equiv.ext
intro k
refine Fin.lastCases ?_ (fun k => ?_) k
· simp [Equiv.swap_apply_of_ne_of_ne
(Fin.castSucc_ne_last i).symm (Fin.castSucc_ne_last j).symm]
· by_cases hki : k = i
· subst k
simp
· by_cases hkj : k = j
· subst k
simp
· simp [Equiv.swap_apply_of_ne_of_ne hki hkj,
Equiv.swap_apply_of_ne_of_ne (fun h => hki (Fin.castSucc_inj.mp h))
(fun h => hkj (Fin.castSucc_inj.mp h))]
lemma permute_mul (e f : Equiv.Perm (Fin N)) :
(permute (e * f) : Sample Ω O N → Sample Ω O N) = permute f ◦ permute e
:= rfl
lemma pool_orderEmb {n m k : N} (K : Finset (Fin (n + m))) (hK : K.card = k)
(i : Fin k) :
(pool K).orderEmbOfFin (by simpa [pool] using hK) i = (K.orderEmbOfFin hK
i).castSucc := by
have he := Finset.orderEmbOfFin_unique (s := pool K) (by simpa [pool] using
hK)
(f := fun i : Fin k => (K.orderEmbOfFin hK i).castSucc)
(fun i => (mem_pool K _).mpr (orderEmbOfFin_mem K hK i))
(Fin.castSuccOrderEmb.strictMono.comp (K.orderEmbOfFin hK).strictMono)
exact (congrFun he i).symm
lemma information_eq_subtuple {R : Type*} [MeasurableSpace R] (other : O → R)
{k : N} (K : Finset (Fin N)) (hK : K.card = k) :
information (Ω := Ω) other K =
MeasurableSpace.comap
(fun ω : Sample Ω O N => (StratifiedSample.subtuple K hK ω.1, other ω
.2)) inferInstance := by
subst k
exact information_eq other K
lemma appendNext_information {R : Type*} [MeasurableSpace R] (other : O → R)
{n m k : N} (K : Finset (Fin (n + m))) (hK : K.card = k) :
MeasurableSpace.comap (appendNext (Ω := Ω) (O := O))
(information other (pool K)) =
MeasurableSpace.comap
(fun ω : (Fin (n + m) → Ω) × O × Ω =>
(StratifiedSample.subtuple K hK ω.1, other ω.2.1)) inferInstance :=
by
rw [information_eq_subtuple other (pool K) (by simpa [pool] using hK),
MeasurableSpace.comap_comp]
congr 1
funext ω
apply Prod.ext
· funext i
change (Fin.snoc ω.1 ω.2.2 : Fin (n + m + 1) → Ω) ((pool
K).orderEmbOfFin _ i) = _
rw [pool_orderEmb, Fin.snoc_castSucc]
rfl
· rfl
/-- Pool permutations and next-occurrence swaps generate the required full
symmetry. -/
theorem full_exchangeability (sP : Measure (Sample Ω O (N + 1)))
(hp : ∀ e : Equiv.Perm (Fin N), MeasurePreserving (permute (fixLast e))
sP sP)
(hs : ∀ i : Fin N, MeasurePreserving (permute (Equiv.swap i.castSucc
(Fin.last N))) sP sP)
(e : Equiv.Perm (Fin (N + 1))) :
MeasurePreserving (permute e) sP sP := by
have hswap (i j : Fin (N + 1)) :
MeasurePreserving (permute (Equiv.swap i j)) sP sP := by
refine Fin.lastCases ?_ (fun i => ?_) i
· refine Fin.lastCases ?_ (fun j => ?_) j
· refine ⟨(permute _).measurable, ?_⟩
simpa [permute] using Measure.map_id sP
· rw [Equiv.swap_comm]
exact hs j
· refine Fin.lastCases (hs i) (fun j => ?_) j
rw [← fixLast_swap]
exact hp _
induction e using Equiv.Perm.swap_induction_on with
| one =>
exact ⟨(permute 1).measurable, by simpa [permute] using Measure.map_id
| swap_mul e i j _ ih =>
rw [permute_mul]
exact ih.comp (hswap i j)
/-- Transport an occurrence action through a measurable coordinate map. -/
lemma map_symmetry {A B : Type*} [MeasurableSpace A] [MeasurableSpace B]
(P : Measure A) {f : A → B} (hf : Measurable f) {e : A → A} {g : B → B}
(hg : Measurable g) (he : MeasurePreserving e P P)
(h : f ∘ e =ᵐ[P] g ∘ f) :
MeasurePreserving g (P.map f) (P.map f) := by
refine ⟨hg, ?_⟩
calc
(P.map f).map g = P.map (g ∘ f) := Measure.map_map hg hf
_ = P.map (f ∘ e) := Measure.map_congr h.symm
_ = (P.map e).map f := (Measure.map_map hf he.measurable).symm
_ = P.map f := by rw [he.map_eq]
/-- Conditional error probabilities are unchanged by the sample-coordinate
map. -/
lemma conditional_probability_coordinates {A B : Type*} {m : MeasurableSpace
B} [mA : MeasurableSpace A]
[mB : MeasurableSpace B] (P : Measure A) [IsProbabilityMeasure P]
{f : A → B} (hf : Measurable f) (hm : m ≤ mB)
{E : Set B} (hE : MeasurableSet E) :
(fun ω => ConditionalCoverage.conditionalProbability (P.map f) m E (f ω))
=ᵐ[P]
ConditionalCoverage.conditionalProbability P (MeasurableSpace.comap f
m) (f ⁻¹' E) := by
exact condExp_map P hf hm ((integrable_const (1 : ℝ)).indicator hE)
/-- The PAC bound also transports when its threshold is learned from
training. -/
lemma conditional_probability_tail_coordinates {A B : Type*} {m :
MeasurableSpace B} [mA : MeasurableSpace A]
[mB : MeasurableSpace B] (P : Measure A) [IsProbabilityMeasure P]
{f : A → B} (hf : Measurable f) (hm : m ≤ mB)
{E : Set B} (hE : MeasurableSet E) {q : B → ℝ} (hq : Measurable q) :
P.real {ω | q (f ω) <
ConditionalCoverage.conditionalProbability P (MeasurableSpace.comap f
m) (f ⁻¹' E) ω} =
(P.map f).real {ω | q ω < ConditionalCoverage.conditionalProbability
(P.map f) m E ω} := by
calc
_ = P.real (f ⁻¹' {ω | q ω <
ConditionalCoverage.conditionalProbability (P.map f) m E ω}) := by
apply measureReal_congr
filter_upwards [conditional_probability_coordinates P hf hm hE] with ω
simp only [Set.mem_ofPred_eq, Set.mem_preimage, hω]
_ = _ := (map_measureReal_apply hf
(measurableSet_lt hq (stronglyMeasurable_condExp.mono
hm).measurable)).symm
lemma conditional_probability_exists_coordinates {A B I : Type*} {m :
MeasurableSpace B} [mA : MeasurableSpace A]
[mB : MeasurableSpace B] [Countable I] (P : Measure A)
[IsProbabilityMeasure P]
{f : A → B} (hf : Measurable f) (hm : m ≤ mB)
{E : I → Set B} (hE : ∀ i, MeasurableSet (E i)) {q : I → B → ℝ}
(hq : ∀ i, Measurable (q i)) :
P.real {ω | ∃ i, q i (f ω) <
ConditionalCoverage.conditionalProbability P (MeasurableSpace.comap f
m) (f ⁻¹' E i) ω} =
(P.map f).real {ω | ∃ i, q i ω <
ConditionalCoverage.conditionalProbability (P.map f) m (E i) ω} := by
have hall := ae_all_iff.mpr fun i => conditional_probability_coordinates P
hf hm (hE i)
have hmeas : MeasurableSet {ω | ∃ i, q i ω <
ConditionalCoverage.conditionalProbability (P.map f) m (E i) ω} := by
simp only [Set.ofPred_exists]
exact MeasurableSet.iUnion fun i =>
measurableSet_lt (hq i) (stronglyMeasurable_condExp.mono hm).measurable
calc
_ = P.real (f ⁻¹' {ω | ∃ i, q i ω <
ConditionalCoverage.conditionalProbability (P.map f) m (E i) ω}) := by
apply measureReal_congr
filter_upwards [hall] with ω hω
simp only [Set.mem_ofPred_eq, Set.mem_preimage]
apply propext
exact exists_congr fun i => by rw [hω i]
_ = _ := (map_measureReal_apply hf hmeas).symm
/-- Relabel the other class while retaining every occurrence of the evaluated
class. -/
def permuteOther {M : N} (e : Equiv.Perm (Fin M)) :
Sample Ω (Fin M → Ω) N ≃ₘ Sample Ω (Fin M → Ω) N where
toFun ω := (ω.1, ω.2 ∘ e)
invFun ω := (ω.1, ω.2 ∘ e.symm)
left_inv ω := by ext i <;> simp
right_inv ω := by ext i <;> simp
measurable_toFun := measurable_fst.prodMk
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e i)).comp
measurable_snd)
measurable_invFun := measurable_fst.prodMk
(measurable_pi_iff.mpr fun i => (measurable_pi_apply (e.symm i)).comp
measurable_snd)
section Joint
open StratifiedSample
variable {Y : Ω → Fin 2} {n0 m0 n1 m1 : N}
(P : Measure (mΩ Y n0 m0 n1 m1)) (hY : Measurable Y)
(hex : FiniteExchangeableExtension P)
def class0Coordinates (ω : mΩ Y n0 m0 n1 m1) :
Sample Ω (Fin (n1 + m1) → Ω) (n0 + m0 + 1) :=
appendNext (JointSample.class0 ω)
def class1Coordinates (ω : mΩ Y n0 m0 n1 m1) :
Sample Ω (Fin (n0 + m0) → Ω) (n1 + m1 + 1) :=
appendNext (JointSample.class1 ω)
lemma class0Coordinates_measurable :
Measurable (class0Coordinates (Y := Y) (n0 := n0) (m0 := m0) (n1 := n1) (m1 := m1)) :=
appendNext.measurable.comp JointSample.class0_measurable
lemma class1Coordinates_measurable :
Measurable (class1Coordinates (Y := Y) (n0 := n0) (m0 := m0) (n1 := n1) (m1 := m1)) :=
appendNext.measurable.comp JointSample.class1_measurable
lemma class0_training_information :
MeasurableSpace.comap (class0Coordinates (Y := Y))
(information (JointSample.observed (n := n1) (m := m1)) (pool (gI_in_y n0 m0))) =
MeasurableSpace.comap (mD_in (Y := Y) (n_0 := n0) (m_0 := m0)
(n_1 := n1) (m_1 := m1)) inferInstance := by
change MeasurableSpace.comap (appendNext ∘ JointSample.class0) _ = _
rw [← MeasurableSpace.comap_comp, appendNext_information _ _
trainingIndices_card,
MeasurableSpace.comap_comp]
exact JointSample.class0_information
lemma class1_training_information :
MeasurableSpace.comap (class1Coordinates (Y := Y))
(information (JointSample.observed (n := n0) (m := m0)) (pool (gI_in_y n1 m1))) =
MeasurableSpace.comap (mD_in (Y := Y) (n_0 := n0) (m_0 := m0)
(n_1 := n1) (m_1 := m1)) inferInstance := by
change MeasurableSpace.comap (appendNext ∘ JointSample.class1) _ = _
rw [← MeasurableSpace.comap_comp, appendNext_information _ _
trainingIndices_card,
MeasurableSpace.comap_comp]
exact JointSample.class1_information
include hY hex in
/-- Assumption 1 supplies the classwise symmetry used by the LOO
construction. -/
theorem class0_exchangeability (e : Equiv.Perm (Fin (n0 + m0 + 1))) :
MeasurePreserving (permute e)
((cond P (JointSample.classEvent 0)).map class0Coordinates)
((cond P (JointSample.classEvent 0)).map class0Coordinates) := by
apply full_exchangeability
· intro a
apply map_symmetry _ class0Coordinates_measurable (permute _).measurable
(JointSample.permutes0_of_exchangeable hY hex a)
apply ae_of_all
intro ω
change appendNext (JointSample.class0 (JointSample.permute0 a ω)) = _
rw [JointSample.class0_permute]
exact appendNext_permute a _
· intro i
apply map_symmetry _ class0Coordinates_measurable (permute _).measurable
(JointSample.swaps0_of_exchangeable hY hex i)
apply ae_cond_of_forall_mem (JointSample.classEvent_measurable hY 0)
intro ω hω
change appendNext (JointSample.class0 (JointSample.swapNext0 i ω)) = _
rw [JointSample.class0_swapNext i ω hω]
exact appendNext_swap i _
include hY hex in
theorem class1_exchangeability (e : Equiv.Perm (Fin (n1 + m1 + 1))) :
MeasurePreserving (permute e)
((cond P (JointSample.classEvent 1)).map class1Coordinates)
((cond P (JointSample.classEvent 1)).map class1Coordinates) := by
apply full_exchangeability
· intro a
apply map_symmetry _ class1Coordinates_measurable (permute _).measurable
(JointSample.permutes1_of_exchangeable hY hex a)
apply ae_of_all
intro ω
change appendNext (JointSample.class1 (JointSample.permute1 a ω)) = _
rw [JointSample.class1_permute]
exact appendNext_permute a _
· intro i
apply map_symmetry _ class1Coordinates_measurable (permute _).measurable
(JointSample.swaps1_of_exchangeable hY hex i)
apply ae_cond_of_forall_mem (JointSample.classEvent_measurable hY 1)
intro ω hω
change appendNext (JointSample.class1 (JointSample.swapNext1 i ω)) = _
rw [JointSample.class1_swapNext i ω hω]
exact appendNext_swap i _
include hex in
/-- The second factor in the product average also preserves the class-0 law.
-/
theorem class0_other_exchangeability (e : Equiv.Perm (Fin (n1 + m1))) :
MeasurePreserving (permuteOther e)
((cond P (JointSample.classEvent 0)).map class0Coordinates)
((cond P (JointSample.classEvent 0)).map class0Coordinates) := by
apply map_symmetry _ class0Coordinates_measurable (permuteOther e).measurable
(show MeasurePreserving (JointSample.permute1 e) (cond P
(JointSample.classEvent 0)) (cond P (JointSample.classEvent 0)) from ⟨
JointSample.permute1_measurable e, hex.2.1 e⟩)
apply ae_of_all
intro ω
ext i <;> simp [Function.comp_def, class0Coordinates, class1Coordinates,
JointSample.class0, JointSample.class1, JointSample.permute0,
JointSample.permute1,
appendNext, permuteOther]
include hex in
theorem class1_other_exchangeability (e : Equiv.Perm (Fin (n0 + m0))) :
MeasurePreserving (permuteOther e)
((cond P (JointSample.classEvent 1)).map class1Coordinates)
((cond P (JointSample.classEvent 1)).map class1Coordinates) := by
apply map_symmetry _ class1Coordinates_measurable (permuteOther
e).measurable
(show MeasurePreserving (JointSample.permute0 e) (cond P
(JointSample.classEvent 1))
(cond P (JointSample.classEvent 1)) from
⟨JointSample.permute0_measurable e, hex.2.2.2 e⟩)
apply ae_of_all
intro ω
ext i <;> simp [Function.comp_def, class0Coordinates, class1Coordinates,
JointSample.class0, JointSample.class1, JointSample.permute0,
JointSample.permute1,
appendNext, permuteOther]
end Joint
end LeBet.LeaveOneOut
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.OccurrenceCalibration
open FiniteSampling EmpiricalOptimization
variable {Ω : Type*} {N n : N}
lemma relabel_erase (e : Equiv.Perm (Fin N)) (K : Finset (Fin N)) (i : Fin N)
:
relabel e (K.erase i) = (relabel e K).erase (e i) := by
ext j
simp only [mem_relabel, mem_erase]
simp only [ne_eq, Equiv.symm_apply_eq]
noncomputable def level (u : Ω → Finset (Fin N) → Fin N → R)
(r : N) (hr : r < n) (ω : Ω) (K : Finset (Fin N)) : R :=
if hK : K.card = n then
upperQuantile (fun i => u ω K (K.orderEmbOfFin hK i)) r hr else 0
lemma level_permute (u : Ω → Finset (Fin N) → Fin N → R)
(r : N) (hr : r < n) (e : Equiv.Perm (Fin N)) (act : Ω → Ω)
(hu : ∀ ω K i, u (act ω) K i = u ω (relabel e K) (e i))
(ω : Ω) (K : Finset (Fin N)) :
level u r hr (act ω) K = level u r hr ω (relabel e K) := by
by_cases hK : K.card = n
· have hL := (relabel_card e K).trans hK
simp only [level, dite_eq_left hK, dite_eq_left hL, hu]
obtain ⟨a, ha⟩ := StratifiedSample.subtuple_permute e K hK (u ω (relabel e
K))
change upperQuantile
(StratifiedSample.subtuple K hK (u ω (relabel e K) ∘ e)) r hr = _
rw [ha, upperQuantile_perm]
rfl
· have hL : (relabel e K).card ≠ n := by simpa only [relabel_card] using hK
simp only [level, dite_eq_right hK, dite_eq_right hL]
lemma training_budget (u : Ω → Finset (Fin N) → Fin N → ℝ)
(r : N) (hr : r < n) (ω : Ω) (K : Finset (Fin N)) (hK : K.card = n) :
(K.filter fun i => level u r hr ω K < u ω K i).card ≤ r := by
let p (i : Fin N) := level u r hr ω K < u ω K i
have hc : (K.filter p).card =
(univ.filter fun j : Fin n => p (K.orderEmbOfFin hK j)).card := by
calc
_ = ((univ.map (K.orderEmbOfFin hK).toEmbedding).filter p).card := by
rw [map_orderEmbOfFin_univ]
_ = _ := by rw [filter_map, card_map]; rfl
change (K.filter p).card ≤ r
rw [hc]
simpa only [p, level, dite_eq_left hK] using
(upperQuantile_le_iff (fun j => u ω K (K.orderEmbOfFin hK j)) r hr _).mp
le_rfl
lemma level_mono (u v : Ω → Finset (Fin N) → Fin N → ℝ)
(r : N) (hr : r < n) (ω : Ω) (K : Finset (Fin N))
(huv : ∀ i ∈ K, u ω K i ≤ v ω K i) :
level u r hr ω K ≤ level v r hr ω K := by
by_cases hK : K.card = n
· simp only [level, dite_eq_left hK]
exact upperQuantile_mono _ _
(fun i => huv _ (orderEmbOfFin_mem K hK i)) r hr
· simp only [level, dite_eq_right hK, le_refl]
lemma level_measurable [MeasurableSpace Ω]
(u : Ω → Finset (Fin N) → Fin N → ℝ)
(r : N) (hr : r < n) (K : Finset (Fin N))
(hu : ∀ i ∈ K, Measurable fun ω => u ω K i) :
Measurable fun ω => level u r hr ω K := by
by_cases hK : K.card = n
· simp only [level, dite_eq_left hK]
exact measurable_upperQuantile _ (fun i => hu _ (orderEmbOfFin_mem K hK i)) r hr
· simp only [level, dite_eq_right hK]
exact measurable_const
lemma measurable_function_fixed {m : MeasurableSpace Ω} {f : Ω → ℝ}
(hf : Measurable[m] f) (e : Ω → Ω)
(hfix : ∀ A, MeasurableSet[m] A → e ⁻¹' A = A) (ω : Ω) :
f (e ω) = f ω := by
have h := hfix (f ⁻¹' {f ω}) (hf (measurableSet_singleton (f ω)))
have hmem : ω ∈ e ⁻¹' (f ⁻¹' {f ω}) := by rw [h]; rfl
exact hmem
end LeBet.OccurrenceCalibration
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.OccurrenceCalibration
open FiniteSampling EmpiricalOptimization
variable {Ω : Type*} {N n : ℕ}
section Probability
variable {mΩ : MeasurableSpace Ω} {sP : Measure Ω} [IsProbabilityMeasure sP]
{m : ℕ}
lemma extensionRate_measurable
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ)
(q : Ω → Finset (Fin (n + m)) → ℝ) (K : Finset (Fin (n + m))) (B : ℝ)
(hu : ∀ i, Measurable fun ω => u ω K i) (hq : Measurable fun ω => q ω K) :
Measurable fun ω => extensionErrorRate m (u ω) (q ω) B K := by
have h : Measurable fun ω => ∑ i ∈ Kᶜ,
if q ω K + 2 * B < u ω K i then (1 : ℝ) else 0 :=
Finset.measurable_sum _ fun i _ =>
Measurable.ite (measurableSet_lt (hq.add_const _) (hu i))
measurable_const measurable_const
simpa only [sum_bool, extensionErrorRate] using h.div_const m
lemma extensionRate_bounds
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ)
(q : Ω → Finset (Fin (n + m)) → ℝ) (K : Finset (Fin (n + m)))
(hK : K.card = n) (hm : 0 < m) (B : ℝ) (ω : Ω) :
0 ≤ extensionErrorRate m (u ω) (q ω) B K ∧
extensionErrorRate m (u ω) (q ω) B K ≤ 1 := by
have hm’ : (0 : ℝ) < m := by exact_mod_cast hm
have hc : Kᶜ.card = m := by rw [card_compl, hK]; simp
refine ⟨by unfold extensionErrorRate; positivity, ?_⟩
apply (div_le_one hm’).mpr
exact_mod_cast (card_le_card (filter_subset _ _)).trans_eq hc
lemma conditional_probability_mono_on_ae {gFin : MeasurableSpace Ω} (hFin :
gFin ≤ mΩ)
{A B F : Set Ω} (hA : MeasurableSet[mΩ] A) (hB : MeasurableSet[mΩ] B)
(hF : MeasurableSet[gFin] F)
(hAB : ∀ᵐ ω ∂sP, ω ∈ F → ω ∈ A → ω ∈ B) :
∀ᵐ ω ∂sP, ω ∈ F →
ConditionalCoverage.conditionalProbability sP gFin A ω ≤
ConditionalCoverage.conditionalProbability sP gFin B ω := by
have hmono := condExp_mono (m := gFin)
((integrable_const (1 : ℝ)).indicator ((hFin _ hF).inter hA))
((integrable_const (1 : ℝ)).indicator ((hFin _ hF).inter hB)) (by
filter_upwards [hAB] with ω hω
by_cases hf : ω ∈ F
· by_cases ha : ω ∈ A
· simp [hf, ha, hω hf ha]
· simp [hf, ha, Set.indicator_nonneg]
· simp [hf])
have hleft := condExp_indicator
((integrable_const (1 : ℝ) : Integrable (fun _ : Ω => (1 : ℝ))
sP).indicator hA) hF
have hright := condExp_indicator
((integrable_const (1 : R) : Integrable (fun _ : Ω => (1 : R))
sP).indicator hB) hF
simp only [Set.indicator_indicator] at hleft hright
filter_upwards [hmono, hleft, hright] with ω hω hl hr hωF
simpa only [ConditionalCoverage.conditionalProbability, hl, hr,
Set.indicator_of_mem hωF] using hω
end Probability
end LeBet.OccurrenceCalibration
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : ℕ}
def pool (K : Finset (Fin (n + m))) : Finset (Fin (n + m + 1)) :=
K.map Fin.castSuccEmb
lemma mem_pool (K : Finset (Fin (n + m))) (i : Fin (n + m)) :
i.castSucc ∈ pool K ↔ i ∈ K := by simp [pool]
lemma last_not_mem_pool (K : Finset (Fin (n + m))) :
Fin.last (n + m) ∉ pool K := by
simp only [pool, Finset.mem_map]
rintro ⟨i, _, hi⟩
exact Fin.castSucc_ne_last i hi
lemma pool_relabel (e : Equiv.Perm (Fin (n + m))) (K : Finset (Fin (n + m))) :
pool (relabel e K) = relabel (fixLast e) (pool K) := by
unfold pool relabel
rw [Finset.map_map, Finset.map_map]
congr 1
apply Function.Embedding.ext
intro i
exact (fixLast_castSucc e i).symm
lemma swap_fixes_pool (K : Finset (Fin (n + m))) (i : Fin (n + m)) (hi : i ∉
K) :
relabel (Equiv.swap i.castSucc (Fin.last (n + m))) (pool K) = pool K := by
have hfix (j : Fin (n + m + 1)) (hj : j ∈ pool K) :
Equiv.swap i.castSucc (Fin.last (n + m)) j = j := by
have hji : j ≠ i.castSucc := fun h => hi ((mem_pool K i).mp (h ▸ hj))
have hjl : j ≠ Fin.last (n + m) := fun h => last_not_mem_pool K (h ▸ hj)
exact Equiv.swap_apply_of_ne_of_ne hji hjl
unfold relabel
ext j
constructor
· intro hj
obtain ⟨k, hk, he⟩ := Finset.mem_map.mp hj
change Equiv.swap i.castSucc (Fin.last (n + m)) k = j at he
rw [hfix k hk] at he
exact he ▸ hk
· intro hj
exact Finset.mem_map.mpr ⟨j, hj, hfix j hj⟩
end LeBet.LeaveOneOut
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : ℕ}
variable (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration ℕ (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : R) (gW : Finset ℕ) (hne : gW.Nonempty)
noncomputable def values (ω : Sample Ω O (n + m + 1))
(K : Finset (Fin (n + m))) (i : Fin (n + m)) : R :=
s other ho learner rules sP hex d gW hne (pool K) i.castSucc i.castSucc 0 ω
noncomputable def nextValue (K₀ : Finset (Fin (n + m))) (ω : Sample Ω O (n + m + 1)) : R :=
s other ho learner rules sP hex d gW hne (pool K₀)
(Fin.last (n + m)) (Fin.last (n + m)) 0 ω
lemma values_measurable (K : Finset (Fin (n + m))) (i : Fin (n + m)) :
Measurable fun ω => values other ho learner rules sP hex d gW hne ω K i :=
s_measurable other ho learner rules sP hex d gW hne _ _ _ _
lemma nextValue_measurable (K₀ : Finset (Fin (n + m))) :
Measurable (nextValue other ho learner rules sP hex d gW hne K₀) :=
s_measurable other ho learner rules sP hex d gW hne _ _ _ _
lemma values_training_measurable (K : Finset (Fin (n + m))) (i : Fin (n + m))
(hi : i ∈ K) :
Measurable[information other (pool K)]
(fun ω => values other ho learner rules sP hex d gW hne ω K i) :=
training_s_measurable other ho learner rules sP hex d gW hne _ _ ((mem_pool
K i).mpr hi) _
lemma values_permute (e : Equiv.Perm (Fin (n + m))) (ω : Sample Ω O (n + m +
1))
(K : Finset (Fin (n + m))) (i : Fin (n + m)) :
values other ho learner rules sP hex d gW hne (permute (fixLast e) ω) K i
=
values other ho learner rules sP hex d gW hne ω (relabel e K) (e i) := by
unfold values
rw [s_permute, fixLast_castSucc, ← pool_relabel]
lemma nextValue_swap (K0 : Finset (Fin (n + m))) (i : Fin (n + m)) (hi : i ∉
K0)
(ω : Sample Ω O (n + m + 1)) :
nextValue other ho learner rules sP hex d gW hne K0
(permute (Equiv.swap i.castSucc (Fin.last (n + m))) ω) =
values other ho learner rules sP hex d gW hne ω K0 i := by
unfold nextValue values
rw [s_permute, swap_fixes_pool K0 i hi, Equiv.swap_apply_right]
lemma training_swap (K0 : Finset (Fin (n + m))) (i : Fin (n + m)) (hi : i ∉ K0)
(ω : Sample Ω O (n + m + 1)) :
training other (pool K0) (permute (Equiv.swap i.castSucc (Fin.last (n +
m))) ω) =
training other (pool K0) ω := by
apply Prod.ext
· funext j
change ω.1 (Equiv.swap i.castSucc (Fin.last (n + m)) ((pool
K0).orderEmbOfFin rfl j)) = _
have hj := orderEmbOfFin_mem (pool K0) rfl j
have hji : (pool K0).orderEmbOfFin rfl j ≠ i.castSucc := by
intro h
rw [h] at hj
exact hi ((mem_pool K0 i).mp hj)
have hjl : (pool K0).orderEmbOfFin rfl j ≠ Fin.last (n + m) := by
intro h
rw [h] at hj
exact last_not_mem_pool K0 hj
rw [Equiv.swap_apply_of_ne_of_ne hji hjl]
· rfl
lemma information_fixed (K0 : Finset (Fin (n + m))) (i : Fin (n + m)) (hi : i
∉ K0)
(A : Set (Sample Ω O (n + m + 1))) (hA : MeasurableSet[information other
(pool K0)] A) :
(permute (Equiv.swap i.castSucc (Fin.last (n + m)))) ⁻¹' A = A := by
rw [information_eq] at hA
obtain ⟨B, _, rfl⟩ := hA
ext ω
simp only [Set.mem_preimage, training_swap other K0 i hi]
end LeBet.LeaveOneOut
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
set_option maxHeartbeats 800000
namespace LeBet.LeaveOneOut
open FiniteSampling
open StratifiedSample.JointSample (fixLast fixLast_castSucc)
variable {Ω O R C : Type*} [MeasurableSpace Ω] [MeasurableSpace O]
[MeasurableSpace R] [MeasurableSpace C] [Fintype C]
[MeasurableSingletonClass C]
{n m : N}
variable (other : O → R) (ho : Measurable other) (learner : Learner Ω R C)
{gF : Filtration N (inferInstance : MeasurableSpace Ω)}
(rules : C → BinaryMonitor gF)
(sP : Measure (Sample Ω O (n + m + 1))) [IsProbabilityMeasure sP]
(hex : ∀ e, MeasurePreserving (permute e) sP sP)
(d : R) (gW : Finset N) (hne : gW.Nonempty)
section Probability
variable (K₀ : Finset (Fin (n + m))) (hK₀ : K₀.card = n) (hm : 0 < m)
(r : N) (hr : r < n)
local notation "u" => values other ho learner rules sP hex d gW hne
local notation "v" => nextValue other ho learner rules sP hex d gW hne K₀
local notation "gFin" => information (Ω := Ω) other (pool K₀)
variable {A : Type*} [Fintype A] [Nonempty A]
(otherAct : A → Sample Ω O (n + m + 1) ≃ₘ Sample Ω O (n + m + 1))
(hother : ∀ a, MeasurePreserving (otherAct a) sP sP)
{B κ : R} {b : N} (hκ : 0 ≤ κ)
(hfail : OccurrenceCalibration.averageFailure (sP := sP)
(values other ho learner rules sP hex d gW hne) K₀ otherAct B b ≤ κ)
noncomputable def trainingMonitor (i : Fin n) :
BinaryMonitor (filtration other ho (gF := gF)
((pool K₀).erase (K₀.orderEmbOfFin hK₀ i).castSucc) (K₀.orderEmbOfFin
hK₀ i).castSucc) :=
monitor other ho learner rules _ _
noncomputable def deployedMonitor :=
monitor other ho learner rules (pool K₀) (Fin.last (n + m))
lemma trainingMonitor_information (i : Fin n) (t : N) :
filtration other ho (gF := gF) ((pool K₀).erase (K₀.orderEmbOfFin hK₀
i).castSucc)
(K₀.orderEmbOfFin hK₀ i).castSucc t ≤ gFin :=
leave_one_out_filtration_le other ho _ _
((mem_pool K₀ _).mpr (orderEmbOfFin_mem K₀ hK₀ i)) t
lemma training_values_ae (i : Fin n) :
(fun ω => u ω K₀ (K₀.orderEmbOfFin hK₀ i)) =ᵐ[sP] fun ω =>
signedMeanValue d gW hne
(fun t => (trainingMonitor other ho learner rules K₀ hK₀ i).A sP t ω /
t) 0 :=
s_ae other ho learner rules sP hex d gW hne _ _ _ _
lemma next_value_ae :
v =ᵐ[sP] fun ω => signedMeanValue d gW hne
(fun t => (deployedMonitor other ho learner rules K₀).A sP t ω / t) 0
:= by
have h := s_ae other ho learner rules sP hex d gW hne (pool K₀)
(Fin.last (n + m)) (Fin.last (n + m)) 0
rw [erase_eq_of_notMem (last_not_mem_pool (n := n) (m := m) K₀)] at h
exact h
noncomputable def calibratedLevel (β cap B : R) (T₀ : N) :
Sample Ω O (n + m + 1) → R :=
PredictableLearning.meanLevel (trainingMonitor other ho learner rules K₀ hK₀)
gW hne (T₀ := T₀) β d cap r hr B
lemma calibratedLevel_measurable (β cap B : R) (T₀ : N) :
Measurable[gFin] (calibratedLevel other ho learner rules d gW hne K₀ hK₀ r
hr β cap B T₀) :=
PredictableLearning.meanLevel_measurable r hr
(trainingMonitor other ho learner rules K₀ hK₀) gW hne
(fun i t _ => trainingMonitor_information other ho K₀ hK₀ i t) β d cap
end Probability
end LeBet.LeaveOneOut
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical BigOperators
namespace LeBet.FiniteSampling
end LeBet.FiniteSampling
namespace LeBet.OccurrenceCalibration
open FiniteSampling
variable {Ω A : Type*} {mΩ : MeasurableSpace Ω} [Fintype A] [Nonempty A]
{sP : Measure Ω} [IsProbabilityMeasure sP] {n m : N}
def pairStability (u : Ω → Finset (Fin (n + m)) → Fin (n + m) → R)
(K₀ : Finset (Fin (n + m))) (otherAct : A → Ω ≃ᵐ Ω) (B : R) (b : N)
(a : A) (K : Finset (Fin (n + m))) : Set Ω :=
{ω | (univ.filter fun i => B < |u (otherAct a ω) K i - u ω K₀ i|).card ≤ b}
noncomputable def averageFailure
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → R)
(K₀ : Finset (Fin (n + m))) (otherAct : A → Ω ≃ᵐ Ω) (B : R) (b : N) : R
:=
∑ a, ∑ K ∈ (univ : Finset (Fin (n + m))).powersetCard n,
sP.real (pairStability u K₀ otherAct B b a K)
lemma pairStability_measurable
(u : Ω → Finset (Fin (n + m)) → Fin (n + m) → ℝ)
(hu : ∀ K i, Measurable fun ω => u ω K i)
(K₀ : Finset (Fin (n + m))) (otherAct : A → Ω ≃ᵐ Ω)
(ho : ∀ a, Measurable (otherAct a)) (B : ℝ) (b : ℕ) (a : A) (K : Finset
(Fin (n + m))) :
MeasurableSet (pairStability u K₀ otherAct B b a K) := by
have h : Measurable fun ω => ∑ i : Fin (n + m),
if B < |u (otherAct a ω) K i - u ω K₀ i| then (1 : ℕ) else 0 :=
Finset.measurable_sum _ fun i _ =>
Measurable.ite (measurableSet_lt measurable_const
(((hu K i).comp (ho a)).sub (hu K₀ i)).abs) measurable_const
measurable_const
simpa only [pairStability, sum_boole, Nat.cast_id] using
measurableSet_le h (measurable_const : Measurable fun _ : Ω => b)
lemma integral_expect {ι : Type*} (S : Finset ι) (f : ι → Ω → ℝ)
(hf : ∀ i ∈ S, Integrable (f i) sP) :
(∫ ω, ∑ i ∈ S, f i ω ∂sP) = ∑ i ∈ S, ∫ ω, f i ω ∂sP := by
simp only [expect_eq_sum_div_card]
rw [integral_div, integral_finsetSum _ hf]
lemma integrable_expect {ι : Type*} (S : Finset ι) (f : ι → Ω → ℝ)
(hf : ∀ i ∈ S, Integrable (f i) sP) :
Integrable (fun ω => ∑ i ∈ S, f i ω) sP := by
simp only [expect_eq_sum_div_card]
exact (integrable_finsetSum S hf).div_const _
end LeBet.OccurrenceCalibration
Uniformly averaging law-preserving exchanges preserves the sample law.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical BigOperators
namespace LeBet.TruncatedCoverage
variable {Ω I : Type*} {mΩ : MeasurableSpace Ω}
[Fintype I] [Nonempty I] [MeasurableSpace I] [DiscreteMeasurableSpace I]
{P : Measure Ω} [IsProbabilityMeasure P]
noncomputable def exchangeLaw (P : Measure Ω) : Measure (I × Ω) :=
(PMF.uniformOfFintype I).toMeasure.prod P
instance exchangeLaw_isProbabilityMeasure : IsProbabilityMeasure (exchangeLaw
(I := I) P) := by
unfold exchangeLaw
infer_instance
lemma exchangeLaw_real (E : Set (I × Ω)) (hE : MeasurableSet E) :
(exchangeLaw P).real E = ∑ i, P.real (Prod.mk i ⁻¹' E) := by
have hi : Integrable (E.indicator (1 : I × Ω → ℝ)) (exchangeLaw P) :=
(integrable_const 1).indicator hE
rw [← integral_indicator_one hE, exchangeLaw, integral_prod _ hi,
PMF.integral_eq_sum]
have he i : (∫ ω, E.indicator (1 : I × Ω → ℝ) (i, ω) ∂P) = P.real
(Prod.mk i ⁻¹' E) :=
integral_indicator_one ((measurable_const.prodMk measurable_id) hE)
simp only [he, PMF.uniformOfFintype_apply, ENNReal.toReal_inv,
ENNReal.toReal_natCast,
smul_eq_mul, ← Finset.mul_sum, Fintype.expect_eq_sum_div_card,
div_eq_mul_inv, mul_comm]
lemma exchangeLaw_map (act : I → Ω ≃ᵐ Ω)
(hact : ∀ i, MeasurePreserving (act i) P P) :
(exchangeLaw P).map (fun p : I × Ω => act p.1 p.2) = P := by
have hm : Measurable (fun p : I × Ω => act p.1 p.2) :=
measurable_from_prod_countable_right fun i => (act i).measurable
apply Measure.ext
intro E hE
apply ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _
_) |>.mp
rw [← measureReal_def, map_measureReal_apply hm hE, exchangeLaw_real _ (hm
hE)]
have he i : P.real (Prod.mk i ⁻¹' ((fun p : I × Ω => act p.1 p.2) ⁻¹' E)) =
P.real E := by
change (P ((act i) ⁻¹' E)).toReal = _
rw [(hact i).measure_preimage hE.nullMeasurableSet]
rfl
simp only [he, expect_const univ_nonempty]
rfl
end LeBet.TruncatedCoverage
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical BigOperators
namespace LeBet.TruncatedCoverage
variable {Ω I : Type*} {mΩ : MeasurableSpace Ω}
[Fintype I] [Nonempty I] [MeasurableSpace I] [DiscreteMeasurableSpace I]
{P : Measure Ω} [IsProbabilityMeasure P]
end LeBet.TruncatedCoverage
namespace LeBet.FiniteSampling
lemma expect_subtype {ι : Type*} (S : Finset ι) (f : ι → ℝ) :
(𝔼 i : S, f i) = 𝔼 i ∈ S, f i := by
simp only [Fintype.expect_eq_sum_div_card, expect_eq_sum_div_card,
card_univ, Fintype.card_coe]
congr 1
rw [Finset.univ_eq_attach]
exact Finset.sum_attach S f
lemma expect_product_subtype {A ι : Type*} [Fintype A] (S : Finset ι) (f : A →
ι → ℝ) :
(E p : A × S, f p.1 p.2) = E a, E K ∈ S, f a K := by
rw [← Finset.univ_product_univ, expect_product]
simp only [expect_subtype]
end LeBet.FiniteSampling
The default parameters are measurable, and the stake is positive.
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
lemma calibratedStake_pos {p α : ℝ} (hp : 0 ≤ p) (hp1 : p < 1)
(ha : 0 < α) (ha1 : α < 1) {T : ℕ} (hT : 0 < T) :
0 < calibratedStake p α T := by
apply div_pos
· apply Real.sqrt_pos.mpr
have hlog := Real.log_pos ((one_lt_div ha).mpr ha1)
have hT’ : (0 : ℝ) < T := by exact_mod_cast hT
positivity
· exact Real.sqrt_pos.mpr (bernoulliVarianceBound_pos hp hp1)
end LeBet
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
lemma calibratedStake_nonneg (p α : ℝ) (T : ℕ) : 0 ≤ calibratedStake p α T :=
div_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)
end LeBet
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
variable {Ω : Type*} {m mΩ : MeasurableSpace Ω}
lemma measurable_calibratedStake {p : Ω → ℝ} (hp : Measurable p) (α : ℝ) (T
: ℕ) :
Measurable (fun ω => calibratedStake (p ω) α T) := by
unfold calibratedStake bernoulliVarianceBound
exact measurable_const.div
((measurable_const.sub (((hp.sub_const (1 / 2)).max
measurable_const).pow_const 2)).sqrt)
end LeBet
Appendix E: Betting Interpretation of the Monitor Evidence
The log-growth decomposition gives the Bernoulli KL maximum and its optimizer.
/-
# Bernoulli log growth and its KL maximum
The general log-growth decomposition in the betting-interpretation appendix
and its specialization
at the stake maximizing the drift. These identities support the general-stake
detection bound and its KL special case.
Nothing here mentions a probability space.
-/
import LeBet.Algebra
namespace LeBet
/-- ‘ψ_λ(u) = log(1 - u + u e^λ)’, the conditional cumulant generating
function
used in ‘eq:conditional-bernoulli-martingale’. -/
noncomputable def psi («λ» u : ℝ) : ℝ := Real.log (1 - u + u * Real.exp «λ»)
/-- The Kullback--Leibler divergence between two Bernoulli laws. -/
noncomputable def kl (p q : ℝ) : ℝ :=
p * Real.log (p / q) + (1 - p) * Real.log ((1 - p) / (1 - q))
/-- The optimal stake for two interior Bernoulli reference levels. -/
noncomputable def lamStar (p_0 p_1 : ℝ) : ℝ :=
Real.log (p_1 * (1 - p_0) / (p_0 * (1 - p_1)))
/-- ‘ψ_λ‘ in the ‘k‘-parametrisation. -/
lemma psi_eq_log_k («λ» u : ℝ) :
psi «λ» u = Real.log (1 + (Real.exp «λ» - 1) * u) := by
rw [psi, normaliser_eq]
lemma num_pos’ {p_0 p_1 : ℝ} (h1 : 0 < p_1) (h0’ : p_0 < 1) : 0 < p_1 * (1 -
p_0) :=
mul_pos h1 (by linarith)
lemma den_pos’ {p_0 p_1 : ℝ} (h0 : 0 < p_0) (h1’ : p_1 < 1) : 0 < p_0 * (1 -
p_1) :=
mul_pos h0 (by linarith)
section
variable {p_0 p_1 : ℝ} (h0 : 0 < p_0) (h0’ : p_0 < 1) (h1 : 0 < p_1) (h1’ :
p_1 < 1)
include h0 h0’ h1 h1’
/-- ‘eq:lambda-star-exponential’. -/
lemma exp_lamStar :
Real.exp (lamStar p_0 p_1) = p_1 * (1 - p_0) / (p_0 * (1 - p_1)) :=
Real.exp_log (div_pos (num_pos’ h1 h0’) (den_pos’ h0 h1’))
omit h0’ h1 in
/-- ‘eq:lambda-star-positive’: the optimal stake is positive exactly under
separation. Only ‘0 < p_0‘ and ‘p_1 < 1‘ are needed besides the separation.
-/
lemma lamStar_pos (hlt : p_0 < p_1) : 0 < lamStar p_0 p_1 := by
refine Real.log_pos ?_
rw [one_lt_div (den_pos’ h0 h1’)]
nlinarith
/-- ‘eq:lambda-star-normalizer‘. -/
lemma normaliser_lamStar :
1 - p_0 + p_0 * Real.exp (lamStar p_0 p_1) = (1 - p_0) / (1 - p_1) := by
rw [exp_lamStar h0 h0’ h1 h1’]
have hp_0 : p_0 ≠ 0 := ne_of_gt h0
have hq : (1 : R) - p_1 ≠ 0 := by intro h; rw [sub_eq_zero] at h; linarith
field_simp
ring
/-- The compensator of the evidence process at the optimal stake. -/
lemma psi_lamStar :
psi (lamStar p_0 p_1) p_0 = Real.log (1 - p_0) - Real.log (1 - p_1) := by
rw [psi, normaliser_lamStar h0 h0’ h1 h1’]
exact Real.log_div (by intro h; rw [sub_eq_zero] at h; linarith)
(by intro h; rw [sub_eq_zero] at h; linarith)
lemma lamStar_eq_logs :
lamStar p_0 p_1
= Real.log p_1 + Real.log (1 - p_0) - Real.log p_0 - Real.log (1 - p_1)
:= by
have hp_1 : p_1 ≠ 0 := ne_of_gt h1
have hp_0 : p_0 ≠ 0 := ne_of_gt h0
have ha : (1 : R) - p_0 ≠ 0 := by intro h; rw [sub_eq_zero] at h; linarith
have hb : (1 : R) - p_1 ≠ 0 := by intro h; rw [sub_eq_zero] at h; linarith
rw [lamStar, Real.log_div (mul_ne_zero hp_1 ha) (mul_ne_zero hp_0 hb),
Real.log_mul hp_1 ha, Real.log_mul hp_0 hb]
ring
lemma kl_eq_logs :
kl p_1 p_0
= p_1 * (Real.log p_1 - Real.log p_0)
+ (1 - p_1) * (Real.log (1 - p_1) - Real.log (1 - p_0)) := by
have hp_1 : p_1 ≠ 0 := ne_of_gt h1
have hp_0 : p_0 ≠ 0 := ne_of_gt h0
have ha : (1 : R) - p_0 ≠ 0 := by intro h; rw [sub_eq_zero] at h; linarith
have hb : (1 : R) - p_1 ≠ 0 := by intro h; rw [sub_eq_zero] at h; linarith
rw [kl, Real.log_div hp_1 hp_0, Real.log_div hb ha]
/--
**The KL drift identity**, ‘eq:kl-drift-identity‘. The per-step drift of the
evidence process at the optimal stake is the Bernoulli KL divergence.
Note that the separation hypothesis ‘p_0 < p_1‘ is *not* needed: the identity
is
algebraic, and holds for any two rates in ‘(0,1)‘. Separation is only what
makes
‘λ*‘ positive and the divergence nonzero.
-/
theorem kl_drift_identity :
p_1 * lamStar p_0 p_1 - psi (lamStar p_0 p_1) p_0 = kl p_1 p_0 := by
rw [psi_lamStar h0 h0’ h1 h1’, lamStar_eq_logs h0 h0’ h1 h1’,
kl_eq_logs h0 h0’ h1 h1’]
ring
end
/-- Exponential tilting of a Bernoulli reference law. -/
noncomputable def tiltedRate («λ» p : R) : R :=
p * Real.exp «λ» / (1 - p + p * Real.exp «λ»)
lemma tiltedRate_range {p : R} (hp : 0 < p) (hp’ : p < 1) («λ» : R) :
0 < tiltedRate «λ» p ∧ tiltedRate «λ» p < 1 := by
have hc := add_pos (sub_pos.mpr hp’) (mul_pos hp (Real.exp_pos «λ»))
constructor
· exact div_pos (mul_pos hp (Real.exp_pos «λ»)) hc
· exact (div_lt_one hc).mpr (by linarith)
/-- Nonnegativity of the Bernoulli KL divergence, from ‘log x ≤ x - 1‘. -/
lemma kl_nonneg {p q : R} (hp : 0 < p) (hp’ : p < 1)
(hq : 0 < q) (hq’ : q < 1) : 0 ≤ kl p q := by
have hp1 : 0 < 1 - p := by linarith
have hq1 : 0 < 1 - q := by linarith
have h_0 : p * (Real.log q - Real.log p) ≤ q - p := by
calc
p * (Real.log q - Real.log p) = p * Real.log (q / p) := by
rw [Real.log_div hq.ne’ hp.ne’]
_ ≤ p * (q / p - 1) :=
mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos (div_pos hq
hp)) hp.le
_ = q - p := by field_simp
have h_1 : (1 - p) * (Real.log (1 - q) - Real.log (1 - p)) ≤ p - q := by
calc
(1 - p) * (Real.log (1 - q) - Real.log (1 - p)) =
(1 - p) * Real.log ((1 - q) / (1 - p)) := by
rw [Real.log_div hq1.ne’ hp1.ne’]
_ ≤ (1 - p) * ((1 - q) / (1 - p) - 1) :=
mul_le_mul_of_nonneg_left
(Real.log_le_sub_one_of_pos (div_pos hq1 hp1)) hp1.le
_ = p - q := by field_simp; ring
rw [kl_eq_logs hq hq’ hp hp’]
nlinarith
/-- ‘eq:bernoulli-log-growth-kl‘, for every real stake. -/
theorem log_growth_kl_decomposition {p_0 p_1 : R}
(h0 : 0 < p_0) (h0’ : p_0 < 1) (h1 : 0 < p_1) (h1’ : p_1 < 1) («λ» : R) :
«λ» * p_1 - psi «λ» p_0 = kl p_1 p_0 - kl p_1 (tiltedRate «λ» p_0) := by
let c := 1 - p_0 + p_0 * Real.exp «λ»
have hc : 0 < c := add_pos (sub_pos.mpr h0’) (mul_pos h0 (Real.exp_pos «λ»))
have hp : 0 < 1 - p_0 := by linarith
have hq := tiltedRate_range h0 h0’ «λ»
have heq : 1 - tiltedRate «λ» p_0 = (1 - p_0) / c := by
dsimp [tiltedRate, c] at *
field_simp; ring
have hlog : Real.log (tiltedRate «λ» p_0) = Real.log p_0 + «λ» - Real.log c
:= by
rw [tiltedRate, Real.log_div (mul_ne_zero h0.ne’ (Real.exp_ne_zero «λ»))
hc.ne’,
Real.log_mul h0.ne’ (Real.exp_ne_zero «λ»), Real.log_exp]
have hlog’ : Real.log (1 - tiltedRate «λ» p_0) = Real.log (1 - p_0) -
Real.log c := by
rw [heq, Real.log_div hp.ne’ hc.ne’]
rw [kl_eq_logs h0 h0’ h1 h1’, kl_eq_logs hq.1 hq.2 h1 h1’, hlog, hlog’]
change «λ» * p_1 - Real.log c = _
ring
/-- KL is the maximal bracketed drift, with equality given by
‘kl_drift_identity‘. -/
theorem log_growth_le_kl {p_0 p_1 : R}
(h0 : 0 < p_0) (h0’ : p_0 < 1) (h1 : 0 < p_1) (h1’ : p_1 < 1) («λ» : R) :
«λ» * p_1 - psi «λ» p_0 ≤ kl p_1 p_0 := by
rw [log_growth_kl_decomposition h0 h0’ h1 h1’ «λ»]
have hq := tiltedRate_range h0 h0’ «λ»
exact sub_le_self _ (kl_nonneg h1 h1’ hq.1 hq.2)
/-- ‘eq:bernoulli-kl-duality‘, with the maximum attained at ‘lamStar‘. -/
theorem bernoulli_kl_duality {p_0 p_1 : R}
(h0 : 0 < p_0) (h0’ : p_0 < 1) (h1 : 0 < p_1) (h1’ : p_1 < 1) :
(⨆ z : R, z * p_1 - psi z p_0) = kl p_1 p_0 := by
apply le_antisymm
· exact ciSup_le (log_growth_le_kl h0 h0’ h1 h1’)
· have hb : BddAbove (Set.range (fun z : R => z * p_1 - psi z p_0)) :=
⟨kl p_1 p_0, by rintro _ ⟨z, rfl⟩; exact log_growth_le_kl h0 h0’ h1 h1’ z⟩
have h := le_ciSup hb (lamStar p_0 p_1)
simpa only [mul_comm (lamStar p_0 p_1) p_1, kl_drift_identity h0 h0’ h1
h1’] using h
end LeBet
Appendix G: Auxiliary Lemmas
Log-normalizer bounds give the evidence comparisons.
import LeBet.RawScores
import LeBet.JointIntervention
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet
/-- Jensen’s inequality for the Bernoulli normalizer, including both
endpoints. -/
lemma psi_ge_linear {p : R} (hp : 0 ≤ p) (hp’ : p ≤ 1) («λ» : R) :
«λ» * p ≤ psi «λ» p := by
have h : Real.exp («λ» * p) ≤ 1 - p + p * Real.exp «λ» := by
simpa [smul_eq_mul, mul_comm] using
convexOn_exp.2 (Set.mem_univ (0 : R)) (Set.mem_univ «λ»)
(sub_nonneg.mpr hp’) hp (by ring : 1 - p + p = 1)
simpa [psi] using Real.log_le_log (Real.exp_pos («λ» * p)) h
lemma psi_le_hoeffding {«λ» p : ℝ} (hl : 0 ≤ «λ») (hp : 0 ≤ p) (hp’ : p ≤ 1) :
psi «λ» p ≤ «λ» * p + «λ» ˆ 2 / 8 := by
have hc : 0 < 1 - p + p * Real.exp «λ» := by
rw [normaliser_eq]
exact one_add_mul_pos (exp_sub_one_nonneg hl) hp
have h := Real.log_le_log (mul_pos hc (Real.exp_pos (-«λ» * p)))
(bernoulli_hoeffding hp hp’ «λ»)
rw [Real.log_mul hc.ne’ (Real.exp_ne_zero _), Real.log_exp, Real.log_exp]
at h
change psi «λ» p + (-«λ» * p) ≤ «λ» ˆ 2 / 8 at h
linarith
lemma psi_le_one_sided {«λ» p : ℝ} (hl : 0 ≤ «λ») (hp : 0 ≤ p) (hp’ : p ≤ 1) :
psi «λ» p ≤ «λ» * p + bernoulliVarianceBound p * «λ» ˆ 2 / 2 := by
have hc : 0 < 1 - p + p * Real.exp «λ» := by
rw [normaliser_eq]
exact one_add_mul_pos (exp_sub_one_nonneg hl) hp
have h := Real.log_le_log (mul_pos hc (Real.exp_pos (-«λ» * p)))
(bernoulli_hoeffding_one_sided hp hp’ hl)
rw [Real.log_mul hc.ne’ (Real.exp_ne_zero _), Real.log_exp, Real.log_exp]
at h
change psi «λ» p + (-«λ» * p) ≤ bernoulliVarianceBound p * «λ» ˆ 2 / 2 at h
linarith
namespace BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration ℕ mΩ}
(X : BinaryMonitor gF)
/-- The lower evidence bound is deterministic and permits ‘p = 0‘ and ‘p =
1‘. -/
lemma log_evidence_ge_hoeffding {«λ» p : ℝ} (hl : 0 ≤ «λ»)
(hp : 0 ≤ p) (hp’ : p ≤ 1) (t : ℕ) (ω : Ω) :
«λ» * (X.S t ω - t * p) - t * «λ» ˆ 2 / 8 ≤
Real.log (X.E «λ» p t ω) := by
rw [X.log_evidence hl hp]
have h := mul_le_mul_of_nonneg_left (psi_le_hoeffding hl hp hp’)
(Nat.cast_nonneg t : (0 : ℝ) ≤ t)
nlinarith
lemma log_evidence_ge_one_sided {«λ» p : ℝ} (hl : 0 ≤ «λ»)
(hp : 0 ≤ p) (hp’ : p ≤ 1) (t : ℕ) (ω : Ω) :
«λ» * (X.S t ω - t * p) - t * bernoulliVarianceBound p * «λ» ˆ 2 / 2 ≤
Real.log (X.E «λ» p t ω) := by
rw [X.log_evidence hl hp]
have h := mul_le_mul_of_nonneg_left (psi_le_one_sided hl hp hp’)
(Nat.cast_nonneg t : (0 : ℝ) ≤ t)
nlinarith
lemma log_evidence_le_linear {«λ» p : ℝ} (hl : 0 ≤ «λ»)
(hp : 0 ≤ p) (hp’ : p ≤ 1) (t : ℕ) (ω : Ω) :
Real.log (X.E «λ» p t ω) ≤ «λ» * (X.S t ω - t * p) := by
rw [X.log_evidence hl hp]
have h := mul_le_mul_of_nonneg_left (psi_ge_linear hp hp’ «λ»)
(Nat.cast_nonneg t : (0 : R) ≤ t)
nlinarith
/-- The auxiliary evidence bounds, with the observed average and closed
reference interval. -/
theorem pathwise_evidence_bounds {«λ» p : R} (hl : 0 ≤ «λ»)
(hp : 0 ≤ p) (hp’ : p ≤ 1) {t : N} (ht : 0 < t) (ω : Ω) :
(t : R) * («λ» * (X.S t ω / t - p) - bernoulliVarianceBound p * «λ» ^ 2 /
2) ≤
Real.log (X.E «λ» p t ω) ∧
Real.log (X.E «λ» p t ω) ≤
(t : R) * «λ» * (X.S t ω / t - p) := by
have ht’ : (t : R) ≠ 0 := by exact_mod_cast ht.ne’
constructor
· calc
(t : R) * («λ» * (X.S t ω / t - p) - bernoulliVarianceBound p * «λ» ^ 2
/ 2) =
«λ» * (X.S t ω - t * p) - t * bernoulliVarianceBound p * «λ» ^ 2 /
2 := by
field_simp
_ ≤ Real.log (X.E «λ» p t ω) := X.log_evidence_ge_one_sided hl hp hp’ t
· calc
Real.log (X.E «λ» p t ω) ≤ «λ» * (X.S t ω - t * p) :=
X.log_evidence_le_linear hl hp hp’ t ω
_ = (t : R) * «λ» * (X.S t ω / t - p) := by
field_simp
end BinaryMonitor
end LeBet
Hoeffding Bounds
The finite-sampling proof uses Bernoulli populations. The general convex comparison and arbitrary bounded-population versions are not separately formalized.
import Mathlib.Analysis.Convex.Deriv
import Mathlib.Analysis.SpecialFunctions.Log.Deriv
import Mathlib.Tactic
namespace LeBet
/-- The one-sided Bernoulli curvature ‘v(p)‘. -/
noncomputable def bernoulliVarianceBound (p : R) : R :=
1 / 4 - max (p - 1 / 2) 0 ^ 2
lemma bernoulliVarianceBound_pos {p : R} (hp : 0 ≤ p) (hp1 : p < 1) :
0 < bernoulliVarianceBound p := by
unfold bernoulliVarianceBound
by_cases hh : p ≤ 1 / 2
· rw [max_eq_right (by linarith)]
norm_num
· rw [max_eq_left (by linarith)]
have hp0 : 0 < p := by linarith
nlinarith [mul_pos hp0 (sub_pos.mpr hp1)]
/-- The first derivative of the Bernoulli log normalizer. -/
lemma hasDerivAt_bernoulli_cgf {p : R} (hp : 0 ≤ p) (hp1 : p ≤ 1) (z : R) :
HasDerivAt (fun x => Real.log (1 - p + p * Real.exp x))
(p * Real.exp z / (1 - p + p * Real.exp z)) z := by
have hc : 0 < 1 - p + p * Real.exp z := by
rcases eq_or_lt_of_le hp with h | h
· simp [← h]
· exact add_pos_of_nonneg_of_pos (sub_nonneg.mpr hp1) (mul_pos h
(Real.exp_pos z))
convert (((Real.hasDerivAt_exp z).const_mul p).const_add (1 - p)).log
hc.ne’ using 1
/-- ‘eq:bernoulli-cgf-curvature‘, including both Bernoulli endpoints. -/
theorem bernoulli_cgf_curvature {p z : R} (hp : 0 ≤ p) (hp1 : p ≤ 1) (hz : 0
≤ z) :
0 ≤ deriv (deriv (fun x => Real.log (1 - p + p * Real.exp x))) z ∧
deriv (deriv (fun x => Real.log (1 - p + p * Real.exp x))) z ≤
bernoulliVarianceBound p := by
let c := fun x => 1 - p + p * Real.exp x
let q := fun x => p * Real.exp x / c x
have hc (x : R) : 0 < c x := by
rcases eq_or_lt_of_le hp with h | h
· simp [c, ← h]
· exact add_pos_of_nonneg_of_pos (sub_nonneg.mpr hp1) (mul_pos h
(Real.exp_pos x))
have dc (x : R) : HasDerivAt c (p * Real.exp x) x :=
((Real.hasDerivAt_exp x).const_mul p).const_add (1 - p)
have dq : HasDerivAt q (q z * (1 - q z)) z := by
convert ((Real.hasDerivAt_exp z).const_mul p).div (dc z) (hc z).ne’ using
1
dsimp [q]
field_simp [(hc z).ne’]
have hd : deriv (fun x => Real.log (1 - p + p * Real.exp x)) = q :=
funext (fun x => (hasDerivAt_bernoulli_cgf hp hp1 x).deriv)
rw [hd, dq.deriv]
have hq0 : 0 ≤ q z := div_nonneg (mul_nonneg hp (Real.exp_pos z).le) (hc
z).le
have hq1 : q z ≤ 1 := (div_le_one (hc z)).mpr (by dsimp [c]; linarith)
refine ⟨mul_nonneg hq0 (sub_nonneg.mpr hq1), ?_⟩
unfold bernoulliVarianceBound
by_cases hh : p ≤ 1 / 2
· rw [max_eq_right (by linarith)]
nlinarith [sq_nonneg (q z - 1 / 2)]
· have hpq : p ≤ q z := by
apply (le_div_iff0 (hc z)).mpr
have he := Real.one_le_exp_iff.mpr hz
have hprod := mul_nonneg (mul_nonneg hp (sub_nonneg.mpr hp1))
(sub_nonneg.mpr he)
dsimp [c]
nlinarith
rw [max_eq_left (by linarith)]
nlinarith [mul_nonneg (sub_nonneg.mpr hpq)
(show 0 ≤ q z + p - 1 by linarith)]
/-- Fixed-monitor proof, ‘eq:bernoulli-hoeffding-scalar‘.
The sharp Bernoulli Hoeffding bound, including both signs of the stake. -/
theorem bernoulli_hoeffding {m : R} (hm0 : 0 ≤ m) (hm1 : m ≤ 1) (z : R) :
(1 - m + m * Real.exp z) * Real.exp (-z * m) ≤ Real.exp (z ^ 2 / 8) := by
let c : R → R := fun x => 1 - m + m * Real.exp x
let q : R → R := fun x => m * Real.exp x / c x
let g : R → R := fun x => x ^ 2 / 8 - Real.log (c x) + m * x
let g' : R → R := fun x => x / 4 - q x + m
have hc (x : R) : 0 < c x := by
dsimp [c]
rcases eq_or_lt_of_le hm0 with h | h
· simp [← h]
· exact add_pos_of_nonneg_of_pos (sub_nonneg.mpr hm1) (mul_pos h
(Real.exp_pos x))
have dc (x : R) : HasDerivAt c (m * Real.exp x) x := by
convert (hasDerivAt_const x (1 - m)).add ((Real.hasDerivAt_exp
x).const_mul m) using 1
simp [c]
have dq (x : R) : HasDerivAt q (q x * (1 - q x)) x := by
convert ((Real.hasDerivAt_exp x).const_mul m).div (dc x) (hc x).ne' using
1
dsimp [q]
field_simp [(hc x).ne']
have dg (x : R) : HasDerivAt g (g' x) x := by
convert ((((hasDerivAt_id x).pow 2).div_const 8).sub
((dc x).log (hc x).ne')).add ((hasDerivAt_id x).const_mul m) using 1
· rfl
· dsimp [g', q]; ring
have dg' (x : R) : HasDerivAt g' (1 / 4 - q x * (1 - q x)) x := by
convert (((hasDerivAt_id x).div_const 4).sub (dq x)).add_const m using 1
rfl
have hconv : ConvexOn ℝ Set.univ g := by
apply convexOn_of_hasDerivWithinAt2_nonneg convex_univ
(fun x _ => (dg x).continuousAt.continuousWithinAt)
(fun x _ => (dg x).hasDerivWithinAt)
(fun x _ => (dg' x).hasDerivWithinAt)
intro x _
nlinarith [sq_nonneg (q x - 1 / 2)]
have dg0 : HasDerivAt g 0 0 := by
convert dg 0 using 1
simp [g', q, c]
have hg : 0 ≤ g z := by
have hmin := hconv.isMinOn_of_rightDeriv_eq_zero (x := 0) (by simp)
(dg0.hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Ioi 0))
have := hmin (Set.mem_univ z)
simpa [g, c] using this
have hlog : Real.log (c z) + (-z * m) ≤ z ^ 2 / 8 := by
dsimp [g] at hg
nlinarith
calc
(1 - m + m * Real.exp z) * Real.exp (-z * m)
= Real.exp (Real.log (c z) + (-z * m)) := by rw [Real.exp_add,
Real.exp_log (hc z)]
_ ≤ Real.exp (z ˆ 2 / 8) := Real.exp_le_exp.mpr hlog
/-- The sharper scalar bound for nonnegative stakes, obtained from the
curvature of the Bernoulli log normalizer on the positive half-line. -/
theorem bernoulli_hoeffding_one_sided {p z : R}
(hp : 0 ≤ p) (hp1 : p ≤ 1) (hz : 0 ≤ z) :
(1 - p + p * Real.exp z) * Real.exp (-z * p) ≤
Real.exp (bernoulliVarianceBound p * z ˆ 2 / 2) := by
by_cases hh : p ≤ 1 / 2
· have hv : bernoulliVarianceBound p = 1 / 4 := by
simp only [bernoulliVarianceBound, max_eq_right (by linarith : p - 1 /
2 ≤ 0)]
norm_num
rw [hv]
convert bernoulli_hoeffding hp hp1 z using 1
congr 1
ring
have hp0 : 0 < p := by linarith
have hv : bernoulliVarianceBound p = p * (1 - p) := by
rw [bernoulliVarianceBound, max_eq_left (by linarith : 0 ≤ p - 1 / 2)]
ring
let c : R → R := fun x => 1 - p + p * Real.exp x
let q : R → R := fun x => p * Real.exp x / c x
let g : R → R := fun x => p * (1 - p) * x ˆ 2 / 2 - Real.log (c x) + p * x
let g’ : R → R := fun x => p * (1 - p) * x - q x + p
have hc (x : R) : 0 < c x :=
add_pos_of_nonneg_of_pos (sub_nonneg.mpr hp1) (mul_pos hp0 (Real.exp_pos
x))
have hq (x : R) (hx : 0 ≤ x) : p ≤ q x ∧ q x ≤ 1 := by
have he : 1 ≤ Real.exp x := Real.one_le_exp hx
constructor
· apply (le_div_iff0 (hc x)).mpr
dsimp [c]
nlinarith [mul_nonneg (mul_nonneg hp (sub_nonneg.mpr hp1))
(sub_nonneg.mpr he)]
· exact (div_le_one (hc x)).mpr (by dsimp [c]; linarith)
have dc (x : R) : HasDerivAt c (p * Real.exp x) x := by
convert (hasDerivAt_const x (1 - p)).add ((Real.hasDerivAt_exp
x).const_mul p) using 1
simp [c]
have dq (x : R) : HasDerivAt q (q x * (1 - q x)) x := by
convert ((Real.hasDerivAt_exp x).const_mul p).div (dc x) (hc x).ne’ using
1
dsimp [q]
field_simp [(hc x).ne’]
have dg (x : R) : HasDerivAt g (g’ x) x := by
convert (((((hasDerivAt_id x).pow 2).const_mul (p * (1 - p))).div_const
2).sub
((dc x).log (hc x).ne’)).add ((hasDerivAt_id x).const_mul p) using 1
· rfl
· dsimp [g’, q]; ring
have dg’ (x : R) : HasDerivAt g’ (p * (1 - p) - q x * (1 - q x)) x := by
convert (((hasDerivAt_id x).const_mul (p * (1 - p))).sub (dq
x)).add_const p using 1 <;>
simp [g']
have hconv : ConvexOn ℝ (Set.Ici 0) g := by
apply convexOn_of_hasDerivWithinAt2_nonneg (convex_Ici 0)
(fun x _ => (dg x).continuousAt.continuousWithinAt)
(fun x _ => (dg x).hasDerivWithinAt)
(fun x _ => (dg' x).hasDerivWithinAt)
intro x hx
have hx0 : 0 ≤ x := (interior_subset hx : x ∈ Set.Ici 0)
have hqx := hq x hx0
nlinarith [mul_nonneg (sub_nonneg.mpr hqx.1) (show 0 ≤ q x + p - 1 by
linarith)]
have dg0 : HasDerivAt g 0 0 := by
convert dg 0 using 1
simp [g', q, c]
have hg : 0 ≤ g z := by
rcases eq_or_lt_of_le hz with hzero | hpos
· rw [← hzero]
simp [g, c]
· have h := hconv.le_slope_of_hasDerivAt (by simp) hz hpos dg0
rw [slope_def_field] at h
have hnum := (le_div_iff₀ (show 0 < z - 0 by linarith)).mp h
simpa [g, c] using hnum
have hlog : Real.log (c z) + (-z * p) ≤ p * (1 - p) * z ^ 2 / 2 := by
dsimp [g] at hg
linarith
rw [hv]
calc
_ = Real.exp (Real.log (c z) + (-z * p)) := by
rw [Real.exp_add, Real.exp_log (hc z)]
_ ≤ _ := Real.exp_le_exp.mpr hlog
end LeBet
import LeBet.Hoeffding
import Mathlib.Probability.Distributions.Uniform
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Tactic
open Finset
open scoped Classical
namespace LeBet.FiniteSampling
variable {ι : Type*}
/-- Count a subset once for each possible first sampled element. -/
lemma sum_remove_one (s : Finset ι) (k : ℕ) (f : Finset ι → ℝ) :
∑ i ∈ s, ∑ R ∈ (s.erase i).powersetCard k, f (insert i R) =
(k + 1 : ℝ) * ∑ K ∈ s.powersetCard (k + 1), f K := by
have hinner (i : ι) (hi : i ∈ s) :
∑ R ∈ (s.erase i).powersetCard k, f (insert i R) =
∑ K ∈ (s.powersetCard (k + 1)).filter (i ∈ ·), f K := by
apply sum_bij (fun R _ => insert i R)
· intro R hR
obtain ⟨hRs, hRk⟩ := mem_powersetCard.mp hR
have hiR : i ∉ R := fun h => (mem_erase.mp (hRs h)).1 rfl
exact mem_filter.mpr ⟨mem_powersetCard.mpr
⟨insert_subset hi (hRs.trans (erase_subset _ _)), by simp [hiR, hRk]⟩,
mem_insert_self _ _⟩
· intro R hR T hT he
have hiR : i ∉ R := fun h => (mem_erase.mp ((mem_powersetCard.mp hR).1 h)).1 rfl
have hiT : i ∉ T := fun h => (mem_erase.mp ((mem_powersetCard.mp hT).1 h)).1 rfl
have hh := congrArg (erase · i) he
simpa [hiR, hiT] using hh
· intro K hK
obtain ⟨hK, hiK⟩ := mem_filter.mp hK
obtain ⟨hKs, hKk⟩ := mem_powersetCard.mp hK
refine ⟨K.erase i, mem_powersetCard.mpr ⟨erase_subset_erase _ hKs, ?_⟩,
· rw [card_erase_of_mem hiK, hKk]
omega
· exact insert_erase hiK
· intros
rfl
simp_rw [sum_congr rfl hinner, sum_filter]
rw [sum_comm]
calc
∑ K ∈ s.powersetCard (k + 1), ∑ i ∈ s, (if i ∈ K then f K else 0) =
∑ K ∈ s.powersetCard (k + 1), (k + 1 : R) * f K := by
apply sum_congr rfl
intro K hK
obtain ⟨hKs, hKk⟩ := mem_powersetCard.mp hK
have he : s.filter (· ∈ K) = K := by
ext i
simp only [mem_filter]
exact ⟨And.right, fun h => ⟨hKs h, h⟩⟩
rw [← sum_filter, he, sum_const, hKk]
simp
_ = _ := (mul_sum _ _ _).symm
noncomputable def populationMean (s : Finset ι) (v : ι → R) : R :=
(∑ i ∈ s, v i) / s.card
lemma populationMean_bounds (s : Finset ι) (v : ι → R)
(hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) :
0 ≤ populationMean s v ∧ populationMean s v ≤ 1 := by
have hs : ∑ i ∈ s, v i ≤ s.card := by
calc
∑ i ∈ s, v i ≤ ∑ _i ∈ s, (1 : R) := sum_le_sum (fun i hi => by rcases
hv i hi with h | h <;> simp [h])
_ = s.card := by simp
constructor
· exact div_nonneg (sum_nonneg (fun i hi => by rcases hv i hi with h | h <;>
simp [h])) (Nat.cast_nonneg _)
· exact div_le_one_of_le0 hs (Nat.cast_nonneg _)
/-- Hoeffding’s scalar lemma for one uniform draw from a binary population. -/
lemma population_mgf (s : Finset ι) (hs : s.Nonempty) (v : ι → ℝ)
(hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) (z : ℝ) :
∑ i ∈ s, Real.exp (z * (v i - populationMean s v)) ≤
(s.card : ℝ) * Real.exp (z ^ 2 / 8) := by
let m := populationMean s v
have hN : (s.card : ℝ) ≠ 0 := by exact_mod_cast hs.card_pos.ne’
have hsum : ∑ i ∈ s, v i = (s.card : ℝ) * m := by
dsimp [m, populationMean]
field_simp
have he : ∑ i ∈ s, Real.exp (z * (v i - m)) =
(s.card : ℝ) * ((1 - m + m * Real.exp z) * Real.exp (-z * m)) := by
calc
∑ i ∈ s, Real.exp (z * (v i - m)) =
∑ i ∈ s, (1 + (Real.exp z - 1) * v i) * Real.exp (-z * m) := by
apply sum_congr rfl
intro i hi
rw [mul_sub, Real.exp_sub, div_eq_mul_inv, ← Real.exp_neg]
rcases hv i hi with h | h <;> simp [h, neg_mul]
_ = _ := by rw [← sum_mul, sum_add_distrib, sum_const, ← mul_sum,
hsum]; simp; ring
rw [he]
exact mul_le_mul_of_nonneg_left
(bernoulli_hoeffding (populationMean_bounds s v hv).1
(populationMean_bounds s v hv).2 z)
(Nat.cast_nonneg _)
set_option maxHeartbeats 800000 in
/-- The centered MGF with Serfling’s finite-population correction.
This is the binary case of Bardenet--Maillard, Proposition 2.2. -/
theorem uniform_subset_serfling_mgf (k : ℕ) (s : Finset ι) (hk : k ≤ s.card)
(v : ι → ℝ) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) (z : ℝ) :
∑ K ∈ s.powersetCard k, Real.exp (z * ((∑ i ∈ K, v i) - k *
populationMean s v)) ≤
(s.card.choose k : ℝ) *
Real.exp ((k : ℝ) * ((s.card : ℝ) - k + 1) / s.card * z ^ 2 / 8) := by
induction k generalizing s with
| zero => simp
| succ k ih =>
have hNpos : 0 < s.card := by omega
have hN : (s.card : ℝ) ≠ 0 := by exact_mod_cast hNpos.ne’
have hmean : ∑ i ∈ s, v i = (s.card : ℝ) * populationMean s v := by
dsimp [populationMean]
field_simp
by_cases hfull : k + 1 = s.card
· rw [hfull, powersetCard_self, sum_singleton,
hmean, sub_self]
simp only [mul_zero, Real.exp_zero, Nat.choose_self, Nat.cast_one,
one_mul]
apply Real.one_le_exp_iff.mpr
simp only [sub_self, zero_add]
positivity
have hNtwo : 1 < s.card := by omega
have hNm : 0 < (s.card : ℝ) - 1 := by
have : (1 : ℝ) < s.card := by exact_mod_cast hNtwo
linarith
let m := populationMean s v
let c : R := ((s.card : R) - (k + 1)) / ((s.card : R) - 1)
let V : R := (k : R) * ((s.card : R) - k) / ((s.card : R) - 1)
let V’ : R := (k + 1 : R) * ((s.card : R) - k) / s.card
have hvariance : V + c ^ 2 ≤ V’ := by
have hid : (V’ - (V + c ^ 2)) *
((s.card : R) * ((s.card : R) - 1) ^ 2) =
(k : R) * ((s.card : R) - k - 1) := by
dsimp [V, V’, c]
field_simp
ring
have hremaining : (0 : R) ≤ (s.card : R) - k - 1 := by
have : (k + 1 : R) ≤ s.card := by exact_mod_cast hk
linarith
have hden : (0 : R) < (s.card : R) * ((s.card : R) - 1) ^ 2 := by
positivity
have hnonneg : 0 ≤ (V’ - (V + c ^ 2)) *
((s.card : R) * ((s.card : R) - 1) ^ 2) := by
rw [hid]
exact mul_nonneg (Nat.cast_nonneg _) hremaining
have := (mul_nonneg_iff_of_pos_right hden).mp hnonneg
linarith
let A : R := ((s.card - 1).choose k : R) * Real.exp (V * z ^ 2 / 8)
have hA : 0 ≤ A := mul_nonneg (Nat.cast_nonneg _) (Real.exp_pos _).le
have hinner (i : ι) (hi : i ∈ s) :
R ∈ (s.erase i).powersetCard k,
Real.exp (z * ((∑ j ∈ insert i R, v j) - (k + 1) * m)) ≤
A * Real.exp ((z * c) * (v i - m)) := by
have hec : (s.erase i).card = s.card - 1 := card_erase_of_mem hi
have hiR {R : Finset ι} (hR : R ∈ (s.erase i).powersetCard k) : i ∉ R :=
fun h => (mem_erase.mp ((mem_powersetCard.mp hR).1 h)).1 rfl
have herase : populationMean (s.erase i) v =
((s.card : R) * m - v i) / ((s.card : R) - 1) := by
unfold populationMean
rw [sum_erase_eq_sub hi, hec, Nat.cast_sub (by omega), Nat.cast_one,
hmean]
have hshift : v i + (k : R) * populationMean (s.erase i) v - (k + 1) *
c * (v i - m) := by
rw [herase]
dsimp [c]
field_simp [hNm.ne’]
ring
have hih := ih (s.erase i) (by rw [hec]; omega)
(fun j hj => hv j (mem_of_mem_erase hj))
have hexp (R : Finset ι) (hR : R ∈ (s.erase i).powersetCard k) :
Real.exp (z * ((∑ j ∈ insert i R, v j) - (k + 1) * m)) =
Real.exp ((z * c) * (v i - m)) *
Real.exp (z * ((∑ j ∈ R, v j) - k * populationMean (s.erase i)
v)) := by
rw [sum_insert (hiR hR), ← Real.exp_add]
congr 1
nlinarith only [congrArg (z * ·) hshift]
calc
_ = Real.exp ((z * c) * (v i - m)) *
∑ R ∈ (s.erase i).powersetCard k,
Real.exp (z * ((∑ j ∈ R, v j) - k * populationMean (s.erase i)
v)) := by
rw [mul_sum]
exact sum_congr rfl hexp
_ ≤ Real.exp ((z * c) * (v i - m)) * A := by
apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le
simpa only [A, V, hec, Nat.cast_sub (by omega : 1 ≤ s.card),
Nat.cast_one,
show (s.card : ℝ) - 1 - k + 1 = (s.card : ℝ) - k by ring] using
_ = _ := mul_comm _ _
have hmgf : ∀ i ∈ s, Real.exp ((z * c) * (v i - m)) ≤
(s.card : ℝ) * Real.exp ((z * c) ^ 2 / 8) :=
population_mgf s (card_pos.mp hNpos) v hv (z * c)
have hchoose : (s.card : ℝ) * ((s.card - 1).choose k : ℝ) =
(k + 1 : ℝ) * (s.card.choose (k + 1) : ℝ) := by
have h := Nat.add_one_mul_choose_eq (s.card - 1) k
simp only [Nat.sub_add_cancel (show 1 ≤ s.card by omega)] at h
exact_mod_cast h.trans (Nat.mul_comm _ _)
have hexp : Real.exp (V * z ^ 2 / 8) * Real.exp ((z * c) ^ 2 / 8) ≤
Real.exp (V' * z ^ 2 / 8) := by
rw [← Real.exp_add]
apply Real.exp_le_exp.mpr
nlinarith [mul_nonneg (sub_nonneg.mpr hvariance) (sq_nonneg z)]
have hbound : (k + 1 : ℝ) *
∑ K ∈ s.powersetCard (k + 1), Real.exp (z * ((∑ i ∈ K, v i) - (k +
1) * m)) ≤
(k + 1 : ℝ) * ((s.card.choose (k + 1) : ℝ) * Real.exp (V' * z ^ 2 /
8)) := by
calc
_ = ∑ i ∈ s, ∑ R ∈ (s.erase i).powersetCard k,
Real.exp (z * ((∑ j ∈ insert i R, v j) - (k + 1) * m)) :=
(sum_remove_one s k (fun K => Real.exp (z * ((∑ i ∈ K, v i) - (k + 1) *
m)))).symm
_ ≤ ∑ i ∈ s, A * Real.exp ((z * c) * (v i - m)) := sum_le_sum hinner
_ = A * ∑ i ∈ s, Real.exp ((z * c) * (v i - m)) := (mul_sum _ _
_).symm
_ ≤ A * ((s.card : ℝ) * Real.exp ((z * c) ^ 2 / 8)) :=
mul_le_mul_of_nonneg_left hmgf hA
_ = ((s.card : ℝ) * ((s.card - 1).choose k : ℝ)) *
(Real.exp (V * z ^ 2 / 8) * Real.exp ((z * c) ^ 2 / 8)) := by
dsimp [A]; ring
_ ≤ ((s.card : ℝ) * ((s.card - 1).choose k : ℝ)) *
Real.exp (V' * z ^ 2 / 8) :=
mul_le_mul_of_nonneg_left hexp (by positivity)
_ = _ := by rw [hchoose]; ring
have hkpos : (0 : ℝ) < k + 1 := by positivity
convert (mul_le_mul_iff_right₀ hkpos).mp hbound using 1 <;>
simp only [Nat.cast_succ, V', m] <;>
ring_nf
/-- The Hoeffding bound follows by dropping the finite-population correction.
-/
theorem uniform_subset_mgf (k : N) (s : Finset ι) (hk : k ≤ s.card)
(v : ι → R) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) (z : R) :
∑ K ∈ s.powersetCard k, Real.exp (z * ((∑ i ∈ K, v i) - k *
populationMean s v)) ≤
(s.card.choose k : R) * Real.exp (k * z ^ 2 / 8) := by
by_cases hk0 : k = 0
· simp [hk0]
apply (uniform_subset_serfling_mgf k s hk v hv z).trans
apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _)
apply Real.exp_le_exp.mpr
have hN : (0 : R) < s.card := by exact_mod_cast (Nat.zero_lt_of_ne_zero
hk0).trans_le hk
have hk1 : (1 : R) ≤ k := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hk0
have hcoef : (k : R) * ((s.card : R) - k + 1) / s.card ≤ k := by
apply (div_le_iff₀ hN).mpr
nlinarith [mul_nonneg (Nat.cast_nonneg k) (sub_nonneg.mpr hk1)]
nlinarith [mul_nonneg (sub_nonneg.mpr hcoef) (sq_nonneg z)]
end LeBet.FiniteSampling
import LeBet.FiniteSampling
import LeBet.RankTransfer
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
variable {ι : Type*}
/-- The actual uniform law on the ‘k‘-element subsets of ‘s‘. -/
noncomputable def subsetLaw (s : Finset ι) (k : N) (hk : k ≤ s.card) :
Measure[⊤] (Finset ι) := by
letI : MeasurableSpace (Finset ι) := ⊤
exact (PMF.uniformOfFinset (s.powersetCard k) (powersetCard_nonempty.mpr
hk)).toMeasure
lemma subsetLaw_real (s : Finset ι) (k : N) (hk : k ≤ s.card) (A : Set
(Finset ι)) :
(subsetLaw s k hk).real A =
(((s.powersetCard k).filter (· ∈ A)).card : R) / s.card.choose k := by
letI : MeasurableSpace (Finset ι) := ⊤
have hA : MeasurableSet A := trivial
unfold subsetLaw Measure.real
rw [PMF.toMeasure_uniformOfFinset_apply _ _ hA]
simp [ENNReal.toReal_div, card_powersetCard]
lemma subset_chernoff (k : N) (s : Finset ι) (hk : k ≤ s.card)
(v : ι → R) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) (z a : R) :
(subsetLaw s k hk).real {K | a ≤ z * ((∑ i ∈ K, v i) - k *
populationMean s v)} ≤
Real.exp (-a + k * z ^ 2 / 8) := by
let B := (s.powersetCard k).filter fun K => a ≤ z * ((∑ i ∈ K, v i) - k *
populationMean s v)
have hC : (0 : R) < s.card.choose k := by exact_mod_cast Nat.choose_pos hk
have hbound : (B.card : R) * Real.exp a ≤
(s.card.choose k : R) * Real.exp (k * z ^ 2 / 8) := by
calc
_ = ∑ _K ∈ B, Real.exp a := by simp
_ ≤ ∑ K ∈ B, Real.exp (z * ((∑ i ∈ K, v i) - k * populationMean s v)) := by
apply sum_le_sum
intro K hK
exact Real.exp_le_exp.mpr (mem_filter.mp hK).2
_ ≤ ∑ K ∈ s.powersetCard k, Real.exp (z * ((∑ i ∈ K, v i) - k *
populationMean s v)) := by
sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ =>
(Real.exp_pos _).le)
_ ≤ _ := uniform_subset_mgf k s hk v hv z
rw [subsetLaw_real]
change (B.card : R) / s.card.choose k ≤ _
calc
_ ≤ Real.exp (k * z ^ 2 / 8) / Real.exp a := by
apply (div_le_div_iff₀ hC (Real.exp_pos a)).mpr
simpa [mul_comm] using hbound
_ = _ := by rw [← Real.exp_sub]; congr 1; ring
/-- The binary sampling-without-replacement Hoeffding inequality, in either
direction.
‘sign = 1‘ gives the upper tail and ‘sign = -1‘ the lower tail. -/
theorem subset_hoeffding {k : N} (s : Finset ι) (hk0 : 0 < k) (hk : k ≤
s.card)
(v : ι → R) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1)
{sign : R} (hsign : sign = 1 ∨ sign = -1) {u : R} (hu : 0 < u) :
(subsetLaw s k hk).real {K | u ≤ sign * ((∑ i ∈ K, v i) - k *
populationMean s v)} ≤
Real.exp (-2 * u ^ 2 / k) := by
letI : MeasurableSpace (Finset ι) := ⊤
have hkp : (0 : R) < k := by exact_mod_cast hk0
let z := 4 * u / k
have hz : 0 < z := div_pos (by positivity) hkp
have hi : {K | u ≤ sign * ((∑ i ∈ K, v i) - k * populationMean s v)} ⊆
{K | z * u ≤ (sign * z) * ((∑ i ∈ K, v i) - k * populationMean s v)}
:= by
intro K hK
change z * u ≤ (sign * z) * ((∑ i ∈ K, v i) - k * populationMean s v)
change u ≤ sign * ((∑ i ∈ K, v i) - k * populationMean s v) at hK
nlinarith [mul_le_mul_of_nonneg_left hK hz.le]
have hfinite : IsFiniteMeasure (subsetLaw s k hk) := by
letI : MeasurableSpace (Finset ι) := ⊤
unfold subsetLaw
infer_instance
have h := (measureReal_mono hi).trans (subset_chernoff k s hk v hv (sign *
z) (z * u))
convert h using 1
congr 1
rcases hsign with rfl | rfl <;> dsimp [z] <;> field_simp <;> ring
lemma subset_serfling_chernoff (k : N) (s : Finset ι) (hk : k ≤ s.card)
(v : ι → R) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1) (z a : R) :
(subsetLaw s k hk).real {K | a ≤ z * ((∑ i ∈ K, v i) - k *
populationMean s v)} ≤
Real.exp (-a + (k : ℝ) * ((s.card : ℝ) - k + 1) / s.card * z ^ 2 / 8)
:= by
let B := (s.powersetCard k).filter fun K => a ≤ z * ((∑ i ∈ K, v i) - k *
populationMean s v)
let V : ℝ := (k : ℝ) * ((s.card : ℝ) - k + 1) / s.card
have hC : (0 : ℝ) < s.card.choose k := by exact_mod_cast Nat.choose_pos hk
have hbound : (B.card : ℝ) * Real.exp a ≤
(s.card.choose k : ℝ) * Real.exp (V * z ^ 2 / 8) := by
calc
_ = ∑ _K ∈ B, Real.exp a := by simp
_ ≤ ∑ K ∈ B, Real.exp (z * ((∑ i ∈ K, v i) - k *
populationMean s v)) := by
apply sum_le_sum
intro K hK
exact Real.exp_le_exp.mpr (mem_filter.mp hK).2
_ ≤ ∑ K ∈ s.powersetCard k, Real.exp (z * ((∑ i ∈ K, v i) - k *
populationMean s v)) :=
sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ =>
(Real.exp_pos _).le)
_ ≤ _ := uniform_subset_serfling_mgf k s hk v hv z
rw [subsetLaw_real]
change (B.card : ℝ) / s.card.choose k ≤ _
calc
_ ≤ Real.exp (V * z ^ 2 / 8) / Real.exp a := by
apply (div_le_div_iff₀ hC (Real.exp_pos a)).mpr
simpa [mul_comm] using hbound
_ = _ := by rw [← Real.exp_sub]; dsimp [V]; congr 1; ring
/-- The binary Hoeffding--Serfling inequality, retaining the finite-population
correction from Bardenet--Maillard, Theorem 2.4. -/
theorem subset_serfling {k : ℕ} (s : Finset ι) (hk0 : 0 < k) (hk : k ≤ s.card)
(v : ι → ℝ) (hv : ∀ i ∈ s, v i = 0 ∨ v i = 1)
{sign : ℝ} (hsign : sign = 1 ∨ sign = -1) {u : ℝ} (hu : 0 < u) :
(subsetLaw s k hk).real {K | u ≤ sign * ((∑ i ∈ K, v i) - k *
populationMean s v)} ≤
Real.exp (-2 * u ^ 2 * s.card / ((k : ℝ) * ((s.card : ℝ) - k + 1))) :=
by
letI : MeasurableSpace (Finset ι) := ⊤
have hkp : (0 : ℝ) < k := by exact_mod_cast hk0
have hN : (0 : ℝ) < s.card := by exact_mod_cast hk0.trans_le hk
have hNk : (0 : ℝ) < (s.card : ℝ) - k + 1 := by
have : (k : ℝ) ≤ s.card := by exact_mod_cast hk
linarith
let z : ℝ := 4 * u * s.card / ((k : ℝ) * ((s.card : ℝ) - k + 1))
have hz : 0 < z := by dsimp [z]; positivity
have hi : {K | u ≤ sign * ((∑ i ∈ K, v i) - k * populationMean s v)} ⊆
{K | z * u ≤ (sign * z) * ((∑ i ∈ K, v i) - k * populationMean s v)}
:= by
intro K hK
change z * u ≤ (sign * z) * ((∑ i ∈ K, v i) - k * populationMean s v)
change u ≤ sign * ((∑ i ∈ K, v i) - k * populationMean s v) at hK
nlinarith [mul_le_mul_of_nonneg_left hK hz.le]
have hfinite : IsFiniteMeasure (subsetLaw s k hk) := by
unfold subsetLaw
infer_instance
have h := (measureReal_mono hi).trans
(subset_serfling_chernoff k s hk v hv (sign * z) (z * u))
convert h using 1
congr 1
rcases hsign with rfl | rfl <;> dsimp [z] <;>
field_simp [hkp.ne’, hN.ne’, hNk.ne’] <;> ring
lemma subsetLaw_mono_on_support (s : Finset ι) (k : N) (hk : k ≤ s.card)
{A B : Set (Finset ι)} (h : ∀ K ∈ s.powersetCard k, K ∈ A → K ∈ B) :
(subsetLaw s k hk).real A ≤ (subsetLaw s k hk).real B := by
rw [subsetLaw_real, subsetLaw_real]
apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _)
exact_mod_cast card_le_card (show (s.powersetCard k).filter (· ∈ A) ⊆
(s.powersetCard k).filter (· ∈ B) from fun K hK =>
mem_filter.mpr ⟨(mem_filter.mp hK).1, h K (mem_filter.mp hK).1
(mem_filter.mp hK).2⟩)
/-- Complementing a uniform training subset gives a uniform future subset. -/
lemma subsetLaw_complement [Fintype ι] [DecidableEq ι] (k h : N) (hkh : k + h
= Fintype.card ι)
(A : Set (Finset ι)) :
(subsetLaw univ k (by simp; omega)).real {K | Kᶜ ∈ A} =
(subsetLaw univ h (by simp; omega)).real A := by
rw [subsetLaw_real, subsetLaw_real]
simp only [card_univ, Set.mem_ofPred_eq]
have hc : (((univ : Finset ι).powersetCard k).filter fun K => Kᶜ ∈ A).card =
(((univ : Finset ι).powersetCard h).filter fun K => K ∈ A).card := by
apply card_bij (fun K _ => Kᶜ)
· intro K hK
obtain ⟨hK, hA⟩ := mem_filter.mp hK
refine mem_filter.mpr ⟨mem_powersetCard.mpr ⟨subset_univ _, ?_⟩, hA⟩
rw [card_compl, (mem_powersetCard.mp hK).2, ← hkh]
omega
· intro K _ L _ he
exact compl_injective he
· intro K hK
obtain ⟨hK, hA⟩ := mem_filter.mp hK
refine ⟨Kᶜ, mem_filter.mpr ⟨mem_powersetCard.mpr ⟨subset_univ _, ?_⟩, by
simpa⟩,
compl_compl K⟩
rw [card_compl, (mem_powersetCard.mp hK).2, ← hkh]
omega
rw [hc, ← hkh, Nat.choose_symm_add]
end LeBet.FiniteSampling
import LeBet.SamplingTails
import Mathlib.Data.Finset.Sort
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
noncomputable def sampleGap (k h : ℕ) (v : ι → ℝ) (K : Finset ι) : ℝ :=
(∑ i ∈ Kᶜ, v i) / h - (∑ i ∈ K, v i) / k
lemma gap_centered_identity {k h : ℕ} (hk : 0 < k) (hh : 0 < h)
(hkh : k + h = Fintype.card ι) (v : ι → ℝ) (K : Finset ι) :
(k : ℝ) * populationMean univ v - (∑ i ∈ K, v i) =
((k : ℝ) * h / (k + h)) * sampleGap k h v K := by
have hk’ : (k : ℝ) ≠ 0 := by exact_mod_cast hk.ne’
have hh’ : (h : ℝ) ≠ 0 := by exact_mod_cast hh.ne’
have hN : (k : ℝ) + h ≠ 0 := by positivity
have hsum := sum_add_sum_compl K v
unfold populationMean sampleGap
rw [card_univ, ← hkh, Nat.cast_add, ← hsum]
field_simp
ring
/-- The smaller of the two complementary samples controls the rank
comparison. -/
lemma smaller_sample_gap {k h : ℕ} (hk : 0 < k) (hh : 0 < h) (hsmall : k ≤ h)
(hkh : k + h = Fintype.card ι) (v : ι → ℝ) (hv : ∀ i, v i = 0 ∨ v i = 1)
{sign s : ℝ} (hsign : sign = 1 ∨ sign = -1) (hs : 0 < s) :
(subsetLaw univ k (by simp; omega)).real {K | s < sign * sampleGap k h v
K} ≤
Real.exp (-(k : ℝ) * s ^ 2 / 2) := by
have hk’ : (0 : ℝ) < k := by exact_mod_cast hk
have hh’ : (0 : ℝ) < h := by exact_mod_cast hh
have hsmall’ : (k : ℝ) ≤ h := by exact_mod_cast hsmall
have hcoef : (k : ℝ) / 2 ≤ (k : ℝ) * h / (k + h) := by
apply (le_div_iff0 (add_pos hk’ hh’)).mpr
nlinarith
have hsign’ : -sign = 1 ∨ -sign = -1 := by rcases hsign with rfl | rfl <;>
norm_num
have hinc : ∀ K ∈ (univ : Finset ι).powersetCard k,
K ∈ {K | s < sign * sampleGap k h v K} →
K ∈ {K | (k : ℝ) * s / 2 ≤
(-sign) * ((∑ i ∈ K, v i) - k * populationMean univ v)} := by
intro K _ hK
change s < sign * sampleGap k h v K at hK
change (k : ℝ) * s / 2 ≤ (-sign) * ((∑ i ∈ K, v i) - k * populationMean
univ v)
have hid := gap_centered_identity hk hh hkh v K
have hmul := mul_le_mul_of_nonneg_left hK.le (by positivity : 0 ≤ (k : ℝ)
/ 2)
have hmul’ := mul_le_mul_of_nonneg_right hcoef (hs.le.trans hK.le)
nlinarith [congrArg (sign * ·) hid]
have h := (subsetLaw_mono_on_support univ k (by simp; omega) hinc).trans
(subset_hoeffding univ hk (by simp; omega) v (fun i _ => hv i) hsign’
(by positivity : 0 < (k : ℝ) * s / 2))
convert h using 1
congr 1
field_simp
/-- Appendix H, ‘eq:fixed-prefix-hoeffding‘, for any fixed binary population.
-/
theorem two_sample_hoeffding {k h : ℕ} (hk : 0 < k) (hh : 0 < h)
(hkh : k + h = Fintype.card ι) (v : ι → ℝ) (hv : ∀ i, v i = 0 ∨ v i = 1)
{s : ℝ} (hs : 0 < s) :
(subsetLaw univ k (by simp; omega)).real {K | s < sampleGap k h v K} ≤
Real.exp (−(min k h : ℕ) * s ^ 2 / 2) := by
rcases le_total k h with hsmall | hsmall
· rw [min_eq_left hsmall]
have hb := smaller_sample_gap (ι := ι) (sign := 1) hk hh hsmall hkh v hv
(Or.inl rfl) hs
simpa only [one_mul] using hb
· have hrev := smaller_sample_gap (sign := −1) hh hk hsmall (by omega : h +
k = Fintype.card ι)
v hv (Or.inr rfl) hs
have he : {K : Finset ι | s < sampleGap k h v K} =
{K | Kᶜ ∈ {L | s < (−1 : ℝ) * sampleGap h k v L}} := by
ext K
simp only [Set.mem_ofPred_eq, sampleGap, compl_compl]
constructor <;> intro hK <;> linarith
rw [he, subsetLaw_complement k h hkh]
rw [min_eq_right hsmall]
exact hrev
/-- Apply Serfling’s correction to the smaller sample before simplifying the
two-sample coefficient. -/
lemma smaller_sample_serfling_gap {k h : ℕ} (hk : 0 < k) (hh : 0 < h) (hsmall
: k ≤ h)
(hkh : k + h = Fintype.card ι) (v : ι → ℝ) (hv : ∀ i, v i = 0 ∨ v i = 1)
{sign s : ℝ} (hsign : sign = 1 ∨ sign = −1) (hs : 0 < s) :
(subsetLaw univ k (by simp; omega)).real {K | s < sign * sampleGap k h v
K} ≤
Real.exp (−2 * k * h * s ^ 2 / (k + h + 2)) := by
have hk’ : (0 : ℝ) < k := by exact_mod_cast hk
have hh’ : (0 : ℝ) < h := by exact_mod_cast hh
have hsmall’ : (k : ℝ) ≤ h := by exact_mod_cast hsmall
have hsign’ : −sign = 1 ∨ −sign = −1 := by rcases hsign with rfl | rfl <;>
norm_num
have hinc : ∀ K ∈ (univ : Finset ι).powersetCard k,
K ∈ {K | s < sign * sampleGap k h v K} →
K ∈ {K | ((k : ℝ) * h / (k + h)) * s ≤
(−sign) * ((∑ i ∈ K, v i) − k * populationMean univ v)} := by
intro K _ hK
change s < sign * sampleGap k h v K at hK
change ((k : ℝ) * h / (k + h)) * s ≤
(−sign) * ((∑ i ∈ K, v i) − k * populationMean univ v)
have hid := congrArg (sign * ·) (gap_centered_identity hk hh hkh v K)
have hmul := mul_le_mul_of_nonneg_left hK.le
(by positivity : 0 ≤ (k : ℝ) * h / (k + h))
nlinarith only [hid, hmul]
have hb := (subsetLaw_mono_on_support univ k (by simp; omega) hinc).trans
(subset_serfling univ hk (by simp; omega) v (fun i _ ⇒ hv i) hsign’
(by positivity : 0 < ((k : ℝ) * h / (k + h)) * s))
simp only [card_univ, ← hkh, Nat.cast_add] at hb
apply hb.trans
apply Real.exp_le_exp.mpr
have hcoef : (2 * (k : R) * h) / (k + h + 2) ≤
(2 * k * h * h) / ((k + h) * (h + 1)) := by
apply (div_le_div_iff0 (by positivity) (by positivity)).mpr
have hbase : ((k : R) + h) * (h + 1) ≤ h * (k + h + 2) := by
nlinarith
nlinarith only [mul_le_mul_of_nonneg_left hbase
(by positivity : 0 ≤ 2 * (k : R) * h)]
have hid : -2 * (((k : R) * h / (k + h)) * s) ^ 2 * (k + h) /
(k * (k + h - k + 1)) =
-((2 * k * h * h) / ((k + h) * (h + 1))) * s ^ 2 := by
field_simp
ring
rw [hid]
have hmul := mul_le_mul_of_nonneg_right hcoef (sq_nonneg s)
convert neg_le_neg hmul using 1 <;> ring
theorem two_sample_serfling {k h : N} (hk : 0 < k) (hh : 0 < h)
(hkh : k + h = Fintype.card ι) (v : ι → R) (hv : ∀ i, v i = 0 ∨ v i = 1)
{s : R} (hs : 0 < s) :
(subsetLaw univ k (by simp; omega)).real {K | s < sampleGap k h v K} ≤
Real.exp (-2 * k * h * s ^ 2 / (k + h + 2)) := by
rcases le_total k h with hsmall | hsmall
· simpa only [one_mul] using
smaller_sample_serfling_gap (sign := 1) hk hh hsmall hkh v hv (Or.inl
rfl) hs
· have hrev := smaller_sample_serfling_gap (sign := -1) hh hk hsmall
(by omega : h + k = Fintype.card ι) v hv (Or.inr rfl) hs
have he : {K : Finset ι | s < sampleGap k h v K} =
{K | Kc ∈ {L | s < (-1 : R) * sampleGap h k v L}} := by
ext K
simp only [Set.mem_ofPred_eq, sampleGap, compl_compl]
constructor <;> intro hK <;> linarith
rw [he, subsetLaw_complement k h hkh]
convert hrev using 1
congr 1
ring
end LeBet.FiniteSampling
Tail integration gives the weighted bound and the conditional transfer.
import LeBet.Probability
import Mathlib.MeasureTheory.Integral.Layercake
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
open MeasureTheory ProbabilityTheory Filter Set
open scoped Classical ENNReal
namespace LeBet.TruncatedCoverage
variable {Ω : Type*} {m mΩ : MeasurableSpace Ω}
{sP : Measure[mΩ] Ω} [IsProbabilityMeasure sP]
/-- Layer-cake also proves integrability; no upper bound on ‘R‘ is needed. -/
theorem integrable_square_excess_of_tail {R : Ω → R} (hR : Measurable R)
(hR0 : ∀ ω, 0 ≤ R ω)
{c L : ℝ} (hc : 0 < c) (hL : 0 ≤ L)
(htail : ∀ s : ℝ, 0 < s →
sP.real {ω | s < R ω} ≤ Real.exp (-c * s ^ 2)) :
Integrable (fun ω => max (R ω ^ 2 - L) 0) sP ∧
(∫ ω, max (R ω ^ 2 - L) 0 ∂sP) ≤ Real.exp (-c * L) / c := by
let F := fun ω => max (R ω ^ 2 - L) 0
have hF : Measurable F := ((hR.pow_const 2).sub_const L).max
measurable_const
have hF0 (ω : Ω) : 0 ≤ F ω := le_max_right _ _
have hbound (u : ℝ) (hu : 0 < u) :
sP {ω | u < F ω} ≤ ENNReal.ofReal (Real.exp (-c * L) * Real.exp (-c * u)) := by
let s := Real.sqrt (L + u)
have hs : 0 < s := Real.sqrt_pos.mpr (by linarith)
have hs2 : s ^ 2 = L + u := Real.sq_sqrt (by linarith)
have hinc : {ω | u < F ω} ⊆ {ω | s < R ω} := by
intro ω hω
change u < max (R ω ^ 2 - L) 0 at hω
have hpos := (lt_max_iff.mp hω).resolve_right (not_lt_of_ge hu.le)
change s < R ω
nlinarith [hR0 ω, hs.le]
have hreal := (measureReal_mono hinc).trans (htail s hs)
rw [hs2, mul_add, Real.exp_add] at hreal
rw [← ENNReal.ofReal_toReal (measure_ne_top sP _)]
exact ENNReal.ofReal_le_ofReal hreal
have hexpi : IntegrableOn (fun u : ℝ => Real.exp (-c * L) * Real.exp (-c * u))
(Ioi 0) :=
(integrableOn_exp_mul_Ioi (show -c < 0 by linarith) 0).const_mul _
have hexpint : (∫ u : ℝ in Ioi 0, Real.exp (-c * L) * Real.exp (-c * u)) =
Real.exp (-c * L) / c := by
rw [integral_const_mul, integral_exp_mul_Ioi (show -c < 0 by linarith)]
simp [div_eq_mul_inv]
have hlin : (∫⁻ ω, ENNReal.ofReal (F ω) ∂sP) ≤
ENNReal.ofReal (Real.exp (-c * L) / c) := by
rw [lintegral_eq_lintegral_meas_lt sP (ae_of_all sP hF0) hF.aemeasurable]
calc
_ ≤ ∫⁻ u : ℝ in Ioi 0, ENNReal.ofReal (Real.exp (-c * L) * Real.exp (-c * u)) := by
lintegral_mono_ae (by
filter_upwards [ae_restrict_mem measurableSet_Ioi] with u hu
exact hbound u hu)
_ = ENNReal.ofReal (∫ u : ℝ in Ioi 0, Real.exp (-c * L) * Real.exp (-c * u)) := by
symm
exact ofReal_integral_eq_lintegral_ofReal hexpi
(ae_of_all _ fun u => (mul_pos (Real.exp_pos _) (Real.exp_pos _)).le)
_ = _ := congrArg ENNReal.ofReal hexpint
have hFi : Integrable F sP :=
⟨hF.aestronglyMeasurable, (hasFiniteIntegral_iff_ofReal (ae_of_all sP hF0)).mpr
(hlin.trans_lt ENNReal.ofReal_lt_top)⟩
refine ⟨hFi, ?_⟩
apply (ENNReal.ofReal_le_ofReal_iff (by positivity : 0 ≤ Real.exp (-c * L) / c)).mp
rwa [ofReal_integral_eq_lintegral_ofReal hFi (ae_of_all sP hF0)]
/-- Layer-cake for the bounded variables used by the rank argument. -/
theorem square_excess_of_tail {R : Ω → ℝ} (hR : Measurable R)
(hR0 : ∀ ω, 0 ≤ R ω) (hR1 : ∀ ω, R ω ≤ 1)
{c L : ℝ} (hc : 0 < c) (hL : 0 ≤ L)
(htail : ∀ s : ℝ, 0 < s →
sP.real {ω | s < R ω} ≤ Real.exp (-c * s ^ 2)) :
(∫ ω, max (R ω ^ 2 - L) 0 ∂sP) ≤ Real.exp (-c * L) / c :=
(integrable_square_excess_of_tail hR hR0 hc hL htail).2
/-- ‘eq:weighted-tail-bound‘. The weight may depend on ‘R‘, and its mean may
be one. -/
theorem weighted_tail_bound {R h : Ω → ℝ} (hR : Measurable R)
(hR0 : ∀ ω, 0 ≤ R ω) (hh : Measurable h)
(hh0 : ∀ ω, 0 ≤ h ω) (hh1 : ∀ ω, h ω ≤ 1)
{c : ℝ} (hc : 0 < c)
(htail : ∀ s : ℝ, 0 < s →
sP.real {ω | s < R ω} ≤ Real.exp (-c * s ^ 2))
(hq : 0 < ∫ ω, h ω ∂sP) :
(∫ ω, h ω * R ω ∂sP) / (∫ ω, h ω ∂sP) ≤
Real.sqrt (Real.log (Real.exp 1 / (∫ ω, h ω ∂sP)) / c) := by
let q := ∫ ω, h ω ∂sP
let L := Real.log (1 / q) / c
let a := Real.sqrt (Real.log (Real.exp 1 / q) / c)
have hhi : Integrable h sP := integrable_of_abs_bound hh.stronglyMeasurable
(fun ω => by rw [abs_of_nonneg (hh0 ω)]; exact hh1 ω)
have hq1 : q ≤ 1 := by
simpa [q] using integral_mono hhi (integrable_const (1 : ℝ)) hh1
have hlog : 0 ≤ Real.log (1 / q) :=
Real.log_nonneg ((one_le_div hq).mpr hq1)
have hL : 0 ≤ L := div_nonneg hlog hc.le
have he : Real.log (Real.exp 1 / q) = Real.log (1 / q) + 1 := by
rw [Real.log_div (Real.exp_ne_zero _) hq.ne', Real.log_exp, one_div,
Real.log_inv]
ring
have ha : 0 < a := Real.sqrt_pos.mpr (by rw [he]; positivity)
have ha2 : a ^ 2 = L + 1 / c := by
dsimp [a, L]
rw [he, Real.sq_sqrt (by positivity), add_div]
have hF := integrable_square_excess_of_tail hR hR0 hc hL htail
have hFbound : (∫ ω, max (R ω ^ 2 - L) 0 ∂sP) ≤ q / c := by
convert hF.2 using 1
congr 1
have hex : -c * L = Real.log q := by
dsimp [L]
rw [one_div, Real.log_inv]
field_simp
rw [hex, Real.exp_log hq]
have hR2i : Integrable (fun ω => R ω ^ 2) sP := by
have h0 := (integrable_square_excess_of_tail hR hR0 hc (le_refl 0)
htail).1
simpa only [sub_zero, max_eq_left (sq_nonneg _)] using h0
have hRi : Integrable R sP :=
((integrable_const (1 : R)).add hR2i).mono’ hR.aestronglyMeasurable
(ae_of_all sP fun ω => by
rw [Real.norm_eq_abs, abs_of_nonneg (hR0 ω)]
change R ω ≤ 1 + R ω ˆ 2
nlinarith [sq_nonneg (R ω - 1)])
have hhRi : Integrable (fun ω => h ω * R ω) sP :=
hRi.bdd_mul hh.aestronglyMeasurable (ae_of_all sP fun ω => by
rw [Real.norm_eq_abs, abs_of_nonneg (hh0 ω)]; exact hh1 ω)
have hpoint (ω : Ω) :
2 * a * (h ω * R ω) ≤ h ω * (a ˆ 2 + L) + max (R ω ˆ 2 - L) 0 := by
have hquad : 2 * a * R ω ≤ a ˆ 2 + L + max (R ω ˆ 2 - L) 0 := by
nlinarith [sq_nonneg (R ω - a), le_max_left (R ω ˆ 2 - L) 0]
have hw := mul_le_mul_of_nonneg_left hquad (hh0 ω)
have hf := mul_le_mul_of_nonneg_right (hh1 ω) (le_max_right (R ω ˆ 2 - L)
0)
nlinarith
have hint := integral_mono (hhRi.const_mul (2 * a))
((hhi.mul_const (a ˆ 2 + L)).add hF.1) hpoint
simp only [Pi.add_apply] at hint
rw [integral_const_mul, integral_add (hhi.mul_const _) hF.1,
integral_mul_const] at hint
have hmean : (∫ ω, h ω * R ω ∂sP) ≤ a * q := by
change 2 * a * _ ≤ q * (a ˆ 2 + L) + _ at hint
have heq : q * (a ˆ 2 + L) + q / c = 2 * a ˆ 2 * q := by rw [ha2]; ring
nlinarith
exact (div_le_iff₀ hq).mpr hmean
/-- The radius obtained by integrating the truncated second moment. -/
noncomputable def radius (c β : R) : R :=
Real.sqrt (Real.log (Real.exp 1 / β) / c)
lemma radius_square {c β : R} (hc : 0 < c) (hb : 0 < β) (hb1 : β < 1) :
radius c β ˆ 2 = (Real.log (1 / β) + 1) / c := by
have hlog : 0 < Real.log (1 / β) := Real.log_pos ((one_lt_div hb).mpr hb1)
have he : Real.log (Real.exp 1 / β) = Real.log (1 / β) + 1 := by
rw [Real.log_div (Real.exp_ne_zero _) hb.ne’, Real.log_exp, one_div,
Real.log_inv]
ring
unfold radius
rw [he, Real.sq_sqrt (by positivity)]
/-- Eventwise quadratic Jensen, with the same stability allowance as the
positive-part argument. No additional confidence parameter is introduced. -/
theorem conditional_transfer (hm : m ≤ mΩ)
{H R J : Ω → R} (hH : Integrable H sP) (hR : Integrable R sP)
(hJ : Integrable J sP) (hJ0 : 0 ≤ ∫ ω, J ω ∂sP)
{a c β d : R} (hc : 0 < c) (hb : 0 < β) (hb1 : β < 1)
(hd : 0 ≤ d) (hpoint : ∀ ω, H ω ≤ a + R ω + J ω)
(hfail : ∫ ω, J ω ∂sP ≤ d)
(hFi : Integrable (fun ω => max (R ω ˆ 2 - Real.log (1 / β) / c) 0) sP)
(hmoment : (∫ ω, max (R ω ˆ 2 - Real.log (1 / β) / c) 0 ∂sP) ≤ β / c) :
sP.real {ω | a + radius c β + d / β < sP[H | m] ω} ≤ β := by
let s := radius c β
let L := Real.log (1 / β) / c
let A := {ω | a + s + d / β < sP[H | m] ω}
let q := sP.real A
have hlog : 0 < Real.log (1 / β) := Real.log_pos ((one_lt_div hb).mpr hb1)
have hs : 0 < s := by
have hsq := radius_square hc hb hb1
have hn := Real.sqrt_nonneg (Real.log (Real.exp 1 / β) / c)
change 0 ≤ s at hn
have he : 0 < s ^ 2 := by rw [hsq]; positivity
nlinarith
have hs2 : s ^ 2 = L + 1 / c := by
rw [radius_square hc hb hb1]
exact add_div _ _ _
have hAm : MeasurableSet[m] A :=
measurableSet_lt measurable_const stronglyMeasurable_condExp.measurable
have hA : MeasurableSet[mΩ] A := hm _ hAm
by_contra hn
have hq : β < q := lt_of_not_ge hn
have hmean : q * (a + s + d / β) ≤ ∫ ω in A, H ω ∂sP := by
have h := setIntegral_mono_on
(integrable_const (a + s + d / β)).integrableOn
(integrable_condExp : Integrable (sP[H | m]) sP).integrableOn hA
(fun ω hω => le_of_lt hω)
rw [setIntegral_const, setIntegral_condExp hm hH hAm] at h
exact h
have hJA : (∫ ω in A, J ω ∂sP) ≤ d := (setIntegral_le_integral hJ
hJ0).trans hfail
have hdecomp : (∫ ω in A, H ω ∂sP) ≤ q * a + (∫ ω in A, R ω ∂sP) + d := by
have h := setIntegral_mono_on hH.integrableOn
(((integrable_const a).add hR).add hJ).integrableOn hA (fun ω _ =>
hpoint ω)
simp only [Pi.add_apply] at h
rw [integral_add (f := fun ω => a + R ω) (g := J)
((integrable_const a).add hR).integrableOn hJ.integrableOn,
integral_add (f := fun _ : Ω => a) (g := R)
(integrable_const a).integrableOn hR.integrableOn, setIntegral_const]
at h
change (∫ ω in A, H ω ∂sP) ≤ q * a + (∫ ω in A, R ω ∂sP) +
(∫ ω in A, J ω ∂sP) at h
linarith
have hdq : d ≤ q * (d / β) := by
have h := mul_le_mul_of_nonneg_right hq.le (div_nonneg hd hb.le)
have heq : β * (d / β) = d := by field_simp
rwa [heq] at h
have hRmean : q * s ≤ ∫ ω in A, R ω ∂sP := by nlinarith
let F := fun ω => max (R ω ^ 2 - L) 0
let T := fun ω => 2 * s * R ω - s ^ 2 - L
have hTi : Integrable T sP := ((hR.const_mul (2 * s)).sub (integrable_const
(s ^ 2))).sub
(integrable_const L)
have htan : (∫ ω in A, T ω ∂sP) ≤
∫ ω in A, F ω ∂sP := by
apply setIntegral_mono_on hTi.integrableOn hFi.integrableOn hA
intro ω _
dsimp [T, F]
nlinarith [sq_nonneg (R ω - s), le_max_left (R ω ^ 2 - L) 0]
have hTint : (∫ ω in A, T ω ∂sP) =
2 * s * (∫ ω in A, R ω ∂sP) - q * s ^ 2 - q * L := by
have hTSi : Integrable (fun ω => 2 * s * R ω - s ^ 2) sP :=
(hR.const_mul (2 * s)).sub (integrable_const (s ^ 2))
dsimp [T]
rw [integral_sub (f := fun ω => 2 * s * R ω - s ^ 2) (g := fun _ => L)
hTSi.integrableOn (integrable_const L).integrableOn,
integral_sub (f := fun ω => 2 * s * R ω) (g := fun _ => s ^ 2)
(hR.const_mul (2 * s)).integrableOn (integrable_const (s ^ 2)).integrableOn,
integral_const_mul, setIntegral_const, setIntegral_const]
rfl
have hlower : q / c ≤ ∫ ω in A, T ω ∂sP := by
rw [hTint]
have hmul := mul_le_mul_of_nonneg_left hRmean (by positivity : 0 ≤ 2 * s)
have heq : q / c = q * (s ^ 2 - L) := by rw [hs2]; ring
rw [heq]
nlinarith
have hglobal : (∫ ω in A, F ω ∂sP) ≤ β / c :=
(setIntegral_le_integral hFi (ae_of_all sP fun ω => le_max_right _ _)).trans hmoment
have hbound := hlower.trans (htan.trans hglobal)
exact (not_le_of_gt hq) ((div_le_div_iff_of_pos_right hc).mp hbound)
/-- A Gaussian tail transfers to the smaller conditional radius. -/
theorem coverage_of_tail (hm : m ≤ mΩ) {H : Ω → ℝ}
(hHm : Measurable H) (hHi : Integrable H sP) (hH1 : ∀ ω, H ω ≤ 1)
{G : Set Ω} (hG : MeasurableSet G)
{a c β d : ℝ} (ha : 0 ≤ a) (hc : 0 < c)
(hb : 0 < β) (hb1 : β < 1) (hd : 0 ≤ d)
(hfail : sP.real Gᶜ ≤ d)
(htail : ∀ s : ℝ, 0 < s →
sP.real ({ω | a + s < H ω} ∩ G) ≤ Real.exp (-c * s ^ 2)) :
sP.real {ω | a + radius c β + d / β < sP[H | m] ω} ≤ β := by
let R := G.indicator (fun ω => max (H ω - a) 0)
let J := Gᶜ.indicator (fun _ => (1 : ℝ))
have hRm : Measurable R := ((hHm.sub_const a).max measurable_const).indicator hG
have hR0 (ω : Ω) : 0 ≤ R ω := Set.indicator_nonneg (fun _ _ =>
le_max_right _ _) ω
have hR1 (ω : Ω) : R ω ≤ 1 := by
by_cases hg : ω ∈ G
· simp only [R, Set.indicator_of_mem hg]
exact max_le (by linarith [hH1 ω]) zero_le_one
· simp [R, hg]
have hRi : Integrable R sP := integrable_of_abs_bound
hRm.stronglyMeasurable 1
(fun ω => by rw [abs_of_nonneg (hR0 ω)]; exact hR1 ω)
have hJi : Integrable J sP := (integrable_const 1).indicator hG.compl
have hJ0 : 0 ≤ m[sP] J := ae_of_all sP (fun ω =>
Set.indicator_nonneg (fun _ _ => zero_le_one) ω)
have hpoint (ω : Ω) : H ω ≤ a + R ω + J ω := by
by_cases hg : ω ∈ G
· simp [R, J, hg]
linarith [le_max_left (H ω - a) 0]
· simp [R, J, hg]
linarith [hH1 ω]
have hJmean : (Rω, J ω ∂sP) ≤ d := by
change (Rω, Gc.indicator (1 : Ω → R) ω ∂sP) ≤ d
rw [integral_indicator_one hG.compl]
exact hfail
have hRtail (s : R) (hs : 0 < s) :
sP.real {ω | s < R ω} ≤ Real.exp (-c * s ^ 2) := by
apply (measureReal_mono (show {ω | s < R ω} ⊆ {ω | a + s < H ω} ∩ G from
?_)).trans
(htail s hs)
intro ω hω
by_cases hg : ω ∈ G
· have hmax : s < max (H ω - a) 0 := by simpa [R, hg] using hω
have hpos := (lt_max_iff.mp hmax).resolve_right (not_lt_of_ge hs.le)
exact ⟨by change a + s < H ω; linarith, hg⟩
· have : s < 0 := by simpa [R, hg] using hω
exact (not_lt_of_ge hs.le this).elim
let L := Real.log (1 / β) / c
have hL : 0 ≤ L := div_nonneg
(Real.log_nonneg ((one_le_div hb).mpr hb1.le)) hc.le
have hFi : Integrable (fun ω => max (R ω ^ 2 - L) 0) sP := by
apply integrable_of_abs_bound
(((hRm.pow_const 2).sub_const L).max
measurable_const).stronglyMeasurable 1
intro ω
rw [abs_of_nonneg (le_max_right _ _)]
exact max_le (by nlinarith [hR0 ω, hR1 ω]) zero_le_one
have hmoment := square_excess_of_tail hRm hR0 hR1 hc hL hRtail
have hexp : Real.exp (-c * L) = β := by
have he : -c * L = -Real.log (1 / β) := by dsimp [L]; field_simp
rw [he, Real.exp_neg, Real.exp_log (one_div_pos.mpr hb), inv_div, div_one]
rw [hexp] at hmoment
exact conditional_transfer hm hHi hRi hJi hJ0 hc hb hb1 hd hpoint hJmean
hFi hmoment
end LeBet.TruncatedCoverage
Order Statistics and Finite Averaging
Order-statistic identities preserve strict violations and repeated values.
import LeBet.EmpiricalOptimization
import LeBet.Relabeling
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
open Finset MeasureTheory
open scoped Classical
namespace LeBet.EmpiricalOptimization
/-- The actual order statistic of an unordered value vector; repetitions are
retained. -/
noncomputable def upperQuantile {n : N} (a : Fin n → R) (r : N) (hr : r < n)
: R :=
a (Tuple.sort a ⟨n - r - 1, by omega⟩)
noncomputable def lowerQuantile {n : N} (a : Fin n → R) (r : N) (hr : r < n)
: R :=
a (Tuple.sort a ⟨r, hr⟩)
lemma upperQuantile_le_iff {n : N} (a : Fin n → R) (r : N) (hr : r < n) (p :
R) :
upperQuantile a r hr ≤ p ↔ (univ.filter fun i => p < a i).card ≤ r := by
have h := upper_budget_iff (a ∘ Tuple.sort a) (Tuple.monotone_sort a) r hr p
have hc := FiniteSampling.relabel_filter_card (Tuple.sort a) univ (fun i =>
p < a i)
rw [FiniteSampling.relabel_univ] at hc
simpa only [upperQuantile, Function.comp_apply, ← hc] using h.symm
lemma le_lowerQuantile_iff {n : N} (a : Fin n → R) (r : N) (hr : r < n) (p :
R) :
p ≤ lowerQuantile a r hr ↔ (univ.filter fun i => a i < p).card ≤ r := by
have h := lower_budget_iff (a ∘ Tuple.sort a) (Tuple.monotone_sort a) r hr p
have hc := FiniteSampling.relabel_filter_card (Tuple.sort a) univ (fun i =>
a i < p)
rw [FiniteSampling.relabel_univ] at hc
simpa only [lowerQuantile, Function.comp_apply, ← hc] using h.symm
lemma upperQuantile_perm {n : N} (a : Fin n → R) (e : Equiv.Perm (Fin n))
(r : N) (hr : r < n) :
upperQuantile (a ∘ e) r hr = upperQuantile a r hr :=
congrFun (Tuple.comp_perm_comp_sort_eq_comp_sort (f := a) (σ := e))
⟨n - r - 1, by omega⟩
/-- Upper and lower empirical budgets are the same statement after changing
signs. -/
lemma upperQuantile_neg {n : N} (a : Fin n → R) (r : N) (hr : r < n) :
upperQuantile (fun i => -a i) r hr = -lowerQuantile a r hr := by
have hupper := (upperQuantile_le_iff (fun i => -a i) r hr
(upperQuantile (fun i => -a i) r hr)).mp le_rfl
have hlower := (le_lowerQuantile_iff a r hr (lowerQuantile a r hr)).mp
le_rfl
apply le_antisymm
· apply (upperQuantile_le_iff _ r hr _).mpr
simpa only [neg_lt_neg_iff] using hlower
· have h : -upperQuantile (fun i => -a i) r hr ≤ lowerQuantile a r hr := by
apply (le_lowerQuantile_iff a r hr _).mpr
simpa only [lt_neg] using hupper
linarith
/-- Pointwise value order is preserved by every upper order statistic,
including ties. -/
lemma upperQuantile_mono {n : N} (a b : Fin n → R) (hab : ∀ i, a i ≤ b i)
(r : N) (hr : r < n) : upperQuantile a r hr ≤ upperQuantile b r hr := by
apply (upperQuantile_le_iff a r hr _).mpr
have h := (upperQuantile_le_iff b r hr _).mp le_rfl
apply (card_le_card (show
(univ.filter fun i => upperQuantile b r hr < a i) ⊆
(univ.filter fun i => upperQuantile b r hr < b i) from ?_)).trans h
intro i hi
exact mem_filter.mpr ⟨mem_univ _, (mem_filter.mp hi).2.trans_le (hab i)⟩
lemma lowerQuantile_mono {n : ℕ} (a b : Fin n → ℝ) (hab : ∀ i, a i ≤ b i)
(r : ℕ) (hr : r < n) : lowerQuantile a r hr ≤ lowerQuantile b r hr := by
have h := upperQuantile_mono (fun i => -b i) (fun i => -a i)
(fun i => neg_le_neg (hab i)) r hr
simpa only [upperQuantile_neg, neg_le_neg_iff] using h
lemma measurable_upperQuantile {Ω : Type*} [MeasurableSpace Ω] {n : ℕ}
(a : Ω → Fin n → ℝ) (ha : ∀ i, Measurable fun ω => a ω i)
(r : ℕ) (hr : r < n) :
Measurable fun ω => upperQuantile (a ω) r hr := by
apply measurable_of_Iic
intro p
have hcount : Measurable fun ω => (univ.filter fun i => p < a ω i).card := by
have hs : Measurable fun ω => ∑ i : Fin n, if p < a ω i then (1 : ℕ)
else 0 :=
Finset.measurable_sum univ (fun i _ =>
Measurable.ite (measurableSet_lt measurable_const (ha i))
measurable_const measurable_const)
simpa only [sum_boole, Nat.cast_id] using hs
have he : (fun ω => upperQuantile (a ω) r hr) ⁻¹' Set.Iic p =
{ω | (univ.filter fun i => p < a ω i).card ≤ r} := by
ext ω
exact upperQuantile_le_iff (a ω) r hr p
rw [he]
exact measurableSet_le hcount measurable_const
lemma measurable_lowerQuantile {Ω : Type*} [MeasurableSpace Ω] {n : ℕ}
(a : Ω → Fin n → ℝ) (ha : ∀ i, Measurable fun ω => a ω i)
(r : ℕ) (hr : r < n) :
Measurable fun ω => lowerQuantile (a ω) r hr := by
have h := (measurable_upperQuantile (fun ω i => -a ω i)
(fun i => (ha i).neg) r hr).neg
simpa only [upperQuantile_neg, Pi.neg_def, neg_neg] using h
end LeBet.EmpiricalOptimization
import LeBet.Relabeling
import LeBet.Probability
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
/-- Every two subsets of the same size are related by a permutation of the
population. -/
lemma exists_relabel_eq {ι : Type*} [Fintype ι] (S T : Finset ι) (h : S.card =
T.card) :
∃ e : Equiv.Perm ι, relabel e S = T := by
let e : S ≃ T := Fintype.equivOfCardEq (by simpa using h)
refine ⟨e.extendSubtype, ?_⟩
apply eq_of_subset_of_card_le
· intro j hj
obtain ⟨i, hi, rfl⟩ := mem_map.mp hj
exact e.extendSubtype_mem i hi
· rw [relabel_card, h]
/-- Choose one population permutation for each possible training subset. -/
noncomputable def subsetSwap {ι : Type*} [Fintype ι] (S T : Finset ι) :
Equiv.Perm ι :=
if h : S.card = T.card then (exists_relabel_eq S T h).choose else
Equiv.refl ι
lemma subsetSwap_maps {ι : Type*} [Fintype ι] (S T : Finset ι) (h : S.card =
T.card) :
relabel (subsetSwap S T) S = T := by
simp only [subsetSwap, dite_eq_left h]
exact (exists_relabel_eq S T h).choose_spec
private lemma relabel_trans {ι : Type*} (e f : Equiv.Perm ι) (K : Finset ι) :
relabel (e.trans f) K = relabel f (relabel e K) := by
ext i
simp only [mem_relabel]
rfl
/-- A uniform population permutation induces the uniform law on training
indices.
Repeated observations remain distinct coordinates. -/
theorem permutation_subset_average {ι : Type*} [Fintype ι] [DecidableEq ι]
(K_0 : Finset ι) (A : Set (Finset ι)) :
(((univ : Finset (Equiv.Perm ι)).filter fun e => relabel e K_0 ∈ A).card :
ℝ) /
Fintype.card (Equiv.Perm ι) =
(subsetLaw univ K_0.card (by simpa only [card_univ] using card_le_univ
K_0)).real A := by
let S := (univ : Finset ι).powersetCard K_0.card
let c := ((univ : Finset (Equiv.Perm ι)).filter fun e => relabel e K_0 =
K_0).card
have hmem (e : Equiv.Perm ι) : relabel e K_0 ∈ S :=
mem_powersetCard.mpr ⟨subset_univ _, relabel_card e K_0⟩
have hc (K : Finset ι) (hK : K ∈ S) :
((univ : Finset (Equiv.Perm ι)).filter fun e => relabel e K_0 = K).card
= c := by
let a := subsetSwap K K_0
have ha : relabel a K = K_0 :=
subsetSwap_maps K K_0 (mem_powersetCard.mp hK).2
have hback : relabel a.symm K_0 = K := by
rw [← ha, relabel_symm]
apply card_bij (fun e _ => e.trans a)
· intro e he
simp only [mem_filter, mem_univ, true_and] at he ⊢
rw [relabel_trans, he, ha]
· intro e _ f _ hef
ext i
exact a.injective (Equiv.congr_fun hef i)
· intro f hf
simp only [mem_filter, mem_univ, true_and] at hf
refine ⟨f.trans a.symm, ?_, ?_⟩
· simp only [mem_filter, mem_univ, true_and]
rw [relabel_trans, hf, hback]
· ext i
exact a.apply_symm_apply (f i)
have hcount (T : Finset (Finset ι)) (hT : T ⊆ S) :
((univ : Finset (Equiv.Perm ι)).filter fun e => relabel e K_0 ∈ T).card =
T.card * c := by
rw [← sum_card_fiberwise_eq_card_filter]
exact sum_const_nat (fun K hK => hc K (hT hK))
have htotal : Fintype.card (Equiv.Perm ι) = S.card * c := by
have ht := hcount S (Subset.refl _)
simpa [hmem] using ht
have hevent :
((univ : Finset (Equiv.Perm ι)).filter fun e => relabel e K_0 ∈ A).card =
(S.filter fun K => K ∈ A).card * c := by
have ht := hcount (S.filter fun K => K ∈ A) (filter_subset _ _)
simpa only [mem_filter, hmem, true_and] using ht
have hcpos : 0 < c := by
apply card_pos.mpr
refine ⟨Equiv.refl ι, mem_filter.mpr ⟨mem_univ _, ?_⟩⟩
ext i
simp only [mem_relabel, Equiv.refl_symm, Equiv.refl_apply]
rw [hevent, htotal, Nat.cast_mul, Nat.cast_mul,
mul_div_mul_right _ _ (by exact_mod_cast hcpos.ne')]
rw [subsetLaw_real]
simp only [S, card_powersetCard]
/-- The finite-averaging identity for measurable law-preserving maps, without
invertibility. -/
theorem finite_event_average {Ω ι : Type*} [MeasurableSpace Ω]
{sP : Measure Ω} [IsProbabilityMeasure sP]
(S : Finset ι) (hne : S.Nonempty) (act : ι → Ω → Ω)
(hact : ∀ i, MeasurePreserving (act i) sP sP)
{A : Set Ω} (hA : MeasurableSet A) :
(∫ ω, (((S.filter fun i => act i ω ∈ A).card : ℝ) / S.card) ∂sP) =
sP.real A := by
let f (i : ι) : Ω → ℝ := (act i ⁻¹' A).indicator (fun _ => 1)
have hf (i : ι) : Integrable (f i) sP :=
(integrable_const 1).indicator ((hact i).measurable hA)
have he (i : ι) : (∫ ω, f i ω ∂sP) = sP.real A := by
calc
(∫ ω, f i ω ∂sP) = sP.real (act i ⁻¹' A) := by
simpa only [f, Pi.one_def] using
(integral_indicator_one (µ := sP) ((hact i).measurable hA))
_ = sP.real A := by
simp only [measureReal_def, (hact i).measure_preimage
hA.nullMeasurableSet]
have hsum (ω : Ω) : ∑ i ∈ S, f i ω =
((S.filter fun i => act i ω ∈ A).card : ℝ) := by
simp only [f, Set.indicator_apply, Set.mem_preimage, ← sum_filter,
sum_const, nsmul_eq_mul, mul_one]
simp_rw [← hsum]
rw [integral_div, integral_finsetSum S (fun i _ => hf i)]
simp_rw [he]
have hn : (S.card : ℝ) ≠ 0 := by exact_mod_cast hne.card_pos.ne'
simp [hn]
Lean 4 Supplement
/-- A pointwise bound on the finite average bounds the event probability. -/
theorem event_bound_of_finite_average {Ω ι : Type*} [MeasurableSpace Ω]
{sP : Measure Ω} [IsProbabilityMeasure sP]
(S : Finset ι) (hne : S.Nonempty) (act : ι → Ω → Ω)
(hact : ∀ i, MeasurePreserving (act i) sP sP)
{A : Set Ω} (hA : MeasurableSet A) {c : ℝ}
(hpoint : ∀ ω, (((S.filter fun i => act i ω ∈ A).card : ℝ) / S.card) ≤
c) :
sP.real A ≤ c := by
let f (i : ι) : Ω → ℝ := (act i ⁻¹' A).indicator (fun _ => 1)
have hf (i : ι) : Integrable (f i) sP :=
(integrable_const 1).indicator ((hact i).measurable hA)
have havg : Integrable (fun ω => (∑ i ∈ S, f i ω) / (S.card : ℝ)) sP :=
(integrable_finsetSum S (fun i _ => hf i)).div_const _
have hsum (ω : Ω) : ∑ i ∈ S, f i ω = ((S.filter fun i => act i ω ∈ A).card
: ℝ) := by
simp only [f, Set.indicator_apply, Set.mem_preimage, ← sum_filter,
sum_const, nsmul_eq_mul, mul_one]
simp_rw [hsum] at havg
calc
sP.real A = ∫ ω, (((S.filter fun i => act i ω ∈ A).card : ℝ) / S.card) ∂
sP :=
(finite_event_average S hne act hact hA).symm
_ ≤ ∫ ω, c ∂sP := integral_mono havg (integrable_const c) hpoint
_ = c := by simp
/-- The specialization to permutations used in the rank and exchangeability
proofs. -/
theorem event_bound_of_finite_symmetry {Ω ι : Type*} [MeasurableSpace Ω]
{sP : Measure Ω} [IsProbabilityMeasure sP]
(S : Finset ι) (hne : S.Nonempty) (act : ι → Ω ≃ₘ Ω)
(hact : ∀ i, MeasurePreserving (act i) sP sP)
{A : Set Ω} (hA : MeasurableSet A) {c : ℝ}
(hpoint : ∀ ω, (((S.filter fun i => act i ω ∈ A).card : ℝ) / S.card) ≤
c) :
sP.real A ≤ c :=
event_bound_of_finite_average S hne (fun i => act i) hact hA hpoint
end LeBet.FiniteSampling
import LeBet.RankProbability
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
/-- A strict rank exceedance; the pivot has exactly ‘a‘ training ranks before
it. -/
def rankExceeds {N : ℕ} (k h a : ℕ) (s : ℝ) (K : Finset (Fin N)) : Prop :=
∃ p ∈ K, (K.filter (· < p)).card = a ∧
(a : ℝ) / k + s < ((Kᶜ.filter (· < p)).card : ℝ) / h
lemma rank_floor_cutoff {k h a N : ℕ} (hk : 0 < k) (hh : 0 < h) {s : ℝ} (hs :
0 < s)
{K : Finset (Fin N)} {p : Fin N}
(hp : (a : R) / k + s < ((Kᶜ.filter (· < p)).card : R) / h) :
Nat.floor ((h : R) * ((a : R) / k + s)) + 1 ≤ (Kᶜ.filter (· < p)).card :=
by
have hk’ : (0 : R) < k := by exact_mod_cast hk
have hh’ : (0 : R) < h := by exact_mod_cast hh
have hx : 0 ≤ (h : R) * ((a : R) / k + s) := by positivity
have hlt : (h : R) * ((a : R) / k + s) < (Kᶜ.filter (· < p)).card := by
nlinarith [(lt_div_iff₀ hh’).mp hp]
exact Nat.succ_le_of_lt ((Nat.floor_lt hx).mpr hlt)
noncomputable def prefixValue {N : N} (q : Fin N) (i : Fin N) : R := if i < q
then 1 else 0
lemma prefix_sum {N : N} (q : Fin N) (K : Finset (Fin N)) :
∑ i ∈ K, prefixValue q i = ((K.filter (· < q)).card : R) := by
simp only [prefixValue, ← sum_filter, sum_const, nsmul_eq_mul, mul_one]
lemma prefix_total {N : N} (q : Fin N) : ∑ i : Fin N, prefixValue q i =
(q.val : R) := by
rw [prefix_sum]
have he : (univ : Finset (Fin N)).filter (· < q) = Iio q := by ext i; simp
rw [he, Fin.card_Iio]
/-- Appendix H, ‘eq:uniform-rank-tail‘, for the actual uniform-subset law.
No independence of the learned threshold from the training ranks is assumed.
-/
theorem uniform_rank_serfling_tail {k h a : N} (hk : 0 < k) (hh : 0 < h) (ha
: a < k)
{s : R} (hs : 0 < s) :
(subsetLaw (univ : Finset (Fin (k + h))) k (by simp)).real {K |
rankExceeds k h a s K} ≤
Real.exp (-2 * k * h * s ^ 2 / (k + h + 2)) := by
let j := Nat.floor ((h : R) * ((a : R) / k + s)) + 1
have hk’ : (0 : R) < k := by exact_mod_cast hk
have hh’ : (0 : R) < h := by exact_mod_cast hh
by_cases hj : j ≤ h
· let q : Fin (k + h) := ⟨a + j, by omega⟩
have hjlt : (a : R) / k + s < (j : R) / h := by
apply (lt_div_iff₀ hh’).mpr
simpa only [j, Nat.cast_add, Nat.cast_one, mul_comm] using
Nat.lt_floor_add_one ((h : R) * ((a : R) / k + s))
have hinc : ∀ K ∈ (univ : Finset (Fin (k + h))).powersetCard k,
K ∈ {K | rankExceeds k h a s K} → K ∈ {K | s < sampleGap k h
(prefixValue q) K} := by
intro K _ hK
obtain ⟨p, _, hpa, hpex⟩ := hK
have hjJ := rank_floor_cutoff hk hh hs hpex
have hcard := RankTransfer.rank_to_fixed_prefix K p a j hpa hjJ
have hcard’ : (K.filter (· < q)).card ≤ a := hcard
have htrain : ∑ i ∈ K, prefixValue q i ≤ (a : R) := by
rw [prefix_sum]
exact_mod_cast hcard’
have hsum := sum_add_sum_compl K (prefixValue q)
rw [prefix_total] at hsum
have hfuture : (j : R) ≤ ∑ i ∈ Kᶜ, prefixValue q i := by
dsimp [q] at hsum
rw [Nat.cast_add] at hsum
linarith
change s < sampleGap k h (prefixValue q) K
unfold sampleGap
have hx := div_le_div_of_nonneg_right htrain hk’.le
have hy := div_le_div_of_nonneg_right hfuture hh’.le
have hd : s < (j : R) / h - (a : R) / k :=
lt_sub_iff_add_lt.mpr (by simpa only [add_comm] using hjlt)
exact hd.trans_le (sub_le_sub hy hx)
exact (subsetLaw_mono_on_support univ k (by simp) hinc).trans
(two_sample_serfling hk hh (by simp) (prefixValue q)
(fun i => by by_cases hi : i < q <;> simp [prefixValue, hi]) hs)
· have hinc : ∀ K ∈ (univ : Finset (Fin (k + h))).powersetCard k,
K ∈ {K | rankExceeds k h a s K} → K ∈ (∅ : Set (Finset (Fin (k +
h)))) := by
intro K hK hbad
obtain ⟨p, _, _, hpex⟩ := hbad
have hjJ := rank_floor_cutoff hk hh hs hpex
have hcard := card_le_card (filter_subset (· < p) Kᶜ)
have hcomp : Kᶜ.card = h := by
rw [card_compl, (mem_powersetCard.mp hK).2]
simp
rw [hcomp] at hcard
dsimp [j] at hj
exfalso
omega
have hp := subsetLaw_mono_on_support univ k (by simp) hinc
simp only [measureReal_empty] at hp
exact hp.trans (Real.exp_pos _).le
/-- The preceding Hoeffding coefficient is a consequence of the refined
bound. -/
theorem uniform_rank_tail {k h a : N} (hk : 0 < k) (hh : 0 < h) (ha : a < k)
{s : R} (hs : 0 < s) :
(subsetLaw (univ : Finset (Fin (k + h))) k (by simp)).real {K |
rankExceeds k h a s K} ≤
Real.exp (-(min k h : N) * s ˆ 2 / 2) := by
apply (uniform_rank_serfling_tail hk hh ha hs).trans
apply Real.exp_le_exp.mpr
have hk’ : (1 : R) ≤ k := by exact_mod_cast hk
have hh’ : (1 : R) ≤ h := by exact_mod_cast hh
have hcoef : ((min k h : N) : R) / 2 ≤ 2 * k * h / (k + h + 2) := by
apply (le_div_iff₀ (by positivity)).mpr
rcases le_total k h with hle | hle
· rw [min_eq_left hle]
have hle’ : (k : R) ≤ h := by exact_mod_cast hle
nlinarith [mul_nonneg (show (0 : R) ≤ k by positivity)
(show (0 : R) ≤ 3 * h - k - 2 by linarith)]
· rw [min_eq_right hle]
have hle’ : (h : R) ≤ k := by exact_mod_cast hle
nlinarith [mul_nonneg (show (0 : R) ≤ h by positivity)
(show (0 : R) ≤ 3 * k - h - 2 by linarith)]
have hmul := mul_le_mul_of_nonneg_right hcoef (sq_nonneg s)
convert neg_le_neg hmul using 1 <;> ring
end LeBet.FiniteSampling
import LeBet.StableScores
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
/-- A uniform singleton falls in the first ‘a+1‘ ranks with probability
‘(a+1)/N‘. -/
lemma singleton_prefix_probability {N : N} (a : Fin N) :
(subsetLaw (univ : Finset (Fin N)) 1 (by have h := a.isLt; simp only
[card_univ, Fintype.card_fin]; omega)).real
{R | ∃ i ∈ R, i ≤ a} = (a.val + 1 : R) / N := by
rw [subsetLaw_real]
simp only [card_univ, Nat.choose_one_right, Fintype.card_fin,
Set.mem_ofPred_eq]
have hc : (((univ : Finset (Fin N)).powersetCard 1).filter
(fun R => ∃ i ∈ R, i ≤ a)).card = a.val + 1 := by
calc
_ = (Iic a).card := by
symm
apply card_bij (fun i _ => ({i} : Finset (Fin N)))
· intro i hi
simp only [mem_filter, mem_powersetCard, subset_univ,
card_singleton, true_and]
exact ⟨i, mem_singleton_self i, mem_Iic.mp hi⟩
· intro i _ j _ hij
simpa using hij
· intro R hR
obtain ⟨hR, i, hi, hia⟩ := mem_filter.mp hR
obtain ⟨j, rfl⟩ := card_eq_one.mp (mem_powersetCard.mp hR).2
have hij : i = j := mem_singleton.mp hi
exact ⟨j, mem_Iic.mpr (hij ▸ hia), rfl⟩
_ = _ := Fin.card_Iic a
convert congrArg (fun n : N => (n : R) / N) hc using 1 <;> simp
/-- The lone future rank precedes the ‘(a+1)‘st training rank exactly when
it is one of the first ‘a+1‘ population ranks. -/
lemma one_future_precedes_iff {k a : N} (ha : a < k) (i : Fin (k + 1)) :
(∃ p ∈ ({i}ᶜ : Finset (Fin (k + 1))),
(({i}ᶜ : Finset (Fin (k + 1))).filter (· < p)).card = a ∧
0 < (({i} : Finset (Fin (k + 1))).filter (· < p)).card) ↔ i.val ≤ a :=
by
have hcard (p : Fin (k + 1)) (hip : i < p) :
(({i}ᶜ : Finset (Fin (k + 1))).filter (· < p)).card = p.val - 1 := by
have he : ({i}ᶜ : Finset (Fin (k + 1))).filter (· < p) = (Iio p).erase i
:= by
ext j
simp only [mem_filter, mem_compl, mem_singleton, mem_erase, mem_Iio]
rw [he, card_erase_of_mem (mem_Iio.mpr hip), Fin.card_Iio]
constructor
· rintro ⟨p, _, hp, hf⟩
have hip : i < p := by
obtain ⟨j, hj⟩ := card_pos.mp hf
obtain ⟨hj, hjp⟩ := mem_filter.mp hj
simpa only [mem_singleton.mp hj] using hjp
rw [hcard p hip] at hp
have hiv : i.val < p.val := hip
omega
· intro hi
let p : Fin (k + 1) := ⟨a + 1, by omega⟩
have hip : i < p := by change i.val < a + 1; omega
refine ⟨p, ?_, ?_, ?_⟩
· simpa using (ne_of_gt hip)
· rw [hcard p hip]
simp [p]
· exact card_pos.mpr ⟨i, mem_filter.mpr ⟨mem_singleton_self i, hip⟩⟩
/-- Appendix H, ‘eq:one-future-rank‘, under the actual uniform
training-subset law. -/
theorem one_future_rank {k a : N} (ha : a < k) :
(subsetLaw (univ : Finset (Fin (k + 1))) k (by simp)).real
{K | ∃ p ∈ K, (K.filter (· < p)).card = a ∧ 0 < (Kᶜ.filter (· <
p)).card} =
(a + 1 : R) / (k + 1) := by
let q : Fin (k + 1) := ⟨a, by omega⟩
have heq (K : Finset (Fin (k + 1)))
(hK : K ∈ (univ : Finset (Fin (k + 1))).powersetCard k) :
(∃ p ∈ K, (K.filter (· < p)).card = a ∧ 0 < (Kᶜ.filter (· <
p)).card) ↔
∃ i ∈ Kᶜ, i ≤ q := by
have hc : Kᶜ.card = 1 := by rw [card_compl, (mem_powersetCard.mp hK).2];
simp
obtain ⟨i, hi⟩ := card_eq_one.mp hc
have hK’ : K = ({i}ᶜ : Finset (Fin (k + 1))) := by rw [← hi, compl_compl]
rw [hK’, compl_compl, one_future_precedes_iff ha]
simp only [mem_singleton, exists_eq_left]
change i.val ≤ a ↔ i.val ≤ a
have hp : (subsetLaw (univ : Finset (Fin (k + 1))) k (by simp)).real
{K | ∃ p ∈ K, (K.filter (· < p)).card = a ∧ 0 < (Kᶜ.filter (· <
p)).card} =
(subsetLaw (univ : Finset (Fin (k + 1))) k (by simp)).real
{K | ∃ i ∈ Kᶜ, i ≤ q} := by
apply le_antisymm
· exact subsetLaw_mono_on_support univ k (by simp) (fun K hK h => (heq K
hK).mp h)
· exact subsetLaw_mono_on_support univ k (by simp) (fun K hK h => (heq K
hK).mpr h)
calc
_ = (subsetLaw (univ : Finset (Fin (k + 1))) k (by simp)).real
{K | ∃ i ∈ Kᶜ, i ≤ q} := hp
_ = (subsetLaw (univ : Finset (Fin (k + 1))) 1 (by simp)).real
{R | ∃ i ∈ R, i ≤ q} := by
simpa using subsetLaw_complement k 1 (by simp) {R | ∃ i ∈ R, i ≤ q}
_ = _ := by simpa [q] using singleton_prefix_probability q
end LeBet.FiniteSampling
The exact rank law also gives the single-extension case.
import LeBet.RankBounds
import LeBet.OneFuture
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.FiniteSampling
lemma pivot_unique {N : N} (K : Finset (Fin N)) {a : N} (ha : a < K.card)
{p : Fin N} (hp : p ∈ K) (hcount : (K.filter (· < p)).card = a) :
p = K.orderEmbOfFin rfl ⟨a, ha⟩ := by
have hmem : p ∈ Set.range (K.orderEmbOfFin rfl) := by
simpa only [range_orderEmbOfFin, Finset.mem_coe] using hp
obtain ⟨i, rfl⟩ := hmem
have hi : i.val = a := (training_pivot_counts K i.isLt).1.symm.trans hcount
exact congrArg (K.orderEmbOfFin rfl) (Fin.ext hi)
lemma prefix_card_partition {N : N} (K : Finset (Fin N)) (p : Fin N) :
(K.filter (· < p)).card + (Kᶜ.filter (· < p)).card = p.val := by
have he : (Iio p).filter (· ∈ K) = K.filter (· < p) := by ext i; simp
[and_comm]
have he’ : (Iio p).filter (· ∉ K) = Kᶜ.filter (· < p) := by ext i; simp
[and_comm]
simpa only [he, he’, Fin.card_Iio] using
card_filter_add_card_filter_not (s := Iio p) (fun i => i ∈ K)
private lemma split_at_pivot {N : N} (K : Finset (Fin N)) {p : Fin N} (hp : p
∈ K) :
insert p ((K.filter (· < p)) ∪ (K.filter (p < ·))) = K := by
ext i
simp only [mem_insert, mem_union, mem_filter]
constructor
· rintro (rfl | h | h)
· exact hp
· exact h.1
· exact h.1
· intro hi
rcases lt_trichotomy i p with h | h | h
· exact Or.inr (Or.inl ⟨hi, h⟩)
· exact Or.inl h
· exact Or.inr (Or.inr ⟨hi, h⟩)
private lemma pivot_union_filters {N : N} (p : Fin N) {L U : Finset (Fin N)}
(hL : L ⊆ Iio p) (hU : U ⊆ Ioi p) :
(insert p (L ∪ U)).filter (· < p) = L ∧
(insert p (L ∪ U)).filter (p < ·) = U := by
constructor <;> ext i <;> simp only [mem_filter, mem_insert, mem_union]
· constructor
· rintro ⟨rfl | hi | hi, hlt⟩
· exact (lt_irrefl _ hlt).elim
· exact hi
· exact (not_lt_of_gt (mem_Ioi.mp (hU hi)) hlt).elim
· intro hi
exact ⟨Or.inr (Or.inl hi), mem_Iio.mp (hL hi)⟩
· constructor
· rintro ⟨rfl | hi | hi, hlt⟩
· exact (lt_irrefl _ hlt).elim
· exact (not_lt_of_gt (mem_Iio.mp (hL hi)) hlt).elim
· exact hi
· intro hi
exact ⟨Or.inr (Or.inr hi), mem_Ioi.mp (hU hi)⟩
private lemma pivot_union_card {N : ℕ} (p : Fin N) {L U : Finset (Fin N)}
(hL : L ⊆ Iio p) (hU : U ⊆ Ioi p) :
(insert p (L ∪ U)).card = L.card + U.card + 1 := by
have hd : Disjoint L U := disjoint_left.mpr fun i hi hi’ =>
(not_lt_of_gt (mem_Iio.mp (hL hi))) (mem_Ioi.mp (hU hi’))
have hp : p ∉ L ∪ U := by
intro hi
rcases mem_union.mp hi with hi | hi
· exact lt_irrefl _ (mem_Iio.mp (hL hi))
· exact lt_irrefl _ (mem_Ioi.mp (hU hi))
rw [card_insert_of_notMem hp, card_union_of_disjoint hd]
/-- Count training subsets with a specified pivot and a specified number of
predecessors. -/
lemma fixed_pivot_card {N k a : ℕ} (ha : a < k) (p : Fin N) :
(((univ : Finset (Fin N)).powersetCard k).filter
(fun K => p ∈ K ∧ (K.filter (· < p)).card = a)).card =
p.val.choose a * (N - p.val - 1).choose (k - a - 1) := by
let B := (Iio p).powersetCard a ×ˢ (Ioi p).powersetCard (k - a - 1)
have hc : B.card = p.val.choose a * (N - p.val - 1).choose (k - a - 1) := by
simp only [B, card_product, card_powersetCard, Fin.card_Iio, Fin.card_Ioi]
congr 2
omega
rw [← hc]
symm
apply card_bij (fun LU _ => insert p (LU.1 ∪ LU.2))
· intro LU hLU
obtain ⟨hL, hU⟩ := mem_product.mp hLU
obtain ⟨hLsub, hLcard⟩ := mem_powersetCard.mp hL
obtain ⟨hUsub, hUcard⟩ := mem_powersetCard.mp hU
apply mem_filter.mpr
refine ⟨mem_powersetCard.mpr ⟨subset_univ _, ?_⟩, mem_insert_self _ _, ?_⟩
· rw [pivot_union_card p hLsub hUsub, hLcard, hUcard]
omega
· rw [(pivot_union_filters p hLsub hUsub).1, hLcard]
· intro LU hLU LV hLV he
have hL := mem_product.mp hLU
have hV := mem_product.mp hLV
have hLU’ := pivot_union_filters p (mem_powersetCard.mp hL.1).1
(mem_powersetCard.mp hL.2).1
have hLV’ := pivot_union_filters p (mem_powersetCard.mp hV.1).1
(mem_powersetCard.mp hV.2).1
apply Prod.ext
· simpa only [hLU’.1, hLV’.1] using congrArg (fun K => K.filter (· < p)) he
· simpa only [hLU’.2, hLV’.2] using congrArg (fun K => K.filter (p < ·)) he
· intro K hK
obtain ⟨hKcard, hp, hpre⟩ := mem_filter.mp hK
have hcard := (mem_powersetCard.mp hKcard).2
have hL : K.filter (· < p) ⊆ Iio p := fun i hi => mem_Iio.mpr
(mem_filter.mp hi).2
have hU : K.filter (p < ·) ⊆ Ioi p := fun i hi => mem_Ioi.mpr
(mem_filter.mp hi).2
have hc := pivot_union_card p hL hU
rw [split_at_pivot K hp, hcard, hpre] at hc
refine ⟨(K.filter (· < p), K.filter (p < ·)), mem_product.mpr
⟨mem_powersetCard.mpr ⟨hL, hpre⟩, mem_powersetCard.mpr ⟨hU, ?_⟩⟩,
split_at_pivot K hp⟩
change (K.filter (p < ·)).card = k - a - 1
omega
/-- The explicit mass function of the uniform-subset rank. -/
theorem uniform_rank_pmf {n m a j : N} (ha : a < n) (hj : j ≤ m) :
(subsetLaw (univ : Finset (Fin (n + m))) n (by simp)).real
{K | rankCount a K = j} =
((a + j).choose a : R) * ((n + m - a - j - 1).choose (n - a - 1) : R) /
(n + m).choose n := by
let p : Fin (n + m) := ⟨a + j, by omega⟩
have he (K : Finset (Fin (n + m))) (hK : K.card = n) :
rankCount a K = j ↔ p ∈ K ∧ (K.filter (· < p)).card = a := by
have haK : a < K.card := by omega
let q := K.orderEmbOfFin rfl ⟨a, haK⟩
have hq := (training_pivot_counts K haK).1
change (K.filter (· < q)).card = a at hq
have hsum := prefix_card_partition K q
rw [hq] at hsum
constructor
· intro h
have hj’ : (Kᶜ.filter (· < q)).card = j := by
simpa only [rankCount, dite_eq_left haK] using h
have hpq : p = q := Fin.ext (by change a + j = q.val; rw [hj’] at hsum;
exact hsum)
rw [hpq]
exact ⟨orderEmbOfFin_mem K rfl _, hq⟩
· rintro ⟨hp, hpre⟩
have hpq : p = q := pivot_unique K haK hp hpre
have hval : q.val = a + j := by rw [← hpq]
simp only [rankCount, dite_eq_left haK]
change (Kᶜ.filter (· < q)).card = j
rw [hval] at hsum
omega
rw [subsetLaw_real]
have hfilter : ((univ : Finset (Fin (n + m))).powersetCard n).filter (fun K
=> rankCount a K = j) =
((univ : Finset (Fin (n + m))).powersetCard n).filter
(fun K => p ∈ K ∧ (K.filter (· < p)).card = a) := by
apply filter_congr
intro K hK
exact he K (mem_powersetCard.mp hK).2
simp only [Set.mem_ofPred_eq]
rw [hfilter, fixed_pivot_card ha p]
simp only [card_univ, Fintype.card_fin, Nat.cast_mul, p]
rw [show n + m - (a + j) - 1 = n + m - a - j - 1 by omega]
/-- A single extension makes the rank error Bernoulli, so its positive-part
expectation is linear throughout the unit interval. -/
lemma rankExcessMean_one_future {n a : N} (ha : a < n) {u : R}
(hu : u ∈ Set.Icc (0 : R) 1) :
rankExcessMean n 1 a 0 u = (1 - u) * ((a + 1 : R) / (n + 1)) := by
let G : Set (Finset (Fin (n + 1))) := {K | rankCount a K = 1}
have hmass : (subsetLaw (univ : Finset (Fin (n + 1))) n (by simp)).real G =
(a + 1 : R) / (n + 1) := by
have h := uniform_rank_pmf ha (j := 1) (m := 1) le_rfl
have he : n + 1 - a - 1 - 1 = n - a - 1 := by omega
simpa only [he, Nat.choose_succ_self_right, Nat.choose_self, Nat.cast_add,
Nat.cast_one, mul_one] using h
have hw (K : Finset (Fin (n + 1))) (hK : K.card = n) :
rankErrorRate n 1 a 0 K = if K ∈ G then 1 else 0 := by
have haK : a < K.card := by omega
have hc : Kᶜ.card = 1 := by rw [card_compl, hK]; simp
have hj : rankCount a K ≤ 1 := by
simp only [rankCount, dite_eq_left haK]
exact (card_le_card (filter_subset _ _)).trans_eq hc
have he : rankErrorRate n 1 a 0 K = (rankCount a K : R) := by
simp only [rankErrorRate, add_zero, if_pos ha, Nat.cast_zero,
Nat.cast_one, div_one]
exact min_eq_right (by exact_mod_cast hj)
rw [he]
by_cases h : K ∈ G
· simp only [if_pos h, show rankCount a K = 1 from h, Nat.cast_one]
· have hz : rankCount a K = 0 := by
have hn : rankCount a K ≠ 1 := h
omega
simp only [if_neg h, hz, Nat.cast_zero]
have hsum : (∑ K ∈ (univ : Finset (Fin (n + 1))).powersetCard n,
max (rankErrorRate n 1 a 0 K - u) 0) =
((((univ : Finset (Fin (n + 1))).powersetCard n).filter (· ∈ G)).card :
R) * (1 - u) := by
calc
_ = ∑ K ∈ (univ : Finset (Fin (n + 1))).powersetCard n,
if K ∈ G then 1 - u else 0 := by
apply sum_congr rfl
intro K hK
rw [hw K (mem_powersetCard.mp hK).2]
by_cases h : K ∈ G
· simp [h, max_eq_left (sub_nonneg.mpr hu.2)]
· simp [h, max_eq_right (neg_nonpos.mpr hu.1)]
_ = _ := by rw [← sum_filter]; simp only [sum_const, nsmul_eq_mul]
calc
rankExcessMean n 1 a 0 u =
(1 - u) * (subsetLaw (univ : Finset (Fin (n + 1))) n (by simp)).real
G := by
rw [rankExcessMean, hsum, subsetLaw_real]
simp only [card_univ, Fintype.card_fin]
rw [mul_comm _ (1 - u), mul_div_assoc]
congr 2
congr 1
congr 1
``
ext K
simp only [mem_filter]
_ = _ := by rw [hmass]
/-- The exact capped minimum for one future trajectory and no exceptional
occurrences. -/
theorem rankErrorBound_one_future {n a : N} (ha : a < n)
{β : R} (hb : 0 < β) :
rankErrorBound n 1 a 0 β 0 = min 1 ((a + 1 : R) / (β * (n + 1))) := by
let q := ((a + 1 : R) / (n + 1)) / β
have hq : q = (a + 1 : R) / (β * (n + 1)) := by
dsimp [q]
rw [div_div, mul_comm _ β]
have hobj {u : R} (hu : u ∈ Set.Icc (0 : R) 1) :
rankObjective n 1 a 0 β 0 u = u + (1 - u) * q := by
rw [rankObjective, rankExcessMean_one_future ha hu]
dsimp [q]
ring
have hlo : min 1 q ≤ rankErrorBound n 1 a 0 β 0 := by
obtain ⟨u, hu, he⟩ := rankErrorBound_minimizer n 1 a 0 β 0
rw [he, hobj hu]
by_cases h : q ≤ 1
· rw [min_eq_right h]
nlinarith [mul_nonneg hu.1 (sub_nonneg.mpr h)]
· rw [min_eq_left (le_of_not_ge h)]
nlinarith [mul_nonneg (sub_nonneg.mpr hu.2) (sub_nonneg.mpr
(le_of_not_ge h))]
have hhi : rankErrorBound n 1 a 0 β 0 ≤ min 1 q := by
apply le_min (rankErrorBound_le_one n 1 a 0 β 0)
have h := rankErrorBound_le n 1 a 0 β 0 (u := 0) (by norm_num)
simpa only [hobj (by norm_num : (0 : R) ∈ Set.Icc (0 : R) 1),
sub_zero, one_mul, zero_add] using h
rw [← hq]
exact le_antisymm hhi hlo
end LeBet.FiniteSampling
Reflection at the first crossing gives the balanced finite-sampling bound.
import LeBet.RankDistribution
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.FiniteSampling
/-- The signed difference between extension and training counts in a prefix.
-/
def prefixDifference {N : N} (K : Finset (Fin N)) (j : N) : Z :=
j - 2 * ((K.filter fun i => i.val < j).card : Z)
lemma prefixDifference_zero {N : N} (K : Finset (Fin N)) :
prefixDifference K 0 = 0 := by simp [prefixDifference]
lemma prefixDifference_last {N : N} (K : Finset (Fin N)) :
prefixDifference K N = (N : Z) - 2 * K.card := by
have he : K.filter (fun i => i.val < N) = K := filter_true_of_mem (fun i _
=> i.isLt)
rw [prefixDifference, he]
lemma prefixDifference_step {N : N} (K : Finset (Fin N)) (j : N) :
prefixDifference K (j + 1) ≤ prefixDifference K j + 1 := by
have hcard := card_le_card (show K.filter (fun i => i.val < j) ⊆
K.filter (fun i => i.val < j + 1) from
fun i hi => mem_filter.mpr ⟨(mem_filter.mp hi).1, Nat.lt_succ_of_lt
(mem_filter.mp hi).2⟩)
unfold prefixDifference
omega
private lemma exists_prefix_ge {N : N} (K : Finset (Fin N)) (k : N) :
∃ j, (k : Z) ≤ prefixDifference K j := by
refine ⟨2 * N + k, ?_⟩
have hc : (K.filter fun i => i.val < 2 * N + k).card ≤ N :=
(card_le_card (subset_univ _)).trans_eq (by simp)
unfold prefixDifference
omega
/-- The first crossing exists after extending the count formula beyond the
last index.
Only crossings at or before ‘N‘ enter the reflection argument. -/
noncomputable def firstCrossing {N : N} (K : Finset (Fin N)) (k : N) : N :=
Nat.find (exists_prefix_ge K k)
lemma firstCrossing_spec {N : N} (K : Finset (Fin N)) (k : N) :
(k : Z) ≤ prefixDifference K (firstCrossing K k) :=
Nat.find_spec (exists_prefix_ge K k)
lemma firstCrossing_min {N : N} (K : Finset (Fin N)) (k : N) {j : N}
(hj : j < firstCrossing K k) : prefixDifference K j < k :=
lt_of_not_ge (Nat.find_min (exists_prefix_ge K k) hj)
lemma firstCrossing_le {N : N} (K : Finset (Fin N)) (k : N) {j : N}
(hj : (k : Z) ≤ prefixDifference K j) : firstCrossing K k ≤ j :=
Nat.find_min’ (exists_prefix_ge K k) hj
lemma firstCrossing_exact {N k : N} (K : Finset (Fin N)) (hk : 0 < k) :
prefixDifference K (firstCrossing K k) = k := by
have hge := firstCrossing_spec K k
have hj : 0 < firstCrossing K k := by
by_contra h
have he : firstCrossing K k = 0 := by omega
rw [he, prefixDifference_zero] at hge
omega
have hprev := firstCrossing_min K k (Nat.sub_lt hj (by norm_num : 0 < 1))
have hstep := prefixDifference_step K (firstCrossing K k - 1)
rw [Nat.sub_add_cancel hj] at hstep
omega
/-- Reflect all steps after the specified prefix. -/
def reflectAfter {N : N} (K : Finset (Fin N)) (j : N) : Finset (Fin N) :=
(K.filter fun i => i.val < j) ∪ (Kᶜ.filter fun i => j ≤ i.val)
lemma reflectAfter_involutive {N : N} (K : Finset (Fin N)) (j : N) :
reflectAfter (reflectAfter K j) j = K := by
ext i
by_cases hi : i.val < j <;> simp [reflectAfter, hi, not_lt.mp, not_le.mpr]
lemma reflectAfter_prefix {N : N} (K : Finset (Fin N)) {t j : N} (ht : t ≤ j) :
prefixDifference (reflectAfter K j) t = prefixDifference K t := by
have he : (reflectAfter K j).filter (fun i => i.val < t) = K.filter (fun i => i.val < t) := by
ext i
by_cases hi : i.val < t
· have hij : i.val < j := hi.trans_le ht
simp [reflectAfter, hi, hij, not_le.mpr hij]
· simp [hi]
rw [prefixDifference, he, prefixDifference]
lemma reflectAfter_card {N : N} (K : Finset (Fin N)) {j : N} (hj : j ≤ N) :
((reflectAfter K j).card : ℤ) + K.card + prefixDifference K j = N := by
let P : Finset (Fin N) := univ.filter fun i => i.val < j
have hP : P.card = j := by simpa only [P, Fin.card_filter_val_lt, min_eq_right hj]
have he : P.filter (· ∈ K) = K.filter (fun i => i.val < j) := by
ext i
simp [P, and_comm]
have he’ : P.filter (· ∉ K) = Kᶜ.filter (fun i => i.val < j) := by
ext i
simp [P, and_comm]
have hpre := card_filter_add_card_filter_not (s := P) (fun i => i ∈ K)
rw [he, he’, hP] at hpre
have hsplit := card_filter_add_card_filter_not (s := Kᶜ) (fun i => i.val < j)
simp only [not_lt] at hsplit
have hc : K.card + Kᶜ.card = N := by simp
have hd : Disjoint (K.filter fun i => i.val < j) (Kᶜ.filter fun i => j ≤ i.val) := by
apply disjoint_left.mpr
intro i hi hi’
exact not_lt_of_ge (mem_filter.mp hi’).2 (mem_filter.mp hi).2
have hr : (reflectAfter K j).card =
(K.filter fun i => i.val < j).card + (Kᶜ.filter fun i => j ≤ i.val).card :=
card_union_of_disjoint hd
unfold prefixDifference
omega
lemma reflected_firstCrossing {N : N} (K : Finset (Fin N)) (k : N) :
firstCrossing (reflectAfter K (firstCrossing K k)) k = firstCrossing K k
:= by
apply (Nat.find_eq_iff _).mpr
constructor
· rw [reflectAfter_prefix K le_rfl]
exact firstCrossing_spec K k
· intro j hj
rw [reflectAfter_prefix K hj.le]
exact not_le.mpr (firstCrossing_min K k hj)
/-- Reflection after the first crossing is an involution. -/
noncomputable def reflectCrossing {N : N} (K : Finset (Fin N)) (k : N) :
Finset (Fin N) :=
reflectAfter K (firstCrossing K k)
lemma reflectCrossing_involutive {N : N} (K : Finset (Fin N)) (k : N) :
reflectCrossing (reflectCrossing K k) k = K := by
simp only [reflectCrossing, reflected_firstCrossing,
reflectAfter_involutive]
/-- The reflection bijection counts all balanced walks which reach level ‘k‘.
-/
theorem balanced_crossing_card {n k : N} (hk : 0 < k) (hkn : k ≤ n) :
(((univ : Finset (Fin (2 * n))).powersetCard n).filter
(fun K => ∃ j ≤ 2 * n, (k : Z) ≤ prefixDifference K j)).card =
(2 * n).choose (n - k) := by
have hreflect (K : Finset (Fin (2 * n))) (hcross : firstCrossing K k ≤ 2 *
n) :
((reflectCrossing K k).card : Z) + K.card + k = 2 * n := by
simpa only [reflectCrossing, firstCrossing_exact K hk, Nat.cast_mul,
Nat.cast_ofNat] using
reflectAfter_card K hcross
have hc : ((univ : Finset (Fin (2 * n))).powersetCard (n - k)).card =
(2 * n).choose (n - k) := by simp
rw [← hc]
apply card_bij (fun K _ => reflectCrossing K k)
· intro K hK
obtain ⟨hK, j, hj, hcross⟩ := mem_filter.mp hK
have hcard := (mem_powersetCard.mp hK).2
have hr := hreflect K ((firstCrossing_le K k hcross).trans hj)
apply mem_powersetCard.mpr
refine ⟨subset_univ _, ?_⟩
omega
· intro K _ L _ he
have h := congrArg (fun J => reflectCrossing J k) he
simpa only [reflectCrossing_involutive] using h
· intro L hL
have hcard := (mem_powersetCard.mp hL).2
have hlast : (k : Z) ≤ prefixDifference L (2 * n) := by
rw [prefixDifference_last]
omega
have hfirst := firstCrossing_le L k hlast
have hcard’ : (reflectCrossing L k).card = n := by
have h := hreflect L hfirst
omega
refine ⟨reflectCrossing L k, mem_filter.mpr
⟨mem_powersetCard.mpr ⟨subset_univ _, hcard’⟩,
firstCrossing L k, hfirst, ?_⟩, reflectCrossing_involutive L k⟩
rw [reflectCrossing, reflectAfter_prefix L le_rfl]
exact firstCrossing_spec L k
/-- The exact reflection probability under the uniform balanced-subset law. -/
theorem balanced_reflection_probability {n k : N} (hk : 0 < k) (hkn : k ≤ n) :
(subsetLaw (univ : Finset (Fin (2 * n))) n (by simp; omega)).real
{K | ∃ j ≤ 2 * n, (k : Z) ≤ prefixDifference K j} =
((2 * n).choose (n - k) : R) / (2 * n).choose n := by
rw [subsetLaw_real]
simp only [Set.mem_ofPred_eq, balanced_crossing_card hk hkn, card_univ,
Fintype.card_fin]
end LeBet.FiniteSampling
import LeBet.BalancedReflection
import Mathlib.Analysis.Calculus.Deriv.MeanValue
open MeasureTheory ProbabilityTheory Filter Finset
open scoped Classical
namespace LeBet.FiniteSampling
/-- The logarithmic estimate used in the balanced reflection bound. -/
lemma log_reflection_ratio_le {x : R} (hx : 0 ≤ x) (hx1 : x < 1) :
Real.log ((1 - x) / (1 + x)) ≤ -2 * x := by
let f : R → R := fun y => Real.log (1 - y) - Real.log (1 + y) + 2 * y
let f’ : R → R := fun y => -2 * y ˆ 2 / ((1 - y) * (1 + y))
have hd (y : R) (hy : y ∈ Set.Icc 0 x) : HasDerivAt f (f’ y) y := by
have hminus : 1 - y ≠ 0 := by linarith [hy.2]
have hplus : 1 + y ≠ 0 := by linarith [hy.1]
convert ((((hasDerivAt_id y).const_sub 1).log hminus).sub
(((hasDerivAt_id y).const_add 1).log hplus)).add
((hasDerivAt_id y).const_mul 2) using 1
· rfl
· dsimp [f’]
field_simp
ring
have hf : AntitoneOn f (Set.Icc 0 x) := by
apply antitoneOn_of_hasDerivWithinAt_nonpos (convex_Icc 0 x)
(fun y hy => (hd y hy).continuousAt.continuousWithinAt)
(fun y hy => (hd y (interior_subset hy)).hasDerivWithinAt)
intro y hy
have hyy := interior_subset hy
exact div_nonpos_of_nonpos_of_nonneg (by nlinarith [sq_nonneg y])
(mul_nonneg (by linarith [hyy.2]) (by linarith [hyy.1]))
have h := hf ⟨le_rfl, hx⟩ ⟨hx, le_rfl⟩ hx
simp only [f, sub_zero, add_zero, Real.log_one, sub_self, mul_zero] at h
rw [Real.log_div (by linarith : 1 - x ≠ 0) (by linarith : 1 + x ≠ 0)]
linarith
private lemma balanced_binomial_step {n j : N} (hj : j < n) :
((2 * n).choose (n - (j + 1)) : R) / (2 * n).choose n =
(((2 * n).choose (n - j) : R) / (2 * n).choose n) *
((n : R) - j) / (n + j + 1) := by
have hn : 0 < ((2 * n).choose n : R) := by exact_mod_cast Nat.choose_pos
(by omega : n ≤ 2 * n)
have hd : 0 < (n : R) + j + 1 := by positivity
have h := Nat.choose_succ_right_eq (2 * n) (n - (j + 1))
have he : n - (j + 1) + 1 = n - j := by omega
have he’ : 2 * n - (n - (j + 1)) = n + j + 1 := by omega
rw [he, he’] at h
have hreal : ((2 * n).choose (n - j) : R) * ((n : R) - j) =
((2 * n).choose (n - (j + 1)) : R) * ((n : R) + j + 1) := by
have hr := congrArg (fun x : N => (x : R)) h
push_cast [Nat.cast_sub hj.le] at hr
exact hr
field_simp
nlinarith
/-- The binomial ratio in the reflection formula is the finite product in the paper. -/
theorem balanced_binomial_product {n k : N} (hk : k ≤ n) :
((2 * n).choose (n - k) : R) / (2 * n).choose n =
∏ j ∈ range k, ((n : R) - j) / (n + j + 1) := by
induction k with
| zero =>
have hp : ((2 * n).choose n : R) ≠ 0 := by exact_mod_cast Nat.ne_of_gt
(Nat.choose_pos (by omega : n ≤ 2 * n))
simp [hp]
| succ j ih =>
rw [balanced_binomial_step (by omega : j < n), ih (by omega),
prod_range_succ]
ring
/-- The exponential part of the balanced-prefix bound. -/
theorem balanced_binomial_bound {n k : N} (hk : k ≤ n) :
((2 * n).choose (n - k) : R) / (2 * n).choose n ≤
Real.exp (-2 * (k : R) ^ 2 / (2 * n + 1)) := by
induction k with
| zero =>
have hp : ((2 * n).choose n : R) ≠ 0 := by exact_mod_cast Nat.ne_of_gt
(Nat.choose_pos (by omega : n ≤ 2 * n))
simp [hp]
| succ j ih =>
have hj : j < n := by omega
have hj’ : (j : R) < n := by exact_mod_cast hj
have hd : 0 < (2 : R) * n + 1 := by positivity
let x : R := (2 * j + 1) / (2 * n + 1)
have hx : 0 ≤ x := by dsimp [x]; positivity
have hx1 : x < 1 := (div_lt_one hd).mpr (by linarith)
have hr : 0 < ((n : R) - j) / (n + j + 1) := div_pos (by linarith) (by
positivity)
have he : (1 - x) / (1 + x) = ((n : R) - j) / (n + j + 1) := by
dsimp [x]
field_simp
ring
have hlog := log_reflection_ratio_le hx hx1
rw [he] at hlog
have hfactor : ((n : R) - j) / (n + j + 1) ≤ Real.exp (-2 * x) := by
simpa only [Real.exp_log hr] using Real.exp_le_exp.mpr hlog
calc
_ = (((2 * n).choose (n - j) : R) / (2 * n).choose n) *
(((n : R) - j) / (n + j + 1)) := by rw [balanced_binomial_step hj];
ring
_ ≤ Real.exp (-2 * (j : R) ^ 2 / (2 * n + 1)) * Real.exp (-2 * x) :=
mul_le_mul (ih (by omega)) hfactor hr.le (Real.exp_pos _).le
_ = _ := by
rw [← Real.exp_add]
congr 1
dsimp [x]
push_cast
field_simp
ring
/-- The maximum prefix difference, normalized by the training size. -/
noncomputable def balancedPrefixDeviation (n : ℕ) (K : Finset (Fin (2 * n)))
: ℝ :=
((range (2 * n + 1)).sup’ (by simp) (fun j => (prefixDifference K j : ℝ))) / n
/-- Uniform control of every prefix under the balanced-subset law. -/
theorem balanced_prefix_tail {n : ℕ} (hn : 0 < n) {s : ℝ} (hs : 0 < s) :
(subsetLaw (univ : Finset (Fin (2 * n))) n (by simp; omega)).real
{K | s < balancedPrefixDeviation n K} ≤
Real.exp (-2 * (n : ℝ) ^ 2 * s ^ 2 / (2 * n + 1)) := by
let k := Nat.floor ((n : ℝ) * s) + 1
have hk : 0 < k := by dsimp [k]; omega
have hn’ : (0 : ℝ) < n := by exact_mod_cast hn
have hns : 0 ≤ (n : ℝ) * s := mul_nonneg hn’.le hs.le
have hfloor := Nat.floor_le hns
have hlt : (n : ℝ) * s < k := by
simpa only [k, Nat.cast_add, Nat.cast_one] using
Nat.lt_floor_add_one ((n : ℝ) * s)
have hinc : {K | s < balancedPrefixDeviation n K} ⊆
{K | ∃ j ≤ 2 * n, (k : ℤ) ≤ prefixDifference K j} := by
intro K hK
have hmax : (n : ℝ) * s <
(range (2 * n + 1)).sup’ (by simp) (fun j => (prefixDifference K j : ℝ)) := by
simpa only [mul_comm] using (lt_div_iff₀ hn’).mp hK
obtain ⟨j, hj, hval⟩ := (lt_sup’_iff (by simp)).mp hmax
refine ⟨j, by simpa only [mem_range, Nat.lt_succ_iff] using hj, ?_⟩
have hcast : (Nat.floor ((n : ℝ) * s) : ℤ) < prefixDifference K j := by
exact_mod_cast hfloor.trans_lt hval
dsimp only [k]
omega
by_cases hkn : k ≤ n
· calc
_ ≤ (subsetLaw (univ : Finset (Fin (2 * n))) n (by simp; omega)).real
{K | ∃ j ≤ 2 * n, (k : ℤ) ≤ prefixDifference K j} :=
subsetLaw_mono_on_support univ n (by simp; omega) (fun K _ h => hinc h)
_ = ((2 * n).choose (n - k) : ℝ) / (2 * n).choose n :=
balanced_reflection_probability hk hkn
_ ≤ Real.exp (-2 * (k : ℝ) ^ 2 / (2 * n + 1)) :=
balanced_binomial_bound hkn
_ ≤ _ := by
apply Real.exp_le_exp.mpr
apply div_le_div_of_nonneg_right _ (by positivity)
nlinarith [sq_nonneg ((k : ℝ) - n * s)]
· have hempty : ∀ K ∈ (univ : Finset (Fin (2 * n))).powersetCard n,
K ∈ {K | s < balancedPrefixDeviation n K} →
K ∈ (∅ : Set (Finset (Fin (2 * n)))) := by
intro K hK hbad
obtain ⟨j, hj, hcross⟩ := hinc hbad
have hfirst := (firstCrossing_le K k hcross).trans hj
have hcard := (mem_powersetCard.mp hK).2
have h := reflectAfter_card K hfirst
rw [firstCrossing_exact K hk] at h
omega
have h := subsetLaw_mono_on_support univ n (by simp; omega) hempty
exact h.trans (by simp; positivity)
end LeBet.FiniteSampling
Conditional Means and Stability
Training-sample averaging. Reindex the extension errors under training-sample permutations.
open Finset MeasureTheory
open scoped Classical
namespace LeBet.FiniteSampling
lemma extension_error_rate_permute {Ω : Type*} [MeasurableSpace Ω] {N h : N}
(u : Ω → Finset (Fin N) → Fin N → R) (q : Ω → Finset (Fin N) → R)
(act : Equiv.Perm (Fin N) → Ω ≃
Ω)
(hu : ∀ e ω K i, u (act e ω) K i = u ω (relabel e K) (e i))
(hq : ∀ e ω K, q (act e ω) K = q ω (relabel e K))
(e : Equiv.Perm (Fin N)) (ω : Ω) (B : R) (K : Finset (Fin N)) :
extensionErrorRate h (u (act e ω)) (q (act e ω)) B K =
extensionErrorRate h (u ω) (q ω) B (relabel e K) := by
have hueq : u (act e ω) = fun L i => u ω (relabel e L) (e i) :=
funext (fun L => funext (fun i => hu e ω L i))
have hqeq : q (act e ω) = fun L => q ω (relabel e L) :=
funext (fun L => hq e ω L)
rw [hueq, hqeq, future_error_relabel]
end LeBet.FiniteSampling
Martingales and Concentration
The Bernoulli exponential martingale gives the concentration bounds.
import Mathlib.Probability.Martingale.OptionalStopping
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real
import Mathlib.Tactic
open MeasureTheory ProbabilityTheory Filter Finset
open scoped ENNReal
namespace LeBet
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {sP : Measure Ω}
[IsProbabilityMeasure sP] {gF : Filtration N mΩ}
/-- A measurable bounded real function is integrable under a probability law.
-/
lemma integrable_of_abs_bound {f : Ω → R} (hf : StronglyMeasurable f)
(C : R) (hC : ∀ ω, |f ω| ≤ C) : Integrable f sP :=
(integrable_const C).mono’ hf.aestronglyMeasurable (ae_of_all _ (by simpa
using hC))
/-- The product through time ‘t’; factor ‘s’ is observed at paper time ‘s+1’.
-/
noncomputable def productProcess (F : ℕ → Ω → ℝ) (t : ℕ) (ω : Ω) : ℝ :=
∏ s ∈ range t, F s ω
lemma productProcess_adapted {F : ℕ → Ω → ℝ}
(hF : ∀ s, StronglyMeasurable[gF (s + 1)] (F s)) :
StronglyAdapted gF (productProcess F) := by
intro t
exact (range t).stronglyMeasurable_fun_prod (fun s hs =>
(hF s).mono (gF.mono (Nat.succ_le_of_lt (mem_range.mp hs))))
lemma productProcess_bounds {F : ℕ → Ω → ℝ} {C : ℝ}
(hF : ∀ s ω, 0 ≤ F s ω ∧ F s ω ≤ C) (t : ℕ) (ω : Ω) :
0 ≤ productProcess F t ω ∧ productProcess F t ω ≤ C ^ t := by
constructor
· exact prod_nonneg fun s _ => (hF s ω).1
· calc
productProcess F t ω ≤
∏ _s ∈ range t, C :=
prod_le_prod0 (fun s _ => (hF s ω).1) (fun s _ => (hF s ω).2)
_ = C ^ t := by simp
lemma productProcess_integrable {F : ℕ → Ω → ℝ} {C : ℝ}
(hF : ∀ s, StronglyMeasurable[gF (s + 1)] (F s))
(hb : ∀ s ω, 0 ≤ F s ω ∧ F s ω ≤ C) (t : ℕ) :
Integrable (productProcess F t) sP := by
apply integrable_of_abs_bound ((productProcess_adapted hF t).mono (gF.le
t)) (C ^ t)
intro ω
rw [abs_of_nonneg (productProcess_bounds hb t ω).1]
exact (productProcess_bounds hb t ω).2
/-- Multiplying bounded, adapted, nonnegative factors with conditional mean
at most one
produces a supermartingale for mathlib’s actual conditional expectation. -/
theorem productProcess_supermartingale {F : ℕ → Ω → ℝ} {C : ℝ}
(hF : ∀ s, StronglyMeasurable[gF (s + 1)] (F s))
(hb : ∀ s ω, 0 ≤ F s ω ∧ F s ω ≤ C)
(hm : ∀ s, sP[F s | gF s] ≤
𝔼[sP] (fun _ => (1 : ℝ))) :
Supermartingale (productProcess F) gF sP := by
have had := productProcess_adapted hF
have hint := productProcess_integrable (sP := sP) hF hb
apply supermartingale_nat had hint
intro s
have hprod : productProcess F (s + 1) = productProcess F s * F s := by
funext ω
simp [productProcess, prod_range_succ]
rw [hprod]
have hiF : Integrable (F s) sP := by
apply integrable_of_abs_bound ((hF s).mono (gF.le _)) C
intro ω
rw [abs_of_nonneg (hb s ω).1]
exact (hb s ω).2
have hpull := condExp_mul_of_stronglyMeasurable_left (had s)
(hprod ▶ hint (s + 1)) hiF
filter_upwards [hpull, hm s] with ω hp hmw
simp only [Pi.mul_apply] at hp
rw [hp]
simpa using mul_le_mul_of_nonneg_left hmw (productProcess_bounds hb s ω).1
/-- Fixed-monitor proof, ‘eq:ville-conditional-martingale‘, on an arbitrary
probability space. -/
theorem finite_ville {M : N → Ω → R} (hM : Supermartingale M gF sP)
(hpos : ∀ t ω, 0 ≤ M t ω) (hzero : M 0 = fun _ => 1)
{a : R} (ha : 0 < a) (T : N) :
sP.real {ω | ∃ t ≤ T, a ≤ M t ω} ≤ 1 / a := by
let σ := hittingBtwn M (Set.Ici a) 0 T
let τ : Ω → WithTop N := fun ω => σ ω
have hτ : IsStoppingTime gF τ :=
hM.stronglyAdapted.adapted.isStoppingTime_hittingBtwn measurableSet_Ici
have hb : ∀ ω, τ ω ≤ T := fun ω => WithTop.coe_le_coe.mpr (hittingBtwn_le ω)
have hint : Integrable (stoppedValue M τ) sP :=
integrable_stoppedValue N hτ hM.integrable hb
have hstop : ∫ ω, stoppedValue M τ ω ∂sP ≤ 1 := by
have h := hM.neg.expected_stoppedValue_mono (isStoppingTime_const gF 0) hτ
(fun ω => bot_le) hb
have hn : stoppedValue (-M) τ = -(stoppedValue M τ) := rfl
simp only [stoppedValue_const, hn, Pi.neg_apply, integral_neg] at h
rw [hzero] at h
simpa using h
have hinc : {ω | ∃ t ≤ T, a ≤ M t ω} ⊆ {ω | a ≤ stoppedValue M τ ω} := by
rintro ω ⟨t, ht, haM⟩
exact stoppedValue_hittingBtwn_mem ⟨t, ⟨Nat.zero_le _, ht⟩, haM⟩
have hmark := mul_meas_ge_le_integral_of_nonneg
(ae_of_all sP (fun ω => hpos (σ ω) ω)) hint a
change a * sP.real {ω | a ≤ stoppedValue M τ ω} ≤
∫ ω, stoppedValue M τ ω ∂sP at hmark
have hprob := measureReal_mono (μ := sP) hinc
apply (le_div_iff0 ha).mpr
simpa [mul_comm] using (mul_le_mul_of_nonneg_left hprob ha.le).trans
(hmark.trans hstop)
/-- Event comparison used in E, F, and H. -/
lemma probability_le_add_of_subset {A B C : Set Ω} (h : A ⊆ B ∪ C) :
sP.real A ≤ sP.real B + sP.real C :=
(measureReal_mono h).trans (measureReal_union_le _ _)
lemma probability_le_add_of_ae_imp {A B C : Set Ω}
(h : ∀ᵐ ω ∂sP, ω ∈ A → ω ∈ B ∪ C) :
sP.real A ≤ sP.real B + sP.real C := by
have hm : sP A ≤ sP (B ∪ C) := measure_mono_ae h
exact (ENNReal.toReal_mono (measure_ne_top sP _) hm).trans
(measureReal_union_le _ _)
/-- The equality case of the same product construction. -/
theorem productProcess_martingale {F : N → Ω → R} {C : R}
(hF : ∀ s, StronglyMeasurable[gF (s + 1)] (F s))
(hb : ∀ s ω, 0 ≤ F s ω ∧ F s ω ≤ C)
(hm : ∀ s, sP[F s | gF s] =ᵐ[sP] (fun _ => (1 : ℝ))) :
Martingale (productProcess F) gF sP := by
have had := productProcess_adapted hF
have hint := productProcess_integrable (sP := sP) hF hb
apply martingale_nat had hint
intro s
have hprod : productProcess F (s + 1) = productProcess F s * F s := by
funext ω
simp [productProcess, prod_range_succ]
rw [hprod]
have hiF : Integrable (F s) sP := by
apply integrable_of_abs_bound ((hF s).mono (gF.le _)) C
intro ω
rw [abs_of_nonneg (hb s ω).1]
exact (hb s ω).2
have hpull := condExp_mul_of_stronglyMeasurable_left (had s)
(hprod ▸ hint (s + 1)) hiF
filter_upwards [hpull, hm s] with ω hp hmω
simp only [Pi.mul_apply] at hp
rw [hp, hmω, mul_one]
omit [IsProbabilityMeasure sP] in
lemma probability_exists_finset_le {ι : Type*} (s : Finset ι) (A : ι → Ω →
Prop) :
sP.real {ω | ∃ i ∈ s, A i ω} ≤
∑ i ∈ s, sP.real {ω | A i ω} := by
have he : {ω | ∃ i ∈ s, A i ω} = ⋃ i ∈ s, {ω | A i ω} := by
ext ω
simp
rw [he]
exact measureReal_biUnion_finset_le s _
end LeBet
import LeBet.Concentration
import LeBet.KL
open MeasureTheory ProbabilityTheory Filter Finset
namespace LeBet.BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration ℕ mΩ}
(X : BinaryMonitor gF) (sP : Measure Ω) [IsProbabilityMeasure sP]
noncomputable def comparisonFactor (k : ℝ) (s : ℕ) (ω : Ω) : ℝ :=
(1 + k * X.X s ω) / (1 + k * X.µ sP s ω)
omit [IsProbabilityMeasure sP] in
lemma comparisonFactor_measurable (k : ℝ) (s : ℕ) :
StronglyMeasurable[gF (s + 1)] (X.comparisonFactor sP k s) := by
have hm := (X.mean_measurable sP s).mono (gF.mono (Nat.le_succ s))
exact ((measurable_const.add ((X.adapted s).measurable.const_mul k)).div
(measurable_const.add (hm.measurable.const_mul k))).stronglyMeasurable
omit [IsProbabilityMeasure sP] in
lemma comparisonFactor_bounds {k : ℝ} (hk : 0 ≤ k) (s : ℕ) (ω : Ω) :
0 ≤ X.comparisonFactor sP k s ω ∧ X.comparisonFactor sP k s ω ≤ 1 + k :=
by
have hd := one_add_mul_pos hk (X.mean_nonneg sP s ω)
have hn := one_add_mul_pos hk (X.nonneg s ω)
constructor
· exact (div_pos hn hd).le
· apply (div_le_iff0 hd).mpr
have h1 := mul_le_mul_of_nonneg_left (X.le_one s ω) hk
have h2 := mul_nonneg hk (X.mean_nonneg sP s ω)
nlinarith
omit [IsProbabilityMeasure sP] in
lemma comparisonFactor_bounds_general {k : R} (hk : -1 < k) (s : N) (ω : Ω) :
0 ≤ X.comparisonFactor sP k s ω ∧
X.comparisonFactor sP k s ω ≤ (1 + |k|) / min 1 (1 + k) := by
have hd := one_add_mul_pos′ hk (X.mean_nonneg sP s ω) (X.mean_le_one sP s ω)
have hn := one_add_mul_pos′ hk (X.nonneg s ω) (X.le_one s ω)
have hlow : 0 < min 1 (1 + k) := lt_min zero_lt_one (by linarith)
have hden : min 1 (1 + k) ≤ 1 + k * X.μ sP s ω := by
by_cases h : 0 ≤ k
· exact (min_le_left _ _).trans (by nlinarith [X.mean_nonneg sP s ω])
· exact (min_le_right _ _).trans (by nlinarith [X.mean_le_one sP s ω])
have hnum : 1 + k * X.X s ω ≤ 1 + |k| := by
by_cases h : 0 ≤ k
· rw [abs_of_nonneg h]
nlinarith [X.le_one s ω]
· rw [abs_of_neg (lt_of_not_ge h)]
nlinarith [X.nonneg s ω]
exact ⟨(div_pos hn hd).le, div_le_div0 (by positivity) hnum hlow hden⟩
lemma comparisonFactor_condExp_general {k : R} (hk : -1 < k) (s : N) :
sP[X.comparisonFactor sP k s | gF s] =ᵐ[sP] (fun _ => (1 : R)) := by
let f : Ω → R := fun ω => (1 + k * X.μ sP s ω)⁻¹
let g : Ω → R := fun ω => 1 + k * X.X s ω
have hf : StronglyMeasurable[gF s] f :=
(measurable_const.add ((X.mean_measurable sP s).measurable.const_mul
k)).inv.stronglyMeasurable
have heq : X.comparisonFactor sP k s = f * g := by
funext ω
simp only [comparisonFactor, Pi.mul_apply, f, g, div_eq_mul_inv]
ring
have hi : Integrable (X.comparisonFactor sP k s) sP := by
apply integrable_of_abs_bound ((X.comparisonFactor_measurable sP k
s).mono (gF.le _))
((1 + |k|) / min 1 (1 + k))
intro ω
rw [abs_of_nonneg (X.comparisonFactor_bounds_general sP hk s ω).1]
exact (X.comparisonFactor_bounds_general sP hk s ω).2
rw [heq]
have hpull := condExp_mul_of_stronglyMeasurable_left hf (heq ▸ hi)
((integrable_const 1).add ((X.integrable sP s).const_mul k))
filter_upwards [hpull, X.condExp_affine sP s 1 k] with ω hp hm
change sP[f * g | gF s] ω = f ω * sP[g | gF s] ω at hp
rw [hp]
change f ω * sP[fun ω => 1 + k * X.X s ω | gF s] ω = 1
rw [hm]
exact inv_mul_cancel0
(one_add_mul_pos’ hk (X.mean_nonneg sP s ω) (X.mean_le_one sP s ω)).ne’
lemma comparisonFactor_condExp {k : R} (hk : 0 ≤ k) (s : N) :
sP[X.comparisonFactor sP k s | gF s] =m[sP] (fun _ => (1 : R)) :=
X.comparisonFactor_condExp_general sP (by linarith) s
theorem comparison_martingale_general {k : R} (hk : -1 < k) :
Martingale (productProcess (X.comparisonFactor sP k)) gF sP :=
productProcess_martingale (X.comparisonFactor_measurable sP k)
(X.comparisonFactor_bounds_general sP hk)
(X.comparisonFactor_condExp_general sP hk)
/-- The fixed-monitor comparison martingale, in the equivalent ‘k = exp λ -
1‘ form. -/
theorem comparison_martingale {k : R} (hk : 0 ≤ k) :
Martingale (productProcess (X.comparisonFactor sP k)) gF sP :=
productProcess_martingale (X.comparisonFactor_measurable sP k)
(X.comparisonFactor_bounds sP hk) (X.comparisonFactor_condExp sP hk)
omit [IsProbabilityMeasure sP] in
lemma comparison_lambda_form («λ» : R) (t : N) (ω : Ω) :
productProcess (X.comparisonFactor sP (Real.exp «λ» - 1)) t ω =
Real.exp («λ» * X.S t ω - ∑ s ∈ range t, psi «λ» (X.µ sP s ω)) := by
have hk : -1 < Real.exp «λ» - 1 := by linarith [Real.exp_pos «λ»]
have he (s : N) :
X.comparisonFactor sP (Real.exp «λ» - 1) s ω =
Real.exp («λ» * X.X s ω - psi «λ» (X.µ sP s ω)) := by
rw [Real.exp_sub, psi, Real.exp_log]
· exact (evidence_bridge «λ» (X.µ sP s ω) (X.binary s ω)).symm
· rw [normaliser_eq]
exact one_add_mul_pos’ hk (X.mean_nonneg sP s ω) (X.mean_le_one sP s ω)
simp only [productProcess, he, ← Real.exp_sum, sum_sub_distrib, ← mul_sum,
]
/-- The conditional Bernoulli martingale lemma, including negative stakes. -/
theorem bernoulli_martingale («λ» : R) :
Martingale (fun t ω =>
Real.exp («λ» * X.S t ω -
∑ s ∈ range t, psi «λ» (X.µ sP s ω))) gF sP
:= by
have he : productProcess (X.comparisonFactor sP (Real.exp «λ» - 1)) =
fun t ω => Real.exp («λ» * X.S t ω -
∑ s ∈ range t, psi «λ» (X.µ sP s ω)) := by
funext t ω
exact X.comparison_lambda_form sP «λ» t ω
rw [← he]
exact X.comparison_martingale_general sP (by linarith [Real.exp_pos «λ»])
end LeBet.BinaryMonitor
import LeBet.Monitor
open MeasureTheory ProbabilityTheory Filter Finset
namespace LeBet.BinaryMonitor
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {gF : Filtration N mΩ}
(X : BinaryMonitor gF) (sP : Measure Ω) [IsProbabilityMeasure sP]
noncomputable def hoeffdingFactor (z : ℝ) (s : ℕ) (ω : Ω) : ℝ :=
Real.exp (z * (X.X s ω - X.μ sP s ω) - z ^ 2 / 8)
omit [IsProbabilityMeasure sP] in
lemma hoeffdingFactor_measurable (z : ℝ) (s : ℕ) :
StronglyMeasurable[gF (s + 1)] (X.hoeffdingFactor sP z s) := by
have hm := (X.mean_measurable sP s).mono (gF.mono (Nat.le_succ s))
exact ((((X.adapted s).measurable.sub hm.measurable).const_mul z).sub_const
(z ^ 2 / 8)).exp.stronglyMeasurable
omit [IsProbabilityMeasure sP] in
lemma hoeffdingFactor_bounds (z : ℝ) (s : ℕ) (ω : Ω) :
0 ≤ X.hoeffdingFactor sP z s ω ∧
X.hoeffdingFactor sP z s ω ≤ Real.exp |z| := by
constructor
· exact (Real.exp_pos _).le
· apply Real.exp_le_exp.mpr
have hd : |X.X s ω - X.μ sP s ω| ≤ 1 :=
abs_le.mpr ⟨by linarith [X.nonneg s ω, X.mean_le_one sP s ω],
by linarith [X.le_one s ω, X.mean_nonneg sP s ω]⟩
have h := mul_le_mul_of_nonneg_left hd (abs_nonneg z)
rw [← abs_mul, mul_one] at h
have := (le_abs_self (z * (X.X s ω - X.μ sP s ω))).trans h
nlinarith [sq_nonneg z]
/-- The conditional Hoeffding bound is derived from the scalar theorem and the
Bernoulli conditional MGF; it is not an assumption. -/
lemma hoeffdingFactor_condExp (z : ℝ) (s : ℕ) :
sP[X.hoeffdingFactor sP z s | gF s] ≤
𝔼[sP] (fun _ => (1 : ℝ)) := by
let f : Ω → ℝ := fun ω => Real.exp (-z * X.μ sP s ω - z ^ 2 / 8)
let g : Ω → ℝ := fun ω => Real.exp (z * X.X s ω)
have hf : StronglyMeasurable[gF s] f :=
(((X.mean_measurable sP s).measurable.const_mul (-z)).sub_const
(z ^ 2 / 8)).exp.stronglyMeasurable
have heq : X.hoeffdingFactor sP z s = f * g := by
funext ω
simp only [hoeffdingFactor, Pi.mul_apply, f, g, ← Real.exp_add]
congr 1
ring
have hi : Integrable (X.hoeffdingFactor sP z s) sP := by
apply integrable_of_abs_bound ((X.hoeffdingFactor_measurable sP z s).mono
(gF.le _))
(Real.exp |z|)
intro ω
rw [abs_of_nonneg (X.hoeffdingFactor_bounds sP z s ω).1]
exact (X.hoeffdingFactor_bounds sP z s ω).2