Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 7: multi-class OOD detection in the separate space with finite feature space

Proved
OODLearnable.multiclass_separate_learnable

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

impossibility-theoremslearnabilityood-detectionpac-learningvc-dimension

Let X⊆Rd\mathcal X\subseteq\mathbb R^dX⊆Rd be finite, let ℓ\ellℓ be a loss with ℓ(y1,y2)=0\ell(y_1,y_2)=0ℓ(y1​,y2​)=0 iff y1=y2y_1=y_2y1​=y2​ that satisfies Condition 2,

ℓ(y2,y1)≤ℓ(K+1,y1)for all y1,y2∈Y,\ell(y_2,y_1)\le\ell(K+1,y_1)\qquad\text{for all }y_1,y_2\in\mathcal Y,ℓ(y2​,y1​)≤ℓ(K+1,y1​)for all y1​,y2​∈Y,

let Hin\mathcal H^{\rm in}Hin be a nonempty set of functions X→Y\mathcal X\to\mathcal YX→Y, and let Hb\mathcal H^{\rm b}Hb be a set of functions X→{1,2}\mathcal X\to\{1,2\}X→{1,2} with Hall∖{hout}⊆Hb\mathcal H_{\rm all}\setminus\{h^{\rm out}\}\subseteq\mathcal H^{\rm b}Hall​∖{hout}⊆Hb (Hall\mathcal H_{\rm all}Hall​ all functions X→{1,2}\mathcal X\to\{1,2\}X→{1,2}, hout≡2h^{\rm out}\equiv2hout≡2). Then OOD detection is learnable in the separate space DXYs\mathscr D^s_{XY}DXYs​ for H=Hin∙Hb\mathcal H=\mathcal H^{\rm in}\bullet\mathcal H^{\rm b}H=Hin∙Hb.

