Environmental water quality monitoring and predicting method based on deep learning

By using spatiotemporal joint modeling and multi-indicator collaborative prediction through deep learning models, the problems of spatiotemporal fusion and multi-indicator collaboration in environmental water quality prediction are solved, achieving efficient and accurate water quality prediction and risk assessment.

CN122045779APending Publication Date: 2026-05-15GUIZHOU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610216946.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-14
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing environmental water quality prediction methods are inadequate in terms of spatiotemporal fusion modeling capabilities, multi-indicator collaborative modeling, model training stability, and uncertainty quantification, making it difficult to achieve efficient and accurate water quality prediction and risk assessment.

Method used

We employ Mamba-based temporal feature modeling and multi-head local attention spatial modeling, combined with the GRPO optimizer and Monte Carlo Dropout method, to construct a deep learning model that enables deep spatiotemporal joint modeling and multi-indicator collaborative prediction, and provides reliable early warning information.

Benefits of technology

It significantly improves the accuracy and stability of water quality prediction, can efficiently capture long-term dependence and local spatial relationships, achieve multi-indicator collaborative prediction, and provide reliable prediction results and risk level assessment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122045779A_ABST
    Figure CN122045779A_ABST
Patent Text Reader

Abstract

The invention discloses an environmental water quality monitoring and predicting method based on deep learning, and relates to the technical field of environmental monitoring. The method comprises the steps of collecting multi-site time series data and constructing a space-time input matrix and a space relation matrix; a time sequence feature is extracted by using 1D convolution and an improved Mama network; spatial features are extracted through multi-head local attention with distance punishment; carrying out multi-index multi-step prediction by adopting a multi-task learning framework after fusion; a multi-objective loss function is constructed, and a GRPO optimization strategy is adopted for training; during reasoning, uncertainty estimation is carried out through Monte Carlo Dropout, and a prediction mean value, a confidence interval and a risk level are output. According to the method, deep space-time joint modeling and multi-index collaborative prediction can be realized, the prediction precision and the training stability are improved, credible early warning information can be provided, and the method can be widely applied to water quality prediction of various environmental water bodies such as rivers, lakes and reservoirs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of environmental monitoring technology, and specifically to a method for environmental water quality monitoring and prediction based on deep learning. Background Technology

[0002] Environmental water quality is a crucial indicator for assessing the health of ecosystems and the safety of human production and daily life. It is widely used in the monitoring and management of various water environments, including rivers, lakes, reservoirs, wetlands, urban water bodies, and groundwater. With the large-scale construction of automatic monitoring stations, environmental monitoring systems can continuously collect high-frequency, multi-dimensional water quality indicators (such as chemical oxygen demand, ammonia nitrogen, total phosphorus, total nitrogen, dissolved oxygen, and pH) as well as auxiliary information such as meteorological and hydrological data. How to utilize this heterogeneous data to accurately predict future water quality is a key task for environmental management departments in achieving pollution early warning, risk assessment, and dispatching decisions.

[0003] Existing methods for predicting environmental water quality have the following main shortcomings:

[0004] 1. Weak spatiotemporal fusion modeling capability: Traditional deep learning models (such as LSTM, GRU) or graph neural networks (GNN) struggle to simultaneously and efficiently capture long temporal dependencies and complex local spatial relationships. For example, methods based on recurrent neural networks have high computational complexity and are susceptible to gradient problems; while methods based on static graph structures cannot dynamically adapt to the temporal changes in relationships between sites.

[0005] 2. Insufficient multi-indicator collaborative modeling: Most methods predict each water quality indicator independently, ignoring the inherent coupling and synergistic evolution of different indicators (such as nutrients TN and TP and organic pollutants CODMn), resulting in limited overall prediction performance.

[0006] 3. Unstable model training: Environmental water quality data are usually characterized by high noise and strong fluctuations. When using conventional optimizers (such as Adam) under complex loss functions, gradient oscillations or getting stuck in local optima are likely to occur, affecting the model's convergence and generalization ability.

[0007] 4. Lack of uncertainty quantification: Most existing models only output single-point prediction values ​​and cannot provide confidence intervals or credibility assessments of the prediction results, which is not conducive to environmental management departments to make scientific risk classification and early warning decisions. Summary of the Invention

