Water quality prediction method, device, equipment and medium based on deep learning
By improving the Transformer model, the dependency, time and position characteristics in river water quality prediction are extracted, and the water quality prediction results are generated by combining the encoder and decoder, which solves the shortcomings of traditional methods in prediction accuracy and spatiotemporal scale processing, and improves the water quality prediction. Accuracy and reliability.
Patent Information
- Application Number
- CN202411162757.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-08-23
AI Technical Summary
Traditional river water quality prediction methods have shortcomings in prediction accuracy, spatiotemporal scale processing and model generalization capabilities, making it difficult to effectively capture the impact of seasonal and geographical differences, and need to readjust parameters or remodel in the face of new environments or conditions. , affects the accuracy and reliability of predictions.
Using the target water quality prediction model based on improved Transformer, the long-sequence data is generated by obtaining the original data, the dependency matrix, the time feature matrix and the position feature matrix are extracted, and the feature fusion is performed to generate water quality prediction results, combining the time series embedding layer and encoding. The device and decoder perform encoding processing to improve the accuracy and reliability of water quality prediction.
It significantly improves the accuracy and reliability of water quality prediction, can better process multi-scale time series data, enhances the generalization ability of the model, is suitable for short-term and long-term prediction tasks, and reduces the cost of model training.
Smart Images

Figure CN118673467B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of water quality prediction, and in particular to a water quality prediction method, device, equipment and medium based on deep learning. Background Art
[0002] Water quality prediction can improve the efficiency of environmental protection and water resources management, reduce pollutant emissions, respond to water environment accidents, maintain ecological balance, ensure the safety of agricultural production and urban water supply, and provide support for scientific research and policy making.
[0003] Traditional methods for predicting river water quality mainly include models based on statistical models and models based on physical processes. Although these methods can predict water quality changes to a certain extent, they also have some shortcomings and limited prediction accuracy: because water quality is affected by many factors and is subject to randomness, traditional methods have limited accuracy in predicting water quality changes, especially long-term and cross-regional predictions. Insufficient spatiotemporal scale: Traditional methods sometimes have difficulty dealing with changes in water quality at different spatiotemporal scales, such as being unable to capture seasonal and geographical differences. Poor model generalization ability: Some traditional methods have poor generalization ability when faced with new environments or conditions, and require readjustment of parameters or remodeling. Therefore, it is necessary to continuously explore new methods and technologies to improve the accuracy and reliability of water quality predictions. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a water quality prediction method, device, equipment and medium based on deep learning, which can significantly improve the accuracy and reliability of water quality prediction.
[0005] In a first aspect, an embodiment of the present invention provides a water quality prediction method based on deep learning, comprising:
[0006] Obtaining the original data of the watershed covered by the section to be studied, and generating long sequence time series data based on the original data, wherein the long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution;
[0007] Through the target water quality prediction model based on the improved Transformer, the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data are extracted, and based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix, the water quality prediction result corresponding to the watershed covered by the section is generated.
[0008] In one embodiment, the raw data includes one or more of DEM data, initial river discharge outlet data, initial land cover type, river section monitoring data, initial climate data, initial hydrological data, initial evapotranspiration data, and initial river network data;
[0009] The long sequence time series data includes one or more of current section monitoring data, upstream section monitoring data, target river discharge outlet data, basin average slope data, target climate data, river network attribute data, basin land cover indicators, target hydrological data, and basin average rainfall data.
[0010] In one embodiment, a target water quality prediction model based on an improved Transformer includes a time series embedding layer, an encoder, and a decoder;
[0011] The steps of extracting a first dependency matrix, a time feature matrix and a position feature matrix of the long sequence time series data, and generating a water quality prediction result corresponding to the watershed covered by the section based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix, include:
[0012] Through the time series embedding layer, a first dependency matrix in the long sequence time series data is captured, and a time feature matrix and a position feature matrix of the long sequence time series data are extracted, and feature fusion is performed on the first dependency matrix, the time feature matrix and the position feature matrix to obtain a fusion result;
[0013] The fusion result is encoded and decoded by the encoder and the decoder to generate a water quality prediction result corresponding to the watershed covered by the section.
[0014] In one embodiment, the time series embedding layer includes a neighboring convolution unit, a time encoding unit, and a position encoding unit;
[0015] The steps of capturing a first dependency matrix in the long sequence time series data and extracting a time feature matrix and a position feature matrix of the long sequence time series data include:
[0016] By using the neighboring convolution unit, the long sequence time series data is convolved using convolution kernels of different sizes to capture a first dependency matrix in the long sequence time series data;
[0017] Decomposing the time information of the long sequence time series data into features in vector form by the time encoding unit, and generating a time feature matrix based on the features in vector form by using a convolutional neural network;
[0018] The position encoding unit performs sinusoidal wave position encoding on the long sequence time series data to extract the position feature matrix of the long sequence time series data.
[0019] In one embodiment, the encoder includes a plurality of first convolutional attention units and a downsampling layer, and the decoder includes a second convolutional attention unit, a multi-head attention unit, and a fully connected layer;
[0020] The step of encoding and decoding the fusion result to generate a water quality prediction result corresponding to the watershed covered by the section includes:
[0021] By using the first convolutional attention unit, non-important features in the fusion result are suppressed, and important features in the fusion result are extracted; by using the downsampling layer, the important features in the fusion result are downsampled to obtain encoding features;
[0022] Through the second convolutional attention unit, non-important features in the coding features are suppressed, and important features in the coding features are extracted; through the multi-head attention unit, the second dependency matrix of the important features in the coding features is captured; through the fully connected layer, the second dependency matrix is subjected to dimensionality reduction processing to obtain the water quality prediction result corresponding to the watershed covered by the section.
[0023] In one embodiment, the training step of the target water quality prediction model based on the improved Transformer includes:
[0024] Acquire training long sequence time series data, and construct a multi-task data set based on the training long sequence time series data, where the multi-task includes one or more of a multi-region water quality prediction task, a multi-water quality parameter prediction task, a multi-time scale prediction task, and a multi-feature learning task;
[0025] By improving the initial water quality prediction model of Transformer, water quality prediction is performed on the multi-task data set to generate a water quality prediction result corresponding to the multi-task data set;
[0026] A loss function is determined based on the water quality prediction results corresponding to the multi-task data set, and transfer learning is used to train and fine-tune the initial water quality prediction model of the improved Transformer based on the loss function to obtain a target water quality prediction model.
[0027] In one embodiment, the loss function includes multi-region water quality prediction task loss, multi-water quality parameter prediction task loss, multi-time scale prediction task loss, multi-feature learning task loss and a regularization term to balance the importance between different tasks.
[0028] In a second aspect, an embodiment of the present invention further provides a water quality prediction device based on deep learning, comprising:
[0029] A data generation module is used to obtain the original data of the section covering the watershed to be studied, and generate long sequence time series data based on the original data, wherein the long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution;
[0030] The water quality prediction module is used to extract the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data through a target water quality prediction model based on the improved Transformer, and generate the water quality prediction result corresponding to the watershed covered by the section based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix.
[0031] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement any one of the methods provided in the first aspect.
[0032] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement any one of the methods provided in the first aspect.
[0033] The embodiment of the present invention provides a water quality prediction method, device, equipment and medium based on deep learning. First, the original data of the section covering the basin to be studied is obtained, and then long sequence time series data is generated based on the original data. The long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution; finally, the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data are extracted through the target water quality prediction model based on the improved Transformer, and the water quality prediction result corresponding to the section covering the basin is generated based on the fusion result of the first dependency matrix, time feature matrix and position feature matrix. The above method combines the monitoring situation of the water quality section and the impact of water pollution, and uses the target water quality prediction model based on the improved Transformer to extract the dependency matrix, time feature matrix and position feature matrix of the data, and generates water quality prediction results on this basis, which can significantly improve the accuracy and reliability of water quality prediction.
[0034] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 A schematic diagram of a flow chart of a water quality prediction method based on deep learning provided in an embodiment of the present invention;
[0038] Figure 2 A schematic diagram of the structure of a target water quality prediction model provided by an embodiment of the present invention;
[0039] Figure 3 A schematic diagram of the structure of a water quality prediction device based on deep learning provided by an embodiment of the present invention;
[0040] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described in combination with the embodiments below. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] At present, the accuracy and reliability of traditional methods for predicting river water quality need to be improved. Based on this, the present invention implements a water quality prediction method, device, equipment and medium based on deep learning to improve the accuracy and reliability of water quality prediction.
[0043] To facilitate understanding of this embodiment, a water quality prediction method based on deep learning disclosed in an embodiment of the present invention is first described in detail. Figure 1 The flowchart of a water quality prediction method based on deep learning is shown, and the method mainly includes the following steps S102 to S104:
[0044] Step S102, obtaining the original data of the section covering the watershed to be studied, and generating long sequence time series data based on the original data.
[0045] In one example, the original data includes one or more of DEM data, initial river discharge outlet data, initial land cover type, river section monitoring data, initial climate data, initial hydrological data, initial evapotranspiration data, and initial river network data;
[0046] In one example, long sequence time series data is used to reflect the water quality section monitoring conditions and the impact of water pollution. Specifically, the long sequence time series data includes one or more of the current section monitoring data, upstream section monitoring data, target river discharge outlet data, basin average slope data, target climate data, river network attribute data, basin land cover indicators, target hydrological data, and basin average rainfall data.
[0047] Step S104, through the target water quality prediction model based on the improved Transformer, the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data are extracted, and based on the fusion results of the first dependency matrix, time feature matrix and position feature matrix, the water quality prediction result corresponding to the section coverage basin is generated.
[0048] In one example, the target water quality prediction model of the improved Transformer includes a time series embedding layer, an encoder and a decoder. The time series embedding layer is used to extract the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data, and perform feature fusion on the extracted matrices. The encoder and decoder are used to encode and decode the fusion results to generate water quality prediction results corresponding to the section coverage basin.
[0049] The above method provided by the embodiment of the present invention combines the water quality section monitoring situation and the impact of water pollution, and uses the target water quality prediction model based on the improved Transformer to extract the data dependency matrix, time feature matrix and location feature matrix, and generates water quality prediction results on this basis, which can significantly improve the accuracy and reliability of water quality prediction.
[0050] For ease of understanding, an embodiment of the present invention provides a specific implementation of a water quality prediction method based on deep learning.
[0051] The aforementioned step S102 includes two parts: data collection and data processing:
[0052] (I) Data collection: The collected raw data include section coverage basin DEM data, river discharge outlet data, land cover type, river section monitoring data, climate data, hydrological data, evapotranspiration data, river network data, etc.
[0053] (II) Data processing: By processing the collected raw data, we can obtain the current section monitoring data, upstream section monitoring data, target river discharge outlet data, basin average slope data, target climate data, river network attribute data, basin land cover index, target hydrological data, basin average rainfall data, etc. Specifically:
[0054] (1) The current section monitoring data mainly include: hydrology, pH, dissolved oxygen, total nitrogen and total phosphorus at the current section.
[0055] (2) The upstream section monitoring data mainly include: geographical location coordinates, elevation difference with the monitoring section, distance along the river from the monitoring section, and section monitoring data.
[0056] (3) Data of target sewage outlets into rivers:
[0057] (3.1) Geographic information: geographic location coordinates, elevation difference with the monitoring section, and distance along the river from the section;
[0058] (3.2) Types of sewage outlets: There are four types: industrial sewage outlets, urban sewage treatment plant outlets, agricultural outlets, and other outlets.
[0059] (3.3) Monitoring data: monitoring items (pH value at the sewage outlet, ammonia nitrogen, chemical oxygen demand, hydrology, total phosphorus, total nitrogen, flow), monitoring time, flow;
[0060] (3.4) Emissions: total daily emissions, total annual emissions;
[0061] (4) Average slope of the watershed: This indicator is used to measure the slope of the watershed. The calculation method is as follows:
[0062] (4.1) The watershed is divided into several small regions, each of which has an area and elevation.
[0063] (4.2) Calculate the slope of each area as the elevation difference divided by the area (in meters per square kilometer).
[0064] (4.3) Add the slopes of all areas and divide by the total number of areas to obtain the average slope of the basin.
[0065] (5) Target climate data (also called climate conditions) mainly include: daily maximum temperature, daily minimum temperature, and daily average temperature. A warm climate is conducive to microbial activity and can enhance the self-purification capacity of river water.
[0066] (6) River network attribute data mainly include: average depth, average width. Broad and deep rivers can provide larger dilution space and sedimentation area; river bottom and river bank characteristics. The material of the riverbed and river bank (such as sand, gravel, silt, etc.) will affect the adsorption and sedimentation of pollutants); water area.
[0067] (7) The land cover index of the watershed mainly includes: based on the land cover type data of the watershed, calculate the proportion of various major land features such as forest land, grassland, water area, building, open land, rocky mountain, glacier, desert, etc. The calculation formula is as follows:
[0068] ;
[0069] in For land features The proportion of the total basin area, For the basin's internal features Total area, is the total area of the basin.
[0070] (8) Target hydrological data mainly include: location coordinates of hydrological stations, flow velocity and flow rate.
[0071] (9) The average rainfall in a river basin mainly includes hourly average rainfall, daily average rainfall and monthly average rainfall.
[0072] For the aforementioned step S104, the embodiment of the present invention first explains the target water quality prediction model of the improved Transformer. A water quality prediction model is constructed based on Transformer, which can process multi-scale time series data and has good prediction performance. It performs well in both short-term and long-term prediction tasks, but its quadratic time complexity, high memory usage, and inherent limitations of the encoder-decoder architecture make it not directly applicable to the long-short-term prediction (LSTF) problem. The embodiment of the present invention improves the problems existing in Transformer and constructs a water quality prediction model based on Transformer for water quality prediction.
[0073] For details, see Figure 2 A structural schematic diagram of a target water quality prediction model is shown. The target water quality prediction model based on the improved Transformer includes a time series embedding layer, an encoder and a decoder. The time series embedding layer includes a neighboring convolution unit, a time encoding unit and a position encoding unit. The encoder includes multiple first convolutional attention units and a downsampling layer. The decoder includes a second convolutional attention unit, a multi-head attention unit and a fully connected layer.
[0074] On this basis, the embodiment of the present invention provides a specific implementation method of extracting the first dependency matrix, time feature matrix and position feature matrix of long sequence time series data through the target water quality prediction model, and generating the water quality prediction result corresponding to the section coverage basin based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix, see the following steps 1 to 2:
[0075] Step 1: Capture the first dependency matrix in the long sequence time series data through the time series embedding layer, extract the time feature matrix and position feature matrix of the long sequence time series data, and perform feature fusion on the first dependency matrix, the time feature matrix and the position feature matrix to obtain the fusion result.
[0076] In the specific implementation, the convolution processing can be performed on the long sequence time series data through the neighboring convolution unit using convolution kernels of different sizes to capture the first dependency matrix in the long sequence time series data; and the time information of the long sequence time series data can be decomposed into features in the form of vectors through the time coding unit, and the time feature matrix can be generated based on the features in the form of vectors using the convolution neural network; and the long sequence time series data can be sinusoidally encoded through the position coding unit to extract the position feature matrix of the long sequence time series data; finally, the first dependency matrix, the time feature matrix and the position feature matrix are feature fused to obtain the fusion result.
[0077] In practical applications, the time series embedding layer based on Embedding is composed of neighbor convolution units, position encoding units and time encoding units. The calculation process is as follows:
[0078] ;
[0079] in, Represents the value of long sequence time series data, It is the time information corresponding to the generation of long sequence time series data. represents the time coding unit, represents the position encoding unit, Represents the neighbor convolution unit. The temporal encoding unit converts the input Generate the corresponding time Decompose into a vector form of [year, month, day, hour, minute, second] and use a convolutional neural network to generate a time feature matrix The position encoding unit will input Use sinusoidal position coding to represent the position information of the time series and the relative position of the time state in the time series to obtain the position feature matrix In the nearest convolution unit, the input The neighbor dependency is captured by three dilated convolutional neural networks with different convolution kernel sizes, and then projected to the corresponding dimension using a fully connected layer to obtain the first dependency matrix Finally, the time feature matrix , position feature matrix , the first dependency matrix Fusion is performed to obtain the fusion result .
[0080] Step 2: Encode and decode the fusion results through the encoder and decoder to generate the water quality prediction results corresponding to the watershed covered by the section.
[0081] In one example, the processing of the encoder is as follows: through the first convolutional attention unit, the non-important features in the fusion result are suppressed, and the important features in the fusion result are extracted; through the downsampling layer, the important features in the fusion result are downsampled to obtain the encoded features.
[0082] In practical applications, the encoder is to focus on important features, suppress unimportant features, and convert feature vectors into hidden representations. The encoder is composed of multiple first convolutional attention units and downsampling layers. This paper uses the fusion result of the output of the time series embedding layer As the input of the time series encoder-decoder. The first convolutional attention unit is used in the encoder to fusion the result Perform calculations to further obtain high-level features, while capturing neighbor dependencies and preventing the receptive field from growing exponentially with the number of layers, which leads to focusing on unimportant features and obtaining important features Then the important features Input to the downsampling layer, and reduce parameters and filter features through the maximum pooling layer to obtain the encoded features .
[0083] In one example, the processing process of the decoder is as follows: through the second convolutional attention unit, the non-important features in the encoded features are suppressed, and the important features in the encoded features are extracted; through the multi-head attention unit, the second dependency matrix of the important features in the encoded features is captured; through the fully connected layer, the second dependency matrix is reduced in dimension to obtain the water quality prediction result corresponding to the watershed covered by the section.
[0084] In practical applications, the purpose of the decoder is to further obtain neighbor dependencies and capture long-distance dependencies, and generate water quality prediction results. The decoder is composed of a second convolutional attention unit, a multi-head attention unit and a fully connected layer. As the input of the decoder. In the decoder, the second convolutional attention unit is used to encode the features Perform calculations to further obtain advanced features, while capturing neighbor dependencies to obtain important features Then the important features Input the multi-head attention unit to capture the long-distance dependency (that is, the second dependency matrix mentioned above), and finally use the fully connected layer to project to the original dimension of the time series to obtain the water quality prediction result output by the decoder .
[0085] Furthermore, the embodiment of the present invention also provides an implementation method of training a target water quality prediction model, including the following steps 1 to 3:
[0086] Step 1: obtain training long sequence time series data, and build a multi-task data set based on the training long sequence time series data. The multi-task includes one or more of multi-region water quality prediction tasks, multi-water quality parameter prediction tasks, multi-time scale prediction tasks, and multi-feature learning tasks. In one example, 60% of the multi-task data set can be used as training data, 20% as test data, and 20% as validation data to train the model.
[0087] Step 2: Perform water quality prediction on the multi-task dataset by improving the initial water quality prediction model of Transformer to generate water quality prediction results corresponding to the multi-task dataset;
[0088] Step 3: Determine the loss function based on the water quality prediction results corresponding to the multi-task dataset, and use transfer learning to train and fine-tune the initial water quality prediction model of the improved Transformer based on the loss function to obtain the target water quality prediction model. Among them, the loss function includes multi-region water quality prediction task loss, multi-water quality parameter prediction task loss, multi-time scale prediction task loss, multi-feature learning task loss and regularization term to balance the importance of different tasks.
[0089] The embodiments of the present invention further explain transfer learning: the embodiments of the present invention adopt a multi-task learning method to improve the model performance and universality of different regions, including multi-region water quality prediction tasks, multi-water quality parameter prediction tasks, multi-time scale prediction tasks, and multi-feature learning tasks.
[0090] 1) According to the aforementioned step S102, water quality monitoring data and various characteristic data of different regions are collected, and then sorted and cleaned.
[0091] 2) Combine the water quality prediction tasks in different regions with the multi-feature learning tasks to construct a multi-task learning dataset. Standardize or normalize the data for each task.
[0092] 3) Use a multi-task neural network or a shared representation learning model.
[0093] 4) Input the data of water quality prediction tasks and multi-feature learning tasks from different regions into the model and train the model parameters together. Design a loss function, including the water quality prediction task loss for each region, the multi-feature learning task loss, and possible regularization terms to balance the importance of different tasks.
[0094] 5) Use methods such as cross-validation to verify the performance of the model, and adjust the model's hyperparameters based on the verification results to improve the model's generalization ability.
[0095] When predicting water quality in a new area, the trained model is applied to the new data and predictions are made. The difference between the prediction results and the actual situation is analyzed, and the results are fed back to the model to continuously improve the model and improve the accuracy and stability of water quality predictions.
[0096] The embodiment of the present invention uses water quality section monitoring data and water pollution impact data to train a deep learning model for water quality prediction based on an improved Transformer and transfer learning. By adding a time series embedding layer including position encoding, time encoding and neighbor convolution modules, the time information in the long sequence time series is added to the Transformer model, and the heterogeneity problem between the three is overcome. This layer captures neighbor information from the long sequence time series data through the neighbor convolution module, and fuses the data value, time information in the time series and position information to enhance the feature extraction capability and meet the requirements of the long time series time series prediction task. The embodiment of the present invention combines water quality section monitoring data with pollution source influencing factors to improve the accuracy of water quality prediction. The embodiment of the present invention can train hour, day, and month multi-time resolution models based on different sample data through a deep learning model and a transfer learning method. In addition, by using data from different regions and time periods, the model is trained and fine-tuned using a transfer learning model, which can improve the generalization ability of the water quality prediction model in a new environment and reduce the cost of model training.
[0097] In summary, the embodiments of the present invention have at least the following features:
[0098] (1) Adding a time series embedding layer including position encoding, time encoding and neighbor convolution modules adds time information in the long sequence time series to the Transformer model and overcomes the heterogeneity problem among the three. This layer captures neighbor information from the long sequence time series data through the neighbor convolution module, and fuses the data value, time information in the time series and position information to enhance the feature extraction capability and meet the requirements of long time series time series prediction tasks.
[0099] (2) The water quality section monitoring data of the embodiment of the present invention is combined with pollution influencing factors to improve the accuracy of water quality prediction. In addition to the section monitoring data, the model input data of the embodiment of the present invention also includes river sewage outlet data, land cover type, river section monitoring data, climate data, hydrological data, evapotranspiration data, river network data, etc., so as to capture the influence of relevant factors on water quality and make water quality prediction more accurate.
[0100] (3) The embodiment of the present invention can establish a multi-time resolution model of training hours, days, and months based on different sample data through a deep learning model and transfer learning method. In addition, by using data from different regions and time periods and using a transfer learning model to train and fine-tune the model, the generalization ability of the water quality prediction model in a new environment can be improved, and the model training cost can be reduced.
[0101] Based on the above embodiments, the present invention provides a water quality prediction device based on deep learning. Figure 3 The schematic diagram of the structure of a water quality prediction device based on deep learning is shown in FIG. The device mainly includes the following parts:
[0102] The data generation module 302 is used to obtain the original data of the section covering the watershed to be studied, and generate long sequence time series data based on the original data, and the long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution;
[0103] The water quality prediction module 304 is used to extract the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data through the target water quality prediction model based on the improved Transformer, and generate the water quality prediction result corresponding to the section coverage basin based on the fusion result of the first dependency matrix, time feature matrix and position feature matrix.
[0104] The above-mentioned device provided by the embodiment of the present invention combines the water quality section monitoring situation and the impact of water pollution, and uses the target water quality prediction model based on the improved Transformer to extract the data dependency matrix, time feature matrix and location feature matrix, and generates water quality prediction results on this basis, which can significantly improve the accuracy and reliability of water quality prediction.
[0105] In one embodiment, the original data includes one or more of DEM data, initial river discharge outlet data, initial land cover type, river section monitoring data, initial climate data, initial hydrological data, initial evapotranspiration data, and initial river network data;
[0106] Long-sequence time series data include one or more of current section monitoring data, upstream section monitoring data, target river discharge outlet data, basin average slope data, target climate data, river network attribute data, basin land cover indicators, target hydrological data, and basin average rainfall data.
[0107] In one embodiment, the target water quality prediction model based on the improved Transformer includes a time series embedding layer, an encoder and a decoder; the water quality prediction module 304 is also used for:
[0108] Through the time series embedding layer, the first dependency matrix in the long sequence time series data is captured, and the time feature matrix and position feature matrix of the long sequence time series data are extracted, and the first dependency matrix, the time feature matrix and the position feature matrix are fused to obtain the fusion result;
[0109] The fusion results are encoded and decoded through the encoder and decoder to generate the water quality prediction results corresponding to the watershed covered by the section.
[0110] In one embodiment, the time series embedding layer includes a neighboring convolution unit, a time encoding unit, and a position encoding unit; the water quality prediction module 304 is further used to:
[0111] Through the neighboring convolution unit, the long sequence time series data is convolved using convolution kernels of different sizes to capture the first dependency matrix in the long sequence time series data;
[0112] Through the time coding unit, the time information of long sequence time series data is decomposed into features in vector form, and the convolutional neural network is used to generate a time feature matrix based on the features in vector form;
[0113] Through the position encoding unit, the long sequence time series data is sinusoidally encoded to extract the position feature matrix of the long sequence time series data.
[0114] In one embodiment, the encoder includes a plurality of first convolutional attention units and a downsampling layer, the decoder includes a second convolutional attention unit, a multi-head attention unit and a fully connected layer; the water quality prediction module 304 is further used to:
[0115] Through the first convolutional attention unit, the non-important features in the fusion result are suppressed, and the important features in the fusion result are extracted; through the downsampling layer, the important features in the fusion result are downsampled to obtain the encoded features;
[0116] Through the second convolutional attention unit, non-important features in the encoded features are suppressed, and important features in the encoded features are extracted; through the multi-head attention unit, the second dependency matrix of important features in the encoded features is captured; through the fully connected layer, the second dependency matrix is reduced in dimensionality to obtain the water quality prediction results corresponding to the watershed covered by the section.
[0117] In one embodiment, a model training module is further included, which is used to:
[0118] Obtain training long sequence time series data, and construct a multi-task data set based on the training long sequence time series data, where the multi-task includes one or more of a multi-region water quality prediction task, a multi-water quality parameter prediction task, a multi-time scale prediction task, and a multi-feature learning task;
[0119] By improving the initial water quality prediction model of Transformer, water quality prediction is performed on the multi-task dataset to generate water quality prediction results corresponding to the multi-task dataset;
[0120] The loss function is determined based on the water quality prediction results corresponding to the multi-task dataset, and the initial water quality prediction model of the improved Transformer is trained and fine-tuned based on the loss function using transfer learning to obtain the target water quality prediction model.
[0121] In one embodiment, the loss function includes a multi-region water quality prediction task loss, a multi-water quality parameter prediction task loss, a multi-time scale prediction task loss, a multi-feature learning task loss, and a regularization term to balance the importance of different tasks.
[0122] The device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0123] An embodiment of the present invention provides an electronic device. Specifically, the electronic device includes a processor and a storage device. The storage device stores a computer program, and when the computer program is executed by the processor, it executes the method described in any one of the above-mentioned implementation methods.
[0124] Figure 4 A structural diagram of an electronic device provided in an embodiment of the present invention, the electronic device 100 includes: a processor 40, a memory 41, a bus 42 and a communication interface 43, wherein the processor 40, the communication interface 43 and the memory 41 are connected via the bus 42; the processor 40 is used to execute an executable module stored in the memory 41, such as a computer program.
[0125] The memory 41 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 43 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0126] The bus 42 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0127] Among them, the memory 41 is used to store programs, and the processor 40 executes the program after receiving the execution instruction. The method executed by the device for flow process definition disclosed in any embodiment of the above-mentioned embodiment of the present invention can be applied to the processor 40 or implemented by the processor 40.
[0128] The processor 40 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 40. The above processor 40 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 41, and the processor 40 reads the information in the memory 41 and completes the steps of the above method in combination with its hardware.
[0129] The computer program product of the readable storage medium provided in the embodiment of the present invention includes a computer-readable storage medium storing program code, and the instructions included in the program code can be used to execute the methods described in the previous method embodiments. The specific implementation can be referred to the previous method embodiments, which will not be repeated here.
[0130] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0131] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A water quality prediction method based on deep learning, characterized in that: include: Obtaining the original data of the watershed covered by the section to be studied, and generating long sequence time series data based on the original data, wherein the long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution; Through the target water quality prediction model based on the improved Transformer, the first dependency matrix, the time feature matrix and the position feature matrix of the long sequence time series data are extracted, and based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix, the water quality prediction result corresponding to the watershed covered by the section is generated; The target water quality prediction model based on the improved Transformer includes a time series embedding layer, an encoder and a decoder; extracting the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data, and generating the water quality prediction result corresponding to the watershed covered by the section based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix, comprising: capturing the first dependency matrix in the long sequence time series data through the time series embedding layer, extracting the time feature matrix and the position feature matrix of the long sequence time series data, and performing feature fusion on the first dependency matrix, the time feature matrix and the position feature matrix to obtain a fusion result; encoding and decoding the fusion result through the encoder and the decoder to generate the water quality prediction result corresponding to the watershed covered by the section; The time series embedding layer includes a neighboring convolution unit, a time encoding unit and a position encoding unit; the steps of capturing the first dependency matrix in the long sequence time series data, and extracting the time feature matrix and position feature matrix of the long sequence time series data include: through the neighboring convolution unit, using convolution kernels of different sizes to convolve the long sequence time series data to capture the first dependency matrix in the long sequence time series data; through the time encoding unit, decomposing the time information of the long sequence time series data into features in the form of vectors, and using a convolutional neural network to generate a time feature matrix based on the features in the form of vectors; through the position encoding unit, performing sinusoidal wave position encoding on the long sequence time series data to extract the position feature matrix of the long sequence time series data.
2. The water quality prediction method based on deep learning according to claim 1, characterized in that: The original data includes one or more of DEM data, initial river discharge outlet data, initial land cover type, river section monitoring data, initial climate data, initial hydrological data, initial evapotranspiration data, and initial river network data; The long sequence time series data includes one or more of current section monitoring data, upstream section monitoring data, target river discharge outlet data, basin average slope data, target climate data, river network attribute data, basin land cover indicators, target hydrological data, and basin average rainfall data.
3. The water quality prediction method based on deep learning according to claim 1 is characterized in that: The encoder includes a plurality of first convolutional attention units and a downsampling layer, and the decoder includes a second convolutional attention unit, a multi-head attention unit and a fully connected layer; The step of encoding and decoding the fusion result to generate a water quality prediction result corresponding to the watershed covered by the section includes: By using the first convolutional attention unit, non-important features in the fusion result are suppressed, and important features in the fusion result are extracted; by using the downsampling layer, the important features in the fusion result are downsampled to obtain encoding features; Through the second convolutional attention unit, non-important features in the coding features are suppressed, and important features in the coding features are extracted; through the multi-head attention unit, the second dependency matrix of the important features in the coding features is captured; through the fully connected layer, the second dependency matrix is subjected to dimensionality reduction processing to obtain the water quality prediction result corresponding to the watershed covered by the section.
4. The water quality prediction method based on deep learning according to claim 1, characterized in that: The training steps of the target water quality prediction model based on the improved Transformer include: Acquire training long sequence time series data, and construct a multi-task data set based on the training long sequence time series data, where the multi-task includes one or more of a multi-region water quality prediction task, a multi-water quality parameter prediction task, a multi-time scale prediction task, and a multi-feature learning task; By improving the initial water quality prediction model of Transformer, water quality prediction is performed on the multi-task data set to generate a water quality prediction result corresponding to the multi-task data set; A loss function is determined based on the water quality prediction results corresponding to the multi-task data set, and transfer learning is used to train and fine-tune the initial water quality prediction model of the improved Transformer based on the loss function to obtain a target water quality prediction model.
5. The water quality prediction method based on deep learning according to claim 4 is characterized in that: The loss function includes multi-region water quality prediction task loss, multi-water quality parameter prediction task loss, multi-time scale prediction task loss, multi-feature learning task loss and regularization term to balance the importance between different tasks.
6. A water quality prediction device based on deep learning, characterized in that: include: A data generation module is used to obtain the original data of the section covering the watershed to be studied, and generate long sequence time series data based on the original data, wherein the long sequence time series data is used to reflect the monitoring situation of the water quality section and the impact of water pollution; A water quality prediction module, used to extract the first dependency matrix, time feature matrix and position feature matrix of the long sequence time series data through a target water quality prediction model based on an improved Transformer, and generate a water quality prediction result corresponding to the watershed covered by the section based on the fusion result of the first dependency matrix, the time feature matrix and the position feature matrix; The target water quality prediction model based on the improved Transformer includes a time series embedding layer, an encoder and a decoder; the water quality prediction module is specifically used to: capture the first dependency matrix in the long sequence time series data through the time series embedding layer, and extract the time feature matrix and the position feature matrix of the long sequence time series data, and perform feature fusion on the first dependency matrix, the time feature matrix and the position feature matrix to obtain a fusion result; perform encoding and decoding processing on the fusion result through the encoder and the decoder to generate a water quality prediction result corresponding to the watershed covered by the section; The time series embedding layer includes a neighboring convolution unit, a time encoding unit and a position encoding unit; the water quality prediction module is specifically used to: through the neighboring convolution unit, use convolution kernels of different sizes to perform convolution processing on the long sequence time series data to capture the first dependency matrix in the long sequence time series data; Decomposing the time information of the long sequence time series data into features in vector form by the time encoding unit, and generating a time feature matrix based on the features in vector form by using a convolutional neural network; The position encoding unit performs sinusoidal wave position encoding on the long sequence time series data to extract the position feature matrix of the long sequence time series data.
7. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the method according to any one of claims 1 to 5.
