## 3 Electricity Consumption Behavior Classification Based on CLB-BER
### Improved CLUBS Clustering
#### 3.2.2 Optimization-of-Adjustment Phase  
Based on the conclusion of the splitting phase, the data space is segmented into two distinct types of blocks: one containing only a cluster and another containing only noise, as shown in Figure 6. In the adjustment phase, the CLUBS algorithm undertakes two tasks: (i) separating blocks containing clusters and (ii) forming an elliptic cluster from the separated blocks. Since noise-only blocks exhibit lower density, the first task can be achieved through density observation. CLUBS incrementally sorts all blocks by density and detects density jumps between neighboring blocks to identify potential subsets of noisy blocks. The candidate subset is then tested by creating a smaller hypercube at the centroidof the block. If the density within this hypercube significantly exceeds that of the entire block, the block is classified as noise-only. Otherwise, it is categorized as a cluster block.  
Once all the cluster blocks have been identified, the process of forming comprehensive clusters for the remaining blocks and materializing the centroid of their clusters begins, and each data point is assigned to the cluster with the closest centroid. To achieve this, the approach in this paper employs a weighted function that considers the distance between points along each dimension. More specifically, this paper uses the centroid \((c_{1},c_{2},\ldots,c_{d})\) to measure the distance from each point \(\mathrm{P}=(p_{1},p_{2},\ldots,p_{d})\) to each cluster block \(\mathrm{C}\).  
\[dist^{\star}(p,C)=\sum_{i=1}^{d}\biggl{(}\frac{\parallel p_{i}-c_{i} \parallel}{r_{i}}\biggr{)}^{2} \tag{15}\]  
\[r_{i}=3\sqrt{\frac{WCS_{i}(C)}{n}} \tag{16}\]  
where \(n\) represents the count of points within cluster \(C\), and \(WCS_{i}(c)\) denotes the variance in dimension \(i\). Let \(dist^{\star}(p,C)=1\). Define an ellipse whose center is then the centroid of the cluster, and the radius of dimension \(\mathrm{i}\) is then the radius of \(r_{i}\).  
The Euclidean distance solely measures point-to-point distances, neglecting the similarity in temporal patterns. Conversely, dynamic time warping (DTW) accounts for shape similarity, but overlooks temporal characteristics. The corresponding formula is as follows:  
\[\mathrm{Dist}(\mathrm{Euclidean}) =\sqrt{\left(\mathrm{q}_{1}-\mathrm{c}_{1}\right)^{2}+\left( \mathrm{q}_{2}-\mathrm{c}_{2}\right)^{2}+\cdots+\left(\mathrm{q}_{n}-\mathrm{ c}_{n}\right)^{2}} \tag{17}\] \[=\sqrt{\sum_{i=1}^{n}\left(\mathrm{q}_{i}-\mathrm{c}_{i}\right)^ {2}} \tag{18}\]  
In order to calculate the minimum distance between two time series, in this paper, we move the time-series data via a sliding window; the sliding window size equals the shorter time-series length, and the sliding step is 1. Cosine similarity is employed for initial similarity judgment, discarding data points that exceed the cosine similarity threshold. The Euclidean distance metric is then used to compute the distance among the windowed data. Ultimately, the function returns the smallest distance among the time series. This approach addresses the challenge of aligning points due to varying sequence lengths while considering both shape and distance similarity. This dynamic windowing intrinsically maintains symmetry constraints during shape alignment, optimizing pattern consistency without manual intervention. The pseudo code is as follows.  
Figure 6: A block containing a cluster (**a**) and a block containing only outliers (**b**).