Large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism

By applying deep learning and attention mechanisms in water quality simulation and attention mechanism, the problem of data scarcity and complexity in the existing water quality model in large -scale water quality simulation is solved, and the concentration and general phosphorus concentration and general phosphorus of hundreds of watersheds are realized. Efficient simulation and prediction of quantity.

CN119049586BActive Publication Date: 2025-01-28HOHAI UNIV

Patent Information

Application Number
CN202411505973.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-01-28
Estimated Expiration
2044-10-28

AI Technical Summary

Technical Problem

In large-scale water quality simulation, existing water quality models have problems such as scarce data, complex parameter setting, high model complexity, limited scope of application, lack of real-time prediction capabilities, and insufficient ability to deal with nonlinear and complex relationships.

Method used

Using a large -scale basin simulation method based on deep learning and attention mechanisms, training and predicting hydrological and water quality data through the LSTM model and attention mechanism can be used to achieve the simulation of the total phosphorus concentration and general volume of hundreds of watershed in the basin. Essence

Benefits of technology

It has improved the model's ability to pay attention to important time steps and characteristics, simplifies parameter adjustment, reduces the cost of calculation, improves the accuracy and simulation efficiency, and is suitable for large -scale and multi -watershed water quality simulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119049586B_ABST
    Figure CN119049586B_ABST
Patent Text Reader

Abstract

The present invention discloses a large-scale basin total phosphorus simulation method based on deep learning and attention mechanism, including: collecting daily hydrological and meteorological time series data, water quality data and constant basin attribute data; preprocessing the collected data; creating and introducing the attention mechanism in the LSTM model to set hyperparameters; inputting the preprocessed data into the LSTM model containing the attention mechanism for model training and evaluation; outputting the simulated data set of the basin's daily total phosphorus concentration and flux. The present invention applies the deep learning algorithm to the training of the LSTM model, and introduces the attention mechanism to improve the model's attention to important time steps and features, realizing the simultaneous simulation of daily TP data of hundreds of basins, and learning of hundreds of basin characteristics and dynamic behaviors, which has the advantages of wide spatial range and large time span in water quality simulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of water quality monitoring and relates to total phosphorus simulation technology, and specifically to a large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism. Background Art

[0002] Phosphorus is one of the important elements in the Earth's biological system and a key limiting factor for eutrophication of rivers and lakes. Therefore, predicting phosphorus in surface waters and analyzing the influencing factors of TP emission characteristics in watersheds can improve the accuracy and efficiency of surface water eutrophication control and decision-making, which is of great significance for improving surface water quality, maintaining water ecological balance, and scientifically managing water resources.

[0003] Rivers are fluid channels for the transfer of phosphorus nutrients from land to sea. In traditional studies, the phosphorus content and water quality of water bodies are usually assessed by measuring the total phosphorus (TP) concentration. TP concentration refers to the total amount of dissolved and particulate phosphorus in the water body, which provides a static water quality indicator. However, this method has certain limitations because it cannot reflect the dynamic changes of TP in time and space, nor can it fully describe the phosphorus transport process and load in rivers.

[0004] In order to more accurately understand and evaluate the emission characteristics of phosphorus in rivers, researchers introduced the concept of TP flux. TP flux refers to the amount of TP in a water body passing through a certain point or area per unit time, which can more comprehensively reflect the transportation process and load of TP in the water body.

[0005] Water quality model is one of the important tools for predicting and analyzing the TP discharge characteristics of water bodies. Currently, widely used water quality models such as MIKE, EFDC, SWAT, etc. perform well in the migration and load calculation of TP in surface water bodies. However, current water quality prediction still faces challenges. On the one hand, water quality data are sparse and discontinuous and are limited in time, space and frequency; on the other hand, traditional numerical models require massive data support and complex calculation processes, resulting in high computational costs; the changes in water quality data in time and space force the variables to be repeatedly calibrated during the derivation process, especially at large temporal and spatial scales. The simulation results are not ideal.

