NUQ: Nonparametric Uncertainty Quantification for Deterministic Neural Networks

1 INTRODUCTION . It is crucial in many applications of modern machine learning methods to complement the prediction with some sort of a “ confidence ” score . In particular , deep neural network models , which usually achieve state-of-the-art results in various tasks , are notorious for providing overconfident predictions on data they did not see during training ( Nguyen et al. , 2015 ) . This issue restricts their wide usage in the fields with high costs of wrong predictions , such as medicine ( Miotto et al. , 2016 ) , autonomous driving ( Levinson et al. , 2011 ; Filos et al. , 2020 ) , finance ( Brando et al. , 2018 ) and others . Thus , developing a reliable method of quantifying uncertainty is of great interest to researchers and especially practitioners . The community in recent years made tremendous efforts to develop different uncertainty estimation methods and approaches , including calibration Guo et al . ( 2017 ) , ensembling ( Lakshminarayanan et al. , 2017 ) , Bayesian methods ( Gal & Ghahramani , 2016 ) , and many others ( Ovadia et al. , 2019 ; Wang et al. , 2019 ) . Recently , a series of methods of uncertainty estimation based on the single deterministic neural network model was developed ( Van Amersfoort et al. , 2020 ; Liu et al. , 2020 ; van Amersfoort et al. , 2021 ) . Their primary focus is on ensuring that embeddings of the data obtained on some layer of a network capture the geometrical relationships between the data samples in the input space , which is done via different regularization strategies . Given this property , one can apply a certain approach to capture uncertainty in the embedding space . The crucial property of these methods is the relatively mild required change in architectures and training procedures , which allows the application of the majority of existing deep learning models . In practice it is usually important to distinguish two types of uncertainty : aleatoric and epistemic ( Der Kiureghian & Ditlevsen , 2009 ; Kendall & Gal , 2017 ) . The aleatoric uncertainty reflects the internal noise in the data due to class overlap , data markup errors , or other reasons . This type of uncertainty can not be reduced by providing more data . The epistemic uncertainty reflects the model ’ s ignorance of data . We can reduce the uncertainty of this type once we get more data . Epistemic uncertainty , thus , may be used to identify out-of-distribution OOD data . If the model can quantify this type of uncertainty , it may abstain from prediction and address it to a human expert . Also , the ability to quantify epistemic uncertainty helps in active learning ( Gal et al. , 2017 ) , where lack of “ knowledge ” naturally indicates in which areas we should label samples . Importantly , there is no single definition of uncertainty , and diverse , often heuristic treatments are usually used in practice . Summary of the contributions . In this paper , we develop a new and theoretically grounded method of uncertainty quantification applicable to any deterministic neural network model . More specifically , our contributions are as follows . 1 . We rigorously define the uncertainty of the model prediction at a particular data point . This is done by direct consideration of the probability of the wrong prediction . 2 . We provide corresponding uncertainty estimate by computing the variance of the kernel estimate of conditional density with the appropriately chosen bandwidth . 3 . We apply the resulting method of uncertainty estimation in the neural network ’ s embedding space . Our approach complements recent works in uncertainty estimation for deterministic neural networks , which suffered from a lack of a principled method to quantify the uncertainty . 4 . We implement the method in a scalable manner , which allows it to be used on large datasets such as ImageNet . The experimental results in misclassification detection and OOD detection tasks show the significant potential of the proposed approach . The rest of the work is organised as follows . Section 2 describes the theoretical background and the resulting uncertainty estimation method . Section 3 reviews the related works . In Section 4 we describe the experimental evaluation of the proposed method . Section 5 concludes the study . 2 NONPARAMETRIC UNCERTAINTY QUANTIFICATION . 2.1 ESTIMATION UNDER COVARIATE SHIFT . Let ’ s consider the standard binary classification setup ( X , Y ) ∈ Rd × { 0 , 1 } with ( X , Y ) ∼ Ptr . We assume that we observe the dataset D = { ( Xi , Yi ) } ni=1 of i.i.d . points from Ptr . The classical problem in statistics and machine learning is to find a rule ĝ based on the dataset D which approximates the optimal one : g∗ = argmin g P ( g ( X ) 6= Y ) . Here g : Rd → { 0 , 1 } is any classifier and the probability of wrong classificationRg = P ( g ( X ) 6= Y ) is usually called risk . The rule g∗ is given by the Bayes optimal classifier : g∗ ( x ) = { 1 , η ( x ) ≥ 12 , 0 , η ( x ) < 12 , where η ( x ) = p ( Y = 1 | X = x ) which is the conditional distribution of Y given X = x under the distribution P. In this work , we consider a situation when the distribution of the test samples Ptest is different from the one for the training dataset Ptr , i.e . Ptest 6= Ptr . Obviously , the rule g∗ obtained for P = Ptr might no longer be optimal if the aim is to minimize the error on the test data Ptest ( g ( X ) 6= Y ) . In order to formulate a meaningful estimation problem , some additional assumptions are needed . First of all , we assume that the distribution Ptest is unknown at the model construction moment , and only the dataset D is available . Also , we will assume that the conditional label distribution p ( y | x ) is the same under both Ptr and Ptest . The latter assumption has two important consequences : 1 . All the difference between Ptr and Ptest is due to the difference between marginal distributions of X : ptrain ( X ) and ptest ( X ) . The situation when ptest ( X ) 6= ptrain ( X ) is known as covariate shift . 2 . The Bayes rule is still valid , i.e. , optimal even under Ptest . However , while Bayes rule g∗ is still optimal , its approximation ĝ might be arbitrary bad under the covariate shift . The reason for that is that we can ’ t expect ĝ to approximate g∗ well in the areas where we have few samples from the training set or don ’ t have them at all . Thus , some special treatment of covariate shift is required . We will discuss the particular problem statement in the next section . 2.2 PROBLEM STATEMENT . We consider a classification rule ĝ ( x ) = ĝD ( x ) constructed solely based on the dataset D. Let us start from defining pointwise risk of estimation : R ( x ) = P ( ĝ ( X ) 6= Y | X = x ) , where P ( ĝ ( X ) 6= Y | X = x ) ≡ Ptr ( ĝ ( X ) 6= Y | X = x ) ≡ Ptest ( ĝ ( X ) 6= Y | X = x ) under the assumptions above . The valueR ( x ) is independent of covariate distribution ptest ( X ) and essentially allows to define a meaningful target of estimation which is based solely on the quantities known for the training distribution . Let us note that the total risk valueR ( x ) admits the following decomposition : R ( x ) = R̃ ( x ) +R∗ ( x ) , where R∗ ( x ) = P ( g∗ ( X ) 6= Y | X = x ) is Bayes risk and R̃ ( x ) = P ( ĝ ( X ) 6= Y | X = x ) − P ( g∗ ( X ) 6= Y | X = x ) is an excess risk . HereR∗ ( x ) corresponds to aleatoric uncertainty as it completely depends on the data distribution . Excess risk R̃ ( x ) directly measures imperfectness of the model ĝ and thus can be seen as a measure of epistemic uncertainty . To proceed , we first assume that the classifier ĝ has the standard form : ĝ ( x ) = { 1 , η̂ ( x ) ≥ 12 , 0 , η̂ ( x ) < 12 , where η̂ ( x ) = p̂ ( Y = 1 | X = x ) is an estimate of the conditional density η ( x ) . For such an estimate we can efficiently bound the excess risk via the following classical inequality Devroye et al . ( 2013 ) : R̃ ( x ) = P ( ĝ ( X ) 6= Y | X = x ) − P ( g∗ ( X ) 6= Y | X = x ) ≤ 2|η̂ ( x ) − η ( x ) | . It allows us to obtain an upper bound for the risk : R ( x ) ≤ L ( x ) = R∗ ( x ) + 2|η̂ ( x ) − η ( x ) | , where R∗ ( x ) = min { η ( x ) , 1 − η ( x ) } is just the Bayes risk . While the upper bound still depends on the unknown quantity η ( x ) , we will see in the next section that L ( x ) allows for an efficient approximation under mild assumptions . 2.3 NONPARAMETRIC UNCERTAINTY QUANTIFICATION . 2.3.1 KERNEL DENSITY ESTIMATE AND ITS ASYMPTOTIC DISTRIBUTION . To execute the approach above we need to consider some particular type of estimator for ĝ . In this work , we suggest to consider classical kernel-based estimator of the conditional density as it allows for simple description of its asymptotic properties . For an arbitrary class label c , the conditional probability estimate can be expressed as : p̂ ( Y = c | X = x ) = ∑N i=1Kh ( xi − x ) [ yi = c ] ∑N j=1Kh ( xj − x ) . ( 1 ) Note that in case of c = 1 the equation above gives us η̂ ( x ) . In our experiments , we consider one dimensional kernel function K : R → R+ and construct the resulting kernel in Rd of the following form : Kh ( x− y ) = d∏ j=1 K ( xj − yj h ) . Different choices of kernels are possible , see Supplementary Material , Section A.4.1 ) . A well-known fact ( see , e.g . Powell ( 2010 ) ) is that the difference between η̂ ( x ) −η ( x ) for properly chosen bandwidth h converges in distribution as follows : η̂ ( x ) − η ( x ) → N ( 0 , 1 Nhd σ2 ( x ) p ( x ) { ∫ [ K ( u ) ] 2du } d ) , ( 2 ) where n is the number of data points in the training set , K ( · ) is the kernel used for kernel density estimate ( KDE ) , h is the bandwidth of the kernel ; d is the dimensionality of the problem and σ2 ( x ) is the standard deviation of the data label at point x . Note that we can efficiently approximate the variance term in ( 2 ) . To start with , the integral∫ [ K ( u ) ] 2du can be computed in the closed form for various standard kernels , see Supplementary Material , Table 3 . Second , we approximate the marginal density of objects p ( x ) . The density can be again obtained via KDE : p̂ ( x ) = 1 Nhd ∑N i=1Kh ( x− xi ) . However , one can choose the other estimates of the density , not necessarily related to the considered kernel estimate . For example , Gaussian Mixture Model ( GMM ) can be used similarly to Mukhoti et al . ( 2021 ) . The only thing left is the variance which can be estimated as σ̂2 ( x ) = σ̂2 ( y | x ) = η̂ ( x ) ( 1− η̂ ( x ) ) . Now we are equipped with an estimate of the distribution for η̂ ( x ) − η ( x ) . Let us denote by τ ( x ) the standard deviation of a Gaussian from equation ( 2 ) : τ2 ( x ) = 1 Nhd σ2 ( x ) p ( x ) { ∫ [ K ( u ) ] 2du } d . Based on the obtained approximation of the distribution for L ( x ) , one can construct an abstention procedure that takes into account properties of this distribution and study the theoretical properties of the resulting method similarly to ( Zaoui et al. , 2020 ) . We defer these studies to future work and focus on the practical approach for obtaining uncertainty estimates which directly follows from the derivations above .

Summary: This paper proposes a nonparametric uncertainty quantification method for deep neural networks. Using a kernel-based estimator of the conditional density (i.e., the predictive distribution $p(y|x)$) in the feature space of a pre-trained neural network, the epistemic and the aleatoric uncertainty can be obtained separately from an upper bound of the excess risk and Bayes risk. For practical feasibility, several subproblems are approached with existing methods, such as kernel density estimation/GMM for $p(x)$, Improved Sheather-Jones algorithm for kernel bandwidth selection, HMSW for fast nearest neighbors retrieval. Finally, good OOD detection performance is demonstrated on several image datasets including MNIST, CIFAR, and ImageNet.