[0008] The purpose of this invention is to solve the above-mentioned problems by providing a deep learning-based environmental water quality monitoring and prediction method that can achieve deep spatiotemporal joint modeling and multi-indicator collaborative prediction, improve prediction accuracy and training stability, and provide reliable early warning information.

[0009] To achieve the above-mentioned objectives, the present invention provides the following technical solution:

[0010] The present invention provides a deep learning-based method for environmental water quality monitoring and prediction, comprising the following steps:

[0011] Step S1, Data Acquisition and Preprocessing:

[0012] Multidimensional environmental water quality time-series data were collected from multiple monitoring stations, including target water quality indicators (such as chemical oxygen demand, ammonia nitrogen, total phosphorus, total nitrogen, dissolved oxygen, pH, etc.) and meteorological and hydrological auxiliary characteristics; missing value imputation, outlier detection, standardization, and time alignment were performed on the data; and a spatiotemporal input matrix Xt and a spatial relationship matrix S calculated based on the geographical distance between stations were constructed.

[0013] Step S2, Time-series feature modeling based on Mamba:

[0014] Short-term local trend features are extracted using 1D convolution (1D CNN), and the extracted features are input into an improved Mamba state-space sequence network to model long-term dependencies; the temporal feature representation H(tem) of each site is obtained.

[0015] Step S3, Spatial modeling based on multi-head local attention:

[0016] Using the features of each site at the same time as input, multi-head self-attention calculation is performed, and a distance penalty term based on the spatial relationship matrix S is introduced to automatically bias the spatial attention weights toward neighboring sites; thus, the spatial feature representation H(spa) is obtained.

[0017] Step S4, Spatiotemporal fusion and multi-indicator joint prediction:

[0018] The temporal feature H(tem) and spatial feature H(spa) are concatenated to form the fused feature Zi. A multi-task learning framework is adopted so that multiple water quality indicators share the underlying fused feature and output the future sequence of each water quality indicator through an independent prediction head, thereby realizing multi-step prediction of the future H steps (e.g., 72 hours).

[0019] Step S5, Adaptive optimization training based on GRPO:

[0020] A multi-objective loss function is constructed, including a prediction error term, an L2 regularization term, and a task consistency constraint term. The GRPO (Gradient Reparameterization Optimization) optimization strategy is adopted to dynamically adjust the parameter learning rate according to the gradient sign change, and gradient sign truncation is combined to improve training stability. The model is iteratively trained to obtain the optimal model parameters.

[0021] Step S6, Uncertainty estimation and risk output:

[0022] Multi-step rolling prediction is performed using a sliding window approach; Monte Carlo Dropout is enabled during the inference phase to perform multiple random forward propagations; the prediction mean and confidence interval are calculated to achieve uncertainty estimation; and the prediction results of multiple indicators and their corresponding risk levels are output.

[0023] Compared with existing technologies, this invention has significant advantages. As can be seen from the above technical solution, the core network structure MLA-Mamba used in this invention consists of: multi-site sensor data being processed by a one-dimensional convolutional neural network to extract spatiotemporal feature matrices; the temporal module employing an improved Mamba unit containing a selective state space; and the spatial module employing a multi-head local attention mechanism with distance bias. The outputs of both are fused through a feature fusion and multi-task layer, and then output 72-hour predicted values ​​and 95% confidence intervals for indicators such as NH3-N, TP, and TN through independent prediction heads. The GRPO optimizer participates in training through adaptive learning rate and momentum pruning. This invention connects to the feature preprocessing module through a multi-source monitoring data acquisition layer. After STL decomposition, anomaly detection, and spatiotemporal matrix construction, the data is input to the MLA-Mamba feature extraction network. The network output features are iteratively optimized by the GRPO optimization training module and then input to the uncertainty assessment and early warning module. Finally, Dropout sampling generates prediction results with confidence intervals and an early warning level map. It has the following advantages:

[0024] 1. Deep spatiotemporal joint modeling: Through the collaborative work of the Mamba temporal module and the multi-head local attention (MLA) spatial module, it can efficiently and accurately model long-term dependent features and local spatial relationships at the same time, significantly improving the accuracy of multi-site water quality prediction.

[0025] 2. Multi-indicator collaborative prediction: Through a multi-task learning framework, knowledge sharing and collaborative prediction among different pollutant indicators are realized, effectively capturing the coupling patterns between indicators and improving the overall prediction performance.

