Paper: Detecting Out-of-Distribution Samples via Conditional Distribution Entropy with Optimal Transport (ICLR-2024)

Reviewer comment (Writing):
The organization and writing of the paper need to be improved. Notations are overly complicated and scattered around. Multiple theorems and definitions can be omitted or miss citations.

Author response:
__A1.1 & A1.2__ We aim to ensure the paper is self-contained and presented clearly. While there is room for improvement, particularly in the points you highlighted, we plan to enhance these aspects in the revised version.

Reviewer comment (Theory):
The formal definition of the OOD detection problem is missing. Therefore, it could be hard to understand why "the OOD detection problem can be formulated as a discrete optimal transport problem with entropic regularization" in P4 (Sec 3.1). Note that the OOD detection problem is a binary classification problem, which is related but not equal to solving the optimal transport problem.

Author response:
__A1.3__ Please see the Def 2.1(P2) for the definition of OOD detection. 

Our definition aligns with your viewpoint that OOD detection is indeed a binary classification problem. In fact, the entropic regularized OT in our paper is used to model the mass transport between test inputs and ID training data, which is a crucial aspect of our method. Therefore, we agree that it is better to rephrase the sentence that you mentioned to as "we leverage optimal transport with entropic regularization [1] for measuring the discrepancy of empirical distributions between test inputs and ID data." in P4 (Sec 3.1). We will modify it in the revised version.

[1] Cuturi, Marco. "Sinkhorn distances: Lightspeed computation of optimal transport." Advances in neural information processing systems 26 (2013).

Reviewer comment (Writing):
A transition is needed from Sec 3.2 and Sec 3.3. It is unknown why optimal transport is related to contrastive learning. It seems ill-motivated why "in this work, we employ supervised contrastive training" (Sec 3.3, P6). Is the feature quality of models trained with standard cross entropy loss undesirable?

Author response:
__A1.4__ We clarify that our approach is model-agnostic, meaning that the testing procedure is applicable to different model architectures and training losses, including cross entropy loss and contrastive training loss (as shown in Table 1). This has been confirmed in the line of research on distance-based OOD detections. Also, the advantage of contrastive training over cross entropy was discussed in previous works (e.g., KNN and SSD). In our implementation, we employ supervised training, for being in line with existing distance-based OOD detection approaches (e.g., KNN and SSD) and for empirically fair comparison. 

We will incorporate the above discussion to make a smooth transition between Sections 3.2 and 3.3.

Reviewer comment (Reproducibility):
The methodology is somewhat vague. It remains unclear how OOD scores are calculated. If I understand correctly, $\nu$ (p3) is the empirical distribution of the validation set, where in practice we only have access to the ID validation set. For OOD inputs, how is the distance calculated?

Author response:
__A2.__ Please see Q1 for the calculation of scoring function. The $\nu$ means the empirical distribution of a set of test inputs. 
It is worth noting that our method only uses ID data to train model and obtain training data features without requiring any OOD validation set. Following with distance-based methods (KNN and SSD), we use the trained model to extract the feature of a test input. Then, the distances between a test input and training samples can be calculated by some distance metrics, such as Euclidean distance and cosine distance.

Reviewer comment (Reproducibility):
Can authors explain how OOD scores are calculated? As one only has access to the ID validation set, how is the empirical distribution used for OOD detection?

Author response:
We plan to update the Uncertainty Modeling as follows, in which the description of OOD detection function can be found.

__Modified Uncertainty Modeling.__ 
In Definition 3.1, it shows that the transport plan $\mathbf{P}$ can be viewed as a joint probability distribution $\pi(\mu,\nu)$, with marginals $\mu$ and $\nu$.
Given a transport plan in the form of a matrix, we use two random variables, $U$ and $V$, to describe the randomness of the mass distributed in rows and columns, respectively.
For a test input $v \in dom(V)$, there is a corresponding column in the transport plan, which is essentially a conditional probability distribution $\pi_{U|V}(u|v)$ computed by joint probability $\pi(u,v)$ and marginal probability $\pi(v)$, as defined in Definition 3.4.
Accordingly, the entropy of the conditional probability distribution indicates the level of uncertainty regarding a test input belonging to the OOD. To this end, formally, we define the transport that happens on the test input $v$ as a random event, represented by a random variable $T$ that follows the conditional distribution, i.e., $T\sim \pi_{U|V}(u|v)$.
Then, __the score function is denoted as the entropy of
conditional distribution $\mathbb{H}(U|V=v)$, as defined in Definition 3.5.__ 

