KSD Aggregated Goodness-of-ﬁt Test
Abstract
We investigate properties of goodness-of-ﬁt tests based on the Kernel Stein Discrepancy (KSD).
We introduce a strategy to construct a test, called KSDA GG , which aggregates multiple tests with different kernels.
KSDA GG avoids splitting the data to perform kernel selection (which leads to a loss in test power), and rather maximises the test power over a collection of kernels.
We provide non-asymptotic guarantees on the power of KSDA GG : we show it achieves the smallest uniform separation rate of the collection, up to a logarithmic term.
For compactly supported densities with bounded model score function, we derive the rate for KSDA GG over restricted Sobolev balls; this rate corresponds to the minimax optimal rate over unrestricted Sobolev balls, up to an iterated logarithmic term.
KSDA GG can be computed exactly in practice as it relies either on a parametric bootstrap or on a wild bootstrap to estimate the quantiles and the level corrections.
In particular, for the crucial choice of bandwidth of a ﬁxed kernel, it avoids resorting to arbitrary heuristics (such as median or standard deviation) or to data splitting.
We ﬁnd on both synthetic and real-world data that KSDA GG outperforms other state-of-the-art quadratic-time adaptive KSD-based goodness-of-ﬁt testing procedures.
Introduction
Kernel selection remains a fundamental problem in kernel-based nonparametric hypothesis testing, as it signiﬁcantly impacts the test power.
Kernel selection has attracted a signiﬁcant interest in the literature and a number of methods have been proposed in the two-sample, independence and goodness-of-ﬁt testing frameworks, such as using heuristics (Gretton et al., 2012a), relying on data splitting (Gretton et al., 2012b;
Sutherland et al., 2017; Kübler et al., 2022), learning deep kernels (Grathwohl et al., 2020; Liu et al., 2020), working in the post-selection inference framework (Yamada et al., 2019; Lim et al., 2019, 2020; Kübler et al., 2020;
Freidling et al., 2021), to name but a few.
In this work, we focus on aggregated tests, which have been investigated for the two-sample problem by Fromont et al.
(2013), Kim et al.
(2022) and Schrab et al.
(2021) using the Maximum Mean
Discrepancy (MMD; Gretton et al., 2012a), and for the independence problem by Albert et al. (2022) and Kim et al.
using the Hilbert Schmidt Independence Criterion (HSIC; Gretton et al., 2005).
We extend the use of aggregated tests to the goodness-of-ﬁt setting, where we are given a model and some samples, and test whether the samples have been drawn from the model.
We employ the Kernel
Stein Discrepancy (KSD; Chwialkowski et al., 2016; Liu et al., 2016) as our test statistic, which is an ideal measure of distance for this setting: it admits an estimator which can be computed without requiring samples from the model, and does not require the model to be normalised.
To the best of our knowledge, ours represents the ﬁrst aggregation procedure for the KSD test in the literature.
Related work.
Fromont et al.
(2012, 2013) introduced non-asymptotic aggregated tests for the two-sample problem with sample sizes following a Poisson process, using an unscaled version of the MMD.
Using a wild bootstrap, they derived uniform separation rates (Ingster, 1987, 1989, 1993a,b; Baraud, 2002).
Albert et al.
(2022) then proposed an independence aggregated test using the HSIC, with guarantees using a theoretical quantile, but relying on permutations to obtain the test threshold in practice.
Kim et al.
(2022) then extended those theoretical results to also hold for the quantile estimated using permutations, however, they did not obtain the desired level dependency in their HSIC bound.
All those aforementioned results were proved for the Gaussian kernel only.
Schrab et al.
(2021) generalised the two-sample results to hold for the usual MMD estimator and for a wide range of kernels using either a wild bootstrap or permutations, and provided optimality results which hold with fewer restrictions.
Our work builds and extends on the above non-asymptotic results: we consider the goodness-of-ﬁt framework, where we have samples from only one of the two densities.
The main challenges arise from working with the Stein kernel which deﬁnes the KSD test statistic: for example, we lose the transition-invariant property of the kernel which is crucial to work in the Fourier domain.
Balasubramanian et al.
(2021) considered adaptive MMD-based goodness-of-ﬁt tests and obtained their uniform separation rates over Sobolev balls in the asymptotic regime.
More generally, Li and Yuan (2019) studied asymptotic adaptive kernel-based tests for the three testing frameworks.
Tolstikhin et al.
(2016) derived minimax rates for MMD estimators using radial universal kernel (Sriperumbudur et al., 2011).
Schrab et al.
(2022) extends this work, together with those of Albert et al.
(2022) and Schrab et al.
(2021), to construct efﬁcient aggregated tests for the three testing frameworks using incomplete U -statistics.
They quantify the cost in the minimax rate over Sobolev balls incurred for computational efﬁciency, and prove minimax optimality of the quadratic-time HSIC permuted aggregated test by improving the bound of Kim et al.
See Appendix C for details.
Contributions.
We propose a solution to the fundamental kernel selection problem for the widelyused KSD goodness-of-ﬁt tests: we construct an adaptive test KSDA GG which aggregates multiple tests with different kernels.
Our contribution is in showing, both theoretically and experimentally, that the aggregation procedure works in this novel setting in which it has never been considered before.
We work in the kernel selection framework; this general setting has many applications including the one of kernel bandwidth selection.
Our aggregated test allows for two numerical methods for estimating the test thresholds: the wild bootstrap and the parametric bootstrap (a procedure unique to the goodness-of-ﬁt framework).
We conduct a theoretical analysis: we derive a general condition which guarantees test power for KSDA GG in terms of its uniform separation rate, with extra assumptions including regularity over restricted Sobolev balls we prove that KSDA GG attains the minimax rate over (unrestricted) Sobolev balls.
We discuss the implementation of KSDA GG and experimentally validate our proposed approach on benchmark problems, not only on datasets classically used in the literature but also on original data obtained using state-of-the-art generative models ( i.e. Normalizing
Flows).
We observe, both on synthetic and real-world data, that KSDA GG obtains higher power than other KSD-based adaptive state-of-the-art tests.
Contributing to the real-world applications of these goodness-of-ﬁt tests, we provide publicly available code to allow practitioners to employ our method: https://github.com/antoninschrab/ksdagg-paper .
Notation
We consider the goodness-of-ﬁt problem where given access to a known model probability density p (which can be unnormalised since we actually only need access to its score function r log p ( · ) ) and to some i.i.d.
d -dimensional samples X N :=
( X i )
Ni =1 drawn from an unknown data density q , we want to decide whether p 6 = q holds.
This can be expressed as a statistical hypothesis testing problem with null hypothesis H 0 : p = q and alternative H a : p 6 = q .
As a measure of distance between p and q , we use the Kernel Stein Discrepancy (KSD) introduced by
Chwialkowski et al.
(2016) and Liu et al.
For a kernel k , the KSD is the Maximum Mean
Discrepancy (MMD; Gretton et al., 2012a) between p and q using the Stein kernel associated to k
KSD 2 p,k ( q ) :
= MMD 2 h p,k ( p, q ) :=
E q,q [ h p,k ( X, Y )]  2 E p,q [ h p,k ( X, Y )] + E p,p [ h p,k ( X, Y )]
=
E q,q [ h p,k ( X, Y )] where the Stein kernel h p,k : R d ⇥ R d ! R is deﬁned as
[Equation]
and satisﬁes the Stein identity E p [ h p,k ( X, · )]
= 0 .
Additional background details on the KSD are presented in Appendix C. A quadratic-time KSD estimator can be computed as the U -statistic
(Hoeffding, 1992)
[Equation]
In this work, the score of the model density p is always known, we do not always explicitly write the dependence on p of all the variables we consider.
We assume that the kernel k is such that
[Equation]
We now address the requirements for consistency ( i.e. test power converges to 1 as the sample size goes to 1 ) of the Stein test (Chwialkowski et al., 2016, Theorem 2.2): we assume that the kernel k is
C 0 -universal (Carmeli et al., 2010, Deﬁnition 4.1) and that E q
[Equation]
We use the notations P p and P q to denote the probability under the model distribution p and under the data distribution q , respectively.
Given a kernel  : R d ⇥ R d !
R and a function f : R d ! R in L R d  , we consider the integral transform T  deﬁned as
[Equation]
for y 2 R d .
When the kernel  is translation-invariant, the integral transform corresponds to a convolution.
However, the lack of translation invariance of the Stein kernel introduces new challenging problems.
First, working the integral transform of the Stein kernel is more complicated since it does not correspond to a simple convolution.
Second, for the expectation of the Stein kernel squared, C k :=
E q,q [ h p,k ( X, Y ) 2 ] , it is not possible to extract the bandwidth parameter  outside of the expectation as it is the case when using the usual kernel directly as for the MMD and HSIC.
Construction of tests and bounds
We now introduce the single and aggregated KSD tests.
We show that these control the probability of type I error as desired, and provide conditions for the control of the probability of type II error.
3.1 Single test
We ﬁrst construct a KSD test for a ﬁxed kernel k as proposed by Chwialkowski et al.
(2016) and Liu et al.
To estimate the test threshold, we can either use a wild bootstrap (Shao, 2010; Leucht and Neumann, 2013; Fromont et al., 2012;
Chwialkowski et al., 2014) or a parametric bootstrap (Stute et al., 1993).
Both methods work by simulating sampling values  ¯ K 1 k , . . .
, ¯ K B 1 k  from the (asymptotic) distribution of [ KSD 2 p,k under the null hypothesis and estimating the (1  ↵ ) -quantile for ↵ 2 (0 , 1) using a Monte Carlo approximation
[Equation]
where ¯ K • 1 k  · · ·  ¯ K • B 1 +1 k are the sorted elements
[Equation]  with ¯ K B [Equation] +
[Equation] := [ KSD 2 p,k ( X N ) .
The single test is then deﬁned as (a test function outputs 1 when the null is rejected and 0 otherwise)
[Equation]
For the parametric bootstrap , we directly draw new samples ( X 0 i )
Ni
=1 from the model distribution p (it might not always be possible to so) and compute the KSD
[Equation]
For the wild bootstrap , we ﬁrst generate n i.i.d.
Rademacher random variables ✏ 1 , . . . , ✏ n , each taking value in {  1 , 1 } , and then compute
[Equation]
By repeating either procedure B 1 times, we obtain the bootstrapped samples ¯ K 1 k , . . . , ¯ K B 1 k .
Since it uses samples from the model p , the parametric bootstrap (Stute et al., 1993) results in a test with non-asymptotic level ↵ .
This comes at the cost of being computationally more expensive and assuming that we are able to sample from p (which may be out of reach in some settings).
Conversely, the wild bootstrap has the advantage of not requiring to sample from p , which makes it computationally more efﬁcient as only one kernel matrix needs to be computed, but it only achieves the desired level ↵ asymptotically (Shao, 2010; Leucht and Neumann, 2013; Leucht, 2012;
Chwialkowski et al., 2014, 2016) assuming Lipschitz continuity of h p,k
(see Appendix D for details).
Note that we cannot obtain a non-asymptotic level for the wild bootstrap by relying on the result of
Romano and Wolf (2005, Lemma 1) as done in the two-sample framework by Fromont et al.
(2013) and Schrab et al.
This is because in our case ¯ K k and [ KSD 2 p,k ( X N ) are not exchangeable variables under the null hypothesis, due to the asymmetry of the KSD statistic with respect to p and q .
Having discussed control of the probability of type I error of the single test  k ↵ , we now provide a condition on k p  q k 2 which ensures that the probability of type II error is controlled by some  2 (0 , 1) .
The smallest such value of k p  q k 2 , provided that p  q lies in some given class of regular functions, is called the uniform separation rate (Ingster, 1987, 1989, 1993a,b; Baraud, 2002).
Theorem 3.1.
Suppose the assumptions listed in Appendix A.2 hold, and let :=
p  q .
There exists a positive constant C such that the condition
[Equation]
guarantees control over the probability of type II error, such that P q
[Equation]
Theorem 3.1, which is proved in Appendix I.1, provides a power guaranteeing condition consisting of two terms.
The ﬁrst term k  T h p,k k 22 indicates the size of the effect of the Stein integral transform operator on the difference in densities :
= p  q , it is a measure of distance from the null (where this quantity is zero).
The second term C log  1 / ↵  (  N )  1 p C k is obtained from upper bounding the variance of the KSD U -statistic, it depends on the expectation of the squared Stein kernel C k :=
E q,q [ h p,k ( X, Y ) 2 ] .
This second term also controls the quantile of the test.
3.2 Aggregated test
We can now introduce our aggregated test, which is motivated by the earlier works of Fromont et al.
(2012, 2013), Albert et al.
(2022), and Schrab et al.
(2021) for two-sample and independence testing.
We compute e K 1 k , . .
, e K B 2 k further KSD values simulated from the null hypothesis obtained using either a parametric bootstrap or a wild bootstrap as in Equations (4) or (5), respectively.
We consider a ﬁnite collection K of kernels satisfying the properties presented in Section 2.
We construct an aggregated test  K ↵ , called KSDA GG , which rejects the null hypothesis if one of the single tests   ku ↵ w k
k 2 K rejects it, that is
[Equation]
The levels of the single tests are adjusted to ensure the aggregated test has the prescribed level ↵ .
This adjustment is performed by introducing positive weights ( w k ) k 2 K satisfying
P k 2 K w k  1 and some correction
[Equation]
Algorithm 1 KSDA Inputs: samples X N = ( x i ) Ni =1 , density p or score r log p ( · ) , ﬁnite kernel collection K , weights ( w k ) k 2 K , level ↵ 2 (0 , e  1 ) , estimation parameters B 1 , B 2 , B 3 2 N , parametric or wild bootstrap
Output: 0 (fail to reject H 0 ) or 1 (reject H 0 )
Algorithm: for k 2 K do compute ¯ K B 1 +1 k :=
[ KSD 2 p,k ( X N ) as in Equation (1) compute
¯ K bk  1  b  B 1 as in Equations (4) or (5) {+sort  ¯ K bk  1  b  B 
 +
+}
in ascending order to obtain  ¯ K • bk  1  b  B {+1 + compute  e K bk  
+}
 b  B 2 as in Equations (4) or (5) u min = 0 , u max = min
k 2 K w  1 k for t = 1 , . . .
, B 3 do u = 12 ( u min + u max ) , b
P u = 1 B
B
X b =1 ✓ max k 2 K ⇣e
K bk  ¯ K • d ( B 1 +1)(1  uw k ) e k ⌘ >◆ if b
P u  ↵ then u min =
u else u max = u u ↵ = u min if max k 2 K ⇣ [ KSD [Equation] [Equation]
( X N )  ¯ K • d ( B 1 +1)(1  u ↵ w k ) e k ⌘ > 0 then return 1 else return
Time complexity: O  |K| [Equation] + B
[Equation]
) N where [Equation] ⌘ >◆ is a Monte Carlo approximation of the type I error probability of the aggregated test with correction u P
[Equation]
To compute u ↵ , we estimate the supremum in Equation (6) by performing B 3 steps of the bisection method, the theoretical results account for this extra approximation.
Detailed pseudocode for KSDA GG is provided in Algorithm 1, and details regarding our aggregation procedure are provided in Appendix G.
We discuss potential limitations of KSDAgg in Appendix H.
We verify in the next proposition that performing this correction indeed ensures that our aggregated test  K ↵ has the prescribed level ↵ .
Proposition 3.2.
For ↵ 2 (0 , 1) and a collection of kernels K , the aggregated test  K ↵ satisﬁes
[Equation]
asymptotically using a wild bootstrap (with Lipschitz continuity of h p,k required) and nonasymptotically using a parametric bootstrap.
The proof of Proposition 3.2 is presented in Appendix I.2.
Details about the asymptotic result for the wild bootstrap case are reported in Appendix D.
We now provide guarantees for the power of our aggregated test KSDA GG in terms of its uniform separation rate.
Theorem 3.3.
Suppose the assumptions listed in Appendix A.3 hold, and let := p  q .
There exists a positive constant C such that if
[Equation]
then the probability of type II error of  K ↵ is controlled by  , that is, P q
[Equation]
The proof Theorem 3.3 can be found in Appendix I.3, it relies on upper bounding the probability of the intersection of some events by the minimum of the probabilities of each event, and on applying
Theorem 3.1 after having veriﬁed that its assumptions are satisﬁed for the tests with adjusted levels.
We observe that the aggregation procedure allows to achieve the smallest uniform separation rate of the single tests [Equation] K up to some logarithmic weighting term log(1 /w k ) .
3.3 Bandwidth selection
A speciﬁc application of the setting we have considered is the problem of bandwidth selection for a ﬁxed kernel.
Given a kernel k : R d ⇥ R d ! R , the function
[Equation]
is also a kernel for any bandwidth  > 0 .
A common example is the Gaussian kernel, for which we have k ( x, y ) =
exp( k x  y k 22 ) and k  ( x, y ) = exp   k x  y k  .
As shown by Gorham and Mackey (2017), a more appropriate kernel for goodness-of-ﬁt testing using the KSD is the
IMQ (inverse multiquadric) kernel, which is deﬁned with k ( x, y ) = ⇣ 1 + k x  y k⌘ [Equation] k for a ﬁxed parameter  k 2 (0 , 1) as
[Equation]
which is the well-known form of the IMQ kernel with parameters  > 0 and  k 2 (0 , 1) .
Note that it is justiﬁed to consider the kernel up to a multiplicative constant because the single and aggregated tests are invariant under this kernel transformation.
In practice, as suggested by Gretton et al.
(2012a)
, the bandwidth is often set to a heuristic such as the median or the standard deviation of the L 2 -distances between the samples ( X i )
Ni =1 , however, these are arbitrary choices with no theoretical guarantees.
Another common approach proposed by Gretton et al.
(2012b) for the linear-time setting, and extended to the quadratic-time setting by Liu et al.
(2020), is to resort to data splitting in order to select a bandwidth on held-out data, by maximising for a proxy for asymptotic power (see Section 4.1 for details).
Both methods were originally proposed for the two-sample problem, but extend straightforwardly to the goodness-of-ﬁt setting.
By considering a kernel collection K ⇤ = { k  :  2 ⇤ } for a collection of bandwidths ⇤ , we can use our aggregated test KSDA GG to test multiple bandwidths using all the data and without resorting to arbitrary heuristics.
We now obtain an expression for the uniform separation rate of  K ⇤ ↵ in terms of the bandwidths  2 ⇤ .
Corollary 3.4.
Suppose the assumptions listed in Appendix A.3 hold for K = K ⇤ =
{ k  :  2 ⇤ } , and let := p  q .
There exists a positive constant C such that the condition
[Equation]
ensures control over the probability of type II error of the aggregated test P q
[Equation]
Corollary 3.4 follows from applying Theorem 3.3 to the collection of kernels K ⇤ .
Our results hold with great generality as we have not imposed any restrictions on :=
p  q such as assuming it belongs to a speciﬁc regularity class.
For this reason, the dependence on  in the terms k  T h p,k  k 22 and log  [Equation] / ( ↵ [Equation]
[Equation]
[Equation]  [Equation]
p
C k  is not explicit.
In Section 3.4, we characterise this dependence with regularity assumptions on :=
p  q , and derive uniform seperation rates in terms of the sample size.
3.4 Uniform separation rates over restricted Sobolev balls
In this section, we derive uniform separation rates with stronger assumptions on p and q .
This provides settings in which the power guaranteeing conditions of Theorems 3.1 and 3.3 are satisﬁed, and illustrates the interactions between the two terms in those conditions.
We make the following assumptions.
• The model density p is strictly positive on its connected and compact support S ✓ R d .
The score function r log p ( x ) is continuous and bounded on S .
• The support of the density q is a connected and compact subset of S .
The kernel used is a scaled Gaussian kernel k
[Equation]
In particular, any strictly positive twice-differentiable density on R d truncated to some d -dimensional interval will satisfy the assumptions for the model p .
Any density truncated to the same d -dimensional interval will satisfy the assumption for the density q .
As an example, one can consider truncated normal densities.
Given some smoothness parameter s > 0 , radius R > 0 and dimension d 2 N \ { 0 } , the Sobolev ball S sd ( R ) is deﬁned as the function space
[Equation]
where b f denotes the Fourier transform of f .
For s, t, d, R, L all strictly positive, we deﬁne the restricted Sobolev ball S s,td ( R, L ) as containing all functions f 2 S sd ( R ) satisfying [Equation]
[Equation]
With the Sobolev assumption p  q 2 S sd ( R ) , the densities p and q can differ at any frequencies.
The restricted Sobolev assumption p  q 2 S s,td
( R, L ) does not include the case in which the densities p and q differ only at low frequencies due to the additional restriction in Equation (8).
Theorem 3.5.
Suppose the assumptions listed in Appendix A.4 hold for K ⇤ = { k  :  2 ⇤ } .
Let :=
p  q .
We show that there exists some L > 0 such that if p  q 2 S s,td ( R, L ) then (i) & (ii) hold.
(i) Under the assumptions of Theorem 3.1, for the KSD test with bandwidth  :=
N  2 / (4 s + d ) , the condition
[Equation]
for some C > 0 guarantees control over the probability of type II error P q
[Equation]
(ii) Under the assumptions of Theorem 3.3, for KSDA GG with the collection
[Equation]
and weights w  := 6 / ⇡ 2 ` 2 , we have P q [Equation]  provided that, for some C > 0 ,
[Equation]
The proof of Theorem 3.5 is presented in Appendix I.4.
The uniform separation rate N  4 s/ (4 s + d ) in
Theorem 3.5 is known to be optimal in the minimax sense over (unrestricted)
Sobolev balls S sd ( R ) (Li and Yuan, 2019; Balasubramanian et al., 2021;
Albert et al., 2022; Schrab et al., 2021).
However, this rate is for the KSD test with bandwidth depending on the smoothness parameter s > 0 which is unknown in practice.
Note that even methods which split the data to perform kernel selection are not able to select this bandwidth depending on s and cannot achieve the minimax rate.
The aggregation procedure is adaptive to this unknown parameter s : crucially, the collection of bandwidths ⇤ does not depend on s , and so, the aggregated KSDA GG test of Theorem 3.5 (ii) can be implemented in practice, unlike the single KSD test of Theorem 3.5 (i).
The price to pay for this adaptivity is only an iterated logarithmic factor in the minimax rate over Sobolev balls S sd ( R ) .
The uniform separation rates presented in Theorem 3.5 are over the restricted Sobolev balls S s,td ( R, L ) .
Whether those rates can also be derived under less restrictive assumptions and in the more general setting of (unrestricted)
Sobolev balls S sd ( R ) , is a challenging problem, which is left for future work.
Implementation and experiments
We consider three different experiments based on a Gamma one-dimensional distribution, a GaussianBernoulli Restricted Boltzmann Machine, and a Normalizing Flow for the MNIST dataset.
We compare our proposed aggregated test KSDA GG against three alternatives: the KSD test which uses the median bandwidth, a test which splits the data to select an ‘optimal’ bandwidth according to a proxy for asymptotic test power, and a test which uses extra data for bandwidth selection.
The ‘extra data’ test is designed simply to provide a best-case scenario for the bandwidth selection procedure which maximises asymptotic test power, but it cannot be used in practice as it has access to extra data compared to the other tests.
In order to ensure that our tests always have correct levels for all bandwidth values, dimensions and sample sizes, we use the parametric bootstrap in our experiments.
4.1 Alternative bandwidth selection approaches
Gretton et al.
(2012a) proposed to use the median heuristic as kernel bandwidth, it consists in the median of the L 2 -distances between the samples given by
[Equation]
Gretton et al.
(2012b)
ﬁrst proposed, for the two-sample problem using a linear-time MMD estimator, to split the data and to use half of it to select an ‘optimal’ bandwidth which maximises a proxy for asymptotic power.
This procedure was extended to quadratic-time estimators and to the goodnessof-ﬁt framework by Jitkrittum et al.
(2017), Sutherland et al.
(2017) and Liu et al.
These strategies rely on the asymptotic normality of the test statistic under H a .
In our setting, the asymptotic power proxy to maximise is the ratio
[Equation]
where b  2 H a is a closed-form regularised positive estimator of the asymptotic variance of [ KSD 2 p,k under H a (Liu et al., 2020, Equation 5).
In our experiments, we also consider a test which has access to N extra samples drawn from q to select an ‘optimal’ bandwidth to run the KSD test on the original
N samples X N .
This test is interesting to compare to because it uses an ‘optimal’ bandwidth without being detrimental to power (as it uses all N samples X N to run the test with the selected bandwidth).
4.2 Experimental details
Inspired from Theorem 3.5, in each experiments, we use KSDA GG with different collections of bandwidths of the form ⇤ ( `  , ` + ) :
= [-(cid:8) 
-] [Equation]
med : i = `  , . . .
, ` + for the median bandwidth  med and integers `  < ` + with uniform weights w  := 1 / ( ` +  `  + 1) .
For the tests which split the data, we select the bandwidth, out of the collection ⇤ ( `  , ` + ) , which maximises the power proxy discussed in Section 4.1.
All our experiments are run with level ↵ = 0 .
05 using the IMQ kernel deﬁned in Equation (7) with parameter  k = 0 .
We use a parametric bootstrap with B 1 = B 2 =bootstrapped KSD values to compute the adjusted test thresholds, and B 3 = 50 steps of bisection method to estimate the correction u ↵ in Equation (6).
For our aggregated test, we have also designed another collection which is parameter-free (no varying parameters across experiments) and performs as well as the previous variant whose parameters are chosen appropriately for each experiments.
The collection is obtained using the maximal inter-sample distance normalised by the dimension (see details in Appendix B).
We denote the resulting robust test by KSDA GG ?
for which we use either a wild or parametric bootstrap with B 1 = B 2 = 2000 and B 3 = 50 , this is the variant we recommend using in practice.
To estimate the probability of rejecting the null hypothesis, we average the test outputs across 200 repetitions.
All experiments have been run on an AMD Ryzen Threadripper 3960X 24 Cores 128Gb RAM CPU at 3.8GHz, the runtime is of the order of a couple of hours (signiﬁcant speedup can be obtained by using parallel computing).
We have used the implementation of Jitkrittum et al.
(2017) to sample from a Gaussian-Bernoulli Restricted Boltzmann Machine, and Phillip Lippe’s implementation of MNIST Normalizing Flows, both under the MIT license.
4.3 Gamma distribution
For our ﬁrst experiment, we consider a one-dimensional Gamma distribution with shape parameterand scale parameter 5 as the model p .
For q , we draw 500 samples from a Gamma distribution with the same scale parameter 5 and with a shifted shape parameter 5 + s for s 2 { 0 , 0 . 1 , 0 . 2 , 0 . 3 , 0 . 4 } .
We consider the collection of bandwidths ⇤ (0 , 10) .
The results we obtained are presented in Figure 1a.
We observe that all tests have the prescribed level 0.05 under the null hypothesis, which corresponds to the case s = 0 .
As the shift parameter s increases, the two densities p and q become more different and rejection of the null becomes an easier task, thus the test power increases.
Our aggregated test KSDA GG achieves the same power as the KSD test with an ‘optimal’ bandwidth selected using extra data by maximizing the proxy for asymptotic power.
The median test obtains only slightly lower power, this closeness in power can be explained by the fact that this one-dimensional problem is a simple one.
All four tests KSDA GG ⇤ (0 , 10) , KSDA GG ? , KSD median, and KSD split, all achieve very similar power.
We note that the normal splitting test has signiﬁcantly lower power: this is because, even though it uses an ‘optimal’ bandwidth, it is then run on only half the data, which results in a loss of power. {+4 Shape parameter shift s 0 .0 .0 .
 P r o b a b ili t y o f r e j ec t i n g H+}
KSDAgg ⇤ (0 , 10)
KSDAgg ?
{+KSD split extra data KSD median KSD split (a) 0 .0 .0 .0 . 03 Perturbation standard deviation  0 .0 .0 .
+}
P r o b a b ili t y o f r e j ec t i n g
H
KSDAgg ⇤ (  20 , 0) KSDAgg ?
KSD split extra data
KSD median
KSD split (b)
4.4 Gaussian-Bernoulli Restricted Boltzmann Machine
As ﬁrst considered by Liu et al.
(2016) for goodness-of-ﬁt testing using the KSD, we consider a
Gaussian-Bernoulli Restricted Boltzmann Machine.
It is a graphical model with a binary hidden variable h 2 {  1 , 1 } d h and a continuous observable variable x 2 R d .
Those variables have joint density
[Equation]
◆ where Z is an unknown normalizing constant.
By marginalising over h , we obtain the density p of x
[Equation]
We can sample from it using a Gibbs sampler with 2000 burn-in iterations.
We use the dimensions d = 50 and d h = 40 as considered by Jitkrittum et al.
(2017) and Grathwohl et al.
Even though computing p is intractable for large dimension d h , the score function admits a convenient closed-form expression
[Equation]
We draw the components of b and c from Gaussian standard distributions and sample Rademacher variables taking values in {  1 , 1 } for the elements of B for the model p .
We draw 1000 samples from a distribution q which is constructed in a similar way as p but with the difference that
some
Gaussian noise N (0 ,  ) is injected into each of the elements of B .
For the standard deviations of the perturbations, we consider  2 { 0 , 0 . 01 , 0 .
We use the collection ⇤ (  20 , 0) (different from Section 4.3), for KSDA GG ?
we use a wild bootstrap, the results are provided in Figure 1b.
Again, we observe that our aggregated tests KSDA GG ⇤ (0 , 20) and KSDA GG ? match the power obtained by the test which uses extra data to select an ‘optimal’ bandwidth.
This means that, in this experiment, the aggregated tests obtain the same power as the ‘best’ single test.
The difference with the median heuristic test is signiﬁcant in this experiment, and the splitting test obtains the lowest power of the four tests.
Again, all tests have well-calibrated levels (case  = 0 ) and increasing the noise level  results in more power for all the tests.
4.5 MNIST Normalizing Flow
Finally, we consider a high-dimensional problem working with images in dimensions 28 2 = 784 .
We consider a multi-scale Normalizing Flow (Dinh et al., 2017; Kingma and Dhariwal, 2018) which has been trained on the MNIST dataset (LeCun et al., 1998, 2010), it is a generative model which has a [Figure] probability density p .
As observed in Figure 2, some samples produced by the model can look exactly like MNIST digits, while others do not resemble digits.
This Normalizing Flow has been trained to ‘ideally’ produce samples from the MNIST dataset.
We are interested in whether or not we can detect the difference in densities.
Given some images of digits, are we able to tell if those were sampled from the Normalizing Flow model?
We consider the case where the samples from q are drawn from the true MNIST dataset (power experiment), and the case where the images from q are sampled from the Normalizing Flow model (level experiment, conﬁrming performance for the power experiment).
The experiments are run with the collection of bandwidths ⇤ (  20 , 0) .
The results are displayed in Figure 3a and Figure 3b.
We use a parametric bootstrap for KSDA GG ? . In Figure 3a, we observe that the four tests have correct levels (around 0.05) for the ﬁve different sample sizes considered (the small ﬂuctuations about the designed test level can be explained by the fact that we are averaging 200 test outputs to estimate these levels).
The well-calibrated levels obtained in Figure 3a demonstrate the validity of the power results presented in Figure 3b.
As seen in Figure 3b, only our aggregated tests KSDA GG and KSDA GG ? obtain high power; they are able to detect that MNIST samples are not drawn from the Normalizing Flow.
The power of the other tests increases only marginally as the sample size increases.
The test which uses extra data to select an ‘optimal’ bandwidth performs poorly when compared to the aggregated tests.
This could be explained by the fact that this test selects the bandwidth using a proxy for the asymptotic power, and that in this high-dimensional setting, the asymptotic regime is not attained with sample sizes below 500.
See Appendices E and F for details regarding selected bandwidths and for reported runtimes.
[Figure]
[Figure]
[-= (cid:8) 
-]
Acknowledgements
Antonin Schrab acknowledges support from the U.K. Research and Innovation (EP/S021566/1).
Benjamin Guedj acknowledges partial support by the U.S. Army Research Laboratory and the U.S.
Army Research Ofﬁce, and by the U.K. Ministry of Defence and the U.K. Engineering and Physical
Sciences Research Council (EP/R013616/1), and by the French National Agency for Research (ANR-18-CE40-0016-01 & ANR-18-CE23-0015-02).
Arthur Gretton acknowledges support from the Gatsby Charitable Foundation.
[-ψ − T ¯ k λ ψ (cid:13)(cid:13) 2 
-]
[-(cid:13)(cid:13) (cid:98) ψ (cid:13)(cid:13) 
-]