A CCELERATING M ONTE C ARLO B AYESIAN P REDICTION VIA A PPROXIMATING P REDICTIVE U NCERTAINTY OVER THE S IMPLEX
Anonymous authors
Paper under double-blind review
A
BSTRACT
Estimating the predictive uncertainty of a Bayesian learning model is critical in various decision-making problems, e.g., reinforcement learning, detecting adversarial attack, self-driving car.
As the model posterior is almost always intractable, most efforts were made on ﬁnding an accurate approximation the true posterior.
Even though a decent estimation of the model posterior is obtained, another approximation is required to compute the predictive distribution over the desired output.
A common accurate solution is to use Monte Carlo (MC) integration.
However, it needs to maintain a large number of samples, evaluate the model repeatedly and average multiple model outputs.
In many real-world cases, this is computationally prohibitive.
In this work, assuming that the exact posterior or a decent approximation is obtained, we propose a generic framework to approximate the output probability distribution induced by model posterior with a parameterized model and in an amortized fashion.
The aim is to approximate the true uncertainty of a speciﬁc Bayesian model, meanwhile alleviating the heavy workload of MC integration at testing time.
The proposed method is universally applicable to Bayesian classiﬁcation models that allow for posterior sampling.
Theoretically, we show that the idea of amortization incurs no additional costs on approximation performance.
Empirical results validate the strong practical performance of our approach.
I NTRODUCTION
Bayesian inference is a principled method to estimate the uncertainty of probabilistic models.
In most applications, especially in deep learning, the likelihood model and model prior are not conjugate hence marginalizing over model prior or posterior cannot be performed analytically, which hinders the practical applicability.
For tractability, a simple point estimate such as maximum a posteriori (MAP) estimate could be used to approximate the full model posterior.
The price paid is the loss of model uncertainty due to incomplete characterization of the model posterior.
Approximate inference methods, such as Markov chain Monte Carlo and variational inference, enhance the approximate posterior by a better probability distribution while keeping inference tractability.
However, even though a decent approximation of posterior can be obtained, computation of predictive distribution is usually intractable due to loss of conjugacy, and is of high cost if tractable.
To introduce the problem, we consider a Bayesian classiﬁcation model trained on dataset D
= { ( y n , x n ) } Nn =1 , where x n ∈ X and y n ∈ Y are the n th input and output, respectively.
Let the model posterior p ( θ |D ) be approximated by MC estimate 1 S (cid:80) Ss =1 δ ( θ − θ s ) , and the predictive distribution (a categorical distribution parameterized by the predicted class probabilities ) is thus approximated by
[Equation]
The predictive distribution can be accurately estimated as S → ∞ .
However, to perform the computation, we need to maintain a large number of samples, repeatedly evaluate the model for S times and ﬁnally average the model outputs.
This problem is critical in many real-world cases.
For example, assisted-driving car system requires an accurate measure of uncertainty to avoid making mistakes with a high conﬁdence (Kendall & Gal, 2017; Sünderhauf et al., 2018).
Due to the limited computational resources and storage in such system, it’s hard to maintain a large number of samples and perform S times evaluation of the Bayes model for the real-time image data.
In this work, aiming at boosting the prediction speed while maintaining a rich characterization of the prediction, we propose to approximate the distribution of class probabilities over the simplex induced by the model posterior p ( θ |D ) , in an amortized fashion.
This naturally diverts the heavy-load MC integration process from testing period to approximation period.
Different from the previous work in
Bayesian knowledge distillation (Balan et al., 2015; Bulò et al., 2016) that only focuses on the output categorical distribution (a point on simplex), the induced distribution over simplex provides: 1) rich knowledge includes prediction conﬁdence for identifying out-of-domain (OOD) data (see empirical examples in Fig. 2); 2) the possibility to use more expressive distributions as the approximate model.
We term the Bayes classiﬁer as “Bayes teacher” and the approximate distribution as “student”, due to the analogy with teacher-student learning.
A Dirichlet distribution is used as the student due to its expressiveness, conjugacy to categorical distribution and its efﬁcient reparameterization for training.
We propose to explicitly disentangle the parameters of the student into a prediction model (PM) and concentration model (CM), which capture class probability and sharpness of Dirichlet respectively.
The CM output can directly be used as a measure for detecting OOD data.
We term our approximation method as One-Pass Uncertainty (OPU) as it simpliﬁes real-world evaluation of Bayesian models by computing the predictive distribution with only one model evaluation.
Note that, OPU allows choosing various types of student model (e.g., compressed neural network (Lin et al., 2017; Hubara et al., 2016; Han et al., 2015)) for further speedup on speciﬁc platforms with no extra design efforts.
As the amortized approximation of induced distributions is unexplored in the literature, we consider and compare several choices of probability distance measure: forward KL, earth-mover’s distance (EMD) and maximum mean discrepancy (MMD).
We theoretically analyze the performance gap incurred by the amortized approximation and show that, under MMD, besides model loss due to restriction of student distribution, the amortized approximation does not introduce additional loss.
Empirical evaluations show a signiﬁcant speedup ( ∼ 500 × ) of Bayes models.
The results on Bayes
NN show that OPU performs better in misclassiﬁcation detection and OOD detection than state-ofthe-art works in Bayesian knowledge distillation.
It can also be observed that explicit disentangling of mean and concentration helps improve the performance.
The comparisons of different probability measures validate the theoretical analysis.
We also conduct empirical evaluations and comparisons on Bayes logistic regression and Gaussian process, to show OPU is universally applicable to all
Bayesian classiﬁcation models.
O NE -P ASS U NCERTAINTY F RAMEWORK 2. I NDUCED D ISTRIBUTION OVER S IMPLEX
In this section we present our OPU framework for a generic Bayesian parametric classiﬁer, e.g.
Bayesian logistic regression (BLR) or Bayesian neural networks (NN).
Let the Bayesian classiﬁer be speciﬁed with categorical likelihood and a parametric function, i.e.,
[Equation]
and a prior distribution p ( θ ) be speciﬁed over the parameter space Θ , where T :
X × Θ → S K − 1 is a parametric function from input space to simplex, e.g., a neural network with softmax output layer, and K is the number of classes.
In this paper, we assume the posterior p ( θ |D ) is obtained and focus on the computation of the predictive distribution.
In what follows, let p ( θ |D ) be approximate or exact (if available) model posterior, from which samples could be obtained.
From a dual perspective, with a ﬁxed input x , the mapping T x = T ( x ; · ) is also understood as a data-dependent mapping
T x : Θ → S K − 1 , which could be used to transform the posterior p ( θ |D ) to a conditional distribution (on x ) over the simplex.
That is, for each x , we can deﬁne a random variable π
= T x ( θ ) whose distribution is induced by θ ∼ p ( θ |D ) and T x .
This is effectively a well- deﬁned push-forward measure
T x # p ( θ |D ) over the simplex (see Fig. 1).
We term the conditional distribution of π | x , D as an “induced distribution” and deﬁne p x ( π ) =
p ( π | x , D ) to keep the notation uncluttered.
The induced distribution isolates the dependence between input and output and simpliﬁes the computation of predictive distribution due to the change-of-variable formula.
Speciﬁcally, given a test point x ∗ , the predictive distribution can be alternatively written as
[Equation]
[Table]
/ID19gke540n</latexit>
[Figure]
Conﬁdence x <latexit sha1_base64="vdzmATc8TMUqFF5AvQufOlJfXJs=">AAAB8XicdVDLSgMxFL3js9ZX1aWbYBFcDZlxqF0W3bisYB/YlpJJM20wkxmSjFiG/oUbF4q49W/c+TemD0FFDwQO59xLzj1hKrg2GH84S8srq2vrhY3i5tb2zm5pb7+pk0xR1qCJSFQ7JJoJLlnDcCNYO1WMxKFgrfD2Yuq37pjSPJHXZpyyXkyGkkecEmOlm25MzCiM8vtJv1TGLvZxtVJB2PW9IMCBJUHFP/V95Ll4hjIsUO+X3ruDhGYxk4YKonXHw6np5UQZTgWbFLuZZimht2TIOpZKEjPdy2eJJ+jYKgMUJco+adBM/b6Rk1jrcRzayWlC/dubin95ncxE1V7OZZoZJun8oygTyCRoej4acMWoEWNLCFXcZkV0RBShxpZUtCV8XYr+J03f9U5d/yoo184XdRTgEI7gBDw4gxpcQh0aQEHCAzzBs6OdR
[Figure]
fFeZ2PLjmLnQP4AeftE
[Figure]
rkVg
[Figure] [Figure]
Our key insight is that p x contains all information we need for prediction and uncertainty measurement.
Hence π is sufﬁcient in the sense that, given π , y is independent of both θ and x .
The isolation combines the complexities in both the likelihood and posterior into a single object p x , and keeps a simple dependence structure between y and π .
Also, the isolation renders the last probabilistic layer y |
π nuisance, which can thus be peeled off for prediction.
To validate the idea, one can show that the predictive distribution is simply p ( y | x , D )
=
Cat( y | E p x π ) .
The difference between probabilistic structures of original Bayesian model and the isolated version is showed in Fig.
3, Appendix.
Although the density function p x is sometimes hard to compute, especially for complicated T x (like
NN), its samples can be obtained via 1) sampling the posterior, i.e. θ s ∼ p ( θ |D ) ; 2) “push-forward” the samples by T x , i.e. π s = T x ( θ s ) .
The behavior of π can be empirically observed via the particles { π s } Ss =1 .
As shown in Fig.
2, π is able to distinguish different types of input x based on the behavior of its samples.
In Fig. 2(a), the inputs are similar to the training data.
The particles gather around a corner of the simplex, indicating a conﬁdent prediction.
In Fig. 2(b), the inputs are digit images but are relatively hard to predict.
Therefore, the particles gathers around the center, indicating the model is certain that the input is on decision boundary.
In Fig. 2(c), the inputs are images outside the domain of training data, the particles spread over the simplex, which means the model has a high uncertainty about input, indicating out-of-domain (OOD).
In Fig. 2(d), the particles spread along a line between two corners, indicating the model is conﬁdent that the result is not at the other corner.
However, using particles for inference is time-consuming as each particle requires one evaluation of the model.
This motivates us to use a tractable conditional distribution q ( π | x ) to approximate p x .
2. A MORTIZED A PPROXIMATION
The view of p x enables ﬂexible choices of q ( π | x ) , as any distribution deﬁned on R K can be transformed to S K − 1 via logistic transformation (Aitchison, 1982).
However, modeling q ( π | x ) locally for every input is not practical, as the design efforts and number of parameters grows linearly with the number of data points.
Therefore, we propose to approximate p x in two aspects: 1) use a single family of distribution q ; 2) to generalize to unseen examples, let the parameter of q , α x = α ( x ; φ ) , be a function depending on x and parameterized by a set of global adaptive parameters φ , and thus q x = q ( π | x )
=
q ( π | α x ) .
The computational cost is amortized by casting the problem of learning a series of conditional distributions to a regression problem.
We term p x as “teacher distribution” and q x as “student”.
In our method, as seen in graphical representation in Fig. 3, Appendix, by proper approximation, the stochasticity and knowledge in node θ of the teacher is transferred into node π of the student model, such that the full predictive uncertainty is maintained.
In terms of computation, the approximation requires sampling only in the training stage.
While in the testing stage, to obtain the predictive distribution, only one evaluation is required.
Thus, we denote the framework as the One-Pass Uncertainty (OPU) model.
The above beneﬁts do not introduce any concession on generalizability.
Since OPU is based on approximating the distribution of the output class probabilities which is common for all classiﬁers, the amortized approximation can be applied to any Bayesian classiﬁer.
Note that the approximation framework can be extended to non-parametric model like Gaussian process, where the computational cost of inference is high 1 .
In this work, we choose the student model q to be a Dirichlet distribution, q ( π | α x ) =
Dir( π | α x ) , where α x is a function mapping input x to a Dirichlet parameter.
The reasons for choosing Dirichlet is the tractability: the Dirichlet is the conjugate prior to the Categorical, and thus enables tractable integration of (2) given the parameters.
To better disentangle the uncertainty measures, we use the design α x = h x · e g x , where h x = h ( x ; φ 1 ) and g x = g ( x ; φ 2 ) are two neural networks, and the vector output h sums to 1.
Vector output h determines the mean of the Dirichlet (i.e., the predicted class probabilities), and g determines the concentration of the Dirichlet (i.e., the prediction conﬁdence).
To see this, the posterior of the class labels is the Dirichlet mean, p ( y (cid:96) =
1 | x , φ ) =
(cid:82) Cat ( y (cid:96) =
[Equation]
x ,c = h x ,(cid:96) where y (cid:96) and α x ,(cid:96) are the (cid:96) -th coordinate of y and α x respectively.
Therefore, we call h x as the “prediction model” (PM).
Similarly, the precision parameter α 0 (determines sharpness) of the Dirichlet solely depends on g x , α
0 = (cid:80)
c α x ,c = (cid:80)
c h x ,c e g x =
e g x .
Therefore, we term g x as the “concentration model” (CM).
Based on this property, whether the
Dirichlet is ﬂat or not, can be fully characterized by CM.
It can be expected that, when approximating particles in Fig. 2(a) and (b), the output value of CM is high, as the samples are concentrated, which means high conﬁdence.
CM outputs a low value for particles in Fig. 2(c), yielding a ﬂat distribution and low conﬁdence.
2. L EARNING
With a probability distance or divergence, we deﬁne the approximation loss
L ( x , α )
=
ρ ( p x , q x )
The student model is trained to minimize the aggregated objective
[Equation]
where F is some hypothesis space and p ( x ) is some distribution over X .
In practice we take p ( x ) =
p D (cid:48)
( x ) with D (cid:48)
= { x m } Mm =1 a dataset containing features only.
As the amortized approximation of induced distributions in Bayesian classiﬁers is unexplored in the literature, we consider and compare several choices of ρ including KL divergence, earth mover’s distance (EMD) and maximum mean discrepancy (MMD).
The corresponding derivation of the training objectives and training algorithms are in the appendix.
Forward KL divergence Minimizing aggregated reverse KL divergence is not tractable in our scenario as the density function p x is not available in general.
This difﬁculty is avoided by using forward KL, in which the intractable density function is only involved in the irrelevant entropy term.
It is equivalent to using cross-entropy as a local loss, i.e. L ( x , α ) =
− E
p x ln q x .
By plugging in a particle estimation ˆ p x = 1 S (cid:80) Ss =1 δ ( π − T x ( θ s )) , the training objective becomes min α − E p D(cid:48)
( x ) 1 S (cid:80) s ln q x ( T x ( θ s )) , which is equivalent to an “amortized” MLE problem with particles providing the estimation of sufﬁcient statistics of q x .
Due to the zero-avoiding nature, forward KL tends to over-estimate the support of p x .
This leads to under-conﬁdence approximation (“ﬂat” approximate distribution) and hence might deteriorate the quality of uncertainty measurements.
This is expected to be more serious
when p x is multi-modal.
EMD It is known that EMD provides much weaker topology than other probability distance measures Peyré et al.
In the application where data is supported on strictly lower-dimensional manifolds, EMD provides more stable gradient than KL divergence (Arjovsky et al., 2017; Tolstikhin et al., 2017).
An example of particles on low-dimensional manifold is shown in Fig. 2(d).
Speciﬁcally, the KR dual representation of EMD (Villani, 2008) in our problem is given by
[Equation]
x [ ψ ( π )] , where (cid:107) · (cid:107) L denotes the Lipschitz semi-norm and ψ is known as the critic (or the discriminator (Arjovsky et al., 2017)).
As the induced distribution is conditioned on x , a local critic ψ x should be deﬁned for each x .
Following
Arjovsky et al.
(2017), intractable supremum is solved by parameterizing ψ x = ψ ( · ; w x ) .
To avoid training |D (cid:48) | local critics, we propose to let w be the global weight, and let ψ depends on x , i.e., ψ x = ψ ( π ; w, x ) (see Fig.
4, Appendix).
The ﬁnal aggregated training objective becomes,
[Equation]
where w is the introduced global parameter for ψ , R ( w ) is the imposed gradient penalty (Gulrajani et al., 2017) over w to enforce the Lipschitz constraint.
Solving the minimax problem requires the supremum to be attained for each x under the Lipschitz constraint.
Speciﬁcally, in every optimization step, ψ is trained to generate a critic for each x that matches the exact EMD.
Practically, this needs a high-capacity critic and the required capacity increases with the number of classes K .
MMD Let H k be a reproducing kernel Hilbert space (RKHS) deﬁned by a positive-deﬁnite kernel k , the MMD between p x and q x can be written as
[Equation]
Compared with EMD, the advantage of MMD is that there is no need to train an NN as the critic that maximizes Eq.
With kernel trick, MMD can be readily estimated in closed-form with its empirical version under ﬁnite sample (Sec. C).
Compared with KL divergence, MMD is a valid statistical metric.
Due to the symmetry property, the approximation is expected to be neither mean-seeking nor mode-seeking.
Therefore, MMD is not expected to have an under-conﬁdence issue.
Reparameterization Note that optimization under both EMD and MMD requires gradient of the expectation of critic via sampling from q , which contains parameters.
To obtain efﬁcient gradient estimator and reduce variance, we use the reparameterization trick (speciﬁcally, implicit reparameterization trick).
For details, see Sec.
C in Appendix.
2. A MORTIZATION G AP
To better understand nature of the proposed approximation, we consider the “unamortized” version of the approximation as an intermediate stage, which involves ﬁtting separate approximations to each p x .
To demonstrate the idea, we leverage to MMD due to its nice property.
For ﬁxed p x , the optimal point-wise approximation within family Q is deﬁned as
[Equation]
Then we have the following lemma:
Lemma 1.
Let P ( S K − 1 ) be the space of probability measures over the simplex, equipped with MMD metric deﬁned by a universal kernel.
If T satisﬁes Assumption 1, then the map x (cid:55)→ p x is continuous.
Further, if Q ⊆ P ( S K − 1 ) is a closed convex model space, the projection ¯ q ∗ x is unique and the map x
(cid:55)→ ¯ q ∗ x is also continuous.
Further, if we assume the model space is parameterized and identiﬁable in MMD, i.e. Q = { q ( π | α ) : α ∈ A} and MMD k ( q ( π | α ) , q ( π | α (cid:48) ))
=
if and only if (cid:107) α − α (cid:48) (cid:107) =
, we may obtain continuity in parameter space.
The continuity of optimal parameters implies there exists a continuous function α ∗ : x ∈ X (cid:55)→ α ∗ ( x ) ∈ A , which serves as the essential target of our amortized goal.
To analyze how amortization affects the approximation, we deﬁne the local amortization gap as
[Equation]
Then it holds that
[Equation]
where the lower bound is because ¯ q ∗ x is the projection and the upper bound is due to triangle inequality.
Then our goal, minimizing aggregated MMD loss E p ( x ) MMD k ( q x , p x ) , is essentially equivalent to minimizing aggregated amortization gap E p ( x ) ∆( x ) , up to an irrelevant additive constant.
One can see that α ∗ is the global minimizer of aggregated amortization gap and hence the global minimizer of the aggregated MMD loss.
Intuitively, if F is of enough capacity, then the inﬁmum (over
F ) of aggregated amortization gap could be 0, i.e. we can push the amortization gap arbitrarily small.
If the optimal solution is covered by hypothesis space, no additional cost is introduced by amortizing the approximation.
In other words, model loss due to using restrictive Q will dominate.
Further, if the global optimum is reached, OPU approximation exactly matches the point-wise minimizer, i.e.
MMD k ( q x , q ∗ x ) = 0 , due to uniqueness of projection.
R ELATED W ORK
In this section, related works are reviewed and compared with OPU in terms of methodology.
In
CompactApprox (Snelson & Ghahramani, 2005), a parametric model composed of a small subset of “best samples” selected from the original MC samples is used to approximate the full predictive
Categorical distribution.
Extending the approximation to Bayes NN, BDK (Balan et al., 2015) proposes to use NN to approximate the predictive Categorical distribution of a Bayes NN trained by stochastic gradient Langevin dynamics (SGLD).
Speciﬁcally, the teacher network generates samples via SGLD and KL between the two distributions is minimized in an online fashion.
However, the disadvantage is that data uncertainty, model uncertainty and distributional uncertainty are all entangled in the class probabilities because categorical distributions are of limited expressiveness.
Different from these previous works that only approximate the class probabilities, OPU approximates the induced distribution of class probabilities, which contains richer information including both class probabilities and prediction conﬁdence (e.g., the three types of uncertainty observable via the samples in Fig.
We choose a Dirichlet distribution as the student model, and explicitly disentangle the mean and concentration to fully capture the thee types of uncertainty.
We also explore other probability distance measures (EMD and MMD), showing that KL yields degenerate prediction performance.
Using a Dirichlet to estimate uncertainty has also been explored by Deep Prior Network (DPN) (Malinin & Gales, 2018), where a parameterized Dirichlet is used in a Bayesian model to characterize the “distributional uncertainty”, i.e., to tell if the data is in the training domain or not.
However,
DPN adds a stochastic layer in the Bayes model, rather than approximating a well-trained Bayes teacher.
Due to the intractable inference, DPN uses an MAP estimate of the model posterior which incurs a loss of uncertainty .
To compensate for the lost characterization of uncertainty, DPN uses a hand-crafted training goal that explicitly requires OOD examples (which are typically unavailable in real-world applications).
In contrast to DPN, our OPU is able to: 1) extract predictive uncertainty from any Bayesian classiﬁcation model according to the practical requirements; 2) choose various types for student model (e.g., quantized neural network) to enable fast prediction; 3) use only indomain data in training to get a good uncertainty measure (see Sec. 4).
Note that none of these properties can be achieved by DPN.
E XPERIMENTS 4. E XPERIMENTAL S ETUP
Models and Tasks
In this section, we present the experimental results on using Bayesian NN (BNN).
For each model, we choose a few Bayesian methods as teachers, and approximate them with our OPU.
We also compare with state-of-the-art approximations that are proposed for the speciﬁc types of methods.
For BNN, we use MCDP (Gal & Ghahramani, 2016) and SGLD (Welling & Teh, 2011) as the teacher, and BDK and DPN for comparisons.
The methods for obtaining posterior samples from the Bayes teachers are in Appendix B. For each type of model, in-domain misclassiﬁcation (MisC) detection, out-of-domain (OOD) input detection, prediction performance and prediction time are presented.
Baselines and Uncertainty Measures For the uncertainty measures of teachers, we take MCDP and KL as a example.
For each testing data x , a Dirichlet is ﬁt on particles under KL, to get an optimal q ∗ x , whose differential entropy (D) is an uncertainty measure.
For the uncertainty in prediction, to avoid the model loss, entropy (E) and maximum probability (P) of the averaged particle are directly adopted as uncertainty measures.
This gives MCDP-KL model as a baseline.
The other baselines
MCDP-EMD and MCDP-MMD are also obtained similarly.
Note that they share the same E and P as the sample mean is the same.
The D of q ∗ x is expected to be the best uncertainty measure that OPU can approach theoretically (when the amortization loss is zero, see Sec. 2.4).
For fairness, the same set of posterior particles is used for obtaining D. The baselines for SGLD are obtained in a similar way.
Students use categorical entropy (for BDK) or D (for DPN) and P of the output distributions.
For OPU, we consider E and P of the prediction model, and the scalar output of the concentration model (C) as the measures.
Data and Evaluation Metrics For a fair comparison, we let D (cid:48)
=
D in the approximation of OPU.
The in-domain dataset is split to training data and testing data, i.e., D in = D (cid:48)
= {D tr , D te } , which is used for training models, evaluating prediction and MisC detection.
The OOD dataset
D ood and D te are used for OOD detection.
To assess the performance, we use accuracy, time, Area under the ROC [Table] [Table] (AUROC) and PR (AUPR), following the baseline in (Hendrycks & Gimpel, 2017)
(The detailed calculation process is shown appendix D.3).
Time is evaluated on the whole D te .
To save space, we only present the best performing uncertainty measure (E, P or C) for each task and method.
(Full results on undistilled MCDP/SGLD are shown in appendix D.3.)
We use the MXNet implementation of BDK and GPﬂow implementation of GP, and the remaining models are implemented in Pytorch.
All experiments run on a desktop with an i7-8700 CPU and an RTX-2080 Ti GPU.
The experiments for Bayesian logistic regression follows the same setup as Gaussian process.
4. B AYESIAN N EURAL N ETWORK
The experiments for Bayesian neural network use MNIST and balanced EMNIST datasets as D in , and use Omniglot and SEMEION dataset as D ood , as in Malinin & Gales (2018).
Given MCDP and SGLD as teacher models, the baselines are obtained as illustrated in Sec. 4.1.
The rest models are: OPU approximating MCDP (OPU-MCDP), OPU-SGLD, BDK-SGLD, BDK-Dir-SGLD and DPN.
For BDK-Dir-SGLD, we replace the Categorical distribution in BDK by a Dirichlet without disentangling the mean and concentration, then train it with the same MC ensemble as OPU-SGLD.
This is to show the beneﬁts of explicit disentanglement.
The NN architecture used by these models is an MLP with size 784-400-400-10, ReLU activations, and softmax outputs, following Balan et al.
For CM, we use an MLP with size 784-400-4001.
MCDP is trained by SGD with hyper-parameters: dropout-rate of 0.5, learning rate 5 × 10 − 4 , mini-batch size of 256, number of iterations 10 3 .
The parameters of critic are shown in Appendix.
For MMD, we use a summation of RBF kernel and polynomial kernel.
OPU-MCDP is trained by Adam with hyper-parameters: number of iterations 100 , learning rate for student 10 − 3 .
The training of SGLD and BDK follows Balan et al.
Then OPU-SGLD is trained with the same hyperparameters as OPU-MCDP.
Results of DPN are from Malinin & Gales (2018).
The results are presented in Table 1.
Computation time.
OPU offers a ∼ 500x speedup compared to the original MCDP/SGLD, as OPU only evaluate the model twice (PM and CM in the student network) while MCDP/SGLD evaluates for S times.
This conﬁrms our idea of accelerating Bayesian prediction by diverting the sampling process from the test period to the approximation period .
Note that the time cost of MCDP/SGLD increases with more posterior samples involved.
BDK is slightly faster than OPU because it runs one network while OPU runs both PM and CM.
Experimental results on original MCDP/SGLD with fewer samples are given in appendix D.3 to show performance degradation with fewer samples.
OPU vs BDK.
In some tasks especially OOD detection, the measure of concentration outperforms the baseline.
This is because the explicit disentanglement of mean and concentration helps “targeted” knowledge distillation, as shown in Sec. 2.2.
By comparing OPU-SGLD-KL and BDK (trained by forward KL), we observe that OPU-SGLD-KL is signiﬁcantly better in OOD detection tasks and
AUROC in MisC detection.
BDK shows a slight advantage in AUPR in MisC detection task.
This is because the knowledge distillation only happens between two categorical variables in BDK, which only helps capturing prediction information.
In contrast, OPU framework ﬁrst extracts all information in a BNN with the induced distribution, then transfers the knowledge to a more expressive distribution with a small loss guaranteed (Sec. 2.4).
Adding a Dirichlet distribution to BDK (BDK-DIR-SGLD) helps improving the performance in OOD detection.
However, on SEMEION, which is expected to be harder as it is more similar to MNIST, there is a large performance difference from OPU.
This further validates the necessity of explicit disentanglement of mean and concentration.
OPU vs DPN.
Our OPU model (without OOD data in training) has comparable performance to DPN (which uses a hand-crafted goal and OOD data in training).
Another reason that DPN performs slightly better is that DPN uses VGG-6 (4 Convolutional layer and 1 FC layer), which is a much stronger model than the 2-layer MLP model that other models use.
KL vs EMD vs MMD.
With MCDP, MCDP-MMD gives the best performance of differential entropy baseline (D).
This is because the samples of MCDP are relatively spread out over the simplex and might be multi-modal.
The probability distance is fully captured by MMD under such case.
EMD is expected to perform well as there are a lot of samples π s residing on a low-dimensional manifold.
However, the performance seems to be degenerated due to the limited capacity of the hyper-network and the difﬁculty to train the minimax problem.
KL presents the worst performance as expected because it is likely to be under conﬁdent with samples of MCDP.
With SGLD, the performance of KL is the best except for AUROC of MisC detection.
This is because the samples π s of SGLD over the simplex are much denser and are typically unimodal.
KL vs MMD (EMNIST).
The experiments are conducted on EMNIST whose number of classes is large.
We choose Omniglot as the OOD detection dataset as it is also contains handwritten characters, which are harder than SEMEION for a model trained on EMNIST.
A CNN with structure similar with LeNet is used for MCDP and OPU (20 and 50 output channels in two convolutional layers).
The baseline approach achieves a classiﬁcation accuracy of 88.8%.
The samples of MCDP Bayes NN are expected to be even more dispersive and multi-modal than MCDP trained with MNIST.
OPU trained with EMD failed to converge, possibly because the capacity of the hypernetwork was not enough.
Therefore, we do not recommend to use EMD for amortized approximation of predictive uncertainty, unless a more scalable estimator of EMD can be provided.
As shown in Table 2, the performance gap between OPU-MCDP-KL and the baseline is larger because the multi-modality is severe – the entropy of sample mean is a better measure for OOD detection than the concentration.
This further validates that OPU trained by KL suffers from an under-conﬁdence issue.
Speciﬁcally, KL forces OPU to cover the support of all samples, making the student distribution more dispersive.
This inaccurate estimate of concentration affects the estimation of prediction results (mean) in turn, thus the accuracy is lower and MisC detection performance is degenerated.
By contrast, MMD consistently provides an approximation that has similar performance with the teacher, that echoes the analysis in Sec. 2.4. Amortization Gap.
The details of experiments on the approximation error/gap can be found in appendix D.3.
It is shown that the amortization gap of using OPU is small, indicating the function space is enough to cover the essential target.
It also shows the approximation error is mainly from the model error of using Dirichlet distribution, which is small as well, see appendix D.3 for details.
D ISCUSSION
The idea of “transferring” the randomness from model posterior to a simple-structure distribution at the output can be generalized to other problems where a real-time evaluation of uncertainty is critical, e.g., object segmentation.
This allows interesting designs of structured output distributions.
The choice of student distribution for OPU is ﬂexible. Although we verify that Dirichlet is suitable for the tested classiﬁcation tasks, there are still chances that Dirichlet incurs great model error. Note that, in our framework, using a Dirichlet for the student is modeling choice, similar to assuming Gaussian posteriors for variational approximations. The OPU framework is general and any student distribution can be adopted, e.g., generalized Dirichlet, mixture of Dirichlets.
To do this requires: 1) a suitable parametrization of the model that can capture uncertainty; 2) deriving/computing the approximation loss (KL, MMD, EMD); 3) reparameterization trick of expectations for efﬁcient gradient estimation.
The algorithms of KL, EMD and MMD as well as the analysis still apply.
A A PPENDIX : P ROOF
Assumption 1.
Let T : X × Θ
→ Y be a map between ﬁnite dimensional vector spaces.
We say T satisﬁes Assumption 1 for distribution p if
T ( · ; θ ) is Lipschitz and the Lipschitz constant L θ satisﬁes E θ ∼ p
L θ < + ∞ .
Proof.
We simply show both maps are Lipschitz continuous with MMD metric on P ( S K − 1 ) .
Let x , x (cid:48) ∈ X and ψ ∈
H k such that (cid:107) ψ (cid:107)
H k ≤ 1 .
For x (cid:55)→ p x , the “push-forward” deﬁnition of p x leads to
[Equation]
≤
[Equation]
where d k = is a kernel-based distance.
The constant C emits when bounding d k with Euclidean norm and the existence of such a constant is due to topology equivalence in ﬁnite-dimensional space.
For x → ¯ q ∗ x , we notice that ¯ q ∗ x is the projection of p x onto Q (effectively the projection of kernel mean embeddings in H k ).
By projection theorem in Hilbert space, the projection map p x (cid:55)→ ¯ q ∗ x is non-expansive, i.e.
[Equation]
which leads to Lipschitz property of x (cid:55)→ ¯ q ∗ x .
B A PPENDIX : P LOTS .
The graph representations of original view , isolated view of Bayes teacher and the student are shown in Fig.
C A PPENDIX : ALGORITHMS .
For presenting the algorithms, we slightly change the notation.
We let α ( x ) =
α ( x , φ ) , h ( x ) =
h ( x , φ 1 ) , g ( x ) =
g ( x , φ 2 ) , where φ = { φ 1 , φ 2 } , φ 1 and φ 2 are the parameters of prediction model h and concentration model g , respectively.
KL.
With the training objective
[Equation]
[Figure]
The student model is updated by doing φ t +
[Equation]
) and φ t +
[Equation]
alternately, where γ t is the learning rate at iteration t and x ∗ is the input at this iteration.
EMD.
With the following training objective,
[Equation]
Algorithm
Input : Posterior samples: { θ s } Ss =1 ; OPU training data D (cid:48) ; Gradient penalty coefﬁcient λ ; Number of training iterations: T stu and T wit .
while φ not converge do
[Equation]
* Update Approximation */ for iter in 1 . . .
T stu do
Sample
[Equation]
s
[Equation]
φ 1 ← Adam
[Equation]
Sample
[Equation]
φ 2 ← Adam( ∇ φ 2 L ( i ) ) end /
* Update Critic */ for iter in 1 . . .
T wit do
Sample
[Equation]
Compute
[Equation]
v ← Adam( ∇ v L ( i ) ) end end
MMD.
The kernel mean embedding of p x and q x are given by µ p =
E p x
[ k ( π , · )] and µ q = E q x [ k ( π , · )] .
The training objective is then,
[Equation]
[Equation]
[Table]
5QP</latexit>
NN NN
Feat
Feat Concatenate
NN
Scalar
[Table]
of EMD
w
[Table]
[Equation]
[Figure]
[Equation]
[Figure]
[Equation]
[Figure]
[Equation]
[Figure]
[Equation] [Figure] [Equation] [Figure]
Output
[Figure]
Input
Posterior
while φ not converge do
Sample
[Equation] [Table]
[Equation]
[Table]
[Equation]
[Table]
Sample
[Table]
Reparameterization: To obtain efﬁcient gradient estimator and reduce variance, we reparameterize the Dirichlet by an equivalent product of K independent Gamma distributions.
If ˜ π ∼
PG(˜ π | α ) =
(cid:81)
Kk =
1 Gam(˜ π k | α k ) , then π =
( (cid:80) k
˜ π k ) − 1 ˜ π ∼ Dir( π | α ) .
By Thm. 3 in (Arjovsky et al., 2017), in each L ( φ | x ) , the supremum is attained at ψ ∗ x ∈ L 1 and the gradient is ∇ φ L ( φ | x )
=
−∇ φ E q ( π | x , φ ) [ ψ ∗ x ( π )] .
Then as noted by (Figurnov et al., 2018), the gradient ∇ φ L ( φ | x ) can be implicitly computed without knowing the inverse of standardization function (e.g., CDF).
Speciﬁcally, by Eq. 5 in (Figurnov et al., 2018), ∇ φ E q ( π | x ; φ ) [ ψ ∗ x ( π )] =
E PG(˜ π | x ; φ ) [ ∇ ˜ π ψ ∗ x ( π ) ∇ φ ˜ π ] , where the ﬁrst term ∇ ˜ π ψ ∗ x ( π ) is computed via the chain rule and the second term ∇ φ ˜ π is obtained by solving a local diagonal linear system.
Refer to (Figurnov et al., 2018) and references therein for details.
D A PPENDIX : EXPERIMENTS
For the critic in EMD used in MNIST experiments, NN1 is a 784-256 MLP, NN2 is a 10-256 MLP and NN3 is a 512-256-1 MLP (see Fig. 4).
For the critic in EMD used in MNIST experiments, NN is the same as convolutional layers used in Ba, NN2 is a 10-256 MLP and NN3 is a 512-256-1 MLP (see Fig. 4).
D. B AYESIAN LOGISTIC REGRESSION
We test two models in this experiment: Polya Gamma (PG), CompactApprox approximating PG (CA-PG) and OPU approximating PG (OPU-PG).
We draw 500 posterior samples from PG and train
OPU with the following hyperparameters: number of epochs 100, learning rate for student.
CA-PG is trained by ﬁrst drawing 5000 samples from PG then evaluating the model with 50 randomly selected samples from them (same setup as CompactApprox).
The random selection is repeated for
[Table]
times
[Table] [Table]
and we pick the best group of samples.
As the results for the three metrics are similar, we only show the results trained with KL divergence.
The results are shown in Table 3.
OPU-PG maintains similar performance with the original PG on prediction accuracy and MisC detection.
Meanwhile, OPU outperforms CA-PG on prediction accuracy, MisC and OOD detection.
For OPU, CM outperforms other uncertainty measures at OOD detection, which indicates it captures the distributional uncertainty well.
OPU performs better than the PG Bayes teacher.
The reason might be that a parametric model is learned to approximate the ensemble of discrete samples, which could produce a smoother output distribution (regularization), leading to better performance.
OPU also achieves a ∼ 100-600x speedup from the original PG.
D. G AUSSIAN P ROCESS
For GP, we use SGPMC (Hensman et al., 2015a) as the teacher, and SVGP (Hensman et al., 2015b) for comparison.
This experiment uses Pima and Spambase datasets as D in .
Pima is a medical dataset with 769 data points and 9 dimensions.
Spambase is a text dataset with 4601 data points and 57 dimensions for identifying spam email.
We generate the same number of data points from a zero-mean multivariate
Gaussian distribution for D ood .
For each dataset, 10% of data points are uniformly selected into the testing set D te .
We normalize the data by features with L2 norm.
where K is the number of classes.
There are 3 models tested: SGPMC, OPU approximating SGPMC (OPU-SGPMC) and
SVGP.
SGPMC and SVGP are trained with 110 |D in | data points randomly selected from D in as inducing points.
Then 500 samples over functions of D in are generated from SGPMC.
As the results for the three metrics are similar, we only show the results trained with KL divergence.
The results are presented in Table 4.
On MisC detection and prediction accuracy, OPU has similar performance to SGPMC, which indicates the effectiveness of approximating prediction results with ensemble of samples in the nonparametric family.
With the same number of inducing points, SVGP performs slightly worse than SGPMC, because it incurs a two-fold approximation.
Measuring uncertainty with CM in OPU outperforms other measures and models, which indicates the sharpness of the logistic-normal distribution can be captured via the CM the designed Dirichlet.
SGPMC and SVGP are faster than OPU on Pima, but are slower than OPU on the larger Spambase.
This is due to the static latency for setting up the GPU for OPU, which becomes the main time cost when the dataset is small (as in Pima).
For the two GP methods, the computation time depends on the number of inducing points and the number of dimensions.
Therefore, as the dataset becomes larger (Spambase), the computation time increases. [Table]
D. M ORE EXPERIMENTS ON B AYESIAN N EURAL N ETWORK
In this section, we present more experimental results/details on Bayesian NN.
Computation of AUROC/AUPR: First, we show how AUROC/AUPR is calculated. We use entropy (E) and max probability (P) of the particle mean, and differential entropy (D) of locally ﬁtted student distribution as the measures for the teacher. We use entropy (E) and max probability (P) of the particle mean, and the scalar output of student concentration model (C) as the measures for the OPU student. For OOD detection, say q x 1 has higher E (or lower P or lower C) than q x 2 , then q x 1 is more likely to be an OOD data.
The value of E, P and C (D for the teacher) are computed for all testing data points (both in domain data and out-of-domain data), which rank the data points based on the numerical magnitude.
The ROC curve is plotted by setting threshold on each magnitude and compute the True
Positive Rate and False Positive Rate at each threshold.
The PR curve is plotted similar by computing the Precision and Recall.
Then the area under two curves (AUROC and AUPR) can be obtained.
For misclassiﬁcation detection, the similar calculation process is applied.
Error/gap: Second, we use the four types of error/gap under MMD deﬁned in Sec.
2.4 to show the effectiveness of amortized approximation and the suitableness of using Dirichlet family.
Speciﬁcally, the following measures are used:
• Averaged total approximation error (Avg.Approx.
Err.
The
averaged MMD be
- tween teacher’s particles (for each x) and the predicted Dirichlet by OPU, i.e., 1 N (cid:80) Ni =1 MMD( q x i , p x i ) .
• Averaged total approximation error (Avg.Model.
Err.
): The averaged MMD between teacher’s particles (for each x) and locally ﬁtted Dirichlet, i.e., 1 N (cid:80) Ni =1 MMD( p x i , ¯ q ∗ x i ) .
• Averaged local amortization gap (Avg.Amt.
Gap): The difference between Avg.
Approx.
Err and Avg.
Model.
Err.
, i.e., ∆( x ) , deﬁned in Eq.
• Averaged local amortization error (Avg.Amt.
Err.
): We deﬁne this type of error to be the averaged MMD between locally ﬁtted Dirichlet (for each x) and the predicted Dirichlet by OPU, i.e., 1 N (cid:80) Ni =1 MMD( q x i , ¯ q ∗ x i ) .
The relation between Avg.Amt.
Gap and Avg.
Amt.
Err. is given by Eq. 8.
We show the numerical results on EMNIST dataset by Table 5.
It can be observed that the Avg.Amt.
Err.
0.0053 is low and it bounds the Avg.
Amt.
Gap ∆( x ) =
Avg.
Approx.
Err.
– Avg.
Model.
Err=0.0049, which is consistent with Eq. 8.
The approximation error is mainly determined by the model error, which turns out to be acceptably small.
This is consistent with the analysis and also shows the effectiveness and suitableness of using Dirichlet family.
Cifar10 results: Third, we show the experimental results of OPU approximating Bayesian NN on
Cifar10 dataset in Table 6.
The NN model for teacher and student is standard VGG19 with the output dimension of concentration model to be 1.
The MCDP teacher model is trained with SGD optimizer and a cyclical learning rate policy.
The base learning rate is initialized to be 0.01 and linearly increased to 10x of learning rate, then decreases back to the base learning rate.
The base learning rate is then scaled by half.
The number of MCDP particles is 700.
The OPU students are trained with KL/EMD/MMD using the corresponding algorithm for 200 epochs.
As the task is harder than MNIST, particles tends to be more spread over the corners.
Under such case, it can be observed that the performance of EMD and MMD is much better than that of KL.
Teachers with fewer samples: Fourth, the performance of original MCDP/SGLD with fewer samples is shown in Table 7.
We note that using few particles would affect the performance of Bayesian classiﬁer, especially the performance on OOD detection.
In real-world cases like automatic driving car where the robustness is critical, it is not worth to trade safety for speed.
Therefore, OPU solves this issue by providing accurate estimation of predictive uncertainty with short evaluation time.
Besides the speedup, OPU approximation provides a full distribution to characterize the predictive
[Table]
[Table]
distribution, which is not available with particle approximation.
This allows for better uncertainty measures such as differential entropy
[Table]
Un-distilled teachers
: Finally, we show the detailed un-distilled MCDP/SGLD, whose elements might be covered by differential entropy of locally ﬁtted Dirichlet in Table 1.
The detailed results are shown in Table
E A PPENDIX : SAMPLING
In this section, we illustrate the details for extracting samples from Bayesian logistic regression,
Bayesian neural network and Gaussian process.
Under some contexts, we use X and Y to collectively denote the inputs and outputs respectively for previous D .
E. B AYESIAN L OGISTIC R EGRESSION
The Polya-Gamma (PG) scheme (Polson et al., 2013) is a data augmentation strategy that allows for a closed-form Gibbs sampler.
In binary classiﬁcation, i.e., y n ∈ Y = { 1 , 0 } , let θ be the regression coefﬁcients with a Gaussian conditional conjugate prior p ( θ ) ∼ N ( 0 , Λ − 1 ) .
The PG Gibbs sampler is composed of the following two conditionals,
[Equation]
where ω n is the augmenting data corresponding to the n th data point.
The posterior conditional variance and mean are given by V ω
=
( X T Ω X + Λ − 1 ) − 1 and m ω
= V − 1 ω ( X T ( y − 12 )) , respectively.
Given this formulation we will be able to collect samples from the posterior after a burn-in period.
The posterior samples { θ } Ss =1 , together with dataset D (cid:48) , are used to train our approximation with goal deﬁned in Eq.
As an MCMC method, the PG augmentation scheme offers accurate samples.
Other alternative methods such as local variational approximation can be employed, which are much faster but sacriﬁce accuracy.
E. M ONTE C ARLO D ROPOUT
A neural network with dropout applied before every weight layer was shown to be an approximation to probabilistic deep Gaussian process (GP) (Gal & Ghahramani, 2016).
Let q ( θ ) to be the approximate distribution to the GP posterior.
Here, θ = { Θ i } Li =1 and Θ i is a parameter matrix of dimensions
K i × K i =1 for NN layer i .
In this approximation, q ( θ ) can be deﬁned through direct modiﬁcation:
[Equation]
[Table]
where z i,j ∼ Bern( p i ) for i ∈
[ L ] and j ∈ [ K i − 1 ] , given some prior dropout probabilities p i and matrices Θ i are treated as variational parameters.
The binary variable z
i,j = 0 indicates that unit j in layer i − 1 being dropped out as an input to layer i .
The predictive mean of this approximation is given by E
[ y | x ] ≈ 1 S (cid:80) Ss =1 f ( x , ˆ z 1 ,s , . . .
, ˆ z L,s ) , which hence referred to as MC dropout (MCDP).
We use OPU to approximate the uncertainty induced by q ( θ ) .
A sample in the MC ensemble is given by θ s =
{ Θ i,s } Li =1 =
M i diag([ z i,j ] K
i
i =1 ) .
We set φ 1 = { Φ i } Li =1 Z to the mean of θ s , i.e., Φ i = 1 S (cid:80) Ss =1 Θ i,s =
M i 1 S (cid:80)
Ss =1 diag([ z i,j,s ]
K i i =1 ) .
MCDP provides a simple way of approximating Bayesian inference through dropout sampling.
However, it still introduces a variational approximation to exact Bayesian posterior.
Therefore, we further include a more accurate way to generate MC ensemble - stochastic gradient Langevin dynamics (SGLD).
E. V ANILLA SGLD
SGLD enables mini-batch MC sampling from the posterior via adding a noise step to SGD (Welling & Teh, 2011).
We choose the “vanilla” version of SGLD in our approximation.
Speciﬁcally, we start training of f θ ( · ) from θ (0) .
In each epoch with mini-batch size B ,
[Equation]
where B is the size of a mini-batch and η t ∼ N (0 , 2 (cid:15) t I ) .
After SGLD converges at step T , the samples θ s = θ
( T + s ) is collected by running the training process for another S iterations.
We use averaged samples as parameter of h , i.e., φ 1 = 1 S (cid:80) Ss =1 θ s and train OPU by Eq.
10 with this ensemble.
E. M ONTE C ARLO G AUSSIAN P ROCESS
We apply the OPU framework to the GP framework, which demonstrate its use on a non-parametric classiﬁer.
Let data D be split into as input matrix X and output matrix Y .
We consider GP prior over the space of functions, i.e., µ ∼ GP (0 , K ) .
where K is a positive deﬁnite kernel controlling the prior belief on smoothness.
Existing techniques allow us to compute q ( µ ) which approximates p ( µ |D ) and is comparable to previous q ( θ ) under a parametric model.
In a classiﬁcation task, the posterior p ( µ |D ) can be sampled via MCMC (Hensman et al., 2015a) or approximated, e.g., via variational approximation (Hensman et al., 2015b).
Let µ ∗ be a shorthand for µ x and π is then deﬁned as S ( µ ∗ ) .
If Gaussian variational approximation is used, the marginal posterior p ( µ ∗ | x , D ) at x induces a logistic-normal distribution for p ( π | x , D ) .
In our approximation, we obtain samples { µ ∗ s } Ss =1 from p ( µ ∗ | x , D ) .
The optimization goal is the same as that in the NN case with a different target distribution deﬁned as
[Equation]