Similarity Metrics¶
shesha.sim provides extrinsic similarity metrics — measuring how well two
representations align with each other. These are distinct from (and empirically
uncorrelated with) the intrinsic stability metrics in the core module.
CKA¶
shesha.sim.cka() computes Centered Kernel Alignment. Invariant to orthogonal
transformations and isotropic scaling; widely used for comparing neural network layers.
import shesha.sim as sim
similarity = sim.cka(layer_a, layer_b)
similarity_debiased = sim.cka(layer_a, layer_b, debiased=True)
Procrustes similarity¶
shesha.sim.procrustes_similarity() finds the best orthogonal alignment between
two representations and returns the residual similarity. More sensitive to outliers
than CKA (~6× more false alarms in stable regimes).
similarity = sim.procrustes_similarity(X, Y)
RDM similarity (sim module)¶
shesha.sim.rdm_similarity() is an RSA-style RDM correlation. Rank-based and
robust to monotone transformations.
similarity = sim.rdm_similarity(X, Y, metric='cosine', method='spearman')
Bootstrap confidence intervals¶
All similarity metrics support optional bootstrap CIs via n_bootstrap_ci.
Both representations are resampled with the same indices (paired bootstrap).
See Bootstrap Confidence Intervals for full details.
result = sim.cka(X, Y, n_bootstrap_ci=1000, seed=320)
print(f"{result['mean']:.3f} [{result['ci_low']:.3f}, {result['ci_high']:.3f}]")