Skip to content

Inference

MarginalisedLikelihood evaluates the marginalised likelihood for a set of power-spectrum amplitudes, and run_multinest samples it. MaximumAPosteriori recovers the conditional coefficients from the same products. All three are built from the SetupResult returned by run_setup.

from bayeseor_jax import run_nestedsampling

summary = run_nestedsampling(setup, out_dir="outputs/multinest")
log_l = setup.likelihood_class.log_likelihood(rho)

Sampling

run_nestedsampling is an alias of run_multinest.

bayeseor_jax.inference.run_ns.run_multinest

run_multinest(setup_result: SetupResult, out_dir: Path | str, *, random_key: int | None = None, n_live_points: int | None = None, n_live_scale_factor: float = 25.0, calc_avg_eval: bool = False, avg_iters: int = 10, file_root: str = 'data-', resume: bool | None = None, verbose: bool = False, importance_nested_sampling: bool | None = None, multimodal: bool | None = None, const_efficiency_mode: bool | None = None, evidence_tolerance: float | None = None, sampling_efficiency: float | None = None, max_iter: int | None = None, print_rate: int = 100) -> dict[str, Any]

Run MultiNest, or evaluate a parameter-free model analytically.

A model with no sampled hyperparameters needs no nested sampling. Its conditional MAP coefficients and marginalised log-evidence target are evaluated in one solve and saved as map_coefficients.npy and summary.json. The same fixed data/noise normalisation is omitted as in the sampled likelihood, so same-dataset model comparisons are unchanged.

This implementation is intentionally single-process at the sampler level. The expensive operation is still the likelihood evaluation itself, which can use multiple GPUs internally through the JAXMg-backed marginalized likelihood.

By default this wrapper mirrors the old BayesEoR MultiNest runner closely: aside from the required output basename and resolved live-point count, it leaves the remaining MultiNest options unset so the underlying pymultinest.solve defaults apply.

The log likelihood at the prior midpoint is automatically subtracted before passing values to MultiNest. This avoids loss of precision in its evidence-error estimate for bright foregrounds. The offset is restored in the returned logZ and saved in summary.json; native MultiNest files retain centred values. Resuming requires the saved likelihood_offset.json and uses its recorded offset unchanged.

Likelihood and MAP

bayeseor_jax.inference.likelihood_marg.MarginalisedLikelihood

Configuration for marginalized log-likelihood evaluation.

This class evaluates the analytically marginalized BayesEoR target from the compressed matrix stack

T^H N^{-1} T, T^H N^{-1} d, and d^H N^{-1} d.

Single-device inference uses a standard JAX Cholesky factorisation on CPU or GPU; multi-GPU inference uses JAXMG. Both evaluate the same Gaussian target. The large dense matrix is kept row-sharded over a 1D device mesh, while the right-hand side vector and scalar normalization term are replicated. Each likelihood call builds the diagonal prior precision Phi^{-1}, forms

Sigma = T^H N^{-1} T + Phi^{-1}

in a work matrix, and then uses one factorisation to obtain both Sigma^{-1} dbar and log|Sigma|.

Visibilities contain both each measured value and its conjugate, as produced by uvd_to_vector. They are not independent complex samples: the Gaussian exponent and log determinants therefore carry factors of one half. Foreground image coefficients are real, and cosmological Fourier coefficients obey the real-sky conjugacy constraint. A reduced operator must preserve this covariance structure, not introduce independent complex sky amplitudes.

The returned target omits fixed data/noise normalisation terms. These cancel in Bayes factors only when both models use the same dataset, noise covariance and omitted constants; see docs/inference.md.

Parameters:

Name Type Description Default
t_ninv_t Array

Matrix T^H N^{-1} T.

None
dbar Array

Vector T^H N^{-1} d.

None
d_ninv_d float

Scalar d^H N^{-1} d.

None
n_data int

Number of entries including conjugate copies, equal to the number of independent real data components, used in the noise normalisation.

required
phi_inv_class PhiInverse

Prior-precision construction settings.

required
prior_class Prior

Sampler-space prior configuration used to evaluate the full log density.

required
uniform_priors Array

Boolean mask over power-spectrum parameters whose intended physical prior is uniform in linear power. The sampler still works in log10(power) coordinates; True entries receive the Jacobian correction in the likelihood.

None
intrinsic_noise_fitting bool

