Method and device for predicting water quality of urban river network

The sparrow search algorithm optimizes the long-term and short-term memory network model, and combines historical data to predict the water quality of urban river networks, solving the problem of poor accuracy of traditional models for water quality prediction and achieving more accurate water quality prediction.

CN119230003APending Publication Date: 2024-12-31TIANJIN WATER ENG CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411197194.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The traditional hydrodynamic water quality model has poor accuracy on the prediction of urban river network water quality, and cannot effectively capture the impact of time and space factors, resulting in poor prediction results.

Method used

The sparrow search algorithm is used to optimize the hyperparameters of the long and short-term memory network model, and combine historical water quality, flow and rainfall data to predict water quality through pre-trained network models, and continuously adjust to improve prediction accuracy.

Benefits of technology

The accuracy of urban river network water quality prediction is improved, the impact of spatial and temporal factors on the prediction is reduced, and more accurate water quality prediction results are achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119230003A_ABST
    Figure CN119230003A_ABST
Patent Text Reader

Abstract

The invention provides an urban river network water quality prediction method and device, and the method comprises the steps: obtaining the historical data of a target urban river network water supplementing port in a period of time, optimizing the hyper-parameters of a long and short-term memory network model through a sparrow search algorithm, and obtaining a pre-trained network model. And taking the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of a pre-training network model, and obtaining predicted water quality concentration data based on the pre-training network model. And training the pre-trained network model to obtain a river network water quality prediction model. And performing real-time prediction on the river network water quality of the target city based on the river network water quality prediction model to obtain a prediction result. According to the method, the long-term dependency relationship in the data can be better captured, and the prediction of the water quality of the urban river network is more accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of water quality prediction, and in particular to a method and device for predicting water quality of an urban river network. Background Art

[0002] With the continuous development of science and technology, people's environmental awareness is getting stronger and stronger. As one of the important freshwater resources, urban river networks are facing the dual interference of natural changes and human activities. Water quality control and prevention have become a major challenge facing sustainable development. Household consumption, industry, agriculture and ecosystem health are inseparable from good water quality. Related technologies often use traditional hydrodynamic water quality models to predict the water quality of urban river networks, but the accuracy of traditional hydrodynamic water quality models in predicting the water quality of urban river networks is poor. Therefore, how to improve the accuracy of predicting the water quality of urban river networks has become a technical problem that technicians in this field need to solve urgently. Summary of the invention

[0003] Based on the above problems, the present application provides a method and device for predicting the water quality of an urban river network to improve the accuracy of the prediction of the water quality of an urban river network. The present application provides a method for predicting the water quality of an urban river network, and the method comprises the following steps:

[0004] Obtain historical water quality data over a period of time at the water replenishment outlet of the target city's river network, historical flow data over a period of time at the water replenishment outlet of the target city's river network, historical rainfall data over a period of time in the target city, and historical water quality concentration data over a period of time at at least two water quality sections of the target city's river network;

[0005] The sparrow search algorithm is used to optimize the hyperparameters of the long short-term memory network model to obtain a pre-trained network model;

[0006] Using the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of the pre-trained network model, and obtaining predicted water quality concentration data based on the pre-trained network model;

[0007] Using the difference between the predicted water quality concentration data and the historical water quality concentration data to adjust the pre-trained network model, and continuously using the historical water quality concentration data, the historical flow data and the historical rainfall data to train the pre-trained network model until a training cutoff condition is reached, thereby obtaining a river network water quality prediction model;

[0008] Based on the river network water quality prediction model, the river network water quality of the target city is predicted in real time to obtain a prediction result.

[0009] In a possible implementation, the method for predicting water quality of an urban river network further includes:

[0010] Preprocessing the historical water quality concentration data, the historical flow data and the historical rainfall data respectively to obtain preprocessed historical water quality concentration data, preprocessed historical flow data and preprocessed historical rainfall data;

[0011] The preprocessed historical water quality concentration data is used as the historical water quality concentration data, the preprocessed historical flow data is used as the historical flow data, and the preprocessed historical rainfall data is used as the historical rainfall data to perform the step of using the historical water quality concentration data, the historical flow data and the historical rainfall data as the input of the pretrained network model.

[0012] In a possible implementation, the preprocessing of the historical water quality concentration data, the historical flow data, and the historical rainfall data respectively includes:

[0013] Generate a data set using the historical water quality concentration data, the historical flow data and the historical rainfall data, wherein a set of data in the data set includes one historical water quality concentration data, one historical flow data and one historical rainfall data;

[0014] Performing a normal distribution test on the data set to test whether the data in the data set conforms to a normal distribution;

[0015] If the data set includes data that does not conform to the normal distribution, the data that does not conform to the normal distribution is normalized.

[0016] In a possible implementation, the normalization process is performed using the following formula:

[0017]

[0018] Among them, the X norm is the normalization result, the X i is the data in the data set that does not conform to the normal distribution, the X min Indicates the minimum value of the data in the data set, the X max Indicates the maximum value of the data in the dataset.

[0019] In a possible implementation, the method for predicting water quality of an urban river network further includes:

[0020] Get the traditional long short-term memory network model;

