Water quality long-term prediction method and system based on double attention mechanism and bidirectional stacked simple recurrent neural network
By employing a dual attention mechanism and a bidirectional stacked simple recurrent neural network for long-term water quality prediction, this method addresses the issues of long-term reliance, insufficient feature utilization, and inadequate environmental adaptability in existing technologies. It achieves high-precision and stable prediction of water quality parameters and is applicable to complex open water bodies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING UNIV OF POSTS & TELECOMM
- Filing Date
- 2026-05-11
- Publication Date
- 2026-07-31
AI Technical Summary
Existing water quality prediction methods are unable to effectively capture long-term time-series dependencies, ignore environmental error characteristics, fail to adaptively differentiate the importance of features and time points, and have a simple model structure that is difficult to cope with complex open water areas.
A long-term water quality prediction method based on dual attention mechanism and bidirectional stacked simple recurrent neural network is adopted. By integrating multi-source environmental information through feature and time series dual attention mechanism, a DA-Bi-SRU prediction model is constructed, which dynamically adjusts feature weights, focuses on key features and time points, and captures long-term time series dependencies.
It significantly improves the accuracy and robustness of long-term water quality prediction, can adaptively focus on key features and time points, enhances the ability to predict environmental changes in open waters, and meets the actual needs of intelligent aquaculture.
Smart Images

