Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Domains, risks, learnability and conditions for OOD detection (Fang et al. 2022)

Definition
OODLearnable_Basic

by Xeroth · Nov 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

impossibility-theoremslearnabilityood-detectionpac-learningvc-dimension

Objects of Sections 2-5 and Appendices D-J of Fang, Li, Lu, Dong, Han and Liu (NeurIPS 2022).

  1. Spaces and loss. The feature space is a set X⊆Rd\mathcal X\subseteq\mathbb R^dX⊆Rd with its Borel σ\sigmaσ-algebra and subspace topology. The ID labels are Y={1,…,K}\mathcal Y=\{1,\dots,K\}Y={1,…,K}, all OOD data carry the label K+1K+1K+1, and Yall=Y∪{K+1}\mathcal Y_{\rm all}=\mathcal Y\cup\{K+1\}Yall​=Y∪{K+1}. A loss is ℓ:Yall×Yall→R≥0\ell:\mathcal Y_{\rm all}\times\mathcal Y_{\rm all}\to\mathbb R_{\ge0}ℓ:Yall​×Yall​→R≥0​ with ℓ(y1,y2)=0\ell(y_1,y_2)=0ℓ(y1​,y2​)=0 if and only if y1=y2y_1=y_2y1​=y2​. A hypothesis space is a set H\mathcal HH of functions X→Yall\mathcal X\to\mathcal Y_{\rm all}X→Yall​.
  2. Domains. A domain DXY=(1−πout)DXIYI+πoutDXOYOD_{XY}=(1-\pi^{\rm out})D_{X_{\rm I}Y_{\rm I}}+\pi^{\rm out}D_{X_{\rm O}Y_{\rm O}}DXY​=(1−πout)DXI​YI​​+πoutDXO​YO​​ is given by a probability measure DXIYID_{X_{\rm I}Y_{\rm I}}DXI​YI​​ on X×Y\mathcal X\times\mathcal YX×Y, a probability measure DXOD_{X_{\rm O}}DXO​​ on X\mathcal XX and a class prior πout∈[0,1)\pi^{\rm out}\in[0,1)πout∈[0,1). DXID_{X_{\rm I}}DXI​​ is the X\mathcal XX-marginal of DXIYID_{X_{\rm I}Y_{\rm I}}DXI​YI​​, and DXYαD^\alpha_{XY}DXYα​ is the same domain with prior α∈[0,1)\alpha\in[0,1)α∈[0,1).
  3. Risks. RDin(h)=E(x,y)∼DXIYIℓ(h(x),y)R^{\rm in}_D(h)=\mathbb E_{(x,y)\sim D_{X_{\rm I}Y_{\rm I}}}\ell(h(x),y)RDin​(h)=E(x,y)∼DXI​YI​​​ℓ(h(x),y), RDout(h)=Ex∼DXOℓ(h(x),K+1)R^{\rm out}_D(h)=\mathbb E_{x\sim D_{X_{\rm O}}}\ell(h(x),K+1)RDout​(h)=Ex∼DXO​​​ℓ(h(x),K+1), RDα(h)=(1−α)RDin(h)+αRDout(h)R^\alpha_D(h)=(1-\alpha)R^{\rm in}_D(h)+\alpha R^{\rm out}_D(h)RDα​(h)=(1−α)RDin​(h)+αRDout​(h) for α∈[0,1]\alpha\in[0,1]α∈[0,1], and RD(h)=RDπout(h)R_D(h)=R^{\pi^{\rm out}}_D(h)RD​(h)=RDπout​(h) (eq. 1).
  4. Learnability (Definitions 1-2). An algorithm maps every sample S∈(X×Y)nS\in(\mathcal X\times\mathcal Y)^nS∈(X×Y)n, n≥1n\ge1n≥1, to an element of H\mathcal HH. OOD detection is learnable in a domain space D\mathscr DD for H\mathcal HH if there are an algorithm A\mathbf AA and a non-increasing sequence ϵ(n)→0\epsilon(n)\to0ϵ(n)→0 with
ES∼DXIYInRD(A(S))≤inf⁡h∈HRD(h)+ϵ(n)for all D∈D, n≥1.\mathbb E_{S\sim D^n_{X_{\rm I}Y_{\rm I}}}R_D(\mathbf A(S))\le\inf_{h\in\mathcal H}R_D(h)+\epsilon(n)\qquad\text{for all }D\in\mathscr D,\ n\ge1.ES∼DXI​YI​n​​RD​(A(S))≤h∈Hinf​RD​(h)+ϵ(n)for all D∈D, n≥1.

