River total nitrogen concentration prediction method based on hybrid neural network
1. A river total nitrogen concentration prediction method based on a hybrid neural network is characterized by comprising the following steps:
step 1: collecting 28390river section water quality data once every four hours through a collecting module of the Internet of things equipment, and cleaning an original water quality data set of a river area to be predicted;
step 2: dividing river water quality data of an area to be predicted into a training set and a testing set; constructing a model, wherein the model mainly comprises two modules: the device comprises a feature learning module and a prediction generation module; the feature learning module uses 1-DRCNN, and the prediction generation module uses BiGRU and a full connection layer;
and step 3: training the model constructed in the step 2 by using an Adam optimization algorithm, obtaining an optimal water quality parameter prediction model after the training is finished, and predicting the total nitrogen concentration of the river to be predicted in a test set;
and 4, step 4: and evaluating the performance of the model by using model evaluation indexes comprising average absolute error, average absolute percentage error, root mean square error and decision coefficient.
2. The method for predicting the total nitrogen concentration of the river based on the hybrid neural network as claimed in claim 1, wherein: the river water quality data to be predicted in the data cleaning method in the step 1 comprises 9 water quality parameters including temperature (T, DEG C), PH, dissolved oxygen (COD, mg/L), biochemical oxygen demand (BOD, mg/L), turbidity (NTU), potassium permanganate (COD-Mn, mg/L), ammonia nitrogen (NH3-N, mg/L), total phosphorus (TP, mg/L) and total nitrogen (TN, mg/L).
3. The method for predicting the total nitrogen concentration of the river based on the hybrid neural network as claimed in claim 1, wherein: the data cleaning method in the step 1 has the functions of detecting abnormal values of river water quality data to be predicted and filling vacancy values;
wherein, the abnormal value detection of the water quality data to be predicted by using the soliton is mainly divided into two steps:
firstly, constructing an isolated forest; the method comprises the steps of recursively dividing a water quality data set to be predicted without considering the distance or the density of two samples of the water quality data set to be predicted, and constructing an isolated tree until all sample points are isolated;
secondly, calculating an abnormality score, wherein the formula is as follows:
wherein n represents the size of the water quality sample data x to be predicted, H (n-1) represents a harmonic function, and the harmonic function is estimated by ln (n-1) + 0.5772156649; c (n) represents the average path length of a binary tree constructed by the water quality sample data to be predicted of n samples, and the average path length is mainly used for normalization; e (h (x)) represents the mean value of the path lengths of the sample data x to be predicted in a plurality of iTrees; if the node score is closer to 1, the more likely the sample node is abnormal; if the score of the sample node is closer to 0, the node is normal;
after abnormal value detection is carried out on the water quality data to be detected, setting the water quality data to be detected as a null value; then filling the package by using a method based on the Langerhan method; finding out a polynomial function which can give out a plurality of known points which just pass through a two-dimensional plane according to the non-vacant m sample points of the water quality data set to be predicted, and obtaining observed values just at each observation point; realizing filled vacancy values according to the polynomial function; the polynomial function formula of the lagrange interpolation method is thus as follows:
Lm(x)=y0l0(x)+y1l1(x)+...+ymlm
wherein, ymRepresenting the true value, l, of the corresponding sample point in the river water quality dataset to be predictedi(x) Representing an interpolation function corresponding to a sample point in a river water quality data set to be predicted:
4. the method for predicting the total nitrogen concentration of the river based on the hybrid neural network as claimed in claim 1, wherein: the specific steps of constructing the prediction model of the river total nitrogen concentration in the step 2 comprise:
step 2.1, randomly dividing a water quality data set of a river area to be tested into a training set and a testing set;
step 2.2, constructing a characteristic learning module 1-DRCNN network, and inputting the training set serving as the current water quality parameter into the 1-DRCNN network; 1-DRCNN can excavate and extract potential nonlinear relation characteristics among the current water quality parameters to form effective low-dimensional characteristics; the method uses two one-dimensional convolution residual blocks (1-DConv _ block) as a main body structure of a feature learning module, wherein each residual block mainly comprises 3 convolution layers of 1x1, 3 batch normalization layers (BN layer) and three activation functions (Selu), and the sizes of a filter and a convolution kernel of each convolution layer are set to be 32;
before each 1x1 convolutional layer is input, a Batch Normalization layer (BN layer) is needed to be used for carrying out transformation reconstruction on the output of the upper layer, the BN calculates first-order and second-order statistics of each Batch, the intermediate output of the one-dimensional convolutional neural network progressive layer is continuously adjusted, the high-layer network is continuously adapted to the parameter updating of the low-layer network, the output of each layer of the network tends to be stable, and the problem that the convergence speed of the network is reduced due to the fact that the gradient of the high-layer network disappears is solved; example a as above (a)1,...,ad) The reconstruction formula is as follows:
to pairAnd (3) carrying out reconstruction:
wherein the content of the first and second substances,represents the variance, β, of the sample(k)=E[a(k)]Representing the expectation of the sample;
in addition, the convolution layer of 1 × 1 performs convolution operations using convolution kernels having the same weight and different regions in the training set of the river water quality data input after reconstruction in the above-described embodiment, and learns the river water quality data in the above-described embodiment to remember all the positions in the training setGenerating a low-dimensional feature vector; output of each convolutional layerComprises the following steps:
f(x)=SELU=βmax(αezx-α,x)
in the formula (I), the compound is shown in the specification,is the input to the i-th neuron in the l-th layer network,is the output of the ith neuron in the l-1 th layer network,is a filter between the kth neuron of the l-1 th layer network and the ith neuron of the l-1 th layer network,defined as the bias of the kth neuron of the l-th layer network; the nonlinear feature mapping of the convolutional layer is realized by adopting an activation function f (); wherein, alpha and beta are fixed values, beta is 1.05070098, alpha is 1.67326324;
step 2.3, the 1-DRCNN output is used as a BiGRU model input, the BiGRU network autonomously captures the dependence relationship of short time sequence data, long time data and context attributes, a forward and backward combined hidden state is obtained, the dependence of time water quality parameters before and after learning and integration is learned, the water quality data expressed by characteristics is further optimized, and the BiGRU-based characteristic modeling process is described as follows:
in the formula, a GRU function represents that the GRU network is adopted to carry out nonlinear conversion on the embodiment, and an input vector is coded into a corresponding GRU hidden state; w is at、vtRespectively representing the forward hidden layer state of the bidirectional BiGUR at the time tAnd reverse hidden layer statesA weight; btA bias representing the hidden layer state at time t;
and 2.4, at the top layer of the model, taking the output of the BiGRU as the input of a full connection layer, wherein the full connection layer is used for generating a total nitrogen concentration predicted value in the river flow area to be predicted.
5. The method for predicting the total nitrogen concentration of the river based on the hybrid neural network as claimed in claim 1, wherein: step 3, training by using an Adam optimization algorithm, and obtaining an optimal river water quality prediction model after the training is finished, wherein the method specifically comprises the following steps:
step 3.1, in the model training process, using an optimizer Adma to adjust the weight and the deviation of the model, and calculating the error between the total nitrogen concentration of the river water output by the full-connection layer and the real concentration in the training set; when the error is smaller than a preset threshold value, finishing model training to obtain an optimal model;
and 3.2, predicting the total nitrogen concentration on the test set by using the trained optimal model to obtain a prediction result of the total nitrogen concentration.
6. The method for predicting the total nitrogen concentration of the river based on the hybrid neural network as claimed in claim 1, wherein: the performance indexes of the evaluation model in the step 4 are as follows:
where N is the size of the test set sample, yiIs a predicted value of the total nitrogen concentration of the model, YiIs the observed value (true value) of the ith total nitrogen concentration in the test set,is the average value of the observed values of the total nitrogen concentration in the test set; if the result of MAE, MAPE, RMSE is closer to 0, R2The closer to 1, the higher the prediction accuracy of the constructed model.
Technical Field
With the rapid development of economy and the rapid progress of science and technology in China, the production and living range of people is more and more extensive, and the domestic sewage, chemical fertilizers, food and other industrial wastewater and farmland drainage contain a large amount of nitrogen, phosphorus and other inorganic salts, so that the nutrient substances of rivers are greatly increased, and the water environment of the rivers is likely to generate the phenomenon of water eutrophication. The substance of the water eutrophication is that the input and output of nutritive salt are unbalanced, so that the distribution of water ecological substances is unbalanced, a single species is excessively swelled, the substance and energy flow of the system are damaged, and the whole ecological system gradually goes to death. River water quality deterioration has profound effects on the ecological health of surface water and its tributaries, which undoubtedly increases the burden of sustainable development of drinking water for humans. In the water environment treatment stage, the real-time prediction of the water quality can provide scientific basis for the protection and treatment of the water environment, and the construction of an accurate and effective water quality parameter prediction model is a crucial link for improving the water quality of rivers.
Most data-driven models have remarkable effect on water quality parameter prediction, and the main methods are a time sequence method, a grey theory prediction method, a regression prediction method (such as a support vector machine) and an artificial neural network prediction method. However, the first three methods have the defects of poor generalization ability, low prediction accuracy and the like. In recent years, deep learning methods have received increasing attention in water quality modeling. The artificial neural network is a machine learning technology for simulating a biological nervous system by widely and parallelly interconnecting adaptive simple units, is the basis of deep learning, and has the advantages of good robustness, capability of fully fitting complex nonlinear relations and the like. Therefore, the embodiment of the invention provides a river total nitrogen concentration prediction method based on a hybrid neural network, aiming at improving the stability and generalization capability of a model and reducing the prediction error of the total nitrogen concentration.
Disclosure of Invention
The invention aims to provide a river total nitrogen concentration prediction method based on a mixed neural network, and the method is used for predicting water quality parameters total nitrogen. In order to solve the problem that the existing and traditional single water quality prediction algorithm cannot mine the local characteristics of water quality and improve the prediction precision and efficiency, the overall network model mainly comprises two parts: the device comprises a feature learning module and a prediction generation module. The local characteristics of the water quality data are extracted by utilizing the one-dimensional convolution residual neural network, and the bidirectional gating circulation unit serving as a prediction module can integrate the information of the time sequence before and after and obtain the final prediction result of the water quality parameters. In order to improve the integrity of the data, before model training, the water quality data of the river is cleaned and corrected by adopting an isolation forest and a Langery interpolation method. The data set used for model training and testing comes from the real data set of \28390river. The method realizes the fusion of the neural network, and provides a brand-new deep learning water quality prediction method so as to improve the prediction precision of the water quality parameters.
In order to solve the problems, the invention adopts the following technical scheme:
a river total nitrogen concentration prediction method based on a hybrid neural network mainly comprises the following steps:
step 1, collecting 28390river section water quality data once every four hours through a collecting module of the Internet of things equipment, and cleaning an original water quality data set of a water quality area to be predicted.
And 2, dividing river water quality data of the area to be predicted into a training set and a testing set. Constructing a model, wherein the model mainly comprises two modules: the device comprises a feature learning module and a prediction generation module. The feature learning module uses 1-DRCNN, and the prediction generation module uses BiGRU and a full connection layer.
And 3, training the model constructed in the step 2 by using an Adam optimization algorithm, obtaining an optimal water quality parameter prediction model after the training is finished, and predicting the total nitrogen concentration of the river to be predicted in the test set.
And 4, evaluating the performance of the model by using model evaluation indexes including average absolute error, average absolute percentage error, root mean square error and decision coefficient.
According to the river total nitrogen concentration prediction method based on the hybrid neural network, the water quality data comprise 9 water quality parameters: temperature (T, DEG C.), PH, dissolved oxygen (COD, mg/L), biochemical oxygen demand (BOD, mg/L), turbidity (NTU), potassium permanganate (COD-Mn, mg/L), ammonia nitrogen (NH3-N, mg/L), total phosphorus (TP, mg/L), total nitrogen (TN, mg/L).
Preferably, step 1 specifically comprises the following steps:
and performing data cleaning on the original water quality data set, specifically comprising detecting abnormal data in the original water quality data set based on an isolation forest and completing vacancy values in the original water quality data based on a Langery method.
Preferably, step 2 specifically comprises the following steps:
step 2.1, randomly dividing a water quality data set of a river area to be tested into a training set and a testing set;
and 2.2, inputting the training set serving as the current water quality parameter into the 1-DRCNN network. 1-DRCNN can excavate and extract potential nonlinear relation characteristics among the current water quality parameters to form effective low-dimensional characteristics;
step 2.3, inputting the 1-DRCNN output as a BiGRU model, learning and integrating the dependency of time water quality parameters before and after, and further optimizing the water quality data expressed by characteristics;
and 2.4, at the top layer of the model, taking the output of the BiGRU as the input of a full connection layer, wherein the full connection layer is used for generating a predicted value of the water quality parameter.
Preferably, step 3 specifically comprises the following steps:
and 3.1, in the model training process, using an Adma optimizer to adjust the weight and the deviation of the model, and continuously calculating the deviation between the total nitrogen concentration of the river water output by the full-connection layer and the real total nitrogen concentration in the training set in the training process. And when the deviation is smaller than a self-determined threshold value, finishing the model training to obtain an optimal model.
And 3.2, acquiring a total nitrogen concentration result of the river to be predicted on the test set by using the trained optimal model.
Compared with the prior art, the invention has the following advantages:
the invention not only realizes the function of predicting the river concentration, but also cleans the water quality data of the river to be detected before prediction, and enhances the integrity of the water quality data of the river. The invention utilizes the 1-DRCNN to solve the problem that the result can reach saturation and rapidly decrease along with the deepening of the network in the model training process of the traditional long and deep CNN network, thereby generating gradient explosion and degradation, and fully utilizes the good characteristic extraction and expression capability of the 1-DRCNN network to learn the complex and nonlinear local characteristics of the river water quality data and reduce the latitude of the river water quality data. In addition, the BiGRU in the prediction generation module enables the model to capture the context time dependency of the river water quality data in the training process, and the model prediction precision of the river total nitrogen concentration is effectively improved. In general, the method can predict the total nitrogen concentration of the river efficiently and accurately.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic structural diagram of a 1-DRCNN-BiGRU model in a river total nitrogen concentration prediction method based on a hybrid neural network according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a BiGRU model in a river total nitrogen concentration prediction method based on a hybrid neural network according to an embodiment of the present invention.
Fig. 3 is a complete algorithm flowchart of a method for predicting total nitrogen concentration of a river based on a hybrid neural network according to an embodiment of the present invention;
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The method for predicting the total nitrogen concentration in river water according to the embodiment of the invention is described below with reference to fig. 1, and specifically includes the following steps:
step 1, collecting 28390once every four hours through a data collecting module of the Internet of things equipment, wherein a plurality of water quality parameters collected at each moment form a vector, the vector is used as a sample, and an original water quality data set of a water quality area to be predicted is cleaned.
Due to the factors of failure of the acquisition equipment or artificial error recording and the like, abnormal values and vacancy values inevitably occur in the water quality data, and the prediction accuracy of the model is low due to the data which are not in accordance with the standard. Specifically, the embodiment improves the integrity of the river water quality data to be predicted by performing data cleaning on the original water quality data set of the river to be predicted; and the data cleaning comprises detecting abnormal data in the original water quality data set based on forest isolation and completing vacancy values in the original water quality data based on a Langery method.
The embodiment can detect abnormal values of the river water quality data to be predicted collected by the equipment by using the isolated forest. The abnormal value detection of the water quality data to be predicted by using the soliton is mainly divided into two steps:
firstly, constructing an isolated forest. And (4) recursively dividing the water quality data set to be predicted without considering the distance or the density of two samples of the river water quality data set to be predicted, and constructing an isolated tree until all sample points are isolated.
Secondly, calculating an abnormality score, wherein the formula is as follows:
wherein n represents the size of the water quality sample data x to be predicted, and H (n-1) represents a harmonic function which can be estimated by ln (n-1) + 0.5772156649. And C (n) represents the average path length of a binary tree constructed by the water quality sample data to be predicted of the n samples, and is mainly used for normalization. E (h (x)) represents the mean of the path lengths of the sample data x to be predicted in the plurality of itrees. If the node score is closer to 1, the more likely the sample node is abnormal; if the score of the sample node is closer to 0, the node is normal.
On the basis of the above embodiment, after abnormal value detection is performed on the water quality data to be predicted, the water quality data to be predicted is set as a null value. It is then padded using a langerand-based method. And finding a polynomial function which just passes through a two-dimensional plane formed by the non-vacant m water quality data sample points to be predicted according to the non-vacant m water quality data sample points to be predicted, wherein the observed value of the plane is just obtained at each observation point. And realizing the filled vacancy value according to the polynomial function. The polynomial function formula of the lagrange interpolation method is thus as follows:
Lm(x)=y0l0(x)+y1l1(x)+…+ymlm
wherein, ymRepresenting the true value, l, of the corresponding sample point in the river water quality dataset to be predictedi(x) Representing an interpolation function corresponding to a sample point in a river water quality data set to be predicted:
and 2, on the basis of the embodiment, dividing river water quality data of the area to be predicted into a training set and a testing set. As shown in the structural diagram of the overall model shown in FIG. 1, the river total nitrogen concentration prediction model is constructed and mainly comprises two modules, a feature learning module and a prediction generation module. The feature learning module uses 1-DRCNN, and the prediction generation module uses BiGRU and a full connection layer.
On the basis of the above embodiment, a plurality of water quality parameters collected at each moment constitute a vector as an input sample of the model. Each vector in the input sample consists of eight water quality parameters of temperature (T), PH, dissolved oxygen (COD,), Biochemical Oxygen Demand (BOD), turbidity (NTU), potassium permanganate (COD-Mn), ammonia nitrogen (NH3-N) and Total Phosphorus (TP) at each moment, and Total Nitrogen (TN) is used as an output characteristic prediction vector of the model and is used for comparing with the real total nitrogen concentration and evaluating the prediction accuracy of the model.
Step 2.1, randomly dividing a water quality data set of a river area to be tested into a training set and a testing set;
and 2.2, constructing a characteristic learning module 1-DRCNN network, and inputting the training set serving as the current water quality parameter into the 1-DRCNN network. The 1-DRCNN can be used for mining and extracting potential nonlinear relation features among the current water quality parameters to form effective low-dimensional features. The invention uses two one-dimensional convolution residual blocks (1-DConv _ block) as the main structure of a feature learning module, each residual block mainly comprises 3 convolution layers of 1x1, 3 batch normalization layers (BN layer) and three activation functions (Selu), wherein the sizes of the filter and the convolution kernel of each convolution layer are set to be 32.
On the basis of the above embodiment, before each 1 × 1 convolutional layer is input, a Batch Normalization layer (BN layer) needs to be used to transform and reconstruct the output of the upper layer, the BN calculates the first-order and second-order statistics of each Batch, the intermediate output of the one-dimensional convolutional neural network evolution layer is continuously adjusted, the higher layer network continuously adapts to the parameter update of the lower layer network, the output of each layer network tends to be stable, and the problem that the convergence rate of the network is reduced due to the disappearance of the gradient of the higher layer network is solved. Example a as above (a)1,…,ad) The reconstruction formula is as follows:
to pairAnd (3) carrying out reconstruction:
wherein the content of the first and second substances,represents the variance, β, of the sample(k)=E[a(k)]Indicating the expectation of the sample.
In addition, the convolution layer of 1 × 1 performs convolution operations using convolution kernels having the same weight and different regions in the training set of the river water quality data input after reconstruction in the above-described embodiment, learns information of all positions in the training set of the river water quality data in the above-described embodiment, and generates a low-dimensional feature vector. Output of each convolutional layerComprises the following steps:
f(x)=SELU=βmax(αezx-α,x)
in the formula (I), the compound is shown in the specification,is the input to the i-th neuron in the l-th layer network,is the output of the ith neuron in the l-1 th layer network,is a filter between the kth neuron of the l-1 th layer network and the ith neuron of the l-1 th layer network,defined as the bias of the kth neuron in the l-th layer of the network. In order to improve the feature expression capability of the convolutional layer, the nonlinear feature mapping of the convolutional layer is realized by adopting an activation function f (). In the formula, α and β are fixed values, and β is 1.05070098 and α is 1.67326324, respectively.
Step 2.3, the 1-DRCNN output is used as a BiGRU model input, the BiGRU network autonomously captures the dependence relationship of short time sequence data, long time data and context attributes, a hidden state combining forward and backward is obtained, the dependence of time water quality parameters before and after learning and integration is learned, and the water quality data expressed by characteristics is further optimized, the structure of the water quality data is shown in FIG. 3, and the characteristic modeling process based on the BiGRU is described as follows:
where the GRU (.) function represents the nonlinear transformation of the above embodiment using the GRU network to encode the input vector into the corresponding GRU hidden state. w is at、vtRespectively representing the forward hidden layer state of the bidirectional BiGUR at the time tAnd reverse hidden layer statesAnd (4) weighting. btBiasing to indicate the state of the hidden layer at time t。
And 2.4, at the top layer of the model, taking the output of the BiGRU as the input of a full connection layer, wherein the full connection layer is used for generating a total nitrogen concentration predicted value in the embodiment.
And 3, training the model constructed in the step 3 by using an Adam optimization algorithm, obtaining an optimal water quality parameter prediction model after training is finished, and then predicting the total nitrogen concentration in a test set.
And 3.1, in the model training process, using an optimizer Adma to adjust the weight and the deviation of the model, and calculating the error between the total nitrogen concentration of the river water quality output by the full-connection layer and the real concentration. And when the error is smaller than a preset threshold value, finishing the model training to obtain an optimal model.
And 3.2, predicting the total nitrogen concentration on the test set by using the trained optimal model to obtain a prediction result of the total nitrogen concentration.
Step 4, after obtaining the result of the river total nitrogen concentration to be predicted, in order to evaluate the accuracy and effectiveness of the model for predicting the river total nitrogen concentration to be predicted, the method adopts the average absolute error (MAE), the average absolute percentage error (MAPE), the Root Mean Square Error (RMSE) and the decision coefficient (R)2) And evaluating the prediction effect of the model. The formula of the merit function is as follows:
wherein N isSize of sample set, yiIs a predicted value of the total nitrogen concentration of the model, YiIs the observed value (true value) of the ith total nitrogen concentration in the test set,is the average of observed values of total nitrogen concentration in the test set. If the result of MAE, MAPE, RMSE is closer to 0, R2The closer to 1, the higher the prediction accuracy of the constructed model.
As previously mentioned, the advantages of the present invention are:
1. the problem that a single water quality prediction algorithm cannot mine local characteristics of water quality and learn time dependence of time sequence data is solved, and the prediction accuracy and efficiency of the river total nitrogen concentration are improved.
2. The model realizes organic integration of the feature extraction module and the bidirectional circulation prediction module for the first time, is applied to the field of water quality prediction, and effectively improves the stability and generalization capability of the water quality parameter prediction model.
The above embodiments are only exemplary embodiments of the present invention, and are not intended to limit the present invention, and the scope of the present invention is defined by the claims. Various modifications and equivalents may be made by those skilled in the art within the spirit and scope of the present invention, and such modifications and equivalents should also be considered as falling within the scope of the present invention.