## 5 Clustering Analysis of the Selected Ground Motions Based on a K-Means Algorithm  
### K-Means Clustering Algorithm  
The clustering analysis algorithm classifies the object data, based on distance or similarity, which strengthens the similarity between objects of the same class more than that between those of other classes. This maximizes the homogeneity of objects within the same class and the heterogeneity between objects of different classes. Clustering analysis is an important unsupervised learning algorithm and many scholars have conducted extensive research on clustering analysis algorithms. Currently, more than 100 clustering algorithms have been published. Among these clustering algorithms, the K-means clustering algorithm is a dynamic clustering method that is suitable for large-scale data. The K-means clustering algorithm has a simple principle, yielding easy-to-understand analytical results, and does not require high levels of computer performance. It is currently one of the most widely used clustering analysis methods. Therefore, in this study, the K-means clustering algorithm is applied to cluster the original selected group of 100 pulse-like ground motions, using the first three principal components (\(F_{1}\), \(F_{2}\), and \(F_{3}\)) as clustering indices, as determined in Section 4.4. The following steps are followed to conduct the clustering analysis:  
1. Assuming that the ground motions are divided into \(K\) initial classes, \(K\) data points are randomly selected as the initial clustering centers.
2. Assuming that the first three principal component values of ground motion \(g_{i}(i=1,2,\cdots,100)\) are \(\left(F_{i1},F_{i2},F_{i3}\right)\), and the principal component value of the \(j\)-th \((j=1,2,\cdots,K)\) cluster center is \(C_{j}=\left(F_{j1},F_{j2},F_{j3}\right)\), then the Euclidean distance \(d_{ij}\) between the \(i\)-th ground motion and the \(j\)-th cluster center is: \[d(g_{i},C_{j})=\sqrt{\left(F_{i1}-F_{j1}\right)^{2}+\left(F_{i2}-F_{j2}\right) ^{2}+\left(F_{i3}-F_{j3}\right)^{2}}\] (13)  
Figure 11: Accumulated contribution rate of the principal components.  
3. Using Equation (13), the Euclidean distance from each ground motion to each cluster center point is calculated separately, and the ground motions are assigned to the nearest cluster center, according to the principle of minimum distance, then the ground motions are classified into \(K\) classes;
4. Calculating the sum of squared errors (SSE), \(D\), which reflects the distortion degree of clustering, according to Equation (14): \[D=\sum_{j=1}^{K}\sum\left(d(G_{ij},C_{j})\right)^{2}\] (14) where \(G_{ij}\) represents the principal component of the \(l\)-th (\(l=1,2,\cdots,n_{j}\)) ground motion in the \(j\)-th class, and \(n_{j}\) represents the number of ground motions in the \(j\)-th class.
5. Calculating the mean values of the ground motions assigned to each class in step (3) according to Equation (15) and updating the cluster center for each class by using the mean values as the new centroid, then recalculating the sum of squared errors, \(D\): \[m_{j}=\frac{1}{n_{j}}{\sum G_{ij}}\] (15) where \(m_{j}\) is the mean value of the ground motion data in the \(j\)-th class, and \(n_{j}\) is the number of ground motions in the \(j\)-th class.
6. Performing step (2) to recalculate the Euclidean distance between each ground motion and the updated cluster center in step (5), we then perform step (3) to reclassify each ground motion. We then perform step (5) to update each cluster center point and calculate the sum of squared errors, \(D\). We repeat this process until the sum of squared errors has not changed for two consecutive iterations, then terminate the algorithm and output the final cluster analysis results.