[0021] An optimized long short-term memory network model is obtained by adding a gating unit to the traditional long short-term memory network model, wherein the gating unit includes a forget gate, an input gate, and an output gate, wherein the forget gate is used to control the influence of historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model, the input gate is used to control whether current data enters the neural network of the traditional long short-term memory network model, the input gate and the forget gate are used to update the neuron state of the traditional long short-term memory network model, and the output gate is used to control the output of the traditional long short-term memory network model;

[0022] The forget gate determines the influence of the historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model through the following formula:

[0023] f t =σ(w f [h t-1 ,x t ]+b f )

[0024] Among them, f t represents the output of the forget gate at time t, σ represents the sigmoid activation function, and w f represents the weight of the input loop of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b f is the first deviation term;

[0025] The input gate controls whether the current data enters the neural network of the traditional long short-term memory network model through the following formula:

[0026] i t =σ(w i [h t-1 ,x t ]+b i )

[0027] Among them, i t represents the output value of the input gate at time t, σ represents the sigmoid activation function, and h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b i is the second deviation term;

[0028] The input gate and the forget gate update the neuron state of the traditional long short-term memory network model through the following formula:

[0029] C t =f t C t-1 +i t C′ t

[0030] Among them, C t represents the neuron state at time t, C t-1 represents the neuron state at time t-1, C′ t represents the updated neuron state at the tth moment, f t represents the output of the forget gate at time t, i t represents the output value of the input gate at time t;

[0031] The neuron state C at time t t It is expressed by the following formula:

[0032] C t =Tanh(w C [h t-1 ,x t ]+b C )

[0033] Among them, C t represents the neuron state at the tth moment, Tanh represents the Tanh activation function, and w C represents the first input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b C is the third deviation term;

[0034] The output gate controls the output of the traditional long short-term memory network model through the following formula:

[0035] o t =σ(w o [h t-1 ,x t ]+b o )

[0036] Among them, t represents the output of the output gate at time t, σ represents the sigmoid activation function, and w o represents the second input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and bo is the fourth deviation term;

[0037] The optimized long short-term memory network model is used as the long short-term memory network model to execute the step of optimizing the hyperparameters of the long short-term memory network model using the sparrow search algorithm.

[0038] In a possible implementation, the method of optimizing the hyperparameters of the long short-term memory network model by using the sparrow search algorithm to obtain the pre-trained network model includes:

[0039] The sparrow search algorithm is used to optimize the learning rate, training times, number of first hidden layer nodes and number of second hidden layer nodes of the long short-term memory network model. The optimization range of the learning rate is [0.001, 0.1], the optimization range of the training times is [10, 100], the optimization range of the number of first hidden layer nodes is [1, 100], and the optimization range of the number of second hidden layer nodes is [1, 100]. The parameters of the sparrow search algorithm are set as a population size of 10, a producer ratio of 0.2 and an iteration number of 20.

[0040] In a possible implementation, adjusting the pre-trained network model using the difference between the predicted water quality concentration data and the historical water quality concentration data includes:

[0041] determining a loss function based on a difference between the predicted water quality concentration data and the historical water quality concentration data;

[0042] The loss function can be expressed by the following formula:

[0043]

[0044] Wherein, MSE represents the loss function, n represents the total amount of data input into the pre-trained network model, Represents the predicted water quality concentration data, y i Represents historical water quality concentration data;

[0045] The pre-trained network model is adjusted based on the loss function.

[0046] The present application also provides a device for predicting water quality of an urban river network, and the device for predicting water quality of an urban river network includes the following modules:

[0047] An acquisition module, used to acquire historical water quality data at a water replenishment outlet of a target city's river network, historical flow data at a water replenishment outlet of a target city's river network, historical rainfall data of the target city, and historical water quality concentration data at at least two water quality sections of the target city's river network;

[0048] An optimization module is used to optimize the hyperparameters of the long short-term memory network model using a sparrow search algorithm to obtain a pre-trained network model;

[0049] An input module, used to use the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of the pre-trained network model, and obtain predicted water quality concentration data based on the pre-trained network model;

[0050] A training module, used to adjust the pre-trained network model using the difference between the predicted water quality concentration data and the historical water quality concentration data, and continuously train the pre-trained network model using the historical water quality concentration data, the historical flow data and the historical rainfall data until a training cutoff condition is reached, thereby obtaining a river network water quality prediction model;

[0051] The prediction module is used to make a real-time prediction of the river network water quality of the target city based on the river network water quality prediction model to obtain a prediction result.

[0052] The present application also provides an electronic device, the electronic device comprising a processor and a memory:

[0053] The memory is used to store a computer program and transmit the computer program to the processor;

[0054] The processor is used to execute the steps of the above-mentioned method for predicting the water quality of the urban river network according to the instructions in the computer program.

[0055] The present application also provides a computer-readable storage medium, characterized in that the computer-readable storage medium is used to store a computer program, and when the computer program is executed by an electronic device, the steps of the above-mentioned method for predicting the water quality of an urban river network are implemented.

[0056] Compared with the prior art, this application has the following beneficial effects:

[0057] The method provided in the present application does not use the traditional hydrodynamic water quality model, but uses the sparrow search algorithm to optimize the hyperparameters of the long short-term memory network model to obtain a pre-trained network model. The river network water quality prediction model is obtained by training the pre-trained network model. During the training process, the historical water quality data at the water replenishment port of the river network in the target city, the historical flow data at the water replenishment port of the river network in the target city, the historical rainfall data of the target city, and the historical water quality concentration data at at least two water quality sections of the river network in the target city are first obtained. The historical water quality concentration data, the historical flow data and the historical rainfall data are used as inputs of the pre-trained network model, and the predicted water quality concentration data is obtained based on the pre-trained network model. The pre-trained network model is adjusted using the difference between the predicted water quality concentration data and the historical water quality concentration data, and the pre-trained network model is continuously trained using the historical water quality concentration data, the historical flow data and the historical rainfall data until the training cutoff condition is reached to obtain the river network water quality prediction model. The river network water quality of the target city is predicted in real time based on the river network water quality prediction model to obtain a prediction result. The method of the present application can better capture the long-term dependencies in the data. The method provided by the present application selects the historical water quality concentration data of at least two water quality sections of the target city river network when training the model. By capturing the historical water quality concentration data at different water quality sections, the impact of spatial factors on the prediction accuracy can be reduced. Since the selected historical data are all within a period of time, by capturing the long-term dependencies between the historical data selected within a period of time, the impact of time factors on the prediction accuracy can be reduced. The method provided by the present application can more accurately predict the water quality of the urban river network. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0059] Figure 1 A flow chart of a method for predicting water quality of an urban river network provided in an embodiment of the present application;

[0060] Figure 2 A schematic diagram of the structure of a device for predicting water quality of an urban river network provided in an embodiment of the present application;

[0061] Figure 3 A schematic diagram of an error convergence curve for hyperparameter optimization provided in an embodiment of the present application;

[0062] Figure 4A schematic diagram of optimization results of hyperparameters of a long short-term memory network model provided in an embodiment of the present application;

[0063] Figure 5 A river network water quality prediction model for COD provided in the embodiment of the present application Cr Schematic diagram of comparison between the predicted value and the actual value of the concentration prediction;

[0064] Figure 6 A schematic diagram showing a comparison between a predicted value and an actual value of NH3-N concentration predicted by a river network water quality prediction model provided in an embodiment of the present application;

[0065] Figure 7 A schematic diagram showing a comparison between a predicted value and an actual value of TP concentration predicted by a river network water quality prediction model provided in an embodiment of the present application. DETAILED DESCRIPTION

[0066] As described above, water quality control and prevention have become major challenges facing sustainable development. Household consumption, industry, agriculture and ecosystem health are all inseparable from good water quality. Related technologies often use traditional hydrodynamic water quality models to predict urban river network water quality, but traditional hydrodynamic water quality models have poor accuracy in predicting urban river network water quality.

[0067] After research, it was found that the water quality of urban river networks is affected by many factors, such as time factors and space factors. The TP value of urban river networks in summer is significantly higher than that of river networks in winter. Traditional hydrodynamic water quality models cannot avoid time and space factors, resulting in poor prediction results. Therefore, the present application provides a method and device for predicting the water quality of urban river networks to improve the accuracy of predicting the water quality of urban river networks.

[0068] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0069] It is understandable that the method provided in the present application can be applied to a processing device, which is a processing device that can predict the water quality of an urban river network, such as a terminal device or a server that can predict the water quality of an urban river network. The method provided in the present application can be executed independently by a terminal device or a server, or can be applied to a network scenario in which a terminal device and a server communicate, and is executed by the cooperation of a terminal device and a server. Among them, the terminal device can be a computer, a mobile phone and other devices. The server can be understood as an application server or a Web server. In actual deployment, the server can be an independent server or a cluster server.

[0070] Figure 1 A flow chart of a method for predicting water quality of an urban river network provided in this application, the method comprising the following steps:

[0071] S101: Obtain historical water quality data over a period of time at the water replenishment outlet of the target city's river network, historical flow data over a period of time at the water replenishment outlet of the target city's river network, historical rainfall data over a period of time at the target city, and historical water quality concentration data over a period of time at at least two water quality sections of the target city's river network.

[0072] The target city may be a city where urban river network water quality prediction is conducted, and the processing equipment obtains historical water quality data over a period of time at the water replenishment port of the target city river network, historical flow data over a period of time at the water replenishment port of the target city river network, historical rainfall data over a period of time at the target city, and historical water quality concentration data over a period of time at at least two water quality sections of the river network of the target city. The processing equipment may obtain data in a variety of ways, for example, it may obtain historical water quality data over a period of time at the water replenishment port of the target city river network in a database that records historical data. The period of time may be a set time period, or it may be an optimal time period determined through a large number of experiments. In order to train a model with better performance, the period of time may be one year.

[0073] In a possible implementation, the processing device may preprocess the data. The processing device may preprocess the historical water quality concentration data, the historical flow data, and the historical rainfall data respectively to obtain the preprocessed historical water quality concentration data, the preprocessed historical flow data, and the preprocessed historical rainfall data.

[0074] The process of preprocessing the above data may be that a processing device generates a data set using the historical water quality concentration data, the historical flow data and the historical rainfall data, wherein a set of data in the data set includes one historical water quality concentration data, one historical flow data and one historical rainfall data;

