Manuscript Offprint
arXiv:2610.16574: High-dimensional MCMC Convergence Diagnosis with Normalizing Flows
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
\journalinfo
The Open Journal of Astrophysics
NFDiag: High-dimensional MCMC Convergence Diagnosis with Normalizing Flows
Abstract
Accurately assessing the convergence of Monte Carlo Markov Chains is crucial for ensuring their validity in Bayesian inference problems. However, convergence assessment in high dimensions is known to be difficult, due to most convergence diagnostics becoming insensitive beyond a few dozen parameters. Conventional convergence statistics analyze marginal distributions which in high dimensions neglects increasing levels of information from the joint and conditional probability distributions. Thus we propose NFDiag, which taps into the information of the full multivariate joint posterior with a normalizing flow (NF). Our convergence diagnostic thereby also analyzes information from conditional distributions. In other words, by working in the full multivariate space, it is sensitive with respect to the geometry of the chain in high dimensions. Our diagnostic utilizes that NFs assume independent and identically distributed (iid) training samples, which is a testable assumption that will be violated by a non-converged or strongly correlated chain. Our diagnostic trains NFs on separate parts of a chain, and then assesses whether these correspond to the same multivariate target distribution. We test our diagnostic in up to 250 dimensions, and demonstrate it is universal and unbiased, and detects problematic chain quality also when Gelman-Rubin and the multivarite effective sample size do not.
As these algorithms allowed for sampling from more complex and increasingly higher dimensional probability distributions, a typical research question became: How can one tell that a chain is of sufficient quality to faithfully represent the target distribution? This is usually abbreviated to the question of whether the chain has converged.
In dimensions beyond a few dozen, this question becomes increasingly hard to answer, and this paper hence proposes a diagnostic for chain quality assessment in high dimensions.
One prerequisite for convergence is that the chain has sufficiently mixed and explored all the subvolumes of the probability distribution. This is implicitly a question about the geometric shape of the chain in high dimensions. This geometry contains valuable information about whether the chain correctly resolves the conditionals of the target distribution.
The most popular convergence diagnostics analyze marginals of the chain only. These include visual inspection of marginal scatter plots, the correlation length of the chain and the effective sample size (ESS) [21], Gelman-Rubin’s [18] and Hanson’s diagnostic [23]).
Restricting the analysis to marginals only loses information. For example, unexplored sub-volumes typically become invisible when projecting down onto a 2-dimensional marginal, and a convoluted trace of the chain in the full volume can look like a well-mixed chain in a 2-dimensional projection. In the following, we therefore train normalizing flows (NFs) to use the information in the conditional distributions on top of that in the marginals.
We utilize NFs to construct the posterior of samples from an MCMC chain. NFs assume the samples used to train its neural networks to be independent and identically distributed (iid), and a chain that is yet to converge contradicts this assumption. Thus a NF model built with samples falsely assuming iid will fail to accurately represent another chain from the same target distribution. Our code NFDiag harnesses this fact to render the lack of convergence in MCMC chains visible. It computes a new convergence statistic in high dimensions we have called NFD, given by Eq. 8, which is the main result of this paper.
We structure this work as follows. Further details about NF and the theoretical formulation that makes NFDiag possible are given in Sec. 2 and 3. We provide a brief user guide to NFDiag in Sec. 4. Sec. 5 demonstrates our method is universal and unbiased in up to 125 dimensions, and highlights its advantages in comparison with other common statistics. In Sec. 5.3, we test it on a presently relevant cosmological inference problem in 250 dimensions. In Sec. 6, we conclude.
2 Methodology
NFDiag relies on normalizing flows (NFs) to model the joint probability distribution of a (or part of a) chain of samples acquired from a Markov Chain Monte Carlo (MCMC) sampler. We provide a brief introduction to NFs in Sec. 2.1. Crucially, we outline the capabilities of NF models and how they relate to NFDiag in 2.2.
2.1 Normalizing Flows
NFs aim to represent an intractable probability distribution as a series of variable transformations of a known probability distribution. We denote the former as for , and the latter with for . Then, let be functions in the family of diffeomorphisms . NFs aim to establish a probability-preserving relation of the form
between the domains of and . Preservation of probability density requires that
where are representations of the intermediate variables of the transformations (with and ). The change of variables formula given by Eq. 2 allows the probability of any x to be uniquely calculated without , relying only on the Jacobian matrix and the probability . The complete mathematical derivation of NF is presented in [31].
While is required for above to hold, in practice, it might be impossible to find with a finite or small such that Eq. 2 remains computable in a reasonable amount of time. Thus realistically, Eqs. 1 and 2 are only approximately satisfied, with specifically selected from families of functions with high expressive flexibility. Let denote the hyperparameters of such a set of , and the resulting approximate representation of . are then optimized via minimizing a distance metric between and to ensure the approximation is as close to equality as possible.
Conventionally for NF models, the hyperparameters are represented as neural networks (NN), and the distance metric, or loss function, is the forward Kullback-Leibler (KL) divergence [28], given by
Here the constant term is the expectation under of ; since it does not vary as the NF model is trained, we drop it when minimizing .
2.2 Sensitivity to Sample Quality
In practice, the integral of Eq. (3) has to be calculated with a sample-based Monte Carlo estimator. The expectation value in the KL divergence of Eq. (3) is approximated by the Monte Carlo integral
which assumes that the set of samples are independently and identically drawn (iid) from the target distribution .
Crucially, if the samples are not iid, will no longer be an unbiased approximator of . Then minimizing will produce an NF model that is a biased approximation of [26], but a faithful fit to the imperfect MCMC samples, pretending they were iid. The resulting NF will hence include information on the imperfections of the MCMC chain.
Consequently, if a problematic MCMC chain is split into several subsections, and NF models are trained on each of these subsections, then the resulting NFs will all differ from each other. Each of these NFs will then assign a low probability to samples of other sub-sections of the chain.
In brief, for a bad chain, each NF will be a bad statistical model for samples from other sections of the chain, whereas a good chain will result in NFs that agree. The new MCMC convergence diagnostic we will detail upon in the following Sec. relies on this discrepancy. In practice, the direct comparison of an NF model to unseen samples is dependent on the exact and hyperparameters of the NF architecture. To drop this dependency, a normalization via training of several flows is necessary. These details will also be discussed in the following section.
3 NFDiag: MCMC Convergence using Normalizing Flows
An MCMC sampler builds up a chain of length of samples of the parameters generated from a posterior function conditioned on the data d given by . Often one runs several such chains, and we denote the th such MCMC chain as , where for chains. Each of these chains will separately satisfy that its number density of samples will be proportional to a probability density
Chain is considered converged when the density of samples is proportional to the target density over the entire domain of . If the chains are not converged, then these individual densities will differ from each other, , and this implies that they cannot be trusted to represent the target density .
Let and be two chains. To quantify whether they represent compatible distributions, we train an NF model on and compare it to such that the second chain serves as validation chain.
To do so, we evaluate the NF-based probabilities for for the samples in the two chains, and compute a distance between them. We detail upon this distance metric in Sec. 3.1. This distance measures whether an NF model trained on one chain assigns a large probability to the samples of another chain, which will be the case if the chains are good, and otherwise not.
If both and are converged to target, then and
for some threshold that depends on the chain length and act as due to Eq. 5.
If either are not converged, than , and due to the biases in as outlined in Sec. 2.2. Thus, computing the probability evaluations via the NF model, followed by the distance between them allows us to quantify the compatibility and convergence to target of the chains and .
3.1 Distance Metric for Convergence Assessment
For the distance metric , we adopt the Bhattacharyya distance [7] as implemented in OpenCV [9]. The advantage of this distance is that it is bounded to the interval , where the minimum is achieved for identical distributions. For two histograms and with bins, OpenCV implements this distance by
where the index runs over the bins of the histograms and are the mean counts. We illustrate below in Fig. 1, where we plot histograms of sample densities drawn from two Gamma distributions for .

