Chain Analysis¶
See Chain Analysis for the command-line interface and the tutorial for a worked example.
cmb_lensing.chain_analysis.main ¶
main(chain_dir, nside=DEFAULT_NSIDE, theta_pix=DEFAULT_THETA_PIX, noise=DEFAULT_NOISE, pol=DEFAULT_POL, burn_in=DEFAULT_BURN_IN, ground_truth=GROUND_TRUTH, should_thin=True, out_dir=None, run_fisher=False, delensed_covariance=None, qe_filter=DEFAULT_QE_FILTER, phi_noise=None, include_bb=True, camb_lmax=CAMB_LMAX)
Analyse a directory of LCDM chains: the MCMC plots and, optionally, the comparison with a Fisher forecast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_dir
|
directory of sample_joint's history files,
|
required | |
nside, theta_pix, noise
|
the box the chains ran on (pixels per side, arcmin, uK-arcmin); they label the triangle plot and set the forecast's box |
required | |
pol
|
"I", "P" or "IP", the data the chains saw; it labels the triangle plot and is the data the forecast models |
DEFAULT_POL
|
|
burn_in
|
sweeps removed from the start of every sub-chain |
DEFAULT_BURN_IN
|
|
ground_truth
|
{param_name: value} the maps were simulated at (all five parameters) |
GROUND_TRUTH
|
|
should_thin
|
thin each sub-chain by its integrated autocorrelation time before the per-parameter plots (the covariance always uses the unthinned chains) |
True
|
|
out_dir
|
where the plots go (default |
None
|
|
run_fisher
|
also run the Fisher forecast for data of this |
False
|
|
delensed_covariance
|
a merged delensed_covariance.npz measured at this box, noise
level and |
None
|
|
qe_filter
|
"unlensed" (default) or "lensed": the spectra in the filter of the QE N0 the forecast uses as its phi noise (the response is always unlensed) |
DEFAULT_QE_FILTER
|
|
phi_noise
|
a merged map_joint_phi_noise.npz / sampler_phi_noise.npz whose |
None
|
|
include_bb
|
for "P" / "IP" chains, whether the forecast counts the delensed BB block |
True
|
|
camb_lmax
|
how far the forecast runs CAMB |
CAMB_LMAX
|
Returns:
| Type | Description |
|---|---|
|
A dict: |
|
|
(per parameter: the product mean / std / z-score with their errors, the average |
|
|
single-map std, R-hat per map and the acceptance rate), |
|
|
|
|
|
|
Source code in cmb_lensing/chain_analysis.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | |
cmb_lensing.chain_analysis.load_chains ¶
Read every post-burn-in sub-chain in a directory of sample_joint history files.
A sub-chain is kept when every parameter has its file. Its files are cut to their common length (they differ by a sweep when copied from a running job) BEFORE the burn-in is removed, so row k of every parameter is the same sweep; a sub-chain no longer than the burn-in is left out, and so is a map with no sub-chain left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_dir
|
directory holding |
required | |
burn_in
|
sweeps removed from the start of every sub-chain |
DEFAULT_BURN_IN
|
Returns:
| Type | Description |
|---|---|
|
(chains, map_seeds) - |
|
|
GROUND_TRUTH parameter with files, in GROUND_TRUTH's order, with maps and sub-chains |
|
|
in the same order for every parameter; map_seeds lists the kept maps. |
Source code in cmb_lensing/chain_analysis.py
cmb_lensing.chain_analysis.get_avg_covariance_matrix ¶
Map-averaged posterior covariance of the sampled parameters, with its jackknife error.
chains is load_chains' dict, whose sub-chains line up row by row across parameters.
Each map's sub-chains are concatenated and give one covariance matrix, and those are
averaged over maps. Samples from different maps are never pooled: each map is a
different data realization with its own posterior mean, so pooling would add the scatter
of those means to the diagonal. The average is a single-realization posterior, which is
what a Fisher forecast predicts.
Returns:
| Type | Description |
|---|---|
|
(avg_cov_mat, param_names, cov_err, sigma_err), the last two from measured_errors: |
|
|
the element-wise error of the averaged covariance and the error of each width |
|
|
sqrt(C_ii). |
Source code in cmb_lensing/chain_analysis.py
cmb_lensing.chain_analysis.get_forecasted_covariance ¶
get_forecasted_covariance(nside, theta_pix, noise, param_names, delensed_covariance, pol=DEFAULT_POL, qe_filter=DEFAULT_QE_FILTER, phi_noise=None, include_bb=True, ground_truth=GROUND_TRUTH, camb_lmax=CAMB_LMAX)
Fisher-forecast covariance of the sampled parameters, with white noise and no beam.
A thin wrapper of fisher_forecast.forecast. Its field blocks are the empirical delensed
covariance of delensed_covariance (plus the analytic noise); its phi block's noise is
the box QE N0 or a measured matrix. Build the delensed covariance's Wiener filter from
the same N_phi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nside, theta_pix, noise
|
the chains' box (pixels per side, arcmin, uK-arcmin) |
required | |
param_names
|
the sampled parameters; the others are held fixed |
required | |
delensed_covariance
|
a merged delensed_covariance.npz at this box, noise level and
|
required | |
pol
|
"I", "P" or "IP": the data the chains saw |
DEFAULT_POL
|
|
qe_filter
|
"unlensed" (default) or "lensed": the spectra in the QE N0's filter. The response always uses the unlensed spectra |
DEFAULT_QE_FILTER
|
|
phi_noise
|
a merged map_joint_phi_noise.npz / sampler_phi_noise.npz; its
|
None
|
|
include_bb
|
for "P" / "IP", whether the delensed BB block is counted |
True
|
|
ground_truth
|
{param_name: value}, the fiducial point, all five parameters |
GROUND_TRUTH
|
|
camb_lmax
|
how far CAMB is run |
CAMB_LMAX
|
Returns:
| Type | Description |
|---|---|
|
The covariance matrix F^-1 over param_names, rows and columns in |
|
|
constants.PARAM_ORDER (the order load_chains returns its parameters in). |