Following the distance-based methods, our method also trains the model only using ID data and then utilizes the trained model to extract the features of test inputs. Therefore, we don't use OOD data to train the model at all. But we recognize the term "OOD validation set" is inaccurate, as in the response to Reviewer c9Kw. 

Since our proposal is to explore the empirical distribution with geometric information to determine whether it can enhance the OOD detection task, our method requires a set of inputs to build the empirical distribution. As in the response to Reviewer uQxg, we have discussed the limitations and advantages of our proposal in detail.  

We feel sorry about the PDF not yet updated. We will refine the manuscript after the rebuttal period.

Reviewer comment (Evaluation):
Why is the method better than KNN or SSD for hard OOD tasks? (Table 3) In principle, it seems that hard OOD samples are challenging for distance-based approaches due to the proximity of OOD samples and ID samples.

Author response:
__A2.__ Current challenges faced by existing distance-based methods in handling OOD samples that closely resemble ID in difficult OOD tasks arise from their simplistic utilization of distance information, as seen in methods like SSD or KNN. These approaches rely solely on the distance from test samples to either the centroid of training data or some ID samples.
In contrast, our approach leverages the empirical distribution of training data and test inputs. By integrating pair-wise distance information with distributional insights through optimal transport, our method develops a scoring function that effectively captures the distinctions between OOD and ID samples. This enables more accurate discrimination of OOD samples that are closely located to ID data.

Reviewer comment (Experiments):
Dimension is not discussed too too much in this work, but greatly affects usefulness + ability-to-solve OT and approx. OT such as Sinkhorn. Given that I believe the work is fairly complete as far as other aspects of experiments go (datasets, benchmarks etc) I will choose to push on this. Do you have any experimental results varying the encoder/feature-space dimension? It would be great to know how this affects performance, especially for higher dim image datasets.

Author response:
__Dimension of Encoding.__ We provide the ablation study on the dimension of encoding in the table below. Here, we adopt the ResNet18 as the backbone and the same dataset settings as Table 1.

| Backbone    | Feature Dimension | FPR   | AUROC |
|:--------:|:---------:|:-----:|:-----:|
| ResNet18 | 128       | 28.25 | 93.79 |
|          | 256       | 28.31 | 94.50 |
|          | 512       | 28.58 | 93.94 |
|          | 1024      | 29.07 | 93.94 |
|          | 2048      | 33.28 | 92.92 |
| ResNet50 | 2048      | __22.76__ | __95.11__ |

We can find the effect of feature dimension on performance is not monotonic on a single model. For example, on the backbone ResNet18, the performance decreases when the feature dimension exceeds 1024.
However, a higher feature dimension yields better performance for larger models, such as ResNet50.

Reviewer comment (Evaluation):
Could discuss the role of the whole test set in making decisions on each test point, in more detail. See QUESTIONS.

Author response:
Thanks for your comments. 
As you have pointed out, there are several works (Serrà, Joan, et al. 2019; Schirrmeister, Robin, et al. 2020; Ren, Jie, et al. 2019) that employ the likelihood ratio for OOD detection. Notably, (Serrà, Joan, et al. 2019; Schirrmeister, Robin, et al. 2020;) necessitate training models beyond ID data, requiring additional knowledge, in addition to using multiple samples for making decision on a test point. The work by (Ren, Jie, et al. 2019) doesn't require extra data, but it computes the likelihood ratio by training a background model on perturbed ID data. In contrast, our method doesn't have access to additional data, such as generated data or OOD data, for model training. Despite there being some differences, we agree that it would be an interesting line to consider the likelihood ratio in-depth for OOD detection. 

In the sequel, we have tried to discuss the strategy of taking the whole test set in making decisions, covering comparisons with other distance-based competitors, addressing limitations, and contemplating potential future directions. 

__Differentiating with methods not using empirical distribution.__ We discussed the relationship between our method and existing distance-based methods. For example, SSD, it uses Mahalanobis distance as a detection metric. As mentioned in page 13, we remark that the Mahalanobis distance can be viewed as a special case of OT. Another baseline KNN, which is a degenerated version of our method (as described in page 9) when OT is eliminated from our method, using the $k$-th distance to ID sample as a detection metric.


__Limitations.__ Nevertheless, relying on the entire test input may pose challenges in terms of efficiency, which is the cost paid for performance enhancement. In the current manuscript, we have investigated how the scale of test inputs impacts performance. We split the whole test set into multiple batches with varied batch sizes. As presented in Figure 2, our method benefits from an increase in the size of the test batch and shows a gradual rise in performance until convergence.

Thus, it is of interest to further study the balance between the batch size and the performance variance. It would also give the promise for adapting the techniques to different applications with various performance requirements and affordable computational resources. Also, when test data arrives in batches, another interesting question arises: Can we leverage the information from previously detected batches to enhance OOD detection in subsequent batches?


__Future works.__ Shifting our attention to training samples, a mirroring problem arises: how to effectively utilize training samples, which remains underexplored in existing distance-based methods that use all training samples. 

One possible solution is to find effective representations in the feature space. Following this line of thought, in our study, one way that we can try to explore these effective representations in the probability space, such as the barycenters of empirical probability distribution.

Another possible solution is to generate virtual samples as effective representations to substitute for all training samples. Certainly, the application of generation is not limited to this. It is known that a kind of research on OOD detection involves accessing known OOD samples during the training stage (OOD exposure). However, assuming the explicit knowledge of unknowns is not practical due to the vulnerability of OOD inputs. This leads to a potential problem: Can we randomly generate virtual OOD samples for OOD exposure?

These discussions can be integrated into a revised manuscript.


####  __References__

Serrà, Joan, et al. "Input Complexity and Out-of-distribution Detection with Likelihood-based Generative Models." International Conference on Learning Representations. 2019.

Schirrmeister, Robin, et al. "Understanding anomaly detection with deep invertible networks through hierarchies of distributions and features." Advances in Neural Information Processing Systems 33 (2020): 21038-21049.

Ren, Jie, et al. "Likelihood ratios for out-of-distribution detection." Advances in neural information processing systems 32 (2019).

Reviewer comment (Writing):
If there is a main thing to improve, I think it would be help the not-familiar-with-OT reader gain a little more intuition for higher entropy of the transport plan (resulting from running Sinkhorn, etc) correlating with more-likely-to-be-OOD. There is a worked example with a few datapoints in figure 1, that is good. You could maybe supplement it and help the reader by pointing out some other visual examples like e.g. if P and Q are same and you have very large N for both, you would get closer to the identity mapping being the solution, which has zero variance/entropy, etc. In short, I think your typical reader might be quite familiar with OOD but not familiar with OT so you could add just a little more hand-holding in that part of the text since the main intuition for the method comes from understanding why the conditional entropy should be high or low.

Author response:
We agree that the readability of paper is very important.
We will incorporate more visual examples as follows in the revised manuscript (we feel sorry about that we can't provide figure in comments.), to enhance the readability of our paper.

__Showcase.__ When $\mu$ and $\nu$ are identical empirical distributions, the transport of a test input is exactly, suggesting the smallest entropy in the respective conditional distribution.

Reviewer comment (Experiments):
If I understand correctly, the score for one test point is determined in part by the whole test set's W_p distance to the train set. This is both interesting and raises questions. One analogy is the subset of OOD methods that try to fit a density to the test points to do likelihood ratio tests (the density is evaluated on each test datapoint but is the result of learning on all test points). If I understand correctly, though you briefly acknowledge using geometry of the whole test set as a motivation, you eventually do not return to a discussion on this particular aspect of the setup. I think it's worth differentiating between methods that use the whole test set for each test point's decision or not. Could you provide more discussion on this (what to take away from it, and what could be inspired by it in the future)? You could potentially consider introducing some new tasks as well such as making decisions on sets of points. Apologies if you discuss this in more detail and I missed it.

Author response:
Thanks for your comments. 
As you have pointed out, there are several works (Serrà, Joan, et al. 2019; Schirrmeister, Robin, et al. 2020; Ren, Jie, et al. 2019) that employ the likelihood ratio for OOD detection. Notably, (Serrà, Joan, et al. 2019; Schirrmeister, Robin, et al. 2020;) necessitate training models beyond ID data, requiring additional knowledge, in addition to using multiple samples for making decision on a test point. The work by (Ren, Jie, et al. 2019) doesn't require extra data, but it computes the likelihood ratio by training a background model on perturbed ID data. In contrast, our method doesn't have access to additional data, such as generated data or OOD data, for model training. Despite there being some differences, we agree that it would be an interesting line to consider the likelihood ratio in-depth for OOD detection. 

In the sequel, we have tried to discuss the strategy of taking the whole test set in making decisions, covering comparisons with other distance-based competitors, addressing limitations, and contemplating potential future directions. 

__Differentiating with methods not using empirical distribution.__ We discussed the relationship between our method and existing distance-based methods. For example, SSD, it uses Mahalanobis distance as a detection metric. As mentioned in page 13, we remark that the Mahalanobis distance can be viewed as a special case of OT. Another baseline KNN, which is a degenerated version of our method (as described in page 9) when OT is eliminated from our method, using the $k$-th distance to ID sample as a detection metric.


__Limitations.__ Nevertheless, relying on the entire test input may pose challenges in terms of efficiency, which is the cost paid for performance enhancement. In the current manuscript, we have investigated how the scale of test inputs impacts performance. We split the whole test set into multiple batches with varied batch sizes. As presented in Figure 2, our method benefits from an increase in the size of the test batch and shows a gradual rise in performance until convergence.

Thus, it is of interest to further study the balance between the batch size and the performance variance. It would also give the promise for adapting the techniques to different applications with various performance requirements and affordable computational resources. Also, when test data arrives in batches, another interesting question arises: Can we leverage the information from previously detected batches to enhance OOD detection in subsequent batches?


__Future works.__ Shifting our attention to training samples, a mirroring problem arises: how to effectively utilize training samples, which remains underexplored in existing distance-based methods that use all training samples. 

One possible solution is to find effective representations in the feature space. Following this line of thought, in our study, one way that we can try to explore these effective representations in the probability space, such as the barycenters of empirical probability distribution.

Another possible solution is to generate virtual samples as effective representations to substitute for all training samples. Certainly, the application of generation is not limited to this. It is known that a kind of research on OOD detection involves accessing known OOD samples during the training stage (OOD exposure). However, assuming the explicit knowledge of unknowns is not practical due to the vulnerability of OOD inputs. This leads to a potential problem: Can we randomly generate virtual OOD samples for OOD exposure?

These discussions can be integrated into a revised manuscript.


####  __References__

Serrà, Joan, et al. "Input Complexity and Out-of-distribution Detection with Likelihood-based Generative Models." International Conference on Learning Representations. 2019.

Schirrmeister, Robin, et al. "Understanding anomaly detection with deep invertible networks through hierarchies of distributions and features." Advances in Neural Information Processing Systems 33 (2020): 21038-21049.

Ren, Jie, et al. "Likelihood ratios for out-of-distribution detection." Advances in neural information processing systems 32 (2019).

Reviewer comment (Experiments):
The experiments are mostly based on basic architecture and rather stylized academic benchmarks. Experiments on larger models (ResNet-50 / ViT) and more realistic benchmarks (e.g., ImageNet-O) can make the result considerably more convincing.

Author response:
Thanks for your suggestions. We have added more experimental results for larger models and datasets as suggested.

* __Evaluation on ResNet50.__ Following the experimental settings of SSD, we alter the backbone to ResNet50 and use the CIFAR100 as ID dataset. The average performance over five datasets (in Table 1) is presented in the table below.

|        | SVHN  |       | iSUN  |       | LSUN  |       | Texture |       | Place365 |       |
|--------|-------|-------|-------|-------|-------|-------|---------|-------|----------|-------|
| Method | FPR   | AUROC | FPR   | AUROC | FPR   | AUROC | FPR     | AUROC | FPR      | AUROC |
| SSD+   | 9.63  | 98.14 | 96.48 | 76.89 | 81.00 | 83.49 | 65.79   | 86.71 | 79.04    | 79.03 |
| KNN+   | 21.49 | 96.00 | 75.67 | 83.07 | 44.53 | 92.32 | 50.37   | 90.13 | 77.57    | 79.40 |
| Ours   | __5.68__  | __98.96__ | __23.28__ | __95.21__ | __5.70__  | __98.90__ | __29.89__   | __94.16__ | __49.26__    | __88.32__ |


* __Evaluation on ImageNet with ViT.__ Following the parameter settings of KNN, we take ViT-B/16 as the backbone. We use ImageNet-1k as the ID dataset and five datasets (in Table 1) as the OOD datasets. The average performance is presented in the table below.

| Model | ID          | Method | FPR   | AUROC |
|:-----:|:-----------:|:------:|:-----:|:-----:|
|       |             | SSD    | 22.23 | 94.80 |
| ViT   | ImageNet-1k | KNN    | 21.39 | 94.70 |
|       |             | Ours   | __14.34__ | __96.50__ |


The above results show the superiority of our method under the settings of larger models and datasets, which is consistent with the result shown in the manuscript. We will incorporate these results in the revised version.

Reviewer comment (Evaluation):
Table 4: How are the result from "w/o OT" rows obtained? Specifically, what metric is used for OOD detection?

Author response:
Incorporating optimal transport (OT) into our approach allows us to go beyond traditional distance-based methods that rely solely on the distance information of training samples and test inputs. Our method harnesses OT to capture empirical distribution information in the feature space, enhancing out-of-distribution (OOD) detection.

To assess the impact of optimal transport (OT) on OOD detection performance, we conducted an ablation study. The results are presented in Table 4, where the row labeled (w/o OT) represents calculations based solely on the distance between a test input and training samples. The distance metric employed in this case is the mean Euclidean distance.