Title: L-C2ST: Local Diagnostics for Posterior Approximations in Simulation-Based Inference
Venue: NeurIPS 2023
Accepted: yes
Keywords: machine learning

calibration

simulation-based inference

neuroscience

normalizing flows

classifier two-sample tests
Abstract: Many recent works in simulation-based inference  (SBI) rely on deep generative models to approximate complex, high-dimensional posterior distributions. However, evaluating whether or not these approximations can be trusted remains a challenge. Most approaches evaluate the posterior estimator only in expectation  over the observation space. This limits their interpretability and is not sufficient to identify for which observations the approximation can be trusted or should be improved. Building upon the well-known classifier two-sample test (C2ST), we introduce $\ell$-C2ST, a new method that allows for a local evaluation of the posterior estimator at any given observation. It offers theoretically grounded and easy to interpret -- e.g. graphical -- diagnostics, and unlike C2ST, does not require access to samples from the true posterior. In the case of normalizing flow-based posterior estimators, $\ell$-C2ST can be specialized to offer better statistical power, while being computationally more efficient. On standard SBI benchmarks, $\ell$-C2ST  provides comparable results to C2ST and outperforms alternative local approaches such as coverage tests based on highest predictive density (HPD). We further highlight the importance of local evaluation and the benefit of interpretability of $\ell$-C2ST on a challenging application from computational neuroscience.

L-C2ST: Local Diagnostics for Posterior Approximations in Simulation-Based Inference

Abstract

Many recent works in simulation-based inference (SBI) rely on deep generative models to approximate complex, high-dimensional posterior distributions. However, evaluating whether or not these approximations can be trusted remains a challenge. Most approaches evaluate the posterior estimator only in expectation over the observation space. This limits their interpretability and is not sufficient to identify for which observations the approximation can be trusted or should be improved. Building upon the well-known classifier two-sample test (C2ST), we introduce ℓ -C2ST, a new method that allows for a local evaluation of the posterior estimator at any given observation. It offers theoretically grounded and easy to interpret - e.g. graphical - diagnostics, and unlike C2ST, does not require access to samples from the true posterior. In the case of normalizing flow-based posterior estimators, ℓ -C2ST can be specialized to offer better statistical power, while being computationally more efficient. On standard SBI benchmarks, ℓ -C2ST provides comparable results to C2ST and outperforms alternative local approaches such as coverage tests based on highest predictive density (HPD). We further highlight the importance of local evaluation and the benefit of interpretability of ℓ -C2ST on a challenging application from computational neuroscience.

1 Introduction

Expressive simulators are at the core of modern experimental science, enabling the exploration of rare or challenging-to-measure events in complex systems across various fields such as population genetics [43], astrophysics [7], cosmology [32], and neuroscience [28, 16, 1, 20]. These simulators implicitly encode the intractable likelihood function p ( x | θ ) of the underlying mechanistic model, where θ represents a set of relevant parameters and x ∼ Simulator( θ ) is the corresponding realistic observation. The main objective is to infer the parameters associated with a given observation using the simulator's posterior distribution p ( θ | x ) [4]. However, classical methods for sampling posterior distributions, such as MCMC [41] and variational inference [40], rely on the explicit evaluation of the model-likelihood, which is not possible when working with most modern simulators.

Simulation-based inference (SBI) [4] addresses this problem by estimating the posterior distribution on simulated data from the joint distribution. This can be done after choosing a prior distribution

p ( θ ) over the parameter space and using the identity p ( θ, x ) = p ( x | θ ) p ( θ ) . In light of recent developments in the literature on deep generative models, different families of algorithms have been proposed to approximate posterior distributions in SBI [4]. Certain works use normalizing flows [37] to directly learn the posterior density function (neural posterior estimation, NPE [18]) or aim for the likelihood (neural likelihood estimation, NLE [36]). Other approaches reframe the problem in terms of a classification task and aim for likelihood ratios (neural ratio estimation, NRE [22]). However, appropriate validation remains a challenge for all these paradigms, and principled statistical approaches are still needed before SBI can become a trustworthy technology for experimental science.

This topic has been the goal of many recent studies. For instance, certain proposals aim at improving the posterior estimation by preventing over-confidence [23] or addressing model misspecification [14] to ensure conservative [8] and more robust posterior estimators [46, 27]. Another approach is the development of a SBI benchmark [31] for comparing and validating different algorithms on many standard tasks. While various validation metrics exist, Lueckmann et al. [31] show that, overall, classifier two sample tests (C2ST) [30] are currently the most powerful and flexible approach. Based on standard methods for binary classification, they can scale to high-dimensions as well as handle non-Euclidean data spaces [26, 34]. Typical use-cases include tests for statistical independence and the evaluation of sample quality for generative models [30]. Implicitly, C2ST is used in algorithms such as noise contrastive estimation [19] and generative adversarial networks [17], or to estimate likelihood-to-evidence ratios [22]. To be applied in SBI settings, however, C2ST requires access to samples from the true target posterior distribution, which renders it useless in practice. Simulationbased calibration (SBC) [42] bypasses this issue by only requiring samples from the joint distribution. Implemented in standard packages of the field ( sbi [44], Stan [2]), it has become the go-to validation method for SBI [31, 23] and has been further studied in recent works [33, 5, 15]. Coverage tests based on the highest predictive density (HPD) as used in [23, 8], can be seen as a variant of SBC that are particularly well adapted to multivariate data distribution.

Nevertheless, a big limitation of current SBI diagnostics remains: they only evaluate the quality of the posterior approximation globally (in expectation) over the observation space and fail to give any insight of its local behavior. This hinders interpretability and can lead to false conclusions on the validity of the estimator [48, 29]. There have been attempts to make existing methods local, such as local -HPD [48] or local -multi-PIT [29], but they depend on many hyper-parameters and are computationally too expensive to be used in practice. In this work, we present ℓ -C2ST, a new local validation procedure based on C2ST that can be used to evaluate the quality of SBI posterior approximations for any given observation, without using any data from the target posterior distribution. ℓ -C2ST comes with necessary, and sufficient, conditions for the local validity of multivariate posteriors and is particularly computationally efficient when applied to validate NPE with normalizing flows, as often done in SBI literature [7, 16, 27, 46, 6, 45, 24]. Furthermore, ℓ -C2ST offers graphical tools for analysing the inconsistency of posterior approximations, showing in which regions of the observation space the estimator should be improved and how to act upon, e.g. signs of positive / negative bias, signs of over / under dispersion, etc.

In what follows, we first introduce the SBI framework and review the basics of C2ST. Then, we detail the ℓ -C2ST method and prove asymptotic theoretical guarantees. Finally, we report empirical results on two SBI benchmark examples to analyze the performance of ℓ -C2ST and a non-trivial neuroscience use-case that showcases the need of a local validation method.

2 Validating posterior approximations with classifiers

Consider a model with parameters θ ∈ R m and observations x ∈ R d obtained via a simulator. In what follows, we will always assume the typical simulation-based inference setting , meaning that the likelihood function p ( x | θ ) of the model cannot be easily evaluated. Given a prior distribution p ( θ ) , it is possible to generate samples from the joint pdf p ( θ, x ) as per:

Let N s be a fixed simulation budget and { (Θ n , X n ) } N s n =1 = D train ∪ D cal with D train ∩ D cal = ∅ . The data from D train are used to train an amortized 2 approximation q ( θ | x ) ≈ p ( θ | x ) , e.g. via NPE [18], and those from D cal to diagnose its local consistency [48].

Definition 1 (Local consistency) . A conditional density estimator q is said to be locally consistent at x o with the true posterior density p if, and only if, the following null hypothesis holds:

We can reformulate H 0 ( x o ) as a binary classification problem by partitioning the parameter space into two balanced classes: one for samples from the approximation ( C = 0 ) and one for samples from the true posterior ( C = 1 ), as in

for which the optimal Bayes classifier [21] is f ⋆ x o ( θ ) = argmax { 1 -d ⋆ x o ( θ ) , d ⋆ x o ( θ ) } with

It is a standard result [30, 26] to relate (2) with (3) as per

When the classes are non-separable, the optimal Bayes classifier will be unable to make a decision and we can assume that it behaves as a Bernoulli random variable [30].

2.1 Classifier Two-Sample Test (C2ST)

The original version of C2ST [30] uses (5) to define a test statistic for H 0 ( x o ) based on the accuracy of a classifier f x o trained on a dataset defined as

The classifier accuracy is then empirically estimated over 2 N v samples ( N v samples in each class) from a held-out validation dataset D v generated in the same way as D :

Theorem 1 (Local consistency and classification accuracy) . If f x o is Bayes optimal 3 and N v →∞ , then ˆ t Acc ( f x o ) = 1 / 2 is a necessary and sufficient condition for the local consistency of q at x o .

