# Anomaly Detection through Grouping of SMD Machine Sounds Using Hierarchical Clustering
## 3 Proposed Method
### Hierarchical Clustering  
By hierarchically clustering the obtained latent vectors according to the distance in the latent space, products closer than the distance between the normal data of the trained product and abnormal data _Error 1_ and _Error 2_ of the trained product can be grouped and overseen. _Error 1_ is noise that is difficult for humans to distinguish, and _Error 2_ is noise that can be recognized by humans.  
Hierarchical clustering is a hierarchical system in which all objects are grouped into a single cluster, with each object represented as a separate cluster [10]. The following linkage methods [26] are used to compute the distance between two clusters \(U\) and \(V\). \(d(U,V)\) refers to the distance between clusters \(U\) and \(V\).  
* Centroid: For all combinations of data \(u_{i}\) in cluster \(U\) and data \(\
u_{j}\) in cluster \(V\), the distance between the center points of clusters \(U\) and \(V\) according to the following equation: \[d(U,V)=\|c_{u}-c_{v}\|^{2},\] (19) where \(c_{u}\) and \(c_{v}\) are the central points of the two clusters \(U\) and \(V\), respectively. The center point of the cluster uses the average of all data contained in the cluster according to the following equation: \[c_{u}=\frac{1}{|U|}\sum_{i}u_{i},\] (20) where the \(|\mid\) symbol refers to the number of elements in a cluster.
* Single: For all combinations of data \(u_{i}\) and data \(v_{j}\), we measure the distance to find the smallest value according to the following equation: \[d(U,V)=\min(d(u_{i},v_{j})).\] (21)* Complete: For all combinations of data \(\mathbf{u}_{i}\) and \(\mathbf{v}_{j}\), we measure the distance to find the largest value according to the following equation: \[d(\mathbf{U},\mathbf{V})=\max(d(\mathbf{u}_{i},\mathbf{v}_{j})).\] (22)
* Average: For all combinations of data \(\mathbf{u}_{i}\) and \(\mathbf{v}_{j}\), we measure the distance to find the average according to the following equation: \[d(\mathbf{U},\mathbf{V})=\sum_{ij}\frac{d(\mathbf{u}_{i},\mathbf{v}_{j})}{|\mathbf{U}||\mathbf{V}|}.\] (23)
* Median: This method is a variation of the centroid linkage method. Similar to the centroid method, the distance of the center points of clusters is the distance between clusters. If clusters \(\mathbf{S}\) and \(\mathbf{T}\) combine to form cluster \(\mathbf{U}\) according to the following equation: \[\mathbf{U}\leftarrow\mathbf{S}+\mathbf{T},\] (24) the center point of the cluster \(\mathbf{U}\) is not newly calculated, but the average of the center points of the two clusters of the original cluster is used according to the following equation: \[c_{u}=\frac{1}{2}(c_{s}+s_{t}).\] (25) Therefore, the calculation is faster than obtaining the center point by averaging all the data in the cluster.  
The dendrogram resulting from the hierarchical clustering of the latent vectors can be used to set a threshold distance between the latent vectors of normal data and abnormal data of the trained product. Normal data of untrained products that are closer than this threshold can be grouped for anomaly detection. This is because the pre-trained autoencoder embeds data with similar characteristics to the training data closely in the latent space. By performing hierarchical clustering on these latent vectors, similar characteristics to the training data can be grouped together, which enables anomaly detection without the need for separate model training. If the grouping threshold is placed on _Error 1_, it can be overseen more strictly, even though there are fewer products that can be grouped, and if the grouping threshold is placed on _Error 2_, there are many products that can be grouped, so it can be overseen more efficiently.