rxmc.constraint.Constraint#
- class rxmc.constraint.Constraint(observations: list[Observation], physical_model: PhysicalModel, likelihood_model: LikelihoodModel)[source]#
Bases:
objectPair observations with a physical model and a likelihood model.
A
Constraintis the composition of one or moreObservationobjects with aPhysicalModeland aLikelihoodModel. It acts as a box that accepts model parameters and returns the log likelihood or other statistics, acting as a constraint on those parameters.- Parameters:
observations (list of Observation) – The observed data that the model will attempt to reproduce.
physical_model (PhysicalModel) – Model that predicts the observed data.
likelihood_model (LikelihoodModel) – Model that defines the likelihood of the observations given the physical-model predictions.
- __init__(observations: list[Observation], physical_model: PhysicalModel, likelihood_model: LikelihoodModel)[source]#
Methods
__init__(observations, physical_model, ...)chi2(model_params[, likelihood_params])Generalised chi-squared (Mahalanobis distance) summed over observations.
empirical_coverage(ylow, yhigh[, xlim])Fraction of data points within a predictive interval.
log_likelihood(model_params[, likelihood_params])Total log likelihood over all observations.
marginal_log_likelihood(ym, *likelihood_params)Log likelihood given pre-computed model predictions.
model(model_params)Compute the physical model output for each observation.
num_pts_within_interval(ylow, yhigh[, xlim])Count data points that fall within a predictive interval.
predict(*model_params)Generate predictions for each observation.
- model(model_params)[source]#
Compute the physical model output for each observation.
- Parameters:
model_params (tuple) – Parameters of the physical model.
- Returns:
list of np.ndarray – Model predictions, one array per observation.
- log_likelihood(model_params, likelihood_params=())[source]#
Total log likelihood over all observations.
- Parameters:
model_params (tuple) – Parameters of the physical model.
likelihood_params (tuple, optional) – Additional parameters for the likelihood model.
- Returns:
float – Sum of log likelihoods across all observations.
- marginal_log_likelihood(ym: list, *likelihood_params)[source]#
Log likelihood given pre-computed model predictions.
- Parameters:
ym (list of np.ndarray) – Pre-computed model predictions for each observation.
*likelihood_params (float) – Additional parameters for the likelihood model.
- Returns:
float – Sum of log likelihoods across all observations.
- chi2(model_params, likelihood_params=())[source]#
Generalised chi-squared (Mahalanobis distance) summed over observations.
- Parameters:
model_params (tuple) – Parameters of the physical model.
likelihood_params (tuple, optional) – Additional parameters for the likelihood model.
- Returns:
float – Total chi-squared statistic.
- predict(*model_params)[source]#
Generate predictions for each observation.
- Parameters:
*model_params (float) – Parameters of the physical model.
- Returns:
list of np.ndarray – Predicted values for each observation.
- num_pts_within_interval(ylow: list[ndarray], yhigh: list[ndarray], xlim=None)[source]#
Count data points that fall within a predictive interval.
- Parameters:
ylow (list of np.ndarray) – Lower bounds of the interval for each observation.
yhigh (list of np.ndarray) – Upper bounds of the interval for each observation.
xlim (tuple, optional) –
(x_min, x_max)range to restrict the count.
- Returns:
int – Total number of points within the interval across all observations.
- empirical_coverage(ylow: list[ndarray], yhigh: list[ndarray], xlim=None)[source]#
Fraction of data points within a predictive interval.
- Parameters:
ylow (list of np.ndarray) – Lower bounds of the interval for each observation.
yhigh (list of np.ndarray) – Upper bounds of the interval for each observation.
xlim (tuple, optional) –
(x_min, x_max)range to restrict the count.
- Returns:
float – Empirical coverage fraction in
[0, 1].