# A Hybrid Routing Protocol Based on Naive Bayes and Improved Particle Swarm Optimization Algorithms
## 3 Network Model and Assumptions
### Cluster Head Selection Based on a Naive Bayes Classifier  
A Bayesian network can predict the probability of future events through their statistical probability [32; 33]. The problem of WSN cluster head selection is to classify local nodes as either cluster head nodes or ordinary nodes. An energy-efficient naive Bayesian network decision-making method is proposed that estimates the unknown node categories according to the known node categories. By using the Bayes method, the network can be clustered automatically without considering the division of nodes. Suppose \(\textbf{Y}^{(i)}\) is the feature vector of naive node \(i\), representing a set of features of node _naive_, and \(\textbf{Y}^{(i)}=\{\textbf{Y}^{(i)}|_{\textbf{Y}^{(i)}},\textbf{Y}^{(i)}, \textbf{Y}^{(i)}\}\), where \(k\) refers to the dimension of the vector. Figure 1: Network architecture of the WSN hybrid routing algorithm. The features of node \(i\) include the residual energy \(re^{(i)}\), the distance from the node to the \(BS\)\(ds^{(i)}\), the node degree \(de^{(i)}\), the average distance from the node \(i\) to its neighbor \(dc^{(i)}\), the average link quality between node \(i\) and its neighbor \(Lqc^{(i)}\), and the data fusion degree \(Df^{(i)}\) when node \(i\) becomes the cluster head. The vector can be expressed as follows:  
\[\mathbf{Y}^{(i)}=\left\{re^{(i)},ds^{(i)},de^{(i)},dc^{(i)},Lqc^{(i)},Df^{(i)}\right\} \tag{8}\]  
where \(C\) represents the category that the node belongs to. In the cluster head selection issue, \(C\) is binary, which means that the node is an ordinary node or a cluster head node, expressed as \(C=\{c_{0},c_{1}\}\). The aim of cluster head selection is to find the mapping relationship between \(\mathbf{Y}^{(i)}\) and \(C\). Finally, we can obtain \(P(C\,|\,\mathbf{Y}^{(i)})\), which represents the probability of node \(i\) becoming the cluster head with the characteristics of \(\mathbf{Y}^{(i)}\). We can obtain Equation (9) according to the Bayesian theorem. \[P(C=c_{1}|\,\mathbf{Y}^{(i)})=\frac{P(\mathbf{Y}^{(i)}|\,C=c_{1})P(C=c_{1})}{ P(\mathbf{Y}^{(i)})} \tag{9}\]  
There is an assumption in the Naive Bayes method that all the features are independent. Then, we can obtain:  
\[P(\mathbf{Y}^{(i)}|\,C=c_{1})=\prod_{i}^{K}P(Y_{j}^{(i)}=y_{j}|\,C=c_{1}) \tag{10}\]  
Here, we mainly estimate the conditional probability that a node will become a cluster head, so Equation (9) can be transformed into:  
\[P(C=c_{1}|\,\mathbf{Y}_{1}^{(i)},\mathbf{Y}_{2}^{(i)},\ldots\,\mathbf{Y}_{k}^ {(i)})=\frac{P(C=c_{1})P(\mathbf{Y}_{1}^{(i)},\mathbf{Y}_{2}^{(i)},\ldots\, \mathbf{Y}_{k}^{(i)}|\,C=c_{1})}{P(\mathbf{Y}_{1}^{(i)},\mathbf{Y}_{2}^{(i)}, \ldots\,\mathbf{Y}_{k}^{(i)})} \tag{11}\]  
We select the node with the highest conditional probability of becoming the cluster head within the radius of the clustered domain:  
\[C\leftarrow\text{argmax}_{c_{1}}(P(\mathbf{Y}^{(i)}|\,C=c_{1})) \tag{12}\]  
In a real WSN application, considering that the prior probability estimation caused by the lack of sample data in the training set is 0, the Laplace smoothing method is used for sample estimation. \[\hat{P}(C=c_{k})=\frac{\#\{C=c_{k}\}+t}{\#\{C\}+tK} \tag{13}\]  
where \(t\) is the number of false samples added for each class, \(K\) is the number of classes, and \(\#\{C\}\) represents the number of samples in the training set. Firstly, the algorithm (Algorithm 1) determines the residual energy of nodes, calculates the probability that all energy-dominant nodes will become cluster heads, selects the node with the greatest probability within the set radius to become the cluster head, and improves the accuracy of cluster head node prediction through sample training. The pseudo code of Algorithm 1 is as follows:```
-Input: The number of sensors \(N\), number of clusters \(m\), and node initial energy \(E_{0}\) -Output: Cluster-head assignment and the cluster partition of all nodes -Algorithm 1. Network initialization. 2. Randomly generate the initial position of all nodes.