Is Out-of-Distribution Detection Learnable?

Zhen Fang, Yixuan Li, Jie Lu, Jiahua Dong, Bo Han, Feng Liu

Introduction

The success of supervised learning is established on an implicit assumption that training and test data share a same distribution, i.e., in-distribution (ID) . However, test data distribution in many real-world scenarios may violate the assumption and, instead, contain out-of-distribution (OOD) data whose labels have not been seen during the training process . To mitigate the risk of OOD data, researchers have considered a more practical learning scenario: OOD detection which determines whether an input is ID/OOD, while classifying the ID data into respective classes. OOD detection has shown great potential to ensure the reliable deployment of machine learning models in the real world. A rich line of algorithms have been developed to empirically address the OOD detection problem . However, very few works study theory of OOD detection, which hinders the rigorous path forward for the field. This paper aims to bridge the gap.

In this paper, we provide a theoretical framework to understand the learnability of the OOD detection problem. We investigate the probably approximately correct (PAC) learning theory of OOD detection, which is posed as an open problem to date. Unlike the classical PAC learning theory in a supervised setting, our problem setting is fundamentally challenging due to the absence of OOD data in training. In many real-world scenarios, OOD data can be diverse and priori-unknown. Given this, we study whether there exists an algorithm that can be used to detect various OOD data instead of merely some specified OOD data. Such is the significance of studying the learning theory for OOD detection . This motivates our question: is OOD detection PAC learnable? i.e., is there the PAC learning theory to guarantee the generalization ability of OOD detection?

To investigate the learning theory, we mainly focus on two basic spaces: domain space and hypothesis space. The domain space is a space consisting of some distributions, and the hypothesis space is a space consisting of some classifiers. Existing agnostic PAC theories in supervised learning are distribution-free, i.e., the domain space consists of all domains. Yet, in Theorem 4, we shows that the learning theory of OOD detection is not distribution-free. In fact, we discover that OOD detection is learnable only if the domain space and the hypothesis space satisfy some special conditions, e.g., Conditions 1 and 3. Notably, there are many conditions and theorems in existing learning theories and many OOD detection algorithms in the literature. Thus, it is very difficult to analyze the relation between these theories and algorithms, and explore useful conditions to ensure the learnability of OOD detection, especially when we have to explore them from the scratch. Thus, the main aim of our paper is to study these essential conditions. From these essential conditions, we can know when OOD detection can be successful in practical scenarios. We restate our question and goal in following:

Given hypothesis spaces and several representative domain spaces, what are the conditions to ensure the learnability of OOD detection? If possible, we hope that these conditions are necessary and sufficient in some scenarios.

Main Results. We investigate the learnability of OOD detection starting from the largest space—the total space, and give a necessary condition (Condition 1) for the learnability. However, we find that the overlap between ID and OOD data may result in that the necessary condition does not hold. Therefore, we give an impossibility theorem to demonstrate that OOD detection fails in the total space (Theorem 4). Next, we study OOD detection in the separate space, where there are no overlaps between the ID and OOD data. Unfortunately, there still exists impossibility theorem (Theorem 5), which demonstrates that OOD detection is not learnable in the separate space under some conditions.

Although the impossibility theorems obtained in the separate space are frustrating, we find that some conditions of these impossibility theorems may not hold in some practical scenarios. Based on this observation, we give several necessary and sufficient conditions to characterize the learnability of OOD detection in the separate space (Theorems 6 and 10). Especially, when our model is based on fully-connected neural network (FCNN), OOD detection is learnable in the separate space if and only if the feature space is finite. Furthermore, we investigate the learnability of OOD detection in other more practical domain spaces, e.g., the finite-ID-distribution space (Theorem 8) and the density-based space (Theorem 9). By studying the finite-ID-distribution space, we discover a compatibility condition (Condition 3) that is a necessary and sufficient condition for this space. Next, we further investigate the compatibility condition in the density-based space, and find that such condition is also the necessary and sufficient condition in some practical scenarios (Theorem 11).

Implications and Impacts of Theory. Our study is not of purely theoretical interest; it has also practical impacts. First, when we design OOD detection algorithms, we normally only have finite ID datasets, corresponding to the finite-ID-distribution space. In this case, Theorem 8 gives the necessary and sufficient condition to the success of OOD detection. Second, our theory provides theoretical support (Theorems 10 and 11) for several representative OOD detection works . Third, our theory shows that OOD detection is learnable in image-based scenarios when ID images have clearly different semantic labels and styles (far-OOD) from OOD images. Fourth, we should not expect a universally working algorithm. It is necessary to design different algorithms in different scenarios.

Learning Setups

Given an ID joint distribution DXIYID_{X_{\rm I}Y_{\rm I}} and a training data S:={(x1,y1),...,(xn,yn)}S:=\{(\mathbf{x}^{1},{y}^{1}),...,(\mathbf{x}^{n},{y}^{n})\} drawn independent and identically distributed from DXIYID_{X_{\rm I}Y_{\rm I}}, the aim of OOD detection is to train a classifier ff by using the training data SS such that, for any test data x\mathbf{x} drawn from the mixed marginal distribution DXD_{X}: 1) if x\mathbf{x} is an observation from DXID_{X_{\rm I}}, ff can classify x\mathbf{x} into correct ID classes; and 2) if x\mathbf{x} is an observation from DXOD_{X_{\rm O}}, ff can detect x\mathbf{x} as OOD data.

According to the survey , when K>1K>1, OOD detection is also known as the open-set recognition or open-set learning ; and when K=1K=1, OOD detection reduces to one-class novelty detection and semantic anomaly detection .

OOD Label and Domain Space. Based on Problem 1, we know it is not necessary to classify OOD data into the correct OOD classes. Without loss of generality, let all OOD data be allocated to one big OOD class, i.e., YO=K+1Y_{\rm O}=K+1 . To investigate the PAC learnability of OOD detection, we define a domain space DXY\mathscr{D}_{XY}, which is a set consisting of some joint distributions DXYD_{XY} mixed by some ID joint distributions and some OOD joint distributions. In this paper, the joint distribution DXYD_{XY} mixed by ID joint distribution DXIYID_{X_{\rm I}Y_{\rm I}} and OOD joint distribution DXOYOD_{X_{\rm O}Y_{\rm O}} is called domain.

The α\alpha-risk RDα(h):=(1−α)RDin(h)+αRDout(h),∀α∈R_{D}^{\alpha}({h}):=(1-\alpha)R^{\rm in}_{D}({h})+\alpha R^{\rm out}_{D}({h}),\forall\alpha\in, where the risks RDin(h)R^{\rm in}_{D}({h}), RDout(h)R^{\rm out}_{D}({h}) are

Learnability. We aim to select a hypothesis function h∈Hh\in\mathcal{H} with approximately minimal risk, based on finite data. Generally, we expect the approximation to get better, with the increase in sample size. Algorithms achieving this are said to be consistent. Formally, we introduce the following definition:

Given a domain space DXY\mathscr{D}_{XY} and a hypothesis space H⊂{h:X→Yall}\mathcal{H}\subset\{{h}:\mathcal{X}\rightarrow\mathcal{Y}_{\rm all}\}, we say OOD detection is learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}, if there exists an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H}Similar to , in this paper, we regard an algorithm as a mapping from ∪n=1+∞(X×Y)n\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n} to H\mathcal{H}. and a monotonically decreasing sequence ϵcons(n)\epsilon_{\rm cons}(n), such that ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY},

An algorithm A\mathbf{A} for which this holds is said to be consistent with respect to DXY\mathscr{D}_{XY}.

Since OOD data are unavailable, it is impossible to obtain information about the class-prior probability πout\pi^{\rm out}. Furthermore, in the real world, it is possible that πout\pi^{\rm out} can be any value in [0,1)[0,1). Therefore, the imbalance issue between ID and OOD distributions, and the priori-unknown issue (i.e., πout\pi^{\rm out} is unknown) are the core challenges. To ease these challenges, researchers use AUROC, AUPR and FPR95 to estimate the performance of OOD detection . It seems that there is a gap between Definition 1 and existing works. To eliminate this gap, we revise Eq. (2) as follows:

If an algorithm A\mathbf{A} satisfies Eq. (3), then the imbalance issue and the prior-unknown issue disappear. That is, A\mathbf{A} can simultaneously classify the ID data and detect the OOD data well. Based on the above discussion, we define the strong learnability of OOD detection as follows:

Given a domain space DXY\mathscr{D}_{XY} and a hypothesis space H⊂{h:X→Yall}\mathcal{H}\subset\{{h}:\mathcal{X}\rightarrow\mathcal{Y}_{\rm all}\}, we say OOD detection is strongly learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}, if there exists an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H} and a monotonically decreasing sequence ϵcons(n)\epsilon_{\rm cons}(n), such that ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY},

In Theorem 1, we have shown that the strong learnability of OOD detection is equivalent to the learnability of OOD detection, if the domain space DXY\mathscr{D}_{XY} is a prior-unknown space (see Definition 3). In this paper, we mainly discuss the learnability in the prior-unknown space. Therefore, when we mention that OOD detection is learnable, we also mean that OOD detection is strongly learnable.

Goal of Theory. Note that the agnostic PAC learnability of supervised learning is distribution-free, i.e., the domain space DXY\mathscr{D}_{XY} consists of all domains. However, due to the absence of OOD data during the training process , it is obvious that the learnability of OOD detection is not distribution-free (i.e., Theorem 4). In fact, we discover that the learnability of OOD detection is deeply correlated with the relationship between the domain space DXY\mathscr{D}_{XY} and the hypothesis space H\mathcal{H}. That is, OOD detection is learnable only when the domain space DXY\mathscr{D}_{XY} and the hypothesis space H\mathcal{H} satisfy some special conditions, e.g., Condition 1 and Condition 3. We present our goal as follows:

Goal: given a hypothesis space H\mathcal{H} and several representative domain spaces DXY\mathscr{D}_{XY}, what are the conditions to ensure the learnability of OOD detection? Furthermore, if possible, we hope that these conditions are necessary and sufficient in some scenarios.

Therefore, compared to the agnostic PAC learnability of supervised learning, our theory doesn’t focus on the distribution-free case, but focuses on discovering essential conditions to guarantee the learnability of OOD detection in several representative and practical domain spaces DXY\mathscr{D}_{XY}. By these essential conditions, we can know when OOD detection can be successful in real applications.

Learning in Priori-unknown Spaces

We first investigate a special space, called prior-unknown space. In such space, Definition 1 and Definition 2 are equivalent. Furthermore, we also prove that if OOD detection is strongly learnable in a space DXY\mathscr{D}_{XY}, then one can discover a larger domain space, which is prior-unknown, to ensure the learnability of OOD detection. These results imply that it is enough to consider our theory in the prior-unknown spaces. The prior-unknown space is introduced as follows:

Given a domain space DXY\mathscr{D}_{XY}, we say DXY\mathscr{D}_{XY} is a priori-unknown space, if for any domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY} and any α∈[0,1)\alpha\in[0,1), we have DXYα:=(1−α)DXIYI+αDXOYO∈DXYD_{XY}^{\alpha}:=(1-\alpha)D_{X_{\rm I}Y_{\rm I}}+\alpha D_{X_{\rm O}Y_{\rm O}}\in\mathscr{D}_{XY}.

Given domain spaces DXY\mathscr{D}_{XY} and DXY′={DXYα:∀DXY∈DXY,∀α∈[0,1)}\mathscr{D}_{XY}^{\prime}=\{D_{XY}^{\alpha}:\forall D_{XY}\in\mathscr{D}_{XY},\forall\alpha\in[0,1)\}, then 1) DXY′\mathscr{D}_{XY}^{\prime} is a priori-unknown space and DXY⊂DXY′\mathscr{D}_{XY}\subset\mathscr{D}_{XY}^{\prime}; 2) if DXY\mathscr{D}_{XY} is a priori-unknown space, then Definition 1 and Definition 2 are equivalent; 3) OOD detection is strongly learnable in DXY\mathscr{D}_{XY} if and only if OOD detection is learnable in DXY′\mathscr{D}_{XY}^{\prime}.

The second result of Theorem 1 bridges the learnability and strong learnability, which implies that if an algorithm A\mathbf{A} is consistent with respect to a prior-unknown space, then this algorithm A\mathbf{A} can address the imbalance issue between ID and OOD distributions, and the priori-unknown issue well. Based on Theorem 1, we focus on our theory in the prior-unknown spaces. Furthermore, to demystify the learnability of OOD detection, we introduce five representative priori-unknown spaces:

∙\bullet Single-distribution space DXYDXY\mathscr{D}_{XY}^{D_{XY}}. For a domain DXYD_{XY}, DXYDXY:={DXYα:∀α∈[0,1)}\mathscr{D}_{XY}^{D_{XY}}:=\{D_{XY}^{\alpha}:\forall\alpha\in[0,1)\}. ∙\bullet Total space DXYall\mathscr{D}_{XY}^{\rm all}, which consists of all domains. ∙\bullet Separate space DXYs\mathscr{D}_{XY}^{s}, which consists of all domains that satisfy the separate condition, that is for any DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s}, suppDXO∩suppDXI=∅,{\rm supp}D_{X_{\rm O}}\cap{\rm supp}D_{X_{\rm I}}=\emptyset, where supp{\rm supp} means the support set. ∙\bullet Finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F}, which is a prior-unknown space satisfying that the number of distinct ID joint distributions DXIYID_{X_{\rm I}Y_{\rm I}} in DXYF\mathscr{D}_{XY}^{F} is finite, i.e., ∣{DXIYI:∀DXY∈DXYF}∣<+∞|\{D_{X_{\rm I}Y_{\rm I}}:\forall D_{XY}\in\mathscr{D}_{XY}^{F}\}|<+\infty. ∙\bullet Density-based space DXYμ,b\mathscr{D}^{\mu,b}_{XY}, which is a prior-unknown space consisting of some domains satisfying that: for any DXYD_{XY}, there exists a density function ff with 1/b≤f≤b1/b\leq f\leq b in suppμ{\rm supp}\mu and 0.5∗DXI+0.5∗DXO=∫fdμ0.5*D_{X_{\rm I}}+0.5*D_{X_{\rm O}}=\int f{\rm d}\mu, where μ\mu is a measure defined over X\mathcal{X}. Note that if μ\mu is discrete, then DXD_{X} is a discrete distribution; and if μ\mu is the Lebesgue measure, then DXD_{X} is a continuous distribution.

The above representative spaces widely exist in real applications. For example, 1) if the images from different semantic labels with different styles are clearly different, then those images can form a distribution belonging to a separate space DXYs\mathscr{D}_{XY}^{s}; and 2) when designing an algorithm, we only have finite ID datasets, e.g., CIFAR-10, MNIST, SVHN, and ImageNet, to build a model. Then, finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F} can handle this real scenario. Note that the single-distribution space is a special case of the finite-ID-distribution space. In this paper, we mainly discuss these five spaces.

Impossibility Theorems for OOD Detection

In this section, we first give a necessary condition for the learnability of OOD detection. Then, we show this necessary condition does not hold in the total space DXYall\mathscr{D}_{XY}^{\rm all} and the separate space DXYs\mathscr{D}_{XY}^{s}.

Necessary Condition. We find a necessary condition for the learnability of OOD detection, i.e., Condition 1, motivated by the experiments in Figure 1. Details of Figure 1 can be found in Appendix C.2.

For any DXY∈DXYD_{XY}\in\mathscr{D}_{XY} and any α∈[0,1)\alpha\in[0,1),

To reveal the importance of Condition 1, Theorem 2 shows that Condition 1 is a necessary and sufficient condition for the learnability of OOD detection if the DXY\mathscr{D}_{XY} is the single-distribution space.

Theorem 2. Given a hypothesis space H\mathcal{H} and a domain DXYD_{XY}, OOD detection is learnable in the single-distribution space DXYDXY\mathscr{D}_{XY}^{D_{XY}} for H\mathcal{H} if and only if linear condition (i.e., Condition 1) holds.

Theorem 2 implies that Condition 1 is important for the learnability of OOD detection. Due to the simplicity of single-distribution space, Theorem 2 implies that Condition 1 is the necessary condition for the learnability of OOD detection in the prior-unknown space, see Lemma 1 in Appendix F.

Impossibility Theorems. Here, we first study whether Condition 1 holds in the total space DXYall\mathscr{D}_{XY}^{\rm all}. If Condition 1 does not hold, then OOD detection is not learnable. Theorem 3 shows that Condition 1 is not always satisfied, especially, when there is an overlap between the ID and OOD distributions:

Given a hypothesis space H\mathcal{H} and a prior-unknown space DXY\mathscr{D}_{XY}, if there is DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, which has overlap between ID and OOD, and inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0, then Condition 1 does not hold. Therefore, OOD detection is not learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}.

Theorem 3 clearly shows that under proper conditions, Condition 1 does not hold, if there exists a domain whose ID and OOD distributions have overlap. By Theorem 3, we can obtain that the OOD detection is not learnable in the total space DXYall\mathscr{D}^{\rm all}_{XY} for any non-trivial hypothesis space H\mathcal{H}.

Theorem 4 (Impossibility Theorem for Total Space). OOD detection is not learnable in the total space DXYall\mathscr{D}^{\rm all}_{XY} for H\mathcal{H}, if ∣ϕ∘H∣>1|\phi\circ\mathcal{H}|>1, where ϕ\phi maps ID labels to 11 and maps OOD labels to 22.

