Skip to content

Xiaosheng-Zhao/21cmDELFI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

21cmDELFI

This package is for the density estimation likelihood-free inference (DELFI, or called implicit-likelihood inference or simulation-based inference) with 21 cm statistics like the power spectrum (21cmDELFI-PS, Zhao et al. 2022a), 3D CNN summaries (DELFI-3D CNN, Zhao et al. 2022b), and solid harmonic wavelet transform (WST)(dubbed 3D ScatterNet, Zhao et al. 2023). The main module of DELFI is heavily borrowed from the pydelfi package, mainly described in Alsing, Charnock, Feeney and Wandelt 2019, with minor changes in delfi.py. The validations of the posteriors are partly borrowed from galpo, which is based on S. Mucesh et al. 2021. The other validation tool is based on Diana Harrison et al. 2015. If you use this code, please consider citing these papers.

Update 2023.10.26

Kymatio is required to install for the analysis from solid harmonic wavelet scattering transform (WST) with DELFI (Zhao et al. 2023). Check the tutural directory for scripts to calculate solid harmonic WST as training data. Moreover, we developed a tool, led by Ce Sui, using mutual information for the comparison of varied summary statistics, including solid harmonic WST and bispectrum.

Installation:

The code is tested with python3 (3.7) and the tensorflow (1.15) in a separate conda environment. Other dependencies:
getdist
emcee (>=3.0.2)
tqdm
mpi4py (if MPI is required)

To install the dependencies and this package, you can first run

pip install tensorflow==1.15

then clone the repo and run python setup.py install from the top-level directory.
Another suggeted way to install mpi4py if some problem happens:

conda install -c anaconda mpi4py

For the active learning (under development) with the 21 cm power spectrum, the implemented example has the other two dependencies:
21cmFAST
21cmSense

Documentation and tutorials:

If you want to implement your own 21cm signal, please check the scripts in the tutural directory, where you can replace the data with your own.

For validation of both marginal and joint posteriors, you can check the Diagnostics.ipynb under the tutural directory.

Comparing to the pydelfi package, the delfi.py in this repo has the following minor changes:

  1. Add a free parameter n_noise under the pydelfi directory for the active learning, . This new parameter describes the number of realizations of noise for each simulation of signal. You can refer to Active_learning.py under the tutorial directory to play with your own application of active learning.
  2. Add two emcee_sample functions that can output the posterior samples from individual neural density estimator in an ensemble.
  3. Output the full chains together with the corresponding log probabilities, in order to evaluate the probabilistic HPD calibration (for the validation of posteriors).
  4. For the log_likelihood_staked function, we watch out for overflow if the likelihood has extreme number, in which case you can force it's type to be np.float64.

You may also want to compress the 21 cm images into different low-dimensional summaries. For example, in this repository, we present the code used to train a 3DCNN (Zhao et al. 2022b) as the data compressor.

The main documentation of pydelfi can be found here.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published