See Appendix A.1 for a proof. The intuition is that, under the null hypothesis H 0 ( x o ) , it is impossible for the optimal classifier to distinguish between the two data classes, and its accuracy will remain at chance-level [30]. In the context of SBI, C2ST has been used to benchmark a variety of different procedures on toy examples where the true posterior is known and can be sampled [31]. This is why we call this procedure an oracle C2ST, since it uses information that is not available in practice.

Regression C2ST. Kim et al. [26] argues that the usual C2ST based on the classifier's accuracy may lack statistical power because of the 'binarization' of the posterior class probabilities. They propose to instead use probabilistic classifiers (e.g. logistic regression) of the form

and define the test statistics in terms of the predicted class probabilities d x o instead of the predicted class labels. The test statistic is then the mean squared distance between the estimated class posterior probability and one half:

Theorem 2 (Local consistency and regression) . If f x o is Bayes optimal and N v → ∞ , then ˆ t MSE ( f x o ) = 0 is a necessary and sufficient condition for the local consistency of q at x o .

See Appendix A.2 for a proof. The numerical illustrations in Kim et al. [26] give empirical evidence that Regression C2ST has superior statistical power as compared to its accuracy-based counterpart, particularly for high-dimensional data spaces. Furthermore, it offers tools for interpretation and visualization: evaluating the predicted class probabilities d x o ( θ ) for any θ ∈ R m informs the regions where the classifier is more (or less) confident about its choice [30, 26].

3 ℓ -C2ST: Local Classifier Two-Sample Tests

The oracle C2ST framework is not applicable in practical SBI settings, since it requires access to samples from the true posterior distribution to (1) train a classifier and (2) evaluate its performance in discriminating data from q and p . This section presents a new method called local C2ST ( ℓ -C2ST) capable of evaluating the local consistency of a posterior approximation requiring data only from the joint pdf p ( θ, x ) which can be easily sampled as per (1).

(1) Train the classifier. We define a modified version of the classification framework (3) with:

The optimal Bayes classifier is now f ⋆ ( θ, x ) = argmax { 1 -d ⋆ ( θ, x ) , d ⋆ ( θ, x ) } with

where one can notice the direct relation with the Bayes classifier for (3). Therefore, using data sampled as in (10), it is possible to train a classifier f ( θ, x ) and write f x o ( θ ) = f ( θ, x o ) for each x o . See Algorithm 1 for details on the implementation of this procedure.

(2) Evaluate the classifier. Define a new test statistic that evaluates the MSE-statistic for a classifier f and its associated predicted probabilities d using data samples from only the class associated to the posterior approximation ( C = 0 ):

Theorem 3 (Local consistency and single class evaluation) . If f is Bayes optimal and N v → ∞ , then ˆ t MSE 0 ( f, x o ) = 0 is a necessary and sufficient condition for the local consistency of q at x o .

Proof. Let d be an estimator of P ( C = 1 | Θ , X ) and f = I ( d > 0 . 5) . Suppose that f = f ⋆ is Bayes optimal and let x o be a fixed observation. We have that

Because of the squared term in the integral and q being a p.d.f., we have that

This new statistical test can thus be used to assess the local consistency of posterior approximation q without using any sample from the true posterior distribution p , but only from the joint pdf. Furthermore, it is amortized, so a single classifier is trained for (10) that can then be used for any choice of conditioning observation x o . This is not the case in the usual oracle C2ST framework.

0.0

0.5

1.0

1.5

0.5

1.0

Optimal Bayes (statistics)

t

0

t

Acc

0

t

Acc

(+0.5)

0.0

0.5

1.0

1.5

2

0.0

0.5

1.0

QDA-C2ST (power)

t

MSE

t

MSE0

2

Figure 1: Results for the C2ST framework when p = N (0 , I 2 ) and q = N (0 , σ 2 I 2 ) . Left panel portrays the test statistics for the optimal Bayes classifier and the right panel shows the test's empirical power with QDA. Single-class accuracy test ( ˆ t Acc 0 ) fails to detect when p = q but ˆ t MSE 0 behaves correctly.

̸

̸

includes the results for a one-class test statistic based on accuracy values ( ˆ t Acc 0 ) which, as opposed to ˆ t MSE 0 , has no guarantees for being a necessary and sufficient condition for local consistency. Not surprisingly, it fails to reject the null hypothesis for various choices of σ .

The assumptions of Theorem 3 are never met in practice: datasets are finite and one rarely knows which type of classifier is optimal for a given problem. Therefore, the values of ˆ t MSE 0 in the null hypothesis ( p = q ) tend to fluctuate around one-half, and it is essential to determine a threshold for deciding whether or not H 0 ( x o ) should be rejected. In ℓ -C2ST, these threshold values are obtained via a permutation procedure [13] described in Algorithm 1. This yields N H estimates of the test statistic under the null hypothesis and can be used to calculate p -values for any given α significance level as described in Algorithm 2. These estimates can also be used to form graphical summaries known as PP-plots, which display the empirical CDF of the probability predictions versus the nominal probability level. These plots show how the predicted class probability d ( x o ) deviates from its theoretical value under the null hypothesis (i.e. one half) as well as (1 -α ) confidence regions; see Algorithm B.1 available in the appendix for more details and Figure 4 for an example.

3.1 The case of normalizing flows

The ℓ -C2ST framework can be further improved when the posterior approximation q is a conditional normalizing flow [37], which we denote q ϕ . Given a Gaussian base distribution u ( z ) = N (0 , I m ) and a bijective transform T ϕ ( · ; x ) with Jacobian J T ϕ ( · ; x ) we have

In other words, normalizing flows (NF) are invertible neural networks that define a map between a latent space where data follows a Gaussian distribution and the parameter space containing complex posterior distributions. This allows for both efficient sampling and density evaluation:

Our main observation is that the inverse transform T -1 ϕ can also be used to characterize the local consistency of the conditional normalizing flow in its latent space, yielding a much simpler and computationally less expensive statistical test for posterior local consistency.

Theorem 4 (Local consistency and normalizing flows) . Given a posterior approximation q ϕ based on a normalizing flow, its local consistency at x o can be characterized as follows:

Proof. Let Θ ∼ p ( θ | x o ) . Following (14), we have that Θ ∼ q ϕ ( θ | x o ) if, and only if, Θ = T ϕ ( Z ; x o ) with Z ∼ N (0 , I m ) . Applying the inverse transformation of the flow gives us T -1 ϕ (Θ; x o ) = T -1 ϕ ( T ϕ ( Z ; x o ); x o ) = Z ∼ N (0 , I m ) , which concludes the proof.

Based on Theorem 4 we propose a modified version of our statistical test named ℓ -C2ST-NF. The new null hypothesis associated with the consistency of the posterior approximation q ϕ at x o is

which leads to a new binary classification framework

Algorithm 3 describes how to sample data from each class and train a classifier to discriminate them. The classifier is then evaluated on N v samples Z n ∼ N (0 , I m ) which are independent of x o .

A remarkable feature of ℓ -C2ST-NF is that calculating the test statistics under the null hypothesis is considerably faster than for ℓ -C2ST. In fact, for each null trial h = 1 , . . . , N H we use the dataset D cal only for recovering the samples X n and then independently sample new data Z n ∼ N (0 , I m ) . As such, it is possible to pre-train the classifiers without relying on a permutation procedure (cf. Algorithm 4), and to re-use them to quickly compute the validation diagnostics for any choice of x o or new posterior estimator q ϕ of the given inference task. It is worth mentioning that this is not possible with the usual ℓ -C2ST, as it depends on q and it would require new simulations for each trial.

4 Experiments

All experiments were implemented with Python and the sbi package [44] combined with PyTorch [38] and nflows [12] for neural posterior estimation 4 . Classifiers on the C2ST framework use the MLPClassifier from scikit-learn [39] with the same parameters as those used in sbibm [31].

4.1 Two benchmark examples for SBI

We illustrate ℓ -C2ST on two examples: Two Moons and SLCP . These models have been widely used in previous works from SBI literature [18, 36] and are part of the SBI benchmark [31]. They both represent difficult inference tasks with locally structured multimodal true posteriors in, respectively, low ( θ ∈ R 2 , x ∈ R 2 ) and high ( θ ∈ R 5 , x ∈ R 8 ) dimensions. See [31] for more details. To demonstrate the benefits of ℓ -C2ST-NF, all experiments use neural spline flows [11] trained under the amortized paradigm for neural posterior estimation (NPE) [37]. We use implementations from the sbibm package [31] to ensure uniform and consistent experimental setups. Samples from the true posterior distributions for both examples are obtained via MCMC and used to compare ℓ -C2ST(NF) to the oracle -C2ST framework. We include results for local -HPD implemented using the code repository of the authors of [48] with default hyper-parameters and applied to HPD. 5

First, we evaluate the local consistency of the posterior estimators of each task over ten different observations x o with varying N train and fixed N cal = 10 4 . The first column of Figure 2 displays the MSE statistics for the oracle and ℓ -C2ST frameworks. As expected, we observe a decrease in the test statistics as N train increases: more training data usually means better approximations. For Two Moons the statistic of ℓ -C2ST decreases at the same rate as oracle -C2ST, with notably accurate results for ℓ -C2ST-NF. However, in SLCP both ℓ -C2ST statistics decrease much faster than the oracle . This is possibly due to the higher dimension of the observation space in the latter case, which impacts the training-procedure of ℓ -C2ST on the joint distribution.

