December 15, 2022
We introduce ensembles of stochastic neural networks to approximate the Bayesian posterior, combining stochastic methods such as dropout with deep ensembles. The stochastic ensembles are formulated as families of distributions and trained to approximate the Bayesian posterior with variational inference. We implement stochastic ensembles based on Monte Carlo dropout, DropConnect and a novel non-parametric version of dropout and evaluate them on a toy problem and CIFAR image classification. For both tasks, we test the quality of the posteriors directly against Hamiltonian Monte Carlo simulations. Our results show that stochastic ensembles provide more accurate posterior estimates than other popular baselines for Bayesian inference.
Bayesian neural networks provide a principled way of reasoning about model selection and assessment with posterior distributions of model parameters [1]–[4]. Although the analytical Bayesian posteriors can answer questions about model parameter uncertainty, the immense computational challenge for commonly used neural network architectures makes them practically infeasible1. Instead, we are forced to resign to approximation methods that makes a trade-off between posterior accuracy and computational complexity [5].
A prominent method to approximate the Bayesian posterior is deep ensembles [6]–[8], that can be shown to correspond to a variational inference approximation with a delta distribution family [9]. This method is implemented by simply training an ensemble of models and treating them as samples from the model posterior. In the variational inference formulation, this corresponds to approximating the posterior by sampling from many sets of maximum a posteriori parameters.
To further reduce the computational effort in evaluating the approximate posterior, stochastic methods such as Monte Carlo dropout [10] and DropConnect [11] inference have also been used extensively [12]–[14]. They benefit from computationally cheaper inference by virtue of sampling stochastically from a single model. Formulated as a variational approximation to the posterior, dropout samples from a family of parameter distributions where parameters can be randomly set to zero. Although this particular family of distributions might seem unnatural [15], it turns out that the stochastic property can help to find more robust regions of the parameter space, a fact well-known from a long history of using dropout as a regularization method.
Recently, there has been great progress towards understanding the analytical posteriors of larger neural networks by means of direct Markov Chain Monte Carlo sampling of the parameter posterior [16]. Through impressive computational efforts, the posteriors for models as large as ResNet-20 have been sampled using Hamiltonian Monte Carlo (HMC) simulations. The sampled posterior has been shown to provide more accurate predictions that are surprisingly sensitive to data distribution shift as compared to standard maximum likelihood estimation training procedures. These HMC computations have made it possible to compare approximation methods such as dropout inference and deep ensembles directly to the Bayesian posterior. Ensembling and stochastic methods such as dropout have been used successfully to find posterior approximations in many settings, but without a Bayesian formulation that includes both ensembling and stochastic methods it is difficult to understand if and how the two approaches can complement each other.
Recent work have shown that uncertainty quantification is subjective to neural network architectures, and that the accuracy of posterior approximations depend non-trivially on model architecture and dataset complexity [17]. To find computationally efficient methods that can accurately approximate the Bayesian posterior, for different data domains and architectures, is therefore an important goal with practical implications for applications that require accurate uncertainty quantification to assess network predictions[18], [19].
In this paper we combine deep ensembles and regularization methods into stochastic ensembles of neural networks. We formulate the stochastic ensemble construction within the Bayesian variational formalism, where multiple stochastic methods such as regular Monte Carlo dropout, DropConnect, and others are combined with ensembling into one general variational ansatz. We then conduct a series of tests using a simple toy model (synthetic data) and CIFAR (image classification), where stochastic deep ensembles are found to provide more accurate posteriors than MultiSWA [6] and regular deep ensembles in a number of settings. In particular, for CIFAR we use a neural network architecture evaluated by Izmailov et al. [16] in their large-scale experiments, allowing us to make a direct comparison of the ensemble methods to the “ground truth" HMC posterior.
Bayesian inference for neural networks has a long history [1]–[4]. A variety of methods have been developed for estimating the Bayesian posterior, including Laplace approximation[20], Markov Chain Monte Carlo methods [21]–[23], variational Bayesian methods [24]–[30] and Monte Carlo dropout [12], [13]. Deep ensembles [7], [8] have shown surprising abilities to approximate the Bayesian posterior well. They were found to empirically outperform other scalable methods [31], [32] and important conceptual aspects of their excellent performance were recently explained [6], [33], [34]. Forced diversity between ensemble members, motivated from a Bayesian perspective, has been shown to improve accuracy and out-of-distribution detection [35]. The dependence of the posterior on priors in weight and function space for deep ensembles has also been investigated [35], [36]. Various methods for improving deep ensembles have also recently been proposed [37]–[44].
One of the widely used ensemble methods is MultiSWAG [6], where an ensemble of networks trained with Stochastic Weight Averaging Gaussian [6], [45], [46] is used for approximating the posterior. These networks were shown to have better generalization properties than networks trained using conventional SGD protocols [45], [46]. MultiSWAG was also found to provide posteriors that are more robust to distributional shifts than regular deep ensembles [6].
Our variational inference formulation is based on the works of Gal et al. [12], [13] for dropout and Hoffmann et al. [9] for deep ensembles. We combine these two methods and formulate one general Bayesian variational ansatz. We also note that our independent rederivation of the loss from Ref. [9] uncovered a new loss contribution promoting member diversity. A similar loss term was studied in Ref. [35] that was argued to be seen as Wasserstein gradient descent on the Kullback-Leibler divergence. Here we derive it explicitly from Bayesian variational inference.
The numeric tests on CIFAR image classification follow closely the impressive effort of Izmailov at al. [16] reporting full-batch HMC computations on CIFAR datasets. We reproduced the exact network architecture and used their reported results for making a quantitative comparison of different ensemble types against HMC, indicating that our stochastic ensembles produce better posterior approximations than the non-stochastic baselines.
We introduce stochastic ensembles. They are formulated using Bayesian variational inference where deep ensembles and stochastic methods such as dropout are combined into one general variational family of distributions. We show the theoretical advantage in using stochastic over regular (non-stochastic) ensembles and test different ensemble methods on a toy problem and CIFAR image classification.
We show that for image classification on CIFAR, our stochastic ensembles based on Monte Carlo dropout produce the most accurate posterior approximations compared to other ensemble methods: They are found to be closer to HMC than MultiSWA and regular deep ensembles in terms of log-likelihood loss, accuracy, calibration, agreement, variance, out-of-distribution detection, predictive entropy, and robustness to distributional shifts.
The posteriors produced by the Monte Carlo dropout ensembles for CIFAR image classification are also seen to outperform various stochastic gradient Monte Carlo (SGMCMC) methods: They are closer to the HMC posteriors and require less inference samples at test time.
We introduce a novel stochastic model with a non-parametric version of dropout by jointly training an ensemble of models with exchange of parameters. It was found to outperform other methods for our simple toy task in terms of the agreement and variance computed in respect to the HMC posterior. It was also found to provide more accurate uncertainty estimates.
In modelling we aim to predict a label \(y^*\) for a given input \(x^*\) and provide uncertainty estimates of the prediction. The output should be in alignment with our observation, i.e. it should be conditioned on the training (observed) data \(\mathcal{D} = \{x_i, y_i\}^N_{i=1}\). This is captured by the predictive probability distribution \(p(y^*| x^*, \mathcal{D})\), which provides a distribution over possible output values \(y^*\).
Consider a model with \(\theta\). The predictive distribution \(p(y^*| x^*, \mathcal{D})\) can then be represented as follows \[\begin{align}
\begin{aligned}
p(y^*| x^*, \mathcal{D}) &= \int \, d\theta \, \underbrace{p(y^*| x^*, \theta)}_\text{aleatoric} \, \underbrace{p(\theta| \mathcal{D})}_\text{epistemic}. \\
\end{aligned}
\label{eq:Baysian}
\end{align}\tag{1}\] The posterior distribution \(p(\theta| \mathcal{D})\) describes uncertainty, the type of uncertainty that is by definition associated with the model parameters \(\theta\). The term \(p(y^*| x^*, \theta)\) corresponds to aleatoric (data) uncertainty [47].
Approximate methods. In practice, \(p(\theta| \mathcal{D})\) is unknown and hard to : methods for computing \(p(\theta| \mathcal{D})\) exist but they are for models with
large number of . Approximate Bayesian inference aims to find a distribution \(q(\theta)\) that is as close to the true posterior \(p(\theta| \mathcal{D})\) as possible. To date, the golden
standard method for approximate Bayesian inference is HMC[21]. It is based on performing Metropolis-Hastings updates using Hamiltonian dynamics associated
with the potential energy \(U(\theta) = - \log p(y |x, \theta)p(\theta)\) with \(\mathcal{D} = (x, y)\). This method is accurate but numerically tractable only for small models and datasets,
severely limiting its practical applicability.
Variational inference [26], [27], [48] is less precise than HMC, but more numerically efficient. The idea is to look at a family of distributions \(q_\omega(\theta)\), where \(\omega\)
parameterizes the family, and find a distribution that approximates the posterior \(p(\theta| \mathcal{D})\) well. One common approach for finding the best family member \(q_\omega(\theta)\)
is to numerically minimize the Kullback-Leibler (KL) divergence \(\text{KL}(q_\omega(\theta)\,||\,p(\theta|\mathcal{D}) )\) [47], a measure quantifying how much information is lost when \(q_\omega(\theta)\) is approximated by \(p(\theta|\mathcal{D})\):
\[\begin{align}
\begin{aligned}
&\text{KL}(q_\omega(\theta)\,||\,p(\theta|\mathcal{D}) ) =\int \, d\theta \, q_\omega(\theta) \, \log\,\frac{q_\omega(\theta)}{p(\theta|\mathcal{D})} \\
&= \text{KL}(q_\omega(\theta)\,||\,p(\theta) ) - \mathbb{E}_{q_\omega(\theta)} [\log \, p(y | \theta, x)] + C,\\
\end{aligned}
\label{eq:VI}
\end{align}\tag{2}\] where the training data is denoted by \(\mathcal{D} = (x, y)\) and \(C\) is a \(\theta\)-independent term. Here we applied
Bayes’ theorem \(p(\theta|x,y) = p(y |\theta, x) \, p(\theta) / p(y |x)\). By minimizing the loss function in Eq. (2 ) one obtains an approximation for the posterior \(p(\theta|\mathcal{D})\). Note that the cost function consists of two terms, (1) the KL divergence against the prior \(p(\theta)\) and (2) the expected negative log likelihood (ENLL), that is a
standard loss for classification tasks. Minimization of the ENLL loss in Eq. (2 ) is usually archived via stochastic-gradient-based methods implemented on the Monte Carlo sampled model.
Deep ensembles. Conventional maximum likelihood training of a neural network can be naturally described within the Bayesian variational inference picture [26]. Deep ensembles can be explicitly reformulated within the Bayesian setting as well [9] and are associated with
ansatz \[\begin{align}
\begin{aligned}
&q_\omega(\theta) = \frac{1}{K}\sum^K_{k = 1} \, \mathcal{N}(\theta; \omega_k, \sigma^2 I_{\text{dim} [\theta]}),\\
\end{aligned}
\label{eq:BDE}
\end{align}\tag{3}\] where \(K\) is the number of networks in the ensemble, \(\omega\) consists of \(K\) independent sets \(\omega_k\) of parameters \(\theta\), \(k = 1, ..., K\). Conventional deep ensembles are associated with the case of infinitesimal (machine-precision) \(\sigma\) so that the normal distributions in Eq. (3 ) are sharply peaked and approach the delta function distributions \(\delta(\theta - \omega_k)\).
The ENLL contribution to the cost function in Eq. (2 ) simplifies to a sum of independent loss terms associated with each ensemble member, weighted by factor \(1/K\). In this case the KL divergence against the standard normally-distributed prior \(p(\theta) = \mathcal{N}(\theta; 0, \, \lambda^{-1} I_{\text{dim}[\theta]})\) reduces to [9] \[\begin{align} \begin{aligned} &\text{KL}( \, q_\omega(\theta) \,||\,p(\theta) \, ) = \, \frac{1}{2} \text{dim}[\theta]\left(\lambda \sigma^2-\log \, \sigma^2 - 1 - \log \lambda \right)\\ & + \underbrace{\frac{1}{2K} \sum^K_{k = 1} \lambda ||\omega_k||^2}_\text{L2 regularization} - \underbrace{\;\;\log K \;\;}_\text{\shortstack{KL loss reduction \\ due to ensembling}} + \underbrace{\;\;\;\text{RF}_{\phantom{2}} \;\;}_\text{repulsive force},\\ \end{aligned} \label{eq:BDE95KL} \end{align}\tag{4}\] where the repulsive-force correction \(\text{RF}\) becomes negligibly small as \(\sigma\) approaches zero and was dropped in Ref. [9]. In our SM [49] we show that the repulsive-force correction can be approximated by the following upper bound \[\begin{align} \begin{aligned} &\text{RF} \leq \frac{1}{K}\sum^K_{k=1} \sum_{k^\prime \neq \, k} \exp[-||\omega_k - \omega_ {k^\prime}||^2/(8 \, \sigma^2)].\\ \end{aligned} \label{eq:RF} \end{align}\tag{5}\]
The L2 regularization term in Eq. (4 ) corresponds to our choice of a Gaussian prior distribution for the model parameters, other terms come from the entropy contribution \(H(q_\omega(\theta))\) to \(\text{KL}( \, q_\omega(\theta) \,||\,p(\theta) \, )\) that is independent of the prior choice. The KL loss reduction due to ensembling is represented here by the \([-\log K]\) term that decreases with the ensemble size. Interestingly, Eq. (4 ) also contains a repulsive force in weight space promoting the ensemble members to be diverse. Diversity among the ensemble members is believed to be a key element for reaching good performance [33], [35].
Posterior landscape. To motivate our construction we start with an intuitive perspective. Regular deep ensembles are believed to be effective at approximating the posterior because of their ability to probe multiple modes of the posterior landscape [9], [33]. This is in contrast to less effective single network stochastic methods that only sample from a single mode. MultiSWAG [6] improves deep ensembles by virtue of Stochastic Weight Averaging protocol that finds flatter parameter regions in the basins of attraction uncovered by deep ensembles. The flatter regions are believed to more accurately represent the posterior [6], [45], [46]. Note, however, that the basins of attraction sampled by MultiSWAG may not be optimal and there can exist wider basins that may be less probable for regular training protocols to end up in. Stochastic ensembles are built from trained networks regularized by stochastic methods such as dropout. They are also multimodal but they only find basins of attraction that are robust to stochastic perturbations and sampling from wide, robust parameter regions is essential for constructing an efficient posterior approximation, cf. the outlined arguments for MultiSWAG.
The length scale of parameter regions probed by a stochastic method is defined by its hyperparameters: dropout networks with larger drop rates, for example, will look for larger robust parameter regions. There will always be a trade off between the
region size and its quality in terms of the robustness. To avoid the need to manually tune the hyper parameters one can aim towards finding a non-parametric stochastic method capable of probing parameter regions on different scales. This motivated us to
introduce a non-parametric version of dropout described in the next section. We also note that different stochastic methods probe the parameter space in different ways. For example dropout probes random hyperplane projections in the parameter space.
Bayesian description. A well known example of stochastic regularization methods is Monte Carlo dropout [15]. For concreteness let us
consider a single fully-connected layer with conventional (Bernoulli) dropout applied after some activation. The layer’s input-output transformation, say from the node layer \(x_l\) to the node layer \(x_{l+1}\), can be expressed as follows \[\begin{align}
\begin{aligned}
x_{l+1} = \sigma(W_{l+1, \, l} \, x_{l} + B_{l+1}) \circ z_{l+1},\\
\end{aligned}
\label{eq:DO}
\end{align}\tag{6}\] where \(W_{l+1, \, l}\) and \(B_{l+1}\) are the layer’s weights and biases respectively, \(\sigma(x)\) is the activation,
and \(z_{l+1, n} \sim \mathcal{B}(p_{l+1, n})\) are Bernoulli-distributed variables, namely \(z_{l+1, n} = 1\) with probability \(p_{l+1, n}\) and \(z_{l+1, n} = 0\) with probability \((1 - p_{l+1, n})\) with \(n = 1, ..., N\). Here \(N\) is the layer’s output dimension and
\(\circ\) denotes the element-wise (Hadamard) product.
The dropout input-output transformation in Eq. (6 ) can be equivalently described as Monte Carlo sampling from a family of Bernoulli functions. Recently it was shown that networks regularized by Bernoulli methods can be viewed as variational inference [12], [13], [50]. We combine these networks into an ensemble and obtain a generalization of the deep ensemble variational ansatz in Eq. (3 ) that we call stochastic ensemble. For the example of a fully-connected dropout layer in Eq. (6 ), the stochastic ensemble ansatz is given by \[\begin{align} \begin{aligned} &q_\omega(\theta_l) = \frac{1}{K}\sum_{k = 1}^K \prod^{N}_{n = 1} \, \hat{q}_{\omega_{l, n, k}}(\theta_{l, n}),\\ \end{aligned} \label{eq:BSDON} \end{align}\tag{7}\] with \[\begin{align} \begin{aligned} \hat{q}_{\omega_{l, n, k}}(\theta_{l, n}) &= p^{(1)}_{l+1, \,n} \, \mathcal{N}(\, \theta_{l, n}; \omega^{(1)}_{\,l, n, k}\, , \, \sigma^2 \, I_{\text{dim} [\theta_{l, n}]}\,)\\ &+ \, p^{(2)}_{l+1, \,n} \, \mathcal{N}(\, \theta_{l, n}; \omega^{(2)}_{\,l, n, k}\, , \, \sigma^2 \, I_{\text{dim} [\theta_{l, n}]}\,),\\ \end{aligned} \label{eq:BSDON95b} \end{align}\tag{8}\] where \(n\) labels the layer’s output nodes \(x_{l+1}\), \(\theta_{l, n}\) consists of all weights and bias connecting the layer’s input \(x_l\) to the layer’s output node \(x_{l+1, n} \,\), and \(\omega^{(i)}_{l, n, k}\) for \(i = 1, 2\) are independent realizations of the network’s parameters \(\theta_{l, n}\), \(p^{(i)}_{l,n}\) the Bernoulli probabilities for the two realizations, and \(k = 1, ..., K\).
As in the case of regular deep ensembles, the ENLL loss reduces to a sum of independent single network losses weighted by \(1/K\). Each such loss term and its gradients can be handled using conventional stochastic
methods such as Monte Carlo sampling [13]. The KL divergence against the normal prior reduces to (see our SM [49]): \[\begin{align}
\label{eq:BPDEDO95KL}
\begin{aligned} &\text{KL}( \, q_\omega(\theta) \,||\,p(\theta) \, ) = \, \frac{1}{2} \text{dim}[\theta]\left(\lambda \sigma^2-\log \, \sigma^2 - 1 - \log \lambda \right)\\ & + \frac{1}{2K} \sum^K_{k = 1} \sum^N_{n = 1} \sum^2_{i = 1} \lambda \,
p^{(i)}_{l+1, \,n} ||\omega^{(i)}_{\,l, n, k}||^2 - \log K \\ & + \underbrace{\sum^{N}_{n = 1} \sum^2_{i = 1} p^{(i)}_{l+1, \,n} \log p^{(i)}_{l+1, \,n}}_\text{\shortstack{KL loss reduction \\due to stochasticity}}+ \text{RF}_2.
\end{aligned}
\end{align}\tag{9}\] The difference to regular deep ensembles in Eq. (4 ) is one additional term that describes the KL loss reduction corresponding to using stochastic over non-stochastic deep networks [13]. The repulsive force \(\text{RF}_2\) is of a more complex form than in the regular deep ensemble case, see our SM [49] for the derivation of the corresponding upper bound. The bound contains an accumulation of the RF contributions coming from every possible stochastic
parameter realizations, weighted by the of obtaining these configurations. Note that it approaches zero for infinitesimal (machine-precision) \(\sigma\).
Stochastic ensemble realizations. The ansatz in Eqs. (7 ) and (8 ) is equivalent to the dropout ensemble by assuming the limit of small \(\sigma\),
and taking \(\omega^{(2)}_{\,l, n, k}\) to be always zero. Other types of stochastic ensembles, such as DropConnect ensembles, as well as other varieties of network layers, beyond the fully-connected layers, can be
formulated similarly to Eq. (7 ). In our experiments we study the dropout and DropConnect realizations of stochastic ensembles, and denote them by SE1 and SE2 respectively. We also look at a realization of Eqs. (7 ) and (8 ) where two sets of trainable parameters are exchanged with equal probability \(p^{(1)}_{l+1, \,n} = p^{(2)}_{l+1, \,n} = 1/2\). This provides an
non-parametric method (in the sense of no tunable probabilities), referred to as SE3, that can be applied to any layer type with just minor changes, including the output layer.
Limitations of the KL loss. The KL loss in Eqs. (4 ) and (9 ) suggest that ensembles of stochastic networks are expected to more accurately approximate the posterior than regular
deep ensembles, especially for large models because the loss reduction due to stochasticity in Eq. (9 ) scales with \(N\). The KL divergence, however, is not a flawless measure. It is known
to ignore parameter regions where the distribution \(q_\omega(\theta)\) is small, and therefore may not penalize the discrepancy with some important parts of the posterior. An interesting improvement to the KL loss was
studied in Ref. [51].
We also stress that the total KL loss that is minimized during the training is not directly correlated with the performance metrics such as accuracy and calibration on the validation set. Smaller KL loss is expected to lead to better quantitative estimates, however, for a given task the quality of these estimates may depend on the data and considered metrics.
To quantitatively compare different ensemble methods we first evaluate them on a toy classification problem. The advantage of using a simple toy model is that the posterior can be straightforwardly sampled using HMC. We implement the NUTS extension [52] of HMC and directly evaluate performance of ensemble methods by comparing their outcomes with the corresponding HMC posterior. The HMC posterior is constructed by stacking 4 independent HMC chains, each of 2000 samples. The details on our HMC (NUTS) implementation are given in the SM [49].
We consider three training datasets shown in Fig. 1 , where the 2D data is classified into two classes. The datasets represent different class separability levels, helping us to make a more comprehensive comparison of the
ensemble methods. We employ a simple feed forward network with two hidden layers of 10 neurons, ReLU activations, and softmax output. The trained models are then tested on two uniformly sampled data domains, \(\mathcal{D_\text{in}}=[-1, \, 1]^2\) (in-domain) and \(\mathcal{D_\text{out}}=[-10, \, 10]^2\) (out-of-domain). We consider three types of stochastic ensembles in our experiments: Monte Carlo
dropout (SE1), DropConnect (SE2), and non-parametric dropout (SE3). More details on the model, training procedure and ensembles are provided in our SM [49].
Uncertainty estimates. In Fig. 1 we also depict two important uncertainty estimates evaluated using the HMC posterior. The total predictive uncertainty can be estimated by computing the predictive posterior
entropy that formally quantifies how much information on average is contained in the output [53]. The second quantity is the (average) mutual Shannon
information contained between network parameters and test data sample conditioned on the training dataset. It quantifies how the posterior distribution changes as we include a new data point to the training dataset [54]. The mutual information describes only the epistemic part of the total uncertainty and it is an important quantity used in many deep learning applications, for example,
in active learning[55]. For more details on these two quantities, and our implementation, see the SM [49].
The toy classification problem is a good illustration for the concepts of aleatoric (data) uncertainty and epistemic (model) uncertainty. For the boundary regions between the two classes, the prediction is expected to exhibit high uncertainty that is
mostly of aleatoric origin. Our HMC results in Fig. 1 are in agreement with the expectation: The total entropy correctly identifies regions of high uncertainty, both the boundary regions (high aleatoric uncertainty) and certain
regions that were not used in the training (high epistemic uncertainty). The mutual information is seen to be large only in the regions of high epistemic uncertainty. The aleatoric (epistemic) uncertainty is seen to increase (decrease) with the class
mixing level.
| 1e-3 | ||||
| 1e-3 | ||||
| 1e-2 | ||||
| 1e-2 | ||||
| Toy-a (in-domain / out-of-domain) | ||||
| 1.18 | ||||
| 1.16 | ||||
| 95.2 | ||||
| 7.49 | ||||
| 1.32 | ||||
| 1.31 | ||||
| 94.01 | ||||
| 8.46 | ||||
| (SE3) | ||||
| 1.14 | ||||
| 1.13 | ||||
| 95.5 | ||||
| 7.00 | ||||
| Toy-b (in-domain / out-of-domain) | ||||
| 0.89 | ||||
| 0.87 | ||||
| 95.4 | ||||
| 5.44 | ||||
| 1.06 | ||||
| 1.03 | ||||
| 94.4 | ||||
| 6.74 | ||||
| (SE3) | ||||
| 0.73 | ||||
| 0.71 | ||||
| 95.8 | ||||
| 4.51 | ||||
| Toy-c (in-domain / out-of-domain) | ||||
| 0.86 | ||||
| 0.83 | ||||
| 96.8 | ||||
| 4.39 | ||||
| 0.90 | ||||
| 0.86 | ||||
| 95.5 | ||||
| 5.01 | ||||
| (SE3) | ||||
| 0.76 | ||||
| 0.73 | ||||
| 96.7 | ||||
| 3.86 | ||||
0.5em
Performance of the ensemble methods. We quantitatively evaluate performance of the ensemble methods by looking at the agreement and variance between the ensemble posteriors and “ground truth” HMC posterior. For an explicit definition of these two quantities see our SM [49] or Ref. [16]. We also report baseline results for the regular (non-stochastic) deep ensembles and MultiSWA ensemble method [6]. To quantify the quality of uncertainty estimates we also look at the mean absolute differences computed between the HMC and ensemble estimates. All three classification datasets depicted in Fig. 1 (a-c) are considered. For each dataset, we compute metrics on data from \(\mathcal{D}_\text{in}\) (in-domain) and \(\mathcal{D}_\text{out}\) (out-of-domain). The size of each ensemble is 1024. Here we always take only one Monte Carlo inference per trained ensemble member, in this way forcing all types of ensembles to use the same resources at test time. In accordance with this constraint, we implement the test-time efficient MultiSWA instead of MultiSWAG [6], see our SM [49] for implementation details.
The dropout (SE1) and DropConnect (SE2) ensembles were found to not perform as good as the regular and non-parametric dropout (SE3) ensembles, highlighting importance of correctly picking the stochastic type for a particular task. For our toy problems we could anticipate this behaviour by looking at the training KL loss exhibiting high fluctuations for SE1 and SE2. The KL loss of SE3 and non-stochastic networks did not fluctuate as much and resulted in smaller training KL loss values.
We present results corresponding to the non-parametric dropout (SE3), MultiSWA and regular ensembles in Table 1. We observe that SE3 outperforms the other two methods, in most places with large margin. The average improvement with respect to the regular ensemble is approximately 10 percents in each of the metrics. Interestingly, the improvement differs between the different versions of the classification dataset and drops with the mixing between the training datasets. We attribute this to the difficulty of stochastic methods to fit the boundary between mixed classes. We also note that for the case with the largest mixing, SE3 and regular ensembles are indistinguishable in agreement and variance for in-domain data. Surprisingly, MultiSWA does not perform better than the regular ensemble baseline.
Let us consider now more realistic data and focus on the classification of images. The CIFAR dataset [56] consists of 60000 low-resolution (32 by 32) RGB images classified into 10 (CIFAR-10) or 100 (CIFAR-100) classes. Complexity of this image dataset makes the full-batch HMC computations highly nontrivial and computationally demanding. Only recently the full-batch HMC method has been evaluated on CIFAR for large residual networks [16]. In this section we train the much less demanding stochastic and non-stochastic ensembles on the CIFAR dataset and compare our results to the HMC data from Ref. [16]. We employ the same network architecture: A ResNet-20-FRN residual network of depth 20 with batch normalization layers replaced with filter response normalization (FRN). The HMC posteriors are directly loaded from the publicly available resource [16].
Bayesian variational inference fixes some aspects of the training procedure such as weight decay and dispense with the need for early stopping. Our training procedure is therefore different from the implementation in Ref. [16] leading to different results for regular ensembles. Three types of stochastic ensembles are used in our CIFAR tests: Monte Carlo dropout (SE1), DropConnect (SE2),
and non-parametric dropout (SE3). The drop rates of SE1 and SE2 were tuned to target the HMC results, rather than targeting best performance in terms of accuracy and loss. Each ensemble consists of 50 networks and we use strictly one Monte Carlo inference
per ensemble member at test time, i.e. in total 50 inferences per ensemble. This restricts the methods to use the same resources. We also considered increasing the number of inferences per member, obtaining only a minor change in the performance. We report
these results in our SM [49]. We also trained multiple realizations of the MultiSWA protocol corresponding to different hyperparameter sets. In the following
we only present the closest MultiSWA realization to HMC. For the details on our hyperparameter selection see the SM [49].
| 1e-2 | ||||||
| 1e-2 | ||||||
| CIFAR-10 | ||||||
| 3-chains | ||||||
| \(\pm\) 00.03 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.2 | ||||||
| \(\pm\)0.2 | ||||||
| SWA | ||||||
| \(\pm\) 0.10 | ||||||
| \(\pm\) 0.024 | ||||||
| \(\pm\) 0.025 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 1.4 | ||||||
| \(\pm\)1.4 | ||||||
| (SE1) | ||||||
| \(\pm\) 0.03 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\)0.1 | ||||||
| CIFAR-100 | ||||||
| 3-chain | ||||||
| \(\pm\) 0.16 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.002 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\)0.1 | ||||||
| SWA | ||||||
| \(\pm\) 0.6 | ||||||
| \(\pm\) 0.018 | ||||||
| \(\pm\) 0.002 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\)0.1 | ||||||
| (SE1) | ||||||
| \(\pm\) 0.18 | ||||||
| \(\pm\) 0.001 | ||||||
| \(\pm\) 0.002 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.1 | ||||||
| \(\pm\) 0.1 | ||||||
0.5em
Stochastic ensembles. We found our Monte Carlo dropout ensembles (SE1) to produce more accurate posteriors than DropConnect (SE2) and non-parametric dropout (SE3) ensembles. We therefore present only results corresponding to SE1. We
could anticipate SE1 performing better than SE2 and SE3 from the training KL loss analysis.
Test performance metrics. In Table 2 we present the test accuracy, test loss, expected calibration error (ECE), agreement, variance, and out-of-distribution detection (ODD) evaluated for different types of
ensembles. For metric definitions see our SM [49]. From Table 2 we read off that the Monte Carlo dropout ensembles (SE1)
provide more accurate posteriors than the baseline MultiSWA and regular deep ensembles.
Predictive entropy. In Fig. 2 we present the predictive entropy computed for different ensembles trained on CIFAR. SE1 is seen to match more accurately the HMC distribution of entropy values than regular deep
ensembles. We also note that MultiSWA and SE1 perform equally well on CIFAR-10 but SE1 is more accurate on CIFAR-100.
Calibration curve. An accurate approximation of Bayesian posterior is expected to be equally calibrated as HMC. In Fig. 3 we depict calibration curves associated with different ensemble methods. All methods
are found to be relatively poorly calibrated. The SE1 ensembles are seen to be the closest to HMC.
Robustness to distribution shift. To test robustness to distribution shifts we evaluate the performance of different methods on the CIFAR-C and CIFAR-100-C datasets [57]. These datasets contain CIFAR images altered using different types of corruptions with varying intensities. We use the same 16 corruptions as in Ref. [16]. For each method and corruption we compute the accuracy, loss, ECE, agreement, and variance, and then average over all the corrupted datasets. The corresponding data
is presented in Table 3, where SE1 is seen to again be closer to HMC in terms of the agreement and variance. In Fig. 4 we plot the accuracy and loss resolved over different corruption types
and intensities. SE1 is found to be more sensitive to the distribution shifts than the regular ensembles and MultiSWA but still not as much as HMC [16].
| 1e-2 | |||||
| 1e-2 | |||||
| CIFAR-10-C (mean over corruptions) | |||||
| 3-chains | |||||
| \(\pm\) 0.21 | |||||
| \(\pm\) 0.006 | |||||
| \(\pm\) 0.001 | |||||
| \(\pm\) 0.3 | |||||
| \(\pm\) 0.4 | |||||
| SWA | |||||
| \(\pm\) 0.24 | |||||
| \(\pm\) 0.019 | |||||
| \(\pm\) 0.013 | |||||
| \(\pm\) 0.2 | |||||
| \(\pm\) 0.2 | |||||
| (SE1) | |||||
| \(\pm\) 0.29 | |||||
| \(\pm\) 0.002 | |||||
| \(\pm\) 0.001 | |||||
| \(\pm\) 0.1 | |||||
| \(\pm\) 0.1 | |||||
| CIFAR-100-C (mean over corruptions) | |||||
| 3-chain | |||||
| \(\pm\) 0.13 | |||||
| \(\pm\) 0.009 | |||||
| \(\pm\) 0.001 | |||||
| \(\pm\) 0.3 | |||||
| \(\pm\) 0.2 | |||||
| SWA | |||||
| \(\pm\) 0.18 | |||||
| \(\pm\) 0.011 | |||||
| \(\pm\) 0.001 | |||||
| \(\pm\) 0.2 | |||||
| \(\pm\) 0.2 | |||||
| (SE1) | |||||
| \(\pm\) 0.05 | |||||
| \(\pm\) 0.003 | |||||
| \(\pm\) 0.001 | |||||
| \(\pm\) 0.2 | |||||
| \(\pm\) 0.1 | |||||
0.5em
Comparison to stochastic gradient Monte Carlo (SGMCMC) approximate posteriors. Our SE1 is closer to HMC than published results [16] for SGMCMC methods in terms of accuracy, loss, ECE, agreement, variance. SE1 also provides closer posteriors to HMC for CIFAR-10-C evaluations, while also being more computationally efficient.
We introduced a variational ansatz for stochastic ensembles of neural networks. Common Bayesian posterior approximations such as regular deep ensembles, Monte Carlo dropout and DropConnect can all be formulated as special cases of these distributional families. Our theoretical and numerical results suggest that the ensembles of stochastic neural networks can provide more accurate approximations to the Bayesian posteriors than other baseline methods.
Using our variational ansatz we formulated a new type (SE3) of non-parametric stochastic method that can be applied to any layer type with only minor changes to incorporate parameter sharing between ensemble members. For a simple toy model, we showed with HMC sampling of the Bayesian posterior that our SE3 ensembles provide closer posteriors to HMC than all other considered ensemble methods.
We evaluated accuracy, loss, ECE, ODD, entropy, agreement, variance and robustness to distribution shift for a ResNet-20-FRN architecture using different types of ensembles in image classification tasks on CIFAR. We found that our dropout stochastic ensembles (SE1) are closer to the HMC posteriors than all other methods considered.
In each of our numeric tests, all the stochastic methods were manually tuned except non-parametric dropout. To understand better what hyperparameters and stochastic method to use for achieving the most accurate posterior approximations would be highly beneficial.
Acknowledgements. OB was supported by the Knut and Alice Wallenberg Foundation and the Swedish Research Council (grant 2017-05162). HL and BM were supported by Vetenskapsrådet (grants 2017-3865 and 2021-4452).
There are examples of closed-form solutions for small↩︎