Whether the first sampled parameter is intrinsic noise amplitude alpha_prime.

False
power_param_start int

Start index of power-spectrum parameters within theta.

0
n_power_params int

Number of power-spectrum parameters within theta.

0
matrix_dir Path or str

Directory containing saved compressed likelihood terms. When provided, the constructor loads: - T_Ninv_T.npy - dbar.npy - d_ninv_d.npy and ignores the explicit array arguments.

None
jaxmg_tile_size int

Tile size forwarded to jaxmg.potrs for multi-GPU inference; ignored for single-device inference.

256
mesh Mesh or None

Optional pre-built 1D solver mesh. When omitted, the likelihood uses all visible devices via build_solver_mesh(). A single-device mesh uses native JAX on CPU or GPU; a multi-GPU mesh uses JAXMG.

None

log_likelihood

log_likelihood(theta: Array) -> jax.Array

Evaluate marginalized Gaussian log-likelihood.

This integrates out the latent linear coefficient vector analytically, evaluates the resulting dense system on the stored CPU or GPU solver mesh, and returns the Hermitian-augmented Gaussian target with fixed normalisation terms omitted and optional intrinsic-noise and Jacobian corrections.

log_posterior

log_posterior(theta: Array) -> jax.Array

Evaluate full BayesEoR-style log density for sampling.

This folds the sampler-space prior into the marginalized Gaussian objective so the returned value matches the old single-call target.

bayeseor_jax.inference.maxaposteriori.MaximumAPosteriori

Conditional MAP solver for the latent linear coefficient vector.

For fixed sampled parameters theta, this class constructs the dense Gaussian system

Sigma = T^H N^{-1} T + Phi^{-1}

and solves for the conditional MAP coefficients

b_hat = Sigma^{-1} dbar

with dbar = T^H N^{-1} d.

The implementation uses the same compressed likelihood terms as the marginalized likelihood: T_Ninv_T, dbar, and d_ninv_d. The stored normal matrix is row-sharded over a 1D solver mesh, while the right-hand side and scalar normalization term are replicated. Each call builds the diagonal prior precision implied by theta and uses a JAX Cholesky factorisation on one CPU or GPU, or jaxmg.potrs across GPUs, to solve the system and return the MAP coefficient vector.

Parameters:

Name Type Description Default
matrix_dir Path or str or None

Directory containing saved compressed likelihood terms. When provided, the constructor loads T_Ninv_T.npy, dbar.npy, and d_ninv_d.npy from disk.

None
t_ninv_t optional

Explicit compressed likelihood terms used when matrix_dir is not supplied.

None
dbar optional

Explicit compressed likelihood terms used when matrix_dir is not supplied.

None
d_ninv_d optional

Explicit compressed likelihood terms used when matrix_dir is not supplied.

None
n_data int

Number of data samples contributing to the likelihood normalization.

required
phi_inv_class PhiInverse

Object that maps power amplitudes to the diagonal prior precision Phi^{-1}.

required
k_vals Array or None

Mean k value per non-empty spherical bin. Required only for the ps -> dmps convenience conversion helpers.

None
uniform_priors Array or None

Boolean mask over power bins that receive the old BayesEoR Jacobian correction in the marginalized objective.

None
intrinsic_noise_fitting bool

Whether the leading sampled parameter is the intrinsic noise amplitude alpha.

False
power_param_start int

Start index of the power-spectrum block inside theta.

0
n_power_params int

Number of power-spectrum parameters in theta.

0
jaxmg_tile_size int

Tile size forwarded to jaxmg.potrs for multi-GPU inference; ignored for single-device inference.

256
mesh Mesh or None

Optional pre-built 1D solver mesh. When omitted, all visible devices are used via build_solver_mesh().

None

calculate_dmps

calculate_dmps(*, ps: float | ndarray | None = None, dmps: float | ndarray | None = None) -> np.ndarray

Convert ps or dmps inputs into linear dmps values.

map_estimate

map_estimate(theta: Array | None = None, *, ps: float | ndarray | None = None, dmps: float | ndarray | None = None, return_prior_precision: bool = False)

Calculate the conditional MAP coefficients for a fixed theta.

Parameters:

Name Type Description Default
theta Array or None

Full sampled parameter vector in the same coordinates consumed by the marginalized likelihood. If omitted, one of ps or dmps must be provided and is interpreted as the power block only.

None
ps optional