It is strongly learnable if the same holds with RDαR^\alpha_DRDα​ in place of RDR_DRD​ for every α∈[0,1]\alpha\in[0,1]α∈[0,1], with one algorithm and one sequence. Learnability at rate rrr means that in addition ϵ(n)≤C r(n)\epsilon(n)\le C\,r(n)ϵ(n)≤Cr(n) for some constant CCC. 5. Domain spaces. D\mathscr DD is priori-unknown if DXYα∈DD^\alpha_{XY}\in\mathscr DDXYα​∈D whenever DXY∈DD_{XY}\in\mathscr DDXY​∈D and α∈[0,1)\alpha\in[0,1)α∈[0,1) (Definition 3). For any D\mathscr DD, D′={DXYα:DXY∈D,α∈[0,1)}\mathscr D'=\{D^\alpha_{XY}:D_{XY}\in\mathscr D,\alpha\in[0,1)\}D′={DXYα​:DXY​∈D,α∈[0,1)}. The single-distribution space of DXYD_{XY}DXY​ is {DXYα:α∈[0,1)}\{D^\alpha_{XY}:\alpha\in[0,1)\}{DXYα​:α∈[0,1)}, the total space consists of all domains, the separate space Ds\mathscr D^sDs of all domains with supp⁡DXO∩supp⁡DXI=∅\operatorname{supp}D_{X_{\rm O}}\cap\operatorname{supp}D_{X_{\rm I}}=\emptysetsuppDXO​​∩suppDXI​​=∅, and a finite-ID-distribution space is a priori-unknown space containing only finitely many distinct DXIYID_{X_{\rm I}Y_{\rm I}}DXI​YI​​. 6. Conditions. Condition 1 (linear condition): inf⁡h∈HRDα(h)=(1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDout(h)\inf_{h\in\mathcal H}R^\alpha_D(h)=(1-\alpha)\inf_{h\in\mathcal H}R^{\rm in}_D(h)+\alpha\inf_{h\in\mathcal H}R^{\rm out}_D(h)infh∈H​RDα​(h)=(1−α)infh∈H​RDin​(h)+αinfh∈H​RDout​(h) for every D∈DD\in\mathscr DD∈D and α∈[0,1)\alpha\in[0,1)α∈[0,1). Condition 2: ℓ(y2,y1)≤ℓ(K+1,y1)\ell(y_2,y_1)\le\ell(K+1,y_1)ℓ(y2​,y1​)≤ℓ(K+1,y1​) for all y1,y2∈Yy_1,y_2\in\mathcal Yy1​,y2​∈Y. Condition 3 (compatibility): for every D′∈DD'\in\mathscr DD′∈D and ϵ>0\epsilon>0ϵ>0 some hϵ∈Hh_\epsilon\in\mathcal Hhϵ​∈H satisfies RDout(hϵ)≤inf⁡h∈HRDout(h)+ϵR^{\rm out}_D(h_\epsilon)\le\inf_{h\in\mathcal H}R^{\rm out}_D(h)+\epsilonRDout​(hϵ​)≤infh∈H​RDout​(h)+ϵ and RDin(hϵ)≤inf⁡h∈HRDin(h)+ϵR^{\rm in}_D(h_\epsilon)\le\inf_{h\in\mathcal H}R^{\rm in}_D(h)+\epsilonRDin​(hϵ​)≤infh∈H​RDin​(h)+ϵ for every D∈DD\in\mathscr DD∈D with DXIYI=DXIYI′D_{X_{\rm I}Y_{\rm I}}=D'_{X_{\rm I}Y_{\rm I}}DXI​YI​​=DXI​YI​′​ (Definition 5: such D,D′D,D'D,D′ are ID-consistent). 7. Overlap (Definition 4). DXYD_{XY}DXY​ has overlap if some σ\sigmaσ-finite measure μ~\tilde\muμ~​ with DXI,DXO≪μ~D_{X_{\rm I}},D_{X_{\rm O}}\ll\tilde\muDXI​​,DXO​​≪μ~​ gives positive mass to {x:fI(x)>0, fO(x)>0}\{x:f_{\rm I}(x)>0,\ f_{\rm O}(x)>0\}{x:fI​(x)>0, fO​(x)>0}, where fI,fOf_{\rm I},f_{\rm O}fI​,fO​ are the Radon-Nikodym derivatives of DXI,DXOD_{X_{\rm I}},D_{X_{\rm O}}DXI​​,DXO​​ with respect to μ~\tilde\muμ~​. 8. Assumption 1 and VC dimension. H\mathcal HH is separate for OOD if every x∈Xx\in\mathcal Xx∈X has some hx∈Hh_x\in\mathcal Hhx​∈H with hx(x)=K+1h_x(x)=K+1hx​(x)=K+1. ϕ\phiϕ maps ID labels to 111 and K+1K+1K+1 to 222, ϕ∘H={ϕ∘h:h∈H}\phi\circ\mathcal H=\{\phi\circ h:h\in\mathcal H\}ϕ∘H={ϕ∘h:h∈H}, and VCdim{\rm VCdim}VCdim is the largest size of a finite set on which a binary class realises every labelling (∞\infty∞ if unbounded). 9. Finite discrete domains and Hin∙Hb\mathcal H^{\rm in}\bullet\mathcal H^{\rm b}Hin∙Hb. A domain is finite discrete if DXIYID_{X_{\rm I}Y_{\rm I}}DXI​YI​​ and DXOD_{X_{\rm O}}DXO​​ are concentrated on finite sets. For Hin⊆{X→Y}\mathcal H^{\rm in}\subseteq\{\mathcal X\to\mathcal Y\}Hin⊆{X→Y} and Hb⊆{X→{1,2}}\mathcal H^{\rm b}\subseteq\{\mathcal X\to\{1,2\}\}Hb⊆{X→{1,2}}, Hin∙Hb\mathcal H^{\rm in}\bullet\mathcal H^{\rm b}Hin∙Hb consists of the hhh with h(x)=hin(x)h(x)=h^{\rm in}(x)h(x)=hin(x) if hb(x)=1h^{\rm b}(x)=1hb(x)=1 and h(x)=K+1h(x)=K+1h(x)=K+1 otherwise, for some hin∈Hinh^{\rm in}\in\mathcal H^{\rm in}hin∈Hin, hb∈Hbh^{\rm b}\in\mathcal H^{\rm b}hb∈Hb (eq. 4).

Formalization Note The ID label i∈{1,…,K}i\in\{1,\dots,K\}i∈{1,…,K} is Fin.castSucc (i-1) in Fin (K+1) and the OOD label is Fin.last K; the binary labels 1,21,21,2 are 0,10,10,1 in Fin 2. A domain is stored as the triple (DXIYI,DXO,πout)(D_{X_{\rm I}Y_{\rm I}},D_{X_{\rm O}},\pi^{\rm out})(DXI​YI​​,DXO​​,πout), because RDoutR^{\rm out}_DRDout​ and DXYαD^\alpha_{XY}DXYα​ depend on DXOD_{X_{\rm O}}DXO​​ even when πout=0\pi^{\rm out}=0πout=0. Risks take values in [0,∞][0,\infty][0,∞] (they are finite because ℓ\ellℓ is bounded and the measures are probability measures). In Definitions 1-2 the map S↦RD(A(S))S\mapsto R_D(\mathbf A(S))S↦RD​(A(S)) (resp. RDα(A(S))R^\alpha_D(\mathbf A(S))RDα​(A(S))) is required to be almost-everywhere measurable, so that the expectation is defined. Supports are topological supports in X\mathcal XX. All infima are taken in [0,∞][0,\infty][0,∞].

Definition code
import Mathlib

/-!
Fang, Li, Lu, Dong, Han and Liu, *Is Out-of-Distribution Detection Learnable?*, NeurIPS 2022,
arXiv:2210.14707v3: domains, risks, learnability, domain spaces, conditions and assumptions of
Sections 2-5 and Appendices D-J.

Conventions. The feature space is a measurable space `X` (in every statement, a subset of
`ℝ^d` with its Borel structure). The label space `𝒴_all = {1, …, K+1}` is `Fin (K + 1)`: the
in-distribution (ID) label `i ∈ {1, …, K}` is `Fin.castSucc (i - 1)` and the out-of-distribution
(OOD) label `K + 1` is `Fin.last K`. ID samples are labelled by `Fin K`.
-/

