# Optimizing Rule Weights to Improve FRBS Clustering in Wireless Sensor Networks
## 2 Materials and Methods
### Description of the Fuzzy System  
Fuzzy logic [25; 26] is applied to numerous scientific fields and to engineering in multiple types of applications, including denial-of-service cyber-attacks [27], flying ad hoc networks [28], microgrid systems [29], electric vehicles [30], and earthquake control [31], among others. The well-known structure of a fuzzy controller can be observed in Figure 2.  
A fuzzy controller is characterized by a knowledge base (KB) that contains the fuzzy rules that relate the input variables to the output variables. These rules are formed by a series of linguistic variables whose values represent the design of the fuzzy sets for any quantity or information that the fuzzy controller needs. In order to use the value of an input variable in the fuzzy controller, its crisp value must be first fuzzified, transforming this numerical value into a membership degree of the different fuzzy sets. These fuzzy values are then put together using the rules of the KB to obtain the fuzzy values of the output variables, which are defuzzified to obtain the final output of the fuzzy system. For this proposal, we decided to use a Mamdani system, so that the final output is the centroid of the aggregated output fuzzy sets. Taking into account the fuzzy system designed for this paper, we selected some of the most common input variables used by other authors for clustering in WSNs. It must be also stated that the design of the fuzzy sets for all of these variables was the same, defining three triangular shapes (because they were for a Type-1 fuzzy system), as depicted in Figure 3. Thus, the input variables used in the present optimization process were the following:  
* Distance to the base station (\(\mathit{dBS}\)). This input is considered in most fuzzy controllers [32; 33] because it informs about the dispersion of the nodes. The degree of dispersion is critical when nodes are only powered by batteries. This variable measures the normalized distance of each node to the BS using the maximum distance of a node to the BS as the normalization parameter. * Centrality (\(\mathit{C}\)). This variable is calculated based on the distance of the nodes in a CH to the center of the sensing area of their cluster [20]. In this approach, we use the Kmeans [34] function to find the center of the every area, and then the distance from each node to the center of that area is calculated. * Node degree (\(\mathit{ND}\)). This parameter is the number of neighbors that each node has. We assume that a neighbor is a node that is closer than \(d_{0}\) meters (\(d_{0}\) is a constant of the radio model that will be detailed later (see Equation (3)) [35]. The neighbors of each node are then normalized by the maximum number of neighbors reached by one node in the set of the complete WSN. * Residual energy (\(\mathit{RE}\)). This value is used in most clustering methods for WSNs [36; 37]. It is normalized by the maximum initial energy of the nodes, which is assumed to be equivalent for all of them. * CH rotation (\(\mathit{CHR}\)). This input variable informs about the number of times a node has been selected as a CH [38]. The reason for incorporating this variable into the fuzzy system is to limit the intensive use of energy in a node when it is selected as CH in continuous or very close rounds. In this approach, \(\mathit{CHR}\) is calculated as in Equation (1), where \(\mathit{timesCH}\) is the number of times a node has been selected as the CH. Every time a node is promoted to CH, \(\mathit{timesCH}\) is incremented by one and then normalized by the maximum value of this parameter for each \(\mathit{round}\). Figure 2: Fuzzy inference system. \[CHR=1-\frac{timesCH}{max(timesCH)} \tag{1}\]  
Following with the design of the fuzzy system, all input variables except \(dBS\) are defined by linguistic values: low (l), medium (m), and high (h). In the case of \(dBS\), the fuzzy sets are named close (c), adequate (a), and far (f).