̸

We proceed with an empirical analysis based on 50 random test runs for each validation method and computing their rejection-rates to the nominal significance level of α = 0 . 05 . Column 4 in Figure 2 confirms that the false positive rates (or type I errors) for all tests are controlled at desired level. Column 2 of Figure 2 portrays the true positive rates (TPR), i.e. rejecting H 0 ( x o ) when p = q , of each test as a function of N train . Both ℓ -C2ST strategies decrease with N train as in Column 1, with higher TPR for ℓ -C2ST-NF in both tasks. The oracle has maximum TPR and rejects the local consistency of all posterior estimates across all observations at least 90% of the time. Note that SLCP is designed to be a difficult model to estimate 6 , meaning that higher values of TPR are expected ( ˆ t ̸→ 0 in Column 1). In Two Moons , the decreasing rejection rate can be seen as normal as it reflects the convergence of the posterior approximator ( ˆ t → 0 in Column 1): as N train increases, the task of differentiating the estimator from the true posterior becomes increasingly difficult.

We fix N train = 10 3 (which yields inconsistent q ϕ in both examples) and investigate in Column 3 of Figure 2 how many calibration samples are needed to get a maximal TPR in each validation method.

-level:

0.05

oracle C2ST (

/       )

/

/

t

Acc

t

MSE

-C2ST

-NF (

local

-HPD

/

)

t

MSE0

0.00

0.12

0.25

test statistic

t

0

0.0

0.5

1.0

0.0

0.5

1.0

0.0

0.5

1.0

type I error (FPR)

type I error (FPR)

SLCP

power (TPR)

power (TPR)

power (TPR)

power (TPR)

10

2

10

3

10

4

10

5

N

train

(

N

cal

=10 4

)

0.00

0.12

0.25

test statistic

t

0

10

2

10

3

10

4

10

5

N

train

(

N

cal

=10 4

)

0.0

0.5

1.0

100

500

1000 2000 5000

10

4

N

cal

(

N

train

=10 3

)

0.0

0.5

1.0

100

500

1000 2000 5000

10

4

N

cal

(

N

train

=10 3

)

0.0

0.5

1.0

Two Moons

SLCP is expected to be an easy classification task, since the posterior estimator is very far from the true posterior (large values of ˆ t in Column 1). We observe similar performance for ℓ -C2ST-NF and ℓ -C2ST, with slightly faster convergence for the latter. Both methods perform better than local -HPD, that never reaches maximum TPR. Two Moons represents a harder discrimination task, as q ϕ is already pretty close to the reference posterior (see Column 1). Here, ℓ -C2ST-NF attains maximum power at N cal = 2000 and outperforms all other methods. Surprisingly, the regression-based oracle -C2ST performs comparably to local -HPD, converging to TPR = 1 at N cal = 5000 .

4.2 Jansen-Rit Neural Mass Model (JRNMM)

We increase the complexity of our examples and consider the well known Jansen & Rit neural mass model (JRNMM) [25]. This is a neuroscience model which takes parameters θ = ( C, µ, σ, g ) ∈ R 4 as input and generates time series x ∈ R 1024 with properties similar to brain signals obtained in neurophysiology. Each parameter has a physiologically meaningful interpretation, but they are not relevant for the purposes of this section; the interested reader is referred to [3] for more details.

The approximation q ϕ of the model's posterior distribution is a conditioned masked autoregressive flow (MAF) [35] with 10 layers. We follow the same experimental setting from [3], with a uniform prior over physiologically-relevant parameter values and a simulated dataset from the joint distribution including N train = 50 000 training samples for the posterior estimator and N cal = 10 000 samples to compute the validation diagnostics. An evaluation set of size N v 0 = 10 000 is used for ℓ -C2ST-NF.

We first investigate the global consistency of our approximation, which informs whether q ϕ is consistent (or not) on average with the model's true posterior distribution. We use standard tools for this task such as simulation-based calibration (SBC) [42] and coverage tests based on highest predictive density (HPD) [48]. The results are shown in the left panel of Figure 3. We observe that the empirical cdf of the global HPD rank-statistic deviates from the identity function (black dashed line), indicating that the approximator presents signs of global inconsistency. We also note that the marginal SBC-ranks are unable to detect any inconsistencies in q ϕ .

We use ℓ -C2ST-NF to study the local consistency of q ϕ on a set of nine observations x ( i ) o defined as 7

The right panel of Figure 3 shows that the test statistics of ℓ -C2ST-NF vary in a U-shape, attaining higher values as g o deviates from zero and at the borders of the prior. The plot is overlaid with the 95% confidence region, illustrating how much the test statistics deviate from the local null hypothesis.

0.0

0.5

1.0

rank

0.0

0.5

1.0

empirical CDF

20

15

10

5

0

5

10

15

20

0.00

0.05

0.10

test statistic

SBC

1

SBC

2

SBC

3

SBC

4

HPD( )

-C2ST-NF (

t

MSE0

)

t

0

95% CR

gain (

g

o

)

Figure 3: Results for global and local tests on JRNMM. Left : PP-plots for the marginal SBC and global HPD rank statistics. Right : Test statistics for ℓ -C2ST-NF on observations with varying g o . SBC fails to detect any inconsistency of q ϕ , while HPD only provides a global assessment, unlike ℓ -C2ST which locally explains the inconsistencies in q ϕ .

Figure 4: Graphical diagnostics of ℓ -C2ST-NF for JRNMM. Top right panel displays the empirical CDF of the classifier (blue) overlaid with the theoretical CDF of the null hypothesis (step function at 0 . 5 ) and 95% confidence region of estimated classifiers under the null displayed in gray. The pairplot displays histograms of samples from q ϕ within the prior region and dashed lines indicate values of θ o used to generate the conditioning observation x o . The predicted probabilities are mapped on the colors of the bins in the histogram. Blue-green (resp. orange-red) regions indicate low (resp. high) predicted probabilities of the classifier. Yellow regions correspond to chance level, thus q ϕ ≈ p .

We demonstrate the interpretability of the results for ℓ -C2ST-NF with a focus on the behavior of q ϕ when conditioned on an observation for which g o = 10 . The local PP-plot in Figure 4 summarises the test result: the predicted class probabilities deviate from 0 . 5 , outside of the 95% -CR, thus rejecting the null hypothesis of local consistency at g o = 10 . The rest of Figure 4 displays 1D and 2D histograms of samples Θ q ∼ q ϕ ( θ | x o ) within the prior region, obtained by applying the learned T ϕ to samples Z ∼ N (0 , I 4 ) . The color of each histogram bin is mapped to the intensity of the corresponding predicted probability in ℓ -C2ST-NF and informs the regions where the classifier is more (resp. less) confident about its choice of predicting class 0. 8 This relates to regions in the parameter space where the posterior approximation has too much (resp. not enough mass) w.r.t. to the true posterior: q ϕ > p (resp. q ϕ < p ). We observe that the ground-truth parameters are often outside of the red regions, indicating positive bias for µ and σ and negative bias for g in the 1D marginal. It also shows that the posterior is over-dispersed in all 2D marginals. See Appendix D for results on all observations x ( i ) o .

5 Discussion

We have presented ℓ -C2ST, an extension to the C2ST framework tailored for SBI settings which requires only samples from the joint distribution and is amortized along conditioning observations. Strikingly, empirical results show that, while ℓ -C2ST does not have access to samples from the true posterior distribution, it is actually competitive with the oracle-C2ST approach that does. This comes at the price of training a binary classifier on a potentially large dataset to ensure the correct calibration

of the predicted probabilities. Should this be not the case, some additional calibration step for the classifier can be considered [10].

Notably, ℓ -C2ST allows for a local analysis of the consistency of posterior approximations and is more sensible, precise, and computationally efficient than its concurrent method, local -HPD. Appendix F.4 provides a detailed discussion of these statements, based on results obtained for additional benchmark examples. When exploiting properties of normalizing flows, ℓ -C2ST can be further improved as demonstrated by encouraging results on difficult posterior estimation tasks (see Table 2 in Appendix F). We further analyze the benefits of this -NF version in Appendix F.3. ℓ -C2ST provides necessary, and sufficient, conditions for posterior consistency, features that are not shared by other standard methods in the literature (e.g. SBC). When applied to a widely used model from computational neuroscience, the local diagnostic proposed by ℓ -C2ST offered interesting and useful insights on the failure modes of the SBI approach (e.g. poor estimates on the border of the prior intervals), hence demonstrating its potential practical relevance for works leveraging simulators for scientific discoveries.

6 Limitations and Perspectives

