SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Julia Linhart
julia.linhart@inria.fr
Pedro L. C. Rodrigues
Grenoble 38000, France
pedro.rodrigues@inria.fr
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.
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 \mid \theta)$  of the underlying mechanistic model, where  $\theta$  represents a set of relevant parameters and  $x \sim \mathrm{Simulator}(\theta)$  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(\theta \mid 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(\theta)$  over the parameter space and using the identity  $p(\theta, x) = p(x \mid \theta)p(\theta)$ . 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. Simulation-based 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  $\ell$ -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.  $\ell$ -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,  $\ell$ -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  $\ell$ -C2ST method and prove asymptotic theoretical guarantees. Finally, we report empirical results on two SBI benchmark examples to analyze the performance of  $\ell$ -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  $\theta \in \mathbb{R}^m$  and observations  $x\in \mathbb{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\mid \theta)$  of the model cannot be easily evaluated. Given a prior distribution  $p(\theta)$ , it is possible to generate samples from the joint pdf  $p(\theta ,x)$  as per:
$$
\Theta_ {n} \sim p (\theta) \Rightarrow X _ {n} = \operatorname {S i m u l a t o r} \left(\Theta_ {n}\right) \sim p (x \mid \Theta_ {n}) \Rightarrow \left(\Theta_ {n}, X _ {n}\right) \sim p (\theta , x). \tag {1}
$$
Let  $N_{s}$  be a fixed simulation budget and  $\{(\Theta_n,X_n)\}_{n = 1}^{N_s} = \mathcal{D}_{\mathrm{train}}\cup \mathcal{D}_{\mathrm{cal}}$  with  $\mathcal{D}_{\mathrm{train}}\cap \mathcal{D}_{\mathrm{cal}} = \emptyset$ . The data from  $\mathcal{D}_{\mathrm{train}}$  are used to train an amortized approximation  $q(\theta \mid x)\approx p(\theta \mid x)$ , e.g. via NPE [18], and those from  $\mathcal{D}_{\mathrm{cal}}$  to diagnose its local consistency [48].
2i.e. the approximation  $q(\theta \mid x)$  is close to  $p(\theta \mid x)$  on average for all values of  $x\in \mathbb{R}^d$  , so we can quickly generate samples from the posterior for any choice of conditioning observation without redoing any training.
Definition 1 (Local consistency). A conditional density estimator  $q$  is said to be locally consistent at  $x_0$  with the true posterior density  $p$  if, and only if, the following null hypothesis holds:
$$
\mathcal {H} _ {0} \left(x _ {\mathrm {o}}\right): q (\theta \mid x _ {\mathrm {o}}) = p (\theta \mid x _ {\mathrm {o}}), \quad \forall \theta \in \mathbb {R} ^ {m}. \tag {2}
$$
We can reformulate  $\mathcal{H}_0(x_{\mathrm{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
$$
\Theta \mid (C = 0) \sim q (\theta \mid x _ {\mathrm {o}}) \quad \text {v s .} \quad \Theta \mid (C = 1) \sim p (\theta \mid x _ {\mathrm {o}}), \tag {3}
$$
for which the optimal Bayes classifier [21] is  $f_{x_0}^\star(\theta) = \operatorname{argmax}\left\{1 - d_{x_0}^\star(\theta), d_{x_0}^\star(\theta)\right\}$  with
$$
d _ {x _ {\mathrm {o}}} ^ {\star} (\theta) = \mathbb {P} (C = 1 \mid \Theta = \theta ; x _ {\mathrm {o}}) = 1 - \mathbb {P} (C = 0 \mid \Theta = \theta ; x _ {\mathrm {o}}) = \frac {p (\theta \mid x _ {\mathrm {o}})}{p (\theta \mid x _ {\mathrm {o}}) + q (\theta \mid x _ {\mathrm {o}})}. \tag {4}
$$
It is a standard result [30, 26] to relate (2) with (3) as per
$$
\mathcal {H} _ {0} \left(x _ {\mathrm {o}}\right) \text {h o l d s} \Longleftrightarrow d _ {x _ {\mathrm {o}}} ^ {\star} (\theta) = \mathbb {P} (C = 1 \mid \Theta = \theta ; x _ {\mathrm {o}}) = \frac {1}{2} \quad \forall \theta \tag {5}
$$
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  $\mathcal{H}_0(x_{\mathrm{o}})$  based on the accuracy of a classifier  $f_{x_{\mathrm{o}}}$  trained on a dataset defined as
$$
\underbrace {\Theta_ {n} ^ {q} \sim q (\theta \mid x _ {\mathrm {o}})} _ {C = 0} \quad \text {a n d} \quad \underbrace {\Theta_ {n} ^ {p} \sim p (\theta \mid x _ {\mathrm {o}})} _ {C = 1} \quad \text {a n d} \quad \mathcal {D} = \left\{\left(\Theta_ {n} ^ {q}, 0\right) \right\} _ {n = 1} ^ {N} \cup \left\{\left(\Theta_ {n} ^ {p}, 1\right) \right\} _ {n = 1} ^ {N}. \quad (6)
$$
The classifier accuracy is then empirically estimated over  $2N_{v}$  samples ( $N_{v}$  samples in each class) from a held-out validation dataset  $\mathcal{D}_v$  generated in the same way as  $\mathcal{D}$ :
$$
\hat {t} _ {\mathrm {A c c}} \left(f _ {x _ {\mathrm {o}}}\right) = \frac {1}{2 N _ {v}} \sum_ {n = 1} ^ {2 N _ {v}} \left[ \mathbb {I} \left(f _ {x _ {\mathrm {o}}} \left(\Theta_ {n} ^ {q}\right) = 0\right) + \mathbb {I} \left(f _ {x _ {\mathrm {o}}} \left(\Theta_ {n} ^ {p}\right) = 1\right) \right]. \tag {7}
$$
Theorem 1 (Local consistency and classification accuracy). If  $f_{x_0}$  is Bayes optimal<sup>3</sup> and  $N_v \to \infty$ , then  $\hat{t}_{\mathrm{Acc}}(f_{x_0}) = 1/2$  is a necessary and sufficient condition for the local consistency of  $q$  at  $x_0$ .
See Appendix A.1 for a proof. The intuition is that, under the null hypothesis  $\mathcal{H}_0(x_{\mathrm{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
$$
f _ {x _ {\mathrm {o}}} (\theta) = \mathbb {I} \left(d _ {x _ {\mathrm {o}}} (\theta) > \frac {1}{2}\right) \quad \text {w h e r e} \quad d _ {x _ {\mathrm {o}}} (\theta) = \mathbb {P} (C = 1 \mid \theta ; x _ {\mathrm {o}}) \tag {8}
$$
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:
$$
\hat {t} _ {\mathrm {M S E}} \left(f _ {x _ {\mathrm {o}}}\right) = \frac {1}{N _ {v}} \sum_ {n = 1} ^ {N _ {v}} \left(d _ {x _ {\mathrm {o}}} \left(\Theta_ {n} ^ {q}\right) - \frac {1}{2}\right) ^ {2} + \frac {1}{N _ {v}} \sum_ {n = 1} ^ {N _ {v}} \left(d _ {x _ {\mathrm {o}}} \left(\Theta_ {n} ^ {p}\right) - \frac {1}{2}\right) ^ {2} \tag {9}
$$
Theorem 2 (Local consistency and regression). If  $f_{x_{\mathrm{o}}}$  is Bayes optimal and  $N_{v} \to \infty$ , then  $\hat{t}_{\mathrm{MSE}}(f_{x_{\mathrm{o}}}) = 0$  is a necessary and sufficient condition for the local consistency of  $q$  at  $x_{\mathrm{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_0}(\theta)$  for any  $\theta \in \mathbb{R}^m$  informs the regions where the classifier is more (or less) confident about its choice [30, 26].
i.e. it is the classifier with lowest possible classification error for the dataset  $\mathcal{D}$ .
3  $\ell$ -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 ( $\ell$ -C2ST) capable of evaluating the local consistency of a posterior approximation requiring data only from the joint pdf  $p(\theta, x)$  which can be easily sampled as per (1).
(1) Train the classifier. We define a modified version of the classification framework (3) with:
$$
(\Theta , X) \mid (C = 0) \sim q (\theta \mid x) p (x) \quad \text {v s .} \quad (\Theta , X) \mid (C = 1) \sim p (\theta , x). \tag {10}
$$
The optimal Bayes classifier is now  $f^{\star}(\theta, x) = \operatorname{argmax}\left\{1 - d^{\star}(\theta, x), d^{\star}(\theta, x)\right\}$  with
$$
d ^ {\star} (\theta , x) = \frac {p (\theta , x)}{p (\theta , x) + q (\theta \mid x) p (x)} = \frac {p (\theta \mid x)}{p (\theta \mid x) + q (\theta \mid x)} = d _ {x} ^ {\star} (\theta), \tag {11}
$$
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(\theta ,x)$  and write  $f_{x_{\mathrm{o}}}(\theta) = f(\theta ,x_{\mathrm{o}})$  for each  $x_{\mathrm{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)$ :
$$
\hat {t} _ {\mathrm {M S E} _ {0}} (f, x _ {\mathrm {o}}) = \frac {1}{N _ {v}} \sum_ {n = 1} ^ {N _ {v}} \left(d \left(\Theta_ {n} ^ {q}, x _ {\mathrm {o}}\right) - \frac {1}{2}\right) ^ {2} \quad \text {w i t h} \quad \Theta_ {n} ^ {q} \sim q (\theta \mid x _ {\mathrm {o}}). \tag {12}
$$
Theorem 3 (Local consistency and single class evaluation). If  $f$  is Bayes optimal and  $N_v \to \infty$ , then  $\hat{t}_{\mathrm{MSE}_0}(f, x_{\mathrm{o}}) = 0$  is a necessary and sufficient condition for the local consistency of  $q$  at  $x_{\mathrm{o}}$ .
Proof. Let  $d$  be an estimator of  $\mathbb{P}(C = 1\mid \Theta ,X)$  and  $f = \mathbb{I}(d > 0.5)$ . Suppose that  $f = f^{\star}$  is Bayes optimal and let  $x_{\mathrm{o}}$  be a fixed observation. We have that
$$
\lim  _ {N _ {v} \rightarrow \infty} \hat {t} _ {\mathrm {M S E} _ {0}} (f ^ {\star}, x _ {\mathrm {o}}) = \int \left(d _ {x _ {\mathrm {o}}} ^ {\star} (\theta) - \frac {1}{2}\right) ^ {2} q (\theta \mid x _ {\mathrm {o}}) \mathrm {d} \theta .
$$
Because of the squared term in the integral and  $q$  being a p.d.f., we have that
$$
\lim _ {N _ {v} \to \infty} \hat {t} _ {\mathrm {M S E} _ {0}} (f ^ {\star}, x _ {\mathrm {o}}) = 0 \quad \Longleftrightarrow \quad d _ {x _ {\mathrm {o}}} ^ {\star} (\theta) = \mathbb {P} (C = 1 \mid \theta ; x _ {\mathrm {o}}) = \frac {1}{2}.
$$
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_{\mathrm{o}}$ . This is not the case in the usual oracle C2ST framework.
Figure 1: Results for the C2ST framework when  $p = \mathcal{N}(0,\mathbf{I}_2)$  and  $q = \mathcal{N}(0,\sigma^2\mathbf{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  $(\hat{t}_{\mathrm{Acc}_0})$  fails to detect when  $p \neq q$  but  $\hat{t}_{\mathrm{MSE}_0}$  behaves correctly.
Figure 1 illustrates the behavior of different test statistics to discriminate samples from two bivariate Normal distributions whose covariance mismatch is controlled by a single scaling parameter  $\sigma$ . Note that the optimal Bayes classifier for this setting can be obtained via quadratic discriminant analysis (QDA) [21]. The results clearly show that even though  $t_{\mathrm{MSE}_0}$  exploits only half of the dataset (i.e. samples from class  $C = 0$ ) it is capable of detecting when  $p$  and  $q$  are different ( $\sigma \neq 1$ ). The plot also
includes the results for a one-class test statistic based on accuracy values  $(\hat{t}_{\mathrm{Acc}_0})$  which, as opposed to  $\hat{t}_{\mathrm{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  $\sigma$ .
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  $\hat{t}_{\mathrm{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  $\mathcal{H}_0(x_{\mathrm{o}})$  should be rejected. In  $\ell$ -C2ST, these threshold values are obtained via a permutation procedure [13] described in Algorithm 1. This yields  $N_{\mathcal{H}}$  estimates of the test statistic under the null hypothesis and can be used to calculate  $p$ -values for any given  $\alpha$  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_{\mathrm{o}})$  deviates from its theoretical value under the null hypothesis (i.e. one half) as well as  $(1 - \alpha)$  confidence regions; see Algorithm B.1 available in the appendix for more details and Figure 4 for an example.
Algorithm 1:  $\ell$ -C2ST - training the classifier on data from the joint distribution
Input: posterior estimator  $q$  ; calibration data  $\mathcal{D}_{\mathrm{cal}} = \{\Theta_n,X_n\}_{n = 1}^{N_{\mathrm{cal}}}$  classifier  $f$  ; number of samples  $N_{\mathcal{H}}$  from the distribution under the null hypothesis   
Output: estimate  $d$  of the class probabilities; estimates  $\{d_1,\dots ,d_{N_\mathcal{H}}\}$  under the null hypothesis /Construct classification training set \*/   
for  $n = 1,\ldots ,N_{\mathrm{cal}}$  do  $\begin{array}{l}\Theta_n^q\sim q(\theta \mid X_n)\\ W_{2n} = (\Theta_n^q,X_n);C_{2n} = 0/*\\ W_{2n + 1} = (\Theta_n,X_n);C_{2n + 1} = 1/*\\ D\gets \{W_n,C_n\}_{n = 1}^{2N_{\mathrm{cal}}} \end{array}$  \*/   
/\* Get estimate  $d$  of the class probabilities \*/   
Train the classifier  $f$  on  $\mathcal{D}$ $d\gets f_{\mathrm{probability}}$    
/\* Estimate  $d$  under the null hypothesis via permutation procedure \*/   
for  $h = 1,\dots N_{\mathcal{H}}$  do Randomly permute labels  $C_n$  in  $\mathcal{D}$  Train the classifier  $f$  on new  $\mathcal{D}$ $d_h\gets f_{\mathrm{probability}}$    
return  $d;\{d_1,\dots ,d_{N_\mathcal{H}}\}$
Algorithm 2:  $\ell$ -C2ST - evaluating test statistics and  $p$ -values for any  $x_{0}$
Input: Observation  $x_0$ ; estimates  $d$  and  $\{d_1, \ldots, d_{N_{\mathcal{H}}}\}$  obtained in Algorithm 1  
Output: test statistic  $\hat{t}_{\mathrm{MSE}_0}(x_0)$ ; p-value  $\hat{p}(x_0)$   
Generate  $N_v$  samples  $\Theta_n^q \sim q(\theta \mid x_0)$  with predicted probabilities  $d(\Theta_n^q, x_0)$  and  $d_h(\Theta_n^q, x_0)$   
/* Compute test statistics  
 $\hat{t}_{\mathrm{MSE}_0}(x_0) \gets \frac{1}{N_v} \sum_n (d(\Theta_n^q, x_0) - \frac{1}{2})^2$   
for  $h = 1, \ldots, N_{\mathcal{H}}$  do  
 $\left\lfloor \hat{t}_h(x_0) \right\rfloor \leftarrow \frac{1}{N_v} \sum_n (d_h(\Theta_n^q, x_0) - \frac{1}{2})^2$   
/*Compute p-value  
 $\hat{p}(x_0) \gets \frac{1}{N_{\mathcal{H}}} \sum_h \mathbb{I}(\hat{t}_h(x_0) > \hat{t}_{\mathrm{MSE}_0}(x_0))$   
return  $\hat{t}_{\mathrm{MSE}_0}(x_0), \hat{p}(x_0)$
3.1 The case of normalizing flows
The  $\ell$ -C2ST framework can be further improved when the posterior approximation  $q$  is a conditional normalizing flow [37], which we denote  $q_{\phi}$ . Given a Gaussian base distribution  $u(z) = \mathcal{N}(0, I_m)$  and a bijective transform  $T_{\phi}(\cdot; x)$  with Jacobian  $J_{T_{\phi}}(\cdot; x)$  we have
$$
q _ {\phi} (\theta \mid x) = u (z) | \det  J _ {T _ {\phi}} (z; x) | ^ {- 1}, \quad \theta = T _ {\phi} (z; x) \in \mathbb {R} ^ {m}. \tag {13}
$$
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:
$$
Z \sim \mathcal {N} (0, I _ {m}) \Rightarrow \Theta^ {q} = T _ {\phi} (Z; x) \sim q _ {\phi} (\theta \mid x), \tag {14}
$$
$$
q _ {\phi} (\theta \mid x) = u \left(T _ {\phi} ^ {- 1} (\theta ; x)\right) | \det J _ {T _ {\phi} ^ {- 1}} (\theta ; x) |. \tag {15}
$$
Our main observation is that the inverse transform  $T_{\phi}^{-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_{\phi}$  based on a normalizing flow, its local consistency at  $x_{0}$  can be characterized as follows:
$$
p \left(\theta \mid x _ {\mathrm {o}}\right) = q _ {\phi} \left(\theta \mid x _ {\mathrm {o}}\right) \Longleftrightarrow p \left(T _ {\phi} ^ {- 1} \left(\theta ; x _ {\mathrm {o}}\right) \mid x _ {\mathrm {o}}\right) = u (z), \quad \forall \theta \in \mathbb {R} ^ {m}. \tag {16}
$$
Proof. Let  $\Theta \sim p(\theta \mid x_{\mathrm{o}})$ . Following (14), we have that  $\Theta \sim q_{\phi}(\theta \mid x_{\mathrm{o}})$  if, and only if,  $\Theta = T_{\phi}(Z;x_{\mathrm{o}})$  with  $Z \sim \mathcal{N}(0,I_m)$ . Applying the inverse transformation of the flow gives us  $T_{\phi}^{-1}(\Theta ;x_{\mathrm{o}}) = T_{\phi}^{-1}(T_{\phi}(Z;x_{\mathrm{o}});x_{\mathrm{o}}) = Z \sim \mathcal{N}(0,I_m)$ , which concludes the proof.