Expand description
§Kernel Alignment
Implements Kernel Target Alignment (KTA), Centered Kernel Alignment (CKA), HSIC (Hilbert-Schmidt Independence Criterion), and optimization routines for selecting kernel hyperparameters based on alignment with a target kernel.
§Overview
Kernel alignment metrics quantify how well a kernel matrix captures the
structure of the learning problem. Given labels, one constructs an “ideal”
target kernel where T[i,j] = +1 if labels[i] == labels[j] and -1
otherwise. A high alignment between K and T indicates that the kernel
maps similar-class points close together.
§Kernel Target Alignment (KTA)
KTA(K, T) = <K, T>_F / (||K||_F * ||T||_F)§Centered Kernel Alignment (CKA)
CKA applies double-centering before computing alignment, making it invariant to isotropic scaling and constant shifts:
CKA(K1, K2) = HSIC(K1, K2) / sqrt(HSIC(K1,K1) * HSIC(K2,K2))where HSIC(K, L) = (1/n^2) * <H*K*H, H*L*H>_F.
§References
- Cortes, C., Mohri, M., & Rostamizadeh, A. (2012). Algorithms for learning kernels based on centered alignment. JMLR.
- Kornblith, S., et al. (2019). Similarity of neural network representations revisited. ICML.
Structs§
- Alignment
OptConfig - Configuration for alignment-based kernel hyperparameter search.
- Alignment
Result - Result of a pairwise kernel alignment computation.
- Alignment
Stats - Comprehensive alignment statistics between a kernel
Kand a target kernel. - Kernel
Matrix - A square kernel matrix (n×n, symmetric positive semi-definite).
- Optimization
Result - Outcome of a kernel alignment optimisation run.
Enums§
- Alignment
Error - Errors that can arise during kernel alignment computations.
Functions§
- alignment_
stats - Compute all alignment metrics in a single pass.
- centered_
kernel_ alignment - Compute the Centered Kernel Alignment (CKA) between kernel matrices
k1andk2. - gradient_
ascent_ alignment - Gradient ascent on the alignment score via finite differences.
- grid_
search_ alignment - Grid search over a discrete set of kernel parameter vectors, returning
the one that maximises alignment with
target. - hsic
- Compute the biased HSIC (Hilbert-Schmidt Independence Criterion) estimate:
- kernel_
target_ alignment - Compute the Kernel Target Alignment (KTA) between kernel
kand target kerneltarget.