Amortized inference for Bayesian GLMMs
Project description
metabeta
metabeta is an amortized model for Bayesian generalized linear mixed-effects models (GLMMs).
Given a grouped dataset, a model formula, and an optional prior specification, it returns
posterior samples for fixed effects, random effects, variance components, and
correlations with the speed and batching capabilities of a PyTorch forward pass.
- Supports Normal, Bernoulli, and Poisson outcomes.
- Accepts convenient lme4-style formulas.
- Conditions on prior family and hyperparameters at inference time.
- Supports batched prior-sensitivity analysis in one
sample()call. - Includes diagnostics for posterior contraction and prediction accuracy.
- Ships the pretrained inference API, plotting helpers, diagnostics, and demo notebooks.
- Keeps simulation, training, reference-method evaluation, and experiment scripts in the source repository for research workflows.
Pretrained checkpoints are hosted on Hugging Face and are downloaded automatically on first use.
Quick start
For local development, install from source with uv:
git clone https://github.com/adkipnis/metabeta.git
cd metabeta
uv sync
uv pip install -e .
Run posterior inference on a grouped dataframe:
import statsmodels.api as sm
from metabeta.models.api import Api
mb = Api.from_pretrained("normal")
df = sm.datasets.get_rdataset("sleepstudy", "lme4").data
result = mb.sample(df, formula="Reaction ~ Days + (Days | Subject)", n_samples=1000)
print(mb.posteriorSummary(result))
See demos/intro.ipynb for the full sleepstudy
walkthrough and demos/priors.ipynb for an exemplary prior-sensitivity
analysis.
Development and research workflows
The default PyPI install is for pretrained-model inference. To reproduce training runs, generate synthetic datasets, benchmark against reference methods, or extend the package, clone the repository and install the optional research dependencies:
git clone https://github.com/adkipnis/metabeta.git
cd metabeta
uv sync --extra research --group simulation --dev
uv pip install -e ".[research]"
This enables the repository-only paths for synthetic data generation, model training,
benchmarking against reference methods, simulation-based calibration studies, and experiment
scripts. The simulation dependency group installs the GitHub-only scamd dependency used
by SCM dataset generation. The metabeta.posthoc package is included for experimental
posterior refinement, but it is not part of the production pretrained API and may change
without a deprecation window.
From simulation to deployment
Each pretrained model is built through the same pipeline, from a dataset simulator to a checkpoint that can be loaded by the public API.
- Define the model family. Choose the likelihood, GLMM dimensions, group structure, covariate styles, and prior families covered by a checkpoint.
- Generate training data. Simulate hierarchical datasets and posterior reference targets across the configured design space.
- Format inputs. Convert grouped tabular data into padded tensors, masks, and prior encodings shared by training and inference.
- Train amortized posteriors. Use set-transformers (to learn low-dimensional permutation-invariant summaries of the datasets) and conditional coupling flows to approximate posteriors for fixed effects, variance parameters, correlations, and group-wise random effects.
- Validate behavior. Check parameter recovery, credible interval coverage, simulation-based calibration, posterior predictive accuracy and run comparisons against reference methods.
- Package checkpoints. Bundle weights, configs, routing metadata, and preprocessing expectations into a joint checkpoint.
- Deploy through the API. Load joint checkpoints with
Api.from_pretrained(...)for convenient posterior estimation and diagnostics.
Repository map
| Path | Contents |
|---|---|
| metabeta/analytical/ | GLMM analytical fits and helpers |
| metabeta/configs/ | model and preset configuration files |
| metabeta/datasets/ | preprocessing and source-specific dataset fetchers |
| metabeta/evaluation/ | parameter recovery, coverage, SBC, posterior predictive checks and summary metrics |
| metabeta/models/ | model API, set transformers, normalizing flows |
| metabeta/plotting/ | plot functions for posterior samples, recovery, calibration, and runtime |
| metabeta/posthoc/ | experimental post-hoc posterior refinement helpers |
| metabeta/simulation/ | synthetic hierarchical data generation and reference fitting with PyMC |
| metabeta/training/ | training entry point and checkpoint loop |
| metabeta/utils/ | config, dataloading, routing, IO, and shared helper code |
| experiments/ | reproducible experiment scripts grouped by package area |
| tests/ | pytest suite for models, simulation, evaluation, datasets, and utils |
| demos/ | demo notebooks |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metabeta-0.4.2.tar.gz.
File metadata
- Download URL: metabeta-0.4.2.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ad742846082a751c42bdd6449a33658f1cf48f5255c375f30c01df47d5add65
|
|
| MD5 |
ca446b158e11965a248112d8327c7718
|
|
| BLAKE2b-256 |
2f7659c32a1759e861a2edfdc2a554199df2d07d5a9d46810357d9c043d83924
|
Provenance
The following attestation bundles were made for metabeta-0.4.2.tar.gz:
Publisher:
publish-pypi.yml on adkipnis/metabeta
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metabeta-0.4.2.tar.gz -
Subject digest:
8ad742846082a751c42bdd6449a33658f1cf48f5255c375f30c01df47d5add65 - Sigstore transparency entry: 2190505974
- Sigstore integration time:
-
Permalink:
adkipnis/metabeta@4c2b29ac6e8d0b3b71a9c59628c1329d283fc41e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adkipnis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4c2b29ac6e8d0b3b71a9c59628c1329d283fc41e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metabeta-0.4.2-py3-none-any.whl.
File metadata
- Download URL: metabeta-0.4.2-py3-none-any.whl
- Upload date:
- Size: 271.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
948a9f3ae23e168908120515f433a0e6d24a504e00364d200645d480d36a8cbe
|
|
| MD5 |
df022e54c8e8c93453bd6f08945fd899
|
|
| BLAKE2b-256 |
59d07c544f4dbdef42e9ded5f519ffa36fd0dc2280941e22c8f07d633bb60017
|
Provenance
The following attestation bundles were made for metabeta-0.4.2-py3-none-any.whl:
Publisher:
publish-pypi.yml on adkipnis/metabeta
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metabeta-0.4.2-py3-none-any.whl -
Subject digest:
948a9f3ae23e168908120515f433a0e6d24a504e00364d200645d480d36a8cbe - Sigstore transparency entry: 2190506011
- Sigstore integration time:
-
Permalink:
adkipnis/metabeta@4c2b29ac6e8d0b3b71a9c59628c1329d283fc41e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adkipnis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4c2b29ac6e8d0b3b71a9c59628c1329d283fc41e -
Trigger Event:
workflow_dispatch
-
Statement type: