N ATURAL P OSTERIOR N ETWORK : D EEP B AYESIAN U NCERTAINTY FOR E XPONENTIAL F AMILY D ISTRIBUTIONS
A BSTRACT
Uncertainty awareness is crucial to develop reliable machine learning models.
In this work, we propose the Natural Posterior Network (NatPN) for fast and highquality uncertainty estimation for any task where the target distribution belongs to the exponential family.
Thus, NatPN ﬁnds application for both classiﬁcation and general regression settings.
Unlike many previous approaches, NatPN does not require out-of-distribution (OOD) data at training time.
Instead, it leverages
Normalizing Flows to ﬁt a single density on a learned low-dimensional and task dependent latent space.
For any input sample, NatPN uses the predicted likelihood to perform a Bayesian update over the target distribution.
Theoretically NatPN assigns high uncertainty far away from training data.
Empirically our extensive experiments on calibration and OOD detection show that NatPN delivers highly competitive performance for classiﬁcation regression and count prediction tasks.
I NTRODUCTION
[Figure]
Accurate and rigorous uncertainty estimation is key for reliable machine learning models in safety-critical domains.
It quantiﬁes the conﬁdence of machine learning models, thus allowing them to validate knowledgeable predictions corresponding to correct/wrong predictions, ﬂag predictions on unknown input domains corresponding to anomaly or Out-ofDistribution detection, or detect natural shifts of the data facilitating real-time model maintenance (Filos et al., 2019;
Malinin et al., 2021; Ovadia et al., 2019).
Speciﬁcally, a reliable model can handle all these failure modes with high-quality estimates of aleatoric and epistemic uncertainty (Gal, 2016).
These two levels of uncertainty allow a model to account for both irreducible data uncertainty (e.g. a fair dice’s chance of 1 / 6 for each face) and uncertainty due to the lack of knowledge about unseen data (e.g. input features differing signiﬁcantly from training data or a covariate shift) respectively.
Aleatoric and epistemic uncertainty levels can eventually be combined into an overall predictive uncertainty (Gal, 2016)
Traditional neural networks are not readily applicable in safety-critical domains as they show overconﬁdent prediction, in particular on data that is different from training data (Guo et al., 2017; Lakshminarayanan ∗ et al., 2017).
To mitigate this problem, an important model family for uncertainty estimation directly predicts the parameters of a conjugate prior distribution on the predicted target probability distribution , thus accounting for the different levels of uncertainty.
These models are efﬁcient as they only require a single forward pass for target and uncertainty prediction.
Most of those models focus on classiﬁcation and thus predict parameters of a Dirichlet distribution (Biloš et al., 2019; Charpentier et al., 2020; Gast & Roth, 2018; Malinin & Gales, 2018; 2019; Nandy et al., 2020; Sensoy et al., 2020; Shi et al., 2020; Stadler et al., 2021; Zhao et al., 2020b).
However, only two works (Amini et al., 2020; Malinin et al., 2020a) have focused on regression by learning parameters of a Normal Inverse-Gamma (NIG) distribution as conjugate prior.
Hence, all these models are limited to a single task (e.g. either classiﬁcation or regression).
Some approaches even require out-of-distribution (OOD) data at training time (Malinin & Gales, 2018; 2019) which is an unrealistic assumption in many real-world applications where anomalies are a priori diverse, rare or unknown.
Our contribution.
We propose Natural Posterior Network (NatPN) as a new approach parametrizing conjugate prior distributions for versatile uncertainty estimation.
NatPN is motivated from both the theoretical and practical perspective.
(1) NatPN can estimate predictive uncertainty for any task described by the general group of exponential family distributions contrary to existing approaches from this family of models.
Notably, this encompasses very common tasks such as classiﬁcation, regression and count prediction which can be described with Categorical, Normal and Poisson distributions, respectively.
In theory, NatPN is based on a new uniﬁed exponential family framework which performs an input-dependent Bayesian update.
For every input, it predicts the parameters of the posterior over the target exponential family distribution.
We show that this Bayesian update is guaranteed to predict high uncertainty far from training data.
In practice, NatPN requires no
OOD data for training , only adds a single normalizing ﬂow density to the last predictor layer and provides fast uncertainty estimation in a single forward pass .
Our extensive experiments showcase the high performances of NatPN for various criteria (accuracy, calibration, OOD and shift detection) and tasks (classiﬁcation, regression and count prediction).
We illustrate the accurate aleatoric and predictive uncertainty predictions of NatPN on two toy examples for classiﬁcation and regression in
Fig.
None of the conjugate prior related works have similar theoretical and practical properties.
R ELATED W ORK
In this section, we describe other work related to uncertainty estimation for supervised learning.
We refer to Gawlikowski et al.
(2021) for a detailed survey on uncertainty estimation in deep learning.
Sampling-based methods.
A ﬁrst family of models estimates uncertainty by aggregating statistics (e.g. mean and variance) from different samples of an implicit predictive distribution.
Examples are ensemble (Kim & Ghahramani, 2012;
Lakshminarayanan et al., 2017; Simpson et al., 2012; Wen et al., 2020; Wenzel et al., 2020) and dropout (Gal & Ghahramani, 2016) models which provide high-quality uncertainty estimates (Ovadia et al., 2019) at the cost of an expensive sampling phase at inference time.
Moreover, ensembles usually require training multiple models.
Further, Bayesian neural networks (BNN) (Blundell et al., 2015; Maddox et al., 2019; Ritter et al., 2018) model the uncertainty on the weights and also require multiple samples to estimate the uncertainty on the ﬁnal prediction.
While recent BNNs have shown reasonably good performance (Dusenberry et al., 2020;
Farquhar et al., 2020; Osawa et al., 2019), modelling the distribution on the weights suffers from pathological behavior thus limiting these approaches in practice (Foong et al., 2020; Graves, 2011;
Izmailov et al., 2021).
In particular, Izmailov et al.
(2021) uses an enormous computation budget by parallelizing the computation over
TPUv3 devices and running tens of thousands of training epochs to achieve a more exact Bayesian inference which is not suitable for practical applications.
In contrast, NatPN predicts uncertainty in a single forward pass with a closed-form posterior distribution over the target variable.
NatPN does not model uncertainty on the weights.
Sampling-free methods.
A second family of models is capable of estimating uncertainty in a single forward pass.
The family of models parametrizing conjugate prior distributions is the main focus of this paper (Gast & Roth, 2018;
Kopetzki et al., 2021; Nandy et al., 2020; Sensoy et al., 2020; Shi et al., 2020; Stadler et al., 2021; Ulmer, 2021).
Beyond this family of models, we differentiate between four other families of sampling-free models for uncertainty estimation.
A ﬁrst family aims at learning deep Gaussian processes with random features projections or learned inducing points (Biloš et al., 2019;
Lakshminarayanan et al., 2020; van Amersfoort et al., 2020; 2021).
A second family aims at learning deep energy-based models (Elﬂein et al., 2021; Grathwohl et al., 2020).
Another family of models aims at propagating uncertainty across layers (Gast & Roth, 2018; Hernandez-Lobato & Adams, 2015;
Postels et al., 2019; Shekhovtsov & Flach, 2019; Wang et al., 2016).
They model uncertainty at the weight and/or activation levels and are generally constrained to speciﬁc transformations.
In contrast, NatPN only models the uncertainty on the predicted target variable and does not enforce any constraint on the encoder architecture.
Further, some of the models propagating uncertainty already used the exponential family framework (Ranganath et al., 2015; Wang et al., 2016).
However, while they parametrize exponential family distributions, NatPN parametrizes the conjugate prior of the target exponential family distributions which accounts for the epistemic uncertainty.
Finally, while the family of calibration models aims at calibrating predictions (Kuleshov et al., 2018; Moon et al., 2020; Rahimi et al., 2020; Song et al., 2019; Zhao et al., 2020a), NatPN aims at accurately modelling both aleatoric and epistemic uncertainty on in- and out-of-distribution data.
N ATURAL P OSTERIOR N ETWORK
At the very core of NatPN stands the Bayesian update rule: Q ( θ | D ) ∝ P
( D | θ ) × Q ( θ ) where P ( D | θ ) is the target distribution of the target data D given its parameter θ , and Q ( θ ) and Q ( θ | D ) are the prior and posterior distributions, respectively, over the target distribution parameters.
The target distribution P ( D | θ ) could be any likelihood describing the observed target labels.
The Bayesian update has three main advantages: (1) it introduces a prior belief which represents the safe default prediction if no data is observed, (2) it updates the prior prediction based on observed target labels, and (3) it assigns a conﬁdence for the new target prediction given the aggregated evidence count of observed target labels.
While NatPN is capable to perform a Bayesian update for every possible input given the observed training data, we ﬁrst recall the Bayesian background for a single exponential family distribution
[Table]
3. E XPONENTIAL F AMILY D ISTRIBUTION
Distributions from the exponential family are very widely used and have favorable analytical properties.
Indeed, (1) they cover a wide range of target variables like discrete, continuous, counts or spherical coordinates
[Table]
and (2) they beneﬁt from intuitive and generic formulae for their parameters, density functions and statistics which can often be evaluated in closed-form.
Important examples of exponential family distributions are Normal, Categorical and Poisson distributions (see Tab. 1).
Formally, an exponential family distribution on a target variable y ∈ R with natural parameters θ ∈ R L can be denoted as
[Equation]
where h : R → R is the carrier or base measure , A : R L → R the log-normalizer and u : R → R L the sufﬁcient statistics (Bishop, 2006; Nielsen & Nock, 2010).
The entropy of an exponential family distribution can always be written as H
[ P ] =
A ( θ ) − θ T ∇ θ A ( θ ) − E [log h ( y )]
(Nielsen & Nock, 2010).
An exponential family distribution always admits a conjugate prior, which often also is a member of the exponential family:
[Equation]
where η ( χ , n ) is a normalization coefﬁcient, χ ∈ R L are prior parameters and n ∈ R + is the evidence .
Given a set of N target observations { y ( i ) } Ni , it is easy to compute a closed-form Bayesian update Q ( θ | χ post , n post ) ∝ P ( { y ( i ) } Ni | θ ) × Q ( θ | χ prior , n prior ) :
[Equation]
[Figure]
[Table]
+qwsn3CMRNhVCkRcpY8sdAI5REKd6K1dvEiFTvE3xKIIUl/2zyuTLqZJyrHeXrpzF+5cNsiq67gDLl1cuEuarGN1UBxvK+vnGHMoGJdufU1P0MIE1AnPpBYmYBULmMmeNCGbUEWYycuPCWpuZrLJeATD/3A9RmWp80MwlE1zdi1GMqmFAUCMx2mSr6XK9ZNxKfUWwj73xcjFLCFU4ADzPm0OMObM63OtBzjCbiy4YwTVc+As7vbRhhk9j1VRwry2cnzdiJ9BTiBFOJP70FgMIUuSGzezZVzNh7porsG6EVxX70lqYbpirPxa3Ov/KF3Ig4ioDNXXndPaQyA8vwKVNub6uKPaYa9PyKjLsZ/Jxu72lgrILqnfABFwjOkVU12o2+WNASZOeawaVA7V5p3FijMAeWF6jdj2QmW1PoAwDmlwDW1s1Mq2Ckg10qtuaZmV/VLRKRdLO/PTK9W8pY6CKfAOzAAHLIIV0AAtsAcQ+AF+gl/g98jfwmThbWHqEh0eyue8BrdG4f0/rBBL9A==</latexit> where χ post = n prior χ prior + (cid:80) Nj u
( y ( j ) )
n prior + N and n post = n prior + N .
We see that χ prior (resp.
χ post ) can be viewed as the average sufﬁcient statistics of n prior (resp.
n post ) ﬁctitious samples (Bishop, 2006).
Further, the average sufﬁcient statistic of ﬁctitious samples is equal to the expected sufﬁcient statistic of the conjugate distribution, i.e. χ = E Q ( χ ,n ) [ θ ] (Brown, 1986; Diaconis & Ylvisaker, 1979).
Thus, the parameter χ post carries the inherent aleatoric uncertainty on the target distribution with natural parameters θ , while the evidence n post aligns well with the epistemic uncertainty (i.e. a low evidence means few prior target observations).
We stress that the natural conjugate prior parametrization χ , n is often different from the “well-known” parametrization κ used by standard coding libraries.
By deﬁnition, a bijective mapping m ( κ ) =
( χ , n ) from the natural parametrization to the commonly used parametrization always exists (see examples in Tab. 1).
Finally, exponential family distributions always admit a closed-form posterior predictive distribution (Gelman et al., 2004).
3. I NPUT -D EPENDENT B AYESIAN U PDATE FOR E XPONENTIAL F AMILY D ISTRIBUTIONS
We propose to leverage the power of exponential family distributions for the more complex task when the prediction y
( i ) depends on the input x ( i ) .
Hence, NatPN extends the Bayesian treatment of a single exponential family distribution prediction by predicting an individual posterior update per input.
We distinguish between the chosen prior parameters χ prior , n prior shared among samples, and the additional predicted parameters χ ( i ) , n ( i ) dependent on the input x ( i ) leading to the updated posterior parameters:
[Equation]
Equivalently, NatPN may be interpreted as predicting a set of n ( i ) pseudo observations { y ( j ) }
( i ) j such that their aggregated sufﬁcient statistics satisfy (cid:80) n ( i )
j y
( j ) =
n ( i ) χ
( i ) , and perform the respective
Bayesian update.
This Bayesian update works for any choice of exponential family distributions as long as parameters are mapped to their standard form (see Tab. 1).
According to the principle of maximum entropy (Rosenkrantz, 1989), a practical choice for the prior is to enforce high entropy for the prior distribution which is usually considered less informative.
It is typically achieved when the prior pseudo-count n prior is small and the prior parameter χ prior shows a high aleatoric uncertainty.
Hence, NatPN proposes a generic way to perform the input-dependent Bayesian update χ ( i ) , n ( i ) for any exponential family distribution in three steps (see Fig. 2): (1) An encoder f φ maps the input x ( i ) onto a low-dimensional latent vector z ( i ) =
f φ ( x ( i ) )
∈
R H representing useful features for the prediction task (see left Fig.2).
Note that the architecture of the encoder can be arbitrarily complex.
Then, (2) the latent representation z ( i ) is used in two different ways to predict the parameter update χ ( i ) and the evidence update n ( i ) (see center Fig.2).
On the one hand, a linear decoder g ψ is trained to output the parameter update χ ( i ) =
g ψ ( z ( i ) )
∈ R L accounting for the aleatoric uncertainty.
On the other hand, a single normalized density is trained to output the evidence update n ( i ) =
N H P ( z ( i ) | ω ) accounting for the epistemic uncertainty.
The intuition is that increasing the evidence on training data during training forces the evidence everywhere else (incl.
far from training data) to decrease thanks to the density normalization constraint.
The constant N H is a certainty budget distributed by the normalized density P ( z ( i ) | ω ) over the latent representations z ( i ) i.e. N H = (cid:82) N H P
( z ( i ) | ω ) d z ( i ) =
(cid:82) n ( i )
d z ( i ) .
In practice, we observed that scaling the certainty budget w.r.t.
the latent dimension H helped the density to cover larger volumes in higher dimension (see app.).
Finally, (3) NatPN computes the posterior parameters χ post , ( i ) and n post , ( i ) which can be viewed respectively as the mean and concentration of the posterior distribution (see right Fig.2).
Note that the posterior parameter χ post , ( i ) is a simple weighted average of the prior parameter χ prior and the update parameter χ ( i ) as shown by Eq. 4.
NatPN extends PostNet (Charpentier et al., 2020) which also performs an input-dependent Bayesian update with density estimation.
Yet, it has three crucial differences which lead to major practical improvements.
First, the new exponential family framework is signiﬁcantly more ﬂexible and is not restricted to classiﬁcation.
Second, the Dirichlet α parameter computation is different: NatPN computes the χ parameters – which can be viewed as standard softmax output – and the n evidence separately (i.e. α = n χ ) while PostNet computes one evidence pseudo-count per class.
Third, NatPN is computationally more efﬁcient.
It requires a single density while PostNet requires C densities.
3. ID AND OOD U NCERTAINTY E STIMATES
NatPN intuitively leads to reasonable uncertainty estimation for the two limit cases of strong indistribution (ID) and out-of-distribution (OOD) inputs (see red and purple samples in Fig. 2).
For very likely in-distribution data (i.e. P ( z ( i ) | ω ) → ∞ ), the posterior parameter overrules the prior (i.e. χ post , ( i ) → χ ( i ) ).
Conversely, for very unlikely out-of-distribution data (i.e. P ( z ( i ) | ω ) → 0 ), the prior parameter takes over in the posterior update (i.e. χ post , ( i ) → χ prior ).
Hence, the choice of the prior parameter should reﬂect the default prediction when the model lacks knowledge.
We formally show under mild assumptions on the encoder that NatPN predicts very low additional evidence ( n ( i ) ≈ 0 ) for (almost) any input x ( i ) far away from the training data (i.e. || x ( i ) ||
→ + ∞ ), thus recovering prior predictions (i.e. χ post , ( i ) ≈ χ prior ) (see proof in app.).
Theorem 1.
Let a NatPN model be parametrized with a (deep) encoder f φ with ReLU activations, a decoder g ψ and the density P ( z | ω ) .
Let f φ ( x ) =
V ( l ) x
+ a ( l ) be the piecewise afﬁne representation of the ReLU network f φ on the ﬁnite number of afﬁne regions Q ( l ) (Arora et al., 2018).
Suppose that V ( l ) have independent rows and the density function P ( z | ω ) has bounded derivatives, then for almost any x we have P ( f φ ( δ · x ) | ω )
→ δ →∞ 0 .
i.e the evidence becomes small far from training data.
This theorem only requires that the density avoids very unlikely pathological behavior with unbounded derivatives (Dix, 2013).
A slightly weaker conclusion holds using the notion of limit in density if the density function does not have bounded derivatives (Niculescu & Popovici, 2011).
Finally, the independent rows condition is realistic for trained networks with no constant output (Hein et al., 2019).
It advantageously leads NatPN to consistent uncertainty estimation contrary to standard ReLU networks which are overconﬁdent far from training data (Hein et al., 2019).
3. B AYESIAN N AT PN E NSEMBLE
Interestingly, it is natural to extend the Bayesian treatment of a single NatPN to an ensemble of
NatPN models (NatPE).
An ensemble of m NatPN models is intuitively equivalent to performing m successive Bayesian updates using each NatPN member separately.
More formally, given an input x ( i ) and an ensemble of m jointly trained NatPN models, the Bayesian update for the posterior distribution becomes χ post , ( i ) =
n prior χ prior + (cid:80) mk n ( i ) k χ ( i ) k n prior + (cid:80) mk n ( i ) k and n post , ( i ) =
n prior + (cid:80) mk n ( i ) k .
Note that the standard Bayesian averaging which is used in many ensembling methods (Chipman et al., 2007; Lakshminarayanan et al., 2017; Wen et al., 2020; Wenzel et al., 2020) is different from this
Bayesian combination.
While Bayesian averaging assume that only one model is correct, the Bayesian combination of NatPN allows more or none of the models to be “expert” for some input (Monteith et al., 2011).
For example, an input x ( i ) unfamiliar to every model m (i.e. n ( i ) m ≈ 0 ) would recover the prior default prediction χ prior , n prior .
Existing models already had similar properties for Bayesian combination of classiﬁers (Kim & Ghahramani, 2012; Simpson et al., 2012).
3. O PTIMIZATION
The choice of the optimization procedure is of primary importance in order to obtain both high-quality target predictions and uncertainty estimates regardless of the task.
Bayesian Loss.
We follow Charpentier et al.
and aim at minimizing the Bayesian formulation:
[Equation]
where H [ Q post , ( i ) ] denotes the entropy of the predicted posterior distribution Q post , ( i ) .
Similarly to the ELBO loss, this loss is guaranteed to be optimal when the predicted posterior distribution is close to the true posterior distribution Q ∗ ( θ | x ( i ) ) i.e. Q post , ( i ) ≈ Q ∗ ( θ | x ( i ) )
(Bissiri et al., 2016;
Shawe-Taylor & Williamson, 1997; Zellner, 1988).
However, this loss is generally not equal to the
ELBO loss especially for real valued targets i.e. y ∈ R (see app.).
The term (i) is the expected likelihood under the predicted posterior distribution.
It can be viewed as the Uncertain Cross Entropy (UCE) loss (Biloš et al., 2019) which is known to reduce uncertainty on observed data.
The term (ii) is an entropy regularizer acting as a prior which favors uninformative distributions Q post , ( i ) with high entropy.
In our case, we assume the likelihood P ( y ( i ) | θ ( i ) ) and the posterior Q post , ( i ) to be members of the exponential family.
We take advantage of the convenient computations for such distributions and derive a more explicit formula for the Bayesian formulation (5) (see derivation in the appendix):
[Equation]
6) where λ is an additional regularization weight tuned with a grid search.
Note that the term E [ θ ] T u ( y ( i ) ) favors a good alignment of the expected sufﬁcient statistic E [ θ ] = χ with the observed sufﬁcient statistic u ( y ( i ) ) .
In practice, all terms can be computed efﬁciently in closed form for most exponential family distributions (see examples in Tab. 1).
In particular, simpliﬁcations are possible when the conjugate prior distribution is also in an exponential family which is often the case.
Ultimately Eq.
(6) applies to any exponential family distribution unlike Charpentier et al.
Optimization Scheme.
NatPN is fully differentiable using the closed-form Bayesian loss.
Thus, we train the encoder f φ , the parameter decoder g ψ and the normalizing ﬂow P ( z ( i ) | ω ) w.r.t.
parameters φ , ψ , ω jointly.
Further, we observed that “warm-up training” (Ash & Adams, 2020) and “ﬁne-tuning” (Käding et al., 2016) of the density helped to improve uncertainty estimation for more complex ﬂows and datasets.
Thus, we train the normalizing ﬂow density to maximize the likelihood of the latent representations before and after the joint optimization while keeping all other parameters ﬁxed.
3. M ODEL L IMITATIONS
Task-Speciﬁc OOD.
Previous works show that density estimation is unsuitable for acting on the raw image input (Choi et al., 2019;
Nalisnick et al., 2019; 2020) or on a non-carefully transformed space (Lan & Dinh, 2020).
To circumvent this issue, NatPN does not perform OOD detection directly on the input but rather ﬁts a normalizing ﬂow on a learned space.
In particular, the latent space is (1) low-dimensional, (2) task-speciﬁc and (3) encodes meaningful semantic features.
Similarly,
Charpentier et al.
; Kirichenko et al.
(2020); Morningstar et al.
Winkens et al.
(2020) already improved OOD detection of density-based methods by leveraging a task-induced bias or low-dimensional statistics.
In the case of NatPN, the low-dimensional latent space has to contain relevant features to linearly predict the sufﬁcient statistics required for the task.
For example, NatPN aims at a linearly separable latent space for classiﬁcation.
The downside is that NatPN is capable of detecting OOD samples only with respect to the considered task and requires labeled examples during training.
As an example, NatPN likely fails to detect a change of image color if the task aims at classifying object shapes and the latent space has no notion of color.
Hence, we underline that
NatPN comes with a task-dependent OOD deﬁnition, which is a reasonable choice in practice.
Model-Task Mismatch.
Second, we emphasize that the uncertainty estimation quality of NatPN for (close to) ID data depends on the convergence of the model, the encoder architecture (e.g. MLP, Conv.,
DenseDepth (Eigen et al., 2014)) and the target distribution (e.g. Poisson, Normal distributions) choice which should match the task needs.
However, we show empirically that NatPN provides high quality uncertainty estimates in practice on a wide range of tasks.
Further, we show theoretically that
NatPN leads to uncertain prediction far away from training data for any exponential family target distributions.
In comparison, Meinke & Hein (2020) showed akin guarantees for classiﬁcation only.
E XPERIMENTS
In this section
[Table]
we compare NatPN to existing methods on extensive experiments including three different tasks: classiﬁcation, regression and count prediction.
For each task type
[Table]
we evaluate the prediction quality based on target error and uncertainty metrics.
These various set-ups aim to highlight the versatility of NatPN.
In particular, NatPN is the only model that adapts to all tasks and achieves high performances for all metrics without requiring multiple forward passes.
[Table]
[Table] [Table]
[Figure]
4. S
[Figure]
In our experiments, we change the encoder architecture of NatPN to match the dataset needs.
We perform a grid search over normalizing ﬂows types (i.e. radial ﬂows (Rezende & Mohamed, 2015) and MAF (Germain et al., 2015; Papamakarios et al., 2017)) and latent dimensions.
We show further experiments on architecture, latent dimension, normalizing ﬂow choices and certainty budget choice in the appendix.
Furthermore, we use approximations of the log-Gamma log Γ( x ) and the Digamma ψ ( x ) functions for large input values to avoid unstable ﬂoating computations (see app.).
As prior parameters, we set χ prior = 1 C /C, n prior =
C for classiﬁcation, χ prior =
(0 , 100) T , n prior = 1 for regression and χ prior = 1 , n prior = 1 for count prediction enforcing high entropy for prior distributions.
[Table] [Table]
Baselines.
We focus on recent models parametrizing prior distributions over the target distribution.
For classiﬁcation, we compare NatPN to Reverse KL divergence
Prior Networks (R-PriorNet) (Malinin & Gales, 2019), Ensemble Distribution Distillation (EnD 2 ) (Malinin et al., 2020b) and Posterior
Networks (PostNet) (Charpentier et al., 2020).
Note that Prior Networks require OOD training data — we use an auxiliary dataset when available and Gaussian noise otherwise.
For regression, we compare to Evidential Regression (EvReg) (Amini et al., 2020).
Beyond baselines parametrizing conjugate prior distributions, we also compare to dropout (Dropout) (Gal & Ghahramani, 2016) and ensemble (Ensemble) (Lakshminarayanan et al., 2017) models for all tasks.
These sampling baselines require multiple forward passes for uncertainty estimation.
Further details are given in the appendix.
Datasets.
We split all datasets into train, validation and test sets.
For classiﬁcation, we use one tabular dataset (Sensorless Drive (Dua & Graff, 2017)) and three image datasets (MNIST (LeCun et al., 2010), FMNIST (Xiao et al., 2017) and CIFAR-10 (Krizhevsky et al., 2009)).
For count prediction, we use the Bike Sharing dataset (Fanaee-T & Gama, 2014) to predict the number of bike rentals within an hour.
For regression, we also use the Bike Sharing dataset where the target is viewed as continuous, real-world UCI datasets used in Amini et al.
(2020); Hernandez-Lobato & Adams (2015) and the image NYU Depth v2 dataset (Nathan Silberman & Fergus, 2012) where the goal is to predict the image depth per pixel.
All inputs are rescaled with zero mean and unit variance.
We also scale the output target for regression.
Further details are given in the appendix.
Metrics.
Beyond the target prediction error, we evaluate model uncertainty estimation using calibration and OOD detection scores.
Furthermore, we report the inference speed.
Further results including histograms with uncertainty estimates or latent space visualization are presented in appendix.
Target error:
We use the accuracy (Accuracy) for classiﬁcation and the Root Mean Squared
Error (RMSE) for regression and count prediction.
Calibration: For classiﬁcation, we use the Brier score (Brier)
(Gneiting & Raftery, 2007).
For regression and count prediction, we use the quantile calibration score (Calibration) (Kuleshov et al., 2018).
OOD detection: We evaluate how the uncertainty scores enable to detect OOD data using the area under the precision-recall curve (AUC-PR) the area under the receiver operating characteristic curve (AUC-ROC) in the appendix.
We use two different uncertainty measures: the negative entropy of the predicted target distribution accounting for the aleatoric uncertainty (Alea.
OOD) and the predicted evidence or variance of the predicted mean (Epist.
OOD).
Similarly to (Charpentier et al., 2020; Ovadia et al., 2019), we use four different types of clear OOD samples: Unseen datasets (KMNIST Clanuwat et al.
, Fashion-MNIST (Xiao et al., 2017), SVHN (Netzer et al., 2011), LSUN (Yu et al., 2015), CelebA (Liu et al., 2015),
KITTI (Geiger et al., 2013)), left-out data (classes 9/10 for Sensorless Drive, winter/spring/autumn seasons for Bike Sharing), out-of-domain data not normalized in [0 , 1] (OODom) and dataset shifts (corrupted CIFAR-10 (Hendrycks & Dietterich, 2019)).
Further details are given in the appendix.
4. R ESULTS
Classiﬁcation.
We show results for the tabular dataset Sensorless Drive with unbounded input domain in Tab. 2, and the image datasets MNIST, FMNIST and CIFAR-10 with bounded input domain in with best single-
(i.e. 12 / 30 top-1 scores, 25 / 30 top-2 scores) and NatPE performs the best among multiple-pass models (i.e. 28 / 30 top-1 scores).
A single NatPN achieves accuracy and calibration performance on par with the most calibrated baselines, namely PostNet and R-PriorNet which requires one normalizing ﬂow per class or training OOD data.
Further, NatPE consistently improves accuracy and calibration performance of a single NatPN which underlines the beneﬁt of aggregating multiple models predictions for accuracy and calibration (Lakshminarayanan et al., 2017).
Without requiring
OOD data during training, both NatPN and NatPE achieve excellent OOD detection scores w.r.t.
all
OOD types.
This strongly suggests that NatPN does not suffer from the ﬂaws in Choi et al.
Nalisnick et al.
In particular, NatPN and NatPE achieve almost perfect OODom scores contrary to all other baselines except PostNet.
This observation aligns well with the theoretical guarantee of NatPN far from training data (see Thm. 1) which also applies to each NatPE member.
The similar performance of NatPN and PostNet for classiﬁcation is intuitively explained by their akin design: both models perform density estimation on a low-dimensional latent space.
Similarly to
Charpentier et al.
, we compute the average conﬁdence avg-conf = 1 N (cid:80) [Equation] n [Equation]
=
[Equation]
N (cid:80) Ni
[Equation]
i )and then compare the average conﬁdence change.
The average conﬁdence change is computed by taking the ratio of the average conﬁdence of N corrupted data at severity s and the average conﬁdence of N clean data (i.e. the corrupted data at severity 0 ) i.e. avg-conf s avg-conf 0 for s ∈ [[1 , 5]] .
NatPN maintains a competitive accuracy (Fig. 3, left) while assigning higher epistemic uncertainty as desired (Fig. 3, right).
Baselines provide a slower relative conﬁdence decay.
Regression & Count Prediction.
We show the results for the Bike Sharing, the tabular UCI datasets and the image NYU Depth v2 datasets in Tab. 4, 5, 6.
For the large NYU dataset, we compare against all baselines which require only a single model to be trained.
Overall, NatPN outperforms other single-pass models for 23 / 26 scores for regression, thus signiﬁcantly improving calibration and OOD detection scores.
Further, NatPN shows a strong improvement for calibration and OOD detection for count prediction with Poisson distributions among all models.
Interestingly, all the models are less calibrated on the Bike Sharing dataset using a target Poisson distribution rather than a target Normal distribution.
This suggests a mismatch of the Poisson distribution for this particular task.
The almost perfect OODom scores of NatPN validate again Thm. 1 which also holds for regression.
[Table]
Inference Speed.
We show the average inference time per batch for all models on CIFAR-10 for classiﬁcation and the NYU Depth v2 dataset for regression in Tab. 7.
NatPN shows a signiﬁcant improvement over Dropout and Ensemble which are both approximately ﬁve times slower since they require ﬁve forward passes for prediction.
Notably, the NatPN speedup does not deteriorate target error and uncertainty scores.
NatPN is slightly slower than RPriorNet, EnD 2 and EvReg as they do not evaluate an additional normalizing ﬂow.
However, NatPN – which uses a single normalizing ﬂow – is faster than
PostNet – which scales linearly w.r.t.
the number of classes since it evaluates one normalizing ﬂow per class.
Lastly, NatPN is the only single-pass model that can be used for both tasks.
C ONCLUSION
We introduce Natural Posterior Network which belongs to the family of models parametrizing conjugate prior distributions.
NatPN is capable of efﬁcient uncertainty estimation for any task where the target distribution is in the exponential family (incl.
classiﬁcation, regression and count prediction).
NatPN relies on the Bayes formula and the general form of exponential family distributions to perform a closed-form input-dependent posterior update over the target distribution.
Further, an ensemble of
NatPNs has a principled Bayesian combination interpretation.
Theoretically, NatPN guarantees high uncertainty far from training data.
Experimentally, NatPN achieves fast, versatile and high-quality uncertainty predictions with strong performance in calibration and OOD detection.
E THICS S TATEMENT
Accurate uncertainty estimation aims at improving trust in safety-critical domains subject to automation, and in a maintenance context where the underlying data distribution might slowly shift over time.
In this regard, NatPN signiﬁcantly improves the applicability of uncertainty estimation across a wide range of prediction domains (e.g. classiﬁcation, regression, count prediction, etc) while maintaining a fast inference time.
This could be particularly beneﬁcial in industrial applications with time pressure and potential critical consequences (e.g. ﬁnance, medicine, policy decision making, etc).
Nonetheless, while NatPN achieves high-quality uncertainty estimation, there is always a risk that
NatPN does not fully capture the real-world complexity e.g. for OOD data close to ID data.
Furthermore, we raise awareness about two other risks of excessive trust related to the Dunning-Kruger effect (Kruger & Dunning, 2000): human excessive trust in Machine Learning model capacity, and human excessive trust in its own interpretation capacity.
Therefore, we encourage practitioners to proactively confront the model design and its uncertainty estimates to desired behaviors in real-world use cases.
R EPRODUCIBILITY S TATEMENT
We provide all datasets and the model code at the following project page 1 .
In App.
F, we give a detailed description for each dataset used in this paper.
This description includes the task description, the dataset size, the input/output dimensions, the input/output preprossessing and the train/validation/test splits used in the experiments.
In App.
G, we give a detailed description for the architecture and grid search performed for each model used in this paper.
Speciﬁcally, we provide an hyper-parameter study for NatPN in App.
I.6,
In App.
H, we give a detailed description of the metrics used in the experiments.
Finally, we provide a complete proof of Thm. 1, a detailed description of the Bayesian loss and relevant formulae for exponential family distributions in App.
A, App. B and App.
C.
A T HEOREM
We prove theorem 1 based on Lemmas 2 and 3.
Lemma 2 states that the input space can be divided in a ﬁnite number of linear regions (Arora et al., 2018).
Lemma 3 states that a probability density with bounded derivatives has to converge to 0 at inﬁnity (Dix, 2013).
We additionally recall Lemmawhich provide a similar convergence guarantee without the bounded derivative constraint (Niculescu & Popovici, 2011).
Finally, Lemma 5 particularly shows that the guarantee of theorem 1 can be obtained with Gaussian Mixtures which are commonly used for density estimation or radial ﬂows which are used in the experiments.
Lemma 2.
(Arora et al., 2018) Let { Q l } Rl be the set of linear regions associated to the piecewise
ReLU network f φ ( x ) .
For any x ∈ R D , there exists δ ∗ ∈ R + and l ∗ ∈ 1 , ..., R such that δ x ∈ Q l ∗ for all δ > δ ∗ .
Lemma 3.
(Dix, 2013) Let
p ∈
L 1 (0 , ∞ ) with bounded ﬁrst derivative p (cid:48) , then p ( δ ) →
δ →∞ 0 .
This convergence is stronger than in Lem.
4 as the limit is not in density but with standard limit notation.
Lemma 4.
(Niculescu & Popovici, 2011) Let p ∈
L 1 (0 , ∞ ) , then p ( δ ) → δ →∞ 0 in density.
This means that the sets where p ( t ) is far from its 0 limit (i.e. { t ≥ 0 : | p ( t ) | ≥ (cid:15) } with (cid:15) > 0 ) has zero density.
Lemma 5.
Let P ( z | ω ) be parametrized with a Gaussian Mixture Model (GMM) or a radial ﬂow, then P ( z | ω ) → || z ||→∞ 0 .
Proof.
We prove now lem.
5 for GMM and radial ﬂow.
The proof is straightforward for the GMM parametrization since every Gaussian component of the mixture has 0 limit when || z || → ∞ .
Let denote now p 1 ( z )
=
P ( z | ω ) be parametrized with a radial ﬂow transformation g ( z ) and a base unit Gaussian distribution p 0 i.e.:
[Equation]
Further, we can express the transformation g ( z ) and its determinant det ∂g ( z ) ∂ z as follows:
[Equation]
where h ( α, r ) = 1 α + r and r = ||
z − z 0 || .
On one hand, we have || g ( z ) ||
→ + ∞ when || z || → ∞ since || βh ( α, r )( z − z 0 )
|| <
β .
Thus, the base Gaussian density p 0 ( g ( z ))
→ 0 when || z || → ∞ .
On the other hand, we have | det ∂g ( z ) ∂ z | → 1 since βh ( α, r ) → 0 and βh (cid:48)
( α, r ) r
→ 0 when || z || → ∞ .
Therefore, the transformed density p 0 ( g ( z ))
×| det ∂g ( z ) ∂ z | → 0 when || z || → ∞ which ends the proof.
Note that this proof can be extended to stacked radial ﬂows by induction.
Theorem.
Let a NatPN model parametrized with a (deep) encoder f φ with piecewise ReLU activations, a decoder g ψ and the density P ( z | ω ) .
Let f φ ( x ) =
V ( l ) x
+ a ( l ) be the piecewise afﬁne representation of the ReLU network f φ on the ﬁnite number of afﬁne regions Q ( l ) (Arora et al., 2018).
Suppose that V ( l ) have independent rows and the density function P ( z | ω ) has bounded derivatives, then for almost any x we have P ( f φ ( δ · x ) | ω )
→ δ →∞ 0 .
i.e the evidence becomes small far from training data.
Proof.
We prove now thm.
Let x ∈ R D be a non-zero input and f φ be a ReLU network.
Lem.implies that there exists δ ∗ ∈ R + and l ∈ { 1 , ..., R } such that δ · x ∈ Q ( l ) for all δ > δ ∗ .
Thus, z δ = f φ ( δ · x ) =
δ · ( V ( l ) x ) + a ( l ) for all δ > δ ∗ .
Note that for δ ∈ [ δ ∗ , + ∞ ] , z δ follows an afﬁne half line S x
= { z | z
=
δ · ( V ( l ) x ) + a ( l ) , δ > δ ∗ } in the latent space.
Further, note that V ( l ) x (cid:54) =
and ||
z
δ ||
→ δ →∞ + ∞ since x (cid:54) = 0 and V ( l ) has independent rows.
We now deﬁne the function p ( δ ) =
P ( z δ | ω ) which is the density function P ( z | ω ) restricted on the afﬁne half line S x .
Since P ( z | ω ) is a normalized probability density, then the function δ (cid:55)→ p ( δ − δ ∗ ) is integrable on [0 , + ∞ ] .
Indeed we have:
[Equation]
Further since the function P ( z | ω ) has bounded derivatives, we can apply Lem.
3 to the function δ (cid:55)→ p ( δ − δ ∗ ) to get the expected result i.e.
[Equation]
which ends the proof.
Alternatively a slightly weaker conclusion also holds if the density function does not have bounded derivatives using lem.
4 (instead of lem. 3) with the notion of limit in density.
The stronger conclusion is valid if we parametrize P ( z | ω ) with a Gaussian Mixture Model or a radial ﬂow density according to lem.
5 since ||
z δ ||
→ δ →∞ + ∞ .
Further, we provide additional comments on the assumption that a trained network converges to linear transformation with exactly two or more dependent rows in Thm. 1.
Under this realistic condition
Hein et al.
(2019), the null space is reduced to 0 according to the rank-nullity theorem meaning that there should be no dead input feature/pixel.
If this condition does not hold, this would mean that this speciﬁc input feature/pixel is not informative for the prediction task.
Thus it could be desired in practice that it does not affect the uncertainty on the prediction.
This latter aspect is discussed in the “Task-Speciﬁc OOD” paragraph in Sec. 3.6.
B B AYESIAN L OSS
NatPN minimizes the following Bayesian formulation:
[Equation]
where H [ Q post , ( i ) ] denotes the entropy of the predicted posterior distribution Q post , ( i ) .
This loss is generally not equal to the ELBO loss.
While the term (i) can be viewed as an ELBO loss without
KL regularization, the term (ii) is not necessarily equal to the prior KL regularization term in the
ELBO loss since a proper uniform prior might not exist (e.g. the target y is a real number).
Indeed, if the target y is a real number, there exists no uniform prior on θ and the Bayesian loss and ELBO loss are different i.e. KL ( Q || Q prior )
= (cid:82)
[Equation]
=
[Equation]
log
[Equation]
= H ( Q ) .
Nonetheless, when a uniform prior Q unif exists (e.g. the target y is a class), the loss optimization can be seen as an amortized variational optimization of an ELBO loss (Zhang et al., 2018)
i.e. L ( i ) =
− E Q post , ( i ) [log P ( y ( i ) | θ ( i ) )]
+ KL [ Q post , ( i ) (cid:107) Q unif ] where the predicted distribution
Q post , ( i ) is the variational distribution — which approximates the true posterior distribution.
Indeed, the KL regularization term is equal to the entropy regularization term i.e. KL ( Q || Q unif ) =
(cid:82)
Q ( θ ) log( Q ( θ ) Q unif ( θ ) dθ ) ∝ (cid:82) Q ( θ ) log Q ( θ ) dθ ) =
H ( Q ) .
Hence, the loss name “Bayesian loss” (Charpentier et al., 2020) is motivated by its difference with the ELBO loss and its Bayesian property at optimum.
C F ORMULAE FOR E XPONENTIAL F AMILY D ISTRIBUTIONS C. G ENERAL C ASE
Target Distribution.
An exponential family distribution on a target variable y ∈ R with natural parameters θ ∈ R L can be denoted as
[Equation]
where h : R → R is the carrier measure, A : R L → R the log-normalizer and u : R → R L the sufﬁcient statistics.
Conjugate Prior Distribution.
An exponential family distribution P always admits a conjugate prior:
[Equation]
where η : R L × R → R is a normalization factor and A the log-normalizer of the distribution P as in
Eq.
Posterior Predictive Distribution.
The posterior predictive distribution is given as (cid:82) P ( y [Equation] i [Equation]
| θ
[Equation]
Q
[Equation]
| χ post
[Equation]
( i
[Equation]
n post
[Equation]
( i )
[Equation]
d θ where the parameter θ is marginalized out (Gal, 2016).
This distribution can always be computed in closed form for exponential family distributions:
[Equation]
where h is the carrier measure deﬁned in Eq.
8 and η is the normalization factor deﬁned in Eq.
In particular, the posterior predictive distributions for Categorical, Normal and Poisson target distributions are Categorical, Student and Negative Binomial distributions, respectively.
Likelihood.
The log-likelihood of an exponential family distribution can be written as follows:
[Equation]
Expected Log-Likelihood.
Given the log-likelihood of an exponential family distribution, its expectation under the conjugate prior distribution Q ( θ | χ , n ) can be written as
[Equation]
θ )] [Equation] 12) where E Q ( θ | χ ,n ) [ θ ] =
χ (Brown, 1986; Diaconis & Ylvisaker, 1979).
Entropy.
The entropy of a random variable y ∼ P ( y | θ ) for an exponential family distribution P can be written as follows (Nielsen & Nock, 2010):
[Equation]
C. C ATEGORICAL & D IRICHLET D ISTRIBUTIONS
The Dirichlet distribution p ∼ Dir( α ) is the conjugate prior of the categorical distributions y ∼
Cat( p ) .
Target Distribution.
The density and the entropy of the categorical distribution are:
[Equation]
Conjugate Prior Distribution.
The density and the entropy of the Dirichlet distribution are:
[Equation]
where ψ ( α ) and B ( α ) denote Digamma and Beta functions, respectively, and α 0 = (cid:80)
c α c .
Expected Log-Likelihood.
The expected likelihood of the categorical distribution Cat( p ) under the
Dirichlet distribution Dir( α ) is
[Equation]
(18) where ψ ( α ) denotes Digamma function.
C. N ORMAL & N ORMAL -I NVERSE -G AMMA D ISTRIBUTIONS
The Normal-Inverse-Gamma (NIG) distribution µ, σ ∼ N Γ -1 ( µ 0 , λ, α, β ) is the conjugate prior of the normal distribution y ∼ N ( µ, σ ) .
Note that as both parameters λ and α can be viewed as pseudocounts.
However, the natural prior parametrization enforces a single pseudo-count n corresponding to λ
= 2 α .
Target Distribution.
The density and the entropy of the Normal distribution are:
[Equation]
Conjugate Prior Distribution.
The density and the entropy of the NIG distribution are:
[Equation]
where Γ( α ) denotes the Gamma function.
Expected Log-Likelihood.
The expected likelihood of the Normal distribution N ( µ, σ ) under the
NIG distribution N Γ -1 ( µ 0 , λ, α, β ) is:
[Equation]
where ψ ( α ) denotes the Digamma function.
We used here the moments of the NIG distribution
E (cid:2) µσ [Equation]
=
[Equation] [Equation]
=
[Equation]
β + 1 λ
[Equation]
and the moment of the inverse Gamma distribution
E (cid:2) log
[Equation]
C. P OISSON & G AMMA D ISTRIBUTIONS
The Gamma distribution λ ∼ Γ( α, β ) is the conjugate prior of the Poisson distributions
y ∼ Poi
( λ ) .
Target Distribution.
The density and the entropy of the Poisson distribution are:
[Equation]
Conjugate Prior Distribution.
The density and the entropy of the Gamma distribution are:
[Equation]
where Γ( α ) denotes the Gamma function.
Expected Log-Likelihood.
The expected likelihood of the Poisson distribution Poi( λ ) under the
Gamma distribution Γ( α, β ) is
[Equation]
where ψ ( α ) denotes Digamma function.
We used here the moments the Gamma distributions E [log λ ]
= ψ ( α ) − log β and E [ λ ] = αβ .
Note that (cid:80) yk =1 log k is constant w.r.t.
parameters α, β .
D A PPROXIMATION OF E NTROPIES
The computation of a distribution’s entropy often requires subtracting huge numbers from each other.
While these numbers tend to be very close together, this introduces numerical challenges.
For large parameter values, we therefore approximate the entropy by substituting numerically unstable terms and simplifying the resulting formula.
For this procedure, we make use of the following equivalences (taken from Rocktäschel (1922) and Whittaker & Watson (1927), respectively):
[Equation]
We note that Eq.
35 especially implies ψ ( x ) ≈ log x and x ψ ( x ) ≈ x log x − 12 for large x .
D. D IRICHLET D ISTRIBUTION
We consider a Dirichlet distribution Dir( α ) of order K with α
= (cid:80)
Ki
=1 α i .
For α 0 ≥ 10 4 , we use the following approximation:
[Equation]
D. N ORMAL -I NVERSE -G AMMA D ISTRIBUTION
We consider a Normal-Inverse-Gamma distribution N Γ -1 ( µ, λ, α, β ) .
For α ≥ 10 4 , we use the following approximation:
[Equation]
D. G AMMA D ISTRIBUTION
We consider a Gamma distribution Γ( α, β ) .
For α ≥ 10 4 , we use the following approximation:
[Equation] [Equation]
E F ORMULAE FOR U NCERTAINTY E STIMATES
Aleatoric Uncertainty.
The entropy of the target distribution P ( y | θ ) was used to estimate the aleatoric uncertainty i.e. H
[ P ( y | θ )] .
Epistemic Uncertainty.
The evidence parameter n post , ( i ) was used to estimate the epistemic uncertainty.
Due to its interpretation as a pseudo-count of observed labels, the posterior evidence parameter is indeed a natural indicator for the epistemic uncertainty.
Predictive Uncertainty.
The entropy of the posterior distribution Q ( θ | χ post , ( i ) , n post , ( i ) ) was used to estimate the predictive uncertainty.
F D ATASET D ETAILS
We use a train/validation/test split in all experiments.
For datasets with a dedicated test split, we split the rest of the data into training and validation sets of size 80%/20%.
For all other datasets, we used 70%/15%/15% for the train/validation/test sets.
All inputs are rescaled with zero mean and unit variance.
Similarly, we also scale the output target for regression.
We provide the datasets at the project page 2 .
Sensorless Drive (Dua & Graff, 2017)
This is a tabular dataset where the goal is to classify extracted motor current measurements into 11 different classes.
We remove the last two classes (9 and 10) from training and use them as the OOD dataset for OOD detection experiments.
Each input is composed of 48 attributes describing motor behavior.
The dataset contains 58 , 509 samples in total.
MNIST (LeCun et al., 2010) & Fashion-MNIST (Xiao et al., 2017)
These are image dataset where the goal is to classify pictures of hand-drawn digits into 10 classes (from digit 0 to digit 9 ) or classify pictures of clothers.
Each input is composed of a 1 × 28 × 28 tensor.
The dataset contains 70 ,samples.
For OOD detection experiments againt MNIST data, we use KMNIST (Clanuwat et al., 2018) and Fashion-MNIST (Xiao et al., 2017) containing images of Japanese characters and images of clothes, respectively.
For OOD detection experiments againt Fasgion-MNIST data, we use KMNIST (Clanuwat et al., 2018) and MNIST (LeCun et al., 2010) containing images of Japanese characters and images of digits, respectively.
It uses the MIT License (MIT).
CIFAR-10 (Krizhevsky et al., 2009)
This is an image dataset where the goal is to classify a picture of objects into 10 classes (airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck).
Each input is a 3 × 32 × 32 tensor.
The dataset contains 60 , 000 samples.
For OOD detection experiments, we use street view house numbers (SVHN)
(Netzer et al., 2011) containing images of numbers and
CelebA (Liu et al., 2015) containing images of celebrity faces.
We do not use CIFAR100 (Krizhevsky et al., 2009) or TinyImageNet (Fei-Fei Li & Johnson, 2017) as OOD as they also contain images of vehicles and animals similar to CIFAR10.
This rightly questions to what extent are these datasets really OOD for CIFAR10.
Furthermore, we generate the corrupted CIFAR-10 dataset (Hendrycks &
Dietterich, 2019) with 15 corruption types per image, each with 5 different severities.
It uses the MIT
License (MIT).
Bike Sharing (Fanaee-T & Gama, 2014)
This is a tabular dataset where the goal is to predict the total number of rentals within an hour.
Each input is composed of 15 attributes.
We removed features related to the year period (i.e. record index, date, season, months) which would make OOD detection trivial, leading to 11 attributes.
The dataset contains 17 , 389 samples in total.
For OOD detection, we removed the attribute season from the input data and only trained on the summer season.
The samples related to winter, spring and autumn were used as OOD datasets.
Concrete (Dua & Graff, 2017)
This is a tabular dataset where the goal is to predict the compressive strength of high-performance concrete.
Each input is composed of 8 attributes.
The dataset contains 1 , 030 samples in total.
For OOD detection, we use the Energy and Kin8nm datasets which have the same input size.
Kin8nm (Dua & Graff, 2017)
This is a tabular dataset where the goal is to predict the forward kinematics of an 8-link robot arm.
Each input is composed of 8 attributes.
The dataset contains 8 ,samples in total.
For OOD detection, we the Concrete and Energy datasets which have the same input size.
NYU Depth v2 (Nathan Silberman & Fergus, 2012)
This is an image dataset where the goal is to predict the depth of room images at each pixel position.
All inputs are of shape 3x640x480 tensors while we rescale outputs to be 320x240 tensors at both training and test time.
This setting is slightly different from Kendall & Gal (2017) and Nathan Silberman & Fergus (2012).
Indeed, (Kendall & Gal, 2017) up-scales the model output to 640x480 at training and test time while (Nathan Silberman &
Fergus, 2012) up-scales the model output to 640x480 at test time only.
The dataset contains 50 , samples total on DenseDepth
OOD detection, we use the KITTI (Geiger et al., 2013)
dataset containing images of driving cars and two out of the 20 categories from the
LSUN (Yu et al., 2015) dataset.
G M ODEL D ETAILS
We train all models using 5 seeds except for the large NYU dataset where we use a single randomly selected seed.
All models are optimized with the Adam optimizer without further learning rate scheduling.
We perform early stopping by checking loss improvement every epoch and a patience p selected per dataset (Sensorless Drive: p = 15 , MNIST: p = 15 , CIFAR10: p = 20 , Bike Sharing: p = 50 , Concrete: p = 50 , Kin8nm: p = 30 , NYU Depth v2: p = 2 ).
We train all models on a single GPU (NVIDIA GTX 1080 Ti or NVIDIA GTX 2080 Ti, 11 GB memory).
All models are trained after a grid search for the learning rate in [1 e − 2 , 5 e − 4 ] .
The backbone architecture is shared across models and selected per dataset to match the task needs (Sensorless Drive: 3 lin.
layers with 64 hidden dim, MNIST: 6 conv.
layers with 32/32/32/64/64/64 ﬁlters + 3 lin.
layers with hidden dim 1024/128/64, CIFAR10: 8 conv.
layers with 32/32/32/64/64/128/128/128 ﬁlters + 3 lin.
layers with hidden dim 1024/128/64, Bike Sharing: 3 lin.
layers with 16/16/16 hidden dim, Concrete: 2 lin.
layers with 16/16 hidden dim, Kin8nm: 2 lin.
layers with 16/16 hidden dim, NYU Depth v2: DenseDepth + 4 upsampling layers with convolutions and skip connections).
For the NYU Depth v2 dataset, we use a pretrained DenseNet for initialization of the backbone architecture which was ﬁne-tuned during training.
The remaining layers are trained from scratch.
All architectures use LeakyReLU activations.
For further details, we provide the code at the project page 4 .
Baselines.
For the dropout models, we use the best drop out rate p drop per dataset after a grid search in { 0 . 1 , 0 . 25 , 0 . 4 } and sample 5 times for uncertainty estimation.
Similarly, we use m = 5 for the ensemble baseline and the distribution distillation.
Note that Ovadia et al.
(2019) found that a relative small ensemble size (e.g. m = 5 ) may indeed be sufﬁcient in practice.
We also train Prior Networks where we set β in = 1 e 2 as suggested in the original papers (Malinin & Gales, 2018; 2019).
Prior
Networks use Fashion-MNIST and SVHN as training OOD datasets for MNIST and CIFAR-10, respectively.
As there is no available OOD dataset for the Sensorless Drive dataset, we use Gaussian noise as training OOD data.
Natural Posterior Network.
We perform a grid search for the entropy regularizer λ in the range [1 e − 5 , 0] , for the latent dimension H in { 4 , 8 , 16 , 32 } , for the certainty budget N H in { e 12 H , e H , e log( √ 4 π ) H } , and for normalizing ﬂow type between radial ﬂows (Rezende & Mohamed, 2015) with 8 , 16 layers and Masked Autoregressive ﬂows (Germain et al., 2015; Papamakarios et al., 2017) with 4 , 8 , 16 layers.
Further results on latent dimensions, density types, number of normalizing ﬂow layers and certainty budget are presented in Sec.
I.6.
We use “warm-up” training for the normalizing ﬂows for all datasets except for the simple Concrete and Kin8nm datasets, and the NYU
Depth v2 dataset which starts from a pretrained encoder.
We use “ﬁne-tuning” for the normalizing ﬂows for all datasets except for the simple Concrete and Kin8nm datasets.
As prior parameters, we set χ prior = 1 C /C, n prior =
C for classiﬁcation, χ prior =
(0 , 100) T , n prior = 1 for regression and χ prior = 1 , n prior = 1 for count prediction.
Note that the mean of these prior distributions correspond to an equiprobable Categorical distribution Cat( 1 C /C ) , a Normal distribution with large variance
N (0 , 10) and a Poisson distribution with a unitary mean Poi(1) .
Those prior target distributions represent the safe default prediction when no evidence is predicted.
H E XPERIMENT D ETAILS
Target Error Metric.
For classiﬁcation, we use the standard accuracy 1 N (cid:80) i I
[ y ∗ , ( i ) =
y ( i ) ] where y ∗ , ( i ) is the one-hot true label and y ( i ) is the one-hot predicted label.
For regression, we use the standard Root Mean Square Error (cid:113) 1 N (cid:80) N i ( y ∗ , ( i ) − y ( i ) ) 2 .
Calibration Metric.
For classiﬁcation, we use the Brier score which is computed as 1 C (cid:80)
Ni
|| p
( i ) − y
( i )
||
2 where p ( i ) is the predicted softmax probability and y ( i ) is the one-hot encoded ground-truth label.
For regression and count prediction, we use the absolute difference between the percentile p and the percentage of target lying in the conﬁdence interval I p =
[0 , p 2 ] ∪ [1 − p 2 , 1] under the predicted target distribution.
Formally, we compute p pred = 1 N (cid:80) i
I
[ F θ ( i ) ( y ∗ , ( i ) ))
∈
I p ] where
F θ ( i ) ( y ∗ , ( i ) )
=
P ( y ≤ y ∗ , ( i ) | θ ( i ) ) is the cumulative function of the predicted target distribution evaluated at the true target.
For example, the percentile p = 0 .
1 would be compared to p pred =
N (cid:80) i
I [ F θ ( i ) ( y ∗ , ( i ) )) ∈
[0 , 0 . 05] ∪ [0 .
95 , 1]] which should be close to 0 .
10 for calibrated predictions.
We compute a single calibration score by summing the square difference for p ∈ { 0 . 1 , . . .
9 } i.e. (cid:113)(cid:80) p ( p − p pred ) 2 (Kuleshov et al., 2018).
OOD Metric.
The OOD detection task can be evaluated as a binary classiﬁcation.
Hence, we assign class 1 to ID data and class 0 to OOD data task and use the aleatoric and epistemic uncertainty estimates as scores for OOD data.
It enables to compute ﬁnal scores using the area under the precision-recall curve (AUC-PR) and the area under the receiver operating characteristic curve (AUC-ROC).
Both metrics have been scaled by 100 .
We obtain numbers in [0 , 100] for all scores instead of [0 , 1] .
Results for AUC-ROC are reported in Sec.
I.7.
For the aleatoric uncertainty, we use the negative entropy of the predicted target distribution.
For the epistemic uncertainty, we use the predicted evidence for models parametrizing conjugate-prior, or the variance of the predicted winning probability class for classiﬁcation and the variance of the mean for regression and class count prediction for ensemble or dropout.
Inference Time Metric.
We measure inference time of models in ms and used NVIDIA GTX
Ti GPUs.
We evaluate the inference for one classiﬁcation dataset (CIFAR-10) and one regression dataset (NYU Depth v2).
For evaluation, we use a randomly initialized model and simply push random data through the model with batch size of 4,096 CIFAR10 and batch size of 4 for NYU
Depth v2.
The ﬁnal numbers are averaged over 100 batches excluding the ﬁrst batch due to GPU initialization.
Compared models shared the same backbone architecture.
I A DDITIONAL E XPERIMENTS I. MNIST, F ASHION MNIST, CIFAR10 AND B IKE S HARING RESULTS
[Table]
[Table] [Table]
[Table]
I. U NCERTAINTY V ISUALIZATION ON T OY D ATASETS
We visualize the aleatoric and the epistemic uncertainty for two toy datasets with three classes with the same number of training examples for the three classes (see Fig. 4) and different number of training examples for the three classes (see Fig. 5).
The predictions are more aleatorically certain close to training samples.
The preidctions are more epistemically uncertain close to fewer training examples and very epistemically
I. L ATENT S PACE V ISUALIZATIONS
We propose additional visualizations of the latent space for MNIST with t-SNE (Chan et al., 2019) with different perplexities (see Fig. 6).
For all perplexities, we clearly observe ten green clusters corresponding to the ten classes for MNIST.
The KNMIST (OOD) samples in red can easily be separated from the MNIST (ID) samples in green.
As desired, NatPN assigns higher log-probabilities used in evidence computation to ID samples from MNIST.
I. H ISTOGRAM OF U NCERTAINTY E STIMATES
We visualize the histogram distribution of the entropy of the posterior distribution accounting for predictive uncertainty for ID (MNIST/NYU) and OOD (KNMIST and Fashion-MNIST/LSUN classroom and LSUN church + KITTI) (see Fig. 7).
We clearly observe lower predictive entropy for
ID data than for OOD data for both MNIST and NYU datasets.
On one hand, the entropy clearly differentiates between ID data (MNIST) and any other OOD datasets (KMNIST, Fashion MNIST,
OODom) for classiﬁcation.
We intuitively explain this clear distinction since the samples from the
OOD datasets are irrelevant for the digit classiﬁcation task.
On the other hand, the entropy is still a good indicator of ID (NYU) and OOD datasets (LSUN classroom and LSUN church + KITTI) for regression although the distinction between ID and OOD datasets is less strong compared to
MNIST.
We intuitively explain this behavior since the task of depth estimation is still relevant to
LSUN classroom and LSUN church + KITTI.
on MNIST (ID) vs KMNIST, Fashion-MNIST, Out-Of-Domain (OOD) and NYU (ID) vs LSUN classroom and LSUN church + KITTI (OOD).
In both cases, low entropy is a good indicator of in-distribution data.
[Figure]
I. U NCERTAINTY V ISUALIZATION ON NYU D EPTH V 2 D ATASET
We visualize the prediction and the predictive uncertainty per pixel for the NYU Depth v2 dataset (see Fig.
We observe accurate target predictions compared to the ground truth depth of the images.
Further NatPN assigns higher uncertainty for pixels close to object edges, which is reasonable since the depth abruptly change at these locations.
[Figure]
I. H YPER -P ARAMETER S TUDY
As a ablation study, we also report the results of the grid search on the latent dimension, normalizing ﬂow types and number of normalizing ﬂow layers for MNIST, CIFAR-10 and Bike Sharing datasets in Tab. 12, 13, 14, 15.
While most models converge to fairly good uncertainty estimates, we notice that 16 layers of simple radial ﬂows on latent spaces of 16 dimensions were achieving very good results in practice.
Changing the ﬂow type or the number of normalizing ﬂow layers does not lead to strong variations of the results except for Bike sharing with Poisson target distributions.
In this case, more complex MAF normalizing ﬂows improve NatPN performance.
The latent dimension appears to be a more important choice for the model convergence.
As an example, a higher latent dimension of 16 or 32 leads to signiﬁcantly better performances than a latent dimension of 4 on MNIST, CIFAR10 and Bike Sharing datasets.
We hypothesize that too low latent dimensions are less able to encode the necessary information for the prediction task, leading to worse target errors.
Further, we compare three different variants of the certainty budget N H used in the evidence computation n ( i ) =
N H P ( z ( i ) | ω ) : a constant unit budget (i.e. N H = 1 (I)) corresponding to a ﬁxed budget regardless of the number of training data and the latent dimension, a budget equals to the number of training data (i.e. N H = N (II)) similarly to Charpentier et al.
(2020), or a budget which scales exponentially with the number of latent dimensions (e.g. N H equal to e 12 H (III), e H (IV) or e log( √ 4 π )
H (V)).
We observe that scaling the budget w.r.t.
the latent space dimension ( H -budget) is more stable in practice than constant budget ( 1 -budget) and budget related to the number of training data ( N -budget)
(see.
Tab. 12,13,14,15).
In aprticular, the H -budgets achieve more better results on higher latent dimensions and performance on par with the other certainty budget scheme otherwise.
The intuition is that due to the curse of dimensionality, the expected value of a probability density function
E z
[ P ( z )] tends to decrease exponentially fast.
For example, we have E z [ P ( z )]
= 1 ( √ 4 π ) H when z ∼ N ( 0 , 1 ) in a H -dimensional space.
Increasing the certainty budget N H exponentially w.r.t.
to the dimension H avoids numerical issues by allocating close to 0 evidence to latent representations.
In our experiments, we use a grid search in different exponential scaling N H equal to e 12 H (III), e H (IV), e log( √ 4 π ) H (V).
I. OOD D ETECTION WITH AUC-ROC S CORES
In addition to the AUC-APR scores, we report the OOD detection results for MNIST, CIFAR10 and
Bike Sharing datasets in Tab. 16, 17, 18 with AUC-ROC scores.
Similarly as with AUC-APR scores,
NatPN and NatPE achieve very competitive performances compare to the baselines.
It particular, they outperform all baselines to detect challenging OODom data.
[Table]
[Table] [Table]
[Table] [Table]
[Table] [Table]