Since the overlaps between ID and OOD distributions may cause that Condition 1 does not hold, we then consider studying the learnability of OOD detection in the separate space DXYs\mathscr{D}_{XY}^{s}, where there are no overlaps between the ID and OOD distributions. However, Theorem 5 shows that even if we consider the separate space, the OOD detection is still not learnable in some scenarios. Before introducing the impossibility theorem for separate space, i.e., Theorem 5, we need a mild assumption:

A hypothesis space H\mathcal{H} is separate for OOD data, if for each data point x∈X\mathbf{x}\in\mathcal{X}, there exists at least one hypothesis function hx∈Hh_{\mathbf{x}}\in\mathcal{H} such that hx(x)=K+1h_{\mathbf{x}}(\mathbf{x})=K+1.

Assumption 1 means that every data point x\mathbf{x} has the possibility to be detected as OOD data. Assumption 1 is mild and can be satisfied by many hypothesis spaces, e.g., the FCNN-based hypothesis space (Proposition 1 in Appendix K), score-based hypothesis space (Proposition 2 in Appendix K) and universal kernel space. Next, we use Vapnik–Chervonenkis (VC) dimension to measure the size of hypothesis space, and study the learnability of OOD detection in DXYs\mathscr{D}_{XY}^{s} based on the VC dimension.

Theorem 5 (Impossibility Theorem for Separate Space). If Assumption 1 holds, VCdim(ϕ∘H)<+∞{\rm VCdim}(\phi\circ\mathcal{H})<+\infty and sup⁡h∈H∣{x∈X:h(x)∈Y}∣=+∞\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|=+\infty, then OOD detection is not learnable in separate space DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, where ϕ\phi maps ID labels to 1{1} and maps OOD labels to 22.

The finite VC dimension normally implies the learnability of supervised learning. However, in our results, the finite VC dimension cannot guarantee the learnability of OOD detection in the separate space, which reveals the difficulty of the OOD detection. Although the above impossibility theorems are frustrating, there is still room to discuss the conditions in Theorem 5, and to find out the proper conditions for ensuring the learnability of OOD detection in the separate space (see Sections 5 and 6).

When OOD Detection Can Be Successful

Here, we discuss when the OOD detection can be learnable in the separate space DXYs\mathscr{D}_{XY}^{s}, finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F} and density-based space DXYμ,b\mathscr{D}_{XY}^{\mu,b}. We first study the separate space DXYs\mathscr{D}_{XY}^{s}.

OOD Detection in the Separate Space. Theorem 5 has indicated that VCdim(ϕ∘H)=+∞{\rm VCdim}(\phi\circ\mathcal{H})=+\infty or sup⁡h∈H∣{x∈X:h(x)∈Y}∣<+∞\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|<+\infty is necessary to ensure the learnability of OOD detection in DXYs\mathscr{D}_{XY}^{s} if Assumption 1 holds. However, generally, hypothesis spaces generated by feed-forward neural networks with proper activation functions have finite VC dimension . Therefore, we study the learnability of OOD detection in the case that ∣X∣<+∞|\mathcal{X}|<+\infty, which implies that sup⁡h∈H∣{x∈X:h(x)∈Y}∣<+∞\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|<+\infty. Additionally, Theorem 10 also implies that ∣X∣<+∞|\mathcal{X}|<+\infty is the necessary and sufficient condition for the learnability of OOD detection in separate space, when the hypothesis space is generated by FCNN. Hence, ∣X∣<+∞|\mathcal{X}|<+\infty may be necessary in the space DXYs\mathscr{D}_{XY}^{s}.

For simplicity, we first discuss the case that K=1K=1, i.e., the one-class novelty detection. We show the necessary and sufficient condition for the learnability of OOD detection in DXYs\mathscr{D}_{XY}^{s}, when ∣X∣<+∞|\mathcal{X}|<+\infty.

Theorem 6. Let K=1K=1 and ∣X∣<+∞|\mathcal{X}|<+\infty. Suppose that Assumption 1 holds and the constant function hin:=1∈Hh^{\rm in}:=1\in\mathcal{H}. Then OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H} if and only if Hall−{hout}⊂H\mathcal{H}_{\rm all}-\{h^{\rm out}\}\subset\mathcal{H}, where Hall\mathcal{H}_{\rm all} is the hypothesis space consisting of all hypothesis functions, and houth^{\rm out} is a constant function that hout:=2h^{\rm out}:=2, here 11 represents ID data and 22 represents OOD data.

The condition hin∈Hh^{\rm in}\in\mathcal{H} presented in Theorem 6 is mild. Many practical hypothesis spaces satisfy this condition, e.g., the FCNN-based hypothesis space (Proposition 1 in Appendix K), score-based hypothesis space (Proposition 2 in Appendix K) and universal kernel-based hypothesis space. Theorem 6 implies that if K=1K=1 and OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for H\mathcal{H}, then the hypothesis space H\mathcal{H} should contain almost all hypothesis functions, implying that if the OOD detection can be learnable in the distribution-agnostic case, then a large-capacity model is necessary.

Next, we extend Theorem 6 to a general case, i.e., K>1K>1. When K>1K>1, we will first use a binary classifier hbh^{b} to classify the ID and OOD data. Then, for the ID data identified by hbh^{b}, an ID hypothesis function hinh^{\rm in} will be used to classify them into corresponding ID classes. We state this strategy as follows: given a hypothesis space Hin\mathcal{H}^{\rm in} for ID distribution and a binary classification hypothesis space Hb\mathcal{H}^{\rm b} introduced in Section 2, we use Hin\mathcal{H}^{\rm in} and Hb\mathcal{H}^{\rm b} to construct an OOD detection’s hypothesis space H\mathcal{H}, which consists of all hypothesis functions hh satisfying the following condition: there exist hin∈Hinh^{\rm in}\in\mathcal{H}^{\rm in} and hb∈Hbh^{\rm b}\in\mathcal{H}^{b} such that for any x∈X\mathbf{x}\in\mathcal{X},

Let ∣X∣<+∞|\mathcal{X}|<+\infty and H=Hin∙Hb\mathcal{H}=\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}. If Hall−{hout}⊂Hb\mathcal{H}_{\rm all}-\{h^{\rm out}\}\subset\mathcal{H}^{\rm b} and Condition 2 holds, then OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, where Hall\mathcal{H}_{\rm all} and houth^{\rm out} are defined in Theorem 6.

OOD Detection in the Finite-ID-Distribution Space. Since researchers can only collect finite ID datasets as the training data in the process of algorithm design, it is worthy to study the learnability of OOD detection in the finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F}. We first show two necessary concepts below.

Given a domain space DXY\mathscr{D}_{XY}, we say any two domains DXY∈DXYD_{XY}\in\mathscr{D}_{XY} and DXY′∈DXYD_{XY}^{\prime}\in\mathscr{D}_{XY} are ID consistency, if DXIYI=DXIYI′D_{X_{\rm I}Y_{\rm I}}=D_{X_{\rm I}Y_{\rm I}}^{\prime}. We use the notation ∼\sim to represent the ID consistency, i.e., DXY∼DXY′D_{XY}\sim D_{XY}^{\prime} if and only if DXYD_{XY} and DXY′D_{XY}^{\prime} are ID consistency.

It is easy to check that the ID consistency ∼\sim is an equivalence relation. Therefore, we define the set [DXY]:={DXY′∈DXY:DXY∼DXY′}[D_{XY}]:=\{D_{XY}^{\prime}\in\mathscr{D}_{XY}:D_{XY}\sim D_{XY}^{\prime}\} as the equivalence class with respect to space DXY\mathscr{D}_{XY}.

For any equivalence class [DXY′][D_{XY}^{\prime}] with respect to DXY\mathscr{D}_{XY} and any ϵ>0\epsilon>0, there exists a hypothesis function hϵ∈Hh_{\epsilon}\in\mathcal{H} such that for any domain DXY∈[DXY′]D_{XY}\in[D_{XY}^{\prime}],

In Appendix F, Lemma 2 has implied that Condition 3 is a general version of Condition 1. Next, Theorem 8 indicates that Condition 3 is the necessary and sufficient condition in the space DXYF\mathscr{D}_{XY}^{F}.

Theorem 8. Suppose that X\mathcal{X} is a bounded set. OOD detection is learnable in the finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F} for H\mathcal{H} if and only if the compatibility condition (i.e., Condition 3) holds. Furthermore, the learning rate ϵcons(n)\epsilon_{\rm cons}(n) can attain O(1/n1−θ){O}(1/\sqrt{n^{1-\theta}}), for any θ∈(0,1)\theta\in(0,1).

Theorem 8 shows that, in the process of algorithm design, OOD detection cannot be successful without the compatibility condition. Theorem 8 also implies that Condition 3 is essential for the learnability of OOD detection. This motivates us to study whether OOD detection can be successful in more general spaces (e.g., the density-based space), when the compatibility condition holds.

OOD Detection in the Density-based Space. To ensure that Condition 3 holds, we consider a basic assumption in learning theory—Realizability Assumption (see Appendix D.2), i.e., for any DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, there exists h∗∈Hh^{*}\in\mathcal{H} such that RD(h∗)=0R_{D}(h^{*})=0. We discover that in the density-based space DXYμ,b\mathscr{D}_{XY}^{\mu,b}, Realizability Assumption can conclude the compatibility condition (i.e., Condition 3). Based on this observation, we can prove the following theorem:

Theorem 9. Given a density-based space DXYμ,b\mathscr{D}_{XY}^{\mu,b}, if μ(X)<+∞\mu(\mathcal{X})<+\infty, the Realizability Assumption holds, then when H\mathcal{H} has finite Natarajan dimension , OOD detection is learnable in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H\mathcal{H}. Furthermore, the learning rate ϵcons(n)\epsilon_{\rm cons}(n) can attain O(1/n1−θ){O}(1/\sqrt{n^{1-\theta}}), for any θ∈(0,1)\theta\in(0,1).

To further investigate the importance and necessary of Realizability Assumption, Theorem 11 has indicated that in some practical scenarios, Realizability Assumption is the necessary and sufficient condition for the learnability of OOD detection in the density-based space. Therefore, Realizability Assumption may be indispensable for the learnability of OOD detection in some practical scenarios.

Connecting Theory to Practice

In Section 5, we have shown the successful scenarios where OOD detection problem can be addressed in theory. In this section, we will discuss how the proposed theory is applied to two representative hypothesis spaces—neural-network-based hypothesis spaces and score-based hypothesis spaces.

In Appendix L, Lemma 10 shows q≲q′⇒Fqσ⊂Fq′σ\mathbf{q}\lesssim\mathbf{q}^{\prime}\Rightarrow\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}. We use ≲\lesssim to compare the sizes of FCNNs.

FCNN-based Hypothesis Space. Let lg=K+1l_{g}=K+1. The FCNN-based scoring function space Fqσ\mathcal{F}_{\mathbf{q}}^{\sigma} can induce an FCNN-based hypothesis space. For any fw,b∈Fqσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}}^{\sigma}, the induced hypothesis function is:

Then, the FCNN-based hypothesis space is defined as Hqσ:={hw,b:∀ weights w, ∀ bias b}.\mathcal{H}_{\mathbf{q}}^{\sigma}:=\{h_{\mathbf{w},\mathbf{b}}:\forall~{}\textnormal{weights}~{}\mathbf{w},~{}\forall~{}\textnormal{bias}~{}\mathbf{b}\}.

∙\bullet energy-based function : λ∈(0,+∞)\lambda\in(0,+\infty) and T>0T>0,

Using EE, λ\lambda and f∈Fqσ\mathbf{f}\in\mathcal{F}_{\mathbf{q}}^{\sigma}, we have a classifier: hf,Eλ(x)=1h^{\lambda}_{\mathbf{f},E}(\mathbf{x})=1, if E(f(x))≥λE(\mathbf{f}(\mathbf{x}))\geq\lambda; otherwise, hf,Eλ(x)=2h^{\lambda}_{\mathbf{f},E}(\mathbf{x})=2, where 11 represents the ID data and 22 represents the OOD data. Hence, a binary classification hypothesis space Hb\mathcal{H}^{b}, which consists of all hf,Eλh^{\lambda}_{\mathbf{f},E}, is generated. We define Hq,Eσ,λ:={hf,Eλ:∀f∈Fqσ}\mathcal{H}^{{\sigma},\lambda}_{{\mathbf{q}},E}:=\{h^{\lambda}_{\mathbf{f},E}:\forall\mathbf{f}\in\mathcal{F}_{\mathbf{q}}^{\sigma}\}.

Learnability of OOD Detection in Different Hypothesis Spaces. Next, we present applications of our theory regarding the above two practical and important hypothesis spaces Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma} and Hq,Eσ,λ\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}.

Suppose that Condition 2 holds and the hypothesis space H\mathcal{H} is FCNN-based or score-based, i.e., H=Hqσ\mathcal{H}=\mathcal{H}_{\mathbf{q}}^{\sigma} or H=Hin∙Hb\mathcal{H}=\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}, where Hin\mathcal{H}^{\rm in} is an ID hypothesis space, Hb=Hq,Eσ,λ\mathcal{H}^{\rm b}=\mathcal{H}^{{\sigma},\lambda}_{{\mathbf{q}},E} and H=Hin∙Hb\mathcal{H}=\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b} is introduced below Eq. (4), here EE is introduced in Eqs. (5) or (6). Then There is a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) such that OOD detection is learnable in the separate space DXYs\mathscr{D}^{s}_{XY} for H\mathcal{H} if and only if ∣X∣<+∞|\mathcal{X}|<+\infty. Furthermore, if ∣X∣<+∞|\mathcal{X}|<+\infty, then there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) such that for any sequence q′\mathbf{q}^{\prime} satisfying that q≲q′\mathbf{q}\lesssim\mathbf{q}^{\prime}, OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for H\mathcal{H}.

Theorem 10 states that 1) when the hypothesis space is FCNN-based or score-based, the finite feature space is the necessary and sufficient condition for the learnability of OOD detection in the separate space; and 2) a larger architecture of FCNN has a greater probability to achieve the learnability of OOD detection in the separate space. Note that when we select Eqs. (5) or (6) as the scoring function EE, Theorem 10 also shows that the selected scoring functions EE can guarantee the learnability of OOD detection, which is a theoretical support for the representative works . Furthermore, Theorem 11 also offers theoretical supports for these works in the density-based space, when K=1K=1.

Suppose that each domain DXYD_{XY} in DXYμ,b\mathscr{D}_{XY}^{\mu,b} is attainable, i.e., arg min⁡h∈HRD(h)≠∅\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}(h)\neq\emptyset (the finite discrete domains satisfy this). Let K=1K=1 and the hypothesis space H\mathcal{H} be score-based ((H=Hq,Eσ,λ\mathcal{H}=\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}, where EE is in Eqs. (5) or (6))) or FCNN-based (<spanclass="katex−display"><spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"display="block"><semantics><mrow><mimathvariant="script">H</mi><mo>=</mo><msubsup><mimathvariant="script">H</mi><mimathvariant="bold">q</mi><mi>σ</mi></msubsup></mrow><annotationencoding="application/x−tex">H=Hqσ</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6833em;"></span><spanclass="mordmathcal"style="margin−right:0.0097em;">H</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">=</span><spanclass="mspace"style="margin−right:0.2778em;"></span></span><spanclass="base"><spanclass="strut"style="height:1.0975em;vertical−align:−0.3831em;"></span><spanclass="mord"><spanclass="mordmathcal"style="margin−right:0.0097em;">H</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.7144em;"><spanstyle="top:−2.453em;margin−left:−0.0097em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmtight"><spanclass="mordmathbfmtight">q</span></span></span></span><spanstyle="top:−3.113em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmtight"><spanclass="mordmathnormalmtight"style="margin−right:0.0359em;">σ</span></span></span></span></span><spanclass="vlist−s">​</span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.3831em;"><span></span></span></span></span></span></span></span></span></span></span>)(<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="script">H</mi><mo>=</mo><msubsup><mi mathvariant="script">H</mi><mi mathvariant="bold">q</mi><mi>σ</mi></msubsup></mrow><annotation encoding="application/x-tex">\mathcal{H}=\mathcal{H}_{\mathbf{q}}^{\sigma}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathcal" style="margin-right:0.0097em;">H</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0975em;vertical-align:-0.3831em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.0097em;">H</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7144em;"><span style="top:-2.453em;margin-left:-0.0097em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathbf mtight">q</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.0359em;">σ</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3831em;"><span></span></span></span></span></span></span></span></span></span></span>). If μ(X)<+∞\mu(\mathcal{X})<+\infty, then the following four conditions are equivalent: Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H\mathcal{H}   ⟺  \iff Condition 1   ⟺  \iff Realizability Assumption   ⟺  \iff Condition 3

Theorem 11 still holds if the function space Fqσ\mathcal{F}_{\mathbf{q}}^{\sigma} is generated by Convolutional Neural Network.

Overlap and Benefits of Multi-class Case. We investigate when the hypothesis space is FCNN-based or score-based, what will happen if there exists an overlap between the ID and OOD distributions?

Let K=1K=1 and the hypothesis space H\mathcal{H} be score-based ((H=Hq,Eσ,λ\mathcal{H}=\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}, where EE is in Eqs. (5) or (6))) or FCNN-based (<spanclass="katex−display"><spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"display="block"><semantics><mrow><mimathvariant="script">H</mi><mo>=</mo><msubsup><mimathvariant="script">H</mi><mimathvariant="bold">q</mi><mi>σ</mi></msubsup></mrow><annotationencoding="application/x−tex">H=Hqσ</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6833em;"></span><spanclass="mordmathcal"style="margin−right:0.0097em;">H</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">=</span><spanclass="mspace"style="margin−right:0.2778em;"></span></span><spanclass="base"><spanclass="strut"style="height:1.0975em;vertical−align:−0.3831em;"></span><spanclass="mord"><spanclass="mordmathcal"style="margin−right:0.0097em;">H</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.7144em;"><spanstyle="top:−2.453em;margin−left:−0.0097em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmtight"><spanclass="mordmathbfmtight">q</span></span></span></span><spanstyle="top:−3.113em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmtight"><spanclass="mordmathnormalmtight"style="margin−right:0.0359em;">σ</span></span></span></span></span><spanclass="vlist−s">​</span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.3831em;"><span></span></span></span></span></span></span></span></span></span></span>)(<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="script">H</mi><mo>=</mo><msubsup><mi mathvariant="script">H</mi><mi mathvariant="bold">q</mi><mi>σ</mi></msubsup></mrow><annotation encoding="application/x-tex">\mathcal{H}=\mathcal{H}_{\mathbf{q}}^{\sigma}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathcal" style="margin-right:0.0097em;">H</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0975em;vertical-align:-0.3831em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.0097em;">H</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7144em;"><span style="top:-2.453em;margin-left:-0.0097em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathbf mtight">q</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.0359em;">σ</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3831em;"><span></span></span></span></span></span></span></span></span></span></span>). Given a prior-unknown space DXY\mathscr{D}_{XY}, if there exists a domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, which has an overlap between ID and OOD distributions (see Definition 4), then OOD detection is not learnable in the domain space DXY\mathscr{D}_{XY} for H\mathcal{H}.

When K=1K=1 and the hypothesis space is FCNN-based or score-based, Theorem 12 shows that overlap between ID and OOD distributions is the sufficient condition for the unlearnability of OOD detection. Theorem 12 takes roots in the conditions inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0. However, when K>1K>1, we can ensure inf⁡h∈HRDin(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)>0 if ID distribution DXIYID_{X_{\rm I}Y_{\rm I}} has overlap between ID classes. By this observation, we conjecture that when K>1K>1, OOD detection is learnable in some special cases where overlap exists, even if the hypothesis space is FCNN-based or score-based.

Discussion

Understanding Far-OOD Detection. Many existing works study the far-OOD detection issue. Existing benchmarks include 1) MNIST as ID dataset, and Texture , CIFAR-1010 or Place365365 as OOD datasets; and 2) CIFAR-1010 as ID dataset, and MNIST , or Fashion-MNIST as OOD datasets. In far-OOD case, we find that the ID and OOD datasets have different semantic labels and different styles. From the theoretical view, we can define far-OOD detection tasks as follows: for τ>0\tau>0, a domain space DXY\mathscr{D}_{XY} is τ\tau-far-OOD, if for any domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY},

Theorems 7, 8 and 10 imply that under appropriate hypothesis space, τ\tau-far-OOD detection is learnable. In Theorem 7, the condition ∣X∣<+∞|\mathcal{X}|<+\infty is necessary for the separate space. However, one can prove that in the far-OOD case, when Hin\mathcal{H}^{\rm in} is agnostic PAC learnable for ID distribution, the results in Theorem 7 still holds, if the condition ∣X∣<+∞|\mathcal{X}|<+\infty is replaced by a weaker condition that X\mathcal{X} is compact. In addition, it is notable that when Hin\mathcal{H}^{\rm in} is agnostic PAC learnable for ID distribution and X\mathcal{X} is compact, the KNN-based OOD detection algorithm is consistent in the τ\tau-far-OOD case.

Understanding Near-OOD Detection. When the ID and OOD datasets have similar semantics or styles, OOD detection tasks become more challenging. consider this issue and name it near-OOD detection. Existing benchmarks include 1) MNIST as ID dataset, and Fashion-MNIST or Not-MNIST as OOD datasets; and 2) CIFAR-1010 as ID dataset, and CIFAR-100100 as OOD dataset. From the theoretical view, some near-OOD tasks may imply the overlap condition, i.e. Definition 4. Therefore, Theorems 3 and 12 imply that near-OOD detection may be not learnable. Developing a theory to understand the feasibility of near-OOD detection is still an open question.

Understanding One-class Novelty Detection. In one-class novelty detection and semantic anomaly detection (i.e. K=1K=1), Theorem 6 has revealed that it is necessary to use a large-capacity model to ensure the good generalization in the separate space. Theorem 3 and Theorem 12 suggest that we should try to avoid the overlap between ID and OOD distributions in the one-class case. If the overlap cannot be avoided, we suggest considering the multi-class OOD detection instead of the one-class case. Additionally, in the density-based space, Theorem 11 has shown that it is necessary to select a suitable hypothesis space satisfying the Realizability Assumption to ensure the learnability of OOD detection in the density-based space. Generally, a large-capacity model can be helpful to guarantee that the Realizability Assumption holds.

Related Work

We briefly review the related theoretical works below. See Appendix A for detailed related works.

OOD Detection Theory. understands the OOD detection via goodness-of-fit tests and typical set hypothesis, and argues that minimal density estimation errors can lead to OOD detection failures without assuming an overlap between ID and OOD distributions. Beyond , paves a new avenue to designing provable OOD detection algorithms. Compared to , our theory focuses on the PAC learnable theory of OOD detection and identifies several necessary and sufficient conditions for the learnability of OOD detection, opening a door to study OOD detection in theory.

Open-set Learning Theory. and propose the agnostic PAC learning bounds for open-set detection and open-set domain adaptation, respectively. Unfortunately, all require that the test data are indispensable during the training process. To investigate open-set learning (OSL) without accessing the test data during training, proposes and investigates the almost agnostic PAC learnability for OSL. However, the assumptions used in are very strong and unpractical.

Learning Theory for Classification with Reject Option. Many works also investigate the classification with reject option (CwRO) problem, which is similar to OOD detection in some cases. study the learning theory and propose the PAC learning bounds for CwRO. However, compared to our work regarding OOD detection, existing CwRO theories mainly focus on how the ID risk RDinR^{\rm in}_{D} (i.e., the risk that ID data is wrongly classified) is influenced by special rejection rules. Our theory not only focuses on the ID risk, but also pays attention to the OOD risk.

Robust Statistics. In the field of robust statistics , researchers aim to propose estimators and testers that can mitigate the negative effects of outliers (similar to OOD data). The proposed estimators are supposed to be independent of the potentially high dimensionality of the data . Existing works in the field have identified and resolved the statistical limits of outlier robust statistics by constructing estimators and proving impossibility results. In the future, it is a promising and interesting research direction to study the robustness of OOD detection based on robust statistics.

PQ Learning Theory. Under some conditions, PQ learning theory can be regarded as the PAC theory for OOD detection in the semi-supervised or transductive learning cases, i.e., test data are required during training. Besides, aim to give the PAC estimation under Realizability Assumption . Our theory does not only study the PAC estimation in the realization cases, but also studies the other cases, which are more difficult than PAC theory under Realizability Assumption.

Conclusions and Future Works

Detecting OOD data has shown its significance in improving the reliability of machine learning. However, very few works discuss OOD detection in theory, which hinders real-world applications of OOD detection algorithms. In this paper, we are the first to provide the PAC theory for OOD detection. Our results imply that we cannot expect a universally consistent algorithm to handle all scenarios in OOD detection. Yet, it is still possible to make OOD detection learnable in certain scenarios. For example, when we design OOD detection algorithms, we normally only have finite ID datasets. In this real scenario, Theorem 8 provides a necessary and sufficient condition for the success of OOD detection. Our theory reveals many necessary and sufficient conditions for the learnability of OOD detection, hence opening a door to studying the learnability of OOD detection. In the future, we will focus on studying the robustness of OOD detection based on robust statistics .

Acknowledgment

JL and ZF were supported by the Australian Research Council (ARC) under FL190100149. YL is supported by the AFOSR Young Investigator Program Award. BH was supported by the RGC Early Career Scheme No. 22200720 and NSFC Young Scientists Fund No. 62006202. ZF would also like to thank Prof. Peter Bartlett and Dr. Tongliang Liu for productive discussions.

References

Checklist

Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes]

Did you describe the limitations of your work? [Yes] See Appendix B

Did you discuss any potential negative societal impacts of your work? [Yes] See Appendix B

Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]

If you are including theoretical results…

Did you state the full set of assumptions of all theoretical results? [Yes]

Did you include complete proofs of all theoretical results? [Yes]

Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)? [N/A]

Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [N/A]

Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [N/A]

Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)? [N/A]

If you are using existing assets (e.g., code, data, models) or curating/releasing new assets…

If your work uses existing assets, did you cite the creators? [N/A]

Did you mention the license of the assets? [N/A]

Did you include any new assets either in the supplemental material or as a URL? [N/A]

Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A]

Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A]

If you used crowdsourcing or conducted research with human subjects…

Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A]

Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A]

Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]

Appendix A Detailed Related Work

OOD Detection Algorithms. We will briefly review many representative OOD detection algorithms in three categories. 1) Classification-based methods use an ID classifier to detect OOD data Note that, some methods assume that OOD data are available in advance . However, the exposure of OOD data is a strong assumption . We do not consider this situation in our paper.. Representative works consider using the maximum softmax score , temperature-scaled score and energy-based score to identify OOD data. 2) Density-based methods aim to estimate an ID distribution and identify the low-density area as OOD data . 3) The recent development of generative models provides promising ways to make them successful in OOD detection . Distance-based methods are based on the assumption that OOD data should be relatively far away from the centroids of ID classes , including Mahalanobis distance , cosine similarity , and kernel similarity .

Early works consider using the maximum softmax score to express the ID-ness . Then, temperature scaling functions are used to amplify the separation between the ID and OOD data . Recently, researchers propose hyperparameter-free energy scores to improve the OOD uncertainty estimation . Additionally, researchers also consider using the information contained in gradients to help improve the performance of OOD detection .

Except for the above algorithms, researchers also study the situation, where auxiliary OOD data can be obtained during the training process . These methods are called outlier exposure, and have much better performance than the above methods due to the appearance of OOD data. However, the exposure of OOD data is a strong assumption . Thus, researchers also consider generating OOD data to help the separation of OOD and ID data . In this paper, we do not make an assumption that OOD data are available during training, since this assumption may not hold in real world.

OOD Detection Theory. rejects the typical set hypothesis, the claim that relevant OOD distributions can lie in high likelihood regions of data distribution, as implausible. argues that minimal density estimation errors can lead to OOD detection failures without assuming an overlap between ID and OOD distributions. Compared to , our theory focuses on the PAC learnable theory of OOD detection. If detectors are generated by FCNN, our theory (Theorem 12) shows that the overlap is the sufficient condition to the failure of learnability of OOD detection, which is complementary to . In addition, we identify several necessary and sufficient conditions for the learnability of OOD detection, which opens a door to studying OOD detection in theory. Beyond , paves a new avenue to designing provable OOD detection algorithms. Compared to , our paper aims to characterize the learnability of OOD detection to answer the question: is OOD detection PAC learnable?

Open-set Learning Theory. is the first to propose the agnostic PAC guarantees for open-set detection. Unfortunately, the test data must be used during the training process. considers the open-set domain adaptation (OSDA) and proposes the first learning bound for OSDA. mainly depends on the positive-unlabeled learning techniques . However, similar to , the test data must be available during training. To study open-set learning (OSL) without accessing the test data during training, proposes and studies the almost PAC learnability for OSL, which is motivated by transfer learning . In our paper, we study the PAC learnability for OOD detection, which is an open problem proposed by .

Learning Theory for Classification with Reject Option. Many works also investigate the classification with reject option (CwRO) problem, which is similar to OOD detection in some cases. study the learning theory and propose the agnostic PAC learning bounds for CwRO. However, compared to our work regarding OOD detection, existing CwRO theories mainly focus on how the ID risk (i.e., the risk that ID data is wrongly classified) is influenced by special rejection rules. Our theory not only focuses on the ID risk, but also pays attention to the OOD risk.

Robust Statistics. In the field of robust statistics , researchers aim to propose estimators and testers that can mitigate the negative effects of outliers (similar to OOD data). The proposed estimators are supposed to be independent of the potentially high dimensionality of the data . Existing works in the field have identified and resolved the statistical limits of outlier robust statistics by constructing estimators and proving impossibility results. In the future, it is a promising and interesting research direction to study the robustness of OOD detection based on robust statistics.

PQ Learning Theory. Under some conditions, PQ learning theory can be regarded as the PAC theory for OOD detection in the semi-supervised or transductive learning cases, i.e., test data are required during the training process. Additionally, PQ learning theory in aims to give the PAC estimation under Realizability Assumption . Our theory focuses on the PAC theory in different cases, which is more difficult and more practical than PAC theory under Realizability Assumption.

Appendix B Limitations and Potential Negative Societal Impacts

Limitations. The main limitation of our work lies in that we do not answer the most general question:

Given any hypothesis space H\mathcal{H} and space DXY\mathscr{D}_{XY}, what is the necessary and sufficient condition to ensure the PAC learnability of OOD detection?

However, this question is still difficult to be addressed, due to limited mathematical skills. Yet, based on our observations and the main results in our paper, we believe the following result may hold:

Conjecture: If H\mathcal{H} is agnostic learnable for supervised learning, then OOD detection is learnable in DXY\mathscr{D}_{XY} if and only if compatibility condition (i.e., Condition 3) holds.

Potential Negative Societal Impacts. Since our paper is a theoretical paper and the OOD detection problem is significant to ensure the safety of deploying existing machine learning algorithms, there are no potential negative societal impacts in our paper.

Appendix C Discussions and Details about Experiments in Figure 1

In this section, we summarize our main results, then give the details of the experiments in Figure 1.

We summarize our main results as follows:

∙\bullet A necessary condition (i.e., Condition 1) for the learnability of OOD detection is proposed. Theorem 2 shows that Condition 1 is the necessary and sufficient condition for the learnability of OOD detection, when the domain space is the single-distribution space DXYDXY\mathscr{D}_{XY}^{D_{XY}}. This implies the Condition 1 is the necessary condition for the learnability of OOD detection.

∙\bullet Theorem 3 has shown that the overlap between ID and OOD data can lead the failures of OOD detection under some mild assumptions. Furthermore, Theorem 12 shows that when K=1K=1, the overlap is the sufficient condition for the failures of OOD detection, when the hypothesis space is FCNN-based or score-based.

∙\bullet Theorem 4 provides an impossibility theorem for the total space DXYall\mathscr{D}_{XY}^{\rm all}. OOD detection is not learnable in DXYall\mathscr{D}_{XY}^{\rm all} for any non-trivial hypothesis space.

∙\bullet Theorem 5 gives impossibility theorems for the separate space DXYs\mathscr{D}_{XY}^{s}. To ensure the impossibility theorems hold, mild assumptions are required. Theorem 5 also implies that OOD detection may be learnable in the separate space DXYs\mathscr{D}_{XY}^{s}, if the feature space is finite, i.e., ∣X∣<+∞|\mathcal{X}|<+\infty. Additionally, Theorem 10 implies that the finite feature space may be the necessary condition to ensure the learnability of OOD detection in the separate space.

∙\bullet When ∣X∣<+∞|\mathcal{X}|<+\infty and K=1K=1, Theorem 6 provides the necessary and sufficient condition for the learnability of OOD detection in the separate space DXYs\mathscr{D}_{XY}^{s}. Theorem 6 implies that if the OOD detection can be learnable in the distribution-agnostic case, then a large-capacity model is necessary. Based on Theorem 6, Theorem 7 studies the learnability in the K>1K>1 case.

∙\bullet The compatibility condition (i.e., Condition 3) for the learnability of OOD detection is proposed. Theorem 8 shows that Condition 3 is the necessary and sufficient condition for the learnability of OOD detection in the finite-ID-distribution space DXYF\mathscr{D}_{XY}^{F}. This also implies Condition 3 is the necessary condition for any prior-unknown space. Note that we can only collect finite ID datasets to build models. Hence, Theorem 8 can handle the most practical scenarios.

∙\bullet To further understand the importance of the compatibility condition (Condition 3). Theorem 9 considers the density-based space DXYμ,b\mathscr{D}_{XY}^{\mu,b}. We discover that Realizability Assumption implies the compatibility condition in the density-based space. Based on this observation, we prove that OOD detection is learnable in DXYμ,b\mathscr{D}_{XY}^{\mu,b} under Realizability Assumption.

∙\bullet Theorem 10 gives practical applications of our theory. In this theorem, we discover that the finite feature space is a necessary and sufficient condition for the learnability of OOD detection in the separate space DXYs\mathscr{D}_{XY}^{s}, when the hypothesis space is FCNN-based or score-based.

∙\bullet Theorem 11 has shown that when K=1K=1 and the hypothesis space is FCNN-based or score-based, Realizability Assumption, Condition 3, Condition 1 and the learnability of OOD detection in the density-based space DXYμ,b\mathcal{D}_{XY}^{\mu,b} are all equivalent.

∙\bullet Meaning of Our Theory. In classical statistical learning theory, the generalization theory guarantees that a well-trained classifier can be generalized well on the test set as long as the training and test sets are from the same distribution . However, since the OOD data are unseen during the training process, it is very difficult to determine whether the generalization theory holds for OOD detection.

Normally, OOD data are unseen and can be various. We hope that there exists an algorithm that can be used for the various OOD data instead of some certain OOD data, which is the reason why the generalization theory for OOD detection needs to be developed. In this paper, we investigate the generalization theory regarding OOD detection and point out when the OOD detection can be successful. Our theory is based on the PAC learning theory. The impossibility theorems and the given necessary and sufficient conditions outlined provide important perspectives from which to think about OOD detection.

C.2 Details of Experiments in Figure 1

In this subsection, we present details of the experiments in Figure 1, including data generation, configuration and OOD detection procedure.

Data Generation. ID and OOD data are drawn from the following uniform (U) distributions (note that we use U(I){\rm U}(\mathbf{I}) to present the uniform distribution in region I\mathbf{I}). ∙\bullet The marginal distribution of ID distribution for class cc: for any c∈{1,...,10}c\in\{1,...,10\},

here di=5+gapII∗(i−1)+4(i−2)d_{i}=5+{\rm gap}_{\rm II}*(i-1)+4(i-2) and gapII{\rm gap}_{\rm II} is a positive constant. ∙\bullet The class-prior probability for class cc: for any c∈{1,...,10}c\in\{1,...,10\},

∙\bullet The marginal distribution of OOD distribution:

Figure 2 shows the OOD and ID distributions, when gapII=20{\rm gap}_{\rm II}=20 and gapIO=−2{\rm gap}_{\rm IO}=-2. In Figure 1, we draw nn data from ID distribution (n=15,000,20,000,25,000n=15,000,20,000,25,000) and 25,00025,000 data from the OOD distribution.

OOD Detection Procedure. We first train an ID classifier with nn data drawn from the ID distribution. Then, according to , we apply the free-energy score to identify the OOD data and calculate the α\alpha-risk (with the -11 loss). We repeat the above detection procedure 2020 times and report the average α\alpha-risk in Figure 1. Note that, following , we choose the threshold used by the free-energy method so that 95%95\% of ID data are correctly identified as the ID classes by the OOD detector.

Appendix D Notations

In this section, we summarize important notations in Table 1.

Given f=[f1,...,fl]⊤\mathbf{f}=[f^{1},...,f^{l}]^{\top}, for any x∈X\mathbf{x}\in\mathcal{X},

where fkf^{k} is the kk-th coordinate of f\mathbf{f} and fif^{i} is the ii-th coordinate of f\mathbf{f}. The above definition about arg max⁡\operatorname*{arg\,max} aims to overcome some special cases. For example, there exist k1{k}_{1}, k2{k}_{2} (k1<k2k_{1}<k_{2}) such that fk1(x)=fk2(x)f^{k_{1}}(\mathbf{x})=f^{k_{2}}(\mathbf{x}) and fk1(x)>fi(x)f^{k_{1}}(\mathbf{x})>f^{i}(\mathbf{x}), fk2(x)>fi(x)f^{k_{2}}(\mathbf{x})>f^{i}(\mathbf{x}), ∀i∈{1,...,l}−{k1,k2}\forall i\in\{1,...,l\}{-}\{k_{1},k_{2}\}. Then, according to the above definition, k2=arg max⁡k∈{1,...,l}fk(x)k_{2}=\operatorname*{arg\,max}_{k\in\{1,...,l\}}f^{k}(\mathbf{x}).

D.2 Realizability Assumption

A domain space DXY\mathscr{D}_{XY} and hypothesis space H\mathcal{H} satisfy the Realizability Assumption, if for each domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, there exists at least one hypothesis function h∗∈Hh^{*}\in\mathcal{H} such that RD(h∗)=0R_{D}(h^{*})=0.

D.3 Learnability and PAC learnability

Here we give a proof to show that Learnability given in Definition 1 and PAC learnability are equivalent.

First, we prove that Learnability concludes the PAC learnability.

Note that RD(A(S))−inf⁡h∈HRD(h)≥0R_{D}(\mathbf{A}(S))-\inf_{h\in\mathcal{H}}R_{D}(h)\geq 0. Therefore, by Markov’s inequality, we have

Because ϵcons(n)\epsilon_{\rm cons}(n) is monotonically decreasing, we can find a smallest mm such that ϵcons(m)≥ϵδ\epsilon_{\rm cons}(m)\geq\epsilon\delta and ϵcons(m−1)<ϵδ\epsilon_{\rm cons}(m-1)<\epsilon\delta, for δ∈(0,1)\delta\in(0,1). We define that m(ϵ,δ)=mm(\epsilon,\delta)=m. Therefore, for any ϵ>0\epsilon>0 and δ∈(0,1)\delta\in(0,1), there exists a function m(ϵ,δ)m(\epsilon,\delta) such that when n>m(ϵ,δ)n>m(\epsilon,\delta), with the probability at least 1−δ1-\delta, we have

which is the definition of PAC learnability.

Second, we prove that the PAC learnability concludes Learnability.

PAC-learnability: for any ϵ>0\epsilon>0 and 0<δ<10<\delta<1, there exists a function m(ϵ,δ)>0m(\epsilon,\delta)>0 such that when the sample size n>m(ϵ,δ)n>m(\epsilon,\delta), we have that with the probability at least 1−δ>01-\delta>0,

If we set δ=ϵ\delta=\epsilon, then when the sample size n>m(ϵ,ϵ)n>m(\epsilon,\epsilon), we have that

which implies the Learnability in Definition 1. We have completed this proof.

D.4 Explanations for Some Notations in Section 2

First, we explain the concept that S∼DXIYInS\sim{D}_{X_{I}Y_{I}}^{n} in Eq. (2).

S={(x1,y1),...,(xn,yn)}S=\{(\mathbf{x}^{1},{y}^{1}),...,(\mathbf{x}^{n},{y}^{n})\} is training data drawn independent and identically distributed from DXIYID_{X_{\rm I}Y_{\rm I}}.

DXIYInD_{X_{\rm I}Y_{\rm I}}^{n} denotes the probability over nn-tuples induced by applying DXIYID_{X_{\rm I}Y_{\rm I}} to pick each element of the tuple independently of the other members of the tuple.

Because these samples are i.i.d. drawn nn times, researchers often use ”S∼DXIYInS\sim D_{X_{\rm I}Y_{\rm I}}^{n}” to represent a sample set SS (of size nn) whose each element is drawn i.i.d. from DXIYID_{X_{\rm I}Y_{\rm I}}.

Second, we explain the concept ”++” in (1−πout)DXI+πoutDXO(1-\pi^{\rm out})D_{X_{\rm I}}+\pi^{\rm out}D_{X_{\rm O}}.

For convenience, let P=(1−πout)DXIP=(1-\pi^{\rm out})D_{X_{\rm I}} and Q=πoutDXOQ=\pi^{\rm out}D_{X_{\rm O}}. It is clear that PP and QQ are measures. Then P+QP+Q is also a measure, which is defined as follows: for any measurable set A⊂XA\subset\mathcal{X}, we have

For example, when PP and QQ are discrete measures, then P+QP+Q is also discrete measure: for any x∈X\mathbf{x}\in\mathcal{X},

When PP and QQ are continuous measures with density functions ff and gg, then P+QP+Q is also continuous measure with density function f+gf+g: for any measurable A⊂XA\subset\mathcal{X},

For example, when DXYD_{XY} is a finite discrete distribution: let Z={(x1,y1),...,(xm,ym)}\mathcal{Z}=\{(\mathbf{x}^{1},y^{1}),...,(\mathbf{x}^{m},y^{m})\} be the support set of DXYD_{XY}, and assume that aia^{i} is the probability for (xi,yi)(\mathbf{x}^{i},y^{i}), i.e., ai=DXY(xi,yi)a^{i}=D_{XY}(\mathbf{x}^{i},y^{i}). Then

When DXD_{X} is a continuous distribution with density ff, and DY∣X(Y=k∣X=x)D_{Y|X}(Y=k|X=\mathbf{x}) (kk-th class-conditional distribution for x\mathbf{x}) is ak(x)a^{k}(\mathbf{x}), then

where DY∣X(Y=k∣X=x)D_{Y|X}(Y=k|X=\mathbf{x}) is the kk-th class-conditional distribution.

Appendix E Proof of Theorem 1

To prove that DXY′\mathscr{D}_{XY}^{\prime} is a priori-unknown space, we need to show that for any DXYα′∈DXY′D_{XY}^{\alpha^{\prime}}\in\mathscr{D}_{XY}^{\prime}, then DXYα∈DXY′D_{XY}^{\alpha}\in\mathscr{D}_{XY}^{\prime} for any α∈[0,1)\alpha\in[0,1).

According to the definition of DXY′\mathscr{D}_{XY}^{\prime}, for any DXYα′∈DXY′D_{XY}^{\alpha^{\prime}}\in\mathscr{D}_{XY}^{\prime}, we can find a domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, which can be written as 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}} (here πout∈[0,1)\pi^{\rm out}\in[0,1)) such that

Note that DXYα=(1−α)DXIYI+αDXOYOD_{XY}^{\alpha}=(1-\alpha)D_{X_{\rm I}Y_{\rm I}}+\alpha D_{X_{\rm O}Y_{\rm O}}.

Therefore, based on the definition of DXY′\mathscr{D}_{XY}^{\prime}, for any α∈[0,1)\alpha\in[0,1), DXYα∈DXY′D_{XY}^{\alpha}\in\mathscr{D}_{XY}^{\prime}, which implies that DXY′\mathscr{D}_{XY}^{\prime} is a prior-known space. Additionally, for any DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, we can rewrite DXYD_{XY} as DXYπoutD_{XY}^{\pi_{\rm out}}, thus DXY=DXYπout∈DXY′D_{XY}=D_{XY}^{\pi_{\rm out}}\in\mathscr{D}_{XY}^{\prime}, which implies that DXY⊂DXY′\mathscr{D}_{XY}\subset\mathscr{D}_{XY}^{\prime}.

First, we prove that Definition 1 concludes Definition 2, if DXY\mathscr{D}_{XY} is a prior-unknown space:

In the priori-unknown space, for any DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, we have that for any α∈[0,1)\alpha\in[0,1),

Then, according to the definition of learnability of OOD detection, we have an algorithm A\mathbf{A} and a monotonically decreasing sequence ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, such that for any α∈[0,1)\alpha\in[0,1),

Since RDα(A(S))=RDα(A(S))R_{D^{\alpha}}(\mathbf{A}(S))=R_{D}^{\alpha}(\mathbf{A}(S)) and RDα(h)=RDα(h)R_{D^{\alpha}}(h)=R_{D}^{\alpha}(h), we have that

Next, we consider the case that α=1\alpha=1. Note that

Then, we assume that hϵ∈Hh_{\epsilon}\in\mathcal{H} satisfies that

Let α→1\alpha\rightarrow 1. Then, for any ϵ>0\epsilon>0,

Combining Eq. (10) with Eq. (11), we have

Hence, Lebesgue’s Dominated Convergence Theorem implies that

Combining Eq. (13), Eq. (14) with Eq. (15), we obtain that

Since RDout(A(S))=RD1(A(S))R_{D}^{\rm out}(\mathbf{A}(S))=R_{D}^{1}(\mathbf{A}(S)) and RDout(h)=RD1(h)R_{D}^{\rm out}(h)=R_{D}^{1}(h), we obtain that

Combining Eq. (9) and Eq. (16), we have proven that: if the domain space DXY\mathscr{D}_{XY} is a priori-unknown space, then OOD detection is learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}.                                                                                ⇓~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}{\Huge\Downarrow} OOD detection is strongly learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}: there exist an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H}, and a monotonically decreasing sequence ϵ(n)\epsilon(n), such that ϵ(n)→0\epsilon(n)\rightarrow 0, as n→+∞n\rightarrow+\infty,

which means that OOD detection is learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}. We have completed this proof.

The third result is a simple conclusion of the second result. Hence, we omit it. ∎

Appendix F Proof of Theorem 2

Before introducing the proof of Theorem 2, we extend Condition 1 to a general version (Condition 4). Then, Lemma 1 proves that Conditions 1 and 4 are the necessary conditions for the learnability of OOD detection. First, we provide the details of Condition 4.

Let Δlo={(λ1,...,λl):∑j=1lλj<1 and λj≥0,∀j=1,...,l}\Delta_{l}^{\rm o}=\{(\lambda_{1},...,\lambda_{l}):\sum_{j=1}^{l}\lambda_{j}<1~{}{\rm and}~{}\lambda_{j}\geq 0,\forall j=1,...,l\}, where ll is a positive integer. Next, we introduce an important definition as follows:

Given any domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY}, we say joint distributions Q1,...,QlQ_{1},...,Q_{l}, which are defined over X×{K+1}\mathcal{X}\times\{K+1\}, are the OOD convex decomposition for DXYD_{XY}, if

for some (λ1,...,λl)∈Δlo(\lambda_{1},...,\lambda_{l})\in\Delta_{l}^{\rm o}. We also say domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY} is an OOD convex domain corresponding to OOD convex decomposition Q1,...,QlQ_{1},...,Q_{l}, if for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

We extend the linear condition (Condition 1) to a multi-linear scenario.

For each OOD convex domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY} corresponding to OOD convex decomposition Q1,...,QlQ_{1},...,Q_{l}, the following function

where 0\mathbf{0} is the 1×l1\times l vector, whose elements are , and αj{\bm{\alpha}}_{j} is the 1×l1\times l vector, whose jj-th element is 11 and other elements are .

When l=1l=1 and the domain space DXY\mathscr{D}_{XY} is a priori-unknown space, Condition 4 degenerates into Condition 1. Lemma 1 shows that Condition 4 is necessary for the learnability of OOD detection.

Given a priori-unknown space DXY\mathscr{D}_{XY} and a hypothesis space H\mathcal{H}, if OOD detection is learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}, then Conditions 1 and 4 hold.

Since Condition 1 is a special case of Condition 4, we only need to prove that Condition 4 holds.

For any OOD convex domain DXY∈DXYD_{XY}\in\mathscr{D}_{XY} corresponding to OOD convex decomposition Q1,...,QlQ_{1},...,Q_{l}, and any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o}, we set

Since OOD detection is learnable in DXY\mathscr{D}_{XY} for H\mathcal{H}, there exist an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H}, and a monotonically decreasing sequence ϵ(n)\epsilon(n), such that ϵ(n)→0\epsilon(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and

Therefore, we have that for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

Step 1. Since αj∉Δlo{\bm{\alpha}}_{j}\notin\Delta_{l}^{\rm o}, we need to prove that

where αj{\bm{\alpha}}_{j} is the 1×l1\times l vector, whose jj-th element is 11 and other elements are .

We note that inf⁡h∈HRQj(h)=fD,Q(αj)\inf_{h\in\mathcal{H}}R_{Q_{j}}(h)=f_{D,Q}({\bm{\alpha}}_{j}). Therefore,

Step 2. It is easy to check that for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

According to Eq. (18) and Eq. (22), we have

Combining Eq. (24) with Eq. (23), we complete the proof. ∎

For the sake of convenience, we set fD(α)=inf⁡h∈HRDα(h)f_{D}(\alpha)=\inf_{h\in\mathcal{H}}R_{D}^{\alpha}(h), for any α∈\alpha\in.

First, we prove that fD(α)=(1−α)fD(0)+αfD(1)f_{D}(\alpha)=(1-\alpha)f_{D}(0)+\alpha f_{D}(1), ∀α∈[0,1)\forall\alpha\in[0,1) implies

For any ϵ>0\epsilon>0 and 0≤α<10\leq\alpha<1, we can find hϵα∈Hh_{\epsilon}^{\alpha}\in\mathcal{H} satisfying that

Note that fD(α)=(1−α)fD(0)+αfD(1),∀α∈[0,1)f_{D}(\alpha)=(1-\alpha)f_{D}(0)+\alpha f_{D}(1),\forall\alpha\in[0,1), i.e.,

Using Eqs. (25) and (26), we have that for any 0≤α<10\leq\alpha<1,

Since RDout(hϵα)−inf⁡h∈HRDout(h)≥0R_{D}^{\rm out}(h_{\epsilon}^{\alpha})-\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)\geq 0 and RDin(hϵα)−inf⁡h∈HRDin(h)≥0R_{D}^{\rm in}(h_{\epsilon}^{\alpha})-\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)\geq 0, Eq. (27) implies that: for any 0<α<10<\alpha<1,

If we set α=0.5\alpha=0.5, we obtain that for any ϵ>0\epsilon>0,

Second, we prove that for any ϵ>0\epsilon>0, if

then fD(α)=(1−α)fD(0)+αfD(1)f_{D}(\alpha)=(1-\alpha)f_{D}(0)+\alpha f_{D}(1), for any α∈[0,1)\alpha\in[0,1). Let hϵ∈{h′∈H:RDin(h′)≤inf⁡h∈HRDin(h)+2ϵ}∩{h′∈H:RDout(h′)≤inf⁡h∈HRDout(h)+2ϵ}h_{\epsilon}\in\{h^{\prime}\in\mathcal{H}:R_{D}^{\rm in}(h^{\prime})\leq\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)+2\epsilon\}\cap\{h^{\prime}\in\mathcal{H}:R_{D}^{\rm out}(h^{\prime})\leq\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)+2\epsilon\}.

which implies that ∣fD(α)−(1−α)fD(0)−αfD(1)∣≤2ϵ|f_{D}(\alpha)-(1-\alpha)f_{D}(0)-\alpha f_{D}(1)|\leq 2\epsilon.

As ϵ→0\epsilon\rightarrow 0, ∣fD(α)−(1−α)fD(0)−αfD(1)∣≤0|f_{D}(\alpha)-(1-\alpha)f_{D}(0)-\alpha f_{D}(1)|\leq 0. We have completed the proof. ∎