[0006] Specifically, the above methods all have defects in large-scale water quality simulation. During the development process, water quality models require a large amount of hydrological and meteorological data and water quality monitoring data support. The contradiction between the large data demand and the scarcity of water quality data is difficult to reconcile. In addition, water quality models usually rely on prior knowledge and physical principles, and their structure is complex, containing a large number of parameters and cumbersome calculation processes. The setting of these parameters not only needs to take into account the influence of multiple boundary conditions, but also needs to be calibrated and verified in a specific environment. However, the diversity and variability of boundary conditions increase the uncertainty of parameter setting, which not only challenges the accuracy of the model, but also limits its application scope in different regions and environments. In other words, the applicability of the model is greatly limited, and it is difficult to be widely promoted and used at different scales and under different water conditions. Non-mechanistic methods such as traditional machine learning methods often require a lot of manual interaction through feature engineering to generate results. Taking water quality simulation as an example, researchers need to manually select and extract various environmental factors, such as rainfall, flow, land use type, temperature, etc., as input features. However, these manually selected features may not be able to fully capture the complex relationships and potential patterns in the data, resulting in limited model performance. On the other hand, machine learning models have limited ability to capture nonlinear relationships and lack adaptability when it comes to large-scale, multi-dimensional data and cross-domain applications, which limits the scope of application and the accuracy of simulation results. Summary of the invention

[0007] Purpose of the invention: In order to overcome the shortcomings of the prior art, a large-scale basin total phosphorus simulation method based on deep learning and attention mechanism is provided. By introducing deep learning and attention mechanism, the limitations of the existing simulation methods are successfully broken through, and the accurate simulation of daily TP data of hundreds of basins in different climatic and geographical zones is achieved.

[0008] Technical solution: To achieve the above purpose, the present invention provides a large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism, comprising the following steps:

[0009] S1: Collect daily hydrological and meteorological time series data, water quality data, and constant watershed attribute data;

[0010] S2: preprocess the collected data;

[0011] S3: Create an LSTM model and introduce the attention mechanism, and set the hyperparameters of the LSTM model;

[0012] S4: Input the preprocessed data in step S3 into the LSTM model for model training and evaluation to obtain the LSTMTP model;

[0013] S5: The improved LSTMTP model outputs a simulated data set of daily total phosphorus concentration and flux in the basin.

[0014] Furthermore, the time series data in step S1 includes flow, precipitation, sunshine time, maximum and minimum temperatures, snow water equivalent, water vapor pressure, solar radiation, and biogeochemical parameters;

[0015] The daily data of water quality data such as dissolved oxygen and TP are not continuous and have many missing values;

[0016] The constant basin attribute data include six groups: topography, climate, hydrology, land use conditions, soil and geological properties. These characteristics correspond to a series of parameters, including the basin's coordinate position, altitude, basin slope, annual snow cover ratio, average annual precipitation, average annual and monthly temperature, as well as flow, base flow index, etc.

[0017] Furthermore, the pre-processing method in step S2 includes:

[0018] A1: Delete duplicate time series data, erroneous records and outliers;

[0019] A2: Perform data standardization;

[0020] A3: Transpose and reshape the time data to obtain three-dimensional time series data. The three dimensions are the number of watersheds, the number of time steps, and the variable characteristics and attributes corresponding to each time step.

[0021] Furthermore, the data standardization process in step A2 is specifically as follows:

[0022] The data is Z-score standardized to convert the data into a distribution with a mean of 0 and a standard deviation of 1, and to ensure that the data has a similar scale and distribution. The calculation formula is as follows:

[0023]

[0024] Among them, x is the original data, μ is the average value of the original data, is the standard deviation of the original data, is the normalized data.

[0025] Furthermore, the LSTM model in step S3 is created by calling the torch.cuda.is available() function to determine whether there is an available GPU device in the current system. When it is detected that the GPU is available, the LSTM model is instantiated using the rnn.CudnnLstmModel class.

[0026] Furthermore, the hyperparameter settings in step S3 include: the total number of epochs for training runs, the number of epochs at which the model is saved, the batch size, the time step, the number of units in the LSTM hidden layer, and the Dropout rate.

[0027] Furthermore, the training of the LSTM model in step S4 includes: setting loss weights w1, w2 and w3 for multi-task training; using the loss function crit.RmseLoss(); defining the number of training epochs nEpoch;

[0028] The algorithm equation of the LSTM model is as follows:

[0029]

[0030] in, represents the activation vector of the forget gate, yes function, is the weight matrix of the forget gate, is the hidden state at the previous time step, is the input of the current time step, is the bias term of the forget gate;

[0031]

[0032]

[0033] in, represents the activation vector of the input gate, is the candidate cell state, which represents the amount of new information added to the cell state through the input gate;

