A water quality prediction method and system based on shifted window attention and dynamic graph
The method addresses the challenge of dynamic time and spatial dependencies in water quality prediction by using shift window attention and dynamic graph construction, improving predictive accuracy and computational efficiency.
Patent Information
- Application Number
- CN202510300133.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2045-03-14
AI Technical Summary
When existing water quality prediction methods deal with complex temporal dynamic characteristics and spatial correlation characteristics, there are problems such as high model complexity, high training and inference costs, and insufficient multi-scale temporal feature modeling and complex spatial and temporal relationship interaction modeling capabilities.
The water quality prediction method based on shift window attention and dynamic graph is adopted. Through convolutional layer, gated time convolution module based on shift window attention, graph convolution module based on moving window attention and dynamic graph construction module, combined with window division and attention calculation, the dependence and local relationship in time and space are learned.
It improves the accuracy and efficiency of water quality prediction, can adaptively adjust the relationship between nodes, dynamically adjust the adjacency of the graph, and improves the accuracy and calculation efficiency of prediction.
Smart Images

Figure CN119830953B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality prediction, and particularly 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 predict the water quality changes of future water bodies by using historical water quality data and related environmental information. 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 cyanobacterial blooms can be prevented in advance, thereby protecting the stability of the water ecosystem. In addition, water quality prediction can also provide a scientific basis for the protection of drinking water sources and help ensure human health. In the water quality prediction task, researchers need to simultaneously handle complex temporal dynamic characteristics and spatial correlation characteristics. Water quality changes are usually affected by multiple factors, including pollutant emissions, meteorological conditions, and water body flow. These factors not only have temporal dynamics but also form complex correlation relationships through the spatial distribution of water bodies. Therefore, effectively modeling temporal and spatial dependencies is the core challenge of water quality prediction.
[0003] Researchers have tried many methods in the water quality prediction task. For example, methods such as using recurrent neural networks and long short-term memory networks are used to capture temporal dependencies, but these methods do not consider spatial correlations. There are also methods that introduce spatio-temporal 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 relatively high, and the training and inference time costs are relatively large, especially more obvious when the number of nodes is large or the time series is long.
[0004] Spatio-temporal convolutional networks, as classical models, 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 spatio-temporal dependency relationships. Some studies introduce an adaptive graph generation mechanism to combine the graph structure with data characteristics. These methods combine graph convolution and temporal convolution to capture dynamic spatio-temporal dependencies and show good prediction performance. However, there are still problems such as insufficient ability to capture multi-scale temporal features, limited ability to model dynamic spatial relationships, insufficient spatio-temporal feature interaction, and relatively high model complexity in multi-scale temporal feature modeling and complex spatio-temporal relationship interaction modeling. Existing methods have certain limitations in terms of temporal features, spatial dependencies, and computational efficiency in water quality prediction, and it is difficult to meet the actual application requirements. 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 its technical problems is as follows:
[0007] A water quality prediction method based on shift window attention and dynamic graph, the method comprising the following steps:
[0008] S100: Obtain various water quality data at different times recorded at each station, and process the water quality data to obtain water quality time series data as a data set;
[0009] S200: Build a water quality prediction model, including a convolutional layer, a gated time convolutional module based on shift window attention, a graph convolutional module based on moving window attention, a dynamic graph construction module, and an output layer;
[0010] S300: Input the water quality time series data into the convolutional layer for dimensional mapping to obtain the time series data after convolution;
[0011] S400: Input the time series data after convolution into the gated time convolutional module based on shift window attention, and learn the temporal dependence and periodicity characteristics of the time series data after convolution based on window, shift window division, and attention calculation to obtain intermediate output features;
[0012] S500: The intermediate output features are output to the output layer through skip 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 into the graph convolutional module based on moving window attention, and learn the spatial dependence and local relationship between the intermediate output features and the dynamic graph based on 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 time convolutional module based on shift window attention in the next cycle, and S400 and S500 are repeated a preset number of times;
[0013] S600: After all the intermediate output features of the loop layers are output to the output layer, the output layer outputs the prediction results of the future time series. The water quality prediction model is trained 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 real-time obtained water quality data to obtain the prediction results.
[0014] Preferably, S400 includes:
[0015] S410: Divide the time series data after convolution in the time dimension T to obtain multiple window output features;
[0016] S420: For the multiple window output features after division, calculate the time attention respectively and then splice the windows to obtain the output window features;
[0017] S430: For the output window feature, perform shifted window partitioning in the time dimension T to obtain multiple window output features. For the multiple window output features after partitioning, calculate the temporal attention respectively and then perform window splicing to obtain the output shifted window feature;
[0018] S440: The gating part is obtained by adding the residual connection of the output window feature and the input feature, then entering the dilated convolution and sigmoid. The output shifted window feature and the residual connection of the input feature are added together, then enter the dilated convolution and multiplied by the gating part to obtain the intermediate output feature.
[0019] Preferably, in S420 and S430, the calculation of temporal attention for the window output feature is specifically as follows:
[0020] Let be the matrix representing the temporal dependence of the data at time steps, be the element in and representing the numerical value of the temporal dependence between time steps . To ensure that the sum of the attention weights is equal to 1, therefore needs to be normalized to , and its calculation is defined as:
[0021] (1);
[0022] (2);
[0023] where is the input feature, , , , , are all learnable parameters, represents the activation function;
[0024] Furthermore, the output is defined as:
[0025] (3);
[0026] where is the weight matrix of the temporal attention, and the element is , .
[0027] Preferably, in S500, the dynamic graph construction module generates a dynamic graph by combining the output result of the previous cycle, including:
[0028] S510: Generate an attention map through the multi-head attention mechanism implemented by the node embedding matrix;
[0029] S520: Calculate the normalized cosine similarity after linearly mapping the output result of the previous cycle to obtain a trend map; where, when the cycle is the first cycle, the output result of the previous cycle corresponds to the time series data after convolution;
[0030] S530: Adaptively fuse the attention map and the trend map to obtain a dynamic map.
[0031] Preferably, in S510, for the attention map , it is defined as:
[0032] (8)
[0033] (9)
[0034] (10)
[0035] (11)
[0036] Where is a learnable node embedding matrix, are both learnable linear transformation matrices, both represent on the attention head above , where is the multi-head attention matrix, respectively represent Query, Key, and Value, represents the dimension on each attention head, and Linear represents the linear transformation operation.
[0037] Preferably, in S520, for the trend map , it is defined as:
[0038] (12);
[0039] (13);
[0040] Where 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 map is first normalized before calculating the cosine similarity to capture the trend changes between nodes rather than the specific numerical values;
[0041] In S530, the dynamic map is defined as:
[0042] (14);
[0043] Among them, is a learnable parameter matrix.
[0044] Preferably, in S500, the intermediate output feature and the dynamic graph are input into the graph convolutional module based on moving window attention, and the spatial dependence and local relationship between the intermediate output feature and the dynamic graph are learned based on window, shifted window division, and graph attention calculation to obtain the output result of the current loop, including:
[0045] S540: Divide the intermediate output feature in the channel dimension R into multiple window output features;
[0046] S550: For the multiple window output features after division, perform graph attention calculation respectively and then perform window splicing to obtain the output window feature;
[0047] S560: For the output window feature, perform shifted window division in the channel dimension R to obtain multiple window output features. For the multiple window output features after division, perform graph attention calculation respectively and then perform window splicing to obtain the output shifted window feature;
[0048] S570: The output window feature is added to the residual connection of the intermediate output feature and the dynamic graph input at the beginning and then enters the graph convolution, and then the feature obtained by adding the output shifted window feature to the residual connection of the intermediate output feature and the dynamic graph input at the beginning and entering the graph convolution is added to obtain the output result of the current loop.
[0049] Preferably, the graph attention calculation for the window output feature in S550 and S560 is specifically as follows:
[0050] H is the linear mapping of the input feature in the feature space, represents the node and the numerical value of the spatial dependence between them, , in order to ensure that the sum of the attention weights is equal to 1, so needs to be normalized to , and its calculation is defined as:
[0051] (4)
[0052] (5)
[0053] (6)
[0054] Among them, is the input feature, is a learnable parameter matrix, [, ] represents the concatenation operation, respectively represent nodes and node features, is a learnable attention vector;
[0055] Furthermore, based on the attention weight , the features of the node neighborhood are weighted and summed to obtain the output feature :
[0056] (7);
[0057] Among them, is the updated feature of node n, is the node to node attention weight, is the node features.
[0058] Preferably, in S600, the output of the output layer is defined as:
[0059] (15);
[0060] Among them, represents the layer output of the time convolutional module based on shifted window attention, represents the total number of layers, ReLU is the activation function, and conv represents the convolutional layer.
[0061] A water quality prediction system based on shifted window attention and dynamic graph, including a water quality time series data acquisition module, a convolutional module, a gated time convolutional module based on shifted window attention, a dynamic graph construction module, a graph convolutional module based on moving window attention, an output layer, and a training and prediction module;
[0062] The water quality time series data acquisition module is used to obtain various water quality data at different times recorded at each site, and process the water quality data to obtain water quality time series data;
[0063] The convolutional module is used to perform dimensional mapping on the water quality time series data to obtain the convolved time series data;
[0064] Enter the recurrent layer, and the gated time convolutional module based on shifted window attention is used to learn the temporal dependence and periodic characteristics of the convolved time series data based on window, shifted window partitioning, and attention calculation, obtain the intermediate output features, and the intermediate output features are output to the output layer through skip connections;
[0065] The dynamic graph construction module generates a dynamic graph by combining the output results of the previous cycle;
[0066] The graph convolution module based on moving window attention is used to learn the spatial dependence and local relationship between the intermediate output features and the dynamic graph based on window, shifted window partitioning, and graph attention calculation, 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 loop layer is repeated a preset number of times;
[0067] The output layer is used to receive the intermediate output features of all loop layers and output the prediction result of the future time series;
[0068] The training and prediction module is used to train the water quality prediction model by combining 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 real-time obtained water quality data to obtain the prediction result.
[0069] The above water quality prediction method and system based on shifted window attention and dynamic graph propose a temporal convolution TCN, 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 for time steps, channels, and graphs, and greatly improves the accuracy of water quality prediction. Brief Description of the Drawings
[0070] Figure 1 It is a flowchart of a water quality prediction method based on shifted window attention and dynamic graph in an embodiment of the present invention;
[0071] 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;
[0072] Figure 3 It is a schematic diagram of the principle of the TCN module based on shifted window attention in an embodiment of the present invention;
[0073] Figure 4 It is a schematic diagram of the window shifting operation in shifted window partitioning in an embodiment of the present invention;
[0074] Figure 5 It is a schematic diagram of the principle of the dynamic graph construction module in an embodiment of the present invention;
[0075] Figure 6 It is a schematic diagram of the principle of the GCN module based on shifted window attention in an embodiment of the present invention. Detailed Embodiments
[0076] To enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings.
[0077] In one embodiment, as Figure 1 and Figure 2 shown, a water quality prediction method based on shifted window attention and dynamic graph, the method comprising the following steps:
[0078] S100: Obtain various water quality data at different times recorded at each station, and process the water quality data to obtain water quality time series data as a data set;
[0079] S200: Build a water quality prediction model, including a convolutional layer, a gated temporal convolutional module based on shifted window attention, a graph convolutional module based on moving window attention, a dynamic graph construction module, and an output layer;
[0080] S300: Input the water quality time series data into the convolutional layer for dimensional mapping to obtain the convolved time series data;
[0081] S400: Input the convolved time series data into the gated temporal convolutional (TCN) module based on shifted window attention, and learn the temporal dependence and periodicity characteristics of the convolved time series data based on window, shifted window division, and attention calculation to obtain intermediate output features;
[0082] S500: The intermediate output features are output to the output layer through skip connections. 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 into the graph convolutional (GCN) module based on moving window attention, and learn the spatial dependence and local relationship between the intermediate output features and the dynamic graph based on window, shifted 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 convolutional module based on shifted window attention in the next cycle. Repeat S400 and S500 for a preset number of times;
[0083] S600: After the intermediate output features of all cycle layers are output to the output layer, the output layer outputs the prediction results of the future time series. The water quality prediction model is trained 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 real-time obtained water quality data to obtain prediction results.
[0084] Specifically, obtain the original data of the excel table of various water quality indicators recorded at each station, and then perform data processing on it (transformation of row and column labels, filling of missing values) to make the shape of the data conform to the input shape required by the model. What is obtained is the water quality time series data that meets the input reading requirements of the model.
[0085] Furthermore, the TCN module based on shifted window attention is constructed based on the principle of gated TCN, and the gated TCN can extract temporally relevant features from the input time series data. The original gated TCN directly inputs and outputs time series data, while in the TCN module based on shifted window attention, as Figure 3 shown, S400 includes:
[0086] S410: Divide the time series data after convolution in the time dimension T to obtain multiple window output features;
[0087] S420: For the multiple window output features after division, calculate the temporal attention respectively and then splice the windows to obtain the output window features;
[0088] S430: For the output window features, perform shifted window division in the time dimension T to obtain multiple window output features. For the multiple window output features after division, calculate the temporal attention respectively and then splice the windows to obtain the output shifted window features; Furthermore, the window shift operation in the shifted window division is as Figure 4 shown;
[0089] S440: The gated part is obtained by adding the residual connection of the output window features and the input features, then entering the dilated convolution and sigmoid. The output shifted window features and the residual connection of the input features are added and then enter the dilated convolution and multiplied by the gated part to obtain the intermediate output features; among them, the dilated convolution is a common temporal convolution module in gated TCN.
[0090] In one embodiment, the calculation of the temporal attention for the window output features in S420 and S430 is specifically as follows:
[0091] is a matrix representing the temporal dependence of the data at time steps, is an element in, representing the temporal dependence value between time step and , , in order to ensure that the sum of the attention weights is equal to 1, so needs to be normalized to , and its calculation is defined as:
[0092] (1);
[0093] (2);
[0094] Among them, is the input feature, , , , , are all learnable parameters, represents the activation function;
[0095] Furthermore, the output is defined as:
[0096] (3);
[0097] wherein, is the weight matrix of the temporal attention, and the elements therein are , .
[0098] In one embodiment, as Figure 5 shown, the dynamic graph construction module in S500 generates a dynamic graph by combining the output result of the previous cycle, including:
[0099] S510: Generate an attention graph through the multi-head attention mechanism implemented by the node embedding matrix;
[0100] S520: Calculate the normalized cosine similarity after linearly mapping the output result of the previous cycle 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;
[0101] S530: Adaptively fuse the attention graph and the trend graph to obtain a dynamic graph.
[0102] In one embodiment, in S510, for the attention graph , its definition is:
[0103] (8)
[0104] (9)
[0105] (10)
[0106] (11)
[0107] wherein, is the learnable node embedding matrix, are all learnable linear transformation matrices, both represent on the attention head of , where is the multi-head attention matrix, respectively represent query, key, and value, indicating the dimension of each attention head, and Linear represents a linear transformation operation.
[0108] In one embodiment, in S520, for the trend graph , it is defined as:
[0109] (12);
[0110] (13);
[0111] Among them, is the output result of the previous cycle of the model, is a learnable linear transformation matrix, ReLU is an 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 magnitudes;
[0112] In S530, the dynamic graph is defined as:
[0113] (14)
[0114] Among them, is a learnable parameter matrix.
[0115] In one embodiment, as Figure 6 shown, in S500, the intermediate output feature and the dynamic graph are input into the graph convolutional module based on moving window attention, and the spatial dependence and local relationship between the intermediate output feature and the dynamic graph are learned based on window, shifted window partitioning, and graph attention calculation to obtain the output result of the current cycle, including:
[0116] S540: Partition the intermediate output feature in the channel dimension R to obtain multiple window output features;
[0117] S550: For each of the multiple window output features after partitioning, perform graph attention calculation and then window splicing to obtain the output window feature;
[0118] S560: For the output window feature, perform shifted window partitioning in the channel dimension R to obtain multiple window output features. For each of the multiple window output features after partitioning, perform graph attention calculation and then window splicing to obtain the output shifted window feature;
[0119] S570: The output window feature is added to the residual connection of the initially input intermediate output feature and the dynamic graph, and then enters the graph convolution. Additionally, the feature obtained by adding the output shifted window feature to the residual connection of the initially input intermediate output feature and the dynamic graph and then entering the graph convolution is added, resulting in the output of the current loop.
[0120] In one embodiment, the graph attention calculation for the window output feature in S550 and S560 is as follows:
[0121] H is a linear mapping of the input feature in the feature space. denotes node and the numerical value of the spatial dependence between them. , to ensure that the sum of the attention weights equals 1, thus needs to be normalized to , and its calculation is defined as:
[0122] (4)
[0123] (5)
[0124] (6)
[0125] Among them, is the input feature, is the learnable parameter matrix, [, ] represents the concatenation operation, respectively denote the features of node and node , is the learnable attention vector;
[0126] Furthermore, based on the attention weight , the features of the node neighborhood are weighted and summed to obtain the output feature :
[0127] (7);
[0128] Among them, is the updated feature of node n, is the attention weight of node to node , is the feature of node .
[0129] In one embodiment, in S600, the output is defined as:
[0130] (15);
[0131] Among them, represents the output of the time convolutional module based on shifted window attention for the -th layer, represents the total number of layers, ReLU is the activation function, and conv represents the convolutional layer.
[0132] The above water quality prediction method and system based on shifted window attention and dynamic graph have the following beneficial effects:
[0133] (1) Improve the TCN and GCN parts, and use the window partitioning algorithm to partition windows in the time dimension T and the channel dimension R. Since different windows contribute differently to the target time point, through the attention mechanism, the model can automatically assign higher weights to key time steps or channels, improving the pertinence of prediction. (2) Long time series input will introduce noise, affecting the prediction accuracy. Through the window mechanism, the model only focuses on the local time dependencies within each window, while the shifting mechanism enhances the information capture across windows. (3) An adaptive dynamic graph that combines the attention map and the trend map is implemented. The attention map is used to capture the correlation between nodes, and the trend map 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, dynamically adjusting the adjacency of the graph during training to obtain higher prediction accuracy.
[0134] In one embodiment, a water quality prediction system based on shifted window attention and dynamic graph includes a water quality time series data acquisition module, a convolutional module, a gated time convolutional module based on shifted window attention, a dynamic graph construction module, a graph convolutional module based on moving window attention, an output layer, and a training and prediction module;
[0135] The water quality time series data acquisition module is used to acquire various water quality data at different times recorded at each site, and process the water quality data to obtain water quality time series data;
[0136] The convolutional module is used to perform dimensional mapping on the water quality time series data to obtain the convolved time series data;
[0137] Entering the recurrent layer, the gated time convolutional module based on shifted window attention is used to learn the temporal dependencies and periodic characteristics of the convolved time series data based on windows, shifted window partitioning, and attention calculation, obtaining intermediate output features, and the intermediate output features are output to the output layer through skip connections;
[0138] The dynamic graph construction module generates a dynamic graph in combination with the output result of the previous cycle;
[0139] The graph convolution module based on moving window attention is used to learn the intermediate output features and the spatial dependence and local relationship of the dynamic graph based on window, shifted window partitioning, and graph attention calculation, and obtain the output result of the current loop. The output result of the current loop is used as the input of the gated temporal convolution module based on shifted window attention in the next loop, and the loop layer is repeated a preset number of times;
[0140] The output layer is used to receive the intermediate output features of all loop layers and output the prediction result of the future time series;
[0141] 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 real-time obtained water quality data and obtain the prediction result.
[0142] For the specific definition of a water quality prediction system based on shifted window attention and dynamic graph, reference can be made to the definition of a water quality prediction method based on shifted window attention and dynamic graph in the above text, which will not be elaborated here. Each module in the above water quality prediction system based on shifted window attention and dynamic graph can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.
[0143] The above has introduced in detail 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 elaborate on the principle and implementation manner 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 noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present invention, several improvements and modifications can still be made to the present invention, and these improvements and modifications also fall within the protection scope 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 includes the following steps: S100: Obtain various water quality data at different times recorded by each site, 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 a convolutional layer, a gated time convolutional module based on shifted window attention, a graph convolutional module based on moving window attention, a dynamic graph construction module, and an output layer; S300: Input the water quality time series data into the convolutional layer for dimensional mapping to obtain the convolved time series data; S400: Input the convolved time series data into the gated time convolutional module based on shifted window attention, and learn the temporal dependence and periodicity characteristics of the convolved time series data based on window, shifted window division, and attention calculation to obtain intermediate output features; S500: 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 intermediate output features and the dynamic graph are input into the graph convolutional module based on moving window attention, and learn the spatial dependence and local relationship between the intermediate output features and the dynamic graph based on window, shifted 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 time convolutional module based on shifted window attention in the next cycle, and repeat S400 and S500 for a preset number of times; where, when the cycle is the first cycle, the output result of the previous cycle corresponds to the convolved time series data; S600: After the intermediate output features of all cycle layers are output to the output layer, the output layer outputs the prediction results of the future time series. Combine the preset loss function to train the water quality prediction model. When the preset training end condition is reached, obtain the trained water quality prediction model, which is used to predict the real-time obtained water quality data to obtain the prediction results.
2. The method according to claim 1, wherein S400 includes: S410: Divide the convolved time series data in the time dimension T into windows to obtain multiple window output features; S420: For the multiple window output features after division, calculate the time attention respectively and then perform window splicing to obtain the output window features; S430: For the output window features, perform shifted window division in the time dimension T to obtain multiple window output features. For the multiple window output features after division, calculate the time attention respectively and then perform window splicing to obtain the output shifted window features; S440: The gated part is obtained by adding the residual connection of the output window features and the input features, entering the dilated convolution and then sigmoid. The output shifted window features and the residual connection of the input features are added together, enter the dilated convolution and multiplied by the gated part to obtain the intermediate output features.
3. The method according to claim 2, characterized in that, In S500, the dynamic graph construction module generates a dynamic graph by combining the output results of the previous cycle, including: S510: Generate an attention graph through the multi-head attention mechanism implemented by the node embedding matrix; S520: Perform a linear mapping on the output results of the previous cycle and then calculate the normalized cosine similarity between nodes to obtain a trend graph; S530: The attention map and the trend map are adaptively fused to obtain a dynamic map.
4. The method according to claim 3, wherein In S510, for the attention map , it is defined as: (8) (9) (10) (11) Among them, is a learnable node embedding matrix, are all learnable linear transformation matrices, both represent at the attention head on the , where is the multi-head attention matrix, respectively represent Query, Key, Value, d represents the dimension of each attention head, and Linear represents the linear transformation operation.
5. The method according to claim 4, wherein In S500, the intermediate output feature and the dynamic map are input into the graph convolutional module based on moving window attention. Based on window, shifted window partitioning, and graph attention calculation, the spatial dependence and local relationship between the intermediate output feature and the dynamic map are learned to obtain the output result of the current cycle, including: S540: The intermediate output feature is partitioned into windows in the channel dimension R to obtain multiple window output features; S550: For the multiple window output features after partitioning, graph attention calculations are performed respectively and then window splicing is carried out to obtain the output window feature; S560: For the output window feature, shifted window partitioning is performed in the channel dimension R to obtain multiple window output features. For the multiple window output features after partitioning, graph attention calculations are performed respectively and then window splicing is carried out to obtain the output shifted window feature; S570: The output window feature is added to the residual connection of the intermediate output feature and the dynamic map input at the beginning and then enters the graph convolution. Additionally, the feature obtained by adding the output shifted window feature to the residual connection of the intermediate output feature and the dynamic map input at the beginning and then entering the graph convolution is added, resulting in the output result of the current cycle.
6. 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 convolutional module, a gated time convolutional module based on shifted window attention, a dynamic graph construction module, a graph convolutional 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 acquire various water quality data at different times recorded at each station and process the water quality data to obtain water quality time series data; The convolutional 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 time convolutional module based on shifted window attention is used to learn the temporal dependence and periodic characteristics of the convolved time series data based on window, shifted window partitioning, and attention calculation to obtain the intermediate output feature. The intermediate output feature is output to the output layer through a skip connection; The dynamic graph construction module generates a dynamic graph in combination with the output result of the previous cycle; The graph convolutional module based on moving window attention is used to learn the spatial dependence and local relationship between the intermediate output feature and the dynamic map based on window, shifted window partitioning, 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 time convolutional module based on shifted window attention in the next cycle, and the recurrent layer is repeated a preset number of times; The output layer is used to receive the intermediate output features of all recurrent layers and output the prediction result of the 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 real-time acquired water quality data to obtain the prediction result.
Citation Information
Patent Citations
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