[0026] 3. High training stability: Relying on the GRPO optimization strategy, through dynamic learning rate adjustment and gradient truncation mechanism, gradient oscillation and local convergence are effectively avoided, thereby improving the training efficiency and generalization performance of the model.

[0027] 4. Reliable prediction results: The Monte Carlo Dropout method is used to provide prediction confidence intervals, making the prediction results not only "accurate" but also "reliable", which meets the decision-making needs of environmental regulation regarding risk level and safety margin.

[0028] 5. Strong generalization ability: This method does not depend on a specific water body type and can be widely applied to water quality prediction of various environmental water bodies such as rivers, lakes, reservoirs, wetlands and even groundwater. Attached Figure Description

[0029] Figure 1 This is a flowchart illustrating the overall process structure of the present invention.

[0030] Figure 2 This is a block diagram of the technical structure of the present invention. Detailed Implementation

[0031] The following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of the deep learning-based environmental water quality monitoring and prediction method proposed in this invention:

[0032] Example 1:

[0033] See Figure 1 A deep learning-based method for environmental water quality monitoring and prediction includes the following steps:

[0034] Step S1, Data Acquisition and Preprocessing:

[0035] This embodiment acquires continuous, multi-dimensional time-series data from multiple environmental water quality monitoring stations. It focuses on the Chayuan, Xinrenqiao, and Panghai monitoring stations in the Chong'anjiang River basin of the Yangtze River system in Guizhou Province, collecting hourly water quality and meteorological / hydrological data from January 2021 to December 2022. The prediction targets are four indicators—CODMn, NH3-N, TP, and TN—for the Panghai station over the next 72 hours.

[0036] (1) Data include: target water quality indicators: chemical oxygen demand, permanganate index (CODMn), ammonia nitrogen (NH3–N), total phosphorus (TP), total nitrogen (TN), etc.; auxiliary variables: temperature, pH, flow rate, rainfall, etc.; spatial information: station latitude and longitude, relative distance, etc.

[0037] (2) Perform data integrity processing: use linear interpolation or forward imputation to fill missing values; perform 3σ rule detection on outliers and replace them with nearby normal values; perform z-score standardization on all features to make their mean 0 and variance 1;

[0038] (3) Align the timestamps of all monitoring stations to ensure that the input matrix Xt contains the features of all stations at each time point;

[0039] (4) Construct the spatial correlation matrix S using the Gaussian kernel function:

[0040] ;

[0041] in To monitor the distance between stations i and j, σ is half the average distance between the stations;

[0042] Step S2, time series feature modeling based on Mamba (see...) Figure 2 ):

[0043] This step is used to extract long-short sequence variation features. The kernel size can be set to 3, and the number of output channels can be set to 64 or 128.

[0044] (1) Perform 1D convolution on the T-step historical sequence input for each station, with a kernel size of 3 and the number of output channels set to 64 or 128. This convolutional layer extracts local short-term trends, such as diurnal cycle fluctuations and sudden peaks.

[0045] (2) Input the convolutional features into the improved Mamba state-space sequence modeling unit, which includes:

[0046] State-space update equation:

[0047] ;

[0048] Output mapping equation:

[0049] ;

[0050] Where: h t Let A, B, and C be the hidden states, and let u be the learnable parameter matrix. t This is the output of a 1D-CNN;

[0051] (3) The selective gating structure in the GRU style is adopted to improve the controllability of state updates. The specific implementation method is as follows:

[0052] The input u of the state-space model t (i.e., the features after 1D convolution) are taken as input to GRU, and the hidden state h to be updated is taken as input. t These are considered as hidden states of the GRU. The standard state-space equations are gated and modulated using the following gated computation:

[0053] Reset door r t : Control the state h of the previous moment t-1 How much of the information is used to calculate the current candidate state? t =σ(W r ·u t +U r ·h t-1 )

[0054] Update Gate Z t : Control state from h t-1 to h t The update status. t =σ(W z · u t +U z · h t-1 )

[0055] Among them, W r U r W z U z Let be the learnable weight matrix, and σ be the sigmoid activation function.

[0056] The specific modulation state update process of the gating signal is as follows:

[0057] First, compute a candidate hidden state modulated by a reset gate. Its calculation method borrows from GRU and incorporates the form of a state-space model:

[0058] ;

[0059] Here, reset gate r t Acting on the previous state h t-1 This allows for the selective "forgetting" of historical information, thereby affecting the actual target of the state transition matrix A.

[0060] Finally, the hidden state h at the current moment t By update gate z t For the previous state h t-1 and candidate states By performing a weighted summation, we can obtain the selective update of the completed state:

[0061] ;

[0062] Note: Update gate z t This determines the extent to which the model adopts new candidate states. (Including current input information) versus retain old state h t-1 .

[0063] Relationship with the original state-space equation: The above process is equivalent to constructing a gated state-space update equation. Here, the learning of matrices A and B is related to the gate signal r. t ,z t Collaborative work. Reset door r t The state h was dynamically modulated t-1 Entering the linear transformation part, and updating the gate z. tThe dynamics determine the mixing ratio of the old and new states. This structure allows the model to adjust according to the current input u. t It adaptively manages the retention and updating of long-term memory, thereby effectively mitigating the gradient vanishing problem and enhancing the ability to capture long-term temporal dependencies.

[0064] The complete definition of the computational process of the GRPO (Gradient Reparameterization Optimization) optimizer. The GRPO optimization strategy aims to improve training stability by dynamically adjusting the learning rate and gradient management. Its core steps are as follows:

[0065] a. Gradient calculation: Calculate the gradient of the loss function L with respect to the model parameters θt at the current iteration step t. .

[0066] b. Dynamic learning rate adjustment (gradient reparameterization): An independent learning rate ηt,k is maintained for each parameter component θt,k. The adjustment rule is based on the consistency between the current gradient sign and the historical gradient signs.

[0067] 1) If sign(Gt,k)=sign(G t-1 If the gradient directions are consistent, then increasing the learning rate accelerates convergence: ηt,k = min(ηt,k). t-1 ,k×c↑,ηmax). Where c↑>1 is the increase factor (suggested value 1.05).

[0068] 2) If sign(Gt,k)=sign(G t-1 ηt,k) indicates that the gradient direction oscillates, so the learning rate is reduced to stabilize training: ηt,k=max(ηt,k) t-1 ,k×c↓,ηmin). Where c↓<1 is the reduction factor (suggested value 0.5). Note: ηmax and ηmin are the upper and lower bounds of the learning rate (e.g., 10⁻² and 10⁻⁵).

[0069] c. Gradient Truncation and Momentum Update: Calculate the momentum term vt+1 = μ·vt + ηt⊙Gt, where μ is the momentum coefficient (recommended value 0.9), and ⊙ indicates element-wise multiplication. Simultaneously, perform gradient sign truncation: when a gradient sign flip is detected (i.e., sign(Gt,k) = sign(Gt-1,k)), the current gradient component Gt,k ​​of the corresponding parameter can be selectively set to zero to counteract any overshoot that momentum might cause.

[0070] d. Parameter Update: The final parameter update formula is: θt+1=θt-vt+1+λ· sign(Gt). Where -vt+1 is the standard momentum update term, λ· sign(Gt) is the gradient sign adjustment term, and λ is a small threshold parameter (recommended value 0.01) to ensure that the parameters can be updated slightly even when the gradient is extremely small, avoiding getting stuck in the flat region;

[0071] (4) Output the time series feature H(tem) to characterize the dynamic evolution of the monitoring station;

[0072] Step S3, Spatial modeling based on multi-head local attention (see...) Figure 2 ):

[0073] Spatial dependency modeling of features at different sites at the same time;

[0074] (1) Take Xt as input, and use it as Query, Key and Value, and obtain Q, K and V through linear mapping;

[0075] (2) Calculate attention weights with distance penalty:

[0076] ;

[0077] (3) Perform softmax to obtain attention weights This directs spatial attention toward adjacent sites and suppresses the influence of distant, irrelevant sites.

[0078] (4) The spatial feature H(spa) is obtained by splicing the multi-head attention outputs and then linearly projecting them.

[0079] Step S4, Spatiotemporal feature fusion and multi-indicator joint prediction:

[0080] (1) For each site, concatenate H(tem) and H(spa) to obtain the fused features:

[0081] ;

