#### Abstract

In order to ensure “a river of clear water is supplied to Beijing and Tianjin” and improve the water quality prediction accuracy of the Danjiang water source, while avoiding the local optimum and premature maturity of the artificial bee colony algorithm, an improved artificial bee colony algorithm (ABC algorithm) is proposed to optimize the Danjiang water quality prediction model of BP neural network is proposed. This method improves the local and global search capabilities of the ABC algorithm by adding adaptive local search factors and mutation factors, improves the performance of local search, and avoids local optimal conditions. The improved ABC algorithm is used to optimize the weights and thresholds of the BP neural network to establish a water quality grade prediction model. Taking the water quality monitoring data of Danjiang source (Shangzhou section) from 2015 to 2019 as the research object, it is compared with GA-BP, PSO-BP, ABC-BP, and BP models. The research results show that the improved ABC-BP algorithm has the highest prediction accuracy, faster convergence speed, stronger stability, and robustness.

#### 1. Introduction

The Party Central Committee, State Council, Provincial Committee, and Provincial Government attach great importance to the work of ecological environment protection in Qinling area. General Secretary Xi Jinping emphasized: “No one can destroy the natural ecological beauty of the Qinling Mountains.” The Danjiang River originates from the southern foot of the Qinling Mountains in the northwestern part of Shangluo, Shaanxi Province, and flows through Shaanxi Province, Henan Province, and Hubei Province. It is injected into Danjiangkou Reservoir in Danjiangkou City of Hubei Province and intersects with the Han River [1]. The total length of the mainstream is 390 km, which is the longest tributary of the Hanjiang River. The basin area is 17300 square kilometers, accounting for 10% of the total area of the Hanjiang River Basin [2]. The Danjiang River is an important water source for the Middle Route Project of the “South-to-North Water Diversion”. In recent years, Shangluo City has fully implemented the circular development strategy to protect the water sources, built ecological Shangluo, and ensured that “a river of clean water is supplied to Beijing and Tianjin.” However, with the advancement of the resettlement project and social economic development, more and more domestic sewage is discharged to the Danjiang River, which directly affects the water quality of the Danjiang River Basin. Therefore, by predicting the water quality of the Danjiang River Basin, a scientific decision-making basis can be provided for the protection and management of the water environment.

The currently used common methods for water quality prediction include the GM model, artificial neural network, and SVM. In the literature [3], the gray prediction method is used for water quality prediction. This method is only suitable for short-term prediction. There is also the disadvantage that the larger the gray level of the data, the lower the prediction accuracy. Literature [4] and Literature [5] proposed a water quality prediction model based on the weighted combination, combined exponential smoothing method, and water quality prediction model of GM (1,1) model. Compared with the literature [3], the prediction accuracy of this method has been improved to a certain extent, but there is a problem of excessive error, which cannot be solved. Literature [6] and Literature [7] proposed an improved water quality prediction model based on the gray GM(1,1) model, which is much better than the traditional gray GM(1,1) model. The BP neural network has the advantages of self-learning and fault tolerance, which is widely used in water quality prediction. In the literature [8], BP neural network was applied to the study of water quality evaluation and temporal-spatial evolution trend of water quality. The results showed that the evaluation results of this method were more objective and the evaluation process was more convenient. Aiming at the problem of low prediction accuracy of small sample data and easy to fall into local optimum of BP neural network, a water quality prediction model of double hidden layer BP neural network based on artificial bee colony algorithm is proposed in the literature [9], the initial weights and thresholds of BP neural network are optimized by the ABC algorithm, and the prediction accuracy is improved. However, the BP neural network with double hidden layers has overfitting, which easily leads to the decrease of the generalization ability of the prediction model.

Aiming at the problems existing in the current water quality prediction model, this paper improves the local and global search ability of the ABC algorithm by adding adaptive local search factors and mutation factors. The improved ABC algorithm is used to optimize the weights and thresholds of the BP neural network, and the improved ABC-BP hybrid neural network model is obtained. Taking the water quality monitoring data of the source of Dan River (Shangzhou District) from 2015 to 2019 as the research object, compared with GA-BP, PSO-BP, ABC-BP, and BP models. The results show that the algorithm has the highest prediction accuracy and faster convergence speed.

#### 2. Principle of BP Neural Network

BP neural network is mainly composed of input layer, hidden layer (one or more layers), and output layer [10]. The neurons in the same layer are not interconnected, and the neurons in the adjacent layer are connected by weights, and the output of each layer of nodes only affects the input of the nodes of the lower layer. The BP neural network model structure is shown in Figure 1. The learning process of the BP neural network is mainly composed of two parts: forward propagation of signal and backpropagation of error. In the forward propagation process of the signal, after the input signal passes through the network weight, threshold, and neuron transfer function, an output signal can be obtained in the output layer. If the error between the output value and the expected value is greater than the specified amount, then the error will be entered The backpropagation process of the error, that is, through the error return layer by layer, the error is “allocated” to the neurons of each layer, and the weight is self-adjusted until the error between the output data value of the output layer and the expected data value reaches the preset range, then the training of the network is completed.

Suppose the number of nodes in the input layer, hidden layer, and output layer of the BP neural network is *n*, *m*, and *l,* respectively; the weights between the input layer and the hidden layer and the weights between the hidden layer and the output layer are and , respectively; the thresholds of the hidden layer and the output layer are and , respectively; is the transfer function; the expected output of the output layer is .

The output of the hidden layer node and the output layer node is

The error between the output value and the expected output is

It can be seen from the error formula that the error can be changed by adjusting the weights and , and the weight adjustment is proportional to the drop of the error gradient, then for the output layer and the hidden layerwhere is the learning rate,

Among them, the transfer function , then .

BP weight adjustment formula is

Since the BP neural network has slow convergence speed and low prediction accuracy, it cannot meet the performance requirements of water quality prediction. Therefore, this paper uses an improved artificial bee colony algorithm to optimize the weights and thresholds of the BP neural network to improve its water quality prediction performance.

#### 3. Artificial Bee Colony Algorithm

In order to solve the problem of multivariate function optimization, Karaboga proposed the artificial bee colony (ABC) algorithm model in 2005, which simulates the honey-collecting behavior of bees to search for global optimization goals [11, 12].

##### 3.1. Basic Artificial Bee Colony Algorithm

Artificial bee colony algorithm is a swarm intelligence optimization algorithm that simulates the process of bees searching for the best quality and the largest number of nectar sources in nature. The algorithm contains three types of bee colonies: collecting bees, observing bees, and investigating bees. The nectar source is a possible solution in the solution space. Assuming that the algorithm is solved in the K-dimensional space, the total amount of nectar source is N, and the initial position formula is .where is the position of the initial solution, and are the upper and lower bounds of j dimension, ; ; And both are randomly generated and are not equal to each other; is a randomly generated number between 0 and 1.

Suppose the probability of finding a new high-quality nectar source and being selected is

In the formula, represents the *i*^{th} nectar source, that is, the fitness value of the solution. If the fitness of the new solution is higher than the original solution, it will be replaced by the new solution.where is the objective function value of the *i*^{th} solution.

When falling into the local optimum, the honey bee will abandon the nectar source and become a scout bee. According to formula (9), a new nectar source position will be randomly generated to replace the corresponding position in the initially marked nectar source to determine the final nectar source. According to this, iteration is carried out repeatedly until the termination condition of the algorithm is reached [13].

In the formula, ; , and *t* is not equal to *i*, both *t* and *j* are randomly generated; is a randomly selected value between [1,−1].

##### 3.2. Improved Artificial Bee Colony Algorithm

In order to enhance the global optimization and local search capabilities of the algorithm, adaptive local search factors and mutation factors are added to improve the ABC algorithm to avoid premature phenomena [14].

###### 3.2.1. Adaptive Search Factor

In the initial search stage of the algorithm, an adaptive local search factor is introduced to prevent falling into local optimization. The local search is enhanced by adaptively adjusting the population update step size, and the global and local search capabilities of the algorithm are balanced. That is, equation (9) is updated to

In the formula, is the previous worst source of nectar.

The introduction of can speed up the algorithm convergence speed and avoid premature maturity. The change of iswhere and are the maximum and minimum values of inertia weight; is the maximum number of maximum mixing iterations between the subpopulations; represents the total number of iterations of the current subpopulation.

###### 3.2.2. Variation Factor

In order to improve the global optimization ability and accuracy of the algorithm, the mutation factor Levy is introduced. Compared with other operators (such as the Gaussian operator, etc.), the mutation factor can greatly improve the global optimization ability of the algorithm and prevent the algorithm from emergence of precocious puberty. The introduction of the Levy mutation factor enhances the global optimization capability of the algorithm based on the adaptive factor. The specific implementation is to add the Levy mutation operator to equation (3) and update it to the following equation:

In the formula, is a random number that obeys the Levy distribution.

After introducing the adaptive mutation factor, the local update method of the ABC algorithm is shown in equations (13) and (14):

#### 4. Improved Water Quality Prediction Model of ABC-BP Algorithm

In this paper, a water quality prediction model is established by improving the ABC-BP algorithm. The input of the BP neural network is ammonia nitrogen (NH3–N), dissolved oxygen (DO), chemical oxygen demand (COD), permanganate index (I_{Mn}), and total phosphorus, six water quality evaluation indicators of total nitrogen and total nitrogen, and the output is the water quality grade. The water quality prediction model is shown in Figure 2, and the algorithm flow chart is shown in Figure 3.

*Step 1. *Take 6 indicators of NH3–N, DO, COD, I_{Mn}, total phosphorus, and total nitrogen as the input of the BP network for training.

*Step 2. *Optimize the weights and thresholds trained by the BP network.

*Step 3. *Determine whether the output data O and the error value meet the requirements, if the requirements are met by the formula (6), the optimal solution is the output, and the optimal weight and threshold are obtained.

*Step 4. *If the requirements are not met, the search bee will find a new nectar source according to formula (13) and output the value of the solution.

*Step 5. *Repeat the loop, and finally get the optimal solution.

*Step 6. *If the number of calculations exceeds the set maximum number of iterations, the training ends, otherwise the function of formula (7) is returned.

*Step 7. *Obtain the optimal solution, and verify the BP neural network according to the weight and threshold.

#### 5. Experimental Analysis

##### 5.1. Data Source

In order to verify the reliability and effectiveness of the improved ABC-BP algorithm for water quality prediction, the water quality measurement data from the six monitoring points in the Shangzhou section of Shangluo City in the Danjiang River Basin from 2015 to 2019 was used as the research object for experimental research. The geographical distribution and latitude and longitude information of water quality monitoring points are shown in Figure 4 and Table 1, respectively.

##### 5.2. Water Quality Evaluation Index

Water quality evaluation is the process of determining the water quality level of the sampled water sample based on the various index values of the sampled water sample and the water quality evaluation standard, combined with a certain mathematical model [15]. Since there are many indicators for water quality analysis [16], combined with surface water environmental quality standards, the water quality evaluation indicators used in this article are DO, NH3–N, COD, I_{Mn}, total phosphorus and total nitrogen [17], which correspond to The water quality grades and content standards are shown in Table 2.

##### 5.3. Data Preprocessing and Evaluation Indicators

In order to improve the accuracy of the predicted data, use formula (15) to normalize the data and convert the data to the range of [−1, 1].

In the formula, represents the original water quality data, is the maximum value in the original data sequence, is the minimum value in the original data sequence, and *y* represents the data after the normalization transformation, which can reduce the difference between the result and the actual value The deviation. In order to facilitate the comparison of water quality grade evaluation of different evaluation methods, formula (16) is used as the evaluation index of water quality grade evaluation:

In the formula, *C* represents the accuracy of evaluation; *N* is the total number of samples; *TN* is the number of samples correctly classified.

##### 5.4. Experimental Results and Analysis

The water quality measured data from 2015 to 2019 in the Shangzhou section of Shangluo city in the Danjiang River basin was selected as the research object. After sorting, the measured data was divided into two parts: a training set and a test set. The training set was mainly used to establish a Danjiang water quality prediction model, the test set is mainly used to test the pros and cons of the built model. In order to verify the superiority of the improved ABC-BP algorithm, it is compared with GA-BP, PSO-BP, and ABC-BP algorithms.

Six indicators of NH3–N, DO, COD, I_{Mn}, total phosphorus, and total nitrogen were used as the input of the improved ABC-BP model, and the water quality grade was used as the output of the improved ABC-BP model to establish the improved ABC-BP water quality evaluation model [18, 19]. This article sets the number of input layer nodes of the BP network inputnum = 6, the number of hidden layer nodes hiddennum = 20, the output layer node outputnum = 5, the hidden layer transfer function is the purelin function, the output layer transfer function is the logsig function, and the training function is the trainlm function, The maximum number of training times is set to 1000 times, and the learning accuracy target is 0.0001. Different algorithms are run independently for 10 times, and the average of the 10 water quality prediction results is used as the final evaluation result. The population size of GA-BP, PSO-BP, and ABC-BP algorithms are all set to 10, the maximum number of iterations is 100, the search interval is [−1,1], the algorithm runs 10 times independently, and the results of 10 water quality predictions The average value is used as the final evaluation result [20]. The results are shown in Table 3, Figures 5 and 6.

From the comparison results of the evaluation accuracy in Table 3, it can be seen that in the training set and test set, the optimal accuracy rate of improved ABC-BP is the highest, 96.58% and 97.32%, respectively, and the accuracy rate is higher than that of GA-BP, PSO-BP, and ABC-BP; compared with the ABC-BP, the optimal accuracy rate is increased by 3.64% and 3.28%, respectively; compared with the PSO-BP, the optimal accuracy rate is increased by 3.90 and 4.07%, respectively; compared with the GA-BP, the optimal accuracy rates were increased by 3.86% and 3.99%, respectively, indicating that the improved ABC-BP can effectively improve the accuracy of water quality evaluation.

On the training set and test set, the worst and average accuracy rates of the improved ABC-BP algorithm are higher than those of GA-BP, PSO-BP, and ABC-BP, which shows that the improved ABC-BP algorithm has better stability and robustness.

Figures 7 and 8 are the simulation comparison diagrams between the single BP neural network algorithm, the improved ABC-BP algorithm, the standard ABC-BP algorithm iteration number, and the target error. From the figure, it can be seen that the improved ABC-BP algorithm, the number of iterations of the BP algorithm tending to the target error value is lower than that of the other two algorithms. When the standard ABC algorithm falls into the local optimization, the improved ABC-BP algorithm can jump out of the local optimization. Due to the addition of the levy factor and the adaptive factor, the prediction accuracy, convergence speed, and stability of the improved ABC-BP algorithm are greatly improved. Figure 9 is a fitting diagram of actual output and target output. It can be seen from the figure that the fitting is better, indicating that the improved ABC-BP algorithm has better convergence.

In order to compare and study the influence of different hidden layer node numbers, learning rate, and iteration number parameters on the water quality prediction and evaluation results, the accuracy rates of different parameters were compared, and the results are shown in Figure 10.

**(a)**

**(b)**

**(c)**

It can be seen from Figure 10(a) that the accuracy rate of the water quality evaluation model gradually increases with the number of hidden layer nodes. When the number of nodes is 20, the accuracy rate reaches the maximum, and when the number of hidden layer nodes increases, the accuracy rate gradually decreases, and the network complexity increases. Therefore, considering the prediction accuracy, network generalization ability, and complexity, the best number of hidden layer nodes of the BP neural network is 20. It can be seen from Figure 10(b) that as the learning rate increases, the accuracy of the water quality evaluation model gradually increases. When the learning rate is 0.05, the accuracy reaches the maximum, and after it exceeds 0.05, the accuracy gradually increases and then it reduces. It can be seen that when the learning rate is 0.05, the effect of the model is the best, and the generalization ability and accuracy rate reach the best state. It can be seen from Figure 10(c) that as the number of iterations increases, the accuracy of the water quality evaluation model gradually increases. When the number of iterations is about 500, the prediction accuracy is the highest. After more than 500, the accuracy increases with iterations. The increase in frequency gradually decreases. It can be seen that when the number of iterations is about 500, the local search ability and global search ability of the model are the best, and the accuracy rate is the highest. At the same time, the iteration time and prediction accuracy of GA-BP, PSO-BP, ABC-BP, and improved ABC-BP are compared, and the results are shown in Table 4. Analysis of the results shows that the improved ABC-BP algorithm has the shortest iteration time, the highest accuracy, and the best model. The above analysis lays the foundation for the construction of the later water quality evaluation model and the study of parameter selection.

#### 6. Conclusion

In order to build a stable, reliable, and highly accurate water quality prediction model, an improved ABC-BP algorithm model is proposed. By adding the adaptive local search factors and mutation factors, the local and global search capabilities of the ABC algorithm are improved to improve the performance of local search and avoid local optimal conditions. The improved ABC algorithm is used to optimize the weights and thresholds of the BP neural network and establish a water quality grade prediction model. Taking the water quality monitoring data of Danjiang source (Shangzhou section) from 2015 to 2019 as the research object, compared with GA-BP, PSO-BP, ABC-BP, and BP models, the research results show that the improved ABC-BP algorithm has lower iterations, faster convergence speed, highest prediction accuracy, and has good engineering application and promotion value. Since there are fewer evaluation indicators that affect the water quality grade in this article, more water quality evaluation methods with more influencing factors will be studied later to further improve the applicability of the model.

#### Data Availability

The datasets used and/or analyzed during the current study are available from the corresponding author on reasonable request.

#### Conflicts of Interest

The author(s) declare no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.

#### Acknowledgments

The authors acknowledge the National Natural Science Foundation of China (Grant: 61876143), Shaanxi Provincial Department of Education 2019 Special Scientific Research Plan Project (Grant: 19JK0261), Shaanxi Provincial Department of Science and Technology 2019 Scientific Research Plan Project (Grant: 2019JQ-541), and Special Project of Shangluo University Serving Local Scientific Research (Grant: 19FK002).