Figure 1: Sample density histograms and for two Gamma distributions for . We outline the overlap region of the two histograms with dark purple. As the volume of the overlap region increases, decreases.
As such, we compute the distance , where are the binned probability evaluations . We discuss how NFDiag automatically optimizes binning in Appendix A.
Both binning and NNs are dependent on some hyperparameters, which could affect . One cannot ignore this dependency, as similar values of could then indicate different states of convergence across problems with different target distributions . To remove this dependency, we normalize in the following manner to reduce its sensitivity to hyperparameters of binning, the NF models and the shape of the target distribution.
We first join the two MCMC chains and used in training and validation respectively. We shuffle the positions of the samples in this combined chain such to destroy the correlations between successive samples. Then, we re-separate the shuffled combined chain into two random chains and such that the length of matches length of .
Then, we train a second NF model we name whose architecture and hyperparameters are identical to those of . We compute a second distance used in normalization. Then, the normalized diagnostic we call NFD is given by
This way, we succeed in dropping any variation in due to differences in training of the NF model, binning of the histograms, and original target distribution. The resulting statistic NFD is then such that corresponds to total convergence and to total lack of overlap in the number densities of the samples in the two chains.
A minor side effect of the division in Eq. (8) is that is possible when samples are iid due to variances in model fitting or computation. This means our convergence diagnostic can, due to noise, slightly exceed the value of unity in case of a perfect chain.
We provide a short user guide for this statistic in the following section, and demonstrate its performance in Section 5.
4 User Guide for NFDiag
NFDiag is our NF-based code that uses MCMC chains as input and computes a convergence diagnostic NFD for them. In this section, we detail on the code of NFDiag, and provide a guide of its features for users.
For the NFs, we use neural spline flows [12]: rational quadratic splines with knot points and derivatives predicted by NN. Normflows [37] provides both the masked coupling and the autoregressive neural spline flows. We acknowledge that the latter would be faster to train and evaluate for probabilities, but we have used the former for faster sampling for diagnostics. The user can swap NFDiag between the variants, and we have noticed no difference in results obtained from doing so.
A central aspect of NN-based research is the potential of overfitting [19]. To combat this, we utilize dropout [35], L2 regularization [27] and early stopping. A common approach is to terminate training as soon as the mean validation loss increases. However, there is evidence that this is an oversimplification of real NN training [32].
We implement a early stopping method that assigns a penalty for increases in the loss function and until a budget for the penalty is exceeded. To accurately compute the training losses, after every epoch and freezing the NN weights, the loss in Eq. 4 is reevaluated on the entire training chain in addition to the validation chain. Then, once the cumulative penalties exceed the budget, the training is stopped. The penalties and the budget are hyperparameters that control the trade-off between the generalization of the model and the training time and can be tuned by the user to adapt to their use case.
To run NFDiag for assessing the quality of their MCMC chains, the user needs to provide
- files for chains and , or alternatively only which the code then splits into and
- number of epochs to train NF models for
- snapshot frequency, which defines the epochs where NFD is computed and plots are produced.
NFDiag then will automatically:
- Assign to training and to validation. If only is provided, assign the first to training, and rest to validation.
- Train an NF model on
- At the snapshot epochs, save a copy of the model and the probability evaluations and .
- Once the NF model converges or the maximum number of epochs is reached, repeat the above 3 steps, but for the pair model which is trained instead on as defined in Sec. 3.1.
- Histogram the probability evaluations and for and compute NFD for every snapshot.
All hyperparameters of the models and NN training can also be specified by the user. We provide sensible values for these in Sec. 5 alongside our demonstrations of NFDiag.
5 Demonstrations of NFDiag
In this section, we demonstrate NFDiag across different experiments. In Sec. 5.1, we establish that NFD is a universal and unbiased indicator of multivariate convergence in up to 125 dimensions. Sec. 5.2 is dedicated to applying NFDiag to chains from various MC samplers.
Due to runtimes, it is difficult to systematically demonstrate reliable performance of NFDiag in higher dimensions than 125, even though we found good performance in all higher dimensional tests we performed. We hence demonstrate in Sec. 5.3, an application of NFDiag to chains of the weak lensing power spectrum in 250 dimensions. This demonstrates the science-readiness of NFDiag as the weak lensing power spectrum is a common approach to inferring parameters of the current cosmological models using large scale matter distribution in the universe.
| Hyperparameter | Value | Hyperparameter | Value |
|---|---|---|---|
| Flow layers | 3 | Batch size | 5k |
| NN layers | 3 | Spline knots | 20 |
| Neurons/layer | 512 | Dropout | 0.45 |
| Learning rate | Weight decay | 0.005 |
Table 1: Hyperparameters shared between all NF models and training regimens for the experiments in Sec. 5.
The hyperparameters common to all NF models are displayed in Table 1. We have independently verified that choosing different values will not significantly alter the results we present here and solely affect the point at which the NF models converge.
All experiments were performed on an Asus Zephyrus S GX701GWR with Intel Core i7-9750H CPU, 16.0 GB of RAM and an NVIDIA GeForce RTX 2070 GPU with 8GB of VRAM using Python 3.13.5 and PyTorch 2.7.1 with CUDA 11.8. They take around 2 to 20 minutes per repetition depending on the dimensionality.
5.1 Universality of NFD in the IID Limit
The most popular subclass of MCMC algorithms are so-called ‘universal’ samplers for which it can be shown that they correctly sample from a very wide class of target distributions. It is hence natural to ask whether NFD is also universally applicable to different distributions, or whether it will fail e.g. for multi-modal distributions.
For all distributions we tested, we found NFDiag to be of generic and stable performance. Moreover, as any unimodal and even multimodal multivariate probability distributions can be approximated as a sum of multivariate Gaussian distributions, one can expect universal stable performance of our diagnostic for any probability distribution if the NFD performs well for Gaussian Mixtures (GMs). To demonstrate that our diagnostic even handles multimodal distributions well, we here include into our demonstrations GM distributions in dimensions. For each, we create multimodal distributions consisting of Gaussian components with random mean vectors, covariance matrices and weights, and acquire iid samples as chains.
To establish NFD is unbiased, in each dimension, we generate iid chains from a multivariate Student’s t, and a matrix-variate Wishart distribution with . Since for a set of iid samples
one would expect the NFD to asymptotically approach unity with increasing if the test is truly unbiased. The results are given in Fig. 2, which indeed demonstrates the unbiasedness of our diagnostic across all test cases. Note that for the shorter chains, we reduce the batch size from the value in Table 1 to keep the number of batches constant.

