# Asymmetric Distance in K-Means Clustering Enhances Quality of Cells Raman Imaging
## 3 Anisotropic Distance Metric
asymmetric matrix (Figure 2B-D), the sphere deforms into an ellipsoid (indicating an anisotropic distance). In this formulation, points aligned with \(\mathbf{r_{0}}\) along the major axis are assigned smaller distances, while points deviating from \(\mathbf{r_{0}}\) along the minor axes are assigned larger distances. This ensures that the metric prioritizes spectral similarity based on relative peak ratios rather than absolute intensity differences. If \(\mathbf{r_{0}}\) lies on the \(x\) axis, the asymmetric metric matrix that produces the desired result in 3D is given by:  
\[T= \begin{bmatrix}\frac{1}{ecc_{x}}&0&0\\ 0&\frac{1}{ecc_{y}}&0\\ 0&0&\frac{1}{ecc_{z}}\end{bmatrix} \]  
where \(1/ecc_{x}\) determines the elongation along the \(x\) axis (such that a smaller \(ecc_{x}\) results in a larger elongation), and \(ecc_{x}\) corresponds to the eccentricity parameter \(ecc\) introduced earlier, i.e., \(ecc_{x}=ecc\). For the other axes we set \(ecc_{y}=ecc_{z}\) to obtain a prolate ellipsoid shape. These parameters can be collectively denoted as \(ecc_{\perp}\). Moreover, to prevent volume scaling when transitioning from spherical to ellipsoidal isodistance surfaces, we impose the asymmetric metric matrix \(T\) to be unitary by applying the following condition:  
\[1=\frac{1}{ecc_{x}}\cdot\frac{1}{ecc_{y}}\cdot\frac{1}{ecc_{z}}\]  
which simplifies to  
\[1=\frac{1}{ecc}\cdot\left(\frac{1}{ecc_{\perp}}\right)^{2}\]  
Figure 2: Isodistance surfaces calculated using an asymmetric metric matrix for different values of the eccentricity parameter \(ecc\). The red circle indicates the point \(\mathbf{r_{0}}\), starting from which distances are computed; the blue dots delineate the shape of the isodistance surfaces, while the straight line represents the axis along which ellipsoids are expected to align. (**A**) Isotropic Euclidean distance corresponding to \(ecc\) = 1.00. (**B–D**) Anisotropic distances with \(ecc\) = 0.50, 0.25, and 0.10, respectively. Solving for \(ecc_{\perp}\), we obtain:  
\[ecc_{\perp}=\left(\frac{1}{ecc}\right)^{1/2}\]  
This result implies that only a single eccentricity parameter, \(ecc\), needs to be specified along the axis of \(\mathbf{r_{0}}\), while the others are uniquely determined. To compute the distances from \(\mathbf{r_{0}}\) using the metric matrix \(T\), we apply:  
\[d^{2}=\mathbf{\Delta r^{T}}T\mathbf{\Delta r},\]  
yielding isodistance surfaces in the form of prolate ellipsoids with the major axis aligned to \(x\) axis. However, this formulation is only valid when \(\mathbf{r_{0}}\) lies on the \(x\) axis. To extend the approach for a generic \(\mathbf{r_{0}}\), we first apply a rotation matrix \(R\), which aligns \(\mathbf{r_{0}}\) with the \(x\) axis:  
\[\mathbf{r_{0}}^{\prime}=R\mathbf{r_{0}}\] \[\mathbf{\Delta r^{\prime}}=R\mathbf{\Delta r}=R(\mathbf{r}-\mathbf{ r_{0}})\]  
Then, the asymmetric matrix \(T\) is used to compute the distances between the rotated vectors:  
\[d^{2}=\mathbf{\Delta r^{T}}T\mathbf{\Delta r^{\prime}}\]  
Substituting \(\mathbf{\Delta r^{\prime}}=R\mathbf{\Delta r}\) yields:  
\[d^{2}=(R\mathbf{\Delta r})^{\mathbf{T}}T\left(R\mathbf{\Delta r }\right)\] \[d^{2}=\mathbf{\Delta r^{T}}(R^{T}TR)\mathbf{\Delta r}\]  
Thus, the desired asymmetric metric matrix, \(M_{AS}\), applicable to any arbitrary \(\mathbf{r_{0}}\), is given by:  
\[1=\frac{1}{ecc}\cdot\left(\frac{1}{ecc_{\perp}}\right)^{2}\]0  
Since \(T\) is a positive definite matrix and the application of a rotation \(R\) preserves the positive definiteness of \(T\), the resulting matrix \(M_{AS}\) remains positive definite and constitutes a valid metric matrix. Extending this approach to \(N\)-dimensions is straightforward. The matrix \(T\) in \(N\)-dimensions is given by:  
\[T= \begin{bmatrix}\frac{1}{ecc}&\dots&0\\ \vdots&\ddots&\vdots\\ 0&\dots&\frac{1}{ecc_{\perp}}\end{bmatrix} \]  
where the unitary condition results in:  
\[ecc_{\perp}=\left(\frac{1}{ecc}\right)^{1/(N-1)}\]  
Instead, the \(N\)-dimensional rotation matrix \(R\) is computed using the general method proposed in ref. [16].