Tutorials › Multivariate Statistics (Graduate) › Kernel Choice and Bandwidth Sensitivity

Multivariate Dependence Testing · Tutorial 444 of 975

Kernel Choice and Bandwidth Sensitivity

Learn to choose and assess Gaussian-kernel bandwidths by connecting HSIC sensitivity to distance scales and to the geometry of dependence.

Advanced 12 min read

What You'll Learn

  • Define Gaussian kernels with separate bandwidths for the two variables
  • Use pairwise-distance summaries to identify plausible bandwidth scales
  • Derive the large-bandwidth approximation of HSIC
  • Understand the small-bandwidth limit for continuous distributions
  • Compare bandwidth effects for correlated, discrete, and nonlinear dependence
  • Distinguish sensitivity diagnostics from a guarantee of greater test power

Why Bandwidth Changes the View of Dependence

The Gaussian kernel compares observations according to their distance: nearby points receive a similarity close to one, while sufficiently separated points receive a similarity close to zero. Its bandwidth controls what counts as “nearby.” Since HSIC combines similarities in the two variables, changing either bandwidth changes which patterns of paired observations contribute most to the statistic.

A narrow bandwidth emphasizes very local matches; a wide bandwidth smooths over local structure and can make HSIC respond mainly to broad, nearly linear features. The value of HSIC therefore cannot be interpreted without its kernel and bandwidths. This is a sensitivity issue, not a change to the basic independence target: for Euclidean data, Gaussian kernels with any fixed, positive bandwidth are characteristic, so the population HSIC is zero exactly under independence. But finite samples can reveal markedly different evidence at different bandwidths.