Figure 2: Evaluating NFD for iid samples in increasing dimensions, and for several distributions. The error bars are standard deviations obtained from 5 repetitions. The multivariate Student’s t and matrix-variate Wishart distributions are indicated with triangles and circles respectively. With increasing , the NFD approaches 1, indicating that it is unbiased. The Gaussian Mixture (GM) chains indicated with crosses are all of . Since any probability distribution can be approximated through a GM, we conclude that the NFD is universally applicable to any target distribution as we see here that it performs reliably even for these multimodal distributions.
5.2 Comparisons with Other Convergence Statistics
In this section, we apply NFDiag to chains of samples acquired using various auto-correlated MC samplers and compare NFD to other statistics commonly used in assessment of convergence of MCMC chains.
First is the univariate [18] computed on the marginals of the multivariate chains, which aims to evaluate the stationarity of a chain via comparing the within-chain and between-chain variances. We adopt the split- from [39], defined as
where and are the between- and within-chain variances of a chain of length . [39] recommend to indicate marginal convergence. Rather than requiring each marginal to fall below this threshold, we consider our multivariate chains ‘converged wrt. ’ when the mean of the s is less than .
We also compare against multivariate effective sample size (mESS) proposed by [38], which extends the univariate formulation. Let be the sample covariance matrix of a -dimensional chain of length , and be the Monte Carlo error estimate for this chain. Then, the mESS is given by
Crucially, we use the Monte Carlo error estimator in [1] for greater accuracy in higher dimensions, which is a hybrid of initial sequence and batch-means estimators. Still, we notice the estimation for the correlation matrix of the mean to be dominated by noise regardless of choice of batch size. This leads to overestimates of mESS up to an order of magnitude in highly correlated chains in high number of dimensions. So, we also compute mESS using the true correlation matrix as the lowest bound. The recommendation of [39] is to aim for at least over an ensemble of chains. In this work, we consider a stricter to indicate a chain is ‘converged wrt. mESS’.
We sample chains of a multivariate Gaussian in dimensions, of a fixed length from three samplers to compute the above statistics and NFD on:
- Metropolis-Hastings (MH) sampler with a multivariate Gaussian proposal distribution, available through emcee [14, 22]. Following [33], we set the variances of the proposal distribution to for where the last value provides the lowest theoretical auto-correlation in a given number of dimensions. The preceding smaller values scale the proposed step sizes down, resulting in greater auto-correlation between the samples.
- Metropolis-adjusted Langevin algorithm (MALA) sampler [5] in PINTS [10]. MALA proposes next states using the local gradient information, but the proposed jumps can be scaled with an hyperparameter. We run MALA with to get chains with various auto-correlation lengths akin to the MHMC.
- Our in-house Hamiltonian Monte Carlo (HMC) sampler [34, 29] with automated hyperparameter tuning conditioned on a target acceptance rate , for . The higher target acceptance rates correspond to smaller proposed jump trajectories and vice versa.
Fig. 3 shows the comparison between NFD, and mESS. Since the and mESS adhere to the same general trend, we base our discussion mainly on the latter. Overall, for all we have tested, the NFD of a“ chain increases with mESS. This indicates that the statistics share a common sensitivity to quality of the chains, and serves to increase confidence in the former’s ability to assess convergence accurately. This can naturally also be extended to comparisons.
The advantage of NFD comes from how it scales across in comparison to mESS or . Generally, for a fixed value of mESS, the NFD decreases with , indicating that the higher dimensional chains are much further from iid (and thus convergence to target) than their lower dimensional counterparts. In turn, a dimension agnostic threshold such as or taken as a strong indicator of a well converged chain in a small number of dimensions might not extrapolate to the same degree of convergence in higher.