Formalization Note The nonemptiness of Hin\mathcal H^{\rm in}Hin is implicit in the paper (for Hin=∅\mathcal H^{\rm in}=\emptysetHin=∅ and X≠∅\mathcal X\neq\emptysetX=∅ the space H\mathcal HH is empty and the claim fails). The binary labels 1,21,21,2 are 0,10,10,1 in Fin 2. The feature space is X⊆Rd\mathcal X\subseteq\mathbb R^dX⊆Rd with the Borel structure; every hypothesis in H\mathcal HH is assumed measurable (the paper's implicit convention, needed for the risks to be defined).

Preamble
import Mathlib
import Definitions.Def_OODLearnable_Basic

open MeasureTheory Filter Topology
open scoped ENNReal NNReal
Formal statement
namespace OODLearnable

theorem multiclass_separate_learnable {dim : ℕ} {𝒳 : Set (EuclideanSpace ℝ (Fin dim))}
    (h𝒳 : 𝒳.Finite) {K : ℕ} (ℓ : Fin (K + 1) → Fin (K + 1) → ℝ≥0) (hℓ : IsOODLoss ℓ)
    (Hin : Set (𝒳 → Fin K)) (hHin : Hin.Nonempty) (Hb : Set (𝒳 → Fin 2))
    (hHmeas : ∀ h ∈ dotSpace Hin Hb, Measurable h)
    (hHb : {g : 𝒳 → Fin 2 | g ≠ fun _ => 1} ⊆ Hb) (hC2 : LossCondition2 ℓ) :
    IsLearnable ℓ (separateSpace : Set (Domain 𝒳 K)) (dotSpace Hin Hb) := by sorry

end OODLearnable
Source
Fang, Li, Lu, Dong, Han and Liu, Is Out-of-Distribution Detection Learnable?, NeurIPS 2022, arXiv:2210.14707v3, Section 5, Theorem 7, eq. (4) and Condition 2, p. 7; proof in Appendix I.2, pp. 38-39
Read-back

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

Setting. The theorem is stated for the following data:

  • Ambient space. Fix a natural number d≥0d \ge 0d≥0 (possibly 000, in which case R0\mathbb{R}^0R0 is a single point). Let X⊆Rd\mathcal{X} \subseteq \mathbb{R}^dX⊆Rd be an arbitrary finite subset (possibly empty) of Euclidean space.
  • Structure on X\mathcal{X}X. X\mathcal{X}X carries the subspace topology and the subspace (trace) Borel σ-algebra. Because X\mathcal{X}X is finite, the topology is discrete and every subset of X\mathcal{X}X is measurable.
  • Labels. Fix K∈NK \in \mathbb{N}K∈N (possibly 000). The label set is {1,…,K+1}\{1,\dots,K+1\}{1,…,K+1}, where 1,…,K1,\dots,K1,…,K are the "ID" labels and K+1K+1K+1 is the "OOD" label.
  • Loss. Let ℓ:{1,…,K+1}2→[0,∞)\ell:\{1,\dots,K+1\}^2\to[0,\infty)ℓ:{1,…,K+1}2→[0,∞) satisfy ℓ(y1,y2)=0  ⟺  y1=y2\ell(y_1,y_2)=0 \iff y_1=y_2ℓ(y1​,y2​)=0⟺y1​=y2​ for all labels. The first argument is the predicted label and the second is the true label.
  • Loss Condition 2. Assume
ℓ(y2,y1)≤ℓ(K+1,y1)for all ID labels y1,y2∈{1,…,K}.\ell(y_2,y_1)\le \ell(K+1,y_1)\quad\text{for all ID labels } y_1,y_2\in\{1,\dots,K\}.ℓ(y2​,y1​)≤ℓ(K+1,y1​)for all ID labels y1​,y2​∈{1,…,K}.

So predicting any ID label when the truth is ID label y1y_1y1​ costs no more than predicting OOD.

  • ID classifiers. Let HinH^{\mathrm{in}}Hin be a nonempty set of functions X→{1,…,K}\mathcal{X}\to\{1,\dots,K\}X→{1,…,K}. When K=0K=0K=0, this nonemptiness forces X=∅\mathcal{X}=\varnothingX=∅.
  • Binary detectors. Let HbH^{b}Hb be a set of functions X→{ID,OOD}\mathcal{X}\to\{\text{ID},\text{OOD}\}X→{ID,OOD}. Assume HbH^bHb contains every such function except possibly the constant function x↦OODx\mapsto\text{OOD}x↦OOD. When X=∅\mathcal{X}=\varnothingX=∅ this assumption is empty.
  • Combined hypothesis space. Define H=Hin∙HbH = H^{\mathrm{in}}\bullet H^{b}H=Hin∙Hb as the set of all h:X→{1,…,K+1}h:\mathcal{X}\to\{1,\dots,K+1\}h:X→{1,…,K+1} for which there exist hin∈Hinh^{\mathrm{in}}\in H^{\mathrm{in}}hin∈Hin and hb∈Hbh^b\in H^bhb∈Hb with
h(x)={hin(x)if hb(x)=ID,K+1if hb(x)=OOD,for all x∈X.h(x)=\begin{cases}h^{\mathrm{in}}(x) & \text{if } h^b(x)=\text{ID},\\ K+1 & \text{if } h^b(x)=\text{OOD},\end{cases}\qquad\text{for all } x\in\mathcal{X}.h(x)={hin(x)K+1​if hb(x)=ID,if hb(x)=OOD,​for all x∈X.
  • Measurability. Assume every h∈Hh\in Hh∈H is measurable. Given the discrete σ-algebra noted above, this holds automatically.

Domains and risk. A domain DDD consists of three pieces:

  • a probability measure DXIYID_{X_IY_I}DXI​YI​​ on X×{1,…,K}\mathcal{X}\times\{1,\dots,K\}X×{1,…,K};
  • a probability measure DXOD_{X_O}DXO​​ on X\mathcal{X}X;
  • a number πout∈[0,1)\pi^{\mathrm{out}}\in[0,1)πout∈[0,1).

Its ID marginal DXID_{X_I}DXI​​ is the pushforward of DXIYID_{X_IY_I}DXI​YI​​ to X\mathcal{X}X. The risk of hhh is the [0,∞][0,\infty][0,∞]-valued quantity

RD(h)=(1−πout)∫ℓ(h(x),y) dDXIYI(x,y)  +  πout∫ℓ(h(x),K+1) dDXO(x).R_D(h)=(1-\pi^{\mathrm{out}})\int \ell(h(x),y)\,dD_{X_IY_I}(x,y)\;+\;\pi^{\mathrm{out}}\int \ell(h(x),K+1)\,dD_{X_O}(x).RD​(h)=(1−πout)∫ℓ(h(x),y)dDXI​YI​​(x,y)+πout∫ℓ(h(x),K+1)dDXO​​(x).

The separate space Ds\mathcal{D}^sDs is the set of all domains whose ID marginal DXID_{X_I}DXI​​ and OOD distribution DXOD_{X_O}DXO​​ have disjoint supports. Here the support is the set of points all of whose neighbourhoods have positive measure. In the discrete topology on X\mathcal{X}X, this is the set of points of positive mass.

Conclusion. OOD detection is learnable in Ds\mathcal{D}^sDs for HHH. That is, there exist an algorithm AAA and a sequence ε:N→R\varepsilon:\mathbb{N}\to\mathbb{R}ε:N→R with the following properties.

  1. The algorithm. AAA assigns to every sample size nnn and every sample S∈(X×{1,…,K})nS\in(\mathcal{X}\times\{1,\dots,K\})^nS∈(X×{1,…,K})n a function An(S):X→{1,…,K+1}A_n(S):\mathcal{X}\to\{1,\dots,K+1\}An​(S):X→{1,…,K+1}.
  2. Range. For every n≥1n\ge1n≥1 and every SSS, An(S)∈HA_n(S)\in HAn​(S)∈H. Nothing is required at n=0n=0n=0.
  3. Rate. ε\varepsilonε is non-increasing and ε(n)→0\varepsilon(n)\to0ε(n)→0. Consequently ε≥0\varepsilon\ge 0ε≥0.
  4. Consistency. For every domain D∈DsD\in\mathcal{D}^sD∈Ds and every n≥1n\ge1n≥1:
    • the map S↦RD(An(S))S\mapsto R_D(A_n(S))S↦RD​(An​(S)) is almost-everywhere measurable with respect to the nnn-fold product DXIYI nD_{X_IY_I}^{\,n}DXI​YI​n​ (i.i.d. samples drawn only from the ID distribution);
    • the following bound holds:
ES∼DXIYI n[RD(An(S))]  ≤  inf⁡h∈HRD(h)+max⁡(ε(n),0).\mathbb{E}_{S\sim D_{X_IY_I}^{\,n}}\big[R_D(A_n(S))\big]\;\le\;\inf_{h\in H}R_D(h)+\max(\varepsilon(n),0).ES∼DXI​YI​n​​[RD​(An​(S))]≤h∈Hinf​RD​(h)+max(ε(n),0).

Degenerate cases.

  • If X=∅\mathcal{X}=\varnothingX=∅, or if K=0K=0K=0, there are no domains, since no probability measure exists on an empty space. There are also no samples of size n≥1n\ge1n≥1. The conclusion then holds trivially.
  • An infimum over an empty HHH would be +∞+\infty+∞.
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