open MeasureTheory Filter Topology
open scoped ENNReal NNReal

noncomputable section

namespace OODLearnable

variable {X : Type*} [MeasurableSpace X] {K : ℕ}

/-- Section 2, "Loss and Risks": a loss `ℓ : 𝒴_all × 𝒴_all → ℝ_{≥0}` with `ℓ(y₁, y₂) = 0` if and
only if `y₁ = y₂`. -/
def IsOODLoss (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) : Prop :=
  ∀ y₁ y₂, ℓ y₁ y₂ = 0 ↔ y₁ = y₂

/-- Section 2: a domain `D_XY = (1 - π^out) D_{X_I Y_I} + π^out D_{X_O Y_O}`, recorded as its ID
joint distribution `D_{X_I Y_I}` on `X × {1, …, K}`, its OOD distribution `D_{X_O}` on `X` (all OOD
data carry the label `K + 1`) and its class-prior `π^out ∈ [0, 1)`. -/
structure Domain (X : Type*) [MeasurableSpace X] (K : ℕ) where
  /-- The ID joint distribution `D_{X_I Y_I}`. -/
  DI : ProbabilityMeasure (X × Fin K)
  /-- The OOD marginal distribution `D_{X_O}`. -/
  DO : ProbabilityMeasure X
  /-- The class-prior probability `π^out ∈ [0, 1)`. -/
  piOut : Set.Ico (0 : ℝ) 1

/-- Section 2: the ID marginal distribution `D_{X_I}`. -/
def marginalIn (D : Domain X K) : Measure X :=
  (D.DI : Measure (X × Fin K)).map Prod.fst

/-- Definition 3 (Section 3): `D^α_XY = (1 - α) D_{X_I Y_I} + α D_{X_O Y_O}` for `α ∈ [0, 1)`. -/
def withPrior (D : Domain X K) (α : Set.Ico (0 : ℝ) 1) : Domain X K :=
  { D with piOut := α }

