ProbJax¶
A JAX-native research toolbox for probabilistic computation: probabilistic-program
transformations, SciPy-style distributions, automatic program inversion, a large
inference suite, and Flax NNX generative models — all jit-able and vmap-able
together.
Note
ProbJax is research software. APIs evolve, and the accelerator-specific kernels and sharding features are experimental.
import jax
import jax.numpy as jnp
from probjax.core import condition, joint_sample, log_joint_fn
from probjax.stats import norm
def model(key):
key_z, key_y = jax.random.split(key)
z = norm.rvs(key_z, 0.0, 1.0, name="z")
return norm.rvs(key_y, z, 0.5, name="y")
# Sample every named site at once
sites = joint_sample(model)(jax.random.key(0))
# Condition on an observation and score the latent
posterior = condition(model, {"y": jnp.asarray(0.25)})
latent = joint_sample(posterior)(jax.random.key(1))["z"]
log_joint = log_joint_fn(posterior)(z=latent)
What is here¶
-
Probabilistic programs
Write an ordinary JAX function, then
trace,condition,observe,interveneandjoint_sampleit. Sampling a distribution inside a transformation records a named site; outside one it is a plain JAX sample. -
Program inversion
inverseandinverse_and_logabsdetwalk a jaxpr backwards to build the inverse of a function, withcustom_inversefor the parts that need an analytic rule. See Program inversion. -
Density estimation
Normalizing flows, autoregressive models, diffusion and flow matching, with one
fitand oneas_distinterface across all of them. See Density estimation. -
Inference
Ten MCMC kernels, SMC, Kalman-family filters and particle filtering, plus flow-based variational inference and NeuTra preconditioning. See Inference.
Install¶
Python 3.11 or newer. Accelerator options are in Getting started.
Examples¶
Runnable notebooks live in the repository rather than in these pages:
examples/core— tracing random variables, probabilistic programs, jaxpr graphsexamples/stats— distribution basics and higher-order distributionsexamples/inference— MCMC, SMC, Kalman filtering, Bayesian neural networksexamples/nnandexamples/utils
Some notebooks predate recent API refactors. Where a notebook disagrees with these pages, prefer these pages and the Reference.