## 4 SF-Partition-Based Clustering and Relaying (SFPCR) Scheme
### Density-Based Subspace Clustering in the HSFZ  
Clustering is one of the main methods used to divide a network into a number of groups (clusters), with one node designated as the cluster head (CH) for each cluster [46]. Intuitively, a cluster in the SFPCR scheme is precisely defined as a set of density-connected LoRa devices in a particular region. Usually, the expected type of cluster is determined by the clustering criterion. The SFPCR scheme constructs LoRa nodes in the HSFZ as clusters. For clustering of the HSFZ, we used a combination of the DBSCAN algorithm [47] and naive Bayes classifier, a density-based subspace clustering algorithm that created arbitrary-shaped clusters and eliminated outliers, as shown in Figure 3. The naive Bayes classifier [48] was used for the CH selection based on the CH's conditional probability. The DBSCAN clustering algorithm was suitable for the discovery of subspace clusters of arbitrary shape with a high efficiency in the network. The SFPCR scheme employs a centralized clustering strategy in which the network exerts complete control over the clustering procedure via the GW. In this method, the GW always selects which LD will function as CHs in the HSFZ, requiring periodic information on all LoRa devices to select the most suitable nodes. Moreover, there are eight standardized message types for LoRaWAN. We used the proprietary message type to encode a collection of messages necessary for network layering, cluster formation, and multihop message relaying. To facilitate proper cluster formation, we also defined a control message called the \"HELLO\" message. The GW periodically broadcasted the control message to all LDs within the cluster. The centralized clustering algorithm was dissected into two main phases: an initial setup phase and a steady-state phase for the subspace cluster formation and the CH's selection criteria, respectively. We explain each of them in detail. Figure 3: Arbitrary subspace clusters in the HSFZ: (**a**) Node density-reachability, (**b**) Node density-connected arbitrary subspace clusters. - \(n_{j}\) is a member of a cluster \(C_{i}\) if \(n_{i}\) is a member of \(C_{i}\) and \(n_{j}\) is density-reachable from \(n_{i}\). - \(n_{i}\) and \(n_{j}\) are density-connected if both of them are members of a cluster \(C_{i}\). Assume the distance in the HSFZ between two sets \(S_{1}\) and \(S_{2}\) of LDs is defined as \(dist(S_{1},S_{2})=min\{dist(n_{i},n_{j})\mid n_{i}\in S_{1},n_{j}\in S_{2}\}\). Two sets with at least the density of the thinnest cluster will be separated only if the distance between them is greater
than \(d_{0}\). The LoRa device density connection determines the maximum number of LDs (\(LD_{max}\)) in an arbitrary cluster. Furthermore, in the steady-state phase, the GW is critical in computing the CHs of clusters by using network information from the IoT LoRa devices during network initialization. * **Steady-state phase:** In this phase, the cluster head selection is performed using a naive Bayes classifier [48]. The GW plays a crucial role in generating the score value needed to categorize normal LoRa devices as CHs or cluster members. Based on the Bayes classifier, the GW determines the \(\kappa\) best LoRa devices to become CHs based on their binary score. The value of \(\kappa\) indicates the appropriate number of CHs. In [52], the authors explained what clustering algorithms were and how they worked. Moreover, there were three types of algorithms for choosing CHs: predetermined, random, and attribute-based. In the SFPCR scheme, we adopted attribute-based algorithms to select CHs. The GW constitutes the vector metric attributes \(A^{(i)}\) for a LoRa device LD(i) to become the CH. \(A^{(i)}=\{A_{1}^{(i)},A_{2}^{(i)},\ldots A_{j}^{(i)}\}\), where j is the vector's dimension.