A water quality prediction method and system based on seasonal term enhanced modeling
By employing a seasonal enhancement modeling method and utilizing local expert coding routing and cross-attention mechanisms, the problem of local structural differences and multi-scale variations in water quality prediction under complex aquaculture environments was solved, achieving high-precision prediction of water quality in marine ranches.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- YANTAI UNIV
- Filing Date
- 2026-04-27
- Publication Date
- 2026-07-03
AI Technical Summary
Existing water quality prediction methods are unable to effectively express local structural differences, coexistence of multi-scale components, and phased change pattern switching in complex aquaculture environments, leading to a decline in prediction accuracy and stability.
A seasonal-based augmentation modeling approach is adopted, which decomposes water quality data into trend and seasonal components through exponential moving average. Combined with local expert coding routing, context-guided scale-adaptive mixer and cross-attention mechanism, multi-scale dynamic fusion and state interaction are performed to achieve fine prediction of water quality parameters.
The model's ability to handle local structural differences, multi-scale dynamic changes, and phased mode switching has been improved, thus enhancing the accuracy and stability of water quality prediction.
Smart Images

Figure CN122087432B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of water quality prediction technology, specifically relating to a water quality prediction method and system based on seasonal enhancement modeling. Background Technology
[0002] Water quality time series in marine ranching environments are influenced by multiple factors, including tides, hydrodynamic exchange, meteorological changes, and aquaculture activities, exhibiting significant non-stationarity, complex fluctuations, and dynamic evolutionary characteristics. Accurate prediction of key parameters such as dissolved oxygen, temperature, pH, turbidity, and chlorophyll a is crucial for realizing ecological monitoring, risk early warning, and intelligent regulation in marine ranching. However, existing water quality prediction methods face the following prominent challenges in complex aquaculture environments:
[0003] Significant differences in local structures make it difficult for a uniform embedding approach to effectively represent the characteristics of different time segments: Marine ranch water quality sequences often exhibit distinctly different change patterns across different time intervals, with some segments showing dramatic fluctuations and frequent abrupt changes, while others remain relatively stable. Existing methods typically employ a uniform feature mapping or embedding approach for all time segments, which can easily compress significantly different local variations into a similar representation space. This weakens the model's ability to identify key local fluctuations and complex local structures, thereby affecting the accuracy and stability of rolling predictions.
[0004] The coexistence of multiple scale components and the changing dominance scale over time make it difficult to highlight key information using fixed fusion methods: Marine ranch water quality sequences typically contain components varying across multiple time scales, and the importance of these components changes dynamically over time. Existing methods for multi-scale modeling often rely on fixed fusion paths, fixed convolutional receptive fields, or pre-defined hierarchical aggregation rules. This makes it difficult to adaptively determine which time scale is more critical based on the current context, easily introducing redundant scale information and noise, leading to error accumulation and decreased prediction stability over long prediction ranges.
[0005] Frequent shifts in phased change patterns and the lack of state-aware mechanisms can easily lead to cross-phase feature confusion: In complex aquaculture environments, the dominant change patterns of water quality sequences shift over time, with significant differences in fluctuation intensity, change trends, and dominant dynamics between different phases. Most existing methods rely solely on the similarity between time tokens for modeling, lacking the ability to explicitly identify the current stage of change. This easily leads to the mixing of feature information from different stages during state transitions, causing representational confusion and prediction fluctuations, making it difficult to maintain long-term prediction stability.
[0006] To address the aforementioned problems, this invention proposes a water quality prediction method and system based on seasonal enhancement modeling for complex aquaculture environments. Summary of the Invention
[0007] To overcome the problems in the prior art, this invention proposes a water quality prediction method and system based on seasonal enhancement modeling.
[0008] The technical solution of the present invention to solve the above-mentioned technical problems is as follows:
[0009] In a first aspect, the present invention provides a water quality prediction method based on seasonal component enhancement modeling, comprising the following steps:
[0010] Step 100: Obtain historical multivariate water quality monitoring data and perform standardization processing;
[0011] Step 200: Perform exponential moving average decomposition on the standardized multivariate water quality monitoring data to obtain trend components and seasonal components;
[0012] Step 300: Based on the seasonal components, introduce local expert coding routing, context-guided scale-adaptive mixer, and cross-attention mechanism, and map the output to obtain the seasonal prediction components;
[0013] Step 400: Map and extract features from the trend components to obtain the trend prediction components;
[0014] Step 500: Fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter values.
[0015] Furthermore, the historical multivariate water quality monitoring data includes temperature, pH, dissolved oxygen, salinity, turbidity, and chlorophyll a.
[0016] Further, step 200 includes:
[0017] set up Input sequences for standardized multivariate water quality monitoring data. Let L represent the observation at time t, and L represent the length of the input sequence.
[0018] The formula for decomposing the exponential moving average is:
[0019] ;
[0020] in, As a trend component, It is the smoothing coefficient, and ; Indicates t Trend component values at time 1;
[0021] After obtaining the trend component, the seasonal component S is obtained by the difference between the standardized multivariate water quality monitoring data input sequence X and the trend component T.
[0022] Further, step 300 includes:
[0023] The seasonal components are divided into patches and differentially encoded to obtain the enhanced time patch sequence;
[0024] Global context modeling and multi-scale dynamic fusion are performed on the enhanced time patch sequence to obtain the multi-scale fusion result;
[0025] Using the multi-scale fusion result as the input of the time token, the interaction relationship between the time token and the state representation is established to obtain the cross-attention output;
[0026] The seasonal component is obtained by mapping the cross-attention output through the prediction head.
[0027] Furthermore, using a local expert routing method, the seasonal components are patched and differentially encoded to obtain an enhanced time patch sequence, including:
[0028] The seasonal component is divided into multiple time patches according to a preset time window, and each time patch is mapped to a shared basic embedding space to obtain a shared embedding result.
[0029] Based on the content characteristics of each time patch, a sparse routing mechanism is used to select the corresponding expert branch for processing; each expert branch performs targeted compensation on the shared embedding results, so that different local segments obtain representation results suitable for their own structural features, resulting in an enhanced time patch sequence.
[0030] Furthermore, global context modeling and multi-scale dynamic fusion are performed on the enhanced time patch sequences to obtain multi-scale fusion results, including:
[0031] The enhanced time patch sequence is input into the Mamba branch to extract global time series context information and obtain the context information.
[0032] Based on the context information, fusion weights corresponding to different time scales are generated. At the same time, multi-scale dynamic features are extracted through local branches of multiple different receptive fields. The features of each time scale are adaptively weighted and fused according to the fusion weights to obtain multi-scale fusion results.
[0033] Furthermore, using the multi-scale fusion result as the input of the time token, the interaction relationship between the time token and the state representation is established to obtain the cross-attention output, including:
[0034] Based on the multi-scale fusion results, the similarity between the time position and the state vector is calculated, and the state assignment weight is calculated. The state assignment weight is used to perform weighted aggregation and normalization on the multi-scale fusion results to obtain the state representation tensor.
[0035] Using the multi-scale fusion result as the time token input and the state representation tensor as the key and value, a cross-attention relationship is established between the two to obtain the cross-attention output.
[0036] Furthermore, in step 400, the trend component is processed using a linear flow consisting of a fully connected layer and an average pooling layer to generate a trend prediction component.
[0037] Further, step 500 includes:
[0038] The seasonal forecast component and the trend forecast component are concatenated, and then compressed and reshaped into a multivariate time series structure through a linear fusion layer to obtain the final forecast result. The prediction results are then inversely normalized.
[0039] ;
[0040] in, Indicates the trend forecast component; Indicates seasonal forecast components; This indicates a splicing operation. Indicates the fusion weight. This indicates a reshaping operation; and the output is then subjected to inverse normalization.
[0041] Secondly, a water quality prediction system based on seasonal enhanced modeling, employing the water quality prediction method based on seasonal enhanced modeling described in the first aspect, includes: a data input and preprocessing unit, a trend-seasonal decomposition unit, a seasonal modeling unit, and a trend modeling and fusion output unit.
[0042] The data input and preprocessing unit is used to acquire historical multivariate water quality monitoring data and perform standardized processing.
[0043] The trend-seasonal decomposition unit is used to decompose standardized multivariate water quality monitoring data into an exponential moving average to obtain trend and seasonal components.
[0044] The seasonal component modeling unit is used to introduce local expert coding routes, context-guided scale-adaptive mixers, and cross-attention mechanisms based on seasonal components, and to map the output to obtain seasonal prediction components.
[0045] The trend modeling and fusion output unit is used to input the trend component into the trend modeling branch, perform mapping and feature extraction to obtain the trend prediction component; and fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter prediction value.
[0046] Compared with the prior art, the present invention has the following technical effects:
[0047] (1) This invention achieves the prediction of complex water quality time series through a collaborative architecture of "trend-seasonal decoupling + seasonal term hierarchical enhancement modeling + dual-branch fusion output". First, the multivariate water quality series is decomposed into trend components and seasonal components to characterize long-term stable changes and short-term dynamic fluctuations, respectively. Second, local difference modeling, multi-scale dynamic fusion and state interaction enhancement are performed around the seasonal term branch in sequence. Finally, the results of the seasonal branch and the results of the trend branch are fused to predict the target prediction series.
[0048] (2) This invention divides the seasonal sequence into multiple time patches through a local expert coding routing mechanism, and performs differentiated processing based on the content characteristics of different time patches. This approach avoids the compression of local differences by traditional unified mapping methods, which is beneficial to improving the model's ability to identify and model local mutations and non-uniform structural segments.
[0049] (3) This invention uses a context-guided scale-adaptive fusion mechanism to first extract the global context information of the enhanced time patch sequence, and then dynamically generate fusion weights for different time scales based on the context information to adaptively weight the multi-scale local features. This method can more accurately highlight the more relevant time scale information when multiple scale components coexist and the dominant scale changes over time.
[0050] (4) This invention extracts representative state information through a state interaction cross-attention mechanism and incorporates this state information into the update process of the current time token. This mechanism enables the model to better identify the phased changes and dominant mode shifts in the sequence, thereby improving the stability of the prediction process and the accuracy of the results.
[0051] (5) Under the synergistic effect of multiple mechanisms such as local expert coding routing mechanism, local expert coding routing mechanism, context-guided scale adaptive hybrid mechanism and state interaction cross attention mechanism, this invention can simultaneously optimize local structure modeling, multi-scale information selection and stage state recognition during end-to-end training, and combine trend branching to achieve fine prediction of multivariate water quality sequences in complex aquaculture environments. Attached Figure Description
[0052] To more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0053] Figure 1 This is a schematic diagram of the structure of the present invention;
[0054] Figure 2 This is a structural block diagram of the present invention. Detailed Implementation
[0055] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the specific implementation methods, structures, features, and effects of the technical solutions proposed according to the present invention are described in detail below with reference to the accompanying drawings and preferred embodiments. Specific features, structures, or characteristics in one or more embodiments may be combined in any suitable form. Unless otherwise defined, all technical and scientific terms used in this invention have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0056] This invention improves the model's ability to handle local structural differences, multi-scale dynamic changes, and phased mode switching by introducing local expert coding routing, context-guided scale-adaptive mixer, and state interaction cross-attention mechanism into the seasonal term branch. Combined with trend branch modeling and dual-branch fusion output, it achieves high-precision prediction of complex non-stationary water quality processes in marine ranches.
[0057] In this embodiment, refer to Figures 1-2 This paper provides a water quality prediction method based on seasonal enhancement modeling, which includes the following steps:
[0058] Step 100: Obtain historical multivariate water quality monitoring data and perform standardization processing;
[0059] Step 200: Perform exponential moving average decomposition on the standardized multivariate water quality monitoring data to obtain trend components and seasonal components;
[0060] Step 300: Based on the seasonal components, introduce local expert coding routing, context-guided scale-adaptive mixer, and cross-attention mechanism, and map the output to obtain the seasonal prediction components;
[0061] Step 400: Input the trend component into the trend modeling branch, perform mapping and feature extraction, and obtain the trend prediction component;
[0062] Step 500: Fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter values.
[0063] The following is a detailed explanation of each of the above steps:
[0064] Step 100: Obtain historical multivariate water quality monitoring data and perform standardization processing.
[0065] As an example, step 100 specifically includes:
[0066] Step 110: Obtain historical multivariate water quality monitoring data, including temperature, pH, dissolved oxygen, salinity, turbidity, chlorophyll a, etc.
[0067] Acquire historical multivariate water quality monitoring data continuously collected in the target aquaculture area. The historical multivariate water quality monitoring data includes one or more water quality monitoring indicators such as temperature, pH, dissolved oxygen, salinity, turbidity, and chlorophyll a.
[0068] Step 120: Standardize the acquired historical multivariate water quality monitoring data.
[0069] To ensure the validity of the input data, water quality monitoring index collection ranges were set. Specifically, the temperature collection range was 0-35℃, pH was 6.0-9.5, dissolved oxygen was 3 mg / L-15 mg / L, salinity was 0-35‰, turbidity was 0-50 NTU, and chlorophyll a was 0-50 μg / L. Raw data outside these ranges were considered outlier candidates and further screened using the Z-score method.
[0070] The original data is further processed by time alignment, resampling, missing value imputation, outlier screening and standardization, with missing values imputed by linear interpolation. Then, a reversible normalization mechanism is used to unify the differences in the scale and distribution of different variables to obtain a stable multivariate input sequence of the same scale, which is used as the input for the subsequent prediction model.
[0071] Step 200: Perform exponential moving average decomposition on the standardized multivariate water quality monitoring data to obtain trend components and seasonal components. The trend component characterizes the long-term smooth changes in the multivariate water quality monitoring data, while the seasonal component characterizes periodic fluctuations and local disturbances.
[0072] The standardized multivariate water quality monitoring data were decomposed using an exponential moving average to separate the trend and seasonal components. Let... Input sequences for standardized multivariate water quality monitoring data. Let represent the observation at time t, and L represent the length of the input sequence. The formula for the exponential moving average decomposition is:
[0073] ;
[0074] in, The trend component is used to characterize long-term smooth changes in water quality series. It is the smoothing coefficient, and It is used to control the sensitivity of the trend component to the data. The larger the value, the more sensitive the trend component is to recent data changes. By setting the smoothing coefficient β, short-term noise and random fluctuations in the data can be filtered out, making the long-term patterns of water quality changes clearer. This provides the subsequent trend modeling branch with input data that accurately reflects the long-term evolution characteristics of water quality, helping to more accurately predict the future long-term trend of water quality. Indicates t The trend component value at time 1.
[0075] After obtaining the trend component, the seasonal component S is obtained by the difference between the standardized multivariate water quality monitoring data input sequence X and the trend component T. The seasonal component is used to characterize the periodic fluctuations and local disturbances in the water quality data. Water quality data is often affected by factors such as seasons, weather, and biological activity cycles, exhibiting periodic changes. Extracting the seasonal component separates these influencing factors from the raw data, providing targeted input for the seasonal component modeling branch. By modeling the seasonal component separately, we can better understand and predict the changing patterns of water quality in different seasons or cycles, improve the prediction accuracy of short-term water quality fluctuations, and thus provide more comprehensive and accurate information support for the management and decision-making of aquaculture areas.
[0076] Step 300: Based on the seasonal components, introduce local expert coding routing, context-guided scale-adaptive mixer, and cross-attention mechanism, and map the output to obtain the seasonal prediction components.
[0077] As an example, step 300 specifically includes:
[0078] Step 310: Using the local expert routing method, the seasonal components are divided into patches and differentially encoded to obtain the enhanced time patch sequence.
[0079] As an example, step 310 specifically includes the following sub-steps:
[0080] Step 3101: Divide the seasonal component into multiple time patches according to the preset time window, and map each time patch to the shared basic embedding space to obtain the shared embedding result.
[0081] To analyze the periodic characteristics of the seasonal components in more detail, the seasonal components are divided into multiple time patches according to a preset time window. The time patches are represented as follows:
[0082] ;
[0083] in, B represents the patch tensor; C represents the batch size, i.e., the number of data samples processed simultaneously; p represents the number of variable channels, corresponding to different indicators of water quality monitoring; and p represents the patch length, i.e., the number of time steps contained in each time patch. , The total length of the seasonal component sequence is represented by N, the number of patches is represented by N, and the stride represents the step size of the time window, which determines the degree of overlap or the size of the interval between adjacent time patches.
[0084] The division of time patches allows the seasonal component sequence to be segmented into multiple local segments according to time windows, enabling the model to model local change patterns within different time periods on a patch-by-pattern basis. Each time patch represents local temporal information within a specific time range, which helps to preserve the local structural differences between different time segments, thereby providing richer feature information for subsequent modeling.
[0085] After completing the time patch partitioning, each time patch needs to be mapped to a shared basic embedding space to obtain a more representative and processable patch sequence representation. This mapping process is achieved through shared basic embedding operations, and its formula is as follows:
[0086] ;
[0087] in, The representation of the patch sequence obtained after the shared basic embedding operation in the shared basic embedding space can be denoted as: ,in, This represents the embedding vector corresponding to the nth time patch; and To share projection parameters, d represents the embedding dimension, which is the dimension of the feature vector corresponding to each time patch after mapping. GELU (Gaussian Error Linear Unit) is an activation function that introduces nonlinear characteristics into the model, enhancing its ability to express complex patterns.
[0088] Sharing basic embedding operations helps improve model efficiency and generalization ability. Sharing projection parameters ensures that different time patches follow the same transformation rules when mapped to the embedding space, reducing the number of model parameters, lowering model complexity, and avoiding the risk of overfitting. Simultaneously, the sharing mechanism integrates and refines common features learned from different time patches, enabling the model to better learn general patterns and regularities in water quality data. This enhances the model's adaptability to different time periods and water quality conditions, thereby improving its predictive power and stability.
[0089] Step 3102: Select the corresponding expert branch for processing based on the content characteristics of each time patch using a sparse routing mechanism; each expert branch performs targeted compensation on the shared embedding results so that different local segments obtain representation results suitable for their own structural features, thus obtaining the enhanced time patch sequence.
[0090] Layer normalization is performed on the temporal patch tensor to obtain the normalized patch features. Layer normalization helps accelerate the convergence speed of model training and improve stability. It makes the data distribution more stable by normalizing each sample in the feature dimension.
[0091] Based on the routing matrix, the original routing score Z of the normalized patch features in the expert space is calculated. :
[0092] ;
[0093] In the above formula, Here, E represents the temperature coefficient; E represents the number of expert branches. The routing matrix is a trainable parameter matrix in a sparse gated routing network. It is used to map the normalized time patch features to the expert scoring space and generate the original routing score for each patch. This matrix is not manually preset or empirically specified, but is initialized at the beginning of model training and jointly optimized with other network parameters through backpropagation during training, thereby gradually learning the mapping relationship of which type of patch should be assigned to which expert.
[0094] During the training phase, to enhance the stability of the routing process, a perturbation term can be superimposed on the routing score Z to obtain... The perturbation term is applied before the Top-k sparse routes are selected, aiming to enhance the stability and robustness of route selection during the training phase. When the scores of different experts are similar, the perturbation term can reduce the early concentration of routes on a few experts, improve the exploration ability of different expert branches, and make the division of labor among experts more efficient. It also helps to mitigate the instability of hard selection caused by local noise or small fluctuations in scores. The perturbed route scores are then used for subsequent Top-k expert selection and Softmax weight normalization, resulting in more robust expert allocation results.
[0095] At the expert level, a Top-k selection strategy is executed for each time patch. The goal of this strategy is to select the k experts from among many who are most relevant to the current time patch and have the highest scores. The resulting expert index set is denoted as... For the nth time patch, the scores are Softmax normalized only within the expert index set to obtain the routing weights. Experts who are not selected have their routing weights reset to 0. This method allows for the selection of expert branches based on the routing score corresponding to the time patch content, with the routing weights determined by the normalization of the selected expert's relative score.
[0096] The difference between each expert branch lies in its independent parameters, used to learn the structural compensation patterns of different local segments. Specifically, the e-th expert adopts a low-rank adaptation structure, and its parameters are decomposed as follows: and For the nth patch vector The residual contribution can be expressed as Then, through learnable scaling parameters Bounded scaling of the residual yields the compensation term. The use of the tanh function ensures that the value of the compensation term is within a certain range, avoiding instability caused by values that are too large or too small; the learnable scaling parameter can be automatically adjusted during training to adapt to different data distributions and task requirements.
[0097] The compensation items for each selected expert are summed according to their routing weights and then added to the corresponding shared embedding to obtain the enhanced time patch representation:
[0098] ;
[0099] This aggregates the outputs from all patch locations to obtain the complete patch sequence embedding. Through the above processing, different time patches can be adaptively assigned to more suitable expert branches according to their own local structural characteristics, thereby improving the model's ability to model local mutations, heterogeneous fluctuations, and non-uniform fragment structures; This represents the set of indexes for the selected experts.
[0100] By employing a local expert coding routing mechanism, the seasonal sequence is divided into multiple time patches, and differentiated processing is performed based on the content characteristics of each patch. This approach avoids the compression of local differences inherent in traditional uniform mapping methods, thus enhancing the model's ability to identify and model local mutations and non-uniform structural segments.
[0101] Step 320: Perform global context modeling and multi-scale dynamic fusion on the enhanced time patch sequence to obtain the multi-scale fusion result.
[0102] As an example, step 320 specifically includes the following sub-steps:
[0103] Step 3201: Input the enhanced time patch sequence into the Mamba branch to extract global time series context information and obtain the context information.
[0104] ;
[0105] in, Indicates contextual information; Embed the complete patch sequence output from step 3102. This indicates a normalization operation.
[0106] Step 3202: Generate fusion weights corresponding to different time scales based on the context information, extract multi-scale dynamic features through local branches of multiple different receptive fields, and perform adaptive weighted fusion of the features at each time scale according to the fusion weights to obtain the multi-scale fusion result.
[0107] To comprehensively depict dynamic changes across different time scales, M parallel time-scale branches are set up. Each time-scale branch corresponds to a different receptive field local convolutional extraction path, used to depict dynamic changes over short, medium, and long time scales. Each time-scale branch outputs the local features extracted at its corresponding time scale. ,in, Indicates weight Depth-separable convolution operations.
[0108] The M value is set to 3, representing three parallel time-scale branches corresponding to local modeling paths over short, medium, and long time spans, respectively. Each time-scale branch employs depthwise separable one-dimensional convolutions with different receptive fields to extract features from the enhanced time patch sequence. The convolution kernel size is set to 3, 5, and 7: branches with smaller kernels primarily characterize short-term dynamics such as local mutations and short-period fluctuations; branches with medium kernels represent the medium-range variation relationships between several adjacent patches; and branches with larger kernels extract slow changes and wide-scale patterns over longer time spans. Subsequently, based on the contextual guidance information output by the Mamba branches, adaptive weights are assigned to each scale branch at different time positions and channels, and the features of each scale are dynamically weighted and fused to achieve adaptive modeling of the dominant time scale's temporal variation.
[0109] Using the context information obtained from the Mamba branch, the importance of each time-scale branch at each time position and channel is evaluated to obtain a scale score. This score is then normalized along the scale dimension to obtain the adaptive weight of the m-th time-scale branch. .
[0110] The local features of each time-scale branch are summed position-wise and channel-wise according to the adaptive weights of the corresponding time-scale branch, and the sum is output through a mapping matrix. and bias terms Perform a linear transformation to obtain the multi-scale fusion result. :
[0111] ;
[0112] The context-guided scale-adaptive mixer, by setting multiple parallel time-scale branches, comprehensively captures dynamic changes across different time ranges, enriching the diversity of feature representations and enabling the model to better understand complex data patterns. Utilizing Mamba branches to obtain contextual information for scale evaluation and weight allocation achieves dynamic attention to features at different scales, improving the model's adaptability to various data scenarios. Furthermore, operations such as depthwise separable convolution and linear transformations effectively control computational load while ensuring effective feature extraction and fusion, improving the model's computational efficiency. Finally, the introduction of Dropout regularization enhances the model's generalization ability, reduces the risk of overfitting, and allows the model to exhibit good performance even when facing new and unseen data.
[0113] Step 330: Using the multi-scale fusion result as the input of the time token, establish the interaction relationship between the time token and the state representation to obtain the cross-attention output.
[0114] As an example, step 330 specifically includes the following sub-steps:
[0115] Step 3301: Based on the multi-scale fusion results, calculate the similarity between the time position and the state vector, and calculate the state assignment weight. Use the state assignment weight to perform weighted aggregation and normalization on the multi-scale fusion results to obtain the state representation tensor.
[0116] First, extract representative state information from the historical sequence and form a state representation that can be referenced at the current moment.
[0117] Introducing a learnable state codebook Where J is the number of states, denoted as J. For multi-scale fusion results The feature vector at the nth position, Let j be the j-th state vector in the codebook.
[0118] To clarify how the similarity between time position and state vector is calculated, we first... and After performing layer normalization, the cosine similarity matrix between the two can be calculated as follows:
[0119] ;
[0120] in, LN( represents the similarity between the nth time position and the jth state vector; This indicates a layer normalization operation. For vector dot product, ∥ ∥2 is L2-norm. Cosine similarity measures the degree of similarity between two vectors by measuring the angle between them, with values ranging from [ ]. The values are between 1 and 1, and the larger the value, the more similar the two vectors are.
[0121] Based on the similarity matrix, in the temperature coefficient Weight allocation for computational state under control It can be represented as:
[0122] ;
[0123] In the above formula, Indicates the nth time position and the nth time position. l The similarity between state vectors.
[0124] Using this state to assign weights to the multi-scale fusion results The state representation tensor is obtained by weighting, aggregating, and normalizing the feature vector at the nth position. It can be represented as:
[0125] ;
[0126] in, For temperature coefficient, It is the numerical stability constant; This represents the state representation vector corresponding to the j-th state.
[0127] This step introduces a learnable state codebook, enabling the model to automatically learn feature representations of different states, thus enhancing its ability to capture inherent patterns in the data. Secondly, the cosine similarity calculation method intuitively and effectively measures the similarity between feature vectors and state vectors, providing a reasonable basis for weight allocation. The introduction of a temperature coefficient adds flexibility to weight allocation, allowing adjustment of the concentration of weight distribution according to actual needs. Finally, the state representation tensor generated by weighted aggregation and normalization operations comprehensively considers feature information from different time positions, enabling a more comprehensive and accurate representation of the current state.
[0128] Step 3302: Using the multi-scale fusion result as the time token input and the state representation tensor as the key and value, establish the cross-attention relationship between the two to obtain the cross-attention output.
[0129] Multi-scale fusion results As a time token input, the state representation tensor As state context information, let H attention heads be used for cross-attention, where h represents the h-th attention head, and h = 1, 2, ..., H. Under the h-th attention head, the multi-scale fusion results are processed respectively. and state representation tensor Perform a linear mapping to generate the corresponding query matrix, key-value matrix, and value matrix. This can be represented as:
[0130] ;
[0131] in, Let h be the linear projection parameters of the h-th attention head; Let represent the query, key, and value matrix of the h-th attention head, respectively.
[0132] Subsequently, the cross-attention output of the h-th head is calculated. :
[0133] ;
[0134] in, Indicates a single-head dimension.
[0135] The outputs of all heads are concatenated and then fused using a linear mapping to obtain the result. , This represents the multi-head fusion projection matrix, and the intermediate feature points are obtained through residual connections. Then Input the feedforward network and obtain the output seasonal branch result by scaling the residual. .
[0136] This approach, which utilizes time tokens and state representations to establish cross-attention relationships, offers several beneficial effects. First, it allows each time point to retain its local dynamic information while comprehensively integrating historical state information for judgment. The time token acts as a query, guiding the model to focus on state information relevant to the current time, while the state representation provides rich historical contextual knowledge; the combination enhances the model's ability to identify phased changes in the sequence. Second, the multi-head attention mechanism, through the parallel computation of multiple attention heads, can capture dependencies in the data from different perspectives, further improving the model's feature extraction capabilities. Finally, this approach helps improve the stability and accuracy of the model's predictions, enabling the model to make more reliable decisions when faced with complex sequence data.
[0137] Step 340: The seasonal branch results output in Step 330 are flattened and input into the prediction head network. Seasonal prediction components are generated through two layers of linear mapping and the GELU activation function. .
[0138] ;
[0139] In the above formula, and These are projection parameters; This indicates the flattening operation.
[0140] Step 400: Input the trend component into the trend modeling branch, perform mapping and feature extraction, and obtain the trend prediction component.
[0141] The trend component T obtained from the decomposition is processed using a linear flow consisting of a fully connected layer and an average pooling layer to generate the trend prediction component. It can be represented as:
[0142] ;
[0143] in, represents average pooling operation, LN represents normalization operation, and MLP represents linear mapping network.
[0144] Step 500: Fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter values.
[0145] The seasonal forecast component and the trend forecast component are concatenated, and then compressed and reshaped into a multivariate time series structure through a linear fusion layer to obtain the final forecast result. It can be represented as:
[0146] ;
[0147] in, This indicates a splicing operation. Indicates the fusion weight. This indicates a reshaping operation. (Regarding the prediction results...) Inverse normalization is performed to restore its original physical dimensions.
[0148] From a prediction accuracy perspective, this step models seasonal and trend factors separately, enabling more precise capture of different types of change patterns in the sequence. The seasonal component reflects the periodic changes in data over fixed time intervals, while the trend component reflects the long-term trend of the data. Processing them separately and then fusing them allows for a comprehensive consideration of both factors, improving prediction accuracy. Regarding model adaptability, through operations such as linear flow, splicing, and fusion, the model can better adapt to time series data with different characteristics, exhibiting strong generalization ability. Furthermore, this approach makes the model structure clearer, easier to understand and optimize, and contributes to reliable predictions of time series data such as water quality parameters in practical applications.
[0149] Based on the same inventive concept, embodiments of the present invention also provide a water quality prediction system based on seasonal enhancement modeling. The solution provided by this method is similar to the solution described above; therefore, the specific limitations in one or more system embodiments provided below can be found in the limitations of the water quality prediction method based on seasonal enhancement modeling described above, and will not be repeated here.
[0150] A water quality prediction system based on seasonal enhanced modeling includes: a data input and preprocessing unit, a trend-seasonal decomposition unit, a seasonal modeling unit, and a trend modeling and fusion output unit;
[0151] The data input and preprocessing unit is used to acquire historical multivariate water quality monitoring data and perform standardization processing. Historical multivariate water quality monitoring data includes, but is not limited to, temperature, pH, dissolved oxygen, salinity, turbidity, chlorophyll a, and other environmental variables. The unit performs time alignment, resampling, missing value imputation, outlier screening, and standardization processing on the historical multivariate water quality monitoring data, and uses a reversible normalization mechanism to unify the dimensions and distribution of different variables, outputting a stable, homogeneous multivariate input sequence.
[0152] The trend-seasonal decomposition unit is used to decompose standardized multivariate water quality monitoring data into exponential moving averages, yielding trend and seasonal components. The trend component represents slowly evolving long-term changes, while the seasonal component represents periodic fluctuations and local disturbances, providing structured input for subsequent dual-branch modeling.
[0153] The seasonal component modeling unit is used for feature extraction and enhanced modeling of seasonal components. Based on the seasonal components, local expert coding routing, context-guided scale-adaptive mixer, and cross-attention mechanism are introduced, and the output is mapped to obtain the seasonal prediction component.
[0154] Specifically, such as Figure 2 As shown, the seasonal item modeling unit mainly includes the following sub-modules:
[0155] The local expert coding routing module is used for patching and differential coding of seasonal components. This module first divides the seasonal components into multiple time patches according to time windows. Based on the shared basic embedding, a sparse routing mechanism is used to select the appropriate expert branch for processing according to the content characteristics of each time patch. Each expert branch performs targeted compensation on the shared representation, enabling different local segments to obtain representations more suitable for their own structural features, thereby improving the model's ability to model local mutations, heterogeneous fluctuations, and non-uniform segment structures.
[0156] A context-guided scale-adaptive mixer module is used for global context modeling and multi-scale dynamic fusion of time-patched sequences. This module inputs patch features into a Mamba branch to extract global temporal context and generates fusion weights corresponding to different time scales based on this context information. Simultaneously, it extracts multi-scale dynamic features through local branches with multiple different receptive fields and performs adaptive weighted fusion according to the weights. In this way, the model can highlight more relevant scale information based on the current temporal state, improving its adaptability to complex time-varying patterns and dominant scale changes.
[0157] The state interaction cross-attention module is used to establish the interaction relationship between time tokens and state representations. This module first extracts representative state information from the historical sequence and forms a state representation that can be referenced at the current time. Using the multi-scale fusion result as the input time token, and based on the interaction between the time token and the state representation, it updates the current sequence features, enabling each time position to maintain local dynamic information while incorporating historical state information for discrimination and adjustment. This module enhances the model's ability to identify phased changes in the sequence, thereby improving the stability and accuracy of the prediction results.
[0158] The trend modeling and fusion output unit is used to input the trend component into the trend modeling branch, perform mapping and feature extraction to obtain the trend prediction component; and fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter prediction value.
[0159] This invention segments the seasonal sequence and combines this with a differentiated local encoding mechanism to obtain representations for different time segments that better suit their structural characteristics. Compared to a uniform mapping approach, this technique can more effectively characterize local mutations, heterogeneous fluctuations, and non-uniform segment structures, improving the model's ability to recognize complex local dynamics and thus enhancing prediction accuracy and stability.
[0160] Introducing a context-guided multi-scale fusion mechanism during seasonal component modeling enables adaptive selection and weighting of information from different time scales based on the current time series status, avoiding information mismatch issues caused by fixed-scale modeling or fixed fusion paths. This technical approach can more effectively address complex situations where multiple scale components coexist and the dominant scale changes over time, thereby improving the model's accuracy and robustness in long-term predictions.
[0161] By introducing an interaction mechanism between state information and time tokens, the model can refer to historical state representations during the feature update process at the current moment, thereby better identifying phase changes, state transitions, and dominant mode shifts. Compared with existing methods that lack state awareness, this technical solution can reduce the adverse effects of feature confusion at different stages on the prediction process, further improving the stability and reliability of prediction results.
[0162] The overall framework proposed in this invention can simultaneously take into account local structural differences, multi-scale dynamic changes, and staged pattern evolution, demonstrating stability in multi-regional, multi-variable, and multi-scenario water quality prediction tasks. This method maintains strong predictive performance across different water quality variable prediction tasks, exhibiting good cross-regional generalization ability and practical application value.
[0163] Table 1 Prediction Error
[0164]
[0165] As shown in Table 1, this model was compared with EMAformer, TimeMixer, TimeFilter, SparseTSF and iTransformer on the BaffleCreek and Shandong Peninsula datasets. The mean absolute error (MAE) and root mean square error (RMSE) were used as evaluation metrics to measure the prediction performance.
[0166] Overall, this model achieved the best results in both MAE and RMSE on both datasets, demonstrating stronger prediction accuracy and stability. Specifically, on the BaffleCreek dataset, this model's MAE = 0.2312 and RMSE = 0.3567, both lower than EMAformer (0.2485 / 0.3946), TimeMixer (0.2508 / 0.3745), TimeFilter (0.2605 / 0.4003), SparseTSF (0.2624 / 0.3901), and iTransformer (0.2529 / 0.3722). On the Shandong Peninsula dataset, this model also achieved optimal results, with MAE=0.3220 and RMSE=0.5829, outperforming EMAformer (0.3683 / 0.6384), TimeMixer (0.3458 / 0.6093), TimeFilter (0.4109 / 0.6514), SparseTSF (0.3627 / 0.5964), and iTransformer (0.3480 / 0.5905). This indicates that compared to the aforementioned comparative models, this model can more effectively reduce prediction errors and exhibits better generalization ability and robustness across water quality sequences in different regions.
[0167] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A water quality prediction method based on seasonal term enhancement modeling, characterized in that, Includes the following steps: Step 100: Obtain historical multivariate water quality monitoring data and perform standardization processing; Step 200: Perform exponential moving average decomposition on the standardized multivariate water quality monitoring data to obtain trend components and seasonal components; Step 300: Based on the seasonal components, introduce local expert coding routing, context-guided scale-adaptive mixer, and cross-attention mechanism, and map the output to obtain the seasonal prediction components, including: The seasonal components are divided into patches and differentially encoded to obtain an enhanced time patch sequence. This includes: dividing the seasonal components into multiple time patches according to a preset time window; mapping each time patch to a shared basic embedding space to obtain a shared embedding result; selecting the appropriate expert branch for processing based on the content features of each time patch using a sparse routing mechanism; and each expert branch performing targeted compensation on the shared embedding result to enable different local segments to obtain representation results suitable for their own structural features, thus obtaining the enhanced time patch sequence. Global context modeling and multi-scale dynamic fusion are performed on the enhanced time patch sequence to obtain a multi-scale fusion result. The process includes: inputting the enhanced time patch sequence into a Mamba branch to extract global temporal context information; generating fusion weights corresponding to different time scales based on the context information; extracting multi-scale dynamic features through local branches with multiple different receptive fields; and adaptively weighting and fusing the features at each time scale according to the fusion weights to obtain a multi-scale fusion result. Using the multi-scale fusion result as the input of the time token, an interaction relationship between the time token and the state representation is established to obtain the cross-attention output. This includes: calculating the similarity between the time position and the state vector based on the multi-scale fusion result, calculating the state assignment weight, and using the state assignment weight to perform weighted aggregation and normalization on the multi-scale fusion result to obtain the state representation tensor; using the multi-scale fusion result as the input of the time token and the state representation tensor as the key and value, a cross-attention relationship is established between the two to obtain the cross-attention output. The seasonal component is obtained by mapping the cross-attention output through the prediction head; Step 400: Map and extract features from the trend components to obtain the trend prediction components; Step 500: Fuse the trend prediction component with the seasonal prediction component to predict and output the future target water quality parameter values.
2. The water quality prediction method based on seasonal term enhancement modeling according to claim 1, characterized in that, The historical multivariate water quality monitoring data includes temperature, pH, dissolved oxygen, salinity, turbidity, and chlorophyll a.
3. The water quality prediction method based on seasonal term enhancement modeling according to claim 1, characterized in that, Step 200 includes: set up Input sequences for standardized multivariate water quality monitoring data. Let L represent the observation at time t, and L represent the length of the input sequence. The formula for decomposing the exponential moving average is: ; in, As a trend component, It is the smoothing coefficient, and ; Indicates t Trend component values at time 1; After obtaining the trend component, the seasonal component S is obtained by the difference between the standardized multivariate water quality monitoring data input sequence X and the trend component T.
4. The water quality prediction method based on seasonal term enhancement modeling according to claim 1, characterized in that, In step 400, the trend component is processed using a linear flow consisting of a fully connected layer and an average pooling layer to generate a trend prediction component.
5. The water quality prediction method based on seasonal term enhancement modeling according to claim 1, characterized in that, Step 500 includes: The seasonal forecast component and the trend forecast component are concatenated, and then compressed and reshaped into a multivariate time series structure through a linear fusion layer to obtain the final forecast result. The prediction results are then inversely normalized. ; in, Indicates the trend forecast component; Indicates seasonal forecast components; This indicates a splicing operation. Indicates the fusion weight. This indicates a reshaping operation.
6. A water quality prediction system based on seasonal enhanced modeling, employing a water quality prediction method based on seasonal enhanced modeling as described in any one of claims 1-5, characterized in that, include: Data input and preprocessing unit, trend-seasonal decomposition unit, seasonal item modeling unit, trend modeling and fusion output unit; The data input and preprocessing unit is used to acquire historical multivariate water quality monitoring data and perform standardized processing. The trend-seasonal decomposition unit is used to decompose standardized multivariate water quality monitoring data into an exponential moving average to obtain trend and seasonal components. The seasonal component modeling unit is used to introduce local expert coding routes, context-guided scale-adaptive mixers, and cross-attention mechanisms based on seasonal components, and to map the output to obtain seasonal prediction components. The trend modeling and fusion output unit is used to input the trend components into the trend modeling branch, perform mapping and feature extraction, and obtain the trend prediction components. By fusing the trend forecast component with the seasonal forecast component, the predicted values of future target water quality parameters are output.