Correcting Biased Centered Kernel Alignment Measures in Biological and Artificial Neural Networks — part 1/3

Cleaned-text code points [0, 14662). Bibliography omitted here; source.md includes it.

# Correcting Biased Centered Kernel Alignment Measures in Biological and Artificial Neural Networks

###### Abstract

Centred Kernel Alignment (CKA) has recently emerged as a popular metric to compare activations from biological and artificial neural networks (ANNs) in order to quantify the alignment between internal representations derived from stimuli sets (e.g. images, text, video) that are presented to both systems ( Sucholutsky et al., 2023 ; Han et al., 2023 ) . In this paper we highlight issues that the community should take into account if using CKA as an alignment metric with neural data. Neural data are in the low-data high-dimensionality domain, which is one of the cases where (biased) CKA results in high similarity scores even for pairs of random matrices. Using fMRI and MEG data from the THINGS project ( Hebart et al., 2023 ) , we show that if biased CKA is applied to representations of different sizes in the low-data high-dimensionality domain, they are not directly comparable due to biased CKA’s sensitivity to differing feature-sample ratios and not stimuli-driven responses. This situation can arise both when comparing a pre-selected area of interest (e.g. ROI) to multiple ANN layers, as well as when determining to which ANN layer multiple regions of interest (ROIs) / sensor groups of different dimensionality are most similar. We show that biased CKA can be artificially driven to its maximum value when using independent random data of different sample-feature ratios. We further show that shuffling sample-feature pairs of real neural data does not drastically alter biased CKA similarity in comparison to unshuffled data, indicating an undesirable lack of sensitivity to stimuli-driven neural responses. Positive alignment of true stimuli-driven responses is only achieved by using debiased CKA. Lastly, we report findings that suggest biased CKA is sensitive to the inherent structure of neural data, only differing from shuffled data when debiased CKA detects stimuli-driven alignment.

## 1 Introduction

The goal of measuring (or inducing) alignment between biological and artificial neural networks relies on the selection of a metric that can correctly quantify representational alignment between two systems ( Sucholutsky et al., 2023 ) , while also being invariant to transformations that can cause similar representations to appear unrelated. CKA has recently gained popularity as a metric to study alignment between brain responses and deep learning models ( Sucholutsky et al., 2023 ; Han et al., 2023 ) . Furthermore, recent work to create more brain-like ANNs has used CKA in a loss function to force models to exhibit more brain-like responses that maximize CKA-alignment to held-out neural data, resulting in models that are more robust to adversarial attacks ( Dapello et al., 2023 ) .

In the context of modern deep learning, it is common to have dataset sizes multiple orders of magnitude higher than what can be expected for neural data ( Smucny et al., 2022 ) . Therefore, when studying the alignment between ANNs and brains, similarity measures are applied to matrices which contain many more columns (features) than rows (samples). Previous research has noted that this situation is where standard (”biased”) CKA becomes an unreliable alignment metric that can potentially lead to erroneous conclusions ( Kleemann et al., 2007 ; Smilde et al., 2008 ) . This work demonstrates this unreliability in a practical set of experiments, and promotes the adoption of a debiasing step put forward in Kornblith et al. (2019) , which we show is robust to the aforementioned weakness. Though Kornblith et al. (2019) published their work in 2019, biased CKA has still appeared in publications. We further highlight the importance of using both random and shuffled controls when quantifying alignment between neural networks and brains.

We first examine the sensitivity of biased CKA to alignment of two random matrices, where one is of a fixed shape and we systematically increase the feature dimension of the other. We compare three alignment metrics: (i) biased CKA, (ii) debiased CKA and (iii) the RV2 Coefficient. We then examine how varying feature dimensionality alone can result in potentially misleading conclusions by contrasting biased CKA and debiased CKA across two CNN models (ResNet18 & CORnet-S), two brain data modalities (fMRI & MEG) over the same image stimuli set. We compare across three experimental manipulations: (i) using the correct data order (where samples and features are matched correctly), (ii) shuffled neural data and (iii) random data. The final section outlines interesting findings regarding biased CKA’s insensitivity to shuffled data, in which we show that only in the debiased version do we see sensitivity to true sample-feature pairs. Additionally, we suggest that biased CKA is sensitive to the inherent structure of neural data responses and can thus be decomposed into such a component, in addition to true stimuli-driven responses detectable using debiased CKA.

The primary contributions of this work are:

