Worked tutorials

Start with Compile your first function, then follow a complete workflow below. Each page combines the explanation, runnable code and output. Download its Python script or Jupyter notebook from the bottom of the page.

  • New to inference? Start with the Normal model and its known posterior.

  • Have a dataframe? Fit a mixed model with automatic coordinate transforms.

  • Have arrays? Pass runtime data to the Gaussian regression.

  • Want a portable analysis? Save a regression to ZIP, reload it, and fit MAP.

  • Using an inference package? Sample and approximate with BlackJAX, sample with NumPyro, fit with Optax, and diagnose with ArviZ, all from module.logdensity(...).

  • Fitting or sampling outside JAX? Read Hesse and Minos errors with iminuit, minimize with optimistix, or sample with nutpie.

  • Starting from ROOT files? Read histograms with uproot and hist, or build a workspace with cabinetry and run a discovery fit on the FlatPPL likelihood.

  • Shipping a model? Export the compiled density with jax.export and run it without FlatPPL.

  • Running toys? Batch pseudo-experiments with jax.vmap and switch the lowering target between CPU and GPU.

  • Want the whole workflow? Go from a model file and a dataframe to checked posterior draws, or import the published Belle II likelihood, fit, profile and sample it.

  • Have a FlatPPL model? Query its bindings, inspect its graph, or run a file from the example corpus.

For a pyhf workspace, use Import a pyhf model. The Coordinate transforms for inference reference explains how to pass constrained parameters to an unconstrained sampler.

The documentation build executes these scripts against the installed package. Each script states its runtime budget; the build fails if it exceeds that limit.

Sample a posterior with BlackJAX NUTS

Sample a posterior with BlackJAX NUTS

Sample and approximate a posterior with BlackJAX

Sample and approximate a posterior with BlackJAX

Sample a posterior with NumPyro’s NUTS

Sample a posterior with NumPyro's NUTS

Fit maximum a posteriori and maximum likelihood points with Optax

Fit maximum a posteriori and maximum likelihood points with Optax

Diagnose draws with ArviZ

Diagnose draws with ArviZ

Sample a posterior with nutpie

Sample a posterior with nutpie

Fit with optimistix BFGS and Levenberg-Marquardt

Fit with optimistix BFGS and Levenberg-Marquardt

Fit with iminuit and read Hesse and Minos errors

Fit with iminuit and read Hesse and Minos errors

Fit a mixed model with automatic coordinate transforms

Fit a mixed model with automatic coordinate transforms

From a model file and a dataframe to checked posterior draws

From a model file and a dataframe to checked posterior draws

A published Belle II likelihood: pyhf to FlatPPL to JAX

A published Belle II likelihood: pyhf to FlatPPL to JAX

Fit a Gaussian regression with runtime data

Fit a Gaussian regression with runtime data

Save a regression, reload it, and fit MAP

Save a regression, reload it, and fit MAP

Read histograms from ROOT files with uproot and hist

Read histograms from ROOT files with uproot and hist

A discovery fit from ROOT histograms with cabinetry

A discovery fit from ROOT histograms with cabinetry

Export a compiled density with jax.export

Export a compiled density with jax.export

Evaluate batched toys on CPU and GPU

Evaluate batched toys on CPU and GPU

Query any binding of a model

Query any binding of a model

Inspect a model’s graph

Inspect a model's graph

Check a model from the example corpus

Check a model from the example corpus

Gallery generated by Sphinx-Gallery