Robust simulation-based inference in cosmology with Bayesian neural networks

Pablo Lemos, Miles D. Cranmer, Muntazir Abidi, ChangHoon Hahn, Michael Eickenberg, Elena Massara, David Yallup, Shirley Ho · DOI

Abstract

Simulation-based inference (SBI) has emerged as a critical technique in modern cosmology for handling complex likelihoods. However, SBI models often exhibit overconfidence when training simulations fail to account for real-world systematics. This paper introduces cosmoSWAG, an implementation of Bayesian Neural Networks (BNNs) using Stochastic Weight Averaging-Gaussian (SWAG). By marginalizing over the posterior distribution of neural network weights, cosmoSWAG ensures more robust and "honest" uncertainty estimates. When tested against synthetic data with unmodeled systematics, the method successfully avoids the precise but biased results typical of standard SBI, offering a path toward more reliable cosmological inference.

Introduction

In contemporary cosmology, the "likelihood"—the probability of observing specific data given a set of physical parameters—is often too complex to compute analytically. This has led to the rise of Simulation-Based Inference (SBI), or likelihood-free inference. In this paradigm, neural networks are trained on large suites of simulations to learn the mapping between cosmological parameters and observables.

Despite its power, SBI faces a significant "generalization" challenge. Simulations are rarely perfect; they often omit instrumental errors or subtle physical effects known as systematics. When a standard neural network trained on idealized simulations encounters real-world data with these unmodeled effects (a "covariate shift"), it tends to be "confidently wrong," producing narrow posterior distributions that exclude the true parameter values.

Methodology: cosmoSWAG and BNNs

To address the issue of overconfidence, the authors propose cosmoSWAG, which integrates Stochastic Weight Averaging (SWA) into the Density Estimation Likelihood-Free Inference (DELFI) framework.

Stochastic Weight Averaging (SWA) and SWAG

Standard training typically selects the final set of weights that minimizes a loss function. In contrast, SWA averages the weights across the final stages of the training trajectory. SWAG (SWA-Gaussian) extends this by treating the averaged weights and their variance as a Gaussian distribution. This transformation effectively turns a deterministic neural network into a Bayesian Neural Network (BNN).

Inference Framework

The authors utilize Mixture Density Networks (MDNs) to estimate the posterior distribution of cosmological parameters. By marginalizing over the distribution of network weights provided by SWAG, the model accounts for epistemic uncertainty (uncertainty in the model itself). This marginalization leads to wider, more conservative posterior distributions when the input data deviates from the training set.

Experimental Design

The method was evaluated using simulated Cosmic Microwave Background (CMB) power spectra.

  • Training Set: 100,000 simulations generated using the CAMB (Code for Anisotropies in the Microwave Background) software.
  • Ground Truth: The Planck 2018 TT likelihood was used as a reference to ensure the SBI method could recover standard results under ideal conditions.
  • Synthetic Systematics: To test robustness, the authors created "corrupted" datasets by adding Gaussian noise at high multipoles ($\ell > 1000$). This noise simulated unmodeled physics, such as Silk damping effects, which were intentionally omitted from the training simulations.

Results and Discussion

Validation and Efficiency

Under ideal conditions (no systematics), cosmoSWAG successfully recovered the same parameter degeneracies as traditional likelihood-based methods. The authors also determined that the posterior size converges after approximately 50,000 simulations, indicating that the 100,000-simulation training set was more than sufficient for CMB analysis.

Robustness to Systematics

The primary advantage of cosmoSWAG became evident when processing the corrupted synthetic data. Standard, non-Bayesian SBI produced highly biased results, with an Excess Probability (EP) of approximately 0.05, indicating the true value was a significant outlier. In contrast, cosmoSWAG improved the EP to ~0.18. By widening the error bars in response to unfamiliar data, the BNN provided a more reliable and statistically consistent result.

The Sensitivity of Compression

The study also highlighted that "neural compressors"—networks used to reduce high-dimensional data before inference—are particularly sensitive to distribution shifts. These compressors can introduce dangerous biases if the data does not perfectly match the training simulations, further emphasizing the need for Bayesian marginalization.

Conclusion

The introduction of cosmoSWAG represents a significant step toward making machine learning-based cosmological inference more reliable. By providing a mechanism for neural networks to signal their own uncertainty, researchers can avoid the pitfalls of overconfident, biased predictions. Future work will focus on automating the tuning of the SWA "scale" hyperparameter and extending the framework to other density estimators like Masked Autoregressive Flows (MAFs) for application in upcoming large-scale structure surveys.

Summary updated

BibTeX
@article{lemos2023robust,
  author = {Pablo Lemos and Miles D. Cranmer and Muntazir Abidi and ChangHoon Hahn and Michael Eickenberg and Elena Massara and David Yallup and Shirley Ho},
  title = {{Robust simulation-based inference in cosmology with Bayesian neural networks}},
  journal = {Mach. Learn. Sci. Technol.},
  year = {2023},
  doi = {10.1088/2632-2153/acbb53},
}
Figure