## 3 ML-Based Routing Algorithms in WSNs
### Artificial Neural Network-Based Routing Methods  
ANN is an information processing system based on mimicking the structure and function of neural networks in the brain, which achieves the purpose of processing information and simulating the relationship between inputs and outputs through the repeated learning training of known information and by gradually adjusting the connection weights of neurons. ANN is widely used in image recognition, speech recognition, weather forecasting, and facial feature recognition due to its parallelism, efficiency, and flexibility. The self-organizing map (SOM) is a typical ANN algorithm that is trained via unsupervised learning to create a two-dimensional and discrete input example called a map. To exploit the excellence of cluster-based routing algorithms in increasing the lifetime of WSNs, the energy-based clustering self-organizing map (EBC-S) was proposed in [65], which creates clusters with the same energy level, allowing a balanced energy load in the network. In the cluster creation process, SOM and K-means methods are used together to create clusters. First, vector \(V\), which represents the X-Y coordinates and energy of the nodes are input to the SOM. These parameters are normalized as \(V^{1}\):  
\[V^{1}=\frac{V-\min_{a}}{\max_{a}-\min_{a}}, \tag{6}\]  
where \(\max_{a}\) and \(\min_{a}\) are the highest and smallest value for feature \(a\). Then, the base station selects \(n\) nodes by maximum energy, which is considered the weight vector of the SOM. The data are transmitted from the common nodes to the cluster head and aggregated at the cluster head, and then, the information obtained by the cluster head will be sent to the base station. Energy consumption \(E_{Tx}(k,d)\) of transmitting \(k\) bit data with distance \(d\) is calculated as:  
\[E_{Tx}(k,d)\ =E_{elec}(k,d)\ +\ E_{Tx\_amp}(k,d), \tag{7}\]  
where \(E_{elec}(k,d)\) is the energy for transmitting/receiving \(k\) bit data with distance \(d\), \(E_{Tx\_amp}(k,d)\) is the amplification energy of transmitting \(k\) bit data with distance \(d\). The weight matrix consists of the X-Y coordinates of the nodes and the residual energy of the nodes. The nodes with less energy move closer to the high-energy nodes and form clusters aggregated by the SOM. The result of the SOM is specified as the input to the K-means algorithm. Then, cluster heads are selected based on the maximum energy of the nodes, the distance of the nodes from the base station, and the proximity of the nodes to the cluster center. In addition, the EBC-S is deployed on the base station and centralized computation, which assigns the role to each node, whether it is a cluster head or a node. This hybrid scheme considers the energy consumption to extend the lifetime of WSNs. To guarantee the QoS of the network, an ANN-based routing (ANNR) algorithm [66] was proposed to detect the best path using the SOM unsupervised learning, and the ANNR model is shown in Figure 8.  
ANNR adopts a revised Dijkstra algorithm to form a backbone network and minimize the cost path from the sink to each node in WSNs, which adopts QoS parameters as the influencing factor in defining the edge weight coefficients, including delay, throughput, error rate, and duty cycle. Due to the distributed nature of WSNs, ANNR defines the QoS level in a diffuse way. Each node periodically tests the quality of each neighboring link with Ping packets to get input samples. In the training phase, the second layer neurons compete for high weights in the learning chain among each other. Consequently, the weights of the winning neurons and their neighboring neurons are updated through the neighborhood function to further match the input patterns and obtain the QoS value. Then, node \(v_{j}\) uses the obtained QoS value to calculate the distance \(d[v_{j},v_{r}]\) to the base station \(v_{r}\) through neighbor node \(v_{i}\) to avoid the region with the worst QoS level.