Figure CN122491591A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a long-term water quality prediction method and system based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, belonging to the field of water quality prediction technology. Background Technology
[0002] Water quality is a core factor affecting the healthy growth of aquatic products, and accurate prediction of key parameters such as dissolved oxygen, water temperature, and pH is a crucial link in realizing intelligent aquaculture. Currently, water quality prediction methods mainly face the following challenges: 1) Long-term dependency problem: Traditional time series models (such as the Autoregressive Differential Moving Average (ARIMA) model) and basic recurrent neural networks struggle to effectively capture the complex long-term temporal dependencies in water quality data. 2) Insufficient feature utilization: Existing methods often analyze water quality parameters in isolation, failing to fully integrate key environmental error features such as meteorological conditions (e.g., temperature, precipitation), resulting in poor predictive ability for abrupt water quality events. 3) Ignoring multi-scale characteristics: Water quality data exhibits significant diurnal variations, seasonality, and other multi-scale temporal characteristics, making it difficult for traditional models to adaptively focus on key information at different time scales.
[0003] Existing water quality prediction technologies have the following main drawbacks:
[0004] (1) Inability to effectively capture long-term temporal dependencies. Specifically, traditional recurrent neural networks (RNNs) and their variants, such as LSTMs, are still affected by the vanishing or exploding gradient problem when processing long sequences, making it difficult to learn and remember the correlations between distant time steps. This leads to a significant decrease in the performance of the model when making long-term predictions, and it is unable to accurately predict the long-term changing trends of water quality parameters.
[0005] (2) Ignoring environmental error characteristics leads to poor predictive ability for abrupt events. Specifically, most existing methods only focus on historical data of water quality parameters such as water temperature and pH value, while ignoring the "error" effect of external environmental factors such as meteorological conditions such as air temperature and precipitation on water quality. This "error" is the key reason for sudden changes in water quality, such as a sharp drop in dissolved oxygen or abrupt temperature changes. Therefore, existing models may be feasible under relatively stable conditions, but they cannot predict abrupt changes in water quality caused by drastic environmental changes.
[0006] (3) Failed to adaptively differentiate the importance of features and time points. Specific manifestations include:
[0007] At the feature level: the model treats all input features, such as water temperature, salinity, pH, and air temperature, equally, and cannot automatically identify which features are most critical to the prediction target at a specific time. For example, in summer, air temperature may be extremely important for water temperature prediction, while salinity may be relatively stable and less important.
[0008] At the time level: the model assigns equal weight to all historical time points, failing to focus on key historical moments most relevant to the prediction point, such as time points a few days or weeks ago with similar patterns. This results in the model being interfered with by a large amount of irrelevant historical information, reducing prediction accuracy.
[0009] (4) The model structure is too simple to cope with complex open water bodies. Specifically, existing studies are mostly designed for simple, closed water bodies, and the model structure is relatively simple (such as unidirectional RNN / LSTM). When applied to open aquaculture water bodies affected by a variety of natural and human factors, these models have insufficient adaptability and generalization ability, low prediction accuracy and poor reliability. Summary of the Invention
[0010] The purpose of this invention is to provide a long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network. This method can effectively integrate multi-source environmental information and improve the accuracy of long-term water quality prediction by weighting features and time series with dual attention. This solves the problem that the prediction accuracy and robustness of existing technologies need to be improved.
[0011] The technical solution of this invention is:
[0012] A long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network includes the following steps:
[0013] S1. Obtain historical water quality parameter data and historical meteorological data to form a multi-dimensional time series input dataset;
[0014] S2. Construct a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent unit (Bi-SRU) network, namely the DA-Bi-SRU prediction model. The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a Bi-SRU network, a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights of each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain the enhanced feature vector, which is then output. The Bi-SRU (Bi-Stacked Simple Recurrent Unit Network) captures temporal context information from both past and future directions when processing input data step by step. It generates and transmits the hidden state of each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer calculates the correlation weight between the hidden state of all historical time steps in the hidden state sequence and the current prediction task. After weighted summation of the hidden states of all historical time steps, it generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results.
[0015] S3. Use the multidimensional time series input dataset to train the DA-Bi-SRU prediction model to obtain the trained DA-Bi-SRU prediction model.
[0016] S4. The water quality parameter data to be predicted and the meteorological data to be predicted are combined to form the multidimensional time series input dataset to be predicted, and then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.
[0017] Furthermore, in step S1, the historical water quality parameter data includes at least water temperature, pH value and dissolved oxygen, and the historical meteorological data includes at least air temperature and precipitation.
[0018] Furthermore, in the DA-Bi-SRU prediction model, data preprocessing includes data cleaning and standardization.
[0019] Furthermore, in the DA-Bi-SRU prediction model, the calculation process of the feature attention layer is as follows:
[0020] Preprocessed features x at the current time t t d Calculate the attention score e for each feature dimension d. t d :
[0021]
[0022] Where MLP represents a multilayer perceptron, h t-1 This represents the hidden state at time t-1;
[0023] Then the attention score e t d After normalization using the Softmax function, the attention weights 'a' for each feature dimension are obtained. t d :
[0024]
[0025] Where exp represents an exponential function with the natural constant e as the base, and D is the total number of feature dimensions;
[0026] Finally, the obtained attention weights a t d With the corresponding preprocessed feature x t d Element-wise multiplication yields the enhanced feature vector. As input to the Bi-SRU (Bi-Stacked Simple Cyclic Unit) network:
[0027]
[0028] Here, ⊙ represents element-wise multiplication.
[0029] Furthermore, in the DA-Bi-SRU prediction model, the bidirectional stacked simple cyclic unit network Bi-SRU is composed of a forward simple cyclic unit layer for capturing historical information and a reverse simple cyclic unit layer for capturing future information. The final hidden state of the bidirectional stacked simple cyclic unit network Bi-SRU is the concatenation of the hidden states in both the forward and reverse simple cyclic unit layers.
[0030] Furthermore, in the DA-Bi-SRU prediction model, the calculation process of the temporal attention layer is as follows:
[0031] First, the temporal attention layer receives the hidden state sequence output by the bidirectional stacked simple recurrent unit network (Bi-SRU). After that, select the hidden state at the current time t. As a query vector, calculate the hidden state. With all historical hidden states The dot product yields the correlation score. ,in, ;
[0032] Secondly, the relevance score Temporal attention weights are obtained after normalization using the Softmax function. ;
[0033] Finally, using temporal attention weights Hidden states in all histories Performing a weighted summation, i.e., calculating This directly generates the final context vector. , used to output prediction results.
[0034] A system employing the long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described above includes a data acquisition module, a model building module, a model training module, and a result output module.
[0035] Data acquisition module: Acquires historical water quality parameter data and historical meteorological data to form a multidimensional time series input dataset;
[0036] Model Construction Module: This module constructs a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent unit (Bi-SRU) neural network, namely the DA-Bi-SRU prediction model. The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a Bi-SRU network, a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights for each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain the enhanced feature vector. The output is fed to the Bi-SRU (Bi-Stacked Simple Recurrent Unit) network. When processing the input data step by step, the Bi-SRU network captures temporal context information from both past and future directions, generates and transmits the hidden state of each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer is used to calculate the correlation weight between the hidden state of all historical time steps in the hidden state sequence and the current prediction task, and after weighted summation of the hidden states of all historical time steps, it generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results.
[0037] Model training module: The DA-Bi-SRU prediction model is trained using a multi-dimensional time series input dataset to obtain the trained DA-Bi-SRU prediction model;
[0038] The results output module takes the water quality parameter data and meteorological data to be predicted and forms a multidimensional time series input dataset to be predicted. This dataset is then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.
[0039] The beneficial effects of this invention are as follows: Compared with existing methods, the long-term water quality prediction method and system based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network have the following advantages:
[0040] 1. Significantly improved accuracy: By introducing a dual attention mechanism of features and time series, the DA-Bi-SRU prediction model of this invention can adaptively focus on the features and time points most relevant to the prediction target. In long-term prediction tasks, its error indicators such as MAE and RMSE are significantly reduced compared with traditional RNN, LSTM and single Bi-SRU models, and the overall prediction accuracy is improved by more than 20%.
[0041] 2. Strong robustness: By integrating environmental error features such as meteorology, the model has a better predictive ability for water quality fluctuations caused by sudden environmental changes in open water areas, and its generalization performance is better.
[0042] 3. High practicality: The method and system provided by this invention can meet the actual needs of long-term, stable and accurate prediction of water quality in intelligent aquaculture, help to detect the risk of water quality deterioration in advance, and have broad application prospects. Attached Figure Description
[0043] Figure 1 This is a flowchart illustrating the long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, according to an embodiment of the present invention.
[0044] Figure 2 This is a schematic diagram illustrating the DA-Bi-SRU prediction model in the embodiment;
[0045] Figure 3 This is a schematic diagram illustrating the feature attention layer in the embodiment;
[0046] Figure 4 This is an illustrative diagram illustrating the long-term water quality prediction system based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network in the embodiment.
[0047] Figure 5 This is a schematic diagram comparing the water temperature prediction results with the actual water temperature values of the DA-Bi-SRU prediction model and the comparison models, including the RNN model, LSTM model and Bi-SRU baseline model, in the embodiment.
[0048] Figure 6 yes Figure 5 A magnified view of a portion of point A in the middle.
[0049] Figure 7 This is a schematic diagram comparing the predicted water temperature results with the actual water temperature values using the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model, and Bi-SRU baseline model, as described in this embodiment.
[0050] Figure 8 yes Figure 7 A magnified view of a portion of point B in the middle.
[0051] Figure 9 This is a schematic diagram comparing the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model and the Bi-SRU baseline model, in the dissolved oxygen prediction results with the actual dissolved oxygen values.
[0052] Figure 10 yes Figure 9 A magnified view of a portion of point C. Detailed Implementation
[0053] The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0054] The embodiment provides a long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, such as Figure 1 This includes the following steps:
[0055] S1. Obtain historical water quality parameter data and historical meteorological data to form a multidimensional time series input dataset.
[0056] In step S1, historical water quality parameter data shall include at least water temperature, pH value and dissolved oxygen, and historical meteorological data shall include at least air temperature and precipitation.
[0057] S2. Construct a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, namely the DA-Bi-SRU prediction model. Figure 2 The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a bidirectional stacked simple recurrent unit network (Bi-SRU), a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights of each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain an enhanced feature vector, which is then output to the bidirectional stacked simple recurrent unit network (Bi-SRU). When processing the input data step by step, the Bi-SRU captures temporal context information from both past and future directions, generates and transmits the hidden state at each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer calculates the correlation weights between the hidden states of all historical time steps in the hidden state sequence and the current prediction task, and after weighted summation of the hidden states of all historical time steps, generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results.
[0058] In the DA-Bi-SRU prediction model, data preprocessing includes data cleaning and standardization.
[0059] In the DA-Bi-SRU prediction model, such as Figure 3 The calculation process of the feature attention layer is as follows:
[0060] Preprocessed features x at the current time t t d Calculate the attention score e for each feature dimension d. t d :
[0061]
[0062] Where MLP represents a multilayer perceptron, h t-1 This represents the hidden state at time t-1;
[0063] Then the attention score e t d After normalization using the Softmax function, the attention weights 'a' for each feature dimension are obtained. t d :
[0064]
[0065] Where exp represents an exponential function with the natural constant e as the base, and D is the total number of feature dimensions;
[0066] Finally, the obtained attention weights a t d With the corresponding preprocessed feature x t d Element-wise multiplication yields the enhanced feature vector. As input to the Bi-SRU (Bi-Stacked Simple Cyclic Unit) network:
[0067]
[0068] Here, ⊙ represents element-wise multiplication.
[0069] Through the above process, the DA-Bi-SRU prediction model can dynamically adjust the input weights of each environmental factor (such as water temperature, air temperature, etc.) at the current moment according to the historical time series status, so as to achieve adaptive focus on key features.
[0070] In the DA-Bi-SRU prediction model, the bidirectional stacked simple cyclic unit network Bi-SRU consists of a forward simple cyclic unit layer for capturing historical information and a reverse simple cyclic unit layer for capturing future information. The final hidden state of the bidirectional stacked simple cyclic unit network Bi-SRU is the concatenation of the hidden states in both the forward and reverse simple cyclic unit layers.
[0071] The forward and reverse simple recurrent unit (SLU) layers of the bidirectional stacked simple recurrent unit (SLU) network process the sequence in chronological order and reverse order, respectively. The forward SLU layer captures historical information, while the reverse SLU layer captures future information. The final hidden states from both directions are concatenated to form a comprehensive hidden state sequence containing global information.
[0072] In the DA-Bi-SRU prediction model, a bidirectional stacked simple recurrent unit network (Bi-SRU) is employed as the core component for temporal feature extraction. Compared to traditional LSTM or GRU networks, Bi-SRU achieves parallel computation across time steps through a simplified gating mechanism, significantly reducing the training time cost of long-sequence water quality data. Simultaneously, its bidirectional structure comprehensively captures the evolution of water quality parameters from both positive and negative directions, while the stacked structure further enhances the model's ability to fit nonlinear coupling relationships. Combined with a front-end feature attention mechanism, this network effectively filters out redundant environmental factors, focusing on the temporal evolution of key water quality indicators, thereby significantly improving the model's response speed and long-term prediction stability while maintaining prediction accuracy.
[0073] In the DA-Bi-SRU prediction model, the temporal attention layer uses a dot product operation to calculate the association weights between the hidden states at all historical time steps and the current prediction task. The calculation process of the temporal attention layer is as follows:
[0074] First, the temporal attention layer receives the hidden state sequence output by the bidirectional stacked simple recurrent unit network (Bi-SRU). After that, select the hidden state at the current time t. As a query vector, calculate the hidden state. With all historical hidden states The dot product yields the correlation score. ,in, ;
[0075] Secondly, the relevance score Temporal attention weights are obtained after normalization using the Softmax function. ;
[0076] Finally, using temporal attention weights Hidden states in all histories Performing a weighted summation, i.e., calculating This directly generates the final context vector. , used to output prediction results.
[0077] The DA-Bi-SRU prediction model introduces a temporal attention layer based on dot product operations after the Bi-SRU network. This temporal attention layer filters and aggregates states containing contextual information through an attention mechanism, extracting the most critical temporal features for the current prediction task. Unlike traditional recurrent neural networks that compress all historical information into a single hidden state, the temporal attention layer dynamically generates a temporal-dimensional attention weight distribution by calculating the dot product similarity between the current task vector and all historical hidden states. This mechanism allows the model to 'focus' on the key time nodes in the historical sequence that have the greatest impact on current water quality changes (such as upstream sewage discharge or heavy rainfall), while automatically suppressing noise interference from irrelevant time steps. Experiments show that this improvement significantly enhances the model's accuracy in long-sequence water quality prediction, especially when dealing with water quality data with significant lag effects and sudden disturbances. Its prediction stability is superior to the baseline model without temporal attention, and the generated attention weight map provides an intuitive and interpretable basis for tracing water pollution sources.
[0078] S3. Use a multidimensional time series input dataset to train the DA-Bi-SRU prediction model to obtain the trained DA-Bi-SRU prediction model.
[0079] S4. The water quality parameter data to be predicted and the meteorological data to be predicted are combined to form the multidimensional time series input dataset to be predicted, and then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.
[0080] This long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network has the following advantages compared to existing methods: 1. Significantly improved accuracy: By introducing a dual attention mechanism of features and time series, the DA-Bi-SRU prediction model of this invention can adaptively focus on the features and time points most relevant to the prediction target. In long-term prediction tasks, its error indicators such as MAE and RMSE are significantly reduced compared to traditional RNN, LSTM, and single Bi-SRU models, with an overall prediction accuracy improvement of over 20%. 2. Strong robustness: By integrating environmental error features such as meteorology, the model has better predictive ability for water quality fluctuations caused by sudden environmental changes in open waters, and its generalization performance is superior. 3. Good practicality: The method and system provided by this invention can meet the practical needs of long-term, stable, and accurate water quality prediction in intelligent aquaculture, helping to detect water quality deterioration risks in advance and possessing broad application prospects.
[0081] The embodiment also provides a system employing the long-term water quality prediction method based on dual attention mechanism and bidirectional stacked simple recurrent neural network described above, including a data acquisition module, a model building module, a model training module, and a result output module, such as... Figure 4 :
[0082] Data acquisition module: Acquires historical water quality parameter data and historical meteorological data to form a multidimensional time series input dataset;
[0083] Model Construction Module: This module constructs a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent unit (Bi-SRU) neural network, namely the DA-Bi-SRU prediction model. The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a Bi-SRU network, a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights for each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain the enhanced feature vector. The output is fed to the Bi-SRU (Bi-Stacked Simple Recurrent Unit) network. When processing the input data step by step, the Bi-SRU network captures temporal context information from both past and future directions, generates and transmits the hidden state of each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer is used to calculate the correlation weight between the hidden state of all historical time steps in the hidden state sequence and the current prediction task, and after weighted summation of the hidden states of all historical time steps, it generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results.
[0084] Model training module: The DA-Bi-SRU prediction model is trained using a multi-dimensional time series input dataset to obtain the trained DA-Bi-SRU prediction model;
[0085] The results output module takes the water quality parameter data and meteorological data to be predicted and forms a multidimensional time series input dataset to be predicted. This dataset is then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.
[0086] This method and system for long-term water quality prediction, based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, aims to overcome the shortcomings of existing water quality prediction models in terms of long-term dependence, feature utilization, mutation prediction, and environmental adaptability. It proposes a bidirectional stacked neural network model that integrates environmental error features and a dual attention mechanism of features and time series, which can significantly improve the overall performance of long-term water quality prediction.
[0087] This method and system for long-term water quality prediction, based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network (Bi-SRU), can improve the accuracy and reliability of long-term water quality prediction. By employing a Bi-SRU network, it captures temporal information from both past and future directions to obtain global context, thereby more effectively learning the long-term patterns and periodic characteristics in water quality data and enhancing the model's ability to model long-term temporal dependencies.
[0088] This invention enhances the ability to predict sudden changes in water quality by integrating multi-source environmental information. By introducing meteorological data (such as temperature and precipitation) as environmental error features into the model, the model can learn the intrinsic relationship between external environmental changes and water quality parameters, thereby enabling more accurate prediction of sudden changes in water quality caused by weather changes and other factors.
[0089] This long-term water quality prediction method and system, based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, achieves adaptive focusing on features and time series. This core objective is achieved by introducing a dual attention mechanism: a feature attention mechanism allows the model to dynamically assign different weights to different features, automatically strengthening key features and suppressing redundant features; simultaneously, a time series attention mechanism enables the model to automatically focus on the most important key time points in the historical sequence for the current prediction, ignoring less important time points. These two mechanisms work together to enable the model to extract the most effective information from complex data.
[0090] This method and system for long-term water quality prediction, based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, constructs a robust and specialized prediction framework suitable for complex environments. By organically combining feature attention, Bi-SRU networks, and temporal attention, an end-to-end specialized model called DA-Bi-SRU is formed. This model structure aims to comprehensively address issues such as feature utilization, long-term dependence, and key information focus, enabling it to better adapt to complex and variable open aquaculture environments and improve the model's practicality and generalization ability.
[0091] The experimental verification of this long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network is as follows:
[0092] The input data for the DA-Bi-SRU prediction model in this embodiment is a matrix of dimension D×T, where D is the number of features (e.g., water temperature, pH, dissolved oxygen, air temperature, precipitation, etc.) and T is the time series length. The DA-Bi-SRU prediction model of this embodiment is trained using a dataset containing 22,000 samples, with an input feature dimension of 6 and an output dimension of 1 (for a single water quality parameter). The Adam optimizer is used, with mean squared error (MSE) as the loss function, and training is performed for 50 epochs.
[0093] Figure 5 This is a schematic diagram comparing the predicted water temperature results with the actual water temperature values using the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model, and Bi-SRU baseline model, as illustrated in this embodiment. Figure 5 As shown, this invention uses mean squared error (MSE) as the loss function to train the DA-Bi-SRU model of the embodiment for 50 epochs, and compares it with various classic time series prediction models (including LSTM, RNN, and Bi-SRU) on the test set. Figure 5 The prediction curve fitting results show that: 1. Highest prediction accuracy: The prediction trajectory of the DA-Bi-SRU model (blue solid line) in the embodiment highly overlaps with the actual data (red dashed line), especially in the range of drastic temperature fluctuations (such as...). Figure 6 As shown in the figure (around sample points 400–550), its ability to capture peaks and troughs far surpasses other models. In contrast, LSTM (black), RNN (purple), and Bi-SRU (cyan) all exhibit significant lag or overshoot. 2. Strong dynamic response capability: During temperature abrupt changes (such as the steep rise near the 450th prediction point), DA-Bi-SRU can quickly follow the changes in the true value, while traditional models show significant phase delay and amplitude decay. This indicates that the dual attention mechanism effectively enhances the model's sensitivity to key historical moments and key feature dimensions, improving its dynamic modeling capability. 3. Minimum overall error: Quantitative analysis shows that across all 1000 prediction points, the MSE value of DA-Bi-SRU is significantly lower than other models (e.g., DA-Bi-SRU: MSE = 0.018; LSTM: MSE = 0.047; RNN: MSE = 0.062; Bi-SRU: MSE = 0.039). The results verify the superiority of the method of this invention in reducing systematic bias and improving generalization performance. 4. Excellent robustness and stability: Even in regions with strong noise interference (such as sample points 800–950), DA-Bi-SRU maintains a smooth and realistic prediction trend without drastic oscillations or divergence, demonstrating its strong noise resistance and structural stability. In summary, Figure 5This invention provides a clear and compelling demonstration that the proposed DA-Bi-SRU architecture offers higher accuracy, stronger dynamic adaptability, and better engineering practicality in time series prediction of environmental parameters such as water quality and temperature, thus providing reliable technical support for environmental monitoring and early warning systems.
[0094] Figure 7 This is a schematic diagram comparing the predicted water temperature results with the actual water temperature values using the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model, and Bi-SRU baseline model, as illustrated in this embodiment. Figure 7 As shown, the DA-Bi-SRU model (blue solid line) in this embodiment demonstrates significantly superior fitting accuracy and dynamic response capability compared to the traditional RNN (purple), LSTM (black), and the Bi-SRU (cyan) baseline model without attention mechanisms in the pH time series prediction task. Figure 7 It can be seen that: 1. The DA-Bi-SRU model in the embodiment has the highest overall fit: Across all 1000 prediction points, the DA-Bi-SRU prediction curve consistently best matches the actual pH value change trend (red dashed line), especially in the high-frequency fluctuation range (e.g., sample points 800–1000), where its trajectory shows almost no phase shift or amplitude distortion, while other models exhibit varying degrees of hysteresis, smoothing, or overshoot. 2. The DA-Bi-SRU model in the embodiment has strong local detail capture capabilities: In areas such as… Figure 8 The magnified region shown (900–940) reveals that the real data exhibits a multi-peaked, small-amplitude oscillation structure, and DA-Bi-SRU accurately reproduces every minute fluctuation. In contrast, RNN loses details due to over-smoothing, LSTM generates spurious peaks due to sensitivity to noise, and while Bi-SRU shows some improvement, it still suffers from systematic bias. This indicates that the dual attention mechanism effectively enhances the model's sensitivity to subtle dynamic features. 3. The DA-Bi-SRU model in this embodiment has the smallest quantitative error: Calculations show that the mean squared error (MSE) of DA-Bi-SRU in this experiment is only 0.0021, far lower than LSTM (0.0058), RNN (0.0073), and Bi-SRU (0.0039), demonstrating its stable advantage in reducing systematic bias. 4. The DA-Bi-SRU model in this embodiment exhibits excellent robustness and adaptability: even in regions with drastic pH changes or strong disturbances (such as a sudden drop near sample point 500 and a sharp rise near 850), DA-Bi-SRU maintains a smooth transition and quickly returns to the true trajectory, without divergence or continuous deviation, demonstrating strong noise resistance and environmental adaptability. In summary, Figure 7This strongly demonstrates that the DA-Bi-SRU architecture proposed in this invention has higher prediction accuracy, stronger dynamic modeling capability, and better engineering applicability when dealing with high-frequency, nonlinear, and easily disturbed water quality parameters (such as pH), and can provide reliable technical support for intelligent water quality monitoring and early warning systems.
[0095] Figure 9 This is a schematic diagram comparing the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model, and Bi-SRU baseline model, in terms of dissolved oxygen prediction results and actual dissolved oxygen values. For example... Figure 9 As shown, in the task of predicting dissolved oxygen (DO) concentration time series, the DA-Bi-SRU model (blue solid line) in this embodiment exhibits significantly superior fitting accuracy, dynamic response capability, and robustness compared to the traditional RNN (purple), LSTM (black), and the Bi-SRU baseline model without an attention mechanism (cyan). The DA-Bi-SRU model in this embodiment has the highest overall fitting accuracy and the smallest error: across all 1000 prediction points, the prediction trajectory of DA-Bi-SRU consistently best matches the actual DO value change trend (red dashed line). Especially in the range of sharp fluctuations (such as sample points 400–600 and 900–1000), its curve shows almost no phase shift or amplitude distortion, while other models show significant deviations: LSTM exhibits severe overshoot and oscillations, RNN is smooth but severely lagging, and although Bi-SRU shows some improvement, it still has systematic underestimation or overestimation at extreme points. Quantitative analysis shows that the mean squared error (MSE) of the DA-Bi-SRU model in the embodiment is only 0.032, far lower than that of LSTM (0.089), RNN (0.105), and Bi-SRU (0.057), demonstrating its stable and significant advantage in reducing systematic bias. The DA-Bi-SRU model in the embodiment exhibits strong local mutation and extreme value capture capabilities: in situations such as... Figure 10The magnified area shown (bottom right corner: sample points 400–500) reveals a "V-shaped" structure in the real data, characterized by a rapid decline followed by a rebound—a typical dynamic feature commonly seen in eutrophication or sudden pollution events. The DA-Bi-SRU model in this embodiment accurately captures the valley location and the rebound slope, while other models either reach the extreme value earlier / later (LSTM / RNN) or fail to reproduce the steep changes (Bi-SRU). This demonstrates that the dual attention mechanism (feature attention + temporal attention) employed in this invention effectively enhances the model's sensitivity to transient features, key turning points, and local extreme events, making it particularly suitable for applications requiring high real-time performance and accuracy, such as water quality safety early warning and ecological critical state identification. The DA-Bi-SRU model in this embodiment exhibits excellent noise robustness and numerical stability: even in sections where DO values are strongly affected by environmental disturbances and fluctuate frequently (such as sample points 700–850), DA-Bi-SRU maintains a smooth transition and quickly returns to the true trajectory, without any abnormal jumps, divergence, or continuous deviations. In contrast, the LSTM curve oscillates violently, the RNN over-smooths and loses details, and the Bi-SRU generates accumulated errors in some intervals. This performance verifies that the architecture of this invention has strong anti-interference capabilities and engineering practicality when facing non-stationary, multi-scale, and noisy real-world monitoring data. The DA-Bi-SRU model of the embodiment consistently leads in multi-parameter generalization ability: combined with Figure 5 (Water temperature) Figure 7 (pH) and Figure 9 As shown in the (DO) results, regardless of whether the target variable is slowly changing (temperature), high-frequency oscillation (pH), or strongly nonlinear abrupt change (DO), the DA-Bi-SRU model in this embodiment maintains the highest accuracy and best fit among all comparative models. This fully demonstrates that it is not optimized for specific data, but rather possesses a universal intelligent prediction architecture that can be widely applied to online monitoring and future trend prediction of various water quality parameters.
[0096] The comparison results of the DA-Bi-SRU prediction model and the comparative models, including the RNN model, LSTM model and the Bi-SRU baseline model, on mean absolute error (MAE), root mean square error (RMSE) and mean absolute percentage error (MAPE) in the embodiment are shown in Table 1.
[0097] Table 1. Error Comparison of the DA-Bi-SRU Prediction Model and the Comparative Model in Long-Term Water Temperature Prediction (Example).
[0098]
[0099] As shown in Table 1, the DA-Bi-SRU prediction model in this embodiment significantly outperforms the RNN model, LSTM model, and Bi-SRU baseline model in terms of mean absolute error (MAE), root mean square error (RMSE), and mean absolute percentage error (MAPE).
[0100] The above embodiments fully demonstrate the effectiveness and superiority of the present invention in long-term water quality prediction. Those skilled in the art can make various modifications and improvements within the scope of the present invention, and these should all be included within the protection scope of the present invention.
Claims
1. A long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, characterized in that: Includes the following steps, S1. Obtain historical water quality parameter data and historical meteorological data to form a multi-dimensional time series input dataset; S2. Construct a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent unit (Bi-SRU) network, namely the DA-Bi-SRU prediction model. The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a Bi-SRU network, a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights of each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain the enhanced feature vector, which is then output. The Bi-SRU (Bi-Stacked Simple Recurrent Unit Network) captures temporal context information from both past and future directions when processing input data step by step. It generates and transmits the hidden state of each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer calculates the correlation weight between the hidden state of all historical time steps in the hidden state sequence and the current prediction task. After weighted summation of the hidden states of all historical time steps, it generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results. S3. Train the DA-Bi-SRU prediction model using a multidimensional time series input dataset to obtain the trained DA-Bi-SRU prediction model. S4. The water quality parameter data to be predicted and the meteorological data to be predicted are combined to form the multidimensional time series input dataset to be predicted, and then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.
2. The long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described in claim 1, characterized in that: In step S1, historical water quality parameter data shall include at least water temperature, pH value and dissolved oxygen, and historical meteorological data shall include at least air temperature and precipitation.
3. The long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described in claim 1, characterized in that: In the DA-Bi-SRU prediction model, data preprocessing includes data cleaning and standardization.
4. The long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described in claim 1, characterized in that: In the DA-Bi-SRU prediction model, the calculation process of the feature attention layer is as follows: Preprocessed features x at the current time t t d Calculate the attention score e for each feature dimension d. t d : Where MLP represents a multilayer perceptron, h t-1 This represents the hidden state at time t-1; Then the attention score e t d After normalization using the Softmax function, the attention weights 'a' for each feature dimension are obtained. t d : Where exp represents an exponential function with the natural constant e as the base, and D is the total number of feature dimensions; Finally, the obtained attention weights a t d With the corresponding preprocessed feature x t d Element-wise multiplication yields the enhanced feature vector. As input to the Bi-SRU (Bi-Stacked Simple Cyclic Unit) network: Here, ⊙ represents element-wise multiplication.
5. The long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described in any one of claims 1-4, characterized in that: In the DA-Bi-SRU prediction model, the bidirectional stacked simple cyclic unit network Bi-SRU consists of a forward simple cyclic unit layer for capturing historical information and a reverse simple cyclic unit layer for capturing future information. The final hidden state of the bidirectional stacked simple cyclic unit network Bi-SRU is the concatenation of the hidden states in both the forward and reverse simple cyclic unit layers.
6. The long-term water quality prediction method based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network as described in any one of claims 1-4, characterized in that: In the DA-Bi-SRU prediction model, the calculation process of the temporal attention layer is as follows: First, the temporal attention layer receives the hidden state sequence output by the bidirectional stacked simple recurrent unit network (Bi-SRU). After that, select the hidden state at the current time t. As a query vector, calculate the hidden state. With all historical hidden states The dot product yields the correlation score. ,in, ; Secondly, the relevance score Temporal attention weights are obtained after normalization using the Softmax function. ; Finally, using temporal attention weights Hidden states in all histories Performing a weighted summation, i.e., calculating This directly generates the final context vector. This is used to output the prediction results.
7. A system employing any one of the methods described in 1-6 for long-term water quality prediction based on a dual attention mechanism and a bidirectional stacked simple recurrent neural network, characterized in that: It includes a data acquisition module, a model building module, a model training module, and a results output module. Data acquisition module: Acquires historical water quality parameter data and historical meteorological data to form a multidimensional time series input dataset; Model Construction Module: This module constructs a long-term water quality prediction model based on a dual attention mechanism and a bidirectional stacked simple recurrent unit (Bi-SRU) neural network, namely the DA-Bi-SRU prediction model. The DA-Bi-SRU prediction model includes a data preprocessing module, a feature attention layer, a Bi-SRU network, a temporal attention layer, and an output layer. The data preprocessing module preprocesses the input raw features to obtain preprocessed features, which are then output to the feature attention layer. The feature attention layer calculates the attention weights for each feature dimension in the preprocessed features and multiplies them element-wise with the corresponding preprocessed features to obtain the enhanced feature vector. The output is fed to the Bi-SRU (Bi-Stacked Simple Recurrent Unit) network. When processing the input data step by step, the Bi-SRU network captures temporal context information from both past and future directions, generates and transmits the hidden state of each time step to represent the historical temporal information before the current moment, and outputs the hidden state sequence to the temporal attention layer. The temporal attention layer is used to calculate the correlation weight between the hidden state of all historical time steps in the hidden state sequence and the current prediction task, and after weighted summation of the hidden states of all historical time steps, it generates a context vector and outputs it to the output layer. The output layer is used to output the water quality prediction results. Model training module: The DA-Bi-SRU prediction model is trained using a multi-dimensional time series input dataset to obtain the trained DA-Bi-SRU prediction model; The results output module takes the water quality parameter data and meteorological data to be predicted and forms a multidimensional time series input dataset to be predicted. This dataset is then input into the trained DA-Bi-SRU prediction model to obtain the predicted water quality parameter values within the set time range.