[0075] Performing a normal distribution test on the data set to test whether the data in the data set conforms to a normal distribution;

[0076] If the data set includes data that does not conform to the normal distribution, the data that does not conform to the normal distribution is normalized. The normalization process can be performed using the following formula:

[0077]

[0078] Among them, X norm is the normalized result, X i X is the data in the data set that does not conform to the normal distribution. min Indicates the minimum value of the data in the data set, X max Indicates the maximum value of the data in the dataset.

[0079] S102: Optimize the hyperparameters of the long short-term memory network model using the sparrow search algorithm to obtain a pre-trained network model.

[0080] The processing device optimizes the hyperparameters of the long short-term memory network model using a sparrow search algorithm to obtain a pre-trained network model.

[0081] In a possible implementation, the long short-term memory network model may be an optimized long short-term memory network model. The processing device may first obtain a traditional long short-term memory network model, and then optimize the traditional long short-term memory network model to obtain the optimized long short-term memory network model through optimization. The optimization process may be to add a gating unit to the traditional long short-term memory network model, the gating unit includes a forget gate, an input gate, and an output gate, the forget gate is used to control the influence of historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model, the input gate is used to control whether the current data enters the neural network of the traditional long short-term memory network model, the input gate and the forget gate are used to update the neuron state of the traditional long short-term memory network model, and the output gate is used to control the output of the traditional long short-term memory network model.

[0082] In a possible practice, the forget gate can determine the impact of historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model through the following formula:

[0083] f t =σ(w f [h t-1 ,x t ]+b f )

[0084] Among them, f t represents the output of the forget gate at time t, σ represents the sigmoid activation function, and w frepresents the weight of the input loop of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b f is the first deviation term. The hidden layer is the layer between the input layer and the output layer in the neural network, which is responsible for converting the input data into meaningful feature representation. The deviation term refers to the difference between the individual measured value and the measured average value. The first deviation term can be the output f of the forget gate at time t t The difference from the average of the forget gate output values ​​at all times.

[0085] In a possible practice, the input gate controls whether the current data enters the neural network of the traditional long short-term memory network model through the following formula:

[0086] i t =σ(w i [h t-1 ,x t ]+b i )

[0087] Among them, i t represents the output value of the input gate at time t, σ represents the sigmoid activation function, and h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b i is the second deviation term. The second deviation term can be the output value i of the input gate at time t t The difference from the average value of the input gate output at all times.

[0088] In one possible practice, the input gate and forget gate update the neuron state of the traditional long short-term memory network model through the following formula:

[0089] C t =f t C t-1 +i t C′ t

[0090] Among them, C t represents the neuron state at time t, C t-1 represents the neuron state at time t-1, C′ t represents the updated neuron state at the tth moment, f t represents the output of the forget gate at time t, i tRepresents the output value of the input gate at time t. Neurons are the basic processing units of artificial neural networks. Their function is to process each input signal to determine its strength (weighting); determine the combined effect (sum) of all input signals; and determine its output (transfer characteristics). In the field of artificial intelligence, especially in the field of deep learning, we try to simulate complex information processing methods through artificial neural networks. The computing power of neurons determines the speed and efficiency of artificial intelligence models in processing data.

[0091] In one possible implementation, the neuron state C at time t is t It is expressed by the following formula:

[0092] C t =Tanh(w C [h t-1 ,x t ]+b C )

[0093] Among them, C t represents the neuron state at the tth moment, Tanh represents the Tanh activation function, and w C represents the first input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b C The third deviation term may be the difference between the neuron state at the tth moment and the evaluation state of the neuron at all moments.

[0094] In one possible practice, the output gate controls the output of the LSTM network model through the following formula:

[0095] o t =σ(w o [h t-1 ,x t ]+b o )

[0096] Among them, t represents the output of the output gate at time t, σ represents the sigmoid activation function, and w o represents the second input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, b o The fourth deviation term may be the difference between the output of the output gate at the tth time and the average value of the output of the output gate at all times.

[0097] After obtaining the optimized long short-term memory network model, the processing device can use the sparrow search algorithm to optimize the hyperparameters of the optimized long short-term memory network model to obtain a pre-trained network model.

[0098] The sparrow search algorithm can search the hyperparameter space more effectively by combining the characteristics of local search and global search, and has better robustness and convergence, thereby improving the efficiency and performance of the model.

[0099] The sparrow search algorithm abstracts the foraging behavior of sparrows into a search process for the solution space. First, individuals in a sparrow group will conduct local searches in the solution space according to certain strategies to find potential solutions around them as quickly as possible. As the search proceeds, individuals will exchange information and jointly discover better solutions through communication and collaboration. Individuals monitor each other, while followers compete for the resources of high-yield explorers to improve their foraging efficiency. At the same time, the algorithm adds a danger warning mechanism for sparrows, introduces a certain amount of randomness to avoid falling into local optimal solutions and maintain the diversity of the search. During the foraging process, all individuals will always remain vigilant and act as sentinels to prevent the emergence of natural enemies. The identities of explorers and followers change dynamically.

[0100] The explorer's location is updated as follows:

[0101]

