This last term should be subtracted to get an unbiased estimate of \(\|E_{F_1}(X)-E_{F_2}(X)\|^2_2\).
We see then, that for any feature map \(h:\mathbb{R}^p \rightarrow \mathbb{R}^k\) leading to kernel \(K(x,y)=h(x)^Th(y)\) subtracting this \(W_2\) term yields unbiased estimate of
\[
\|E_{F_1}(h(X))-E_{F_2}(h(X))\|^2_2
\]
Maximum Mean Discrepancy Statistic (MMDS)
When \(K\) is the Gram matrix of a covariance kernel, Gretton et al. (almost) propose \(W_1(G)\) as a two-sample test.
This is almost\(W_1(G;X_1,X_2)\): if \(K\) is bounded by \(C'\), difference is bounded by \(C'/n\).
Easy to analyze their form as it is exactly a two-sample \(U\) statistic (degenerate under \(H_0\)).
MMDS in general
For a class of functions \({\cal F}\) define \[
MMD({\cal F}; F_1, F_2) = \sup_{h \in {\cal F}} E_{F_1}(h(X)) - E_{F_2}(h(X))
\]
When \({\cal H}\) is the unit ball in an RKHS with kernel \(K\) they show \[
MMD({\cal H}; F_1, F_2) = E_{F_1 \times F_1}(K(X,X')) + E_{F_2 \times F_2}(K(X,X')) - 2 E_{F_1 \times F_2}(K(X,X'))
\]
Notation:\(E_{F \times G}[h(X,X')]\) denotes expectation under \((X,X') \sim F \times G\).
Statistic of Gretton et al. is an estimator of \(MMD({\cal H}; F_1, F_2)\).
Using kernel property, it is not hard to see that the analog of (rescaled) \(\text{Tr}(XX^TP^{\Delta})\) is given by
Like \(\widehat{MMD}({\cal H}; X_1, X_2)\) but includes this \(W_2\) term…
kernlab
library(kernlab)kmmd(X_1, X_2)
Using automatic sigma estimation (sigest) for RBF or laplace kernel
Kernel Maximum Mean Discrepancy object of class "kmmd"
Gaussian Radial Basis kernel function.
Hyperparameter : sigma = 2.84092523252973e-06
H0 Hypothesis rejected : TRUE
Rademacher bound : 0.444461696552373
1st and 3rd order MMD Statistics : 0.901533156324329 0.643766182287887
kmmd(X_1, X_2, kernel='vanilladot', kpar=list())
Kernel Maximum Mean Discrepancy object of class "kmmd"
Linear (vanilla) kernel function.
H0 Hypothesis rejected : FALSE
Rademacher bound : 3760.42987748469
1st and 3rd order MMD Statistics : 798.276202069945 399126.145253863
Energy statistics
Energy statistics
We saw that Hotelling’s \(T^2\) test is essentially determined by an \(n \times n\) (case) similarity matrix \(G\):
\[
\text{Tr}(P^{\Delta}GP^{\Delta})
\]
A simple way to construct a similarity matrix is from a distance matrix \(D_{ij} = d(X_i, X_j)\) and setting
\[
S = \kappa I - D
\]
Noting that \(\text{Tr}(P^{\Delta}) = 1\) suggests simply using
Create label \[
Y = \begin{pmatrix} 1_{n_1} \\ 2_{n_2} \end{pmatrix}
\] and form D=cbind(Y, X)
Split D randomly up in to D_test and D_train in such a way that for test data the number of cases from X_1 matches that of X_2. Let n_test denote the total number of cases of each held out.
Fit a classifier \(\hat{C}\) on cbind(X_train, Y_train), and evaluate its classification accuracy on cbind(X_test, Y_test).
Under \(H_0:F_1=F_2\), conditional on D_train the accuracy has (approximate) distribution \[
\frac{1}{n_{test}} \text{Binomial}\left(n_{test}, \frac{1}{2} \right).
\] (This seems easiest to justify when \(X_i\) are simple random samples from large populations – in this case given case \(x\) is selected a Bernoulli(1/2) determines which sample it finds itself in.)