Definition: For \(x,x'\in\mathbb{R}^{p}\), the Gaussian kernel with bandwidth \(\sigma_X>0\) is \(k_{\sigma_X}(x,x')=\exp\{-\|x-x'\|^2/(2\sigma_X^2)\}\). For \(y,y'\in\mathbb{R}^{q}\), define \(l_{\sigma_Y}(y,y')\) in the same way, with bandwidth \(\sigma_Y>0\). The population HSIC is
$$ \operatorname{HSIC}(X,Y) =E[k(X,X')l(Y,Y')] +E[k(X,X')]E[l(Y,Y')] -2E[k(X,X')l(Y,Y'')], $$
where \((X,Y),(X',Y'),(X'',Y'')\) are independent, identically distributed copies and \(k=k_{\sigma_X}\), \(l=l_{\sigma_Y}\).

The three terms involve different pairings of independent copies; the third pairs \(X\) with \(X'\), but \(Y\) with \(Y''\). Keeping that pairing straight is important in calculations. Equivalently, HSIC is the expectation of the product of the two population-centered kernels evaluated on two independent paired observations:

$$ \operatorname{HSIC}(X,Y) =E[\widetilde{k}(X,X')\widetilde{l}(Y,Y')], $$

where \(\widetilde{k}(x,x')=k(x,x')-E[k(x,X)]-E[k(X,x')]+E[k(X,X')]\), and \(\widetilde{l}\) is defined analogously. These expressions make clear that bandwidth affects the similarities before they are centered and combined.

Use Distances to Set a Scale

A useful first diagnostic is to examine the distributions of pairwise distances in \(X\) and \(Y\), separately. In a sample, calculate distances between distinct observations, and inspect their median and perhaps lower and upper quantiles. A bandwidth much smaller than nearly all distances makes most off-diagonal similarities tiny; a bandwidth much larger than nearly all distances makes similarities similar to one. Either extreme can be uninformative for finite-sample comparisons.

A practical starting point is to consider bandwidths around a robust distance summary, such as the median pairwise distance, and then inspect a range below and above it. This is a scale diagnostic, not a universal optimality rule. If \(X\) and \(Y\) have different units or distance scales, choose and vary \(\sigma_X\) and \(\sigma_Y\) separately. Rescaling a variable changes its distances, so the corresponding bandwidth must be rescaled as well to preserve the same kernel similarities.

Worked Example: Correlated Gaussian Variables at Two Bandwidths

Let \((X,Y)\) be bivariate normal with mean zero, unit marginal variances, and correlation \(\rho=0.8\). Use the same bandwidth \(\sigma\) for both variables. For independent copies, the difference vector \((X-X',Y-Y')\) has covariance matrix with diagonal entries \(2\) and off-diagonal entries \(2\rho\). The Gaussian quadratic-form expectation gives

$$ E[k(X,X')l(Y,Y')] =\frac{1}{\sqrt{(1+2/\sigma^2)^2-(2\rho/\sigma^2)^2}}. $$

Each marginal difference has variance \(2\), so \(E[k(X,X')]=E[l(Y,Y')]=(1+2/\sigma^2)^{-1/2}\); their product is \((1+2/\sigma^2)^{-1}\). For the third term, the differences \(X-X'\) and \(Y-Y''\) have variances \(2\) and covariance \(\rho\): only \(X\) and \(Y\) from the first paired observation are shared. Thus

$$ E[k(X,X')l(Y,Y'')] =\frac{1}{\sqrt{(1+2/\sigma^2)^2-(\rho/\sigma^2)^2}}. $$

At \(\sigma=0.5\), \(1+2/\sigma^2=9\), \(2\rho/\sigma^2=6.4\), and \(\rho/\sigma^2=3.2\). The three terms in the HSIC formula are therefore \(1/\sqrt{40.04}\), \(1/9\), and \(-2/\sqrt{70.76}\), respectively. Numerically,

$$ \operatorname{HSIC}\approx 0.1580349+0.1111111-0.2377585 =0.0313875. $$

At \(\sigma=2\), the corresponding terms are \(1/\sqrt{2.09}\), \(1/1.5\), and \(-2/\sqrt{2.21}\), giving \(\operatorname{HSIC}\approx0.69171446+0.66666667-1.34534559=0.01303554\). The smaller value at the wider bandwidth does not mean the variables became less dependent. It shows that the numerical scale of HSIC changes with bandwidth, even for the same distribution and the same dependence.

What the Large-Bandwidth Limit Emphasizes

When both bandwidths are large, a Gaussian kernel is nearly constant. Its constant part disappears under centering, and its first nonconstant contribution is governed by ordinary cross-covariance. The following approximation makes precise why a very wide kernel may be insensitive to nonlinear dependence that has no cross-covariance.

Theorem: Suppose \(X\in\mathbb{R}^{p}\) and \(Y\in\mathbb{R}^{q}\) have finite fourth moments. If both Gaussian bandwidths equal \(\sigma\), then
$$ \sigma^4\operatorname{HSIC}_{\sigma}(X,Y) \longrightarrow \|\operatorname{Cov}(X,Y)\|_F^2 \qquad\text{as }\sigma\to\infty, $$
where \(\operatorname{Cov}(X,Y)=E[(X-E[X])(Y-E[Y])^T]\) and \(\|\cdot\|_F\) is the Frobenius norm.

Proof. Write \(X'\) for an independent copy of \(X\). The pointwise limit \(\sigma^2(k_\sigma(x,x')-1)\to-\|x-x'\|^2/2\) follows from \((e^{-u}-1)/u\to-1\) as \(u\to0\). Moreover,

$$ \left|\sigma^2\{k_\sigma(X,X')-1\}\right| \leq \frac{\|X-X'\|^2}{2}, $$

because \(1-e^{-u}\leq u\) for \(u\geq0\). The right-hand side is square-integrable by the finite fourth-moment assumption. Dominated convergence therefore gives convergence in \(L^2\) to \(-\|X-X'\|^2/2\). Population double-centering is a contraction in \(L^2\), so \(\sigma^2\widetilde{k}_\sigma(X,X')\) converges in \(L^2\) to the double-centered limit. Expanding the squared distance shows that this centered limit is \((X-E[X])^T(X'-E[X])\): terms depending on only one of \(X,X'\), and constants, vanish under double-centering. The same argument applies to \(Y\).

By the centered-kernel expression for HSIC and the Cauchy–Schwarz inequality, the product of these two \(L^2\)-convergent quantities has convergent expectation. Its limit is

$$ E[((X-E[X])^T(X'-E[X]))((Y-E[Y])^T(Y'-E[Y]))] =\sum_{a=1}^{p}\sum_{b=1}^{q}\operatorname{Cov}(X_a,Y_b)^2. $$

The equality follows by expanding the product and using independence of the primed and unprimed paired observations. The sum is the squared Frobenius norm, proving the result. \(\square\)

Worked Example: A Nonlinear Relationship with Zero Cross-Covariance

Let \(X\) be uniform on \([-1,1]\) and let \(Y=X^2\). This is a deterministic dependence: knowing \(X\) determines \(Y\). Yet \(E[X]=0\), \(E[X^2]=1/3\), and \(E[X^3]=0\), so

$$ \operatorname{Cov}(X,Y) =E[X^3]-E[X]E[X^2] =0. $$

The distance scales are not identical. For independent copies, \(E[(X-X')^2]=2\operatorname{Var}(X)=2/3\), so the root-mean-square \(X\)-distance is \(\sqrt{2/3}\approx0.816\). Also \(E[Y]=1/3\), \(E[Y^2]=E[X^4]=1/5\), and \(\operatorname{Var}(Y)=1/5-1/9=4/45\). The root-mean-square \(Y\)-distance is therefore \(\sqrt{2\operatorname{Var}(Y)}=\sqrt{8/45}\approx0.422\). Those different scales argue for examining separate bandwidths rather than imposing one numerical value on both variables.

For equal bandwidths, the theorem says \(\sigma^4\operatorname{HSIC}_{\sigma}(X,Y)\to0\), because the cross-covariance is zero. The dependence has not disappeared; rather, its leading large-bandwidth contribution vanishes. A bandwidth range that includes values comparable to the observed distance scales is therefore important for detecting this curved pattern.

What the Small-Bandwidth Limit Emphasizes

For continuous distributions, a very narrow Gaussian kernel makes similarities between distinct observations vanish. At the population level this can drive HSIC to zero, even under dependence. Thus narrowing the bandwidth does not increase sensitivity without limit. The precise limiting statement below applies when both marginal distributions have no atoms, meaning \(P(X=x)=P(Y=y)=0\) for every point \(x,y\).

Result: If the marginal distributions of \(X\) and \(Y\) are nonatomic, then for Gaussian kernels with \(\sigma_X,\sigma_Y\to0\), \(\operatorname{HSIC}(X,Y)\to0\).

Proof. For independent copies, \(k_{\sigma_X}(X,X')\to \mathbf{1}\{X=X'\}\) pointwise as \(\sigma_X\to0\). Nonatomicity implies \(P(X=X')=0\), so the limit is zero almost surely. Since the kernel is bounded by one, dominated convergence gives \(E[k(X,X')]\to0\). The same argument gives \(E[l(Y,Y')]\to0\). Also, the product \(k(X,X')l(Y,Y')\) tends to zero almost surely because the event \(X=X'\) has probability zero, and it is bounded by one; hence its expectation tends to zero. Finally, \(k(X,X')l(Y,Y'')\leq k(X,X')\), so its expectation tends to zero as well. All three terms in the HSIC formula therefore tend to zero. \(\square\)

This result is about the population quantity. In a finite sample, very narrow kernels can instead yield a Gram matrix close to the identity, leaving a statistic strongly affected by the diagonal and by sampling variation. Discrete distributions also behave differently: exact repeated values can retain nonzero similarity as the bandwidth shrinks.

Worked Example: A Two-Point Distribution and a Narrow Kernel

Let \(X\) take values \(-1\) and \(1\) with equal probability, and set \(Y=X\). Both variables are discrete, so the nonatomic small-bandwidth result does not apply. With the same bandwidth \(\sigma\), the kernel is \(1\) for equal values and \(q=\exp(-2/\sigma^2)\) for different values.

For either variable, the population-centered kernel is \((1-q)/2\) when its two arguments agree and \(-(1-q)/2\) when they differ. Since \(Y=X\), the two centered kernels have the same sign for every paired pair of arguments, and their product is always \((1-q)^2/4\). Thus

$$ \operatorname{HSIC}_{\sigma}(X,Y)=\frac{(1-e^{-2/\sigma^2})^2}{4}. $$

At \(\sigma=0.5\), \(q=e^{-8}\approx0.0003355\), giving HSIC \(\approx(0.9996645)^2/4\approx0.2498323\). At \(\sigma=5\), \(q=e^{-0.08}\approx0.9231163\), giving HSIC \(\approx(0.0768837)^2/4\approx0.0014778\). Here the narrow bandwidth preserves strong similarity contrasts between the two support points, while the wide bandwidth makes them look nearly alike. The calculation also shows why a small-bandwidth conclusion for continuous data should not be applied blindly to discrete or tied observations.

Diagnosing Bandwidth Sensitivity in Practice

A useful diagnostic is a small sensitivity analysis rather than a single supposedly universal choice. First inspect pairwise-distance summaries separately for the two variables. Then calculate HSIC across a reasonable grid of bandwidth pairs, including values below and above the marginal distance summaries. Interpret the pattern, not merely the largest statistic: a sharp peak at a narrow scale, a gradual decline at wide scales, or a marked difference between the two margins may indicate which geometric features the kernel is emphasizing.

A bandwidth comparison does not by itself compare calibrated evidence against independence. HSIC values at different bandwidths have different scales, and any inferential comparison must account for the statistic’s null distribution and the procedure used to select or report bandwidths. The material on characteristic kernels establishes the population independence characterization for each fixed positive Gaussian bandwidth; it does not imply that all bandwidths have equal finite-sample sensitivity.

  • Distances are scale guides, not optimality guarantees. A median can conceal clusters, tails, or a small but meaningful local scale.
  • Check each variable separately. Different units and spread can make equal numerical bandwidths inappropriate.
  • Look for nonlinear structure. A wide-bandwidth approximation driven by cross-covariance can attenuate relationships with zero cross-covariance.
  • Account for ties and discreteness. The limiting behavior for nonatomic margins does not describe distributions with point masses.
  • Separate magnitude from evidence. A change in the numerical HSIC value across bandwidths is not, on its own, a change in dependence or a calibrated change in significance.
Common mistake: “The HSIC value is smaller with a wider bandwidth, so the dependence is weaker.” This reasoning confuses the statistic’s bandwidth-dependent numerical scale with the underlying distribution. In the Gaussian example, the distribution stayed fixed while HSIC changed from about \(0.03139\) to \(0.01304\). Compare bandwidths as sensitivity settings, inspect the associated distance scales, and use an appropriate calibration before making inferential claims.

Check Your Understanding

Use the definitions and results above to answer these questions.

  1. Why should the bandwidths for \(X\) and \(Y\) be considered separately when their variables have different units?
  2. In the large-bandwidth result, what dependence feature determines the leading term of HSIC?
  3. Why does the small-bandwidth limit for nonatomic margins not apply to the two-point example?
  4. What distance summaries would you inspect before choosing a grid of Gaussian bandwidths?
  5. Why does a smaller HSIC value at one bandwidth not establish weaker dependence?
Clinical Biostats