# Data Transmission in Wireless Sensor Networks Based on Ant Colony Optimization Technique
## 2 Materials and Methods
### WOA-BP Algorithm  
The WOA-BP neural network model is prone to convergence to local optima due to the randomness of the initial weights and thresholds in traditional BP neural networks, which affects the final prediction performance. To solve the above problems, the WOA is used to improve the BP neural network. The specific process is as follows.  
1. Collect the data obtained from numerical models, divide the dataset, and normalize it.
2. Initialize the BP neural network, set the training frequency, learning rate, and learning accuracy, and determine the neural network structure.
3. Initialize the WOA parameters and use the mean squared error of the training and testing samples as the fitness function.
4. Calculate the fitness value of whales using Formulas (12) and (13) and record the optimal individual position.
5. Use Formulas (16) and (17) to choose different ways to update the whale position.
6. Determine whether the termination conditions are met. If the maximum number of iterations is reached, the optimal initial weights and thresholds are output. Otherwise, repeat steps (4)-(5).  
Figure 18: BP calculation flowchart.  
(7) Assign the optimal initial weights and thresholds to the BP neural network.  
(8) Calculate the output error of the BP neural network.  
(9) Determine whether the termination conditions are met. If the output error reaches the preset learning accuracy or maximum training frequency, the prediction result can be output after reverse normalization processing. Otherwise, update the weights and thresholds first, and then repeat steps (8)-(9).  
The process of improving the BP neural network using the WOA algorithm is shown in Figure 20.  
Figure 19: Global optimum graph.  
Figure 20: WOA-BP.  
The simulation data come from the sensor battery health status dataset, which is a multi-input dataset and simulated using the MATLAB R2023b tool.  
From the Figure 21, it can be seen that as the number of training sessions increases, the error becomes smaller and smaller.  
From the Figure 22, it can be seen that the maximum error is 8.688 and the sample size is 1.  
From the Figure 23, it can be seen that the maximum error is 2.352 and the sample size is 6.  
We can then determine the optimal hidden layer node.  
As shown in Figure 23, The optimal number of hidden layer nodes is 8, with a mean squared error of 0.018178.  
In Table 4, a comparison of errors between BP neural network and WOA-BP neural network is made from five dimensions. The average absolute error of BP Neural Network is 2.9143, which is greater than the average absolute error of WOA-BP Neural Network of 1.7029; The mean square error of BP Neural Network is 12.1307, which is greater than the mean square error of WOA-BP Neural Network, which is 6.5033; The root mean square error of BP Neural Network is 3.4829, which is greater than the root mean square error of WOA-BP Neural Network of 2.5501; The average absolute percentage error of BP Neural  
Figure 21: Comparison between predicted value and actual value.  
Figure 22: BP error histogram with 20 bins.  
Network is 21.3418%, which is greater than the average absolute percentage error of WOA-BP Neural Network of 9.7347%; The prediction accuracy of BP Neural Network is 78.6582%, which is lower than the prediction accuracy of WOA-BP Neural Network of 90.2653%. Therefore, the accuracy of WOA-BP Neural Network is 11.6071% higher than that of BP Neural Network.