A Transformer-based flood forecasting method for variable time periods
Through the variable-time flood prediction method based on Transformer, the problem of flood peak simulation deviation in traditional flood prediction is solved, and the generation of flood sequences with higher resolution is achieved, which improves the accuracy and reliability of flood prediction, and provides technical support for disaster prevention and mitigation.
Patent Information
- Application Number
- CN202411038669.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2044-07-31
AI Technical Summary
Traditional flood prediction methods are based on equal-time data and cannot accurately reflect cross-time flood peaks caused by maximum rainfall, resulting in deviations in simulated flood peaks.
The variable-time flood prediction method based on Transformer is adopted, and the Transformer model is constructed by obtaining equal-time hydrological meteorological data, and the water volume redistribution is carried out in the variable-time sequential rainfall events, and a new uneven-time rainfall sequence is generated. The multi-head self-attention mechanism and feedforward neural network are used to generate higher-resolution flood sequences.
It improves the accuracy and reliability of flood simulation, can more accurately reflect the relationship between maximum rainfall and flood peaks, and provides more powerful disaster prevention and mitigation support.
Smart Images

Figure CN118964847B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of flood prediction, and in particular to a Transformer-based time-varying flood prediction method. Background Art
[0002] Floods, one of the most severe natural disasters worldwide, pose a significant threat to human society and the natural environment. With the impact of climate change and population growth, floods are becoming more frequent and destructive.
[0003] Traditional flood forecasting methods rely primarily on extensive historical hydrological data, analyzing rainfall, river flows, and topographic information to predict flood occurrence and impact. Existing flood simulation methods include physical-based hydrological models and data-driven models, which use hydrological and meteorological data over entire time periods as input and output data at hourly and daily scales.
[0004] However, they are all trained and verified based on data from equal time periods, and the maximum flood peak caused by the maximum rainfall often occurs in areas across time periods and is not well reflected by the data from equal time periods, resulting in deviations in the simulated flood peaks. Summary of the Invention
[0005] In response to the shortcomings of the existing technology, the present invention provides a variable-time-period flood prediction method based on Transformer. The present invention can automatically identify rainfall events across time periods and generate new unequal-time-period rainfall sequences based on the maximum short-duration rainfall. It can more accurately reflect the relationship between maximum rainfall and flood peak value, and improve the accuracy and reliability of flood simulation.
[0006] The technical solution of the present invention is: a Transformer-based time-varying flood prediction method, comprising the following steps:
[0007] S1), obtaining hydrological and meteorological data of equal time periods and preprocessing them;
[0008] S2), building a Transformer model and training the built Transformer model;
[0009] S3) Redistribute water volume in the basin during different periods of precipitation;
[0010] S4) For each time step, the data composed of the redistributed rainfall is input into the trained Transformer model. After position encoding, multi-head self-attention mechanism and feedforward neural network processing, the predicted runoff sequence is output through the fully connected layer.
[0011] Preferably, in step S1), the hydrological and meteorological data of equal time periods include basin precipitation, temperature, humidity and runoff.
[0012] Preferably, in step S1), the preprocessing is to perform missing value and noise processing on the hydrological and meteorological data of equal time periods to ensure alignment on the time scale and to perform standardization on the hydrological and meteorological data.
[0013] Preferably, in step S1), the pre-processed hydrological and meteorological data of equal time periods are divided into a training data set and a validation data set according to the 10-fold cross-validation principle; wherein the basin precipitation, temperature, and humidity are used as inputs, and the runoff is used as output.
[0014] Preferably, in step S2), the Transformer model includes a multi-layer encoder, a multi-layer decoder, a fully connected layer and a hidden layer; each layer of the encoder includes a corresponding multi-head self-attention mechanism and a feedforward neural network; each layer of the decoder includes a corresponding multi-head self-attention mechanism, an encoder-decoder attention mechanism and a feedforward neural network.
[0015] Preferably, in step S2), the input feature dimension of the Transformer model is n, and the time series information is embedded into the input feature:
[0016]
[0017]
[0018] Where, PE (pos,2i) Indicates the position encoding value at the posth position and the 2ith dimension, d model is the total dimension of the embedding vector.
[0019] Preferably, in step S2), the expression of the multi-head self-attention mechanism is:
[0020]
[0021] Where Q is the query matrix, K is the key matrix, and V is the value matrix; is the scaling factor.
[0022] Preferably, in step S2), the expression of the feedforward neural network is:
[0023] FFN(x)=max(0,xW1+b1)W2+b2
[0024] Among them, W1 and W2 are weight matrices, b1 and b2 are bias vectors; the input vector x is the embedded representation obtained from the self-attention mechanism or the output of the previous layer.
[0025] Preferably, in step S2), the Transformer model described in the training data set is used for training, wherein the training rounds are set to 100 epochs; and the learning rate is set to 0.0001.
[0026] Preferably, in step S3), the water redistribution during different time periods specifically includes the following steps:
[0027] S31), select the size of the sliding window;
[0028] S32) Use a sliding window to traverse the entire time series data; for each sliding window, calculate its total rainfall:
[0029]
[0030] Where R i is the cumulative rainfall in the i-th sliding window, P j is the rainfall at the jth time step, W is the sliding window size;
[0031] S33), initialize the maximum cumulative rainfall R max and its corresponding time period [T start ,T end ], traverse all sliding windows, calculate the rainfall of each sliding window, if the rainfall of the current sliding window is R i Greater than the maximum cumulative rainfall recorded R max , then update the maximum rainfall and the corresponding time period, that is:
[0032] R max =max(R i );
[0033] [T strart ,T end ]=[t i ,t i+w-1 ];
[0034] Among them, t i , t i+w-1 is the time period of the i-th sliding window;
[0035] S34), the maximum rainfall R max The corresponding time period t i ,t i+w-1 Re-divide into the maximum rainfall period across the period and two normal periods, and calculate the rainfall in the maximum rainfall period across the period and the two normal periods, and ensure that the time period t i ,t i+w-1 The total rainfall within the period remains unchanged, namely:
[0036]
[0037] Where t1 and t2 are time periods t i ,t i+w-1 The original period, are the rainfall amounts corresponding to the original periods t1 and t2 respectively; t m is the maximum rainfall period; t′1 and t′2 are two new periods respectively; are t′1 and t m , the rainfall corresponding to t′2.
[0038] As a preferred step, step S4), the redistributed rainfall and temperature T t 、Humidity H t Form the new input matrix X t,new ,Right now:
[0039]
[0040] Where, are t′1 and t m , the rainfall corresponding to t′2.
[0041] Then input matrix X t,new The input is fed into the trained Transformer model, and after position encoding, multi-head self-attention mechanism and feedforward neural network processing, a new runoff sequence is generated:
[0042] Q′ t-1 ,Q tm ,Q′ t =Transformer(X t,new );
[0043] Among them, Q′ t-1 For Q′ t is the new runoff corresponding to time t-1 and t, Q tm The maximum rainfall period t m The corresponding runoff.
[0044] The beneficial effects of the present invention are:
[0045] 1. The present invention can automatically identify rainfall events across time periods and generate new unequal-time rainfall sequences based on the maximum short-duration rainfall. Furthermore, the Transformer model can be used to generate unequal-time flood sequences with higher temporal resolution.
[0046] 2. The present invention can more accurately reflect the relationship between maximum rainfall and flood peak, thereby improving the accuracy and reliability of flood simulation;
[0047] 3. The present invention identifies the time period when the maximum rainfall occurs and generates a corresponding rainfall sequence. It then uses this adjusted data to simulate floods. The generated flood sequence can more accurately capture the changes and characteristics of flood peaks. This not only improves the accuracy of flood predictions, but also provides more powerful technical support for disaster prevention and mitigation. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a schematic diagram of the process of the present invention;
[0049] Figure 2 It is a process framework diagram of the present invention. DETAILED DESCRIPTION
[0050] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings:
[0051] like Figure 1 and 2 As shown, this embodiment provides a Transformer-based flood prediction method for variable time periods, including the following steps:
[0052] S1), obtaining hydrological and meteorological data of equal time periods and preprocessing them;
[0053] S2), building a Transformer model and training the built Transformer model;
[0054] S3) Redistribute water volume in the basin during different periods of precipitation;
[0055] S4) For each time step, the data composed of the redistributed rainfall is input into the trained Transformer model, and after processing by position encoding, multi-head self-attention mechanism and feedforward neural network, a new runoff sequence is generated.
[0056] As a preferred embodiment of the present invention, in step S1), the hydrological and meteorological data of equal time periods include basin precipitation, temperature and runoff. In this embodiment, the time scale is days or hours.
[0057] As a preferred embodiment of the present invention, in step S1), the preprocessing is to perform missing value and noise processing on the hydrological and meteorological data of equal time periods to ensure alignment on the time scale and to perform standardization on the hydrological and meteorological data.
[0058] As a preferred embodiment of this invention, in step S1), the pre-processed hydrological and meteorological data of equal time periods are divided into a training data set and a validation data set according to the 10-fold cross-validation principle; wherein the basin precipitation, temperature, and humidity are used as inputs, and the runoff is used as output.
[0059] As a preferred embodiment of this invention, in step S2), the Transformer model includes a multi-layer encoder, a multi-layer decoder, a fully connected layer and a hidden layer; the encoder of each layer includes a corresponding multi-head self-attention mechanism and a feedforward neural network; the decoder of each layer includes a corresponding multi-head self-attention mechanism, an encoder-decoder attention mechanism and a feedforward neural network.
[0060] In this embodiment, the encoder and decoder are each 6 layers with 8 attention heads, the hidden layer dimension is 512, and the feedforward network dimension is 2048.
[0061] As a preferred embodiment of this invention, in step S2), the input feature dimension of the Transformer model is n, and the time series information is embedded into the input feature:
[0062]
[0063] In the formula, in the formula, PE (pos,2i) represents the positional encoding value at the posth position (i.e., the position index in the input sequence) and the 2ith dimension (i.e., the dimension index of the embedding vector), d model is the total dimension of the embedding vector.
[0064] As a preferred embodiment of this invention, in step S2), the expression of the multi-head self-attention mechanism is:
[0065]
[0066] Where Q is the query matrix, K is the key matrix, and V is the value matrix; is the scaling factor.
[0067] As a preferred embodiment of the present invention, in step S2), the expression of the feedforward neural network is:
[0068] FFN(x)=max(0,xW1+b1)W2+b2
[0069] Among them, W1 and W2 are weight matrices, b1 and b2 are bias vectors; the input vector x is the embedded representation obtained from the self-attention mechanism or the output of the previous layer.
[0070] As a preferred embodiment of this invention, in step S2), the Transformer model is trained using a training data set, wherein the training rounds are set to 100 epochs; and the learning rate is set to 0.0001.
[0071] As a preferred embodiment of this invention, in step S3), the water redistribution during different time periods specifically includes the following steps:
[0072] S31) Select the size of the sliding window; for example, 15 minutes, 30 minutes, or 1 hour. Typically, the sliding step size is the same as the sliding window size, that is, each sliding step is one window size.
[0073] S32) Use a sliding window to traverse the entire time series data; for each sliding window, calculate its total rainfall:
[0074]
[0075] Where R i is the cumulative rainfall in the i-th sliding window, P j is the rainfall at the jth time step, W is the sliding window size;
[0076] S33), initialize the maximum cumulative rainfall R max and its corresponding time period [T start ,T end ], traverse all sliding windows, calculate the rainfall of each sliding window, if the rainfall of the current sliding window is R i Greater than the maximum cumulative rainfall recorded R max , then update the maximum rainfall and the corresponding time period, that is:
[0077] R max =max(R i );
[0078] [T strart ,T end ]=[t i ,t i+w-1 ];
[0079] Among them, t i , t i+w-1 is the time period of the i-th sliding window;
[0080] S34), the maximum rainfall R max The corresponding time period t i ,t i+w-1 Re-divide into the maximum rainfall period across the period and two normal periods, and calculate the rainfall in the maximum rainfall period across the period and the two normal periods, and ensure that the time period t i ,t i+w-1 The total rainfall within the period remains unchanged, namely:
[0081]
[0082] Where t1 and t2 are time periods t i ,t i+w-1 The original period, are the rainfall amounts corresponding to the original periods t1 and t2 respectively; tm is the maximum rainfall period; t′1 and t′2 are two new periods respectively; are t′1 and t m , the rainfall corresponding to t′2.
[0083] As a preferred embodiment of the present invention, step S4) the redistributed rainfall and temperature T t 、Humidity H t Form the new input matrix X t,new ,Right now:
[0084]
[0085] Where, are t′1 and t m , the rainfall corresponding to t′2.
[0086] Then input matrix X t,new The input is fed into the trained Transformer model, and after position encoding, multi-head self-attention mechanism and feedforward neural network processing, a new runoff sequence is generated:
[0087] Q′ t-1 ,Q tm ,Q′ t =Transformer(X t,new );
[0088] Among them, Q′ t-1 For Q′ t is the new runoff corresponding to time t-1 and t, Q tm The maximum rainfall period t m The corresponding runoff.
[0089] The above embodiments and descriptions are only for explaining the principles and best embodiments of the present invention. Without departing from the spirit and scope of the present invention, the present invention may be subject to various changes and improvements, which shall fall within the scope of the invention to be protected.
Claims
1. A Transformer-based flood prediction method for variable time periods, characterized in that: The following steps are involved: S1), obtaining hydrological and meteorological data of equal time periods and preprocessing them; S2), building a Transformer model and training the built Transformer model; S3) Redistribute the water volume of the basin precipitation in different time periods; specifically, it includes the following steps: S31), select the size of the sliding window; S32) Use a sliding window to traverse the entire time series data; for each sliding window, calculate its total rainfall: Where R i is the cumulative rainfall in the i-th sliding window, P j is the rainfall at the jth time step, W is the sliding window size; S33), initialize the maximum cumulative rainfall R max and its corresponding time period [T start ,T end ], traverse all sliding windows, calculate the rainfall of each sliding window, if the rainfall of the current sliding window is R i Greater than the maximum cumulative rainfall recorded R max , then update the maximum rainfall and the corresponding time period, that is: R max =max(R i ); [T strart ,T end ]=[t i ,t i+w-1 ]; Among them, t i , t i+w-1 is the time period of the i-th sliding window; S34), the maximum rainfall R max The corresponding time period t i ,t i+w-1 Re-divide into the maximum rainfall period across the period and two normal periods, and calculate the rainfall in the maximum rainfall period across the period and the two normal periods, and ensure that the time period t i ,t i+w-1 The total rainfall within the period remains unchanged, namely: Where t1 and t2 are time periods t i ,t i+w-1 The original period, are the rainfall amounts corresponding to the original periods t1 and t2 respectively; t m is the maximum rainfall period; t1 ′ , t2 ′ There are two new time periods respectively; t1 ′ , t m , t2 ′ corresponding rainfall; S4) For each time step, the redistributed rainfall data is input into the trained Transformer model. After position encoding, multi-head self-attention mechanism and feedforward neural network processing, the predicted runoff sequence is output through the fully connected layer. The redistributed rainfall and temperature T t 、Humidity H t Form the new input matrix X t,new ,Right now: Where, are t′1 and t m , the rainfall corresponding to t′2; Then input matrix X t,new The input is fed into the trained Transformer model, and after position encoding, multi-head self-attention mechanism and feedforward neural network processing, a new runoff sequence is generated: Q′ t-1 ,Q tm ,Q′ t =Transformer(X t,new ); Among them, Q′ t-1 For Q′ t is the new runoff corresponding to time t-1 and t, Q tm The maximum rainfall period t m The corresponding runoff.
2. The Transformer-based time-varying flood prediction method according to claim 1, characterized in that: In step S1), the hydrological and meteorological data of the same time period include basin precipitation, temperature, humidity and runoff.
3. The Transformer-based time-varying flood prediction method according to claim 2, characterized in that: In step S1), the preprocessing is to process missing values and noise of the hydrological and meteorological data of equal time periods to ensure alignment on the time scale and to standardize the hydrological and meteorological data.
4. The Transformer-based time-varying flood prediction method according to claim 3, characterized in that: In step S1), the pre-processed hydrological and meteorological data of equal time periods are divided into a training data set and a validation data set according to the 10-fold cross-validation principle; wherein the basin precipitation, temperature, and humidity are used as inputs, and the runoff is used as output.
5. The Transformer-based time-varying flood prediction method according to claim 1, characterized in that: In step S2), the Transformer model includes a multi-layer encoder, a multi-layer decoder, a fully connected layer and a hidden layer; each layer of the encoder includes a corresponding multi-head self-attention mechanism and a feedforward neural network; each layer of the decoder includes a corresponding multi-head self-attention mechanism, an encoder-decoder attention mechanism and a feedforward neural network.
6. The Transformer-based time-varying flood prediction method according to claim 5, characterized in that: In step S2), the input feature dimension of the Transformer model is n, and the time series information is embedded into the input feature: Where, PE (pos,2i) Indicates the position encoding value at the posth position and the 2ith dimension, d model is the total dimension of the embedding vector.
7. The Transformer-based time-varying flood prediction method according to claim 5, characterized in that: In step S2), the expressions of the multi-head self-attention mechanism and feedforward neural network are: FFN(x)=max(0,xW1+b1)W2+b2; Where Q is the query matrix, K is the key matrix, and V is the value matrix; is the scaling factor; W1 and W2 are weight matrices, b1 and b2 are bias vectors; the input vector x is the embedded representation obtained from the self-attention mechanism or the output of the previous layer.
8. The Transformer-based time-varying flood prediction method according to claim 5, characterized in that: In step S2), the Transformer model is trained using the training data set, wherein the training round is set to 100 epochs and the learning rate is set to 0.0001.
Citation Information
Patent Citations
Flood increase forecasting method based on time period water balance calculation
CN117421564A
Cited By
Basin flood forecasting method and system based on artificial intelligence
CN121234163A
Artificial intelligence-based basin flood forecasting method and system
CN121234163B