arXiv:2609.40024stat.MLSep 2026

Manuscript Offprint

arXiv:2609.40024

Amortized Bayesian Inference on Multilevel Models of Arbitrary Structure

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

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

A PREPRINT

Daniel Habermann ID^{ID}

Department of Statistics

TU Dortmund University, Germany

daniel.habermann@tu-dortmund.de

Andreas Bulling ID^{ID}

Institute for Visualisation and Interactive Systems

University of Stuttgart, Germany

Stefan T. Radev ID^{ID}

Department of Cognitive Science

Rensselaer Polytechnic Institute, USA

Paul-Christian Bürkner ID^{ID}

Department of Statistics

TU Dortmund University, Germany

paul.buerkner@gmail.com

September 30, 2026

ABSTRACT

We develop a general method for amortized Bayesian inference on multilevel models of arbitrary structure. Given a generative model specified as a directed acyclic graph, our method automatically derives valid factorizations of the joint posterior and matching neural network architectures. The key steps, graph expansion and graph inversion, yield an inverse graph that determines how inference networks are stacked and conditioned, producing factorizations that amortize over the number of groups and the number of observations within each group. Unlike approaches that simplify the dependency structure to speed up learning or inference, our method preserves all conditional independence and exchangeability assumptions of the generative model. Across three case studies, it closely matches gold-standard samplers on models with more than 6,500 parameters while reducing inference to a near-instant forward pass once trained.

Keywords amortized Bayesian inference · simulation-based inference · neural posterior estimation · multilevel models · graph inversion

1 Introduction

Amortized Bayesian inference (ABI) approximates the posterior distribution of a Bayesian model by training neural networks on simulated pairs of parameters and datasets [1]. Because it only requires simulation and no likelihood evaluation, ABI enables Bayesian inference for models that are otherwise computationally intractable. In contrast to classical approaches, such as approximate Bayesian computation [ABC; 2], it scales much better to high-dimensional data [3–5] and is also amortized: the computational cost is only incurred once during training. This enables Bayesian inference for real-time applications [6] as well as inference across millions of independent datasets [7]. Consequently, ABI has become instrumental in a growing range of problems in the quantitative sciences [8–13].

Multilevel models, however, are particularly challenging to amortize. The dimension of their posterior depends on the number of groups and can vary from one dataset to the next, which is at odds with the fixed-width inputs and outputs assumed by standard neural approximators.

Recent neural network architectures relax the fixed-dimension requirement. Transformer-based approximators represent parameters and data as tokens and use masked attention to encode assumed dependencies, allowing arbitrary conditioning patterns [14]. Meta-amortized approaches generalize further, amortizing across families of structurally similar models with varying parameterizations, design matrices, and sample sizes [15]. Neither addresses the dependency

A PREPRINT

structure of multilevel models. Attention masks must be pre-specified for each model and do not guaranty conditional independencies, and meta-amortized architectures have so far been restricted to exchangeable observations, with exchangeable parameters left as an open problem.

Prior work [10, 16–19] has made progress on amortized inference for two-level models, deriving the network architecture by hand for that model class in each case. Deriving such an architecture is implicitly a choice of a particular factorization of the posterior: because each network has fixed input and output dimensions, a posterior whose dimension grows with the number of groups cannot be approximated in one piece but only as a product of factors that are learned separately and reused across groups. The choice of posterior factorization decides whether the approximator amortizes over the number of groups at all. Two questions therefore arise: Does such a factorization exist for a given generative model, and if so, which factors are amortizable?

The defining assumption of a multilevel model is that parameters at a given level are exchangeable: they are drawn from a common distribution, whose hyperparameters are themselves estimated from the data. This assumption allows partial pooling of information across groups, rather than fitting each group in isolation or ignoring the grouping structure entirely [20]. It also enables amortization: once we condition on the hyperparameters, a single neural network with shared weights can infer each group independently from its group-specific data alone [18, 19]. This requires a factorization of the joint posterior that makes the corresponding conditional independencies explicit, and not every factorization does. Even for a minimal two-level model, five valid factorizations exist (see Appendix A), of which only two enable amortization over the number of groups.

For multilevel models of arbitrary structure and complexity, we show that a suitable factorization of the posterior can be determined from the model's generative graph alone. It represents the model as an annotated directed acyclic graph (DAG) from which data can be simulated. To derive this factorization, we first apply graph expansion, which splits each exchangeable node into two instances and thereby makes the exchangeability of groups explicit in the graph structure. Graph inversion then enumerates the valid inverse factorizations of the expanded graph, which allows us to identify those that amortize over the number of groups. Even when no such factorization exists, we recover amortization by selecting a factorization that leaves the fewest group-level parameters conditioned on other groups. Then, we infer the remaining parameters autoregressively.

In contrast to prior work, in which the network architecture is derived by hand for a particular model class, our method determines the complete approximator automatically: which posterior factorization to use, which inference and summary networks are required, and how they are stacked and conditioned. Even though our focus lies on multilevel models, this extends amortized Bayesian inference to any model that can be expressed as a DAG, including crossed designs, for which no amortized method has previously been available.

We demonstrate our method in three case studies of increasing structural complexity: a two-level model of the eight schools data, a three-level model of inter-rater agreement on skin lesion segmentations with crossed image and annotator effects, and a four-level model of the UK Breeding Bird Survey with more than 6,500 parameters. In all three, the derived approximators closely match the posteriors obtained by Stan.

An implementation of our method is available in the open-source BayesFlow library [21] as the GraphicalApproximator class.

References (42)