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 and a training data drawn independent and identically distributed from , the aim of OOD detection is to train a classifier by using the training data such that, for any test data drawn from the mixed marginal distribution : 1) if is an observation from , can classify into correct ID classes; and 2) if is an observation from , can detect as OOD data.
According to the survey , when , OOD detection is also known as the open-set recognition or open-set learning ; and when , 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., . To investigate the PAC learnability of OOD detection, we define a domain space , which is a set consisting of some joint distributions mixed by some ID joint distributions and some OOD joint distributions. In this paper, the joint distribution mixed by ID joint distribution and OOD joint distribution is called domain.
The -risk , where the risks , are
Learnability. We aim to select a hypothesis function 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 and a hypothesis space , we say OOD detection is learnable in for , if there exists an algorithm Similar to , in this paper, we regard an algorithm as a mapping from to . and a monotonically decreasing sequence , such that , as , and for any domain ,
An algorithm for which this holds is said to be consistent with respect to .
Since OOD data are unavailable, it is impossible to obtain information about the class-prior probability . Furthermore, in the real world, it is possible that can be any value in . Therefore, the imbalance issue between ID and OOD distributions, and the priori-unknown issue (i.e., 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 satisfies Eq. (3), then the imbalance issue and the prior-unknown issue disappear. That is, 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 and a hypothesis space , we say OOD detection is strongly learnable in for , if there exists an algorithm and a monotonically decreasing sequence , such that , as , and for any domain ,
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 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 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 and the hypothesis space . That is, OOD detection is learnable only when the domain space and the hypothesis space satisfy some special conditions, e.g., Condition 1 and Condition 3. We present our goal as follows:
Goal: given a hypothesis space and several representative domain spaces , 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 . 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 , 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 , we say is a priori-unknown space, if for any domain and any , we have .
Given domain spaces and , then 1) is a priori-unknown space and ; 2) if is a priori-unknown space, then Definition 1 and Definition 2 are equivalent; 3) OOD detection is strongly learnable in if and only if OOD detection is learnable in .
The second result of Theorem 1 bridges the learnability and strong learnability, which implies that if an algorithm is consistent with respect to a prior-unknown space, then this algorithm 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:
Single-distribution space . For a domain , . Total space , which consists of all domains. Separate space , which consists of all domains that satisfy the separate condition, that is for any , where means the support set. Finite-ID-distribution space , which is a prior-unknown space satisfying that the number of distinct ID joint distributions in is finite, i.e., . Density-based space , which is a prior-unknown space consisting of some domains satisfying that: for any , there exists a density function with in and , where is a measure defined over . Note that if is discrete, then is a discrete distribution; and if is the Lebesgue measure, then 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 ; 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 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 and the separate space .
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 and any ,
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 is the single-distribution space.
Theorem 2. Given a hypothesis space and a domain , OOD detection is learnable in the single-distribution space for 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 . 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 and a prior-unknown space , if there is , which has overlap between ID and OOD, and and , then Condition 1 does not hold. Therefore, OOD detection is not learnable in for .
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 for any non-trivial hypothesis space .
Theorem 4 (Impossibility Theorem for Total Space). OOD detection is not learnable in the total space for , if , where maps ID labels to and maps OOD labels to .
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 , 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 is separate for OOD data, if for each data point , there exists at least one hypothesis function such that .
Assumption 1 means that every data point 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 based on the VC dimension.
Theorem 5 (Impossibility Theorem for Separate Space). If Assumption 1 holds, and , then OOD detection is not learnable in separate space for , where maps ID labels to and maps OOD labels to .
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 , finite-ID-distribution space and density-based space . We first study the separate space .
OOD Detection in the Separate Space. Theorem 5 has indicated that or is necessary to ensure the learnability of OOD detection in 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 , which implies that . Additionally, Theorem 10 also implies that is the necessary and sufficient condition for the learnability of OOD detection in separate space, when the hypothesis space is generated by FCNN. Hence, may be necessary in the space .
For simplicity, we first discuss the case that , i.e., the one-class novelty detection. We show the necessary and sufficient condition for the learnability of OOD detection in , when .
Theorem 6. Let and . Suppose that Assumption 1 holds and the constant function . Then OOD detection is learnable in for if and only if , where is the hypothesis space consisting of all hypothesis functions, and is a constant function that , here represents ID data and represents OOD data.
The condition 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 and OOD detection is learnable in for , then the hypothesis space 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., . When , we will first use a binary classifier to classify the ID and OOD data. Then, for the ID data identified by , an ID hypothesis function will be used to classify them into corresponding ID classes. We state this strategy as follows: given a hypothesis space for ID distribution and a binary classification hypothesis space introduced in Section 2, we use and to construct an OOD detection’s hypothesis space , which consists of all hypothesis functions satisfying the following condition: there exist and such that for any ,
Let and . If and Condition 2 holds, then OOD detection is learnable in for , where and 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 . We first show two necessary concepts below.
Given a domain space , we say any two domains and are ID consistency, if . We use the notation to represent the ID consistency, i.e., if and only if and are ID consistency.
It is easy to check that the ID consistency is an equivalence relation. Therefore, we define the set as the equivalence class with respect to space .
For any equivalence class with respect to and any , there exists a hypothesis function such that for any domain ,
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 .
Theorem 8. Suppose that is a bounded set. OOD detection is learnable in the finite-ID-distribution space for if and only if the compatibility condition (i.e., Condition 3) holds. Furthermore, the learning rate can attain , for any .
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 , there exists such that . We discover that in the density-based space , 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 , if , the Realizability Assumption holds, then when has finite Natarajan dimension , OOD detection is learnable in for . Furthermore, the learning rate can attain , for any .
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 . We use to compare the sizes of FCNNs.
FCNN-based Hypothesis Space. Let . The FCNN-based scoring function space can induce an FCNN-based hypothesis space. For any , the induced hypothesis function is:
Then, the FCNN-based hypothesis space is defined as
energy-based function : and ,
Using , and , we have a classifier: , if ; otherwise, , where represents the ID data and represents the OOD data. Hence, a binary classification hypothesis space , which consists of all , is generated. We define .
Learnability of OOD Detection in Different Hypothesis Spaces. Next, we present applications of our theory regarding the above two practical and important hypothesis spaces and .
Suppose that Condition 2 holds and the hypothesis space is FCNN-based or score-based, i.e., or , where is an ID hypothesis space, and is introduced below Eq. (4), here is introduced in Eqs. (5) or (6). Then There is a sequence such that OOD detection is learnable in the separate space for if and only if . Furthermore, if , then there exists a sequence such that for any sequence satisfying that , OOD detection is learnable in for .
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 , Theorem 10 also shows that the selected scoring functions 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 .
Suppose that each domain in is attainable, i.e., (the finite discrete domains satisfy this). Let and the hypothesis space be score-based , where is in Eqs. (5) or (6) or FCNN-based . If , then the following four conditions are equivalent: Learnability in for Condition 1 Realizability Assumption Condition 3
Theorem 11 still holds if the function space 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 and the hypothesis space be score-based , where is in Eqs. (5) or (6) or FCNN-based . Given a prior-unknown space , if there exists a domain , which has an overlap between ID and OOD distributions (see Definition 4), then OOD detection is not learnable in the domain space for .
When 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 and . However, when , we can ensure if ID distribution has overlap between ID classes. By this observation, we conjecture that when , 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- or Place as OOD datasets; and 2) CIFAR- 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 , a domain space is -far-OOD, if for any domain ,
Theorems 7, 8 and 10 imply that under appropriate hypothesis space, -far-OOD detection is learnable. In Theorem 7, the condition is necessary for the separate space. However, one can prove that in the far-OOD case, when is agnostic PAC learnable for ID distribution, the results in Theorem 7 still holds, if the condition is replaced by a weaker condition that is compact. In addition, it is notable that when is agnostic PAC learnable for ID distribution and is compact, the KNN-based OOD detection algorithm is consistent in the -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- as ID dataset, and CIFAR- 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. ), 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 (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 and space , 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 is agnostic learnable for supervised learning, then OOD detection is learnable in 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:
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 . This implies the Condition 1 is the necessary condition for the learnability of OOD detection.
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 , the overlap is the sufficient condition for the failures of OOD detection, when the hypothesis space is FCNN-based or score-based.
Theorem 4 provides an impossibility theorem for the total space . OOD detection is not learnable in for any non-trivial hypothesis space.
Theorem 5 gives impossibility theorems for the separate space . To ensure the impossibility theorems hold, mild assumptions are required. Theorem 5 also implies that OOD detection may be learnable in the separate space , if the feature space is finite, i.e., . 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.
When and , Theorem 6 provides the necessary and sufficient condition for the learnability of OOD detection in the separate space . 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 case.
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 . 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.
To further understand the importance of the compatibility condition (Condition 3). Theorem 9 considers the density-based space . 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 under Realizability Assumption.
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 , when the hypothesis space is FCNN-based or score-based.
Theorem 11 has shown that when 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 are all equivalent.
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 to present the uniform distribution in region ). The marginal distribution of ID distribution for class : for any ,
here and is a positive constant. The class-prior probability for class : for any ,
The marginal distribution of OOD distribution:
Figure 2 shows the OOD and ID distributions, when and . In Figure 1, we draw data from ID distribution () and data from the OOD distribution.
OOD Detection Procedure. We first train an ID classifier with data drawn from the ID distribution. Then, according to , we apply the free-energy score to identify the OOD data and calculate the -risk (with the - loss). We repeat the above detection procedure times and report the average -risk in Figure 1. Note that, following , we choose the threshold used by the free-energy method so that 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 , for any ,
where is the -th coordinate of and is the -th coordinate of . The above definition about aims to overcome some special cases. For example, there exist , () such that and , , . Then, according to the above definition, .
D.2 Realizability Assumption
A domain space and hypothesis space satisfy the Realizability Assumption, if for each domain , there exists at least one hypothesis function such that .
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 . Therefore, by Markov’s inequality, we have
Because is monotonically decreasing, we can find a smallest such that and , for . We define that . Therefore, for any and , there exists a function such that when , with the probability at least , we have
which is the definition of PAC learnability.
Second, we prove that the PAC learnability concludes Learnability.
PAC-learnability: for any and , there exists a function such that when the sample size , we have that with the probability at least ,
If we set , then when the sample size , 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 in Eq. (2).
is training data drawn independent and identically distributed from .
denotes the probability over -tuples induced by applying to pick each element of the tuple independently of the other members of the tuple.
Because these samples are i.i.d. drawn times, researchers often use ”” to represent a sample set (of size ) whose each element is drawn i.i.d. from .
Second, we explain the concept ”” in .
For convenience, let and . It is clear that and are measures. Then is also a measure, which is defined as follows: for any measurable set , we have
For example, when and are discrete measures, then is also discrete measure: for any ,
When and are continuous measures with density functions and , then is also continuous measure with density function : for any measurable ,
For example, when is a finite discrete distribution: let be the support set of , and assume that is the probability for , i.e., . Then
When is a continuous distribution with density , and (-th class-conditional distribution for ) is , then
where is the -th class-conditional distribution.
Appendix E Proof of Theorem 1
To prove that is a priori-unknown space, we need to show that for any , then for any .
According to the definition of , for any , we can find a domain , which can be written as (here ) such that
Note that .
Therefore, based on the definition of , for any , , which implies that is a prior-known space. Additionally, for any , we can rewrite as , thus , which implies that .
First, we prove that Definition 1 concludes Definition 2, if is a prior-unknown space:
In the priori-unknown space, for any , we have that for any ,
Then, according to the definition of learnability of OOD detection, we have an algorithm and a monotonically decreasing sequence , as , such that for any ,
Since and , we have that
Next, we consider the case that . Note that
Then, we assume that satisfies that
Let . Then, for any ,
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 and , we obtain that
Combining Eq. (9) and Eq. (16), we have proven that: if the domain space is a priori-unknown space, then OOD detection is learnable in for . OOD detection is strongly learnable in for : there exist an algorithm , and a monotonically decreasing sequence , such that , as ,
which means that OOD detection is learnable in for . 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 , where is a positive integer. Next, we introduce an important definition as follows:
Given any domain , we say joint distributions , which are defined over , are the OOD convex decomposition for , if
for some . We also say domain is an OOD convex domain corresponding to OOD convex decomposition , if for any ,
We extend the linear condition (Condition 1) to a multi-linear scenario.
For each OOD convex domain corresponding to OOD convex decomposition , the following function
where is the vector, whose elements are , and is the vector, whose -th element is and other elements are .
When and the domain space 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 and a hypothesis space , if OOD detection is learnable in for , 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 corresponding to OOD convex decomposition , and any , we set
Since OOD detection is learnable in for , there exist an algorithm , and a monotonically decreasing sequence , such that , as , and
Therefore, we have that for any ,
Step 1. Since , we need to prove that
where is the vector, whose -th element is and other elements are .
We note that . Therefore,
Step 2. It is easy to check that for any ,
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 , for any .
First, we prove that , implies
For any and , we can find satisfying that
Note that , i.e.,
Using Eqs. (25) and (26), we have that for any ,
Since and , Eq. (27) implies that: for any ,
If we set , we obtain that for any ,
Second, we prove that for any , if
then , for any . Let .
which implies that .
As , . 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 . Next, it suffices to prove that Condition 1 is the sufficient condition for the learnability of OOD detection in the single-distribution space . We use Lemma 2 to prove the sufficient condition.
Let be the infinite sequence set that consists of all infinite sequences, whose coordinates are hypothesis functions, i.e.,
For each , there is a corresponding algorithm In this paper, we regard an algorithm as a mapping from to . So we can design an algorithm like this.: . generates an algorithm class . We select a consistent algorithm from the algorithm class .
Since , we obtain that for any ,
Appendix G Proofs of Theorem 3 and Theorem 4
We first explain how we get and in Definition 4. Since is absolutely continuous respect to (), then and . By Radon-Nikodym Theorem , we know there exist two non-negative functions defined over : and such that for any -measurable set ,
Second, we prove that for any , .
We define . It is clear that
which implies that there exists such that
Third, Condition 1 indicates that (here we have used conditions and ), which contradicts with (). Therefore, Condition 1 does not hold. Using Lemma 1, we obtain that OOD detection in is not learnable for . ∎
G.2 Proof of Theorem 4
We need to prove that OOD detection is not learnable in the total space for , if is non-trivial, i.e.,
The main idea is to construct a domain satisfying that: 1) the ID and OOD distributions have overlap (Definition 4); and 2) , .
According to the condition that is non-trivial, we know that there exist such that , for some . We set , where is the Dirac measure. It is easy to check that , , which implies that and . In addition, the ID distribution and OOD distribution have overlap . 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 is a domain with OOD convex decomposition (convex decomposition is given by Definition 6 in Appendix F), and is a finite discrete distribution, then (the definition of is given in Condition 4)
where is the vector, whose elements are , and is the vector, whose -th element is and other elements are , and
To better understand this proof, we recall the definition of :
Let , for some . Since 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 implies
Therefore, Eq. (28) and Eq. (29) imply that
Since and , for , then using Eq. (30), we have that
we obtain that for any ,
Combining Eq. (31) with Eq. (32), we obtain that
then, for any ,
Therefore, for any ,
which implies that: for any ,
Suppose that Assumption 1 holds. If there is a finite discrete domain such that then OOD detection is not learnable in for .
Suppose that , then it is clear that has OOD convex decomposition , where is the dirac measure whose support set is .
Since is the separate space for OOD (i.e., Assumption 1 holds), then ,
This implies that: if , then for ,
Therefore, if , then for any , we have that
Proof by Contradiction: assume OOD detection is learnable in for , then Lemmas 1 and 3 imply that
Therefore, for any , we have that
which implies that for any , we have which implies that .
It is clear that is inconsistent with the condition . Therefore, OOD detection is not learnable in for . ∎
If Assumption 1 holds, and such that , then OOD detection is not learnable in for , where maps ID’s labels to and maps OOD’s labels to .
Due to , we can obtain a set
Let . It is clear that
where means all elements are .
Let .
Clearly, and . Sauer-Shelah-Perles Lemma (Lemma 6.10 in ) implies that
Since (because ), we obtain that . Therefore, is a proper subset of , where means that all elements are . Note that (all elements are 1) also belongs to . Hence, is a proper subset of , which implies that we can obtain a hypothesis function satisfying that:
Let and ;
Then, we construct a special domain :
Since is a finite discrete distribution and , it is clear that and .
Proof by Contradiction: suppose that OOD detection is learnable in for , then Lemma 1 implies that
Therefore, if OOD detection is learnable in for , then .
Until now, we have constructed a domain (defined over ) with finite support and satisfying that . Note that is the separate space for OOD data (Assumption 1 holds). Using Lemma 4, we know that OOD detection is not learnable in for , which is inconsistent with our assumption that OOD detection is learnable in for . Therefore, OOD detection is not learnable in for . We have completed the proof. ∎
Let . Since , it is clear that . 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 ,…, be a cover of space , i.e., . Let be a sequence of data drawn from , i.i.d. Then
where is the characteristic function.
here we have used inequality: . The proof has been completed. ∎
Since is bounded, without loss of generality, we set . Fix , for some integer . Let and be a cover of : for every , there exists a .
If belong to some , then ; otherwise, . Therefore,
Note that are disjoint.
Therefore, . Using Lemma 6, we obtain
If we set , we complete this proof. ∎
First, we prove that if the hypothesis space is a separate space for OOD (i.e., Assumption 1 holds), the constant function , then that OOD detection is learnable in for implies .
Proof by Contradiction: suppose that there exists such that and .
Let , and .
Because , we know that .
We construct a special domain : if , then ; otherwise,
Since and , then , and . Additionally, (here ), hence, .
Since OOD detection is learnable in for , Lemma 1 implies that
where or . Since and , we obtain that .
Until now, we have constructed a special domain satisfying that . Using Lemma 4, we know that OOD detection in is not learnable for , which is inconsistent with the condition that OOD detection is learnable in for . Therefore, the assumption (there exists such that and ) doesn’t hold, which implies that .
Second, we prove that if , then OOD detection is learnable in for .
For any , it is easy to check that for almost all ,
Using Lemma 7, for any , we have
where , as and is a monotonically decreasing sequence.
where is the product measure of and . Therefore,
It is easy to check that . Therefore, we have constructed a consistent algorithm for . We have completed this proof. ∎
I.2 Proof of Theorem 7
Since , we know that , which implies that is agnostic PAC learnable for supervised learning in classification. Therefore, there exist an algorithm and a monotonically decreasing sequence , such that , as , and for any ,
Since and almost contains all binary classifiers, then using Theorem 6 and Theorem 1, we obtain that there exist an algorithm and a monotonically decreasing sequence , such that , as , and for any ,
where maps ID’s labels to and OOD’s label to ,
here , if .
Note that almost contains all classifiers, and is the separate space. Hence,
Next, we construct an algorithm using and .
Since , , then by Condition 2, it is easy to check that
Additionally, the risk 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 is from the case that OOD data are detected as ID data. Therefore,
Note that . Then, using Eq. (40) and Eq. (41), we obtain that for any ,
According to Theorem 1 (the second result), we complete the proof. ∎
Appendix J Proofs of Theorems 8 and 9
Given a prior-unknown space and a hypothesis space , if Condition 3 holds, then for any equivalence class with respect to , OOD detection is learnable in the equivalence class for . Furthermore, the learning rate can attain .
Let be a set consisting of all infinite sequences, whose coordinates are hypothesis functions, i.e.,
For each , there is a corresponding algorithm : . generates an algorithm class . We select a consistent algorithm from the algorithm class .
Since , we obtain that for any ,
Using Theorem 1 (the second result), we have completed this proof. ∎
First, we prove that if OOD detection is learnable in for , then Condition 3 holds.
Since is the prior-unknown space, by Theorem 1, there exist an algorithm and a monotonically decreasing sequence , such that , as , and for any ,
Then, for any , we can find such that , therefore, if , we have
which implies that there exists such that
Therefore, for any equivalence class with respect to and any , there exists a hypothesis function such that for any domain ,
Second, we prove Condition 3 implies the learnability of OOD detection in for
For convenience, we assume that all equivalence classes are . By Lemma 8, for every equivalence class , we can find a corresponding algorithm such that OOD detection is learnable in for . Additionally, we also set the learning rate for is . By Lemma 8, we know that can attain .
Let be . Then, we consider a bounded universal kernel defined over . Consider the maximum mean discrepancy (MMD) , which is a metric between distributions: for any distributions and defined over , we use to represent the distance.
Let be a set consisting of all finite sequences, whose coordinates are labeled data, i.e.,
Then, we define an algorithm space as follows:
and is the Dirac measure. Next, we prove that we can find an algorithm from the algorithm space such that is the consistent algorithm.
Since the number of different equivalence classes is finite, we know that there exists a constant such that for any different equivalence classes and (),
Additionally, according to and the property of (the number of different equivalence classes is finite), there exists a monotonically decreasing , as such that for any ,
Therefore, for every equivalence class , we can find data points such that
Let . Then, we prove that is a consistent algorithm. By Eq. (42), it is easy to check that for any and any ,
Therefore, (here we set )
Because is a consistent algorithm for , we conclude that for all ,
Let .
Then, we obtain that for any and all ,
According to Theorem 1 (the second result), is the consistent algorithm. This proof is completed. ∎
J.2 Proof of Theorem 9
Since , without loss of generality, we assume that . We also assume that is ’s density function and is ’s density function. Let be the density function for . It is easy to check that . Additionally, due to Realizability Assumption, it is obvious that for any samples , i.i.d., we have that there exists such that
Given data points . We consider the following learning rule:
We denote the algorithm, which solves the above rule, as In this paper, we regard an algorithm as a mapping from to . So we can design an algorithm like this.. For different data points , we have different algorithm . Let be the infinite sequence set that consists of all infinite sequences, whose coordinates are data points, i.e.,
Using , we construct an algorithm space as follows:
Next, we prove that there exists an algorithm , which is a consistent algorithm. Given data points , i.i.d., using the Natarajan dimension theory and Empirical risk minimization principle , it is easy to obtain that there exists a uniform constant such that (we mainly use the uniform bounds to obtain the following bounds)
and because of ,
We set . Then by Eq. (44), we have
Due to Realizability Assumption, we obtain that . Therefore,
which implies that (in following inequalities, is the groundtruth labeling function, i.e., )
This implies that (here we have used the property of zero-one loss)
Additionally, and , 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 such that
Combining inequalities (46) and (53), we obtain that for any , there exists data points such that
We set data point sequences . Then, is the universally consistent algorithm, i.e., for any
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 is the -th layer output and . Then, the output of FCNN is where and .
An FCNN-based scoring function space is defined as:
Additionally, given two sequences and , we use the notation to represent the following equations and inequalities:
Given a sequence satisfying that and , the FCNN-based scoring function space can induce an FCNN-based hypothesis space. Before defining the FCNN-based hypothesis space, we define the induced hypothesis function. For any , the induced hypothesis function is:
where is the -th coordinate of . Then, we define the FCNN-based hypothesis space as follows:
Using , and , we can generate a binary classifier :
where represents ID data, and represents OOD data. Hence, a binary classification hypothesis space , which consists of all , is generated. We define the score-based hypothesis space .
Next, we introduce two important propositions.
Given a sequence satisfying that and (note that is the dimension of input data and is the dimension of output), then the constant functions , ,…, belong to , where , for any . Therefore, Assumption 1 holds for .
Note that the output of FCNN can be written as
Note that in some works , is fixed to . In fact, it is easy to check that when and activation function is not a constant, Proposition 1 still holds, even if .
For any , we have
If we set and , then for any , where is zero matrix. Hence, can be induced by . Therefore, .
Similarly, if we set and , then for any , where is zero matrix. Hence, can be induced by . Therefore, . ∎
It is easy to check that when and activation function is not a constant, Proposition 2 still holds, even if .
Appendix L Proof of Theorem 10
Before proving Theorem 10, we need several lemmas.
Let be ReLU function: . Given and such that and , and , then and .
where is the -th layer output and . Then, the output of last layer is
where means the zero matrix. If and , we set
If and , we set
If and , we set
It is easy to check that if
Therefore, , which implies that . Therefore, . ∎
Let be the ReLU function: . Then, implies that , , where and .
Given satisfying that , for , for , and , we first prove that and .
where is the -th layer output and . Then, the output of the last layer is
We will show that . We construct as follows: if , then and ; if , then and , where is the identity matrix, and is the zero matrix; and if , then , . Then it is easy to check that the output of the -th layer is
Therefore, , which implies that . Hence, .
When , we use Lemma 9 ( and satisfy the condition in Lemma 9), which implies that , . Therefore, , . ∎
The proof of Lemma 11 can be found in Theorem 3.1 in . ∎
Let , where is the -th coordinate of . Based on Lemma 11, we obtain sequences , ,…, such that
It is easy to find a sequence () such that , for all . Using Lemma 10, we obtain that . Therefore,
Therefore, for each , we can find from such that
where represents weights and represents bias.
We construct a larger FCNN with satisfying that , , for . We can regard this larger FCNN as a combinations of FCNNs with architecture , that is: there are disjoint sub-FCNNs with architecture in the larger FCNN with architecture . For -th sub-FCNN, we use weights and bias . For weights and bias which connect different sub-FCNNs, we set these weights and bias to . Finally, we can obtain that , which implies that
Given a sequence , we are interested in following function space :
where means the composition of two functions, means the product of two matrices, and
here is the matrix whose all elements are , and is the zero matrix. Using , we can construct a binary classification space , which consists of all classifiers satisfying the following condition:
where is the -th coordinate of .
Suppose that is the ReLU function: . Given a sequence satisfying that and , then the space contains , and has finite VC dimension Vapnik–Chervonenkis dimension, where maps ID data to and OOD data to . Furthermore, if given satisfying that and , for , then .
For any , then there exists such that is induced by . We can write as follows:
It is obvious that . Using , we construct a classifier :
where is the -th coordinate of .
here is the identity matrix, is the zero matrix, and is the matrix, whose all elements are .
Then, we define that for any ,
where is the -th coordinate of . Furthermore, we can check that can be written as follows: for any ,
where maps ID labels to and OOD labels to .
Therefore, if and only if ; and () if and only if and . This implies that and .
Let and be the ReLU function: . Given hypothesis functions , then there exists a sequence with and , such that .
Since is a compact set, then Lemma 12 implies that there exist a sequence ( and ) and such that
where is the -th coordinate of . Therefore, .
Let be and satisfying that . Using Lemma 10, we obtain that , for each . Therefore, . ∎
For any binary classifier over , we can induce a vector-valued function as follows: for any ,
For each , we have found a sequence such that is induced by , and . Since , only finite binary classifiers are defined over . Using Lemma 14, we can find a sequence such that , where 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.
The Case that is FCNN-based.
First, we prove that if , then OOD detection is not learnable in for , for any sequence and .
By Lemma 13, Theorems 5 and 8 in , we know that , where maps ID data to and maps OOD data to . Additionally, Proposition 1 implies that Assumption 1 holds and , when . Therefore, Theorem 5 implies that OOD detection is not learnable in for , when .
Second, we prove that if , there exists a sequence and such that OOD detection is learnable in for .
Since , it is clear that , where consists of all hypothesis functions from to . According to Lemma 14, there exists a sequence such that . Additionally, Lemma 13 implies that there exist and such that . Since consists all hypothesis space, . Therefore, contains all binary classifiers from to . Theorem 7 implies that OOD detection is learnable in for .
Third, we prove that if , then there exists a sequence and such that for any sequence satisfying that , OOD detection is learnable in for .
We can use the sequence constructed in the second step of the proof. Therefore, . Lemma 10 implies that . Therefore, . The proving process (second step of the proof) has shown that if , Condition 2 holds and hypothesis space consists of all hypothesis functions, then OOD detection is learnable in for . Therefore, OOD detection is learnable in for . We complete the proof when the hypothesis space is FCNN-based.
The Case that is score-based
Fourth, we prove that if , then OOD detection is not learnable in for , where for any sequence , ), where is in Eqs. (5) or (6).
By Theorems 5 and 8 in , we know that . Additionally, Proposition 2 implies that Assumption 1 holds and , when . Hence, Theorem 5 implies that OOD detection is not learnable in for , when .
Fifth, we prove that if , there exists a sequence and such that OOD detection is learnable in for for , where for any sequence , ), where is in Eq. (5) or Eq. (6).
Since , and are continuous functions, whose ranges contain , , and , respectively.
Sixth, we prove that if , then there exists a sequence and such that for any sequence satisfying that , OOD detection is learnable in for for , where , where 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 is score-based. ∎
Appendix M Proofs of Theorem 11 and Theorem 12
1) By Lemma 1, we conclude that Learnability in for Condition 1.
2) By Proposition 1 and Proposition 2, we know that when , there exist , where and , here represents ID, and represent OOD. Therefore, we know that when , and , for any .
By Condition 1, we obtain that , for any . Because each domain in is attainable, we conclude that Realizability Assumption holds.
We have proven that Condition 1 Realizability Assumption.
3) By Theorems 5 and 8 in , we know that and . Then, using Theorem 9, we conclude that Realizability Assumption Learnability in for .
4) According to the results in 1), 2) and 3), we have proven that
Learnability in for Condition 1 Realizability Assumption.
5) By Lemma 2, we conclude that Condition 3Condition 1.
6) Here we prove that Learnability in for Condition 3. Since is the prior-unknown space, by Theorem 1, there exist an algorithm and a monotonically decreasing sequence , such that , as , and for any ,
Then, for any , we can find such that , therefore, if , we have
which implies that there exists such that
Therefore, for any equivalence class with respect to and any , there exists a hypothesis function such that for any domain ,
which implies that Condition 3 holds. Therefore, Learnability in for Condition 3.
7) Note that in 4), 5) and 6), we have proven that
Learnability in for Condition 3Condition 1, and Learnability in for Condition 1, thus, we conclude that Learnability in for Condition 3Condition 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 and . Then, Theorem 3 implies this result. ∎
Note that if we replace the activation function (ReLU function) in Theorem 12 with any other activation functions, Theorem 12 still hold.