Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA017 · Hypothesis test

HSIC independence test

Tests dependence between representations, nuisance attributes, or paired modalities; extends baseline entry 86.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through correlation.dependence. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Tests dependence between representations, nuisance attributes, or paired modalities; extends baseline entry 86.

Question / hypotheses

H0: X is independent of Y; H1: dependence detectable by the selected kernels.

Architecture / computational structure

Compute two Gram matrices on paired observations, center them with H, and aggregate their product into the displayed biased HSIC statistic. Permuting one variable breaks pairwise association under IID independence while retaining each marginal sample.

Assumptions

Pairs must be correctly aligned and observations exchangeable for ordinary permutation calibration. Characteristic-kernel conditions and moment requirements determine consistency.

Formula / computational definition

HSIC^b=n−2tr⁡(KHLH),H=I−11T/n.\widehat{HSIC}_b=n^{-2}\operatorname{tr}(KHLH),\qquad H=I-\mathbf1\mathbf1^T/n.

Parameters and notation

K,L are Gram matrices; H centers them. Kernel bandwidths, representation layer, and permutation count are hyperparameters, not parameters learned by the test.

Fitting, fine-tuning, and adaptation

Kernel and representation choices determine detectable dependence. Freeze those choices before the final test; if label-dependent kernel selection is included, reproduce it in the calibration procedure. For dependent time series, an arbitrary block permutation is not automatically valid: use a procedure and block regime justified for the dependence structure. The numerical snippet supplies no p-value.

How to use and calibrate

Specify kernels before testing, permute one member of the pairs, and compare the statistic with the permutation distribution. For sequences, use appropriate blocks or a dependence-aware procedure.

Example application

Check whether a learned embedding retains a sensitive nuisance variable in a controlled audit.

Interpretation / pitfalls

Watch out

Independence of one measured attribute does not prove fairness or disentanglement. Testing many layers needs multiplicity control. Small samples and unsuitable bandwidths reduce power.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy, sklearn

import numpy as np
from sklearn.metrics.pairwise import rbf_kernel
x=np.arange(5.)[:,None]; y=x*x; n=len(x); H=np.eye(n)-np.ones((n,n))/n
K=rbf_kernel(x,gamma=.5); L=rbf_kernel(y,gamma=.02)
print(np.trace(K@H@L@H)/n**2)
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

x <- 0:4; y <- x*x; n <- length(x); H <- diag(n)-matrix(1/n,n,n)
K <- exp(-.5*outer(x,x,"-")^2); L <- exp(-.02*outer(y,y,"-")^2)
print(sum(diag(K%*%H%*%L%*%H))/n^2)

Sources

From the CodeSplash reference, entry EVA017.