Convenience power-spectrum inputs used to construct the power block of theta. These follow the old MAP helper interface.

None
dmps optional

Convenience power-spectrum inputs used to construct the power block of theta. These follow the old MAP helper interface.

None
return_prior_precision bool

When True, append the diagonal prior precision Phi^{-1}.

False

Returns:

Type Description
tuple

By default returns (map_coeffs, log_post). phi_i is appended when return_prior_precision=True.

log_posterior_at_map

log_posterior_at_map(theta: Array) -> float

Evaluate the old BayesEoR-style marginalized objective at fixed theta.

Priors and noise

The power-spectrum prior, the coefficient prior and the noise covariance.

bayeseor_jax.inference.prior.Prior

Sampler-space prior configuration.

Parameters:

Name Type Description Default
bounds_log Array

Power-spectrum parameter bounds with shape (n_power_params, 2) in log10 space.

required
power_param_start int

Start index of power-spectrum parameters within theta.

0
n_power_params int

Number of power-spectrum parameters in theta.

0

logprior

logprior(theta: Array) -> jax.Array

Evaluate sampler-space log prior density.

sample_from_priors

sample_from_priors(rng_key: Array, n_samples: int) -> jax.Array

Draw independent samples from the sampler-space box priors.

Parameters:

Name Type Description Default
rng_key Array

JAX PRNG key.

required
n_samples int

Number of samples to draw.

required

Returns:

Type Description
Array

Array with shape (n_samples, n_dim).

transform_unit_cube

transform_unit_cube(cube: ndarray) -> np.ndarray

Map a unit-cube point into the sampler-space box prior.

bayeseor_jax.inference.phi.PhiInverse

Construct the diagonal prior precision for the joint coefficients.

The cosmological block is set by the sampled spherical power-spectrum amplitudes. The foreground block accepts one standard deviation per operator column, independent of its representation: physical widths for the original coefficients or unit widths for prior-standardised KL coefficients.

Parameters:

Name Type Description Default
bin_id_per_k_mode array - like

Spherical bin assignments and validity flags for cosmological columns.

required
valid_mask array - like

Spherical bin assignments and validity flags for cosmological columns.

required
k_vals array - like

Representative physical wavenumbers of the sampled power-spectrum bins.

required
ps_box_size_ra_mpc float

Comoving dimensions used in the Fourier power normalisation.

required
ps_box_size_dec_mpc float

Comoving dimensions used in the Fourier power normalisation.

required
ps_box_size_para_mpc float

Comoving dimensions used in the Fourier power normalisation.

required
inst_to_cosmo_vol float

Instrumental-to-cosmological volume conversion.

required
n_par int

Total number of cosmological and foreground coefficient columns.

required
foreground_prior_std array - like

Finite, positive real standard deviations, one per foreground column in operator order. Pass ones for a reduced KL operator; its physical prior has already been absorbed. An empty vector supports zero retained foreground modes.

required

evaluate

evaluate(theta_power_linear: Array) -> jax.Array

Return the joint EoR and foreground prior-precision diagonal.

bayeseor_jax.model.instrument.noise.build_noise_variance

build_noise_variance(n_time: int, n_frequency: int, n_baseline: int, *, sigma: float | None = None, redundancy=None, effective_noise=None) -> jax.Array

Prepare the diagonal complex-visibility noise covariance for an observation.

Parameters:

Name Type Description Default
n_time int

Positive observation dimensions in the forward operator's row order.

required
n_frequency int

Positive observation dimensions in the forward operator's row order.

required
n_baseline int

Positive observation dimensions in the forward operator's row order.

required
sigma float or None

Positive complex noise RMS before redundancy averaging, in visibility units. Required unless effective_noise supplies per-visibility RMS.

None
redundancy array - like or None

Positive baseline redundancies, shape (n_time, n_baseline) or (n_time, n_baseline, 1). Required when effective_noise is absent.

None
effective_noise array - like or None

Per-visibility noise amplitudes, shape (n_timen_frequencyn_baseline,). Their squared magnitudes override the sigma/redundancy model.

None

Returns:

Name Type Description
variance Array

Positive float64 variances E[|n_i|^2], in squared visibility units, flattened in time/frequency/baseline order.

Notes

For redundancy R_tb, N_(tfb) = sigma^2 / R_tb. Real and imaginary noise components each have half this variance. This setup-time function validates inputs on the host; it does not create a dense covariance or save a file.