Training a classifier with finite data. The proposed validation method leverages classifiers to learn global and local data structures and shows great potential in diagnosing conditional density estimators. However, it's validity is only theoretically guaranteed by the optimality of the classifier when N v →∞ . In practice, this can never perfectly be ensured. Figure 6 in Appendix F.2 shows that depending on the dataset, ℓ -C2ST can be more or less accurate w.r.t. the true C2ST. Therefore, one should always be concerned about false conclusions due to a far-from-optimal classifier and make sure that the classifier is 'good enough' before using it as a diagnostic tool, e.g. via cross-validation. Note, however, that the MSE test statistic for ℓ -C2ST is defined by the predicted class probabilities and not the accuracy of the classifier, thus one should also check how well the classifier is calibrated.

Why Binary Classification? An alternative to binary classification would have been to train a second posterior estimate in order to assess the consistency of the first one. Indeed, one could ask whether training a classifier is inherently easier than obtaining a good variational posterior, the response to which is non-trivial. Nevertheless, we believe that adding diversity into the validation pipeline with two different ML approaches might be preferable. Furthermore, building our method on the C2ST framework was mainly motivated by the popularity and robustness of binary classification: it is easy to understand and has a much richer and stable literature than deep generative models. As such, we believe that choosing a validation based on a binary classifier has the potential of attracting the interest of scientists across various fields, rather than solely appealing to the probabilistic machine learning community.

Possible extensions and improvements. Future work could focus on leveraging additional information of q while training the classifier as in [47]. For example, by using more samples from the posterior estimator q or its explicit likelihood function (which is accessible when q is a normalizing flow). On a different note, split-sample conformal inference could be used to speed up the p -value calculations (avoiding the time-consuming permutation step in Algorithm 1).

In summary, our article shows that ℓ -C2ST is theoretically valid and works on several datasets, sometimes even outperforming local -HPD, which to our knowlegde is the only other existing local diagnostic. Despite facing some difficulties for certain examples (just like for other methods as well), an important feature of ℓ -C2ST is that one can directly leverage from improvements in binary classification to adapt and enhance it for any given dataset and task. This makes ℓ -C2ST a competitive alternative to other validation approches, with great potential of becoming the go-to validation diagnostic for SBI practitioners.

Acknowledgments

Julia Linhart is recipient of the Pierre-Aguilar Scholarship and thankful for the funding of the Capital Fund Management (CFM). Alexandre Gramfort was supported by the ANR BrAIN (ANR-20CHIA0016) grant while in his role at Université Paris-Saclay, Inria.

References

Sean R. Bittner, Agostina Palmigiano, Alex T. Piet, Chunyu A. Duan, Carlos D. Brody, Kenneth D. Miller, and John Cunningham. Interrogating theoretical models of neural computation with emergent property inference. eLife , 10, 7 2021. ISSN 2050084X. doi: 10.7554/eLife.56265.

Bob Carpenter, Andrew Gelman, Matthew D Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker, Jiqiang Guo, Peter Li, and Allen Riddell. Stan: A probabilistic programming language. Journal of statistical software , 76(1), 2017.

Pedro Luiz Coelho Rodrigues, Thomas Moreau, Gilles Louppe, and Alexandre Gramfort. HNPE: Leveraging Global Parameters for Neural Posterior Estimation. In NeurIPS 2021 , Sydney (Online), Australia, December 2021. URL https://hal.science/hal-03139916 .

Kyle Cranmer, Johann Brehmer, and Gilles Louppe. The frontier of simulation-based inference. Proceedings of the National Academy of Sciences (PNAS) , 117:30055-30062, 2020. ISSN 0027-8424. doi: 10.1073/pnas.1912789117.

Niccolo Dalmasso, Rafael Izbicki, and Ann Lee. Confidence sets and hypothesis testing in a likelihood-free inference setting. In Hal Daumé III and Aarti Singh, editors, Proceedings of the 37th International Conference on Machine Learning , volume 119 of Proceedings of Machine Learning Research , pages 2323-2334. PMLR, 13-18 Jul 2020.

Maximilian Dax, Stephen R. Green, Jonathan Gair, Jakob H. Macke, Alessandra Buonanno, and Bernhard Schölkopf. Real-time gravitational wave science with neural posterior estimation. Phys. Rev. Lett. , 127:241103, Dec 2021. doi: 10.1103/PhysRevLett.127.241103. URL https: //link.aps.org/doi/10.1103/PhysRevLett.127.241103 .

Maximilian Dax, Stephen R Green, Jonathan Gair, Michael Deistler, Bernhard Schölkopf, and Jakob H. Macke. Group equivariant neural posterior estimation. In International Conference on Learning Representations , 2022. URL https://openreview.net/forum?id= u6s8dSporO8 .

Arnaud Delaunoy, Joeri Hermans, François Rozet, Antoine Wehenkel, and Gilles Louppe. Towards reliable simulation-based inference with balanced neural ratio estimation. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho, editors, Advances in Neural Information Processing Systems , 2022. URL https://openreview.net/forum?id=o762mMj4XK .

Biprateep Dey, David Zhao, Jeffrey A. Newman, Brett H. Andrews, Rafael Izbicki, and Ann B. Lee. Calibrated predictive distributions via diagnostics for conditional coverage. 5 2022. doi: 10.48550/arxiv.2205.14568. URL https://arxiv.org/abs/2205.14568v2 .

Victor Dheur and Souhaib Ben Taieb. A large-scale study of probabilistic calibration in neural network regression. In Proceedings of the 40th International Conference on Machine Learning , 2023. To appear.

Conor Durkan, Artur Bekasov, Iain Murray, and George Papamakarios. Neural spline flows. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems , volume 32. Curran Associates, Inc., 2019.

Conor Durkan, Artur Bekasov, Iain Murray, and George Papamakarios. nflows: normalizing flows in PyTorch. November 2020. doi: 10.5281/zenodo.4296287.

Bradley Efron and Trevor Hastie. Institute of mathematical statistics monographs: Computer age statistical inference: Algorithms, evidence, and data science series number 5 . Cambridge University Press, Cambridge, England, July 2016.

David Frazier, Christian Robert, and Judith Rousseau. Model misspecification in approximate Bayesian computation: consequences and diagnostics. Journal of the Royal Statistical Society: Series B , 82(2):421-444, 2019. doi: 10.1111/rssb.12356.

Andrew Gelman, Aki Vehtari, Daniel Simpson, Charles C. Margossian, Bob Carpenter, Yuling Yao, Lauren Kennedy, Jonah Gabry, Paul-Christian Bürkner, and Martin Modrák. Bayesian workflow, 2020.

Pedro J. Gonçalves, Jan Matthis Lueckmann, Michael Deistler, Marcel Nonnenmacher, Kaan Öcal, Giacomo Bassetto, Chaitanya Chintaluri, William F. Podlaski, Sara A. Haddad, Tim P. Vogels, David S. Greenberg, and Jakob H. Macke. Training deep neural density estimators to identify mechanistic models of neural dynamics. eLife , 9:1-46, 9 2020. ISSN 2050084X. doi: 10.7554/ELIFE.56261.

Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, and Yoshua Bengio. Generative adversarial networks. Communications of the ACM , 63:139-144, 6 2014. ISSN 15577317. doi: 10.1145/3422622.

David Greenberg, Marcel Nonnenmacher, and Jakob Macke. Automatic posterior transformation for likelihood-free inference. In Kamalika Chaudhuri and Ruslan Salakhutdinov, editors, Proceedings of the 36th International Conference on Machine Learning , volume 97, pages 2404-2414. PMLR, 09-15 Jun 2019.

Michael U. Gutmann and Aapo Hyvärinen. Noise-contrastive estimation of unnormalized statistical models, with applications to natural image statistics. Journal of Machine Learning Research , 13(11):307-361, 2012. URL http://jmlr.org/papers/v13/gutmann12a.html .

Meysam Hashemi, Anirudh N. Vattikonda, Jayant Jha, Viktor Sip, Marmaduke M. Woodman, Fabrice Bartolomei, and Viktor K. Jirsa. Simulation-based inference for whole-brain network modeling of epilepsy using deep neural density estimators. medRxiv , page 2022.06.02.22275860, 6 2022. doi: 10.1101/2022.06.02.22275860. URL https://www.medrxiv.org/content/ 10.1101/2022.06.02.22275860v1 .

Trevor Hastie, Robert Tibshirani, and J H Friedman. The elements of statistical learning . Springer series in statistics. Springer, New York, NY, 2 edition, December 2009.

Joeri Hermans, Volodimir Begy, and Gilles Louppe. Likelihood-free MCMC with amortized approximate ratio estimators. In Hal Daumé III and Aarti Singh, editors, Proceedings of the 37th International Conference on Machine Learning , volume 119 of Proceedings of Machine Learning Research , pages 4239-4248. PMLR, 13-18 Jul 2020. doi: 10.48550/arxiv.1903.04057.

