Skip to main content

sbijax

ci codecov documentation version

Simulation-based inference in JAX

Sbijax is a Python library for neural simulation-based inference and approximate Bayesian computation using JAX. It implements recent methods, such as Simulated Annealing ABC, Surjective Neural Likelihood Estimation, Neural Approximate Sufficient Statistics or Neural Posterior Score Estimation.

[!CAUTION] ⚠️ As per the LICENSE file, there is no warranty whatsoever for this free software tool. If you discover bugs, please report them.

Quick start

Sbijax implements a fully functional API in the idiom of Haiku: every method is a factory returning a record of pure functions, with parameters threaded explicitly. All a user needs to define is a prior, a simulator function and an inferential algorithm. For example, you can define a neural likelihood estimation method and generate posterior samples like this:

from jax import numpy as jnp, random as jr
from tensorflow_probability.substrates.jax import distributions as tfd

from sbijax import nle, train, sample, simulate
from sbijax.mcmc import make_sampler, nuts
from sbijax.nn import make_maf

prior = tfd.JointDistributionNamed(dict(
    theta=tfd.Normal(jnp.zeros(2), jnp.ones(2))
), batch_ndims=0)

def simulator_fn(seed, theta):
    p = tfd.Normal(jnp.zeros_like(theta["theta"]), 0.1)
    y = theta["theta"] + p.sample(seed=seed)
    return y

estimator = nle(make_maf(2))

y_observed = jnp.array([-1.0, 1.0])
data = simulate(jr.key(1), prior, simulator_fn, n=10_000)
params, info = train(jr.key(2), estimator, data)
samples, _ = sample(
    jr.key(3), estimator, params, y_observed,
    sampler=make_sampler(nuts, prior=prior),
)

More self-contained examples can be found in examples.

Installation

Make sure to have a working JAX installation. Depending whether you want to use CPU/GPU/TPU, please follow these instructions.

To install from PyPI, just call the following on the command line:

pip install sbijax

To install the latest GitHub , use:

pip install git+https://github.com/dirmeier/sbijax@<RELEASE>

Documentation

Documentation can be found here.

Citing sbijax

If you find our work relevant to your research, please consider citing:

@article{dirmeier2024simulation,
  title={Simulation-based inference with the Python Package sbijax},
  author={Dirmeier, Simon and Ulzega, Simone and Mira, Antonietta and Albert, Carlo},
  journal={arXiv preprint arXiv:2409.19435},
  year={2024}
}

Acknowledgements

[!NOTE] 📝 The API of the package is heavily inspired by Haiku.

Download files

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

Source Distribution

sbijax-0.4.0.tar.gz (13.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sbijax-0.4.0-py3-none-any.whl (110.8 kB view details)

Uploaded Python 3

File details

Details for the file sbijax-0.4.0.tar.gz.

File metadata

  • Download URL: sbijax-0.4.0.tar.gz
  • Upload date:
  • Size: 13.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sbijax-0.4.0.tar.gz
Algorithm Hash digest
SHA256 80ee830bc576aaf50bfb6bf72e70bb49d72bfaa77bd3f17d93e031fe2b11227f
MD5 27546a7e74ff85e7d345ff5140b6c64a
BLAKE2b-256 e997ec0e0ae2b7609d94d23fea307cee2dc8efc6f04cf473528bc60f46844dc3

See more details on using hashes here.

File details

Details for the file sbijax-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: sbijax-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 110.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sbijax-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35db3c8f66ad7c1f674ea85fa4379883b7f1fcd304c495e8f549801a1a206bae
MD5 f947066c80f92cccc0094f0710c11e71
BLAKE2b-256 ed0eba1219cf805ba179f138c517fb8999de084b80f0f9d73522a2158adff439

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.6

2 files

0.3.4

2 files

0.3.3.post1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page