[0082] (2) Construct a multi-task prediction structure, and The input consists of multiple independent fully connected layers, and each output layer is responsible for predicting a water quality index (such as CODMn, NH3–N, TP, TN).

[0083] (3) The model directly outputs the predicted sequence for the next H steps (e.g., 72 hours), reducing the accumulation of recursive errors;

[0084] Step S5, Adaptive optimization training based on GRPO:

[0085] The GRPO (Gradient Reparameterization Optimization) optimization strategy is adopted to make the training process more stable.

[0086] (1) Construct a multi-objective loss function, including: prediction error term (MSE); weight regularization term (L2); KL divergence constraint term for consistency of shared features among tasks.

[0087] (2) Dynamically adjust the learning rate of each parameter according to the change of gradient sign: if the current gradient direction is the same as the previous one, increase the learning rate; if the direction is opposite, decrease the learning rate and perform gradient truncation.

[0088] (3) Using parameter iteration with dynamic updates:

[0089] ;

[0090] Step S6, Uncertainty estimation and risk output:

[0091] (1) Enable Monte Carlo Dropout during the inference phase and perform K forward propagations.

[0092] (2) Calculate the predicted mean With variance Construct the prediction confidence interval:

[0093] ;

[0094] (3) Based on the threshold rules of the National Surface Water Environmental Quality Standard (GB 3838-2002), the predicted mean and the upper limit of the confidence interval are mapped to the output of four water quality risk levels: "Blue (Class I, Class II), Yellow (Class III), Orange (Class IV), Red (Class V and worse than Class V)".

[0095] Hyperparameter settings:

[0096] The input sequence length is T = 168 (hours), and the prediction step size is H = 72 (hours).

[0097] 1D-CNN: Number of channels = [64, 128], kernel size = 3.

[0098] Mamba module: state dimension d_state=16, convolution kernel size d_conv=4.

[0099] Multi-head Local Attention (MLA): Number of heads = 8, key / query dimension d_k = 32, distance penalty coefficient β = 0.1.

[0100] Feature fusion: Feature dimension after splicing = 256.

[0101] Loss function weights: MSE term α=1.0, L2 regularization term β=1e-4, inter-task KL divergence constraint term γ=0.1.

[0102] GRPO optimizer: initial learning rate = 0.001, momentum coefficient μ = 0.9, sign adjustment threshold λ = 0.01, learning rate adjustment factor c↑ = 1.05, c↓ = 0.5.

[0103] Training process:

[0104] After warming up with the AdamW optimizer, switch to GRPO with a batch size of 32, 100 training epochs, and use the validation set for early stopping (patience=10).

[0105] Example 2:

[0106] It is basically the same as Example 1, except that the application scenario is a lake, and some modules are adjusted to take into account the characteristics of slow water flow and long pollution diffusion cycle in lakes.

[0107] Step S1, Data Acquisition and Preprocessing: The spatial relationship matrix S is no longer based solely on geographical distance, but incorporates a water flow direction weighting factor. If monitoring station j is downstream of station i, then... Multiply by an additional flow enhancement factor of 1.2.

[0108] Step S3, Spatial modeling based on multi-head local attention: The distance penalty coefficient β of multi-head local attention is reduced to 0.05 to allow for information interaction between stations over a larger spatial range, adapting to the overall water quality change characteristics of the lake.

[0109] Step S4, Spatiotemporal Feature Fusion and Multi-Indicator Joint Prediction: The prediction step size H is adjusted to 120 hours (5 days) to meet the lake management department's assessment needs for weekly water quality evolution.

[0110] The remaining steps are the same as in Example 1.

[0111] Example 3: Lightweight Implementation for a Single High-Value Water Source (Reservoir)

[0112] It is basically the same as Example 1, except that it is deployed in a lightweight manner for reservoir scenarios with very few monitoring stations (only 1-2).

[0113] Step S3, Spatial Modeling Based on Multi-Head Local Attention: When the number of monitoring stations N < 3, skip the multi-head local attention spatial modeling module. Figure 2 The "spatial module" branch in the architecture shown is not active.

[0114] Step S4, Spatiotemporal Feature Fusion and Multi-Indicator Joint Prediction: Due to the lack of spatial feature representation, the temporal feature representation H(tem) output from step S2 is directly used as the fusion feature Zi, i.e. Instead of performing splicing operations, the subsequent multi-task prediction structure is the same as in Example 1, that is, the future H-step prediction values ​​of each water quality index are still output in parallel through independent fully connected layers.

