A Multivariate-Based Water Quality Prediction Method, System, Device, and Medium

By integrating frequency and time domain features with self-attention in a SegRNN network optimized by PSO, the method enhances the accuracy and efficiency of long-term water quality predictions.

CN119361031BActive Publication Date: 2025-07-15QILU UNIVERSITY OF TECHNOLOGY (SHANDONG ACADEMY OF SCIENCES) +1
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing water quality prediction model faces gradient disappearance and gradient explosion problems during long-term series predictions, and the high demand for computing resources leads to an increase in prediction errors, making it difficult to achieve efficient and accurate water quality prediction.

Method used

A multivariate water quality prediction method is adopted, combining frequency domain information and time domain information, a SegRNN network with self-attention mechanism is introduced, and hyperparameters are optimized through particle swarm optimization algorithm to enhance the prediction model's ability to capture timing features.

Benefits of technology

It significantly improves the prediction accuracy of long-time series, reduces the computational complexity, and improves the accuracy and efficiency of water quality prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119361031B_ABST
    Figure CN119361031B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of water quality prediction. In order to improve the accuracy of water quality prediction, a water quality prediction method, system, device and medium based on multiple variables are proposed. By extracting multivariate time series data in the water quality to be measured, combining frequency domain information and time domain information, and introducing a self-attention mechanism to solve the problems of gradient explosion and gradient disappearance that traditional recurrent neural networks often encounter when dealing with long time series, so as to enhance the ability of the prediction model to capture time series features; the hyperparameters are optimized by the particle swarm optimization (PSO) method to improve the prediction accuracy.
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 particularly relates to a water quality prediction method, system, device and medium based on multiple variables. Background Art

[0002] The statements in this part only provide background technical information related to the present invention, and do not necessarily constitute prior art.

[0003] In modern water resource management, water quality prediction and forecasting technologies play an important role, which can provide strong data support for water resource protection and pollution prevention and control. Accurate water quality prediction not only helps to identify potential pollution risks in advance, but also provides a scientific decision-making basis for relevant departments, enabling them to take preventive measures in a timely manner and reduce the harm of water quality pollution to the ecosystem and human health. The accuracy of the water quality forecasting model directly affects the scientific nature of decision-making and the timeliness of emergency measures. Therefore, constructing an effective water quality prediction model is one of the keys to solving the water pollution problem.

[0004] In this context, using advanced technical means to predict the real-time and accurate water quality change trend and early warning of possible water quality mutations has become an important means to improve the efficiency of water quality management. Facing the complex and changeable water quality, it is difficult to achieve efficient management decisions simply relying on existing monitoring means. Therefore, intelligent prediction technology is particularly important. The water quality prediction model based on time series can use historical data to predict the future water quality change trend, thus helping decision-makers formulate more scientific and reasonable water quality management plans. Therefore, the research on the time series prediction model for water quality problems has very important practical significance.

[0005] Currently, commonly used technologies in time series prediction include recurrent neural network (RNN) and Transformer, etc. RNN is a neural network structure specifically for processing sequence data, which combines the output of the current time step with the state of the previous time step through recursive connections to capture the time dependence in the sequence. Transformer is mainly used to solve the sequence modeling problem. Different from RNN, Transformer does not rely on a recursive structure, but captures the dependencies in the sequence based on the self-attention mechanism. Through self-attention, Transformer can interact with all other positions in the sequence at each position, fully modeling global dependencies. However, when facing long time series prediction, these technologies often face some challenges. Due to the problems of gradient vanishing and gradient explosion, RNN performs poorly in capturing long-term dependencies. And the complexity and high computational resource requirements of the Transformer model lead to a significant increase in 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 the technical problem to be solved currently. Summary of the Invention

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

[0007] To achieve the above object, the present invention adopts the following technical solutions:

[0008] In a first aspect, the present invention provides a multi-variable based water quality prediction method, including:

[0009] Obtain the water quality to be measured, and extract the multi-variable time series data in the water quality to be measured;

[0010] Extract the frequency characteristics of the multi-variable time series data in the water quality to be measured, and combine the extracted frequency characteristics with the latest time domain characteristics to obtain comprehensive characteristics;

