A flood prediction method incorporating covariate offset detection
The Seq2Seq model, which utilizes covariate offset detection and attention mechanisms, addresses the issue of inconsistent distributions between training and testing samples, thereby improving the accuracy of flood forecasting, enhancing the model's generalization ability, and reducing errors.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA YANGTZE POWER
- Filing Date
- 2023-12-08
- Publication Date
- 2026-08-04
AI Technical Summary
Traditional recurrent neural network models struggle to capture the temporal characteristics of rainfall and runoff in long-term flood forecasting, and suffer from inconsistent distributions between training and testing samples, leading to information loss and inaccurate forecasts.
The dataset is partitioned using covariate offset detection combined with symbolic aggregation approximation algorithm and Matthews correlation coefficient. The Seq2Seq model with attention mechanism is used for training. Historical information is filtered through the attention mechanism to enhance the model's ability to fuse contextual information and express key information.
This achieves consistency between the distribution of the training and test sets, improves the model's generalization ability and prediction accuracy, and reduces the root mean square error and mean absolute error.
Smart Images

Figure CN117874591B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of hydrological forecasting, and in particular relates to a flood prediction method that combines covariate migration detection. Background Technology
[0002] Floods, characterized by their suddenness, variability, and scale, cause immense damage to life and property, social production and economic operations, and ecological protection. Therefore, accurate rainfall-runoff forecasting within target watersheds is crucial for flood control and water resource utilization. Traditional physical models suffer from drawbacks such as excessively high requirements for the accuracy of input data and high modeling costs. Given the rapid development of computer technology, utilizing artificial intelligence for hydrological forecasting is an inevitable trend.
[0003] Classical time series forecasting models, such as traditional recurrent neural networks, often fail to capture the temporal characteristics and potential correlations of rainfall and runoff when dealing with long-term forecasting tasks. Furthermore, when partitioning the dataset, changes in external environment or internal factors often lead to covariate shifts in the time series data, resulting in inconsistent distributions between training and test samples.
[0004] Therefore, how to avoid information loss and ensure the consistency of the distribution of training and test sets, and how to establish an accurate rainfall-runoff forecasting mechanism within the watershed are the technical problems that need to be solved. Summary of the Invention
[0005] To address the aforementioned technical problems, this invention provides a flood prediction method that combines covariate offset detection. This prediction method can effectively solve the problems of information loss and data imbalance.
[0006] To achieve the above-mentioned technical features, the objective of this invention is as follows: a flood prediction method combining covariate offset detection, comprising the following steps: S1. Collect rainfall and runoff data from various rainfall observation stations within the forecast interval to construct a dataset; the input part is the rainfall and runoff volume for several consecutive hours before the time period to be predicted, and the label part is the runoff sequence for the time period to be predicted; S2. Compress the dataset obtained in S1 using a symbolic aggregation approximation algorithm, initially divide it into training and test sets according to a certain ratio, insert classification labels, and then perform equal random sampling on the training and test sets to obtain a new dataset. S3. Use the dataset obtained in S2 for training and prediction of the binary classification model. Perform correlation analysis between the prediction results of the classification model and the true classification. Dynamically adjust the ratio of the training set and the test set of the original dataset based on the correlation analysis results to obtain the best splitting result. S4. The training set obtained in S3 is fed into a Seq2Seq model composed of a single-layer LSTM with an attention mechanism for training to obtain a runoff forecast model. S5. Use the rainfall and historical runoff data from each observation station in any test set in S3 as input to the runoff forecasting model obtained in S4 to get the corresponding runoff prediction values.
[0007] The dataset construction process described in step S1 is as follows: S11. Collect hydrological data within the forecast period, including rainfall data and runoff data from each rainfall observation station, to form the original dataset D; S12. Perform linear normalization on each feature of the original dataset D obtained in S11, divide it into multiple forecast sessions, and shuffle them to form a dataset. The linear normalization process is shown in the following equation:
[0008]
[0009] in: Indicates the first i The first feature j A number, and They represent the first i The maximum and minimum values among the features, For the first i The first feature j The linear normalization result of the values.
[0010] S2 includes the following steps: S21. The dataset obtained in S1 is compressed using the symbolic aggregation approximation algorithm, with each rainfall-runoff field as the basic unit. This process transforms the rainfall-runoff fields into a one-dimensional vector represented by binary numbers, thus forming the dataset. ;
[0011] S22. Take the dataset obtained in S21 The dataset is divided into a training set and a test set according to a certain ratio. The number of tests in the training set is in the range of (m, n), with a lower bound of m, a value interval of 1, and an upper bound of n.
[0012] S23. Insert classification labels into the training set and the test set respectively, and denote the data type of the training set as 0 and the data type of the test set as 1; S24. Randomly collect the same number of samples from both the training and test sets, shuffle them, and form a new dataset.
[0013] S3 includes the following steps: S31. Divide the dataset obtained in S2 into a training set and a test set in an 8:2 ratio; S32. Construct a binary classification model and feed the training set obtained in S31 into the model for training the classification task; S33. Input the test set from S31 into the trained binary classification model in S32, and use the Matthews correlation coefficient to perform a correlation analysis between the model's classification results and the actual classification results of the test set. The Matthews correlation coefficient is calculated as follows:
[0014] in: TP and TN This represents the number of true positive and true negative samples. FP and FN This represents the number of false positives and false negatives. To calculate the obtained Matthews correlation coefficient;
[0015] S34. Divide the range of values for the training set size in S22 into multiple sub-ranges, and calculate the corresponding values for each value point step by step. MCC value; S35. Taking the training set sample size into account, the minimum Matthews correlation coefficient of each sub-interval calculated in S34 is weighted and calculated separately to obtain the result. P The value is calculated as shown in the following formula:
[0016] in: C The number of fields in each subset. N The total number of matches. Y The number of subsets included in the training set. and b These are the weights for the Matthews correlation coefficient and the sample size, respectively. P The smaller the value, the more reasonable the division of the dataset.
[0017] S4 includes the following steps: S41. The process by which each LSTM unit in the encoder generates its output is shown in the following equation:
[0018] in: and As respectively The hidden state variables input to the time encoder are related to the cell state. For training set Sample input at time 10:00 The mapping relationship defined for the LSTM units that constitute the encoder. and They are respectively The hidden state variables and cell states output by the time encoder;
[0019] S42. After introducing the attention mechanism, the decoder will be... Hidden state output at any time As a query, the hidden variables of each encoder state The process of generating context vectors using keys and values, and introducing an attention mechanism in the decoder, can be described by the following formula:
[0020]
[0021]
[0022]
[0023]
[0024] in: As The correlation score between the hidden state output by the time-decoder and the hidden state at each time step of the encoder, tanh and soft `max` is the activation function. These are the weight matrices for the query, key, and value, respectively. The linear mapping relationship defined for the fully connected layer. The context vector is obtained by weighting and summing the encoder's state variables at each time step according to their correlation scores. The context vector is then concatenated with the hidden state and passed into the fully connected layer to obtain the final result. For the decoder in The output results generated at each moment;
[0025] S43. With true value Compared with the predicted value The root mean square error is used as the loss function. The model is iterated continuously using the training set. When the iteration termination condition is reached, the training is stopped and the output is obtained to obtain the final rainfall-runoff prediction model, which predicts the runoff value within the forecast interval.
[0026] The LSTM unit in S4 used to construct the Seq2Seq model has the following structure:
[0027]
[0028]
[0029]
[0030]
[0031]
[0032] in: and The inputs are the cell state and hidden state of the LSTM unit. For characteristic sequences t The value at time, The parameter matrix that each gating unit can learn. These are the bias parameters for each gating unit. and For activation function, These are the outputs of the forget gate, input gate, and output gate, respectively. This represents the cell state after the input gate has been updated. and The outputs are the hidden states and cell states of the LSTM unit.
[0033] In S11, the fixed interval Δt for sampling rainfall and runoff at each station is 1 hour.
[0034] S21 includes the following steps: S211. Divide historical rainfall and runoff data into equal subsequences of length w, and characterize them using the variance of each subsequence; S212. Select the character set size, and convert the variance representing each subsequence into the corresponding character according to the breakpoint table. That is, convert the original sequence into a string, and perform one-hot encoding on it to obtain a one-hot encoding matrix to represent the original rainfall dataset, where each row in the matrix represents a precipitation event.
[0035] In S211, the value of w is equal to the length of the input history sequence.
[0036] The present invention has the following beneficial effects: 1. This invention is based on rainfall-runoff data within the forecast interval. Through an attention mechanism, historical information is filtered during the decoding process and assigned appropriate weights, enabling the model to have better contextual information fusion capabilities and the ability to express key information.
[0037] 2. This invention achieves covariate shift detection in a dataset by combining the SAX algorithm with a binary classification model, and uses the Matthews correlation coefficient to quantify the consistency of the distribution. The dataset is partitioned by comprehensively considering the size of the training set samples. This simultaneously ensures both the consistency of the dataset distribution and the diversity of the training set data, enhancing the model's generalization ability. Attached Figure Description
[0038] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0039] Figure 1 This is a flowchart of the Seq2Seq model rainfall-runoff prediction method based on covariate shift verification and the introduction of an attention mechanism, as described in this invention.
[0040] Figure 2 This is a structural diagram of the Seq2Seq prediction model with an attention mechanism used in this invention.
[0041] Figure 3 This is a graph showing the prediction results of the present invention. Detailed Implementation
[0042] The embodiments of the present invention will be further described below with reference to the accompanying drawings.
[0043] Example 1: like Figure 1 As shown, this invention provides a flood prediction method combining covariate shift detection. The method first normalizes and divides the collected rainfall-runoff data into data sessions to construct a dataset. The SAX algorithm combined with a binary classification model is used to detect covariate shifts in the dataset, and the Matthews correlation coefficient is used to quantify the detection results. The dataset partitioning is dynamically adjusted based on the quantization results and the sample size of the training set. The partitioned training set is then fed into a Seq2Seq network for learning, and an attention mechanism is introduced to filter historical information. Finally, the input features from the test set are fed into the trained prediction model to predict runoff volume.
[0044] The specific steps for using examples are as follows: The Three Gorges Reservoir area is located between the Sichuan Basin and the middle reaches of the Yangtze River, with a total drainage area of approximately 56,700 square kilometers. It exhibits a complex climate pattern, with precipitation concentrated in the summer. The data used in this embodiment comes from hourly hydrological data within the Three Gorges Reservoir area from 2014 to 2021, including runoff observations within the basin and rainfall observations from eight rainfall observation intervals: Wansan, Cunwan, Wanfeng, Wanba, Cunqing, Basan, Fengba, and Qingwan.
[0045] A flood prediction method combining covariate shift detection and Seq2Seq-attention, comprising the following steps: S1. Collect rainfall and runoff data from rainfall observation stations in each hydrological interval within the forecast interval to construct a dataset.
[0046] The construction of the dataset in S1 includes the following steps: S11. Collect hourly rainfall and runoff observations for eight rainfall observation intervals: Wan San, Cun Wan, Wan Feng, Wan Ba, Cun Qing, Ba San, Feng Ba, and Qing Wan, to form the original dataset D.
[0047] S12. Perform linear normalization on each feature of the original dataset D obtained in S11, and divide it into two equal parts: one part uses hydrological information from 15 hours before the forecast as historical input, and the other part uses runoff forecast events from 6 hours after the start of the forecast as the forecast interval, thus forming a dataset. The linear normalization process is shown in the following equation:
[0048]
[0049] in: Indicates the first i The first feature j A number, and They represent the first i The maximum and minimum values among the features, For the first i The first feature j The linear normalization result of the values.
[0050] S2. The dataset obtained in S1 is compressed using the Symbolic Aggregation Approximation (SAX) algorithm, initially divided into training and test sets according to a certain ratio, and classification labels are inserted. Equal random sampling is performed on the training and test sets respectively to obtain a new dataset. The construction of the dataset in S2 involves the following steps: S21. The dataset obtained in S1 is compressed using the symbolic aggregation approximation algorithm, with each rainfall-runoff field as the basic unit. This process transforms the rainfall-runoff fields into a one-dimensional vector represented by binary numbers, thus forming the dataset. ;
[0051] S22. Take the dataset obtained in S21 The dataset is divided into a training set and a test set according to a certain ratio. The number of tests in the training set is in the range of (3400, 4400), with an initial value of 3400 and a value interval of 1.
[0052] S23. Insert classification labels into the training and test sets respectively, denoting the data type as 0 in the training set and 1 in the test set. S24. Randomly collect the same number of samples from both the training and test sets, shuffle them, and form a new dataset.
[0053] The SAX algorithm used in this invention is an existing algorithm that can be used directly using relevant functions or programs. In this embodiment, the algorithm includes the following steps: S211. Divide historical rainfall and runoff data into subsequences of length 15, and characterize them using the variance of each subsequence.
[0054] S212. Select the character set size, and convert the variance representing each subsequence into the corresponding character according to the breakpoint table. That is, convert the original sequence into a string, and perform one-hot encoding on it to obtain a one-hot encoding matrix to represent the original rainfall dataset, where each row in the matrix represents a precipitation event.
[0055] S3. Use the dataset obtained in S2 for training and prediction of the binary classification model. Perform a correlation analysis between the prediction results of the classification model and the true classification. Dynamically adjust the sample size of the original dataset training set based on the correlation analysis results to obtain the best splitting result. Furthermore, step S3 includes the following sub-steps: S31. Divide the data obtained in S2 into a training set and a test set in an 8:2 ratio.
[0056] S32. Construct a binary classification model and feed the training set obtained in S31 into the model for training the classification task; S33. Input the test set from S31 into the trained binary classification model in S32, and use the Matthews correlation coefficient to perform correlation analysis between the model's classification results and the actual classification results of the test set. The calculation formula for the Matthews correlation coefficient (MCC) is as follows:
[0057] in: TP and TN This represents the number of true positive and true negative samples. FP and FN This represents the number of false positives and false negatives. To calculate the obtained Matthews correlation coefficient;
[0058] S34. Based on the range of values for the training set size in S22, calculate the corresponding value for each value point step by step. MCC The value is divided into 10 equal sub-intervals, each sub-interval... MCC The statistics are shown in Table 1.
[0059] Table 1. Sub-intervals of Training Session Count MCC Statistic
[0060] S35. Taking the training set sample size into account, the minimum Matthews correlation coefficients of each sub-interval calculated in S34 are weighted separately to obtain the P-value. The calculation process is shown in the following formula:
[0061] in: C The number of fields in each subset. N The total number of matches. Y The number of subsets included in the training set. and b These are the weights for the Matthews correlation coefficient and the sample size, respectively. P The smaller the value, the more reasonable the division of the dataset.
[0062] In this embodiment, a and b The values are 0.9 and 0.1, and the corresponding values for each sub-interval are... P The values are shown in Table 2.
[0063] Table 2. Sub-intervals of Training Session Count P value
[0064] S4. The training set obtained in S3 is fed into a Seq2Seq model consisting of a single-layer LSTM with an attention mechanism for training to obtain the runoff forecast model.
[0065] Furthermore, the training of the S4 model specifically includes the following sub-steps: S41. The input features obtained from the training set in S3 are fed into the encoder. The process of each LSTM unit in the encoder generating an output is shown in the following equation:
[0066] in: and As respectively The hidden state variables input to the time encoder are related to the cell state. For training set Sample input at time 10:00 The mapping relationship defined for the LSTM units that constitute the encoder. and They are respectively The hidden state variables and cell states output by the time encoder;
[0067] S42. After introducing the attention mechanism, the decoder will be... Hidden state output at any time As a query, the hidden variables of each encoder state The process of generating context vectors using keys and values, and introducing an attention mechanism in the decoder, can be described by the following formula:
[0068]
[0069]
[0070]
[0071]
[0072] in: As The correlation score between the hidden state output by the time-decoder and the hidden state at each time step of the encoder, tanh and soft `max` is the activation function. These are the weight matrices for the query, key, and value, respectively. The linear mapping relationship defined for the fully connected layer. The context vector is obtained by weighting and summing the encoder's state variables at each time step according to their correlation scores. The context vector is then concatenated with the hidden state and passed into the fully connected layer to obtain the final result. For the decoder in The output results generated at each moment;
[0073] S43. With true value Compared with the predicted value The root mean square error is used as the loss function. The model is iterated continuously using the training set. When the iteration termination condition is reached, the training is stopped and the output is obtained to obtain the final rainfall-runoff prediction model, which predicts the runoff value within the forecast interval.
[0074] The LSTM unit in S41 used to construct the Seq2Seq model has the following structure:
[0075]
[0076]
[0077]
[0078]
[0079]
[0080] in: and The inputs are the cell state and hidden state of the LSTM unit. For characteristic sequences t The value at time, The parameter matrix that each gating unit can learn. These are the bias parameters for each gating unit. and For activation function, These are the outputs of the forget gate, input gate, and output gate, respectively. This represents the cell state after the input gate has been updated. and The outputs are the hidden states and cell states of the LSTM unit.
[0081] S5. Use the rainfall and historical runoff from any test set in S3 as input to the runoff forecasting model obtained in S4 to get the corresponding runoff prediction value.
[0082] This embodiment uses root mean square error (RMSE), mean absolute error (MAE), and... The coefficient of determination (RMSE) is used as an evaluation metric for traffic flow prediction models. Lower RMSE and MAE values indicate more accurate predictions. A higher value indicates a more accurate result. The three indicators are defined as follows:
[0083]
[0084]
[0085]
[0086] in: For the true value, For predicted values, is the mean of the true values, and n is the output length.
[0087] Experimental results are as follows Figure 3 As shown in Table 3, from Figure 3 As can be seen, the model demonstrates good forecasting and tracking capabilities for runoff data exceeding 1000 m³ / s, while its tracking capability decreases for data below 1000 m³ / s.
[0088] As clearly observed in Table 3, compared to the baseline model, the Seq2Seq model incorporating the attention mechanism shows a 5.52% decrease in RMSE and a 0.88% decrease in MAE, respectively. Simultaneously, it can be observed that for the same model, the partitioning method determined by identically distributed detection reduces the model's error metrics compared to the traditional 8:2 or 7:3 partitioning. Taking the Seq2Seq model incorporating the attention mechanism as an example, the partitioning method obtained by identically distributed detection reduces RMSE and MAE by 5.29% and 4.02% respectively compared to the 7:3 partitioning; and by 1.45% and 1.98% respectively compared to the 8:2 partitioning. This demonstrates the effectiveness of the method proposed in this invention.
[0089] Table 3. Performance comparison of different models for rainfall-runoff forecasting tasks
Claims
1. A flood prediction method combining covariate migration detection, characterized in that, Includes the following steps: S1. Collect rainfall and runoff data from various rainfall observation stations within the forecast interval to construct a dataset; the input part is the rainfall and runoff volume for several consecutive hours before the time period to be predicted, and the label part is the runoff sequence for the time period to be predicted; S2. Compress the dataset obtained in S1 using a symbolic aggregation approximation algorithm, initially divide it into training and test sets according to a certain ratio, insert classification labels, and then perform equal random sampling on the training and test sets to obtain a new dataset. S3. Use the dataset obtained in S2 for training and prediction of the binary classification model. Perform correlation analysis between the prediction results of the classification model and the true classification. Dynamically adjust the ratio of the training set and the test set of the original dataset based on the correlation analysis results to obtain the best splitting result. S4. The training set obtained in S3 is fed into a Seq2Seq model composed of a single-layer LSTM with an attention mechanism for training to obtain a runoff forecast model. S5. Use the rainfall and historical runoff of each observation station in any test set in S3 as input to the runoff forecasting model obtained in S4 to obtain the corresponding runoff prediction value. S3 includes the following steps: S31. Divide the dataset obtained in S2 into a training set and a test set in an 8:2 ratio; S32. Construct a binary classification model and feed the training set obtained in S31 into the model for training the classification task; S33. Input the test set from S31 into the trained binary classification model in S32, and use the Matthews correlation coefficient to perform a correlation analysis between the model's classification results and the actual classification results of the test set. The Matthews correlation coefficient is calculated as follows: in: TP and TN This represents the number of true positive and true negative samples. FP and FN This represents the number of false positives and false negatives. To calculate the obtained Matthews correlation coefficient; S34. Divide the range of values for the training set size in S22 into multiple sub-ranges, and calculate the corresponding values for each value point step by step. MCC value; S35. Taking the training set sample size into account, the minimum Matthews correlation coefficient of each sub-interval calculated in S34 is weighted and calculated separately to obtain the result. P The value is calculated as shown in the following formula: in: C The number of fields in each subset. N The total number of matches. Y The number of subsets included in the training set. and b These are the weights for the Matthews correlation coefficient and the sample size, respectively. P The smaller the value, the more reasonable the division of the dataset; S4 includes the following steps: S41. The process by which each LSTM unit in the encoder generates its output is shown in the following equation: in: and As respectively The hidden state variables input to the time encoder are related to the cell state. For training set Sample input at time 10:00 The mapping relationship defined for the LSTM units that constitute the encoder. and They are respectively The hidden state variables and cell states output by the time encoder; S42. After introducing the attention mechanism, the decoder will be... Hidden state output at any time As a query, the hidden variables of each encoder state The process of generating context vectors using keys and values, and introducing an attention mechanism in the decoder, can be described by the following formula: in: As The correlation score between the hidden state output by the time-decoder and the hidden state at each time step of the encoder, tanh and soft `max` is the activation function. These are the weight matrices for the query, key, and value, respectively. The linear mapping relationship defined for the fully connected layer. The context vector is obtained by weighting and summing the encoder's state variables at each time step according to their correlation scores. The context vector is then concatenated with the hidden state and passed into the fully connected layer to obtain the final result. For the decoder in The output results generated at each moment; S43. With true value Compared with the predicted value The root mean square error is used as the loss function. The model is iterated continuously using the training set. When the iteration termination condition is reached, the training is stopped and the output is obtained to obtain the final rainfall-runoff prediction model, which predicts the runoff value within the forecast interval.
2. The flood prediction method combining covariate offset detection according to claim 1, characterized in that, The dataset construction process described in step S1 is as follows: S11. Collect hydrological data within the forecast period, including rainfall data and runoff data from each rainfall observation station, to form the original dataset D; S12. Perform linear normalization on each feature of the original dataset D obtained in S11, divide it into multiple forecast sessions, and shuffle them to form a dataset. The linear normalization process is shown in the following equation: in: Indicates the first i The first feature j A number, and They represent the first i The maximum and minimum values among the features, For the first i The first feature j The linear normalization result of the values.
3. The flood prediction method combining covariate offset detection according to claim 1, characterized in that, S2 includes the following steps: S21. The dataset obtained in S1 is compressed using the symbolic aggregation approximation algorithm, with each rainfall-runoff field as the basic unit. This process transforms the rainfall-runoff fields into a one-dimensional vector represented by binary numbers, thus forming the dataset. ; S22. Take the dataset obtained in S21 The dataset is divided into a training set and a test set according to a certain ratio. The number of tests in the training set is in the range of (m, n), with a lower bound of m, a value interval of 1, and an upper bound of n. S23. Insert classification labels into the training set and the test set respectively, and denote the data type of the training set as 0 and the data type of the test set as 1; S24. Randomly collect the same number of samples from both the training and test sets, shuffle them, and form a new dataset.
4. The flood prediction method combining covariate offset detection according to claim 1, characterized in that, The LSTM unit in S4 used to construct the Seq2Seq model has the following structure: in: and The inputs are the cell state and hidden state of the LSTM unit. For characteristic sequences t The value at time, The parameter matrix that each gating unit can learn. These are the bias parameters for each gating unit. and For activation function, These are the outputs of the forget gate, input gate, and output gate, respectively. This represents the cell state after the input gate has been updated. and The outputs are the hidden states and cell states of the LSTM unit.
5. The flood prediction method combining covariate offset detection according to claim 2, characterized in that, In S11, the fixed interval Δt for sampling rainfall and runoff at each station is 1 hour.
6. The flood prediction method combining covariate offset detection according to claim 3, characterized in that, S21 includes the following steps: S211. Divide historical rainfall and runoff data into equal subsequences of length w, and characterize them using the variance of each subsequence; S212. Select the character set size, and convert the variance representing each subsequence into the corresponding character according to the breakpoint table. That is, convert the original sequence into a string, and perform one-hot encoding on it to obtain a one-hot encoding matrix to represent the original rainfall dataset, where each row in the matrix represents a precipitation event.
7. The flood prediction method combining covariate offset detection according to claim 6, characterized in that, In S211, the value of w is equal to the length of the input history sequence.