Simulation-based inference in JAX
Project description
sbijax 
Simulation-based inference in JAX
About
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 Consistency model posterior estimation, as well as methods to compute model
diagnostics and for visualizing posterior distributions.
[!CAUTION] ⚠️ As per the LICENSE file, there is no warranty whatsoever for this free software tool. If you discover bugs, please report them.
Examples
Sbijax implements a slim object-oriented API with functional elements stemming from
JAX. All a user needs to define is a prior model, 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 sbijax import NLE
from sbijax.nn import make_maf
from tensorflow_probability.substrates.jax import distributions as tfd
def prior_fn():
prior = tfd.JointDistributionNamed(dict(
theta=tfd.Normal(jnp.zeros(2), jnp.ones(2))
), batch_ndims=0)
return prior
def simulator_fn(seed, theta):
p = tfd.Normal(jnp.zeros_like(theta["theta"]), 0.1)
y = theta["theta"] + p.sample(seed=seed)
return y
fns = prior_fn, simulator_fn
model = NLE(fns, make_maf(2))
y_observed = jnp.array([-1.0, 1.0])
data, _ = model.simulate_data(jr.PRNGKey(1))
params, _ = model.fit(jr.PRNGKey(2), data=data)
posterior, _ = model.sample_posterior(jr.PRNGKey(3), params, y_observed)
More self-contained examples can be found in examples.
Documentation
Documentation can be found here.
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>
Contributing
Contributions in the form of pull requests are more than welcome. A good way to start is to check out issues labelled good first issue.
In order to contribute:
- Clone
sbijaxand installhatchviapip install hatch, - create a new branch locally
git checkout -b feature/my-new-featureorgit checkout -b issue/fixes-bug, - implement your contribution and ideally a test case,
- test it by calling
make tests,make lintsandmake formaton the (Unix) command line, - submit a PR 🙂
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 the excellent Pytorch-based
sbipackage.
Author
Simon Dirmeier sfyrbnd @ pm me
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sbijax-0.3.4.tar.gz.
File metadata
- Download URL: sbijax-0.3.4.tar.gz
- Upload date:
- Size: 47.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb2ac0d25ade8783fed1ccb6916ab336ecca9b159056b5ef7dcfa7c9b865765f
|
|
| MD5 |
3af9d19735abed80d3b5e4364e83d570
|
|
| BLAKE2b-256 |
2b5330e7f61c1151f3dea721a9b96ceb54bb1fcefb4902cbb0629f0ebe2d42ae
|
File details
Details for the file sbijax-0.3.4-py3-none-any.whl.
File metadata
- Download URL: sbijax-0.3.4-py3-none-any.whl
- Upload date:
- Size: 82.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58751377fd9ee9f55928e0a6569375bf329adf3a244fc184ef521eeb6dfb9981
|
|
| MD5 |
ebb3c8a8f941380bce2c593cf2216ae5
|
|
| BLAKE2b-256 |
8662cb4212f728859528b9913a1b177d2fc0bc4dfb7f01f6e8a44b019b857d70
|