-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first attempt of trying pytest for both binned and unbinned cluster likelihood
- Loading branch information
1 parent
6e00212
commit 1b1f537
Showing
6 changed files
with
132 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,148 @@ | ||
import numpy as np | ||
import copy | ||
import pytest | ||
|
||
from cobaya.model import get_model | ||
|
||
fiducial_params = { | ||
"ombh2": 0.02225, | ||
"omch2": 0.1198, | ||
"H0": 67.3, | ||
"tau": 0.06, | ||
"As": 2.2e-9, | ||
"ns": 0.96, | ||
"mnu": 0.0, | ||
"nnu": 3.046, | ||
"omnuh2": 0., | ||
|
||
params = { | ||
'h': 0.68, | ||
'n_s': 0.965, | ||
'Omega_b': 0.049, | ||
'Omega_c': 0.261, | ||
'sigma8': 0.81, | ||
'm_nu': 0., | ||
'tenToA0': 1.9e-05, | ||
'B0': 0.08, | ||
'scatter_sz': 0., | ||
'bias_sz': 1., | ||
'C0': 2. | ||
} | ||
|
||
info_unbinned = { | ||
"params": fiducial_params, | ||
"likelihood": {"soliket.UnbinnedClusterLikelihood": | ||
{"stop_at_error": True, | ||
"theorypred":{"choose_theory":'camb'}}}, | ||
"theory": { | ||
"camb": { | ||
"extra_args": { | ||
"accurate_massive_neutrino_transfers": True, | ||
"num_massive_neutrinos": 1, | ||
"redshifts": np.linspace(0, 2, 41), | ||
"nonlinear": False, | ||
"kmax": 10.0, | ||
"dark_energy_model": "ppf" | ||
}, | ||
"ignore_obsolete": True | ||
}, | ||
path = './clusters/data/advact/DR5CosmoSims/sim-kit_NemoCCL_A10tSZ_DR5White_ACT-DR5_tenToA0Tuned/NemoCCL_A10tSZ_DR5White_ACT-DR5_tenToA0Tuned/' | ||
|
||
lkl_common = { | ||
'verbose': True, | ||
'stop_at_error': True, | ||
'data': { | ||
'data_path': path, | ||
'cat_file': 'NemoCCL_A10tSZ_DR5White_ACT-DR5_tenToA0Tuned_mass.fits', | ||
'Q_file': 'selFn/QFit.fits', | ||
'tile_file': 'selFn/tileAreas.txt', | ||
'rms_file': 'selFn/RMSTab.fits' | ||
}, | ||
'theorypred': { | ||
'choose_theory': 'CCL', | ||
'massfunc_mode': 'ccl', | ||
'compl_mode': 'erf_diff', | ||
'md_hmf': '200c', | ||
'md_ym': '200c' | ||
}, | ||
'YM': { | ||
'Mpivot': 4.25e14 | ||
}, | ||
'selfunc': { | ||
'SNRcut': 5., | ||
'method': 'SNRbased', | ||
'whichQ': 'injection', | ||
'resolution': 'downsample', | ||
'dwnsmpl_bins': 2, | ||
'save_dwsmpld': False, | ||
}, | ||
'binning': { | ||
'z': { | ||
'zmin': 0., | ||
'zmax': 2., | ||
'dz': 0.1 | ||
}, | ||
'q': { | ||
'log10qmin': 0.6, | ||
'log10qmax': 2.0, | ||
'dlog10q': 0.25 | ||
}, | ||
'M': { | ||
'Mmin': 5e13, | ||
'Mmax': 1e16, | ||
'dlogM': 0.01 | ||
}, | ||
'exclude_zbin': 2, | ||
} | ||
} | ||
|
||
info_binned = copy.copy(info_unbinned) | ||
info_binned['likelihood'] = {"soliket.BinnedClusterLikelihood": | ||
{"stop_at_error": True, | ||
"datapath": './soliket/tests/data/toy_cashc.txt'}} | ||
ccl_baseline = { | ||
'transfer_function': 'boltzmann_camb', | ||
'matter_pk': 'halofit', | ||
'baryons_pk': 'nobaryons', | ||
'md_hmf': '200c' | ||
} | ||
|
||
|
||
def test_clusters_unbinned_model(): | ||
|
||
model_fiducial = get_model(info_unbinned) | ||
|
||
info_binned = { | ||
'params': params, | ||
'likelihood': {'soliket.BinnedClusterLikelihood': lkl_common}, | ||
'theory': {'soliket.clusters.CCL': ccl_baseline} | ||
} | ||
|
||
info_unbinned = { | ||
'params': params, | ||
'likelihood': {'soliket.UnbinnedClusterLikelihood': lkl_common}, | ||
'theory': {'soliket.clusters.CCL': ccl_baseline} | ||
} | ||
|
||
|
||
def test_clusters_unbinned_model(): | ||
def test_clusters_import(): | ||
|
||
model_fiducial = get_model(info_unbinned) | ||
from soliket.clusters import BinnedClusterLikelihood | ||
from soliket.clusters import UnbinnedClusterLikelihood | ||
|
||
|
||
def test_clusters_unbinned_loglike(): | ||
def test_clusters_model(): | ||
|
||
model_fiducial = get_model(info_unbinned) | ||
binned_model = get_model(info_binned) | ||
unbinned_model = get_model(info_unbinned) | ||
|
||
lnl = model_fiducial.loglikes({})[0] | ||
|
||
print('lnl: ',lnl) | ||
# exit(0) | ||
def test_clusters_loglike(): | ||
|
||
# assert np.isclose(lnl, -885.678) | ||
binned_model = get_model(info_binned) | ||
unbinned_model = get_model(info_unbinned) | ||
|
||
binned_lnl = binned_model.loglikes({})[0] | ||
unbinned_lnl = unbinned_model.loglikes({})[0] | ||
|
||
def test_clusters_unbinned_n_expected(): | ||
assert np.isfinite(binned_lnl) | ||
assert np.isfinite(unbinned_lnl) | ||
|
||
model_fiducial = get_model(info_unbinned) | ||
|
||
lnl = model_fiducial.loglikes({})[0] | ||
def test_clusters_prediction(): | ||
|
||
like = model_fiducial.likelihood["soliket.UnbinnedClusterLikelihood"] | ||
binned_model = get_model(info_binned) | ||
unbinned_model = get_model(info_unbinned) | ||
|
||
print('like._get_n_expected():',like._get_n_expected()) | ||
print('like._get_nz_expected():',like._get_nz_expected()) | ||
binned_model.loglikes({})[0] | ||
unbinned_model.loglikes({})[0] | ||
|
||
assert np.isfinite(lnl) | ||
assert like._get_n_expected() > 40 | ||
binned_like = binned_model.likelihood['soliket.BinnedClusterLikelihood'] | ||
unbinned_like = unbinned_model.likelihood['soliket.UnbinnedClusterLikelihood'] | ||
|
||
binned_pk_intp = binned_like.theory.get_Pk_interpolator() | ||
unbinned_pk_intp = unbinned_like.theory.get_Pk_interpolator() | ||
SZparams = { | ||
'tenToA0': 1.9e-05, | ||
'B0': 0.08, | ||
'C0': 2., | ||
'scatter_sz': 0., | ||
'bias_sz': 1. | ||
} | ||
|
||
def test_clusters_binned_model(): | ||
Nzq = binned_like._get_theory(binned_pk_intp, **SZparams) | ||
Ntot = unbinned_like._get_n_expected(unbinned_pk_intp, **SZparams) | ||
|
||
assert np.isclose(Nzq.sum(), Ntot) | ||
|
||
model_fiducial = get_model(info_binned) | ||
|
||
# for debugging purposes: | ||
# test_clusters_unbinned_loglike() | ||
# test_clusters_unbinned_model() | ||
test_clusters_unbinned_n_expected() | ||
# test_clusters_import() | ||
# test_clusters_model() | ||
# test_clusters_loglike() | ||
# test_clusters_prediction() |