/-- Section 2: the ID risk `R^in_D(h) = E_{(x,y)∼D_{X_I Y_I}} ℓ(h(x), y)`. -/
def riskIn (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (D : Domain X K) (h : X → Fin (K + 1)) : ℝ≥0∞ :=
  ∫⁻ p, (ℓ (h p.1) (Fin.castSucc p.2) : ℝ≥0∞) ∂(D.DI : Measure (X × Fin K))

/-- Section 2: the OOD risk `R^out_D(h) = E_{x∼D_{X_O}} ℓ(h(x), K + 1)`. -/
def riskOut (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (D : Domain X K) (h : X → Fin (K + 1)) :
    ℝ≥0∞ :=
  ∫⁻ x, (ℓ (h x) (Fin.last K) : ℝ≥0∞) ∂(D.DO : Measure X)

/-- Section 2: the `α`-risk `R^α_D(h) = (1 - α) R^in_D(h) + α R^out_D(h)`, `α ∈ [0, 1]`. -/
def alphaRisk (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (D : Domain X K) (α : ℝ)
    (h : X → Fin (K + 1)) : ℝ≥0∞ :=
  ENNReal.ofReal (1 - α) * riskIn ℓ D h + ENNReal.ofReal α * riskOut ℓ D h

/-- Eq. (1) (Section 2): the risk `R_D(h) = E_{(x,y)∼D_XY} ℓ(h(x), y)`, which equals
`(1 - π^out) R^in_D(h) + π^out R^out_D(h)`. -/
def risk (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (D : Domain X K) (h : X → Fin (K + 1)) : ℝ≥0∞ :=
  alphaRisk ℓ D D.piOut h

/-- Definition 1, footnote 2 (Section 2): an algorithm maps a training sample
`S ∈ (X × 𝒴)^n` to a hypothesis function (only sample sizes `n ≥ 1` are used). -/
abbrev Algorithm (X : Type*) (K : ℕ) : Type _ :=
  (n : ℕ) → (Fin n → X × Fin K) → X → Fin (K + 1)

/-- Section 2: the law `D^n_{X_I Y_I}` of an i.i.d. training sample of size `n`. -/
def sampleMeasure (D : Domain X K) (n : ℕ) : Measure (Fin n → X × Fin K) :=
  Measure.pi fun _ : Fin n => (D.DI : Measure (X × Fin K))

/-- Definition 1 (Section 2), eq. (2): the algorithm `A` takes values in `H` and is consistent
with respect to the domain space `𝒟` with the monotonically decreasing sequence `ε → 0`:
`E_{S∼D^n_{X_I Y_I}} R_D(A(S)) ≤ inf_{h∈H} R_D(h) + ε(n)` for every `D ∈ 𝒟` and `n ≥ 1`. The
expectation is required to be defined, i.e. `S ↦ R_D(A(S))` is a.e.-measurable. -/
def IsConsistent (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) (A : Algorithm X K) (ε : ℕ → ℝ) : Prop :=
  (∀ n, 1 ≤ n → ∀ S, A n S ∈ H) ∧ Antitone ε ∧ Tendsto ε atTop (𝓝 0) ∧
    ∀ D ∈ 𝒟, ∀ n, 1 ≤ n →
      AEMeasurable (fun S => risk ℓ D (A n S)) (sampleMeasure D n) ∧
      ∫⁻ S, risk ℓ D (A n S) ∂(sampleMeasure D n) ≤
        (⨅ h ∈ H, risk ℓ D h) + ENNReal.ofReal (ε n)

/-- Definition 1 (Section 2): OOD detection is learnable in `𝒟` for `H`. -/
def IsLearnable (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) : Prop :=
  ∃ (A : Algorithm X K) (ε : ℕ → ℝ), IsConsistent ℓ 𝒟 H A ε

/-- Definition 2 (Section 2), eq. (3): OOD detection is strongly learnable in `𝒟` for `H`: one
algorithm and one sequence `ε` give `E_S R^α_D(A(S)) ≤ inf_{h∈H} R^α_D(h) + ε(n)` for every
`α ∈ [0, 1]`, every `D ∈ 𝒟` and every `n ≥ 1` (each expectation being defined). -/
def IsStronglyLearnable (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) : Prop :=
  ∃ (A : Algorithm X K) (ε : ℕ → ℝ),
    (∀ n, 1 ≤ n → ∀ S, A n S ∈ H) ∧ Antitone ε ∧ Tendsto ε atTop (𝓝 0) ∧
      ∀ D ∈ 𝒟, ∀ α ∈ Set.Icc (0 : ℝ) 1, ∀ n, 1 ≤ n →
        AEMeasurable (fun S => alphaRisk ℓ D α (A n S)) (sampleMeasure D n) ∧
        ∫⁻ S, alphaRisk ℓ D α (A n S) ∂(sampleMeasure D n) ≤
          (⨅ h ∈ H, alphaRisk ℓ D α h) + ENNReal.ofReal (ε n)

/-- Theorem 8 (Section 5): OOD detection is learnable in `𝒟` for `H` with a learning rate
`ε_cons(n) = O(r(n))`. -/
def IsLearnableAtRate (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) (r : ℕ → ℝ) : Prop :=
  ∃ (A : Algorithm X K) (ε : ℕ → ℝ) (C : ℝ), IsConsistent ℓ 𝒟 H A ε ∧ ∀ n, 1 ≤ n → ε n ≤ C * r n

/-- Definition 3 (Section 3): `𝒟` is a priori-unknown space: `D^α_XY ∈ 𝒟` for every `D_XY ∈ 𝒟`
and every `α ∈ [0, 1)`. -/
def IsPriorUnknown (𝒟 : Set (Domain X K)) : Prop :=
  ∀ D ∈ 𝒟, ∀ α : Set.Ico (0 : ℝ) 1, withPrior D α ∈ 𝒟

/-- Theorem 1 (Section 3): `𝒟' = {D^α_XY : D_XY ∈ 𝒟, α ∈ [0, 1)}`. -/
def priorClosure (𝒟 : Set (Domain X K)) : Set (Domain X K) :=
  {D' | ∃ D ∈ 𝒟, ∃ α : Set.Ico (0 : ℝ) 1, D' = withPrior D α}

/-- Section 3: the single-distribution space `𝒟^{D_XY} = {D^α_XY : α ∈ [0, 1)}`. -/
def singleSpace (D : Domain X K) : Set (Domain X K) :=
  Set.range (withPrior D)

/-- Section 3: the total space `𝒟^all`, which consists of all domains. -/
def totalSpace : Set (Domain X K) :=
  Set.univ

/-- Section 3: the separate space `𝒟^s` of all domains with `supp D_{X_O} ∩ supp D_{X_I} = ∅`
(supports in the topology of the feature space). -/
def separateSpace [TopologicalSpace X] : Set (Domain X K) :=
  {D | Disjoint (marginalIn D).support (D.DO : Measure X).support}

/-- Section 3: the finite-ID-distribution space `𝒟^F`: a priori-unknown space containing only
finitely many distinct ID joint distributions `D_{X_I Y_I}`. -/
def IsFiniteIDSpace (𝒟 : Set (Domain X K)) : Prop :=
  IsPriorUnknown 𝒟 ∧ (Domain.DI '' 𝒟).Finite

/-- Condition 1 (Linear Condition, Section 4): for every `D_XY ∈ 𝒟` and `α ∈ [0, 1)`,
`inf_{h∈H} R^α_D(h) = (1 - α) inf_{h∈H} R^in_D(h) + α inf_{h∈H} R^out_D(h)`. -/
def LinearCondition (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) : Prop :=
  ∀ D ∈ 𝒟, ∀ α ∈ Set.Ico (0 : ℝ) 1,
    (⨅ h ∈ H, alphaRisk ℓ D α h) =
      ENNReal.ofReal (1 - α) * (⨅ h ∈ H, riskIn ℓ D h) +
        ENNReal.ofReal α * (⨅ h ∈ H, riskOut ℓ D h)

/-- Definition 4 (Section 4): `D_XY` has overlap between ID and OOD distributions: there is a
σ-finite measure `μ̃` with `D_{X_I}, D_{X_O} ≪ μ̃` such that `μ̃(A_overlap) > 0`, where
`A_overlap = {x : f_I(x) > 0 and f_O(x) > 0}` and `f_I = dD_{X_I}/dμ̃`, `f_O = dD_{X_O}/dμ̃`. -/
def HasOverlap (D : Domain X K) : Prop :=
  ∃ μ : Measure X, SigmaFinite μ ∧ marginalIn D ≪ μ ∧ (D.DO : Measure X) ≪ μ ∧
    0 < μ {x | 0 < (marginalIn D).rnDeriv μ x ∧ 0 < (D.DO : Measure X).rnDeriv μ x}

/-- Assumption 1 (Section 4): `H` is separate for OOD data: every `x ∈ X` is sent to the OOD
label `K + 1` by some `h_x ∈ H`. -/
def SeparateForOOD (H : Set (X → Fin (K + 1))) : Prop :=
  ∀ x, ∃ h ∈ H, h x = Fin.last K

/-- Theorems 4 and 5 (Section 4): the map `φ` sending the ID labels to `1` and the OOD label to
`2`, written with values `0` (ID) and `1` (OOD) in `Fin 2`. -/
def phi (K : ℕ) (y : Fin (K + 1)) : Fin 2 :=
  if y = Fin.last K then 1 else 0

/-- Theorems 4 and 5 (Section 4): the binary hypothesis space `φ ∘ H = {φ ∘ h : h ∈ H}`. -/
def phiComp (H : Set (X → Fin (K + 1))) : Set (X → Fin 2) :=
  (fun h => phi K ∘ h) '' H

/-- Theorem 5 (Section 4): a finite set `C ⊆ X` is shattered by a class `F` of binary
functions: every labelling of `C` is realised by some `f ∈ F`. -/
def VCShatters {X : Type*} (F : Set (X → Fin 2)) (C : Finset X) : Prop :=
  ∀ g : X → Fin 2, ∃ f ∈ F, ∀ x ∈ C, f x = g x

/-- Theorem 5 (Section 4): the VC dimension of a class of binary functions, the largest size of
a shattered finite set (`⊤` if there is none). -/
def vcDim {X : Type*} (F : Set (X → Fin 2)) : ℕ∞ :=
  ⨆ (C : Finset X) (_ : VCShatters F C), (C.card : ℕ∞)

/-- Lemma 4 (Appendix H): a finite discrete domain: `D_{X_I Y_I}` and `D_{X_O}` are concentrated
on finite sets. -/
def IsFiniteDiscrete (D : Domain X K) : Prop :=
  (∃ s : Finset (X × Fin K), (D.DI : Measure (X × Fin K)) (↑s)ᶜ = 0) ∧
    ∃ t : Finset X, (D.DO : Measure X) (↑t)ᶜ = 0

/-- Eq. (4) (Section 5): `H^in • H^b`, the hypotheses `h` built from `h^in ∈ H^in` and
`h^b ∈ H^b` by `h(x) = h^in(x)` if `h^b(x) = 1` (ID) and `h(x) = K + 1` otherwise. The binary
labels `1` (ID) and `2` (OOD) are written `0` and `1` in `Fin 2`. -/
def dotSpace (Hin : Set (X → Fin K)) (Hb : Set (X → Fin 2)) : Set (X → Fin (K + 1)) :=
  {h | ∃ hin ∈ Hin, ∃ hb ∈ Hb,
    ∀ x, h x = if hb x = 0 then Fin.castSucc (hin x) else Fin.last K}

/-- Condition 2 (Section 5): `ℓ(y₂, y₁) ≤ ℓ(K + 1, y₁)` for all ID labels `y₁, y₂`. -/
def LossCondition2 (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) : Prop :=
  ∀ y₁ y₂ : Fin K, ℓ (Fin.castSucc y₂) (Fin.castSucc y₁) ≤ ℓ (Fin.last K) (Fin.castSucc y₁)

/-- Condition 3 (Compatibility, Section 5), with the ID-consistency classes of Definition 5:
for every `D'_XY ∈ 𝒟` and `ε > 0` there is `h_ε ∈ H` which, for every `D_XY ∈ 𝒟` with
`D_{X_I Y_I} = D'_{X_I Y_I}`, satisfies `R^out_D(h_ε) ≤ inf_{h∈H} R^out_D(h) + ε` and
`R^in_D(h_ε) ≤ inf_{h∈H} R^in_D(h) + ε`. -/
def Compatibility (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (𝒟 : Set (Domain X K))
    (H : Set (X → Fin (K + 1))) : Prop :=
  ∀ D' ∈ 𝒟, ∀ ε : ℝ, 0 < ε → ∃ hε ∈ H, ∀ D ∈ 𝒟, D.DI = D'.DI →
    riskOut ℓ D hε ≤ (⨅ h ∈ H, riskOut ℓ D h) + ENNReal.ofReal ε ∧
      riskIn ℓ D hε ≤ (⨅ h ∈ H, riskIn ℓ D h) + ENNReal.ofReal ε

end OODLearnable
Source
Fang, Li, Lu, Dong, Han and Liu, Is Out-of-Distribution Detection Learnable?, NeurIPS 2022, arXiv:2210.14707v3, Section 2 (Definitions 1-2, eqs. (1)-(3)), Section 3 (Definition 3, domain spaces), Section 4 (Condition 1, Definition 4, Assumption 1), Section 5 (eq. (4), Condition 2, Definition 5, Condition 3), Appendix H (Lemma 4), pp. 2-7, 33
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Common setting (applies to every declaration below). XXX is an arbitrary set with a σ-algebra. It is not required to be a subset of Rd\mathbb R^dRd, and no topology is assumed unless stated. K≥0K \ge 0K≥0 is a natural number, and K=0K = 0K=0 is allowed.

  • The full label set is Yall={1,…,K+1}\mathcal Y_{\mathrm{all}} = \{1,\dots,K+1\}Yall​={1,…,K+1}.
  • The "ID labels" are {1,…,K}\{1,\dots,K\}{1,…,K}, viewed inside Yall\mathcal Y_{\mathrm{all}}Yall​.
  • The "OOD label" is K+1K+1K+1.
  • Binary labels are the two-element set {0,1}\{0,1\}{0,1}.

Every product X×{1,…,K}X \times \{1,\dots,K\}X×{1,…,K} carries the product σ-algebra, with the discrete σ-algebra on the finite factor. Throughout:

  • integrals ∫∗\int^{*}∫∗ are lower Lebesgue integrals of [0,∞][0,\infty][0,∞]-valued functions, which are defined even when the integrand is not measurable;
  • infima over an empty index set equal +∞+\infty+∞;
  • max⁡(t,0)\max(t,0)max(t,0) is written t+t^{+}t+;
  • in [0,∞][0,\infty][0,∞] the convention 0⋅∞=00\cdot\infty = 00⋅∞=0 holds.

IsOODLoss. For a function ℓ:Yall×Yall→[0,∞)\ell : \mathcal Y_{\mathrm{all}} \times \mathcal Y_{\mathrm{all}} \to [0,\infty)ℓ:Yall​×Yall​→[0,∞), this is the property

∀ y1,y2∈Yall:ℓ(y1,y2)=0  ⟺  y1=y2.\forall\, y_1, y_2 \in \mathcal Y_{\mathrm{all}}:\quad \ell(y_1,y_2) = 0 \iff y_1 = y_2 .∀y1​,y2​∈Yall​:ℓ(y1​,y2​)=0⟺y1​=y2​.

No symmetry, triangle inequality or other property is required. In all risk definitions below the first argument is the predicted label and the second is the true label.

Domain. A domain DDD is a triple (DXIYI, DXO, πout)(D_{X_IY_I},\, D_{X_O},\, \pi^{\mathrm{out}})(DXI​YI​​,DXO​​,πout) of three independent pieces of data:

  • DXIYID_{X_IY_I}DXI​YI​​ is a probability measure on X×{1,…,K}X \times \{1,\dots,K\}X×{1,…,K};
  • DXOD_{X_O}DXO​​ is a probability measure on XXX;
  • πout\pi^{\mathrm{out}}πout is a real number with 0≤πout<10 \le \pi^{\mathrm{out}} < 10≤πout<1.

No mixture measure on X×YallX \times \mathcal Y_{\mathrm{all}}X×Yall​ is formed or stored, and no relation between the three components is imposed. Two domains are equal exactly when all three components are equal.

When K=0K = 0K=0, the space X×{1,…,K}X \times \{1,\dots,K\}X×{1,…,K} is empty, so it carries no probability measure and there are no domains at all. The same holds when XXX is empty.

marginalIn. For a domain DDD, DXID_{X_I}DXI​​ is the push-forward of DXIYID_{X_IY_I}DXI​YI​​ under the projection (x,y)↦x(x,y) \mapsto x(x,y)↦x:

DXI(B)=DXIYI(B×{1,…,K})D_{X_I}(B) = D_{X_IY_I}(B \times \{1,\dots,K\})DXI​​(B)=DXI​YI​​(B×{1,…,K})

for measurable B⊆XB \subseteq XB⊆X. It is returned as a general measure on XXX, though it has total mass 111.

withPrior. For a domain DDD and a real α∈[0,1)\alpha \in [0,1)α∈[0,1), DαD^{\alpha}Dα is the domain with the same DXIYID_{X_IY_I}DXI​YI​​ and DXOD_{X_O}DXO​​ as DDD, and with πout\pi^{\mathrm{out}}πout replaced by α\alphaα.

riskIn. For a loss ℓ\ellℓ, a domain DDD and an arbitrary function h:X→Yallh : X \to \mathcal Y_{\mathrm{all}}h:X→Yall​ (no measurability required):

RDin(h)=∫X×{1,…,K}∗ℓ(h(x), y) dDXIYI(x,y)  ∈[0,∞].R^{\mathrm{in}}_D(h) = \int^{*}_{X\times\{1,\dots,K\}} \ell\big(h(x),\, y\big)\, dD_{X_IY_I}(x,y) \;\in [0,\infty].RDin​(h)=∫X×{1,…,K}∗​ℓ(h(x),y)dDXI​YI​​(x,y)∈[0,∞].

Here the ID label yyy is regarded as an element of Yall\mathcal Y_{\mathrm{all}}Yall​. Because ℓ\ellℓ takes only finitely many values and DXIYID_{X_IY_I}DXI​YI​​ is a probability measure, this is at most max⁡ℓ\max \ellmaxℓ, and so finite.

riskOut. With the same data:

RDout(h)=∫X∗ℓ(h(x), K+1) dDXO(x)  ∈[0,∞).R^{\mathrm{out}}_D(h) = \int^{*}_X \ell\big(h(x),\, K+1\big)\, dD_{X_O}(x) \;\in [0,\infty).RDout​(h)=∫X∗​ℓ(h(x),K+1)dDXO​​(x)∈[0,∞).

This is again a lower integral, with hhh arbitrary.

alphaRisk. For a loss ℓ\ellℓ, a domain DDD, an arbitrary real number α\alphaα and a function hhh:

RDα(h)=(1−α)+ RDin(h)+α+ RDout(h).R^{\alpha}_D(h) = (1-\alpha)^{+}\, R^{\mathrm{in}}_D(h) + \alpha^{+}\, R^{\mathrm{out}}_D(h).RDα​(h)=(1−α)+RDin​(h)+α+RDout​(h).
  • For α∈[0,1]\alpha \in [0,1]α∈[0,1] this is (1−α)RDin(h)+αRDout(h)(1-\alpha)R^{\mathrm{in}}_D(h) + \alpha R^{\mathrm{out}}_D(h)(1−α)RDin​(h)+αRDout​(h).
  • For α>1\alpha > 1α>1 it equals αRDout(h)\alpha R^{\mathrm{out}}_D(h)αRDout​(h).
  • For α<0\alpha < 0α<0 it equals (1−α)RDin(h)(1-\alpha) R^{\mathrm{in}}_D(h)(1−α)RDin​(h).

The component πout\pi^{\mathrm{out}}πout of DDD is not used.

risk. RD(h)=RDπout(h)R_D(h) = R^{\pi^{\mathrm{out}}}_D(h)RD​(h)=RDπout​(h), the α\alphaα-risk at α\alphaα equal to the domain's own prior. Since πout∈[0,1)\pi^{\mathrm{out}} \in [0,1)πout∈[0,1):

RD(h)=(1−πout) RDin(h)+πout RDout(h).R_D(h) = (1-\pi^{\mathrm{out}})\, R^{\mathrm{in}}_D(h) + \pi^{\mathrm{out}}\, R^{\mathrm{out}}_D(h).RD​(h)=(1−πout)RDin​(h)+πoutRDout​(h).

No measure on X×YallX \times \mathcal Y_{\mathrm{all}}X×Yall​ is involved.

Algorithm. An algorithm AAA is any assignment that sends each n∈Nn \in \mathbb Nn∈N (including n=0n = 0n=0) and each finite sequence S=((x1,y1),…,(xn,yn))S = ((x_1,y_1),\dots,(x_n,y_n))S=((x1​,y1​),…,(xn​,yn​)) in X×{1,…,K}X \times \{1,\dots,K\}X×{1,…,K} to a function An(S):X→YallA_n(S) : X \to \mathcal Y_{\mathrm{all}}An​(S):X→Yall​. There is no measurability or computability requirement. Training samples contain only ID-labelled points.

sampleMeasure. For a domain DDD and n∈Nn \in \mathbb Nn∈N, DXIYInD^n_{X_IY_I}DXI​YI​n​ is the nnn-fold product measure of DXIYID_{X_IY_I}DXI​YI​​ on (X×{1,…,K})n(X \times \{1,\dots,K\})^n(X×{1,…,K})n, i.e. the law of nnn i.i.d. draws. For n=0n = 0n=0 it is the unit point mass on the empty sequence.

IsConsistent. Fix a loss ℓ\ellℓ, a set of domains D\mathcal DD, a set of functions H⊆{h:X→Yall}H \subseteq \{h : X \to \mathcal Y_{\mathrm{all}}\}H⊆{h:X→Yall​}, an algorithm AAA and a real sequence ε:N→R\varepsilon : \mathbb N \to \mathbb Rε:N→R. The property is the conjunction of four conditions:

  1. An(S)∈HA_n(S) \in HAn​(S)∈H for every n≥1n \ge 1n≥1 and every sample SSS of size nnn. Nothing is required at n=0n = 0n=0.
  2. ε\varepsilonε is non-increasing: m≤n⇒ε(n)≤ε(m)m \le n \Rightarrow \varepsilon(n) \le \varepsilon(m)m≤n⇒ε(n)≤ε(m). This holds on all of N\mathbb NN, including ε(0)\varepsilon(0)ε(0).
  3. ε(n)→0\varepsilon(n) \to 0ε(n)→0 as n→∞n \to \inftyn→∞. Together with condition 2 this forces ε≥0\varepsilon \ge 0ε≥0.
  4. For every D∈DD \in \mathcal DD∈D and every n≥1n \ge 1n≥1, both of the following hold:
    • the map S↦RD(An(S))S \mapsto R_D(A_n(S))S↦RD​(An​(S)) agrees DXIYInD^n_{X_IY_I}DXI​YI​n​-almost everywhere with a measurable function;
    • the expected risk satisfies
∫∗RD(An(S)) dDXIYIn(S)  ≤  inf⁡h∈HRD(h)+ε(n)+.\int^{*} R_D\big(A_n(S)\big)\, dD^n_{X_IY_I}(S) \;\le\; \inf_{h\in H} R_D(h) + \varepsilon(n)^{+}.∫∗RD​(An​(S))dDXI​YI​n​(S)≤h∈Hinf​RD​(h)+ε(n)+.

Degenerate cases:

  • If XXX is empty or K=0K = 0K=0, there are no samples of size n≥1n \ge 1n≥1 and no domains. Conditions 1 and 4 are then vacuous, even for H=∅H = \emptysetH=∅.
  • If D=∅\mathcal D = \emptysetD=∅, condition 4 is vacuous.

IsLearnable. There exist an algorithm AAA and a real sequence ε\varepsilonε such that AAA is consistent with respect to ℓ\ellℓ, D\mathcal DD, HHH and ε\varepsilonε, as defined above.

IsStronglyLearnable. There exist a single algorithm AAA and a single real sequence ε\varepsilonε satisfying conditions 1–3 of IsConsistent, together with the following:

  • for every D∈DD \in \mathcal DD∈D, every real α∈[0,1]\alpha \in [0,1]α∈[0,1] (closed interval, so α=1\alpha = 1α=1 is included) and every n≥1n \ge 1n≥1, the map S↦RDα(An(S))S \mapsto R^{\alpha}_D(A_n(S))S↦RDα​(An​(S)) is DXIYInD^n_{X_IY_I}DXI​YI​n​-a.e. measurable;
  • and
∫∗RDα(An(S)) dDXIYIn(S)  ≤  inf⁡h∈HRDα(h)+ε(n)+.\int^{*} R^{\alpha}_D\big(A_n(S)\big)\, dD^n_{X_IY_I}(S) \;\le\; \inf_{h\in H} R^{\alpha}_D(h) + \varepsilon(n)^{+}.∫∗RDα​(An​(S))dDXI​YI​n​(S)≤h∈Hinf​RDα​(h)+ε(n)+.

The same AAA and ε\varepsilonε must work for all DDD and all α\alphaα simultaneously. The domain's own πout\pi^{\mathrm{out}}πout plays no role.

IsLearnableAtRate. Given additionally an arbitrary real sequence r:N→Rr : \mathbb N \to \mathbb Rr:N→R, there exist an algorithm AAA, a real sequence ε\varepsilonε and a real constant CCC such that:

  • AAA is consistent with respect to ℓ\ellℓ, D\mathcal DD, HHH and ε\varepsilonε;
  • ε(n)≤C r(n)\varepsilon(n) \le C\, r(n)ε(n)≤Cr(n) for every n≥1n \ge 1n≥1.

There is no absolute value, and no sign constraint on CCC or rrr. Because ε≥0\varepsilon \ge 0ε≥0, this in effect requires C r(n)≥0C\, r(n) \ge 0Cr(n)≥0 for all n≥1n \ge 1n≥1.

IsPriorUnknown. A set of domains D\mathcal DD has this property if for every D∈DD \in \mathcal DD∈D and every real α∈[0,1)\alpha \in [0,1)α∈[0,1), the domain DαD^{\alpha}Dα (same ID and OOD measures, prior replaced by α\alphaα) also lies in D\mathcal DD. The empty set qualifies.

priorClosure. For a set of domains D\mathcal DD:

D′={ Dα:D∈D, α∈[0,1) }.\mathcal D' = \{\, D^{\alpha} : D \in \mathcal D,\ \alpha \in [0,1) \,\}.D′={Dα:D∈D, α∈[0,1)}.

singleSpace. For a domain DDD:

DD={ Dα:α∈[0,1) },\mathcal D^{D} = \{\, D^{\alpha} : \alpha \in [0,1) \,\},DD={Dα:α∈[0,1)},

the set of all domains sharing DDD's ID and OOD measures, with any prior in [0,1)[0,1)[0,1).

totalSpace. Dall\mathcal D^{\mathrm{all}}Dall is the set of all domains over XXX and KKK.

separateSpace. This requires an additional topology on XXX. That topology is arbitrary and is not assumed to be related to the σ-algebra; in particular it need not generate it. Ds\mathcal D^{s}Ds is the set of domains DDD with

supp⁡DXI∩supp⁡DXO=∅.\operatorname{supp} D_{X_I} \cap \operatorname{supp} D_{X_O} = \emptyset.suppDXI​​∩suppDXO​​=∅.

The support of a measure μ\muμ is the set of points xxx such that every open neighbourhood of xxx that is measurable... more precisely, every open neighbourhood of xxx has positive μ\muμ-measure. The prior πout\pi^{\mathrm{out}}πout is unrestricted.

IsFiniteIDSpace. A set of domains D\mathcal DD has this property if both:

  • it is prior-unknown (see IsPriorUnknown);
  • the set {DXIYI:D∈D}\{D_{X_IY_I} : D \in \mathcal D\}{DXI​YI​​:D∈D} of ID joint measures occurring in D\mathcal DD is finite.

No finiteness is imposed on the OOD measures. The empty set qualifies.

LinearCondition. For ℓ\ellℓ, D\mathcal DD and HHH: for every D∈DD \in \mathcal DD∈D and every real α∈[0,1)\alpha \in [0,1)α∈[0,1),

inf⁡h∈HRDα(h)=(1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDout(h).\inf_{h\in H} R^{\alpha}_D(h) = (1-\alpha)\inf_{h\in H} R^{\mathrm{in}}_D(h) + \alpha \inf_{h\in H} R^{\mathrm{out}}_D(h).h∈Hinf​RDα​(h)=(1−α)h∈Hinf​RDin​(h)+αh∈Hinf​RDout​(h).

The equation is read in [0,∞][0,\infty][0,∞]. If H=∅H = \emptysetH=∅, both sides equal +∞+\infty+∞ (with 0⋅∞=00\cdot\infty = 00⋅∞=0 at α=0\alpha = 0α=0), so the condition holds for every D\mathcal DD.

HasOverlap. A domain DDD has overlap if there exists a σ-finite measure μ\muμ on XXX with DXI≪μD_{X_I} \ll \muDXI​​≪μ and DXO≪μD_{X_O} \ll \muDXO​​≪μ such that

μ({x:fI(x)>0 and fO(x)>0})>0.\mu\big(\{x : f_I(x) > 0 \text{ and } f_O(x) > 0\}\big) > 0.μ({x:fI​(x)>0 and fO​(x)>0})>0.

Here fIf_IfI​ and fOf_OfO​ are specific fixed versions of the Radon–Nikodym derivatives dDXI/dμdD_{X_I}/d\mudDXI​​/dμ and dDXO/dμdD_{X_O}/d\mudDXO​​/dμ (the library's canonical choice). The prior πout\pi^{\mathrm{out}}πout and the labels play no role.

SeparateForOOD. A set HHH of functions X→YallX \to \mathcal Y_{\mathrm{all}}X→Yall​ has this property if for every x∈Xx \in Xx∈X there exists h∈Hh \in Hh∈H with h(x)=K+1h(x) = K+1h(x)=K+1. Different points may use different hhh. If XXX is empty, this holds for every HHH, including H=∅H = \emptysetH=∅.

phi. The map ϕ:Yall→{0,1}\phi : \mathcal Y_{\mathrm{all}} \to \{0,1\}ϕ:Yall​→{0,1} is defined by

ϕ(y)={1y=K+1,0y∈{1,…,K}.\phi(y) = \begin{cases} 1 & y = K+1, \\ 0 & y \in \{1,\dots,K\}. \end{cases}ϕ(y)={10​y=K+1,y∈{1,…,K}.​

So 000 means ID and 111 means OOD.

phiComp. For a set HHH of functions X→YallX \to \mathcal Y_{\mathrm{all}}X→Yall​:

ϕ∘H={ ϕ∘h:h∈H },\phi\circ H = \{\, \phi\circ h : h \in H \,\},ϕ∘H={ϕ∘h:h∈H},

a set of functions X→{0,1}X \to \{0,1\}X→{0,1}.

VCShatters. This is stated for an arbitrary set XXX (no σ-algebra needed), a set FFF of functions X→{0,1}X \to \{0,1\}X→{0,1} and a finite subset C⊆XC \subseteq XC⊆X. FFF shatters CCC if for every function g:X→{0,1}g : X \to \{0,1\}g:X→{0,1} there is some f∈Ff \in Ff∈F with f(x)=g(x)f(x) = g(x)f(x)=g(x) for all x∈Cx \in Cx∈C. The empty set is shattered exactly when FFF is non-empty.

vcDim. For FFF as above:

VC⁡(F)=sup⁡{ ∣C∣:C⊆X finite, F shatters C }  ∈{0,1,2,… }∪{∞}.\operatorname{VC}(F) = \sup\{\, |C| : C \subseteq X \text{ finite},\ F \text{ shatters } C \,\} \;\in \{0,1,2,\dots\}\cup\{\infty\}.VC(F)=sup{∣C∣:C⊆X finite, F shatters C}∈{0,1,2,…}∪{∞}.
  • The value is ∞\infty∞ if arbitrarily large finite sets are shattered.
  • The value is 000 if no finite set is shattered, which happens exactly when F=∅F = \emptysetF=∅, since the supremum of the empty set is 000.

IsFiniteDiscrete. A domain DDD is finite-discrete if both:

  • there is a finite set s⊆X×{1,…,K}s \subseteq X \times \{1,\dots,K\}s⊆X×{1,…,K} with DXIYI((X×{1,…,K})∖s)=0D_{X_IY_I}\big((X\times\{1,\dots,K\}) \setminus s\big) = 0DXI​YI​​((X×{1,…,K})∖s)=0;
  • there is a finite set t⊆Xt \subseteq Xt⊆X with DXO(X∖t)=0D_{X_O}(X \setminus t) = 0DXO​​(X∖t)=0.

The prior is unrestricted.

dotSpace. This takes a set HinH^{\mathrm{in}}Hin of functions X→{1,…,K}X \to \{1,\dots,K\}X→{1,…,K} and a set HbH^{b}Hb of functions X→{0,1}X \to \{0,1\}X→{0,1}. Hin∙HbH^{\mathrm{in}} \bullet H^{b}Hin∙Hb is the set of all h:X→Yallh : X \to \mathcal Y_{\mathrm{all}}h:X→Yall​ for which there exist hin∈Hinh^{\mathrm{in}} \in H^{\mathrm{in}}hin∈Hin and hb∈Hbh^{b} \in H^{b}hb∈Hb with, for all xxx,

h(x)={hin(x)if hb(x)=0,K+1if hb(x)=1.h(x) = \begin{cases} h^{\mathrm{in}}(x) & \text{if } h^{b}(x) = 0, \\ K+1 & \text{if } h^{b}(x) = 1. \end{cases}h(x)={hin(x)K+1​if hb(x)=0,if hb(x)=1.​

The result is empty if either HinH^{\mathrm{in}}Hin or HbH^{b}Hb is empty.

LossCondition2. For a loss ℓ\ellℓ: for all ID labels y1,y2∈{1,…,K}y_1, y_2 \in \{1,\dots,K\}y1​,y2​∈{1,…,K},

ℓ(y2,y1)≤ℓ(K+1,y1).\ell(y_2, y_1) \le \ell(K+1, y_1).ℓ(y2​,y1​)≤ℓ(K+1,y1​).

That is, predicting any ID label for a true ID label y1y_1y1​ costs no more than predicting K+1K+1K+1. This includes y2=y1y_2 = y_1y2​=y1​, and it is vacuous when K=0K = 0K=0.

Compatibility. For ℓ\ellℓ, D\mathcal DD and HHH: for every D′∈DD' \in \mathcal DD′∈D and every real ε>0\varepsilon > 0ε>0, there exists a single hε∈Hh_\varepsilon \in Hhε​∈H such that, for every D∈DD \in \mathcal DD∈D with DXIYI=DXIYI′D_{X_IY_I} = D'_{X_IY_I}DXI​YI​​=DXI​YI​′​, both

RDout(hε)≤inf⁡h∈HRDout(h)+εR^{\mathrm{out}}_D(h_\varepsilon) \le \inf_{h\in H} R^{\mathrm{out}}_D(h) + \varepsilonRDout​(hε​)≤h∈Hinf​RDout​(h)+ε

and

RDin(hε)≤inf⁡h∈HRDin(h)+ε.R^{\mathrm{in}}_D(h_\varepsilon) \le \inf_{h\in H} R^{\mathrm{in}}_D(h) + \varepsilon .RDin​(hε​)≤h∈Hinf​RDin​(h)+ε.

The quantifier order is: hεh_\varepsilonhε​ is chosen before DDD ranges over all domains in D\mathcal DD sharing D′D'D′'s ID joint measure, with any OOD measure and any prior. This class includes D′D'D′ itself. If D\mathcal DD is non-empty and H=∅H = \emptysetH=∅, the condition fails; if D=∅\mathcal D = \emptysetD=∅, it holds vacuously.

Human review
  • Endorsed by Shuze Chen · Nov 23, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 23, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me