[0011] Input the comprehensive characteristics into the trained prediction model to obtain the prediction result of the water quality to be measured; wherein, in the training of the prediction model, the hyperparameters of the prediction model are optimized through the particle swarm optimization algorithm; the prediction model adopts a SegRNN network with an attention mechanism to enhance the ability of the prediction model to capture time series characteristics.

[0012] In a second aspect, the present invention provides a multi-variable based water quality prediction system, including:

[0013] An acquisition module, which is configured to: obtain the water quality to be measured, and extract the multi-variable time series data in the water quality to be measured;

[0014] A prediction module, which is configured to: extract the frequency characteristics of the multi-variable time series data in the water quality to be measured, and combine the extracted frequency characteristics with the latest time domain characteristics to obtain comprehensive characteristics;

[0015] Input the comprehensive characteristics into the trained prediction model to obtain the prediction result of the water quality to be measured; wherein, in the training of the prediction model, the hyperparameters of the prediction model are optimized through the particle swarm optimization algorithm; the prediction model adopts a SegRNN network with an attention mechanism to enhance the ability of the prediction model to capture time series characteristics

[0016] In a third aspect, the present invention provides an electronic device, including a memory and a processor, as well as computer instructions stored on the memory and running on the processor. When the computer instructions are run by the processor, the method described in the first aspect is completed.

[0017] Fourthly, the present invention provides a computer-readable storage medium for storing computer instructions, which, when executed by a processor, complete the method described in the first aspect.

[0018] Fifthly, the present invention provides a computer program product, including a computer program, which, when executed by a processor, implements the method described in the first aspect.

[0019] The above one or more technical solutions have the following beneficial effects:

[0020] By extracting multivariate time series data from the water quality to be measured, combining frequency domain information and time domain information, and introducing a self-attention mechanism to solve the problems of gradient explosion and gradient disappearance that traditional recurrent neural networks often encounter when dealing with long time series, the present invention enhances the ability of the prediction model to capture time series features; and optimizes hyperparameters through the particle swarm optimization (PSO) method to improve the prediction accuracy.

[0021] Advantages of additional aspects of the present invention will be partially given in the following description, partially become apparent from the following description, or be understood through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings forming a part of this specification are used to provide a further understanding of the present invention. The schematic embodiments and descriptions thereof of the present invention are used to explain the present invention and do not constitute an improper limitation to the present invention.

[0023] Figure 1 It is a flowchart of the prediction model training process in the first embodiment of the present invention;

[0024] Figure 2 It is a flowchart of water quality prediction based on multiple variables in the first embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0025] It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.

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

[0027] Without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.

[0028] Standardization: used to convert data into a distribution with zero mean and unit variance.

[0029] Linear interpolation: Linear interpolation is a mathematical method for estimating unknown data points between known data points. It is based on known adjacent data points and assumes that the data change between two points is linear, thus using a straight line to estimate the value of the unknown point.

[0030] Frequency domain: The frequency-domain representation describes the oscillatory components of different frequencies in a time series and their intensities (amplitudes).

[0031] Time domain: The time-domain representation describes how the sequence values change over time (or in order), which is the most intuitive representation of a time series.

[0032] Discrete cosine transform: It transforms a sequence from the time domain (or spatial domain) to the frequency domain and represents the signal through cosine basis functions, thus achieving the purpose of data compression or feature extraction.

[0033] Attention mechanism: It is used to enable the model to automatically focus on certain important parts of the input data, so as to better understand and process complex tasks.

[0034] Particle swarm optimization algorithm (PSO): By simulating the movement trajectories of a group of particles (solutions), it searches for the optimal solution to the problem in the search space. Each particle has its own position and velocity, and the particle updates its velocity and position by tracking its personal historical best position and the group historical best position, thus conducting a global search.

[0035] Example 1

[0036] This example discloses a multi-variable based water quality prediction method, including:

[0037] Obtain the water quality to be measured and extract the multi-variable time series data in the water quality to be measured;

[0038] Extract the frequency characteristics of the multi-variable time series data in the water quality to be measured, combine the extracted frequency characteristics with the latest time-domain characteristics to obtain comprehensive characteristics;

