Multivariable-based water quality prediction method, system, equipment and medium

By combining frequency domain and time domain information, and introducing the self-attention mechanism, the SegRNN network solves the gradient problem in long-term sequence prediction in water quality prediction in the existing technology, and significantly improves prediction accuracy and computing efficiency.

CN119361031AActive Publication Date: 2025-01-24QILU UNIVERSITY OF TECHNOLOGY (SHANDONG ACADEMY OF SCIENCES) +1

Patent Information

Application Number
CN202411942174.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-01-24
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

The prior art faces the problems of gradient explosion and gradient disappearance during long-term series prediction in water quality prediction, resulting in low prediction accuracy and high computing resource demand.

Method used

By extracting the variable time sequence data in the water quality, combined with frequency domain information and time domain information, and introducing self -attention mechanisms, using the additional SEGRNN network to enhance the predictive model's capture ability to capture the characteristics of timing. At the same time, the particle group optimization (PSO) method is used to optimize the super -recessing number to improve the predictive accuracy.

Benefits of technology

It significantly improves the accuracy of water quality prediction, reduces the complexity of prediction models, reduces computing resource requirements, and significantly improves the prediction accuracy of long-term series.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119361031A_ABST
    Figure CN119361031A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of water quality prediction, and provides a multivariable-based water quality prediction method, system, equipment and medium in order to improve the accuracy of water quality prediction. A self-attention mechanism is introduced to solve the problems of gradient explosion and gradient disappearance which are frequently encountered when a traditional recurrent neural network processes a long-time sequence, so that the capturing capability of a prediction model on time sequence characteristics is enhanced; the hyper-parameters are optimized through a particle swarm optimization (PSO) method, so that the prediction precision is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of water quality prediction, and in particular relates to a water quality prediction method, system, equipment and medium based on multiple variables. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] In modern water resources management, water quality prediction and forecasting technology occupies an important position. It can provide strong data support for water resources protection and pollution prevention and control. Accurate water quality prediction not only helps to identify potential pollution risks in advance, but also provides scientific decision-making basis for relevant departments, enabling them to take preventive measures in time to reduce the harm of water pollution to ecology and human health. The accuracy of the water quality forecast model directly affects the scientific nature of decision-making and the timeliness of emergency measures. Therefore, building an effective water quality prediction model is one of the keys to solving water pollution problems.

[0004] In this context, using advanced technical means to predict water quality trends in real time and accurately, and to warn of possible water quality mutations in advance, has become an important means to improve the efficiency of water quality management. Faced with the complexity and variability of water quality, it is difficult to achieve efficient management decisions by relying solely on existing monitoring methods. Therefore, intelligent prediction technology is particularly important. The water quality prediction model based on time series can use historical data to predict future water quality trends, thereby helping decision makers to formulate more scientific and reasonable water quality management plans. Therefore, the study of time series prediction models for water quality issues has very important practical significance.

[0005] Currently, commonly used technologies in time series prediction include recurrent neural networks (RNNs) and Transformers. RNN is a neural network structure that specializes in processing sequence data. It combines the output of the current time step with the state of the previous time step through recursive connections to capture the temporal dependencies in the sequence. Transformers are mainly used to solve sequence modeling problems. Unlike RNNs, Transformers do not rely on recursive structures, but capture dependencies in sequences based on self-attention mechanisms. Through self-attention, Transformers can interact with all other positions in the sequence at each position to fully model global dependencies. However, these technologies often face some challenges when facing long-term series predictions. RNNs perform poorly in capturing long-term dependencies due to gradient vanishing and gradient exploding problems. The complexity and high computational resource requirements of the Transformer model significantly increase its training time. In addition, as the prediction length increases, the prediction error will also rise rapidly. In summary, improving the accuracy of water quality prediction is a technical problem that needs to be solved at present. Summary of the invention

[0006] In order to overcome the above-mentioned deficiencies of the prior art, the present invention provides a water quality prediction method, system, device and medium based on multivariables, which can effectively reduce the complexity of the prediction model and improve the accuracy of water quality prediction.

[0007] In order to achieve the above object, the present invention adopts the following technical solution: In a first aspect, the present invention provides a water quality prediction method based on multiple variables, comprising: Acquire water quality to be tested, and extract multivariate time series data from the water quality to be tested; Extracting frequency features of the multivariate time series data in the water quality to be tested, and combining the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features.

[0008] In a second aspect, the present invention provides a water quality prediction system based on multiple variables, comprising: An acquisition module is configured to: acquire water quality to be tested, and extract multivariate time series data in the water quality to be tested; A prediction module is configured to: extract frequency features of the multivariate time series data in the water quality to be tested, and combine the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features In a third aspect, the present invention provides an electronic device comprising a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in the first aspect is performed.

