superstats.diagnostics.metrics#
Numerical diagnostics for posterior estimates over time.
Functions
|
Marginal calibration error per step and parameter. |
|
Pearson correlation between point estimates and true values, per step and parameter. |
|
Normalized RMSE between posterior samples and targets, per step and parameter. |
|
Posterior contraction per step and parameter. |
- superstats.diagnostics.metrics.calibration_error_per_step(estimates, targets, resolution=20, aggregation=<function median>, min_quantile=0.005, max_quantile=0.995)[source]#
Marginal calibration error per step and parameter.
Computes an aggregate score for the marginal calibration error over an ensemble of approximate posteriors, per step (time step). The calibration error is given as the aggregate (e.g. median) of the absolute deviation between an alpha-CI and the relative number of inliers from estimates, over multiple alphas in (0, 1).
- Parameters:
- estimates
np.ndarrayofshape(num_sim,num_samples,num_steps,num_params) Posterior samples.
- targets
np.ndarrayofshape(num_sim,num_steps,num_params) Ground-truth parameter values.
- resolution
int,optional, default: 20 Number of credibility intervals (CIs) to consider.
- aggregation
callable(),optional, default:np.median Function used to aggregate the per-alpha calibration errors. Typically np.mean or np.median.
- min_quantile
floatin(0, 1),optional, default: 0.005 Minimum posterior quantile to consider.
- max_quantile
floatin(0, 1),optional, default: 0.995 Maximum posterior quantile to consider.
- estimates
- Returns:
- calibration_error
np.ndarrayofshape(num_steps,num_params) - aggregated calibration error, per step and parameter
- calibration_error
- Parameters:
- Return type:
- superstats.diagnostics.metrics.correlation_per_step(estimates, targets, aggregation=<function median>)[source]#
Pearson correlation between point estimates and true values, per step and parameter.
Posterior samples are first collapsed to a point estimate per simulation, step, and parameter (using aggregation), then the Pearson correlation between those point estimates and targets is computed across simulations.
- Parameters:
- estimates
np.ndarrayofshape(num_sim,num_samples,num_steps,num_params) Posterior samples.
- targets
np.ndarrayofshape(num_sim,num_steps,num_params) Ground-truth parameter values.
- aggregation
callable(),optional, default:np.median Function used to collapse posterior samples into a point estimate per simulation, step, and parameter. Typically np.mean or np.median.
- estimates
- Returns:
- correlation
np.ndarrayofshape(num_steps,num_params) -Pearson correlation per step and parameter
- correlation
- Parameters:
- Return type:
- superstats.diagnostics.metrics.nrmse_per_step(estimates, targets, aggregation=<function median>)[source]#
Normalized RMSE between posterior samples and targets, per step and parameter.
RMSE is computed across posterior draws (not aggregated first) for each simulation, then normalized by a prior-only bootstrap RMSE aggregated across simulations. This follows the “prior” normalization scheme: 0 indicates a maximally informative posterior (point mass at ground truth), 1 indicates a non-informative posterior (equivalent to the prior). The per-simulation ratios are then aggregated over simulations (using aggregation, mirroring the bayesflow convention of aggregating the final metric with the same function used for the normalizer), yielding one value per step and parameter.
- Parameters:
- estimates
np.ndarrayofshape(num_sim,num_samples,num_steps,num_params) Posterior samples per simulation.
- targets
np.ndarrayofshape(num_sim,num_steps,num_params) Target parameter trajectories (themselves prior draws, in a simulation-based calibration setting).
- aggregation
callable(),optional, default:np.median Function used to aggregate both the prior-only bootstrap RMSE (for the normalizer) and the final per-simulation nRMSE values across simulations. Typically np.mean or np.median.
- estimates
- Returns:
- nrmse
np.ndarrayofshape(num_steps,num_params) -RMSEacross posterior draws, normalized by the aggregated prior-only bootstrap RMSE, aggregated across simulations
- nrmse
- Parameters:
- Return type:
- superstats.diagnostics.metrics.posterior_contraction_per_step(estimates, targets, aggregation=<function median>)[source]#
Posterior contraction per step and parameter.
Computes 1 minus the ratio of posterior to prior variance (using the unbiased/sample variance, ddof=1) for each simulation, step, and parameter, clipped to [0, 1], then aggregates across simulations (using aggregation) to yield one value per step and parameter. Matches the bayesflow posterior_contraction metric, extended over an additional time-step axis.
- Parameters:
- estimates
np.ndarrayofshape(num_sim,num_samples,num_steps,num_params) Posterior samples.
- targets
np.ndarrayofshape(num_sim,num_steps,num_params) Ground-truth parameter values, used to estimate the prior variance per step and parameter.
- aggregation
callable(),optional, default:np.median Function used to aggregate the per-simulation contraction values across simulations. Typically np.mean or np.median.
- estimates
- Returns:
- contraction
np.ndarrayofshape(num_steps,num_params) - 1minus the ratio of posterior to prior variance, per step and parameter, clipped to [0, 1], aggregated across simulations
- contraction
- Parameters:
- Return type: