API reference#
Every public symbol lives in the flat setu namespace: import it as
from setu import NLE regardless of which submodule defines it. The tables
below group the surface by purpose for readability; each symbol is documented
once, and the linked page carries the full signature, parameters, and return
type.
Neural Likelihood Estimation (NLE)#
Learn the conditional density \(p(x \mid \theta)\) with a normalizing flow.
Neural Likelihood Estimator using normalizing flows. |
|
Result of NLE training. |
|
Create NLE with sensible defaults. |
|
Train NLE on simulation data. |
Mixed Neural Likelihood Estimation (MixedNLE)#
NLE for mixed discrete + continuous data (a flow for the continuous part, a CategoricalMADE for the discrete part).
Mixed Neural Likelihood Estimator for discrete/continuous data. |
|
Result of MixedNLE training. |
|
Create MixedNLE with sensible defaults. |
|
Train MixedNLE on simulation data. |
Discrete Neural Likelihood Estimation (DiscreteNLE)#
NLE for pure-discrete observations: a categorical head for bounded counts, or a CountMADE (ZINB / NegBinom / Poisson) for count data.
Discrete Neural Likelihood Estimator for categorical or count data. |
|
Result of DiscreteNLE training. |
|
Create a DiscreteNLE for categorical or count data. |
|
Train DiscreteNLE on simulation data. |
Neural Ratio Estimation (NRE)#
Learn a likelihood-to-evidence ratio with a classifier instead of a normalized density.
Neural Ratio Estimator using NRE-C algorithm. |
|
Result of NRE training. |
|
Create NRE with sensible defaults. |
|
Train NRE on simulation data using NRE-C loss. |
Data#
Simulation datasets and shape helpers. See Shape conventions for the
(G, S, T, *E) conventions these follow.
Dataset of (theta, x) simulation pairs with optional conditions. |
|
Dataset for estimator validation with optional conditions. |
|
Generate a SimulationDataset from a simulator and prior. |
|
One-hot encode integer IDs. |
|
Broadcast subject-level conditions to trial-level for hierarchical models. |
Serialization#
Save and load trained estimators (Equinox leaves plus a JSON metadata sidecar).
Save a trained NLE, MixedNLE, or DiscreteNLE to disk. |
|
Load a trained NLE, MixedNLE, or DiscreteNLE from disk. |
Transforms#
Z-scoring transforms applied to parameters and observations.
Z-scoring transform for data standardization. |
Metrics#
Sample-based distances for comparing estimator draws against ground truth.
Classifier Two-Sample Test using MLP. |
|
Maximum Mean Discrepancy with Gaussian (RBF) kernel. |
|
Sliced Wasserstein distance. |
|
Total variation distance between two discrete sample distributions. |
Simulators#
Reference simulators and their analytical likelihoods, used in tests and tutorials.
Sample x from linear Gaussian likelihood: x ~ N(theta + shift, cov). |
|
Sample theta from multivariate normal prior. |
|
Compute analytical log p(x|theta) for linear Gaussian. |
|
Compute analytical log ratio log r(x, theta) = log p(x|theta) - log p(x). |
|
Compute analytical log p(x) for linear Gaussian. |
PyMC integration#
Export a trained estimator as a PyMC likelihood term. See Shape conventions for the
(theta, x_observed) argument order.
Convert trained likelihood estimator (NLE or MixedNLE) to PyMC likelihood. |
|
Convert trained likelihood estimator (NLE or MixedNLE) to PyMC hierarchical likelihood. |
|
Convert trained MixedNLE to PyMC likelihood. |
|
Convert trained DiscreteNLE to PyMC likelihood. |
|
Convert trained NRE to PyMC likelihood using GenericLogpOp. |
|
Convert trained NRE to PyMC hierarchical likelihood. |
NumPyro integration#
Export a trained estimator as a NumPyro factor.
Add NLE/MixedNLE log-likelihood as a factor in the active NumPyro model. |
|
Add hierarchical NLE/MixedNLE log-likelihood as a factor in NumPyro. |
|
Add DiscreteNLE log-likelihood as a factor in the active NumPyro model. |
|
Add NRE log-ratio as a factor in the active NumPyro model. |
|
Add hierarchical NRE log-ratio as a factor in NumPyro. |
Leave-one-out cross-validation#
Compute per-observation log-likelihoods and add to arviz trace. |
Tuning#
Optuna-based hyperparameter search. Requires the tuning extra
(pip install setu-sbi[tuning]).
Tune NLE hyperparameters with Optuna. |
|
Tune NRE hyperparameters with Optuna. |
|
Tune MixedNLE hyperparameters with Optuna. |
|
Result of hyperparameter tuning. |
|
Search space for NLE hyperparameter tuning. |
|
Search space for NRE hyperparameter tuning. |
|
Search space for MixedNLE hyperparameter tuning. |
Predictive checks#
Prior and posterior predictive sampling.
Run prior predictive simulations organized by condition group. |
|
Run posterior predictive simulations. |
|
Result of prior predictive simulations, one dataset per condition. |
Validation#
Diagnostics that confirm a learned likelihood is trustworthy before export.
Configuration for validation check thresholds and parameters. |
|
Complete estimator validation diagnostics. |
|
Raised when validation fails in strict mode. |