Figure 3: NFD of chains from different samplers, vs. mean and mESS. The points indicate the mESS with the true correlation matrix, while the right-pointing error bars are the MCSE estimator with a batch size of . The dashed lines are provided to navigate the plot by connecting points of the same dimension. The vertical blue region corresponds to chains of allegedly identical convergence quality as assessed by the mESS and . Going downwards within these blue regions, one sees that these statistics become insensitive in higher dimensions, whereas NFD continues to resolve difference in convergence quality. As such, we see that mESS and incorrectly indicated convergence high dimensions.
For example, all of the chains in the region around mESS and highlighted with blue in Fig. 3 are considered converged wrt. both mESS and . While the assessment wrt. NFD is in agreement for , note that as the dimensionality of a distribution increases, the conditional information lost by marginalization grows monotonically. While mESS and increasingly fail to capture this information, NFD is built to be highly sensitive to it: hence at , the NFDs are significantly lower when compared to the former . In other words, where other diagnostics return over-confident convergence assessments in high dimensions, which simply originate from lost sensitivity, NFD continues to display dynamic behavior in large dimensions, and succeeds in assessing quality of convergence over a larger range of dimensions.
To underline visually that these significantly lower NFDs indeed pick up information that the other diagnostics were insensitive to, we plot in Fig. 4 marginals of a select 125-d chains mentioned in addition to iid samples for comparison. From top to bottom: iid samples from this distribution, followed by the MALA , and lastly the MH chain with . All of these chains are considered converged wrt. mESS and , even though the human eye is able to see differences in chain quality: the bottom two chains clearly show heavier and spherically asymmetric tails, which would further be exacerbated when considering the full multivariate geometry of the chain. While this is completely missed by the mESS and , NFD accurately flags the problem. This visual impression aligns with the finding that with respect to NFD, only the MALA chain is converged, while the others fall far away from the ideal .
The decrease in NFD in the transition from the best-performing MALA chains to the worst-performing HMC ones is explained by how NFD assesses convergence: similarity to iid samples from that same distribution. If the HMC sampler accepts a new position as the next sample, the long trajectory lengths afforded by the multi-step leapfrog integration ensures low correlation with the previous position. In comparison with algorithms that cannot execute such long jumps, chains acquired from the HMC thus have significantly higher mESS even if they accept new positions at a similar rate. However, at , even an HMC chain will be comprised of a majority of duplicate states. As it is almost impossible for iid samples generated from a (non Dirac-delta) probability distribution to be superimposed, the NFDs of these chains are instead comparable to others with lower mESS.
Taking all of the iid benchmarks and the tests on various chains from the samplers described in this section, we propose a quality cut of to consider an MCMC chain adequately converged wrt. NFD. Thus in practice, any value significantly smaller than this should be taken as strong indicator for a lack of multivariate convergence.

