sbi.diagnostics.run_sbc#
- run_sbc(thetas, xs, posterior, num_posterior_samples=1000, reduce_fns='marginals', num_workers=1, show_progress_bar=True, use_batched_sampling=True, **kwargs)[source]#
Run simulation-based calibration (SBC) or expected coverage.
Note: This function implements two versions of coverage diagnostics:
Setting
reduce_fns = "marginals"performs SBC as proposed in Talts et al. (see https://arxiv.org/abs/1804.06788).Setting
reduce_fns = posterior.log_probperforms sample-based expected coverage as proposed in Deistler et al. (see https://arxiv.org/abs/2210.04815).
- Parameters:
thetas (Tensor) – Ground-truth parameters for SBC, simulated from the prior.
xs (Tensor) – Observed data for SBC, simulated from thetas.
posterior (NeuralPosterior) – A posterior obtained from sbi.
num_posterior_samples (int) – Number of approximate posterior samples used for ranking.
reduce_fns (str | Callable[[Tensor, Tensor], Tensor] | List[Callable[[Tensor, Tensor], Tensor]]) – Function used to reduce the parameter space into 1D. Simulation-based calibration can be recovered by setting this to the string “marginals”. Sample-based expected coverage can be recovered by setting it to posterior.log_prob (as a Callable).
num_workers (int) – Number of CPU cores to use in parallel.
show_progress_bar (bool) – Whether to display a progress bar over SBC runs.
use_batched_sampling (bool) – Whether to use batched sampling for posterior samples.
- Returns:
Ranks of the ground truth parameters under the inferred posterior. dap_samples: Samples from the data-averaged posterior.
- Return type:
ranks