[0039] Input the comprehensive characteristics into the trained prediction model to obtain the prediction result of the water quality to be measured; wherein, in the training of the prediction model, the hyperparameters of the prediction model are optimized by the particle swarm optimization algorithm; the prediction model adopts a SegRNN network with an added attention mechanism to enhance the ability of the prediction model to capture time series characteristics.

[0040] This example extracts the multi-variable time series data in the water quality to be measured, combines the frequency-domain information and time-domain information, and introduces the self-attention mechanism to enhance the ability of the prediction model to capture time series characteristics; the hyperparameters are optimized by the particle swarm optimization (PSO) method to improve the prediction accuracy.

[0041] The following combines Figure 1 - Figure 2A detailed description of a water quality prediction method based on multiple variables proposed in this embodiment is as follows:

[0042] Step 1: Obtain the water quality to be measured and extract the multi-variable time series data in the water quality to be measured.

[0043] In this embodiment, dissolved oxygen, pH value, permanganate index, ammonia nitrogen, and total phosphorus are selected as the multi-variable time series data in the water quality to be measured, and daily data is used for prediction.

[0044] First, to ensure the accuracy and consistency of the data, outliers in the multi-variable time series data are screened and deleted. Specifically, the 3σ principle is used to detect and identify outliers, that is, if the deviation of a data point from the mean exceeds 3 times the standard deviation, this data point is considered an outlier, and the expression is |x - μ| > 3σ , where x is the data point, μ is the mean, σ is the standard deviation. This is to avoid misleading the model training and prediction results caused by abnormal data.

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

[0046] Standardization formula:

[0047]

[0048] where X is the variable time series data, μ is the mean of the variable time series data, is the standard deviation of the variable time series data, is the standardized data.

[0049] The formula for linear interpolation is:

[0050]

[0051] where is the time of the missing data point, and are the known times adjacent to the missing point, and are the known data values at the adjacent time points.

[0052] Step 2: Extract the frequency characteristics of the multi-variable time series data in the water quality to be measured, and combine the extracted frequency characteristics with the time domain characteristics to obtain comprehensive characteristics.

[0053] In the original SegRNN model, by segmenting the input sequence and replacing the traditional time - point - by - time - point iteration with sequence - segment iteration, and then inputting the segmented sequence into the model.

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

[0055] Through discrete cosine transform, the time - series of each time period is converted into a 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 resulting frequency - domain coefficient reflects the component intensity of the time - domain signal at the corresponding frequency. Subsequently, the frequency - domain information obtained by discrete cosine transform is concatenated 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 the subsequent model. This process combines time - domain and frequency - domain features, enhancing the model's ability to capture periodic and trend information.

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

[0057] Concatenate the frequency - domain information obtained by discrete cosine transform with the data of the latest time - point closest to the current prediction moment in the time series along the feature dimension to generate input data containing mixed time - domain and frequency - domain features.

[0058] Discrete cosine transform formula:

[0059]

[0060] Among them, x n represents the value of the n th time - point in the time series; : after discrete cosine transform, represents the frequency - domain coefficient corresponding to the k th frequency component in the time series; k : index in the frequency domain, representing the index of different frequency components when performing discrete cosine transform; N: the length of the time series, that is, the total number of data points; n : index in the time domain, used to traverse each time - point in the time series.

[0061] ​After combining the frequency domain and the time domain, an attention mechanism layer is added, and the self-attention mechanism is adopted to further enhance the model's ability to capture important temporal features. The self-attention mechanism mainly consists of the following three parts: Query, Key, and Value. Attention weights are calculated through these parts and the output is generated. The formula is:

[0062]

[0063] Among them, Q, K, and V represent Query, Key, and Value respectively, is the matrix scaling factor, used to avoid gradient vanishing or explosion, and the superscript T represents transpose.

[0064] The output processed by the attention layer is passed to the SegRNN model. The initial cell structure of SegRNN is GRU. In this embodiment, it is changed to use LSTM as the cell structure, and each component of LSTM is disassembled and improved, including removing the output activation function, removing the input gate, removing the forget gate, and other architectures. By comparing multiple architectures, it is found that removing the activation function of the output gate can significantly improve the efficiency of time series prediction and reduce the prediction error at the same time. The formula of the improved LSTM cell is as follows:

[0065]

[0066]

[0067]

[0068]

[0069]

[0070]

[0071] Among them, 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 are the bias terms of the forget gate, input gate, candidate memory, and output gate respectively; ht is in the 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.

[0072] The improved LSTM can significantly improve the efficiency of time series prediction and reduce the prediction error while maintaining the core advantages of the LSTM.

[0073] There are a large number of hyperparameters during model training, including batch size, learning rate, sequence length, etc. The hyperparameter optimization method PSO is used to adjust the hyperparameters.

[0074] Specifically, the PSO algorithm first defines the value range of the hyperparameters. Each hyperparameter has a value range. For example, the value range of the batch size is set to [16, 256]; next, the particle swarm is initialized, and the objective function value of each particle, that is, the performance of the model, is calculated; then, by updating the velocity and position of the particles, the hyperparameter combination is gradually optimized until the maximum number of iterations is reached; finally, the algorithm will select the hyperparameters corresponding to the best particle and retrain the model using these optimal hyperparameters. Through the PSO algorithm, the best hyperparameter combination suitable for the model can be efficiently found in the search space, thereby improving the prediction accuracy and training effect of the model.

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

[0076]

[0077] where N is the total number of samples, is the real value of the i th sample, is the i predicted value of the th sample.

[0078] This embodiment can significantly improve the prediction accuracy of long time series and aims to predict the water quality change trend 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 have been greatly reduced. In addition, compared with the original SegRNN model, by introducing frequency domain information, self-attention mechanism and improved LSTM unit structure, the model can more effectively capture the complex temporal dependencies in long time series, thereby significantly improving the prediction accuracy.

[0079] Embodiment 2

[0080] The purpose of this embodiment is to provide a water quality prediction system based on multiple variables, including:

[0081] An acquisition module, which is configured to: acquire the water quality to be measured, and extract multivariate time series data in the water quality to be measured;

[0082] A prediction module, which is configured to: extract the frequency characteristics of the multivariate time series data in the water quality to be measured, combine the extracted frequency characteristics with the latest time domain characteristics to obtain comprehensive characteristics;

[0083] Input the comprehensive characteristics into a trained prediction model to obtain a prediction result of the water quality to be measured; wherein, in the training of the prediction model, the hyperparameters of the prediction model are optimized by a particle swarm optimization algorithm; the prediction model adopts a SegRNN network with an attention mechanism to enhance the ability of the prediction model to capture time series characteristics.

[0084] In more embodiments, there is also provided:

[0085] An electronic device, including a memory and a processor, and computer instructions stored on the memory and running on the processor. When the computer instructions are run by the processor, the method described in Embodiment 1 is completed. For the sake of brevity, it will not be elaborated here.

[0086] 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.

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

[0088] A computer-readable storage medium for storing computer instructions, which when executed by a processor, completes the method described in Embodiment 1.

[0089] The method in Embodiment 1 can be directly implemented by a hardware processor to complete, or can be implemented by a combination of hardware and software modules in the processor. The software module may be located in a mature storage medium in the art 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. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps of the above method. To avoid repetition, it will not be described in detail here.

[0090] A computer program product includes a computer program which, when executed by a processor, implements the method described in Embodiment 1.

[0091] 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 program modules, which are executed in a device on a target real or virtual processor to perform the processes / methods described above. Generally, 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 as needed. The machine-executable instructions for program modules can be executed within local or distributed devices. In a distributed device, program modules can be located in local and remote storage media.

[0092] The computer program code for implementing the method of the present invention can be written in one or more programming languages. This computer program code can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the program code is executed by the computer or other programmable data processing device, the functions / operations specified in the flowchart and / or block diagram are implemented. The program code can be executed entirely on the computer, partially on the computer, as a stand-alone software package, partially on the computer and partially on a remote computer, or entirely on a remote computer or server.

[0093] In the context of the present invention, the computer program code or related data can be carried by any suitable carrier so that a device, apparatus, or processor can perform the various processes and operations described above. Examples of carriers include signals, computer-readable media, etc. Examples of signals can include electrical, optical, radio, acoustic, or other forms of propagated signals, such as carrier waves, infrared signals, etc.