[0034]

[0035] in, and represents the cell state at the current time step and the previous time step, represents element-wise multiplication;

[0036]

[0037]

[0038] in, represents the activation vector of the output gate, is the hidden state or output at the current time step.

[0039] The characteristic data x in the algorithm corresponds to the formula , multiple feature quantities are run into the input gate of LSTM to train the model, and the important information in the long time series is captured and retained through the gating structure.

[0040] Furthermore, in step S4, an attention mechanism is added after the LSTM model, and the specific implementation includes:

[0041] Attention weight calculation: For the output of the LSTM model at each time step t , based on the hidden layer state at the previous time step t-1 and the memory cell status , through a trainable feedforward network f( ) Calculate the attention score , these attention scores Indicates the importance of time step t to the current TP prediction, and the calculation formula is as follows:

[0042]

[0043] Then, the attention score is converted into Normalization, generating attention weights , so that the sum of the weights of all time steps is 1, and the calculation formula of the attention weight is:

[0044]

[0045] in, is the output of the LSTM model at time step t, is the hidden layer state at the previous time step, is the memory cell state at the previous time step, It is a trainable feedforward network;

[0046] Weighted sum: Use the calculated attention weights to sum the output of the LSTM at each time step Perform weighted summation to obtain a context vector , which represents the comprehensive consideration of all historical time step information at the current moment, and the calculation formula is as follows:

[0047]

[0048] Prediction of the output layer: The context vector Input to the final output layer to predict TP concentration and flux; the output layer may contain one or more fully connected layers, which are responsible for converting the context vector Mapped to the target variable space to generate the final prediction result.

[0049] Furthermore, the method for model evaluation in step S4 is:

[0050] The input feature data and watershed feature attributes are passed to the trained LSTM model with attention mechanism for forward propagation to obtain the model's prediction results. The model is evaluated based on the prediction results. The evaluation formula is as follows:

[0051]

[0052]

[0053]

[0054]

[0055] in, represents the predicted value of the model, represents the observed value of the model, and n represents the total number of paired predictions and observations during model testing.

[0056] The present invention applies deep learning algorithms to the training of LSTM models, and introduces an attention mechanism to improve the model's attention to important time steps and features. The improved LSTM model outputs a simulated data set of daily total phosphorus concentration and flux in the watershed, thereby achieving simultaneous simulation of daily TP data of hundreds of watersheds and learning of characteristics and dynamic behaviors of hundreds of watersheds. It has the advantages of wide spatial range and large time span in water quality simulation.

[0057] The present invention solves the problem of scarce and discontinuous TP data at large time and space scales, and solves the problems of traditional water quality models in data scarcity, complex parameter settings, model complexity, limited scope of application, lack of real-time prediction capabilities, and insufficient ability to handle nonlinear and complex relationships. The present invention solves the problem that traditional water quality models are usually limited to the study of a single river basin, and it is difficult to effectively handle the simultaneous simulation of multiple river basins (such as hundreds of rivers) across a large range and across climatic and geographical zones. Existing methods have the problems of data scarcity, complex parameter settings, high model complexity, limited scope of application, lack of real-time prediction capabilities, and insufficient ability to handle nonlinear and complex relationships when faced with a wide spatial range and a long time span.

[0058] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0059] 1. Apply deep learning algorithms to the training of LSTM models, and introduce attention mechanisms to improve the model's attention to important time steps and features. The attention mechanism can dynamically adjust the weights of different time steps, thereby more accurately capturing the spatiotemporal variation characteristics of total phosphorus concentration and flux in the watershed.

[0060] 2. Large-scale, multi-basin simulation capabilities: Through the improved LSTM model with attention mechanism, it is possible to output the simulated data set of daily total phosphorus concentration and flux in the basin, and to simulate the daily TP data of hundreds of basins at the same time. The improved model learns the characteristics and dynamic behaviors of hundreds of basins, and has the advantages of wide spatial range and large time span in water quality simulation, which facilitates the understanding and analysis of the spatiotemporal variation characteristics of TP concentration and flux at a large scale.

[0061] 3. Simplify parameter calibration and improve efficiency: The cumbersome problem of parameter calibration under different boundary conditions in existing water quality models is solved. The introduction of the attention mechanism reduces the dependence on parameter tuning, greatly improves the efficiency of water quality simulation, and effectively reduces the computational cost.

[0062] 4. Improve prediction accuracy: The TP concentration and TP flux simulated by the method of the present invention have a high degree of fit with the observed values. The attention mechanism can better capture important time steps and feature information, effectively capture the actual change trend, and have better prediction performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 It is a basic flow chart of the method of the present invention;

[0064] Figure 2 This is a schematic diagram of the deep learning LSTM model structure of the present invention;

[0065] Figure 3 Schematic diagram of the model attention mechanism structure of the present invention;

[0066] Figure 4 It is the time series diagram of s612TP concentration;

[0067] Figure 5 This is the time series diagram of s1661TP concentration. DETAILED DESCRIPTION

[0068] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.

[0069] like Figure 1 As shown, the present invention provides a large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism, comprising the following steps:

[0070] S1: Collect daily hydrological and meteorological time series data, water quality data, and constant watershed attribute data;

[0071] Time series data include flow, precipitation, sunshine hours, maximum and minimum temperatures, snow water equivalent, water vapor pressure, solar radiation, biogeochemical parameters (such as conductivity, pH, bicarbonate (HCO3 − ) and monthly and bimonthly data on dissolved organic carbon);

[0072] The daily data of water quality data such as dissolved oxygen and TP are not continuous and have many missing values;

[0073] The constant basin attribute data include six groups: topography, climate, hydrology, land use conditions, soil and geological properties. These characteristics correspond to a series of parameters, including the basin's coordinate position, altitude, basin slope, annual snow cover ratio, average annual precipitation, average annual and monthly temperature, as well as flow, base flow index, etc.

[0074] S2: Preprocess the collected data, including:

[0075] A1: Delete duplicate time series data, erroneous records and outliers;

[0076] A2: Perform data standardization:

[0077] The data is Z-score standardized to convert the data into a distribution with a mean of 0 and a standard deviation of 1, and to ensure that the data has a similar scale and distribution. The calculation formula is as follows:

[0078]

[0079] Among them, x is the original data, μ is the average value of the original data, is the standard deviation of the original data, is the normalized data.

[0080] A3: Transpose and reshape time data: Load the processed data. Assuming the data file is comma-delimited, flatten the transposed data into a one-dimensional array. Reshape the flattened data into a three-dimensional array. The three dimensions represent the number of watersheds, the number of time steps, and the watershed characteristic attributes.

[0081] A4: Divide the processed sample data into two parts: training set and test set, using a 75%-25% division scheme to ensure that the training and test data have sufficient coverage to ensure the performance of the model.

[0082] S3: Create an LSTM model and set hyperparameters for the LSTM model:

[0083] Call torch.cuda.is available() function to determine whether there is an available GPU device in the current system; when it is detected that the GPU is available, use rnn.CudnnLstmModel class to instantiate the LSTM model; hyperparameter settings include: the total number of epochs for training runs, how many epochs the model is saved every, batch size, time step, number of units in the LSTM hidden layer, and Dropout rate. The Dropout rate is set by specifying the probability of discarding neurons during model training, usually between 0.2 and 0.5. The Dropout rate set in the present invention is 0.2, which prevents overfitting of the model and improves its generalization ability by randomly discarding some neurons in the neural network during training.

[0084] S4: Input the preprocessed data in step S3 into the LSTM model for model training and evaluation to obtain the LSTM TP model:

[0085] The training of the LSTM model includes: hydrological, meteorological and water quality related characteristic data "x" (such as precipitation, snow water equivalent, average temperature, maximum temperature, etc.), target variable data "y" (TP observation data) and static basin attribute characteristic value "c", setting the loss weights w1, w2 and w3 of multi-task training; using the loss function crit.RmseLoss(); defining the number of training epochs nEpoch;

[0086] The algorithm equation of the LSTM model is as follows:

[0087]

[0088] in, represents the activation vector of the forget gate, yes function, is the weight matrix of the forget gate, is the hidden state at the previous time step, is the input of the current time step, is the bias term of the forget gate;

[0089]

[0090]

[0091] in, represents the activation vector of the input gate, is the candidate cell state, which represents the amount of new information added to the cell state through the input gate;

[0092]

[0093] in, and represents the cell state at the current time step and the previous time step, represents element-wise multiplication;

[0094]

[0095]

[0096] in, represents the activation vector of the output gate, is the hidden state or output at the current time step.

[0097] The characteristic data x in the algorithm corresponds to the formula , run multiple feature quantities into the input gate of LSTM, train the model, and capture and retain important information in long time series through the gate control structure. The LSTM model structure is shown in the attached figure. Figure 2 shown.

[0098] like Figure 3 As shown, in the present invention, a time attention mechanism is added after the LSTM model, and the specific implementation includes:

[0099] Attention weight calculation: For the output of the LSTM model at each time step t , based on the hidden layer state at the previous time step t-1 and the memory cell status , through a trainable feedforward network f( ) Calculate the attention score These attention scores Indicates the importance of time step t to the current TP prediction, and the calculation formula is as follows:

[0100]

[0101] Then, the Softmax function is used to calculate these attention scores. Normalization, generating attention weights , so that the sum of the weights of all time steps is 1, and the calculation formula of the attention weight is:

[0102]

[0103] in, is the output of the LSTM model at time step t, is the hidden layer state at the previous time step, is the memory cell state at the previous time step, It is a trainable feedforward network;

[0104] Weighted sum: using the calculated attention weights The output of LSTM at each time step Perform weighted summation to obtain a context vector , which represents the comprehensive consideration of all historical time step information at the current moment, and the calculation formula is as follows:

[0105]

[0106] Prediction of the output layer: The context vector Input to the final output layer to predict TP concentration and flux; the output layer may contain one or more fully connected layers, which are responsible for converting the context vector Mapped to the target variable space to generate the final prediction result.

[0107] The method for model evaluation is:

[0108] The input time series feature data and watershed feature attributes are passed to the trained LSTM model for forward propagation, and the hidden state is obtained by layer-by-layer processing. , and then by the formula The predicted results of TP concentration and TP flux were obtained by mapping.

[0109] Then evaluate the model based on the prediction results. The evaluation formula is as follows:

[0110]

[0111]

[0112]

[0113]

[0114] in, represents the predicted value of the model, represents the observed value of the model, and n represents the total number of paired predictions and observations during model testing.

[0115] S5: Output the simulated data set of daily total phosphorus concentration and flux in the basin through the LSTMTP model.

[0116] In order to verify the effectiveness and practical effect of the method of the present invention, the above scheme is applied as an example in this embodiment, as follows:

[0117] 1) Collection of watershed time series data and characteristic data

[0118] This example selects 513 rivers as research objects, collects dynamic time series data and static watershed attribute information of the 513 rivers, and the time series input of hydrological and meteorological driven data includes flow (Q) and seven M variables, including precipitation, sunshine time, maximum and minimum temperature, snow water equivalent, water vapor pressure and solar radiation. The watershed boundary and Google Earth Engine technology are used to realize the watershed aggregation of data, and the dataRetrieval R language package is used to retrieve and download the above data;

[0119] As one of the water quality indicators, TP data has a lower observation frequency than meteorological and flow data, and the data is often discontinuous and missing to varying degrees. This example characterizes the continuity and completeness of the data by calculating the daily coverage of the observation data (the proportion of data recording days in 1981-2019 to 14,244 days in 40 years). According to statistics, the daily coverage of TP concentration in 513 rivers ranges from 0.49% to 22.61%, with an average of 1.69% and a median of 1.04%; the daily coverage of TP flux ranges from 0.05% to 22.33%, with an average of 1.64% and a median of 0.99%.

[0120] 2) Data preprocessing

[0121] The daily time series of seven hydrological and meteorological variables and 49 watershed attribute characteristics directly imported from CAMELS were used as input data; the log10 equation was used to transform daily precipitation and flow (mm / d), and the formula is as follows:

[0122]

[0123] The transformed input values ​​are then normalized by subtracting the continental-scale mean and dividing by the standard deviation: , where x is the original data, μ is the average value of the original data, is the standard deviation of the original data, The data is normalized; the thresholds of indicator data with different dimensions and magnitudes are adjusted to between 0 and 1.

[0124] 3) Data partitioning

[0125] According to the 75%-25% division scheme, all the processed sample data are divided into 75% as the training set and the remaining 25% as the test set.

[0126] 4) LSTM model hyperparameter setting

[0127] A hidden state size of 128, a dropout rate of 0.2, and a training instance length of 180 days were set to optimize the model’s hyperparameters, and cells and hidden states were randomly initialized to zero from a uniform distribution.

