Year: 2019

Abstract:
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 finding 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 specific Bayesian model, meanwhile alleviating the heavy workload of MC integration at testing time. The proposed method is universally applicable to Bayesian classification 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.

heading: 1 INTRODUCTION
text: 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 classification model trained on dataset D = {(yn,xn)}Nn=1, where xn ∈ X and yn ∈ Y are the nth input and output, respectively. Let the model posterior p(θ|D) be approximated by MC estimate 1S ∑S s=1 δ(θ−θs), and the predictive distribution (a categorical distribution parameterized by the predicted class probabilities) is thus approximated by
p(y|x,D) = ∫ p(y|x,θ)p(θ|D) dθ ≈ 1
S S∑ s=1 p(y|x,θs).
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 finally 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 confidence (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 confidence 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 classifier 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 efficient 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 simplifies 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 specific 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 significant speedup (∼ 500×) of Bayes models. The results on Bayes NN show that OPU performs better in misclassification 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 classification models.

heading: 2 ONE-PASS UNCERTAINTY FRAMEWORK

heading: 2.1 INDUCED DISTRIBUTION OVER SIMPLEX
text: In this section we present our OPU framework for a generic Bayesian parametric classifier, e.g. Bayesian logistic regression (BLR) or Bayesian neural networks (NN). Let the Bayesian classifier be specified with categorical likelihood and a parametric function, i.e.,
p(y|x,θ) = Cat(y|T (x;θ)) (1) and a prior distribution p(θ) be specified over the parameter space Θ, where T : X ×Θ→ SK−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 fixed input x, the mapping Tx = T (x; ·) is also understood as a data-dependent mapping Tx : Θ→ SK−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 define a random variable π = Tx(θ) whose distribution is induced by θ ∼ p(θ|D) and Tx. This is effectively a welldefined push-forward measure Tx#p(θ|D) over the simplex (see Fig. 1). We term the conditional distribution of π|x,D as an “induced distribution” and define px(π) = p(π|x,D) to keep the notation uncluttered. The induced distribution isolates the dependence between input and output and simplifies the computation of predictive distribution due to the change-of-variable formula. Specifically, given a test point x∗, the predictive distribution can be alternatively written as
p(y|x∗,D) = ∫
Θ Cat(y|Tx∗(θ))p(θ|D) dθ = ∫ SK−1 Cat(y|π)px∗(π) dπ. (2)
Our key insight is that px contains all information we need for prediction and uncertainty measurement. Hence π is sufficient 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 px, 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|Epxπ). The difference between probabilistic structures of original Bayesian model and the isolated version is showed in Fig. 3, Appendix.
Although the density function px is sometimes hard to compute, especially for complicated Tx (like NN), its samples can be obtained via 1) sampling the posterior, i.e. θs ∼ p(θ|D); 2) “push-forward” the samples by Tx, i.e. πs = Tx(θ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 confident 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 confident 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 px.

heading: 2.2 AMORTIZED APPROXIMATION
text: The view of px enables flexible choices of q(π|x), as any distribution defined on RK can be transformed to SK−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 px 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 qx = 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 px as “teacher distribution” and qx 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 benefits 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 classifiers,
the amortized approximation can be applied to any Bayesian classifier. 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 = hx · egx , where hx = h(x;φ1) and gx = 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 confidence). To see this, the posterior of the class labels is the Dirichlet mean, p(y` = 1|x,φ) = ∫ Cat(y` =
1|π)Dir(π|αx) dπ = αx,`∑ c αx,c
= hx,` where y` and αx,` are the `-th coordinate of y and αx respectively. Therefore, we call hx as the “prediction model” (PM). Similarly, the precision parameter α0 (determines sharpness) of the Dirichlet solely depends on gx, α0 = ∑ c αx,c = ∑ c hx,ce
gx = egx . Therefore, we term gx as the “concentration model” (CM). Based on this property, whether the Dirichlet is flat 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 confidence. CM outputs a low value for particles in Fig. 2(c), yielding a flat distribution and low confidence.

heading: 2.3 LEARNING
text: With a probability distance or divergence, we define the approximation loss L(x,α) = ρ(px, qx) The student model is trained to minimize the aggregated objective
min α∈F Ep(x)L(x,α) (3) where F is some hypothesis space and p(x) is some distribution over X . In practice we take p(x) = pD′(x) with D′ = {xm}Mm=1 a dataset containing features only. As the amortized approximation of induced distributions in Bayesian classifiers 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 px is not available in general. This difficulty 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,α) = −Epx ln qx. By plugging in a particle estimation p̂x = 1S ∑S s=1 δ(π − Tx(θs)), the training objective becomes
minα−EpD′ (x) 1S ∑ s ln qx(Tx(θs)), which is equivalent to an “amortized” MLE problem with particles providing the estimation of sufficient statistics of qx. Due to the zero-avoiding nature, forward KL tends to over-estimate the support of px. This leads to under-confidence approximation (“flat” approximate distribution) and hence might deteriorate the quality of uncertainty measurements. This is expected to be more serious when px is multi-modal.
EMD It is known that EMD provides much weaker topology than other probability distance measures Peyré et al. (2019). 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).
Specifically, the KR dual representation of EMD (Villani, 2008) in our problem is given by W1(px, qx) = sup‖ψ‖L≤1 Eθ∼p(θ|D)[ψ(Tx(θ))] − Eπ∼qx [ψ(π)], where ‖ · ‖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 defined for each x. Following Arjovsky et al. (2017), intractable supremum is solved by parameterizing ψx = ψ(·;wx). To avoid training |D′| 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 final aggregated training objective becomes,
min α max w
EpD′ (x) [ Ep(θ|D)[ψ(Tx(θ);w,x)]− Eqx [ψ(π;w,x)] ] + λR(w), (4)
1The details of extracting samples from various Bayes parametric models and non-parametric model (GP classifier) are summarized in the appendix.
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. Specifically, 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 LetHk be a reproducing kernel Hilbert space (RKHS) defined by a positive-definite kernel k, the MMD between px and qx can be written as
MMDk(p, q) = sup ψ∈Hk,‖ψ‖H≤1
Ep(θ|D)[ψ(Tx(θ))]− Eqx [ψ(π)] (5)
Compared with EMD, the advantage of MMD is that there is no need to train an NN as the critic that maximizes Eq. 5. With kernel trick, MMD can be readily estimated in closed-form with its empirical version under finite 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-confidence 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 efficient gradient estimator and reduce variance, we use the reparameterization trick (specifically, implicit reparameterization trick). For details, see Sec. C in Appendix.

heading: 2.4 AMORTIZATION GAP
text: To better understand nature of the proposed approximation, we consider the “unamortized” version of the approximation as an intermediate stage, which involves fitting separate approximations to each px. To demonstrate the idea, we leverage to MMD due to its nice property. For fixed px, the optimal point-wise approximation within family Q is defined as
q̄∗x = arg min q∈Q MMDk(q, px). (6)
Then we have the following lemma:
Lemma 1. Let P(SK−1) be the space of probability measures over the simplex, equipped with MMD metric defined by a universal kernel. If T satisfies Assumption 1, then the map x 7→ px is continuous. Further, if Q ⊆ P(SK−1) is a closed convex model space, the projection q̄∗x is unique and the map x 7→ q̄∗x is also continuous. Further, if we assume the model space is parameterized and identifiable in MMD, i.e. Q = {q(π|α) : α ∈ A} and MMDk(q(π|α), q(π|α′)) = 0 if and only if ‖α−α′‖ = 0, we may obtain continuity in parameter space. The continuity of optimal parameters implies there exists a continuous function α∗ : x ∈ X 7→ α∗(x) ∈ A, which serves as the essential target of our amortized goal. To analyze how amortization affects the approximation, we define the local amortization gap as
∆(x) = MMDk(qx, px)−MMDk(q̄∗x, px). (7)
Then it holds that 0 ≤ ∆(x) ≤ MMDk(qx, q̄∗x), (8)
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 Ep(x)MMDk(qx, px), is essentially equivalent to minimizing aggregated amortization gap Ep(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, ifF is of enough capacity, then the infimum (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. MMDk(qx, q ∗ x) = 0, due to uniqueness of projection.

heading: 3 RELATED WORK
text: 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). Specifically, 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 confidence (e.g., the three types of uncertainty observable via the samples in Fig. 2.) 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 classification 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.

heading: 4 EXPERIMENTS

heading: 4.1 EXPERIMENTAL SETUP
text: Models and Tasks In this section, we present the experimental results on using Bayesian NN (BNN).2 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 specific 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 misclassification (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 fit 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′ = D in the approximation of OPU. The in-domain dataset is split to training data and testing data, i.e., Din = D′ = {Dtr,Dte}, which is used for training models, evaluating prediction and MisC detection. The OOD dataset Dood and Dte are used for OOD detection. To assess the performance, we use accuracy, time, Area under the ROC
2The setup and results on BLR and GP are available in the appendix.
(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 Dte. 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 GPflow 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.

heading: 4.2 BAYESIAN NEURAL NETWORK
text: The experiments for Bayesian neural network use MNIST and balanced EMNIST datasets as Din, and use Omniglot and SEMEION dataset as Dood, 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 benefits 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. (2015). For CM, we use an MLP with size 784-400-400- 1. 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 103. 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. (2015). 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 confirms 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 significantly 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 first 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 difficulty to train the minimax problem. KL presents the worst performance as expected because it is likely to be under confident 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 classification 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-confidence issue. Specifically, 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.

heading: 5 DISCUSSION
text: 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 flexible. Although we verify that Dirichlet is suitable for the tested classification 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 efficient gradient estimation. The algorithms of KL, EMD and MMD as well as the analysis still apply.

heading: A APPENDIX: PROOF
text: Assumption 1. Let T : X ×Θ→ Y be a map between finite dimensional vector spaces. We say T satisfies Assumption 1 for distribution p if T (·;θ) is Lipschitz and the Lipschitz constant Lθ satisfies Eθ∼pLθ < +∞.
Proof. We simply show both maps are Lipschitz continuous with MMD metric on P(SK−1). Let x,x′ ∈ X and ψ ∈ Hk such that ‖ψ‖Hk ≤ 1. For x 7→ px, the “push-forward” definition of px leads to
MMDk(px, px′) = sup ‖ψ‖≤1
Ep(θ|D)ψ(Tx(θ))− Ep(θ|D)ψ(Tx′(θ))
≤ sup ‖ψ‖≤1 Ep(θ|D)|ψ(Tx(θ))− ψ(Tx′(θ))|
≤ sup ‖ψ‖≤1 ‖ψ‖Ep(θ|D)dk(Tx(θ), Tx′(θ))
≤ CEp(θ|D)‖Tx(θ)− Tx′(θ)‖ ≤ CEp(θ|D)Lθ‖x− x′‖,
where dk = is a kernel-based distance. The constant C emits when bounding dk with Euclidean norm and the existence of such a constant is due to topology equivalence in finite-dimensional space. For x → q̄∗x, we notice that q̄∗x is the projection of px onto Q (effectively the projection of kernel mean embeddings in Hk). By projection theorem in Hilbert space, the projection map px 7→ q̄∗x is non-expansive, i.e.
MMDk(q̄ ∗ x, q̄ ∗ x′) ≤ MMDk(px, px′),
which leads to Lipschitz property of x 7→ q̄∗x.

heading: B APPENDIX: PLOTS.
text: The graph representations of original view , isolated view of Bayes teacher and the student are shown in Fig. 3.

heading: C APPENDIX: ALGORITHMS.
text: 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
min φ
−EpD′ (x) 1
S ∑ s ln q(T (x;θs)|x,α), (9)
The student model is updated by doing φt+11 := φ t 1 − γt(− 1S ∑ θs ∇φ1 ln q(T (x∗;θs)|α(x∗;φ1))) and φt+12 := φ t 2−γt(− 1S ∑ θs ∇φ2 ln q(T (x∗;θs)|α(x∗;φ2))) alternately, where γt is the learning rate at iteration t and x∗ is the input at this iteration.
EMD. With the following training objective,
min φ max w
EpD′ (x) [ Ep(θ|D)[ψ(Tx(θ);w,x)]− Eqx [ψ(π;w,x)] ] + λR(w),
Algorithm 1: OPU Training Algorithm with EMD Input: Posterior samples: {θs}Ss=1; OPU training data D′; Gradient penalty coefficient λ; Number of training iterations: Tstu and Twit. while φ not converge do
Sample x(i) ∼ pD′(x) /* Update Approximation */ for iter in 1 . . . Tstu do
Sample {πs′}S ′ s′=1 ∼ q(π|x(i),φ) L(i)(φ1) = − ∑S′ s′=1 ψ(πs′ ;w,x (i)) φ1 ← Adam(∇φ1L(i)) Sample {πs′}S ′
s′=1 ∼ q(π|x(i),φ) L(i)(φ2) = − ∑S′ s′=1 ψ(πs′ ;w,x (i))
φ2 ← Adam(∇φ2L(i)) end /* Update Critic */ for iter in 1 . . . Twit do
Sample {πS′s′=1} ∼ q(π|x(i),φ) ComputeR(v) L(i)(v) = ∑Ss=1 ψ(T (x;θs);w,x(i))−∑S′s′=1 ψ(πs′ ;w,x(i)) + λR(w) v ← Adam(∇vL(i))
end end
MMD. The kernel mean embedding of px and qx are given by µp = Epx [k(π, ·)] and µq = Eqx [k(π, ·)]. The training objective is then,
min φ ‖µp − µq‖Hk , (10)
Algorithm 2: OPU Training Algorithm with MMD Input: Posterior samples: {θs}Ss=1; OPU training data D′; Gradient penalty coefficient λ. while φ not converge do
Sample x(i) ∼ pD′(x) Sample {πq,s′}S ′ s′=1 ∼ q(π|x(i),φ), get {πp,s′}S ′ s′=1 = {T (x|θs′)}S ′ s′=1
L(i)(φ1) = 1S′(S′−1) ∑S′ m 6=n k(πq,m,πq,m) + 1 S′(S′−1) ∑S′ m 6=n k(πp,m,πp,m)−
2 S′(S′−1) ∑S′,S′ m,n=1 k(πq,m,πp,n) φ1 ← Adam(∇φ1L(i)) Sample {πs′}S ′
s′=1 ∼ q(π|x(i),φ) L(i)(φ1) = 1S′(S′−1) ∑S′ m 6=n k(πq,m,πq,m) + 1 S′(S′−1) ∑S′ m 6=n k(πp,m,πp,m)−
2 S′(S′−1) ∑S′,S′ m,n=1 k(πq,m,πp,n)
φ← Adam(∇φ2L(i)) end
Reparameterization: To obtain efficient gradient estimator and reduce variance, we reparameterize the Dirichlet by an equivalent product of K independent Gamma distributions. If π̃ ∼ PG(π̃|α) = ∏Kk=1 Gam(π̃k|αk), then π = (∑k π̃k)−1 π̃ ∼ Dir(π|α). By Thm. 3 in (Arjovsky et al., 2017), in each L(φ|x), the supremum is attained at ψ∗x ∈ L1 and the gradient is ∇φL(φ|x) = −∇φEq(π|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). Specifically, by Eq. 5 in (Figurnov et al., 2018),∇φEq(π|x;φ)[ψ∗x(π)] = EPG(π̃|x;φ)[∇π̃ψ∗x(π)∇φπ̃], where the first 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.

heading: D APPENDIX: EXPERIMENTS
text: 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, NN1 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.1 BAYESIAN 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 first 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 105 times
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.2 GAUSSIAN PROCESS
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 Din. 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 Dood. For each dataset, 10% of data points are uniformly selected into the testing set Dte. 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 |Din| data points randomly selected from Din as inducing points. Then 500 samples over functions of Din 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.
D.3 MORE EXPERIMENTS ON BAYESIAN NEURAL NETWORK
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 fitted 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 qx1 has higher E (or lower P or lower C) than qx2 , then qx1 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 misclassification detection, the similar calculation process is applied.
Error/gap: Second, we use the four types of error/gap under MMD defined in Sec. 2.4 to show the effectiveness of amortized approximation and the suitableness of using Dirichlet family. Specifically, the following measures are used:
• Averaged total approximation error (Avg.Approx.Err.): The averaged MMD between teacher’s particles (for each x) and the predicted Dirichlet by OPU, i.e., 1 N ∑N i=1 MMD(qxi , pxi). • Averaged total approximation error (Avg.Model.Err.): The averaged MMD between teacher’s particles (for each x) and locally fitted Dirichlet, i.e., 1N ∑N i=1 MMD(pxi , q̄
∗ xi).• Averaged local amortization gap (Avg.Amt.Gap): The difference between Avg.Approx.Err
and Avg.Model.Err., i.e., ∆(x), defined in Eq. 7. • Averaged local amortization error (Avg.Amt.Err.): We define this type of error to be the
averaged MMD between locally fitted Dirichlet (for each x) and the predicted Dirichlet by OPU, i.e., 1N ∑N i=1 MMD(qxi , q̄ ∗ xi). 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 classifier, 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
distribution, which is not available with particle approximation. This allows for better uncertainty measures such as differential entropy.
Un-distilled teachers: Finally, we show the detailed un-distilled MCDP/SGLD, whose elements might be covered by differential entropy of locally fitted Dirichlet in Table 1. The detailed results are shown in Table 8

heading: E APPENDIX: SAMPLING
text: 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.1 BAYESIAN LOGISTIC REGRESSION
The Polya-Gamma (PG) scheme (Polson et al., 2013) is a data augmentation strategy that allows for a closed-form Gibbs sampler. In binary classification, i.e., yn ∈ Y = {1, 0}, let θ be the regression coefficients with a Gaussian conditional conjugate prior p(θ) ∼ N (0,Λ−1). The PG Gibbs sampler is composed of the following two conditionals,
ωn|θ,xn ∼ PG(1,xTnθ) (11) θ|ω,D ∼ N (mω,Vω), (12)
where ωn is the augmenting data corresponding to the nth data point. The posterior conditional variance and mean are given by Vω = (XTΩ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′, are used to train our approximation with goal defined in Eq. 10.
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 sacrifice accuracy.
E.2 MONTE CARLO DROPOUT
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 Ki ×Ki=1 for NN layer i. In this approximation, q(θ) can be defined through direct modification:
Θi = Midiag([zi,j ] Ki i=1), (13)
where zi,j ∼ Bern(pi) for i ∈ [L] and j ∈ [Ki−1], given some prior dropout probabilities pi and matrices Θi are treated as variational parameters. The binary variable zi,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] ≈ 1S ∑S s=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 = Midiag([zi,j ]Kii=1). We set φ1 = {Φi}Li=1Z to the mean of θs, i.e., Φi = 1 S ∑S s=1 Θi,s = Mi 1 S ∑S s=1 diag([zi,j,s] Ki 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.3 VANILLA 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. Specifically, we start training of fθ(·) from θ(0). In each epoch with mini-batch size B,
θ(t+1) = θ(t) + t∇ log p(θ(t)|D) + ηt (14)
= θ(t) + t∇(log p(θ(t)) + B∑ b=1 log p(yb|xb,θ(t))) + ηt, (15)
where B is the size of a mini-batch and ηt ∼ N (0, 2 tI). 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 = 1S ∑S s=1 θs and train OPU by Eq. 10 with this ensemble.
E.4 MONTE CARLO GAUSSIAN PROCESS
We apply the OPU framework to the GP framework, which demonstrate its use on a non-parametric classifier. 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 definite 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 classification 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 defined 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 defined as
p̂(π|x,D) = 1 S S∑ s=1 δ(π − S(µ∗s)). (16)

Review summaries:
This paper studies the problem of avoiding Monte Carlo (MC) estimate for the predictive distribution during the test for Bayesian methods. MC estimate will incur multiple passes where the number of passes depends on the number of samples and therefore the cost can be huge. The authors propose One-Pass Uncertainty (OPU) methods to approximate the predictive distribution through distillation. Experiments on Bayesian neural networks are conducted to demonstrate the proposed method.