  Simulation-based inference (SBI) is rapidly establishing itself as a standard
machine learning technique for analyzing data in cosmological surveys. Despite
continual improvements to the quality of density estimation by learned models,
applications of such techniques to real data are entirely reliant on the
generalization power of neural networks far outside the training distribution,
which is mostly unconstrained. Due to the imperfections in scientist-created
simulations, and the large computational expense of generating all possible
parameter combinations, SBI methods in cosmology are vulnerable to such
generalization issues. Here, we discuss the effects of both issues, and show
how using a Bayesian neural network framework for training SBI can mitigate
biases, and result in more reliable inference outside the training set. We
introduce cosmoSWAG, the first application of Stochastic Weight Averaging to
cosmology, and apply it to SBI trained for inference on the cosmic microwave
background.