1. We provide a systematic investigation of CKA for the alignment of biological and artificial neural networks, arguing for the importance of using random and shuffled controls and of applying the debiasing step to avoid erroneous conclusions.

2. We show that without debiasing, CKA alignment of data matrices that have a larger number of columns than rows is an unreliable quantification of similarity. This situation is a common occurrence when comparing ANN models with neural data when the number of parameters between ANN layers or neural data set sizes are not equal.

3. We show how biased CKA can give the incorrect impression that fMRI / MEG have similar alignment scores across multiple ANN layers, which the debiased version of CKA successfully detects as erroneous.

4. Our experiments support the idea that biased CKA is decomposable into at least two components: one that is sensitive to the generalized structure of neural data (e.g. prototypical fMRI responses to image viewing) and one that is sensitive to true stimuli-driven responses, while debiased CKA is only sensitive to the latter component.

## 2 CKA Overview

### 2.1 Mathematical Formulation & Properties

Centered Kernel Alignment ( Cortes et al., 2012 ; Kornblith et al., 2019 ) is a metric used to quantify the similarity of representational structure between two matrices, each of which must be matched for the number of samples but can differ in the dimensionality of each feature space, i.e. X ∈ ℝ N × P ​ 1 X\in\mathbb{R}^{N\times P1} , Y ∈ ℝ N × P ​ 2 Y\in\mathbb{R}^{N\times P2} , but P ​ 1 ≠ P ​ 2 P1\neq P2 . Unlike correlation/cosine-based measures of matrix similarity (e.g. Representational Similarity Analysis ( Kriegeskorte et al., 2008 ) ), CKA quantifies similarity using the dot-product operation. A generalization of dot-product similarity for centered matrices is the Hilbert-Schmidt Independence Criterion (HSIC), which is a kernel-based operation. Namely, if K K and L L represent the output of two kernel operations on the original data, the empirical estimator for HSIC is given by the following, where H H is a centering matrix:

HSIC ​ ( K , L ) = 1 ( n − 1 ) 2 ​ tr ​ ( K ​ H ​ L ​ H ) \text{HSIC}(K,L)=\frac{1}{(n-1)^{2}}\text{tr}(KHLH) (1)

CKA is the extension of HSIC through the application of a normalization step in order to introduce invariance to isotropic scaling:

CKA ​ ( K , L ) = HSIC ​ ( K , L ) HSIC ​ ( K , K ) ​ HSIC ​ ( L , L ) \text{CKA}(K,L)=\frac{\text{HSIC}(K,L)}{\sqrt{\text{HSIC}(K,K)\text{HSIC}(L,L)}} (2)

Regarding the selection of an appropriate kernel in CKA, it is virtually ubiquitous to use CKA with a linear kernel since initial experiments demonstrated that it performed comparatively well to non-linear kernels ( Han et al., 2023 ; Davari et al., 2022a ) . We only consider the linear variant in this work.

The invariance properties of CKA are important to consider with regard to the other similarity metrics to which it has previously been compared. CKA is invariant to orthogonal transformations and isotropic scaling, but not to invertible linear transformations, unlike other methods such as Canonical Correlation Analysis (CCA). Kornblith et al. (2019) showed that several common similarity metrics were unable to detect similarity between corresponding layers of neural networks trained using the same architecture and hyperparameters, but different random seeds. In contrast, CKA was able to detect this similarity. Operations such as batch normalization apply an invertible linear transformation that changes ANN behavior, and it’s not clear that a similarity metric should be invariant to such operations ( Thompson et al., 2019 ) . Other interesting findings using CKA to provide insights into the representational structure in ANNs were that wide networks learn similar representations and that saturation of feature channels is more commonly a feature of higher layers rather than lower layers ( Nguyen et al., 2021 ) . We next examine some of the criticisms of CKA and the attempts to address identified weaknesses.

### 2.2 Criticisms