Joeri Hermans, Arnaud Delaunoy, François Rozet, Antoine Wehenkel, Volodimir Begy, and Gilles Louppe. A crisis in simulation-based inference? beware, your posterior approximations can be unfaithful. Transactions on Machine Learning Research , 2022. ISSN 2835-8856. URL https://openreview.net/forum?id=LHAbHkt6Aq .

Maëliss Jallais, Pedro L. C. Rodrigues, Alexandre Gramfort, and Demian Wassermann. Inverting brain grey matter models with likelihood-free inference: a tool for trustable cytoarchitecture measurements. Machine Learning for Biomedical Imaging , 1:1-28, 2022. ISSN 2766-905X. URL https://melba-journal.org/2022:010 .

Ben H. Jansen and Vincent G. Rit. Electroencephalogram and visual evoked potential generation in a mathematical model of coupled cortical columns. Biological Cybernetics 1995 73:4 , 73: 357-366, 9 1995. ISSN 1432-0770. doi: 10.1007/BF00199471.

Ilmun Kim, Ann B. Lee, and Jing Lei. Global and local two-sample tests via regression. Electronic Journal of Statistics , 13:5253-5305, 12 2018. ISSN 19357524. doi: 10.48550/arxiv. 1812.08927.

Pablo Lemos, Miles Cranmer, Muntazir Abidi, ChangHoon Hahn, Michael Eickenberg, Elena Massara, David Yallup, and Shirley Ho. Robust simulation-based inference in cosmology with bayesian neural networks. Machine Learning: Science and Technology , 4(1):01LT01, feb 2023. doi: 10.1088/2632-2153/acbb53. URL https://dx.doi.org/10.1088/2632-2153/ acbb53 .

Paula Sanz Leon, Stuart A. Knock, M. Marmaduke Woodman, Lia Domide, Jochen Mersmann, Anthony R. Mcintosh, and Viktor Jirsa. The virtual brain: a simulator of primate brain network dynamics. Frontiers in neuroinformatics , 7, 6 2013. ISSN 1662-5196. doi: 10.3389/FNINF. 2013.00010. URL https://pubmed.ncbi.nlm.nih.gov/23781198/ .

Julia Linhart, Alexandre Gramfort, and Pedro L. C. Rodrigues. Validation diagnostics for SBI algorithms based on normalizing flows, 2022.

David Lopez-Paz and Maxime Oquab. Revisiting classifier two-sample tests. 5th International Conference on Learning Representations, ICLR 2017 , 10 2016. doi: 10.48550/arxiv.1610.06545. URL https://arxiv.org/abs/1610.06545v4 .

Jan-Matthis Lueckmann, Jan Boelts, David S Greenberg, Pedro J Gonçalves, and Jakob H Macke. Benchmarking simulation-based inference. Proceedings of The 24th International Conference on Artificial Intelligence and Statistics (PMLR) , 130:343-351, 4 2021. doi: 10. 48550/arxiv.2101.04653.

T. Lucas Makinen, Tom Charnock, Justin Alsing, and Benjamin D. Wandelt. Lossless, scalable implicit likelihood inference for cosmological fields. Journal of Cosmology and Astroparticle Physics , 2021, 7 2021. doi: 10.1088/1475-7516/2021/11/049.

Martin Modrák, Angie H. Moon, Shinyoung Kim, Paul Bürkner, Niko Huurre, Kateˇ rina Faltejsková, Andrew Gelman, and Aki Vehtari. Simulation-based calibration checking for bayesian computation: The choice of test quantities shapes sensitivity. 11 2022. doi: 10.48550/arxiv.2211.02383. URL https://arxiv.org/abs/2211.02383v1 .

Teodora Pandeva, Tim Bakker, Christian A. Naesseth, and Patrick Forré. E-valuating classifier two-sample tests, 2022.

George Papamakarios, Theo Pavlakou, and Iain Murray. Masked autoregressive flow for density estimation. Advances in Neural Information Processing Systems (NeurIPS) , pages 2339-2348, 12 2017. ISSN 10495258. doi: 10.48550/arxiv.1705.07057.

George Papamakarios, David Sterratt, and Iain Murray. Sequential neural likelihood: Fast likelihood-free inference with autoregressive flows. 89:837-848, 16-18 Apr 2019.

George Papamakarios, Eric Nalisnick, Danilo Jimenez Rezende, Shakir Mohamed, and Balaji Lakshminarayanan. Normalizing flows for probabilistic modeling and inference. Journal of Machine Learning Research , 22:1-64, 2021. ISSN 15337928. doi: 10.48550/arxiv.1912.02762.

Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. PyTorch: An Imperative Style, High-Performance Deep Learning Library. In Advances in Neural Information Processing Systems (NeurIPS) , page 12, Vancouver, BC, Canada, 2019.

F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research , 12:2825-2830, 2011.

Danilo Rezende and Shakir Mohamed. Variational inference with normalizing flows. In Francis Bach and David Blei, editors, Proceedings of the 32nd International Conference on Machine Learning , volume 37 of Proceedings of Machine Learning Research , pages 1530-1538, Lille, France, 07-09 Jul 2015. PMLR. URL https://proceedings.mlr.press/v37/rezende15. html .

Christian Robert and George Casella. Monte Carlo statistical methods . Springer Texts in Statistics. Springer, New York, NY, 2 edition, July 2005.

Sean Talts, Michael Betancourt, Daniel Simpson, Aki Vehtari, and Andrew Gelman. Validating bayesian inference algorithms with simulation-based calibration. 4 2018. doi: 10.48550/arxiv. 1804.06788.

Simon Tavaré, David J. Balding, R. C. Griffiths, and Peter Donnelly. Inferring coalescence times from DNA sequence data. Genetics , 145:505-518, 2 1997. ISSN 00166731. doi: 10.1093/GENETICS/145.2.505.

Alvaro Tejero-Cantero, Jan Boelts, Michael Deistler, Jan-Matthis Lueckmann, Conor Durkan, Pedro J. Gonçalves, David S. Greenberg, and Jakob H. Macke. sbi: A toolkit for simulationbased inference. Journal of Open Source Software , 5(52):2505, 2020. doi: 10.21105/joss.02505.

Vasist, Malavika, Rozet, François, Absil, Olivier, Mollière, Paul, Nasedkin, Evert, and Louppe, Gilles. Neural posterior estimation for exoplanetary atmospheric retrieval. A&A , 672:A147, 2023. doi: 10.1051/0004-6361/202245263. URL https://doi.org/10.1051/0004-6361/ 202245263 .

Daniel Ward, Patrick Cannon, Mark Beaumont, Matteo Fasiolo, and Sebastian M Schmon. Robust neural posterior estimation and statistical model criticism. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho, editors, Advances in Neural Information Processing Systems , 2022. URL https://openreview.net/forum?id=MHE27tjD8m3 .

Yuling Yao and Justin Domke. Discriminative calibration. 2023.

David Zhao, Niccolò Dalmasso, Rafael Izbicki, and Ann B. Lee. Diagnostics for conditional density models and bayesian inference algorithms. In Cassio de Campos and Marloes H. Maathuis, editors, Proceedings of the Thirty-Seventh Conference on Uncertainty in Artificial Intelligence , volume 161 of Proceedings of Machine Learning Research , pages 1830-1840. PMLR, 27-30 Jul 2021. URL https://proceedings.mlr.press/v161/zhao21b.html .

Appendices

A Proofs

̸

In what follows, we assume that it is sufficient for the null hypothesis H 0 to hold on any set C ⊆ R m of strictly positive measure, rather than requiring it to hold for all points θ ∈ R m . In practice, it generally has no practical implications if the posterior estimator is inconsistent with the true posterior ( q = p ) on a set of measure zero, since those sets don't have any real statistical significance.

For the proofs of Theorems 1 and 2, we will consider a classifier f x o defined for a fixed observation x o ∈ R d on S x o = { θ ∈ R m , q ( θ | x o ) + p ( θ | x o ) > 0 } .

A.1 Proof of Theorem 1

Theorem 1 (Local consistency and classification accuracy). If f x o is Bayes optimal and N v →∞ , then ˆ t Acc ( f x o ) = 1 / 2 is a necessary and sufficient condition for the local consistency of q at x o .

Proof. As S x o contains all data points Θ q n ∼ q ( θ | x o ) ( C n = 0 ) and Θ p n ∼ p ( θ | x o ) ( C n = 1 ), the empirical accuracy ˆ t Acc ( f x o ) over the validation set D v = { (Θ n , C n ) } 2 N v n =1 is well defined (7) and

Let's show that if f x o is Bayes optimal, then H 0 ( x o ) holds ⇐⇒ Acc( f x o ) = 1 2 .

( ⇒ ): Suppose H 0 ( x o ) holds. The optimality of f x o implies that f x o (Θ q ) and f x o (Θ p ) are Bernoulli random variables B ( 1 2 ) (see interpretation of equation (5)), and so Acc( f x o ) = 1 2 ( 1 2 + 1 2 ) = 1 2 .

̸

