HSIC, Hands On
← text notes · Foundations › Linear algebra. Five widgets for the Hilbert–Schmidt independence criterion: where correlation fails, why more features help, HSIC as agreement between two Gram matrices, the permutation test and its bandwidth, and CKA for comparing representations.
1. Correlation misses it, HSIC does not
Pick a data set. Two tests look for dependence between x and y. The first uses a linear kernel, which is exactly the same test as Pearson correlation: it only sees straight-line trends. The second uses a Gaussian kernel, which sees any dependence given enough points. Both are judged the same way: shuffle y 499 times, and ask how often a shuffle scores as high as the real data. That fraction is the p-value.
A longer bar means stronger evidence. Past the dashed line means p < 0.05. Choose your own points to click in any shape you like.
2. More features, more chances
If x and y are independent, then no feature of x is correlated with any feature of y. So give each variable several features, here its powers x, x², …, and look at every correlation between a feature of x and a feature of y. Degree 1 is plain correlation, a single cell. Raise the degree and new cells appear. Each kind of dependence lights up its own cell.
HSIC with a polynomial kernel adds up the squares of this table. The Gaussian kernel does the same with every power at once (§3 of the notes).
3. Two similarity tables, and whether they agree
Forty points, sorted by x. K̃ says how much more alike each pair of samples is in x than a typical pair: blue for more alike, orange for less. L̃ says the same for y. The right-hand table multiplies them cell by cell: blue where x and y agree about a pair, orange where they disagree. HSIC is the average of that last table.
Hover over any table to see which pair a cell is. Then press Shuffle y. The x-table does not change, but the y-table is scrambled, the agreement table turns to noise, and its average drops.
4. The shuffle test, and the bandwidth
The left chart is the test itself. Grey is HSIC for 400 shuffles of y (the "independent world" built from your own data), and red is the real data. The right chart repeats the test at every bandwidth σ, from a thousandth of the median distance to a thousand times it. Its height says how many shuffle standard deviations the real data sit above the shuffle average.
The checkerboard starts at the median bandwidth, where the test sees nothing. Drag σ to the left. Then try the parabola, whose curve peaks near the median, and notice that far to the right every curve settles on the dashed line: the linear kernel's answer.
5. CKA: comparing two representations
Think of the left cloud as one network's embeddings of 90 inputs and the right cloud as another network's embeddings of the same inputs (colours mark which is which). CKA is HSIC normalised to lie between 0 and 1. It is the cosine of the angle between the two centred Gram matrices. Transform the right-hand representation and see what CKA ignores and what it notices.