Based on Lemma 1, we obtain that Condition 1 is the necessary condition for the learnability of OOD detection in the single-distribution space DXYDXY\mathscr{D}_{XY}^{D_{XY}}. Next, it suffices to prove that Condition 1 is the sufficient condition for the learnability of OOD detection in the single-distribution space DXYDXY\mathscr{D}_{XY}^{D_{XY}}. We use Lemma 2 to prove the sufficient condition.

Let F\mathscr{F} be the infinite sequence set that consists of all infinite sequences, whose coordinates are hypothesis functions, i.e.,

For each h∈F{\bm{h}}\in\mathscr{F}, there is a corresponding algorithm Ah\mathbf{A}_{\bm{h}}In this paper, we regard an algorithm as a mapping from ∪n=1+∞(X×Y)n\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n} to H\mathcal{H}. So we can design an algorithm like this.: Ah(S)=hn, if ∣S∣=n\mathbf{A}_{\bm{h}}(S)=h_{n},~{}{\rm if}~{}|S|=n. F\mathscr{F} generates an algorithm class A={Ah:∀h∈F}\mathscr{A}=\{\mathbf{A}_{\bm{h}}:\forall{\bm{h}}\in\mathscr{F}\}. We select a consistent algorithm from the algorithm class A\mathscr{A}.

Since (1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDout(h)≤inf⁡h∈HRDα(h)(1-\alpha)\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)+\alpha\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)\leq\inf_{h\in\mathcal{H}}R_{D}^{\rm\alpha}(h), we obtain that for any α∈\alpha\in,

Appendix G Proofs of Theorem 3 and Theorem 4

We first explain how we get fIf_{\rm I} and fOf_{\rm O} in Definition 4. Since DXD_{X} is absolutely continuous respect to μ\mu (DX≪μD_{X}\ll\mu), then DXI≪μD_{X_{\rm I}}\ll\mu and DXO≪μD_{X_{\rm O}}\ll\mu. By Radon-Nikodym Theorem , we know there exist two non-negative functions defined over X\mathcal{X}: fIf_{\rm I} and fOf_{\rm O} such that for any μ\mu-measurable set A⊂XA\subset\mathcal{X},

Second, we prove that for any α∈(0,1)\alpha\in(0,1), inf⁡h∈HRDα(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\alpha}(h)>0.

We define Am={x∈X:fI(x)≥1m and fO(x)≥1m}A_{m}=\{\mathbf{x}\in\mathcal{X}:f_{\rm I}(\mathbf{x})\geq\frac{1}{m}~{}{\rm and}~{}f_{\rm O}(\mathbf{x})\geq\frac{1}{m}\}. It is clear that

which implies that there exists m0m_{0} such that

Third, Condition 1 indicates that inf⁡h∈HRDα(h)=(1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\alpha}(h)=(1-\alpha)\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)+\alpha\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 (here we have used conditions inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0), which contradicts with inf⁡h∈HRDα(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\alpha}(h)>0 (α∈(0,1)\alpha\in(0,1)). Therefore, Condition 1 does not hold. Using Lemma 1, we obtain that OOD detection in DXY\mathscr{D}_{XY} is not learnable for H\mathcal{H}. ∎

G.2 Proof of Theorem 4

We need to prove that OOD detection is not learnable in the total space DXYall\mathscr{D}_{XY}^{\rm all} for H\mathcal{H}, if H\mathcal{H} is non-trivial, i.e., {x∈X:∃h1,h2∈H,s.t. h1(x)∈Y,h2(x)=K+1}≠∅.\{\mathbf{x}\in\mathcal{X}:\exists h_{1},h_{2}\in\mathcal{H},\textnormal{s.t.}~{}h_{1}(\mathbf{x})\in\mathcal{Y},h_{2}(\mathbf{x})=K+1\}\neq\emptyset.

The main idea is to construct a domain DXYD_{XY} satisfying that: 1) the ID and OOD distributions have overlap (Definition 4); and 2) RDin(h1)=0R_{D}^{\rm in}(h_{1})=0, RDout(h2)=0R_{D}^{\rm out}(h_{2})=0.

According to the condition that H\mathcal{H} is non-trivial, we know that there exist h1,h2∈Hh_{1},h_{2}\in\mathcal{H} such that h1(x1)∈Y,h2(x1)=K+1h_{1}(\mathbf{x}_{1})\in\mathcal{Y},h_{2}(\mathbf{x}_{1})=K+1, for some x1∈X\mathbf{x}_{1}\in\mathcal{X}. We set DXY=0.5∗δ(x1,h1(x1))+0.5∗δ(x1,h2(x1))D_{XY}=0.5*\delta_{(\mathbf{x}_{1},h_{1}(\mathbf{x}_{1}))}+0.5*\delta_{(\mathbf{x}_{1},h_{2}(\mathbf{x}_{1}))}, where δ\delta is the Dirac measure. It is easy to check that RDin(h1)=0R_{D}^{\rm in}(h_{1})=0, RDout(h2)=0R_{D}^{\rm out}(h_{2})=0, which implies that inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0. In addition, the ID distribution δ(x1,h1(x1))\delta_{(\mathbf{x}_{1},h_{1}(\mathbf{x}_{1}))} and OOD distribution δ(x1,h2(x1))\delta_{(\mathbf{x}_{1},h_{2}(\mathbf{x}_{1}))} have overlap x1\mathbf{x}_{1}. By using Theorem 3, we have completed this proof. ∎

Appendix H Proof of Theorem 5

Before proving Theorem 5, we need three important lemmas.

Suppose that DXYD_{XY} is a domain with OOD convex decomposition Q1,...,QlQ_{1},...,Q_{l} (convex decomposition is given by Definition 6 in Appendix F), and DXYD_{XY} is a finite discrete distribution, then (the definition of fD,Qf_{D,Q} is given in Condition 4)

where 0\mathbf{0} is the 1×l1\times l vector, whose elements are , and αj{\bm{\alpha}}_{j} is the 1×l1\times l vector, whose jj-th element is 11 and other elements are , and

To better understand this proof, we recall the definition of fD,Q(α1,...,αl)f_{D,Q}(\alpha_{1},...,\alpha_{l}):

Let DXY=(1−∑j=1lλj)DXIYI+∑j=1lλjQjD_{XY}=(1-\sum_{j=1}^{l}\lambda_{j})D_{X_{\rm I}Y_{\rm I}}+\sum_{j=1}^{l}\lambda_{j}Q_{j}, for some (λ1,...,λl)∈Δlo(\lambda_{1},...,\lambda_{l})\in\Delta_{l}^{\rm o}. Since DXYD_{XY} has finite support set, we have

We can find that h_{0}\in\operatorname*{arg\,min}_{h\in\mathcal{H}}\Big{(}(1-\sum_{j=1}^{l}\lambda_{j})R_{D}^{\rm in}(h)+\sum_{j=1}^{l}\lambda_{j}R_{Q_{j}}(h)\Big{)}. Hence,

Note that the condition fD,Q(α1,...,αl)=(1−∑j=1lαj)fD,Q(0)+∑j=1lαjfD,Q(αj)f_{D,Q}(\alpha_{1},...,\alpha_{l})=(1-\sum_{j=1}^{l}\alpha_{j})f_{D,Q}(\mathbf{0})+\sum_{j=1}^{l}\alpha_{j}f_{D,Q}({\bm{\alpha}}_{j}) implies

Therefore, Eq. (28) and Eq. (29) imply that

Since RDin(h0)≥inf⁡h∈HRDin(h)R_{D}^{\rm in}(h_{0})\geq\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h) and RQj(h0)≥inf⁡h∈HRQjin(h)R_{Q_{j}}(h_{0})\geq\inf_{h\in\mathcal{H}}R_{Q_{j}}^{\rm in}(h), for j=1,...,lj=1,...,l, then using Eq. (30), we have that

we obtain that for any h′∈⋂j=1larg min⁡h∈HRQj(h)⋂arg min⁡h∈HRDin(h)h^{\prime}\in\bigcap_{j=1}^{l}\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{Q_{j}}(h)\bigcap\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}^{\rm in}(h),

Combining Eq. (31) with Eq. (32), we obtain that

then, for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

Therefore, for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

which implies that: for any (α1,...,αl)∈Δlo(\alpha_{1},...,\alpha_{l})\in\Delta_{l}^{\rm o},

Suppose that Assumption 1 holds. If there is a finite discrete domain DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s} such that inf⁡h∈HRDout(h)>0,\inf_{h\in\mathcal{H}}R_{D}^{\rm out}({\bm{h}})>0, then OOD detection is not learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}.

Suppose that suppDXO={x1out,...,xlout}{\rm supp}D_{X_{\rm O}}=\{\mathbf{x}_{1}^{\rm out},...,\mathbf{x}_{l}^{\rm out}\}, then it is clear that DXYD_{XY} has OOD convex decomposition δx1out,...,δxlout\delta_{\mathbf{x}_{1}^{\rm out}},...,\delta_{\mathbf{x}_{l}^{\rm out}}, where δx\delta_{\mathbf{x}} is the dirac measure whose support set is {x}\{\mathbf{x}\}.

Since H\mathcal{H} is the separate space for OOD (i.e., Assumption 1 holds), then ∀j=1,...,l\forall j=1,...,l,

This implies that: if ⋂j=1larg min⁡h∈HRδxjout(h)≠∅\bigcap_{j=1}^{l}\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{\delta_{\mathbf{x}_{j}^{\rm out}}}(h)\neq\emptyset, then for ∀h′∈⋂j=1larg min⁡h∈HRδxjout(h)\forall h^{\prime}\in\bigcap_{j=1}^{l}\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{\delta_{\mathbf{x}_{j}^{\rm out}}}(h),

Therefore, if ⋂j=1larg min⁡h∈HRδxjout(h)⋂arg min⁡h∈HRDin(h)≠∅\bigcap_{j=1}^{l}\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{\delta_{\mathbf{x}_{j}^{\rm out}}}(h)\bigcap\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}^{\rm in}(h)\neq\emptyset, then for any h∗∈⋂j=1larg min⁡h∈HRδxjout(h)⋂arg min⁡h∈HRDin(h)h^{*}\in\bigcap_{j=1}^{l}\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{\delta_{\mathbf{x}_{j}^{\rm out}}}(h)\bigcap\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}^{\rm in}(h), we have that

Proof by Contradiction: assume OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, then Lemmas 1 and 3 imply that

Therefore, for any h∗∈arg min⁡h∈HRD(h)h^{*}\in\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}(h), we have that

which implies that for any h∗∈arg min⁡h∈HRD(h)h^{*}\in\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}(h), we have RDout(h∗)=0,R_{D}^{\rm out}(h^{*})=0, which implies that inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0.

It is clear that inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0 is inconsistent with the condition inf⁡h∈HRDout(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)>0. Therefore, OOD detection is not learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}. ∎

If Assumption 1 holds, VCdim(ϕ∘H)=v<+∞{\rm VCdim}(\phi\circ\mathcal{H})=v<+\infty and sup⁡h∈H∣{x∈X:h(x)∈Y}∣>m\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|>m such that v<mv<m, then OOD detection is not learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, where ϕ\phi maps ID’s labels to 1{1} and maps OOD’s labels to 22.

Due to sup⁡h∈H∣{x∈X:h(x)∈Y}∣>m\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{\bm{h}}(\mathbf{x})\in\mathcal{Y}\}|>m, we can obtain a set

Let HCϕ={(ϕ∘h(x1),...,ϕ∘h(xm),ϕ∘h(xm+1):h∈H}\mathcal{H}_{C}^{\phi}=\{(\phi\circ h(\mathbf{x}_{1}),...,\phi\circ h(\mathbf{x}_{m}),\phi\circ h(\mathbf{x}_{m+1}):h\in\mathcal{H}\}. It is clear that

where (1,1,...,1)(1,1,...,1) means all elements are 11.

Let Hm+1ϕ={(ϕ∘h(x1),...,ϕ∘h(xm),ϕ∘h(xm+1):h is any hypothesis function from X to Yall}\mathcal{H}_{m+1}^{\phi}=\{(\phi\circ h(\mathbf{x}_{1}),...,\phi\circ h(\mathbf{x}_{m}),\phi\circ h(\mathbf{x}_{m+1}):h~{}\textnormal{is~{}any~{}hypothesis~{}function~{}from~{}}\mathcal{X}~{}\textnormal{to}~{}\mathcal{Y}_{\rm all}\}.

Clearly, HCϕ⊂Hm+1ϕ\mathcal{H}_{C}^{\phi}\subset\mathcal{H}_{m+1}^{\phi} and ∣Hm+1ϕ∣=2m+1|\mathcal{H}_{m+1}^{\phi}|=2^{m+1}. Sauer-Shelah-Perles Lemma (Lemma 6.10 in ) implies that

Since ∑i=0v(m+1i)<2m+1−1\sum_{i=0}^{v}\tbinom{m+1}{i}<2^{m+1}-1 (because v<mv<m), we obtain that ∣HCϕ∣≤2m+1−2|\mathcal{H}^{\phi}_{C}|\leq 2^{m+1}-2. Therefore, HCϕ∪{(2,2...,2)}\mathcal{H}^{\phi}_{C}\cup\{(2,2...,2)\} is a proper subset of Hm+1ϕ\mathcal{H}_{m+1}^{\phi}, where (2,2,...,2)(2,2,...,2) means that all elements are 22. Note that (1,1...,1)(1,1...,1) (all elements are 1) also belongs to HCϕ\mathcal{H}_{C}^{\phi}. Hence, HCϕ∪{(2,2...,2)}∪{(1,1...,1)}\mathcal{H}^{\phi}_{C}\cup\{(2,2...,2)\}\cup\{(1,1...,1)\} is a proper subset of Hm+1ϕ\mathcal{H}_{m+1}^{\phi}, which implies that we can obtain a hypothesis function h′h^{\prime} satisfying that:

Let CI=C∩{x∈X:ϕ∘h′(x)=1}C_{\rm I}=C\cap\{\mathbf{x}\in\mathcal{X}:\phi\circ h^{\prime}(\mathbf{x})=1\} and CO=C∩{x∈X:ϕ∘h′(x)=2}C_{\rm O}=C\cap\{\mathbf{x}\in\mathcal{X}:\phi\circ h^{\prime}(\mathbf{x})=2\};

Then, we construct a special domain DXYD_{XY}:

Since DXYD_{XY} is a finite discrete distribution and (ϕ∘h′(x1),...,ϕ∘h′(xm),ϕ∘h′(xm+1))∉HCϕ(\phi\circ h^{\prime}(\mathbf{x}_{1}),...,\phi\circ h^{\prime}(\mathbf{x}_{m}),\phi\circ h^{\prime}(\mathbf{x}_{m+1}))\notin\mathcal{H}^{\phi}_{C}, it is clear that arg min⁡h∈HRD(h)≠∅\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}(h)\neq\emptyset and inf⁡h∈HRD(h)>0\inf_{h\in\mathcal{H}}R_{D}(h)>0.

Proof by Contradiction: suppose that OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, then Lemma 1 implies that

Therefore, if OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, then inf⁡h∈HRDout(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)>0.

Until now, we have constructed a domain DXYD_{XY} (defined over X×Yall\mathcal{X}\times\mathcal{Y}_{\rm all}) with finite support and satisfying that inf⁡h∈HRDout(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)>0. Note that H\mathcal{H} is the separate space for OOD data (Assumption 1 holds). Using Lemma 4, we know that OOD detection is not learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, which is inconsistent with our assumption that OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}. Therefore, OOD detection is not learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}. We have completed the proof. ∎

Let VCdim(ϕ∘H)=v{\rm VCdim}(\phi\circ\mathcal{H})=v. Since sup⁡h∈H∣{x∈X:h(x)∈Y}∣=+∞\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{\bm{h}}(\mathbf{x})\in\mathcal{Y}\}|=+\infty, it is clear that sup⁡h∈H∣{x∈X:h(x)∈Y}∣>v\sup_{{h}\in\mathcal{H}}|\{\mathbf{x}\in\mathcal{X}:{\bm{h}}(\mathbf{x})\in\mathcal{Y}\}|>v. Using Lemma 5, we complete this proof. ∎

Appendix I Proofs of Theorem 6 and Theorem 7

Firstly, we need two lemmas, which are motivated by Lemma 19.2 and Lemma 19.3 in .

Let C1C_{1},…,CrC_{r} be a cover of space X\mathcal{X}, i.e., ∑i=1rCi=X\sum_{i=1}^{r}C_{i}=\mathcal{X}. Let SX={x1,...,xn}S_{X}=\{\mathbf{x}^{1},...,\mathbf{x}^{n}\} be a sequence of nn data drawn from DXID_{X_{\rm I}}, i.i.d. Then

where 1\mathbf{1} is the characteristic function.

here we have used inequality: max⁡i∈{1,...,r}aie−nai≤1/(ne)\max_{i\in\{1,...,r\}}a_{i}e^{-na_{i}}\leq 1/{(ne)}. The proof has been completed. ∎

Since X\mathcal{X} is bounded, without loss of generality, we set X⊂[0,1)d\mathcal{X}\subset[0,1)^{d}. Fix ϵ=1/T\epsilon=1/T, for some integer TT. Let r=Tdr=T^{d} and C1,C2,...,CrC_{1},C_{2},...,C_{r} be a cover of X\mathcal{X}: for every (a1,...,aT)∈[T]d:=[1,...,T]d(a_{1},...,a_{T})\in[T]^{d}:=[1,...,T]^{d}, there exists a Ci={x=(x1,...,xd):∀j∈{1,...,d},xj∈[(aj−1)/T,aj/T)}C_{i}=\{\mathbf{x}=(x_{1},...,x_{d}):\forall j\in\{1,...,d\},x_{j}\in[(a_{j}-1)/T,a_{j}/T)\}.