( ⇐ ): Let's proceed by showing the contraposition: if H 0 ( x o ) does not hold, then Acc( f x o ) = 1 2 .

̸

Suppose that H 0 ( x o ) does not hold, there exists a set C = { θ ∈ R m , p ( θ | x o ) = q ( θ | x o ) } of strictly positive measure (w.r.t. p or q , which ever is non zero on that set). We can decompose C into the direct sum of A = { θ ∈ C , q ( θ | x o ) < p ( θ | x o ) } and B = { θ ∈ C , q ( θ | x o ) > p ( θ | x o ) } . Either A or B is necessarily of strictly positive measure. Let's say A (see Lemma 1 for the symmetric case).

A is exactly the region where Prob ( C = 1 | Θ = θ ) > 1 2 and thus where f x o ( θ ) = 1 ; B is the region where f x o ( θ ) = 0 . We therefore get that:

But ∀ θ ∈ A , 0 ≤ q ( θ | x ) < p ( θ | x ) (and A is of strictly positive measure), so the integral in the last equality is strictly positive and we get Acc( f x ) > 1 2 , which concludes the proof.

Lemma 1. Let p and q be two probability density functions defined on a space S . If there exists a set A ⊆ S of strictly positive measure such that ∀ θ ∈ A , q ( θ ) < p ( θ ) , then there exists a set B ⊆ S of strictly positive measure such that ∀ θ ′ ∈ B , q ( θ ′ ) > p ( θ ′ ) .

Proof. We know that ∫ S p = ∫ S q = 1 or equivalently, using S = A∪B = { q > p } ∪ { q ≤ p } ,

By grouping the integrals over A on one side and the ones over B on the other, we get:

which is non-negative because A is assumed to be of strictly positive measure and q -p > 0 everywhere in A .

The integral of p -q over { p = q } is zero, which implies that

meaning that the region { θ ∈ S , p ( θ ) < q ( θ ) } is is of strictly positive measure, which concludes the proof.

A.2 Proof of Theorem 2

Theorem 2 (Local consistency and regression). If f x o is Bayes optimal and N v → ∞ , then ˆ t MSE ( f x o ) = 0 is a necessary and sufficient condition for the local consistency of q at x o .

Proof. Let d x o be an estimator of P ( C = 1 | Θ; x o ) defined on S x o such that f x o = I d x o > 1 2 . As this region contains all the data points Θ q n ∼ q ( θ | x o ) ( C n = 0 ) and Θ p n ∼ p ( θ | x o ) ( C n = 1 ), the mean squared error ˆ t MSE ( f x o ) over the dataset D = { (Θ n , C n ) } 2 n N =1 is well defined (9) and

This integral is zero if, and only if ( d x o ( θ ) -1 2 ) 2 = 0 for every θ ∈ S x o (all terms are non-negative and q ( θ | x o ) + p ( θ | x o ) > 0 ) 9 , which is equivalent to d x o ( θ ) = 1 2 for every θ ∈ S x o . Assuming f x o = f ⋆ x o is optimal , we have that d x o ( θ ) = d ∗ x o ( θ ) = P( C = 1 | θ ; x o ) and we conclude the proof using the result from equation (5) (and knowing that outside of S x o , p = q = 0 ):

A.3 Proof of Theorem 3

Theorem 3 (Local consistency and single class evaluation). If f is Bayes optimal and N v →∞ , then ˆ t MSE 0 ( f, x o ) = 0 is a necessary and sufficient condition for the local consistency of q at x o .

Proof. Let d be an estimator of P ( C = 1 | Θ; X ) and f = I d> 1 2 the associated classifier, both defined on S = { w = ( θ, x ) ∈ R m × R d , q ( θ, x ) + p ( θ, x ) > 0 } . Suppose that f = f ⋆ is optimal and let x o ∈ R d be a fixed observation. As explained in section 3, we have that

Consider the support S q,x o = { θ ∈ R m , q ( θ | x o ) > 0 } ⊂ S x o containing all data points Θ q n ∼ q ( θ | x o ) from our single-class validation set D v 0 = { (Θ q n , 0) } N v 0 n =1 . Therefore our single-class test statistic ˆ t MSE 0 is well defined (12) and

With the same arguments as in the proof of Theorem 2 in A.2, we get that

where the second equivalence is true because S q,x o = S x o for p ( . | x o ) = q ( . | x o ) . Therefore, t MSE 0 ( f ⋆ , x o ) = 0 is a necessary and sufficient condition for H 0 ( x o ) .

N.B. Single-class accuracy ( Acc 0 ) does not provide a sufficient condition for H 0 ( x o ) .

Proof. Following the proof of Theorem 1 in A.1, we have that

This means that Acc 0 ( f ⋆ , x o ) = P( f ⋆ x o (Θ q ) = 0) = 1 2 can only be a sufficient condition for H 0 ( x o ) if P( f ⋆ x o (Θ q ) = 0) = P ( f ⋆ x o (Θ p ) = 1) , which is not generally true. In conclusion, evaluating Acc 0 ( f ⋆ , x o ) only provides a necessary condition for the local null hypothesis (see ( ⇒ ) in A.1).

B Algorithms

B.1 Generating PP-plots with ℓ -C2ST

Algorithm 5: ℓ -C2ST - local PP-plots for any x

C Run-times for each validation procedure

To complete the benchmark experiments from Section 4.1, we analyze the run-times of each validation method to compute the test statistic 10 for an NPE of the SLCP -task, obtained for different values of N train . Results are displayed in Table 1 and computed on average over all given observations x o and for N cal -values that ensure high test power. We here focus solely on the SLCP -task, as the higher dimensional observation space allows to illustrate the differences between local methods (trained on the joint data space, ( θ, x ) ∈ R 5+8 ) and the oracle (trained on the parameter space only, θ ∈ R 5 ).

As expected, the computation time increases with the sample size N cal (left vs. right part of Table 1). While the oracle C2ST has close to constant run-time for fixed N cal , local methods become faster with increasing N train . We observe that ℓ -C2ST(-NF) has comparable run-times to the oracle C2ST: the amortization cost is negligible, in particular for difficult tasks involving "good" posterior estimators (high N train ). However, this is not the case for local -HPD, which is the most expensive method. Indeed, it involves (1) the costly computation of the HPD statistics on the joint and (2) the training of several (default is n c = 11 ) classifiers, both of which increase with the sample size and dimension of the data space.

D Graphical diagnostics ( ℓ -C2ST-NF) for the JRNMM posterior estimator

The following figures present additional results for the interpretability of ℓ -C2ST applied to the JRNMM neural posterior estimator. They complete Figure 4. Results are shown for all given observations associated to ground-truth gain values g o = -20 , -15 , -10 , -5 , 0 , 5 , 10 , 15 , 20 .

In each Figure, the top right panel displays the empirical CDF of the classifier (blue) overlaid with the theoretical CDF of the null hypothesis (step function at 0 . 5 ) and 95% confidence region of estimated classifiers under the null displayed in gray. The pairplot displays histograms of samples from the posterior estimator q ϕ within the prior region and dashed lines indicate values of θ o used to generate the conditioning observation x o . The predicted probabilities are mapped on the colors of the bins in the histogram. Blue-green (resp. orange-red) regions indicate low (resp. high) predicted probabilities of the classifier. Yellow regions correspond to chance level, thus q ϕ ≈ p .

E On the cross-entropy loss for ℓ -C2ST

This section aims at facilitating the understanding of ℓ -C2ST by proving the result of equation (11).

As detailed in section 3, the first step in ℓ -C2ST consists in training a classifier to distinguish between N cal data points (Θ n , X n ) and (Θ q n , X n ) from the joint distributions p ( θ, x ) and q ( θ, x ) respectively. Here, the same conditioning observations { X n } N cal n =1 are used to construct the data samples for each class (see Algorithm 1). We show that this does not affect the objective function and convergence of the classifier.

The theoretical cross-entropy loss function to distinguish between data (Θ , X ) from class C = 1 and class C = 0 is defined by

Note that the we have equal marginals X | ( C = 1) ∼ p ( x ) = q ( x ) = X | ( C = 0) . 11 This allows us to take the expectation over X and approximate (20) via Monte-Carlo for only one set of conditioning observations { X n } N cal n =1 , and with data points Θ n and Θ q n respectively associated to class C = 1 and C = 0 for a given X n :

Therefore, we can train a classifier to minimize (20) using data from the joint distributions with same conditioning observations. The obtained estimate d = arg min { l CE ( d ) } of the class probabilities is defined for every ( θ, x ) ∈ R m × R d by d ( θ, x ) ≈ p ( θ,x ) p ( θ,x )+ q ( θ,x ) . As p ( x ) = q ( x ) , we recover the class probabilities of the optimal Bayes classifier on the conditional data space for any given x ∈ R d :

For an example, see works related to neural ratio estimation (NRE) [22, 8]: these algorithms implicitly use a classifier to distinguish between the joint and marginal distributions p ( θ, x ) and p ( θ ) p ( x ) . Like in our case, both classes are modeled using the same observations X n obtained via the simulator.

