Approximate Message Passing for Bayesian Neural Networks

Romeo Sommerfeld, Christian Helms, Ralf Herbrich · DOI

Abstract

Bayesian Neural Networks (BNNs) provide a robust framework for capturing epistemic uncertainty, yet scaling them to modern architectures remains a significant challenge. This work introduces a scalable Message Passing (MP) framework that treats BNNs as factor graphs. By deriving novel message equations and implementing a batching strategy that avoids data "double-counting," we demonstrate the first MP method capable of training convolutional neural networks (CNNs). Our approach achieves state-of-the-art calibration and reliable uncertainty quantification, offering a deterministic and scalable alternative to Variational Inference.

Introduction

Deep learning models often exhibit overconfidence, leading to "confidently wrong" predictions in ambiguous or out-of-distribution scenarios. While BNNs offer a solution by modeling distributions over weights, existing inference methods face steep trade-offs. Markov Chain Monte Carlo (MCMC) methods provide high-quality posteriors but are computationally prohibitive. Variational Inference (VI) is scalable but prone to posterior collapse and sensitive to hyperparameter tuning.

Previous attempts at Message Passing for BNNs failed to scale to complex architectures like CNNs and suffered from "double-counting" data—a phenomenon where training points are treated as new information in every epoch, leading to extreme overconfidence. This paper addresses these limitations by providing a deterministic, scalable MP framework with reliable uncertainty estimates.

Methodology

The core of our approach is modeling the BNN as a factor graph, where weights and activations are random variables connected by factors representing mathematical operations such as addition, multiplication, and nonlinearities.

Factor graph representation of a BNN showing weights, activations, and message flow.

Gaussian Message Approximation

We approximate messages as one-dimensional Gaussians using a natural parameterization (precision and precision-mean) to enhance numerical stability. We derive specific message equations for various factors, including weighted sums and nonlinearities like LeakyReLU. For non-integrable functions, moment matching is employed to find the optimal Gaussian approximation.

The "Double-Counting" Fix and Trainer Object

A critical innovation is the handling of cycles in the neural network graph via Loopy Belief Propagation. To prevent the overconfidence caused by double-counting data across epochs, we introduce a Trainer object. This object stores aggregated messages from previous batches. When a batch is revisited, the framework "divides out" the old information before "multiplying in" the new update, ensuring a proper Bayesian update.

The Trainer object and batching strategy designed to prevent data double-counting.

Experimental Results

We evaluated our framework on synthetic data, CIFAR-10, and SVHN (for out-of-distribution detection).

Performance and Calibration

On CIFAR-10, our MP method achieved an accuracy of 77.3%, comparable to state-of-the-art Bayesian optimizers like IVON (77.2%) and standard AdamW (78.3%). Notably, the MP method significantly outperformed others in Expected Calibration Error (ECE), achieving 0.029 compared to AdamW's 0.046 and IVON's 0.035. This indicates that the predicted probabilities are much more representative of the actual likelihood of correctness.

Uncertainty Quantification

Using a synthetic sine curve dataset, we observed a 0.90 correlation between the model's predicted credible intervals and the actual probability of the true function falling within those intervals. Furthermore, the method successfully scaled to a Multi-Layer Perceptron (MLP) with 5.6 million parameters, demonstrating its viability for large-scale problems.

Discussion and Future Work

While promising, the current implementation has limitations. Training is currently 1-2 orders of magnitude slower than deterministic methods and more memory-intensive due to the need to store means and variances for all parameters. Additionally, the framework does not yet support residual connections or normalization layers, and it relies on FP64 precision for stability.

Future work will focus on extending the library to support Transformers (requiring a "softargmax" factor) and exploring applications in continual and reinforcement learning.

Summary updated

BibTeX
@misc{sommerfeld2025approximate,
  author = {Romeo Sommerfeld and Christian Helms and Ralf Herbrich},
  title = {{Approximate Message Passing for Bayesian Neural Networks}},
  year = {2025},
  eprint = {2501.15573},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.15573},
}
Figure