A water quality mutation prediction method and system based on explicit periodic decoupling and multi-scale hybrid expert network
By employing explicit periodic decoupling and a multi-scale hybrid expert network approach, the problem of strong periodic signals masking weak abrupt change signals in water quality prediction was solved, achieving efficient and accurate prediction of water quality abrupt changes and improving the model's response speed and robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HOHAI UNIV
- Filing Date
- 2026-04-28
- Publication Date
- 2026-07-14
Smart Images

Figure CN122113681B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of water environment monitoring and intelligent early warning technology, specifically involving a prediction method for processing non-stationary time series data using deep learning technology, and in particular a water quality mutation prediction method and system based on explicit periodic decoupling and multi-scale hybrid expert network. Background Technology
[0002] Water quality monitoring and forecasting are fundamental tasks for water environment management, pollution prevention and control, and water ecological security. Accurately predicting the future trends of key water quality indicators such as dissolved oxygen (DO), ammonia nitrogen (NH3-N), and total phosphorus (TP) is of great significance for timely detection of sudden environmental pollution incidents and optimization of water conservancy project scheduling.
[0003] With the development of artificial intelligence technology, deep learning models, represented by Long Short-Term Memory (LSTM) networks and Transformers, have been widely applied in water quality prediction. These models, by learning the statistical regularities of historical data, often achieve high prediction accuracy during normal stable periods. However, in actual water environment supervision operations, existing data-driven models still face severe challenges. First, strong periodic signals mask weak abrupt change signals. Water quality data usually exhibits significant natural periodicity (such as the diurnal rhythm of dissolved oxygen influenced by photosynthesis). Existing deep learning models tend to prioritize fitting this large-amplitude, easily learned periodic "background waveform," often ignoring the small or instantaneous "abrupt change signals" superimposed on the periodicity, caused by sewage discharge or heavy rain. This results in a sluggish response from the model when abrupt changes occur. Second, the prediction results suffer from phase lag and amplitude reduction. When faced with abrupt changes in water quality (such as a sharp rise in ammonia nitrogen concentration), the prediction curves generated by existing models (especially those trained based on mean squared error loss) often appear as "shifted" observation curves, meaning that the predicted peak appears later than the actual peak, and the predicted peak height is significantly lower than the actual value. This lag and conservatism significantly reduce the model's practical value in early warning tasks. Third, a single model struggles to account for different frequency characteristics: Water quality changes are coupled with slow trend terms (such as seasonal variations) and rapid abrupt changes (such as event-driven fluctuations). Traditional methods attempt to fit these two distinctly different dynamic characteristics simultaneously using the same neural network, often resulting in neglecting one aspect for the other, making it difficult to capture abrupt changes while maintaining trend stability. Summary of the Invention
[0004] Purpose of the invention: One objective of this invention is to provide a water quality abrupt change prediction method based on explicit periodic decoupling and multi-scale hybrid expert networks. This method can explicitly decouple the periodic background and abrupt change residual from a physical mechanism and perform refined modeling for different frequency characteristics, thereby improving the response speed and prediction accuracy to sudden water quality events.
[0005] Another objective of this invention is to provide a water quality mutation prediction system based on explicit periodic decoupling and multi-scale hybrid expert networks.
[0006] Technical solution: The method described in this invention includes the following steps:
[0007] Construct a multi-source water quality time series dataset, including target water quality variables and driving covariates; encapsulate the multi-source water quality time series dataset into batch tensors to obtain the original input tensor and ground truth label tensor containing batch dimensions, and output the batch start time index for period alignment;
[0008] Construct an explicit periodic memory module and perform periodic decoupling; including: constructing an explicit periodic memory tensor and constructing a phase index matrix that is completely consistent with the spatiotemporal dimension of the original input tensor; using the phase index matrix to retrieve periodic sequence tensors in batches from the explicit periodic memory tensor; decoupling the generated periodic sequence tensor from the original input tensor and separating the pure residual sequence containing mutation information;
[0009] Through mathematical transformation, the pure residual sequence is decomposed in the frequency domain to extract low-frequency trend components and high-frequency mutation components.
[0010] A multi-scale hybrid expert network with environmental perception gating is constructed, comprising a hybrid expert network and an environmental perception gating network. The hybrid expert network includes a low-frequency trend expert network and a high-frequency mutation expert network. Multi-step predictions are performed on the low-frequency trend component and the high-frequency mutation component to obtain the low-frequency trend expert prediction value and the high-frequency mutation expert prediction value, respectively. An environmental perception gating network is constructed based on the driving covariates, and a dynamic gating weight is output that fuses the trend expert weight and the mutation expert weight. The low-frequency trend expert prediction value and the high-frequency mutation expert prediction value are then weighted and fused using the dynamic gating weight to obtain the prediction residual tensor.
[0011] Results Reconstruction and Mutation Weighted Optimization: The predicted residual tensor and the explicit periodic memory tensor are aligned with future phases and reconstructed to obtain a standardized predicted tensor. At the same time, a mutation weighted mean square error loss function is constructed to jointly update the parameters of the explicit periodic memory tensor, the hybrid expert network and the environment-aware gating network.
[0012] Furthermore, the multi-source water quality time-series dataset is encapsulated into batch tensors to obtain the original input tensor and truth label tensor containing the batch dimension, and the batch start time index for period alignment is output; including:
[0013] A sliding window is used to convert the standardized observation vectors in the multi-source water quality time series dataset into input-output sample pairs required for network training. For any historical window's end time... Define the history window sequence and the corresponding future truth value label sequence :
[0014] ;
[0015] ;
[0016] in, These represent different moments within the historical window. 3D standardized observation vector For the future Step 3D standardized truth label vector For the length of the history window, To predict the step size, input-output sample pairs are obtained. Random sampling Each input-output sample pair constitutes a batch, which is encapsulated as the original input tensor and the truth label tensor containing the batch dimension. This represents the batch dimension; it also records the absolute time step index of the historical window start point in the multi-source water quality time series dataset for each input-output sample pair, forming the batch start time vector.
[0017] Furthermore, the phase index matrix is used to batch retrieve periodic sequence tensors from the explicit periodic memory tensor: the generated periodic sequence tensors are decoupled from the original input tensor to separate the pure residual sequence containing mutation information; including:
[0018] Using the phase index matrix as a lookup table, parallel searching is performed on the time dimension of the explicit periodic memory tensor to generate a periodic sequence tensor with the same dimension as the original input tensor; the formula for calculating any element in the periodic sequence tensor is:
[0019] ;
[0020] in, Indicates the first The sample in its historical window Each time step dimensional periodic baseline vector, Represents the phase index from the explicit periodic memory tensor Found dimensional periodic baseline vector, Indicates the first The sample in its historical window The periodic phase index corresponding to each time step. This indicates the index of the time step within the history window. Indicates the sample index. Indicates selecting all One feature channel;
[0021] By using element-level subtraction, the generated periodic sequence tensor is removed from the original input tensor to obtain a pure residual sequence.
[0022] Furthermore, through mathematical transformations, the pure residual sequence is decomposed in the frequency domain to extract low-frequency trend components and high-frequency abrupt change components, including:
[0023] Non-overlapping average pooling downsampling is performed on the pure residual sequence in the time dimension to obtain the compressed feature sequence. Linear interpolation upsampling is then performed on the compressed feature sequence to obtain the low-frequency trend component.
[0024] Based on the additivity principle of signal decomposition, the high-frequency mutation components containing mutation information are extracted using subtraction operations.
[0025] Furthermore, an environment-aware gating network is constructed based on driving covariates, outputting dynamic gating weights that fuse trend expert weights and mutation expert weights. These dynamic gating weights are then used to weight and fuse low-frequency trend expert predictions and high-frequency mutation expert predictions to obtain the prediction residual tensor; including:
[0026] The driving covariates are extracted from the original input tensor, and then flattened in the time and channel dimensions to obtain the gated input feature vector.
[0027] Unnormalized fraction vectors are obtained by linear mapping based on gated input feature vectors;
[0028] The unnormalized score vector is normalized into dynamic gating weights using the Softmax function, including trend expert weights and mutation expert weights;
[0029] By using dynamic gating weights, the low-frequency trend expert predictions and the high-frequency mutation expert predictions are linearly weighted and fused to obtain the final prediction residual tensor. ;
[0030] ;
[0031] in, Tensor The first in A slice, Tensor The first in A slice, Tensor The first in A slice, This represents element-wise multiplication under the broadcast mechanism. Weighting for trend experts For mutation expert weights.
[0032] Further, the results are reconstructed and optimized using mutation weighting, including:
[0033] Construct a future phase index matrix, and use the future phase index matrix to perform batch retrieval on the explicit periodic memory tensor to obtain a future periodic tensor aligned with the prediction time dimension.
[0034] The predicted residual tensor and the future period tensor are added element-wise to obtain the normalized predicted tensor with a normalized scale.
[0035] A mutation weight matrix is constructed based on the rate of change of the real labels. A mutation weighted mean square error loss function is constructed based on the mutation weight matrix. A gradient-based optimization algorithm is used to minimize the mutation weighted mean square error loss function. Finally, the water quality mutation prediction results under physical dimensions are output.
[0036] The system corresponding to the method described in this invention includes:
[0037] The dataset construction and processing unit is used to construct a multi-source water quality time series dataset, including target water quality variables and driving covariates; it performs batch tensor encapsulation on the multi-source water quality time series dataset to obtain the original input tensor and truth label tensor containing the batch dimension, and outputs the batch start time index for period alignment.
[0038] The periodic decoupling unit is used to construct an explicit periodic memory module and perform periodic decoupling; it includes: constructing an explicit periodic memory tensor and constructing a phase index matrix that is completely consistent with the spatiotemporal dimension of the original input tensor; using the phase index matrix to retrieve periodic sequence tensors in batches from the explicit periodic memory tensor; and decoupling the generated periodic sequence tensor from the original input tensor to separate the pure residual sequence containing mutation information.
[0039] The residual decomposition unit is used to decompose the pure residual sequence in the frequency domain through mathematical transformations, and extract low-frequency trend components and high-frequency abrupt change components.
[0040] The expert network construction unit is used to construct a multi-scale hybrid expert network for environment perception gating, including a hybrid expert network and an environment perception gating network. The hybrid expert network includes a low-frequency trend expert network and a high-frequency mutation expert network, which perform multi-step predictions on the low-frequency trend component and the high-frequency mutation component respectively to obtain the low-frequency trend expert prediction value and the high-frequency mutation expert prediction value. The environment perception gating network is constructed based on the driving covariates, and outputs dynamic gating weights that fuse the trend expert weights and mutation expert weights. The low-frequency trend expert prediction value and the high-frequency mutation expert prediction value are then weighted and fused using the dynamic gating weights to obtain the prediction residual tensor.
[0041] The model optimization unit is used for result reconstruction and mutation-weighted optimization: it aligns the predicted residual tensor with the explicit periodic memory tensor in the future phase and reconstructs the standardized predicted tensor. At the same time, it constructs a mutation-weighted mean square error loss function to jointly update the parameters of the explicit periodic memory tensor, the hybrid expert network and the environment-aware gating network.
[0042] An electronic device for storing and executing the method includes:
[0043] Memory, used to store computer programs;
[0044] A processor for executing the computer program to implement the method.
[0045] A non-volatile storage medium for storing and executing the method, for storing a computer program, wherein the computer program implements the method when executed by a processor.
[0046] The present invention also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the method described.
[0047] Beneficial effects: Compared with the prior art, the significant technical effects of the present invention include: (1) effectively solving the problem of capturing mutation signals under strong periodic background; the present invention innovatively introduces an explicit periodic memory module, which explicitly models the inherent periodic pattern of the data through learnable parameter tensors and "physically strips" it from the original input to obtain a pure residual sequence; this mechanism forces the subsequent neural network to focus on learning those "abnormal fluctuations" (i.e., residuals) that deviate from the normal period, thereby avoiding the problem of the model ignoring sudden pollution signals due to overfitting the periodic background, and significantly improving the model's sensitivity to mutation events; (2) eliminating the phase lag of the prediction results and improving the peak prediction accuracy; through the combined use of multi-scale residual decomposition and mutation weighted loss function, the present invention can separate high-frequency mutation signals and use a specially designed mutation expert network for independent modeling; combined with a loss function that assigns high weight to the first-order difference, the model is forced to focus on the moment when the numerical changes drastically during the training phase; experiments show that this method can effectively correct the prediction lag common in traditional LSTM models. (3) It realizes dynamic environmental perception and adaptive prediction. The present invention constructs an environmental perception gating network and uses driving covariates such as rainfall and water level as gating signals. This enables the model to dynamically adjust the weight ratio of "trend expert" and "mutation expert" according to the current hydrological and meteorological conditions (for example, automatically increasing the weight of mutation expert during rainstorms). This mechanism enables the model to have a discrimination ability similar to human experts, remain stable during the normal water period, and react quickly during the mutation period, thus enhancing the robustness of the model in complex and changeable environments. (4) It is computationally efficient and physically interpretable. Compared with the Transformer model based on complex attention mechanism, the explicit periodic memory tensor and lightweight hybrid expert network used in the present invention are more computationally efficient and support parallel training (thanks to the batch index retrieval mechanism). At the same time, the trained periodic memory tensor directly reflects the "standard daily variation curve" of water quality of the monitoring section, providing an intuitive physical benchmark for water environment managers and enhancing the interpretability of the model. Attached Figure Description
[0048] Figure 1 This is a flowchart of the method of the present invention;
[0049] Figure 2 This is a schematic diagram of DO periodic decoupling, where (a) is the original DO sequence, (b) is the DO periodic sequence, and (c) is the DO residual sequence after periodic decoupling.
[0050] Figure 3 This is a schematic diagram of DO multiscale decomposition, where (a) represents the low-frequency trend component and (b) represents the high-frequency abrupt change component.
[0051] Figure 4The diagram shows the final prediction results of DO, where (a) is the final prediction result of DO and (b) is the prediction error of DO. Detailed Implementation
[0052] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.
[0053] like Figure 1 As shown, the method of the present invention includes the following steps:
[0054] Step S1: Construct and preprocess a multi-source water quality time-series dataset. This step aims to convert raw, unstructured environmental monitoring data into a standard tensor format containing batch dimensions that can be directly read by deep learning models, and output batch start time indices for period alignment. Specifically, it includes the following steps:
[0055] S1-1: Data Acquisition and Cleaning. Acquire the raw historical time series data of the monitoring sections in the target watershed. The data includes target water quality variables and driving covariates. Target water quality variables refer to the water quality indicators that need to be predicted, including dissolved oxygen (DO), ammonia nitrogen (NH3-N), permanganate index (CODMn), and total phosphorus (TP). Driving covariates refer to external environmental factors affecting water quality changes, including rainfall, water level, flow rate, water temperature, and air temperature. Let the total time step be... , will be the moment The original historical time series data is represented as ,in The total number of characteristic channels represents the combined total of the target water quality variable and the driving covariates, and is expressed as... Indicates the first The variable (the first) (each feature channel) at time... The original historical time series data, , The acquired raw historical time series data is cleaned, including time alignment, outlier handling, and missing value handling. Time alignment refers to resampling all variables at a uniform sampling interval and aligning them to the same time axis; outlier handling refers to removing or truncating data points that are outside the physical reasonable range or instrument measurement range and marking them as missing; missing value handling refers to imputing missing values using linear interpolation to obtain a continuous multivariate series. .
[0056] S1-2: Data Standardization. To eliminate the influence of different variable units on model training, all variables are standardized using Z-scores. The standardization formula is as follows:
[0057] ;
[0058] in, Indicates the first The mean of each variable; Indicates the first Standard deviation of each variable; Represents the standardized first Each variable value. The time... The standardized observation vector is denoted as:
[0059] ;
[0060] This set of vectors constitutes the multi-source water quality time series dataset. .
[0061] S1-3: Sliding Window Sample Construction and Batch Tensor Encapsulation. The sliding window technique is used to... This is converted into the input-output sample pairs required for subsequent training. For any historical window's end time... Define the history window sequence and the corresponding future truth value label sequence :
[0062] ;
[0063] ;
[0064] in, These represent different moments within the historical window. 3D standardized observation vector For the future Step 3D standardized observation vector For the length of the history window, To predict the step size. This yields the input-output sample pair. In each subsequent iteration of training or inference, random samples are drawn. Each input-output sample pair constitutes a batch (i.e., the batch dimension is 1). Encapsulate it as a raw input tensor containing batch dimensions. and truth label tensor That is, satisfying:
[0065] ;
[0066] ;
[0067] in, Tensor The Middle slices ( [1, This slice is a matrix. Tensor The A slice, Indicates the end time of the historical window as Historical window sequence, Indicates the end time of the historical window as The future truth value label sequence, For the first The historical window ends for each input-output sample pair. To enable periodic phase alignment in step S2, this step also records the start time of the historical window in the entire sequence for each input-output sample pair. Absolute time step index in (multi-source water quality time series dataset) Defined as:
[0068] ;
[0069] And form a batch start time vector:
[0070] ;
[0071] in, These represent the 1st, 2nd, ..., 1st batch of the batch. The starting point of the history window in each input-output sample pair is in the entire sequence. The absolute time step index in the table.
[0072] Step S2: Construct an explicit periodic memory module and decouple it from the periodicity. This step aims to establish a learnable parameterization mechanism for explicitly modeling the inherent periodic patterns of water quality data (such as diurnal variations) and removing periodic components from the original input tensor, thereby separating the pure residual sequence containing abrupt change information.
[0073] S2-1: Initialize the explicit periodic memory tensor. In a neural network, an independent parameter matrix is initialized that can be updated via gradient descent during training. This matrix is defined as the explicit periodic memory tensor, denoted as [e.g., S2-1]. .in This indicates the preset base period length. In this embodiment, for hourly sampling data, it is set... (Represents a 24-hour daily cycle); They are shared at the batch level; among which Indicates the periodic phase as Time corresponding Dimensional periodic baseline vector.
[0074] S2-2: Periodic component retrieval and alignment based on batch time index. The core of this sub-step lies in constructing a tensor that is consistent with the original input tensor. A phase index matrix with completely consistent spatiotemporal dimensions, and using this phase index matrix from... Medium-batch retrieval of periodic sequence tensors. First, generate a phase index matrix based on the batch relative time. Phase index matrix The Middle line, number Column elements Representing the The sample in its historical window The periodic phase index corresponding to each time step is calculated using the following formula:
[0075] ;
[0076] in, This represents the index of the time step within the history window, with a value of... ; The absolute time step index obtained in step S1, Indicates the length of the basic period Modulo operation is performed. Then, a broadcast collection operation is executed. The phase index matrix is used. As a lookup table, in the explicit periodic memory tensor Parallel retrieval is performed in the time dimension to generate tensors that are identical to the original input tensors. Periodic sequence tensors with completely identical dimensions For any element in a periodic sequence tensor, the computation logic is as follows:
[0077] ;
[0078] in, Indicates the first The sample in its historical window Each time step dimensional periodic baseline vector, Indicates from Middle by phase index Found dimensional periodic baseline vector, Indicates selecting all Each feature channel. Through this step, the original dimension [ , The static parameters of ] are expanded to a dimension of [ , , The dynamic tensor of [] achieves [interaction with] the original input tensor. Timing alignment.
[0079] S2-3: Periodic Decoupling and Purified Residual Acquisition. Using element-wise subtraction, the generated periodic sequence tensor is separated from the original input tensor obtained in step S1, yielding a purified residual sequence, denoted as... The calculation formula is as follows:
[0080] .
[0081] Step S3: Multi-scale residual decomposition. This step decomposes the purified residual sequence from step S2. As input, low-frequency trend components are extracted using an "average pooling downsampling + linear interpolation upsampling" method, and high-frequency abrupt change components are obtained in differential form. The low-frequency trend components are then output. With high-frequency mutation components The two types of expert networks are modeled separately for step S4.
[0082] S3-1: Low-frequency trend extraction based on average pooling downsampling and linear interpolation upsampling. To filter out instantaneous high-frequency fluctuations in the residual sequence while retaining its short-term trend, a trend extractor incorporating downsampling and upsampling is constructed. First, average pooling downsampling is performed. The pooling window size is defined as... The step size is also set to For pure residual sequences Non-overlapping average pooling operations are performed over time to obtain the compressed feature sequence. , where the intermediate hidden layer parameters , This indicates rounding down to the nearest integer. For the first integer in the batch... The sample, the first The first feature channel, the downsampled first The compressed feature sequence at each time step Represented as:
[0083] ;
[0084] The average pooling formula weakens high-frequency fluctuations through local averaging. Then, linear interpolation upsampling is performed. To align the extracted trend components with the original input tensor in the time dimension, [the following is omitted as the text is incomplete and requires further context]. Upsample length The low-frequency trend component was obtained. For any point in time on the original timeline First, define its corresponding downsampling index. :
[0085] = ;
[0086] And define the interpolation weight coefficients. :
[0087] ;
[0088] make Then we have:
[0089] ;
[0090] in, Tensor The position in is ( elements, Tensor The position in is ( elements, Tensor The position in is ( Element.
[0091] Through the above interpolation, the upsampled... and Having the same time length It exhibits a smooth trend curve.
[0092] S3-2: High-Frequency Abrupt Component Extraction. Based on the additivity principle of signal decomposition, subtraction operations are used to extract high-frequency abrupt change components containing abrupt change information. The high-frequency abrupt change component is defined as... The calculation formula is as follows:
[0093] ;
[0094] This step outputs and These are used as inputs for the trend expert and mutation expert in step S4, respectively.
[0095] Step S4: Construct a multi-scale hybrid expert network with environment perception gating, including a hybrid expert network and an environment perception gating network. This step uses the output of step S3 as an example. and Using the original input tensor from step S1 as the primary input, driving covariates are extracted to construct an environment-aware gating network. The prediction results of the two experts are dynamically fused using gating weights to output the final prediction residual tensor. This is for use in subsequent steps (reconstruction and loss).
[0096] S4-1: Construct a hybrid expert network and perform multi-step residual prediction. The hybrid expert network includes a low-frequency trend expert network. and high-frequency mutation expert network The low-frequency trend component and the high-frequency abrupt change component were respectively analyzed. Step-by-step prediction yields low-frequency trend expert prediction values. and high-frequency mutation expert prediction value :
[0097] ;
[0098] ;
[0099] In terms of implementation, Multilayer perceptron (MLP) can be used to process tensors. The Middle slice After flattening, it is mapped to a length of The vector, and reshaped into Matrix; A one-dimensional convolutional network (CNN) can be used to extract local mutation features along the time dimension, and then output through a fully connected prediction head. The multi-step prediction results.
[0100] S4-2: Constructing an environment-aware gating network. Gating network Its function is to calculate a normalized weight vector based on the current external environment state, which is used to arbitrate the outputs of the two experts. First, gated input feature extraction is performed. From the original input tensor... Extract the driving covariate from it, denoted as . , The number of driving covariates. To capture the overall characteristics of the environmental state, we first... Flattening the vectors in the time and channel dimensions yields the gated input feature vector:
[0101] ;
[0102] in, For flattening operation; For the first The gated input feature vector of each sample, For tensor The first in A slice.
[0103] Then, gating weights are generated. The gating network uses a linear mapping to obtain an unnormalized score vector. :
[0104] ;
[0105] in, For the learnable weight matrix of the gated network, This is the bias term. Finally, probability normalization is performed. The Softmax function is then used to... Normalized to dynamic gating weights :
[0106] ;
[0107] in, Indicates the original trend expert weight. Indicates the original mutation expert weight. Weighting for trend experts As mutation expert weights, and .
[0108] S4-3: Expert Output Fusion Based on Dynamic Gating Weights. Using calculated dynamic gating weights, low-frequency trend expert predictions and high-frequency mutation expert predictions are linearly weighted and fused to obtain the final prediction residual tensor. .
[0109] ;
[0110] in, Tensor The first in A slice, Tensor The first in A slice, Tensor The first in A slice, This represents element-wise multiplication under the broadcast mechanism, and the final output is... The final predicted value will be obtained by reconstructing it with the periodic components in subsequent steps.
[0111] Step S5: Result Reconstruction and Mutation-Weighted Optimization. This step aims to reconstruct the predicted residual tensor output from step S4. With explicit periodic memory tensor Future phase alignment and reconstruction are performed to obtain the final prediction result, and a "mutation-weighted loss function" is constructed for joint updating. The parameters of two types of expert networks and gating networks are used to improve the model's fitting ability and prediction accuracy during periods of abrupt changes. Specifically, the following steps are included:
[0112] S5-1: Construct the future periodic tensor and align it with the prediction step size. Since the periodic component was removed in step S2, the future periodic component needs to be "added back" to obtain the final prediction result. First, construct the future phase index matrix. .matrix elements Indicates the first The sample in the future The periodic phase index corresponding to the step is calculated as follows:
[0113] ;
[0114] Then, the future periodic tensor is retrieved using the index matrix. In explicit periodic memory tensors Perform batch retrieval to obtain the future periodic tensor aligned with the prediction step size. The calculation formula is as follows:
[0115] ;
[0116] in, Tensor The first in The slice The vector of rows, Representation matrix The Middle A vector of rows.
[0117] S5-2: Reconstruct the final prediction result. Convert the prediction residual tensor output from step S4... With future cycle tensor Element-wise addition yields the standardized prediction tensor. :
[0118] ;
[0119] Standardized prediction tensor The position is ( elements Indicates the first The first sample, the future first Step, First The standardized predicted values of each variable (channel), corresponding to an absolute time step of . .
[0120] S5-3: Constructing the abrupt change weighted mean squared error loss function. To enhance the model's learning strength during periods of abrupt (drastic) water quality changes, an abrupt change weight matrix is constructed based on the rate of change of the true labels, and the prediction error is weighted accordingly. Let the target water quality variable channel index set be... (For example, corresponding to DO, NH3_33-N, CODMn, TP, etc. channels), for the first The first sample, the future first Step, First Each variable (channel) defines the difference between the true labels. When At that time, the observation at the end of the historical window was used as the first term to obtain... ,in, Tensor The position is ( elements, Tensor The position is ( elements, Tensor The position is ( The element. When hour, ,in, Tensor The position is ( elements, Tensor The position is ( elements, Tensor The position is ( The elements are defined accordingly. The mutation weight tensor is defined based on this. :
[0121] ;
[0122] in, Tensor The position is ( elements, Let be the mutation concern coefficient. The final mutation-weighted mean squared error loss function is defined as:
[0123]
[0124] in, This indicates the number of elements in the target water quality variable channel index set.
[0125] S5-4: Joint Optimization and Parameter Update. A gradient-based optimization algorithm (such as the Adam or AdamW optimizer) is used to minimize the above loss function. Specifically, in one training iteration, steps S1 to S5-2 are executed sequentially to obtain the standardized prediction tensor at the standardized scale. And calculate the loss function according to step S5-3. Then the loss function The gradients of each learnable parameter are calculated and the parameters are updated. Each learnable parameter includes the explicit periodic memory tensor. Low-frequency trend expert network and high-frequency mutation expert network The parameters, and the parameters of the environment-aware gating network G. Repeat the above training iterations until a preset stopping condition is met (e.g., reaching a preset number of training rounds or convergence of the validation set loss). During the inference phase, the input... and Steps S2 to S5-2 are executed sequentially to obtain the desired result. And based on the statistics from step S1-2 , right Denormalization is performed to output water quality abrupt change prediction results in physical dimensions.
[0126] Another embodiment also provides a system corresponding to the method, including:
[0127] The dataset construction and processing unit is used to construct a multi-source water quality time series dataset, including target water quality variables and driving covariates; it performs batch tensor encapsulation on the multi-source water quality time series dataset to obtain the original input tensor and truth label tensor containing the batch dimension, and outputs the batch start time index for period alignment.
[0128] The periodic decoupling unit is used to construct an explicit periodic memory module and perform periodic decoupling; it includes: constructing an explicit periodic memory tensor and constructing a phase index matrix that is completely consistent with the spatiotemporal dimension of the original input tensor; using the phase index matrix to retrieve periodic sequence tensors in batches from the explicit periodic memory tensor; and decoupling the generated periodic sequence tensor from the original input tensor to separate the pure residual sequence containing mutation information.
[0129] The residual decomposition unit is used to decompose the pure residual sequence in the frequency domain through mathematical transformations, and extract low-frequency trend components and high-frequency abrupt change components.
[0130] The expert network construction unit is used to construct a multi-scale hybrid expert network for environment perception gating, including a hybrid expert network and an environment perception gating network. The hybrid expert network includes a low-frequency trend expert network and a high-frequency mutation expert network, which perform multi-step predictions on the low-frequency trend component and the high-frequency mutation component respectively to obtain the low-frequency trend expert prediction value and the high-frequency mutation expert prediction value. The environment perception gating network is constructed based on the driving covariates, and outputs dynamic gating weights that fuse the trend expert weights and mutation expert weights. The low-frequency trend expert prediction value and the high-frequency mutation expert prediction value are then weighted and fused using the dynamic gating weights to obtain the prediction residual tensor.
[0131] The model optimization unit is used for result reconstruction and mutation-weighted optimization: it aligns the predicted residual tensor with the explicit periodic memory tensor in the future phase and reconstructs the standardized predicted tensor. At the same time, it constructs a mutation-weighted mean square error loss function to jointly update the parameters of the explicit periodic memory tensor, the hybrid expert network and the environment-aware gating network.
[0132] Another embodiment also provides an electronic device, including:
[0133] Memory, used to store computer programs;
[0134] A processor for executing the computer program to implement the method.
[0135] A non-volatile storage medium for storing and executing the method, for storing a computer program, wherein the computer program implements the method when executed by a processor.
[0136] Another embodiment also provides a computer program product including a computer program / instructions that, when executed by a processor, implement the method described.
[0137] like Figure 2 (a) to (c) Figure 3 (a) and (b) and Figure 4 The schematic diagrams shown in (a) and (b) illustrate the effect using dissolved oxygen (DO) as the target water quality variable. The input data is hourly historical time series data, which includes the target water quality variable DO and driving covariates. The driving covariates may include external environmental factors such as rainfall, water level, flow rate, water temperature, and air temperature. Figures 2 to 4 The diagram illustrates the processing steps of the method of the present invention in periodic component extraction, residual decomposition, and prediction result reconstruction using schematic data, to explain the technical path of the method and its applicability in predicting sudden changes in water quality. Figure 2 Figures (a) to (c) illustrate that the periodic decoupling mechanism can effectively extract and remove repetitive periodic information; Figure 3 (a) and (b) illustrate that the multi-scale decomposition mechanism can further distinguish between slow background changes and rapid abrupt changes; Figure 4 Figures (a) and (b) illustrate that after dual-expert prediction and result reconstruction, the model output can better match the actual DO change process and control the prediction error within a small range. Therefore, the method of this invention has good rationality and feasibility in the task of predicting sudden changes in water quality.
Claims
1. A method for predicting sudden changes in water quality based on explicit periodic decoupling and multi-scale hybrid expert networks, characterized in that, Includes the following steps: Construct a multi-source water quality time series dataset, including target water quality variables and driving covariates; The multi-source water quality time series dataset is batch tensor encapsulated to obtain the original input tensor and truth label tensor containing the batch dimension, and the batch start time index for period alignment is output. Construct an explicit periodic memory module and perform periodic decoupling; including: constructing an explicit periodic memory tensor and constructing a phase index matrix that is completely consistent with the spatiotemporal dimension of the original input tensor; using the phase index matrix to retrieve periodic sequence tensors in batches from the explicit periodic memory tensor; decoupling the generated periodic sequence tensor from the original input tensor and separating the pure residual sequence containing mutation information; Through mathematical transformation, the pure residual sequence is decomposed in the frequency domain to extract low-frequency trend components and high-frequency mutation components. A multi-scale hybrid expert network for environmental perception gating is constructed, including a hybrid expert network and an environmental perception gating network. The hybrid expert network includes a low-frequency trend expert network and a high-frequency mutation expert network. Multi-step predictions are performed on the low-frequency trend component and the high-frequency mutation component to obtain the low-frequency trend expert prediction value and the high-frequency mutation expert prediction value. An environment-aware gating network is constructed based on driving covariates, and a dynamic gating weight is output that fuses trend expert weights and mutation expert weights. The dynamic gating weight is then used to weight and fuse low-frequency trend expert predictions and high-frequency mutation expert predictions to obtain the prediction residual tensor. Results Reconstruction and Mutation Weighted Optimization: The predicted residual tensor and the explicit periodic memory tensor are aligned with future phases and reconstructed to obtain a standardized predicted tensor. At the same time, a mutation weighted mean square error loss function is constructed to jointly update the parameters of the explicit periodic memory tensor, the hybrid expert network and the environment-aware gating network.
2. The method according to claim 1, characterized in that, The multi-source water quality time-series dataset is batch tensor-encapsulated to obtain the original input tensor containing the batch dimension and the truth label tensor, and outputs the batch start time index for period alignment; including: A sliding window is used to convert the standardized observation vectors in the multi-source water quality time series dataset into input-output sample pairs required for network training. For any historical window's end time... Define the history window sequence and the corresponding future truth value label sequence : ; ; in, These represent different moments within the historical window. 3D standardized observation vector For the future Step 3D standardized truth label vector For the length of the history window, To predict the step size, input-output sample pairs are obtained. Random sampling Each input-output sample pair constitutes a batch, which is encapsulated as the original input tensor and the truth label tensor containing the batch dimension. This represents the batch dimension; it also records the absolute time step index of the historical window start point in the multi-source water quality time series dataset for each input-output sample pair, forming the batch start time vector.
3. The method according to claim 1, characterized in that, Batch retrieval of periodic sequence tensors from explicit periodic memory tensors using phase index matrix: Decoupling the generated periodic sequence tensors from the original input tensors to separate the pure residual sequences containing mutation information; include: Using the phase index matrix as a lookup table, parallel searching is performed on the time dimension of the explicit periodic memory tensor to generate a periodic sequence tensor with the same dimension as the original input tensor; the formula for calculating any element in the periodic sequence tensor is: ; in, Indicates the first The sample in its historical window Each time step dimensional periodic baseline vector, Represents the phase index from the explicit periodic memory tensor Found dimensional periodic baseline vector, Indicates the first The sample in its historical window The periodic phase index corresponding to each time step. This indicates the index of the time step within the history window. Indicates the sample index. Indicates selecting all One feature channel; By using element-level subtraction, the generated periodic sequence tensor is removed from the original input tensor to obtain a pure residual sequence.
4. The method according to claim 1, characterized in that, Through mathematical transformations, the pure residual sequence is decomposed in the frequency domain to extract low-frequency trend components and high-frequency abrupt change components, including: Non-overlapping average pooling downsampling is performed on the pure residual sequence in the time dimension to obtain the compressed feature sequence. Linear interpolation upsampling is then performed on the compressed feature sequence to obtain the low-frequency trend component. Based on the additivity principle of signal decomposition, the high-frequency mutation components containing mutation information are extracted using subtraction operations.
5. The method according to claim 1, characterized in that, An environment-aware gating network is constructed based on driving covariates, outputting dynamic gating weights that fuse trend expert weights and mutation expert weights. These dynamic gating weights are then used to weight and fuse low-frequency trend expert predictions and high-frequency mutation expert predictions to obtain the prediction residual tensor; including: The driving covariates are extracted from the original input tensor, and then flattened in the time and channel dimensions to obtain the gated input feature vector. Unnormalized fraction vectors are obtained by linear mapping based on gated input feature vectors; The unnormalized score vector is normalized into dynamic gating weights using the Softmax function, including trend expert weights and mutation expert weights; By using dynamic gating weights, the low-frequency trend expert predictions and the high-frequency mutation expert predictions are linearly weighted and fused to obtain the final prediction residual tensor. ; ; in, Tensor The first in A slice, Tensor The first in A slice, Tensor The first in A slice, This represents element-wise multiplication under the broadcast mechanism. Weighting for trend experts For mutation expert weights.
6. The method according to claim 1, characterized in that, Results reconstruction and mutation-weighted optimization include: Construct a future phase index matrix, and use the future phase index matrix to perform batch retrieval on the explicit periodic memory tensor to obtain a future periodic tensor aligned with the prediction time dimension. The predicted residual tensor and the future period tensor are added element-wise to obtain the normalized predicted tensor with a normalized scale. A mutation weight matrix is constructed based on the rate of change of the real labels. A mutation weighted mean square error loss function is constructed based on the mutation weight matrix. A gradient-based optimization algorithm is used to minimize the mutation weighted mean square error loss function. Finally, the water quality mutation prediction results under physical dimensions are output.
7. A water quality mutation prediction system based on explicit periodic decoupling and multi-scale hybrid expert networks, characterized in that, include: The dataset construction and processing unit is used to construct multi-source water quality time series datasets, including target water quality variables and driving covariates; The multi-source water quality time series dataset is batch tensor encapsulated to obtain the original input tensor and truth label tensor containing the batch dimension, and the batch start time index for period alignment is output. The periodic decoupling unit is used to construct an explicit periodic memory module and perform periodic decoupling; it includes: constructing an explicit periodic memory tensor and constructing a phase index matrix that is completely consistent with the spatiotemporal dimension of the original input tensor; using the phase index matrix to retrieve periodic sequence tensors in batches from the explicit periodic memory tensor; and decoupling the generated periodic sequence tensor from the original input tensor to separate the pure residual sequence containing mutation information. The residual decomposition unit is used to decompose the pure residual sequence in the frequency domain through mathematical transformations, and extract low-frequency trend components and high-frequency abrupt change components. The expert network construction unit is used to construct a multi-scale hybrid expert network for environment perception gating, including a hybrid expert network and an environment perception gating network. The hybrid expert network includes a low-frequency trend expert network and a high-frequency mutation expert network, which perform multi-step predictions on the low-frequency trend component and the high-frequency mutation component respectively to obtain the low-frequency trend expert prediction value and the high-frequency mutation expert prediction value. The environment perception gating network is constructed based on the driving covariates, and outputs dynamic gating weights that fuse the trend expert weights and mutation expert weights. The low-frequency trend expert prediction value and the high-frequency mutation expert prediction value are then weighted and fused using the dynamic gating weights to obtain the prediction residual tensor. The model optimization unit is used for result reconstruction and mutation-weighted optimization: it aligns the predicted residual tensor with the explicit periodic memory tensor in the future phase and reconstructs the standardized predicted tensor. At the same time, it constructs a mutation-weighted mean square error loss function to jointly update the parameters of the explicit periodic memory tensor, the hybrid expert network and the environment-aware gating network.
8. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the method as described in any one of claims 1-6.
9. A non-volatile storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the method as described in any one of claims 1-6.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the method described in any one of claims 1-6.