Water quality prediction method and system based on shift window attention and dynamic graph
By introducing a gated time convolution module based on shift window attention and a graph convolution module based on moving window attention in the water quality prediction model, combined with a dynamic graph construction module, the shortcomings of the existing methods in capturing multi-scale time features and complex spatiotemporal relationship interactions are solved, and more efficient and accurate water quality prediction is achieved.
Patent Information
- Application Number
- CN202510300133.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2045-03-14
AI Technical Summary
The existing water quality prediction methods have shortcomings in capturing multi-scale time characteristics and complex spatiotemporal relationship interactions. The model is complex and the time cost of training and inference is high, making it difficult to meet the practical application needs.
The gated time convolution module based on shift window attention and the graph convolution module based on moving window attention are adopted, combined with the dynamic graph construction module, and through window division and attention calculation, time and space dependence are learned to realize adaptive spatio-temporal feature interaction.
It improves the accuracy and efficiency of water quality prediction, enhances the dynamic weight allocation ability of the model to time steps and channels, and can more effectively capture multi-scale time characteristics and complex spatiotemporal relationships, reducing model complexity and calculation costs.
Smart Images

Figure CN119830953A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality prediction, and in particular relates to a water quality prediction method and system based on shifted window attention and dynamic graph. Background Art
[0002] Water quality prediction aims to use historical water quality data and related environmental information to predict future changes in water quality. Water quality prediction is of great significance for water resource management and environmental protection. For example, by accurately predicting water quality, ecological disasters such as blue algae blooms can be prevented in advance, thereby protecting the stability of aquatic ecosystems. In addition, water quality prediction can also provide a scientific basis for the protection of drinking water sources and help protect human health. In the task of water quality prediction, researchers need to deal with complex temporal dynamic characteristics and spatial correlation characteristics at the same time. Water quality changes are usually affected by multiple factors, including pollution source emissions, meteorological conditions, and water flow. These factors are not only dynamic in time, but also form complex correlations through the spatial distribution of water bodies. Therefore, effectively modeling temporal and spatial dependencies is a core challenge for water quality prediction.
[0003] Researchers have tried many methods for water quality prediction tasks. For example, recurrent neural networks and long short-term memory networks are used to capture temporal dependencies, but these methods do not take into account spatial associations. There are also methods that introduce spatiotemporal attention and use pure attention networks. These methods have certain advantages in capturing long-term dependencies and non-local spatial characteristics, but the model complexity is high, and the training and inference time costs are high, especially when there are a large number of nodes or a long time series.
[0004] As a classic model, spatiotemporal convolutional networks combine graph convolutional networks (GCNs) and temporal convolutional networks (TCNs) to simultaneously model temporal and spatial characteristics. However, these methods usually assume that spatial dependencies are fixed and cannot adapt to the dynamic changes of spatiotemporal dependencies. Some studies combine graph structure with data characteristics by introducing adaptive graph generation mechanisms. These methods combine graph convolution and temporal convolution to capture dynamic spatiotemporal dependencies and show good prediction performance. However, in terms of multi-scale temporal feature modeling and complex spatiotemporal relationship interaction modeling, there are still problems such as insufficient ability to capture multi-scale temporal features, limited ability to model dynamic spatial relationships, insufficient interaction of spatiotemporal features, and high model complexity. Existing methods have certain limitations in terms of temporal characteristics, spatial dependencies, and computational efficiency in water quality prediction, and are difficult to meet the needs of actual applications. Summary of the invention
[0005] In view of the above technical problems, the present invention provides a water quality prediction method and system based on shifted window attention and dynamic graph.
[0006] The technical solution adopted by the present invention to solve the technical problem is: A water quality prediction method based on shifted window attention and dynamic graph, the method comprising the following steps: S100: Acquire various water quality data recorded at different times at various stations, and process the water quality data to obtain water quality time series data as a data set; S200: Build a water quality prediction model, including convolutional layers, gated temporal convolution modules based on shifted window attention, graph convolution modules based on moving window attention, dynamic graph construction modules, and output layers; S300: inputting the water quality time series data into the convolution layer for dimensional mapping to obtain the convolved time series data; S400: inputting the convolved time series data into a gated time convolution module based on shift window attention, learning the temporal dependency and periodicity characteristics of the convolved time series data based on windows, shift window division and attention calculation, and obtaining intermediate output features; S500: The intermediate output features are output to the output layer through the jump connection. The dynamic graph construction module generates a dynamic graph in combination with the output result of the previous cycle. The intermediate output features and the dynamic graph are input to the graph convolution module based on the moving window attention. The spatial dependency and local relationship between the intermediate output features and the dynamic graph are learned based on the window, shift window division and graph attention calculation to obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on the shift window attention in the next cycle. S400 and S500 are repeated for a preset number of times. S600: After the intermediate output features of all the circulation layers are output to the output layer, the output layer outputs the prediction results of the future time series, and the water quality prediction model is trained in combination with the preset loss function. When the preset training end condition is reached, the trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction results.
[0007] Preferably, S400 includes: S410: Divide the convolved time series data into windows on the time dimension T to obtain multiple window output features; S420: For the divided multiple window output features, calculate the temporal attention respectively and then splice the windows to obtain output window features; S430: For the output window feature, perform shift window division on the time dimension T to obtain multiple window output features, and for the multiple window output features after division, perform window splicing after performing time attention calculation respectively to obtain the output shift window feature; S440: The gated part is obtained by adding the residual connection of the output window feature and the input feature, then entering the dilated convolution and sigmoid, and the output shifted window feature is added to the residual connection of the input feature, then entering the dilated convolution and multiplying with the gated part to obtain the intermediate output feature.
[0008] Preferably, in S420 and S430, the temporal attention is calculated for the window output features, specifically: To indicate data in The matrix of time dependencies at time steps, for The elements in represent the time steps and The time-dependent value of , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (1); (2); in, is the input feature, , , , , are all learnable parameters. represents the activation function; Furthermore, the output Defined as: (3); in, is the weight matrix of temporal attention, where the elements are , .
[0009] Preferably, the dynamic graph construction module in S500 generates a dynamic graph in combination with the output result of the previous cycle, including: S510: Generate attention graph through multi-head attention mechanism implemented by node embedding matrix; S520: performing linear mapping on the output result of the previous cycle and calculating the normalized cosine similarity to obtain a trend graph; wherein, when the cycle is the first cycle, the output result of the previous cycle corresponds to the time series data after convolution; S530: Adaptively fuse the attention map and the trend map to obtain a dynamic map.
[0010] Preferably, in S510, for the attention map , which is defined as: (8) (9) (10) (11) in, is the learnable node embedding matrix, are all learnable linear transformation matrices, Both indicate that in the attention head on ,in is the multi-head attention matrix, They represent query, key, and value respectively. Represents the dimension of each attention head, and Linear represents the linear transformation operation.
[0011] Preferably, in S520, for the trend graph , which is defined as: (12); (13); in, is the output result of the previous cycle of the model, is a learnable linear transformation matrix, ReLU is the activation function, and the trend graph is first normalized before calculating the cosine similarity to capture the trend changes between nodes rather than the specific numerical values; In S530, dynamic image Defined as: (14); in, is the learnable parameter matrix.
[0012] Preferably, in S500, the intermediate output features and the dynamic graph are input to a graph convolution module based on moving window attention, and the spatial dependency and local relationship between the intermediate output features and the dynamic graph are learned based on window, shift window division and graph attention calculation to obtain the output result of the current cycle, including: S540: Divide the intermediate output features into windows on the channel dimension R to obtain multiple window output features; S550: For the divided multiple window output features, respectively perform graph attention calculations and then perform window splicing to obtain output window features; S560: For the output window feature, shift window division is performed on the channel dimension R to obtain multiple window output features, and for the multiple window output features after division, image attention is calculated respectively and then the windows are spliced to obtain the output shift window feature; S570: The output window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution, and then the output shift window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution feature to obtain the output result of the current cycle.
[0013] Preferably, in S550 and S560, the graph attention is calculated for the window output features, specifically: H is the linear mapping of the input features in the feature space, Representation Node and The spatial dependence between , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (4) (5) (6) in, is the input feature, is a learnable parameter matrix, [ , ] represents the concatenation operation, Respectively represent nodes and nodes Features, is the learnable attention vector; Furthermore, based on the attention weight , perform weighted summation on the features of the node domain to obtain the output features : (7); in, is the updated feature of node n, For Node For Node The attention weight, For Node characteristics.
[0014] Preferably, in S600, the output of the output layer Defined as: (15); in, Indicates The output of the temporal convolutional module based on shifted window attention of the layer, ReLU is the activation function, and conv represents the convolutional layer.
[0015] A water quality prediction system based on shifting window attention and dynamic graph, comprising a water quality time series data acquisition module, a convolution module, a gated time convolution module based on shifting window attention, a dynamic graph construction module, a graph convolution module based on shifting window attention, an output layer, and a training and prediction module; The water quality time series data acquisition module is used to obtain various water quality data recorded at different times by each station, and process the water quality data to obtain water quality time series data; The convolution module is used to perform dimensional mapping on the water quality time series data to obtain the convolved time series data; Entering the recurrent layer, the gated temporal convolution module based on shifted window attention is used to learn the temporal dependency and periodicity characteristics of the convolved time series data based on windows, shifted window division and attention calculation, and obtain intermediate output features. The intermediate output features are output to the output layer through skip connections; The dynamic graph construction module generates a dynamic graph by combining the output results of the previous cycle; The graph convolution module based on moving window attention is used to learn the spatial dependencies and local relationships of intermediate output features and dynamic graphs based on windows, shifted window divisions and graph attention calculations, and obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on shifted window attention in the next cycle, and the cycle layer is repeated for a preset number of times; The output layer is used to receive the intermediate output features of all loop layers and output the prediction results of future time series; The training and prediction module is used to train the water quality prediction model in combination with a preset loss function. When the preset training end condition is reached, a trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction result.
[0016] The above-mentioned water quality prediction method and system based on shifted window attention and dynamic graph proposes a time convolution TCN and graph convolution GCN algorithm based on window partitioning and a dynamic graph construction method for water quality prediction tasks. This method systematically improves TCN and GCN, realizes adaptive dynamic weight allocation of time steps, channels and graphs, and greatly improves the accuracy of water quality prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A flow chart of a water quality prediction method based on shifted window attention and dynamic graph in one embodiment of the present invention; Figure 2 It is an overall framework diagram of a water quality prediction method based on shifted window attention and dynamic graph in another embodiment of the present invention; Figure 3 Schematic diagram of the principle of a TCN module based on shifted window attention in one embodiment of the present invention; Figure 4 A schematic diagram of a window shifting operation in shifting window division in one embodiment of the present invention; Figure 5 It is a schematic diagram of the principle of a dynamic graph construction module in one embodiment of the present invention; Figure 6 Schematic diagram of the principle of a GCN module based on shifted window attention in one embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.
[0019] In one embodiment, Figure 1 and Figure 2 As shown, a water quality prediction method based on shifted window attention and dynamic graph, the method comprises the following steps: S100: Acquire various water quality data recorded at different times at various stations, and process the water quality data to obtain water quality time series data as a data set; S200: Build a water quality prediction model, including convolutional layers, gated temporal convolution modules based on shifted window attention, graph convolution modules based on moving window attention, dynamic graph construction modules, and output layers; S300: inputting the water quality time series data into the convolution layer for dimensional mapping to obtain the convolved time series data; S400: inputting the convolved time series data into a gated temporal convolution (TCN) module based on shift window attention, learning the temporal dependency and periodicity characteristics of the convolved time series data based on window, shift window division and attention calculation, and obtaining intermediate output features; S500: The intermediate output features are output to the output layer through the jump connection. The dynamic graph construction module generates a dynamic graph in combination with the output result of the previous cycle. The intermediate output features and the dynamic graph are input to the graph convolution (GCN) module based on the moving window attention. The spatial dependency and local relationship between the intermediate output features and the dynamic graph are learned based on the window, shift window division and graph attention calculation to obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on the shift window attention in the next cycle. S400 and S500 are repeated for a preset number of times. S600: After the intermediate output features of all the circulation layers are output to the output layer, the output layer outputs the prediction results of the future time series, and the water quality prediction model is trained in combination with the preset loss function. When the preset training end condition is reached, the trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction results.
[0020] Specifically, the original data of various water quality indicators recorded at different times at each station are obtained in Excel tables, and then the data is processed (row and column labels are transformed, and missing values are filled) so that the shape of the data can meet the input shape required by the model. The result is water quality time series data that meets the model input reading requirements.
[0021] Furthermore, the TCN module based on shifted window attention is built on the principle of gated TCN, which can extract temporally relevant features from input time series data. The original gated TCN input and output are both directly input as time series data, while in the TCN module based on shifted window attention, Figure 3 As shown, S400 includes: S410: Divide the convolved time series data into windows on the time dimension T to obtain multiple window output features; S420: For the divided multiple window output features, calculate the temporal attention respectively and then splice the windows to obtain output window features; S430: For the output window feature, shift window division is performed on the time dimension T to obtain multiple window output features. For the multiple window output features after division, time attention is calculated respectively and then window splicing is performed to obtain output shift window features; further, the window shift operation in the shift window division is as follows: Figure 4 As shown; S440: The gated part is obtained by adding the residual connection of the output window feature and the input feature, then entering the dilated convolution and sigmoid, and the output shifted window feature is added to the residual connection of the input feature, then entering the dilated convolution and multiplying with the gated part to obtain the intermediate output feature; among them, the dilated convolution is a common temporal convolution module of the gated TCN.
[0022] In one embodiment, the temporal attention is calculated for the window output features in S420 and S430, specifically: To indicate data in The matrix of time dependencies at time steps, for The elements in represent the time steps and The time-dependent value of , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (1); (2); in, is the input feature, , , , , are all learnable parameters. represents the activation function; Furthermore, the output Defined as: (3); in, is the weight matrix of temporal attention, where the elements are , .
[0023] In one embodiment, Figure 5 As shown, the dynamic graph construction module in S500 generates a dynamic graph in combination with the output result of the previous cycle, including: S510: Generate attention graph through multi-head attention mechanism implemented by node embedding matrix; S520: performing linear mapping on the output result of the previous cycle and calculating the normalized cosine similarity to obtain a trend graph; wherein, when the cycle is the first cycle, the output result of the previous cycle corresponds to the time series data after convolution; S530: Adaptively fuse the attention map and the trend map to obtain a dynamic map.
[0024] In one embodiment, in S510, for the attention map , which is defined as: (8) (9) (10) (11) in, is the learnable node embedding matrix, are all learnable linear transformation matrices, Both indicate that in the attention head on ,in is the multi-head attention matrix, They represent query, key, and value respectively. Represents the dimension of each attention head, and Linear represents the linear transformation operation.
[0025] In one embodiment, in S520, for the trend graph , which is defined as: (12); (13); in, is the output result of the previous cycle of the model, is a learnable linear transformation matrix, ReLU is the activation function, and the trend graph is first normalized before calculating the cosine similarity to capture the trend changes between nodes rather than the specific numerical values; In S530, dynamic image Defined as: (14) in, is the learnable parameter matrix.
[0026] In one embodiment, Figure 6 As shown, in S500, the intermediate output features and the dynamic graph are input to the graph convolution module based on the moving window attention, and the spatial dependency and local relationship of the intermediate output features and the dynamic graph are learned based on the window, shift window division and graph attention calculation to obtain the output result of the current cycle, including: S540: Divide the intermediate output features into windows on the channel dimension R to obtain multiple window output features; S550: For the divided multiple window output features, respectively perform graph attention calculations and then perform window splicing to obtain output window features; S560: For the output window feature, shift window division is performed on the channel dimension R to obtain multiple window output features, and for the multiple window output features after division, image attention is calculated respectively and then the windows are spliced to obtain the output shift window feature; S570: The output window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution, and then the output shift window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution feature to obtain the output result of the current cycle.
[0027] In one embodiment, in S550 and S560, the graph attention is calculated for the window output features, specifically: H is the linear mapping of the input features in the feature space, Representation Node and The spatial dependence between , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (4) (5) (6) in, is the input feature, is a learnable parameter matrix, [ , ] represents the concatenation operation, Respectively represent nodes and nodes Features, is the learnable attention vector; Furthermore, based on the attention weight , perform weighted summation on the features of the node domain to obtain the output features : (7); in, is the updated feature of node n, For Node For Node The attention weight, For Node characteristics.
[0028] In one embodiment, in S600, output Defined as: (15); in, Indicates The output of the temporal convolutional module based on shifted window attention of the layer, ReLU is the activation function, and conv represents the convolutional layer.
[0029] The above-mentioned water quality prediction method and system based on shifted window attention and dynamic graph has the following beneficial effects: (1) Improve the TCN and GCN parts, and use the window partitioning algorithm to divide the windows on the time dimension T and channel dimension R. Since different windows contribute differently to the target time point, the model can automatically assign higher weights to key time steps or channels through the attention mechanism to improve the targeted prediction. (2) Long time series input will introduce noise and affect the prediction accuracy. Through the window mechanism, the model only focuses on the local time dependency within each window, and the shift mechanism enhances the information capture across windows. (3) An adaptive dynamic graph that integrates the attention graph and the trend graph is implemented. The attention graph is used to capture the correlation between nodes, and the trend graph obtains the change trend characteristics between nodes through the output of the previous layer. The adaptive dynamic graph can effectively and adaptively adjust the relationship between nodes, and dynamically adjust the adjacency of the graph during the training process to obtain higher prediction accuracy.
[0030] In one embodiment, a water quality prediction system based on shifting window attention and dynamic graph includes a water quality time series data acquisition module, a convolution module, a gated temporal convolution module based on shifting window attention, a dynamic graph construction module, a graph convolution module based on shifting window attention, an output layer, and a training and prediction module; The water quality time series data acquisition module is used to obtain various water quality data recorded at different times by each station, and process the water quality data to obtain water quality time series data; The convolution module is used to perform dimensional mapping on the water quality time series data to obtain the convolved time series data; Entering the recurrent layer, the gated temporal convolution module based on shifted window attention is used to learn the temporal dependency and periodicity characteristics of the convolved time series data based on windows, shifted window division and attention calculation, and obtain intermediate output features. The intermediate output features are output to the output layer through skip connections; The dynamic graph construction module generates a dynamic graph by combining the output results of the previous cycle; The graph convolution module based on moving window attention is used to learn the spatial dependencies and local relationships of intermediate output features and dynamic graphs based on windows, shifted window divisions and graph attention calculations, and obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on shifted window attention in the next cycle, and the cycle layer is repeated for a preset number of times; The output layer is used to receive the intermediate output features of all loop layers and output the prediction results of future time series; The training and prediction module is used to train the water quality prediction model in combination with a preset loss function. When the preset training end condition is reached, a trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction result.
[0031] For the specific definition of a water quality prediction system based on shifting window attention and dynamic graphs, please refer to the definition of a water quality prediction method based on shifting window attention and dynamic graphs in the above text, which will not be repeated here. Each module in the above-mentioned water quality prediction system based on shifting window attention and dynamic graphs can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0032] The above is a detailed introduction to a water quality prediction method and system based on shifted window attention and dynamic graph provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A water quality prediction method based on shifted window attention and dynamic graph, characterized in that: The method comprises the following steps: S100: Acquire various water quality data recorded at different times at various stations, and process the water quality data to obtain water quality time series data as a data set; S200: Build a water quality prediction model, including convolutional layers, gated temporal convolution modules based on shifted window attention, graph convolution modules based on moving window attention, dynamic graph construction modules, and output layers; S300: inputting the water quality time series data into the convolution layer for dimensional mapping to obtain the convolved time series data; S400: inputting the convolved time series data into a gated time convolution module based on shift window attention, learning the temporal dependency and periodicity characteristics of the convolved time series data based on windows, shift window division and attention calculation, and obtaining intermediate output features; S500: The intermediate output features are output to the output layer through the jump connection. The dynamic graph construction module generates a dynamic graph in combination with the output result of the previous cycle. The intermediate output features and the dynamic graph are input to the graph convolution module based on the moving window attention. The spatial dependency and local relationship between the intermediate output features and the dynamic graph are learned based on the window, shift window division and graph attention calculation to obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on the shift window attention in the next cycle. S400 and S500 are repeated for a preset number of times. S600: After the intermediate output features of all the circulation layers are output to the output layer, the output layer outputs the prediction results of the future time series, and the water quality prediction model is trained in combination with the preset loss function. When the preset training end condition is reached, the trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction results.
2. The method according to claim 1, characterized in that S400 includes: S410: Divide the convolved time series data into windows on the time dimension T to obtain multiple window output features; S420: For the divided multiple window output features, calculate the temporal attention respectively and then splice the windows to obtain output window features; S430: For the output window feature, perform shift window division on the time dimension T to obtain multiple window output features, and for the multiple window output features after division, perform window splicing after performing time attention calculation respectively to obtain the output shift window feature; S440: The gated part is obtained by adding the residual connection of the output window feature and the input feature, then entering the dilated convolution and sigmoid, and the output shifted window feature is added to the residual connection of the input feature, then entering the dilated convolution and multiplying with the gated part to obtain the intermediate output feature.
3. The method according to claim 2, characterized in that In S420 and S430, the temporal attention is calculated for the window output features, specifically: To indicate data in The matrix of time dependencies at time steps, for The elements in represent the time steps and The time-dependent value of , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (1); (2); in, is the input feature, , , , , are all learnable parameters. represents the activation function; Furthermore, the output Defined as: (3); in, is the weight matrix of temporal attention, where the elements are , .
4. The method according to claim 3, characterized in that The dynamic graph construction module in S500 generates a dynamic graph in combination with the output result of the previous cycle, including: S510: Generate attention graph through multi-head attention mechanism implemented by node embedding matrix; S520: performing linear mapping on the output result of the previous cycle and calculating the normalized cosine similarity to obtain a trend graph; wherein, when the cycle is the first cycle, the output result of the previous cycle corresponds to the time series data after convolution; S530: Adaptively fuse the attention map and the trend map to obtain a dynamic map.
5. The method according to claim 4, characterized in that In S510, for the attention map , which is defined as: (8) (9) (10) (11) in, is the learnable node embedding matrix, are all learnable linear transformation matrices, Both indicate that in the attention head on ,in is the multi-head attention matrix, They represent query, key, and value respectively. Represents the dimension of each attention head, and Linear represents the linear transformation operation.
6. The method according to claim 5, characterized in that In S520, for trend graph , which is defined as: (12); (13); in, is the output result of the previous cycle of the model, is a learnable linear transformation matrix, ReLU is the activation function, and the trend graph is first normalized before calculating the cosine similarity to capture the trend changes between nodes rather than the specific numerical values; In S530, dynamic image Defined as: (14); in, is the learnable parameter matrix.
7. The method according to claim 6, characterized in that In S500, the intermediate output features and dynamic graph are input to the graph convolution module based on moving window attention. The spatial dependency and local relationship of the intermediate output features and dynamic graph are learned based on window, shift window division and graph attention calculation to obtain the output result of the current cycle, including: S540: Divide the intermediate output features into windows on the channel dimension R to obtain multiple window output features; S550: For the divided multiple window output features, respectively perform graph attention calculations and then perform window splicing to obtain output window features; S560: For the output window feature, shift window division is performed on the channel dimension R to obtain multiple window output features, and for the multiple window output features after division, image attention is calculated respectively and then the windows are spliced to obtain the output shift window feature; S570: The output window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution, and then the output shift window feature is added to the initial input intermediate output feature and the residual connection of the dynamic graph and then enters the graph convolution feature to obtain the output result of the current cycle.
8. The method according to claim 7, characterized in that In S550 and S560, the graph attention is calculated for the window output features, specifically: H is the linear mapping of the input features in the feature space, Display Node and The spatial dependence between , in order to ensure that the sum of the attention weights is equal to 1, it is necessary to Normalize to , whose calculation is defined as: (4) (5) (6) in, is the input feature, is a learnable parameter matrix, [ , ] represents the concatenation operation, Respectively represent nodes and nodes Features, is the learnable attention vector; Furthermore, based on the attention weight , perform weighted summation on the features of the node domain to obtain the output features : (7); in, is the updated feature of node n, For Node For Node The attention weight, For Node characteristics.
9. The method according to claim 8, characterized in that In S600, the output of the output layer Defined as: (15); in, Indicates The output of the temporal convolutional module based on shifted window attention of the layer, ReLU is the activation function, and conv represents the convolutional layer.
10. A water quality prediction system based on shifted window attention and dynamic graph, characterized in that: It includes a water quality time series data acquisition module, a convolution module, a gated time convolution module based on shifted window attention, a dynamic graph construction module, a graph convolution module based on moving window attention, an output layer, and a training and prediction module; The water quality time series data acquisition module is used to obtain various water quality data recorded at different times by each station, and process the water quality data to obtain water quality time series data; The convolution module is used to perform dimensional mapping on the water quality time series data to obtain the convolved time series data; Entering the recurrent layer, the gated temporal convolution module based on shifted window attention is used to learn the temporal dependency and periodicity characteristics of the convolved time series data based on windows, shifted window division and attention calculation, and obtain intermediate output features. The intermediate output features are output to the output layer through skip connections; The dynamic graph construction module generates a dynamic graph by combining the output results of the previous cycle; The graph convolution module based on moving window attention is used to learn the spatial dependencies and local relationships of intermediate output features and dynamic graphs based on windows, shifted window divisions and graph attention calculations, and obtain the output result of the current cycle. The output result of the current cycle is used as the input of the gated temporal convolution module based on shifted window attention in the next cycle, and the cycle layer is repeated for a preset number of times; The output layer is used to receive the intermediate output features of all loop layers and output the prediction results of future time series; The training and prediction module is used to train the water quality prediction model in combination with a preset loss function. When the preset training end condition is reached, a trained water quality prediction model is obtained, which is used to predict the water quality data obtained in real time to obtain the prediction result.
Citation Information
Patent Citations
Lightweight shift graph convolution behavior recognition method based on attention mechanism
CN113673411A
Optical flow calculation method, system and device fusing shift window attention and medium
CN115731263A
Method, device and equipment for predicting dyskinesia based on multi-modal image data
CN117079093A
Network attack identification method based on improved Swinin-Transform model
CN117375924A
Time series data prediction method based on Transform architecture
CN118332490A
Cited By
Water environment index space-time correlation simulation forecasting method based on deep graph learning
CN122175018A
Water environment index spatio-temporal correlation simulation and prediction method based on graph deep learning
CN122175018B