Figure 4: Marginal plot of, in order, iid samples, MALA chains with and MH chain with , together with their mESS, and NFD. The points are colored from orange to black in the sampling order of the chain. All chains are considered converged by mESS and , but visually inspecting the marginals reveals convergence problems in the latter two, which would be exacerbated in the full multivariate geometry. NFD is very sensitive to this, and accurately flags the chains as not converged.
5.3 250-dimensional Cosmology Example
The primary driver for the development of NFDiag is to provide a statistic that is sensitive and accurate in convergence assessment in high dimensional and topologically complex problems encountered in frontier scientific inference problems. In this section, we demonstrate how NFD can be utilized to ensure the quality of chains in weak lensing power spectrum inference.
We replicate the analysis in [29], albeit in a smaller scale: we limit ourselves to 1 tomographic bin, and generate an all-sky shear map with an -range of . The resulting joint posterior of spherical harmonic coefficients and power spectra is in dimensions. However, in the weak lensing regime, shear is symmetric and curl-free [36, 2]: therefore the majority cosmological signal is embedded in the 250-dimensional combined power spectrum of and which we call . While our in-house HMC samples from the joint posterior in dimensions, we are primarily interested in the quality of the 250-dimensional samples for the scientific analysis.
This example showcases another unique strength of NFDiag. The probability values of samples generated by the HMC are for the joint posterior of and , and there is no known analytic integral to marginalize out the contribution of the former to obtain probability values for just the , which could be used to further inform convergence decisions.
NFDiag builds precisely that distribution and can be used to assess convergence of not only full chains, but also multi-dimensional marginals of chains. This is vital in scientific inference precisely: it is common to infer nuisance parameters required by the complex Bayesian hierarchical models alongside parameters of scientific interest in scenarios where the marginal posterior distribution might not be analytically available or highly costly to evaluate numerically.
The chain of length we sample from this posterior is converged wrt. all of the following widely adopted statistics:
- bulk ESS [39] btw. 1000-10000 per ,
- [18] less than across all ,
- fraction of missing information [6] FMI ,
- Hanson’s diagnostic [23] btw. for all .
We provide plots for all in Appendix B.