If x,x′\mathbf{x},\mathbf{x}^{\prime} belong to some CiC_{i}, then dist(x,x′)≤dϵ{\rm dist}(\mathbf{x},\mathbf{x}^{\prime})\leq\sqrt{d}\epsilon; otherwise, dist(x,x′)≤d{\rm dist}(\mathbf{x},\mathbf{x}^{\prime})\leq\sqrt{d}. Therefore,

Note that C1,...,CrC_{1},...,C_{r} are disjoint.

Therefore, ∑i:Ci∩SX≠∅DXI(Ci)≤DXI(∑i:Ci∩SX≠∅Ci)≤1\sum_{i:C_{i}\cap S_{X}\neq\emptyset}D_{X_{\rm I}}(C_{i})\leq D_{X_{\rm I}}(\sum_{i:C_{i}\cap S_{X}\neq\emptyset}C_{i})\leq 1. Using Lemma 6, we obtain

If we set ϵcons(n)=2dn1/(d+1)+d2den1/(d+1)\epsilon_{\rm cons}(n)=\frac{2\sqrt{d}}{n^{1/(d+1)}}+\frac{\sqrt{d}}{2^{d}en^{1/(d+1)}}, we complete this proof. ∎

First, we prove that if the hypothesis space H\mathcal{H} is a separate space for OOD (i.e., Assumption 1 holds), the constant function hin:=1∈Hh^{\rm in}:=1\in\mathcal{H}, then that OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H} implies Hall−{hout}⊂H\mathcal{H}_{\rm all}-\{h^{\rm out}\}\subset\mathcal{H}.

Proof by Contradiction: suppose that there exists h′∈Hallh^{\prime}\in\mathcal{H}_{\rm all} such that h′≠houth^{\prime}\neq h^{\rm out} and h′∉Hh^{\prime}\notin\mathcal{H}.

Let X={x1,...,xm}\mathcal{X}=\{\mathbf{x}_{1},...,\mathbf{x}_{m}\}, CI={x∈X:h′(x)∈Y}C_{\rm I}=\{\mathbf{x}\in\mathcal{X}:h^{\prime}(\mathbf{x})\in\mathcal{Y}\} and CO={x∈X:h′(x)=K+1}C_{\rm O}=\{\mathbf{x}\in\mathcal{X}:h^{\prime}(\mathbf{x})=K+1\}.

Because h′≠houth^{\prime}\neq h^{\rm out}, we know that CI≠∅C_{\rm I}\neq\emptyset.

We construct a special domain DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s}: if CO=∅C_{\rm O}=\emptyset, then DXY=DXI∗DYI∣XID_{XY}=D_{X_{\rm I}}*D_{Y_{\rm I}|X_{\rm I}}; otherwise,

Since h′∉Hh^{\prime}\notin\mathcal{H} and ∣X∣<+∞|\mathcal{X}|<+\infty, then arg min⁡h∈HRD(h)≠∅\operatorname*{arg\,min}_{h\in\mathcal{H}}R_{D}(h)\neq\emptyset, and inf⁡h∈HRD(h)>0\inf_{h\in\mathcal{H}}R_{D}(h)>0. Additionally, RDin(hin)=0R_{D}^{\rm in}(h^{\rm in})=0 (here hin=1h^{\rm in}=1), hence, inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0.

Since OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}, Lemma 1 implies that

where πout=DY(Y=K+1)=1\pi^{\rm out}=D_{Y}(Y=K+1)=1 or 0.50.5. Since inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRD(h)>0\inf_{h\in\mathcal{H}}R_{D}(h)>0, we obtain that inf⁡h∈HRDout(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)>0.

Until now, we have constructed a special domain DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s} satisfying that inf⁡h∈HRDout(h)>0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)>0. Using Lemma 4, we know that OOD detection in DXYs\mathscr{D}_{XY}^{s} is not learnable for H\mathcal{H}, which is inconsistent with the condition that OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}. Therefore, the assumption (there exists h′∈Hallh^{\prime}\in\mathcal{H}_{\rm all} such that h′≠houth^{\prime}\neq h^{\rm out} and h∉Hh\notin\mathcal{H}) doesn’t hold, which implies that Hall−{hout}⊂H\mathcal{H}_{\rm all}-\{h^{\rm out}\}\subset\mathcal{H}.

Second, we prove that if Hall−{hout}⊂H\mathcal{H}_{\rm all}-\{h^{\rm out}\}\subset\mathcal{H}, then OOD detection is learnable in DXYs\mathscr{D}_{XY}^{s} for H\mathcal{H}.

For any x∈suppDXI\mathbf{x}\in{\rm supp}D_{X_{\rm I}}, it is easy to check that for almost all S∼DXIYInS\sim D^{n}_{X_{\rm I}Y_{\rm I}},

Using Lemma 7, for any x∈suppDXI\mathbf{x}\in{\rm supp}D_{X_{\rm I}}, we have

where ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→0n\rightarrow 0 and ϵcons(n)\epsilon_{\rm cons}(n) is a monotonically decreasing sequence.

where DXI×DXIYInD_{X_{\rm I}}\times D_{X_{\rm I}Y_{\rm I}}^{n} is the product measure of DXID_{X_{\rm I}} and DXIYInD_{X_{\rm I}Y_{\rm I}}^{n} . Therefore,

It is easy to check that A(S)∈Hall−{hout}\mathbf{A}(S)\in\mathcal{H}_{\rm all}-\{h^{\rm out}\}. Therefore, we have constructed a consistent algorithm A\mathbf{A} for H\mathcal{H}. We have completed this proof. ∎

I.2 Proof of Theorem 7

Since ∣X∣<+∞|\mathcal{X}|<+\infty, we know that ∣H∣<+∞|\mathcal{H}|<+\infty, which implies that Hin\mathcal{H}^{\rm in} is agnostic PAC learnable for supervised learning in classification. Therefore, there exist an algorithm Ain:∪n=1+∞(X×Y)n→Hin\mathbf{A}^{\rm in}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H}^{\rm in} and a monotonically decreasing sequence ϵ(n)\epsilon(n), such that ϵ(n)→0\epsilon(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s},

Since ∣X∣<+∞|\mathcal{X}|<+\infty and Hb\mathcal{H}^{\rm b} almost contains all binary classifiers, then using Theorem 6 and Theorem 1, we obtain that there exist an algorithm Ab:∪n=1+∞(X×{1,2})n→Hb\mathbf{A}^{\rm b}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\{1,2\})^{n}\rightarrow\mathcal{H}^{\rm b} and a monotonically decreasing sequence ϵ′(n)\epsilon^{\prime}(n), such that ϵ′(n)→0\epsilon^{\prime}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any DXY∈DXYsD_{XY}\in\mathscr{D}_{XY}^{s},

where ϕ\phi maps ID’s labels to 11 and OOD’s label to 22,

here ϕ(S)={(x1,ϕ(y1)),...,(xn,ϕ(yn))}\phi(S)=\{(\mathbf{x}^{1},\phi({y}^{1})),...,(\mathbf{x}^{n},\phi({y}^{n}))\}, if S={(x1,y1),...,(xn,yn)}S=\{(\mathbf{x}^{1},{y}^{1}),...,(\mathbf{x}^{n},{y}^{n})\}.

Note that Hb\mathcal{H}^{b} almost contains all classifiers, and DXYs\mathscr{D}^{s}_{XY} is the separate space. Hence,

Next, we construct an algorithm A\mathbf{A} using Ain\mathbf{A}^{\rm in} and Aout\mathbf{A}^{\rm out}.

A(S)(x)={K+1,    if  Ab(ϕ(S))(x)=2;Ain(S)(x),    if  Ab(ϕ(S))(x)=1.\mathbf{A}(S)(\mathbf{x})=\left\{\begin{aligned} K+1,&~{}~{}~{}~{}{\rm if}~{}~{}\mathbf{A}^{\rm b}(\phi(S))(\mathbf{x})=2;\\ \mathbf{A}^{\rm in}(S)(\mathbf{x}),&~{}~{}~{}~{}{\rm if}~{}~{}\mathbf{A}^{\rm b}(\phi(S))(\mathbf{x})=1.\\ \end{aligned}\right.

Since inf⁡h∈HRϕ(D)in(ϕ∘h)=0\inf_{h\in\mathcal{H}}R_{\phi(D)}^{\rm in}(\phi\circ h)=0, inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0, then by Condition 2, it is easy to check that

Additionally, the risk RDin(A(S))R_{D}^{\rm in}(\mathbf{A}(S)) is from two parts: 1) ID data are detected as OOD data; 2) ID data are detected as ID data, but are classified as incorrect ID classes. Therefore, we have the inequality:

Note that the risk RDout(A(S))R_{D}^{\rm out}(\mathbf{A}(S)) is from the case that OOD data are detected as ID data. Therefore,

Note that (1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDout(h)≤inf⁡h∈HRDα(h)(1-\alpha)\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)+\alpha\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)\leq\inf_{h\in\mathcal{H}}R_{D}^{\alpha}(h). Then, using Eq. (40) and Eq. (41), we obtain that for any α∈\alpha\in,

According to Theorem 1 (the second result), we complete the proof. ∎

Appendix J Proofs of Theorems 8 and 9

Given a prior-unknown space DXY\mathscr{D}_{XY} and a hypothesis space H\mathcal{H}, if Condition 3 holds, then for any equivalence class [DXY′][D_{XY}^{\prime}] with respect to DXY\mathscr{D}_{XY}, OOD detection is learnable in the equivalence class [DXY′][D_{XY}^{\prime}] for H\mathcal{H}. Furthermore, the learning rate can attain O(1/n)O(1/n).

Let F\mathscr{F} be a set consisting of all infinite sequences, whose coordinates are hypothesis functions, i.e.,

For each h∈F{\bm{h}}\in\mathscr{F}, there is a corresponding algorithm Ah\mathbf{A}_{\bm{h}}: Ah(S)=hn, if ∣S∣=n\mathbf{A}_{\bm{h}}(S)=h_{n},~{}{\rm if}~{}|S|=n. F\mathscr{F} generates an algorithm class A={Ah:∀h∈F}\mathscr{A}=\{\mathbf{A}_{\bm{h}}:\forall{\bm{h}}\in\mathscr{F}\}. We select a consistent algorithm from the algorithm class A\mathscr{A}.

Since (1−α)inf⁡h∈HRDin(h)+αinf⁡h∈HRDout(h)≤inf⁡h∈HRDα(h)(1-\alpha)\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)+\alpha\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)\leq\inf_{h\in\mathcal{H}}R_{D}^{\rm\alpha}(h), we obtain that for any α∈\alpha\in,

Using Theorem 1 (the second result), we have completed this proof. ∎

First, we prove that if OOD detection is learnable in DXYF\mathscr{D}_{XY}^{F} for H\mathcal{H}, then Condition 3 holds.

Since DXYF\mathscr{D}^{F}_{XY} is the prior-unknown space, by Theorem 1, there exist an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H} and a monotonically decreasing sequence ϵcons(n)\epsilon_{\rm cons}(n), such that ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any DXY∈DXYFD_{XY}\in\mathscr{D}_{XY}^{F},

Then, for any ϵ>0\epsilon>0, we can find nϵn_{\epsilon} such that ϵ≥ϵcons(nϵ)\epsilon\geq\epsilon_{\rm cons}(n_{\epsilon}), therefore, if n=nϵn={n_{\epsilon}}, we have

which implies that there exists Sϵ∼DXIYInϵS_{\epsilon}\sim D^{n_{\epsilon}}_{X_{\rm I}Y_{\rm I}} such that

Therefore, for any equivalence class [DXY′][D_{XY}^{\prime}] with respect to DXYF\mathscr{D}_{XY}^{F} and any ϵ>0\epsilon>0, there exists a hypothesis function A(Sϵ)∈H\mathbf{A}(S_{\epsilon})\in\mathcal{H} such that for any domain DXY∈[DXY′]D_{XY}\in[D_{XY}^{\prime}],

Second, we prove Condition 3 implies the learnability of OOD detection in DXYF\mathscr{D}_{XY}^{F} for H.\mathcal{H}.

For convenience, we assume that all equivalence classes are [DXY1],...,[DXYm][D^{1}_{XY}],...,[D^{m}_{XY}]. By Lemma 8, for every equivalence class [DXYi][D_{XY}^{i}], we can find a corresponding algorithm ADi\mathbf{A}_{D^{i}} such that OOD detection is learnable in [DXYi][D_{XY}^{i}] for H\mathcal{H}. Additionally, we also set the learning rate for ADi\mathbf{A}_{D^{i}} is ϵi(n)\epsilon^{i}(n). By Lemma 8, we know that ϵi(n)\epsilon^{i}(n) can attain O(1/n)O(1/n).

Let Z{\mathcal{Z}} be X×Y\mathcal{X}\times\mathcal{Y}. Then, we consider a bounded universal kernel K(⋅,⋅)K(\cdot,\cdot) defined over Z×Z\mathcal{Z}\times\mathcal{Z}. Consider the maximum mean discrepancy (MMD) , which is a metric between distributions: for any distributions PP and QQ defined over Z{\mathcal{Z}}, we use MMDK(Q,P){\rm MMD}_{K}(Q,P) to represent the distance.

Let F\mathscr{F} be a set consisting of all finite sequences, whose coordinates are labeled data, i.e.,

Then, we define an algorithm space as follows:

and δ(x,y)\delta_{(\mathbf{x},y)} is the Dirac measure. Next, we prove that we can find an algorithm A\mathbf{A} from the algorithm space A\mathscr{A} such that A\mathbf{A} is the consistent algorithm.

Since the number of different equivalence classes is finite, we know that there exists a constant c>0c>0 such that for any different equivalence classes [DXYi][D_{XY}^{i}] and [DXYj][D_{XY}^{j}] (i≠ji\neq j),

Additionally, according to and the property of DXYF\mathscr{D}_{XY}^{F} (the number of different equivalence classes is finite), there exists a monotonically decreasing ϵ(n)→0\epsilon(n)\rightarrow 0, as n→+∞n\rightarrow+\infty such that for any DXY∈DD_{XY}\in\mathscr{D},

Therefore, for every equivalence class [DXYi][D_{XY}^{i}], we can find data points SDiS_{D^{i}} such that

Let S′={SD1,...,SDi,...,SDm}\mathbf{S}^{\prime}=\{S_{D^{1}},...,S_{D^{i}},...,S_{D^{m}}\}. Then, we prove that AS′\mathbf{A}_{\mathbf{S}^{\prime}} is a consistent algorithm. By Eq. (42), it is easy to check that for any i∈{1,...,m}i\in\{1,...,m\} and any 0<δ<10<\delta<1,

Therefore, (here we set δ=200ϵ(n)/c\delta=200\epsilon(n)/c)

Because ADi\mathbf{A}_{D^{i}} is a consistent algorithm for [DXYi][D_{XY}^{i}], we conclude that for all α∈\alpha\in,

Let ϵmax(n)=max⁡{ϵ1(n),...,ϵm(n)}+200Bϵ(n)c\epsilon^{\rm max}(n)=\max\{\epsilon^{1}(n),...,\epsilon^{m}(n)\}+\frac{200B\epsilon(n)}{c}.

Then, we obtain that for any DXY∈DXYFD_{XY}\in\mathscr{D}_{XY}^{F} and all α∈\alpha\in,

According to Theorem 1 (the second result), AS′\mathbf{A}_{\mathbf{S}^{\prime}} is the consistent algorithm. This proof is completed. ∎

J.2 Proof of Theorem 9

Since μ(X)<+∞\mu(\mathcal{X})<+\infty, without loss of generality, we assume that μ(X)=1\mu(\mathcal{X})=1. We also assume that fIf_{\rm I} is DXID_{X_{\rm I}}’s density function and fOf_{\rm O} is DXOD_{X_{\rm O}}’s density function. Let ff be the density function for 0.5∗DXI+0.5∗DXO0.5*D_{X_{\rm I}}+0.5*D_{X_{\rm O}}. It is easy to check that f=0.5∗fI+0.5∗fOf=0.5*f_{\rm I}+0.5*f_{\rm O}. Additionally, due to Realizability Assumption, it is obvious that for any samples S={(x1,y1),...,(xn,yn)}∼DXIYInS=\{(\mathbf{x}_{1},y_{1}),...,(\mathbf{x}_{n},y_{n})\}\sim D^{n}_{X_{\rm I}Y_{\rm I}}, i.i.d., we have that there exists h∗∈Hh^{*}\in\mathcal{H} such that

Given mm data points Sm={x1′,...,xm′}⊂XmS_{m}=\{\mathbf{x}_{1}^{\prime},...,\mathbf{x}_{m}^{\prime}\}\subset\mathcal{X}^{m}. We consider the following learning rule:

We denote the algorithm, which solves the above rule, as ASm\mathbf{A}_{S_{m}}In this paper, we regard an algorithm as a mapping from ∪n=1+∞(X×Y)n\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n} to H\mathcal{H}. So we can design an algorithm like this.. For different data points SmS_{m}, we have different algorithm ASm\mathbf{A}_{S_{m}}. Let S\mathcal{S} be the infinite sequence set that consists of all infinite sequences, whose coordinates are data points, i.e.,

Using S\mathcal{S}, we construct an algorithm space as follows:

Next, we prove that there exists an algorithm AS∈A\mathbf{A}_{\mathbf{S}}\in\mathscr{A}, which is a consistent algorithm. Given data points Sn∼μnS_{n}\sim\mu^{n}, i.i.d., using the Natarajan dimension theory and Empirical risk minimization principle , it is easy to obtain that there exists a uniform constant CθC_{\theta} such that (we mainly use the uniform bounds to obtain the following bounds)

and because of HS⊂H\mathcal{H}_{S}\subset\mathcal{H},

We set DI={DXIYI:there exists DXOYOsuch that (1−α)DXIYI+αDXOYO∈DXYμ,b}\mathscr{D}_{\rm I}=\{D_{X_{\rm I}Y_{\rm I}}:\text{there exists }D_{X_{\rm O}Y_{\rm O}}\text{such that}~{}(1-\alpha)D_{X_{\rm I}Y_{\rm I}}+\alpha D_{X_{\rm O}Y_{\rm O}}\in\mathscr{D}^{\mu,b}_{XY}\}. Then by Eq. (44), we have

Due to Realizability Assumption, we obtain that inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0. Therefore,

which implies that (in following inequalities, gg is the groundtruth labeling function, i.e., RD(g)=0R_{D}(g)=0)

This implies that (here we have used the property of zero-one loss)

Additionally, Rμ(g,K+1)=μ(x∈X:g(x)<K+1)R_{\mu}(g,K+1)=\mu({\mathbf{x}\in\mathcal{X}:g(\mathbf{x})<K+1}) and g∈HSg\in\mathcal{H}_{S}, which implies that

Combining inequalities (47) and (48), we obtain that

Using inequalities (45) and (49), we obtain that

which implies that (here we use the property of zero-one loss)

Combining inequalities (50) and (52), we have

Therefore, there exist data points Sn′S_{n}^{\prime} such that

Combining inequalities (46) and (53), we obtain that for any nn, there exists data points Sn′S_{n}^{\prime} such that

We set data point sequences S′=(S1′,S2′,...,Sn′,...)\mathbf{S}^{\prime}=(S_{1}^{\prime},S_{2}^{\prime},...,S_{n}^{\prime},...). Then, AS′∈A\mathbf{A}_{\mathbf{S}^{\prime}}\in\mathscr{A} is the universally consistent algorithm, i.e., for any α∈\alpha\in

Appendix K Proof of Proposition 1 and Proof of Proposition 2

To better understand the contents in Appendices K-M, we introduce the important notations for FCNN-based hypothesis space and score-based hypothesis space detaily.

where fi−1(x)\mathbf{f}_{i-1}(\mathbf{x}) is the ii-th layer output and f1(x)=x\mathbf{f}_{1}(\mathbf{x})=\mathbf{x}. Then, the output of FCNN is fw,b(x)=wgfg−1(x)+bg,\mathbf{f}_{\mathbf{w},\mathbf{b}}(\mathbf{x})=\mathbf{w}_{g}\mathbf{f}_{{g-1}}(\mathbf{x})+\mathbf{b}_{g}, where w={w2,...,wg}\mathbf{w}=\{\mathbf{w}_{2},...,\mathbf{w}_{g}\} and b={b2,...,bg}\mathbf{b}=\{\mathbf{b}_{2},...,\mathbf{b}_{g}\}.

An FCNN-based scoring function space is defined as:

Additionally, given two sequences q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) and q′=(l1′,...,lg′′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g^{\prime}}^{\prime}), we use the notation q≲q′\mathbf{q}\lesssim\mathbf{q}^{\prime} to represent the following equations and inequalities:

Given a sequence q=(l1,...lg)\mathbf{q}=(l_{1},...l_{g}) satisfying that l1=dl_{1}=d and lg=K+1l_{g}=K+1, the FCNN-based scoring function space Fqσ\mathcal{F}_{\mathbf{q}}^{\sigma} can induce an FCNN-based hypothesis space. Before defining the FCNN-based hypothesis space, we define the induced hypothesis function. For any fw,b∈Fqσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}}^{\sigma}, the induced hypothesis function is:

where fw,bk(x){f}^{k}_{\mathbf{w},\mathbf{b}}(\mathbf{x}) is the kk-th coordinate of fw,b(x)\mathbf{f}_{\mathbf{w},\mathbf{b}}(\mathbf{x}). Then, we define the FCNN-based hypothesis space as follows:

Using EE, λ\lambda and f∈Fqσ\mathbf{f}\in\mathcal{F}_{\mathbf{q}}^{\sigma}, we can generate a binary classifier hf,Eλh^{\lambda}_{\mathbf{f},E}:

where 11 represents ID data, and 22 represents OOD data. Hence, a binary classification hypothesis space Hb\mathcal{H}^{b}, which consists of all hf,Eλh^{\lambda}_{\mathbf{f},E}, is generated. We define the score-based hypothesis space Hq,Eσ,λ:={hf,Eλ:∀f∈Fqσ}\mathcal{H}^{{\sigma},\lambda}_{{\mathbf{q}},E}:=\{h^{\lambda}_{\mathbf{f},E}:\forall\mathbf{f}\in\mathcal{F}_{\mathbf{q}}^{\sigma}\}.

Next, we introduce two important propositions.

Given a sequence q=(l1,...lg)\mathbf{q}=(l_{1},...l_{g}) satisfying that l1=dl_{1}=d and lg=K+1l_{g}=K+1 (note that dd is the dimension of input data and K+1K+1 is the dimension of output), then the constant functions h1h_{1}, h2h_{2},…,hK+1h_{K+1} belong to Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}, where hi(x)=ih_{i}(\mathbf{x})=i, for any x∈X\mathbf{x}\in\mathcal{X}. Therefore, Assumption 1 holds for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}.

Note that the output of FCNN can be written as

Note that in some works , bg\mathbf{b}_{g} is fixed to 0\mathbf{0}. In fact, it is easy to check that when g>2g>2 and activation function σ\sigma is not a constant, Proposition 1 still holds, even if bg=0\mathbf{b}_{g}=\mathbf{0}.

For any fw,b∈Fqσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}^{\sigma}_{\mathbf{q}}, we have

If we set wg=0l×lg−1\mathbf{w}_{g}=\mathbf{0}_{l\times l_{g-1}} and bg=v1\mathbf{b}_{g}=\mathbf{v}_{1}, then fw,b(x)=v1\mathbf{f}_{\mathbf{w},\mathbf{b}}(\mathbf{x})=\mathbf{v}_{1} for any x∈X\mathbf{x}\in\mathcal{X}, where 0l×lg−1\mathbf{0}_{l\times l_{g-1}} is l×lg−1l\times l_{g-1} zero matrix. Hence, h1h_{1} can be induced by fw,b\mathbf{f}_{\mathbf{w},\mathbf{b}}. Therefore, h1∈Hq,Eσ,λh_{1}\in\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}.

Similarly, if we set wg=0l×lg−1\mathbf{w}_{g}=\mathbf{0}_{l\times l_{g-1}} and bg=v2\mathbf{b}_{g}=\mathbf{v}_{2}, then fw,b(x)=v2\mathbf{f}_{\mathbf{w},\mathbf{b}}(\mathbf{x})=\mathbf{v}_{2} for any x∈X\mathbf{x}\in\mathcal{X}, where 0l×lg−1\mathbf{0}_{l\times l_{g-1}} is l×lg−1l\times l_{g-1} zero matrix. Hence, h2h_{2} can be induced by fw,b\mathbf{f}_{\mathbf{w},\mathbf{b}}. Therefore, h2∈Hq,Eσ,λh_{2}\in\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}. ∎

It is easy to check that when g>2g>2 and activation function σ\sigma is not a constant, Proposition 2 still holds, even if bg=0\mathbf{b}_{g}=\mathbf{0}.

Appendix L Proof of Theorem 10

Before proving Theorem 10, we need several lemmas.

Let σ\sigma be ReLU function: max⁡{x,0}\max\{x,0\}. Given q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) and q′=(l1′,...,lg′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g}^{\prime}) such that lg=lg′l_{g}=l_{g}^{\prime} and l1=l1′l_{1}=l_{1}^{\prime}, and li≤li′l_{i}\leq l^{\prime}_{i} (i=1,...,g−1)(i=1,...,g-1), then Fqσ⊂Fq′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma} and Hqσ⊂Hq′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}.

where fi−1(x)\mathbf{f}_{i-1}(\mathbf{x}) is the ii-th layer output and f1(x)=x\mathbf{f}_{1}(\mathbf{x})=\mathbf{x}. Then, the output of last layer is

where 0pq\mathbf{0}_{pq} means the p×qp\times q zero matrix. If li′−li=0l_{i}^{\prime}-l_{i}=0 and li−1′−li−1>0l_{i-1}^{\prime}-l_{i-1}>0, we set

If li−1′−li−1=0l_{i-1}^{\prime}-l_{i-1}=0 and li′−li>0l_{i}^{\prime}-l_{i}>0, we set

If li−1′−li−1=0l_{i-1}^{\prime}-l_{i-1}=0 and li′−li=0l_{i}^{\prime}-l_{i}=0, we set

It is easy to check that if li′−li>0l_{i}^{\prime}-l_{i}>0

Therefore, fw,b∈Fq′σf_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, which implies that Fqσ⊂Fq′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}. Therefore, Hqσ⊂Hq′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}. ∎

Let σ\sigma be the ReLU function: σ(x)=max⁡{x,0}\sigma(x)=\max\{x,0\}. Then, q≲q′\mathbf{q}\lesssim\mathbf{q}^{\prime} implies that Fqσ⊂Fq′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, Hqσ⊂Hq′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}, where q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) and q′=(l1′,...,lg′′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g^{\prime}}^{\prime}).

Given l′′=(l1′′,...,lg′′′′)l^{\prime\prime}=(l_{1}^{\prime\prime},...,l_{g^{\prime\prime}}^{\prime\prime}) satisfying that g≤g′′g\leq g^{\prime\prime}, li′′=lil_{i}^{\prime\prime}=l_{i} for i=1,...,g−1i=1,...,g-1, li′′=lg−1l_{i}^{\prime\prime}=l_{g-1} for i=g,...,g′′−1i=g,...,g^{\prime\prime}-1, and lg′′′′=lgl_{g^{\prime\prime}}^{\prime\prime}=l_{g}, we first prove that Fqσ⊂Fq′′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime\prime}}^{\sigma} and Hqσ⊂Hq′′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime\prime}}^{\sigma}.

where fi−1(x)\mathbf{f}_{i-1}(\mathbf{x}) is the ii-th layer output and f1(x)=x\mathbf{f}_{1}(\mathbf{x})=\mathbf{x}. Then, the output of the last layer is

We will show that fw,b∈Fq′′σ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}^{\prime\prime}}^{\sigma}. We construct fw′′,b′′\mathbf{f}_{\mathbf{w}^{\prime\prime},\mathbf{b}^{\prime\prime}} as follows: if i=2,...,g−1i=2,...,g-1, then wi′′=w\mathbf{w}^{\prime\prime}_{i}=\mathbf{w} and bi′′=bi\mathbf{b}_{i}^{\prime\prime}=\mathbf{b}_{i}; if i=g,...,g′′−1i=g,...,g^{\prime\prime}-1, then wi′′=Ilg−1×lg−1\mathbf{w}^{\prime\prime}_{i}=\mathbf{I}_{l_{g-1}\times l_{g-1}} and bi′′=0lg−1×1\mathbf{b}^{\prime\prime}_{i}=\mathbf{0}_{l_{g-1}\times 1}, where Ilg−1×lg−1\mathbf{I}_{l_{g-1}\times l_{g-1}} is the lg−1×lg−1l_{g-1}\times l_{g-1} identity matrix, and 0lg−1×1\mathbf{0}_{l_{g-1}\times 1} is the lg−1×1l_{g-1}\times 1 zero matrix; and if i=g′′i=g^{\prime\prime}, then wg′′′′=wg\mathbf{w}^{\prime\prime}_{g^{\prime\prime}}=\mathbf{w}_{g}, bg′′′′=bg\mathbf{b}^{\prime\prime}_{g^{\prime\prime}}=\mathbf{b}_{g}. Then it is easy to check that the output of the ii-th layer is

Therefore, fw′′,b′′=fw,b\mathbf{f}_{\mathbf{w}^{\prime\prime},\mathbf{b}^{\prime\prime}}=\mathbf{f}_{\mathbf{w},\mathbf{b}}, which implies that Fqσ⊂Fq′′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime\prime}}^{\sigma}. Hence, Hqσ⊂Hq′′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime\prime}}^{\sigma}.

When g′′=g′g^{\prime\prime}=g^{\prime}, we use Lemma 9 (q′′\mathbf{q}^{\prime\prime} and q\mathbf{q} satisfy the condition in Lemma 9), which implies that Fq′′σ⊂Fq′σ\mathcal{F}_{\mathbf{q}^{\prime\prime}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, Hq′′σ⊂Hq′σ\mathcal{H}_{\mathbf{q}^{\prime\prime}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}. Therefore, Fqσ⊂Fq′σ\mathcal{F}_{\mathbf{q}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, Hqσ⊂Hq′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}. ∎

The proof of Lemma 11 can be found in Theorem 3.1 in . ∎

Let f=[f1,...,fl]⊤\mathbf{f}=[f_{1},...,f_{l}]^{\top}, where fif_{i} is the ii-th coordinate of f\mathbf{f}. Based on Lemma 11, we obtain ll sequences q1\mathbf{q}^{1}, q2\mathbf{q}^{2},…,ql\mathbf{q}^{l} such that

It is easy to find a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (lg=1l_{g}=1) such that qi≲q\mathbf{q}^{i}\lesssim\mathbf{q}, for all i=1,...,li=1,...,l. Using Lemma 10, we obtain that Fqiσ⊂Fqσ\mathcal{F}_{\mathbf{q}^{i}}^{\sigma}\subset\mathcal{F}_{\mathbf{q}}^{\sigma}. Therefore,

Therefore, for each ii, we can find gwi,big_{\mathbf{w}^{i},\mathbf{b}^{i}} from Fqσ\mathcal{F}_{\mathbf{q}}^{\sigma} such that

where wi\mathbf{w}^{i} represents weights and bi\mathbf{b}^{i} represents bias.

We construct a larger FCNN with q′=(l1′,l2′,...,lg′)\mathbf{q}^{\prime}=(l_{1}^{\prime},l_{2}^{\prime},...,l_{g}^{\prime}) satisfying that l1′=dl_{1}^{\prime}=d, li′=l∗lil_{i}^{\prime}=l*l_{i}, for i=2,...,gi=2,...,g. We can regard this larger FCNN as a combinations of ll FCNNs with architecture q\mathbf{q}, that is: there are mm disjoint sub-FCNNs with architecture q\mathbf{q} in the larger FCNN with architecture q′\mathbf{q}^{\prime}. For ii-th sub-FCNN, we use weights wi\mathbf{w}^{i} and bias bi\mathbf{b}^{i}. For weights and bias which connect different sub-FCNNs, we set these weights and bias to 0\mathbf{0}. Finally, we can obtain that gw,b=[gw1,b1,gw2,b2,...,gwl,bl]⊤∈Fq′σ\mathbf{g}_{\mathbf{w},\mathbf{b}}=[g_{\mathbf{w}^{1},\mathbf{b}^{1}},g_{\mathbf{w}^{2},\mathbf{b}^{2}},...,g_{\mathbf{w}^{l},\mathbf{b}^{l}}]^{\top}\in\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, which implies that

Given a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}), we are interested in following function space Fq,Mσ\mathcal{F}^{\sigma}_{\mathbf{q},\mathbf{M}}:

where ∘\circ means the composition of two functions, ⋅\cdot means the product of two matrices, and

here 11×(lg−1)\mathbf{1}_{1\times(l_{g}-1)} is the 1×(lg−1)1\times(l_{g}-1) matrix whose all elements are 11, and 01×(lg−1)\mathbf{0}_{1\times(l_{g}-1)} is the 1×(lg−1)1\times(l_{g}-1) zero matrix. Using Fq,Mσ\mathcal{F}^{\sigma}_{\mathbf{q},\mathbf{M}}, we can construct a binary classification space Hq,Mσ\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}}, which consists of all classifiers satisfying the following condition:

where fMk(x)f^{k}_{\mathbf{M}}(\mathbf{x}) is the kk-th coordinate of M⋅(σ∘f)\mathbf{M}\cdot(\sigma\circ\mathbf{f}).

Suppose that σ\sigma is the ReLU function: max⁡{x,0}\max\{x,0\}. Given a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) satisfying that l1=dl_{1}=d and lg=K+1l_{g}=K+1, then the space Hq,Mσ\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}} contains ϕ∘Hqσ\phi\circ\mathcal{H}^{\sigma}_{\mathbf{q}}, and Hq,Mσ\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}} has finite VC dimension ((Vapnik–Chervonenkis dimension)), where ϕ\phi maps ID data to 11 and OOD data to 22. Furthermore, if given q′=(l1′,...,lg′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g}^{\prime}) satisfying that lg′=Kl_{g}^{\prime}=K and li′=lil_{i}^{\prime}=l_{i}, for i=1,...,g−1i=1,...,g-1, then Hqσ⊂Hq′σ∙Hq,Mσ\mathcal{H}^{\sigma}_{\mathbf{q}}\subset\mathcal{H}^{\sigma}_{\mathbf{q}^{\prime}}\bullet\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}}.

For any hw,b∈Hqσh_{\mathbf{w},\mathbf{b}}\in\mathcal{H}^{\sigma}_{\mathbf{q}}, then there exists fw,b∈Fqσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}^{\sigma}_{\mathbf{q}} such that hw,bh_{\mathbf{w},\mathbf{b}} is induced by fw,b\mathbf{f}_{\mathbf{w},\mathbf{b}}. We can write fw,b\mathbf{f}_{\mathbf{w},\mathbf{b}} as follows:

