Water quality prediction method based on double decomposition and hybrid model and related device
By using the dual decomposition and mixed model method in water quality prediction, using CEEMDAN, k-means clustering and VMD decomposition technology, combined with the ParallelTransformer-LSTM model, the problem of insufficient accuracy and stability of the existing water quality prediction methods is solved, and more efficient water quality parameter prediction is achieved.
Patent Information
- Application Number
- CN202411733154.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-21
AI Technical Summary
When existing water quality prediction methods deal with complex water quality data, they lack accuracy and stability, making it difficult to effectively capture the dependencies in nonlinear and time series data.
The water quality prediction method based on double decomposition and mixed model is adopted, and the eigenmodal function is extracted through CEEMDAN decomposition, combined with k-means clustering and VMD decomposition, the data dimension is reduced and the high-frequency detail features are extracted. Finally, the decomposed modality is input to the ParallelTransformer-LSTM model for prediction.
It improves the accuracy and stability of water quality parameter prediction, can capture the complex characteristics and time series dependencies in water quality data more accurately, and enhances the ability to predict water quality changes.
Smart Images

Figure CN119673325A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of water quality monitoring, and in particular to a water quality prediction method and related devices based on a double decomposition and hybrid model. Background Art
[0002] Water quality monitoring is essential to ensure the safety and health of water resources. With the advancement of industrialization and urbanization, water pollution has become increasingly serious, affecting the ecological environment and human health. Accurate prediction and monitoring of water quality parameters such as dissolved oxygen, ammonia nitrogen, and total phosphorus can help to timely discover and control pollution sources, so as to take effective treatment measures. At present, the methods of water quality prediction mainly include statistical methods, traditional machine learning methods (such as linear regression, support vector machine, etc.) and deep learning methods (such as LSTM, CNN, etc.). These methods have certain limitations in practical applications:
[0003] (1) Statistical methods: Assume that the data follows a specific distribution and have difficulty capturing complex nonlinear relationships.
[0004] (2) Traditional machine learning methods: Although they have improved prediction accuracy to a certain extent, they are not ideal for handling the dependency relationships of time series data.
[0005] (3) Deep learning methods: LSTM performs well in processing time series data, but there is still room for improvement when facing high-dimensional and complex water quality data.
[0006] Therefore, how to improve the accuracy and stability of water quality parameter prediction has become a technical problem that needs to be urgently solved in this field. Summary of the invention
[0007] The purpose of the present invention is to provide a water quality prediction method and related devices based on double decomposition and hybrid model, which can improve the accuracy and stability of water quality parameter prediction and provide strong technical support for water quality monitoring and management.
[0008] To achieve the above object, the present invention provides the following solutions:
[0009] In a first aspect, the present invention provides a water quality prediction method based on a double decomposition and hybrid model, the water quality prediction method based on a double decomposition and hybrid model comprising:
[0010] The original water quality time series data are obtained; the original water quality time series data include: water temperature (WT), pH, dissolved oxygen (DO), permanganate index (CODMn), ammonia nitrogen (NH3-N), total phosphorus (TP), total nitrogen (TN), electrical conductivity (EC) and turbidity (TU).
[0011] The original water quality time series data is preprocessed to obtain preprocessed data; the preprocessing includes: denoising processing and normalization processing.
[0012] Based on the Pearson correlation coefficient method and the pre-processed data, the data to be processed are determined; the data to be processed are indicator data that are correlated with the indicator to be predicted.
[0013] The data to be processed are subjected to complete ensemble empirical mode decomposition (CEEMDAN) to obtain a plurality of intrinsic mode functions.
[0014] K-means clustering is performed on a plurality of the intrinsic mode functions to obtain clustered intrinsic mode functions; the clustered intrinsic mode functions include: high-frequency mode, medium-frequency mode and low-frequency mode.
[0015] The high-frequency modes in the clustered intrinsic mode functions are subjected to variational mode decomposition (VMD) to obtain a plurality of high-frequency sub-modes.
[0016] Several of the high-frequency sub-modes, the medium-frequency modes and the low-frequency modes are respectively input into the Parallel Transformer-LSTM model to obtain the final prediction result; the Parallel Transformer-LSTM model is a model established based on the Transformer model and the LSTM model.
[0017] In a second aspect, the present invention provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the water quality prediction method based on the dual decomposition and mixing model described above.
[0018] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the water quality prediction method based on the double decomposition and hybrid model described above.
[0019] In a fourth aspect, the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the water quality prediction method based on the double decomposition and hybrid model described above.
[0020] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0021] The present invention provides a water quality prediction method and related device based on double decomposition and hybrid model. First, original water quality time series data are obtained; the original water quality time series data include: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity and turbidity; the original water quality time series data are preprocessed to obtain preprocessed data; the preprocessing includes: denoising and normalization; based on the Pearson correlation coefficient method and the preprocessed data, the data to be processed are determined; the data to be processed are index data with correlation with the index to be predicted; secondly, the data to be processed are subjected to complete set empirical mode decomposition to obtain a plurality of intrinsic mode functions; in this way, non-stationary and nonlinear water quality time series signals can be more accurately decomposed and the intrinsic mode functions can be extracted; furthermore, if The k-means clustering is performed on the eigenmode functions to obtain the clustered eigenmode functions; the clustered eigenmode functions include: high-frequency mode, medium-frequency mode and low-frequency mode; this can reduce the dimension of the data, improve the calculation efficiency, and retain the characteristics of information in different frequency bands; again, the high-frequency mode in the clustered eigenmode function is subjected to variational mode decomposition to obtain several high-frequency sub-modes; through the secondary decomposition of the high-frequency mode, the detailed features in the signal can be further extracted, the feature extraction capability of complex water quality data is enhanced, and the accuracy of data representation is improved; finally, the several high-frequency sub-modes, the medium-frequency mode and the low-frequency mode are respectively input into the Parallel Transformer-LSTM model to obtain the final prediction result; the Parallel Transformer-LSTM model is a model established based on the Transformer model and the LSTM model. The Transformer model captures long-term dependencies through the self-attention mechanism and is suitable for processing data with a long time span. The LSTM model processes short-term dependencies through memory units and gating mechanisms and is suitable for processing data with a short time span. Compared with the serial Transformer-LSTM model, it can simultaneously capture long-term and short-term dependencies in time series data and improve prediction performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 This is a diagram of the application environment of a water quality prediction method based on double decomposition and hybrid model in one embodiment of the present invention.
[0024] Figure 2 A schematic flow chart of a water quality prediction method based on a double decomposition and hybrid model provided in one embodiment of the present invention.
[0025] Figure 3 A schematic diagram of the overall process of a water quality prediction method based on a double decomposition and hybrid model provided in one embodiment of the present invention.
[0026] Figure 4 A Pearson correlation heat map of water quality indicators provided by an embodiment of the present invention.
[0027] Figure 5 A schematic diagram of partial CEEMDAN decomposition of original total nitrogen data provided by an embodiment of the present invention.
[0028] Figure 6 Another schematic diagram of CEEMDAN decomposition of raw total nitrogen data provided by an embodiment of the present invention.
[0029] Figure 7 A schematic diagram of the K-means clustering results of IMF components provided by an embodiment of the present invention.
[0030] Figure 8 A schematic diagram of three high-frequency components, a mid-frequency component and a low-frequency component decomposed by VMD provided in an embodiment of the present invention.
[0031] Fig. 9 A schematic diagram of the structure of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0034] In order to overcome the limitations of existing methods, this paper proposes a water quality prediction method based on CEEMDAN, k-means clustering, VMD, parallel Transformer, LSTM and random forest (RF). This method combines the advantages of signal decomposition, deep learning and ensemble learning, aims to improve the accuracy and stability of water quality parameter prediction, and provides strong technical support for water quality monitoring and governance.
[0035] The water quality prediction method based on double decomposition and hybrid model provided by the embodiment of the present invention can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be set up separately, or it can be integrated on the server 104, or it can be placed on the cloud or other servers. The terminal 102 can send the acquired raw water quality time series data to the server 104, and the raw water quality time series data include: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity and turbidity; after the server 104 receives the raw water quality time series data, the server 104 pre-processes the raw water quality time series data to obtain pre-processed data; the pre-processing includes: denoising and normalization; based on the Pearson correlation coefficient method and the pre-processed data, determine the data to be processed; the data to be processed The processed data is the index data correlated with the index to be predicted; the data to be processed is subjected to complete set empirical mode decomposition to obtain several intrinsic mode functions; the several intrinsic mode functions are subjected to k-means clustering to obtain the clustered intrinsic mode functions; the clustered intrinsic mode functions include: high-frequency mode, medium-frequency mode and low-frequency mode; the high-frequency mode in the clustered intrinsic mode function is subjected to variational mode decomposition to obtain several high-frequency sub-modes; the several high-frequency sub-modes, the medium-frequency mode and the low-frequency mode are respectively input into the Parallel Transformer-LSTM model to obtain the final prediction result; the Parallel Transformer-LSTM model is a model established based on the Transformer model and the LSTM model. The server 104 can feed back the obtained prediction result to the terminal 102. In addition, in some embodiments, the water quality prediction method based on the dual decomposition and hybrid model can also be implemented independently by the server 104 or the terminal 102. For example, the terminal 102 can directly perform water quality prediction on the original water quality time series data, or the server 104 can obtain the original water quality time series data from the data storage system and perform water quality prediction on the original water quality time series data.
[0036] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, and tablet computers. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers, or may be a cloud server.
[0037] In an exemplary embodiment, Figure 2As shown, a water quality prediction method based on double decomposition and hybrid model is provided. The method is executed by a computer device, specifically, it can be executed by a computer device such as a terminal or a server alone, or it can be executed by a terminal and a server together. In an embodiment of the present invention, the method is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0038] S1: Obtaining original water quality time series data; the original water quality time series data includes: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity and turbidity.
[0039] S2: Preprocessing the original water quality time series data to obtain preprocessed data; the preprocessing includes: denoising processing and normalization processing.
[0040] S3: Based on the Pearson correlation coefficient method and the pre-processed data, determine the data to be processed; the data to be processed is indicator data that is correlated with the indicator to be predicted.
[0041] S4: Perform complete set empirical mode decomposition on the data to be processed to obtain a plurality of intrinsic mode functions.
[0042] S5: performing k-means clustering on a plurality of the intrinsic mode functions to obtain clustered intrinsic mode functions; the clustered intrinsic mode functions include: high-frequency mode, medium-frequency mode and low-frequency mode.
[0043] S6: performing variational mode decomposition on the high-frequency modes in the clustered intrinsic mode functions to obtain a plurality of high-frequency sub-modes.
[0044] S7: Inputting the plurality of high-frequency sub-modes, the intermediate-frequency modes and the low-frequency modes into the Parallel Transformer-LSTM model respectively to obtain a final prediction result; the Parallel Transformer-LSTM model is a model established based on the Transformer model and the LSTM model.
[0045] Implementing the above steps S1 to S7 and using CEEMDAN for signal decomposition can more accurately decompose non-stationary and nonlinear water quality time series signals, extract intrinsic mode functions, improve the accuracy of signal decomposition, and better capture the characteristics of water quality data. Use k-means clustering to classify the intrinsic mode functions (IMFs) obtained by decomposition into high-frequency modes, medium-frequency modes, and low-frequency modes, which reduces the dimension of the data, improves the calculation efficiency, and retains the characteristics of information in different frequency bands. VMD is introduced for secondary decomposition, and the high-frequency modes in the clustered intrinsic mode functions are secondary decomposed to further extract detailed features in the signal, enhance the feature extraction capability of complex water quality data, and improve the accuracy of data representation. Use the parallel Transformer-LSTM model for feature extraction. The Transformer model captures long-term dependencies through the self-attention mechanism and is suitable for processing data with a long time span. The LSTM model processes short-term dependencies through memory units and gating mechanisms and is suitable for processing data with a short time span. Compared with the serial Transformer-LSTM model, it can simultaneously capture long-term and short-term dependencies in time series data and improve prediction performance.
[0046] The overall program process is as follows Figure 3 As shown, in step S1, the original water quality time series data is collected from the data source (such as sensor, historical database). The original water quality time series data includes 9 water quality indicators: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity, and turbidity.
[0047] In step S2, the data is normalized to eliminate the influence of different eigenvalue ranges, usually using min-max normalization:
[0048]
[0049] Among them, x' is the normalized data, x is the original water quality time series data; x min is the minimum value of the original water quality time series data; x max is the maximum value of the original water quality time series data.
[0050] In step S3, the feature parameter most correlated with the prediction parameter is selected using the Pearson correlation coefficient method:
[0051]
[0052] Among them, ρ X,Y is the correlation coefficient between feature X and target Y, cov(X,Y) is the covariance, σ X is the standard deviation of the feature, σ Yis the standard deviation of the target.
[0053] As an optional implementation, in step S4, the original water quality time series data is decomposed into several intrinsic mode functions to capture nonlinear and non-stationary characteristics. The basic steps of CEEMDAN are as follows:
[0054] (1) Add noise to generate a noise auxiliary signal.
[0055] Superimpose a white noise sequence n with the same variance on the original signal x(t) i (t) to generate a noise auxiliary signal:
[0056] x i (t) = x(t) + ε·n i (t) (3);
[0057] Where: x i (t) is the noise auxiliary signal, ε is a very small positive number for controlling the noise amplitude, and i is a positive integer representing different noise realizations.
[0058] (2) Calculate the first IMF: For each noise auxiliary signal x i (t) Perform EMD decomposition to obtain the first IMF.
[0059]
[0060] Among them, IMF 1 (t) is the first IMF, and N is the number of noise additions.
[0061] (3) Residual calculation
[0062] Remove the first IMF from the original signal to get the residual signal:
[0063] r 1 (t) = x(t) - IMF 1 (t) (5);
[0064] Among them, r 1 (t) is the residual signal.
[0065] (4) Recursively calculate the subsequent IMF: take the residual signal as input, repeat steps (1) and (2), continue to perform EMD decomposition on the residual, and obtain the next IMF until the residual tends to zero.
[0066] As an optional implementation, in step S5, the decomposed IMFs are clustered, and the complexity of each IMF component is calculated by calculating the sample entropy, and it is divided into high-frequency mode, medium-frequency mode and low-frequency mode. The goal of clustering is to group IMFs with similar frequency characteristics, calculate the distance between each IMF component and all cluster centers, and assign it to the nearest center.
[0067]
[0068] Where k is the number of clusters, C i is the i-th cluster, μ i is the center of the ith cluster. According to the final clustering results, the IMF components are marked as high frequency, medium frequency and low frequency. The IMF decomposed by CEEMDAN is divided into three categories: high frequency, medium frequency and low frequency, which simplifies the subsequent processing flow and can process different frequency components in a targeted manner, especially the further removal of high frequency noise.
[0069] Specifically, K-means clustering includes the following steps:
[0070] (1) The complexity of each IMF component is calculated by sample entropy SE to distinguish high, medium and low frequencies. The basic steps of sample entropy calculation are as follows:
[0071] Step 1: Input parameters and data preprocessing.
[0072] 1) Input data: IMF component IMF k (t).
[0073] 2) Embedding dimension m: The dimension of the constructed vector (usually 2 or 3).
[0074] 3) Similarity tolerance r: used to determine whether two sequences are similar, usually selected as 0.1 to 0.25 times the standard deviation of the prediction index sequence.
[0075] 4) Delay time τ: The time interval used to construct the embedding matrix. The default value is 1.
[0076] Step 2: Construct the embedding matrix.
[0077] Construct an embedding vector sequence of length m for the time series x(t) with length N:
[0078] X m (i)={x(i),x(i+1),…,x(i+m-1)},i=1,2,…,N-m+1 (7);
[0079] Among them, X m (i) is a subsequence of length m.
[0080] Step 3: Calculate the distance of the embedded vector.
[0081] Define two embedding vectors X m (i) and X m The distance between (j) is the Chebyshev distance:
[0082]
[0083] This distance is used to determine the similarity between two subsequences.
[0084] Step 4: Count the number of matching samples.
[0085] For each embedding vector X m (i) Count the number of vectors whose distance is less than the threshold r and remove the sub-matching items:
[0086]
[0087] in, Indicates that X m (i) Ratio of similar vectors.
[0088] Step 5: Calculate the average of all matching samples.
[0089] Compute the average similarity of all embedding vectors:
[0090]
[0091] Step 6: Increase the embedding dimension.
[0092] Increase the embedding dimension from m to m+1 and repeat the above steps to calculate B m+1 .
[0093] Step 7: Calculate sample entropy.
[0094] The definition of sample entropy is the negative logarithm of the ratio of similarities between two embedding dimensions:
[0095]
[0096] If the pattern in the signal is complex, the sample entropy will be large; conversely, the simpler the pattern, the smaller the sample entropy.
[0097] (2) Construct the feature matrix: The sample entropy and frequency energy of each IMF form the feature matrix F:
[0098]
[0099] Among them, SE k represents the sample entropy value of the kth IMF, Spectrumk represents the spectrum of the kth IMF.
[0100] (3) Apply K-means clustering.
[0101] IMFs are clustered into three categories, representing high-frequency modes, medium-frequency modes, and low-frequency modes. The sample entropy values of several IMF components (3 in this patent) are randomly selected as the initial cluster centers. The distance between each IMF component and all cluster centers is calculated using the Euclidean distance, and it is assigned to the nearest center.
[0102] Euclidean distance formula:
[0103]
[0104] Among them, d(x i ,c j ) is the distance between the data point xi and the cluster center cj; x i =(x i1 ,x i2 ,…,x in ) is the coordinate of data point i in n-dimensional space; c j =(c j1 ,c j2 ,…,c jn ) is the coordinate of cluster center j in n-dimensional space.
[0105] For each cluster, calculate the average of all data points in the cluster and use the average as the new cluster center.
[0106]
[0107] Among them, C j represents the set of all data points currently belonging to cluster j; |C j | is the number of data points in the family; x i It belongs to C j data points.
[0108] Repeat the assignment and update steps until the cluster center does not change. According to the clustering results, calculate the sum of each type of IMF to obtain high-frequency mode, medium-frequency mode and low-frequency mode.
[0109] In an exemplary embodiment, in step S6, it specifically includes:
[0110] S61: Determine the number of high-frequency sub-modes, and initialize the center frequency and modal function of each high-frequency sub-mode.
[0111] S62: performing bandwidth minimization decomposition on the high-frequency mode to obtain a plurality of modal components.
[0112] S63: Based on the plurality of modal components, the modal function and the center frequency are iteratively updated using a variational method to minimize the bandwidth of the mode until convergence, thereby obtaining a plurality of high-frequency sub-modes.
[0113] Each clustered high-frequency mode is further decomposed using VMD to generate sub-modes. VMD is an adaptive non-stationary signal decomposition method that decomposes the signal into several sub-modes with central frequencies by solving the variational problem. The basic steps of VMD are as follows:
[0114] (1) Initialize the center frequency of each submode.
[0115] (2) Use the variational method to iteratively update the submodes and center frequencies until convergence.
[0116] Specifically, for the high-frequency modes after clustering, VMD is applied for secondary decomposition to further extract detailed features:
[0117] (1) Initializing the number of modes and frequencies: setting the number of modes K (the present invention decomposes the high-frequency signal into three components) and the initial center frequency (firstly, performing spectrum analysis on the signal to find the main frequency components in the signal, and using this as the initial center frequency of each mode).
[0118] (2) Signal decomposition: The input high-frequency signal is decomposed in a bandwidth-minimizing manner to obtain several modal components.
[0119] (3) Alternating optimization: Minimize the bandwidth of the mode by alternately updating the modal components and center frequencies.
[0120] (4) Convergence judgment: judge whether the convergence conditions are met. If the conditions are met, output each modal component; otherwise, continue to iterate.
[0121] As an optional implementation, the water quality prediction method based on the double decomposition and hybrid model further includes: data reconstruction, recombining the intermediate frequency mode, the low frequency mode and the high frequency sub-mode to generate a feature data set for prediction. The feature data set is organized into a training set and a test set, usually using 80% of the data as the training set and 20% of the data as the test set.
[0122] In an exemplary embodiment, in step S7, it specifically includes:
[0123] S71: Divide the plurality of high-frequency sub-modes into a plurality of parallel streams.
[0124] S72: Input the plurality of parallel streams into the Transformer model and the LSTM model respectively to obtain features of a plurality of first different time scales.
[0125] S73: Connecting a plurality of the first features of different time scales at a feature level to obtain a plurality of first prediction results.
[0126] S74: Input the intermediate frequency mode into the Transformer model and the LSTM model respectively to obtain features of a second different time scale.
[0127] S75: Perform feature-level connection on the features of the second different time scales to obtain a second prediction result.
[0128] S76: Input the low-frequency mode into the Transformer model and the LSTM model respectively to obtain features of a third different time scale.
[0129] S77: Perform feature-level connection on the features of the third different time scales to obtain a third prediction result.
[0130] S78: Use random forest to perform regression prediction on a number of the first prediction results, the second prediction results and the third prediction results to obtain a final prediction result.
[0131] The present invention uses a random forest model to make a final prediction of the features extracted from the Transformer-LSTM model. The prediction results of each IMF in the parallel transformer-LSTM are more effectively combined, thereby reducing the impact of the offset and error directly superimposed on the prediction results, improving the stability and noise resistance of the model, and helping to improve the accuracy and robustness of the prediction.
[0132] (The conventional superposition method will lead to the problem of increased error, one of the reasons is:
[0133] Bias in IMF forecast results: There are biases in the forecast results of each IMF, and these biases will accumulate when superimposed, resulting in large errors.
[0134] Correlation between IMFs: There is correlation between IMFs, and direct superposition will introduce more errors.
[0135] Error propagation: The error of each IMF forecast result will be amplified in the superposition process. Therefore, a regression model is used to learn how to combine the IMF forecast results instead of simply superimposing them.
[0136] Random forest is an integrated learning method that can improve the stability and noise resistance of the model by integrating multiple decision trees, which helps to improve the accuracy and robustness of predictions and reduce the risks of overfitting, bias, and error accumulation.
[0137] The following is an introduction to the Parallel Transformer-LSTM model.
[0138] The Transformer model is used to capture long-term dependencies in time series data and calculates the weighted sum of each position in the sequence through a self-attention mechanism.
[0139]
[0140] Where Q is the query matrix, K is the key matrix, V is the value matrix, and d k is the dimension of the key vector.
[0141] step:
[0142] ① Input data embedding: embedding time series data into high-dimensional space.
[0143] ② Self-attention mechanism: Calculate the attention weight of each time step with other time steps to capture global dependencies.
[0144] ③ Feedforward neural network: processes self-attention output and generates the final feature representation.
[0145] The LSTM model is used to capture short-term dependencies in time series data and controls the processing of time series data through forget gates, input gates, candidate memory states, and output gates. Steps:
[0146] Forget gate: determines what information needs to be retained in the state of the memory cell at the previous time step.
[0147] f t =σ(W f ·[h t-1 ,x t ]+b f ) (16);
[0148] ① Meaning: The forget gate determines which information in the memory cell state Ct-1 of the previous time step needs to be forgotten.
[0149] ② Calculation: Input is the previous hidden state h t-1 and the current input x t , after the weight matrix W f and bias b f The linear transformation of , and then through the sigmoid function σ (output between 0 and 1). Output f t is a vector, each element of which represents the proportion of information retained at the corresponding position in the memory cell state.
[0150] Input gate: determines the part of the current input information that needs to be written into the memory cell state.
[0151] i t =σ(W i ·[ht-1 ,x t ]+b i ) (17);
[0152] ① Meaning: The input gate determines the current input x t Which information in needs to be written into the memory cell state Ct.
[0153] ② Calculation: Input is the previous hidden state h t-1 and the current input x t , after the weight matrix W i and bias b i The linear transformation of , and then through the sigmoid function σ. Output i t is a vector, each element of which represents the proportion of the information at the corresponding position in the current input written into the memory cell state.
[0154] Candidate memory cell state: Generates new candidate memory content for the current time step.
[0155]
[0156] ① Meaning: Generate a new candidate memory cell state C~ t , which represents the new memory content calculated at the current time step based on the current input and the previous hidden state.
[0157] ② Calculation: Input is the previous hidden state h t-1 and the current input x t , after the weight matrix W C and bias b C Linear transformation, and then through the tanh function (output between -1 and 1). Output is a vector, each element of which represents the candidate memory content at the current time step.
[0158] Memory unit state update: The memory state of the previous time step and the candidate memory state of the current time step are combined to generate a new memory unit state.
[0159]
[0160] ① Meaning: Update the memory unit state Ct, combining the memory state Ct-1 of the previous time step and the candidate memory state of the current time step
[0161] ② Calculation: The memory cell state Ct is the sum of the previous memory cell state Ct-1 and the current candidate memory state Ct-1. t The weighted sum of . The forget gate f t Determines which information in the previous memory state is retained, and the input gate i tDetermines which information of the current input is written into the new memory state.
[0162] Output gate: determines which information in the memory cell state is output to the hidden state.
[0163] o t =σ(W o ·[h t-1 ,x t ]+b o ) (20);
[0164] ① Meaning: The output gate determines which information in the current memory cell state Ct needs to be output to the hidden state h t .
[0165] ② Calculation: Input is the previous hidden state h t-1 and the current input x t , after the weight matrix W o and bias b o The linear transformation of , and then through the sigmoid function σ. Output o t It is a vector, each element of which represents the ratio of the information at the corresponding position in the memory cell state output to the hidden state.
[0166] Calculate the hidden state: the output of the LSTM unit, which contains the memory and state information of the current time step.
[0167] h t =o t tanh(C t ) (twenty one);
[0168] ① Meaning: Calculate the hidden state h of the current time step t , which is the output of the LSTM unit.
[0169] ② Calculation: Hidden state h t is the output gate o t The output of the gate is the product of the weighted output of the current memory cell state Ct (after the tanh function). t Controls which information in the memory cell state is output to the hidden state.
[0170] ParallelTransformer-LSTM model processing:
[0171] ① Data parallelization: Divide the data into multiple parallel streams and input them into Transformer and LSTM respectively to capture features of different time scales.
[0172] ② Model fusion: The outputs of Transformer and LSTM are fused, and feature-level connections are used to make final predictions through a fully connected layer. This allows the model to simultaneously utilize the self-attention mechanism of Transformer and the time series modeling capability of LSTM, combining two different types of feature extraction capabilities to generate the final prediction results and provide richer feature representations.
[0173] Random Forest Regression Prediction:
[0174] Use random forest to post-process the parallel-transformer-LSTM output to reduce the impact of each IMF offset and error. Random forest is an ensemble learning method that improves prediction performance and stability by building multiple decision trees and averaging their results. The basic steps of random forest are as follows:
[0175] ① Randomly sample several subsamples from the training set.
[0176] ②Build a decision tree for each sub-sample.
[0177] ③Average the prediction results of all decision trees as the final prediction value.
[0178] Model evaluation and prediction.
[0179] 1) Evaluate model performance.
[0180] The error index was calculated and evaluated using the mean square error (MSE), root mean square error (RMSE), mean absolute error (MAE), and coefficient of determination (R2).
[0181]
[0182] Among them, MSE is the mean square error, RMSE is the root mean square error, MAE is the mean absolute error, R 2 is the coefficient of determination, N is the number of samples; y is the true value; is the predicted value of the model; is the mean of the true values.
[0183] MSE, RMSE and MAE measure the deviation between the true value and the predicted value. The smaller the value, the more accurate the model prediction. 2 It can reflect the accuracy of the model fitting data, and its range is 0-1. 2 The closer it is to 1, the better the model fit is.
[0184] 2) Generate prediction results.
[0185] Generate prediction results using the trained model and denormalize to the original range. Deploy the trained model to the production environment for real-time prediction and decision support.
[0186] In an exemplary embodiment, the following steps are specifically included:
[0187] (1) Data collection and preprocessing: Collect water quality monitoring data and perform necessary preprocessing, denoising, and normalization.
[0188] (2) CEEMDAN decomposition: CEEMDAN decomposition is performed on the preprocessed data to obtain a series of IMFs.
[0189] (3) k-means clustering classification: k-means clustering is performed on IMFs to divide them into high-frequency, medium-frequency and low-frequency components.
[0190] (4) VMD secondary decomposition: VMD decomposition is performed on the clustered IMFs to further extract detailed features.
[0191] (5) Parallel Transformer-LSTM feature extraction: The decomposed features are simultaneously input into the Transformer and LSTM models for feature extraction, improving processing efficiency and integrating multiple feature information.
[0192] (6) Random forest final prediction: Use random forest to make final predictions on the features output by LSTM to obtain the predicted values of water quality parameters.
[0193] (7) Result analysis and evaluation: Analyze the prediction results, evaluate the performance of the model, and make adjustments and optimizations as needed.
[0194] In an exemplary embodiment, the water quality dataset is derived from the public data of China National Environmental Monitoring Center (https: / / www.cnemc.cn / ). The total nitrogen in the Xiatong section of the Zhejiang-Min River in Zhejiang Province is predicted.
[0195] (1) Data processing and feature extraction.
[0196] Abnormal data were deleted, and missing data were interpolated using the spline interpolation method. Based on the Pearson correlation coefficient method, the parameters with correlation coefficients greater than 0.2 with total nitrogen were water temperature, dissolved oxygen, ammonia nitrogen, and total phosphorus. Therefore, water temperature, dissolved oxygen, ammonia nitrogen, total phosphorus, and total nitrogen were selected for water quality prediction. The Pearson correlation heat map of water quality indicators is shown in the figure below. Figure 4 shown.
[0197] (2) CEEMDAN signal decomposition.
[0198] like Figure 5 and Figure 6As shown in Figure 1, the original water quality time series data is decomposed into 14 intrinsic mode functions (IMFs).
[0199] (3) k-means clustering.
[0200] like Figure 7 As shown in Figure 1, by calculating the sample entropy, the decomposed IMFs are clustered and divided into high-frequency modes, medium-frequency modes, and low-frequency modes.
[0201] (4) Figure 8 As shown, the high-frequency signal VMD secondary decomposition obtains IMF1, IMF2 and IMF3, IMF4 and IMF5 correspond to Figure 7 The intermediate and low frequency signals in the
[0202] (5) Water quality model prediction results and comparison with other prediction methods. The comparison results are shown in Table 1.
[0203] Table 1 Comparison of prediction performance
[0204] Model MSE RMSE MAE <![CDATA[R 2 ]]> This method 0.19334 0.37234 0.30162 0.93821 Parallel-tansformer-lstm 0.36571 0.40708 0.35207 0.91451 serial-tansformerl-lstm 0.34412 0.43963 0.34088 0.91816
[0205] The present invention also provides an application scenario, which applies the above-mentioned water quality prediction method based on double decomposition and hybrid model. Specifically: the water quality prediction method based on double decomposition and hybrid model provided in this embodiment can be applied in the water quality prediction scenario. The water quality prediction scenario includes: data acquisition link, data processing link, complete set empirical mode decomposition link, clustering link, variational mode decomposition link and prediction link. First, the original water quality time series data is obtained; the original water quality time series data includes: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity and turbidity; the original water quality time series data is preprocessed to obtain preprocessed data; the preprocessing includes: denoising and normalization; based on the Pearson correlation coefficient method and the preprocessed data, the data to be processed is determined; the data to be processed is indicator data that is correlated with the indicator to be predicted; secondly, the data to be processed is The data is subjected to complete set empirical mode decomposition to obtain several intrinsic mode functions; further, the several intrinsic mode functions are subjected to k-means clustering to obtain clustered intrinsic mode functions; the clustered intrinsic mode functions include: high-frequency mode, medium-frequency mode and low-frequency mode; thirdly, the high-frequency mode in the clustered intrinsic mode function is subjected to variational mode decomposition to obtain several high-frequency sub-modes; finally, the several high-frequency sub-modes, the medium-frequency mode and the low-frequency mode are respectively input into the Parallel Transformer-LSTM model to obtain the final prediction result.
[0206] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store raw water quality time series data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a water quality prediction method based on a dual decomposition and hybrid model is implemented.
[0207] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present invention, and does not constitute a limitation on the computer device to which the scheme of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0208] In an exemplary embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the above-mentioned method embodiments are implemented when the processor executes the computer program.
[0209] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, and when the computer program is executed by a processor, the above-mentioned method embodiments are implemented.
[0210] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the above-mentioned method embodiments are implemented.
[0211] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0212] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0213] The database involved in each embodiment provided by the present invention may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided by the present invention may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0214] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0215] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A water quality prediction method based on double decomposition and hybrid model, characterized in that: The water quality prediction method based on double decomposition and hybrid model includes: Obtaining original water quality time series data; the original water quality time series data includes: water temperature, pH, dissolved oxygen, permanganate index, ammonia nitrogen, total phosphorus, total nitrogen, conductivity and turbidity; Preprocessing the original water quality time series data to obtain preprocessed data; the preprocessing includes: denoising and normalization; Based on the Pearson correlation coefficient method and the pre-processed data, determining the data to be processed; the data to be processed is the index data that is correlated with the index to be predicted; Performing complete set empirical mode decomposition on the data to be processed to obtain a plurality of intrinsic mode functions; Performing k-means clustering on a plurality of the intrinsic mode functions to obtain clustered intrinsic mode functions; the clustered intrinsic mode functions include: high-frequency mode, medium-frequency mode and low-frequency mode; Performing variational mode decomposition on the high-frequency modes in the clustered intrinsic mode functions to obtain a plurality of high-frequency sub-modes; Several of the high-frequency sub-modes, the medium-frequency modes and the low-frequency modes are respectively input into the Parallel Transformer-LSTM model to obtain the final prediction result; the Parallel Transformer-LSTM model is a model established based on the Transformer model and the LSTM model.
2. The water quality prediction method based on double decomposition and hybrid model according to claim 1, characterized in that: The expression of the normalization process is: Among them, x' is the normalized data, x is the original water quality time series data; x min is the minimum value of the original water quality time series data; x max is the maximum value of the original water quality time series data.
3. The water quality prediction method based on double decomposition and hybrid model according to claim 1 is characterized in that: The expression of the Pearson correlation coefficient method is: Among them, ρ X,Y is the correlation coefficient between feature X and target Y, cov(X,Y) is the covariance, σ X is the standard deviation of the feature, σ Y is the standard deviation of the target.
4. The water quality prediction method based on double decomposition and hybrid model according to claim 1, characterized in that: The high-frequency modes in the clustered intrinsic mode functions are subjected to variational mode decomposition to obtain several high-frequency sub-modes, including: Determine the number of high-frequency sub-modes, and initialize the center frequency and modal function of each high-frequency sub-mode; Performing bandwidth minimization decomposition on the high frequency mode to obtain a plurality of modal components; Based on the several modal components, the modal function and the center frequency are iteratively updated by using the variational method to minimize the bandwidth of the mode until convergence, thereby obtaining several high-frequency sub-modes.
5. The water quality prediction method based on double decomposition and hybrid model according to claim 1, characterized in that: Inputting a plurality of the high-frequency sub-modes, the medium-frequency modes and the low-frequency modes into the Parallel Transformer-LSTM model respectively to obtain the final prediction result, specifically including: dividing a plurality of the high frequency sub-modes into a plurality of parallel streams; Inputting the plurality of parallel streams into a Transformer model and an LSTM model respectively to obtain features of a plurality of first different time scales; Connecting a plurality of features of the first different time scales at a feature level to obtain a plurality of first prediction results; Inputting the intermediate frequency mode into the Transformer model and the LSTM model respectively to obtain features of a second different time scale; Performing feature-level connection on the features of the second different time scales to obtain a second prediction result; Inputting the low-frequency mode into the Transformer model and the LSTM model respectively to obtain features of a third different time scale; Performing feature-level connection on the features of the third different time scales to obtain a third prediction result; Use random forest to perform regression prediction on several of the first prediction results, the second prediction results and the third prediction results to obtain a final prediction result.
6. The water quality prediction method based on double decomposition and hybrid model according to claim 1, characterized in that: The water quality prediction method based on the double decomposition and hybrid model also includes: The Parallel Transformer-LSTM model is evaluated by using evaluation indicators, and the evaluation indicators include: mean square error, root mean square error, mean absolute error and determination coefficient.
7. The water quality prediction method based on double decomposition and hybrid model according to claim 6 is characterized in that: The calculation formula of the mean square error is: The calculation formula of the root mean square error is: The calculation formula of the mean absolute error is: The calculation formula of the determination coefficient is: Among them, MSE is the mean square error, RMSE is the root mean square error, MAE is the mean absolute error, R 2 is the coefficient of determination, N is the number of samples; y is the true value; is the predicted value of the model; is the mean of the true values.
8. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the water quality prediction method based on the dual decomposition and mixing model as described in any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the water quality prediction method based on the double decomposition and mixing model described in any one of claims 1 to 7 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the water quality prediction method based on the double decomposition and mixing model described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Settlement prediction method and system fused with multi-scale optimization, terminal and storage medium
CN120338211A
Water quality prediction method and system in combination with time-frequency characteristics and deep margin learning network
CN120509529A
Water quality detection method and system
CN121141981A
Sewage treatment fault diagnosis method and system based on variational mode decomposition and Transform integration
CN121919694A