[0102] Among them, i represents the i-th sparrow, j represents the j-th dimension, and X i,j represents the position information of the i-th sparrow in the j-th dimension, t is the current iteration number, iter max is the maximum number of iterations; α∈[0,1], α is a random number; R 2 is the warning value, R 2 The value range is R 2 ∈[0,1], ST is a safe value, and the range of ST is ST∈[0.5,1]. Q is a random number that obeys a normal distribution; L is a 1×d matrix, in which each element is 1.

[0103] For followers, these sparrows will always monitor the explorer during the foraging process. Once they realize that the explorer has found better food, they will immediately leave their current position to compete for the food. If they win, they can immediately get the explorer's food. In addition, the lower the energy and the worse the foraging position, the more likely they are to fly to other places to forage.

[0104] Since the sparrow search algorithm is an iterative process, the position information of the i-th sparrow in the j-dimension at the t+1th time can be determined by the position information of the i-th sparrow in the j-dimension at the tth time. The formula is as follows:

[0105]

[0106] in, represents the position information of the i-th sparrow in the j-th dimension at the t+1th time, represents the optimal explorer position at the t+1th time, X worst represents the current global worst position, n is the population size, A is a 1×d matrix with each element having a random amplitude of 1 or -1, and A+ is defined as follows:

[0107] A + =A T (AA T ) -1

[0108] In the above formula, when i>n / 2, it means that the i-th follower with a lower fitness value has not found food and needs to fly to other places to find food. At this time, 10% to 20% of the individuals in the population will be aware of the danger, and the initial positions of these individuals are randomly generated in the population.

[0109] The processing device can use the sparrow search algorithm to optimize the learning rate, training times, number of first hidden layer nodes and second hidden layer nodes of the long short-term memory network model. The optimization range of the learning rate is [0.001, 0.1], the optimization range of the training times is [10, 100], the optimization range of the first hidden layer nodes is [1, 100], and the optimization range of the second hidden layer nodes is [1, 100]. The parameters of the sparrow search algorithm are set to a population size of 10, a producer ratio of 0.2 and an iteration number of 20.

[0110] S103: Using historical water quality concentration data, historical flow data and historical rainfall data as inputs of a pre-trained network model, and obtaining predicted water quality concentration data based on the pre-trained network model.

[0111] The processing device uses historical water quality concentration data, historical flow data and historical rainfall data as inputs of a pre-trained network model, and obtains predicted water quality concentration data based on the pre-trained network model.

[0112] S104: Using the difference between the predicted water quality concentration data and the historical water quality concentration data to adjust the pre-trained network model, and continuously using the historical water quality concentration data, the historical flow data, and the historical rainfall data to train the pre-trained network model until the training cutoff condition is reached, thereby obtaining a river network water quality prediction model.

[0113] The processing device adjusts the pre-trained network model using the difference between the predicted water quality concentration data and the historical water quality concentration data, and continues to train the pre-trained network model using the historical water quality concentration data, historical flow data, and historical rainfall data until the training cutoff condition is reached, thereby obtaining a river network water quality prediction model. The training cutoff condition may be a preset round of training, or the model reaches a preset accuracy, etc.

[0114] In a possible implementation, the processing device may determine a loss function based on the difference between the predicted water quality concentration data and the historical water quality concentration data. The loss function may be expressed by the following formula:

[0115]

[0116] Wherein, MSE represents the loss function, n represents the total amount of data input into the pre-trained network model, Represents the predicted water quality concentration data, y i Represents historical water quality concentration data. The processing device can adjust the pre-trained network model based on the above loss function.

[0117] S105: Based on the river network water quality prediction model, real-time prediction of the river network water quality of the target city is performed to obtain a prediction result.

[0118] The processing equipment makes a real-time prediction of the river network water quality of the target city based on the river network water quality prediction model to obtain the prediction results, which may include the CODCr concentration of the river network water quality section, the NH3-N concentration of the river network water quality section, and the TP concentration of the river network water quality section.

[0119] In a possible implementation, the processing device may evaluate the accuracy of the prediction result. For example, the processing device may evaluate the accuracy of the prediction result based on historical data. The processing device may select root mean square error (RMSE), mean absolute error (MAE), and coefficient of determination (R 2 ) Three indicators measure the prediction ability of the model. The root mean square error can be calculated by the following formula:

[0120]

[0121] Wherein, RMSE represents the root mean square error, n represents the total amount of data input into the pre-trained network model, Represents the predicted water quality concentration data, y i Represents historical water quality concentration data, and i represents the i-th prediction.

[0122] The mean absolute error can be calculated using the following formula:

[0123]

[0124] Wherein, MAE represents mean absolute error, n represents the total amount of data input into the pre-trained network model, Represents the predicted water quality concentration data, y i Represents historical water quality concentration data, and i represents the i-th prediction.

[0125] The coefficient of determination can be calculated using the following formula:

[0126]

[0127] Among them, R 2 represents the determination coefficient, n represents the total amount of data input into the pre-trained network model, represents the predicted water quality concentration data, represents the mean value of the pollutant concentration actually monitored, y i Represents historical water quality concentration data, and i represents the i-th prediction.

