Posterior components and power spectra#

An ML-GPR fit represents uncertainty in both the covariance hyperparameters and the reconstructed components. Power-spectrum methods propagate samples from that posterior instead of evaluating only one best-fitting model.

Common products#

Given a fitted result and a configured power-spectrum generator:

ps_eor = result.get_ps_eor(ps_gen, kbins, n_pick=50)
ps_fg = result.get_ps_fg(ps_gen, kbins, n_pick=50)
ps_residual = result.get_ps_res(ps_gen, kbins, n_pick=50)

ps_eor.get_ps3d().plot()

n_pick is the number of posterior hyperparameter samples used for GP prediction. Larger values describe the posterior more densely, but each sample requires component prediction and power-spectrum evaluation. Increase it until the reported posterior intervals are stable for the statistic being used.

A simulated posterior#

The example below uses the MCMC fit introduced in Choosing an inference method. For one representative UV cell, posterior component draws are summarized by their median and 16th–84th percentile interval. The input realization is shown because it is known for simulated data.

Input and reconstructed foreground and 21-cm-like frequency spectra.

Posterior reconstructions of the smooth foreground and the much fainter 21-cm-like component.#

The same component draws can be passed directly to the power-spectrum estimator. The gray line and bands below summarize the recovered 21-cm-like power over posterior hyperparameter and component draws.

Input and posterior power spectra for a simulated 21-cm-like component.

Input signal, noise, and posterior signal power as frequency-dependent variance and a spherical power spectrum.#

The complete simulation and figure-generation script is available at the end of the inference page.

Selecting components#

Inspect the component names stored with the fitted result before selecting them. Configuration-based models add fg_ and eor_ prefixes, while the advanced API preserves the names supplied when constructing Components:

>>> print(result.sampler_result.components)
fg_intrinsic  (UVScaledKernel(rbf))
    variance     1            free  Uniform(0.8, 1.2)
    lengthscale  50           free  Uniform(10, 100)
    var_alpha    0            fixed
    ls_alpha     0            fixed
fg_mixing  (UVScaledKernel(matern32))
    variance     0.01         free  Log10Uniform(-3, -0.5)
    lengthscale  10           free  Uniform(2, 60)
    var_alpha    0            fixed
    ls_alpha     0            free  Uniform(0, 1.5)
eor_signal  (UVScaledKernel(exponential))
    variance     0.001        free  Log10Uniform(-5, -1)
    lengthscale  0.7          free  Uniform(0.2, 2)
    var_alpha    0            fixed
    ls_alpha     0            fixed
noise  (WhiteHeteroscedasticKernel)
    alpha  1            free  Uniform(0.9, 1.6)

The summary reports each component’s kernel family, parameter names and current values, and whether each parameter is fixed or sampled under a prior.

get_ps() accepts glob patterns for component names. For example, "eor*" selects all 21-cm components and "fg*" selects all foreground components. This is particularly useful for models containing multiple chromatic foreground terms. Every semicolon-separated term must match at least one component. Invalid patterns and unavailable :coherent or :independent parts raise an error before posterior prediction starts.

Always examine the reconstructed foreground, 21-cm, and residual products together. Unexpected structure in the residual or strong sensitivity to n_pick can reveal an incomplete covariance model or an insufficiently sampled posterior.

Saving and loading#

Results can be stored with their input cubes, configuration, posterior samples, and sampler diagnostics:

from ps_eor.ml_gpr import MLGPRResult

result.save("results", "night_01")
result = MLGPRResult.load("results", "night_01")

Keeping the configuration with the posterior is important: component names, priors, normalization, and noise processing are all part of the interpretation of the reconstructed products.