# Research on Danjiang Water Quality Prediction Based on Improved Artificial Bee Colony Algorithm and Optimized BP Neural Network

Authors: Jian’qiang He; Naian Liu; Mei’lin Han; Yao Chen
Journal: Scientific Programming
 (2021)

---

## 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.


---

## Body

## 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.Figure 1
BP neural network model structure diagram.Suppose the number of nodes in the input layer, hidden layer, and output layer of the BP neural network isn, 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 wij and wjk, respectively; the thresholds of the hidden layer and the output layer are tj and tk, respectively; f is the transfer function; the expected output of the output layer is dk.The output of the hidden layer node and the output layer node is(1)yj=f∑i=1nwijxi−tj=fnetj,ok=f∑j=1mwjkyj−tk=fnetk.The error between the output value and the expected output is(2)E=12∑k=1ldk−ok2=12∑k=1ldk−f∑j=1mwjkf∑i=1nwijxi−tj−tk2.It can be seen from the error formula that the errorE can be changed by adjusting the weights wij and wjk, and the weight adjustment is proportional to the drop of the error gradient, then for the output layer and the hidden layer(3)Δwjk=−η∂E∂wjk=−η∂E∂netk∂netk∂wjk=ηδkyj,Δwij=−η∂E∂wij=−η∂E∂netj∂netj∂wij=ηδjxi,where η is the learning rate,(4)δk=−∂E∂netk=dk−okf′netk=dk−okok1−ok,δj=−∂E∂netj=f′netj∑k=1lδkwjk=∑k=1lδkwjkyj1−yj.Among them, the transfer functionfx=1+e−x−1, then f′x=fx1−fx.BP weight adjustment formula is(5)Δwjk=ηdk−okok1−okyj,Δwij=η∑k=1lδkwjkyj1−yjxi.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 .(6)xijnew=xmin,j+randxmax,j−xmin,j,where xijnew is the position of the initial solution, xmin,j and xmax,j are the upper and lower bounds of j dimension, i=1,2,3⋯,N; j=1,2,3⋯,K; And both i,j are randomly generated and are not equal to each other; rand is a randomly generated number between 0 and 1.Suppose the probability of finding a new high-quality nectar source and being selected is(7)pi=fiti∑n=1Nfitn.In the formula,fiti represents the ith 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.(8)fiti=11+fi,fi>0,11+absfi,fi<0,where fi is the objective function value of the ith 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].(9)vij=xij+rxij−xtj.In the formula,j=1,2,3⋯,K; t=1,2,3⋯,N, and t is not equal to i, both t and j are randomly generated; r 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(10)vij=ωxij+rxij−xtj.In the formula,xij is the previous worst source of nectar.The introduction ofω can speed up the algorithm convergence speed and avoid premature maturity. The change of ω is(11)ω=ωmin+ωmax−ωmin×Tmax−cTmax,where ωmax and ωmin are the maximum and minimum values of inertia weight; Tmax is the maximum number of maximum mixing iterations between the subpopulations; c 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:(12)vijnew=ωxij+rxij−xtj×Ljt⊕.In the formula,Ljt 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):(13)xijnew=ωxij+rxij−xtj×Ljt,(14)xtj=xtj+xij.


## 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 .(6)xijnew=xmin,j+randxmax,j−xmin,j,where xijnew is the position of the initial solution, xmin,j and xmax,j are the upper and lower bounds of j dimension, i=1,2,3⋯,N; j=1,2,3⋯,K; And both i,j are randomly generated and are not equal to each other; rand is a randomly generated number between 0 and 1.Suppose the probability of finding a new high-quality nectar source and being selected is(7)pi=fiti∑n=1Nfitn.In the formula,fiti represents the ith 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.(8)fiti=11+fi,fi>0,11+absfi,fi<0,where fi is the objective function value of the ith 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].(9)vij=xij+rxij−xtj.In the formula,j=1,2,3⋯,K; t=1,2,3⋯,N, and t is not equal to i, both t and j are randomly generated; r 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(10)vij=ωxij+rxij−xtj.In the formula,xij is the previous worst source of nectar.The introduction ofω can speed up the algorithm convergence speed and avoid premature maturity. The change of ω is(11)ω=ωmin+ωmax−ωmin×Tmax−cTmax,where ωmax and ωmin are the maximum and minimum values of inertia weight; Tmax is the maximum number of maximum mixing iterations between the subpopulations; c 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:(12)vijnew=ωxij+rxij−xtj×Ljt⊕.In the formula,Ljt 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):(13)xijnew=ωxij+rxij−xtj×Ljt,(14)xtj=xtj+xij.


## 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(10)vij=ωxij+rxij−xtj.In the formula,xij is the previous worst source of nectar.The introduction ofω can speed up the algorithm convergence speed and avoid premature maturity. The change of ω is(11)ω=ωmin+ωmax−ωmin×Tmax−cTmax,where ωmax and ωmin are the maximum and minimum values of inertia weight; Tmax is the maximum number of maximum mixing iterations between the subpopulations; c 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:(12)vijnew=ωxij+rxij−xtj×Ljt⊕.In the formula,Ljt 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):(13)xijnew=ωxij+rxij−xtj×Ljt,(14)xtj=xtj+xij.


## 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 (IMn), 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.Figure 2
Water quality prediction model.Figure 3
Algorithm flow chart.Step 1.
Take 6 indicators of NH3–N, DO, COD, IMn, total phosphorus, and total nitrogen as the input of the BP network for training.Step 2.
Optimize the weightswij,wjk and tj,tk 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 Figure4 and Table 1, respectively.Figure 4
Geographical distribution map of water quality monitoring points.Table 1
Site name and latitude and longitude information.
Monitoring point numberSite nameLongitude (degrees)Latitude (degrees)Monitoring point 1Gouyu bridge110.0217633.88903Monitoring point 2Wangyuan bridge109.9228333.87804Monitoring point 3Jinyuan water bank109.9315333.86736Monitoring point 4Overpass109.9383633.86604Monitoring point 5Rainbow bridge109.9555333.86311Monitoring point 6Renyuan bridge109.9705233.85894


### 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, IMn, total phosphorus and total nitrogen [17], which correspond to The water quality grades and content standards are shown in Table 2.Table 2
Water quality content grades and classification standards.
Taxon descriptionClass 1Class 2Class 3Class 4Class 5NH3–N/mg • L−10–0.150.15–0.500.5–1.01.0–1.51.5–2.0DO/mg • L−17.5–6.06.0–5.05.0–4.04.0–2.02.0–0COD/mg • L−10–1010–1515–2020–3030–40IMn/mg • L−10–2.02.0–4.04.0–6.06.0–1010–15Total phosphorus/mg • L−10–0.020.02–0.100.10–0.200.20–0.300.30–0.40Total nitrogen/mg • L−10–0.200.20–0.500.50–1.01.0–1.51.5–2.0


### 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].(15)y=2Xi−XminXmax−Xmin−1.In the formula,Xi represents the original water quality data, Xmax is the maximum value in the original data sequence, Xmin 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:(16)C=TNN×100%.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, IMn, 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.Table 3
Comparison of water quality evaluation accuracy.
MethodTraining set accuracy (%)Test set accuracy (%)OptimalWorstAverage valueOptimalWorstAverage valueGA-BP92.7291.6892.293.2492.1792.70PSO-BP92.6892.1992.4393.1692.3992.77ABC-BP92.9492.3892.6693.9593.4293.68Improved ABC-BP96.5893.3694.9797.2393.8995.56Figure 5
Training set.Figure 6
Test set.From the comparison results of the evaluation accuracy in Table3, 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.Figures7 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.Figure 7
BP network simulation diagram.Figure 8
AMABC and ABC optimization comparison chart.Figure 9
Fitting diagram of actual output and target output.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 Figure10.Figure 10
Relationship between different parameters and accuracy (a) Number of hidden layer nodes (b) Learning rate (c) Number of iterations.
(a)(b)(c)It can be seen from Figure10(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.Table 4
Comparison of optimization algorithms.
Algorithm nameIteration time (ms)Accuracy rate of water quality evaluation (%)GA-BP51.692.43PSO-BP49.892.87ABC-BP44.393.58Improved ABC-BP42.195.56


## 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 Figure4 and Table 1, respectively.Figure 4
Geographical distribution map of water quality monitoring points.Table 1
Site name and latitude and longitude information.
Monitoring point numberSite nameLongitude (degrees)Latitude (degrees)Monitoring point 1Gouyu bridge110.0217633.88903Monitoring point 2Wangyuan bridge109.9228333.87804Monitoring point 3Jinyuan water bank109.9315333.86736Monitoring point 4Overpass109.9383633.86604Monitoring point 5Rainbow bridge109.9555333.86311Monitoring point 6Renyuan bridge109.9705233.85894


## 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, IMn, total phosphorus and total nitrogen [17], which correspond to The water quality grades and content standards are shown in Table 2.Table 2
Water quality content grades and classification standards.
Taxon descriptionClass 1Class 2Class 3Class 4Class 5NH3–N/mg • L−10–0.150.15–0.500.5–1.01.0–1.51.5–2.0DO/mg • L−17.5–6.06.0–5.05.0–4.04.0–2.02.0–0COD/mg • L−10–1010–1515–2020–3030–40IMn/mg • L−10–2.02.0–4.04.0–6.06.0–1010–15Total phosphorus/mg • L−10–0.020.02–0.100.10–0.200.20–0.300.30–0.40Total nitrogen/mg • L−10–0.200.20–0.500.50–1.01.0–1.51.5–2.0


## 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].(15)y=2Xi−XminXmax−Xmin−1.In the formula,Xi represents the original water quality data, Xmax is the maximum value in the original data sequence, Xmin 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:(16)C=TNN×100%.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, IMn, 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.Table 3
Comparison of water quality evaluation accuracy.
MethodTraining set accuracy (%)Test set accuracy (%)OptimalWorstAverage valueOptimalWorstAverage valueGA-BP92.7291.6892.293.2492.1792.70PSO-BP92.6892.1992.4393.1692.3992.77ABC-BP92.9492.3892.6693.9593.4293.68Improved ABC-BP96.5893.3694.9797.2393.8995.56Figure 5
Training set.Figure 6
Test set.From the comparison results of the evaluation accuracy in Table3, 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.Figures7 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.Figure 7
BP network simulation diagram.Figure 8
AMABC and ABC optimization comparison chart.Figure 9
Fitting diagram of actual output and target output.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 Figure10.Figure 10
Relationship between different parameters and accuracy (a) Number of hidden layer nodes (b) Learning rate (c) Number of iterations.
(a)(b)(c)It can be seen from Figure10(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.Table 4
Comparison of optimization algorithms.
Algorithm nameIteration time (ms)Accuracy rate of water quality evaluation (%)GA-BP51.692.43PSO-BP49.892.87ABC-BP44.393.58Improved ABC-BP42.195.56


## 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.



---

*Source: 3688300-2021-12-29.xml*