Runoff prediction method and device based on Xinanjiang-self-attention and medium
By integrating the self-attention mechanism of the Xin'anjiang hydrological model and the Transformer model, the parameters are optimized to improve the accuracy of runoff prediction and watershed adaptability. This solves the problems of insufficient reliability of traditional models in watershed change response and data-driven models in extreme events, and achieves high-precision and interpretable runoff prediction.
Patent Information
- Application Number
- CN202511447910.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-11
- Publication Date
- 2025-11-14
AI Technical Summary
Existing runoff prediction models have shortcomings in terms of watershed adaptability and prediction accuracy. Traditional process-driven methods cannot dynamically respond to watershed changes, while data-driven models lack hydrophysical constraints and have insufficient predictive reliability in extreme events.
By integrating the physical mechanism of the Xin'anjiang hydrological model with the time-series analysis capabilities of Transformer deep learning, the parameters of the Xin'anjiang model are optimized through a genetic algorithm, and a Transformer model is constructed for training. Runoff prediction is then performed using a self-attention mechanism.
It improves the accuracy and watershed adaptability of runoff forecasting, achieves high-precision forecasting in complex hydrological scenarios, and possesses physical interpretability and forecast reliability.
Smart Images

Figure CN120952264A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of runoff prediction, and more particularly to a runoff prediction method, apparatus and medium based on the Xin'an River-self-attention system. Background Technology
[0002] Runoff forecasting is a crucial foundation for flood control scheduling, optimal water resource allocation, and ecological environmental protection. Its accuracy directly affects the timeliness of disaster early warning and the reliability of water resource management decisions. Traditional runoff forecasting often employs process-driven methods such as the Xin'anjiang model, simulating hydrological processes through three-layer evapotranspiration calculations and full-storage runoff generation theory. However, its static physical parameters are difficult to adapt to the dynamic changes in the underlying surface of the watershed.
[0003] Data-driven models such as LSTM alleviate the gradient vanishing problem of traditional RNNs through gating units and can capture dynamic features of time series, but they still have significant drawbacks. First, their "black box" nature leads to a lack of physical interpretability; second, their long-term memory dependence is limited, and their ability to capture hydrological sequences longer than 72 hours decreases, with flood peak arrival time prediction errors reaching more than 3 hours. While Transformer models improve their ability to process long sequences through self-attention mechanisms, they also lack hydrological physical constraints and are prone to misjudging random correlations in historical data as valid patterns.
[0004] The core contradiction of existing technologies lies in the fact that process-driven methods such as the Xin'anjiang model are limited by fixed physical parameters and cannot dynamically respond to changes in the watershed; while data-driven models such as LSTM and Transformer lack hydrological mechanism constraints and have insufficient predictive reliability in data extrapolation or extreme events. Summary of the Invention
[0005] To address the shortcomings of existing single models in terms of prediction accuracy and watershed adaptability, this invention provides a runoff prediction method, device, and medium based on the Xin'anjiang River self-attention model to solve the above problems. By integrating the physical mechanism of the Xin'anjiang River hydrological model with the time series analysis capabilities of Transformer deep learning, high-precision runoff prediction is achieved.
[0006] To address the aforementioned technical problems, this application employs a runoff prediction method based on the Xin'an River and self-attention, comprising the following steps: S1, collect and preprocess data, wherein data collection includes historical rainfall, historical evaporation and historical runoff within the watershed; the preprocessing includes interpolation of missing values and processing of outliers. S2, Construct the Xin'anjiang model. By inputting the historical rainfall and runoff obtained in step S1, obtain the predicted runoff of the watershed confluence, so as to predict the confluence process of a single watershed and obtain the predicted watershed confluence amount. S3. Construct a genetic algorithm model with the goal of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. Use the parameters of the Xin'anjiang model as optimization variables, and obtain the optimal parameter combination through optimization and update the Xin'anjiang model. S4. Construct a Transformer model. Use the rainfall, evaporation and the watershed runoff prediction obtained in step S2 as the input of the Transformer model, and the predicted value of the watershed runoff prediction as the output of the Transformer model. Train the model by obtaining the dataset from steps S1 and S2, and then obtain the adjusted Transformer model. S5. Input the real-time rainfall, real-time evaporation and the watershed runoff prediction obtained in step S2 into the adjusted Transformer model to obtain the predicted flow rate.
[0007] Furthermore, the specific process of S2 includes: S2.1, Determine the actual evapotranspiration based on the upper layer evapotranspiration, lower layer evapotranspiration, and deep layer evapotranspiration of the watershed; S2.2, Calculate the watershed runoff based on the actual evapotranspiration; S2.3, divide the runoff into water sources and calculate the confluence to obtain the predicted runoff volume of the watershed.
[0008] Furthermore, the specific process of step S3 is as follows: S3.1, with the optimization objective of minimizing the error between the predicted runoff output by the Xin'anjiang model and the preprocessed historical runoff in step S1, the Nash efficiency coefficient (NSE) is used as the fitness evaluation index; the key parameters of the Xin'anjiang model are used as optimization variables, and the range of values for the optimization variables is set. S3.2, randomly generate multiple sets of parameter combinations to form an initial population, where the number of parameter combinations is set as the population size, and the parameter values in each set of parameter combinations fall within the corresponding value range set in S3.1. S3.3 Input each set of parameters in the initial population into the Xin'anjiang model, and simultaneously input the preprocessed historical rainfall data from step S1 to obtain the runoff prediction sequence corresponding to each set of parameters; according to the NSE calculation formula in S3.1, calculate the NSE value of the prediction sequence and the historical runoff measurement sequence in step S1, and use the NSE value as the fitness value of the corresponding parameter combination. S3.4, through tournament selection, crossover and mutation operations, the offspring parameter combination population is obtained.
[0009] S3.5 Take the offspring parameter combination population as a new population and repeat S3.3 to S3.4 until the termination condition is met to obtain the optimal parameter combination; S3.6 Substitute the obtained optimal parameter combination into the Xin'anjiang model to update the Xin'anjiang model parameters.
[0010] Substituting the optimal parameter combination obtained after the iteration terminates into the Xin'anjiang model completes the model parameter optimization, thereby improving the accuracy of the watershed runoff prediction output by the model.
[0011] Furthermore, the tournament selection method, based on the fitness value (NSE) calculated in S3.3, sets the tournament size to k, randomly selects k individuals from the initial population, and selects the individual with the highest fitness value among them as the parent individual; In the crossover operation, the parent individuals selected based on the tournament selection method are recombined according to the preset crossover rules to generate intermediate offspring carrying the superior parameter characteristics of the parent individuals. In the mutation operation, within the range of preset mutation probabilities and the physical meaning of the parameters of the Xin'anjiang model, the parameters of the intermediate offspring are randomly adjusted to introduce new parameter combination types to avoid population homogenization and local optima of the algorithm. The final offspring parameter combination population has all parameter values that conform to the logic of the Xin'anjiang model for the hydrological process of the watershed.
[0012] Furthermore, the specific process of step S4 is as follows: S4.1, Constructing a Transformer model: Add location encoding to the predicted rainfall, evaporation, and watershed runoff to transform the input into an initial sequence; process the initial sequence through a Transformer encoder to extract data association features and obtain a feature sequence; process it through a Transformer decoder to generate a predicted sequence; process the predicted sequence through a fully connected layer to obtain a corrected predicted sequence; Various patterns and correlations that are meaningful to the prediction target in all input data, such as the interrelationships between multiple input variables (rainfall, evaporation, runoff prediction, etc.), and abstract patterns such as time series; S4.2 uses the Adam optimizer, cosine annealing learning rate scheduling strategy, and loss function to iterate the neural network model parameters and obtain the adjusted Transformer model.
[0013] Furthermore, the specific process of step S4.1 includes: First, location codes are added to the input data, including the historical rainfall-evaporation sequence of the watershed, the runoff prediction sequence output by the Xin'anjiang model, and the historical runoff sequence. Features are extracted using a Transformer encoder; The prediction sequence is generated using the Transformer decoder; The Transformer model uses a 6-layer encoder-decoder structure to output corrected watershed runoff predictions through fully connected layers. Each encoder layer contains a multi-head self-attention mechanism and a feedforward neural network.
[0014] Furthermore, the specific process of step S4.2 is as follows: The Adam optimizer is used to iteratively update the neural network model parameters (weights, biases, etc.), and the cosine annealing strategy is used to dynamically adjust the learning rate of the neural network model parameters.
[0015] Mini-batch training is used, and the loss function is calculated and the weights are updated by backpropagation in each training round until the set early stopping condition is triggered. When the real-time rainfall sequence, the predicted runoff volume within a set time period output by the Xin'anjiang model, and the historical runoff sequence are input, the Transformer encoder and decoder calculates and generates the future runoff prediction sequence. The parameters of the neural network model are optimized using a loss function.
[0016] A runoff prediction device based on the Xin'anjiang model and Transformer includes: The data collection module collects and preprocesses data, including historical rainfall, historical evaporation, and historical runoff within the watershed. The preprocessing includes interpolation of missing values and handling of outliers. The Xin'anjiang Model Module is used to build the Xin'anjiang River model. By inputting historical rainfall and runoff data obtained from the mobile phone module, the predicted runoff of the watershed can be obtained. The update module constructs a genetic algorithm model with the goal of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. The parameters of the Xin'anjiang model are used as optimization variables. Through optimization, the optimal parameter combination is obtained and the Xin'anjiang model is updated. The adjustment module constructs a Transformer model, using rainfall, evaporation, and watershed runoff predictions obtained from the Xin'anjiang model module as inputs to the Transformer model and the predicted values of the watershed runoff predictions as outputs. The model is trained by acquiring datasets from the collection module and the Xin'anjiang model module, thereby obtaining the adjusted Transformer model. The prediction module uses the real-time rainfall, real-time evaporation, and the watershed runoff prediction obtained from the Xin'anjiang model module to input the adjusted Transformer model and obtain the predicted flow rate.
[0017] A runoff prediction device based on Xin'anjiang River self-attention includes a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they implement the runoff prediction method based on Xin'anjiang River self-attention.
[0018] A computer-readable medium having a program stored thereon that, when executed by a processor, implements the aforementioned runoff prediction method based on the Xin'anjiang River-self-attention method.
[0019] The beneficial effects of this application are as follows: This application presents a runoff prediction method, device, and medium based on the Xin'anjiang River self-attention model. It integrates the hydrophysical mechanism of the Xin'anjiang River model, the optimization of the genetic algorithm, and the temporal feature learning capability of the Transformer model, effectively improving the shortcomings of single models in terms of prediction accuracy and watershed adaptability. The evapotranspiration calculation and runoff generation and confluence mechanism of the Xin'anjiang River model provide physical constraints for prediction, ensuring the rationality of water balance and hydrological processes. The genetic algorithm optimizes and calibrates parameters to address the problems of difficult observation of Xin'anjiang River model parameters and the tendency of traditional calibration to fall into local optima, making the hydrological data simulated by the Xin'anjiang River model closer to the measured data. The self-attention mechanism of the Transformer model breaks through the long sequence dependency limitation of traditional recurrent networks, realizing effective modeling of hydrological sequences. This fusion scheme significantly improves the fitting accuracy of the model for runoff peak and process line in complex hydrological scenarios. At the same time, through the cross-constraint of hydrophysical mechanisms and temporal features, it improves the black-box characteristics of deep learning models, providing a technical solution for runoff prediction that combines physical interpretability and prediction reliability. Attached Figure Description
[0020] Figure 1 The flowchart below shows the runoff prediction method based on the Xin'anjiang River-self-attention method in Example 1. Figure 2 This is a schematic diagram of the Xin'anjiang model process in Example 1; Figure 3 This is a schematic diagram of the Transformer model in Example 1; Figure 4 This is a comparison chart of time series predictions in Example 1. Detailed Implementation The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0021] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0022] Example 1 In this embodiment, as Figure 1As shown, a runoff prediction method based on the Xin'an River self-attention model includes the following steps: S1. Collect historical daily rainfall, historical runoff data, and watershed parameters (such as soil water capacity, evapotranspiration conversion factor, etc.) of the target watershed. Perform normalization preprocessing on the data, remove outliers, and divide the data into training set and test set according to time series. The training set is used for model parameter optimization, and the test set is used to verify the prediction accuracy. Specifically, the following steps are taken: First, obtain historical daily rainfall and runoff data and watershed parameters (such as watershed water storage capacity WM, evapotranspiration coefficient K, etc.) for the past 10-15 years through watershed hydrological monitoring stations, meteorological stations, or public datasets to ensure that the data time span covers the wet season, dry season, and extreme hydrological events.
[0023] The data was then cleaned, and outliers were removed using the 3-standard-deviation method. Specifically, for a data sequence X (rainfall, runoff, etc.), if a sample value was less than [a certain value], outliers were removed. (in The mean, If the value is less than the standard deviation, it is considered an outlier, and missing data is filled using forward imputation or linear interpolation.
[0024] The rainfall and runoff data were then normalized using the Min-Max normalization formula:
[0025] Mapping the data to the [0,1] interval eliminates the influence of dimensions. Wherein: The normalized value ranges from [0,1]. : Raw datasets; specifically including raw datasets of rainfall, runoff, etc. The minimum value in the dataset; The maximum value in the dataset.
[0026] S2, as Figure 2 and Figure 3 As shown, the Xin'anjiang model is constructed. By inputting the historical rainfall and runoff obtained in step S1, the predicted runoff of the watershed is obtained, thereby enabling the prediction of the runoff process in a single watershed and yielding the predicted watershed runoff. The specific process includes: S2.1, Determine the actual evapotranspiration based on the upper layer evapotranspiration, lower layer evapotranspiration, and deep layer evapotranspiration of the watershed; The determination of actual evapotranspiration based on the upper, lower, and deep evapotranspiration of the watershed includes: Determine the upper layer evaporation rate:
[0027] In the formula, Potential evapotranspiration This is the evaporation capacity coefficient. This refers to the actual evaporation from the water surface; the upper layer evaporation. equal ; When the upper layer tension water content WU + precipitation P - actual evapotranspiration E < 0, calculate the lower layer evapotranspiration EL:
[0028] In the formula, WL is the lower layer tension water content, and WLM is the lower layer water storage capacity; when EL / (EP - EU) > deep layer evaporation coefficient C, the deep layer evaporation ED is calculated:
[0029] In the formula, the actual evaporation rate is... . S2.2, Calculate the watershed runoff based on the actual evapotranspiration; the calculation of watershed runoff based on the actual evapotranspiration includes: Formula for calculating watershed runoff R:
[0030] If P - E + A < maximum soil water capacity WMM, it indicates local runoff:
[0031] If P - E + A ≥ WMM, then the runoff is generated across the entire basin:
[0032] In the formula, denoted as current soil moisture content, A as previous rainfall, B as water storage capacity curve index, WM as watershed water storage capacity, and W0 as initial soil moisture content.
[0033] S2.3, divide the runoff into water sources and calculate the confluence to obtain the predicted runoff volume of the watershed.
[0034] Runoff is classified into surface runoff, interflow, and groundwater runoff; After runoff, water sources are divided, and the area distribution curve for free water storage capacity is determined as follows:
[0035] In the formula, MS is the current free water storage capacity, EX is the curvature parameter, f is the catchment area when the water storage capacity is less than or equal to Wm′, and F is the catchment area. Surface runoff Based on free water storage With change Calculate based on the following cases:
[0036] For the distribution curve parameters, The ratio of runoff area is given by S, where S is the mean free water depth.
[0037] The interflow RI is calculated as follows:
[0038] underground runoff for:
[0039] In the formula, Q is the free water storage capacity, AU is the change in free water storage, SM is the distribution curve parameter, FR is the runoff area ratio, KI is the outflow coefficient of the free water reservoir to the midstream flow, and KG is the outflow coefficient of the free water reservoir to the groundwater runoff. For runoff calculations, a linear reservoir model is used for runoff on slopes: Surface runoff:
[0040] Flowing in the soil:
[0041] Groundwater runoff:
[0042] In the formula, , , Let be the runoff volumes of surface runoff, interflow, and groundwater runoff at time t, respectively. , , , respectively, represent the runoff volumes of surface runoff, interflow, and groundwater runoff at time t-1; CS and CI are the interflow runoff coefficients, CG is the groundwater runoff coefficient, CS is the river channel runoff lag coefficient, and U is the area per unit area; , and These represent surface runoff, interflow, and groundwater runoff, respectively. Calculate the total inflow of the river network within the unit area. :
[0043] River network confluence uses a lag algorithm:
[0044] In the formula, CR represents the coefficients of the river network lag algorithm, and L represents the lag time. and These represent the predicted confluence of the Xin'anjiang River basin at time t and time t-1, respectively.
[0045] S3. Construct a genetic algorithm model with the objective of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. Use the parameters of the Xin'anjiang model as optimization variables, and through optimization, obtain the optimal parameter combination and update the Xin'anjiang model. The specific process is as follows: S3.1, with the optimization objective of minimizing the error between the predicted runoff output by the Xin'anjiang model and the preprocessed historical runoff in step S1, the Nash efficiency coefficient (NSE) is used as the fitness evaluation index; the key parameters of the Xin'anjiang model are used as optimization variables, and the range of values for the optimization variables is set. Specifically, 15 key parameters of the Xin'anjiang model are used as optimization variables, including: watershed storage capacity WM, upper layer storage capacity WUM, lower layer storage capacity WLM, deep layer storage capacity WDM, evapotranspiration coefficient K, impermeable area ratio IMP, stable infiltration rate FC, distribution curve parameter SM, outflow coefficient of free water reservoir to interflow KI, outflow coefficient of free water reservoir to groundwater runoff KG, interflow confluence coefficient CI, groundwater runoff confluence coefficient CG, channel confluence lag coefficient CS, channel confluence recession coefficient CE, and watershed area correction coefficient AREA. Based on the watershed hydrological characteristics, the following value ranges are set for each parameter: WM∈[50mm, 300mm], WUM∈[5mm, 20mm], WLM∈[20mm, 100mm], WDM∈[25mm, 180mm], K∈[0.5, 1.5], IMP∈[0.01, 0.2], FC∈[50mm, 200mm], SM∈[5mm, 40mm], KI∈[0.2, 0.8], KG∈[0.1, 0.5], CI∈[0.5, 2.0], CG∈[0.1, 0.5], CS∈[1h, 24h], CE∈[0.1, 0.9], AREA∈[0.9, 1.1].
[0046] S3.2, randomly generate multiple sets of parameter combinations to form an initial population, where the number of parameter combinations is set as the population size, and the parameter values in each set of parameter combinations fall within the corresponding value range set in S3.1. Specifically, N sets of parameter combinations are randomly generated to form the initial population, where the population size N is selected from 50 to 200; the parameter values in each set of parameter combinations must fall within the corresponding value range set in S3.1 to ensure the diversity of the population and the comprehensiveness of subsequent optimization.
[0047] S3.3 Input each set of parameters in the initial population into the Xin'anjiang model, and simultaneously input the preprocessed historical rainfall data from step S1 to obtain the runoff prediction sequence corresponding to each set of parameters; according to the calculation formula in S3.1, calculate the NSE value of the prediction sequence and the historical runoff measurement sequence in step S1, and use the NSE value as the fitness value of the corresponding parameter combination. The calculation formula is:
[0048] In the formula, This represents the historical measured runoff value at time i in step S1. This represents the output of the Xin'anjiang model. i Predicted runoff volume at any time This represents the average of historical measured runoff values, where n represents the total number of samples. The value range is (-∞, 1]. The closer the value is to 1, the higher the prediction accuracy and the better the fitness of the corresponding parameter combination.
[0049] S3.4, through tournament selection, crossover operation and mutation operation in sequence, to obtain the offspring parameter combination population.
[0050] Among them, the tournament selection method is based on the fitness value (NSE) calculated by S3.3, and selects the parameter combination with a higher fitness value from the initial population as the parent individual; Crossover operation recombines the parameter features of the selected parent individuals according to preset crossover rules to generate intermediate offspring that carry the superior parameter features of the parent. The mutation operation randomly adjusts some parameters of the intermediate offspring within the range of preset mutation probabilities and the physical meaning of the parameters of the Xin'anjiang model. New parameter combination types are introduced to avoid population homogenization and local optima of the algorithm. The final offspring parameter combination population has all parameter values that conform to the logic of the Xin'anjiang model for the hydrological process of the watershed.
[0051] Specifically, a tournament selection method is used to randomly select m individuals (m≥2) from the current population, and select the individual with the highest fitness value as the parent individual to be retained for the next generation; this process is repeated to select a set of parent individuals with the same size as the initial population.
[0052] Crossover operation: Based on the selected parent individuals, crossover operation is performed with a crossover probability P1 (P1=0.6-0.8) (i.e., the preset crossover rule): two parent individuals are randomly selected, a crossover position k0 is randomly determined (1≤k0≤14), and the values of parameters k0+1 to 15 in the two parent individuals are swapped to generate two child parameter combinations; parent individuals that are not selected for crossover are directly retained as child individuals.
[0053] Mutation operation: For the offspring individuals obtained after crossover, a mutation operation is performed according to the mutation probability P2 (P2=0.01-0.05): a parameter is randomly selected from the offspring individuals, and a new value is randomly generated within its corresponding value range to replace the original value, so as to enhance the diversity of the population. S3.5 The offspring individuals obtained after mutation are used as a new population. S3.3 to S3.4 are repeated until the termination condition is met, and the optimal parameter combination is obtained. Iteration termination judgment: After each iteration, the optimal fitness value in the population is recorded. The iteration terminates when either of the following conditions is met: 1. The number of iterations reaches the preset maximum value T (T=100-500); 2. The change in the optimal fitness value over M consecutive generations (M=10-20) is ≤0.001.
[0054] S3.6 Substitute the obtained optimal parameter combination into the Xin'anjiang model to update the Xin'anjiang model parameters.
[0055] Substituting the optimal parameter combination obtained after the iteration terminates into the Xin'anjiang model completes the model parameter optimization, thereby improving the accuracy of the watershed runoff prediction output by the model.
[0056] S4. Construct a Transformer model. Use the rainfall, evaporation and the watershed runoff prediction obtained in step S2 as the input of the Transformer model, and the predicted value of the watershed runoff prediction as the output of the Transformer model. Train the model by obtaining the dataset from steps S1 and S2, and then obtain the adjusted Transformer model. First, the data to be divided is clearly defined as the complete time-series data preprocessed by S1, including input features and output labels. The input features cover historical rainfall and evaporation within the watershed, as well as the predicted runoff from the Xin'anjiang model constructed by S2; the output labels are the measured runoff from the corresponding time period. Then, according to the chronological order of the time-series data, the above data is divided into three subsets: Training set: accounting for 80% of the total data volume, composed of the earliest 80% of the time series data; Validation set: accounting for 10% of the total data, located in the middle 10% period after the training set; Test set: accounting for 10% of the total data volume, selecting the latest 10% of the time period data in the entire time series data.
[0057] The test set operates completely independently during model training and hyperparameter tuning, and does not participate in any parameter optimization process. Its purpose is to simulate real-world scenarios in practical applications, examine the predictive performance of the S3.2-optimized Transformer model on unseen state-of-the-art data, and verify the model's generalization ability in complex hydrological scenarios.
[0058] S4.1, Constructing a Transformer model: Add location encoding to the predicted rainfall, evaporation, and watershed runoff to transform the input into an initial sequence; process the initial sequence through a Transformer encoder to extract data association features and obtain a feature sequence; process it through a Transformer decoder to generate a predicted sequence; process the predicted sequence through a fully connected layer to obtain a corrected predicted sequence; Various patterns and correlations that are meaningful to the prediction target in all input data, such as the interrelationships between multiple input variables (rainfall, evaporation, runoff prediction, etc.), and abstract patterns such as time series; First, construct the input sequence, which is the historical confluence prediction sequence output by the Xin'anjiang model. Historical rainfall sequence and historical runoff sequence Aligned by time steps to form a three-dimensional tensor As input to the model, The current time is represented by time steps of 24 hours (rainfall and runoff) and 72 hours (historical runoff).
[0059] To capture the temporal position information of the sequence, position encoding is added to the input tensor. The position encoding formula is as follows:
[0060] in Here, j is the location index, and j is the dimension index. The model dimension is set to 64 in this embodiment. The positional encoding is added element-wise to the input tensor and then input into the Transformer model. Generate the prediction sequence using the Transformer decoder:
[0061]
[0062] xInput to the first layer of the decoder , The input x is the result after masking multi-head self-attention, and y is the output of the first sub-layer of the decoder. 1 represents the sequence generated by the first layer of the decoder. The sequence generated by the second layer of the decoder. The encoder output representation provides the decoder with contextual information about the input sequence; attention(.) is the attention mechanism function; LayerNorm(.) is the normalization function after summation.
[0063] The corrected watershed runoff prediction is output through the fully connected layer. :
[0064] The Transformer model employs a 6-layer encoder-decoder structure, with each encoder layer containing a multi-head self-attention mechanism and a feedforward neural network. (.) represents the function used by the fully connected layer.
[0065] The Transformer model employs a 6-layer encoder-decoder structure. Each encoder layer includes a multi-head self-attention mechanism and a feedforward neural network, while the decoder additionally includes an encoder-decoder attention layer. The multi-head attention is calculated as follows:
[0066] in The attention function is . For the first l The projection matrix of each attention head (dimension 1) This is used to map the input sequence to query vector Q, key vector K, and value vector V, enabling parallel computation of multi-head attention. The connection matrix for multi-head attention output is used to... The outputs of the attention heads are merged into a feature vector of uniform dimension. This refers to the dimension of a single attention head. This embodiment sets... Size, .
[0067] The feature sequence output by the decoder is mapped to the runoff prediction space through a fully connected layer. The structure of the fully connected layer is as follows: It contains two linear transformation layers and a ReLU activation function.
[0068] S4.2 uses the Adam optimizer, cosine annealing learning rate scheduling strategy, and loss function to iterate the neural network model parameters and obtain the adjusted Transformer model.
[0069] The Adam optimizer is used to iteratively update the neural network model parameters (weights, biases, etc.), with an initial learning rate of 0.001. A cosine annealing strategy is used to dynamically adjust the learning rate. .
[0070]
[0071] in =0.0001, =0.001, For the current training round, Set to the maximum number of rounds (set to 100).
[0072] The loss function uses a weighted combination of RMSE (root mean square error) and NSE (Nash-Sutcliffe efficiency coefficient):
[0073] in , , , The measured historical runoff value at time i in step S1. Let be the predicted value of the Transformer model at time i. This represents the average value of historical measured runoff.
[0074] An early stopping mechanism is used during training. Training stops when the validation set NSE shows no improvement for 10 consecutive rounds, and the parameters of the model with the best performance on the validation set are saved. The batch size is set to 32, and the maximum number of training rounds is 100. Finally, a well-trained Transformer runoff prediction model is obtained. .
[0075] Mini-batch training with a batch size of 32 is used. The loss function is calculated and the weights are updated by backpropagation in each training round. An early stopping mechanism is triggered when the NSE value on the validation set does not improve for 10 consecutive rounds to avoid overfitting.
[0076] S5 inputs real-time rainfall data into the Xin'anjiang model, calculates the current runoff prediction according to the S2 process, integrates it with the real-time rainfall sequence and historical runoff data, and inputs it into the trained Transformer model. The codec infers and generates the runoff prediction sequence for the next 24 hours, and outputs the corrected prediction value through the fully connected layer, thus completing the dynamic prediction of runoff in a single watershed.
[0077] When the real-time rainfall sequence, the 3-hour runoff forecast output by the Xin'anjiang model, and the historical runoff sequence (i.e., data from the past 72 hours) are input, the Transformer encoder and decoder calculates and generates the runoff forecast sequence for the next 24 hours. The single-step prediction formula is as follows:
[0078] In the formula , This is a mapping function for the trained Transformer model.
[0079] Time series prediction comparison chart as follows Figure 4 As shown, Figure 4 (a) in the figure is the data plot of the training set, which has a total of 61,047 data points and RMSE=0.122. The red curve in the figure is the actual value curve and the blue curve is the predicted value curve. Figure 4 (b) in the figure is the data plot of the validation set, which has a total of 12,880 data points and RMSE=0.220. The red curve in the figure is the actual value curve and the blue curve is the predicted value curve. Figure 4 (c) in the figure is the data plot of the test set, which has 12,887 data points and RMSE=0.126. The red curve in the figure is the actual value curve and the blue curve is the predicted value curve. It can be seen from the figure that the predicted curve and the actual value curve under each dataset show good fit and can accurately reproduce the dynamic change characteristics of the actual hydrological sequence. Moreover, the RMSE values of the training set and the test set are close (0.122, 0.126), indicating that the model does not have obvious overfitting and has generalization ability.
[0080] Example 2 A runoff prediction device based on the Xin'anjiang model and Transformer includes: The data collection module collects and preprocesses data, including historical rainfall, historical evaporation, and historical runoff within the watershed. The preprocessing includes interpolation of missing values and handling of outliers. The Xin'anjiang Model Module is used to build the Xin'anjiang River model. By inputting historical rainfall and runoff data obtained from the mobile phone module, the predicted runoff of the watershed can be obtained. The update module constructs a genetic algorithm model with the goal of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. The parameters of the Xin'anjiang model are used as optimization variables. Through optimization, the optimal parameter combination is obtained and the Xin'anjiang model is updated. The adjustment module constructs a Transformer model, using rainfall, evaporation, and watershed runoff predictions obtained from the Xin'anjiang model module as inputs to the Transformer model and the predicted values of the watershed runoff predictions as outputs. The model is trained by acquiring datasets from the collection module and the Xin'anjiang model module, thereby obtaining the adjusted Transformer model. The prediction module uses the real-time rainfall, real-time evaporation, and the watershed runoff prediction obtained from the Xin'anjiang model module to input the adjusted Transformer model and obtain the predicted flow rate.
[0081] Example 3 A runoff prediction device based on Xin'anjiang River self-attention includes a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they implement the runoff prediction method based on Xin'anjiang River self-attention of Embodiment 1.
[0082] Example 4 A computer-readable medium having a program stored thereon, which, when executed by a processor, implements the runoff prediction method based on the Xin'anjiang River-self-attention method of Embodiment 1.
[0083] It should be noted that the above content merely illustrates the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. For those skilled in the art, various improvements and modifications can be made without departing from the principle of the present invention, and all such improvements and modifications fall within the scope of protection of the claims of the present invention.
Claims
1. A runoff prediction method based on the Xin'an River self-attention system, characterized in that, The steps include the following: S1, collect and preprocess data, wherein data collection includes historical rainfall, historical evaporation and historical runoff in the watershed, and the preprocessing includes interpolation of missing values and processing of outliers. S2, construct the Xin'anjiang model, and obtain the predicted runoff of the watershed by inputting the historical rainfall and runoff obtained in step S1; S3. Construct a genetic algorithm model with the goal of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. Use the parameters of the Xin'anjiang model as optimization variables, and obtain the optimal parameter combination through optimization and update the Xin'anjiang model. S4. Construct a Transformer model. Use the rainfall, evaporation and the watershed runoff prediction obtained in step S2 as the input of the Transformer model, and the predicted value of the watershed runoff prediction as the output of the Transformer model. Train the model by obtaining the dataset from steps S1 and S2, and then obtain the adjusted Transformer model. S5. Input the real-time rainfall, real-time evaporation and the watershed runoff prediction obtained in step S2 into the adjusted Transformer model to obtain the predicted flow rate.
2. The runoff prediction method based on Xin'anjiang River self-attention as described in claim 1, characterized in that, The specific process of S2 includes: S2.1, Determine the actual evapotranspiration based on the upper layer evapotranspiration, lower layer evapotranspiration, and deep layer evapotranspiration of the watershed; S2.2, Calculate the watershed runoff based on the actual evapotranspiration; S2.3, divide the runoff into water sources and calculate the confluence to obtain the predicted runoff volume of the watershed.
3. The runoff prediction method based on Xin'anjiang River self-attention as described in claim 1, characterized in that, Step S3 specifically includes the following processes: S3.1, with the optimization objective of minimizing the error between the predicted runoff output by the Xin'anjiang model and the preprocessed historical runoff in step S1, the Nash efficiency coefficient is used as the fitness evaluation index; the key parameters of the Xin'anjiang model are used as optimization variables, and the range of values for the optimization variables is set. S3.2, randomly generate multiple sets of parameter combinations to form an initial population, where the number of parameter combinations is set to the population size, and the parameter values in each set of parameter combinations fall within the corresponding value range set in S3.
1. S3.3 Input each set of parameters in the initial population into the Xin'anjiang model, and simultaneously input the preprocessed historical rainfall data from step S1 to obtain the runoff prediction sequence corresponding to each set of parameters; according to the Nash efficiency coefficient calculation formula in S3.1, calculate the NSE value of the prediction sequence and the historical runoff measured sequence in step S1, and use the NSE value as the fitness value of the corresponding parameter combination. S3.4, the offspring parameter combination population is obtained by sequentially using tournament selection, crossover operation and mutation operation; S3.5 Take the offspring parameter combination population as a new population and repeat S3.3 to S3.4 until the termination condition is met to obtain the optimal parameter combination; S3.6 Substitute the obtained optimal parameter combination into the Xin'anjiang model to update the Xin'anjiang model parameters.
4. The runoff prediction method based on Xin'anjiang River self-attention as described in claim 3, characterized in that, The tournament selection method, based on the fitness value calculated in S3.3, sets the tournament size, randomly selects the same number of individuals as the tournament size from the initial population, and selects the individual with the highest fitness value among them as the parent individual; In the crossover operation, based on the parent individual, the parameter characteristics of the parent individual are recombined according to the preset crossover rules to generate an intermediate offspring carrying the superior parameter characteristics of the parent. In the mutation operation, within the preset mutation probability and the range of values of the Xin'anjiang model parameters, the parameters of the intermediate offspring are randomly adjusted to form the final offspring parameter combination population.
5. The runoff prediction method based on Xin'anjiang River self-attention as described in claim 1, characterized in that, The S4 process includes: S4.1, Constructing a Transformer model: Add location encoding to the predicted rainfall, evaporation, and watershed runoff to transform the input into an initial sequence; process the initial sequence through a Transformer encoder to extract data association features and obtain a feature sequence; process it through a Transformer decoder to generate a predicted sequence; process the predicted sequence through a fully connected layer to obtain a corrected predicted sequence; S4.2 uses the Adam optimizer, cosine annealing learning rate scheduling strategy, and loss function to iterate the neural network model parameters and obtain the adjusted Transformer model.
6. The runoff prediction method based on Xin'anjiang River self-attention as described in claim 5, characterized in that, The specific process of S4.2 is as follows: The Adam optimizer is used to iteratively update the parameters of the neural network model, and the learning rate of the neural network model parameters is dynamically adjusted using a cosine annealing strategy. Mini-batch training is used, and the loss function is calculated and the weights are updated by backpropagation in each training round until the set early stopping condition is triggered. When the real-time rainfall sequence, the predicted runoff volume within a set time period output by the Xin'anjiang model, and the historical runoff sequence are input, the Transformer encoder and decoder calculates and generates the future runoff prediction sequence. The parameters of the neural network model are optimized using a loss function.
7. A runoff prediction device based on the Xin'an River self-attention system, characterized in that, include: The data collection module collects and preprocesses data, including historical rainfall, historical evaporation, and historical runoff within the watershed. The preprocessing includes interpolation of missing values and handling of outliers. The Xin'anjiang Model Module is used to build the Xin'anjiang River model. By inputting historical rainfall and runoff data obtained from the mobile phone module, the predicted runoff of the watershed can be obtained. The update module constructs a genetic algorithm model with the goal of minimizing the error between the runoff predicted by the Xin'anjiang model and the historical runoff in S1. The parameters of the Xin'anjiang model are used as optimization variables. Through optimization, the optimal parameter combination is obtained and the Xin'anjiang model is updated. The adjustment module constructs a Transformer model, using rainfall, evaporation, and watershed runoff predictions obtained from the Xin'anjiang model module as inputs to the Transformer model and the predicted values of the watershed runoff predictions as outputs. The model is trained by acquiring datasets from the collection module and the Xin'anjiang model module, thereby obtaining the adjusted Transformer model. The prediction module uses the real-time rainfall, real-time evaporation, and the watershed runoff prediction obtained from the Xin'anjiang model module to input the adjusted Transformer model and obtain the predicted flow rate.
8. A runoff prediction device based on the Xin'an River self-attention system, characterized in that, The device includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the runoff prediction method based on the Xin'anjiang River-self-attention method as described in any one of claims 1-6.
9. A computer-readable medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the runoff prediction method based on the Xin'anjiang River-self-attention method as described in any one of claims 1-6.
Citation Information
Patent Citations
Modularized Xinanjiang model construction method
CN117540560A
Flood prediction method and device, electronic equipment and readable storage medium
CN117556255A
Runoff prediction method and device and computer readable storage medium
CN119940610A
Early warning method for debris flow disaster in small watershed, and disaster reduction method for debris flows in small watershed
US20250314492A1
Big data-based hydrologic forecasting method
WO2022032872A1