[0128] RMSE and MAE are used to quantify the overall difference between the actual value and the simulated value. The smaller the value, the higher the prediction accuracy. R2 reflects the degree of correlation between the measured sequence and the simulated sequence. The larger the R2 value, the higher the prediction quality. It is generally believed that the model with R2 closer to 1 has better positive correlation.

[0129] The method provided in the present application does not use the traditional hydrodynamic water quality model, but uses the sparrow search algorithm to optimize the hyperparameters of the long short-term memory network model to obtain a pre-trained network model. The river network water quality prediction model is obtained by training the pre-trained network model. During the training process, the historical water quality data at the water replenishment port of the river network in the target city, the historical flow data at the water replenishment port of the river network in the target city, the historical rainfall data of the target city, and the historical water quality concentration data at at least two water quality sections of the river network in the target city are first obtained. The historical water quality concentration data, the historical flow data and the historical rainfall data are used as inputs of the pre-trained network model, and the predicted water quality concentration data is obtained based on the pre-trained network model. The pre-trained network model is adjusted using the difference between the predicted water quality concentration data and the historical water quality concentration data, and the pre-trained network model is continuously trained using the historical water quality concentration data, the historical flow data and the historical rainfall data until the training cutoff condition is reached to obtain the river network water quality prediction model. The river network water quality of the target city is predicted in real time based on the river network water quality prediction model to obtain a prediction result. The method of the present application can better capture the long-term dependencies in the data. The method provided by the present application selects the historical water quality concentration data of at least two water quality sections of the target city river network when training the model. By capturing the historical water quality concentration data at different water quality sections, the impact of spatial factors on the prediction accuracy can be reduced. Since the selected historical data are all within a period of time, by capturing the long-term dependencies between the historical data selected within a period of time, the impact of time factors on the prediction accuracy can be reduced. The method provided by the present application can more accurately predict the water quality of the urban river network.

[0130] This application also provides a Figure 2 The schematic diagram of the structure of the prediction device of the urban river network water quality shown in FIG. 200 includes the following modules:

[0131] An acquisition module 201 is used to acquire historical water quality data at a water replenishment outlet of a target city river network, historical flow data at a water replenishment outlet of a target city river network, historical rainfall data of the target city, and historical water quality concentration data at at least two water quality sections of the target city river network;

[0132] An optimization module 202 is used to optimize the hyperparameters of the long short-term memory network model using a sparrow search algorithm to obtain a pre-trained network model;

[0133] An input module 203, used to use the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of the pre-trained network model, and obtain predicted water quality concentration data based on the pre-trained network model;

[0134] A training module 204 is used to adjust the pre-trained network model using the difference between the predicted water quality concentration data and the historical water quality concentration data, and continuously train the pre-trained network model using the historical water quality concentration data, the historical flow data and the historical rainfall data until a training cutoff condition is reached, thereby obtaining a river network water quality prediction model;

[0135] The prediction module 205 is used to perform real-time prediction of the river network water quality of the target city based on the river network water quality prediction model to obtain a prediction result.

[0136] The device provided in the present application does not use the traditional hydrodynamic water quality model, but uses the sparrow search algorithm to optimize the hyperparameters of the long short-term memory network model to obtain a pre-trained network model. The river network water quality prediction model is obtained by training the pre-trained network model. During the training process, the historical water quality data at the water replenishment port of the river network in the target city, the historical flow data at the water replenishment port of the river network in the target city, the historical rainfall data of the target city, and the historical water quality concentration data at at least two water quality sections of the river network in the target city are first obtained. The historical water quality concentration data, the historical flow data and the historical rainfall data are used as inputs of the pre-trained network model, and the predicted water quality concentration data is obtained based on the pre-trained network model. The pre-trained network model is adjusted using the difference between the predicted water quality concentration data and the historical water quality concentration data, and the pre-trained network model is continuously trained using the historical water quality concentration data, the historical flow data and the historical rainfall data until the training cutoff condition is reached to obtain the river network water quality prediction model. The river network water quality of the target city is predicted in real time based on the river network water quality prediction model to obtain a prediction result. The method of the present application can better capture the long-term dependencies in the data. The method provided by the present application selects the historical water quality concentration data of at least two water quality sections of the target city river network when training the model. By capturing the historical water quality concentration data at different water quality sections, the impact of spatial factors on the prediction accuracy can be reduced. Since the selected historical data are all within a period of time, by capturing the long-term dependencies between the historical data selected within a period of time, the impact of time factors on the prediction accuracy can be reduced. The method provided by the present application can more accurately predict the water quality of the urban river network.

[0137] In S102, the hyperparameters of the long short-term memory network model are optimized using the sparrow search algorithm to obtain a pre-trained network model. The error convergence curve of the hyperparameter optimization is as follows: Figure 3 As shown, Figure 3 A schematic diagram of an error convergence curve for hyperparameter optimization provided in an embodiment of the present application.

[0138] In the prediction method of urban river network water quality, the hyperparameters of the long short-term memory network model can include iteration optim, learning rate optim, firest hidden nodes optim and second hidden nodes optim. Figure 4 A schematic diagram of the optimization results of the hyperparameters of a long short-term memory network model provided in an embodiment of the present application, Figure 4 The optimization results of the above four hyperparameters are shown in Figure .