[0009] In a fourth aspect, the present invention provides a computer-readable storage medium for storing computer instructions, wherein when the computer instructions are executed by a processor, the method described in the first aspect is performed.

[0010] In a fifth aspect, the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described in the first aspect.

[0011] One or more of the above technical solutions have the following beneficial effects: The present invention extracts multivariate time series data from the water quality to be tested, combines frequency domain information with time domain information, and introduces a self-attention mechanism to solve the gradient explosion and gradient vanishing problems often encountered by traditional recurrent neural networks when processing long time series, so as to enhance the prediction model's ability to capture time series characteristics; and optimizes hyperparameters through the particle swarm optimization (PSO) method to improve prediction accuracy.

[0012] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0014] Figure 1 This is a flow chart of the prediction model training process in Embodiment 1 of the present invention; Figure 2 This is a flow chart of water quality prediction based on multiple variables in Example 1 of the present invention. DETAILED DESCRIPTION

[0015] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0016] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.

[0017] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0018] Standardization: It is used to transform data into a distribution with zero mean and unit variance.

[0019] Linear interpolation: Linear interpolation is a mathematical method for estimating unknown data points between known data points. It uses a straight line to estimate the value of an unknown point based on known adjacent data points, assuming that the data change between two points is linear.

[0020] Frequency domain: The frequency domain representation describes the oscillatory components of different frequencies in the time series and their intensity (amplitude).

[0021] Time domain: The time domain representation describes the changes of sequence values ​​over time (or order) and is the most intuitive representation of time series.

[0022] Discrete cosine transform: It converts a sequence from the time domain (or space domain) to the frequency domain and represents the signal through cosine basis functions to achieve the purpose of data compression or feature extraction.

[0023] Attention mechanism: used to allow the model to automatically focus on certain important parts of the input data, so as to better understand and handle complex tasks.

[0024] Particle Swarm Optimization (PSO): It searches for the optimal solution to a problem in the search space by simulating the motion trajectory of a group of particles (solutions). Each particle has its own position and speed. The particle updates its speed and position by tracking its own historical best position and the group's historical best position, thereby performing a global search.

[0025] Embodiment 1 This embodiment discloses a water quality prediction method based on multiple variables, including: Acquire water quality to be tested, and extract multivariate time series data from the water quality to be tested; Extracting frequency features of the multivariate time series data in the water quality to be tested, and combining the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features.

[0026] This embodiment extracts multivariate time series data from the water quality to be tested, combines frequency domain information with time domain information, and introduces a self-attention mechanism to enhance the prediction model's ability to capture time series features; and optimizes hyperparameters through a particle swarm optimization (PSO) method to improve prediction accuracy.

[0027] Combine the following Figure 1-Figure 2 A water quality prediction method based on multiple variables proposed in this embodiment is described in detail, including: Step 1: Obtain the water quality to be tested and extract the multivariate time series data of the water quality to be tested.

[0028] In this embodiment, dissolved oxygen, pH value, permanganate index, ammonia nitrogen and total phosphorus are selected as multivariate time series data in the water quality to be tested, and daily data are used for prediction.

[0029] First, to ensure the accuracy and consistency of the data, outliers in the multivariate time series data are screened and deleted. Specifically, the 3σ principle is used to detect and identify outliers. That is, if a data point deviates from the mean by more than 3 times the standard deviation, the data point is considered an outlier. The expression is: |x-μ|>3σ ,in, x is a data point, m is the mean, s is the standard deviation. Avoid abnormal data from misleading model training and prediction results.

[0030] For missing values ​​in the data set, linear interpolation is used to fill them. Then the data is standardized to adapt the data to the input requirements of the model. After the data processing is completed, the data set is divided into training set, validation set and test set in a ratio of 7:1:2.

[0031] Standardization formula:

[0032] in, X is the variable time series data, m is the mean of the variable time series data, is the standard deviation of the variable time series data, is the standardized data.

[0033] The formula for linear interpolation is:

[0034] in, is the time of the missing data point, and is the known time adjacent to the missing point, and are known data values ​​at adjacent time points.

[0035] Step 2: extract the frequency characteristics of the multivariate time series data in the water quality to be tested, and combine the extracted frequency characteristics with the time domain characteristics to obtain comprehensive characteristics.

[0036] In the original SegRNN model, the input sequence is segmented, and the traditional time-point iteration is replaced by sequence segment iteration, and then the segmented sequence is input into the model.

[0037] In order to further improve the prediction effect and performance of the model, this embodiment introduces the concept of frequency domain information before data is input into the model.

[0038] Through discrete cosine transform, the time series of each time period is converted into frequency domain representation, from which frequency features are extracted. Specifically, the time domain signal is weighted and summed with cosine basis functions of different frequencies, and each frequency domain coefficient obtained reflects the component intensity of the time domain signal at the corresponding frequency. Subsequently, the frequency domain information obtained by discrete cosine transform is spliced ​​with the latest time point in the time series, that is, the frequency domain information and time domain information are reorganized along the feature dimension to form a comprehensive input containing mixed information for further processing by subsequent models. This process combines time domain and frequency domain features, enhancing the model's ability to capture periodicity and trend information.

[0039] Among them, splicing the frequency domain information obtained by discrete cosine transform with the latest time point in the time series means splicing the frequency domain information and the time domain information along the feature dimension, and the spliced ​​data contains mixed information of the time domain and the frequency domain. The latest time point refers to a series of data points closest to the current prediction moment, which reflect the recent dynamic changes in time.

[0040] The frequency domain information obtained by discrete cosine transform is concatenated with the latest time point data closest to the current prediction moment in the time series along the feature dimension to generate input data containing mixed features of time domain and frequency domain. Discrete cosine transform formula:

[0041] in, x [ n ] represents the first n The value at each time point; : After discrete cosine transformation, it represents the k The frequency domain coefficients corresponding to the frequency components; k : Index in the frequency domain, indicating the index of different frequency components when performing discrete cosine transform; N: length of the time series, that is, the total number of data points; n : An index in the time domain, used to traverse each time point in the time series.

[0042] After combining the frequency domain and the time domain, an attention mechanism layer is added, using the self-attention mechanism to further enhance the model's ability to capture important time series features. The self-attention mechanism mainly consists of the following three parts: query, key, and value, through which the attention weight is calculated and the output is generated. The formula is:

[0043] Among them, Q, K, and V represent query, key, and value respectively. is a matrix scaling factor used to avoid gradient vanishing or exploding, and the superscript T represents transpose.

[0044] The output processed by the attention layer is passed to the SegRNN model. The initial unit structure of SegRNN uses GRU. This embodiment changes it and uses LSTM as the unit structure. It also disassembles and improves the various components of LSTM, including removing the output activation function, removing the input gate, removing the forget gate and other architectures. By comparing various architectures, it is found that removing the activation function of the output gate can greatly improve the efficiency of time series prediction and reduce the prediction error. The improved LSTM unit formula is as follows:

[0045]

[0046]

[0047]

[0048]

[0049]

[0050] in, W f , W i , W C , W o are the weight matrices of the forget gate, input gate, candidate memory, and output gate respectively; b f , b i , b C , b o They are the bias items of forget gate, input gate, candidate memory and output gate respectively; h t is a hidden state; represents the hidden state at the previous moment, Represents the input data at the current moment; σ is the Sigmoid activation function; Tanh is the hyperbolic tangent activation function.

[0051] The improved LSTM can significantly improve the efficiency of time series prediction while reducing prediction errors while maintaining the core advantages of LSTM. There are a large number of hyperparameters when training the model, including batch size, learning rate, sequence length, etc. The hyperparameter optimization method PSO is used to adjust the hyperparameters.

[0052] Specifically, the PSO algorithm first defines the range of hyperparameters. Each hyperparameter has a range of values. For example, the range of batch size is set to [16, 256]. Next, the particle swarm is initialized and the objective function value of each particle, i.e., the performance of the model, is calculated. Then, the hyperparameter combination is gradually optimized by updating the particle speed and position until the maximum number of iterations is reached. Finally, the algorithm selects the hyperparameters corresponding to the best particle and retrains the model using these optimal hyperparameters. The PSO algorithm can efficiently find the best hyperparameter combination suitable for the model in the search space, thereby improving the prediction accuracy and training effect of the model.

[0053] The mean absolute error is selected as the loss function of the model, and the formula is:

[0054] Where N is the total number of samples, It is i The true value of the samples, It is i The predicted value of a sample.

[0055] This embodiment can significantly improve the prediction accuracy of long time series, aiming to predict the trend of water quality changes in the next 30 days. Compared with the traditional RNN model, this embodiment has achieved a significant improvement in prediction accuracy; compared with the Transformer model, the calculation time and complexity are greatly reduced. In addition, compared with the original SegRNN model, the model can more effectively capture the complex temporal dependencies in long time series by introducing frequency domain information, self-attention mechanism and improved LSTM unit structure, thereby significantly improving the prediction accuracy.

[0056] Embodiment 2 The purpose of this embodiment is to provide a water quality prediction system based on multiple variables, including: An acquisition module is configured to: acquire water quality to be tested, and extract multivariate time series data in the water quality to be tested; A prediction module is configured to: extract frequency features of the multivariate time series data in the water quality to be tested, and combine the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features.

[0057] In further embodiments, there is also provided: An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 is performed. For the sake of brevity, it will not be described in detail here.

[0058] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0059] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0060] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in embodiment 1 is completed.

[0061] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.

[0062] A computer program product includes a computer program, and when the computer program is executed by a processor, the method described in the first embodiment is implemented.

[0063] The present invention also provides at least one computer program product tangibly stored on a non-transitory computer-readable storage medium. The computer program product includes computer executable instructions, such as instructions included in a program module, which are executed in a device on a real or virtual processor of the target to perform the process / method as described above. Typically, program modules include routines, programs, libraries, objects, classes, components, data structures, etc. that perform specific tasks or implement specific abstract data types. In various embodiments, the functions of program modules can be combined or divided between program modules as needed. Machine executable instructions for program modules can be executed in local or distributed devices. In distributed devices, program modules can be located in local and remote storage media.

[0064] The computer program code for implementing the method of the present invention can be written in one or more programming languages. These computer program codes can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the computer or other programmable data processing device, causes the function / operation specified in the flow chart and / or block diagram to be implemented. The program code can be executed completely on a computer, partially on a computer, as an independent software package, partially on a computer and partially on a remote computer or completely on a remote computer or server.

[0065] In the context of the present invention, computer program codes or related data may be carried by any appropriate carrier to enable a device, apparatus or processor to perform the various processes and operations described above. Examples of carriers include signals, computer readable media, etc. Examples of signals may include electrical, optical, radio, acoustic or other forms of propagation signals, such as carrier waves, infrared signals, etc.

[0066] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0067] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.

Claims

1. A water quality prediction method based on multivariate, characterized in that: include: Acquire water quality to be tested, and extract multivariate time series data from the water quality to be tested; Extracting frequency features of the multivariate time series data in the water quality to be tested, and combining the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features.

2. A water quality prediction method based on multiple variables as claimed in claim 1, characterized in that: The frequency characteristics of the multivariate time series data in the water quality to be tested are extracted using discrete cosine transform.

3. A water quality prediction method based on multiple variables as claimed in claim 1, characterized in that: The SegRNN network is improved by replacing the GRU unit structure in the SegRNN network with a variant LSTM unit; wherein the variant LSTM unit is based on the existing LSTM and removes the activation function of the output gate.

4. A water quality prediction method based on multiple variables as claimed in claim 1, characterized in that: The method also includes preprocessing the multivariate time series data in the water quality to be tested, wherein the preprocessing includes outlier screening, missing value filling and standardization processing.

5. A water quality prediction method based on multiple variables as claimed in claim 1, characterized in that: The hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm, specifically: Define the value range of hyperparameters; Initialize the particle swarm and calculate the objective function value of each particle; where the objective function of each particle corresponds to the performance of the prediction model; Update the speed and position of the particle, gradually optimize the hyperparameter combination until the maximum number of iterations is reached, determine the optimal hyperparameters corresponding to the best particle, and retrain the prediction model using the optimal hyperparameters.

6. A water quality prediction method based on multiple variables as claimed in claim 3, characterized in that: The comprehensive features are predicted after passing through the attention mechanism and then through the improved SegRNN network.

7. A water quality prediction system based on multiple variables, characterized in that: include: An acquisition module is configured to: acquire water quality to be tested, and extract multivariate time series data in the water quality to be tested; A prediction module is configured to: extract frequency features of the multivariate time series data in the water quality to be tested, and combine the extracted frequency features with the latest time domain features to obtain comprehensive features; The comprehensive features are input into the trained prediction model to obtain the prediction results of the water quality to be tested; wherein, during the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts the SegRNN network with an attention mechanism to enhance the prediction model's ability to capture time series features.

8. An electronic device, characterized in that: The method comprises a memory and a processor and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method according to any one of claims 1 to 6 is completed.

9. A computer-readable storage medium, characterized in that: Used to store computer instructions, which, when executed by a processor, complete the method described in any one of claims 1 to 6.

10. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Sewage quality prediction method based on optimized LSTM neural network

    CN112884056A

  • Risk identification method and device, electronic equipment and storage medium

    CN115222169A

  • Laser cladding molten pool morphology prediction method and system based on VMD and improved DA-RNN

    CN116108947A

  • Hybrid deep learning power load prediction method and system integrated with frequency attention

    CN116596144A

  • Time series data prediction method and device, equipment and storage medium

    CN116933124A

Cited By

  • Water quality prediction method, system, device and readable storage medium

    CN122713086A