On the Robustness of Bayesian Neural Networks to Adversarial Attacks

Luca Bortolussi, Ginevra Carbone, Luca Laurenti, Andrea Patane, Guido Sanguinetti, Matthew Wicker

TL;DR

This paper provides a mathematical foundation for why Bayesian Neural Networks (BNNs) are inherently more robust to adversarial attacks than their deterministic counterparts. By treating weights as distributions rather than points, BNNs cause the malicious gradients used by attackers to "cancel out" in the infinite-width limit, potentially resolving the long-standing trade-off between model accuracy and robustness.

What Problem Does This Paper Address?

Deep learning models are notoriously brittle. A tiny, imperceptible change to an image (an adversarial perturbation) can cause a state-of-the-art classifier to fail catastrophically. Most of these attacks work by following the "gradient" of the loss function—essentially finding the direction in the input space that most quickly confuses the model.

Researchers have long suspected that data actually lives on low-dimensional "manifolds" (like a 2D sheet of paper crumpled up in a 3D room). Adversarial attacks usually exploit the "empty" space orthogonal to this manifold. While empirical evidence suggested that Bayesian Neural Networks—which maintain an ensemble of possible models rather than just one—were more robust, we lacked a rigorous mathematical explanation for why. This paper aims to bridge that gap by analyzing the geometry of these attacks in the limit of infinitely wide networks.

Methods

The authors combine differential geometry with Bayesian probability to analyze BNN behavior. Their approach involves three key steps:

  1. Symmetry Analysis: They prove a "symmetry property" showing that for any infinitely wide neural network with a specific gradient in a direction orthogonal to the data manifold, there exists another network with the same loss but the exact opposite gradient.
  2. Gaussian Process Convergence: They leverage the fact that as BNNs become infinitely wide, they converge to Gaussian Processes (GPs). This allows them to use the analytical tools of GPs to study the expected gradients of the model.
  3. Bayesian Averaging: They prove that when you average the gradients over the BNN posterior distribution, the components of the gradient that point away from the data manifold (the ones attackers use) vanish to zero.

The authors tested these theories using two main inference methods: Hamiltonian Monte Carlo (HMC), which is computationally expensive but provides highly accurate posterior samples, and Variational Inference (VI), a faster but less precise approximation.

Datasets

The theoretical findings were validated on several benchmarks:

  • Synthetic "Half Moons" and 2D Regression: Used to visualize how gradients behave when the data manifold is known exactly (e.g., a simple line $x_1 = x_2$).
  • MNIST: The classic dataset of handwritten digits.
  • Fashion MNIST: A more complex dataset of clothing items used to test if the robustness holds as the classification task gets harder.

Key Insights and Ideas

  • The Vanishing Gradient: The most striking insight is that in the over-parameterized limit, the expected gradient of the BNN loss function becomes zero in directions orthogonal to the data. Essentially, the "wrong" directions of different models in the Bayesian ensemble cancel each other out.
  • Accuracy and Robustness are Friends (in BNNs): In standard deep learning, there is a famous "robustness-accuracy trade-off"—making a model harder to attack usually makes it less accurate. The authors find that for BNNs (especially those trained with HMC), the opposite is true: as the network gets wider and more accurate, it actually becomes more robust.
  • Uncertainty is the Key: The robustness isn't just a trick of the architecture; it’s a direct result of marginalizing over uncertainty. When the model is uncertain (which it is in the "empty" space off the data manifold), the average gradient disappears, leaving the attacker with no clear direction to follow.

Key Results

  • Empirical Robustness: On MNIST, a BNN trained with HMC achieved 87.6% robustness against FGSM (a common gradient-based attack), compared to just 37.6% for a standard deterministic network trained with SGD.
  • Gradient Convergence: The authors demonstrated that as you increase the number of samples from the BNN posterior, the magnitude of the input gradient consistently drops, confirming their "vanishing gradient" theory.
  • Gradient-Free Attacks: Even when using "Zero-Order Optimization" (ZOO) attacks—which don't rely on the model's internal gradients—BNNs remained significantly more robust than deterministic models, suggesting the benefit is fundamental to the predictive distribution, not just a result of "obfuscated gradients."

Limitations and Future Work

  • The Infinite Limit: The core proofs rely on the "infinitely wide" limit. While the authors show this holds well for finite networks, the mathematical guarantee is strongest for theoretical models that are impossible to build in reality.
  • Linear Subspaces: Some proofs assume the data manifold is a linear subspace. While the authors argue this approximates local manifold behavior, extending the proof to more complex, non-linear geometries is an open challenge.
  • The Cost of HMC: The most robust results came from HMC, which is notoriously difficult to scale to large, modern architectures like Transformers or deep ResNets.
  • Variational Inference Gap: The "cheaper" VI methods were less robust than HMC because they tend to under-estimate uncertainty. Improving approximate inference is essential for bringing this robustness to real-world production models.

Summary updated

BibTeX
@article{bortolussi2024robustness,
  author = {Luca Bortolussi and Ginevra Carbone and Luca Laurenti and Andrea Patane and Guido Sanguinetti and Matthew Wicker},
  title = {{On the Robustness of Bayesian Neural Networks to Adversarial Attacks}},
  journal = {IEEE Transactions on Neural Networks and Learning Systems},
  year = {2024},
  doi = {10.1109/tnnls.2024.3386642},
}
Figure