[0094] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with this embodiment can be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. A professional technician can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of this application.

[0095] Although the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, they do not limit the protection scope of the present invention. Those skilled in the art should understand that various modifications or deformations that can be made without creative efforts on the basis of the technical solutions of the present invention are still within the protection scope of the present invention.

Claims

1. A water quality prediction method based on multiple variables, characterized in that Including: Obtain the water quality to be measured and extract the multivariate time series data in the water quality to be measured; Extract the frequency characteristics of the multivariate time series data in the water quality to be measured, and combine the extracted frequency characteristics with the latest time domain characteristics to obtain comprehensive characteristics; Specifically: Use discrete cosine transform to extract the frequency characteristics of the multivariate time series data in the water quality to be measured; Concatenate the frequency domain information obtained by discrete cosine transform with the latest time point in the time series along the feature dimension to form a comprehensive input containing mixed information; Among them, the latest time point refers to a series of data points closest to the current prediction moment; Input the comprehensive characteristics into the trained prediction model to obtain the prediction result of the water quality to be measured; Among them, in the training of the prediction model, the hyperparameters of the prediction model are optimized through the particle swarm optimization algorithm; The prediction model uses a SegRNN network with self-attention mechanism to enhance the ability of the prediction model to capture time series characteristics; The comprehensive characteristics are processed through the self-attention mechanism and the SegRNN network in sequence; Improve the SegRNN network, and use a variant LSTM unit to replace the GRU unit structure in the SegRNN network; Among them, the variant LSTM unit is based on the existing LSTM and removes the activation function of the output gate.

2. The water quality prediction method based on multiple variables according to claim 1, characterized in that It also includes preprocessing the multivariate time series data in the water quality to be measured, and the preprocessing includes outlier screening, missing value filling and standardization processing.

3. The water quality prediction method based on multiple variables according to claim 1, characterized in that, Optimize the hyperparameters of the prediction model through the particle swarm optimization algorithm, specifically: Define the value range of the hyperparameters; Initialize the particle swarm and calculate the objective function value of each particle; Among them, the objective function of each particle corresponds to the performance of the prediction model; Update the velocity and position of the particles, 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 with the optimal hyperparameters.

4. A water quality prediction system based on multiple variables, characterized in that, Including: An acquisition module, which is configured to: Obtain the water quality to be measured and extract the multivariate time series data in the water quality to be measured; A prediction module, which is configured to: Extract the frequency characteristics of the multivariate time series data in the water quality to be measured, and combine the extracted frequency characteristics with the latest time domain characteristics to obtain comprehensive characteristics; Specifically: Use discrete cosine transform to extract the frequency characteristics of the multivariate time series data in the water quality to be measured; Concatenate the frequency domain information obtained by discrete cosine transform with the latest time point in the time series along the feature dimension to form a comprehensive input containing mixed information; Among them, the latest time point refers to a series of data points closest to the current prediction moment; Input the comprehensive characteristics into the trained prediction model to obtain the prediction result of the water quality to be measured; Among them, in the training of the prediction model, the hyperparameters of the prediction model are optimized through the particle swarm optimization algorithm; The prediction model uses a SegRNN network with attention mechanism to enhance the ability of the prediction model to capture time series characteristics; The comprehensive characteristics are processed through the self-attention mechanism and the SegRNN network in sequence; Improve the SegRNN network by replacing the GRU cell structure in the SegRNN network with a variant LSTM cell; wherein, the variant LSTM cell is based on the existing LSTM and removes the activation function of the output gate.

5. An electronic device, characterized in that, It includes a memory, a processor, and computer instructions stored on the memory and running on the processor. When the computer instructions are run by the processor, the method according to any one of claims 1-3 is completed.

6. A computer-readable storage medium, characterized in that, It is used to store computer instructions. When the computer instructions are executed by the processor, the method according to any one of claims 1-3 is completed.

7. A computer program product, characterized in that, It includes a computer program. When the computer program is executed by the processor, the method according to any one of claims 1-3 is implemented.

Citation Information

Patent Citations

  • Sewage quality prediction method based on optimized LSTM neural network

    CN112884056A

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

    CN116933124A