[0139] In the above river network water quality prediction model, COD Cr The concentration, NH3-N concentration and TP concentration are predicted in real time. Table 1 shows the COD concentration of the river network water quality section according to different models provided in the embodiment of the present application. Cr Prediction results of concentration:

[0140] Table 1

[0141]

[0142] In Table 1, the COD of four locations is calculated by three models. Cr The concentration is predicted, where MLP represents the multi-layer perceptron model, LSTM represents the long short-term memory network model, and SSA-LSTM represents the river network water quality prediction model provided by itself.

[0143] Figure 5 A river network water quality prediction model for COD provided in the embodiment of the present application Cr Schematic diagram of the comparison between the predicted value and the actual value of the concentration prediction. The light-colored line in the figure is the actual value, and the dark-colored line is the predicted value. Figure 5 It can be seen that the predicted values ​​of the river network water quality prediction model trained by the method provided by itself are highly consistent with the actual values. The method provided by itself can accurately predict the water quality of urban river networks.

[0144] Table 2 is the prediction result of NH3-N concentration in river network water quality section by a different model provided in the embodiment of the present application:

[0145] Table 2

[0146]

[0147] In Table 2, the NH3-N concentrations at four locations are predicted by three models, where MLP represents the multi-layer perceptron model, LSTM represents the long short-term memory network model, and SSA-LSTM represents the river network water quality prediction model provided by itself.

[0148] Figure 6A schematic diagram showing a comparison between the predicted value and the actual value of NH3-N concentration predicted by a river network water quality prediction model provided in an embodiment of the present application. The light-colored line in the figure is the actual value, and the dark-colored line is the predicted value. Figure 6 It can be seen that the predicted values ​​of the river network water quality prediction model trained by the method provided by itself are highly consistent with the actual values. The method provided by itself can accurately predict the water quality of urban river networks.

[0149] Table 3 is the prediction result of TP concentration of river network water quality section by a different model provided in the embodiment of the present application:

[0150] Table 3

[0151]

[0152] In Table 3, the NH3-N concentrations at four locations are predicted by three models, where MLP represents the multi-layer perceptron model, LSTM represents the long short-term memory network model, and SSA-LSTM represents the river network water quality prediction model provided by itself.

[0153] Figure 7 A schematic diagram showing a comparison between the predicted value and the actual value of TP concentration predicted by a river network water quality prediction model provided in an embodiment of the present application. The light-colored line in the figure is the actual value, and the dark-colored line is the predicted value. Figure 7 It can be seen that the predicted values ​​of the river network water quality prediction model trained by the method provided by itself are highly consistent with the actual values. The method provided by itself can accurately predict the water quality of urban river networks.

[0154] An embodiment of the present application also provides a device for predicting the water quality of an urban river network, wherein the device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device performs the steps of the method for predicting the water quality of an urban river network described in any embodiment of the present application.

[0155] In practical applications, the computer-readable storage medium may be any combination of one or more computer-readable media, which may be a computer-readable signal medium or a computer-readable storage medium.

[0156] The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.

[0157] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0158] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0159] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0160] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely schematic, in which the unit described as a separate component may or may not be physically separated, and the component prompted as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0161] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for predicting water quality of an urban river network, characterized in that: include: Obtain historical water quality data over a period of time at the water replenishment outlet of the target city's river network, historical flow data over a period of time at the water replenishment outlet of the target city's river network, historical rainfall data over a period of time in the target city, and historical water quality concentration data over a period of time at at least two water quality sections of the target city's river network; The sparrow search algorithm is used to optimize the hyperparameters of the long short-term memory network model to obtain a pre-trained network model; Using the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of the pre-trained network model, and obtaining predicted water quality concentration data based on the pre-trained network model; Using the difference between the predicted water quality concentration data and the historical water quality concentration data to adjust the pre-trained network model, and continuously using the historical water quality concentration data, the historical flow data and the historical rainfall data to train the pre-trained network model until a training cutoff condition is reached, thereby obtaining a river network water quality prediction model; Based on the river network water quality prediction model, the river network water quality of the target city is predicted in real time to obtain a prediction result.

2. The method according to claim 1, characterized in that The method further comprises: Preprocessing the historical water quality concentration data, the historical flow data and the historical rainfall data respectively to obtain preprocessed historical water quality concentration data, preprocessed historical flow data and preprocessed historical rainfall data; The preprocessed historical water quality concentration data is used as the historical water quality concentration data, the preprocessed historical flow data is used as the historical flow data, and the preprocessed historical rainfall data is used as the historical rainfall data to perform the step of using the historical water quality concentration data, the historical flow data and the historical rainfall data as the input of the pretrained network model.

3. The method according to claim 2, characterized in that The preprocessing of the historical water quality concentration data, the historical flow data and the historical rainfall data respectively comprises: Generate a data set using the historical water quality concentration data, the historical flow data and the historical rainfall data, wherein a set of data in the data set includes one historical water quality concentration data, one historical flow data and one historical rainfall data; Performing a normal distribution test on the data set to test whether the data in the data set conforms to a normal distribution; If the data set includes data that does not conform to the normal distribution, the data that does not conform to the normal distribution is normalized.