Figure 5: Histograms of the training loss and validation loss at Epoch for the NF model trained on (Top) samples and (Bottom) for thinned samples of from a longer chain of length M from our HMC sampler.
The is of this chain is significantly less than established in Sec. 5.2. Fig. 5 plots the histograms of training loss and validation loss at model convergence and is automatically generated by NFDiag. The top panel corresponds to the aforementioned chain and displays the NFD, and . The separation between the two histograms directly corresponds to the geometric separation between the halves of the chain. In an iid sample or a well converged chain, one would expect near-perfect overlap of these histograms.
We resume sampling until we acquire a total of M samples, and thin the chain to samples to have an equivalent analysis (NFDiag results with the unthinned M chain are in Appendix C). As expected, this extended and thinned chain has : similar to the multivariate Gaussian in Sec. 5.2. The bottom panel of Fig. 5 displays and histograms for this chain, and the overlap of the two histograms has improved considerably when compared to the former chain.
The scientific inference problem in this Sec. presents a high dimensional MCMC chain that, by various convergence tests, is sufficiently converged. Our convergence assessment with NFDiag utilizing the entirety of the geometric information available in the chain however indicates that the chain is yet to adequately converge. We posit such a wholistic analysis is crucial. Basing a scientific conclusion on such an MCMC chain would yield biased results, as there is no guarantee the sampler has explored the full posterior volume. Resuming the sampler for a significantly longer time generates more effective samples, and improves NFD, increasing the confidence in the convergence of the chain.
6 Conclusions
Accurately assessing the convergence of MCMC chains is central to avoiding biases in Bayesian inference. Only inspecting marginal distributions of samples can lead to overconfident assessment of convergence, as all information in the joint distribution is ignored. This is particularly problematic in high dimensions.
Our NFs based algorithm NFDiag determines the convergence of high dimensional chains by modeling the posterior of samples from the chain itself. This NF model is then used to evaluate the consistency of the rest of the chain via measuring the degree with which it fails to satisfy the assumption that the samples are iid distributed.
We demonstrate that the NFD is a generic and unbiased metric for summarizing the degree of convergence across all dimensions. In Sec. 5.2, we test the NFD on chains obtained from multiple samplers in up to dimensions.
Finally, we demonstrate NFDiag in dimensions in a relevant Bayesian scientific inference problem, that of cosmological parameter inference from the weak lensing shear field, in Sec. 5.3. We show how NFDiag can spot chains that are not yet fully converged even when the conventional convergence statistics would indicate the contrary.
Acknowledgements
We would like to thank Alan F. Heavens, Andrew H. Jaffe, Lorne Whiteway, Arthur Loureiro and Javier Silva Lafaurie for their help with the weak lensing inference problem in this work and their insightful discussions and comments.
References
[1] A. Banerjee and D. Vats (2024) Efficient Multivariate Initial Sequence Estimators for MCMC. arXiv e-prints, pp. arXiv:2406.15874. External Links: Document, 2406.15874 Cited by: §5.2.
[2] M. Bartelmann and P. Schneider (2001) Weak gravitational lensing. Phys. Rep. 340 (4-5), pp. 291–472. External Links: Document, astro-ph/9912508 Cited by: §5.3.
[3] T. Bayes (1763) LII. an essay towards solving a problem in the doctrine of chances. by the late rev. mr. bayes, f. r. s. communicated by mr. price, in a letter to john canton, a. m. f. r. s. Philosophical Transactions (53), pp. 370–418. External Links: ISSN 0260-7085, Document, Link, https://royalsocietypublishing.org/rstl/article-pdf/doi/10.1098/rstl.1763.0053/1458453/rstl.1763.0053.pdf Cited by: §1.
[4] A. Bertazzi and J. Bierkens (2022) Adaptive schemes for piecewise deterministic Monte Carlo algorithms. Bernoulli 28 (4), pp. 2404 – 2430. External Links: Document, Link Cited by: §1.
[5] J. Besag (1994) Discussion: Markov Chains for Exploring Posterior Distributions. The Annals of Statistics 22 (4), pp. 1734 – 1741. External Links: Document, Link Cited by: item –.
[6] M. Betancourt (2016) Diagnosing Suboptimal Cotangent Disintegrations in Hamiltonian Monte Carlo. arXiv e-prints, pp. arXiv:1604.00695. External Links: Document, 1604.00695 Cited by: Appendix B, item –.
[7] A. Bhattacharyya (1943) On a measure of divergence between two statistical populations defined by their probability distributions. Bull. Calcutta Math. Soc. 35, pp. 99–109. External Links: ISSN 0008-0659, MathReview (R. L. Anderson) Cited by: §3.1.
[8] Birgé, Lucien and Rozenholc, Yves (2006) How many bins should be put in a regular histogram. ESAIM: PS 10, pp. 24–45. External Links: Document, Link Cited by: Appendix A.
[9] G. Bradski (2000) The OpenCV Library. Dr. Dobb’s Journal of Software Tools. Cited by: §3.1.
[10] M. Clerx, M. Robinson, B. Lambert, C. L. Lei, S. Ghosh, G. R. Mirams, and D. J. Gavaghan (2019) Probabilistic inference on noisy time series (PINTS). Journal of Open Research Software 7 (1), pp. 23. External Links: Document Cited by: item –.
[11] S. Duane, A. D. Kennedy, B. J. Pendleton, and D. Roweth (1987) Hybrid Monte Carlo. Physics Letters B 195 (2), pp. 216–222. External Links: Document Cited by: §1.
[12] C. Durkan, A. Bekasov, I. Murray, and G. Papamakarios (2019) Neural Spline Flows. arXiv e-prints, pp. arXiv:1906.04032. External Links: Document, 1906.04032 Cited by: §4.
[13] S. E. Fienberg (2006) When did Bayesian inference become ”Bayesian”?. Bayesian Analysis 1 (1), pp. 1 – 40. External Links: Document, Link Cited by: §1.
[14] D. Foreman-Mackey, D. W. Hogg, D. Lang, and J. Goodman (2013) emcee: The MCMC Hammer. PASP 125 (925), pp. 306. External Links: Document, 1202.3665 Cited by: item –.
[15] D. A. Freedman and P. Diaconis (1981) On the histogram as a density estimator:l2 theory. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete 57, pp. 453–476. Cited by: Appendix A.
[16] A. E. Gelfand and A. F. M. Smith (1990) Sampling-based approaches to calculating marginal densities. Journal of the American Statistical Association 85 (410), pp. 398–409. External Links: Document Cited by: §1.
[17] A. Gelman, J. B. Carlin, H. S. Stern, D. B. Dunson, A. Vehtari, and D. B. Rubin (2013) Bayesian data analysis. Third edition, Chapman and Hall/CRC Texts in Statistical Science Series, CRC, Boca Raton, Florida. External Links: ISBN 9781439840955 1439840954, Link Cited by: §1.
[18] A. Gelman and D. B. Rubin (1992) Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7 (4), pp. 457 – 472. External Links: Document, Link Cited by: Appendix B, §1, item –, §5.2.
[19] S. Geman, E. Bienenstock, and R. Doursat (1992) Neural networks and the bias/variance dilemma. Neural Computation 4, pp. 1–58. External Links: Document Cited by: §4.
[20] S. Geman and D. Geman (1984) Stochastic relaxation, gibbs distributions, and the bayesian restoration of images. IEEE Transactions on Pattern Analysis and Machine Intelligence PAMI-6 (6), pp. 721–741. External Links: Document Cited by: §1.
[21] C. J. Geyer (1992) Practical Markov Chain Monte Carlo. Statistical Science 7 (4), pp. 473 – 483. External Links: Document, Link Cited by: Appendix B, §1.
[22] J. Goodman and J. Weare (2010) Ensemble samplers with affine invariance. Communications in Applied Mathematics and Computational Science 5, pp. . External Links: Document Cited by: §1, item –.
[23] K. M. Hanson (2001) Markov chain Monte Carlo posterior sampling with the Hamiltonian method. In Medical Imaging 2001: Image Processing, M. Sonka and K. M. Hanson (Eds.), , Vol. 4322, pp. 456 – 467. External Links: Document, Link Cited by: Appendix B, §1, item –.
[24] W. K. Hastings (1970) Monte carlo sampling methods using markov chains and their applications. Biometrika 57 (1), pp. 97–109. External Links: ISSN 00063444, 14643510, Link Cited by: §1.
[25] M. D. Hoffman and A. Gelman (2014) The no-u-turn sampler: adaptively setting path lengths in hamiltonian monte carlo. Journal of Machine Learning Research 15 (1), pp. 1593–1623. Cited by: §1.
[26] M. Kirchler, C. Lippert, and M. Kloft (2022) Training Normalizing Flows from Dependent Data. arXiv e-prints, pp. arXiv:2209.14933. External Links: Document, 2209.14933 Cited by: §2.2.
[27] A. Krogh and J. A. Hertz (1991) A simple weight decay can improve generalization. In Proceedings of the 5th International Conference on Neural Information Processing Systems, NIPS’91, San Francisco, CA, USA, pp. 950–957. External Links: ISBN 1558602224 Cited by: §4.
[28] S. Kullback and R. A. Leibler (1951) On information and sufficiency. The Annals of Mathematical Statistics 22 (1), pp. 79–86. External Links: ISSN 00034851, Link Cited by: §2.1.
[29] A. Loureiro, L. Whiteway, E. Sellentin, J. Silva Lafaurie, A. H. Jaffe, and A. F. Heavens (2023) Almanac: Weak Lensing power spectra and map inference on the masked sphere. The Open Journal of Astrophysics 6, pp. 6. External Links: Document, 2210.13260 Cited by: item –, §5.3.
[30] N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller, and E. Teller (1953) Equation of state calculations by fast computing machines. J. Chem. Phys. 21, pp. 1087–1092. External Links: Document Cited by: §1.
[31] G. Papamakarios, E. Nalisnick, D. Jimenez Rezende, S. Mohamed, and B. Lakshminarayanan (2019) Normalizing Flows for Probabilistic Modeling and Inference. arXiv e-prints, pp. arXiv:1912.02762. External Links: Document, 1912.02762 Cited by: §2.1, footnote 2.
[32] L. Prechelt (2000) Early stopping - but when?. Lecture Notes in Computer Science, pp. . External Links: ISBN 978-3-540-65311-0, Document Cited by: §4.
[33] G. O. Roberts, A. Gelman, and W. R. Gilks (1997) Weak convergence and optimal scaling of random walk Metropolis algorithms. The Annals of Applied Probability 7 (1), pp. 110 – 120. External Links: Document, Link Cited by: item –.
[34] E. Sellentin, A. Loureiro, L. Whiteway, J. S. Lafaurie, S. T. Balan, M. Olamaie, A. H. Jaffe, and A. F. Heavens (2023) Almanac: MCMC-based signal extraction of power spectra and maps on the sphere. The Open Journal of Astrophysics 6, pp. 31. External Links: Document, 2305.16134 Cited by: item –.
[35] N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, and R. Salakhutdinov (2014) Dropout: a simple way to prevent neural networks from overfitting. Journal of Machine Learning Research 15 (56), pp. 1929–1958. External Links: Link Cited by: §4.
[36] A. Stebbins (1996) Weak Lensing On the Celestial Sphere. arXiv e-prints, pp. astro–ph/9609149. External Links: Document, astro-ph/9609149 Cited by: §5.3.
[37] V. Stimper, D. Liu, A. Campbell, V. Berenz, L. Ryll, B. Schölkopf, and J. M. Hernández-Lobato (2023) Normflows: a pytorch package for normalizing flows. Journal of Open Source Software 8 (86), pp. 5361. External Links: Document, Link Cited by: §4.
[38] D. Vats and C. Knudson (2018) Revisiting the Gelman-Rubin Diagnostic. arXiv e-prints, pp. arXiv:1812.09384. External Links: Document, 1812.09384 Cited by: §5.2.
[39] A. Vehtari, A. Gelman, D. Simpson, B. Carpenter, and P. Bürkner (2021) Rank-normalization, folding, and localization: an improved for assessing convergence of mcmc. Bayesian Analysis 16 (2), pp. 667–718. External Links: Document Cited by: Appendix B, item –, §5.2, §5.2, §5.2.
Appendix A B and Automated Binning
The major variable that influences the distance is the number of histogram bins . Choosing too small would effectively smooth out over the differences in the histograms of comparison, while picking too large would cause to be dominated by noise.
NFDiag therefore computes the optimal number of bins using the Freedman-Diaconis Rule [15] in cases where , and with the method in [8] when the number of samples is small. Alternatively, the user is able to specify their own desired to linearly histogram the log probability evaluations.
In cases where strong outliers are present, if the histogram bins are prescribed between the minimal and maximal log probability values, it is highly probable that many of the bins will be under-full or simply empty due to the unrepresentative binning range. This will translate to the effective number of bins in the distance calculation to decrease and bias to reporting more similar distributions.


Figure 6: Effective sample size and for the sample chain.
To counteract this technicality, NFDiag removes the bottom and top quantiles prior to histogramming.
Additionally, NFDiag can be asked to remove under-full bins from the tails post histogram computation, where under-full is defined as a user prescribed fraction of the highest density bin. While this additionally can help cut outlier behavior such as inadvertently included burn-in samples or spurious walkers, we caution users that removing such bins will result in NFDiag signalling improved convergence, as the user removed a sample pathology by hand. We hence recommend users only rely on this when the source of the under-full bins can be identified with confidence.
Appendix B Conventional Convergence Diagnostics
In this section we provide additional plots for the convergence statistics that were quoted for the scientific inference example in Section 5.3. The effective sample size (ESS) [21, 39] and Gelman-Rubin [18] are given in Fig. 6, and the Hanson’s diagnostic [23] and FMI [6] are given in Fig. 7.


Figure 7: Hanson’s diagnostic and FMI for the sample chain.
Appendix C NFDiag of the Unthinned 1M Chain
This section is dedicated to evaluating the convergence of the unthinned chain of M samples in addition to the thinned version presented in Section 5.3. Since we keep the batch size constant between the two analyses, the NF model in this section essentially updates a factor of times more per training epoch, and therefore converges rapidly and stably. The results are presented below in Fig. 8.

Figure 8: Histograms of the training loss and validation loss at Epoch for the NF model trained on M samples from our HMC sampler.