F Additional Experiments on several benchmark examples

The results on the two benchmark examples in Figure 2 give first intuitions about the validity and behaviour of ℓ -C2ST(-NF), our proposal, w.r.t. the oracle C2ST and the alternative local -HPD methods. In this section, Figure 5 extends Figure 2 with results on additional benchmark examples and more detailed results on the correlation between the test statistics of ℓ -C2ST(-NF) and the oracle C2ST for different conditioning observations are shown in Figure 6 and Table 3. We refer the reader to Table 2 for a description of all benchmark examples (data dimensionality, posterior structure, challenges) and a summary of the main results comparing local methods.

While investigating the scalability of the algorithms to high dimensional data spaces, these additional experiments help to further analyze how well ℓ -C2ST(-NF) captures the true C2ST, when it outperforms local -HPD, and better understand the benefit of the -NF version. These points are further detailed in the following subsections. The goal is to create a first guideline for when our proposal can and should be used, while raising awareness of its limitiations (i.e. when it should not be used or at least be adpated for improved performance).

F.1 Scalability to high dimensions

First of all, note that in the specific case of SBI, the dimension of the parameter space is typically of order 10 0 to 10 1 and m ≈ 10 2 is already often considered as high dimensional. The observation space, however, can be of higher dimension (e.g. d ≈ 10 3 for time-series), but summary statistics are often used to reduce the dimension of the observations to the order of d ≈ 10 1 . In Section 4 we analyze the results obtained for rather low-dimensional benchmark examples ( Two-Moons : m = 2 , d = 2 , SLCP : m = 5 , d = 8 ). As an extension of Figure 2, Figure 5 includes additional benchmark examples with low and medium dimensionality: Gaussian Mixture ( m = 2 , d = 2 ) Gaussian Linear Uniform ( m = 10 , d = 10 ) and Bernoulli GLM ( m = 10 , d = 10 ). Furthermore, the Bernoulli GLM Raw task allows us to analyze how our method scales to high dimensional observation spaces only (without parameter-space / task variability): it considers raw observation data with d = 100 , as opposed to sufficient summary statistics in the Bernoulli GLM task.

Column 3 in Figure 5 shows that ℓ -C2ST requires more data to converge to the oracle C2ST (at maximum power TPR = 1 ) as the data dimensionality increases: N cal ≈ 2000 for Two Moons and SLCP , but N cal ≈ 5000 for the Bernouilli GLM task. Note that the Gaussian Mixture and

0.00

0.12

0.25

test statistic

t

0

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

type I error (FPR)

Gaussian Mixture

-level:

0.05

-level:

0.05

0.00

0.12

0.25

test statistic

t

0

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

type I error (FPR)

oracle C2ST (

/       )

/

/

t

Acc

t

MSE

-C2ST

-NF (

local

-HPD

/

)

t

MSE0

0.00

0.12

0.25

test statistic

t

0

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

power (TPR)

0.0

0.5

1.0

type I error (FPR)

-level:

0.05

-level:

0.05

Gaussian Linear Uniform tasks were not included in this analysis, as here, the difficulty of the classification task has more impact on statistical power than the data dimensionality 12 .

Interestingly, we observe in the Bernoulli GLM Raw task, that ℓ -C2ST-NF scales well to the highdimensional observation space (faster convergence to maximum TPR compared to Bernoulli GLM ), while the normal ℓ -C2ST and local-HPD significantly lose in statistical power. It should also be noted that local-HPD performs significantly worse in medium dimensions (cf. Bernoulli GLM or even SLCP ) than in low dimensions ( Gaussian Mixture and Two Moons ), though this could be because of the complex posterior structure.

F.2 Accuracy of ℓ -C2ST(-NF) w.r.t. the true C2ST

Figures 2 and 5 compare our method to the oracle C2ST, but only in terms of statistical power, as the local analysis is limited to the averaged results over 10 different reference observations x o . We here provide a more detailed local analysis that examines how the ℓ -C2ST(-NF) test statistics correlate with those from the oracle C2ST, by plotting them against each other. The results obtained for the above mentioned 10 reference observations are shown in Figure 6a. To allow for more robust conclusions, we also show results obtained for a total of 100 different reference observations (cf. Figure 6b), as well as quantitative results on the statistical significance of the correlation indices in Table 3.

Overall, the scattered points are not too far from the diagonal, which indicates that there is some correlation between the test statistics for ℓ -C2ST(-NF) and those from the oracle C2ST. This correlation becomes weaker when N train becomes larger, since the test statistics in these cases tend to zero and can start to be confused with noise. This observation is consistent with the results in Table 3, showing the p-values of the Pearson test, a standard tests for the statistical significance of the correlation indices between the scores.

Another general trend is that the scattered points tend to be below the diagonal, indicating that ℓ -C2ST(-NF) is less sensible to local inconsistencies than the oracle C2ST. This behaviour was expected, as ℓ -C2ST is trained on the joint and thus less precise. Interestingly this doesn't apply to

the Gaussian Mixture task. This could be due to a big variability in the local consistency of q : while trained on the joint ℓ -C2ST(-NF) could overfit on the "bad" observations, resulting in higher test statistics for observations where the true C2ST statistic would be small.

Finally, across all benchmark examples we observe results that are consistent with the ones from Figure 5: higher correlation means higher statistical power.

0

0.125

0.25

-C2ST (

t

MSE0

)

Two Moons

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

