rxmc.config.CalibrationConfig#
- class rxmc.config.CalibrationConfig(evidence: Evidence, model_config: ParameterConfig, likelihood_configs: list | None = None, likelihood_scaling: float | None = None)[source]#
Bases:
objectEnd-to-end configuration for Bayesian calibration.
Combines an
Evidenceobject withParameterConfiginstances for the physical-model parameters and any parametric likelihood parameters. The result is a flat parameterization suitable for black-box samplers (emcee, Dynesty, black-box-bayes, etc.).- Parameters:
evidence (Evidence) – Aggregated experimental constraints.
model_config (ParameterConfig) – Prior and proposal for the physical-model parameters.
likelihood_configs (list of ParameterConfig, optional) – One
ParameterConfigper parametric constraint inevidence.parametric_constraints. Omit or passNonewhen there are no parametric likelihood models.likelihood_scaling (float, optional) – Multiplicative scale applied to the total log-likelihood before adding the log-prior. Useful for tempering or importance re-weighting. Defaults to
1.0.
- Raises:
ValueError – If
evidencecontains no constraints.ValueError – If the model parameters in
model_configdo not match those in the evidence constraints.ValueError – If the number or parameter lists of
likelihood_configsdo not matchevidence.parametric_constraints.
- dimensions#
Array of sector sizes
[model_ndim, lc0_ndim, lc1_ndim, ...].- Type:
ndarray
- indices#
Cumulative split indices derived from
dimensions; used bysplit_parameters().- Type:
ndarray
- __init__(evidence: Evidence, model_config: ParameterConfig, likelihood_configs: list | None = None, likelihood_scaling: float | None = None)[source]#
Methods
__init__(evidence, model_config[, ...])conditional_posterior(x_lm, lm_index, ym)Log posterior for one likelihood sector, conditioned on observed data.
Evaluate the scaled log likelihood at a flat parameter vector.
Evaluate the log posterior at a flat parameter vector.
log_posterior_batch(thetas)Evaluate the log posterior for a batch of parameter vectors.
log_prior(x)Evaluate the joint log prior at a flat parameter vector.
predict(xmodel)Generate model predictions for every constraint.
Map unit-cube coordinates to physical parameters (Dynesty interface).
Split a flat parameter vector into model and likelihood sub-vectors.
starting_location(nwalkers)Generate initial walker positions across all parameter sectors.
Attributes
model first, then likelihoods.
Flat parameter names in sampler order.
All
Parameterobjects in flat sampler order.Prior distribution objects in parameter-sector order.
- property parameter_configs: list#
model first, then likelihoods.
- Type:
All parameter sectors in flat sampler order
- property parameters: List[Parameter]#
All
Parameterobjects in flat sampler order.The order matches the flat parameter vector consumed by
log_posterior(),log_likelihood(), andstarting_location().
- property parameter_names: List[str]#
Flat parameter names in sampler order.
Convenience accessor equivalent to
[p.name for p in self.parameters]. Provided for compatibility with external drivers such as black-box-bayes that export inference results keyed by name.
- property prior: list#
Prior distribution objects in parameter-sector order.
Returns one entry per sector: the model prior first, followed by one entry per likelihood sector. Each entry is whatever was passed as
priorto the correspondingParameterConfig— a list of univariate distributions, a multivariate distribution, or a custom prior object.
- split_parameters(x) tuple[source]#
Split a flat parameter vector into model and likelihood sub-vectors.
- Parameters:
x (ndarray, shape (ndim,)) – Flat parameter vector in sampler order.
- Returns:
xmodel (ndarray) – Model parameter sub-vector of shape
(model_config.ndim,).xlikelihoods (list of ndarray) – One sub-vector per likelihood sector.
- log_prior(x) float[source]#
Evaluate the joint log prior at a flat parameter vector.
- Parameters:
x (ndarray, shape (ndim,)) – Flat parameter vector in sampler order.
- Returns:
float – Sum of log prior densities across all sectors.
- log_likelihood(x) float[source]#
Evaluate the scaled log likelihood at a flat parameter vector.
- Parameters:
x (ndarray, shape (ndim,)) – Flat parameter vector in sampler order.
- Returns:
float –
likelihood_scaling * evidence.log_likelihood(xmodel, xlikelihoods).
- log_posterior(x) float[source]#
Evaluate the log posterior at a flat parameter vector.
Returns
-infimmediately if either the prior or likelihood is non-finite, avoiding unnecessary model evaluations.- Parameters:
x (ndarray, shape (ndim,)) – Flat parameter vector in sampler order.
- Returns:
float –
log_prior(x) + log_likelihood(x), or-infif either term is non-finite.
- log_posterior_batch(thetas: ndarray) ndarray[source]#
Evaluate the log posterior for a batch of parameter vectors.
Convenience wrapper for external orchestration layers (e.g. black-box-bayes). The current implementation is serial but preserves the advertised interface for future parallelisation.
- Parameters:
thetas (ndarray, shape (…, ndim)) – Batch of parameter vectors.
- Returns:
ndarray, shape (n,) – Log posterior value for each row of
thetas.- Raises:
ValueError – If the trailing dimension of
thetasis notndim.
- starting_location(nwalkers: int) ndarray[source]#
Generate initial walker positions across all parameter sectors.
- Parameters:
nwalkers (int) – Number of walkers.
- Returns:
ndarray, shape (nwalkers, ndim) – Concatenated initial positions from each sector’s proposal distribution.
- prior_transform(u) ndarray[source]#
Map unit-cube coordinates to physical parameters (Dynesty interface).
Delegates to
ParameterConfig.prior_transform()for each sector, which in turn either callsppfon each element of a list prior or callsprior_transformdirectly on a joint prior object.- Parameters:
u (array-like, shape (ndim,)) – Unit-cube coordinates, each in
[0, 1).- Returns:
theta (ndarray, shape (ndim,)) – Physical parameter vector.
- Raises:
NotImplementedError – If any sector’s prior does not support a transform (see
ParameterConfig.prior_transform()).ValueError – If
udoes not have lengthndim.
- predict(xmodel) list[source]#
Generate model predictions for every constraint.
- Parameters:
xmodel (ndarray, shape (model_config.ndim,)) – Physical model parameter vector.
- Returns:
list of ndarray – Predicted observable for each constraint, in the order
evidence.constraints + evidence.parametric_constraints.
- conditional_posterior(x_lm, lm_index: int, ym) float[source]#
Log posterior for one likelihood sector, conditioned on observed data.
Evaluates
marginal_log_likelihood(ym, *x_lm) + prior_logpdf(x_lm)for the likelihood sector atlm_index. Useful for Gibbs-style updates where the likelihood parameters are sampled separately from the physical model parameters.- Parameters:
x_lm (ndarray, shape (likelihood_configs[lm_index].ndim,)) – Parameter vector for the target likelihood sector.
lm_index (int) – Index into
likelihood_configs(andevidence.parametric_constraints).ym (ndarray) – Predicted observable used as the conditioning data.
- Returns:
float – Log posterior for this likelihood sector.