[0128] 5) LSTMTP prediction model training

[0129] The data is passed into the LSTM model containing the attention mechanism. In this embodiment, the time step is set to 5, the batch size is set to 20, and the learning rate is set to 0.001. The activation function is selected as follows: the first layer is the ReLU activation function, and the second layer is the ReLU activation function; the output layer is linear activation (because no activation function is used); the hidden layer settings include: the first layer hidden unit is 128, and the second layer hidden unit is 64; the training round is set to 100, and the Adam algorithm is used to optimize the training process until the network converges. The specific training process is as follows: add an attention layer after the second layer LSTM, calculate the attention weight for the output of each time step, and use weighted summation to calculate the context vector. The calculation of the attention weight is realized through a feedforward network, and the weighted summation of the LSTM output is performed to obtain the context vector. The context vector is input to the final output layer for the prediction of TP concentration and flux.

[0130] 6) LSTMTP prediction model performance evaluation

[0131] In this embodiment, the target variables are set as TP concentration and TP flux. In the model training process, four statistical indicators, namely percentage bias (Pbias), Nash efficiency coefficient (NSE), root mean square error (RMSE) and Pearson correlation coefficient (Pcorr), are used to evaluate the performance of the invention on various rivers. The evaluation formula is as follows:

[0132]

[0133]

[0134]

[0135]

[0136] in, represents the predicted value of the model, represents the observed value of the model, and n represents the total number of paired predictions and observations during model testing.

[0137] The range of percentage bias (Pbias) is from negative infinity to positive infinity, and a lower absolute value indicates a more accurate model simulation effect; the range of Nash efficiency coefficient (NSE) is from negative infinity to 1. Traditionally, 1 means that the model prediction completely matches the observed value, NSE<0 means that the model is unreliable, and NSE≥0.5 is considered to be a good performance of the water quality model; the range of root mean square error is 0 to infinity, and the lower the value, the better the model performance; the range of Pcorr is from -1 to 1, indicating the absolute negative correlation and positive correlation between the simulated value and the observed value, respectively.

[0138] The simulated values ​​of each river model are constantly compared with the observed values. Figure 4 and Figure 5 As shown, from the statistical results of the evaluation parameters, the NSE mean of TP concentration in the test period reached 0.74, and more than half of the rivers had NSE higher than 0.8; the NSE mean of TP flux was 0.8, the RMSE mean of TP concentration was 0.13, and the TP flux values ​​of most rivers were below 0.2; the Pearson correlation coefficients were all greater than 0.8, and the Pearson correlation coefficient of TP flux had an average of 0.95. In order to intuitively compare the evaluation results of the model, the present invention compares the simulation results of the existing water quality models and methods, and the comparison results are shown in Table 1;

[0139] Table 1 Comparison of model evaluation performance (NSE)

[0140]

[0141] It can be seen from Table 1 that the method of the present invention has a better total phosphorus simulation effect in a large-scale range of time and space.

[0142] 7) If the model error exceeds the set threshold, the model performance needs to be optimized by adjusting the hyperparameters of the LSTM model (such as learning rate, batch size, number of hidden units, and time step). Adjusting these parameters can change the model's learning efficiency and ability to capture data features, thereby reducing prediction errors. The updated model will be retrained and evaluated, and the above steps will be repeated to ensure the accuracy of the total phosphorus simulation in the basin at a large scale in time and space.

Claims

1. A large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism, characterized in that: The steps include: S1: Collect daily hydrological and meteorological time series data, water quality data, and constant watershed attribute data; S2: preprocess the collected data; S3: Create an LSTM model based on the attention mechanism and set the hyperparameters of the LSTM model; S4: Input the preprocessed data in step S3 into the LSTM model including the attention mechanism for model training and evaluation to obtain the LSTMTP model; S5: Output the simulated data set of daily total phosphorus concentration and flux in the basin through the LSTMTP model; The time series data in step S1 include flow, precipitation, sunshine time, maximum and minimum temperatures, snow water equivalent, water vapor pressure, solar radiation, and biogeochemical parameters; The constant watershed attribute data include six groups: topography, climate, hydrology, land use conditions, soils, and geological attributes; The LSTM model in step S3 is created by calling the torch.cuda.is available() function to determine whether there is an available GPU device in the current system; when it is detected that the GPU is available, the LSTM model is instantiated using the rnn.CudnnLstmModel class; The hyperparameter settings in step S3 include: the total number of epochs for training, the number of epochs at which the model is saved, the batch size, the time step, the number of units in the LSTM hidden layer, and the dropout rate; The training of the LSTM model in step S4 includes: setting the loss weights w1, w2 and w3 of the multi-task training; using the loss function crit.RmseLoss(); defining the number of training epochs nEpoch; The algorithm equation of the LSTM model is as follows: f t =σ(W f ·[h t-1 ,x t ]+b f ) Among them, f t represents the activation vector of the forget gate, σ is the sigmoid function, W f is the weight matrix of the forget gate, h t-1 is the hidden state of the previous time step, x t is the input of the current time step, b f is the bias term of the forget gate; i t =σ(W i ·[h t-1 ,x t ]+b i ) Among them, i t represents the activation vector of the input gate, is the candidate cell state, which represents the amount of new information added to the cell state through the input gate; Among them, C t and C t-1 Represents the cell state of the current time step and the previous time step, * represents element-by-element multiplication; about t =σ(W0 [h t-1 ,x t ]+b0) h t =o t *tanh(c t ) Among them, t represents the activation vector of the output gate, h t is the hidden state or output at the current time step; In step S4, an attention mechanism is added after the LSTM model. The specific implementation includes: Attention weight calculation: For the output h of the LSTM model at each time step t t , based on the hidden layer state d at the previous time step t-1 t-1 and the memory cell state c t-1 , through a trainable feedforward network f(h t ) Calculate the attention score e t , e t Indicates the importance of time step t to the current TP prediction, and the calculation formula is as follows: e t =f(h t ,d t-1 ,c t-1 ) Then, the attention score e is converted into t Normalize and generate attention weight α t , so that the sum of the weights of all time steps is 1, and the calculation formula of the attention weight is: a t =softmax(e t ) Among them, h t is the output of the LSTM model at time step t, d t-1 is the hidden layer state of the previous time step, c t-1 is the memory cell state at the previous time step, and f is a trainable feedforward network; Weighted sum: Use the calculated attention weight α t The output h of LSTM at each time step t Perform weighted summation to obtain a context vector It represents the comprehensive consideration of all historical time step information at the current moment, and the calculation formula is as follows: Prediction of the output layer: The context vector Input to the final output layer to predict TP concentration and flux; the output layer contains one or more fully connected layers, which is responsible for converting the context vector Mapped to the target variable space to generate the final prediction result.

2. According to claim 1, a large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism is characterized in that: The pre-processing method in step S2 includes: A1: Delete duplicate time series data, erroneous records and outliers; A2: Perform data standardization; A3: Transpose and reshape the time data to obtain three-dimensional time series data. The three dimensions are the number of watersheds, the number of time steps, and the variable characteristics and attributes corresponding to each time step.

3. A large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism according to claim 2, characterized in that: The data standardization process in step A2 is specifically as follows: The data is Z-score standardized to convert the data into a distribution with a mean of 0 and a standard deviation of 1, and to ensure that the data has a similar scale and distribution. The calculation formula is as follows: Among them, x is the original data, μ is the average value of the original data, σ x is the standard deviation of the original data, and x′ is the normalized data.

4. According to claim 1, a large-scale watershed total phosphorus simulation method based on deep learning and attention mechanism is characterized in that: The method for model evaluation in step S4 is: The input feature data and watershed feature attributes are passed to the trained LSTM model for forward propagation to obtain the model's prediction results. The model is evaluated based on the prediction results. The evaluation formula is as follows: Among them, Pbias represents the percentage bias, NSE represents the Nash efficiency coefficient, RMSE represents the root mean square error, Pcorr represents the Pearson correlation coefficient, and y mod Represents the predicted value of the model, y obs represents the observed value of the model, and n represents the total number of paired predictions and observations during model testing.

Citation Information

Patent Citations

  • Modeling method for prediction model of dissolved gas concentration in transformer oil

    CN112734028A

  • Method for predicting and simulating total phosphorus concentration of river water body

    CN112784395A

Cited By

  • Nitrogen and phosphorus non-point source pollution key source region identification method based on weighted feature importance

    CN120951065A

  • Method for identifying key source area of nitrogen and phosphorus non-point source pollution based on weighted feature importance

    CN120951065B