Abstract
Cosine similarity is an established similarity metric for computing associations on vectors, and it is commonly used to identify related samples from biological perturbational data. The distribution of cosine similarity changes with the covariance of the data, and this in turn affects the statistical power to identify related signals. In this work, we derive the asymptotic moments of cosine similarity as a function of the data and identify the criteria of the data covariance matrix that minimize the variance of cosine similarity. We find that the variance of cosine similarity is minimized when the eigenvalues of the covariance matrix are equal for centered data. This result can be used to optimize over a set of transformations or representations on a dataset to maximize power, recall, or other discriminative metrics, with direct application to noisy biological data.
Introduction
In systems biology, researchers frequently employ cosine similarity to compare high-dimensional "signatures"—vectors representing cellular changes (e.g., gene expression or morphology) following drug treatment. The objective is to identify related signals, such as drugs sharing a mechanism of action, against a background of noise.
However, biological data is rarely "round." It is typically anisotropic, meaning it possesses a complex covariance structure where certain features vary significantly more than others. This inherent "stretchiness" distorts similarity scores. Until now, the exact relationship between a dataset's covariance and the resulting distribution of cosine similarity was poorly understood, making it difficult to determine if a high similarity score represented a true biological signal or a structural artifact of the data.
Theoretical Framework
The authors addressed this by deriving the asymptotic moments (mean and variance) of cosine similarity across three scenarios:
- Spherically Symmetric: The baseline multivariate standard normal distribution.
- Centered Distribution: Data with a zero mean but unequal variances (eigenvalues) across dimensions.
- Generalized Distribution: The most realistic case, featuring both non-zero means and complex covariance.
To ensure mathematical tractability, the researchers utilized a "rescaling trick," approximating the denominator of the cosine similarity formula (the product of vector norms) by treating the norm as a constant equal to the square root of its expected value. This approximation gains accuracy as the number of dimensions ($n$) increases, making it particularly suitable for high-dimensional biological contexts.
Validation of Theoretical Predictions
The derived formulas were validated using simulated multivariate normal datasets with dimensions ranging from 1 to 1000. By sampling eigenvalues from Gamma distributions to create diverse anisotropic shapes, the authors compared empirical similarity variance against their theoretical predictions.
As shown in the figure above, the theoretical predictions for variance matched empirical results with extraordinary precision, achieving a Pearson correlation of >0.999 for centered data. This confirms that the asymptotic moments derived are highly reliable for high-dimensional data analysis.
Key Insights: The Isotropic Principle
The study's most significant finding is the Isotropic Principle: for centered data (mean = 0), the variance of cosine similarity is at its absolute minimum when all eigenvalues of the covariance matrix are equal. In practical terms, to maximize the clarity of biological signals, researchers should "whiten" their data—transforming it so it forms a perfect sphere in high-dimensional space.
Additionally, the authors introduced a "Power" formula ($\Delta$) to quantify the statistical power to discriminate between related and unrelated samples. This allows for the prediction of how specific data transformations, such as PCA or metric learning, will improve experimental results before they are executed.
Limitations and Future Directions
While the findings are robust, the authors note a "Pure Noise" caveat: while achieving isotropy minimizes total similarity variance, adding dimensions of pure noise will reduce variance without increasing the power to detect real signals. Transformations must be targeted at relevant axes of variation. Furthermore, because the core approximations rely on the law of large numbers, the formulas are most accurate for high-dimensional data (typically $n > 10$).
This work provides a clear target for researchers developing new data representations. Future applications may include designing loss functions for Self-Supervised Learning that encourage isotropic embeddings, thereby maximizing discriminative power in downstream biological tasks.
Summary updated