Skip to main content

Simulation-based inference.

Project description

PyPI version Contributions welcome Tests codecov GitHub license DOI

sbi: Simulation-Based Inference

Getting Started | Documentation

sbi is a Python package for simulation-based inference, designed to meet the needs of both researchers and practitioners. Whether you need fine-grained control or an easy-to-use interface, sbi has you covered.

With sbi, you can perform simulation-based inference (SBI) using a Bayesian approach: Given a simulator that models a real-world process, SBI estimates the full posterior distribution over the simulator’s parameters based on observed data. This distribution indicates the most likely parameter values while additionally quantifying uncertainty and revealing potential interactions between parameters.

Key Features of sbi

sbi offers a blend of flexibility and ease of use:

  • Low-Level Interfaces: For those who require maximum control over the inference process, sbi provides low-level interfaces that allow you to fine-tune many aspects of your workflow.
  • High-Level Interfaces: If you prefer simplicity and efficiency, sbi also offers high-level interfaces that enable quick and easy implementation of complex inference tasks.

In addition, sbi supports a wide range of state-of-the-art inference algorithms (see below for a list of implemented methods):

  • Amortized Methods: These methods enable the reuse of posterior estimators across multiple observations without the need to retrain.
  • Sequential Methods: These methods focus on individual observations, optimizing the number of simulations required.

Beyond inference, sbi also provides:

  • Validation Tools: Built-in methods to validate and verify the accuracy of your inferred posteriors.
  • Plotting and Analysis Tools: Comprehensive functions for visualizing and analyzing results, helping you interpret the posterior distributions with ease.

Getting started with sbi is straightforward, requiring only a few lines of code:

from sbi.inference import SNPE
# Given: parameters theta and corresponding simulations x
inference = SNPE(prior=prior)
inference.append_simulations(theta, x).train()
posterior = inference.build_posterior()

Installation

sbi requires Python 3.9 or higher. While a GPU isn't necessary, it can improve performance in some cases. We recommend using a virtual environment with conda for an easy setup.

To install sbi, follow these steps:

  1. Create a Conda Environment (if using Conda):

    conda create -n sbi_env python=3.9 && conda activate sbi_env
    
  2. Install sbi: Independent of whether you are using conda or not, sbi can be installed using pip:

pip install sbi
  1. Test the installation: Open a Python prompt and run
from sbi.examples.minimal import simple
posterior = simple()
print(posterior)

Tutorials

If you're new to sbi, we recommend starting with our Getting Started tutorial.

You can also access and run these tutorials directly in your browser by opening Codespace. To do so, click the green “Code” button on the GitHub repository and select “Open with Codespaces.” This provides a fully functional environment where you can explore sbi through Jupyter notebooks.

Inference Algorithms

The following inference algorithms are currently available. You can find instructions on how to run each of these methods here.

Neural Posterior Estimation: amortized (NPE) and sequential (SNPE)

Neural Likelihood Estimation: amortized (NLE) and sequential (SNLE)

Neural Ratio Estimation: amortized (NRE) and sequential (SNRE)

Neural Variational Inference, amortized (NVI) and sequential (SNVI)

Mixed Neural Likelihood Estimation (MNLE)

Feedback and Contributions

We welcome any feedback on how sbi is working for your inference problems (see Discussions) and are happy to receive bug reports, pull requests, and other feedback (see contribute). We wish to maintain a positive community; please read our Code of Conduct.

Acknowledgments

sbi is the successor (using PyTorch) of the delfi package. It started as a fork of Conor M. Durkan's lfi. sbi runs as a community project. See also credits.

Support

sbi has been supported by the German Federal Ministry of Education and Research (BMBF) through project ADIMEM (FKZ 01IS18052 A-D), project SiMaLeSAM (FKZ 01IS21055A) and the Tübingen AI Center (FKZ 01IS18039A). Since 2024, sbi is supported by the appliedAI Institute for Europe.

License

Apache License Version 2.0 (Apache-2.0)

Citation

If you use sbi consider citing the sbi software paper, in addition to the original research articles describing the specific sbi-algorithm(s) you are using.

@article{tejero-cantero2020sbi,
  doi = {10.21105/joss.02505},
  url = {https://doi.org/10.21105/joss.02505},
  year = {2020},
  publisher = {The Open Journal},
  volume = {5},
  number = {52},
  pages = {2505},
  author = {Alvaro Tejero-Cantero and Jan Boelts and Michael Deistler and Jan-Matthis Lueckmann and Conor Durkan and Pedro J. Gonçalves and David S. Greenberg and Jakob H. Macke},
  title = {sbi: A toolkit for simulation-based inference},
  journal = {Journal of Open Source Software}
}

The above citation refers to the original version of the sbi project and has a persistent DOI. Additionally, new releases of sbi are citable via Zenodo, where we create a new DOI for every release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sbi-0.23.0.tar.gz (14.1 MB view details)

Uploaded Source

Built Distribution

sbi-0.23.0-py3-none-any.whl (358.4 kB view details)

Uploaded Python 3

File details

Details for the file sbi-0.23.0.tar.gz.

File metadata

  • Download URL: sbi-0.23.0.tar.gz
  • Upload date:
  • Size: 14.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for sbi-0.23.0.tar.gz
Algorithm Hash digest
SHA256 eb7f6d6f7982ae5b9976f41bf7da9e91a909b3616cb5cef1f19e9b0ea8162f2f
MD5 a7f4ec13fa880f191d4e3bed37ba9296
BLAKE2b-256 f66de28440abf95a46b7e261789475a976dd79f54555e13fcd6933f83bc14ce2

See more details on using hashes here.

File details

Details for the file sbi-0.23.0-py3-none-any.whl.

File metadata

  • Download URL: sbi-0.23.0-py3-none-any.whl
  • Upload date:
  • Size: 358.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for sbi-0.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d4cb23a8eaad085180912e6c3f0d407448350af6bb1d425450924565effb86
MD5 423f671d8690d9eb80e6217324f44f5a
BLAKE2b-256 eec8acc532797f514d4579c6c37a563e9b49fd0d7ffb4cdb3d0385c2e3a740da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page