Water quality early warning method based on Informer model
Through the combination of the Informer model and the IsoForest model, the problems of low prediction accuracy and improper threshold setting in traditional water quality early warning methods are solved, and more accurate water quality prediction and sensitive early warning system are realized, which enhances the interpretability and accuracy of the early warning system.
Patent Information
- Application Number
- CN202210026715.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2042-01-11
AI Technical Summary
Traditional water quality early warning methods are difficult to accurately capture long-term laws in time series data, resulting in a decrease in prediction accuracy, and a fixed early warning threshold leads to low sensitivity or excessive alarm problems.
The timing prediction method based on the Informer model is adopted, combined with SG filtering and STL feature decomposition, the threshold is dynamically set using the IsoForest model, and the outlier interpretation is performed in combination with the surface water environmental quality standard GB3838-2002.
It improves the accuracy of water quality prediction, reduces noise interference, enhances the sensitivity and interpretability of the early warning system, and avoids overfitting and over-alarming.
Smart Images

Figure CN114385614B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an early warning method for water quality indicators, and mainly designs a water quality early warning method based on an Informer model. Background Art
[0002] In recent years, with the development of Internet of Things technology, various detection data can be effectively and timely transmitted and analyzed. At the same time, data collection has high frequency, and the scale of data volume is sufficient to meet the application of neural network methods. Time series refers to the sequence of values of the same statistical indicator arranged in the order of their occurrence. There are certain rules between adjacent moments to influence each other. It is difficult for traditional neural networks to capture such long-span key information, resulting in a decrease in prediction accuracy. Although the recurrent neural network can be input into the model for training in the order of data, it is difficult to pay attention to two time series data that are far apart, which affects its prediction accuracy. The neural network model based on the attention mechanism can pay attention to two time series data that are far apart and learn the characteristic relationship between them, greatly improving the prediction accuracy. In the work of water quality early warning, most of the traditional early warning methods set a fixed early warning threshold. If the threshold is set too high, the early warning system will have low sensitivity and affect the emergency treatment of sudden pollution; if the threshold is set too low, the early warning system will frequently alarm and increase unnecessary workload. Accurate prediction of water quality and dynamic setting of thresholds are the technical basis for realizing water quality early warning. Summary of the invention
[0003] In view of the above deficiencies in the prior art, the present invention provides a water quality early warning method based on the Informer model, which includes the following steps: time series prediction based on the Informer model; and early warning threshold calculation based on the isolation forest.
[0004] The objects of the present invention are achieved by the following technologies.
[0005] A water quality early warning method based on an Informer model, the method comprising the following steps:
[0006] Step S1: Obtain the time series data of water quality indicators over a period of time and select one-dimensional water quality features to form two-dimensional time series data consisting of timestamps and specified water quality features, and use polynomial interpolation to fill in the missing values in the two-dimensional data;
[0007] Step S2: Based on step S1, the water quality characteristic data is subjected to SG filtering, smoothing and noise reduction;
[0008] Step S3: Based on step S2, the data after SG processing is input into the Informer model, and the multi-step prediction value of the water quality index is output to obtain the future prediction value of the water quality index;
[0009] Step S4: Based on step S2, the data after SG processing is subjected to STL feature decomposition, which is decomposed into three parts: trend component, seasonal component and residual component, and the seasonal component is eliminated; the timestamp is used as the input of the isolation forest model, and IsoForest is used to model the decomposed multidimensional feature data, and the central deviation degree of the IsoForest non-abnormal point is used as the threshold setting standard of the safety interval;
[0010] Step S5: Based on the future water quality index value obtained in step S3, the STL feature decomposition is performed on it and the seasonal component is eliminated, and an early warning is performed with the safety threshold of IsoForest;
[0011] Step S6: Based on step S5, the abnormal value obtained is combined with the surface water environmental quality standard GB3838-2002 to calculate the water quality grade, and the rationality of the abnormality is explained according to the water quality grade.
[0012] The advantages of the present invention are:
[0013] 1. This method can effectively eliminate data noise by performing SG filtering and smoothing on time series data. On this basis, using Informer's self-attention distillation technology, probabilistic sparse self-attention mechanism and generative decoder as the basic network can increase the training speed, reduce the network's memory overhead, and improve the multi-step prediction accuracy.
[0014] 2. The multi-step prediction results of Informer are decomposed by STL features and the seasonal components are eliminated, which can make the network more focused on learning complex features; and using random forest as anomaly detection model is not prone to overfitting, and multiple decision trees are independent of each other during training, which performs better in speed and accuracy; on this basis, the present invention combines the surface water environmental quality standard GB3838-2002 to interpret the outliers, and has better interpretability when applied to the water quality early warning system. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 Schematic diagram of the conceptual framework of water quality early warning method based on the Informer model;
[0016] Figure 2 SG filtering flow chart;
[0017] Figure 3 STL feature decomposition diagram. DETAILED DESCRIPTION
[0018] 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. 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.
[0019] The following will refer to the attached Figure 1 The specific steps of describing a water quality early warning method based on the Informer model according to an embodiment of the present invention are as follows:
[0020] The first step is to obtain the time series data of water quality indicators over the past period of time, because the monitoring frequency of the automatic water quality monitoring system is usually once every four hours; then obtain the characteristic variables that have a greater impact on the early warning indicators. Here, dissolved oxygen is selected as the characteristic variable that affects the water quality; for the missing values in the monitoring data, polynomial interpolation is used to fill them. The specific method of polynomial interpolation is as follows:
[0021] Given a set of n+1 data points (x i ,y i ), where any two x i are all different, and we need to find a p-order polynomial that satisfies the order no greater than n:
[0022] p(x i )=y i ,i=0,...,n,
[0023] Assume that the interpolation polynomial is of the form:
[0024] p(x)=a n x n +a n-1 x n-1 +…+a2x 2 +a1x+a0,
[0025] The meaning of interpolating data points is:
[0026] p(x i )=y i for all ini∈{0,1,...,n}.
[0027] Solve for a0,a1,...,a n p(x) can be used for interpolation to supplement the missing values.
[0028] In the second step, the time series data of water quality indicators are preprocessed using SG filtering.
[0029] Since there may be noise points in the data, it often leads to overfitting of nonlinear models. By using the SG method to smooth and filter the original data and reduce the interference of noise, the overfitting of nonlinear models can be effectively suppressed. Figure 2 The following is a flow chart of the implementation method of SG filtering. The principle of SG filtering is as follows:
[0030] The SG smoothing filter algorithm is an improvement on the moving smoothing algorithm. Using the SG smoothing filter while keeping the shape and length of the original data unchanged will improve the smoothness of the time series and reduce the interference of noise. The core idea is to perform weighted filtering on the data in the window, but its weighted weight is obtained by least squares fitting of a given high-order polynomial. Filter a total of 2n+1 observations before and after the current moment, and fit them with a k-1 order polynomial. For the observations at the current moment, use the following formula for fitting:
[0031] x t =a0+a1·t+a2·t 2 +…+a k-1 ·t k-1 ,
[0032] Similarly, the predicted values of the previous and next moments (such as t-1, t+1, t-2, t+2, etc.) can be calculated using the above formula, so that a total of 2n+1 formulas are obtained, as follows:
[0033]
[0034] In order to make the entire matrix solvable, 2n+1>k must be satisfied so that the parameters a0, a1, a2, ..., a can be determined by the least squares method. k-1 , the formula is:
[0035] X (2n+1)×1 =T (2n+1)×k +A k×1 +E (2n+1)×1 ,
[0036] The subscripts of each parameter represent their respective dimensions, such as A k×1 It means there are k rows and 1 column of parameters. By the least squares method, we can get A k×1 The solution is:
[0037] A=(T Trans ·T) -1 ·T Trans ·X,
[0038] The superscript Trans represents transposition, so the filter value P of the model is:
[0039] P=T·A=T·(T Trans ·T)-1 ·T Trans ·X
[0040] Finally, the relationship matrix between the filtered values and the observed values can be obtained:
[0041] B=T·(T Trans ·T) -1 ·T TTans .
[0042] The observed values are converted into filtered values through matrix B. The filtered data is subjected to the following sliding window processing for model input.
[0043] The third step is to build the Informer time series prediction model to perform multi-step prediction of dissolved oxygen characteristics.
[0044] The present invention uses the Informer network model to analyze water environment related indicators. After the data is processed in the previous step, the input sequence x1, x2, ..., x t ,...,x T ,The Informer model is used to predict time series data; the processing flow of the Informer network model is as follows:
[0045] The model input consists of a smoothed feature scalar It is composed of a local timestamp PE and a global timestamp SE; the conversion formula is:
[0046]
[0047] Where: i∈{1,...,L x}, α is a factor that balances the size between scalar mapping and local / global embedding.
[0048] The characteristic scalar in the formula The specific operation is to convert the i-dimensional vector into a 512-dimensional vector through Conv1D. The local timestamp uses the Positional Embedding in Transformer, and the calculation formula is:
[0049]
[0050]
[0051] where d model is the feature dimension of the input,
[0052] The global timestamp uses a fully connected layer to map the input timestamp to a 512-dimensional Embedding.
[0053] The specific methods for generating encoders include:
[0054] Unify the transformed input The input is sent to the encoder part of the model. First, the sparse self-attention is calculated in the attention module. Each Key only focuses on u main queries, Q is the query vector, K is the key vector, and V is the value vector. The calculation formula is as follows:
[0055]
[0056] in, is a sparse matrix of the same size as Q and contains only the sparse metrics M(q i ,K) under the top-u queries. Add a sampling factor c and set u = clnL q First, randomly sample c*lnL keys for each query and calculate the sparsity score M(q i ,K).Q i ,K i ,V i are the i-th row of Q, K, and V respectively, and d is q i The dimension of L k =L q = L, sparse metric M(q i ,K) is calculated as follows:
[0057]
[0058] Then, select the N queries with the highest sparsity scores. N defaults to c*lnL. Only the dot product results of N queries and keys are calculated, and the remaining LN queries are not calculated.
[0059] The output after sparse self-attention calculation has redundant combinations of V values, so a distillation operation is needed to give higher weights to the dominant features with main features and generate a focused self-attention feature map in the next layer. This is achieved through four Convld convolution layers and one maximum pooling layer.
[0060] After multiple sparse self-attention layer calculations and distillation operations, the input of the decoder is obtained. For the decoder, the decoder used by Informer is similar to the traditional decoder. In order for the algorithm to generate long sequence outputs, the decoder needs the following input:
[0061]
[0062] in, is the original sequence input to the Decoder, To predict the sequence (filled with 0), the sequence is then passed through a mask-based sparse self-attention layer, which prevents each position from paying attention to future positions, thereby avoiding autoregression. The output of this layer and the output of the encoder are passed to a multi-head attention layer, and the output result is calculated once. Finally, a fully connected layer is passed to get the final output. The predicted output and the true value are calculated using the loss function Loss, which uses RMSE. The calculation formula is as follows:
[0063]
[0064] Among them, m is the number of samples, y i For real data, Iterate again until the training condition is terminated (the number of model iterations is reached or the early stopping mechanism is triggered because the loss does not decrease), and a trained model is generated, which can be used to predict the water environment characteristic values at future moments. The output of the model can obtain multi-step prediction values.
[0065] The fourth step is to perform STL feature decomposition on the data smoothed by SG filtering to remove seasonal component features; use Isolation Forest (IsoForest) to model the data after removing the seasonal component; IsoForest is a non-parametric and unsupervised learning method, that is, no mathematical model needs to be defined and no labeled training is required. As for how to find out which points are easy to be isolated, IsoForest uses a very efficient strategy. It assumes that a random hyperplane is used to cut the data space, and two subspaces can be generated at a time. Then continue to use a random hyperplane to cut each subspace, and loop until there is only one data point in each subspace. For the two-dimensional data of this method, it only needs to be cut in a fixed dimension, and the deviation distance between the low-density cutting boundary and the center is used as the safety interval threshold, and the safety interval is equal to the predicted value ± the maximum and minimum deviation distance. For the three-dimensional feature components after STL feature decomposition, the seasonal component needs to be removed, because the seasonal feature component is repeated regularly over time. Removing this feature component from the feature data makes the relationship between the input and output variables clearer, and focuses more on learning the relationship between the remaining features. Figure 3 It is the characteristic component graph after STL characteristic decomposition. The specific method is as follows:
[0066] (1) Decompose the trend term and use the centralized moving average method as follows:
[0067]
[0068] The above calculation method is used when f is an odd number.
[0069]
[0070] The above calculation method is used when f is an even number.
[0071] Among them, T t is the trend term, f is the time series frequency, 1 is the time series length, and the result is a time series with a length of 1. When t exceeds the domain of the above subscript, its value is empty, such as T1, that is, t = 1.
[0072] (2) Decompose the seasonal component and remove it as follows:
[0073] At time t, Y t is the observed value of the original time series, T t is the trend value at that moment, S t For the seasonal periodic term at this moment, the original time series is subtracted from the trend term:
[0074] S t =Y t -T t ,
[0075] Averaging the values at the same frequency in each cycle gives the seasonal term Figure:
[0076]
[0077] Among them, n = 1, f is rounded to the integer, that is, max(n,nf≤1), Figure is centered, and the centralized seasonal term Figure is obtained. The formula can be expressed as:
[0078] Figure=Figure-mean(Figure).
[0079] The resulting seasonal term of length f is removed and used as the training data for IsoForest.
[0080] The fifth step is to perform STL decomposition on the multi-step results predicted by the Informer network. The seasonal component also needs to be removed, and then compared with the threshold obtained in the fourth step; if it exceeds the safety interval, it is considered an anomaly.
[0081] The sixth step is to interpret abnormal data in combination with GB3838-2002 to explain the causes of the abnormality and make the abnormal data explainable.
[0082] The present invention makes full use of the attention mechanism to achieve long sequence prediction and solves the limitations of hypothesis testing. It no longer assumes that the data obeys a certain distribution, but adopts a more general approach to anomaly detection.
[0083] The present invention is a water quality early warning method based on the Informer model proposed above. It should be understood that, obviously, the above-mentioned specific implementation methods of the present invention are only examples made to clearly illustrate the present invention, and are not specific limitations on the implementation methods of the present invention. A person of ordinary skill in the art can modify the technical solutions recorded in each embodiment based on reading the specification of the present invention, or make equivalent replacements for some of the technical features therein, however, these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of each embodiment of the present invention.
Claims
1. A water quality early warning method based on the Informer model, characterized in that: The steps include: Step S1, obtaining time series data composed of water quality indicators over a period of time in the past and selecting water quality indicator features that have a greater impact on water quality, and using polynomial difference to fill in missing data; and filling in missing data; Step S2, performing polynomial smoothing filtering (Savitzky-Golay, SG) on the data to reduce noise; Step S3, inputting the processed data in step S2 into the Informer model, and the Informer model realizes multi-step prediction of future water quality; Step S4, performing feature decomposition (Seasonal-Trend decomposition procedure based on Loess, STL) on the data processed in step S2 based on local weighted regression and removing seasonal components, modeling the decomposed multidimensional feature data through isolation forest, and using the central deviation degree of non-abnormal points in the isolation forest as the threshold setting standard for the safety interval; Step S5, decomposing the multi-step data STL features predicted in step S3 and removing the seasonal component, and the data outside the isolation forest threshold are outliers; Step S6, referring to the surface water environmental quality standard GB3838-2002, to judge the authenticity of the abnormal value.
2. The water quality early warning method based on the Informer model according to claim 1 is characterized by: The water quality data collected by automatic monitoring stations are selected, and the data itself is time series data. A single water quality indicator that has a greater impact on water quality is selected, and the missing features are supplemented by polynomial interpolation.
3. The water quality early warning method based on the Informer model according to claim 1 is characterized in that: For the data after polynomial interpolation, due to the influence of the data collector itself and other possibilities, there is a certain degree of noise in the data. SG filtering is used to smooth the data, which can filter out the noise while ensuring that the shape and width of the signal remain unchanged.
4. The water quality early warning method based on the Informer model according to claim 1 is characterized in that: For the two-dimensional data after SG filtering and smoothing, the one-dimensional data composed of water quality features is converted into a 512-dimensional vector through convolution, and the local timestamp uses Transformer's positional encoding Positional Embedding; the other one-dimensional data is the acquisition time corresponding to the feature value, which is mapped to a 512-dimensional Embedding through a fully connected layer. The converted vector is input into the Encoder part of the model, and the sparse self-attention calculation is performed on it in the attention module. Each Key only pays attention to u Query is added to speed up the operation of the model. The output after sparse self-attention calculation is passed through four layers of Convld convolutional layers and a maximum pooling layer to give higher weights to the dominant features with main features. For the decoder, the output of the Encoder is passed through a mask-based sparse self-attention layer to prevent each position from paying attention to future positions, thereby avoiding autoregression and improving prediction accuracy. The output of the Decoder is the multi-step result of the prediction.
5. The water quality early warning method based on the Informer model according to claim 1 is characterized by: The two-dimensional data after filtering and smoothing are subjected to STL feature decomposition and the seasonal component is eliminated, so that the characteristic data does not contain seasonal factors; then the characteristic values and residual values of the two-dimensional data are used for anomaly detection through isolation forest, and the degree of central deviation of non-abnormal points in the isolation forest is used as the threshold setting standard for the safety interval, avoiding the defects of using hypothesis testing.
6. The water quality early warning method based on the Informer model according to claim 1 is characterized by: The prediction result in step S3 is multi-step data. After STL feature decomposition and elimination of seasonal components, the data characteristics are free from the interference of seasonal factors. If the predicted multi-step result exceeds the safety interval, it is abnormal data. The data before STL feature decomposition is the focus of attention.
7. The water quality early warning method based on the Informer model according to claim 1 is characterized by: For abnormal data that exceeds the safety range, referring to the current surface water environmental quality standard GB3838-2002, the water quality grade corresponding to the value can be obtained, thereby understanding the degree of abnormality.
