Calibration, model refusal and representation robustness in joint demographic and selection inference
Abstract
We study joint inference of two-epoch demography and a selective sweep from a single 1 Mb genomic window. Four encoder–posterior combinations are evaluated using simulation-based calibration and TARP diagnostics first checked against an analytic posterior. Across reported runs, TARP KS statistics are 0.015–0.025 and nominal 90% coverage is 0.86–0.90; small SBC p-values indicate detectable rank deviations. Under the tested single-window protocol, the composite-likelihood baseline moments covers the three demographic parameters at 0.18–0.53. A conformal refusal layer controls false alarms on exchangeable in-model data and detects complementary forms of misspecification through posterior-predictive and embedding-distance scores. It refuses 10 of 14 real 1000 Genomes windows, indicating incompatibility with the fitted simulator. The raw-genotype CNN has approximately 20% higher point-estimation error than the summary encoder but higher coverage on all 19 tested misspecified variants, with mean coverage deficits of 0.027 and 0.110. The genetics robustness comparison uses one training seed per arm and unequal evaluation sizes. Three-seed experiments in SIR and Ricker simulators reproduce the direction at smaller magnitude. These results motivate matched tests of representation robustness, posterior sharpness and simulator mismatch.
Keywords: simulation-based inference · calibration · conformal prediction · model misspecification · population genetics · flow matching
1Introduction
Simulation-based inference (SBI) replaces an intractable likelihood with a simulator and learns the posterior from simulated pairs [1]. Population genetics is a natural home for it: coalescent simulators such as msprime [2] are fast and expressive, and the summary statistics practitioners rely on are known to discard information. Two habits have come with the adoption. The first is to trust learned posteriors without measuring their calibration, even though amortized estimators are known to be overconfident in practice [3]. The second is to assume that a deep encoder on raw genotype matrices will dominate hand-built summary statistics [4].
We test both habits on a problem chosen to be hard but checkable: joint inference of demography and a selective sweep from one genomic window. Our method is calibration-first. Before any learned posterior is judged, the diagnostics that will judge it are validated on a conjugate model where the exact posterior is known. We then ask three questions. Are calibrated joint posteriors attainable, and how does the classical incumbent compare? Can a refusal head detect misspecification with a guaranteed false-alarm rate? How does encoder choice affect both accuracy and reliability?
The raw-genotype encoder has higher point-estimation error at every tested budget and higher interval coverage across the tested misspecified variants. Two additional simulators reproduce the direction at smaller magnitude. Matched comparisons of posterior width and proper scores are needed to distinguish robustness from conservatism.
2Methods
2.1Forward model and prior
The forward model is a single panmictic population simulated in msprime with a two-epoch demography (recent size N_0, ancestral size N_{\mathrm{anc}}, change time T_c) and a hard sweep of coefficient s at the centre of a 1 Mb region, completed T_e generations ago. Mutation and recombination rates are fixed at human-like values (\mu = 1.5\times10^{-8}, r = 10^{-8} per bp per generation). The five inferred parameters have box priors on \log_{10} N_0, \log_{10} N_{\mathrm{anc}} \in [3.3, 4.7], T_c \in [10^3, 8\times10^4], \log_{10} s \in [-2.7, -1.3] and T_e \in [0, 5000]. msprime forbids demographic events during a sweep, so the box is truncated to T_c \geq 1.25\,(T_e + \tfrac{2}{s}\ln 2N_0) by rejection sampling. The rejection step yields exact draws from the truncated prior, which is used for both training and calibration testing, so the tests remain exact. The observation is the 64 \times 256 genotype matrix of the 256 segregating sites nearest the sweep (32 diploids) with their positions.
2.2Encoders and density heads
The summary encoder computes 90 statistics from the same matrix: diversity, the full unfolded site-frequency spectrum (SFS), Tajima's D, Fay and Wu's H, haplotype homozygosity (H1, H12, H123, H2/H1) region-wide and in the sweep core, the diversity valley, and linkage disequilibrium in six distance bins. An MLP maps them to a 64-dimensional embedding. We deliberately made this baseline strong. The exchangeable CNN convolves along the SNP axis only and mixes haplotypes solely through a symmetric pool, so invariance to haplotype order is architectural [5, 4]. Each encoder feeds either a neural spline flow trained by maximum likelihood (NPE) [6] or a flow-matching posterior estimator (FMPE) [7, 8]. In five dimensions the FMPE log-density is computed exactly by reverse integration with the full divergence.
2.3Calibration diagnostics
Simulation-based calibration (SBC) [9] tests per-parameter rank uniformity. TARP [10] provides multivariate expected-coverage diagnostics with a population-level characterization of posterior correctness under its reference-point conditions. We use randomized ranks and report the Kolmogorov–Smirnov deviation of the coverage curve. A finite diagnostic sample has limited power; passing it supplies empirical evidence of calibration. We treat TARP as primary. On a conjugate Gaussian both tests accept the exact posterior at the nominal false-alarm rate and reject overconfident, underconfident and biased posteriors at p < 10^{-3}.
2.4Conformal refusal head
Let s(\cdot) be any atypicality score fitted without the calibration set. Given n exchangeable in-model calibration scores, the conformal p-value p = (1 + \#\{i : s_i \geq s\})/(n+1) satisfies P(p \leq \alpha) \leq \alpha in finite samples [11]. Refusing when p \leq \alpha therefore bounds the false-alarm rate on well-specified data. We compare three scores: Mahalanobis typicality of the summaries, mean distance to the k nearest training embeddings, and a posterior-predictive discrepancy that simulates from posterior draws and asks whether any believed parameter can regenerate the observation.
2.5Misspecification suite and baselines
Every misspecified variant draws \theta from the training prior and corrupts only the forward or observation model. The variants are soft sweeps, recombination rate scaled by 0.25 to 4, recombination hotspots, mutation-rate error, an unmodelled ancient size change, the neutral extreme, genotyping error, missing calls, and SNP-array minor-allele ascertainment. The classical baseline is moments [12], fitted to the whole-region SFS, which uses frequency information from the full region, with Godambe intervals from a genomic block bootstrap. The poor coverage on the neutral control is a limitation of this implemented comparison and warrants dedicated baseline validation. Real data are 14 phase-3 1000 Genomes windows [13] at LCT, SLC24A5, EDAR and two neutral regions in CEU, YRI and CHB. We fetch them with our own BGZF and tabix reader over HTTP range requests. For cross-domain tests we use a stochastic SIR epidemic and a Ricker map with Poisson observations, each with a summary-MLP and a raw 1-D CNN encoder of matched capacity.
3Results
3.1Posterior accuracy and empirical coverage
Across the four encoder–head arms, three-seed mean TARP KS is 0.015–0.025 and nominal 90% coverage is 0.86–0.90 (Figure 1, left). The saved grid also reports small minimum SBC p-values, down to about 10^{-14} in some cells. These indicate rank deviations and should be reported alongside effect sizes; the results support approximate empirical calibration. Accuracy separates the encoders, and against the raw-genotype network (Table 1). The summary encoder with FMPE reaches normalized RMSE 0.405, 0.386 and 0.379 at 2k, 10k and 40k simulations. The CNN with FMPE sits at 0.492, 0.466 and 0.451, a ratio that barely moves with budget (1.21, 1.21, 1.19).
| Simulations | Summary encoder | Exchangeable CNN | Ratio |
|---|---|---|---|
| 2,000 | 0.405 | 0.492 | 1.21 |
| 10,000 | 0.386 | 0.466 | 1.21 |
| 40,000 | 0.379 | 0.451 | 1.19 |
moments recovers demographic point estimates but its intervals are badly overconfident: 90% coverage of 0.53, 0.26 and 0.18 for \log_{10}N_0, \log_{10}N_{\mathrm{anc}} and T_c, with 39–78% of truths beyond 2\sigma. A neutral control, where its two-epoch model is correctly specified, already gives 0.35–0.64. A single window carries little information about the ancestral epoch, and the sweep removes a further 10–17 points. The neural posteriors cover the same parameters at about 0.88 on identical windows.

moments (red) is overconfident while Summary+FMPE is closer to nominal under this protocol.3.2Refusal with a controlled false-alarm rate
On the well-specified control the three scores refuse 4%, 6% and 3% of 1,000 windows at \alpha = 0.05, consistent with the finite-sample bound. Power depends on the failure mode, and the two leading scores are complementary (Table 2). Genotyping error adds SNPs that no demography can generate but barely moves marginal summaries, so the posterior-predictive score catches it and the typicality scores do not. Ascertainment reshapes the SFS, which the embedding score sees directly.
| Variant | Mahalanobis | Embedding kNN | Post.-predictive |
|---|---|---|---|
| Well-specified control | 0.04 | 0.06 | 0.03 |
| Genotyping error (2%) | 0.01 | 0.01 | 0.70 |
| SNP-array ascertainment | 0.29 | 0.80 | 0.47 |
On real 1000 Genomes windows the Bonferroni-combined rule refuses 10 of 14 (71%). In the fixed-recombination model it rejects the European LCT window (posterior-predictive p=0.001) and accepts the African window. This is a model-compatibility result; the score alone does not identify the biological source of mismatch. A version that marginalizes recombination has TARP KS 0.014 and coverage 0.88, with a small SBC minimum p-value, and accepts 3 of 14 windows against 4 of 14 for the original model. This nuisance extension therefore leaves substantial incompatibility in the small real-data sample.
3.3The encoder trades accuracy for robustness
Running the misspecification ladder through the CNN arm shows that the CNN posterior keeps its calibration far better. It covers higher than the summary posterior on 19 of 19 variants, with a mean shortfall from nominal coverage of 0.027 against 0.110, a fourfold difference. This comparison uses a single training seed per arm and unequal evaluation sizes (1,000 and 600 windows). The direction is consistent across every variant, but the magnitude should be read with that in mind.
To test whether this is a property of genomics, we ran the identical protocol on two unrelated simulators with three seeds each (Table 3). The ordering repeats in both: the summary encoder is more accurate on well-specified data, and the raw encoder holds coverage better under held-out misspecification. The effect is largest in population genetics, where the raw representation is highest-dimensional, and modest but consistent on every seed in the two dynamical models.
| Task | RMSE summary | RMSE raw | Cov. summary | Cov. raw |
|---|---|---|---|---|
| SIR epidemic | 0.287 | 0.348 | 0.588 | 0.632 |
| Ricker | 0.316 | 0.349 | 0.703 | 0.733 |
4Discussion
Calibration across architectures. The tested arms achieve empirical coverage close to the nominal target while retaining detectable SBC deviations. The moments comparison highlights uncertainty estimation under a single-window protocol. Its poor neutral-control coverage also motivates further checks of block-bootstrap settings, identifiability and baseline optimization before broader conclusions about that method.
Interpreting refusal. Frequent refusal on real windows indicates incompatibility with the simulator under the chosen scores. The conformal guarantee controls false alarms only under in-model exchangeability. It does not certify a biological explanation for rejection, establish the correctness of accepted posteriors under shift, or guarantee detection of every misspecification.
A possible mechanism for the encoder tradeoff. Summary statistics emphasize features aligned with the simulator parameters; misspecification can move those features for other reasons. A raw encoder may distribute its dependence more broadly. This is a hypothesis consistent with the ABC misspecification literature [14]. Wider or less informative posteriors can also raise coverage, so matched sharpness, proper-score and prior-only controls are necessary to distinguish robustness from conservatism.
5Limitations
The forward model is a single population. msprime does not combine multi-population demography with its sweep model, which limits the biological scope of the model. The observed refusal rates quantify incompatibility with the implemented simulator. Cryptic structure and continuous growth could not be included as misspecifications for the same reason. The encoder robustness comparison in population genetics is single-seed with unequal evaluation sizes. SBC and TARP probe different aspects of posterior accuracy. Small SBC p-values require examining per-parameter rank histograms, finite-rank handling and diagnostic power, alongside coverage deviations and interval widths.
6Conclusion
Joint demography and selection inference yields near-nominal empirical coverage on the simulated model. A conformal refusal layer detects several tested mismatches and rejects most of the small real-data sample. Across three simulators, raw encoders show higher coverage under the tested shifts alongside higher in-model point error. Repeated, matched evaluations with sharpness controls are needed to characterize that tradeoff.
Data and code availability
Simulation, training and evaluation code, the misspecification suite and every result file are in the private project repository; each number above is generated from those files by a single script. 1000 Genomes data are public and are fetched directly from the project's FTP mirror.
References
- K. Cranmer, J. Brehmer, and G. Louppe. The frontier of simulation-based inference. Proceedings of the National Academy of Sciences, 117(48):30055–30062, 2020.
- F. Baumdicker, G. Bisschop, D. Goldstein, et al. Efficient ancestry and mutation simulation with msprime 1.0. Genetics, 220(3):iyab229, 2022.
- J. Hermans, A. Delaunoy, F. Rozet, A. Wehenkel, V. Begy, and G. Louppe. A crisis in simulation-based inference? Beware, your posterior approximations can be unfaithful. Transactions on Machine Learning Research, 2022.
- L. Flagel, Y. Brandvain, and D. R. Schrider. The unreasonable effectiveness of convolutional neural networks in population genetic inference. Molecular Biology and Evolution, 36(2):220–238, 2019.
- J. Chan, V. Perrone, J. P. Spence, P. A. Jenkins, S. Mathieson, and Y. S. Song. A likelihood-free inference framework for population genetic data using exchangeable neural networks. In Advances in Neural Information Processing Systems 31, 2018.
- C. Durkan, A. Bekasov, I. Murray, and G. Papamakarios. Neural spline flows. In Advances in Neural Information Processing Systems 32, 2019.
- M. Dax, J. Wildberger, S. Buchholz, S. R. Green, J. H. Macke, and B. Schölkopf. Flow matching for scalable simulation-based inference. In Advances in Neural Information Processing Systems 36, 2023.
- Y. Lipman, R. T. Q. Chen, H. Ben-Hamu, M. Nickel, and M. Le. Flow matching for generative modeling. In International Conference on Learning Representations, 2023.
- S. Talts, M. Betancourt, D. Simpson, A. Vehtari, and A. Gelman. Validating Bayesian inference algorithms with simulation-based calibration. arXiv preprint arXiv:1804.06788, 2018.
- P. Lemos, A. Coogan, Y. Hezaveh, and L. Perreault-Levasseur. Sampling-based accuracy testing of posterior estimators for general inference. In Proceedings of the 40th International Conference on Machine Learning, PMLR 202:19256–19273, 2023.
- V. Vovk, A. Gammerman, and G. Shafer. Algorithmic Learning in a Random World. Springer, 2005.
- J. Jouganous, W. Long, A. P. Ragsdale, and S. Gravel. Inferring the joint demographic history of multiple populations: beyond the diffusion approximation. Genetics, 206(3):1549–1567, 2017.
- The 1000 Genomes Project Consortium. A global reference for human genetic variation. Nature, 526(7571):68–74, 2015.
- D. T. Frazier, C. P. Robert, and J. Rousseau. Model misspecification in approximate Bayesian computation: consequences and diagnostics. Journal of the Royal Statistical Society: Series B, 82(2):421–444, 2020.