[0115] The remaining steps are the same as in Example 1.

[0116] This embodiment demonstrates that the technical solution of the present invention can still degenerate into a pure time series prediction model and maintain high accuracy even in the absence of spatial context, reflecting the flexibility of the solution.

[0117] Experimental Example 1: Ablation Experiment and Stability Verification

[0118] To verify the beneficial effects of each core module of the present invention, an ablation experiment was conducted under the dataset and hyperparameter settings described in Example 1.

[0119] 1. Spatiotemporal Module Effectiveness: Removing the "multi-head local attention" module (i.e., becoming a pure Mamba temporal model) increases the RMSE to 0.481 on the CODMn metric, demonstrating the necessity of spatial modeling. Removing the GRU gating in Mamba (degenerating to a standard SSM) causes gradient vanishing in the early stages of training, verifying the crucial role of selective gating in stabilizing long sequence training.

[0120] 2. GRPO Optimizer Effectiveness: Keeping other conditions unchanged, the GRPO optimizer was replaced with AdamW. Under the same epoch, the loss function curve trained by AdamW exhibited significant high-frequency oscillations, while the GRPO curve showed a smooth decline. On the final test set, the RMSE of the model trained by AdamW was 0.477, lower than the 0.451 of this invention, confirming the superior generalization ability of GRPO under complex loss terrain.

[0121] Experiment Example 2: Comparative Experiment and Performance Benchmark

[0122] To demonstrate the effectiveness of this invention, under identical dataset partitioning and feature engineering conditions, the invention (MLA-Mamba) was compared with eight mainstream time series / spatiotemporal prediction models. The experimental results are shown in Table 1.

[0123] Table 1. Comparison of 72-hour multi-indicator prediction performance of different models at the Panghai site (data format in the table is "MAE / RMSE", unit: mg / L) (lower values ​​indicate better performance.)

[0124]

[0125] Conclusion: As shown in Table 1, the predicted mean sequence and 95% confidence interval output by this invention (Example 1) closely match the fluctuations of the actual values. Quantitative comparison reveals that the root mean square error (RMSE) of this method is 0.451 mg / L, and the mean absolute error (MAE) is 0.320 mg / L. In contrast, the baseline LSTM model under the same conditions has an RMSE of 0.490 mg / L and an MAE of 0.370 mg / L. This method significantly outperforms existing technologies in both MAE and RMSE evaluation indicators for all four water quality indicators. Particularly for NH3-N and TN indicators, the RMSE reduction exceeds 8%, and the MAE reduction for CODMn reaches 13.5%. This demonstrates that this invention, through spatiotemporal joint modeling and multi-indicator synergistic optimization, truly achieves more accurate and robust water quality prediction. Furthermore, the provided confidence intervals can be used to output four levels of water quality risk: blue, yellow, orange, and red, providing a quantitative basis for risk management.

[0126] The above are merely preferred embodiments of the present invention and do not impose any limitations on the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from any technical solution of the present invention shall still fall within the scope of the technical solution of the present invention.

Claims

1. A method for environmental water quality monitoring and prediction based on deep learning, characterized in that, Includes the following steps: Step S1, Data Acquisition and Preprocessing: Collect multidimensional environmental water quality time-series data from multiple monitoring stations, perform missing value imputation, outlier detection, standardization, and time alignment processing, and construct a spatiotemporal input matrix X. t and the spatial relationship matrix S calculated based on the geographical distance between sites; Step S2, Temporal Feature Modeling Based on Mamba: Short-term local trend features are extracted using 1D convolution, and the extracted features are input into an improved Mamba state-space sequence network to model long-term dependencies, obtaining the temporal feature representation H for each site. (tem) ; Step S3, Spatial Modeling Based on Multi-Head Local Attention: Using the features of each station at the same time as input, perform multi-head self-attention calculation, and introduce a distance penalty term based on the spatial relationship matrix S to obtain the spatial feature representation H. (spa) ; Step S4, Spatiotemporal fusion and multi-indicator joint prediction: Combine the temporal features H (tem) Spatial features H (spa) The parts are spliced ​​together to form a fusion feature Z. i A multi-task learning framework is adopted, which enables multiple water quality indicators to share the underlying fusion features and output the future sequence of each water quality indicator through an independent prediction head, thereby achieving multi-step prediction. Step S5, Adaptive optimization training based on GRPO: Construct a multi-objective loss function including prediction error term, L2 regularization term and task consistency constraint term; adopt GRPO optimization strategy, dynamically adjust the parameter learning rate according to gradient sign change, and combine gradient sign truncation to iteratively train the model to obtain the optimal model parameters; Step S6, Uncertainty estimation and risk output: Multi-step rolling prediction is performed using a sliding window method; Monte Carlo Dropout is enabled during the inference phase to perform multiple random forward propagations; the predicted mean and confidence interval are calculated to achieve uncertainty estimation, and the prediction results of multiple indicators and their corresponding risk levels are output.

2. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The improved Mamba state-space sequence network described in step S2 modulates state updates by introducing a GRU-style selective gating structure, specifically including: Calculate the reset gate r t = σ(W r ·u t + U r ·h t -1 ) and update gate z t = σ(W2·u t + U2·h t -1 ); According to the reset gate r t The hidden state h from the previous moment t -1 After modulation, combined with the current input u t Calculate candidate hidden state h t = tanh(A(r) t ⊙ h t -1 ) + Bu t ); According to the update gate z t The hidden state h from the previous moment t -1 With the candidate hidden state h t Perform a weighted summation to obtain the hidden state h at the current time. t = (1-z t )⊙h t -1 + z t ⊙h t ′.

3. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The introduction of a distance penalty term based on the spatial relation matrix S in step S3 specifically involves: when calculating the attention weights, dividing the dot product of query Q and key K by the scaling factor, and then subtracting the distance penalty term β·dist(i, j), which is the attention score e. i j (h) =(Q i (h) K j (h)T ) / √d k - β·dist(i, j), where β is the distance penalty coefficient and dist(i, j) is the distance between stations i and j.

4. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The GRPO optimization strategy described in step S5 specifically includes: Calculate the gradient of the current iteration step. ; Maintain an independent learning rate η for each parameter component tk The learning rate is dynamically adjusted based on the consistency between the current gradient sign and the historical gradient signs: if sign(G tk ) =sign(G t-1,k If sign(G) is increased, then the learning rate is increased; if sign(G) is increased, then the learning rate is increased. tk )≠sign(G t-1,k If the learning rate is reduced, then the learning rate will be decreased. Perform gradient cutoff and momentum update, and calculate the momentum term v. t+1 = μ·v t + η t ⊙G t ; Update formula θ based on parameters t+1 = θ t - v t+1 + λ·sign(G t Update the parameters, where μ is the momentum coefficient and λ is the sign adjustment threshold.

5. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The output of multi-indicator prediction results and corresponding risk levels in step S6 involves comparing the predicted mean and upper limit of the confidence interval with the threshold of the national surface water environmental quality standard, and mapping them to the preset four-level water quality risk levels of blue, yellow, orange, and red.

6. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The spatial relationship matrix S is calculated using the Gaussian kernel function S. ij = exp(-d ij ² / (2σ²)), based on the geographical distance d between stations ij The calculation yields a value where σ is half the average distance between stations.

7. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, When the number of monitoring stations is less than 3, the spatial modeling module based on multi-head local attention described in step S3 is skipped, and the temporal feature representation H is directly expressed in step S4. (tem) Z, as a fusion feature i Z i = H i (tem) .

8. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The task consistency constraint term in the multi-objective loss function is the KL divergence between the shared features of each task.

9. The environmental water quality monitoring and prediction method based on deep learning according to claim 1, characterized in that, The construction of the spatial relationship matrix S also introduces a water flow direction weighting factor. If monitoring station j is located downstream of station i, then the corresponding element S in the spatial relationship matrix... ij Multiply by the flow enhancement factor of 1.

2.

10. The environmental water quality monitoring and prediction method based on deep learning according to any one of claims 1 to 9, characterized in that, The predicted mean and confidence interval are calculated as follows: the mean μ and variance σ² are calculated through the results of multiple random forward propagations, and the confidence interval CI = [μ - 1.96σ, μ + 1.96σ] is constructed.