Water quality index prediction method based on Patch Savitsky-Golay filtering and Transform model

By combining Patch Savitsky-Golay filtering and Transformer model water quality index prediction methods, the problems of insufficient prediction capabilities and high computing resources in the process of complex time series data are solved, and more accurate and efficient water quality prediction is achieved, supporting Scientific water resource management.

CN119249079APending Publication Date: 2025-01-03BEIJING UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411282952.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

Existing water quality prediction methods have limited prediction capabilities when processing complex nonlinear and non-stationary time series data, especially when processing large-scale data sets, with low data quality and weak generalization capabilities, and high computing resource requirements. .

Method used

Using a method combining Patch Savitsky-Golay filtering and Transformer model, the water quality data is missed, normalized, and filtered, and the learning position embedding and feedforward network are used to predict, output the predicted value and reverse normalization. to achieve accurate prediction of water quality indicators.

Benefits of technology

It improves the accuracy and generalization ability of water quality prediction, reduces the demand for computing resources, can process large-scale data sets more effectively, and provides more scientific water resource management strategies and water environmental protection support.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119249079A_ABST
    Figure CN119249079A_ABST
Patent Text Reader

Abstract

The invention provides a water quality index prediction model based on the combination of Patch Savitsky-Golay filtering and Transform, and relates to a water quality index prediction model based on the combination of Patch Savitsky-Golay filtering and Transform. The method comprises the following steps: firstly, dividing a water quality time sequence into a plurality of subsequences by using a sliding window technology so as to capture the inherent trend and semantic information of the sequence; on the basis, denoising is carried out on the subsequences through a Savitsky-Golay filter, so that the signal-to-noise ratio is improved, and the quality of water quality sequence data is ensured. And finally, introducing a Transform module, and processing the nonlinear characteristic of the time sequence by using a self-attention mechanism of the Transform module, thereby enhancing the capturing capability of the model on the long-term dependency relationship of the sequence. The above strategy effectively improves the precision and reliability of water quality index prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a prediction method for water quality indicators, in particular to a prediction method for water quality indicators based on PatchSavitsky-Golay filtering and a Transformer model. Background Art

[0002] The health of the water environment is directly related to human health and ecological balance. In today's era, with the rapid development of science and technology, water quality monitoring and prediction are gradually becoming intelligent. By using advanced information technologies such as big data, artificial intelligence, cloud computing and the Internet of Things, we can make more accurate predictions and analyses of water quality changes. The application of these technologies enables us to monitor water quality indicators in real time and predict potential trends in water quality changes, so as to take preventive measures in advance and reduce the risk of water environment pollution. In the field of water quality prediction, complex water quality prediction models can be constructed by analyzing historical data and real-time monitoring data. These models can identify key factors affecting water quality, such as industrial emissions, agricultural pollution, climate change, etc., and predict their potential impact on water quality. In addition, by simulating water quality changes under different scenarios, decision makers can develop more scientific and effective water resources management strategies. Water quality prediction not only helps prevent and reduce the occurrence of water pollution incidents, but also provides data support for the rational allocation of water resources, and provides strong technical support for the sustainable use of water resources and the protection of the water environment.

[0003] Existing water quality prediction methods mainly include traditional statistical models, machine learning methods and deep learning techniques. Traditional statistical models use mathematical formulas and statistical principles to predict future changes in water quality indicators by analyzing historical data. These models work well when dealing with simple linear relationships, but their prediction capabilities are limited when facing complex nonlinear and non-stationary time series data. Machine learning methods, such as support vector machines and random forest algorithms, predict water quality by learning the laws of water quality changes from historical data. They perform well when dealing with medium-sized data sets. However, these methods encounter performance bottlenecks when dealing with large-scale data sets. Deep learning techniques such as convolutional neural networks and recurrent neural networks (RNNs) can more accurately predict water quality changes due to their powerful nonlinear fitting capabilities. The long short-term memory artificial neural network, a variant of RNN, solves the gradient vanishing and explosion problems of traditional RNNs when dealing with long sequence data by introducing a gating mechanism, thereby better capturing the long-term dependencies of time series data. In recent years, the Transformer architecture has attracted attention for its excellent performance in processing sequence data. Transformer can capture long-distance dependencies in sequences through the self-attention mechanism, which performs well in natural language processing and time series analysis. In water quality prediction, the Transformer architecture can process large-scale data sets and provide more accurate prediction results. Although deep learning methods have shown great potential in water quality prediction, challenges such as low data quality, weak model generalization ability, and high computing resource requirements still need to be addressed in practical applications. Summary of the invention

[0004] In view of the above shortcomings of the prior art, the present invention provides a water quality index prediction method integrating Patch Savitsky-Golay filtering and Transformer model. The method comprises the following steps:

[0005] 1) Obtain water quality index data of a river monitored over a period of time;

[0006] 2) Use linear interpolation to complete the missing data in the data;

[0007] 3) Based on 2), the completed data is normalized and divided into training set, validation set and test set.

[0008] 4) Based on 3), the data of the training set is input into the Patch Savitsky-Golay filter.

[0009] 5) Based on 4), the feature sequence is input into the Transformer model and the predicted value is output.

[0010] 6) Based on 5), these predicted values ​​are denormalized to obtain the predicted values ​​of future water quality indicators. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 A schematic diagram of the composition of a water quality index prediction method based on Patch Savitsky-Golay filtering and Transformer model;

[0012] Figure 2 Blocking and filtering operation flow chart;

[0013] Figure 3 A structural diagram of a water quality index prediction method based on Patch Savitsky-Golay filtering and Transformer model. DETAILED DESCRIPTION

[0014] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. The following description covers many specific details in order to provide a comprehensive understanding of the present invention. However, it will be apparent to those skilled in the art that the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is merely to provide a clearer understanding of the present invention by illustrating examples of the present invention. The present invention is by no means limited to any specific configuration and algorithm proposed below, but covers any modification, replacement and improvement of related elements, parts and algorithms without departing from the spirit of the present invention.

[0015] The following will refer to the attached Figure 1 A water quality index prediction method based on Patch Savitsky-Golay filtering and Transformer model according to an embodiment of the present invention is described.

[0016] The first step is to obtain time series data consisting of water quality indicators monitored for a river over a period of time.

[0017] Since the actual monitoring frequency of the water quality automatic monitoring system is usually once every 4 hours, in the data preprocessing stage, the water quality parameter data is screened and uniformly adjusted to data with equal intervals of 4 hours. For missing data, the interpolation method is used to fill in the data.

[0018] use represents the value at time t, where F is the number of features of each node. T} represents the time series of water quality collected from, and T represents the number of previous time steps.

[0019] The second step is to normalize, block and filter the time series data, and divide the subsequence data

[0020] Normalize the time series data processed in the previous step. The steps are as follows:

[0021]

[0022] Among them, x * represents the normalized target value, x represents the data to be normalized, and x min Represents the minimum value in the data, x max Represents the maximum value in the data.

[0023] The input sequence X is divided into multiple overlapping patches to obtain its local semantic information. It can be expressed as:

[0024]

[0025] Where N is the number of patches and P is the patch length. The non-overlapping area between two adjacent patches is represented by the step size S. A single patch is represented by To allow all input values ​​to be patched, we repeatedly replace x T The last value of is added to the end of the original sequence.

[0026] The SG filter is used to reduce the noise interference in the patch sequence. The SG filter fits each patch sequence through the linear least squares method, which removes the sequence noise while retaining the trend information of the data. The calculation formula is as follows:

[0027]

[0028] where m and x r+ζ represent the filter window width and the original data points respectively. represents the vector of convolution coefficients, Indicates the filtered result. The SG filter uses C ζ Use the least squares method to estimate the filter window x r+ζ (ζ=1,…,P). x in the window r It is expressed as:

[0029]

[0030] in represents a sequence of integers. k-1 It is obtained by linear least squares method, where k is the polynomial order. ζ The calculation formula is:

[0031] χ=Z·A

[0032]

[0033] C ζ =(Z T ·Z) -1 ·Z T

[0034] in The least squares fitting result is

[0035] The third step is to embed position encoding

[0036] The Transformer model only performs position encoding on each time step of the time series, rather than encoding the entire time series. Therefore, it cannot capture sequence representation, limiting its capacity and generalization ability to different time series data. The present invention uses learnable position embedding to embed the position information of the filtered output. The steps of the process are as follows:

[0037]

[0038] in W represents the position embedding result, which is fed into the transformer. p Represents a position encoding vector. represents a learnable positional encoding that describes the temporal positional order of patches. We map these patches into a D-dimensional latent space using a trainable linear projection.

[0039] The fourth step is to use the model to predict and use the feedforward network to further process the model's predicted data

[0040] After position embedding, the entire sequence Linear projection is used to generate query (Q), key (K), and value (V), which are input into the attention mechanism to facilitate temporal dependency modeling. The attention mechanism is formulated as:

[0041]

[0042] in and D is the input dimension. N Q 、N K 、N V are the embedding token lengths of Q, K, and V respectively. The attention mechanism can be interpreted as a mapping from a set of key-value pairs to the output. Attention is used to obtain multiple representations of the input sequence. The attention mechanism is defined as:

[0043] MultiHead(Q,K,V)=Concat(head1,…,head ζ )W O

[0044] Among them headi =Attention(Q i ,K i ,V i ), W O To learn the parameters.

