Neural density estimators (NDEs) for the cosmic 21-cm power spectrum likelihoods.
Common assumptions of the classical Bayesian inferences with the 21-cm PS are:
- the likelihood shape is a Gaussian,
- the covariance matrix is usually fixed and pre-calculated at some fiducial parameter values,
- often only diagonal covariance is used, ignoring other correlations,
- the Gaussian mean at each point in parameter space is estimated from only one realization.
All of these assumptions mostly come in order to reduce computational costs, and have a potentially significant impact on the final posterior.
In order to bypass all of these, we use Simulation-Based Inference (SBI). It can be summarized into two main steps:
- draw parameter sample from some distribution (possibly prior) -
$\tilde{\boldsymbol{\theta}} \sim \pi(\boldsymbol{\theta})$ , - draw a data sample by using a realistic data simulator -
$\tilde{\boldsymbol{d}} \sim \mathcal{L}(\boldsymbol{d} | \tilde{\boldsymbol{\theta}})$ , - Repeat many times.
A database of (parameter, data sample) pairs follow full distribution
See examples and article for more details.
We implement three main likelihood categories, by relaxing classical inference constraints.
In order to estimate the mean better, a feed-forward NN is used which takes parameters
The possible Gaussian likelihoods are then:
Here
In code, one can create such likelihoods as:
import numpy as np
from py21cmlikelihoods import ConditionalGaussian
fiducial_covariance = np.load("cov.npy")
NDE = ConditionalGaussian(
n_parameters = 2,
n_data = 5,
covariance = fiducial_covariance,
)where fiducial_covariance can be 1D or 2D, depending if full or diagonal covariance is needed.
Likewise, we can also estimate the (co)variance matrix with a NN. In this scenario, the network can output one of the following:
with their respective likelihoods:
In code:
NDE_diagonal = ConditionalGaussian(
n_parameters = 2,
n_data = 5,
diagonal_covariance = True,
)
NDE_full = ConditionalGaussian(
n_parameters = 2,
n_data = 5,
diagonal_covariance = False,
)Finally, we can relax the Gaussian constraint as well. This can be done in a parametric way by using Gaussian mixture networks, or non-parametric way with Conditional Masked Autoregressive Flows (CMAF).
The setup here is exactly the same as previous cases, with the difference that NN outputs a Gaussian mixture:
where
In code:
from py21cmlikelihoods import ConditionalGaussianMixture
NDE = ConditionalGaussianMixture(
n_parameters = 2,
n_data = 5,
n_components = 3,
)CMAF represents non-parametric density estimator, with large expressivity in the shape of the final distribution. Minimal example is the following:
from py21cmlikelihoods import ConditionalMaskedAutoregressiveFlow
NDE = ConditionalMaskedAutoregressiveFlow(
n_dim = 5,
cond_n_dim = 2,
)To train NDE, simply format the training set and call the training function.
from py21cmlikelihoods.utils import prepare_dataset
data_samples = np.load("data.npy")
param_samples = np.load("params.npy")
batch_size = 100
training_set = prepare_dataset(NDE, data_samples, param_samples, batch_size)
NDE.train(
epochs = 100,
dataset = training_set,
)To install and use the code, clone the repository and run
pip install -e .For a full setup needed to run examples,
check the the conda environment.yml and install it as
conda env create -f environment.yml
conda activate 21cmLikelihoods
pip install -e .If you use the code in your research, please cite the original paper:
@ARTICLE{Prelogovic2023,
author = {{Prelogovi{\'c}}, David and {Mesinger}, Andrei},
title = "{Exploring the likelihood of the 21-cm power spectrum with simulation-based inference}",
journal = {\mnras},
keywords = {cosmology: theory, dark ages, reionization, first stars, methods: data analysis, methods: statistical, Astrophysics - Cosmology and Nongalactic Astrophysics, Astrophysics - Astrophysics of Galaxies},
year = 2023,
month = jul,
doi = {10.1093/mnras/stad2027},
archivePrefix = {arXiv},
eprint = {2305.03074},
primaryClass = {astro-ph.CO},
adsurl = {https://ui.adsabs.harvard.edu/abs/2023MNRAS.tmp.1955P},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}