4. The method according to claim 3, characterized in that The normalization process is performed by the following formula: Among them, the X norm is the normalization result, the X i is the data in the data set that does not conform to the normal distribution, the X min Indicates the minimum value of the data in the data set, the X max Indicates the maximum value of the data in the dataset.

5. The method according to claim 1, characterized in that The method further comprises: Get the traditional long short-term memory network model; An optimized long short-term memory network model is obtained by adding a gating unit to the traditional long short-term memory network model, wherein the gating unit includes a forget gate, an input gate, and an output gate, wherein the forget gate is used to control the influence of historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model, the input gate is used to control whether current data enters the neural network of the traditional long short-term memory network model, the input gate and the forget gate are used to update the neuron state of the traditional long short-term memory network model, and the output gate is used to control the output of the traditional long short-term memory network model; The forget gate determines the influence of the historical information input into the traditional long short-term memory network model on the traditional long short-term memory network model through the following formula: f t =σ(w f [h t-1 ,x t ]+b f ) Among them, f t represents the output of the forget gate at time t, σ represents the sigmoid activation function, and w f represents the weight of the input loop of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b f is the first deviation term; The input gate controls whether the current data enters the neural network of the traditional long short-term memory network model through the following formula: i t =σ(w i [h t-1 ,x t ]+b i ) Among them, i t represents the output value of the input gate at time t, σ represents the sigmoid activation function, and h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b i is the second deviation term; The input gate and the forget gate update the neuron state of the traditional long short-term memory network model through the following formula: C t =f t C t-1 +i t C′ t Among them, C t represents the neuron state at time t, C t-1 represents the neuron state at time t-1, C′ t represents the updated neuron state at the tth moment, f t represents the output of the forget gate at time t, i t represents the output value of the input gate at time t; The neuron state C at time t t It is expressed by the following formula: C t =Tanh(w C [h t-1 ,x t ]+b C ) Among them, C t represents the neuron state at the tth moment, Tanh represents the Tanh activation function, and w C represents the first input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b C is the third deviation term; The output gate controls the output of the traditional long short-term memory network model through the following formula: the t =σ(w o [h t-1 ,x t ]+b o ) Among them, t represents the output of the output gate at time t, σ represents the sigmoid activation function, and w o represents the second input weight of the traditional long short-term memory network model, h t-1 represents the state of the hidden layer of the traditional long short-term memory network model at time t-1, x t represents the input value of the traditional long short-term memory network model at time t, and b o is the fourth deviation term; The optimized long short-term memory network model is used as the long short-term memory network model to execute the step of optimizing the hyperparameters of the long short-term memory network model using the sparrow search algorithm.

6. The method according to claim 5, characterized in that The hyperparameters of the long short-term memory network model are optimized by using the sparrow search algorithm to obtain a pre-trained network model including: The sparrow search algorithm is used to optimize the learning rate, training times, number of first hidden layer nodes and number of second hidden layer nodes of the long short-term memory network model. The optimization range of the learning rate is [0.001, 0.1], the optimization range of the training times is [10, 100], the optimization range of the number of first hidden layer nodes is [1, 100], and the optimization range of the number of second hidden layer nodes is [1, 100]. The parameters of the sparrow search algorithm are set as a population size of 10, a producer ratio of 0.2 and an iteration number of 20.

7. The method according to claim 1, characterized in that The adjusting the pre-trained network model by using the difference between the predicted water quality concentration data and the historical water quality concentration data comprises: determining a loss function based on a difference between the predicted water quality concentration data and the historical water quality concentration data; The loss function can be expressed by the following formula: Wherein, MSE represents the loss function, n represents the total amount of data input into the pre-trained network model, Represents the predicted water quality concentration data, y i Represents historical water quality concentration data; The pre-trained network model is adjusted based on the loss function.

8. A device for predicting water quality of urban river network, characterized in that: include: An acquisition module, used to acquire historical water quality data at a water replenishment outlet of a target city's river network, historical flow data at a water replenishment outlet of a target city's river network, historical rainfall data of the target city, and historical water quality concentration data at at least two water quality sections of the target city's river network; An optimization module is used to optimize the hyperparameters of the long short-term memory network model using a sparrow search algorithm to obtain a pre-trained network model; An input module, used to use the historical water quality concentration data, the historical flow data and the historical rainfall data as inputs of the pre-trained network model, and obtain predicted water quality concentration data based on the pre-trained network model; A training module, used to adjust the pre-trained network model using the difference between the predicted water quality concentration data and the historical water quality concentration data, and continuously train the pre-trained network model using the historical water quality concentration data, the historical flow data and the historical rainfall data until a training cutoff condition is reached, thereby obtaining a river network water quality prediction model; The prediction module is used to make a real-time prediction of the river network water quality of the target city based on the river network water quality prediction model to obtain a prediction result.

9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the method for predicting the water quality of an urban river network as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the method for predicting the water quality of an urban river network as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • An effluent BOD prediction method based on a simplified long-short-term memory neural network

    CN112949894A

  • Water quality prediction method and device, electronic equipment and storage medium

    CN113159456A

  • Water quality pollution monitoring method for seasonal drought river and computer program product

    CN118503890A