Reservoir water level prediction and early warning method based on PSO-LSTM-Attention model
Through the PSO-LSTM-Attention model, the problem of reservoir water level control delay in the existing technology is solved, more accurate reservoir water level prediction is achieved, and reliable data is provided to support flood season prevention.
Patent Information
- Application Number
- CN202210026182.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2042-01-11
AI Technical Summary
Existing reservoir water level control methods rely on manual experience or simple formulas, which cannot adjust the flood discharge volume in a timely manner, resulting in delays and inability to effectively predict future water level changes.
The reservoir water level prediction and early warning method based on the PSO-LSTM-Attention model is used to obtain and preprocess historical monitoring data, search for optimal parameters, build and train the LSTM-Attention model, and perform real-time prediction of the reservoir water level.
It achieves more accurate reservoir water level prediction, reduces the average absolute error between the predicted value and the real value, and provides reliable data to support flood season prevention.
Smart Images

Figure CN114386693B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of reservoir water level prediction and early warning, and in particular to a reservoir water level prediction and early warning method based on a PSO-LSTM-Attention model. Background Art
[0002] Water level is an indispensable part of the inspection of water conservancy projects, and refers to the depth of water intercepted by water conservancy projects such as reservoirs. The ability to control water level directly determines the flood control benefits of the reservoir and the development and utilization of water resources. Controlling the reservoir water level within a reasonable range is one of the most important things for every reservoir manager. The existing reservoir water level control method is mainly based on the existing water level, combined with real-time rainfall and water level changes, relying on manual experience or certain formulas to determine the degree of opening and closing of the gate to control the flood discharge. This method has a certain delay, has no insight into future water level changes, and often cannot complete the adjustment of flood discharge in time. Summary of the invention
[0003] In view of this, the purpose of the present invention is to provide a reservoir water level prediction and early warning method based on the PSO-LSTM-Attention model, which can reliably predict the reservoir water level, provide reliable data for adjusting the flood discharge, and achieve prevention during the flood season.
[0004] To achieve the above object, the present invention adopts the following technical solution:
[0005] A reservoir water level prediction and early warning method based on PSO-LSTM-Attention model includes the following steps:
[0006] Step S1: Obtain historical monitoring data of the reservoir and preprocess it;
[0007] Step S2: obtaining model input features based on the preprocessed historical reservoir monitoring data;
[0008] Step S3: Search for the optimal parameters of the LSTM-Attention model based on PSO;
[0009] Step S4: Based on the optimal parameters obtained in step S3, build and train the LSTM-Attention model;
[0010] Step S5: Based on the trained LSTM-Attention model, real-time prediction of reservoir water level is performed.
[0011] Furthermore, the step S1 is specifically as follows:
[0012] Step S11: Obtaining historical monitoring data of the reservoir including the water level, flood discharge, rainfall, and monitoring time of the reservoir;
[0013] Step S12: Select water level, flood discharge, rainfall, and monitoring time, and align them according to time so that each piece of data is the water level, flood discharge, and rainfall at the same time;
[0014] Step S13: Select a recent period of data with fewer missing values, and use the previous or next value to fill the missing values.
[0015] Furthermore, the step S2 is specifically as follows:
[0016] Step S21: construct the function expression, and construct the time-effect component according to f(α) and the reservoir water level observation time to obtain the time-effect component
[0017] f(α)=a1α+a2 lnα
[0018] Where a1 and a2 are coefficients, t is the cumulative number of days from the monitoring day to the start monitoring day;
[0019] Step S22: The function expression of water level feature transformation is as follows:
[0020]
[0021] The reservoir water level data collection time is T t (t=0, 1, 2, ..., n), T0~T n Reservoir water level during the period, H i for Any non-empty subset of , W is the reservoir water level.
[0022] According to f(W), the reservoir water level characteristics are transformed to obtain W1, W2, and W3 respectively:
[0023]
[0024] Step S23: using maximum and minimum value normalization to process different features;
[0025] Step S24: traverse and extract data, set the length of the sliding window to w, extract w consecutive unit time data as input features, and use the w+1 to w+f unit time data as labels to segment the data. The window sliding step is 1; where f is the prediction length, indicating the water level data of f unit time is predicted backward, which is specifically expressed as:
[0026] Input Features
[0027] Dependent variable Y = (y w+1 ,y w+2 ,y w+3,…,y w+f )
[0028] The input feature X is the time factor, water level, outflow, and rainfall of w consecutive units of time, and the dependent variable is the data of f units of time after the input feature.
[0029] Furthermore, the step S3 is specifically as follows:
[0030] Step S31: Set the optimization parameters of the particle swarm to x[0]: sliding window step size, x[1]: number of neurons in the first layer, x[2]: dropout rate, x[3]: number of neurons in the second layer, x[4]: dropout rate, x[5] learning rate, x[6]: batchsize;
[0031] Step S32: setting the particle position value range;
[0032] Step S33: using MSE as the objective function of the particle swarm and searching for the parameter combination that minimizes MSE;
[0033] Step S34: setting particle swarm algorithm parameters;
[0034] Step S35: Initialize particle position and velocity;
[0035] Step S36: Input each particle into the model, obtain the test set prediction value of each particle in the LSTM-Attention model, and calculate the MSE corresponding to each particle;
[0036] Step S37: Update the individual optimal and population optimal positions of the particle. If the current particle is smaller than the MSE of the particle's historical optimal position, update the individual optimal MSE; if the current population optimal individual is smaller than the MSE of the population optimal position, update the population optimal MSE;
[0037] Step S38: Update the speed of each particle, and then use the updated speed to update the position of the particle;
[0038] Step S39: When the termination condition is not met, steps S36 to S39 are repeated. When the termination condition is met, the global optimal parameters are output.
[0039] Furthermore, the LSTM-Attention model includes two LSTM+Dropout layers, an attention layer, a Flatten layer, and a Dense layer.
[0040] Furthermore, the two LSTM+Dropout layers are specifically: an LSTM+Dropout layer is superimposed on the first LSTM+Dropout layer, and the second LSTM layer can obtain the information learned by the first LSTM layer.
[0041] Furthermore, the LSTM-Attention model is called as follows:
[0042] Let the current time be t i , (i=1,2,3,…), the time increment is Δt(t=1,2,3,…), the sliding window is w, and t i+Δt-w ~t i+Δt The rainfall at time t i+Δt-1-w ~t i+Δt-1 The flood discharge volume and reservoir water level at the moment are input into the trained LSTM-Attention model for t i+Δt Reservoir water level forecast at any time
[0043] The default prediction step size is to predict the water level for one day in the future, that is, the time increment Δt (t = 1). If the default step size is used, the input parameter t i-w ~t i Reservoir water level and flood discharge at time t i+1-w ~t i+1 Rainfall at the time
[0044] If the step size needs to be adjusted, that is, the time increment Δt>1, the input model parameter is t i+1+w ~t i+1 The rainfall at time t i-w ~t i The flood discharge and reservoir water level at time t are predicted. i+1 The reservoir water level at time t i ~t i+Δt The flood discharge at time t i Indicates that, at this time, let Δt increase, input the data at each moment into the model, and predict the reservoir water level at the next moment until t is predicted. i+Δt-1 Reservoir water level at all times.
[0045] Compared with the prior art, the present invention has the following beneficial effects:
[0046] 1. The reservoir water level prediction and control method based on the PSO-LSTM-Attention model of the present invention uses historical water level, rainfall, flood discharge, and time factor to predict future water level. The average absolute error between the predicted value and the true value is smaller, and the model's prediction is more accurate;
[0047] 2. The present invention combines the historical water level, rainfall, and flood discharge data that are most relevant to the water level to obtain a more accurate prediction result than the existing simple formula derivation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 is a flow chart of the method of the present invention;
[0049] Figure 2 is a PSO flow chart in one embodiment of the present invention;
[0050] Figure 3 is a schematic diagram of an LSTM-Attention model in one embodiment of the present invention;
[0051] Figure 4 This is a diagram of the LSTM-Attention model architecture in one embodiment of the present invention. DETAILED DESCRIPTION
[0052] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0053] Please refer to Figure 1 The present invention provides a reservoir water level prediction and early warning method based on the PSO-LSTM-Attention model, comprising the following steps:
[0054] Step S1: Obtain historical reservoir monitoring data and pre-process it, specifically:
[0055] Step S11: Obtaining historical monitoring data of the reservoir including the water level, flood discharge, rainfall, and monitoring time of the reservoir;
[0056] Step S12: Select water level, flood discharge, rainfall, and monitoring time, and align them according to time so that each piece of data is the water level, flood discharge, and rainfall at the same time;
[0057] Step S13: Select a recent period of data with fewer missing values, and use the previous or next value to fill the missing values.
[0058] Step S2: Based on the pre-processed historical reservoir monitoring data, the model input features are obtained, specifically:
[0059] Step S21: construct the function expression, and construct the time-effect component according to f(α) and the reservoir water level observation time to obtain the time-effect component
[0060] f(α)=a1α+a2 lnα
[0061] Where a1 and a2 are coefficients, t is the cumulative number of days from the monitoring day to the start monitoring day;
[0062] Step S22: Function table T of water level characteristic transformation i (i=0,1,2,…,n) The expression is as follows:
[0063]
[0064] The reservoir water level data collection time is T t (t=0, 1, 2, ..., n), T0~T n Reservoir water level during the period, H i for Any non-empty subset of , W is the reservoir water level.
[0065] According to f(W), the reservoir water level characteristics are transformed to obtain W1, W2, and W3 respectively:
[0066]
[0067] Step S23: Use maximum and minimum value normalization to process different features, and its function expression is as follows;
[0068]
[0069] Where x is the value of a single data, min is the minimum value of the column where the data is located, and max is the maximum value of the column where the data is located;
[0070] Step S24: traverse and extract data, set the length of the sliding window to w, extract w consecutive unit time data as input features, and use the w+1 to w+f unit time data as labels to segment the data. The window sliding step is 1; where f is the prediction length, indicating the water level data of f unit time is predicted backward, which is specifically expressed as:
[0071] Input Features
[0072] Dependent variable Y = (y w+1 ,y w+2 ,y w+3 ,…,y w+f )
[0073] The input feature X is the time factor, water level, outflow, and rainfall of w consecutive units of time, and the dependent variable is the data of f units of time after the input feature.
[0074] Step S3: Search for the optimal parameters of the LSTM-Attention model based on PSO, specifically:
[0075] Step S31: Set the optimization parameters of the particle swarm to x[0]: sliding window step size, x[1]: number of neurons in the first layer, x[2]: dropout rate, x[3]: number of neurons in the second layer, x[4]: dropout rate, x[5] learning rate, x[6]: batchsize;
[0076] Step S32: setting the particle position value range;
[0077] Traceback length: The minimum is 1 and the maximum does not exceed the total amount of data.
[0078] Number of neurons: minimum is 1, and generally no more than 1024.
[0079] Dropout: The minimum value is 0 and the maximum value is 1. It is usually not 1.
[0080] Learning rate: The minimum is greater than 0, the maximum is 1, and it is generally not 1.
[0081] Batchsize: The minimum is 1 and the maximum is generally not more than 512.
[0082] The value range of particle velocity is set to 20% of the value range of particle position, so that particles can traverse more positions and increase the individual optimization ability of particles.
[0083] Step S33: using MSE as the objective function of the particle swarm and searching for the parameter combination that minimizes MSE;
[0084] Step S34: setting particle swarm algorithm parameters;
[0085] The particle velocity update function is:
[0086] v i =ω×v i +c1×rand()×(pbest i -x i )+c2×rand()×(gbest i -x i )
[0087] Where ω is the inertia weight, c1 is the individual learning factor, c2 is the group learning factor, rand() is a random number between [0, 1), pbest i is the historical optimal position of the particle, gbest i is the historical optimal position of the particle population, x i is the current position of the particle.
[0088] The particle position update function is:
[0089] x i =xi +v i
[0090] ω is a non-negative number. When it is larger, the global optimization ability is strong and the local optimization ability is strong. When it is smaller, the global optimization ability is weak and the local optimization ability is strong. Let its initial value be larger to improve the global optimization ability. As the number of iterations increases, ω gradually decreases, improving the local optimization ability.
[0091] Therefore:
[0092] Let the current inertia weight be ω i , the maximum inertia weight is ω max , the minimum inertia weight is ω min , the current number of iterations is iter, and the maximum number of iterations is iter max , then the current inertia weight can be expressed as:
[0093]
[0094] The learning factors c1 and c2 are generally set to 2 to ensure that the expected values of c1×rand() and c2×rand() are 1.
[0095] Step S35: Randomly initialize the parameters within the range of the optimization parameters. When it can be determined that the optimal solution of the particle is within a certain range, the particle is initialized within this range to shorten the convergence time of the optimization;
[0096] Step S36: Input each particle into the model, obtain the test set prediction value of each particle in the LSTM-Attention model, and calculate the MSE corresponding to each particle;
[0097] Step S37: Update the individual optimal and population optimal positions of the particle. If the current particle is smaller than the MSE of the particle's historical optimal position, update the individual optimal MSE; if the current population optimal individual is smaller than the MSE of the population optimal position, update the population optimal MSE;
[0098] Step S38: Update the speed of each particle according to the formula, and then use the updated speed to update the position of the particle.
[0099] v i =ω×v i +c1×rand()×(pbest i -x i )+c2×rand()×(gbest i -x i )
[0100] x i =x i +v i
[0101] Step S39: When the termination condition is not met, steps S36 to S39 are repeated. When the termination condition is met, the global optimal parameters are output.
[0102] Step S4: Based on the optimal parameters obtained in step S3, build and train the LSTM-Attention model, including two LSTM+Dropout layers, one attention layer, one Flatten layer, and one Dense layer.
[0103] (1) Two LSTM+Dropout layers
[0104] The LSTM layer receives data from inputs for the training of each neuron. During the training process of each neuron, information is recorded and forwarded to the next neuron.
[0105] LSTM is very easy to overfit on the training data, which affects their prediction performance. Therefore, a Dropout layer is added to each LSTM layer to avoid overfitting and improve model performance by probabilistically inactivating the input and recursive connections of LSTM neurons during the forward pass and weight update process.
[0106] By stacking another LSTM+Doupout layer on the basis of the first LSTM+Doupout layer, the second LSTM layer can obtain the information learned by the first LSTM layer and learn new information on this basis, which can effectively improve the model's ability to process complex data. The second Doupout layer can also effectively avoid overfitting.
[0107] (2) Attention layer
[0108] The combination of the Attention mechanism and LSTM is implemented by a Dense layer with a softmax activation function. The specific operation is: use elementwise (bit-by-bit) multiplication to multiply the output of the Dense layer by the input after swapping the index axis order of the layers, and then restore the index axis order of the layers. This completes the allocation of the Attention weight. Because the input is multidimensional data, each dimension is set to have a separate attention weight. The specific architecture diagram is shown in the figure below:
[0109] After restoring the output features to the index axis order of layers, the shape is (None, step, features).
[0110] (3) Flatten layer
[0111] Use the Flatten layer to "flatten" the input, that is, to convert the multi-dimensional input into one dimension.
[0112] (4)Dense layer
[0113] Use the Dense (fully connected) layer to output the data "flattened" by the Flatten layer into a specified shape.
[0114] Step S5: Based on the trained LSTM-Attention model, real-time prediction of reservoir water level is performed.
[0115] Let the current time be t i , (i=1,2,3,…), the time increment is Δt(t=1,2,3,…), the sliding window is w, and t i+Δt-w ~t i+Δt The rainfall at time t i+Δt-1-w ~t i+Δt-1 The flood discharge volume and reservoir water level at the moment are input into the trained LSTM-Attention model for t i+Δt Reservoir water level forecast at any time
[0116] The default prediction step size is to predict the water level for one day in the future, that is, the time increment Δt (t = 1). If the default step size is used, the input parameter t i-w ~t i Reservoir water level and flood discharge at time t i+1-w ~t i+1 Rainfall at the time
[0117] If the step size needs to be adjusted, that is, the time increment Δt>1, the input model parameter is t i+1+w ~t i+1 The rainfall at time t i-w ~t i The flood discharge and reservoir water level at time t are predicted. i+1 The reservoir water level at time t i ~t i+Δt The flood discharge at time t i Indicates that, at this time, let Δt increase, input the data at each moment into the model, and predict the reservoir water level at the next moment until t is predicted. i+Δt-1 Reservoir water level at all times.
[0118] Embodiment 1:
[0119] In this embodiment, Kafka is used to read the reservoir water level data, reservoir flood discharge data, and meteorological data collected by the sensor into the model; the producer produces and pushes the messages read from the stream data to the Broker by calling the Kafka-related Python API.
[0120] Consumers use the corresponding partition allocation strategy and the pull operation to pull the stream data from the broker, and pass it into the water level scheduling model to load the multivariate linear regression water level scheduling model stored in the cloud or trained locally, so as to prepare for the subsequent use of the model for reservoir water level prediction.
[0121] When the model is loaded, use Kafka to input meteorological data, current reservoir water level, and flood discharge into the model for reservoir water level prediction. You can also manually input the current reservoir water level, flood discharge, and meteorological data into the model for reservoir water level prediction.
[0122] The water level prediction model predicts the value after taking into account human factors such as water storage in the dry season and water release in the rainy season. Therefore, if the predicted water level is within the normal range, the gate can be released normally; if the water level still reaches the warning value, it means that the gate needs to be operated early.
[0123] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. A reservoir water level prediction and early warning method based on PSO-LSTM-Attention model, characterized in that: The following steps are involved: Step S1: Obtain historical monitoring data of the reservoir and preprocess it; Step S2: obtaining model input features based on the preprocessed historical reservoir monitoring data; Step S3: Search for the optimal parameters of the LSTM-Attention model based on PSO; Step S4: Based on the optimal parameters obtained in step S3, build and train the LSTM-Attention model; Step S5: Based on the trained LSTM-Attention model, real-time prediction of reservoir water level is performed; The step S2 is specifically as follows: Step S21: construct the function expression, and construct the time-effect component according to f(α) and the reservoir water level observation time to obtain the time-effect component f(α)=a1α+a2lnα Where a1 and a2 are coefficients, t is the cumulative number of days from the monitoring day to the start monitoring day; Step S22: The function expression of water level feature transformation is as follows: The reservoir water level data collection time is T t (t=0, 1, 2, ..., n), T0~T n Reservoir water level during the period, H i for Any non-empty subset of , W is the reservoir water level; According to f(W), the reservoir water level characteristics are transformed to obtain W1, W2, and W3 respectively: Step S23: using maximum and minimum value normalization to process different features; Step S24: traverse and extract data, set the length of the sliding window to w, extract w consecutive unit time data as input features, and use the w+1 to w+f unit time data as labels to segment the data. The window sliding step is 1; where f is the prediction length, indicating the water level data of f unit time is predicted backward, which is specifically expressed as: Input Features Dependent variable Y = (y w+1 , y w+2 , y w+3 , …, y w+f ) The input feature X is the time factor, water level, outflow, and rainfall of w consecutive units of time, and the dependent variable is the data of f units of time after the input feature; The LSTM-Attention model includes two LSTM+Dropout layers, one attention layer, one Flatten layer, and one Dense layer; The step S3 is specifically as follows: Step S31: Set the optimization parameters of the particle swarm to x[0]: sliding window step size, x[1]: number of neurons in the first layer, x[2]: dropout rate, x[3]: number of neurons in the second layer, x[4]: dropout rate, x[5] learning rate, x[6]: batchsize; Step S32: setting the particle position value range; Step S33: using MSE as the objective function of the particle swarm and searching for the parameter combination that minimizes MSE; Step S34: setting particle swarm algorithm parameters; Step S35: Initialize particle position and velocity; Step S36: Input each particle into the model, obtain the test set prediction value of each particle in the LSTM-Attention model, and calculate the MSE corresponding to each particle; Step S37: Update the individual optimal and population optimal positions of the particle. If the current particle is smaller than the MSE of the particle's historical optimal position, update the individual optimal MSE; if the current population optimal individual is smaller than the MSE of the population optimal position, update the population optimal MSE; Step S38: Update the speed of each particle, and then use the updated speed to update the position of the particle; Step S39: When the termination condition is not met, steps S36 to S39 are repeated, and when the termination condition is met, the global optimal parameters are output; The model call is as follows: Let the current time be t i , (i=1,2,3,…), the time increment is Δt(t=1,2,3,…), the sliding window is w, and t i+Δt-w ~t i+Δt The rainfall at time t i+Δt-1-w ~t i+Δt-1 The flood discharge volume and reservoir water level at the moment are input into the trained LSTM-Attention model for t i+Δt Reservoir water level forecast at any time The default prediction step size is to predict the water level for one day in the future, that is, the time increment Δt (t = 1). If the default step size is used, the input parameter t i-w ~t i Reservoir water level and flood discharge at time t i+1-w ~t i+1 Rainfall at the time If the step size needs to be adjusted, that is, the time increment Δt>1, the input model parameter is t i+1+w ~t i+1 The rainfall at time t i-w ~t i The flood discharge and reservoir water level at time t are predicted. i+1 The reservoir water level at time t i ~t i+Δt The flood discharge at time t i Indicates that, at this time, let Δt increase, input the data at each moment into the model, and predict the reservoir water level at the next moment until t is predicted. i+Δt-1 Reservoir water level at all times.
2. The reservoir water level prediction and early warning method based on the PSO-LSTM-Attention model according to claim 1 is characterized in that: The step S1 is specifically as follows: Step S11: Obtaining historical monitoring data of the reservoir including the water level, flood discharge, rainfall, and monitoring time of the reservoir; Step S12: Select water level, flood discharge, rainfall, and monitoring time, and align them according to time so that each piece of data is the water level, flood discharge, and rainfall at the same time; Step S13: Select a recent period of data with fewer missing values, and use the previous or next value to fill the missing values.
3. The reservoir water level prediction and early warning method based on the PSO-LSTM-Attention model according to claim 1 is characterized in that: The two LSTM+Dropout layers are specifically: a LSTM+Dropout layer is superimposed on the first LSTM+Dropout layer, and the second LSTM layer can obtain the information learned by the first LSTM layer.
Citation Information
Patent Citations
A flood forecasting method based on depth learning model and BP neural network correction
CN109272146A
Sewage quality prediction method based on optimized LSTM neural network
CN112884056A
Reservoir water level prediction method based on neural network
CN113887774A
