## 3 Automatically Choosing the Number of Clusters
### Density Peaks Algorithm  
The density peaks algorithm, which can detect non-convex clusters, is based on two assumptions. The first one is that the cluster centers are surrounded by neighbors with lower local density. The second assumption is the clusters' centers are at a relatively large distance from any snake with a higher local density. The density peaks algorithm uses three important variables: The local density \(\rho_{i}\) for each snake \(T_{i}\) in the whole data set, the minimum distance \(\delta_{i}\) among snake \(T_{i}\) and other snakes that have higher density [30] and the parameter \(\gamma_{i}=\rho_{i}\delta_{i}\), which is the product of \(\rho_{i}\) and \(\delta_{i}\) for each snake \(T_{i}\). Then, we choose the snakes with the largest \(\gamma_{i}\) values as centers. We compute the local density \(\rho_{i}\) and the minimum distance \(\delta_{i}\) from snakes with higher density to represent the two quantities of any snake \(T_{i}\). For each snake \(T_{i}\) in the whole data set of snakes \(\Gamma\), the local density \(\rho_{i}\) is defined as follows:  
\[\rho_{i}=\sum_{T_{j}\in\Gamma,T_{j}\
eq T_{i}}\chi\big{(}d(T_{i},T_{j})-d_{c} \big{)}, \tag{32}\]  
\[\text{with }\chi(x)=\left\{ \begin{array}{ll}1&\text{ if }x<0\\ 0&\text{ otherwise}\end{array} \right\},\]  
where \(d_{c}\) is a cutoff distance, \(\chi(x)\) is a kernel function, and \(d(T_{i},T_{j})\) is the distance among snakes \(T_{i}\) and \(T_{j}\). For each snake \(T_{i}\), these quantities are dependent on the distance \(d(T_{i},T_{j})\) among two snakes \(T_{i}\) and \(T_{j}\). In this paper, we adopted the following distance between two snakes based on the sparse snake similarity matrix as follows:  
\[d(T_{i},T_{j})=1-e^{\frac{-1}{i\overline{\rho}_{i}\overline{\rho}_{i}}}. \tag{33}\]  
The parameter \(\eta\) controls the marginal impact of the authentication in the case of additional similarities taking place among snakes. We choose, in our case \(\eta=3\), to obtain the densely distributed snakes in space. In fact, \(\rho_{i}\) is the number of snakes that are too similar to a snake \(T_{i}\). On the other hand, calculating the local density using the Gaussian function can avoid having the same density values for the snakes. The results are greatly influenced by the cutoff distance \(d_{c}\). The local density is computed as follows:  
\[\rho_{i}=\sum_{T_{j},T_{j}\in\Gamma,T_{j}\
eq T_{i}}e^{-\frac{d(T_{i},T_{j})^{ 2}}{d_{c}^{2}}}. \tag{34}\]  
The \(\delta_{i}\) is the minimum distance from snake \(T_{i}\) to the higher-density snakes and is defined as follows:  
\[\delta_{i}=\left\{ \begin{array}{ll}\max\{d(T_{i},T_{j})|T_{j}\in\Gamma\}& \text{ if }\forall T_{j}\in\Gamma,\rho_{i}\geq\rho_{j}\\ \min\{d(T_{i},T_{j})|\rho_{i}<\rho_{j},T_{j}\in\Gamma\}&\text{ otherwise }.\end{array} \right. \tag{35}\]  
If there is one snake with the largest density, it makes a compromise with \(\delta_{i}\), defined as the maximal distance from itself to other snakes, which enables it to have the largest \(\delta_{i}\) value again. In order to select the centers, we calculate, for each snake, \(T_{i}\) the parameter \(\gamma_{i}=\rho_{i}\delta_{i}\) with the largest values. We select the \(K\) snakes that have the largest values of \(\gamma_{i}\), such that \(K\) is the number of classes. To see whether a distance is relatively large, we should make a comparison of it with another one, so that we can model a comparison with a new quantity for \(\delta_{i}\) and the distance between a snake \(T_{i}\) and its nearest neighbor with a lower density, denoted by \(\tau_{i}\)[30]:  
\[\tau_{i}=\left\{ \begin{array}{ll}\delta_{i}&\text{ if }\forall T_{j}\in \Gamma,\rho_{i}\leq\rho_{j}\\ \min\{d(T_{i},T_{j})|\rho_{i}>\rho_{j},T_{j}\in\Gamma\}&\text{ otherwise}.\end{array} \right. \tag{36}\]  
The parameter \(\tau_{i}\) shows the distance from the snake \(T_{i}\) to the area with lower density. It shows how far away the snake \(i\) is from the area with lower density, which is a suitable quantity for \(\delta_{i}\) to compare with.