# Sequential and Comprehensive Algorithm for Fault Detection in Semiconductor Sensors
## 2 Materials and Methods
### Clustering Analysis  
For other pairs except for the linear and exponential relations, the clustering analysis was conducted. We used a k-means clustering method. To group the data points in a k-means clustering, the centroids were arbitrarily placed on the data plane. The number (\(k\)) of the centroids was pre-defined to equal the number of the clusters. All of the data points should be associated with the closest centroid and the clusters formed as a group of associated data points with the same centroid. To evaluate these clusters' intra-class similarity, the sum of squares (\(V\)) in the distance between every data point and associated centroid was calculated as follows [32]:  
\[V=\sum_{i=1}^{k}\sum_{x_{j}\in S_{i}}\abs{x_{j}-\mu_{i}}^{2} \tag{3}\]  
where \(x_{j}\) is the \(j\)-th data point in the \(i\)-th cluster (\(S_{i}\)) and \(\mu_{i}\) is the centroid of \(S_{i}\). This calculation was iterated as changing the centroid location. The next centroid was relocated on the center of the gravity among the data in the previous cluster.  
\[\mu_{i}^{(t+1)}=\frac{1}{\abs{S_{i}^{(t)}}}\sum_{x_{j}\in S_{i}^{(t)}}x_{j} \tag{4}\]  
The iteration was stopped when the clusters were no longer changed. We obtained the Voronoi diagram with the centroids of k-means clustering and determined the boundary of each cluster. The Voronoi diagram is a partition divided with the perpendicular bisector between a point and the closest one. This Voronoi diagram was implemented by Algorithm 2.  
```
Input:\(N_{i}\), where (\(i=1,2\,\dots\,25\)), a given set of peak sensor values, k (number of clusters) and _Iters_ (iteration number) Output: (i) the optimal k means \(c_{i}\) of clusters \(i=1,2\,\dots\,\mathrm{k}_{i}\) and its Voronoi diagram (ii) the defect zone detection; Process:
1: Initialize the sensor dataset D = \(\{N_{1},\,N_{2}\,\dots\,\,\,N_{25}\}\)
2: Initialize cluster C = \([C_{3},\,C_{4}\,\dots\,\,\,C_{10}]\)
3: Call Voronoi function \(V(S)\)
4: Initialize k cluster centroid \(\mu=\{\mu_{\mathrm{C_{3}}},\,\mu_{\mathrm{C_{4}}}\,\dots\,\,\mu_{\mathrm{C_{10}}}\}\) with k samples randomly picked from D
5: \(C_{i}\,\leftarrow\,\varnothing\,\,(1\leq i\leq k)\); initialize clusters
6: \(N_{C_{i}}\,\leftarrow\,0\,\,(1\leq i\leq k)\); initialize sensor number for each cluster
7:for\(i\)\(=1,2\,\dots\,\mathrm{k}_{\mathrm{d}}\)
8: \(M\leftarrow\{\,x_{m}|\,1<m\leq b\}\,,\) M is the batch dataset and \(x_{m}\) is the sample randomly picked from D
9: \(\mu_{C_{i}}(x_{m})\,\leftarrow\,\frac{1}{|C_{i}|}\sum\limits_{x_{m}\in C_{i}}x _{m}\,\left(x_{m}\,\in M\right)\,;\mu(x_{m})\) is cached cluster nearest to the data sample \(x_{m}\)
10:endfor
11:for m = 1,2\(\dots\) bdo; step 6 to step 8 are to cache the cluster centroid for each sample in the batch dataset.
12: \(\mu_{C_{i}}\,\leftarrow\,\mu_{\mathrm{C}}(x_{m})\,;\) get the catch centroid for \(x_{m}\)
13: \(N_{C_{i}}\,\leftarrow\,N_{C_{i}}+1\); update sample number for each cluster centroid.
14: \(\eta\,\leftarrow\,1\,\,/\,\,N_{C_{i}}\,;\) calculate learning rate for each cluster centroid.
15: \(\mu_{C_{i}}\,\leftarrow\,(1-\eta)\mu_{C_{i}}+\eta x_{m}\,;\) take gradient step to update the cluster in each Voronoi space.
16:endfor
```  
**Algorithm 2****Sensor Defect Analysis Using Voronoi_k-Means (S, k)**