It is obvious that fw′,b′∈Fq′σ\mathbf{f}_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}\in\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}. Using fw′,b′∈Fq′σ\mathbf{f}_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}\in\mathcal{F}_{\mathbf{q}^{\prime}}^{\sigma}, we construct a classifier hw′,b′∈Hq′σ{h}_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}\in\mathcal{H}^{\sigma}_{\mathbf{q}^{\prime}}:

where fw′,b′k{f}_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}^{k} is the kk-th coordinate of fw′,b′\mathbf{f}_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}.

here I(lg−1)×(lg−1)\mathbf{I}_{(l_{g}-1)\times(l_{g}-1)} is the (lg−1)×(lg−1)(l_{g}-1)\times(l_{g}-1) identity matrix, 01×(lg−1)\mathbf{0}_{1\times(l_{g}-1)} is the 1×(lg−1)1\times(l_{g}-1) zero matrix, and 1(lg−1)×1\mathbf{1}_{(l_{g}-1)\times 1} is the (lg−1)×1(l_{g}-1)\times 1 matrix, whose all elements are 11.

Then, we define that for any x∈X\mathbf{x}\in\mathcal{X},

where fw,b,Bk(x){f}_{\mathbf{w},\mathbf{b},\mathbf{B}}^{k}(\mathbf{x}) is the kk-th coordinate of fw,b,B(x)\mathbf{f}_{\mathbf{w},\mathbf{b},\mathbf{B}}(\mathbf{x}). Furthermore, we can check that hw,b,Bh_{\mathbf{w},\mathbf{b},\mathbf{B}} can be written as follows: for any x∈X\mathbf{x}\in\mathcal{X},

where ϕ\phi maps ID labels to 11 and OOD labels to 22.

Therefore, hw,b(x)=K+1h_{\mathbf{w},\mathbf{b}}(\mathbf{x})=K+1 if and only if hw,b,B=2h_{\mathbf{w},\mathbf{b},\mathbf{B}}=2; and hw,b(x)=kh_{\mathbf{w},\mathbf{b}}(\mathbf{x})=k (k≠K+1k\neq K+1) if and only if hw,b,B=1h_{\mathbf{w},\mathbf{b},\mathbf{B}}=1 and hw′,b′(x)=kh_{\mathbf{w}^{\prime},\mathbf{b}^{\prime}}(\mathbf{x})=k. This implies that Hqσ⊂Hq′σ∙Hq,Mσ\mathcal{H}^{\sigma}_{\mathbf{q}}\subset\mathcal{H}^{\sigma}_{\mathbf{q}^{\prime}}\bullet\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}} and ϕ∘Hqσ⊂Hq,Mσ\phi\circ\mathcal{H}^{\sigma}_{\mathbf{q}}\subset\mathcal{H}^{\sigma}_{\mathbf{q},\mathbf{M}}.

Let ∣X∣<+∞|\mathcal{X}|<+\infty and σ\sigma be the ReLU function: max⁡{x,0}\max\{x,0\}. Given rr hypothesis functions h1,h2,...,hr∈{h:X→{1,...,l}}h_{1},h_{2},...,h_{r}\in\{h:\mathcal{X}\rightarrow\{1,...,l\}\}, then there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) with l1=dl_{1}=d and lg=ll_{g}=l, such that h1,...,hr∈Hqσh_{1},...,h_{r}\in\mathcal{H}_{\mathbf{q}}^{\sigma}.

Since X\mathcal{X} is a compact set, then Lemma 12 implies that there exist a sequence qi=(l1i,...,lgii)\mathbf{q}^{i}=(l_{1}^{i},...,l_{g^{i}}^{i}) (l1i=dl_{1}^{i}=d and lgii=ll_{g^{i}}^{i}=l) and fw,b∈Fqiσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}^{i}}^{\sigma} such that

where fw,bk(x){f}^{k}_{\mathbf{w},\mathbf{b}}(\mathbf{x}) is the kk-th coordinate of fw,b(x)\mathbf{f}_{\mathbf{w},\mathbf{b}}(\mathbf{x}). Therefore, hi(x)∈Hqiσh_{i}(\mathbf{x})\in\mathcal{H}_{\mathbf{q}^{i}}^{\sigma}.

Let q\mathbf{q} be (l1,...,lg)(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=l)l_{g}=l) satisfying that qi≲q\mathbf{q}^{i}\lesssim\mathbf{q}. Using Lemma 10, we obtain that Hqiσ⊂Hqσ\mathcal{H}_{\mathbf{q}^{i}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}}^{\sigma}, for each i=1,...,ri=1,...,r. Therefore, h1,...,hr∈Hqσh_{1},...,h_{r}\in\mathcal{H}_{\mathbf{q}}^{\sigma}. ∎

For any binary classifier hh over X\mathcal{X}, we can induce a vector-valued function as follows: for any x∈X\mathbf{x}\in\mathcal{X},

For each hh, we have found a sequence qh\mathbf{q}^{h} such that hh is induced by fw,b∈Fqhσ\mathbf{f}_{\mathbf{w},\mathbf{b}}\in\mathcal{F}_{\mathbf{q}^{h}}^{\sigma}, EE and λ\lambda. Since ∣X∣<+∞|\mathcal{X}|<+\infty, only finite binary classifiers are defined over X\mathcal{X}. Using Lemma 14, we can find a sequence q\mathbf{q} such that Hallb=Hq,Eσ,λ\mathcal{H}^{b}_{\rm all}=\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda}, where Hallb\mathcal{H}^{b}_{\rm all} consists of all binary classifiers. ∎

Note that we use the ReLU function as the activation function in this lemma. Using Lemma 10, Lemma 15 and Theorem 7, we can prove this result. ∎

Note that we use the ReLU function as the activation function in this theorem.

∙\bullet The Case that H\mathcal{H} is FCNN-based.

First, we prove that if ∣X∣=+∞|\mathcal{X}|=+\infty, then OOD detection is not learnable in DXYs\mathscr{D}^{s}_{XY} for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}, for any sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=K+1)l_{g}=K+1).

By Lemma 13, Theorems 5 and 8 in , we know that VCdim(ϕ∘Hqσ)<+∞{\rm VCdim}(\phi\circ\mathcal{H}_{\mathbf{q}}^{\sigma})<+\infty, where ϕ\phi maps ID data to 11 and maps OOD data to 22. Additionally, Proposition 1 implies that Assumption 1 holds and sup⁡h∈Hqσ∣{x∈X:h(x)∈Y}∣=+∞\sup_{{h}\in\mathcal{H}_{\mathbf{q}}^{\sigma}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|=+\infty, when ∣X∣=+∞|\mathcal{X}|=+\infty. Therefore, Theorem 5 implies that OOD detection is not learnable in DXYs\mathscr{D}^{s}_{XY} for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}, when ∣X∣=+∞|\mathcal{X}|=+\infty.

Second, we prove that if ∣X∣<+∞|\mathcal{X}|<+\infty, there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=K+1)l_{g}=K+1) such that OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}.

Since ∣X∣<+∞|\mathcal{X}|<+\infty, it is clear that ∣Hall∣<+∞|\mathcal{H}_{\rm all}|<+\infty, where Hall\mathcal{H}_{\rm all} consists of all hypothesis functions from X\mathcal{X} to Yall\mathcal{Y}_{\rm all}. According to Lemma 14, there exists a sequence q\mathbf{q} such that Hall⊂Hqσ\mathcal{H}_{\rm all}\subset\mathcal{H}_{\mathbf{q}}^{\sigma}. Additionally, Lemma 13 implies that there exist Hin\mathcal{H}^{\rm in} and Hb\mathcal{H}^{\rm b} such that Hqσ⊂Hin∙Hb\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}. Since Hall\mathcal{H}_{\rm all} consists all hypothesis space, Hall=Hqσ=Hin∙Hb\mathcal{H}_{\rm all}=\mathcal{H}_{\mathbf{q}}^{\sigma}=\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}. Therefore, Hb\mathcal{H}^{\rm b} contains all binary classifiers from X\mathcal{X} to {1,2}\{1,2\}. Theorem 7 implies that OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}.

Third, we prove that if ∣X∣<+∞|\mathcal{X}|<+\infty, then there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=K+1)l_{g}=K+1) such that for any sequence q′=(l1′,...,lg′′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g^{\prime}}^{\prime}) satisfying that q≲q′\mathbf{q}\lesssim\mathbf{q}^{\prime}, OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for Hq′σ\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}.

We can use the sequence q\mathbf{q} constructed in the second step of the proof. Therefore, Hqσ=Hall\mathcal{H}_{\mathbf{q}}^{\sigma}=\mathcal{H}_{\rm all}. Lemma 10 implies that Hqσ⊂Hq′σ\mathcal{H}_{\mathbf{q}}^{\sigma}\subset\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}. Therefore, Hq′σ=Hall=Hqσ\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}=\mathcal{H}_{\rm all}=\mathcal{H}_{\mathbf{q}}^{\sigma}. The proving process (second step of the proof) has shown that if ∣X∣<+∞|\mathcal{X}|<+\infty, Condition 2 holds and hypothesis space H\mathcal{H} consists of all hypothesis functions, then OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for H\mathcal{H}. Therefore, OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for Hq′σ\mathcal{H}_{\mathbf{q}^{\prime}}^{\sigma}. We complete the proof when the hypothesis space H\mathcal{H} is FCNN-based.

∙\bullet The Case that H\mathcal{H} is score-based

Fourth, we prove that if ∣X∣=+∞|\mathcal{X}|=+\infty, then OOD detection is not learnable in DXYs\mathscr{D}^{s}_{XY} for Hin∙Hb\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}, where Hb=Hq,Eσ,λ\mathcal{H}^{\rm b}=\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda} for any sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d, lg=ll_{g}=l), where EE is in Eqs. (5) or (6).

By Theorems 5 and 8 in , we know that VCdim(Hq,Eσ,λ)<+∞{\rm VCdim}(\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda})<+\infty. Additionally, Proposition 2 implies that Assumption 1 holds and sup⁡h∈Hqσ∣{x∈X:h(x)∈Y}∣=+∞\sup_{{h}\in\mathcal{H}_{\mathbf{q}}^{\sigma}}|\{\mathbf{x}\in\mathcal{X}:{h}(\mathbf{x})\in\mathcal{Y}\}|=+\infty, when ∣X∣=+∞|\mathcal{X}|=+\infty. Hence, Theorem 5 implies that OOD detection is not learnable in DXYs\mathscr{D}^{s}_{XY} for Hqσ\mathcal{H}_{\mathbf{q}}^{\sigma}, when ∣X∣=+∞|\mathcal{X}|=+\infty.

Fifth, we prove that if ∣X∣<+∞|\mathcal{X}|<+\infty, there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=l)l_{g}=l) such that OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for for Hin∙Hb\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}, where Hb=Hq,Eσ,λ\mathcal{H}^{\rm b}=\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda} for any sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d, lg=ll_{g}=l), where EE is in Eq. (5) or Eq. (6).

Since max⁡k∈{1,...,l}exp⁡(vk)∑c=1lexp⁡(vc)\max_{k\in\{1,...,l\}}\frac{\exp{(v^{k})}}{\sum_{c=1}^{l}\exp{(v^{c})}}, max⁡k∈{1,...,l}exp⁡(vk/T)∑c=1Kexp⁡(vc/T)\max_{k\in\{1,...,l\}}\frac{\exp{(v^{k}/T)}}{\sum_{c=1}^{K}\exp{(v^{c}/T)}} and Tlog⁡∑c=1lexp⁡(vc/T)T\log\sum_{c=1}^{l}\exp{(v^{c}/T)} are continuous functions, whose ranges contain (1l,1)(\frac{1}{l},1), (1l,1)(\frac{1}{l},1), (0,+∞)(0,+\infty) and (0,+∞)(0,+\infty), respectively.

Sixth, we prove that if ∣X∣<+∞|\mathcal{X}|<+\infty, then there exists a sequence q=(l1,...,lg)\mathbf{q}=(l_{1},...,l_{g}) (l1=d(l_{1}=d and lg=l)l_{g}=l) such that for any sequence q′=(l1′,...,lg′′)\mathbf{q}^{\prime}=(l_{1}^{\prime},...,l_{g^{\prime}}^{\prime}) satisfying that q≲q′\mathbf{q}\lesssim\mathbf{q}^{\prime}, OOD detection is learnable in DXYs\mathscr{D}^{s}_{XY} for for Hin∙Hb\mathcal{H}^{\rm in}\bullet\mathcal{H}^{\rm b}, where Hb=Hq′,Eσ,λ\mathcal{H}^{\rm b}=\mathcal{H}_{\mathbf{q}^{\prime},E}^{\sigma,\lambda}, where EE is in Eq. (5) or Eq. (6).

In the fifth step, we have proven that Eq. (5) and Eq. (6) meet the condition in Lemma 16. Therefore, Lemma 16 implies this result. We complete the proof when the hypothesis space H\mathcal{H} is score-based. ∎

Appendix M Proofs of Theorem 11 and Theorem 12

1) By Lemma 1, we conclude that Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇒\mathcal{H}\Rightarrow Condition 1.

2) By Proposition 1 and Proposition 2, we know that when K=1K=1, there exist h1,h2∈Hh_{1},h_{2}\in\mathcal{H}, where h1=1h_{1}=1 and h2=2h_{2}=2, here 11 represents ID, and 22 represent OOD. Therefore, we know that when K=1K=1, inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0, for any DXY∈DXYμ,bD_{XY}\in\mathscr{D}_{XY}^{\mu,b}.

By Condition 1, we obtain that inf⁡h∈HRD(h)=0\inf_{h\in\mathcal{H}}R_{D}(h)=0, for any DXY∈DXYμ,bD_{XY}\in\mathscr{D}_{XY}^{\mu,b}. Because each domain DXYD_{XY} in DXYμ,b\mathscr{D}_{XY}^{\mu,b} is attainable, we conclude that Realizability Assumption holds.

We have proven that Condition 1⇒\Rightarrow Realizability Assumption.

3) By Theorems 5 and 8 in , we know that VCdim(ϕ∘Hqσ)<+∞{\rm VCdim}(\phi\circ\mathcal{H}_{\mathbf{q}}^{\sigma})<+\infty and VCdim(Hq,Eσ,λ)<+∞{\rm VCdim}(\mathcal{H}_{\mathbf{q},E}^{\sigma,\lambda})<+\infty. Then, using Theorem 9, we conclude that Realizability Assumption⇒\Rightarrow Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H\mathcal{H}.

4) According to the results in 1), 2) and 3), we have proven that

Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇔\mathcal{H}\LeftrightarrowCondition 1⇔\Leftrightarrow Realizability Assumption.

5) By Lemma 2, we conclude that Condition 3⇒\RightarrowCondition 1.

6) Here we prove that Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇒\mathcal{H}\RightarrowCondition 3. Since DXYμ,b\mathscr{D}^{\mu,b}_{XY} is the prior-unknown space, by Theorem 1, there exist an algorithm A:∪n=1+∞(X×Y)n→H\mathbf{A}:\cup_{n=1}^{+\infty}(\mathcal{X}\times\mathcal{Y})^{n}\rightarrow\mathcal{H} and a monotonically decreasing sequence ϵcons(n)\epsilon_{\rm cons}(n), such that ϵcons(n)→0\epsilon_{\rm cons}(n)\rightarrow 0, as n→+∞n\rightarrow+\infty, and for any DXY∈DXYμ,bD_{XY}\in\mathscr{D}_{XY}^{\mu,b},

Then, for any ϵ>0\epsilon>0, we can find nϵn_{\epsilon} such that ϵ≥ϵcons(nϵ)\epsilon\geq\epsilon_{\rm cons}(n_{\epsilon}), therefore, if n=nϵn={n_{\epsilon}}, we have

which implies that there exists Sϵ∼DXIYInϵS_{\epsilon}\sim D^{n_{\epsilon}}_{X_{\rm I}Y_{\rm I}} such that

Therefore, for any equivalence class [DXY′][D_{XY}^{\prime}] with respect to DXYμ,b\mathscr{D}_{XY}^{\mu,b} and any ϵ>0\epsilon>0, there exists a hypothesis function A(Sϵ)∈H\mathbf{A}(S_{\epsilon})\in\mathcal{H} such that for any domain DXY∈[DXY′]D_{XY}\in[D_{XY}^{\prime}],

which implies that Condition 3 holds. Therefore, Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇒\mathcal{H}\RightarrowCondition 3.

7) Note that in 4), 5) and 6), we have proven that

Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇒\mathcal{H}\RightarrowCondition 3⇒\RightarrowCondition 1, and Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇔\mathcal{H}\LeftrightarrowCondition 1, thus, we conclude that Learnability in DXYμ,b\mathscr{D}_{XY}^{\mu,b} for H⇔\mathcal{H}\LeftrightarrowCondition 3⇔\LeftrightarrowCondition 1.

8) Combining 4) and 7), we have completed the proof.

M.2 Proof of Theorem 12

Using Proposition 1 and Proposition 2, we obtain that inf⁡h∈HRDin(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm in}(h)=0 and inf⁡h∈HRDout(h)=0\inf_{h\in\mathcal{H}}R_{D}^{\rm out}(h)=0. Then, Theorem 3 implies this result. ∎

Note that if we replace the activation function σ\sigma (ReLU function) in Theorem 12 with any other activation functions, Theorem 12 still hold.