--- sd_hide_title: true --- # setu ```{image} _static/logo.png :alt: setu logo :width: 180px :align: center ``` ```{div} sd-text-center sd-fs-5 A bridge from simulation-based inference to PyMC and NumPyro. ``` Many scientific models are simulators: they generate data from parameters, but do not provide the likelihood $p(x \mid \theta)$, the probability of an observation for a given set of parameters. That is exactly what Bayesian tools like PyMC and NumPyro need to recover the parameters behind observed data, so a simulator cannot be plugged into them directly. setu (Sanskrit for *bridge*) closes that gap. It learns the likelihood from simulated data and exports it to a probabilistic programming language (PPL) in a single call, so the model, including priors, hierarchy, and posterior-predictive checks, is written in PyMC or NumPyro as usual. ```bash pip install setu-sbi ``` Three steps take a simulator to a posterior: simulate, train a neural likelihood, export it into a PPL. ```python import jax import pymc as pm import setu key = jax.random.key(0) # `prior` samples parameters; `simulator` maps parameters to data. # No tractable likelihood is required, which is the whole point. dataset = setu.simulate_dataset(simulator, prior, n_samples=10_000, key=key) # 1. Train a neural likelihood on the simulations. nle = setu.create_nle(x_dim=3, theta_dim=3, key=key) nle = setu.fit_nle(nle, dataset, key=key).nle # 2. Export it into a PyMC model and sample the posterior as usual. with pm.Model(): theta = pm.Normal("theta", 0.0, 1.0, shape=3) setu.to_pymc(nle, theta=theta, x_observed=x_obs) idata = pm.sample( nuts_sampler="blackjax", nuts_sampler_kwargs={"chain_method": "vectorized"}, progressbar=False, ) ``` setu fits a specific case: an intractable likelihood together with repeated or hierarchical structure in the data. With a tractable likelihood, a PPL alone (PyMC, NumPyro, Stan) suffices; with high-dimensional observations and no repeated or hierarchical structure, a general SBI toolkit such as [sbi](https://sbi-dev.github.io/sbi/) or [BayesFlow](https://bayesflow.org/) fits better ([more on when to use setu](explanation/what-is-sbi)). Within that niche it complements both, and tends to be faster on the [benchmarked task](explanation/benchmarks). ```{div} sd-text-center **New here? Start with [Tutorial 1](tutorials/index).** ``` ::::{grid} 1 1 2 2 :gutter: 3 :::{grid-item-card} Tutorials :link: tutorials/index :link-type: doc Learning-oriented, hand-held walkthroughs. Go from a simulator to a posterior in one sitting. ::: :::{grid-item-card} How-to guides :link: how-to/index :link-type: doc Task-oriented recipes for a specific goal, starting with installing the right extras. ::: :::{grid-item-card} Reference :link: reference/index :link-type: doc Lookup: the full API, the `(G, S, T, *E)` shape conventions, and a glossary. ::: :::{grid-item-card} Explanation :link: explanation/index :link-type: doc Understanding-oriented essays: what SBI is, why validation matters, why hierarchical inference is powerful, and how fast setu is. ::: :::: ```{toctree} :hidden: :maxdepth: 1 tutorials/index how-to/index reference/index explanation/index ```