MCPcopy Index your code
hub / github.com/dirmeier/sbijax

github.com/dirmeier/sbijax @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
511 symbols 1,983 edges 130 files 156 documented · 31% updated 3d agov0.4.0 · 2026-07-04★ 523 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Core symbols most depended-on inside this repo

sample
called by 62
sbijax/_src/nn/make_continuous_flow.py
log_prob
called by 25
sbijax/_src/experimental/nn/make_score_network.py
simulate
called by 23
sbijax/_src/simulate/simulate.py
train
called by 22
sbijax/_src/train/train.py
sample
called by 17
sbijax/_src/train/sample.py
make_maf
called by 12
sbijax/_src/nn/make_flow.py
update
called by 11
sbijax/_src/util/early_stopping.py
make_sampler
called by 8
sbijax/_src/mcmc/sampler.py

Shape

Function 406
Method 73
Class 32

Languages

Python100%

Modules by API surface

sbijax/_src/inference/abc/_sabc_engine.py34 symbols
experiments/sabc-performance/tasks.py34 symbols
sbijax/_src/experimental/nn/make_score_network.py23 symbols
experiments/sabc-performance/main.py16 symbols
sbijax/_src/nn/make_continuous_flow.py14 symbols
sbijax/_src/inference/abc/_smcabc_engine.py13 symbols
sbijax/_src/nn/make_consistency_model.py12 symbols
sbijax/_src/inference/ratio/nre.py11 symbols
examples/snle.py11 symbols
sbijax/_src/nn/make_flow.py10 symbols
sbijax/_src/simulators/solar_dynamo.py9 symbols
sbijax/_src/inference/posterior/npe.py9 symbols

For agents

$ claude mcp add sbijax \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact