Title: DETECTING OUT-OF-DISTRIBUTION INPUTS TO DEEP GENERATIVE MODELS USING TYPICALITY

Abstract: Recent work has shown that deep generative models can assign higher likelihood to out-of-distribution data sets than to their training data (Nalisnick et al., 2019; Choi et al., 2019) . We posit that this phenomenon is caused by a mismatch between the model's typical set and its areas of high probability density. In-distribution inputs should reside in the former but not necessarily in the latter, as previous work has presumed (Bishop, 1994) . To determine whether or not inputs reside in the typical set, we propose a statistically principled, easy-to-implement test using the empirical distribution of model likelihoods. The test is model agnostic and widely applicable, only requiring that the likelihood can be computed or closely approximated. We report experiments showing that our procedure can successfully detect the out-of-distribution sets in several of the challenging cases reported by Nalisnick et al. (2019) .

1. INTRODUCTION:

Recent work (Nalisnick et al., 2019; Choi et al., 2019; Shafaei et al., 2018) showed that a variety of deep generative models fail to distinguish training from out-of-distribution (OOD) data according to the model likelihood. This phenomenon occurs not only when the data sets are similar but also when they have dramatically different underlying semantics. For instance, Glow (Kingma & Dhariwal, 2018) , a state-of-the-art normalizing flow, trained on CIFAR-10 will assign a higher likelihood to SVHN than to its CIFAR-10 training data (Nalisnick et al., 2019; Choi et al., 2019) . This result is surprising since CIFAR-10 contains images of frogs, horses, ships, trucks, etc. and SVHN contains house numbers. A human would be very unlikely to confuse the two sets. These findings are also troubling from an algorithmic standpoint since higher OOD likelihoods break previously proposed methods for classifier validation (Bishop, 1994) and anomaly detection (Pimentel et al., 2014) .

We conjecture that these high OOD likelihoods are evidence of the phenomenon of typicality.1 Due to concentration of measure, a generative model will draw samples from its typical set (Cover & Thomas, 2012) , a subset of the model's full support. However, the typical set may not necessarily intersect with regions of high probability density. For example, consider a d-dimensional isotropic Gaussian. Its highest density region is at its mode (the mean) but the typical set resides at a distance of √ d from the mode (Vershynin, 2018) . Thus a point near the mode will have high likelihood while being extremely unlikely to be sampled from the model. We believe that deep generative models exhibit a similar phenomenon since, to return to the CIFAR-10 vs SVHN example, Nalisnick et al. (2019) showed that sampling from the model trained on CIFAR-10 never generates SVHN-looking images despite SVHN having higher likelihood.

Based on this insight, we propose that OOD detection should be done by checking if an input resides in the model's typical set, not just in a region of high density. Unfortunately it is impossible to analytically derive the regions of typicality for the vast majority of deep generative models. To define a widely applicable and scalable OOD-detection algorithm, we formulate Shannon (1948)'s entropy-based definition of typicality into a statistical hypothesis test. To ensure that the test is robust even in the low-data regime, we employ a bootstrap procedure (Efron & Tibshirani, 1994) to set the OOD-decision threshold. In the experiments, we demonstrate that our detection procedure succeeds in many of the challenging cases presented by Nalisnick et al. (2019) . In addition to these successes, we also discuss failure modes that reveal drastic variability in OOD detection for the same data set pairs under different generative models. We highlight these cases to inspire future work.

2. BACKGROUND: TYPICAL SETS:

The typical set of a probability distribution is the set whose elements have an information content sufficiently close to that of the expected information (Shannon, 1948) . A formal definition follows.

Definition 2.1 ( , N)-Typical Set (Cover & Thomas, 2012) For a distribution p(x) with support x ∈ X , the ( , N )-typical set A N [p(x)] ∈ X N is comprised of all N -length sequences that satisfy

H[p(x)] -≤ 1 N -log p(x 1 , . . . , x N ) ≤ H[p(x)] +

where H[p(x)] = X p(x)[-log p(x)]dx and ∈ R + is a small constant.

When the joint density in Definition 2.1 factorizes, we can write:

EQUATION

This is the definition we will use from here forward as we assume both training data and samples from our generative model are identically and independently distributed (i.i.d.) . In this factorized form, the middle quantity can be interpreted as an N -sample empirical entropy: Thomas, 2012) states that this estimate will converge to the true entropy as N → ∞.

