Amortized Bayesian Inference on Multilevel Models of Arbitrary Structure

Daniel Habermann, Andreas Bulling, Stefan T. Radev, Paul-Christian BürknerarXiv 2026

TL;DR

This paper introduces a systematic framework to automatically design neural network architectures for fast, amortized Bayesian inference on complex multilevel models. By transforming a model's generative graph into an "inverse graph," the authors enable near-instant posterior estimation for models with thousands of parameters and intricate grouping structures, matching the accuracy of gold-standard samplers.

What Problem Does This Paper Address?

Bayesian multilevel models (also known as hierarchical models) are the workhorse of modern statistics, used to analyze data with nested or overlapping groups—like students in schools or repeated measurements of patients. However, performing inference on these models is traditionally slow, often requiring computationally expensive Markov Chain Monte Carlo (MCMC) sampling.

Amortized Bayesian Inference (ABI) offers a solution by training neural networks to "learn" the mapping from data to posterior distributions. Once trained, these networks can perform inference almost instantly. The challenge is that multilevel models have a varying number of parameters depending on the number of groups in the dataset. Standard neural networks, which expect fixed-size inputs and outputs, struggle with this flexibility. Until now, researchers had to hand-craft custom architectures for every new model structure, a process that is both error-prone and difficult to scale.

Methods

The authors propose a four-step automated pipeline to transform a model's generative specification (a Directed Acyclic Graph or DAG) into a complete neural architecture:

  1. Graph Expansion: The method identifies "exchangeable" nodes (like group-level effects) and splits them into two instances. This makes the underlying group structure explicit so the algorithm can reason about how groups interact.
  2. Graph Inversion: It then explores valid ways to factorize the joint posterior distribution. This step determines which parameters should be inferred first and what information they need to be conditioned on.
  3. Amortization Analysis: The algorithm selects the specific factorization that maximizes "independent amortization"—meaning it looks for the version that allows the most group-level parameters to be processed in parallel by the same shared neural network.
  4. Architecture Derivation: Finally, the "inverse graph" is mapped to a set of summary networks (which compress raw data into fixed-size statistics) and inference networks (which output the posterior distributions).
Figure 1: Graph processing pipeline. Graph description: Directed acyclic graph of a two-level model with population mean µ, population standard deviation τ, group-level means {λj}, observations yji, and observation-level standard deviation ω. The dashed box denotes that the group-level means λj and observations yji are sampled independently. Graph expansion: The interior node λj is split into two conditionally independent instances λ1 and λ2, each receiving the same parent nodes µ and τ. This makes the exchangeability of groups explicit in the graph structure, allowing the inversion to determine that each instance conditions only on its own data and the global parameters. Graph inversion: Inversion of the expanded two-level model using outer-nodes-first ordering (µ, τ, ω, λ1, λ2). In the inverse graph, each λj conditions only on its own group data yj = {yji} and the global parameters µ, τ, ω, so the per-group inference becomes amortizable: a single inference network can be used for all J groups. Network architecture: Architecture derived from the inverse graph. Each inference network has its own summary network. The local summary network encodes the observation of each group into a group-level summary, from which the local inference network infers λj. The global summary network pools all observations into a single representation of the dataset, from which the global inference network infers µ, τ, and ω. The dashed box denotes that the local summary and inference networks are applied independently for each group.

For complex "crossed" designs where groups overlap (e.g., every student takes every test), the method automatically switches to an autoregressive approach, ensuring the architecture remains valid even when simple parallelization isn't possible.

Datasets

The authors validated their method across three case studies of increasing complexity:

  • Eight Schools: A classic, small-scale meta-analysis of coaching effects on SAT scores.
  • Skin Lesions (ISIC Archive): A three-level model analyzing agreement between different dermatologists (annotators) on various skin lesion images. This features a "crossed" design because each image is seen by multiple annotators, and each annotator sees multiple images.
  • UK Breeding Bird Survey: A massive four-level model of bird counts across the UK, involving nested regions and squares crossed with yearly effects. This model contains over 6,500 parameters.

Key Insights and Ideas

  • Structure is Destiny: The paper shows that the optimal neural architecture for inference is already "hidden" within the model's generative DAG. By formalizing graph inversion, they remove the need for manual architecture engineering.
  • Preserving Dependencies: Unlike previous "meta-amortized" approaches that often simplified models to make them fit into a transformer, this method preserves all conditional independence and exchangeability assumptions of the original model.
  • Handling "Crossed" Designs: One of the biggest hurdles in ABI has been crossed grouping factors. The authors solve this by using the chain rule of probability to infer one factor autoregressively, allowing the model to scale to any number of groups.
  • Universal Applicability: Because the method only requires a simulator (the generative DAG), it works even for "likelihood-free" models where the probability density is impossible to calculate analytically.

Key Results

The derived neural approximators were compared against Stan, the industry-standard MCMC sampler.

  • Accuracy: In all three case studies, the amortized posteriors closely matched the results from Stan, capturing both the means and the uncertainties of thousands of parameters accurately.
  • Speed: The performance gains are dramatic. For the UK Breeding Bird Survey, Stan took approximately 35 minutes to produce a high-quality posterior. The trained neural network achieved the same result in just 4 seconds—a speedup of over 500x.
  • Scalability: The method successfully handled the bird survey model with more than 6,500 parameters, demonstrating that ABI can move beyond toy problems into high-dimensional, real-world scientific applications.
Comparison of the amortized method (BayesFlow) against Stan across the three case studies.

Limitations and Future Work

  • Training Range: The networks are typically trained on a specific range of group sizes (e.g., 1 to 100 regions). While they are very fast at inference, they might not generalize well to datasets with group sizes far outside the training distribution.
  • Training Time: While inference is "near-instant," the initial training phase can be long (e.g., 12 hours for the bird survey model). The authors note this cost is "amortized"—it only needs to be paid once.
  • Misspecification: Like all simulation-based methods, the accuracy depends on the simulator being a good representation of the real world. The authors suggest that future work could integrate "self-consistency losses" to make the models more robust to real-world data that doesn't perfectly match the simulations.

Summary updated

BibTeX
@misc{habermann2026amortized,
  author = {Daniel Habermann and Andreas Bulling and Stefan T. Radev and Paul-Christian Bürkner},
  title = {{Amortized Bayesian Inference on Multilevel Models of Arbitrary Structure}},
  year = {2026},
  eprint = {2609.40024},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.40024},
}
Figure