Manuscript Offprint
arXiv:2611.26426Exact Bayesian layers via characteristic functions
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Bayesian neural networks provide principled uncertainty estimates, but training them with Monte Carlo sampling can be expensive. Sampling-free variational inference algorithms make training Bayesian neural networks feasible, but existing approaches assume a Gaussian output distribution, which can be inaccurate in applied problems. Here, we introduce CF-Prop, an uncertainty propagation method that uses characteristic functions to compute the exact output distribution of a Bayesian ReLU layer, without any sampling, even for non-Gaussian predictive densities. Because CF-Prop propagates characteristic functions, the evidence lower bound—the objective of variational training—can be computed in closed form for a broad class of likelihoods, including the Gaussian, Poisson, and Gamma. This allows us to implement an efficient variational inference algorithm, CF-VI. On CIFAR-100, CF-VI achieves the lowest calibration error of any tested method, improving on the next best method by about 35%. On a heavy-tailed insurance claim dataset, CF-VI accurately captures tail uncertainty that is severely underestimated by both other sampling-free methods and Monte Carlo methods.
1 Introduction
Neural networks are the least reliable when training data is scarce. Bayesian Neural Networks (BNNs) offer a principled way to deal with the fundamental uncertainty of this data regime (Mitros and Mac Namee, 2019; Kristiadi et al., 2020). They quantify both epistemic uncertainty, which arises from limited knowledge of the model, and aleatoric uncertainty, which is due to the inherent randomness of the data-generating process. They excel in high-stakes, safety-critical applications (Ghoshal et al., 2021; Ding et al., 2021), perform well with limited data, prevent overfitting (Depeweg et al., 2018), and can increase fairness and reduce bias (Doherty et al., 2023).
BNNs quantify epistemic uncertainty by introducing a posterior distribution over the model parameters , given training data . Propagating this uncertainty to the output is required for training and inference. Stochastic methods, such as Bayes by Backprop (Graves, 2011; Blundell et al., 2015), estimate it by sampling weights. Sampling-free methods, such as Deterministic Variational Inference (DVI) (Wu et al., 2019), CovProp (Wright et al., 2024), and Variational Bayesian Last Layers (VBLL) (Harrison et al., 2024), replace sampling with moment propagation, which removes noise at the cost of assuming a specific functional form for the pre-activations.
We argue that these methods break down exactly where uncertainty quantification matters most. Indeed, DVI, CovProp and VBLL assume that the predictive distribution and the variational family are Gaussians. However, many applied problems require accurate estimates of tail probabilities—the probability of a 100-year flood or a multi-million-dollar insurance claim—for distributions that are often far from Gaussian. This Gaussian assumption shows up in two places in these methods: the likelihood, which captures aleatoric uncertainty, and the distribution of the network, which captures epistemic uncertainty. But in practice, the likelihood can be skewed, in Gamma regressions for claim sizes, for example. And the distribution of the network output also tends to be skewed in these cases, because tail predictions are often dominated by a few rarely active neurons. Hence, non-Gaussian variational families are required to properly handle these cases. Any propagation method that models either distribution as Gaussian can severely underestimate tail risk. In practice, the BNN literature uses many other variational families: spike-and-slab families for sparsification (Hubin and Storvik, 2019), scale mixtures for shrinkage (Louizos et al., 2017; Ghosh et al., 2019), and multimodal mixtures (Dusenberry et al., 2020; Miller et al., 2017)—though current sampling-free propagation methods are incompatible with these families.
We introduce CF-Prop, an exact and sampling-free method for uncertainty propagation in a single-layer Bayesian perceptron that uses characteristic functions (CF). The forward pass of the layer is expressed in the Fourier domain, making the predictive density tractable. We use this propagation algorithm as the backbone of a new method, Variational Inference via Characteristic Functions (CF-VI). CF-VI extends sampling-free variational inference beyond the Gaussian regime by expressing the predictive density of the Bayesian layer exactly and in closed form. It allows for both non-Gaussian predictive distributions and non-Gaussian variational families. It can accommodate any likelihood and any variational family with a tractable characteristic function.
CF-VI can be used to train a fully exact Bayesian perceptron or as an exact Bayesian last layer on a sampling-free or stochastic trunk. We show that CF-VI performs well on traditional benchmarks such as UCI regressions, and provides state-of-the-art uncertainty quantification on classification tasks with a large number of labels such as CIFAR-100. We also show that CF-VI performs exceptionally well in uncertainty quantification for neural GLMs commonly used in the actuarial sciences. In particular, we show that for a Gamma regression task on heavy-tailed data—predicting the size of insurance claims—other methods severely underestimate uncertainty in the tails of the distribution. In contrast, our method provides an exact description of the tail uncertainty. CF-VI is also computationally efficient: In many common cases, it adds only a modest overhead to the training of a fully deterministic neural network.
Our contributions are as follows:
- An exact expression for the output distribution of a Bayesian ReLU layer using characteristic functions.
- CF-VI, a sampling-free variational inference method compatible with any mean-field variational family and a broad class of likelihoods.
- Lower training and inference cost than other sampling-free methods on UCI benchmarks, at comparable NLL.
- The best calibration among tested methods on CIFAR-100.
- Accurate tail uncertainty on heavy-tailed regression, where other tested methods underweight tail risk.
Directly calculating the probability density function of the activations of a BNN is so computationally expensive that it is rarely implemented. Instead, training and inference of BNNs rely on stochastic sampling (Graves, 2011; Blundell et al., 2015) or sampling-free approximations. We review sampling-free methods below.
2.1 Moment propagation
Even when the full density is intractable, its moments might be easy to compute. Moment propagation methods derive exact or approximate expressions for the moments of the activations of a single hidden layer, then moment-match, assuming that the distribution of the activations is well described by a Gaussian sharing these moments.
Two methods are relevant here: deterministic variational inference (DVI) and covariance propagation (CovProp). Wu et al. (2019) develop DVI expressions for the first and second moments of the activation distribution and derive an asymptotic approximation for the correlation between activations. DVI generally tracks the full covariance structure among all hidden units, with complexity. A diagonal method (dDVI) can also be implemented by ignoring covariance, reducing DVI’s cubic complexity with layer width to linear complexity.
Wright et al. (2024) extend this work. CovProp expresses the moments as a power series in the correlation coefficient. The resulting method can, in principle, attain an arbitrarily accurate representation of the first two moments, provided that enough terms are computed in the power series. In practice, CovProp requires at least 4 terms to outperform DVI.
Both DVI and CovProp can be applied to arbitrarily deep networks, although approximation error compounds for deeper networks: even after 5 layers, DVI’s predictive distribution is distorted significantly. Competitive benchmark performance is attained only for very shallow networks of 1 or 2 layers (Wu et al., 2019).
2.2 Variational Bayesian last layers
Variational Bayesian last layers (VBLLs) (Harrison et al., 2024) are another sampling-free approach. This is an example of Bayesian last-layer methods (Kristiadi et al., 2020), which have many of the benefits of a fully Bayesian neural network. They use a deep deterministic “trunk” to generate low-dimensional features, which are then fed as inputs to a shallow Bayesian network. VBLLs are a sampling-free variational approach where only the linear readout is Bayesian.
While VBLLs are efficient, they have limited expressiveness. VBLLs capture uncertainty only in the linear readout; they cannot account for uncertainty through a full non-linear layer. Like moment propagation methods, VBLLs restrict the predictive distribution of the output to a Gaussian, and thus cannot account for any skew or heavy tails. A VBLL classifier, for example, can only express uncertainty around decision boundaries that are linear in the learned features. While highly efficient, the linear method cannot properly forecast uncertainty when data is sparse.
2.3 Failure of Gaussian assumptions
Moment propagation is a good approximation only when two assumptions hold: the likelihood is Gaussian, and the latent predictive distribution is Gaussian. Many common scenarios violate one or both, including typical configurations of the UCI regression benchmarks frequently used to evaluate Bayesian neural networks.
First, we consider the assumption that the likelihood is Gaussian. If it is not, the expected log-likelihood is no longer determined by the first two moments of . For the Poisson and Gamma likelihoods with a log link, the expectation contains exponential moments, and . These are sensitive to the tails and only weakly constrained by the first two moments.
The second assumption, that the latent predictive is Gaussian, rests on the central limit theorem. When the linear readout sums many weakly correlated activations together, the predictive will be approximately Gaussian. Wu et al. (2019) argue that the correlation between hidden units remains weak enough during training for this to hold approximately, and in a heteroscedastic regression with two hidden layers of 128 units they show close agreement between the Monte Carlo sampled and the moment-matched Gaussian activations. However, many commonly used architectures have last layers with fewer than 128 units: the network used later in the same paper for the UCI regression benchmark has a single hidden layer of 50 units.
Layers of this size (50 units) show meaningfully non-Gaussian predictive distributions, especially in the tails. In Figure 1, we train networks with a deterministic hidden layer followed by a Bayesian hidden layer using CF-VI with a mean-field Gaussian family, varying the layer’s width from 8 to 256 units, and apply CF-Prop, DVI, and CovProp to the same trained network to isolate the differences that can be attributed to propagation alone. All methods model the mean correctly, but DVI and CovProp underestimate the tails. Averaged over test inputs, their error is small, but at individual inputs it can be large. At the width of the example in Wu et al. (2019) (128 units), the average total variation between DVI and Monte Carlo is 0.017, while its worst case over inputs is 0.064. CF-Prop matches the Monte Carlo baseline throughout.
The worst-case failures occur where training data is scarce. Figure 3 below shows that moment propagation works well in distribution but fails to generalize correctly. Moment propagation is thus liable to fail in low-data regimes, where epistemic uncertainty quantification is most important.
3 CF-Prop: Exact uncertainty propagation via characteristic functions
Figure 1: Predictive tails are non-Gaussian for moderate-width networks. A network with two hidden layers of units each (a deterministic layer followed by a Bayesian layer) is trained on UCI Energy with a 90/10 held-out split, using CF-VI with a mean-field Gaussian variational family and prior and a Gaussian likelihood. 20 networks are trained per width. Top: z-scored predictive density of CF-Prop (purple), DVI (teal, solid), CovProp (teal, dashed), and Monte Carlo (grey) with layers of (a) 8, (b) 64, and (c) 256 units. The insets compare the tails up to from the mean. Bottom: Total variation (TV) distance between the sampling-free approximation and Monte Carlo predictions, showing (d) the mean (filled) and worst-case (maximum, open) TV over test points.
We develop an exact description of the predictive density for a perceptron with ReLU activations. We express the forward pass of a network in the Fourier domain via characteristic functions, the Fourier transforms of probability density functions. This approach builds on prior work from Pilipovsky et al. (2023), which expresses the action of the non-linear activation function in the Fourier domain using Hilbert transforms. That work was focused on the output density of a deterministic perceptron with random input. Here, we adapt the method to calculate the predictive density of a random network with a deterministic input. Our network consists of a hidden layer of ReLU units with random weights and biases, followed by a deterministic linear readout. It can be used on its own, as a trained perceptron, or as a Bayesian last layer.
3.1 Characteristic functions
Characteristic functions can be used to propagate the full distribution of uncertainty. The CF of a random variable is defined as:
where is a real number, and is the probability density function of . It uniquely characterizes the random variable .
The CF of a sum of independent random variables is the product of their CFs. Combined with the scaling rule for a constant , the CF of a linear combination of independent random variables is thus the product
3.2 Bayesian ReLU layer
We consider a single hidden layer with a deterministic linear readout,
where is the deterministic input to the layer, is an weight matrix, is an bias vector, and is the vector of pre-activations. The readout weights , an matrix, and bias , an vector, are deterministic, where is the dimension of the output.
We model the rows as mutually independent under , meaning that the pre-activations are independent given . When the entries within each row are also independent, as in a mean-field family, Eq. (2) gives the CF of the pre-activation of the th neuron:
3.3 Feeding the CF through ReLU activations
To go from pre-activations to the final readout, we must apply and feed the results through the linear readout. The non-linearity introduced by the ReLU poses a challenge when working with CFs, but it can be handled using Hilbert transforms of the CF, as shown by Pilipovsky et al. (2023).
More precisely, we find that the CF of the transformed pre-activation is:
where denotes the Hilbert transform, i.e., the convolution of with the function , known as a Cauchy kernel. See Appendix A for details.
Since depends only on the weights and bias of unit , which are independent across units, the activations are independent given . Hence, we can apply Eq. (2) again, with the readout weights as the coefficients, to obtain the CFs of the outputs:
where is the CF of the deterministic bias .
Computations in this CF representation involve up to three steps: Evaluating the CFs of the weights, applying the Hilbert transforms in Eq. (5), and computing an inverse Fourier transform of to obtain the density of the output,
How many of these steps can be done in closed form depends on the choice of variational family. For some choices of weight distributions like the Gaussian, the first two steps are analytic (see Appendix A and the next section). For a general family, all three must be done numerically. Importantly, the layer can be trained on directly, with no Fourier inversion, for the common likelihoods treated in Sec. 4. The inversion in Eq. (7) is only required when the full density is needed for a calculation: for example, the selection criteria for points often depend on the full posterior predictive distribution rather than the first two moments.
Figure 2 showcases the flexibility of CF-Prop. We propagate uncertainty from three different variational families: a Gaussian, a discrete skewed categorical, and a mixture of skew-normals. In all three cases, CF-Prop produces an estimate of the predictive density in close agreement with the Monte Carlo estimates.
3.4 Closed-form weight distribution
Figure 2: Uncertainty propagation with CF-Prop across variational families. Top: Marginal density of a single weight for a Gaussian (left), skewed categorical (middle) and skew-normal mixture (right) family. The insets show the modulus of the CF of the weight, . Bottom: The resulting latent predictive density calculated with CF-Prop (purple) compared to Monte Carlo samples (grey, ). The insets show the modulus of the CF of the output, . In all three cases, the CFs and densities are computed numerically with Fast Fourier transforms and their inverse.
Equation (6) has a closed-form expression in certain cases. For instance, when the weights are Gaussian, the pre-activations are linear combinations of independent Gaussians, and thus follow a Gaussian distribution themselves. More precisely, if and , we have with
and . In this case, one can show from Eq. (5) that the CF of the activation is
where is the complementary error function, , extended to complex arguments (see Appendix A for details).
4 CF-VI: Variational Inference via Characteristic Functions
Figure 3: CF-VI improves epistemic uncertainty quantification in non-Gaussian regression problems. Synthetic data are generated as , where is random. Training pairs are censored in the region, and a network (deterministic ReLU layer of 32 units, Bayesian ReLU layer of 32 units, linear readout, heteroscedastic Gaussian likelihood) is trained on 30 pairs with CF-VI. (a) CF-VI, DVI, CovProp, and Monte Carlo sampling ( samples) are used to draw from the posterior predictive distribution of the same trained network. The discrepancy between the 99% credible interval and the Monte Carlo-sampled posterior, the reference, is shown as a shaded region for each method. The Monte Carlo reference is under the purple line. Inset: comparison of predictive distributions at . (b) Total variation distance between the sampling-free and the Monte Carlo predictive distributions, as a function of . Where training data is available, all three methods closely agree with the Monte Carlo estimate of the predictive density. In the censored region (grey band), however, only CF-VI agrees with the MC samples, while DVI and CovProp underestimate uncertainty.
In Sec. 3, we outlined a general method for uncertainty propagation with characteristic functions. We now use the method to build a variational inference algorithm for the Bayesian ReLU layer: CF-VI. We show how the exact expression for the output distribution yields an evidence lower bound (ELBO) that requires no sampling and is available in closed form for common likelihoods.
CF-VI improves epistemic uncertainty quantification in non-Gaussian settings. Figure 3 compares the predictions of CF-VI, DVI and CovProp for one network, trained with CF-VI, on a toy regression problem with a gap in the training inputs. Where training data is available, all three agree with the Monte Carlo reference. Out of sample, however, DVI and CovProp underestimate epistemic uncertainty, and only CF-VI remains in agreement with the reference.
4.1 Variational objective
Given a dataset , a likelihood and a prior , variational inference approximates the posterior with a distribution from a family by maximizing the ELBO (Blei et al., 2017):
The complexity cost can be calculated analytically for suitable choices of prior and variational family. For example, with the mean-field Gaussian family of Sec. 3.4 and an independent prior on each parameter, it is
where the sum is over all random weights and biases , and and are the variational mean and variance of parameter . For other mean-field families, the complexity cost is cheap to compute numerically.
The reconstruction cost is a high-dimensional integral over the weights. Because the likelihood depends on only through the network output , it can be rewritten as an integral over the output:
where is the distribution of the output induced by . Section 3 gives the CF of this distribution; we obtain from the CF using an inverse Fast Fourier Transform (IFFT), and evaluate the integral in Eq. (11) by quadrature. Both operations are differentiable, so the ELBO can be optimized by backpropagation. That said, for common likelihoods, the integral reduces to evaluations of the CF at a few points with no inversion, as we show next.
4.2 Closed-form reconstruction cost
For many likelihoods, we can circumvent the IFFT and quadrature by evaluating the reconstruction cost directly with the CF. This is because the CF can be used to obtain two kinds of expectations directly. Its derivatives at zero are the moments, , and its values on the imaginary axis give exponential moments, . Both are special cases of the relationship
which follows from differentiating the definition of the CF times. We call a likelihood an exponential-polynomial if its logarithm is a sum of such terms,
where is a non-negative integer, can be a complex number, and the coefficients do not depend on but may depend on . Applying Eq. (12) to the terms gives
so the ELBO can be computed with at most evaluations of Eq. (6) and its derivatives per data point, whenever Eq. (13) holds.
These likelihoods are exponential families whose natural parameters and log-partition function are exponential polynomials in . This exponential-polynomial family includes the Gaussian as a special case and, with a log link, the Poisson, the Gamma, the wider Tweedie family, and the Weibull. The categorical distribution commonly used in classification is, unfortunately, not part of this family, but following Harrison et al. (2024) we can derive a closed-form lower bound on the reconstruction cost, which we can optimize instead. These results are derived in Appendix B; see Table 1 for a summary.
Together with Eq. (10), our calculations yield an ELBO that can be computed in closed form for every exponential-polynomial likelihood, using only a small number of evaluations of the predictive CF and its derivatives.
Table 1: Reconstruction costs in terms of characteristic functions. We denote for simplicity. The Gamma likelihood is expressed with a log link with shape , and the Weibull uses a shape parameter .
| Likelihood | |
|---|---|
| Gaussian | |
| Poisson | |
| Gamma | |
| Weibull | |
| Categorical | |
| Any density |
5 Results
We evaluate CF-VI in three settings: a Gamma neural GLM for insurance claim severity (Sec. 5.1), the UCI regression benchmarks (Sec. 5.2), and classification with Bayesian heads on frozen CIFAR-10 and CIFAR-100 features (Sec. 5.3). On standard benchmarks, CF-VI matches or exceeds the best sampling-free methods at lower prediction and training cost. On the neural GLM task, it is the only tested method that does not underestimate the tail.
5.1 Case study: neural GLMs
Many applied problems use non-Gaussian likelihoods: Poisson and Gamma likelihoods for neural GLMs in actuarial science and forecasting (Noll et al., 2020; Wüthrich and Merz, 2023; Holvoet et al., 2025). Weibull likelihoods are used in neural survival analysis (Martinsson, 2017; Nagpal et al., 2021). All of these settings share heavy-tailed distributions where Gaussian approximations severely underestimate the risk of rare but catastrophic events.
Figure 4: CF-VI outperforms sampling-free methods for heavy-tailed uncertainty quantification. These results use the Gamma neural GLM of Sec. 5.1. (a) Log10 probability of a claim above 80,000 EUR as a function of the bonus-malus score. Monte Carlo estimates are calculated with and samples (averaged across 8 runs in the case). They converge to the CF-VI estimate slowly, and agree with DVI only when very few samples are used. (b) Held-out log-likelihood shortfall relative to CF-VI on the top 1% of claims, against prediction time (Monte Carlo: to ). (c) Held-out NLL minus that of CF-VI (median over 10 seeds). Monte Carlo uses samples.
We consider an example taken from the freMTPL2 claim severity dataset of French motor insurance (Noll et al., 2020). In this task, we predict the claim amount from policy features such as vehicle age and power, driver age, and location. The distribution of claim sizes is very heavy-tailed. As is typical for this setting, we use a Gamma likelihood with a network comprising one deterministic ReLU layer of 16 units, a Bayesian ReLU layer with 16 units and a mean-field Gaussian variational family, and a deterministic linear readout. We report scores on held-out test sets using 5-fold cross-validation. Where applicable, we train 10 random seeds per fold. The results are shown in Fig. 4.
DVI severely underestimates the weight of the tail, and Monte Carlo estimates take a long time to converge. Fig. 4a shows the log probability that the fitted model assigns to large claims, over 80,000 EUR. Holding all other features constant, we sweep the claim-history score (bonus-malus): a score below 100 indicates a driver with few previous claims, while a score above 100 indicates an accident-prone driver. For high-risk individuals (a score of 140), both DVI and Monte Carlo sampling with underestimate the probability of a claim above 80,000 EUR by a factor of . Only by dramatically increasing the number of samples to does the Monte Carlo estimate converge to the CF-VI estimate.
In Fig. 4b we evaluate the shortfall—the average difference in NLL between a method and CF-VI on the top 1% of claims by size—using Monte Carlo with to samples. Despite the nearly increase in time, the increased number of samples reduces the shortfall by only 36%, and at every sample size, MC performs worse than DVI.
CF-VI also outperforms Monte Carlo () and moment-propagation methods in terms of predictive performance. Fig. 4c shows the difference in held-out negative log-likelihood (NLL) between CF-VI and the other methods. CF-VI beats all competing methods by a median of 0.069 (DVI) to 0.115 (VBLL) nats per claim. Its lead is strengthened on the largest claims: on the top 0.1% of claims by size, CF-VI beats the other methods by 40.7 (DVI) to 89.6 (CovProp) nats per claim.
These results suggest CF-VI is valuable whenever forecasting tail risk is important, as in insurance claims, disaster forecasting, or survival analysis. CF-VI extends the use of Bayesian neural networks to these regimes.
5.2 Case study: UCI regression
Figure 5: Predictive performance versus cost on UCI regression. Average rank by test NLL across datasets (lower is better) against the cost (a) per training step and (b) per prediction of the test split. Costs are relative to CF-VI and measured on one CPU core.
Next, we compare our method to competing approaches on the UCI regression benchmarks. The sampling-free methods most comparable to ours are DVI, dDVI (Wu et al., 2019), CovProp (Wright et al., 2024), and VBLL (Harrison et al., 2024). We also include popular stochastic methods: Bayes by Backprop (BBB) (Blundell et al., 2015), deep ensembles (Lakshminarayanan et al., 2017), and MC-Dropout (Gal and Ghahramani, 2016; Le Folgoc et al., 2021). We use the same training and test methods as Wu et al. (2019) for DVI and as Wright et al. (2024) for CovProp.
Table 2: UCI Regression benchmark. We compute both the negative log-likelihood and the root mean square error on the test set, with standard errors. Methods above the bar are sampling-free, methods below are stochastic. The best overall method and the best sampling-free methods are highlighted for each dataset.
Test NLL () Boston Concrete Energy Kin8nm Naval Power Wine Yacht Avg. rank CF-VI DVI dDVI CovProp VBLL Deep ensemble MC-Dropout BBB
Test RMSE () Boston Concrete Energy Kin8nm Naval Power Wine Yacht Avg. rank CF-VI DVI dDVI CovProp VBLL Deep ensemble MC-Dropout BBB
We evaluate methods over 20 random 90/10 train/test splits for all UCI benchmarks. All networks consist of two hidden layers of 50 units on a heteroscedastic Gaussian likelihood that outputs both the prediction and a log-variance . Architectures are as follows:
- Full-covariance DVI, diagonal-covariance dDVI, and CovProp: two fully Bayesian layers and a deterministic readout, following the methods in the original papers.
- VBLL: two deterministic hidden layers with a VBLL readout.
- CF-VI: deterministic hidden layer followed by a Bayesian hidden layer for the prediction . A separate deterministic hidden layer is used for the log-variance.
Every variational method is trained with a mean-field Gaussian family with a standard normal prior. BBB and MC-Dropout predictions use 100 samples, and the deep ensemble has five members. Complete results are shown in Table 2.
Figure 5 shows the average predictive performance rank against cost per training step and per prediction for these methods. We find that CF-VI is among the most efficient, costing only about 1.8 times as much per training step as the same network without the Bayesian layer. Only MC-Dropout, which produces a much cruder uncertainty estimate, is cheaper but costs 40 times as much per prediction. In terms of performance, CF-VI ties with dDVI (avg rank 2.75) and is beaten by the deep ensemble (average rank 2.63), which costs 1.9 times as much per training step and per prediction. We note, however, that while CF-VI beats dDVI in cost, both algorithms have the same asymptotic complexity, and the efficiency difference likely reflects implementation details. That said, we note that we provide an exact estimate of the full posterior predictive distribution as efficiently as dDVI provides its first two moments.
5.3 Case study: Classification
Table 3: CIFAR classification benchmark. We show the mean expected calibration error (ECE), computed with 15 bins of equal width, the negative log-likelihood, and the accuracy for each method on CIFAR-100 and CIFAR-10, with standard deviations. Methods above the bar are sampling-free, methods below are stochastic. The best overall method and the best sampling-free methods are highlighted for each dataset.
CIFAR-100 CIFAR-10 Head ECE (%) NLL Acc. (%) ECE (%) NLL Acc. (%) CF-VI DNN VBLL Last-Layer Laplace DVI CovProp Deep ensemble MC-Dropout BBB
We next evaluate CF-VI on image classification, as a Bayesian head on a pretrained network. We use the same set of baselines, with some additions and modifications; we include a strong last-layer Laplace method (Daxberger et al., 2021), and adapt DVI and CovProp to work with a classification objective. Unlike in regression, where the output is deterministic, in classification deep neural networks also output a categorical distribution over classes, so they are meaningful comparators and included here. Finally, we use the discriminative version of the VBLL classifier introduced in Harrison et al. (2024).
For our trunk, we freeze a Wide ResNet-28-10 backbone (Zagoruyko and Komodakis, 2016) and train the methods as heads on its 640-dimensional features. The CF-VI head has one Bayesian hidden layer of 64 ReLU units, with a Gaussian variational family that has a full covariance over the incoming weights of each unit, and a prior on all weights. It is trained with the lower bound on the reconstruction cost given in Table 1. For the DNN, we use the same architecture but with a deterministic hidden layer.
Table 3 reports the results. On CIFAR-100, CF-VI has the lowest expected calibration error (ECE) of all methods: 3.1%, against 4.8% for the next best, Bayes by Backprop, a reduction of 35%. Its NLL and accuracy are also competitive. On CIFAR-10, all heads are well calibrated, and CF-VI does not perform as well. According to these experiments, the benefits of CF-VI are the most apparent in many-class problems.
6 Conclusion
We have used characteristic functions to derive an exact representation of the full predictive distribution of a Bayesian ReLU layer with a deterministic input and readout, and exact variational objectives for non-Gaussian likelihoods. As demonstrated on CIFAR heads on a Wide ResNet backbone and on freMTPL2, CF-VI excels as a Bayesian last layer on an ordinary deterministic network.
In many cases, our method both captures uncertainty more accurately and can be run more efficiently than existing methods for moment propagation, providing a new optimal balance of predictive performance and efficiency in traditional classification and regression benchmarks. It also extends sampling-free variational inference to non-Gaussian settings. On freMTPL2 insurance severity, CF-VI provided a far superior measure of tail uncertainty for rare but catastrophic predictions. In doing so, it unlocks the application of sampling-free Bayesian neural networks to many applied settings where uncertainty quantification is critical.
Our approach also extends sampling-free mean-field VI to many other variational families and likelihoods, making deterministic variational inference compatible with a much wider array of architectures and methods.
The greatest limitation of the current approach is its inability to capture correlations between activations. Future work may extend these results using low-rank covariance structure to efficiently and exactly track correlations between layers. This extension would be crucial in order to characterize the epistemic, out-of-distribution uncertainty, which mean-field variational families struggle to capture (Foong et al., 2019). Other integral transforms like the Mellin transform, in combination with similar low-rank correlation structures, may be able to describe the full forward pass of the network through many layers.
The present work provides a foundation and proof of concept for integral-transform and Fourier-domain expressions of Bayesian neural networks, which can make BNNs useful across a much wider range of fields.
7 Code Availability
The code for CF-Prop and CF-VI is available under an MIT license at https://github.com/WillHWThompson/cf-vi.
References
David M. Blei, Alp Kucukelbir, and Jon D. McAuliffe. Variational Inference: A Review for Statisticians. Journal of the American Statistical Association, 112(518):859–877, 2017. doi: 10.1080/01621459.2017.1285773.
Charles Blundell, Julien Cornebise, Koray Kavukcuoglu, and Daan Wierstra. Weight Uncertainty in Neural Networks. In Proceedings of the 32nd International Conference on Machine Learning, volume 37 of Proceedings of Machine Learning Research, pages 1613–1622. PMLR, 2015. URL https://proceedings.mlr.press/v37/blundell15.html.
Erik Daxberger, Agustinus Kristiadi, Alexander Immer, Runa Eschenhagen, Matthias Bauer, and Philipp Hennig. Laplace Redux - Effortless Bayesian Deep Learning. In Advances in Neural Information Processing Systems, volume 34, pages 20089–20103. Curran Associates, Inc., 2021. URL https://proceedings.neurips.cc/paper/2021/hash/a7c9585703d275249f30a088cebba0ad-Abstract.html.
Stefan Depeweg, José Miguel Hernández-Lobato, Finale Doshi-Velez, and Steffen Udluft. Decomposition of Uncertainty in Bayesian Deep Learning for Efficient and Risk-sensitive Learning. In Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 1184–1193. PMLR, 2018. URL https://proceedings.mlr.press/v80/depeweg18a.html.
Liuhui Ding, Dachuan Li, Bowen Liu, Wenxing Lan, Bing Bai, Qi Hao, Weipeng Cao, and Ke Pei. Capture Uncertainties in Deep Neural Networks for Safe Operation of Autonomous Driving Vehicles. In 2021 IEEE Intl Conf on Parallel & Distributed Processing with Applications, Big Data & Cloud Computing, Sustainable Computing & Communications, Social Computing & Networking (ISPA/BDCloud/SocialCom/SustainCom), pages 826–835. IEEE, 2021. doi: 10.1109/ISPA-BDCloud-SocialCom-SustainCom52081.2021.00118.
Alice Doherty, Matthew Wicker, Luca Laurenti, and Andrea Patane. Individual Fairness in Bayesian Neural Networks. arXiv preprint arXiv:2304.10828, 2023.
Michael Dusenberry, Ghassen Jerfel, Yeming Wen, Yian Ma, Jasper Snoek, Katherine Heller, Balaji Lakshminarayanan, and Dustin Tran. Efficient and scalable Bayesian neural nets with rank-1 factors. In Proceedings of the 37th International Conference on Machine Learning, volume 119 of Proceedings of Machine Learning Research, pages 2782–2792. PMLR, 2020. URL https://proceedings.mlr.press/v119/dusenberry20a.html.
Andrew Y. K. Foong, Yingzhen Li, José Miguel Hernández-Lobato, and Richard E. Turner. ‘In-Between’ Uncertainty in Bayesian Neural Networks. arXiv preprint arXiv:1906.11537, 2019.
Yarin Gal and Zoubin Ghahramani. Dropout as a Bayesian approximation: Representing model uncertainty in deep learning. In Proceedings of the 33rd International Conference on Machine Learning, volume 48 of Proceedings of Machine Learning Research, pages 1050–1059. PMLR, 2016.
Soumya Ghosh, Jiayu Yao, and Finale Doshi-Velez. Model selection in Bayesian neural networks via horseshoe priors. Journal of Machine Learning Research, 20(182):1–46, 2019.
Biraja Ghoshal, Allan Tucker, Bal Sanghera, and Wai Lup Wong. Estimating uncertainty in deep learning for reporting confidence to clinicians in medical image segmentation and diseases detection. Computational Intelligence, 37(2):701–734, 2021. doi: 10.1111/coin.12411.
Alex Graves. Practical Variational Inference for Neural Networks. In Advances in Neural Information Processing Systems, volume 24, 2011.
James Harrison, John Willes, and Jasper Snoek. Variational Bayesian last layers. In International Conference on Learning Representations, 2024.
Freek Holvoet, Katrien Antonio, and Roel Henckaerts. Neural networks for insurance pricing with frequency and severity data: A benchmark study from data preprocessing to technical tariff. North American Actuarial Journal, 29(3):519–562, 2025. doi: 10.1080/10920277.2025.2451860.
Aliaksandr Hubin and Geir Storvik. Combining Model and Parameter Uncertainty in Bayesian Neural Networks. arXiv preprint arXiv:1903.07594, 2019.
Agustinus Kristiadi, Matthias Hein, and Philipp Hennig. Being Bayesian, Even Just a Bit, Fixes Overconfidence in ReLU Networks. In Proceedings of the 37th International Conference on Machine Learning, volume 119 of Proceedings of Machine Learning Research, pages 5436–5446. PMLR, 2020. URL https://proceedings.mlr.press/v119/kristiadi20a.html.
Balaji Lakshminarayanan, Alexander Pritzel, and Charles Blundell. Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles. In Advances in Neural Information Processing Systems, volume 30, 2017.
Loïc Le Folgoc, Vasileios Baltatzis, Sujal Desai, Anand Devaraj, Sam Ellis, Octavio E. Martinez Manzanera, Arjun Nair, Huaqi Qiu, Julia Schnabel, and Ben Glocker. Is MC Dropout Bayesian? arXiv preprint arXiv:2110.04286, 2021.
Christos Louizos, Karen Ullrich, and Max Welling. Bayesian compression for deep learning. In Advances in Neural Information Processing Systems, volume 30, 2017.
Egil Martinsson. WTTE-RNN: Weibull time to event recurrent neural network. Master’s thesis, Chalmers University of Technology, 2017.
Andrew C. Miller, Nicholas J. Foti, and Ryan P. Adams. Variational boosting: Iteratively refining posterior approximations. In Proceedings of the 34th International Conference on Machine Learning, volume 70 of Proceedings of Machine Learning Research, pages 2420–2429. PMLR, 2017. URL https://proceedings.mlr.press/v70/miller17a.html.
John Mitros and Brian Mac Namee. On the Validity of Bayesian Neural Networks for Uncertainty Estimation. In Proceedings of the 27th AIAI Irish Conference on Artificial Intelligence and Cognitive Science (AICS 2019), volume 2563 of CEUR Workshop Proceedings, pages 140–151, 2019. URL https://ceur-ws.org/Vol-2563/aics_15.pdf.
Chirag Nagpal, Xinyu Li, and Artur Dubrawski. Deep survival machines: Fully parametric survival regression and representation learning for censored data with competing risks. IEEE Journal of Biomedical and Health Informatics, 25(8):3163–3175, 2021. doi: 10.1109/JBHI.2021.3052441.
Alexander Noll, Robert Salzmann, and Mario V. Wüthrich. Case study: French motor third-party liability claims. SSRN 3164764, version of 4 March 2020, 2020.
Joshua Pilipovsky, Vignesh Sivaramakrishnan, Meeko Oishi, and Panagiotis Tsiotras. Probabilistic Verification of ReLU Neural Networks via Characteristic Functions. In Proceedings of the 5th Annual Learning for Dynamics and Control Conference, volume 211 of Proceedings of Machine Learning Research, pages 966–979. PMLR, 2023. URL https://proceedings.mlr.press/v211/pilipovsky23a.html.
Oren Wright, Yorie Nakahira, and José M. F. Moura. An analytic solution to covariance propagation in neural networks. In Proceedings of the 27th International Conference on Artificial Intelligence and Statistics, volume 238 of Proceedings of Machine Learning Research, pages 4087–4095. PMLR, 2024. URL https://proceedings.mlr.press/v238/wright24a.html.
Anqi Wu, Sebastian Nowozin, Edward Meeds, Richard E. Turner, José Miguel Hernández-Lobato, and Alexander L. Gaunt. Deterministic Variational Inference for Robust Bayesian Neural Networks. In International Conference on Learning Representations, 2019. URL https://openreview.net/forum?id=B1l08oAct7.
Mario V. Wüthrich and Michael Merz. Statistical Foundations of Actuarial Learning and its Applications. Springer Actuarial. Springer, 2023. doi: 10.1007/978-3-031-12409-9.
Sergey Zagoruyko and Nikos Komodakis. Wide residual networks. In Proceedings of the British Machine Vision Conference (BMVC), pages 87.1–87.12. BMVA Press, 2016. doi: 10.5244/C.30.87.
Appendix A Derivation of the ReLU characteristic function
This appendix derives Eq. (5) and its closed form for Gaussian pre-activations, Eq. (8). Throughout, is a random variable with density and CF .
A.1 Characteristic function of the rectified variable
We start by splitting the density of into the positive and negative parts of its support,
where is the Heaviside step function, which can be written as , giving
The first term of Eq. (14) straightforwardly has the transform
so most of the difficulty comes from the second term.
We use the Hilbert transform to compute this second term. When applied to the CF, the Hilbert transform multiplies the density by ,
Hence, we can see that the Fourier transform of is . This lets us define the following quantities for the two parts of Eq. (14):
With these results in place, we can then compute the CF of the rectified variable . The ReLU activation maps the negative part of the support of to a point mass at zero, with weight . Noting that
since at , the CF of the rectified variable is given by
Finally, since , we obtain Eq. (5) of the main text:
A.2 Gaussian pre-activations
When the pre-activation is Gaussian, the Hilbert transforms in Eq. (15) can be calculated in closed form. The CF of a Gaussian pre-activation is
where and are the mean and variance of the pre-activation, and where we have dropped the unit index for the sake of simplicity. Completing the square in the exponent gives
Written in this form, is a Gaussian, which has a known Hilbert transform
where
is the Dawson function.
The characteristic function in Eq. (16) is shifted and rescaled from . More precisely, we have that , where , which shows that is rescaled by a factor of and shifted by . These operations commute with the Hilbert transform, and the transform of is therefore
where the leading term, , is the constant in Eq. (16), which passes through the transform by linearity. Next, we use the identity
to obtain
which reduces to at , since . Substituting both expressions into Eq. (15) and grouping like terms then yields
Finally, we obtain Eq. (8) of the main text by using , and the fact that is an odd function, allowing us to simplify the two brackets as:
This expression can be numerically unstable for large , because and can individually underflow and overflow, even as their product remains finite. Instead, our implementation uses the Faddeeva function
to compute the product directly. We find
which can equivalently be written as
using the reflection identity . In practice, we use the first form when and the second when , so that the argument of always falls in the upper half-plane, where is bounded.
Appendix B Derivation of the reconstruction costs
In this appendix, we derive the reconstruction costs shown in Table 1. To simplify the notation, we write for , for , and for the expectation under throughout the calculation. The calculations below use the following three expectations, which are all consequences of Eq. (12) in the main text:
In all cases, the idea is to first compute the log-likelihood of the data for random outputs , and to then take an expectation over , substituting terms using Eq. (19).
B.1 Exponential-polynomial likelihoods
For exponential-polynomial likelihoods conforming to Eq. (13), the reconstruction cost can be computed exactly using the characteristic function and its derivatives, typically with only a few terms.
Gaussian.
For a Gaussian likelihood with variance , the log-likelihood is . Expanding the square and applying Eq. (19) gives
Poisson.
For a Poisson likelihood with a log link, the rate is and the log-likelihood is , so we directly have
Gamma.
For a Gamma likelihood with shape and mean , the log-likelihood is , so we directly have
Weibull.
For a Weibull likelihood with shape and scale , the log-likelihood is , so we directly have
General exponential families.
The same computation can be applied to many exponential families. In the parametrization in terms of sufficient statistics , natural parameters , and log-partition function , the expected log-likelihood is
When and all the natural parameters are sums of terms , the expectation has a closed form.
B.2 Categorical likelihood
In classification problems, the output label is drawn from a categorical distribution whose probabilities are the softmax of the network outputs. Hence, the likelihood can be calculated as . This likelihood is, unfortunately, not an exponential-polynomial, because the logarithm of a sum of exponentials cannot be rewritten as a finite sum of terms of the form .
Instead, following Harrison et al. [2024], we obtain a lower bound on the expected log-likelihood, using Jensen’s inequality:
The bound moves the expectation inside the logarithm, where the terms involve a single output and are given exactly by Eq. (19). Applying Eq. (19) to the lower bound then gives
B.3 General likelihoods
When the reconstruction cost has no closed form, we must invert the CF on a grid with Eq. (7) and evaluate the integral in Eq. (11) by quadrature:
Gradients can be taken through this deterministic transformation. We use an adaptive grid of points spanning standard deviations around the mean of , which can lead to mild numerical artifacts for heavy-tailed output distributions.