1/N N n=1 -log p(x n ) = ĤN [p(x)]. The asymptotic equipartition property (AEP) (Cover &

To build intuition, let p(x) = N(0, σ 2 I) and consider its ( , 1)-typical set. Plugging in the relevant quantities to Equation 1 and simplifying, we have 

x ∈ A 1 [N(0, σ 2 I)] if 1 2 |d -||x -µ|| 2 2 /σ 2 |

= σ √ d.

In turn, we can geometrically interpret A 1 [N(0, σ 2 I)] as an annulus centered at µ with radius σ √ d and whose width is a function of (and σ). This is a well-known concentration of measure result often referred to as the Gaussian Annulus Theorem (Vershynin, 2018) . Figure 1 (a) illustrates a Gaussian centered on the all gray image (pixel value 128). We show that samples from this model never resemble the all gray image, despite it having the highest probability density, because they are drawn from the annulus. In Figure 1 (b) we visualize the interplay between density and volume that gives rise to the typical set. The connection between typicality and concentration of measure can be stated formally as: (van den Oord et al., 2016) . We do not consider implicit generative models (Mohamed & Lakshminarayanan, 2016 ) (such as GANs (Goodfellow et al., 2014 )) due to their likelihood being difficult to even approximate.

The primary focus of this paper is in performing a goodness-of-fit (GoF) test (D'Agostino, 1986; Huber-Carol et al., 2012) for p(x; θ). Specifically, given an M -sized batch of test observations X = { x1 , . . . , xM } (M ≥ 1), we desire to determine if X was sampled (i.i.d.) from p θ or from some other distribution q = p θ . We assume no knowledge of q, thus making our desired GoF test omnibus (Eubank & LaRiccia, 1992) . The vast majority of GoF tests operate via the model's cumulative distribution function (CDF) and/or being able to compute an empirical distribution function (EDF) (Cramér, 1928; Massey Jr, 1951; Anderson & Darling, 1954; Stephens, 1974) . However, the CDFs of DGMs are not available analytically, and numerical approximations are hopelessly slow due to the curse of dimensionality. Likewise, EDFs lose statistical strength exponentially as dimensionality grows (Wasserman, 2006) . Our goal is to formulate a scalable test that does not rely on strong parametric assumptions (e.g. Chen & Xia (2019) ) and has better computational properties than kernel-based alternatives (e.g. Liu et al. (2016) ).

3.2. A HYPOTHESIS TEST FOR TYPICALITY:

Returning to the results of Nalisnick et al. (2019) and Choi et al. (2019) , the high-dimensionality of natural images (d = 3072 for CIFAR and SVHN) alone is enough to suspect the influence of phenomena akin to the Gaussian Annulus Theorem. Yet there are stronger parallels still: Nalisnick et al. (2019) showed that the all-black image has the highest density of any tested input to their FashionMNIST DGM, but this model is never observed to generate all-black images. Thus we are inspired to critique DGMs not via density but via typical set membership:

EQUATION

)

The intuition is that if X is indeed sampled from p θ , then with high probability it must reside in the typical set (Theorem 2.1). To determine if X ∈ A M [p(x; θ)], we can plug X into Equation 1 as a length M sequence and check if the -bound holds:

EQUATION

where ˆ denotes the test statistic. We provide a sanity check for Equation 3 in Subfigure 1(c), showing ˆ calculated for the high-dimensional Gaussian example described in Section 2. We see that ˆ achieves its minimum value exactly at

√ d-distance from 128.

In Appendix A.2 we show that our test is consistent unless the alternative's typical set is a subset of p θ 's:

A M [q(x)] ⊆ A M [p(x; θ)].

This limitation is reasonable and expected given our fundamental assumption in Equation 2. Since the size of the typical set is upper bounded as a function of entropy-log Thomas, 2012) -the model entropy determines the probability of type-II error: higher entropy implies a larger typical set, a larger set implies more chance of

|A M [p(x; θ)]| ≤ M (H[p(x; θ)] + ) (Cover &

A M [q] ⊆ A M [p θ ],

and a higher degree of intersection leads to a better chance of incorrectly failing to reject H 0 : x ∼ p θ . Yet it is not uncommon to sacrifice consistency for generality when testing GoF (e.g. Chi-square vs Kolmogorov-Smirnov tests (Haberman, 1988) ).

3.3. IMPLEMENTATION DETAILS:

In an ideal setting, we could mathematically derive the regions in X that correspond to the typical set (e.g. the Gaussian's annulus) and check if x resides within that region. Unfortunately, finding these regions is analytically intractable for neural-network-based generative models. A practical implementation of Equation 3 requires computing the entropy H[p(x; θ)] and the threshold .

Entropy Estimator:

The entropy of DGMs is not available in closed-form and therefore we resort to the following sampling-based approximation. Recall from Subsection 2 that the AEP states that the sample entropy will converge to the true entropy as the number of samples grows. Since we have access to the model and can drawn a large number of samples from it, the empirical entropy should be a good approximation for the true model entropy:

EQUATION

where xs ∼ p(x; θ). However, in preliminary experiments (reported in Appendix E.1) we observed markedly better OOD detection when using an alternative estimator known as the resubstitution estimator (Beirlant et al., 1997) . This estimator uses the training set for calculating the expectation:

EQUATION

This approximation should be good as well since we assume N to be large. 4Setting the OOD-Threshold with the Bootstrap Concerning the threshold , we propose setting its value through simulation-by constructing a bootstrap confidence interval (BCI) (Efron, 1992; Arcones & Gine, 1992) for the null hypothesis

H 0 : X ∈ A M [p(x; θ)],

with the alternative being

H 1 : X ∈ A M [p(x; θ)].

In a slight deviation from the tradition procedure for BCI construction, we assume the existence of a validation set X that was held-out from X before training the generative model (just as is usually done for hyperparameter tuning).This is only to account for the generative model overfitting to the training set. From this validation set, we bootstrap sample K 'new' data sets {X k } K k=1 of size M and then plug each into Equation 3 in place of X:

1 M M m=1 -log p(x k,m ; θ) -ĤN RESUB [p(x; θ)] = ˆ k (6)

where ˆ k is the estimate for the kth bootstrap sample. All K estimates then form the bootstrap distribution

F ( ) = 1 K K k=1 δ[ˆ k ].

Calculating the α-quantile of F ( ), which we denote as M α , determines the threshold at which we reject the null hypothesis with confidence-level α (Arcones & Gine, 1992). If we reject the null, then we decide that the sample does not reside in the typical set and therefore is OOD. The complete procedure is summarized in Algorithm 1 in Appendix B. Observe that nearly all of the computation can be performed offline before any test set is received, including all bootstrap simulations. The rejection threshold M α depends on a particular M and α setting, but these computations can be done in parallel across multiple machines. The most expensive test-time operation is obtaining log p( x, θ). After this is done, only an O(M ) operation to sum the likelihoods is required.

4. RELATED WORK:

Goodness-of-Fit Tests As mentioned in Section 3.1, many of the traditional GoF tests are not applicable to the DGMs and high-dimensional data sets that we consider since CDFs and EDFs are both intractable in this setting. Kernelized Stein discrepancy (Chwialkowski et al., 2016; Liu et al., 2016) is a recently-proposed GoF test that can scale to the DGM regime, and we compare against it in the experiments. Several works have proposed GoF tests based on entropy (Gokhale, 1983; Parzen, 1990 )-e.g. for normal (Vasicek, 1976 ), uniform (Dudewicz & Van Der Meulen, 1981) , and exponential (Crzcgorzewski & Wirczorkowski, 1999) distributions. However, these tests are derived from maximum entropy results and not motivated from typicality. There are also directed GoF tests such as ones based on likelihood ratios (Neyman & Pearson, 1933; Wilks, 1938) or discrepancies such as KL divergence (Noughabi & Arghami, 2013) . These tests require an explicit definition of q, which may be difficult in many DGM-appropriate scenarios. Yet the recent work of Ren et al. (2019) does apply likelihood ratios to PixelCNNs by constructing q such that it models a background process (i.e. some perturbed version of the original data).

Typical and Minimum Volume Sets:

We are aware of only two previous works that use a notion of typicality for GoF tests or OOD detection. Sabeti & Hst-Madsen (2019) propose a typicality framework based on minimum description length. They deem data as 'atypical' if it can be represented in less bits than one would expect under the generative model. While our frameworks share the same conceptual foundation, Sabeti & Hst-Madsen (2019)'s implementation relies on strong parametric assumptions and cannot be generalized to deep models (without drastic approximations). Choi et al. (2019) , the second work, leverages normalizing flows to test for typicality by transforming the data to a normal distribution and then deeming points outside the annulus to be anomalous. This approach restricts the generative model to be a Gaussian normalizing flow whereas ours is applicable to any generative model with a computable likelihood. Our work is also related to the concept of minimum volume (MV) sets (Sager, 1979; Polonik, 1997; Garcia et al., 2003) . MV sets have been used for GoF testing (Polonik, 1999; Glazer et al., 2012) and to detect outliers (Platt et al., 2001; Scott & Nowak, 2006; Clémenc ¸on et al., 2018) . However, we are not aware of any work that scales MV-set-based methodologies to the degree required to be applicable to DGMs.

Generative Models and Outlier Detection Probabilistic but non-test-based techniques have also been widely employed to discover outliers and anomalies (Pimentel et al., 2014) . One of the most common is to use a (one-sided) threshold on the density function to classify points as OOD (Barnett et al., 1994) ; this idea is used in Tarassenko et al. (1995 ) Bishop (1994) , and Parra et al. (1996) , among others. Other work has applied more sophisticated techniques to density function evaluations-for instance, Clifton et al. (2014) applies extreme value theory. Yet this work and all others of which we are aware do not identify points with abnormally high density as OOD. Thus they would fail in the settings presented by Nalisnick et al. (2019) . As for work focusing on DGMs in particular, most previous work proposes training improvements to make the model more robust. For instance, Hendrycks et al. (2019) show that robustness and uncertainty quantification w.r.t. outliers can be improved by exposing the model to an auxiliary data set (a proxy for OOD data) during training. As for post-training outlier and OOD detection, Choi et al. (2019) proposes using an ensemble of models to compute the Watanabe-Akaike information criterion (WAIC). However, there are no rigorous arguments for why WAIC should quantify GoF. Škvára et al. (2018) proposes using a VAE's conditional likelihood as an outlier criterion, finding that this works well only when the hyperparameters can be tuned using anomalous data. As far as we are aware, we are the first to apply a hypothesis testing framework to the problem of OOD or anomaly detection for DGMs. As mentioned above, Ren et al. (2019) use likelihood ratios, but they do not perform a hypothesis test.

5. EXPERIMENTS:

We now evaluate our typicality test's OOD detection abilities, focusing in particular on the image data set pairs highlighted by Nalisnick et al. (2019) . We use the same three generative models as they did-Glow (Kingma & Dhariwal, 2018) 1. t-test: We apply a two-sample students' t-test to check for a difference in means in the empirical likelihoods. In terms of Equation 3, this baseline will reject for any > 0, and thus we expect it to be overly conservative. Moreover, this test does not have access to validation data and therefore improvements upon it can be attributed to our bootstrap procedure.

2.. Kolmogorov-Smirnov test (KS-test)::

We apply a two-sample KS-test to the likelihood EDFs. This test is stronger than our typicality test since it is checking for equivalence in all moments whereas ours (and the t-test) is restricted to the first moment. In turn, this test has a greater computational complexity-O(M log M ) compared to O(M ).

3.. Maximum Mean Discrepancy (MMD)::

We apply a two-sample MMD (Gretton et al., 2012) test to the data directly. Yet we incorporate the generative model by using a Fisher kernel (Jaakkola & Haussler, 1999) . We also apply the same bootstrap procedure on validation data to construct the test statistic. MMD has greater runtime still at O(N M d). It also requires access to (a subset of) the training data at test-time, which is undesirable.

4.. Kernelized Stein Discrepancy (KSD)::

We apply KSD (Liu et al., 2016) to test for GoF to the generative model and again use a Fisher kernel and the bootstrap procedure on validation data. KSD has runtime O(M 2 d). While we have ignored the construction of the kernel in the runtime analysis, KSD is the most costly since it requires computing three model gradients.

5.. Annulus Method::

We use a modified version of Choi et al. (2019) 's annulus method applied to Gaussian normalizing flows. Like them, we classify something as OOD based on its distance to the sphere with radius √ d. This is essentially performing our test but via closed-form expressions for entropy made available by the Gaussian base distribution. We use the same bootstrap procedure on validation data to set the 'slack' variable .

Grayscale Images We first evaluate our typicality test on grayscale images. We trained a Glow, PixelCNN, and VAE each on the FashionMNIST training split and tested OOD detection using the FashionMNIST, MNIST, and NotMNIST test splits. We use the FashionMNIST test split to evaluate for type-I error (incorrect rejection of the null) and the MNIST and NotMNIST splits for type-II error (incorrect rejection of the alternative). In Figure 2 we show the empirical distribution of likelihoods over each data set for each model. We see the same phenomenon as reported by Nalisnick et al. (2019) -namely, that the MNIST OOD test set (green) has a higher likelihood than the training set (black). Lower-sided thresholding (Bishop, 1994) would clearly fail to detect the OOD sets. Table 1 reports a comparison against baselines, showing the fraction of M -sized batches classified as OOD. The IN-DIST. column reports the value for the FashionMNIST test set and ideally this number should be 0.00; any deviation from zero corresponds to type-I error. Conversely, the MNIST and NOTMNIST columns should be 1.00, and any deviation corresponds to type-II error. We see that for M = 2 all tests find it hard to reject the null hypothesis, which is not surprising given the overlap in the histograms in Figure 2 . The exceptions are the annulus method for NotMNIST-Glow (96%), the typicality test for MNIST-PixelCNN (56%), and all methods except KS-test for NotMNIST-VAE. One failure mode for almost all methods is NotMNIST for the PixelCNN. None of the likelihoodbased tests can distinguish NotMNIST as OOD due to the near perfect overlap in histograms shown in Figure 2(b) . KSD and especially MMD are able to perform better in this case due to having access to the original feature-space representations (in addition to the generative model). Yet, surprisingly, KSD and MMD perform comparatively poorly for MNIST, especially at M = 10 and M = 25. The annulus method was unable to detect MNIST, which we found surprising given its close relationship to our typicality test, which does perform well. Yet Choi et al. (2019) note that Gaussian normalizing flows do not necessarily make the latent space normally distributed, and our typicality test may be able to use information from the volume element that is not available to the annulus method.

Natural Images We next turn to data sets of natural images-in particular SVHN, CIFAR-10, and ImageNet. We train Glow on SVHN, CIFAR-10, and ImageNet and use the two non-training sets for OOD evaluation. We found using MMD and KSD to be too expensive to make OOD decisions in an online system. Table 2 reports the fraction of M -sized batches classified as OOD. We see that our method (first row, bolded) is able to easily detect the OOD sets for SVHN, rejecting size-two batches at the rate of 98%+ while having only 1% type-I error. Performance on the CIFAR-10-trained model is good as well with 42%+ of OOD batches detected at M = 2 and 100% at M = 10 (type-I error at 1% in both cases). The hardest case is Glow trained on ImageNet: the KS-test performed best at M = 25 with 89%, followed by the t-and typicality tests at 72% and 74% respectively. The annulus method again had varying performance, being conspicuously inferior at detecting SVHN for the CIFAR and ImageNet models while having the best performance on ImageNet for the CIFAR model. We report additional results in Appendix E.3 for our method, showing performance for all M ∈ [1, 150] and when using CIFAR-100 as an OOD set.

Lastly, we report two challenging cases worthy of note and further attention. Figure 3 (a) shows our method applied to Glow when trained on CIFAR-10, tested on CIFAR-100. The y-axis again shows fraction of batches reported as OOD and the x-axis the batch size M . Even at M = 150 our method classifies only ∼ 20% of batches as OOD. Yet this result is not surprising given that CIFAR- 10 is a subset of CIFAR-100, which means that our test's subset assumptions for consistency are violated. More interesting is the case of Glow trained on CelebA, tested on CIFAR-10 and CIFAR-100. Figure 3 (b) shows the histogram of log-likelihoods: all distributions peak at nearly the same value. The distribution of observed during the bootstrap procedure (M = 200) is shown in Figure 3 (c), with the red and black dotted lines denoting ˆ computed using the whole set. We see that ˆ for the OOD set is even less than the in-distribution's, meaning that it would be impossible to reliably reject the OOD data while not rejecting the in-distribution test set as well. Interestingly, PixelCNN and VAE do not have as dramatic of an overlap in likelihoods-a phenomenon that can also be observed in Figure 2 -which implies that the ability to detect OOD sets does not only depend on the data involved but the models as well. Some models may have likelihood functions that are reliably discriminative, and this presents an intriguing area for future work. 

6. DISCUSSION AND CONCLUSIONS:

We have presented a model-agnostic and computationally efficient statistical test for OOD inputs derived from the concept of typical sets. In the experiments we showed that the proposed test is especially well-suited to DGMs, identifying the OOD set for SVHN vs CIFAR-10 vs ImageNet (Nalisnick et al., 2019) with high accuracy (while maintaining ≤ 1% type-I error). In this work we used the null hypothesis H 0 : X ∈ A M , which was necessary since we assumed access to only one training data set. One avenue for future work is to use auxiliary data sets (Hendrycks et al., 2019) to construct a test statistic for the null H 0 : X ∈ A M , as would be proper for safety-critical applications. In our experiments we also noticed two cases-PixelCNN trained on FashionMNIST, tested on NotMNIST and Glow trained on CelebA, tested on CIFAR-in which the empirical distributions of in-and out-of-distribution likelihoods matched near perfectly. Thus use of the likelihood distribution produced by DGMs has a fundamental limitation that is seemingly worse than what was reported by Nalisnick et al. (2019) .

D EXPERIMENTAL DETAILS:

MMD and KSD Kernels We found that MMD and KSD only had good performance when using the Fisher kernel (Jaakkola & Haussler, 1999) : k(x i , x j ) = (∇ θ log p(x i ; θ)) T ∇ θ log p(x j ; θ). All other kernels attempted required substantial tuning to the scale parameters and we did not want to assume access to enough data to perform this tuning. The ineffectiveness of MMD on pixelspace has been noted previously (Bikowski et al., 2018) . Furthermore, we found the memory cost of implementing the traditional Fisher kernel to be quite costly for Glow, each vector having 2million+ elements. Hence in the experiments we use the kernel modified such that the derivative is taken w.r.t. the input (making it the likelihood score): k (x i , x j ) = (∇ xi log p(x i ; θ)) T ∇ xj log p(x j ; θ).

Data Set Splits and Bootstrap Re-Samples For each data set we used the canonical train-test splits. To construct the validation set and perform bootstrapping, we extracted 5, 000 samples from the test split and bootstrap sampled (with replacement) K = 50 data sets to calculate F ( ). We didn't find using K > 50 to markedly change performance. We then extracted another 5, 000 samples from the test split, divided them into M -sized batches, and classified each other as OOD or not according to the various tests. We repeated this whole process 10 times, randomizing the instances in the validation and testing splits, in order to compute the means and standard deviations that are reported in Tables 1 and 2 .

α-Level In preliminary experiments, we did not find a notable difference in type-II error when using α = 0.95 vs α = 0.99. Using the latter slightly improved type-I error and thus we used that value for all experiments and all methods.

E ADDITIONAL RESULTS

E.1 COMPARING ENTROPY ESTIMATORS:

In the tables below, we report results comparing the two entropy estimators considered-the Monte Carlo approximation with samples from the model (Equation 4) vs the resubstitution estimator (Equation 5). We see that the samples-based estimator performs better in only one setting, Fash-ionMNIST vs MNIST at M = 2. In all other cases, the resubstitution estimator performs equally well or better. In fact, the samples-based estimator could not detect NotMNIST as OOD at all, having 0% even at M = 10 and M = 25. This inferior performance is mostly due to the distribution of likelihoods being more diffuse when computed with samples. We suspect improvements to the generative models that enable them to better capture the true generative process will in turn improve the MC sample-based estimator. 

:

Choi et al. (2019) also consider typicality as an explanation but ultimately deem it not to be a crucial factor.Nalisnick et al. (2019) implicitly mention typicality in their discussion of the transformed representations' proximity to the mean and explicitly in a comment on Open Review: https://openreview.net/ forum?id=H1xwNhCcYm&noteId=HkgLWfveT7

While A N is not the smallest high-probability set(Polonik, 1997) and therefore not the most efficient compression, its size is of the same order(Cover & Thomas, 2012).

The reader may have noticed Theorem 2.1 requires 'N sufficiently large' but in the Gaussian example we assumed N = 1. For high-dimensional factorized likelihoods, log p(x) = d j=1 log p(xj), and thus we can interpret Definition 2.1 as acting dimension-wise instead of across observations.

The bias and variance of the resubstitution estimator are hard to characterize for DGMs. The work ofJoe (1989) is most related, describing its properties under multivariate kernel density estimators.

We could not replicate the performance of WAIC as reported byChoi et al. (2019). See Appendix E.2.

https://github.com/openai/glow

Figures and Tables:

Figure 1: Typical Sets. Subfigure (a) shows the example of a Gaussian with its mean located at the high-dimensional all-gray image. Subfigure (b) shows how the typical set arises due to the nature of high-dimensional integration. The figure is inspired by Betancourt (2017)'s similar illustration. Subfigure (c) shows our proposed method (Equation 3, higher ˆ implies OOD) applied to a Gaussian simulation. The values have been re-scaled for purposes of visualization.

, PixelCNN (van den Oord et al., 2016), and Rosca et al. (2018)'s VAE architecture-attempting to replicate training and evaluation as closely as possible. See Appendix C for a full description of model architectures and training. See Appendix D for more details on evaluation. We consider the following baselines 5 ; all statistical tests use α = 0.99:

Figure 2: Empirical Distribution of Likelihoods. The above figure shows the histogram of loglikelihoods for FashionMNIST (train, test), MNIST (test), and NotMNIST (test) for the (a) Glow, (b) PixelCNN, and (c) VAE.

Figure 3: Challenging Cases: CIFAR-10 vs CIFAR-100, CelebA vs CIFAR's.

≤ where d denotes dimensionality. See Appendix A.1 for a complete derivation. The inequality will hold for any choice of if ||x -µ|| 2

Table content: <table/>

Theorem 2.1 Probability of the Typical Set (Cover & Thomas, 2012) For N sufficiently large, the typical set has probability P A N [p(x)] > 1 -.

Table content: <table><tr><td>This result speaks to the central role of typical sets in compression: A N is an efficient representation</td></tr><tr><td>of X N as it is sampled under p(x). 2 Returning to the Gaussian example, we could 'compress' R d under N(0, σ 2 I) to just the σ √ d-radius annulus. 3</td></tr><tr><td>3 A TYPICALITY TEST FOR OOD INPUTS</td></tr><tr><td>We next describe our core contribution: a reformulation of Definition 2.1 into a scalable goodness-</td></tr><tr><td>of-fit test to determine if a batch of test data was likely drawn from a given deep generative model.</td></tr><tr><td>3.1 SETTING OF INTEREST: GOODNESS-OF-FIT TESTING FOR DEEP GENERATIVE MODELS</td></tr><tr><td>Assume we have a generative model p(x; θ)-with θ denoting the parameters-that was trained on</td></tr><tr><td>a data set X = {x 1 , . . . , x N }. Take x to be high-dimensional (d &gt; 500) and N to be sufficiently</td></tr><tr><td>large (N &gt; 25, 000) so as to enable training a high-capacity neural-network parametrized model-a</td></tr><tr><td>so-called 'deep generative model' (DGM). Furthermore, we assume that p(x; θ) has a likelihood</td></tr><tr><td>that can be evaluated either directly or closely approximated via Monte Carlo sampling. Examples</td></tr><tr><td>of DGMs that meet these specifications include normalizing flows (Tabak &amp; Turner, 2013) such as</td></tr><tr><td>Glow (Kingma &amp; Dhariwal, 2018), latent variable models such as variational autoencoders (VAEs)</td></tr><tr><td>(Kingma &amp; Welling, 2014; Rezende et al., 2014), and auto-regressive models such as PixelCNN</td></tr></table>

Natural Images: Fraction of M -Sized Batches Classified as OOD.

Table content: <table><tr><td/><td/><td>M = 2</td><td/><td/><td>M = 10</td><td/><td/><td>M = 25</td><td/></tr><tr><td>METHOD</td><td>SVHN</td><td colspan="2">CIFAR-10 IMAGENET</td><td>SVHN</td><td colspan="2">CIFAR-10 IMAGENET</td><td>SVHN</td><td colspan="2">CIFAR-10 IMAGENET</td></tr><tr><td/><td/><td/><td/><td colspan="2">Glow Trained on SVHN</td><td/><td/><td/><td/></tr><tr><td>Typicality Test</td><td>0.01±.00</td><td>0.98±.00</td><td>1.00±.00</td><td>0.00±.00</td><td>1.00±.00</td><td>1.00±.00</td><td>0.02±.00</td><td>1.00±.00</td><td>1.00±.00</td></tr><tr><td>t-Test</td><td>0.00±.00</td><td>0.95±.00</td><td>1.00±.00</td><td>0.04±.00</td><td>1.00±.00</td><td>1.00±.00</td><td>0.03±.00</td><td>1.00±.00</td><td>1.00±.00</td></tr><tr><td>KS-Test</td><td>0.00±.00</td><td>0.00±.00</td><td>0.00±.00</td><td>0.08±.00</td><td>1.00±.00</td><td>1.00±.00</td><td>0.03±.00</td><td>1.00±.00</td><td>1.00±.00</td></tr><tr><td colspan="2">Annulus Method 0.02±.01</td><td>0.70±.05</td><td>1.00±.00</td><td>0.02±.01</td><td>1.00±.00</td><td>1.00±.00</td><td>0.00±.00</td><td>1.00±.00</td><td>1.00±.00</td></tr><tr><td/><td/><td/><td colspan="3">Glow Trained on CIFAR-10</td><td/><td/><td/><td/></tr><tr><td>Typicality Test</td><td>0.42±.09</td><td>0.01±.01</td><td>0.64±.04</td><td>1.00±.00</td><td>0.01±.01</td><td>1.00±.00</td><td>1.00±.00</td><td>0.01±.01</td><td>1.00±.00</td></tr><tr><td>t-Test</td><td>0.44±.01</td><td>0.01±.00</td><td>0.65±.00</td><td>1.00±.00</td><td>0.02±.00</td><td>1.00±.00</td><td>1.00±.00</td><td>0.02±.00</td><td>1.00±.00</td></tr><tr><td>KS-Test</td><td>0.00±.00</td><td>0.00±.00</td><td>0.00±.00</td><td>1.00±.00</td><td>0.01±.00</td><td>0.98±.00</td><td>1.00±.00</td><td>0.01±.00</td><td>1.00±.00</td></tr><tr><td colspan="2">Annulus Method 0.09±.03</td><td>0.02±.00</td><td>0.87±.05</td><td>0.19±.01</td><td>0.03±.00</td><td>1.00±.00</td><td>0.35±.02</td><td>0.04±.00</td><td>1.00±.00</td></tr><tr><td/><td/><td/><td colspan="3">Glow Trained on ImageNet</td><td/><td/><td/><td/></tr><tr><td>Typicality Test</td><td>0.78±.08</td><td>0.02±.01</td><td>0.01±.00</td><td>1.00±.00</td><td>0.20±.06</td><td>0.01±.01</td><td>1.00±.00</td><td>0.74±.05</td><td>0.01±.01</td></tr><tr><td>t-Test</td><td>0.76±.00</td><td>0.02±.00</td><td>0.01±.00</td><td>1.00±.00</td><td>0.18±.01</td><td>0.01±.00</td><td>1.00±.00</td><td>0.72±.01</td><td>0.01±.00</td></tr><tr><td>KS-Test</td><td>0.00±.00</td><td>0.00±.00</td><td>0.00±.00</td><td>1.00±.00</td><td>0.29±.01</td><td>0.01±.00</td><td>1.00±.00</td><td>0.89±.01</td><td>0.02±.00</td></tr><tr><td colspan="2">Annulus Method 0.00±.00</td><td>0.03±.00</td><td>0.02±.01</td><td>0.02±.02</td><td>0.15±.04</td><td>0.02±.00</td><td>0.16±.04</td><td>0.57±.12</td><td>0.02±.00</td></tr></table>

Grayscale Images: Fraction of M -Sized Batches Classified as OOD. The in-distribution column reflects type-I error and the MNIST and NotMNIST columns reflect type-II.

Table content: <table><tr><td/><td>M = 2</td><td/><td>M = 10</td><td/><td>M = 25</td><td/></tr><tr><td>METHOD</td><td colspan="6">IN-DIST. MNIST NOTMNIST IN-DIST. MNIST NOTMNIST IN-DIST. MNIST NOTMNIST</td></tr><tr><td/><td/><td colspan="2">Glow Trained on FashionMNIST</td><td/><td/><td/></tr><tr><td>Typicality Test w/ Data</td><td>0.02±.01 0.14±.10</td><td>0.08±.04</td><td>0.02±.02 1.00±.00</td><td>0.69±.11</td><td>0.01±.00 1.00±.00</td><td>1.00±.00</td></tr><tr><td colspan="2">Typicality Test w/ Samples 0.02±.01 0.44±.17</td><td>0.00±.00</td><td>0.03±.03 1.00±.00</td><td>0.00±.00</td><td>0.06±.05 1.00±.00</td><td>0.00±.00</td></tr></table>

Natural Images: Fraction of M -Sized Batches Classified as OOD.

Table content: <table><tr><td/><td/><td>M = 2</td><td/><td/><td>M = 10</td><td/><td/><td>M = 25</td></tr><tr><td>METHOD</td><td>SVHN</td><td colspan="2">CIFAR-10 IN-DIST.</td><td>SVHN</td><td colspan="2">CIFAR-10 IN-DIST.</td><td>SVHN</td><td>CIFAR-10 IN-DIST.</td></tr><tr><td/><td/><td/><td colspan="3">Glow Trained on ImageNet</td><td/><td/></tr><tr><td>Typicality Test w/ Data</td><td>0.78±.08</td><td>0.02±.01</td><td colspan="2">0.01±.00 1.00±.00</td><td>0.20±.06</td><td colspan="2">0.01±.01 1.00±.00</td><td>0.74±.05</td><td>0.01±.01</td></tr><tr><td colspan="2">Typicality Test w/ Samples 0.29±.08</td><td>0.02±.01</td><td colspan="2">0.01±.00 1.00±.00</td><td>0.16±.05</td><td colspan="2">0.01±.01 1.00±.00</td><td>0.73±.08</td><td>0.01±.01</td></tr></table>

Peer review (iclr2020):
Thanks for the authors for your detailed reviews. My major concerns about the proposed method are whether *the typicality set* could be faithfully applied in the small data regime. The authors point me to the interesting Figure 4, which shows that it basically achieves converged performance when or smaller numbers for some problems. I think this experiment is a strong support for the proposed method. However, I don*t agree that the M=1 Gaussian case acts as a strong support for the method. As I said, for some other wired distribution, it is difficult to interpret what the M=1 Typicality set becomes. The authors also clarify the difference between different baselines. Overall, I will increase my score to *Weak Accept*. ########################## Recent works have shown that out-of-distribution samples can have higher likelihoods than in-distribution samples for some generative models. To explain this phenomenon and to tackle the problem for OOD detection, this paper adopts *typical sets* for identifying in-distribution samples. Specifically, a *typical set* is a set of examples whose expected log likelihood approximate the model*s entropy. For a Gaussian distribution, the paper finds that a single point typical set locates exactly in the sqrt{d} radius, which is usually favored over the high-likelihood origin. Then the paper uses the *typical set* to perform OOD for a batch of examples. Empirically they demonstrate competitive performance over MNIST and natural image tasks. Typical set seems natural for out-of-distribution detection. An important property is that, if one draws a large number of independent samples from the distribution, it is very likely that these samples belong to the typical set (basically Theorem 2.1). However, for small n, this property doesn*t hold anymore, which leaves here a questionmark whether *Typical set* can be used for OOD detection in small n regime. As the author argues, for Gaussian distribution when n=1 the typical locations are those sqrt{d} radius points. But this doesn*t justify the *Typical set*. If the distribution is some non-Gaussian wired distribution, the typical locations doesn*t seem to make sense at all. Following the previous argument above, the Typical set method requires to perform OOD for a batch of examples. In contrast, the Annulus method can be directly applied to one single test example. Empirically, the Typically set doesn*t demonstrate obvious advantages compared to the baselines. For both MNIST and natural image tasks, it seems that all methods behave similarly. For comparing such big tables, I would recommend adding a column showing the average ranks among all methods. Beyond that, standard OOD tasks usually evaluate methods using AUROC and AUPR (Hendrycks and Gimpel, 2017). Is it possible to also include such metrics ? Theorem 2.1 is confusing. It is beneficial to define what P is, and verbally state what the theorem conveys.