-C2ST-NF (

t

MSE0

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

SLCP

0

0.125

0.25

oracle C2ST (

t

MSE

)

Gaussian Mixture

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

N

train

100

1000

10000

100000

N

train

100

1000

10000

100000

Two Moons

Gaussian Mixture

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

-C2ST (

t

MSE0

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

SLCP

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

-C2ST-NF (

t

MSE0

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

0

0.125

0.25

oracle C2ST (

t

MSE

)

F.3 Benefit of the -NF version

The results of all benchmark experiments indicate that the -NF version of ℓ -C2ST works better when the (true) posterior distribution of the model is "more complicated" than a Gaussian distribution (see Table 2 at the beginning of Appendix F). This is for example the case for the Two Moons and SLCP tasks: the posterior distributions are globally multi-modal and locally structured. We observe in Column 3 of Figure 2 in the main paper that the -NF version requires less samples (i.e. lower N cal ) to reach maximum power/ TPR . This is also the case for the additional Bernoulli GLM task (see Column 3 of Figure 5 in Appendix F.1). In contrast, for Gaussian Mixture and Gaussian Linear Uniform , where the posterior is Gaussian, the normal ℓ -C2ST is as powerful or even better than its -NF counterpart.

Finally, we refer the reader to the analysis in Section F.1 to point out an interesting observation: for the Bernoulli GLM , the -NF version scales much better to high dimensional observation spaces than the normal ℓ -C2ST. Note that this does not allow us to make any general conclusions, but it might be worth further investigating this result.

F.4 Advantages of ℓ -C2ST w.r.t. local -HPD

First of all, it is important to mention that having uniform HPD-values is not a sufficient condition for asserting the null hypothesis of consistency (see end of Section 3.3 in [48]). This is a clear disadvantage compared to our proposal, which provides a necessary and sufficient proxy for inspecting local posterior consistency.

Furthermore, the HPD methodology summarizes the whole information concerning θ into a single scalar, while in ℓ -C2ST we handle the θ -vector in its multivariate form. In medium-high θ -dimensions ( m > 2 as in Bernoulli GLM ) or for complex posterior distributions ( SLCP ), such summarized information might discard too much information and not be enough to satisfactorily assess the consistency of the posterior estimator. Indeed, the tasks where local -HPD has similar statistical power to ℓ -C2ST are either in low dimensions ( Two Moons ) and / or have a Gaussian posterior ( Gaussian Mixture / Gaussian Linear Uniform ). See Table 2 for a summary of those results w.r.t. data dimensionality and posterior structure. For a detailed analysis of the scalability to high dimensional data spaces see Appendix F.1.

Finally, local -HPD in its naive implementation is much less efficient than ℓ -C2ST (see Appendix C). Note however that a new "amortized" version of local -HPD has recently been proposed [9] and could be interesting to look at.

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper defines a new diagnostic to check posteriors learned from simulation-based inference.  The main issue in this setting is that one does not have access to likelihoods, and so one needs diagnostics that do not rely on being able to calculate likelihoods.  Here the authors present L-C2ST, which essentially tries to train a classifier to distinguish the _joint_ space over both parameters _and_ observations into whether a given point was more likely under the true joint distribution, $p(x, \\theta)$ or under a variational approximation $q(\\theta | x) p(x)$.  It turns out that a Bayes-optimal (probabilistic) classifier will assign equal weight to the two distributions for all $\\theta$ for a given $x_0$ if and only if $q(\\theta | x_0) = p(\\theta | x_0)$ (up to some technical considerations).  As a result, the authors propose training such a classifier and then seeing how much its weights deviate from $0.5$ and using that as a measure of how well $q$ matches $p$.  Finally, the authors develop a hypothesis testing framework (to account for randomness in the trained classifier) to determine how significant a given deviation is.\n\nSTRENGTHS:\n* Trustworthy checks of how good a given variational posterior is for real settings where we do not have access to the true posterior are sorely needed, and this work is an important step in that direction.\n* The paper is well-written, well-motivated, and clearly explained.\n* The theoretical results complement and motivate the proposed algorithm well (but see below for some minor technical concerns).\n* The proposed algorithm is extremely simple to describe, making it practical and elegant.\n\nWEAKNESSES:\n* My major concern is that I am not totally convinced that learning the proposed classifier is any easier than learning the variational posterior.  As such, I would be concerned that diagnostics showing a good posterior fit could be driven by a far-from-optimal classifier.  My intuition for why this should be a hard problem is as follows: for _any_ amortized posterior $q(\\theta | x)$,  if we can learn a Bayes-optimal classifier $d^*$, then one could recover the true posterior for any $x$ via $p(\\theta | x) = q(\\theta | x) / (1-d^*(\\theta, x))$.  As a result, learning $d^*$ for _any_ $q$ is equivalent to learning the true posterior.  This is somewhat borne out in the third column of figure 2, where one needs roughly the same number of samples to learn a good posterior as one needs in order to learn a good classifier.  I'm wondering if somehow the proposed approach is essentially equivalent to training two different amortized variational posteriors on independent data and then seeing how well they match.  Some further simulations showing that one problem is easier than the other would alleviate some of my concerns.  I should also say that I think that even if my concerns are valid, the diagnostic is still interesting and useful.\n* I felt that the benchmarking could have been improved slightly.  In particular, some empirical relationship between the proposed measure of fit and existing measures would be nice.  For example, the authors could take the true posterior in a toy model where it is known, generate $q$ by perturbing that posterior in a systematic way and compare how increasingly large perturbations affect both the L-C2ST measure as well as things like KL, reverse KL, TV, and so on.  The results in Figures 1 and 2 hint at this, but there are a lot of moving parts (especially in Figure 2) making it difficult to determine whether to contribute power (or lack thereof) to failure of the SBI (i.e., $q$ is bad) or the classifier (i.e. $r$ is good).\n* A minor technical point throughout the proofs of the theorems is that they rely on the null hypothesis $\\mathcal{H}_0$ holding on a set of strictly positive measure.  That is, if $\\mathcal{H}_0$ fails on a set of measure zero then the proofs would break down.  In particular, in that case $\\mathcal{A}$ would have measure zero and the final integral after line 454 would be exactly zero.  I tend to feel that failures on sets of measure zero have no practical implications, and so this is a minor point. But, if one is going to state theorems and proofs, it would be good to be rigorous.\n* Similarly, Lemma 1 should not be phrased in terms of \"points\" as those would have zero measure, and instead should say \"If there exists a set $\\mathcal{A} \\subseteq \\mathcal{S}$ with positive measure such that $p(\\theta) > q(\\theta)$ for all $\\theta \\in \\mathcal{A}$, then there exists a set $\\mathcal{B}$ with positive measure such that $p(\\theta') < q(\\theta')$ for all $\\theta'\\in \\mathcal{B}$.\n* Finally, there are similar  (and equally minor) issues appearing in the proofs of Theorems 2 and 3.\n\nTypos:\n* Line 103: \"may lack of\" --> \"may lack\"\n* Line 240: \"in average\" --> \"on average\"\n* Line 251: Missing period before \"The local PP-plot\"\n\nQUESTIONS:\n* Using the same $X_n$'s in Algorithm 1 for draws from $p(\\cdot | X_n)$ and $q(\\cdot | X_N)$ introduces dependencies in the training data for the classifier.  Can that somehow be leveraged when training the classifier (similar to how in linear regression, we would want to perform GLS instead of OLS to increase the power when data points have shared structure like this).  Along similar lines, if it is much cheaper to sample from $q(\\theta | x)$ than it is to sample from $p(x, \\theta)$, then could it help to somehow incorporate more samples from $q(\\theta  | X_n)$ in the algorithm (or perhaps the whole distribution somehow)?  Obviously this would require accounting for the dependencies (perhaps via some kind of downweighting) in the training of the classifier.  This is obviously not necessary to implement for this paper, but I am curious to hear the authors thoughts.\n* Algorithm 1 also seems computationally intensive due to the permutation step.  Would it be possible to do something like split-sample conformal inference to speed up the p-value calculations?  Again, obviously not necessary for the paper, I'm just curious.\n\nLIMITATIONS:\nI don't see any potential for direct societal harm from this work.  The authors may wish to include a limitations section that highlights failure modes of their method.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 2, "DATE": "2023-06-23"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe authors present a new diagnostic tool for simulation-based inference. The method learns the C2ST without knowledge of the true posterior distribution. If the density estimator is a normalizing flow, the authors propose to perform the classification in latent space.\n\nSTRENGTHS:\n**Originality**: The method tackles and important issue for simulation-based inference. The method is new and potentially very useful. The extension for normalizing flows is interesting and creative. If L-C2ST works well, I could see this be adopted by the community.\n\n**Quality**: The method is rigorously derived.\n\n**Clarity**: Everything is explained well and with sufficient detail. Figures are clear.\n\nWEAKNESSES:\n**Quality**: \nMy main concern with this paper is that it does not sufficiently demonstrate how well the method actually works. In particular, I believe that the following crucial questions remain unanswered:\n\n- Does the method indeed capture the true C2ST for different `x`?\n\nFor example, the (decent) TPRs shown in figure 2 could also be obtained if L-C2ST converges onto the average C2ST across x_o. The central claim of the authors is that L2CT is local, but this claim needs substantially more empirical evidence.\n\nTo address this concerns, I would (for example) suggest to add a scatter plot of L-C2ST vs true C2ST on a task where the ground truth is available by MCMC or analytically\n\n- How well does the method scale with parameter and data dimensionality\n\nSince C2ST is trained on theta and x as input, I could imagine it to not scale well to high-D x or theta (or require **even more** simulations). All tasks in the paper are low-D though. I suggest that the authors add an additional benchmark task with higher data and parameter dimensionality.\n\n- Is the method actually better than local-HPD\n\nOn one task, L-C2ST performs better than local-HPD and worse on another one. Which method should be preferred? The paper also claims that local-HPD is much less efficient than C2ST but this is never empirically shown. In particular, while a naive implementation of local-HPD might be slow, amortizing over the confidence alpha should be trivial and make local-HPD as fast as C2ST. Please correct me if I am wrong or, otherwise, clarify this in the paper.\n\nTo address this, I recommend adding an analysis of the runtimes of the algorithms and ideally have more than only two benchmark tasks.\n\nI believe that the above concerns are critical to the usefulness of the method, but I would be willing to significantly increase my score if these things are addressed.\n\nQUESTIONS:\n- Do I understand correctly that, for large N_H, one has to train the classifier multiple times? If yes, couldn’t this make the method less efficient than local-HPD?\n\nLIMITATIONS:\nThe authors state limitations of their method.", "TITLE": "Official Review", "RECOMMENDATION": 5, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-02"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nAn algorithm for evaluating amortized posterior estimators $q(\\theta|x)$ in simulation-based inference (SBI) is proposed. In the setting considered, we have the ability to sample $p(\\theta)$ and to sample $p(x|\\theta)$ but not to evaluate its density. The algorithm modifies the common classifier two-sample test by learning to discriminate between samples $(\\theta,x)$ sampled ancestrally (though simulation) from $p(\\theta,x)$ and those where $\\theta$ is then resampled from $q(\\theta|x)$. An extension to normalizing flows is also considered, where the discriminator works in the latent space rather than in the theta space. There are strong results on several SBI benchmarks and real-world problems in terms of statistical power and runtime.\n\nSTRENGTHS:\nPlease note that this is a relative outsider's point of view, as I do not directly work on SBI.\n\nI find the paper well-written and was able to understand the main points and the math. In particular, the first few pages are a good introduction to the problem area that will be accessible to any reader who is familiar with Bayesian inference and hypothesis testing.\n\nThe results and their significance are explained well and give intuitions about why the proposed algorithm works well on the chosen problems.\n\nThe provided code is a helpful addition.\n\nWEAKNESSES:\nI do not see any major weaknesses, but have a few questions.\n- Could you please comment on the scalability of the algorithm? What difficulties do you foresee when scaling to high-dimensional theta or problems when the prior is wide? (Same question about high-dimensional observations. Is more risk of overfitting to the class split of $x$?)\n- It would be interesting to understand better the benefit of the -NF version of the algorithm beyond the reasons described in L180, which seem to explain only computation cost improvements. Is it expected that the classification boundary is smoother in the latent space than in the theta space? Maybe this could be illustrated, e.g., on the two moons example.\n\nQUESTIONS:\nPlease see above.\n\nLIMITATIONS:\nyes", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 2, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-07-04"}