API Reference

This page contains the API reference for scisbi.

Core Package

Base Classes

class scisbi.base.BaseInferenceAlgorithm(simulator: BaseSimulator, prior: Any, summary_statistic: BaseSummaryStatistic | None = None, **kwargs: Any)[source]

Bases: ABC

Abstract base class for all Simulation-Based Inference algorithms.

Concrete implementations should inherit from this class and implement the abstract methods. This base class handles the storage of fundamental components like the simulator, prior, and optional summary statistic.

abstract infer(observed_data: Any, num_simulations: int, **kwargs: Any) Any[source]

Runs the simulation-based inference process.

This method orchestrates the simulation, training (if applicable), and posterior estimation steps. The implementation will vary significantly between different SBI algorithms (e.g., ABC, SNPE, SNL, SRE).

Parameters:
  • observed_data (Any) – The observed data point(s) to perform inference on. If a summary statistic was provided during initialization, this data might be the raw observed data which will be transformed internally using the summary statistic. Otherwise, its type/format depends on the simulator’s output structure.

  • num_simulations (int) – The total number of simulations the algorithm is allowed to run across potentially multiple rounds.

  • **kwargs – Algorithm-specific parameters for this specific inference run. Examples might include: number of training epochs for a single round, specific random seeds, control over output verbosity for this run. These override settings from __init__.

Returns:

An object representing the estimated posterior distribution.

This object should provide methods to query the posterior, e.g., sample, log_prob (if density is available).

Return type:

Any

Raises:
  • NotImplementedError – If the method is not implemented by a concrete class.

  • Any other exception relevant to the specific algorithm's execution.

class scisbi.base.BaseSimulator(**kwargs)[source]

Bases: ABC

Abstract base class for simulators.

A simulator takes parameters and generates data/observations.

abstract simulate(parameters, num_simulations=1)[source]

Runs the simulator for a given set of parameters multiple times.

Parameters:
  • parameters – The parameters for the simulation(s). Format depends on the simulator’s input requirements (e.g., a NumPy array, a dictionary, a backend tensor). Assumes these parameters are applied to each simulation run or define the distribution from which parameters for each run are drawn.

  • num_simulations – The number of simulations to run for the given parameters. Defaults to 1.

Returns:

The simulated data/observations. The output should be structured to accommodate multiple simulation results (e.g., a list, a batch tensor with an added dimension for the simulation index). Format depends on the simulator output.

class scisbi.base.BaseSummaryStatistic(**kwargs: Any)[source]

Bases: ABC

Abstract base class for functions that compute summary statistics from data.

abstract compute(data: TensorLike) TensorLike[source]

Computes summary statistics for the given data.

Parameters:

data – The input data. Format depends on the simulator output. Can be varied, hence Any.

Returns:

The computed summary statistics. Format can vary (e.g., NumPy array, dictionary), hence Any.

get_config() Dict[str, Any][source]

Returns the configuration parameters used to initialize the summary statistic.

abstract visualize(stats: Any)[source]

Generates a visualization of the summary statistics.

class scisbi.base.BaseWorkflow(simulator: BaseSimulator, prior: Any, inference_algorithm: BaseInferenceAlgorithm, summary_statistic: BaseSummaryStatistic | None = None, **kwargs: Any)[source]

Bases: ABC

Abstract base class for defining and executing a complete SBI workflow.

A workflow combines a simulator, prior, inference algorithm, summary statistic, etc.

abstract run(observed_data: Any, num_simulations: int, **kwargs: Any) Any[source]

Executes the complete SBI workflow.

Parameters:
  • observed_data (Any) – The observed data. Format depends on the simulator output. Use Any.

  • num_simulations (int) – The number of simulations to run for inference.

  • **kwargs – Additional parameters for running the workflow.

Returns:

The estimated posterior distribution.

Return type:

Any

Inference Methods

Simulators

Summary Statistics