Figures
Abstract
Global pandemics, such as the recent COVID-19 crisis, highlight the need for stochastic epidemic models that can capture the randomness inherent in the spread of disease. Such models must be accompanied by methods for estimating parameters in order to generate fast nowcasts and short-term forecasts that can inform public health decisions. This paper presents a comparison of two advanced Bayesian inference methods: 1) pseudo-marginal particle Markov chain Monte Carlo, using an unbiased likelihood estimate obtained by Particle Filter (PF), and 2) Conditional Normalizing Flows (CNF). We investigate their performance on three commonly used compartmental models: A classical Susceptible-Infected-Susceptible (SIS), a Susceptible-Infected-Recovered (SIR) model and a two-variant Susceptible-Exposed-Infected-Recovered (SEIR) model, complemented by an observation model that maps latent trajectories to empirical data. Addressing the challenges of intractable likelihoods for parameter inference in stochastic settings, our analysis highlights how particle-filter-based likelihood estimation and flow-based posterior approximation can provide accurate and robust inference capabilities. The results of our simulation study further underscore the effectiveness of these approaches in capturing the stochastic dynamics of epidemics, providing prediction capabilities for the control of epidemic outbreaks. Results on an Ethiopian cohort study demonstrate operational robustness under real-world noise and irregular data sampling. To facilitate reuse and to enable building pipelines that ultimately contribute to better informed decision making in public health, we make code and synthetic datasets publicly available.
Citation: Wieland V, Waßmuth N, Contento L, Kühn M, Hasenauer J (2026) Assessment of simulation-based inference methods for stochastic compartmental models in epidemiological research. PLoS One 21(7): e0353306. https://doi.org/10.1371/journal.pone.0353306
Editor: Sarafa A. Iyaniwura, Fred Hutch Cancer Center: Fred Hutchinson Cancer Center, UNITED STATES OF AMERICA
Received: December 2, 2025; Accepted: June 22, 2026; Published: July 13, 2026
Copyright: © 2026 Wieland et al. This is an open access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
Data Availability: The data underlying the results presented in the study are available from (https://zenodo.org/records/17779579).
Funding: This work was supported by the Deutsche Forschungsgemeinschaft (DFG, German Research under Germany’s Excellence Strategy (EXC 2151—390873048), by the European Union via ERC grant INTEGRATE (grant no 101126146) to J.H. and by the University of Bonn via the Bonn Center for Mathematical Life Sciences and the Schlegel Professorship of J.H.). This work received further funding from the Initiative and Networking Fund of the Helmholtz Association (grant agreement number KA1-Co-08, Project LOKI-Pandemics). There was no additional external funding received for this study. The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.
Competing interests: The authors have declared that no competing interests exist.
Introduction
The COVID-19 pandemic underscored the critical importance of epidemic modeling research. Rapid, data-driven approaches have demonstrated their capacity to provide public health decision-makers with essential insights for mitigating emerging infectious disease outbreaks and controlling epidemic dynamics [1,2]. Beyond COVID-19, other outbreaks such as Ebola and MPOX have likewise been designated as “public health emergencies of international concern” by the World Health Organization (WHO) [3]. These crises and consequent public health challenges highlight the need for advanced modeling techniques capable of capturing the intricate dynamics of disease spread.
Epidemiological and medical research revealed that the spread of infectious diseases is shaped by a variety of processes, including transmission dynamics, patient responses to treatment, and pathogen mutation. A wide spectrum of mathematical modeling approaches is used to describe the underlying dynamics, spanning from standard ordinary differential equation (ODE) models [4,5] to agent-based models [6]. On the one hand, ODE-based population models provide a fast to simulate framework, but fall short to describe the variability of events and the resulting complex, stochastic interactions, due to their deterministic nature. Therefore, stochastic models are essential for realistically representing infectious disease dynamics observed in real-world settings, especially in small populations or during the early stages of an outbreak [7]. On the other hand, purely stochastic models, such as agent-based and continuous-time Markov chain (CTMC) models [8,9] provide highly detailed stochastic representations of individual-level processes, but come at the cost of prohibitive computational burden [10]. Mathematical models based on stochastic differential equations – so called stochastic (meta-)population models – can solve the trade-off between fast model simulations and keeping the stochasticity in the model [11]. In this study, we consider compartmental models described by stochastic differential equations (SDE). In compartmental models individuals are arranged in a finite number of mutually disjoint compartments and interaction happens through transfer from one compartment to another which is described by transition equations [12]. Their description in terms of SDEs can be seen as a mesoscopic view on the model dynamics. The SDEs are derived as a diffusion approximation to the microscopic, individual-based, discrete-state CTMC description [11,13,14] and in the large population limit resemble the macroscopic, population-based, (deterministic) ODE models [15]. For a more detailed discussion on stochastic epidemic modeling see [9,11,16] and references contained therein.
A key challenge in mathematical-epidemiological modeling is determining the unknown model parameters that best explain the observed data. This process, often referred to as parameter inference, is commonly approached by maximizing the likelihood function, which measures the probability of the observed data given specific parameter values. For stochastic models, however, likelihood-based inference is often infeasible when fitting to discrete-time data, as the underlying probability distributions can be highly complex or the parameter space very high-dimensional leading to an intractable likelihood function. In such cases, naive approximations quickly become computationally prohibitive.
Many methods have been developed to address the issue of intractable likelihoods and posterior distributions. Early attempts used data augmentation or employed Markov chain Monte Carlo (MCMC) methods [8,17,18]. Later approaches sought to reduce computational cost through surrogate models such as Gaussian processes [19] or linear noise approximations of the underlying Markov jump process [20]. Hybrid strategies combining data augmentation with MCMC have also been proposed [21,22]. Sequential Monte Carlo methods were introduced as a flexible approach for analyzing stochastic state space models and performing Bayesian filtering tasks [23,24]. These methods, also known as particle filters (PF), have been used to produce an unbiased likelihood estimate for an MCMC algorithm, leading to pseudo-marginal methods for Bayesian inference on model parameters [25–27], a popular method for exact Bayesian inference in stochastic models [27,28].
Instead of determining model parameters via sampling based on evaluations of the likelihood or an approximation to it, it is possible to conduct the inference procedure solely based on simulations. In the widely used technique of Approximate Bayesian Computing (ABC), simulated and observed data is compared based on summary statistics [29,30]. However, manually selected summary statistics can be uninformative and their selection poses a challenge on its own. Additionally, as these methods require massive numbers of simulations, more recent machine learning approaches have been adapted for simulation-based inference with neural networks [31]. These promising techniques often circumvent hand-crafted summary statistics and directly approximate the distribution of the parameters from samples generated by the simulator. Therein, conditional normalizing flows (CNF) are an advanced method that uses invertible neural networks to generate samples from the posterior distribution of the parameters [32,33].
PF and CNFs show great potential for Bayesian inference on stochastic models and are increasingly recognized within the epidemiological modeling community for providing probabilistic estimates of disease characteristics to effectively monitor pandemic outbreaks [34,35]. However, their adoption has been limited by the lack of a comprehensive comparison assessing their relative performance. This work offers a praxis-driven comparison between both inference methods, assessing strengths and weaknesses of the particular approaches, as well as their alignment. In the first part, we described the three stochastic compartmental models, the well-known SIS and SIR models [4] and a two-variant SEIR model, which was used to analyse the spread of COVID-19 in Ethiopia [1]. Together with the observational model bridging compartment trajectories with empirical data they serve as the foundation for our study. Moreover, we outline Bayesian inference for stochastic differential equation-based models, and explain the chosen techniques of CNF and PF together with the implementation of our comparison workflow. In the second part of the work, we outline the results from comparing the two inference methods on synthetically generated data for the chosen compartmental models and additionally using real-data for the two-variant SEIR model. For the two smaller compartmental models, SIS and SIR, we compared the estimated posterior distributions with a reference posterior obtained by Hamiltonian Monte Carlo (HMC) sampling on a discretized version of the stochastic model. Both methods provide robust and reliable inference results on the stochastic versions of the SIS and SIR model with synthetically generated data, validating their implementation at hand. For the more complex two-variant SEIR model the approximate computation of a reference posterior using HMC methods is not feasible, showcasing the need of the assessed Bayesian inference methods. Analyzing the agreement of the estimated marginal posteriors and model fits given by PF and CNF based on different synthetic datasets, including (partially) missing data, shows that both methods yield good fits to the data at hand. However, ill-conditioning of the model leads to differences in the shape of the marginal posteriors due to difference in parameter space exploration by the inference methods. Applying both methods to a reparametrized version with parameter dimension reduction can overcome these issues and improves posterior alignment. Inference based on the data from [1] shows the applicability of both methods to real-world data. A discussion of the results, their limitations and further research directions follows in the Discussion.
Materials and methods
Stochastic compartmental models
Compartmental models are a mathematical framework to describe how individuals in a population move between different states and are fundamental for modeling infectious diseases [12]. Such a model partitions a population into mutually exclusive compartments and is characterized by the vector of compartment sizes
together with the transitions of individuals between these compartments.
Let denote the set of admissible transitions. Each transition
is characterized by a stoichiometric vector
, which specifies the change in the compartment counts when the transition occurs. For the movement of one individual from compartment i to compartment j,
, where
denotes the i-th unit vector. The transition intensity is described by a propensity function
, defined through
For infection-driven transitions, a common choice is a mass-action propensity of the form
where is a rate parameter and
contains the compartments contributing to the force of infection. Other transitions, such as recovery, are typically modeled by linear propensities, for example
.
The resulting stochastic compartmental model is a continuous-time Markov jump process. In the large-population regime, it can be approximated by the multivariate stochastic differential equation (SDE) [11]:
where denotes a vector of independent Brownian motions. The representation of compartmental models in terms of multivariate SDEs can capture the randomness of disease spread in their diffusion part
and retain a drift component
for representing the deterministic trend of the population [8,16]. This makes them a favorable choice for modeling disease outbreaks and dynamics.
In this work, we consider two examples of SDE-based compartmental models, a simple standard Susceptible-Infected-Recovered (SIR) model [4] and an extended two-variant Susceptible-Exposed-Infected-Recovered (SEIR) model [5] considering two variants of a single pathogen.
2.1.1. SIS model.
The simplest compartmental model is the SIS-model [4] consisting of one Susceptible compartment S and one Infectious compartment I, where people can transition between them (Fig 1(a)). This model can be used for infectious diseases that do not confer any long-lasting immunity, such as the common cold or influenza. Following simple mass-action incidence individuals get infected with a rate and leave the infective class at rate
(Table 1).
(a) Graph of compartments and possible transitions with corresponding rate parameters for the Susceptible - Infected - Susceptible (SIS) model. (b) Graph of compartments and possible transitions with corresponding rate parameters for the Susceptible - Infected - Recovered (SIR) model. (c) Graph of compartments and possible transitions with corresponding rate parameters for the Susceptible-Exposed-Infected-Recovered (SEIR) model with virus variants wild-type (wt) and variant (var). (d) Workflow for the assessment of the Bayesian inference.
2.1.2. SIR model.
The standard SIR model (Fig 1(b)) considers three compartments: S (Susceptible), I (Infectious) and R (Recovered). The model describes the number of individuals in these compartments given the transition parameters (the transmission rate) and
(the recovery rate). Due to its simplicity, the solution of the deterministic SIR model and its properties can be analysed analytically [36] and it often serves as an initial model for the modeling of unknown diseases [37]. For consistency across models, in the following we compare recovery in terms of the mean infectious period,
, rather than
. The events dynamics are described by three compartments and the transitions between them (Table 2).
2.1.3. Two-variant SEIR model.
Many extensions of the SIR model have been developed to account for the heterogeneity of various infectious diseases [38], for example the Susceptible-Exposed-Infectious-Recovered model, in which the Exposed compartment covers the latent period between being infected and becoming infectious. Recently, an extension to the ODE-based SEIR model was introduced to capture the early COVID-19 dynamics in Ethiopia [1]. In addition to a classical SEIR model, this model distinguishes between two virus variants, namely the wild-type and a novel variant, leading to a total of 10 compartments (Fig 1(c)).
The novel variant is assumed to have a 35% longer infectious period, following the original formulation of the two-variant SEIR model in [1]. We adopt this fixed factor to remain consistent with the published model on which our comparison is based. Additionally, immunity from the wild-type variant does not protect against reinfection with the novel variant. However, an infection with the novel variant type confers immunity against subsequent infections with both the wild-type and the novel variant. The dynamics of the compartment sizes are described by initialization, variant entering and transitions between the compartments (Table 3).
The model exhibits non-identifiability issues in the sense that different parameter combinations, lying along certain curves, can generate nearly indistinguishable epidemic trajectories (see Supplementary Information S1 Text). Therefore, in addition to this model, we also consider a reparametrized version of the model with a reduced number of model parameters to be estimated. For this, we fix , since
seems to participate in the non-identifiable parameter combinations and use the following redefined parameters
while keeping and I0 as well as the observational and noise models unchanged. This transformation allows a comparison of the inference methods CNF and PF in either parameter space without altering the underlying system.
2.1.4. Observation model.
The course of an epidemic is usually only partially observed and data is often only available in aggregated form on population level. For all models introduced above, we consider an observation model reflecting one to two often measured quantities to monitor infectious diseases. For the SIS model, the observable is
For the SIR model, the observables are
For the two-variant SEIR model, they are given by
where the first entry represents the latent prevalence of currently infected individuals. In practice, this quantity is not observed directly but is inferred from testing data. One method of inference is to consider the proportion of positive tests among all tests performed, under the assumption that the cohort tested is representative of the population as a whole. The observation model therefore treats testing-derived prevalence as noisy observations of the underlying population prevalence given by the model. The second entry represents seroprevalence, i.e., the proportion of individuals with antibodies due to a prior infection. Because the observation process may have several limitations, such as incomplete reporting or under-ascertainment, an additional scaling parameter s is used to account for the fact that only a fraction of infections may be captured in the reported testing data [1].
To reflect measurement uncertainty, synthetic realizations of the observables are perturbed with noise. In this study, we leverage additive Gaussian noise. That means we have
where we truncate and
at a lower bound of 0 and at an upper bound of 1 to avoid unrealistic observations. As in the dataset given by [1], the standard deviations
were computed directly using a normal approximation to the binomially distributed testing count data. Alternative probability distributions may be more appropriate in other contexts.
From each of the stochastic compartmental models we generated synthetic data emulating the time course of a disease outbreak. We generated dense datasets with observations every seven or ten days. We used two types of parameter regimes:
- hand-selected values chosen to represent plausible epidemiological regimes, and
- parameters sampled directly from the corresponding priors as an unbiased baseline
Prior draws that generated trajectories with collapsed variance were discarded and resampled to maintain numerical stability of the particle filter. Additionally, to create realistic, heterogeneous observation schedules, we randomly subsampled the dense time series into sparse datasets reducing the number of time points from 57 to fewer than 15 per observable. We also introduced partial missingness in the sparse datasets, where only one of the two observables was available at certain time points. Details on the computation of measurement noise and data generation are provided in the Supplementary Information S1 Text.
Bayesian inference for stochastic compartmental models
To infer the unknown model parameters given data
, we apply Bayesian inference techniques. For this, we denote the space of unobserved states of the diffusion process by
.
Bayes’ rule allows to combine prior information (e.g., from expert judgment, previous studies, biological constraints, or model restrictions) with the likelihood
, which measures how probable the observed data are given specific parameter values, yielding the posterior distribution
The posterior represents the updated belief about the parameters after taking the observed data into account via the likelihood, effectively integrating both previous knowledge and the new information provided by the data. While the full posterior distribution is typically of primary interest, we additionally consider the mode (called maximum a-posteriori) of the posterior distribution as the best point estimate [39].
One challenge in applying Bayesian inference to stochastic compartmental models is dealing with an intractable posterior distribution, because evaluating the likelihood
requires marginalizing over stochastic realizations of the unobserved states at measurement time points.
In most cases, evaluating the density of hidden states analytically is impossible [40], which prohibits evaluating the likelihood. Even in the case of a tractable likelihood, normalization of the posterior is done via the marginal likelihood, which can remain intractable. High-dimensional parameter spaces further make discretization or numerical integration prohibitively expensive [41,42].
Approximation techniques that estimate the posterior distribution without directly computing the complicated likelihood function enable robust parameter estimation, even in settings where traditional methods may fail due to mathematical or computational complexity. In this section, we will introduce two approaches (particle filters (PF) [43] and one particular class of conditional density estimators, conditional normalizing flows (CNF) [31,32]) that circumvent the computation of the likelihood function. PF approximate the likelihood with an unbiased estimator obtained by sequential importance sampling, and conditional normalizing flows learn a series of invertible mappings to transform a Gaussian density into the desired density.
2.2.1. Particle Markov chain Monte Carlo methods.
Particle Markov chain Monte Carlo (PMCMC) methods are based on the idea of using an unbiased estimator of the likelihood function, obtained by a particle filter, inside a Markov chain Monte Carlo (MCMC) method [43].
Particle filters are sequential Monte Carlo (SMC) techniques based on importance sampling with resampling used for handling non-linear and non-Gaussian time-series models. Let denote a discrete time-series of the unobserved states and
a time-series of observations at the same time points. The main idea is to iterate over the following three steps. First, N particles, i.e., realizations of the dynamic process, are propagated through the latent space over time. This means that, given the trajectory of the latent process for the k-th particle and the observables until time
, we sample the state of the latent process at time
,
, based on a chosen proposal distribution
. Second, at each time point, particles are weighted, based on their agreement with the observed values for that time point. And third, they are resampled using auxiliary variables
to discard low-weight particles. In practice, the resampling is not done in every iteration, but only if the variability of the weights becomes too large, as measured by the effective sample size (ESS) (for more details see Supplementary Information S1 Text). The resampled particles are then again propagated forward to the next time point. Hence, for each time
, the particle filter constructs a system of N weighted particles
that approximates the filtering distribution
. Mathematically, this is closely linked to the framework of Feynman-Kac models [26,27,44].
For the task of estimating the likelihood in stochastic compartmental models, we use a bootstrap filter Algorithm 1. This is a PF algorithm, where particles at the next time point are generated solely based on the transition probabilities of the latent process and then those new particles are filtered based on their agreement with the data at hand
, where the function
is determined by the observation and noise model. The bootstrap filter is easy to implement and widely applicable due to its simplicity. It only requires evaluation of the observation model
. However, it is not necessary to compute the transition densities
; we solely need the ability to simulate the state of the process at the next time point given the current state, making it practical for any complex or stochastic model.
Algorithm 1 Bootstrap Filter with Adaptive Resampling
Require: parameter , number of particles N, observation density function
, transition density function
, initial distribution
1: ▷ Operations involving index n must be performed for n = 1,...N
2: Sample
3:
4:
5: for i = 1 to M do
6: if then
7: Sample ▷ See Supplementary Information S1 Text
8:
9: else
10: ▷ No resampling
11:
12: end if
13: Sample
14:
15:
16: end for
Although the name filtering refers to the task of estimating the latent state online given data
, a PF yields, as a by-product, a scheme to compute an unbiased estimator of the likelihood contributions
, crucial for the task of parameter inference [27]. This estimator is obtained by computing the normalizing constants
where corresponds to the desired estimate of
. The estimate
can then be used inside a pseudo-marginal MCMC algorithm to sample from the posterior
.
In this work, we use the likelihood estimate obtained by the bootstrap filter within the acceptance probability of a Metropolis-Hasting (MH) algorithm as the outer MCMC scheme, making it a member of the class of Pseudo-Marginal Metropolis-Hasting methods (PMMH) [25–27]. The full PMMH-algorithm is provided in the Supplementary Information S1 Text.
Using an unbiased estimator of the likelihood
that is obtained by the use of auxiliary random variables
within the acceptance of a MH algorithm then corresponds to simulating a Markov chain
targeting the joint density
For the bootstrap filter, we can, for instance, think of the used in the resampling as being the auxiliary random variables. The joint density admits the correct posterior density of the model
as a marginal and therefore the algorithm samples the parameter vectors
from the true posterior [25,26,45]. With respect to an extended distribution, PMMH algorithms are standard MCMC samplers.
One can use any unbiased estimator within any MCMC algorithm to produce a PMCMC algorithm. Different filtering and sampling algorithms impose different practical and implementational challenges and we focus here on the most general applicable version [27,45]. In the subsequent sections PF method always refers to a PMMH algorithm consisting of a bootstrap filter inside an adaptive Metropolis-Hastings algorithm.
2.2.2. Neural posterior estimation and conditional normalizing flows.
Neural posterior estimation (NPE) is a simulation-based inference (SBI) method which frames posterior construction as a (conditional) density-estimation problem [32]. Given a simulator that produces samples by first drawing
and then
, NPE fits a conditional neural network
to approximate the true posterior
. Here
denotes the implicit likelihood defined by the stochastic forward model. It is the distribution over datasets induced by running the forward model at a fixed parameter
. NPE sidesteps exact likelihood evaluation by relying only on these simulated samples.
Typically the data are preprocessed by a (learned) summary statistic [46], which serves as the input to the conditional density estimator. For clarity, this preprocessing step is omitted from the notation below.
In this work, we focus on Conditional Normalizing Flows (CNFs) [47]. Normalizing flows have since been substantially developed and systematized [33,48,49]. In general, normalizing flows transform a simple base distribution (e.g., a standard Gaussian) into a complex target distribution via a sequence of invertible, differentiable mappings. In our setting, this means that a normalizing flow defines a diffeomorphism such that (for fixed
) the posterior
is the “pushforward” of the base distribution q along
, i.e.,
This construction enables efficient sampling and exact density evaluation via the change- of- variables formula, making normalizing flows a powerful tool for modeling complex probability distributions.
CNFs extend this idea by allowing the transformation to additionally depend on datasets , generated by first drawing
and then
. Rather than learning a single transformation f, CNFs learn a family of conditional flows
, with each
mapping the base distribution q to the posterior
[50]. This conditioning enables CNFs to capture how the posterior changes with different observations, making them particularly well-suited for amortized inference tasks, where a model learns to perform inference efficiently across multiple datasets rather than solving each case from scratch [47,51].
Instead of hand-designing each , we parameterize the family using a neural network
whose parameters
are shared across all
, but whose behavior is modulated by
itself [52]. We train the neural network by minimizing the Kullback-Leibler divergence between the true and learned posteriors for all
in the training distribution [49,53,54]. This means, our optimization objective is finding
For CNFs this requires computing the change-of-variables log-density
for simulator samples and optimizing by stochastic gradient descent. This amortizes the cost of inference: Once trained, the CNF can quickly return an approximate posterior for any new
within the support of the training distribution. Algorithm 2 summarizes the amortized training loop and the inference procedure for drawing approximate posterior samples via inverse flow sampling.
Algorithm 2 Amortized training and inference for conditional normalizing flows
Require: Data source S (pre-simulated dataset or simulator callable ), base density q(z), conditional flow
, optimizer Opt, learning rate
, batch size N, inference data
, inference sample count M
Ensure: Trained parameters ; sampler for approximate posterior
repeat
1:
2: for i = 1 to N do
3:
4:
5: end for
6:
7: untilconvergence of
8: procedure Infer(, M) ▷ M is number of posterior samples
9: for m = 1 to M do
10: Sample
11:
12: end for
13: return
14: end procedure
This amortization not only enables fast inference once training is complete, but also facilitates simulation-based calibration (SBC) diagnostics by allowing posterior approximations to be generated efficiently across many simulated datasets. At the same time, performance of CNFs is tied to the support of the training distribution: the model can interpolate to new values if they are close to the training support, but performance degrades when extrapolating far beyond it [50,55]. In practice, this amortized structure is precisely what makes SBC feasible at scale, since once trained, the CNF can be evaluated repeatedly on equally structured datasets without retraining.
Implementation of the methods and their comparison
In order to render the simulation based approaches computationally feasible, model simulations were conducted using the efficiency of the Julia programming language and the flexible SDE modeling capabilities of SciML and ModelingToolkit.jl [56,57]. To approximate the solution of the SDE, we implemented an Euler-Maruyama scheme that constrains trajectories to stay non-negative, effectively clipping potential negative parts and setting them to zero.
For PF, existing software packages were unsuitable as they either lacked Julia support or restricted model specification to simulator-only interfaces. We therefore implemented a custom particle filter in Julia, drawing inspiration from the Python package Particles [27]. As an outer sampling scheme, we employed an adaptive Metropolis–Hastings algorithm [58], using the implementation in pyPESTO [59], to account for potential multimodality in the posterior distribution. Missing data were handled by setting the likelihood contribution of the corresponding observation to zero. To mitigate particle degeneracy, we set the number of particles to 200, ensuring that the variance of the likelihood estimate remained below one for parameters around the posterior mode (Supplementary Information S1 Text, Fig. S1.1). For the outer MH algorithm, we ran 4 Markov chains with a length of 50,000 samples each. We then discarded a burn-in period of the first 25,000 samples per chain. After that, convergence was evaluated using rank-normalized Gelman–Rubin statistics () and the ESS with autocorrelations up to a maximal lag of 250, both from MCMCDiagnosticTools.jl [60]. Values of
close to 1.0 indicate good convergence and well-mixed chains [61]. The ESS assesses and diagnoses poor convergence in the bulk of the distribution due to trends or different locations of the chains. For a given estimand, it is recommended that ESS should exceed
[61]. Together,
and ESS provide complementary diagnostics of chain convergence and posterior exploration quality.
For CNF, posterior approximations were obtained via neural posterior estimation with learned summary statistics [46], using the BayesFlow software (v1) for amortized Bayesian workflows [49]. We trained an independent neural network for each experiment rather than a single globally amortized model. This preserves amortization over latent trajectories and parameter values within each experiment. Global amortization across experiments is possible in principle but doing so over continuous nuisance variables requires careful conditioning to remain reliable, and broadening the amortization scope was not necessary for our comparison. We therefore adopted per-experiment amortization, which isolates the methodological comparison from the additional design choices that broad amortization would introduce. The resulting per-experiment amortization still enables efficient SBC diagnostics and fast posterior evaluation once training is complete. Rather than fine-tuning each method for every individual experiment, which would confound performance differences with tuning effort, we selected CNF hyperparameters through a principled search procedure that we repeated to assess stability. We verified that training was well-behaved by inspecting training and validation loss curves, which consistently stabilized well before 100 epochs. The dimension of the learned summary statistics was set to , where
denotes the number of model parameters. Training was conducted offline with 100,000 simulations for the training dataset and 400 simulations for validation. Models were trained for 100 epochs with a batch size of 32. Summary statistics were extracted using a SequenceNetwork [34] with 64 LSTM units, and the conditional normalizing flow was modeled using an InvertibleNetwork with spline coupling and eight coupling layers, both implemented within the BayesFlow framework. Detailed configurations are provided in Supplementary Information S1 Text. Handling non-equidistant time points and missing data required a specialized strategy. We adopted the approach of [62], which augments the input with binary indicators marking the presence or absence of each entry. This encoding allows the neural network to account for missing values during inference and provides a consistent representation when combining observation functions recorded at different time points. In our setup, only the dimensional consistency of the two observation functions is strictly required; however, we included the binary mask deliberately to facilitate rapid amortization for practitioners who may wish to extend our framework. For the present experiments, this amortization capability was not used: for sparse datasets, the neural networks were trained solely on the specific missingness pattern present in the simulated data to ensure a fair comparison between PF and CNF and to avoid confounding method differences with amortization artifacts. For experiments with dense, equidistant data, this additional encoding was not applied. Empirical cumulative distribution function (ECDF) plots were obtained to assess calibration, and parameter recovery diagnostics were used to evaluate the correspondence between inferred and true parameter values. These diagnostics provide insight into whether the amortized posterior captures uncertainty appropriately and whether point estimates remain consistent with the generative parameters.
For the comparison of both methods we used visual and quantitative measures. The visual comparison using density plots of the marginal posteriors allows comparison of the shape and variability of the posterior approximations. This is complemented by a visual comparison of the model fit. For the evaluations we draw 10,000 parameter vector samples from each approximate posterior distribution and, for each parameter vector, simulate an observable trajectory to create an ensemble of independent posterior predictive samples obtained by evaluating for draws
. We then plot the central 50% and 95% intervals of the ensemble against the data. As an additional qualitative indicator, we report the maximum a-posteriori (MAP) estimate computed via Gaussian kernel density estimation using Silverman’s rule [63], which provides a consistent definition across methods.
For a quantitative measure of inference accuracy, we first assess marginal coverage by reporting how frequently the true generative parameters fall within the 95% marginal posterior intervals across datasets. We also quantify posterior differences using the 1-Wasserstein distance in log-parameter space. All Wasserstein distances are obtained by repeatedly subsampling 1,000 draws per posterior, and we report in-distribution values to characterize the Monte Carlo error of this procedure. Heuristically, the 1-Wasserstein distance in log-parameter space measures the average multiplicative shift required to transform one posterior into another, providing an interpretable notion of scale-adjusted discrepancy. Concretely, we compute these distances in three settings:
- Baseline comparisons: when a baseline is available, we measure the Wasserstein distance between each method and the baseline and compare it to the corresponding in-distribution reference.
- Model-parameterization comparison: for the full and reparametrized SEIR2v models, we evaluate how the Wasserstein distance changes when keeping the dataset fixed, again reporting the in-distribution values as a baseline.
- Within-method variability: for one representative parameter set, we assess the variability of each method by computing Wasserstein distances between multiple PF runs or multiple CNF trainings.
Finally, we assess predictive accuracy via the energy score of the posterior predictive distributions. For synthetic experiments, the predictive energy score was also computed with respect to the true parameters used to generate the data. For the real-data experiment, true parameters are not available. Instead, we report the energy score relative to published parameter estimates from [1], which serve as a reference baseline.
All experiments were conducted on ten cores of an AMD EPYC 7f72 3.2 GHz processor with a total of 200 GB of RAM made available to the process. In order to ensure reusability and reproducibility, we made the code and all artificial data used for the experiments available at Zenodo (https://zenodo.org/records/17779579) and in a GitHub repository (https://github.com/vwiela/Inference-Methods-for-Stochastic-Compartmental-Models.git).
Results
We examined inference with CNF and PF for stochastic epidemic models through a sequence of in-silico experiments on synthetic data, following the workflow in Fig 1(d). To assess the performance of both inference methods against a baseline posterior distribution, we use the standard SIS and SIR model with a synthetic prior. The baseline posterior was computed on a finely discretized version of the SDE using a state-of-the-art Hamiltonian Monte Carlo sampler [64] (Details in Supplementary Information S1 Text). We then turn to the complex two-variant SEIR model with literature-informed priors [65,66], designed to probe the influence of parameter non-identifiability. For this model the computation of a reference posterior is not possible and we examine inference quality in terms of data fit and assess the differences of both methods. Within the two-variant SEIR setting, we additionally study the effects of data sparsity and timing mismatch and investigate a reparametrization aimed at reducing non-identifiability. Finally, we apply both approaches to longitudinal data from Ethiopia [1] to assess performance under realistic conditions. Evaluation metrics and synthetic dataset generation together with model setups are described in detail in Supplementary Information S1 Text.
CNF and PF agree with a reference posterior for the SIS model
We evaluated convergence and posterior estimates for the SIS model using CNF, PF, and a Hamiltonian Monte Carlo (HMC) baseline applied to a finely discretized version of the SDE. Across 10 synthetic dense datasets, all methods achieved excellent marginal coverage: the true parameters fell within the 95% credible interval for every posterior marginal (100% marginal coverage) and produced highly consistent Wasserstein distances. Throughout, each value pair gives the range (minimum to maximum) of the 1-Wasserstein distance in log-parameter space over subsampling repetitions, reflecting the Monte Carlo error of the procedure. Two datasets stood out for distinct reasons, identified by the in-distribution baseline (HMC-HMC), i.e., the distance of an HMC posterior to an independent HMC run on the same dataset. For sis-4, this baseline was itself elevated (0.116–0.214 vs. 0.056–0.119 across the remaining datasets), indicating an intrinsically dispersed posterior rather than a disagreement between methods. We therefore report it separately, as it inflates the between-method aggregate without reflecting method differences. For sis-2, the baseline was at the normal level (0.058–0.081) while only the HMC comparisons rose (0.175–0.199 for CNF-HMC and 0.204–0.230 for PF-HMC) and CNF-PF remained low (0.097–0.137), indicating a localized disagreement against HMC. We report aggregate between-method distances over the remaining datasets; for all cases, visual posterior differences remained minor.
Across the eight retained datasets, the in-distribution Monte Carlo baseline (HMC-HMC) was small, with values ranging from 0.056 to 0.119. Between-method distances were only moderately larger: CNF–PF ranged from 0.063 to 0.156, CNF–HMC ranged from 0.065 to 0.176 and PF–HMC ranged from 0.058 to 0.124. Interpreted on the log-parameter scale, these values correspond to average multiplicative shifts of roughly for the baseline and
,
, and
for the between-method comparisons, respectively. These results indicate that systematic differences between inference algorithms are small, consistent with the strong visual overlap in marginal and joint posteriors (Fig 2A). Posterior predictive simulations from all three methods reproduced the observed epidemic trajectories with comparable accuracy (Fig 2B), as evidenced by consistent energy scores computed from the posterior predictive distributions of the methods and the ground truth (Table 4).
A Posterior approximations from 10,000 samples. Contour gives the 50% (solid) and 95% (dashed) credible regions, coloured by method. Diagonals show the 1D marginals. Black stars mark the true parameters, coloured circles the joint MAP estimates. B Posterior predictive fit: bands give the 50% and 95% pointwise predictive intervals from the same samples (line styles as in A) with inference data shown as a dotted line.
In terms of sampling behavior, PF showed excellent convergence, with ESS values above 2000 and near 1. CNF showed good calibration in simulation-based calibration diagnostics, with near-uniform rank histograms and accurate parameter recovery. Overall, both PF and CNF matched the predictive and inferential performance of the HMC reference.
Full diagnostics, including ESS, , Wasserstein distance results, calibration plots, and parameter-recovery analyses are provided in Supplementary Information S2 Results.
CNF and PF provide accurate estimates for the SIR model
We compared convergence and posterior estimates obtained with CNF and PF on the SIR model, using twelve distinct synthetic dense datasets. As a reference, we additionally computed a reference posterior using Hamiltonian Monte Carlo (HMC) applied to a finely discretized version of the underlying SDE.
Across all datasets, CNF and PF achieved 83.33% coverage of the 95% credible interval and HMC achieved 87.5% coverage. The three posterior approximations showed high agreement overall: marginal and joint distributions overlapped closely (Fig 3A), with CNF exhibiting a small systematic offset relative to HMC and PF. This offset is consistent with the mild posterior miscalibration discussed below. The Wasserstein distances reflect this pattern. The in-distribution Monte Carlo baseline (HMC–HMC) ranged from 0.034 to 0.096. Between-method distances were modestly larger: CNF–PF ranged from 0.063 to 0.165, CNF–HMC from 0.076 to 0.183 and PF–HMC ranged from 0.048 to 0.125. Interpreted on the log-parameter scale, these values correspond to average multiplicative shifts of approximately 3–10% for the baseline and 6–18%, 8–20%, and 5–13% for the between-method comparisons, respectively. Detailed results are provided in Supplementary Information S3 Results. Posterior predictive checks showed that epidemic trajectories generated from all three methods fit the observed data equally well (Fig 3B), as evidenced by the close agreement in predictive energy scores (Table 5).
Contour gives the 50% (solid) and 95% (dashed) credible regions, coloured by method. Diagonals show the 1D marginals. Black stars mark the true parameters, coloured circles the joint MAP estimates. B Posterior predictive fit: bands give the 50% and 95% pointwise predictive intervals from the same samples (line styles as in A) with inference data shown as a dotted line.
Beyond these direct comparisons, the methods differed in sampling quality. PF achieved excellent convergence, with ESS exceeding 2000 and values close to 1, indicating robust posterior exploration and well-mixed chains (Supplementary Information S3 Results, Tables S3.2 and S3.3). CNF, in contrast, showed deviations in SBC diagnostics (Supplementary Information S3 Results, Fig. S3.14), reflecting limitations of the amortized posterior. For
, this miscalibration is largely consistent across all 12 datasets with SBC histograms predominantly sloping upwards. For
, the histograms did not show one consistent shape. The consistency of the
bias points to a structural rather than dataset-specific cause, likely rooted in the constrained joint prior, though we do not attempt a full diagnosis here. This miscalibration geometry matches the observed offset of CNF relative to PF and HMC: the upward-sloping
histogram corresponds to a left-shift in the
marginal.
Notably, these calibration issues did not carry over to parameter recovery, where recovered values aligned closely with the ground truth and error bars remained narrow (Supplementary Information S3 Results, Fig. S3.16). Nonetheless, since the posterior is the primary inferential target, we regard this calibration gap as a genuine limitation of the amortized CNF here rather than a purely formal one, even though its impact on point estimates and predictive accuracy is minimal.
In summary, CNF and PF both provide robust Bayesian inference for small stochastic compartmental models. Across datasets, both methods produced equivalent posterior distributions and predictive performance. Notably, CNF, despite being an amortized approach, achieved greater computational efficiency in our experiments (roughly 10-fold) while PF excelled in sampling diagnostics. Moreover, since CNF relies purely on simulations it has consistent computational costs across different parameter vectors. In contrast, PF execution times vary greatly, depending on the posterior geometry. Additionally, the evaluation of the likelihood can be computationally expensive in regions where outcomes are highly sensitive to parameter changes or when parameter vectors do not fit the data well.
Full diagnostics, including ESS, , Wasserstein distance results, calibration plots, and parameter-recovery analyses are provided in Supplementary Information S3 Results.
Non-identifiability issues lead to posterior shape differences
Previous studies have shown that parameters in common epidemiological models are often weakly determined by commonly available datasets [67]. To assess how such non-identifiabilities affect inference reliability, we compared PF and CNF on the introduced two-variant SEIR-model with pronounced non-identifiability for specific parameter combinations.
We first examined posterior distributions and predictive performance using twelve dense simulated observational time series. Posterior distributions showed markedly lower variance compared to the corresponding priors, indicating strong information gain from the data (Fig 4). The notable exception is under CNF, whose marginal remained close to the prior for some experiments, consistent with weak identifiability [68]. PF posteriors were generally more concentrated than those of CNF and were largely enveloped by the CNF approximation across parameters (Fig 5A). Despite these width differences, both methods generally include the true parameters in their posteriors, with CNF achieving 95.2% coverage of the 95% credible interval and PF achieving 91.7% coverage. Epidemic trajectories generated from both methods fit the data equally well (Fig 5B) with comparable energy scores (Table 6). PF produced marginally lower energy scores, highlighting the method’s focus on trajectory agreement through resampling.
Histograms of posterior approximations and prior distribution for the two-variant SEIR model using a dense dataset.
A Posterior approximations from 10,000 samples. Contours give the 50% (solid) and 95% (dashed) credible regions, coloured by method. Diagonals show the 1D marginals. Black stars mark the true parameters, coloured circles the joint MAP estimates. B Posterior predictive fit: bands give the 50% and 95% pointwise predictive intervals from the same samples (line styles as in A) with inference data shown as a dotted line.
The CNF–PF distances were broadly comparable to the variability across repeated CNF runs, suggesting that differences between the two methods remain close to the stochastic variability inherent in CNF. CNF showed good calibration in ECDF plots, though parameter recovery was imperfect for several parameters and markedly worse for , which showed weak correlation with the ground truth. PF chains displayed good convergence, with
being close to one across parameters. However, ESS were relatively low (<1000) for several parameter sets, indicating limited exploration of posterior tails.
In practice, observations are often non-equidistant or partially missing. To reflect this, we conducted additional experiments with reduced observation density. Results for sparse datasets were consistent with those obtained under dense observations. Posterior distributions from CNF and PF showed similar shapes, and epidemic trajectories generated from both methods fit the data equally well, with energy scores of comparable magnitude (Table 7). Additionally, CNF remained well calibrated and PF continued to show well-mixed chains, though ESS values remained low for several parameters, mirroring the diagnostics observed in the dense case. Together, these results indicate that both methods can accommodate sparse and irregular data without loss of inference quality, though CNF requires careful amortization design to handle heterogeneous observation schedules.
Taken together, these results show that CNF and PF both provide accurate inference for the two-variant SEIR model, even under pronounced non-identifiability. CNF yields broader posterior approximations that better capture low-probability regions, but do not strongly support specific parameter values. PF, in contrast, produces narrower posteriors and more certain point estimates, despite limited exploration of posterior tails due to low ESS. Predictive performance was high for both methods across dense and sparse datasets, with consistent MAP and predictive energy scores. Sparse observations introduced implementation overhead for CNFs but did not substantially affect inference quality for either method. Additionally, CNF are computationally more efficient and can be parallelized easily, while PF are restricted by their sequential nature and only one core per chain can be leveraged. Therefore, CNF were approximately 10-times faster, when parallelized to 20-cores compared to PF on 4-cores, independent of the used dataset (Supplementary Information S1 Text, Table S1.22).
Full diagnostics, including calibration plots, convergence statistics, Wasserstein-distances and parameter-recovery analyses, are provided in Supplementary Information S4 Results for the dense datasets and Supplementary Information S5 Results for the sparse datasets.
Reducing parameter dependencies improves posterior alignment
Complementing the analysis of the full SEIR2V model, we evaluated the reparametrized version of this model to explore how reduced parameter dependencies affect inference results for PF and CNF. To this end, we analysed twelve synthetic datasets in both the full and the reparametrized settings. In the full SEIR2V model setting, two datasets (r-2 and r-5) did not yield converged Markov chains and one dataset (r-6) showed a high value and small ESS for
and
under our PMMH workflow. This shows the challenges to achieve fast convergence and good mixing in MCMC based methods, if parameters are highly correlated due to unidentifiabilities in the model specification.
In the reparametrized setting, posterior distributions from CNF and PF showed close alignment across parameters, indicating similar exploration of the parameter space (Fig 6A). Unlike in the full SEIR2V model, the posterior approximations exhibited no signs of long-tailed behaviour. This is reflected in the 1-Wasserstein distances in log-parameter space, which were numerically smaller under reparametrization and decreased more strongly than the within-method baselines (CNF–CNF and PF–PF). Moreover, CNF–PF distances were of the same order as the variability observed across independent runs of each method, indicating improved cross-method alignment. Epidemic trajectories fit the data equally well (Fig 6B) with energy scores between CNF, PF, and the true parameters being close to each other in both model settings (Table 8, Table 9).
A Posterior approximations from 10,000 samples. Contours give the 50% (solid) and 95% (dashed) credible regions, coloured by method. Diagonals show the 1D marginals. Black stars mark the true parameters, coloured circles the joint MAP estimates. B Posterior predictive fit: bands give the 50% and 95% pointwise predictive intervals from the same samples (line styles as in A) with inference data shown as a dotted line.
Additionally, we evaluated calibration and convergence diagnostics. While results in the full model setting were consistent with the ones presented above, CNF showed SBC miscalibration in ECDF plots in the reparametrized setting(Supplementary Information S6 Results, Fig. S6.15), aligning with the results reported for the identifiable SIR model and hinting at a potential offset in the posterior. PF, in contrast, achieved ESS exceeding 2000 (Supplementary Information S6 Results, Table S6.2), indicating well-mixed chains and thorough posterior exploration.
In summary, removing parameter dependencies by reducing the number of estimated parameters improved identifiability and brought CNF and PF posterior shapes into closer agreement. While CNF exhibited minor calibration issues, PF benefited from substantially improved ESS, supporting robust posterior exploration in this setting. However, the reparametrization did not enhance predictive performance and relies on reducing the parameter space dimension by fixing , which should be approached with caution in applied inference.
Full diagnostics, including Wasserstein distance analyses, calibration plots, convergence statistics, and parameter-recovery results, are provided in Supplementary Information S6 Results for the reparametrized model and Supplementary Information S7 Results for the full model with datasets of the reparametrized model.
CNF and PF yield consistent results on real-world datasets
To complement the synthetic experiments, we applied both methods to data from a longitudinal cohort study of the COVID-19 outbreak in Ethiopia [1]. Our setup differed from the original study in that we used a stochastic rather than deterministic formulation, offering greater flexibility and better reflecting the inherent randomness in infection dynamics. Due to the unavailability of ground truth, we used the published mean of the parameter samples as a reference.
Posterior approximations from CNF and PF shared a similar overall shape, with the PF posterior largely nested within the broader CNF and exhibiting reduced variance, particularly for the rate parameters ,
, and
(Fig 7A). Trajectory ensembles derived from the inferred posteriors fit the data well, even under the relatively high noise level reported in the original study; one seroprevalence point was not captured by either method within their uncertainty intervals (Fig 7B). Predictive energy scores between CNF and PF improved on the energy score calculated from the originally published parameter set, indicating that both inference methods provide a better probabilistic fit to the observed data than the originally published parameter set (Table 10).
A Posterior approximations from 10,000 samples. Contours give the 50% (solid) and 95% (dashed) credible regions, coloured by method. Diagonals show the 1D marginals. Black stars mark the reference parameters, coloured circles the joint MAP estimates. B Posterior predictive fit: bands give the 50% and 95% pointwise predictive intervals from the same samples (line styles as in A). The inference data (published data from [1]) are shown as a dotted line with error bars.
Diagnostics were consistent with patterns observed in controlled experiments: CNF exhibited good calibration alongside imperfect parameter recovery, while PF demonstrated convergence despite low effective sample sizes for and
.
Taken together, applying both methods to the Ethiopian cohort data yielded results consistent with the synthetic analyses, underscoring the robustness of each approach. The trade-offs identified in controlled settings—CNF’s broader posterior coverage versus PF’s tighter estimates with lower ESS—carried over to this real-world application, while predictive performance remained strong for both methods.
Full diagnostics, including calibration plots, convergence statistics, and parameter-recovery results, are provided in Supplementary Information S8 Results.
Discussion
Responses to public health crises, such as outbreaks of infectious diseases, create a need for informed decision making by realistically modeling the dynamics using stochastic models. Yet, fitting such models to observed data present many difficulties and several methods were developed to address this challenge. In this work, we systematically evaluated two state-of-the-art methods for Bayesian parameter inference, Conditional Normalizing Flows (CNF) and pseudo-marginal particle MCMC, referred to as Particle Filters (PF), across a range of stochastic compartmental models. Our analysis encompassed synthetic and real-world data, varied model structure, and different levels of data sparsity, yielding crucial insights into the strengths and limitations of each methodology when applied in epidemiological modeling scenarios. Where feasible, we calculated a reference posterior using Hamiltonian Monte Carlo (HMC) on a finely discretized version of the stochastic models. Across all investigated scenarios, both methods produced accurate fits and informative posteriors. However, this study revealed systematic differences of uncertainty in the parameter space due to different posterior geometries and model design choices.
In the context of small stochastic models, such as the SIR model and the SIS model, both CNF and PF yielded highly consistent posterior distributions and closely matched predictive epidemic trajectories. The marginal and joint posterior estimates and MAP estimates were near the data-generating parameters and the predictive energy scores confirmed high predictive accuracy for both methods. CNFs exhibited miscalibration for the SIR model, which resulted in small offsets relative to PF and HMC. In contrast to that, CNF exhibited very good recovery plots in these settings. As an exact method, PF showed a good recovery of the true parameters and a high agreement with the reference posterior distributions, that were closely matched by the CNF. Together, this indicates that, once trained, CNF can deliver inference quality on a par with an exact MCMC based baseline while enabling possible amortization across different datasets and yielding high computational efficiency in the inference phase but miscalibration needs to be handled and analysed carefully.
Expanding the analysis, we applied both methods to a more complex stochastic two-variant SEIR model with practical non-identifiabilities and parameter couplings, that does not admit a reference posterior. In this setting, both methods fit the data well and achieved similar predictive power and uncertainty, yet PF produced narrower marginal posteriors that were largely enclosed by the broader CNF posteriors and simultaneously showed low effective sample sizes for several parameters. This pattern is consistent with resampling in PF concentrating particles in high-likelihood basins, i.e., on the fit to the data. This property can limit tail exploration in the parameter space especially when the posterior surface contains ridges or mountain-pass structures. Additionally, PF based methods are, as most MCMC methods, highly dependent on the choice of the initial parameter value. Uninformative initial parameter values lead to degenerate likelihood estimate and therefore stuck Markov chains. CNF achieved good calibration results in this setting, although its recovery plots indicated that parameter recovery was not perfect. The wider posteriors for CNF contrasts with prior literature where amortized inference often underestimates uncertainty [69]. Despite these differences, both methods captured the inference data accurately and showed strong predictive performance, as evidenced by low and similar predictive energy scores. Their application in this setting shows that amortized methods may struggle with calibration, yet still provide strong predictive performance and exact MCMC based method estimate the bulk of the posterior well while underestimating its width caused by insufficient exploration of the parameter space.
Using sparsely sampled datasets with different missingness patterns did not change the qualitative estimation results of both methods. But the two methods inherently treat sparse datasets differently. While CNF methods can accommodate such dataset variability, amortizing over all relevant combinations of time points may become computationally expensive and risks unreliable extrapolation if not carefully designed. This challenge is specific to setups that aim for broad amortization; alternatively, one can train CNFs for fixed missingness patterns. In contrast, PF methods naturally handle non-equidistant and partially missing data via their sequential simulation and weighting scheme, which decomposes the likelihood over time points and observables without requiring amortization or any other adaptation of the method.
Afterwards we introduced a reparametrization of the two-variant SEIR model that combined or transformed parameters based on their observed dependencies. This adjustment resulted in better alignment between CNF and PF posterior estimates and markedly increased PF convergence and mixing. These improvements suggest that the posterior geometry, rather than methods alone, leads to robust inference in the parameter space and model choices should be investigated as thoroughly as tuning of methods. CNF achieved worse calibration than in the full model case but its recovery plots demonstrated good parameter recovery. Both methods showed robustness to practical non-identifiabilities in their quality of fit and predictive power.
Finally, applying both methods to a real dataset from a longitudinal cohort study in Ethiopia confirmed the simulation study findings and yielded broadly similar posterior approximations and epidemic trajectories. Although obtained MAP estimates differed from previously published parameter values, especially for CNFs, both methods captured the data dynamics and produced model fits with predictive energy scores close to or improving upon the deterministic analysis [1]. By demonstrating their effectiveness in a real-world setting, our analysis underscores the potential of these methods to inform public health strategies and decision-making processes.
We also compared the computational efficiency of the two methods. To ensure a meaningful comparison, both methods were calibrated to produce the same number of samples from the parameter posterior, with CNF’s neural network trained on a CPU. Despite this constraint, CNF is roughly 10 times faster than PF, due to PFs sequential nature and the higher number of simulator calls. The bulk of CNF’s computational time is spent on training, but once trained, inference can be performed in mere seconds. CNF’s amortization allows multiple inferences, providing, in this scenario, a significant advantage over PF, which requires separate computations for each run. To achieve greater speed, CNF can make use of a parallelized simulator or training the neural network on a GPU. Meanwhile, PF could benefit from the use of more advanced filtering algorithms such as guided PFs [27,70] or using correlated particles [28] to avoid degeneracy or too high particle numbers. Switching to a more advanced outer MCMC sampler such as a Gibbs sampler [71] or a Metropolis-Adjusted Langevin algorithm [72] and parallelization over particles could speed-up the inference procedure as well. Additionally, the lack of amortization renders assessment of calibration and hyperparameter tuning for PF too computationally expensive.
The scope of this work leads to several limitations. For the more complex two-variant SEIR model no reference posterior was available, leaving the assessment based on comparative observations between the two chosen methods. The observation model employed additive Gaussian noise for clarity and comparability; overdispersed counts or serological adjustments may be better represented by negative-binomial or beta-binomial formulations in other settings. Our use of an Euler–Maruyama integration with positivity clipping introduces discretization error whose interaction with inference can lead to numerical instabilities near boundaries or in small populations. Algorithmic choices were guided by the ease of their applicability in praxis: We focused on a bootstrap PF within PMMH and a tuned CNF architecture with consistent hyperparameters and fixed simulation budget across our datasets and experimental setups. Alternative PF proposals (e.g., guided/auxiliary filters or tempering within SMC) and alternative SBI estimators (likelihood or ratio estimation) or more exhaustive hyperparameter-tuning could shift efficiency–accuracy trade-offs. To avoid out-of-distribution failure modes, CNFs were trained per experiment rather than globally amortized across all data regimes, which tempers their wall-clock advantage in this study; broader amortization remains attractive but demands careful conditioning on meta-data such as time-grid irregularity and noise scales [49,62].
In the SBI literature, recent advances focus on workflows that narrow the gap between neural SBI and Monte Carlo by using learned proposals inside sequential Monte Carlo or MCMC [73,74]. Variational and amortized SMC approaches train proposal families to reduce weight degeneracy and improve effective sample sizes; conversely, particle methods can provide high-quality samples to bootstrap or regularize neural estimators. Looking forward, future work in this context of hybrid approaches could focus on a flow trained in the spirit of neural posterior estimation that proposes parameter values to a PMMH kernel or guide latent-state proposals. These methods could combine the tail coverage and speed of neural estimators with the asymptotic correctness and model flexibility of pseudo-marginal schemes. Recent generative modeling advancements, i.e., flow matching and diffusion-style transports, offer further avenues for robust posterior learning with stronger inductive biases and improved stability [75–77]. Additionally, the use of adaptive prior schemes where the prior is updated in light of the available data, through approaches such as empirical Bayes, hierarchical modeling, or iterative refinement, may help to mitigate issues of non-identifiability while improving robustness. Such strategies may enhance performance in particularly challenging applications that use real world data where information is both sparse and noisy.
In summary, our comparison suggests that both CNF and PF are viable inference strategies for complex epidemic models, with different focus on parameter space exploration and data fitting. CNF tends to provide a more extensive posterior, whereas PF typically produces tighter distributions. Moreover, CNF’s substantially lower computational cost and amortization capabilities, achieving approximately 10 times faster performance than PF under comparable conditions, makes CNF especially advantageous for large-scale or time-sensitive applications. In contrast, PF maintain exactness (in the pseudo-marginal sense) under model changes at the cost of potential tail under-exploration, rendering PF a robust choice across models. The use of sparsely sampled data with different missingness patterns highlights the applicability of both methods and their robustness to different data settings. By clarifying the trade-offs and giving insights into the performance of these two practical inference methods, this work provides the groundwork for evaluating inference engines ready for uncertainty-aware epidemic forecasting and real-time support of public-health decisions.
Supporting information
S4 Result. Supplementary Results SEIR-Model with Dense Data.
https://doi.org/10.1371/journal.pone.0353306.s004
(PDF)
S5 Result. Supplementary Results SEIR-Model with Sparse Data.
https://doi.org/10.1371/journal.pone.0353306.s005
(PDF)
S6 Results. Supplementary Results Reparametrized SEIR-Model.
https://doi.org/10.1371/journal.pone.0353306.s006
(PDF)
S7 Results. Supplementary Results Comparison Full SEIR-Model with Reparametrized Model.
https://doi.org/10.1371/journal.pone.0353306.s007
(PDF)
S8 Results. Supplementary Results SEIR-Model with Real Data.
https://doi.org/10.1371/journal.pone.0353306.s008
(PDF)
References
- 1. Gudina EK, Ali S, Girma E, Gize A, Tegene B, Hundie GB, et al. Seroepidemiology and model-based prediction of SARS-CoV-2 in Ethiopia: longitudinal cohort study among front-line hospital workers and communities. Lancet Glob Health. 2021;9(11):e1517–27. pmid:34678196
- 2. Doms C, Kramer SC, Shaman J. Assessing the Use of Influenza Forecasts and Epidemiological Modeling in Public Health Decision Making in the United States. Sci Rep. 2018;8(1):12406. pmid:30120267
- 3.
Global Preparedness Monitoring Board. The Changing Face of Pandemic Risk: 2024 Report. 2025. https://www.gpmb.org/reports/m/item/the-changing-face-of-pandemic-risk-2024-report
- 4. Kermack WO, McKendrick AG. A contribution to the mathematical theory of epidemics. Proceedings of the Royal Society of London Series A, Containing Papers of a Mathematical and Physical Character. 1927;115(772):700–21.
- 5. Hethcote HW. The mathematics of infectious diseases. SIAM Review. 2000;42(4):599–653.
- 6. Bruch E, Atwell J. AGENT-BASED MODELS IN EMPIRICAL SOCIAL RESEARCH. Sociol Methods Res. 2015;44(2):186–221. pmid:25983351
- 7. Britton T. Stochastic epidemic models: a survey. Math Biosci. 2010;225(1):24–35. pmid:20102724
- 8.
Dragatz C. Bayesian inference for diffusion processes. Fakultät für Mathematik, Informatik und Statistik der Ludwig-Maximilians-Universität München. 2010.
- 9. Allen LJS. A primer on stochastic epidemic models: Formulation, numerical simulation, and analysis. Infect Dis Model. 2017;2(2):128–42. pmid:29928733
- 10. Gillespie DT, Hellander A, Petzold LR. Perspective: Stochastic algorithms for chemical kinetics. J Chem Phys. 2013;138(17):170901. pmid:23656106
- 11.
Dragatz C. A diffusion approximation for an epidemic model. LMU München. 2006.
- 12.
Brauer F. Chapter 6. Compartmental Models in Epidemiology. Springer Berlin Heidelberg. 2008. https://doi.org/10.1007/978-3-540-78911-6-2
- 13.
Van KAMPEN NG. The Expansion of the Master Equation. Advances in Chemical Physics. Wiley. 1976. 245–309. https://doi.org/10.1002/9780470142530.ch5
- 14. Fearnhead P, Giagos V, Sherlock C. Inference for reaction networks using the linear noise approximation. Biometrics. 2014;70(2):457–66. pmid:24467590
- 15. Kurtz TG. Solutions of ordinary differential equations as limits of pure jump Markov processes. Journal of Applied Probability. 1970;7(1):49–58.
- 16.
Andersson H, Britton T. Stochastic epidemic models and their statistical analysis. Cambridge: Springer Verlag. 2001. https://doi.org/10.1007/978-1-4612-1158-7
- 17. Gibson GJ, Renshaw E. Estimating parameters in stochastic compartmental models using Markov chain methods. Mathematical Medicine and Biology: A Journal of the IMA. 1998;15(1):19–40.
- 18. O’Neill PD, Roberts GO. Bayesian Inference for Partially Observed Stochastic Epidemics. Journal of the Royal Statistical Society Series A: Statistics in Society. 1999;162(1):121–9.
- 19. Swallow B, Birrell P, Blake J, Burgman M, Challenor P, Coffeng LE, et al. Challenges in estimation, uncertainty quantification and elicitation for pandemic modelling. Epidemics. 2022;38:100547. pmid:35180542
- 20. Fintzi J, Wakefield J, Minin VN. A linear noise approximation for stochastic epidemic models fit to partially observed incidence counts. Biometrics. 2022;78(4):1530–41. pmid:34374071
- 21. McKinley TJ, Ross JV, Deardon R, Cook AR. Simulation-based Bayesian inference for epidemic models. Computational Statistics & Data Analysis. 2014;71:434–47.
- 22. El Maroufy H, Kernane T, Becheket S, Ouddadj A. Bayesian inference for nonlinear stochastic SIR epidemic model. Journal of Statistical Computation and Simulation. 2015;86(11):2229–40.
- 23. Doucet A, Godsill S, Andrieu C. On sequential Monte Carlo sampling methods for Bayesian filtering. Statistics and Computing. 2000.
- 24. Chopin N, Jacob PE, Papaspiliopoulos O. SMC2: An Efficient Algorithm for Sequential Analysis of State Space Models. Journal of the Royal Statistical Society Series B: Statistical Methodology. 2012;75(3):397–426.
- 25. Andrieu C, Roberts GO. The pseudo-marginal approach for efficient Monte Carlo computations. Ann Statist. 2009;37(2).
- 26. Andrieu C, Doucet A, Holenstein R. Particle Markov Chain Monte Carlo Methods. Journal of the Royal Statistical Society Series B: Statistical Methodology. 2010;72(3):269–342.
- 27.
Chopin N, Papaspiliopoulos O. An introduction to sequential Monte Carlo. Springer International Publishing. 2020. https://doi.org/10.1007/978-3-030-47845-2
- 28. Wiqvist S, Golightly A, McLean AT, Picchini U. Efficient inference for stochastic differential equation mixed-effects models using correlated particle pseudo-marginal algorithms. Computational Statistics & Data Analysis. 2021;157:107151.
- 29. Rubin DB. Bayesianly justifiable and relevant frequency calculations for the applied statistician. The Annals of Statistics. 1984;:1151–72.
- 30. Minter A, Retkute R. Approximate Bayesian Computation for infectious disease modelling. Epidemics. 2019;29:100368. pmid:31563466
- 31. Cranmer K, Brehmer J, Louppe G. The frontier of simulation-based inference. Proc Natl Acad Sci U S A. 2020;117(48):30055–62. pmid:32471948
- 32.
Papamakarios G, Murray I. Fast <>-free inference of simulation models with Bayesian conditional density estimation. In: Proceedings of the 30th International Conference on Neural Information Processing Systems, 2016. 1036–44. https://doi.org/10.5555/3157096.3157212
- 33. Papamakarios G, Nalisnick E, Rezende DJ, Mohamed S, Lakshminarayanan B. Normalizing Flows for Probabilistic Modeling and Inference. Journal of Machine Learning Research. 2021;22(57):1–64.
- 34. Radev ST, Graw F, Chen S, Mutters NT, Eichel VM, Bärnighausen T, et al. OutbreakFlow: Model-based Bayesian inference of disease outbreak dynamics with invertible neural networks and its application to the COVID-19 pandemics in Germany. PLoS Comput Biol. 2021;17(10):e1009472. pmid:34695111
- 35. Storvik G, Diz-Lois Palomares A, Engebretsen S, Rø GØI, Engø-Monsen K, Kristoffersen AB, et al. A sequential Monte Carlo approach to estimate a time-varying reproduction number in infectious disease models: the Covid-19 case. Journal of the Royal Statistical Society Series A: Statistics in Society. 2023;186(4):616–32.
- 36. Harko T, Lobo FS, Mak MK. Exact analytical solutions of the Susceptible-Infected-Recovered (SIR) epidemic model and of the SIR model with equal death and birth rates. Applied Mathematics and Computation. 2014;236:184–94.
- 37.
Daley DJ, Gani JM. Epidemic modelling: an introduction. Cambridge University Press. 1999. https://doi.org/10.1017/CBO9780511608834
- 38.
Keeling MJ, Rohani P. Modeling infectious diseases in humans and animals. Princeton University Press. 2008. https://doi.org/10.1515/9781400841035
- 39.
Bernardo JM, Smith AF, Berliner M. Bayesian theory. Wiley Online Library. 1994. https://doi.org/10.1002/9780470316870
- 40.
Doucet A, de Freitas N, Gordon NJ. Sequential Monte Carlo methods in practice. Springer New York. 2001. https://doi.org/10.1007/978-1-4757-3437-9
- 41.
Wilkinson DJ. Parameter Inference for Stochastic Kinetic Models of Bacterial Gene Regulation: A Bayesian Approach to Systems Biology. Bayesian Statistics 9. Oxford University Press. 2011. p. 679–706. https://doi.org/10.1093/acprof:oso/9780199694587.003.0023
- 42.
Hasenauer J. Modeling and parameter estimation for heterogeneous cell populations. Logos Verlag Berlin GmbH. 2013. https://doi.org/10.18419/opus-4537
- 43. Golightly A, Wilkinson DJ. Bayesian parameter inference for stochastic biochemical network models using particle Markov chain Monte Carlo. Interface Focus. 2011;1(6):807–20. pmid:23226583
- 44.
Moral PF. Feynman-Kac formulae: genealogical and interacting particle systems with applications. Springer. 2004. https://doi.org/10.1007/978-1-4684-9393-1
- 45. Doucet A, Pitt MK, Deligiannidis G, Kohn R. Efficient implementation of Markov chain Monte Carlo when using an unbiased likelihood estimator. Biometrika. 2015;102(2):295–313.
- 46. Radev ST, Mertens UK, Voss A, Ardizzone L, Kothe U. BayesFlow: Learning Complex Stochastic Models With Invertible Neural Networks. IEEE Trans Neural Netw Learn Syst. 2022;33(4):1452–66. pmid:33338021
- 47. Rezende D, Mohamed S. In: 2015. 1530–8.
- 48. Boelts J, Deistler M, Gloeckler M, Álvaro Tejero-Cantero, Lueckmann JM, Moss G. Sbi reloaded: a toolkit for simulation-based inference workflows. Journal of Open Source Software. 2025;10(108):7754.
- 49. Radev ST, Schmitt M, Schumacher L, Elsemüller L, Pratz V, Schälte Y, et al. BayesFlow: Amortized Bayesian Workflows With Neural Networks. arXiv. 2023.
- 50.
Winkler C, Worrall D, Hoogeboom E, Welling M. Learning Likelihoods with Conditional Normalizing Flows. In: 2019. https://doi.org/10.48550/arXiv.1912.00042
- 51. Kobyzev I, Prince SJD, Brubaker MA. Normalizing Flows: An Introduction and Review of Current Methods. IEEE Trans Pattern Anal Mach Intell. 2021;43(11):3964–79. pmid:32396070
- 52. Ardizzone L, Lüth C, Kruse J, Rother C, Köthe U. Guided Image Generation with Conditional Invertible Neural Networks. arXiv preprint. 2019.
- 53.
Weilbach C, Beronov B, Harvey W, Wood F. In: Proceedings of the 23rd International Conference on Artificial Intelligence and Statistics, 2020. 4441–51. https://proceedings.mlr.press/v108/weilbach20a.html
- 54. Siahkoohi A, Rizzuti G, Witte PA, Herrmann FJ. Faster Uncertainty Quantification for Inverse Problems with Conditional Normalizing Flows. arXiv preprint. 2020.
- 55. Talts S, Betancourt M, Simpson D, Vehtari A, Gelman A. Validating Bayesian inference algorithms with simulation-based calibration. arXiv preprint. 2018.
- 56. Rackauckas C, Nie Q. Adaptive Methods For Stochastic Differential Equations Via Natural Embeddings And Rejection Sampling With Memory. Discrete Continuous Dyn Syst Ser B. 2017;22(7):2731–61. pmid:29527134
- 57. Ma Y, Gowda S, Anantharaman R, Laughman C, Shah V, Rackauckas C. ModelingToolkit: A Composable Graph Transformation System for Equation-Based Modeling. arXiv. 2021.
- 58. Haario H, Saksman E, Tamminen J. An Adaptive Metropolis Algorithm. Bernoulli. 2001;7(2):223.
- 59.
Schälte Y, Fröhlich F, Stapor P, Vanhoefer J, Weindl D, Jost PJ. pyPESTO - Parameter estimation toolbox for python (v0.2.16). zenodo. 2023. https://doi.org/10.5281/zenodo.7669757
- 60.
Fjelde TE, Xu K, Widmann D, Tarek M, Pfiffer C, Trapp M. Turing.jl: a general-purpose probabilistic programming language. ACM Transactions on Probabilistic Machine Learning. 2025.
- 61. Vehtari A, Gelman A, Simpson D, Carpenter B, Bürkner P-C. Rank-Normalization, Folding, and Localization: An Improved Rˆ for Assessing Convergence of MCMC (with Discussion). Bayesian Anal. 2021;16(2).
- 62. Wang Z, Hasenauer J, Schälte Y. Missing data in amortized simulation-based neural posterior estimation. PLoS Comput Biol. 2024;20(6):e1012184. pmid:38885265
- 63.
Silverman BW. Density estimation for statistics and data analysis. Routledge. 1998. https://doi.org/10.1201/9781315140919
- 64. Hoffman MD, Gelman A. The no-u-turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo. J Mach Learn Res. 2014;15(1):1593–623.
- 65. McAloon C, Collins Á, Hunt K, Barber A, Byrne AW, Butler F, et al. Incubation period of COVID-19: a rapid systematic review and meta-analysis of observational research. BMJ Open. 2020;10(8):e039652. pmid:32801208
- 66. Fang Z, Zhang Y, Hang C, Ai J, Li S, Zhang W. Comparisons of viral shedding time of SARS-CoV-2 of different samples in ICU and non-ICU patients. J Infect. 2020;81(1):147–78. pmid:32209381
- 67. Raimúndez E, Dudkin E, Vanhoefer J, Alamoudi E, Merkt S, Fuhrmann L, et al. COVID-19 outbreak in Wuhan demonstrates the limitations of publicly available case numbers for epidemiological modeling. Epidemics. 2021;34:100439. pmid:33556763
- 68. Wang Y, Blei D, Cunningham JP. Posterior collapse and latent variable non-identifiability. Advances in Neural Information Processing Systems. 2021;34:5443–55.
- 69. Hermans J, Delaunoy A, Rozet F, Wehenkel A, Begy V, Louppe G. A trust crisis in simulation-based inference? Your posterior approximations can be unfaithful. Transactions on Machine Learning Research. 2022.
- 70.
Snyder C. In: 2011. 1–10.
- 71. Chopin N, Singh SS. On particle Gibbs sampling. Bernoulli. 2015;21(3).
- 72.
Lowe TE. Accelerating pseudo-marginal Metropolis-Hastings schemes for stochastic kinetic models. Newcastle University. 2023.
- 73.
Papamakarios G, Sterratt D, Murray I. In: 2019. 837–48.
- 74. Hermans J, Begy V, Louppe G. In: 2020. 4239–48.
- 75.
Lipman Y, Chen RT, Ben-Hamu H, Nickel M, Le M. Flow matching for generative modeling. In: 2022. https://doi.org/10.48550/arXiv.2210.02747
- 76. Draxler F, Sorrenson P, Zimmermann L, Rousselot A, Köthe U. In: 2024. 2197–205.
- 77.
Arruda J, Bracher N, Köthe U, Hasenauer J, Radev ST. Diffusion Models in Simulation-Based Inference: A Tutorial Review. arXiv preprint. 2025.