[0045] The output of the Transformer is then processed using a feedforward network. The feedforward network is defined as:

[0046] FFN(H)=ReLU(HW1+b1)W2+b2

[0047] Where H is the output of Transformer, D r and D f are the dimensions of the model and feedforward network respectively. ReLU is the activation function. Feedforward neural network captures the relationship between input sequences. Residual network avoids the problem of vanishing gradient in long-term sequences. Residual network is defined as:

[0048]

[0049] Among them, FNN() represents the feedforward network, Norm() represents layer normalization, To embed the input sequence, is the output of the residual network. Finally, the prediction value is obtained through the fully connected layer:

[0050]

[0051] With weight W y and b y The linear function of

[0052] Finally, the predicted values ​​are compared with the unprocessed real water quality index values ​​using RMSE, MAE, and MAPE, and the batch size, window size, size of the time convolution residual, and number of graph convolution layers in the water quality prediction model are adjusted to finally obtain the best model. This water quality prediction model can be used to predict water quality indicators such as dissolved oxygen, ammonia nitrogen, and permanganate in different rivers of surface water, and achieve accurate prediction of related water quality indicators, which is convenient for water quality early warning and water pollution control.

[0053] The present invention is a method for predicting water quality indicators based on Patch Savitsky-Golay filtering and Transformer model proposed above. It should be understood that the detailed description of the technical solution of the present invention with the help of the preferred embodiment is illustrative rather than restrictive. A person of ordinary skill in the art can modify the technical solutions described in each embodiment based on reading the specification of the present invention, or replace some of the technical features therein with equivalents, however, these modifications or replacements do not make the essence of the corresponding technical solution deviate from the spirit and scope of the technical solutions of each embodiment of the present invention.

Claims

1. A water quality prediction method based on mixed spatiotemporal features is proposed. This method combines Patch Savitsky-Golay filtering and Transformer model, which is characterized by: The method comprises the following steps: 1) Obtain water quality index data of a river over a period of time, and sort the collected historical water quality data in time series; 2) Normalize the time series data; 3) Patching technology is used to split the time series into multiple subsequences, each of which contains part of the trend and semantic information of the time series; 4) Using Savitsky-Golay filter to denoise these subsequences to enhance the signal-to-noise ratio of the data; 5) Position embedding of the subsequence after filtering; 6) Construct a Transformer model, take the subsequence with embedded position information as input, process the data through a multi-head attention mechanism and a feedforward network, and capture the nonlinear characteristics of the time series; 7) The prediction results are output through the fully connected layer and these results are denormalized to obtain the predicted values ​​of future water quality indicators.

2. The method according to claim 1, characterized in that The water quality prediction model is trained based on the historical water quality time series data, including: Acquire water quality time series data of the target area as historical data; normalize the historical data; divide the normalized historical data into a training set and a test set according to a preset ratio, and train a water quality prediction model based on the historical data of the training set to obtain parameters of the water quality prediction model.

3. The method according to claim 1, characterized in that The predicting of future water quality based on the water quality prediction model includes: Acquire the water quality time series data of the target area within the preset time period before and at the current moment; normalize the water quality time series data of the target area within the preset time period before and at the current moment, and then input the processed data into the water quality prediction model; use the denormalization to process the output data of the water quality prediction model to obtain the water quality prediction data of the target area.

4. The method according to claim 2 and claim 3, characterized in that The water quality prediction model is constructed based on Patch Savitsky-Golay filtering and Transformer model, including: Patching technology is used to divide the time series into multiple subsequences, and the Savitsky-Golay filter is used to denoise these subsequences, and then the position of the filtered subsequences is embedded; a Transformer model is constructed, and the subsequences with embedded position information are taken as input and processed through a multi-head attention mechanism and a feedforward network to build a water quality prediction model.

5. The method according to claim 2, characterized in that: The method of testing and optimizing the water quality prediction model based on the historical data of the test set includes: According to the test results of the water quality prediction model, the batch size, the dimension size of the hidden layer, the number of layers in the model, the number of heads in the multi-head attention mechanism, the length of the block, and the window size of the filter are adjusted to optimize the parameters of the water quality prediction model to achieve accurate prediction results.

6. The method according to claim 2, characterized in that Before the water quality prediction model predicts water quality, it also includes: The preset ratio of data division is changed, and the normalized historical data is re-divided into a training set and a test set according to the changed preset ratio; the water quality prediction model is trained and fine-tuned based on the re-divided historical data of the training set.

7. The method according to claim 4, characterized in that The water quality prediction model based on Patch Savitsky-Golay filtering and Transformer includes: The lengths of the input and output sequences of the prediction model may not be equal; therefore, the length of the input sequence can be adjusted to further optimize the accuracy of the model prediction.