# Asymmetric Distance in K-Means Clustering Enhances Quality of Cells Raman Imaging
## 3 Anisotropic Distance Metric  
In vibrational spectroscopy, each spectrum can be represented as a point in an \(N\)-dimensional space, where \(N\) is the number of acquired intensities. Thus, each spectrum can be expressed as an array, denoted as \(\mathbf{r}\). Since vibrational intensities are strictly positive, all components of \(\mathbf{r}\) are positive. When applying clustering or other machine learning techniques, a distance metric is required to compare spectra. Incorporating prior knowledge of the data structure can be beneficial in defining an appropriate metric. Two spectra, \(\mathbf{r_{0}}\) and \(\mathbf{r_{1}}\), convey the same chemical information if they exhibit the same relative peak ratios, even if their absolute intensities differ (Figure 1). Mathematically, such spectra can be expressed as:  
\[\mathbf{r_{1}}=c\cdot\mathbf{r_{0}}\text{ with }c>1,\]  
where \(c\) is a scalar greater than 1. In this case, both spectra originate from the same molecular species, with the only difference being concentration (higher for \(\mathbf{r_{1}}\) if \(c>1\)), which affects the overall intensity. Representing \(\mathbf{r_{0}}\) and \(\mathbf{r_{1}}\) as vectors in a coordinate system, they share the same direction and lie on the same straight line originating from the origin. Conversely, a spectrum \(\mathbf{r_{2}}\) that deviates significantly in angle from \(\mathbf{r_{0}}\) represents a different chemical composition. Therefore, an ideal distance metric should reflect this data structure. For simplicity, we consider a three-dimensional (3D) case. Given a reference spectrum \(\mathbf{r_{0}}\) in a 3D space, the distance to another spectrum \(\mathbf{r}\) is computed using a metric matrix. The displacement vector is:  
\[\mathbf{\Delta r}=\mathbf{r}-\mathbf{r_{0}},\]  
The Euclidean distance \(d\) is typically given by:  
\[d^{2}=1\,\mathbf{\Delta r}\,\mathbf{l}\,^{2}=\Delta x^{2}+\Delta y^{2}+\Delta z ^{2},\]  
which can be rewritten as the dot product:  
\[d^{2}=\mathbf{\Delta r}\cdot\mathbf{\Delta r},\]  
Introducing a metric matrix \(M\), the generalized distance is:  
\[d^{2}=\mathbf{\Delta r}^{\mathbf{T}}M\mathbf{\Delta r},\]  
where the Euclidean metric matrix \(M_{EU}\) is simply the identity matrix:  
\[M_{EU}=I,\]  
This defines an isotropic distance, meaning all points equidistant from \(\mathbf{r_{0}}\) form a sphere centered at \(\mathbf{r_{0}}\) (Figure 2A). However, this standard distance metric does not account for the underlying data structure. To incorporate anisotropy, we define an asymmetric metric matrix \(M_{AS}\), which produces ellipsoidal isodistance surfaces instead of spherical ones. The desired anisotropic distance metric forms a prolate ellipsoid with its major axis aligned with \(\mathbf{r_{0}}\). To control elongation, we introduce an eccentricity parameter, \(ecc\), which defines the ratio between minor and major axes. Figure 2 illustrates the effect of varying \(ecc\), with panels B, C, and D corresponding to \(ecc=0.50\), \(0.25\), and \(0.10\), respectively. The most elongated ellipsoid is represented by \(ecc=0.10\). These surfaces indicate that all blue points in Figure 2 have the same computed distance \(d\) from \(\mathbf{r_{0}}\), based on the chosen metric. When using the Euclidean matrix (Figure 2A), the isodistance surface remains a sphere (indicating isotropic distance), whereas with the  
Figure 1: Spectrum similarities and dissimilarities. (**A**) The red curve represents a typical Raman spectrum recorded on cells, while the black curve corresponds to the same spectrum scaled by a factor \(c>1\). These spectra convey identical chemical information. (**B**) Representing the spectra as vectors in 3D space, \(\mathbf{r_{0}}\) and \(\mathbf{r_{1}}\) share the same direction, while \(\mathbf{r_{2}}\) deviates, indicating different chemical composition. This highlights that spectra aligned in the same direction should have smaller distances compared to those that are not aligned.