A multi-site water quality prediction method based on spatiotemporal feature fusion
By adopting the method of spatial and temporal feature fusion in water quality prediction, using technical means such as sparse graph neural network and multi-hop propagation of god-of-frequent differential equations, the problem of low accuracy of water quality prediction in the existing technology is solved, and more efficient and capable Explain the effect of water quality prediction.
Patent Information
- Application Number
- CN202411679803.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-11-22
AI Technical Summary
In the prior art, the accuracy of water quality prediction is low, and the spatial characteristics and diverse causal relationships of water quality data are not effectively utilized.
Using a multi-site water quality prediction method based on spatiotemporal feature fusion, by acquiring and pre-processing the water quality data and physical topological adjacency matrix in the basin, a sparse graph neural network, a time domain convolution module, a multi-hop propagation divine frequent differential equation and self-attention The feature reconstruction module of the force mechanism is modeled and predicted.
It improves the accuracy and interpretability of water quality prediction, and model multi-site water quality index data from causal, spatial and semantic angles, which improves the utilization rate and prediction effect of information.
Smart Images

Figure CN119168176B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial big data, and in particular to a multi-site water quality prediction method based on spatiotemporal feature fusion. Background Art
[0002] Traditional water quality monitoring methods are limited, and the development of new water quality monitoring technologies and prediction models has not yet been fully popularized. Accurate water quality prediction is crucial to protecting water resources, preventing water pollution, and safeguarding public health. Prediction models are mainly divided into three categories: traditional statistical prediction models, such as time series analysis and exponential smoothing; machine learning prediction models, such as support vector machines and neural networks; and combined spatiotemporal representation models based on TCN-graph neural networks.
[0003] Since there are many factors that affect water quality changes and they are uncertain, numerical data often exhibit uncertain, nonlinear and non-stationary characteristics. Traditional statistical prediction models and machine learning are not accurate and do not use the spatial characteristics of water quality data. They only process the temporal characteristics of a single site. Similarly, the combined spatiotemporal representation model based on TCN-graph neural network also has the problem of unexplainable mechanism in the process of simulating water propagation and lack of modeling of the interaction between various indicators. That is, most existing tasks focus on the combination of physical spatial information of water areas and deep learning models, ignoring the internal mechanism of water quality diffusion and the causal relationship between variables in multivariate water quality data.
[0004] Therefore, how to design a high-precision water quality prediction method has become a technical problem that needs to be solved urgently. Summary of the invention
[0005] The purpose of the present invention is to solve the defect of low water quality prediction accuracy in the prior art and to provide a multi-site water quality prediction method based on spatiotemporal feature fusion to solve the above problem.
[0006] In order to achieve the above object, the technical solution of the present invention is as follows:
[0007] A multi-site water quality prediction method based on spatiotemporal feature fusion includes the following steps:
[0008] 11) Acquisition and preprocessing of basic water quality data at multiple sites: Acquire water quality data within the basin and the physical topological adjacency matrix between sites and perform preprocessing;
[0009] 12) Feature screening of water quality data in water areas: Use Pearson correlation coefficient and mutual information coefficient to screen the features in regional water quality data to obtain multi-site water quality index data;
[0010] 13) Build Model: It is constructed using a sparse graph neural network construction module, a time domain convolution module, a multi-hop propagation-based neural ordinary differential equation, and a feature reconstruction module based on a self-attention mechanism. Model;
[0011] 14) Model training: Using multi-site water quality index data, the gradient descent algorithm is used to optimize the parameters of the time domain convolution module, the multi-hop propagation based neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism. The approximate point gradient descent algorithm is used to constrain and optimize the sparsity of the parameters of the multivariate sparse causal graph in the sparse graph neural network construction module. The gradient descent algorithm and the approximate point gradient descent algorithm are executed alternately until the model converges;
[0012] 15) Obtaining water quality prediction results: The water quality indicators detected by each detection station in the water area and the physical topological adjacency matrix of each station are crawled through the crawler algorithm, and the missing values of the water quality indicator data are filled using the Lagrange interpolation method. The filled water quality indicators and physical topological adjacency matrix are input into the trained Model for real-time water quality prediction.
[0013] The acquisition and preprocessing of the multi-site water quality basic data includes the following steps:
[0014] 21) Use the crawler algorithm to extract the water quality time series information and longitude and latitude information of each monitoring point in the basin and save it as document;
[0015] 22) Use the numpy package in Python to read File, and use Lagrange interpolation method to fill the missing values in the water quality time series;
[0016] 23) Convert two-dimensional water quality data Convert to 3D data ,here Indicates a point in time, Indicates the monitoring point. Represents water quality characteristics and is saved as files, called water quality data for watersheds;
[0017] 24) According to the longitude and latitude of each site, the physical topological adjacency matrix between each site is calculated using the Haversine formula and saved as an Excel file. The Haversine formula is as follows:
[0018] ,
[0019] ,
[0020] ,
[0021] in, represents the sine function, represents the cosine function, represents the inverse tangent function, , are the latitudes of the two points in radians; is the difference in latitude between two points; is the difference in longitude between two points; is the radius of the Earth, The angle that represents the geodesic arc, that is, the arc distance between two points on the Earth's surface. is an intermediate calculated variable that combines the sine and cosine of the latitude and longitude difference in order to represent the angular difference between the two locations, By calculation and The product of the two gets the distance between the two sites.
[0022] The feature screening of water quality data in the water area comprises the following steps:
[0023] 31) Using Python Packet Reading File, remove the water temperature feature and ammonia nitrogen feature from the water quality indicators of the water quality data of the water area;
[0024] 32) Calculate the maximum mutual information coefficient of water quality indicators of each monitoring station and other monitoring stations, and screen out the algae density feature based on the significantly low mutual information between the algae density feature and other features; screen out the eight characteristics of predicting water quality indicators, including dissolved oxygen, pH value, permanganate index, total phosphorus, total nitrogen, conductivity, turbidity, and chlorophyll, to obtain the final multi-station water quality indicator data.
[0025] The construction The model consists of the following steps:
[0026] 41) Settings The first part of the model is a sparse graph neural network construction module and a time domain convolution module that run in parallel;
[0027] The input of the time domain convolution module is the multi-site water quality index data or the reconstructed time representation. The time domain convolution module is composed of a TCN module, which consists of 4 convolution layers, using a small kernel of size 2. The expansion factors of the 4 convolution layers are 1, 2, 4, and 8 respectively. Each layer uses the LeakyReLU activation function with a Dropout rate of 0.2. The time domain convolution module converts the multi-site water quality index data into time domain data, and outputs the time domain data to the parallel sparse graph neural network construction module and the multi-hop propagation based neural ordinary differential equation.
[0028] The input of the parallel sparse graph neural network construction module is the time domain data output by the parallel time domain convolution module, the physical topology adjacency matrix and the multi-site water quality index data;
[0029] Construct a sparse physical topology adjacency matrix: Use the K-Means clustering algorithm and the size of the elements in the physical topology adjacency matrix as the criterion to cluster the physical topology adjacency matrix into 5 clusters. For each cluster, use the minimum spanning tree algorithm to generate the minimum spanning tree adjacency matrix between clusters. Merge the adjacency matrices of the minimum spanning trees of the 5 clusters to obtain a sparse physical topology adjacency matrix.
[0030] The input multi-site water quality index data is used to obtain the DTW graph using the DTW algorithm;
[0031] By constructing two learnable vector parameters and performing the matrix product operation of the two vectors, a multivariate sparse causal graph is constructed for the time domain data output by the parallel-running time domain convolution module. The sparsity of the multivariate sparse causal graph is achieved through the approximate point gradient descent algorithm. The obtained sparse physical topology adjacency matrix, DTW graph, and multivariate sparse causal graph are provided to the neural ordinary differential equation based on multi-hop propagation.
[0032] 42) Settings The second part of the model is a multi-hop propagation based neural ordinary differential equation, the input is The first part of the model runs in parallel the time domain data output by the time domain convolution module and the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph output by the sparse graph neural network construction module;
[0033] The process of water quality propagation is modeled interpretably by constructing a neural ordinary differential equation: the Mix-Hop Propagation mechanism is introduced in the process of propagation on the sparse physical topological adjacency matrix of time domain data. The traditional graph convolution operation is transformed into a cumulative propagation matrix The multi-hop propagation operation is constructed by constructing the multi-hop propagation neural ordinary differential equation modeled from multiple perspectives, including the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph. Then, the neural network is constructed using the Pytorch deep learning framework. The library is used to solve the problem and obtain the spatial representation, which is then passed to the feature reconstruction module based on the self-attention mechanism.
[0034] 43) Settings The third part of the model is the feature reconstruction module based on the self-attention mechanism. The input of the feature reconstruction module is The second part of the model outputs the spatial representation, which is first processed by position encoding, and then corrected by the self-attention mechanism to obtain the spatial representation after position encoding ;right Perform layer normalization and input into the feedforward neural network to obtain a new spatial representation , by introducing a learnable rank vector , as a matrix The main diagonal elements of ; the reconstructed feature representation is ,in Represents the matrix multiplication operation; it is measured using the reconstruction loss based on the Frobenius norm. and The reconstruction error between the spatial representations output by the second part of the model is used to optimize the parameters of the network in the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm, and the reconstructed temporal representation is used as the input of the subsequent fully connected layer;
[0035] 44) Settings The fourth part of the model is the fully connected layer, and the features reconstructed from the third part enter The first part of the model is processed by the second and third parts, and finally passes through the fully connected layer to obtain the prediction result.
[0036] Said The training of the model consists of the following steps:
[0037] 51) Setting the optimization objective function consists of two parts as follows:
[0038] ,
[0039] in, is the true value, is the predicted value, express The network parameters of the model, Indicated as setting The multivariate sparse causal graph in the sparse graph neural network construction module running in parallel in the first part of the model, is the balance coefficient, Represents the MAE loss function, that is, the true value With the predicted value The absolute value error of Represents the reconstruction error, that is, the reconstructed data and The output of the second part of the model The Frobenius norm between is used as the reconstruction error to optimize the reconstruction effect through the gradient descent algorithm. As shown below:
[0040] ,
[0041] in, Representation characteristics The Frobenius norm before and after reconstruction is as follows:
[0042] ,
[0043] in, represents the absolute value of the characteristic element, and It means summing the absolute value elements. and Indicates subscript, and express The size of the first dimension and the size of the second dimension of the feature, Return Matrix The Frobenius norm of ;
[0044] The function looks like this:
[0045] ,
[0046] is the number of data points, It is The actual value of the data point, It is The predicted value of the data point, is the absolute error between the predicted value and the actual value, represents the sum operation, is a subscript, ranging from 1 to n, return and MAE error;
[0047] 52) Multi-site water quality index data Input to the parallel time domain convolution module, Indicates a point in time, Indicates the monitoring point. Represent water quality characteristics, extract temporal information in the time dimension, and process the input through the causal convolution layer;
[0048] Set the size of the convolution kernel of the causal convolution layer to , then the convolution output It is expressed as:
[0049] ,
[0050] here, are the elements of the output tensor, Represents an index, represents the sum operation; The corresponding channel The convolution kernel of elements, index The characteristic of causal convolution is guaranteed, that is, the information at the current moment only depends on the information at the previous moment;
[0051] Convolution output As time domain data Y, it is input into the subsequent parallel sparse graph neural network construction module;
[0052] 53) Multi-site water quality index data Input to the sparse graph neural network construction module,
[0053] 531) First pass The algorithm is based on the distance between time series and is used for multi-site water quality index data. ,
[0054] in, Indicates a point in time, Indicates the monitoring point. Indicates water quality characteristics,
[0055] Calculate the mean and standard deviation , and perform standardization:
[0056] ,
[0057] ,
[0058] ,
[0059] in, Represents a sum operation, which means The elements in are summed up, Indicates time step, Indicates nodes, represents the square root operation, It is Time step, The features corresponding to the nodes are Indicates the use of the calculated mean and standard deviation right The results obtained by standardization;
[0060] 532) For each node Time series, calculate the daily mean , using the fast dynamic time warping algorithm to calculate any two nodes and The distance between , the formula is as follows:
[0061] ,
[0062] in, yes The Euclidean distance of Indicates A point in time, express Middle The value at a time point, for Middle The value at a time point, Indicates taking the minimum value;
[0063] 533) For each time step ,calculate and The local Euclidean distance between them and construct a cumulative distance matrix , the formula is as follows:
[0064] ,
[0065] ,
[0066] in Representation Node and The cumulative distance of express The value at the first time point in for The value at the first time point in For and The Euclidean distance between them is used to accumulate the distance matrix Initialization of
[0067] 534) The following constraints are used to calculate the minimum cumulative distance on the path ,
[0068] ,
[0069] in, return and The Euclidean distance between
[0070] express , , The minimum value in ;
[0071] 535) Find the optimal path through step 534) and calculate , and finally get matrix;
[0072] 54) Physical topology adjacency matrix Perform spectral clustering and divide into cluster; for each cluster , apply the minimum spanning tree algorithm to get the adjacency matrix , and the final sparse physical topology adjacency matrix is obtained through the following transformation formula :
[0073]
[0074] here, and Represents two sites, → Indicates the site To site , express Middle site To site physical distance, and same;
[0075] 55) The construction of multivariate sparse causal graph in the parallel running sparse graph neural network construction module is as follows:
[0076] 551) In the sparse graph neural network construction module, a learnable multivariate sparse causal graph is established for the time domain data Y output by the time domain convolution module , Indicates a A two-dimensional matrix, Indicates the number of characteristic dimensions of water quality data in the model, The elements satisfy , the specific construction formula is as follows:
[0077] ,
[0078] ,
[0079] here, Indicates that the embedding operation is through a fully connected layer. It represents the number of nodes in the causal graph, that is, the number of characteristic dimensions of water quality data in the model. Represents when building a causal graph and The number of column components of
[0080] 552) Yes and After linear transformation, the weighted parameters To zoom, , tanh is the hyperbolic tangent function, used to add nonlinearity,
[0081]
[0082]
[0083] here, represents a linear layer;
[0084] 553) By calculation To capture and The interaction information between them is then combined through activation functions to form the final sparse multivariate causal graph.
[0085] ,
[0086] ,
[0087] here, represents the activation function, Representation Matrix The transpose of Representation Matrix The transpose of express and The intermediate variables of the operation, Represents the generated multivariate sparse causal graph;
[0088] 56) The second part of the model is based on the multi-hop propagation Neural ODE module. The steps are as follows:
[0089] 561) The sparse physical topology adjacency matrix is represented as , the multivariate sparse causal graph is represented as , first of all Perform self-join and normalize to get ,in Represents a diagonal matrix. For the matrix , The diagonal elements of yes Midpoint The degree of for ;
[0090] Based on the traditional graph convolution operation, the Mix-Hop Propagation mechanism is introduced. The mechanism is as follows:
[0091] ,
[0092] ,
[0093] here, represents the maximum depth of propagation, is a hyperparameter that controls the degree of state preservation of the source node. get:
[0094] ,
[0095] in, represents the weight of the first layer of accumulated state, represents the weight of the second layer’s accumulated state, Indicates The weight of the layer's accumulated state, is a hyperparameter that controls the degree of state preservation of the source node. An index representing the propagation depth, represents the sparse physical topology adjacency matrix after self-connection and normalization, represents the summation symbol, is the index, ranging from 0 to , Representation Matrix of Power;
[0096] 562) By sharing weights, i.e., fixing , , for , and obtain the final cumulative propagation matrix for:
[0097] ,
[0098] in, represents the maximum depth of propagation, Depth index representing graph propagation; represents the sum operation, Representation Matrix of Power;
[0099] 563) According to the time domain data obtained in step 52) , the normalized sparse physical topology adjacency matrix And the normalized multivariate sparse causal graph , we get the improved Neural Ordinary Differential Equation, which is expressed as follows:
[0100] ,
[0101] in, represents the characteristics of the t-th step, express Relative to time The derivative of represents the normalized multivariate sparse causal graph, Represents normalized matrix; express and Operations on the second and third dimensions of matrices, represents the shared learnable coefficient matrix, represents the sum operation, represents the maximum depth of propagation, Represents the current propagation depth index of the graph, ranging from 0 to , represents the normalized sparse physical topology adjacency matrix, express of Power;
[0102] 564) Pass In Kulai solves the deep neural ordinary differential equations to obtain the spatial representation of the target prediction time step ;
[0103] 57) The third part of the model is the feature reconstruction module based on the self-attention mechanism. The steps are as follows:
[0104] 571) The spatial representation obtained by solving the improved Neural Ordinary Differential Equation After position encoding, , the specific steps are:
[0105] ,
[0106] Among them, pos represents the position of the spatial representation T, represents the spatial representation T Dimensions, is the embedding dimension, Represented as an even-numbered position representation, represents the representation at odd positions, represents the sine function, represents the cosine function;
[0107] 572) The feature reconstruction module based on the self-attention mechanism uses the self-attention mechanism to reconstruct the position-encoded features. The time domain information is processed to obtain the feature output corrected by self-attention, which is expressed as follows:
[0108] ,
[0109] in, represents the feature after position encoding, Indicates the layer normalization operation on the input features. Represented as a self-attention mechanism operation;
[0110] The specific operation of the self-attention mechanism is as follows:
[0111] 5721) will be for input , we map the input to a query by a linear transformation ,key Sum :
[0112]
[0113] in, is the learned weight matrix, For the general pass The transformed query matrix, For the general pass The transformed key matrix, For the general pass The transformed value matrix;
[0114] 5722) Then calculate the query matrix and key matrix The dot product of and scales, then applies The function gets the attention weight:
[0115] ;
[0116] here is the dimension of the key, used to prevent the dot product value from being too large; Represented as the feature after the self-attention mechanism operation, The function is expressed as:
[0117] ,
[0118] in, represents the input features, express Middle elements, Returns the natural constant, based on the number of The value of the power of is the index, from 1 to , n represents the number of elements in z, Returns the sum of all elements in Indicates the converted The value of the component;
[0119] 573) Features after self-attention mechanism processing The layers are normalized again and input into the feedforward neural network, introducing learnable parameters , which forms a diagonal matrix for scaling features of different dimensions. The process formula is:
[0120] ,
[0121] in, represents the scaling factor for each dimension, and Indicates the size of the two dimensions of the learnable parameters, Indicated by As the main diagonal element, the other elements are 0. represents a feedforward neural network, which is used to further process features to make them more capable of nonlinear representation. Represents the product operation between matrices;
[0122] 58) The fourth part of the model is the fully connected layer, which has the following steps:
[0123] 581) When the The third part of the model is based on the reconstruction module output of the self-attention mechanism The time domain convolution module, the neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism are input again in sequence. After repeating steps 52) to 57), the obtained features are passed through the fully connected layer to obtain the prediction results;
[0124] 59) Yes Model training uses the Adam optimizer to perform gradient descent algorithm combined with the approximate point gradient descent algorithm strategy to train the model, as follows:
[0125] 591) The model updates the network parameters in the time domain convolution module, the multi-hop propagation-based neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm according to the requirements of the loss function. :
[0126] Calculate the gradient: loss function Perform gradient calculation to obtain the parameters Gradient; parameter update: then given the gradient In the case of , update the specific parameters of the module in 512):
[0127] ,
[0128] represents the predicted value, represents the true value, represents the parameters in the model, which are optimized to minimize the loss function; represents the parameters of the multivariate sparse causal graph, represents the learning rate, Represents the loss function about The gradient of express minus The value of
[0129] 592) When the parameters of each module in 591) are fixed, perform local operations to process Regularization is used to ensure the sparsity of the multivariate sparse causal graph, and soft threshold processing is performed on the multivariate sparse causal graph parameters in the sparse graph neural network construction module:
[0130] ,
[0131] here, , Representation characteristics The index of represents the parameters after sparseness, represents a symbolic function, output The symbol, represents the threshold, reflecting the strength of the sparsity constraint. Returns the maximum value between the two. return The maximum value between 0 and Representation Elements The absolute value of
[0132] 593) The model is iterated from steps 591) to 592) through the training set and the validation set and early stopping method are used to avoid overfitting of the model until the model converges, and finally the trained prediction model is obtained.
[0133] Beneficial Effects
[0134] Compared with the prior art, the multi-site water quality prediction method based on spatiotemporal feature fusion of the present invention models the multi-site water quality index data from the three perspectives of causality, space, and semantics. For complex water scenes, more relevant factors are taken into account; based on the Neural Ordinary Differential Equation, a more interpretable modeling scheme is provided for the water quality propagation process, and compared with the traditional Neural Ordinary Differential Modeling, the multi-hop propagation method is used to improve the utilization and propagation rate of information. In order to achieve the effective fusion of TCN-based time domain modeling and multi-hop propagation-based Neural Ordinary Differential Equation spatial modeling, a feature reconstruction scheme based on the self-attention mechanism is constructed to achieve more effective spatiotemporal fusion prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0135] Figure 1 is a method sequence diagram of the present invention;
[0136] Figure 2 Schematic diagram of dilated causal convolution in the temporal convolutional network of the present invention;
[0137] Figure 3 It is a schematic diagram of a feature reconstruction module based on a self-attention mechanism of the present invention;
[0138] Figure 4 This is a graph showing the prediction curves of different models at the Zhongmiao monitoring site;
[0139] Figure 5 This is a graph showing the prediction curves of different models at the Zhaohe detection site;
[0140] Figure 6 This is a comparison chart of different models in predicting quantitative effects;
[0141] Figure 7 It is the model optimization process of the present invention. DETAILED DESCRIPTION
[0142] In order to have a further understanding and recognition of the structural features and the effects achieved by the present invention, a preferred embodiment and accompanying drawings are used for detailed description as follows:
[0143] like Figure 1 As shown, the multi-site water quality prediction method based on spatiotemporal feature fusion described in the present invention includes the following steps:
[0144] The first step is to obtain and preprocess the basic water quality data of multiple sites: obtain the water quality data in the basin and the physical topological adjacency matrix between each site and perform preprocessing.
[0145] (1) Use the crawler algorithm to extract the water quality time series information and longitude and latitude information of each monitoring point in the basin and save it as document.
[0146] (2) Use In Packet Reading The Lagrange interpolation method is used to fill in the missing values in the water quality time series.
[0147] (3) Two-dimensional water quality data Convert to 3D data ,here Indicates a point in time, Indicates the monitoring point. Represents water quality characteristics and is saved as File, called water quality data of watershed.
[0148] (4) According to the longitude and latitude of each station, the physical topological adjacency matrix between each station is calculated by the Haversine formula, as shown in Table 1 and saved as an Excel file. The Haversine formula is as follows:
[0149] ,
[0150] ,
[0151] ,
[0152] in, represents the sine function, represents the cosine function, represents the inverse tangent function, , are the latitudes of the two points in radians; is the difference in latitude between two points; is the difference in longitude between two points; is the radius of the Earth, The angle that represents the geodesic arc, that is, the arc distance between two points on the Earth's surface. is an intermediate calculated variable that combines the sine and cosine of the latitude and longitude difference in order to represent the angular difference between the two locations, By calculation and The product of the two gets the distance between the two sites.
[0153]
[0154] The second step is to screen the characteristics of water quality data in the water area: the Pearson correlation coefficient, as shown in Table 2, and the mutual information coefficient are used to screen the characteristics in the regional water quality data to obtain multi-site water quality index data.
[0155]
[0156] (1) Using Python Packet Reading File, removes the water temperature feature and ammonia nitrogen feature from the water quality indicators of water area water quality data.
[0157] (2) The maximum mutual information coefficient of the water quality indicators of each monitoring station and the other monitoring stations was calculated. Based on the significantly low mutual information between the algae density feature and other features, the algae density feature was screened out. The eight features for predicting water quality indicators, namely dissolved oxygen, pH value, permanganate index, total phosphorus, total nitrogen, conductivity, turbidity, and chlorophyll, were screened out to obtain the final multi-station water quality indicator data.
[0158] Step 3: Build Model: It is constructed using a sparse graph neural network construction module, a time domain convolution module, a multi-hop propagation-based neural ordinary differential equation, and a feature reconstruction module based on a self-attention mechanism. Model.
[0159] The present invention constructs The model uses TCN to extract information from water quality index data in the time dimension. The TCN structure is as follows: Figure 2 As shown in the figure, multiple convolutional layers are used to obtain more accurate time domain representation; and multi-site water quality index data are modeled from three perspectives: multivariate causality, spatial propagation, and semantics: in spatial propagation, the K-Means clustering algorithm and the minimum spanning algorithm are used to simplify the physical topological adjacency matrix to improve the robustness of information propagation; in multivariate causal modeling, a learnable sparse multivariate causal matrix is introduced to robustly model the interaction between various indicators in water quality, thereby improving the effect and accuracy of water quality prediction. In semantic modeling, we use the DTW algorithm to construct a DTW graph for multi-site water quality index data; based on the graph structure obtained from the three perspectives, the water quality propagation process of the water area is modeled based on the Neural Ordinary Differential Equation, providing an interpretable modeling that conforms to the physical propagation process, and on this basis, the mix-hop propagation layer is introduced to replace the single neighbor node propagation of the traditional graph convolution operation with multi-hop propagation in the process of spatial information propagation, thereby improving the interaction rate of spatial information. At the same time, based on the self-attention mechanism, the solution of the neural ordinary differential equation is reconstructed in the time dimension so that the solution has richer time domain characteristics, so that the TCN module can be used again to obtain the time domain representation, which improves the utilization of information and improves the prediction accuracy.
[0160] Build The model consists of the following steps:
[0161] (1) Settings The first part of the model is a sparse graph neural network construction module and a time domain convolution module that run in parallel;
[0162] The input of the time-domain convolution module is the water quality index data of multiple sites. The time-domain convolution module is composed of a TCN module. The TCN module consists of 4 convolution layers, using a small kernel of size 2. The expansion factors of the 4 convolution layers are 1, 2, 4, and 8 respectively. Each layer uses the LeakyReLU activation function with a Dropout rate of 0.2. The time-domain convolution module converts the water quality index data of multiple sites into time-domain data, and outputs the time-domain data to the parallel sparse graph neural network construction module and the neural ordinary differential equation based on multi-hop propagation.
[0163] The input of the parallel sparse graph neural network construction module is the time domain data output by the parallel time domain convolution module, the physical topology adjacency matrix and the multi-site water quality index data;
[0164] Construct a sparse physical topology adjacency matrix: Use the K-Means clustering algorithm and the size of the elements in the physical topology adjacency matrix as the criterion to cluster the physical topology adjacency matrix into 5 clusters. For each cluster, use the minimum spanning tree algorithm to generate the minimum spanning tree adjacency matrix between clusters. Merge the adjacency matrices of the minimum spanning trees of the 5 clusters to obtain a sparse physical topology adjacency matrix.
[0165] The input multi-site water quality index data were used to obtain the DTW graph using the DTW algorithm;
[0166] By constructing two learnable vector parameters and performing the matrix product operation of the two vectors, a multivariate sparse causal graph is constructed for the time domain data output by the time domain convolution modules running in parallel. The sparsity of the multivariate sparse causal graph is achieved through the approximate point gradient descent algorithm. The obtained sparse physical topological adjacency matrix, DTW graph, and multivariate sparse causal graph are provided to the neural ordinary differential equation based on multi-hop propagation.
[0167] (2) Settings The second part of the model is a multi-hop propagation based neural ordinary differential equation, the input is The first part of the model runs in parallel the time domain data output by the time domain convolution module and the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph output by the sparse graph neural network construction module;
[0168] The process of water quality propagation is modeled interpretably by constructing a neural ordinary differential equation: the Mix-Hop Propagation mechanism is introduced in the process of propagation on the sparse physical topological adjacency matrix of time domain data. The traditional graph convolution operation is transformed into a cumulative propagation matrix The multi-hop propagation operation is constructed by constructing the multi-hop propagation neural ordinary differential equation modeled from multiple perspectives, including the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph. Then, the neural network is constructed using the Pytorch deep learning framework. The spatial representation is finally passed to the feature reconstruction module based on the self-attention mechanism.
[0169] (3) Settings The third part of the model is the feature reconstruction module based on the self-attention mechanism. The input of the feature reconstruction module is The second part of the model outputs the spatial representation, which is first processed by position encoding, and then corrected by the self-attention mechanism to obtain the spatial representation after position encoding ;right Perform layer normalization and input into the feedforward neural network to obtain a new spatial representation , by introducing a learnable rank vector , as a matrix The main diagonal elements of ; the reconstructed feature representation is ,in Represents the matrix multiplication operation; it is measured using the reconstruction loss based on the Frobenius norm. and The reconstruction error between the spatial representations output by the second part of the model is used to optimize the parameters of the network in the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm, and the reconstructed temporal representation is used as the input of the subsequent fully connected layer.
[0170] (4) Settings The fourth part of the model is the fully connected layer, where the reconstructed features are again After the first, second and third parts of the model, the prediction result is finally obtained through the fully connected layer.
[0171] Step 4. Model training: Using multi-site water quality index data, the gradient descent algorithm is used to optimize the parameters of the time domain convolution module, the multi-hop propagation neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism. The approximate point gradient descent algorithm is used to constrain and optimize the sparsity of the parameters of the multivariate sparse causal graph in the sparse graph neural network construction module. The gradient descent algorithm and the approximate point gradient descent algorithm are executed alternately until the model converges. The training process is as follows: Figure 7 shown.
[0172] During training, we adopted an alternating execution strategy of the gradient descent algorithm and the approximate point gradient descent algorithm. In the process of sparsity-constrained optimization, first, the gradient descent algorithm provides global optimization and achieves robust parameter updates by calculating the average gradient of the entire data set, while the approximate point gradient descent algorithm improves computational efficiency by quickly calculating approximate gradients. Alternating between these two strategies not only improves the convergence speed, but also enhances the robustness of the optimization and reduces update oscillations. In addition, combining the two can better adapt to sparsity constraints, help identify important features and control feature activity. At the same time, this method reduces computational costs, especially when dealing with large-scale data sets, provides greater flexibility and adjustability, and ultimately achieves a more efficient optimization process.
[0173] (1) The optimization objective function consists of two parts as follows:
[0174] ,
[0175] in, is the true value, is the predicted value, Indicates the The network parameters of the model, Indicated as setting The multivariate sparse causal graph in the sparse graph neural network construction module running in parallel in the first part of the model, is the balance coefficient, Represents the MAE loss function, that is, the true value With the predicted value The absolute value error of Represents the reconstruction error, that is, the reconstructed data and The output of the second part of the model The Frobenius norm between is used as the reconstruction error to optimize the reconstruction effect through the gradient descent algorithm. As shown below:
[0176] ,
[0177] in, Representation characteristics The Frobenius norm before and after reconstruction is as follows:
[0178] ,
[0179] in, represents the absolute value of the characteristic element, and It means summing the absolute value elements. and Indicates subscript, and express The size of the first dimension and the size of the second dimension of the feature, Return Matrix The Frobenius norm of ;
[0180] The function looks like this:
[0181] ,
[0182] is the number of data points, It is The actual value of the data point, It is The predicted value of the data point, is the absolute error between the predicted value and the actual value, represents the sum operation, is a subscript, ranging from 1 to n, return and The MAE error.
[0183] (2) Water quality index data from multiple sites Input to the parallel time domain convolution module, Indicates a point in time, Indicates the monitoring point. Represent water quality characteristics, extract temporal information in the time dimension, and process the input through the causal convolution layer;
[0184] Set the size of the convolution kernel of the causal convolution layer to , then the convolution output It is expressed as:
[0185] ,
[0186] here, are the elements of the output tensor, Represents an index, represents the sum operation; The corresponding channel The convolution kernel of elements, index The characteristic of causal convolution is guaranteed, that is, the information at the current moment only depends on the information at the previous moment;
[0187] Convolution output As time domain data Y, it is input into the subsequent parallel sparse graph neural network construction module.
[0188] (3) Water quality index data from multiple sites Input to the sparse graph neural network construction module,
[0189] A1) First pass The algorithm is based on the distance between time series and is used for multi-site water quality index data. ,
[0190] in, Indicates a point in time, Indicates the monitoring point. Indicates water quality characteristics,
[0191] Calculate the mean and standard deviation , and perform standardization:
[0192] ,
[0193] ,
[0194] ,
[0195] in, Represents a sum operation, which means The elements in are summed up, Indicates time step, Indicates nodes, represents the square root operation, It is Time step, The features corresponding to the nodes are Indicates the use of the calculated mean and standard deviation right The results obtained by standardization;
[0196] A2) For each node Time series, calculate the daily mean , using the fast dynamic time warping algorithm to calculate any two nodes and The distance between , the formula is as follows:
[0197] ,
[0198] in, yes The Euclidean distance of Indicates A point in time, express Middle The value at a time point, for Middle The value at a time point, Indicates taking the minimum value;
[0199] A3) For each time step ,calculate and The local Euclidean distance between them and construct a cumulative distance matrix , the formula is as follows:
[0200] ,
[0201] ,
[0202] in Representation Node and The cumulative distance of express The value at the first time point in for The value at the first time point in For and The Euclidean distance between them is used to accumulate the distance matrix Initialization of
[0203] A4) Calculate the minimum cumulative distance on the path using the following constraints ,
[0204] ,
[0205] in, return and The Euclidean distance between
[0206] express , , The minimum value in ;
[0207] A5) Find the optimal path through step A4) and calculate , and finally get matrix.
[0208] (4) Physical topology adjacency matrix Perform spectral clustering and divide into cluster; for each cluster , apply the minimum spanning tree algorithm to get the adjacency matrix , and the final sparse physical topology adjacency matrix is obtained through the following transformation formula :
[0209]
[0210] here, and Represents two sites, → Indicates the site To site , express Middle site To site physical distance, and same.
[0211] (5) The construction of the multivariate sparse causal graph in the sparse graph neural network construction module running in parallel. The specific steps are as follows:
[0212] B1) In the sparse graph neural network construction module, a learnable multivariate sparse causal graph is established for the time domain data Y output by the time domain convolution module , Indicates a A two-dimensional matrix, Indicates the number of characteristic dimensions of water quality data in the model, The elements satisfy , the specific construction formula is as follows:
[0213] ,
[0214] ,
[0215] here, Indicates that the embedding operation is through a fully connected layer. It represents the number of nodes in the causal graph, that is, the number of characteristic dimensions of water quality data in the model. Represents when building a causal graph and The number of column components of
[0216] B2) Yes and After linear transformation, the weighted parameters To zoom, , tanh is the hyperbolic tangent function, used to add nonlinearity,
[0217]
[0218]
[0219] here, represents a linear layer;
[0220] B3) By calculation To capture and The interaction information between them is then combined through activation functions to form the final sparse multivariate causal graph.
[0221] ,
[0222] ,
[0223] here, represents the activation function, Representation Matrix The transpose of Representation Matrix The transpose of express and The intermediate variables of the operation, Represents the generated multivariate sparse causal graph.
[0224] (6) The second part of the model is based on the multi-hop propagation Neural ODE module. The steps are as follows:
[0225] C1) The sparse physical topology adjacency matrix is expressed as , the multivariate sparse causal graph is represented as , first of all Perform self-join and normalize to get ,in Represents a diagonal matrix. For the matrix , The diagonal elements of yes Midpoint The degree of for ;
[0226] Based on the traditional graph convolution operation, the Mix-Hop Propagation mechanism is introduced. The mechanism is as follows:
[0227] ,
[0228] ,
[0229] here, represents the maximum depth of propagation, is a hyperparameter that controls the degree of state preservation of the source node. get:
[0230] ,
[0231] in, represents the weight of the first layer of accumulated state, represents the weight of the second layer’s accumulated state, Indicates The weight of the layer's accumulated state, is a hyperparameter that controls the degree of state preservation of the source node. An index representing the propagation depth, represents the sparse physical topology adjacency matrix after self-connection and normalization, represents the summation symbol, is the index, ranging from 0 to , Representation Matrix of Power;
[0232] C2) By sharing weights, i.e., fixed , , for , the final cumulative propagation matrix is:
[0233] ,
[0234] in, represents the maximum depth of propagation, Depth index representing graph propagation; represents the sum operation, Representation Matrix of Power;
[0235] C3) Based on the time domain data obtained in step (2) , the normalized sparse physical topology adjacency matrix And the normalized multivariate sparse causal graph , we get the improved Neural Ordinary Differential Equation, which is expressed as follows:
[0236] ,
[0237] in, represents the characteristics of the t-th step, express Relative to time The derivative of represents the normalized multivariate sparse causal graph, Represents normalized matrix; express and Operations on the second and third dimensions of matrices, represents the shared learnable coefficient matrix, represents the sum operation, represents the maximum depth of propagation, Represents the current propagation depth index of the graph, ranging from 0 to , represents the normalized sparse physical topology adjacency matrix, express of Power;
[0238] C4) Pass In Kulai solves the deep neural ordinary differential equations to obtain the spatial representation of the target prediction time step .
[0239] (7) The third part of the model is a feature reconstruction module based on the self-attention mechanism. The model structure is as follows Figure 3 As shown, the steps are as follows:
[0240] D1) The spatial representation obtained by solving the improved Neural Ordinary Differential Equation After position encoding, , the specific steps are:
[0241] ,
[0242] Among them, pos represents the position of the spatial representation T, represents the spatial representation T Dimensions, is the embedding dimension, Represented as an even-numbered position representation, represents the representation at odd positions, represents the sine function, represents the cosine function;
[0243] D2) The feature reconstruction module based on the self-attention mechanism uses the self-attention mechanism to reconstruct the position-encoded features. The time domain information is processed to obtain the feature output corrected by self-attention, which is expressed as follows:
[0244] ,
[0245] in, represents the feature after position encoding, Indicates that the layer normalization operation is performed on the input features. Represented as a self-attention mechanism operation;
[0246] The specific operation of the self-attention mechanism is as follows:
[0247] D21) will be for input , we map the input to a query by a linear transformation ,key Sum :
[0248]
[0249] in, is the learned weight matrix, For the general pass The transformed query matrix, For the general pass The transformed key matrix, For the general pass The transformed value matrix;
[0250] D22) Then calculate the query matrix and key matrix The dot product of and scales, then applies The function gets the attention weight:
[0251] ;
[0252] here is the dimension of the key, used to prevent the dot product value from being too large; Represented as the feature after the self-attention mechanism operation, The function is expressed as:
[0253] ,
[0254] in, represents the input features, express Middle elements, Returns the natural constant, based on the number of The value of the power of is the index, from 1 to , n represents the number of elements in z, Returns the sum of all elements in Indicates the converted The value of the component;
[0255] D3) Features after self-attention mechanism processing The layers are normalized again and input into the feedforward neural network, introducing learnable parameters , which forms a diagonal matrix for scaling features of different dimensions. The process formula is:
[0256] ,
[0257] in, represents the scaling factor for each dimension, and Indicates the size of the two dimensions of the learnable parameters, Indicated by As the main diagonal element, the other elements are 0. represents a feedforward neural network, which is used to further process features to make them more capable of nonlinear representation. Represents the product operation between matrices.
[0258] (8) The fourth part of the model is the fully connected layer, which has the following steps:
[0259] E1) When the The third part of the model is based on the reconstruction module output of the self-attention mechanism The time domain convolution module, the neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism are input again in sequence. After repeating steps (2) to (7), the obtained features are passed through the fully connected layer to obtain the prediction results.
[0260] (9) Yes Model training uses the Adam optimizer to perform gradient descent algorithm combined with the approximate point gradient descent algorithm strategy to train the model, as follows:
[0261] F1) The model updates the network parameters in the time domain convolution module, the multi-hop propagation-based neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm according to the requirements of the loss function. :
[0262] Calculate the gradient: loss function Perform gradient calculation to obtain the parameters Gradient; parameter update: then given the gradient In the case of , update the specific parameters of the module in 512):
[0263] ,
[0264] represents the predicted value, represents the true value, represents the parameters in the model, which are optimized to minimize the loss function; represents the parameters of the multivariate sparse causal graph, represents the learning rate, Represents the loss function about The gradient of express minus The value of
[0265] F2) Perform local operation to process the parameters of each module in F1) Regularization is used to ensure the sparsity of the multivariate sparse causal graph, and soft threshold processing is performed on the multivariate sparse causal graph parameters in the sparse graph neural network construction module:
[0266] ,
[0267] here, , Representation characteristics The index of represents the parameters after sparseness, represents a symbolic function, output The symbol, represents the threshold, reflecting the strength of the sparsity constraint. Returns the maximum value between the two. return The maximum value between 0 and Representation Elements The absolute value of
[0268] F3) Iterate the model from steps F1) to F2) through the training set and use the validation set and early stopping method to avoid overfitting of the model until the model converges, and finally obtain the trained prediction model.
[0269] The fifth step is to obtain the water quality prediction results: the water quality indicators detected by each detection station in the water area and the physical topological adjacency matrix of each station are crawled through the crawler algorithm, and the missing values of the water quality indicator data are filled using the Lagrange interpolation method. The filled water quality indicators and physical topological adjacency matrix are input into the trained Model for real-time water quality prediction.
[0270] An efficient water quality prediction model is trained using multi-site water quality index data and physical topology adjacency matrix. The specific process is as follows: First, all samples are divided into training set, validation set and test set in a ratio of 6:2:2 to ensure that the model has sufficient learning, verification and testing capabilities. In the prediction task, the input step size is set to 16 steps for prediction. Our model optimization uses the Adam optimizer, combined with the approximate point gradient descent and gradient descent strategies to improve the training effect. The batch size is 32, which ensures the balance between training speed and memory usage. The internal structure of the model contains two stacked blocks, each of which consists of a parallel-running time domain convolution module, a parallel-running sparse graph neural network construction module, a multi-hop propagation-based neural ordinary differential equation, and a reconstruction module based on the self-attention mechanism. In terms of hyperparameter settings, we set the number of training iterations to 150, the learning rate to 0.0005, and the dropout rate to 0.2 to prevent overfitting. In the validation stage, the prediction results are fine-tuned based on the data of the validation set to determine the best parameter settings. Finally, the optimized parameters were used to predict the test set to comprehensively evaluate the actual performance of the model. Through these strategies, we achieved more accurate and stable water quality prediction capabilities, ensuring that the model performed well in practical applications.
[0271] The present invention illustrates the accuracy, effectiveness and advantages of the present invention compared with other models from the perspective of the test set test results. In the performance analysis of the proposed model, several models were used for comparative analysis, among which GNN-LSTM combines graph neural network (GNN) and long short-term memory network (LSTM), where GNN is used to capture spatial relationships and LSTM processes time series data, which is suitable for the prediction of spatiotemporal data. The multivariate time series graph neural network model (MTGNN) is a multi-task learning graph neural network that shares information between different locations and learns the relationship between each monitoring point, which is suitable for simultaneous prediction of multiple locations. The spatiotemporal graph ordinary differential equation model (STODE) is based on spatiotemporal differential equations, and describes the dynamic changes of data through mathematical equations, which is suitable for processing complex spatiotemporal data. .
[0272] from Figure 4The prediction effects of different models at the Zhongmiao monitoring point can be seen in the figure. The following is an analysis of the prediction curve: In the figure, the Prediction curve represents the prediction results of the model we proposed. As can be seen from the figure, our model performs well in capturing the overall trend and key fluctuation points, and can accurately track the changes in actual data, especially at the peaks and troughs of the data, showing strong stability and accuracy. In contrast, other models have certain shortcomings in the prediction process. For example, (Figure Long Short-Term Memory Network) GNN-LSTM is prone to lag or advance in some areas with drastic fluctuations; although MTGNN is relatively stable in capturing overall trends, it is not as sensitive as our model in detail changes; and when the data changes drastically, STODE has a smoother prediction curve and may miss some detailed fluctuations. These comparisons show the significant advantages of our proposed model in taking into account both global trends and local details.
[0273] Next, we will analyze the prediction results of the proposed model and the comparison model at different sites. In order to illustrate the robustness of the prediction effect of the proposed model at different locations, Figure 5 The performance of different models at the Zhaohe site is given, and the prediction curves of different models at the Zhaohe monitoring point are shown, including the model we proposed. As can be seen from the figure, the prediction results of each model are very close in most of the time period, but there is a significant differentiation at the end of the figure, especially at the sudden drop point. In terms of trend similarity, until the sudden drop at the end, the prediction curves of all models (including our model) overlap closely, indicating that the model prediction capabilities are comparable under normal fluctuations. In terms of the ability to cope with sudden changes, at the end of the figure, the data suddenly drops to a level close to zero. Compared with other models, our model shows a faster response speed and can quickly adjust the prediction to adapt to this drastic change. However, the predictions of other models before the sudden change are very close to our model, but when the sudden change occurs, they fail to adjust the predicted values in time, which may indicate that these models are not adaptable and responsive enough to extreme events.
[0274] Table 3 provides a performance comparison of different models in terms of RMSE (root mean square error), MSE (mean square error) and MAE (mean absolute error). Figure 6A visual comparison of indicators was conducted. At the same time, the statistics and machine learning methods of ARIMA and RandomForest were introduced. ARIMA (Autoregressive Integrated Moving Average) is a time series forecasting tool suitable for data with linear trends. It stabilizes data through differences and combines autoregression and moving average to predict future values. Random Forest is an ensemble learning algorithm based on multiple decision trees for classification and regression tasks. This model improves the accuracy and stability of predictions by averaging the results of multiple decision trees, and can effectively handle large-scale and complex data sets.
[0275]
[0276] To more fully compare the performance differences of the proposed model with other models, I will analyze the percentage of performance improvement compared with several other major models: In terms of RMSE: The RMSE of the proposed model is 2.35, compared with the closest MTGNN model (3.05), the higher LSTM-GNN model (5.01), and the baseline ARIMA model (6.10): about 23% lower than MTGNN. About 53% lower than LSTM-GNN. About 61% lower than ARIMA. In terms of MSE, the MSE of the proposed model is 5.52, compared with MTGNN (9.29), LSTM-GNN (25.05), and ARIMA (37.24): about 41% lower than MTGNN. About 78% lower than LSTM-GNN. About 85% lower than ARIMA. In terms of MAE, the MAE of the proposed model is 1.59, which is about 30% lower than MTGNN (2.26), LSTM-GNN (4.23), and ARIMA (4.59). It is about 62% lower than LSTM-GNN, and about 65% lower than ARIMA.
[0277] These comparative data show that the proposed model not only significantly outperforms the closest competing model MTGNN in all major performance indicators, but also has a clear performance advantage over other models. The significant reduction in mean square error and mean absolute error is particularly prominent, which proves the model's excellent performance in accuracy and stability, making it a strong choice for processing complex and dynamic data. This performance improvement is particularly important for application scenarios that require extremely high accuracy.
[0278] The model described in the present invention shows obvious advantages in dealing with emergencies, and can identify and adapt to extreme changes more quickly, which is very important in practical applications, especially in situations where highly accurate predictions are required. This performance shows that our model architecture and training method may be more efficient in capturing mutation dynamics. Although other models perform well under normal conditions, their performance under extreme conditions needs to be improved. This comparison helps to further optimize the model design and improve the adaptability and robustness of the model.
[0279] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions only describe the principles of the present invention. The present invention may be subject to various changes and improvements without departing from the spirit and scope of the present invention. These changes and improvements fall within the scope of the present invention. The scope of protection claimed by the present invention is defined by the attached claims and their equivalents.
Claims
1. A multi-site water quality prediction method based on spatiotemporal feature fusion, characterized in that: The following steps are involved: 11) Acquisition and preprocessing of basic water quality data at multiple sites: Acquire water quality data within the basin and the physical topological adjacency matrix between sites and perform preprocessing; 12) Feature screening of water quality data in water areas: Use Pearson correlation coefficient and mutual information coefficient to screen the features in regional water quality data to obtain multi-site water quality index data; 13) Build Model: It is constructed using a sparse graph neural network construction module, a time domain convolution module, a multi-hop propagation-based neural ordinary differential equation, and a feature reconstruction module based on a self-attention mechanism. Model; The construction The model consists of the following steps: 131) Settings The first part of the model is a sparse graph neural network construction module and a time domain convolution module that run in parallel; The input of the time domain convolution module is the multi-site water quality index data or the reconstructed time representation. The time domain convolution module is composed of a TCN module, which consists of 4 convolution layers, using a small kernel of size 2. The expansion factors of the 4 convolution layers are 1, 2, 4, and 8 respectively. Each layer uses the LeakyReLU activation function with a Dropout rate of 0.
2. The time domain convolution module converts the multi-site water quality index data into time domain data, and outputs the time domain data to the parallel sparse graph neural network construction module and the multi-hop propagation based neural ordinary differential equation. The input of the parallel sparse graph neural network construction module is the time domain data output by the parallel time domain convolution module, the physical topology adjacency matrix and the multi-site water quality index data; Construct a sparse physical topology adjacency matrix: Use the K-Means clustering algorithm and the size of the elements in the physical topology adjacency matrix as the criterion to cluster the physical topology adjacency matrix into 5 clusters. For each cluster, use the minimum spanning tree algorithm to generate the minimum spanning tree adjacency matrix between clusters. Merge the adjacency matrices of the minimum spanning trees of the 5 clusters to obtain a sparse physical topology adjacency matrix. The input multi-site water quality index data is used to obtain the DTW graph using the DTW algorithm; By constructing two learnable vector parameters and performing the matrix product operation of the two vectors, a multivariate sparse causal graph is constructed for the time domain data output by the parallel-running time domain convolution module. The sparsity of the multivariate sparse causal graph is achieved through the approximate point gradient descent algorithm. The obtained sparse physical topology adjacency matrix, DTW graph, and multivariate sparse causal graph are provided to the neural ordinary differential equation based on multi-hop propagation. 132) Settings The second part of the model is a multi-hop propagation based neural ordinary differential equation, the input is The first part of the model runs in parallel the time domain data output by the time domain convolution module and the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph output by the sparse graph neural network construction module; The process of water quality propagation is modeled interpretably by constructing a neural ordinary differential equation: the Mix-Hop Propagation mechanism is introduced in the process of propagation on the sparse physical topological adjacency matrix of time domain data. The traditional graph convolution operation is transformed into a cumulative propagation matrix The multi-hop propagation operation is constructed by constructing the multi-hop propagation neural ordinary differential equation modeled from multiple perspectives, including the DTW graph, sparse physical topology adjacency matrix, and multivariate sparse causal graph. Then, the neural network is constructed using the Pytorch deep learning framework. The library is used to solve the problem and obtain the spatial representation, which is then passed to the feature reconstruction module based on the self-attention mechanism. 133) Settings The third part of the model is the feature reconstruction module based on the self-attention mechanism. The input of the feature reconstruction module is The second part of the model outputs the spatial representation, which is first processed by position encoding, and then corrected by the self-attention mechanism to obtain the spatial representation after position encoding ;right Perform layer normalization and input into the feedforward neural network to obtain a new spatial representation , by introducing a learnable rank vector , as a matrix The main diagonal elements of ; the reconstructed feature representation is ,in Represents the matrix multiplication operation; it is measured using the reconstruction loss based on the Frobenius norm. and The reconstruction error between the spatial representations output by the second part of the model is used to optimize the parameters of the network in the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm, and the reconstructed temporal representation is used as the input of the subsequent fully connected layer; 134) Settings The fourth part of the model is the fully connected layer, and the features reconstructed from the third part enter The first part of the model is processed by the second and third parts, and finally passes through the fully connected layer to obtain the prediction result; 14) Model training: Using multi-site water quality index data, the gradient descent algorithm is used to optimize the parameters of the time domain convolution module, the multi-hop propagation based neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism. The approximate point gradient descent algorithm is used to constrain and optimize the sparsity of the parameters of the multivariate sparse causal graph in the sparse graph neural network construction module. The gradient descent algorithm and the approximate point gradient descent algorithm are executed alternately until the model converges; 15) Obtaining water quality prediction results: The water quality indicators detected by each detection station in the water area and the physical topological adjacency matrix of each station are crawled through the crawler algorithm, and the missing values of the water quality indicator data are filled using the Lagrange interpolation method. The filled water quality indicators and physical topological adjacency matrix are input into the trained Model for real-time water quality prediction.
2. The multi-site water quality prediction method based on spatiotemporal feature fusion according to claim 1 is characterized in that: The acquisition and preprocessing of the multi-site water quality basic data includes the following steps: 21) Use the crawler algorithm to extract the water quality time series information and longitude and latitude information of each monitoring point in the basin and save it as document; 22) Use In Packet Reading File, and use Lagrange interpolation method to fill the missing values in the water quality time series; 23) Convert two-dimensional water quality data Convert to 3D data ,here Indicates a point in time, Indicates the monitoring point. Represents water quality characteristics and is saved as files, called water quality data for watersheds; 24) According to the longitude and latitude of each site, the physical topological adjacency matrix between each site is calculated using the Haversine formula and saved as an Excel file. The Haversine formula is as follows: , , , in, represents the sine function, represents the cosine function, represents the inverse tangent function, , are the latitudes of the two points in radians; is the difference in latitude between two points; is the difference in longitude between two points; is the radius of the Earth, The angle that represents the geodesic arc, that is, the arc distance between two points on the Earth's surface. is an intermediate calculated variable that combines the sine and cosine of the latitude and longitude difference in order to represent the angular difference between the two locations, By calculation and The product of the two gets the distance between the two sites.
3. The multi-site water quality prediction method based on spatiotemporal feature fusion according to claim 1 is characterized in that: The feature screening of water quality data in the water area comprises the following steps: 31) Using Python Packet Reading File, remove the water temperature feature and ammonia nitrogen feature from the water quality indicators of the water quality data of the water area; 32) Calculate the maximum mutual information coefficient of water quality indicators of each monitoring station and other monitoring stations, and screen out the algae density feature based on the significantly low mutual information between the algae density feature and other features; screen out the eight characteristics of predicting water quality indicators, including dissolved oxygen, pH value, permanganate index, total phosphorus, total nitrogen, conductivity, turbidity, and chlorophyll, to obtain the final multi-station water quality indicator data.
4. The multi-site water quality prediction method based on spatiotemporal feature fusion according to claim 1 is characterized in that: Said The training of the model consists of the following steps: 51) Setting the optimization objective function consists of two parts as follows: , in, is the true value, is the predicted value, express The network parameters of the model, Indicated as setting The multivariate sparse causal graph in the sparse graph neural network construction module running in parallel in the first part of the model, is the balance coefficient, Represents the MAE loss function, that is, the true value With the predicted value The absolute value error of Represents the reconstruction error, that is, the reconstructed data and The output of the second part of the model The Frobenius norm between is used as the reconstruction error to optimize the reconstruction effect through the gradient descent algorithm. As shown below: , in, Representation characteristics The Frobenius norm before and after reconstruction is as follows: , in, represents the absolute value of the characteristic element, and It means summing the absolute value elements. and Indicates subscript, and express The size of the first dimension and the size of the second dimension of the feature, Return Matrix The Frobenius norm of ; The function looks like this: , is the number of data points, It is The actual value of the data point, It is The predicted value of the data point, is the absolute error between the predicted value and the actual value, represents the sum operation, is a subscript, ranging from 1 to n, return and MAE error; 52) Multi-site water quality index data Input to the parallel time domain convolution module, Indicates a point in time, Indicates the monitoring point. Represent water quality characteristics, extract temporal information in the time dimension, and process the input through the causal convolution layer; Set the size of the convolution kernel of the causal convolution layer to , then the convolution output It is expressed as: , here, are the elements of the output tensor, Represents an index, represents the sum operation; The corresponding channel The convolution kernel of elements, index The characteristic of causal convolution is guaranteed, that is, the information at the current moment only depends on the information at the previous moment; Convolution output As time domain data Y, it is input into the subsequent parallel sparse graph neural network construction module; 53) Multi-site water quality index data Input to the sparse graph neural network construction module, 531) First pass The algorithm is based on the distance between time series and is used for multi-site water quality index data. , in, Indicates a point in time, Indicates the monitoring point. Indicates water quality characteristics, Calculate the mean and standard deviation , and perform standardization: , , , in, Represents a sum operation, which means The elements in are summed up, Indicates time step, Indicates nodes, represents the square root operation, It is Time step, The features corresponding to the nodes are Indicates the use of the calculated mean and standard deviation right The results obtained by standardization; 532) For each node Time series, calculate the daily mean , using the fast dynamic time warping algorithm to calculate any two nodes and The distance between , the formula is as follows: , in, yes The Euclidean distance of Indicates A point in time, express Middle The value at a time point, for Middle The value at a time point, Indicates taking the minimum value; 533) For each time step ,calculate and The local Euclidean distance between them and construct a cumulative distance matrix , the formula is as follows: , , in Representation Node and The cumulative distance of express The value at the first time point in for The value at the first time point in For and The Euclidean distance between them is used to accumulate the distance matrix Initialization of 534) The following constraints are used to calculate the minimum cumulative distance on the path , , in, return and The Euclidean distance between express , , The minimum value in ; 535) Find the optimal path through step 534) and calculate , and finally get matrix; 54) Physical topology adjacency matrix Perform spectral clustering and divide into cluster; for each cluster , apply the minimum spanning tree algorithm to get the adjacency matrix , and the final sparse physical topology adjacency matrix is obtained through the following transformation formula : ‘ here, and Represents two sites, → Indicates the site To site , express Middle site To site physical distance, and same; 55) The construction of multivariate sparse causal graph in the parallel running sparse graph neural network construction module is as follows: 551) In the sparse graph neural network construction module, a learnable multivariate sparse causal graph is established for the time domain data Y output by the time domain convolution module , Indicates a A two-dimensional matrix, Indicates the number of characteristic dimensions of water quality data in the model, The elements satisfy , the specific construction formula is as follows: , , here, Indicates that the embedding operation is through a fully connected layer. It represents the number of nodes in the causal graph, that is, the number of characteristic dimensions of water quality data in the model. Represents when building a causal graph and The number of column components of 552) Yes and After linear transformation, the weighted parameters To zoom, , tanh is the hyperbolic tangent function, used to add nonlinearity, , , here, represents a linear layer; 553) By calculation To capture and The interaction information between them is then combined through activation functions to form the final sparse multivariate causal graph. , , here, represents the activation function, Representation Matrix The transpose of Representation Matrix The transpose of express and The intermediate variables of the operation, Represents the generated multivariate sparse causal graph; 56) The second part of the model is based on the multi-hop propagation Neural ODE module. The steps are as follows: 561) The sparse physical topology adjacency matrix is represented as , the multivariate sparse causal graph is represented as , first of all Perform self-join and normalize to get ,in Represents a diagonal matrix. For the matrix , The diagonal elements of yes Midpoint The degree of for ; Based on the traditional graph convolution operation, the Mix-Hop Propagation mechanism is introduced. The mechanism is as follows: , , here, represents the maximum depth of propagation, is a hyperparameter that controls the degree of state preservation of the source node. get: , in, represents the weight of the first layer of accumulated state, represents the weight of the second layer’s accumulated state, Indicates The weight of the layer's accumulated state, is a hyperparameter that controls the degree of state preservation of the source node. An index representing the propagation depth, represents the sparse physical topology adjacency matrix after self-connection and normalization, represents the summation symbol, is the index, ranging from 0 to , Representation Matrix of Power; 562) By sharing weights, i.e., fixing , , for , and obtain the final cumulative propagation matrix for: , in, represents the maximum depth of propagation, Depth index representing graph propagation; represents the sum operation, Representation Matrix of Power; 563) According to the time domain data obtained in step 52) , the normalized sparse physical topology adjacency matrix And the normalized multivariate sparse causal graph , we get the improved Neural Ordinary Differential Equation, which is expressed as follows: , in, represents the characteristics of the t-th step, express Relative to time The derivative of represents the normalized multivariate sparse causal graph, Represents normalized matrix; express and Operations on the second and third dimensions of matrices, represents the shared learnable coefficient matrix, represents the sum operation, represents the maximum depth of propagation, Represents the current propagation depth index of the graph, ranging from 0 to , represents the normalized sparse physical topology adjacency matrix, express of Power; 564) Pass In Kulai solves the deep neural ordinary differential equations to obtain the spatial representation of the target prediction time step ; 57) The third part of the model is the feature reconstruction module based on the self-attention mechanism. The steps are as follows: 571) The spatial representation obtained by solving the improved Neural Ordinary Differential Equation After position encoding, , the specific steps are: , Among them, pos represents the position of the spatial representation T, represents the spatial representation T Dimensions, is the embedding dimension, Represented as an even-numbered position representation, represents the representation at odd positions, represents the sine function, represents the cosine function; 572) The feature reconstruction module based on the self-attention mechanism uses the self-attention mechanism to reconstruct the position-encoded features. The time domain information is processed to obtain the feature output corrected by self-attention, which is expressed as follows: , in, represents the feature after position encoding, Indicates the layer normalization operation on the input features. Represented as a self-attention mechanism operation; The specific operation of the self-attention mechanism is as follows: 5721) will be for input , we map the input to a query by a linear transformation ,key Sum : ’ in, is the learned weight matrix, For the general pass The transformed query matrix, For the general pass The transformed key matrix, For the general pass The transformed value matrix; 5722) Then calculate the query matrix and key matrix The dot product of and scales, then applies The function gets the attention weight: ; here is the dimension of the key, used to prevent the dot product value from being too large; Represented as the feature after the self-attention mechanism operation, The function is expressed as: , in, represents the input features, express Middle elements, Returns the natural constant, based on the number of The value of the power of is the index, from 1 to , n represents the number of elements in z, Returns the sum of all elements in Indicates the converted The value of the component; 573) Features after self-attention mechanism processing The layers are normalized again and input into the feedforward neural network, introducing learnable parameters , this parameter forms a diagonal matrix for scaling features of different dimensions, and the process formula is: , in, represents the scaling factor for each dimension, and Indicates the size of the two dimensions of the learnable parameters, Indicated by As the main diagonal element, the other elements are 0. represents a feedforward neural network, which is used to further process features to make them more capable of nonlinear representation. Represents the product operation between matrices; 58) The fourth part of the model is the fully connected layer, which has the following steps: 581) When the The third part of the model is based on the reconstruction module output of the self-attention mechanism The time domain convolution module, the neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism are input again in sequence. After repeating steps 52) to 57), the obtained features are passed through the fully connected layer to obtain the prediction result; 59) Yes Model training uses the Adam optimizer to perform gradient descent algorithm combined with the approximate point gradient descent algorithm strategy to train the model, as follows: 591) The model updates the network parameters in the time domain convolution module, the multi-hop propagation-based neural ordinary differential equation, and the feature reconstruction module based on the self-attention mechanism through the gradient descent algorithm according to the requirements of the loss function. : Calculate the gradient: loss function Perform gradient calculation to obtain the parameters Gradient; parameter update: then given the gradient In the case of , update the specific parameters of the module in 512): , represents the predicted value, represents the true value, represents the parameters in the model, which are optimized to minimize the loss function; represents the parameters of the multivariate sparse causal graph, represents the learning rate, Represents the loss function about The gradient of express minus The value of 592) When the parameters of each module in 591) are fixed, perform local operations to process Regularization is used to ensure the sparsity of the multivariate sparse causal graph, and soft threshold processing is performed on the multivariate sparse causal graph parameters in the sparse graph neural network construction module: , here, , Representation characteristics The index of represents the parameters after sparseness, represents a symbolic function, output The symbol, represents the threshold, reflecting the strength of the sparsity constraint. Returns the maximum value between the two. return The maximum value between 0 and Representation elements The absolute value of 593) The model is iterated from steps 591) to 592) through the training set and the validation set and early stopping method are used to avoid overfitting of the model until the model converges, and finally the trained prediction model is obtained.
Citation Information
Patent Citations
River water quality prediction method based on graph convolution STG-LSTM
CN114676887A
Basin multi-site water quality space-time prediction method based on space-time diagram convolutional network
CN118940886A