From Scalar Covariance to Kernel Cross-Covariance
For scalar random variables, covariance summarizes linear association. When observations are vectors or have more complex structure, one can instead map each observation into a feature space and measure covariance there. The Hilbert–Schmidt independence criterion, or HSIC, is the squared size of the resulting cross-covariance operator. It is therefore a nonnegative measure of dependence in the chosen feature spaces, with a population definition and a direct empirical Gram-matrix form.
The definition itself does not guarantee that HSIC detects every possible dependence. That depends on properties of the kernels, considered separately in the study of characteristic kernels. Here the focus is the operator definition, its kernel expression, and the exact relationship to a centered Gram-matrix statistic.
Feature Maps and the Cross-Covariance Operator
Let \(X\) and \(Y\) be random elements taking values in measurable spaces \(\mathcal X\) and \(\mathcal Y\). Let \(k\) and \(l\) be measurable, real-valued positive definite kernels on those spaces, with reproducing-kernel Hilbert spaces (RKHSs) \(\mathcal H\) and \(\mathcal G\). Write their feature maps as \(\phi(x)=k(x,\cdot)\) and \(\psi(y)=l(y,\cdot)\). The reproducing property gives \(k(x,x')=\langle\phi(x),\phi(x')\rangle_{\mathcal H}\), and likewise for \(l\).
Assume the feature maps are strongly measurable, the RKHSs are separable, and \(E[k(X,X)]<\infty\) and \(E[l(Y,Y)]<\infty\). These moment conditions ensure that the feature means exist as Bochner expectations. Define \(\mu_X=E[\phi(X)]\), \(\mu_Y=E[\psi(Y)]\), and the centered features \(\tilde\phi(X)=\phi(X)-\mu_X\), \(\tilde\psi(Y)=\psi(Y)-\mu_Y\).
The operator is well-defined under the stated conditions. Indeed, \(E\|\tilde\phi(X)\|_{\mathcal H}^2<\infty\) and \(E\|\tilde\psi(Y)\|_{\mathcal G}^2<\infty\). By Cauchy–Schwarz, \(E[\|\tilde\phi(X)\|\|\tilde\psi(Y)\|]\leq \{E\|\tilde\phi(X)\|^2 E\|\tilde\psi(Y)\|^2\}^{1/2}<\infty\). Thus the rank-one operator inside the expectation has integrable Hilbert–Schmidt norm.
For \(f\in\mathcal H\) and \(g\in\mathcal G\), the operator connects centered feature values to scalar covariance: $$ \langle f,C_{XY}g\rangle_{\mathcal H} =E[\langle f,\tilde\phi(X)\rangle_{\mathcal H} \langle g,\tilde\psi(Y)\rangle_{\mathcal G}]. $$ So \(C_{XY}\) collects covariances between all pairs of linear functionals of the two feature maps. HSIC squares and sums these covariances in an orthonormal-basis-independent way.
Worked Example: Linear Kernels Recover Squared Covariance
Take real-valued \(X,Y\) with finite second moments, and use the linear kernels \(k(x,x')=xx'\) and \(l(y,y')=yy'\). Their feature maps are the identity maps into one-dimensional Hilbert spaces. The cross-covariance operator is therefore multiplication by \(\operatorname{Cov}(X,Y)\), so $$ \operatorname{HSIC}(P_{XY};k,l)=\operatorname{Cov}(X,Y)^2. $$
For a numerical case, let \(X\) be Bernoulli with \(P(X=1)=P(X=0)=1/2\), and set \(Y=X\). Then \(E[X]=E[Y]=1/2\), \(E[XY]=E[X^2]=1/2\), and $$ \operatorname{Cov}(X,Y)=E[XY]-E[X]E[Y]=\frac12-\frac14=\frac14. $$ Consequently, HSIC is \((1/4)^2=1/16\). This example shows directly that with linear kernels HSIC reduces to squared scalar covariance; by itself, that choice only captures linear covariance.
Population HSIC as a Centered-Kernel Expectation
Define the population-centered kernels by centering each feature map with respect to its own marginal distribution: $$ k_c(x,x')=\langle\phi(x)-\mu_X,\phi(x')-\mu_X\rangle_{\mathcal H}, \qquad l_c(y,y')=\langle\psi(y)-\mu_Y,\psi(y')-\mu_Y\rangle_{\mathcal G}. $$ Equivalently, \(k_c(x,x')=k(x,x')-E[k(x,X)]-E[k(X,x')]+E[k(X,X')]\), where \(X,X'\) in the expectations are independent draws from the marginal distribution. The analogous expression holds for \(l_c\).
Proof. Write \(A=\tilde\phi(X)\), \(B=\tilde\psi(Y)\), and let \(A',B'\) be the corresponding centered features from the independent copy. For rank-one operators, the Hilbert–Schmidt inner product satisfies \(\langle a\otimes b,a'\otimes b'\rangle_{\mathrm{HS}} =\langle a,a'\rangle_{\mathcal H}\langle b,b'\rangle_{\mathcal G}\). The integrability established above permits taking the expectation of this inner product for independent copies. Therefore $$ \begin{aligned} \|C_{XY}\|_{\mathrm{HS}}^2 &=\langle E[A\otimes B],E[A'\otimes B']\rangle_{\mathrm{HS}}\\ &=E[\langle A,A'\rangle_{\mathcal H}\langle B,B'\rangle_{\mathcal G}]\\ &=E[k_c(X,X')l_c(Y,Y')]. \end{aligned} $$ The last equality follows from the definitions of the centered kernels. This proves the result. \(\square\)
This expression is useful because it turns an operator norm into an expectation involving scalar kernel evaluations. It also makes clear that the two kernel factors are centered using their separate marginals, while the expectation is over paired observations from the joint distribution.
Worked Example: A Binary Pair with Delta Kernels
Let \(X\) take values \(0,1\) with equal probability and let \(Y=X\). Use the delta kernel \(k(x,x')=\mathbf 1\{x=x'\}\) for both variables. Its feature vectors are the two standard basis vectors \(e_0,e_1\) in \(\mathbb R^2\). Their common mean is \((e_0+e_1)/2\), so the centered feature is \((e_0-e_1)/2\) when the value is \(0\), and its negative when the value is \(1\).
Since \(Y=X\), the two centered feature vectors agree on every observation. Their cross-covariance operator is thus $$ C_{XY}=E[\tilde\phi(X)\otimes\tilde\phi(X)] =\begin{pmatrix}1/4&-1/4\\-1/4&1/4\end{pmatrix}. $$ The squared Hilbert–Schmidt norm is the sum of the squares of all four entries: $$ \operatorname{HSIC}=4\left(\frac14\right)^2=\frac14. $$ The centered-kernel expectation gives the same result. For independent copies, \(k_c(X,X')=\mathbf 1\{X=X'\}-1/2\), and \(l_c(Y,Y')\) has the same value because \(Y=X\). Each factor is either \(1/2\) or \(-1/2\); their product is always \(1/4\), so its expectation is \(1/4\).
The Empirical Centered Gram-Matrix Statistic
Now observe \(n\) paired data points \((x_1,y_1),\ldots,(x_n,y_n)\). Let \(K,L\in\mathbb R^{n\times n}\) be their Gram matrices, with \(K_{ij}=k(x_i,x_j)\) and \(L_{ij}=l(y_i,y_j)\). Let \(\mathbf 1\) be the length-\(n\) vector of ones and define the centering matrix \(H=I_n-\mathbf 1\mathbf 1^\mathsf T/n\). Multiplication on both sides gives the centered Gram matrices \(K_c=HKH\) and \(L_c=HLH\).
The empirical feature means are \(\bar\phi=n^{-1}\sum_i\phi(x_i)\) and \(\bar\psi=n^{-1}\sum_i\psi(y_i)\). The empirical cross-covariance operator, using divisor \(n\), is $$ \widehat C_{XY}=\frac1n\sum_{i=1}^n (\phi(x_i)-\bar\phi)\otimes(\psi(y_i)-\bar\psi). $$ Its squared Hilbert–Schmidt norm is the empirical plug-in HSIC statistic.
Proof. Set \(\tilde\phi_i=\phi(x_i)-\bar\phi\) and \(\tilde\psi_i=\psi(y_i)-\bar\psi\). Expanding the squared norm and applying the rank-one inner-product identity gives $$ \begin{aligned} \|\widehat C_{XY}\|_{\mathrm{HS}}^2 &=\frac{1}{n^2}\sum_{i,j} \langle\tilde\phi_i,\tilde\phi_j\rangle_{\mathcal H} \langle\tilde\psi_i,\tilde\psi_j\rangle_{\mathcal G}. \end{aligned} $$ The first inner product is \((HKH)_{ij}\), and the second is \((HLH)_{ij}\), because centering the feature vectors subtracts their sample means. This proves the double-sum identity. Since \(K_c,L_c\) are symmetric, \(\sum_{i,j}(K_c)_{ij}(L_c)_{ij}=\operatorname{tr}(K_cL_c)\). Using \(H^2=H\) and cyclic invariance of trace, $$ \operatorname{tr}(K_cL_c)=\operatorname{tr}(HKHLH) =\operatorname{tr}(KHLH). $$ Dividing by \(n^2\) gives the claimed trace formula. \(\square\)
Worked Example: Computing the Statistic from Three Observations
Use linear kernels and the data \(x=(0,1,2)\), \(y=(0,0,1)\). The sample means are \(\bar x=1\) and \(\bar y=1/3\), so the centered vectors are \(x_c=(-1,0,1)\) and \(y_c=(-1/3,-1/3,2/3)\). For linear kernels, the empirical cross-covariance operator is the scalar $$ \widehat C_{XY}=\frac13 x_c^\mathsf T y_c =\frac13\left(\frac13+0+\frac23\right)=\frac13. $$ Thus the empirical HSIC is \(\|\widehat C_{XY}\|_{\mathrm{HS}}^2=1/9\).
To check using Gram matrices, centering the linear-kernel Gram matrices gives \(K_c=x_cx_c^\mathsf T\) and \(L_c=y_cy_c^\mathsf T\). Hence $$ \frac{1}{n^2}\sum_{i,j}(K_c)_{ij}(L_c)_{ij} =\frac19(x_c^\mathsf T y_c)^2 =\frac19(1)^2=\frac19. $$ Both calculations agree, including the divisor \(n^2=9\).
Interpretation and a Common Pitfall
HSIC is nonnegative because it is a squared norm, and it measures cross-covariance across the selected feature spaces rather than just covariance between the original coordinates. For example, with \(X\) equally likely to be \(-1,0,1\) and \(Y=X^2\), \(E[X]=0\), \(E[Y]=2/3\), and \(E[XY]=E[X^3]=0\), so \(\operatorname{Cov}(X,Y)=0\) even though \(Y\) is determined by \(X\). Linear kernels therefore give HSIC equal to zero in this example. A richer feature representation can capture associations that a scalar covariance misses, but the choice of kernels matters.
- Pitfall: treating zero cross-covariance as independence for every kernel. The reasoning “HSIC is zero, therefore \(X\) and \(Y\) are independent” is not valid without additional conditions on the kernels. With linear kernels, HSIC is only squared covariance in the scalar case, and the preceding example has zero covariance despite dependence. The correction is to interpret zero HSIC first as \(C_{XY}=0\); an independence conclusion requires suitable kernel properties.
- Pitfall: using uncentered Gram matrices in the centered formula. The formula involves \(K_c=HKH\) and \(L_c=HLH\), or equivalently the trace expression with the centering matrices. Omitting centering changes the statistic because it retains feature-mean contributions.
- Pitfall: losing a factor of \(n\). The empirical operator uses divisor \(n\), so its squared norm has divisor \(n^2\). A different divisor defines a different finite-sample scaling.
The operator view explains why the matrix calculation works: centering the Gram matrices is exactly centering the feature vectors, and the trace aggregates all pairwise products of those centered feature inner products. This makes the population concept usable even when feature maps are implicit and the RKHS is infinite-dimensional.
Check Your Understanding
Use the definitions and derivations above to answer the following.
- What spaces are the domain and range of \(C_{XY}\), and how does its action encode covariance?
- Why do the stated second-moment conditions ensure that the rank-one operator in the definition has an integrable Hilbert–Schmidt norm?
- In the population kernel expression, from which distribution are the independent copies \((X',Y')\) drawn?
- Why does the empirical trace formula contain \(H\), and why is its denominator \(n^2\)?
- Give a reason that zero HSIC need not establish independence when arbitrary kernels are allowed.