Runoff prediction method based on time sequence memory state focusing
By constructing a time-series memory state focusing model, using LSTM units and multi-head attention mechanisms, we solve the limitations of existing deep learning runoff prediction methods in multi-step ahead and time series utilization, and achieve high-precision runoff prediction, suitable for different times. scale.
Patent Information
- Application Number
- CN202410706716.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-03
- Publication Date
- 2024-08-23
AI Technical Summary
Existing runoff prediction methods based on deep learning, especially LSTM and Transformer models, each have their own limitations, making it difficult to achieve optimal results in multi-step advance runoff prediction and time series information utilization, resulting in insufficient prediction accuracy.
Using a method based on temporal memory state focusing, by building a model composed of an encoder, a state focusing module and an output transformation layer, the LSTM unit is used for time series encoding, and a multi-head attention mechanism is used to achieve state focusing, simplifying the model structure to adapt to single step ahead prediction.
It significantly improves the accuracy of runoff prediction, is suitable for short-term, medium- and long-term predictions, reduces the dependence on hydrophysical mechanisms, and expands the applicable scope of the model.
Smart Images

Figure CN118536397A
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of machine learning technology, and in particular to a runoff prediction method based on temporal memory state focusing. Background Art
[0002] Runoff prediction is one of the important tasks in hydrology. This technology uses meteorological data such as rainfall and static properties to predict runoff values, which is the key to water resources planning and flood control. Due to the uncertainty of meteorological data, terrain characteristics, human activities, climate change and other factors, the hydrological process is highly nonlinear and complex, and it is difficult to obtain accurate results for runoff prediction. At present, runoff prediction models can be roughly divided into two categories, namely process-driven models and data-driven models. In recent years, with the rapid development of deep learning technology, data-driven runoff prediction methods based on deep learning have attracted much attention. Specifically, the runoff prediction method based on the LSTM (Long Short-Term Memory) model and the runoff prediction method based on the Transformer model have achieved better results in prediction accuracy than the process-driven model.
[0003] However, these two data-driven runoff prediction methods based on deep learning have their own advantages and disadvantages. For multi-step ahead runoff prediction, the LSTM model has the problem of error accumulation due to its autoregressive structure. The non-autoregressive decoder based on the Transformer model can avoid this problem. Therefore, the runoff prediction method based on the Transformer model is more suitable for multi-step runoff prediction than the runoff prediction method based on the LSTM model. In addition, the runoff prediction method based on the Transformer model can connect any two time points, so it is more flexible than the runoff prediction method based on the LSTM model. However, since the Transformer model uses a position embedding method to identify different positions (i.e., time points), if the two positions are interchanged, the result will not change. Therefore, the runoff prediction method based on the Transformer model cannot make good use of time series information. The LSTM model naturally encodes time series information, but cannot directly connect two arbitrary time points, which is not flexible enough. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a runoff prediction method based on temporal memory state focusing, which can perform short-term runoff prediction or medium- and long-term runoff prediction according to actual needs, thereby greatly improving the runoff prediction accuracy.
[0005] To solve the above-mentioned technical problems, an embodiment of the present application provides a runoff prediction method based on temporal memory state focusing, comprising the following steps: generating an original data set based on the collected runoff data in the target watershed and the meteorological data corresponding to the time; preprocessing the original data set, dividing it into three time-exclusive parts: a training set, a validation set and a test set according to time; wherein the preprocessing includes outlier processing, null value processing, data selection, standardization and data serialization; constructing a temporal memory state focusing model; wherein the temporal memory state focusing model is composed of an encoder, a state focusing module and an output transformation layer, wherein the encoder is composed of several LSTM units, and the encoder is used to model the temporal relationship between the input data, and the state focusing module is based on a multi-head attention mechanism , connect the output state of the last LSTM unit with the output state of each LSTM unit in the previous order, calculate the attention score, assign weights to each output state according to the attention score, and realize state focusing. The higher the attention score, the greater the assigned weight; the output transformation layer is used to convert the output of the state focusing module into a runoff prediction result; based on the training set, the verification set and the test set, perform multiple iterations of training on the temporal memory state focusing model until convergence to obtain a trained temporal memory state focusing model; input the runoff data in the watershed to be predicted and the meteorological data corresponding to the time into the trained temporal memory state focusing model to obtain the runoff prediction result corresponding to the watershed to be predicted output by the trained temporal memory state focusing model.
[0006] The embodiment of the present application also provides a runoff prediction system based on temporal memory state focusing, including: a data preparation module, used to collect runoff data in a target watershed and meteorological data corresponding to the time, and generate an original data set based on the collected runoff data in the target watershed and meteorological data corresponding to the time; a preprocessing module, used to preprocess the original data set, and divide it into three time-exclusive parts: a training set, a validation set, and a test set according to time, wherein the preprocessing includes outlier processing, null value processing, data selection, standardization, and data serialization; a model construction module, used to construct a temporal memory state focusing model; wherein the temporal memory state focusing model is composed of an encoder, a state focusing module, and an output transformation layer, wherein the encoder is composed of a plurality of LSTM units, wherein the encoder is used to model the temporal relationship between input data, and the state focusing module is based on In the multi-head attention mechanism, the output state of the last LSTM unit is connected with the output state of each LSTM unit in the previous order, the attention score is calculated, and a weight is assigned to each output state according to the attention score to achieve state focusing. The higher the attention score, the greater the weight assigned. The output transformation layer is used to convert the output of the state focusing module into a runoff prediction result; the model training module is used to perform multiple iterative training on the temporal memory state focusing model based on the training set, the verification set and the test set until convergence, so as to obtain a trained temporal memory state focusing model; the model use module is used to input the runoff data in the watershed to be predicted and the meteorological data corresponding to the time into the trained temporal memory state focusing model, so as to obtain the runoff prediction result corresponding to the watershed to be predicted output by the trained temporal memory state focusing model.
[0007] An embodiment of the present application also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned runoff prediction method based on temporal memory state focusing.
[0008] An embodiment of the present application further provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the runoff prediction method based on temporal memory state focusing is implemented.
[0009] The embodiment of the present application provides a runoff prediction method based on temporal memory state focusing. Aiming at the problem of insufficient prediction accuracy caused by the defects of the runoff prediction method based on the LSTM model and the runoff prediction method based on the Transformer model, a temporal memory state focusing model is constructed, trained and used for runoff prediction. First, the model uses LSTM units to form an encoder, so that time series information can be encoded and the time pattern of the input data can be captured. Secondly, the entire model uses only one encoder, and meteorological data and runoff data are simultaneously fed into the encoder as input. This setting simplifies the model structure and is more suitable for single-step advance runoff prediction. Finally, the model introduces a state focusing module, so that the output state of the last LSTM unit is directly connected to the output state of other LSTM units, and the output state of the key points is focused with a large weight to obtain better prediction accuracy. The model can perform short-term runoff prediction (such as daily scale) or medium- and long-term runoff prediction (such as ten-day scale, monthly scale) according to actual needs, greatly improving the runoff prediction accuracy, and reducing the dependence on hydrological and physical mechanisms in short-term runoff prediction, effectively expanding the scope of application of the model.
[0010] In some optional embodiments, the LSTM unit is composed of a memory unit and a gating unit. The LSTM unit uses the memory unit to store and transfer information and uses the gating unit to control the flow of information. The gating unit includes an input gate, a forget gate and an output gate. The input gate is used to control whether information is added to the memory unit, the forget gate is used to control whether information is deleted from the memory unit, and the output gate is used to control the output of information from the memory unit. The forward propagation of the LSTM unit is expressed by the following formula:
[0011]
[0012]
[0013]
[0014]
[0015]
[0016] in, express function, represents the hyperbolic tangent function, represents the Hadamard product, express The input gate of the time step, express The forget gate of the time step, express The latent cell state at time step, express The cell state at the time step, express The output gate of the time step, express The hidden state at the time step, Represents the input of the LSTM unit at the current moment, that is, The input of the time step, , , , , , , , , , , and Both represent learnable parameters.
[0017] In some optional embodiments, the encoder is provided with a total of LSTM units, the input of the encoder is a meteorological data sequence and a runoff data sequence, and the sequence lengths of the meteorological data sequence and the runoff data sequence are both , the meteorological data series includes the past The meteorological data of the previous step and the predicted meteorological data of the next step, the runoff data series includes the past The runoff data of the step, is an integer greater than 0; the input of the encoder is expressed by the following formula:
[0018]
[0019]
[0020] in, represents a meteorological data series, represents the runoff data series, Represents the input of the encoder. Runoff prediction is related to people's production and life, and provides a large amount of key data for flood control and disaster reduction and even national defense and military. Therefore, it needs to be kept confidential. When setting the input of the encoder, the meteorological data remains unchanged, and the runoff data is moved back one step in time. This can well prevent information leakage and protect people's lives and property.
[0021] In some optional embodiments, the state focusing module is based on a multi-head attention mechanism, connects the output state of the last LSTM unit with the output state of each preceding LSTM unit, calculates an attention score, and assigns a weight to each output state according to the attention score to achieve state focusing, which is achieved by the following formula:
[0022]
[0023]
[0024]
[0025]
[0026] in, represents the output state of the last LSTM unit, represents the output state of each LSTM unit in the preceding sequence, represents the query vector, represents the key vector, represents the value corresponding to the key vector, express The dimension in the latent space, represents the softmax operation, Indicates the total number of parallel operations. Indicates parallel outputs, Represents a splicing operation, represents the output of the state focusing module, and All represent learnable parameter matrices. This application introduces multiple dimensions for parallel state focusing, and each dimension learns a focusing method in parallel. This setting enables the state focusing operation to achieve better results, further improving the performance of the temporal memory state focusing model, thereby further improving the accuracy of runoff prediction.
[0027] In some optional embodiments, the output transformation layer is a fully connected layer, and the output of the state focusing module is converted into a runoff prediction result, including: concatenating the output of the state focusing module and the output of the last LSTM unit into an intermediate vector; converting the intermediate vector into a scalar, which is the runoff prediction result.
[0028] In some optional embodiments, the temporal memory state focusing model is iteratively trained for multiple times until convergence based on the training set, the validation set and the test set, and the result includes: inputting the training set into the temporal memory state focusing model, training the temporal memory state focusing model for multiple times, calculating the smoothed Nash efficiency coefficient loss using a forward propagation algorithm, and updating the model parameters of the temporal memory state focusing model using a back propagation algorithm based on the smoothed Nash efficiency coefficient loss; in each iteration, the Nash efficiency coefficient is used to measure the performance of the temporal memory state focusing model trained for the current number of iterations under the validation set, and after reaching a preset number of iterations, the temporal memory state focusing model with the best performance under the validation set is saved as the trained temporal memory state focusing model; inputting the test set into the trained temporal memory state focusing model to obtain the runoff prediction results corresponding to each test data in the test set, and evaluating the runoff prediction results corresponding to each test data in combination with the real runoff data. The Nash efficiency coefficient is very suitable for verifying the quality of the simulation results of the hydrological model. This application uses the smoothed Nash efficiency coefficient loss as the loss function in the iterative training process, and uses the Nash efficiency coefficient in the verification process to measure the performance of the model under the verification set, which further improves the training effect of the temporal memory state focusing model and further improves the accuracy of runoff prediction.
[0029] In some optional embodiments, the calculation of the smoothed Nash efficiency coefficient loss is implemented by the following formula:
[0030] in, Indicates the total number of batches, Indicates The total number of samples in a batch, Indicates that for The first sample in a small batch The runoff prediction results of samples are Indicates The first sample in a small batch The real runoff data of samples, Indicates The standard deviation of the true runoff data for all samples in the batch, Indicates a preset extremely small integer to prevent the denominator from being 0; The calculation formula of the Nash efficiency coefficient is as follows:
[0031] in, Represents the mean of the true runoff data of all samples in the validation set. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] One or more embodiments are exemplarily described by the pictures in the corresponding drawings, and these exemplary descriptions do not constitute limitations on the embodiments.
[0033] Figure 1 It is a flowchart of a runoff prediction method based on temporal memory state focusing provided in one embodiment of the present application; Figure 2 It is a flowchart provided in one embodiment of the present application, which performs multiple iterative training on the temporal memory state focusing model until convergence based on the training set, the validation set and the test set to obtain the trained temporal memory state focusing model; Figure 3 It is a structural schematic diagram of a runoff prediction system based on temporal memory state focusing provided in another embodiment of the present application; Figure 4 It is a schematic diagram of the structure of an electronic device provided by another embodiment of the present application. DETAILED DESCRIPTION
[0034] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the present application, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can also be implemented. The division of the following embodiments is for the convenience of description, and the specific implementation of the present application should not be construed as any limitation, and the various embodiments can be combined and referenced with each other under the premise of no contradiction.
[0035] An embodiment of the present application proposes a runoff prediction method based on temporal memory state focusing, which is applied to an electronic device, wherein the electronic device can be a terminal or a server. In this embodiment and the following embodiments, the electronic device is described by taking the server as an example. The implementation details of the runoff prediction method based on temporal memory state focusing proposed in this embodiment are described in detail below. The following content is only the implementation details provided for the convenience of understanding and is not necessary for the implementation of this solution.
[0036] The specific process of the runoff prediction method based on temporal memory state focusing proposed in this embodiment can be as follows: Figure 1 As shown, including: Step 101, generating an original data set based on the collected runoff data in the target watershed and the meteorological data corresponding to the time.
[0037] In the specific implementation, the server first prepares the data, collects the runoff data of each station in the target watershed, and the runoff-related meteorological data corresponding to the time of these runoff data, and generates the original data set based on the collected runoff data in the target watershed and the meteorological data corresponding to the time.
[0038] Step 102, preprocessing the original data set, and dividing it into three mutually exclusive parts according to time: a training set, a validation set, and a test set.
[0039] In a specific implementation, after generating the original data set, the server can perform preprocessing on the original data, including outlier processing, null value processing, data selection, standardization, and data serialization, and divide the data set obtained after preprocessing into three mutually exclusive parts: training set, validation set, and test set. Among them, the data selection process is the process of removing sites with too much missing data, and the training set, validation set, and test set are mutually exclusive in time, that is, the data in the training set, validation set, and test set belong to different time periods.
[0040] Step 103, construct a temporal memory state focusing model, wherein the temporal memory state focusing model is composed of an encoder, a state focusing module and an output transformation layer, and the encoder is composed of several LSTM units.
[0041] In a specific implementation, after dividing the data into training set, validation set and test set, the server can construct a temporal memory state focusing model, which consists of three parts: an encoder, a state focusing module and an output transformation layer, and the encoder consists of several LSTM units.
[0042] In a specific implementation, the encoder is used to model the temporal relationship between input data.
[0043] In the specific implementation, the state focusing module is used to connect the output state of the last LSTM unit with the output state of each previous LSTM unit based on the multi-head attention mechanism, calculate the attention score, and assign weights to each output state according to the attention score to achieve state focusing. Among them, the output state with a higher attention score has a greater weight assigned to it.
[0044] In the specific implementation, the output transformation layer is used to convert the output of the state focusing module into the runoff prediction result.
[0045] In an example, an LSTM unit is composed of a memory unit and a gating unit. The LSTM unit uses the memory unit to store and transmit information and uses the gating unit to control the flow of information. The gating unit includes an input gate, a forget gate, and an output gate. The input gate is used to control whether information is added to the memory unit, the forget gate is used to control whether information is deleted from the memory unit, and the output gate is used to control the output of information from the memory unit.
[0046] In an example, the forward propagation of an LSTM unit can be expressed by the following formula:
[0047]
[0048]
[0049]
[0050]
[0051]
[0052] In the formula, express function, represents the hyperbolic tangent function, represents the Hadamard product, express The input gate of the time step, express The forget gate of the time step, express The latent cell state at time step, express The cell state at the time step, express The output gate of the time step, express The hidden state at the time step, Represents the input of the LSTM unit at the current moment, that is The input of the time step, , , , , , , , , , , and Both represent learnable parameters. It is understandable that when the model parameters are updated, , , , , , , , , , , and Will participate in the update.
[0053] In one example, the encoder is set to have a total of LSTM units, the encoder input is the meteorological data sequence and the runoff data sequence, the sequence length of the meteorological data sequence and the runoff data sequence are , the meteorological data series includes the past The meteorological data of the previous step and the predicted meteorological data of the next step, and the runoff data series include the past The runoff data of the step. is an integer greater than 0. The input of the encoder can be expressed by the following formula:
[0054]
[0055]
[0056] In the formula, represents a meteorological data series, represents the runoff data series, Represents the input of the encoder.
[0057] It is worth noting that runoff prediction is related to people’s production and life, and provides a large amount of key data for flood control and disaster reduction and even national defense and military. Therefore, a certain degree of confidentiality is required. When setting the input of the encoder, the meteorological data remains unchanged, and the runoff data is moved back one step in time. This can effectively prevent information leakage and protect people’s lives and property.
[0058] It is understandable that if there is no need to perform operations to prevent information leakage, the runoff data does not need to be moved back one step in time, and can be directly aligned with the meteorological data and input into the encoder.
[0059] In an example, the state focusing module is based on the multi-head attention mechanism. It connects the output state of the last LSTM unit with the output states of the previous LSTM units, calculates the attention score, and assigns weights to each output state according to the attention score to achieve state focusing. This can be achieved through the following formula:
[0060]
[0061]
[0062]
[0063]
[0064] In the formula, represents the output state of the last LSTM unit, Represents the output state of each LSTM unit in the previous order, represents the query vector, represents the key vector, represents the value corresponding to the key vector, express The dimension in the latent space, represents the softmax operation, Indicates the total number of parallel operations. Indicates parallel outputs, Represents a splicing operation, represents the output of the state focusing module, and Both represent learnable parameter matrices. When the model parameters are updated, and Will participate in the update.
[0065] It is worth noting that this embodiment introduces multiple dimensions for parallel state focusing, and each dimension learns a focusing method in parallel. This setting enables the state focusing operation to achieve better results, further improves the performance of the temporal memory state focusing model, and thus further improves the accuracy of runoff prediction.
[0066] In one example, the output transformation layer is a fully connected layer. When the output transformation layer converts the output of the state focusing module into a runoff prediction result, it first concatenates the output of the state focusing module and the output of the last LSTM unit into an intermediate vector, and then converts the intermediate vector into a scalar, which saves the runoff prediction result.
[0067] Step 104, based on the training set, the validation set and the test set, the temporal memory state focusing model is iteratively trained multiple times until convergence, to obtain a trained temporal memory state focusing model.
[0068] In a specific implementation, after the server builds the initial temporal memory state focusing model, it can perform multiple iterative training on the temporal memory state focusing model based on the training set, the validation set, and the test set until convergence to obtain a trained temporal memory state focusing model.
[0069] In one example, the server performs multiple iterations of training on the temporal memory state focusing model based on the training set, the validation set, and the test set until convergence, and obtains the trained temporal memory state focusing model, which can be obtained by Figure 2 The steps shown are implemented, specifically including: Step 1041, input the training set into the temporal memory state focusing model, perform multiple iterative training on the temporal memory state focusing model, calculate the smoothed Nash efficiency coefficient loss using the forward propagation algorithm, and based on the smoothed Nash efficiency coefficient loss, use the back propagation algorithm to update the model parameters of the temporal memory state focusing model.
[0070] In the specific implementation, after constructing the initial temporal memory state focusing model, the server can input the training set into the temporal memory state focusing model, perform multiple iterative training on the temporal memory state focusing model, calculate the smoothed Nash efficiency coefficient loss using the forward propagation algorithm, and based on the smoothed Nash efficiency coefficient loss, use the back propagation algorithm to update the model parameters of the temporal memory state focusing model.
[0071] In one example, the server calculates the smoothed Nash efficiency coefficient loss, which can be implemented by the following formula:
[0072] In the formula, Indicates the total number of batches, Indicates The total number of samples in a batch, Indicates that for The first batch of samples in the The runoff prediction results of samples are Indicates The first sample in a small batch The real runoff data of samples, Indicates The standard deviation of the true runoff data for all samples in the batch, Indicates a preset extremely small integer to prevent the denominator from being 0.
[0073] Step 1042, in each iteration, the Nash efficiency coefficient is used to measure the performance of the temporal memory state focusing model after training for the current number of iterations under the verification set. After reaching the preset number of iterations, the temporal memory state focusing model with the best performance under the verification set is saved as the trained temporal memory state focusing model.
[0074] In the specific implementation, the server uses the Nash efficiency coefficient to measure the performance of the time-series memory state focusing model trained for the current number of iterations under the validation set in each iteration. After reaching the preset number of iterations, the training is stopped, and the time-series memory state focusing model with the best performance under the validation set is saved, that is, the model with the largest Nash efficiency coefficient under the validation set, as the trained time-series memory state focusing model. The Nash efficiency coefficient is very suitable for verifying the quality of the hydrological model simulation results. This application uses the smoothed Nash efficiency coefficient loss as the loss function during the iterative training process, and uses the Nash efficiency coefficient to measure the performance of the model under the validation set during the verification process, which further improves the training effect of the time-series memory state focusing model and further improves the accuracy of runoff prediction.
[0075] In an example, the Nash efficiency coefficient is calculated as follows:
[0076] In the formula, Represents the mean of the true runoff data for all samples in the validation set.
[0077] Step 1043, input the test set into the trained temporal memory state focusing model to obtain the runoff prediction result corresponding to each test data in the test set, and evaluate the runoff prediction result corresponding to each test data in combination with the real runoff data.
[0078] In the specific implementation, after obtaining the trained temporal memory state focusing model, the server can also input the data in the test set into the trained temporal memory state focusing model to obtain the runoff prediction results corresponding to each test data in the test set, and evaluate the runoff prediction results corresponding to each test data in combination with the actual runoff data to obtain various evaluation indicators for further improving the model.
[0079] Step 105, input the runoff data in the to-be-predicted watershed and the meteorological data corresponding to the time into the trained temporal memory state focusing model, and obtain the runoff prediction result corresponding to the to-be-predicted watershed output by the trained temporal memory state focusing model.
[0080] In a specific implementation, after obtaining the trained temporal memory state focusing model, the server can input the runoff data in the basin to be predicted and the meteorological data corresponding to the time into the trained temporal memory state focusing model to obtain the runoff prediction result corresponding to the basin to be predicted output by the trained temporal memory state focusing model.
[0081] In this embodiment, in view of the problem of insufficient prediction accuracy caused by the defects of the runoff prediction method based on the LSTM model and the runoff prediction method based on the Transformer model, a temporal memory state focusing model is constructed, trained and used for runoff prediction. First, the model uses LSTM units to form an encoder, so that time series information can be encoded and the time pattern of the input data can be captured. Secondly, the entire model uses only one encoder, and meteorological data and runoff data are simultaneously fed into the encoder as input. This setting simplifies the model structure and is more suitable for single-step advance runoff prediction. Finally, the model introduces a state focusing module, so that the output state of the last LSTM unit is directly connected to the output state of other LSTM units, and the output state of the key points is focused with a large weight to obtain better prediction accuracy. The model can perform short-term runoff prediction (such as daily scale) or medium- and long-term runoff prediction (such as ten-day scale, monthly scale) according to actual needs, greatly improving the runoff prediction accuracy, and reducing the dependence on hydrological and physical mechanisms in short-term runoff prediction, effectively expanding the scope of application of the model.
[0082] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0083] Another embodiment of the present application proposes a runoff prediction system based on temporal memory state focusing. The implementation details of the runoff prediction system based on temporal memory state focusing proposed in this embodiment are specifically described below. The following content is only for the convenience of understanding the implementation details provided, and is not necessary for the implementation of this solution. The schematic diagram of the runoff prediction system based on temporal memory state focusing proposed in this embodiment can be shown as follows Figure 3 As shown, including: The data preparation module 201 is used to collect the runoff data in the target watershed and the meteorological data corresponding to the time, and generate an original data set according to the collected runoff data in the target watershed and the meteorological data corresponding to the time.
[0084] The preprocessing module 202 is used to preprocess the original data set and divide it into three mutually exclusive parts: a training set, a validation set and a test set according to time. The preprocessing includes outlier processing, null value processing, data selection, standardization and data serialization.
[0085] The model building module 203 is used to build a temporal memory state focusing model; wherein the temporal memory state focusing model is composed of an encoder, a state focusing module and an output transformation layer, the encoder is composed of a plurality of LSTM units, the encoder is used to model the temporal relationship between the input data, the state focusing module is based on a multi-head attention mechanism, connects the output state of the last LSTM unit with the output state of each preceding LSTM unit, calculates the attention score, and assigns weights to each output state according to the attention score to achieve state focusing, the higher the attention score, the greater the assigned weight, and the output transformation layer is used to convert the output of the state focusing module into a runoff prediction result.
[0086] The model training module 204 is used to perform multiple iterative training on the temporal memory state focusing model based on the training set, the validation set and the test set until convergence, so as to obtain a trained temporal memory state focusing model.
[0087] The model usage module 205 is used to input the runoff data in the to-be-predicted watershed and the meteorological data corresponding to the time into the trained temporal memory state focusing model, and obtain the runoff prediction result corresponding to the to-be-predicted watershed output by the trained temporal memory state focusing model.
[0088] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of this application, this embodiment does not introduce units that are not closely related to solving the technical problems proposed by this application, but this does not mean that there are no other units in this embodiment.
[0089] Another embodiment of the present application relates to an electronic device, such as Figure 4 As shown, it includes: at least one processor 301; and a memory 302 that is communicatively connected to the at least one processor 301; wherein the memory 302 stores instructions that can be executed by the at least one processor 301, and the instructions are executed by the at least one processor 301 so that the at least one processor 301 can execute a runoff prediction method based on temporal memory state focusing described in the above embodiments.
[0090] Among them, the memory and the processor are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors and memories together. The bus can also connect various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor.
[0091] The processor is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory can be used to store data used by the processor when performing operations.
[0092] Another embodiment of the present application relates to a computer-readable storage medium storing a computer program, which implements the above method embodiment when executed by a processor.
[0093] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as: ROM), random access memory (Random Access Memory, referred to as: RAM), disk or optical disk and other media that can store program codes.
[0094] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present application, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present application.
Claims
1. A runoff prediction method based on temporal memory state focusing, characterized in that: include: Generate an original data set based on the collected runoff data in the target watershed and the corresponding meteorological data at that time; Preprocessing the original data set, dividing it into three mutually exclusive parts: a training set, a validation set, and a test set according to time; wherein the preprocessing includes outlier processing, null value processing, data selection, standardization, and data serialization; Construct a temporal memory state focusing model; wherein the temporal memory state focusing model is composed of an encoder, a state focusing module and an output transformation layer, the encoder is composed of a plurality of LSTM units, the encoder is used to model the temporal relationship between input data, the state focusing module is based on a multi-head attention mechanism, connects the output state of the last LSTM unit with the output state of each preceding LSTM unit, calculates the attention score, and assigns a weight to each output state according to the attention score to achieve state focusing, the higher the attention score, the greater the assigned weight, and the output transformation layer is used to convert the output of the state focusing module into a runoff prediction result; Based on the training set, the validation set and the test set, the temporal memory state focusing model is iteratively trained for multiple times until convergence, so as to obtain a trained temporal memory state focusing model; The runoff data in the watershed to be predicted and the meteorological data corresponding to the time are input into the trained temporal memory state focusing model to obtain the runoff prediction result corresponding to the watershed to be predicted output by the trained temporal memory state focusing model.
2. A method for runoff prediction based on temporal memory state focusing according to claim 1, characterized in that: The LSTM unit is composed of a memory unit and a gating unit. The LSTM unit uses the memory unit to store and transfer information and uses the gating unit to control the flow of information. The gating unit includes an input gate, a forget gate and an output gate. The input gate is used to control whether to add information to the memory unit, the forget gate is used to control whether to delete information from the memory unit, and the output gate is used to control the output of information from the memory unit. The forward propagation of the LSTM unit is expressed by the following formula: in, express function, represents the hyperbolic tangent function, represents the Hadamard product, express The input gate of the time step, express The forget gate of the time step, express The latent cell state at time step, express The cell state at the time step, express The output gate of the time step, express The hidden state at the time step, Represents the input of the LSTM unit at the current moment, that is, The input of the time step, , , , , , , , , , , and Both represent learnable parameters.
3. The method for runoff prediction based on temporal memory state focusing according to claim 1 is characterized in that: The encoder is provided with a total of LSTM units, the input of the encoder is a meteorological data sequence and a runoff data sequence, and the sequence lengths of the meteorological data sequence and the runoff data sequence are both , the meteorological data series includes the past The meteorological data of the previous step and the predicted meteorological data of the next step, the runoff data series includes the past The runoff data of the step, is an integer greater than 0; The input of the encoder is expressed by the following formula: in, represents a meteorological data series, represents the runoff data series, Represents the input of the encoder.
4. A method for runoff prediction based on temporal memory state focusing according to claim 3, characterized in that: The state focusing module is based on a multi-head attention mechanism, which connects the output state of the last LSTM unit with the output state of each preceding LSTM unit, calculates the attention score, and assigns a weight to each output state according to the attention score to achieve state focusing, which is achieved by the following formula: in, represents the output state of the last LSTM unit, represents the output state of each LSTM unit in the preceding sequence, represents the query vector, represents the key vector, represents the value corresponding to the key vector, express The dimension in the latent space, represents the softmax operation, Indicates the total number of parallel operations. Indicates parallel outputs, Represents a splicing operation, represents the output of the state focusing module, and Both represent learnable parameter matrices.
5. A runoff prediction method based on temporal memory state focusing according to any one of claims 1 to 4, characterized in that: The output transformation layer is a fully connected layer, which converts the output of the state focusing module into a runoff prediction result, including: Concatenate the output of the state focusing module and the output of the last LSTM unit into an intermediate vector; The intermediate vector is converted into a scalar, which is the runoff prediction result.
6. A runoff prediction method based on temporal memory state focusing according to any one of claims 1 to 4, characterized in that: The temporal memory state focusing model is iteratively trained multiple times until convergence based on the training set, the validation set and the test set, to obtain: Inputting the training set into the temporal memory state focusing model, performing multiple iterative training on the temporal memory state focusing model, calculating the smoothed Nash efficiency coefficient loss using a forward propagation algorithm, and updating the model parameters of the temporal memory state focusing model using a back propagation algorithm based on the smoothed Nash efficiency coefficient loss; In each iteration, the Nash efficiency coefficient is used to measure the performance of the temporal memory state focusing model trained with the current number of iterations under the verification set. After reaching the preset number of iterations, the temporal memory state focusing model with the best performance under the verification set is saved as the temporal memory state focusing model that has completed training; The test set is input into the trained temporal memory state focusing model to obtain the runoff prediction results corresponding to each test data in the test set, and the runoff prediction results corresponding to each test data are evaluated in combination with the real runoff data.
7. A method for runoff prediction based on temporal memory state focusing according to claim 6, characterized in that: The calculation of the smoothed Nash efficiency coefficient loss is achieved by the following formula: in, Indicates the total number of batches, Indicates The total number of samples in a batch, Indicates that for The first batch of samples in the The runoff prediction results of samples are Indicates The first batch of samples in the The real runoff data of samples, Indicates The standard deviation of the true runoff data for all samples in the batch, Indicates a preset extremely small integer to prevent the denominator from being 0; The calculation formula of the Nash efficiency coefficient is as follows: in, Represents the mean of the true runoff data of all samples in the validation set.
8. A runoff prediction system based on temporal memory state focusing, characterized in that: include: A data preparation module is used to collect runoff data in the target watershed and meteorological data corresponding to the time, and generate an original data set based on the collected runoff data in the target watershed and meteorological data corresponding to the time; A preprocessing module is used to preprocess the original data set and divide it into three mutually exclusive parts: a training set, a validation set and a test set according to time. The preprocessing includes outlier processing, null value processing, data selection, standardization and data serialization; A model building module, used to build a temporal memory state focusing model; wherein the temporal memory state focusing model is composed of an encoder, a state focusing module and an output transformation layer, the encoder is composed of a plurality of LSTM units, the encoder is used to model the temporal relationship between input data, the state focusing module is based on a multi-head attention mechanism, connects the output state of the last LSTM unit with the output state of each preceding LSTM unit, calculates the attention score, and assigns a weight to each output state according to the attention score to achieve state focusing, the higher the attention score, the greater the assigned weight, and the output transformation layer is used to convert the output of the state focusing module into a runoff prediction result; A model training module, used to perform multiple iterative training on the temporal memory state focusing model based on the training set, the validation set and the test set until convergence, so as to obtain a trained temporal memory state focusing model; The model usage module is used to input the runoff data in the watershed to be predicted and the meteorological data corresponding to the time into the trained temporal memory state focusing model, and obtain the runoff prediction result corresponding to the watershed to be predicted output by the trained temporal memory state focusing model.
9. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a runoff prediction method based on temporal memory state focusing as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, a runoff prediction method based on temporal memory state focusing as described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Clustering short-term runoff prediction method based on encoder-decoder and attention mechanism
CN120670882A