Davari et al. (2022a) ; Davari et al. (2022b) ; Davari et al. (2023) show that CKA is sensitive to subset translations, and that targeted attacks on the metric can artificially and arbitrarily modulate CKA similarity values, without changing the functional behaviour of a neural network. Thompson et al. (2019) point out that the standard implementation of CKA described above is highly sensitive to dataset size discrepancies, i.e. as the feature-sample ratio increases, CKA will tend towards 1.0 1.0 even for random, unrelated matrices. This is a situation that is common when dealing with neural data, which often results in large feature dimensionalities (e.g. fMRI) from costly experiments, which restricts the amount of data that can be collected. This results in a comparatively lower number of samples that can be concurrently presented to both biological and artificial neural networks. Yao et al. (2020) reported that this issue was also present in biological analysis, e.g. transcriptomics studies, where feature dimensionality of gene expression profiles is much larger than the number of collected samples. Linear CKA is equivalent to a metric introduced in Robert & Escoufier (2018) called the RV Coefficient ( Thompson et al., 2019 ; Klabunde et al., 2023 ) , which Smilde et al. (2008) reformulated in terms of random matrices and showed that this metric can be approximated by the following formula, where N N denotes the number of samples and P 1 P_{1} , P 2 P_{2} denote the feature dimensionality of each matrix:

RV ​ ( A , B ) ≈ P 1 ​ P 2 ( P 1 2 + ( N + 1 ) ​ P 1 ) ​ ( P 2 2 + ( N + 1 ) ​ P 2 ) \text{RV}(A,B)\approx\frac{P_{1}P_{2}}{\sqrt{(P_{1}^{2}+(N+1)P_{1})(P_{2}^{2}+(N+1)P_{2})}} (3)

By subtracting the diagonal elements off the Gram matrix, namely A ​ A T − d ​ i ​ a ​ g ​ ( A ​ A T ) AA^{T}-diag(AA^{T}) , we eliminate the dependence of the metric value on the dimensionalites of P 1 P_{1} and P 2 P_{2} , which are contained within the diagonal of the matrix. This results in the modified RV Coefficient (RV2) that is no longer sensitive to sample-feature ratio discrepancies.

In an updated version of their paper, Kornblith et al. (2019) point out that earlier work ( Song et al., 2007 ) derived an unbiased estimator of HSIC by recognizing that HSIC can be formulated as a U-Statistic. They substituted a more numerically stable formation of this estimator (See A.5 )) from Székely & Rizzo (2014) into the kernel-centering step of CKA, resulting in a debiased version, which fixed the aforementioned issues. The range of the debiased version of CKA is [ − 1 , 1 ] [-1,1] , unlike biased CKA which is in [ 0 , 1 ] [0,1] .

### 2.3 Applications to Neuroscience

Linear CKA is similar to Representational Similarity Analysis (RSA), a common tool in studying neural representations between different biological / artificial systems ( Kriegeskorte et al., 2008 ) . Whereas CKA implements dot-product similarity, RSA often implements correlation/cosine-based similarity. The primary consequence of this difference manifests itself in RSA’s sensitivity to rotations of the data ( Mehrer et al., 2020 ) , which could be important in some scenarios, such as differing head positions in M/EEG acquisition. Kornblith et al. (2019) showed the inability of common alignment metrics to detect similar representations among identical ANN layers trained in identical scenarios but over different random seeds. This highlighted an issue that has important implications in studying model-brain alignment. The mammalian visual processing hierarchy, like ANNs, takes in representations from previous processing stages and applies computations on those representations which are further passed to downstream layers. This raised the question as to whether earlier alignment metrics might have also been insensitive to true similarities among different visual processing systems. CCA, for example, is invariant to invertible linear transformations and might not detect truly similar representations, which CKA would be able to detect. The increased sensitivity led to the consideration of CKA as a promising metric to study alignment in biological and artificial neural networks.

Han et al. (2023) use simulation experiments to test the ability of linear CKA to uncover correct ground truth models of (simulated) neural data and report that under unreasonably idealized conditions, CKA allows for identification capability of a reasonable degree. Recent work has shown promise in inducing brain-like representations in neural networks by incorporating various alignment metrics in custom loss functions in multi-task learning scenarios. Federer et al. (2020) minimize Representational Dissimilarity Matrices (RDMs) between model inputs and brain responses to induce the brain’s statistical properties into CNNs. Pirlot et al. (2022) use Deep Canonical Correlation Analysis (DCCA) to induce brain-like responses in networks and find that they are more accurate and robust. Dapello et al. (2023) used CKA in a loss function to align neural network representations with Macaque inferior temporal cortex and found models that were better aligned to human behaviour and were more robust to adversarial examples. The above approaches that use CKA to quantify / induce alignment between biological and artificial neural networks do not specify that the debiased version of CKA was used in those experiments.

## 3 Methods

### 3.1 Brain Representations