Forecasting
The forecast module provides classes for Fisher matrix forecasting using power spectrum and bispectrum data.
FullForecast
- class forecast.FullForecast(cosmo_funcs, kmax_func=None, s_k=2, nonlin=False, N_bins=None, bkmax_func=None, WS_cut=True, n_mu=8, n_phi=8)
Main class for full survey forecasts over redshift bins.
Parameters:
cosmo_funcs:
ClassWAPinstancekmax_func: Maximum k (float or callable
kmax_func(z))s_k: k-bins per decade (default: 2)
nonlin: Use HALOFIT power spectra (default: False)
N_bins: Number of redshift bins (default: auto)
bkmax_func: Separate kmax for bispectrum (default: same as kmax_func)
WS_cut: Apply wide-separation validity cuts (default: True)
n_mu, n_phi: Angular integration points for covariances
Attributes:
z_bins: Redshift bin edges, shape
(N_bins, 2)z_mid: Bin centre redshifts
k_max_list: Maximum k per bin
N_bins: Number of bins
Methods:
- get_fish(param_list, terms='NPP', cov_terms=None, pkln=None, bkln=None, verbose=True, sigma=None, bias_list=None)
Compute Fisher matrix.
- Parameters:
param_list (list) – Parameters (e.g.,
['A_s', 'n_s', 'h', 'Omega_m'])terms (str) – Contribution terms (see Available Terms)
pkln (list) – Pk multipoles (e.g.,
[0, 2])bkln (list) – Bk multipoles (e.g.,
[0])verbose (bool) – Show progress
sigma (float) – FoG damping
bias_list – Terms for best-fit bias calculation
- Returns:
FisherMatobject
- pk_SNR(term, pkln, verbose=True, sigma=None)
Compute power spectrum SNR per redshift bin.
- bk_SNR(term, bkln, verbose=True, sigma=None)
Compute bispectrum SNR per redshift bin.
- combined_SNR(term, pkln, bkln, verbose=True, sigma=None)
Compute combined Pk + Bk SNR.
- best_fit_bias(param, bias_term, terms='NPP', pkln=None, bkln=None, verbose=True, sigma=None)
Compute parameter bias from neglecting a contribution.
- Returns:
Tuple of (bias_dict, fisher_diagonal)
- get_pk_bin(i=0)
Get
PkForecastfor redshift bini.
- get_bk_bin(i=0)
Get
BkForecastfor redshift bini.
- sampler(param_list, terms=None, pkln=None, bkln=None, R_stop=0.005, max_tries=100, name=None, planck_prior=False, verbose=True, sigma=None)
Create
Samplerinstance for MCMC.
Usage
import cosmo_wap as cw
from cosmo_wap.lib import utils
from cosmo_wap.forecast import FullForecast
cosmo = utils.get_cosmo(h=0.67, Omega_m=0.31)
survey = cw.SurveyParams.Euclid(cosmo)
cosmo_funcs = cw.ClassWAP(cosmo, survey)
forecast = FullForecast(cosmo_funcs, kmax_func=0.15, N_bins=4)
# Fisher from Pk monopole + quadrupole
fisher = forecast.get_fish(
["fNL_loc", "A_b_1", "A_Q", "A_be"],
terms=["NPP", "Loc", "GR2", "IntNPP"],
pkln=[0, 2],
bkln=None
)
# Combined Pk + Bk
fisher_combined = forecast.get_fish(
["fNL_loc", "A_b_1", "A_Q", "A_be"],
terms=["NPP", "Loc", "GR2", "IntNPP"],
pkln=[0, 2],
bkln=[0]
)
Available Parameters
We can forecast over the core cosmological parameter as well as our bias parameters or simply some specific contribution
Cosmological parameters:
A_s,n_s,h,Omega_m,Omega_cdm,Omega_b,sigma8
PNG amplitudes:
fNL(local),fNL_eq(equilateral),fNL_orth(orthogonal)
Survey/nuisance parameters:
A_b_1,A_b_2,A_be,A_Q,A_loc_b_01,A_loc_b_01(bias amplitude parameters)
We can also refer to bias amplitude linked to one survey:
e.g.
- X_b_1, Y_b_1
Available Terms
Terms can be passed as a single string (e.g. terms='NPP') or a list (e.g. terms=['NPP', 'Loc']). The full list of available terms is:
Base:
'NPP'– Newtonian plane-parallel (Kaiser RSD)
Wide-separation (WS):
'WS'– Combined wide-separation (WA + RR)'WA1'– Wide-angle first order'WA2'– Wide-angle second order'RR1'– Radial redshift first order'RR2'– Radial redshift second order
Relativistic (GR):
'GR'– All relativistic corrections'GR1'– First order relativistic'GR2'– Second order relativistic'GRX'– Cross relativistic terms
Combined WS + GR:
'WAGR'– Wide-angle + GR'WARR'– Wide-angle + Radial redshift'RRGR'– Radial redshift + GR'WSGR'– Wide-separation + GR'Full'– All terms
Primordial non-Gaussianity (PNG):
'Loc'– Local PNG'Eq'– Equilateral PNG'Orth'– Orthogonal PNG
Integrated effects (Pk only):
'IntNPP'– Integrated x NPP'IntInt'– Integrated x Integrated'GRI'– GR + Integrated'GRL'– GR + Lensing
Individual integrated components:
'LxNPP'– Lensing x NPP'ISWxNPP'– ISW x NPP'TDxNPP'– Time-delay x NPP'LxL'– Lensing x Lensing'LxTD'– Lensing x Time-delay'LxISW'– Lensing x ISW'ISWxISW'– ISW x ISW'ISWxTD'– ISW x Time-delay'TDxTD'– Time-delay x Time-delay
Multi-Tracer Forecasting
# Bright-faint split for multi-tracer
survey = cw.SurveyParams.Euclid(cosmo)
bright, faint = survey.BF_split(5e-16)
cosmo_funcs_mt = cw.ClassWAP(cosmo, [bright, faint])
forecast_mt = FullForecast(cosmo_funcs_mt, kmax_func=0.15, N_bins=4)
# Multi-tracer Fisher (accounts for cross-correlations)
fisher_mt = forecast_mt.get_fish(
["fNL_loc", "A_b_1", "A_Q", "A_be"],
terms=["NPP", "Loc", "GR2", "IntNPP"],
pkln=[0, 2]
)
PNG Forecasting
# Include local PNG contribution
fisher_png = forecast.get_fish(
["fNL_loc", "A_b_1", "A_Q", "A_be"],
terms=["NPP", "Loc", "GR2", "IntNPP"],
pkln=[0, 2],
bkln=[0]
)
print(f"sigma(fNL_loc) = {fisher_png.get_error('fNL_loc'):.2f}")
MCMC Sampling
Note
For sampling over cosmology we recommend using the CosmoPower extension. See Installation Guide for setup instructions.
# Create sampler (requires CosmoPower)
sampler = forecast.sampler(
["A_s", "n_s", "h"],
terms="NPP",
pkln=[0, 2],
R_stop=0.01 # Convergence criterion
)
# Run MCMC
sampler.run()
# Plot posteriors
sampler.plot()
FisherMat
- class forecast.FisherMat
Stores Fisher matrix results.
Attributes:
fisher_matrix: Fisher information matrix (numpy array)
covariance: Inverse Fisher (parameter covariance)
errors: 1-sigma marginalised errors
correlation: Correlation matrix
param_list: Parameter names
bias: Best-fit bias values (if computed)
Methods:
- get_error(param)
Get 1-sigma error for parameter.
- get_correlation(param1, param2)
Get correlation coefficient.
- summary()
Print formatted summary.
- add_chain(c=None, bias_values=None, name=None)
Add as chain to ChainConsumer for plotting.
- plot_errors(relative=False, figsize=(8, 6))
Plot parameter errors as bar chart.
- plot_1D(param, ci=0.68, ax=None, shade=True, color='royalblue')
Plot 1D Gaussian posterior.
- save(filename)
Save to
.npzfile.
- classmethod load(filename)
Load from file.
Usage
fisher = forecast.get_fish(
["fNL_loc", "A_b_1", "A_Q", "A_be"],
terms=["NPP", "Loc", "GR2", "IntNPP"],
pkln=[0, 2]
)
fisher.summary()
print(fisher.get_error("fNL_loc"))
print(fisher.get_correlation("fNL_loc", "A_b_1"))
# Plot with ChainConsumer
c = fisher.add_chain(name="Pk only")
c.plotter.plot()
FisherList
- class forecast.FisherList
Container for multiple Fisher matrices (e.g., varying flux cuts/splits).
Created via
FullForecast.get_fish_list().
PkForecast / BkForecast
- class forecast.PkForecast
- class forecast.BkForecast
Single-bin forecast classes. Usually accessed via
FullForecast.get_pk_bin()/get_bk_bin().Methods:
- get_data_vector(terms, ln, param=None)
Get data vector (or derivative w.r.t. param).
- get_cov_mat(ln, sigma=None)
Get covariance matrix.
- SNR(term, ln, param=None)
Compute SNR.
Sampler
- class forecast.Sampler
MCMC sampler using cobaya. Created via
FullForecast.sampler(). Requires CosmoPower for efficient cosmology evaluation.Methods:
- run()
Run MCMC chains.
- plot(extents=None, truth=True)
Plot posteriors with ChainConsumer.
- save(filename)
Save chains to file.
Usage
# Create sampler
sampler = forecast.sampler(
["A_s", "n_s"],
terms="NPP",
pkln=[0, 2],
R_stop=0.005, # Gelman-Rubin convergence
planck_prior=True # Add Planck prior
)
# Run chains
sampler.run()
# Plot with fiducial values marked
sampler.plot(truth=True)