Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA058 · Metric

Centered kernel alignment

Compares representational geometry across neural layers, models, or training stages.

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 discover.compare_embeddings. 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

Compares representational geometry across neural layers, models, or training stages.

Question / hypotheses

Do the same observations induce similar pairwise relationships in two representation spaces?

Architecture / computational structure

A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.

Assumptions

Rows must correspond to the same inputs. Choose centering, kernel, biased/unbiased estimator, and sample count consistently; guard against shared nuisance structure.

Formula / computational definition

CKA(K,L)=⟨HKH,HLH⟩F∥HKH∥F∥HLH∥F.CKA(K,L)=\frac{\langle HKH,HLH\rangle_F}{\|HKH\|_F\|HLH\|_F}.

Parameters and notation

K,L are representation kernels; H centers observations. For linear CKA, feature scaling and preprocessing matter. Layer selection and evaluation sample composition are hyperparameters.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.

How to use and calibrate

Calculate a layer-by-layer similarity map on held-out inputs and repeat across seeds. Use ablations or probes to test functional interpretations.

Example application

Inspect representational drift after fine-tuning an audio or language encoder.

Interpretation / pitfalls

Watch out

High CKA does not prove identical task behavior, disentanglement, or causal mechanism. Width, anisotropy, and sample structure can influence comparisons.

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

import numpy as np
X=np.array([[1.,0.],[0.,1.],[1.,1.],[2.,1.]]); Y=X@np.array([[0.,1.],[-1.,0.]])
X=X-X.mean(axis=0); Y=Y-Y.mean(axis=0); K=X@X.T; L=Y@Y.T
print(np.sum(K*L)/np.sqrt(np.sum(K*K)*np.sum(L*L)))
R

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

X <- rbind(c(1,0),c(0,1),c(1,1),c(2,1)); Y <- X%*%rbind(c(0,1),c(-1,0))
X <- scale(X,scale=FALSE); Y <- scale(Y,scale=FALSE); K <- X%*%t(X); L <- Y%*%t(Y)
print(sum(K*L)/sqrt(sum(K*K)*sum(L*L)))

Sources

From the CodeSplash reference, entry EVA058.