sbi.inference.simulate_for_sbi

Navigation

sbi.inference.simulate_for_sbi#

simulate_for_sbi(simulator, proposal, num_simulations, num_workers=1, simulation_batch_size=1, seed=None, show_progress_bar=True)[source]#

Returns pairs \((\theta, x)\) by sampling proposal and running simulations.

This function performs two steps:

  • Sample parameters \(\theta\) from the proposal.

  • Simulate these parameters to obtain \(x\).

Parameters:
  • simulator (Callable) – A function that takes parameters \(\theta\) and maps them to simulations, or observations, x, \(\text{sim}(\theta)\to x\). Any regular Python callable (i.e. function or class with __call__ method) can be used. Note that the simulator should be able to handle numpy arrays for efficient parallelization. You can use process_simulator to ensure this.

  • proposal (Any) – Probability distribution that the parameters \(\theta\) are sampled from.

  • num_simulations (int) – Number of simulations that are run.

  • num_workers (int) – Number of parallel workers to use for simulations.

  • simulation_batch_size (int | None) – Number of parameter sets of shape (simulation_batch_size, parameter_dimension) that the simulator receives per call. If None, we set simulation_batch_size=num_simulations and simulate all parameter sets with one call. Otherwise, we construct batches of parameter sets and distribute them among num_workers.

  • seed (int | None) – Seed for reproducibility.

  • show_progress_bar (bool) – Whether to show a progress bar for simulating. This will not affect whether there will be a progressbar while drawing samples from the proposal.

Return type:

Tuple[Tensor, Tensor]

Returns: Sampled parameters \(\theta\) and simulation-outputs \(x\).