Water quality abnormity real-time early warning method and system based on machine learning
By using a machine learning-based real-time early warning method for water quality anomalies, multi-parameter collaborative anomaly patterns are extracted for early warning and pollution propagation prediction. This solves the problems of lag and high false alarm rate in traditional water quality monitoring and early warning methods, and realizes intelligent emergency response and decision support.
Patent Information
- Application Number
- CN202511771106.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-28
- Publication Date
- 2026-03-31
AI Technical Summary
Existing water quality monitoring and early warning methods cannot adapt to seasonal changes and natural fluctuations in water quality parameters, lack early warning capabilities, and cannot identify multi-parameter coordinated abnormal patterns, resulting in delayed early warnings, high false alarm rates, and insufficient emergency response time.
A machine learning-based approach is adopted to acquire high-quality water quality time-series data, extract temporal features, spatial correlation features, and parameter interaction features, perform isolated forest detection and semi-supervised identification, combine LSTM prediction and risk assessment, calculate dynamic thresholds and Bayesian decision-making, and perform anomaly attribution analysis and structured early warning generation.
It enables early identification of multi-parameter collaborative anomalies, accurate prediction of pollution propagation trends, reduction of false alarm rates, improvement of emergency response efficiency, adaptation to seasonal changes in water quality parameters, and provision of intelligent decision support.
Smart Images

Figure CN121765565A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water quality monitoring and environmental protection technology, and more specifically, to a method and system for real-time early warning of water quality anomalies based on machine learning. Background Technology
[0002] With the acceleration of industrialization and the improvement of urbanization, water pollution has become increasingly serious, and water quality safety has become a major issue concerning the national economy and people's livelihood. Traditional water quality monitoring and early warning methods mainly rely on fixed threshold alarm mechanisms, that is, an alarm is triggered when a certain water quality parameter exceeds a preset standard value.
[0003] However, this method has significant technical limitations: fixed threshold methods cannot adapt to the seasonal variations and natural fluctuations of water quality parameters; traditional methods lack early warning capabilities, meaning that by the time water quality parameters exceed standards, pollution events have often already occurred and begun to spread, leaving extremely limited time for emergency response. This is especially true in river systems, where it typically takes several hours for a pollution plume to travel from the discharge source to downstream sensitive areas (such as drinking water source intakes), while traditional methods can only issue an alarm when pollutant concentrations have already exceeded standards, failing to provide sufficient time for emergency response; and they neglect multi-parameter synergistic anomaly patterns. Water pollution often manifests as synergistic changes in multiple parameters, and single-parameter threshold judgments cannot capture such complex combinations of anomalies. For example, industrial organic wastewater discharge can simultaneously cause a synergistic increase in multiple parameters such as COD, ammonia nitrogen, and total phosphorus, but in the early stages of pollution, individual parameters may not yet exceed standards, making timely identification difficult with traditional methods.
[0004] Existing water quality early warning technologies cannot identify potential pollution risks in the early stages when multiple parameters are abnormally linked but have not yet exceeded the standards. They also lack the ability to accurately predict the pollution propagation path and arrival time, resulting in problems such as delayed early warning, high false alarm rate, and insufficient emergency response time. Traditional methods lack intelligent anomaly attribution and decision support capabilities. When anomalies occur, managers find it difficult to quickly determine the cause of the anomaly, the type of pollution, and the best handling measures, which affects the efficiency of emergency response.
[0005] Therefore, there is a need to develop a real-time early warning method for water quality anomalies that can achieve early warning, accurately identify multi-parameter collaborative anomaly patterns, predict pollution propagation trends, and provide intelligent decision support. Summary of the Invention
[0006] This invention provides a real-time early warning method and system for water quality anomalies based on machine learning, which solves the technical problems in related technologies that are unable to identify potential pollution risks in the early stage when multiple parameters are abnormal but have not yet exceeded the standard, lack the ability to accurately predict the pollution propagation path and arrival time, resulting in delayed early warning, high false alarm rate and insufficient emergency response time.
[0007] This invention provides a real-time early warning method for water quality anomalies based on machine learning, including: High-quality raw water quality time-series data streams are obtained, and through preprocessing, standardized water quality time-series datasets after quality control are obtained; Based on the standardized water quality time series dataset after quality control, temporal features, spatial correlation features, and parameter interaction features are extracted. Through feature concatenation and PCA dimensionality reduction, a spatiotemporal feature vector is formed. Anomaly diagnostic information is obtained by performing isolated forest detection and semi-supervised identification on spatiotemporal feature vectors. Based on abnormal diagnostic information, LSTM prediction and risk assessment are performed to obtain prediction and risk assessment information. Based on prediction and risk assessment information, flow velocity is estimated and propagation is predicted to obtain collaborative early warning information and model update results. Based on risk assessment information and collaborative early warning information, dynamic thresholds and Bayesian decision-making are calculated to obtain hierarchical early warning results and early warning implementation plans. Based on the tiered early warning results, anomaly attribution analysis and structured early warning generation are performed to obtain structured early warning information and push results.
[0008] In one specific implementation, the step of obtaining the standardized water quality time-series dataset after quality control includes: Based on the physical constraints of sensor operating status parameters and water quality data, a rule fusion method is used to identify sensor faults, check whether water quality parameters meet physical constraints, calculate the correlation coefficient between monitoring points and spatiotemporal neighboring point data, and determine that the sensor has malfunctioned if the correlation coefficient is lower than the first threshold. An adaptive interpolation method is used to process missing data. For short-term missing data, cubic spline interpolation is used for temporal interpolation. For medium-term missing data, distance-weighted spatial interpolation is performed using spatial neighborhood monitoring point data. For long-term missing data, a matrix completion method is used for spatiotemporal joint interpolation. An adaptive normalization method is used to calculate the historical quantiles of parameters based on a sliding window, and the current data is normalized to a preset interval to obtain a standardized water quality time series dataset after quality control.
[0009] In one specific implementation, the step of forming the spatiotemporal feature vector includes: Extract statistical features at different time scales, construct short-term, medium-term, and long-term windows, and calculate the mean, standard deviation, range, trend, and confidence features within each window; Based on the spatial topological relationship matrix, a neighborhood aggregation method is used to extract spatial correlation features and calculate the neighborhood mean and parameter difference features. The mutual information calculation method is used to identify the mutual influence relationship between parameters, and the parameters with the highest mutual information values are selected to calculate the product feature and ratio feature. The temporal features, spatial features, and parameter interaction features are concatenated and then dimensionality is reduced using PCA to form a spatiotemporal feature vector.
[0010] In one specific implementation, the steps of isolated forest detection and semi-supervised identification include: An isolated forest model is constructed based on historical normal samples. By randomly selecting features and split points, samples are recursively isolated. The separability of samples is mapped to anomaly scores based on the average path length. Local density correction is introduced to improve the sensitivity to local anomalies. An adaptive threshold is obtained by using the preset quantile of the anomaly score as the base threshold and adjusting it according to the data confidence level. The adaptive threshold is then used to determine whether an anomaly exists. For samples identified as abnormal, a semi-supervised classification method is used. The nearest labeled samples are retrieved in the standardized feature space according to Euclidean distance for label propagation. The classification model is trained on the augmented labeled dataset to obtain abnormal diagnostic information.
[0011] In one specific implementation, the steps of LSTM prediction and risk assessment include: Design an LSTM network architecture. The input layer receives time-series data of water quality parameters. The LSTM layer contains two stacked units. The attention layer automatically learns the weights of different historical moments. The three parallel output layers predict the parameter values at three future time points respectively. The Monte Carlo Dropout method is used to quantify the prediction uncertainty. During the inference phase, the Dropout layer is kept active for forward propagation, and the statistical mean and standard deviation form the prediction confidence interval. The predicted future parameter values are compared with dynamic thresholds to assess the risk of exceeding the standard. Based on the future feature vector, the future anomaly score is calculated through an anomaly detection model. The risk level is then calculated comprehensively and divided into four risk levels.
[0012] In one specific implementation, the steps of velocity estimation and propagation prediction include: The flow velocity is estimated based on the established seasonal water level-flow velocity correspondence. The average flow velocity is retrieved based on the current season and water level interval and then interpolated. The propagation time of the pollution plume is calculated based on the estimated flow velocity and spatial location information of the monitoring points. The theoretical propagation time is corrected by a propagation delay correction factor to obtain the expected arrival time. A dilution attenuation model is used to predict the impact of the pollution plume when it reaches the downstream area. The initial pollution intensity is quantified based on anomaly scores and pollution types, and the final impact intensity is calculated. The system generates collaborative early warning information for downstream monitoring points, including the source of the warning, the estimated arrival time, the warning time window, the estimated impact, the type of pollution, and emergency recommendations. The system also updates the propagation delay correction factor based on the prediction error statistics.
[0013] In one specific implementation, the steps of the dynamic threshold and Bayesian decision include: Based on historical normal data, the seasonal decomposition method is used to extract the periodic and trend characteristics of water quality parameters, establish a seasonal baseline model, and calculate the dynamic confidence interval of the normal fluctuation range. Calculate the rate of change correction factor based on the current rate of change of parameters, and dynamically adjust the abnormal threshold when the standardized rate of change exceeds the upper limit of the normal rate of change. Bayesian decision theory is used to determine the early warning trigger, the cost functions of false alarm and false alarm are defined, the probability of anomaly is estimated based on anomaly score, and the expected benefit of issuing an early warning is calculated as the basis for decision-making. The time window continuous monitoring method is used to filter instantaneous fluctuations. Samples are taken and judged at set intervals within the preset monitoring window. When the conditions of continuous abnormality, rising score trend or predicted exceedance are met, a formal warning is issued. Based on the comprehensive risk level, a four-level early warning system is mapped to determine the scope of early warning notifications and response requirements.
[0014] In one specific implementation, the steps of anomaly attribution analysis and structured early warning generation include: Based on the isolated forest model, the TreeSHAP algorithm is used to quantify the contribution of each feature to anomaly detection. The feature index is mapped back to the original water quality parameters to identify key anomaly parameters. The top 10 parameters with the highest total contribution are selected as the main anomaly parameters. Analyze the collaborative anomaly patterns among water quality parameters, calculate the change in the correlation between the current correlation coefficient of key anomaly parameters and the historical normal state baseline correlation matrix, and identify collaborative patterns of altered relationships. Cosine similarity is used to retrieve similar cases from a historical pollution incident knowledge base, and records of disposal measures and effects are extracted to generate emergency response suggestions; The system generates structured early warning messages based on predefined templates, including early warning information, anomaly description, trend prediction, impact analysis, attribution analysis, handling suggestions, and confidence level descriptions, and converts them into text and charts for display. The notification recipients and communication channels are determined according to the warning level, and the warning information is pushed out and the receipt and confirmation status is monitored.
[0015] In one specific implementation, the attention layer is implemented as follows: The attention layer receives the hidden state sequence of 24 time steps output by the LSTM layer, calculates the attention score for each time step, performs linear transformations on the hidden state vector and the context vector respectively and adds them together, and then performs a nonlinear transformation through the hyperbolic tangent activation function to obtain the attention score. Based on the attention scores, the attention weight distribution is obtained using the softmax normalization method; The attention-weighted context representation is obtained by weighting and summing the hidden states of the LSTM, and the model automatically learns the importance weights of recent data and periodic moments; Monte Carlo Dropout uncertainty quantification calculates the mean and standard deviation of predicted values by keeping the Dropout layer active during the inference phase, and then compares the predicted standard deviation with the historical error standard deviation to divide it into three confidence levels.
[0016] This invention provides a machine learning-based real-time water quality anomaly early warning system for executing the aforementioned machine learning-based real-time water quality anomaly early warning method, comprising: The quality control and preprocessing module acquires high-quality raw water quality time-series data streams and, through preprocessing, obtains standardized water quality time-series datasets after quality control. The spatiotemporal feature extraction module extracts temporal features, spatial correlation features, and parameter interaction features based on the standardized water quality time series dataset after quality control. Through feature concatenation and PCA dimensionality reduction, a spatiotemporal feature vector is formed. The anomaly detection and type recognition module performs isolated forest detection and semi-supervised recognition on spatiotemporal feature vectors to obtain anomaly diagnosis information. The short-term water quality prediction and risk assessment module performs LSTM prediction and risk assessment based on anomaly diagnosis information to obtain prediction and risk assessment information; The abnormal propagation prediction module, based on prediction and risk assessment information, performs flow velocity estimation and propagation prediction to obtain collaborative early warning information and model update results; The dynamic early warning decision module calculates dynamic thresholds and Bayesian decisions based on risk assessment information and collaborative early warning information to obtain hierarchical early warning results and early warning execution plans. The anomaly attribution and early warning generation module performs anomaly attribution analysis and generates structured early warnings based on the hierarchical early warning results, resulting in structured early warning information and push notifications.
[0017] The beneficial effects of this invention are as follows: Multi-parameter collaborative anomaly pattern recognition technology can issue early warnings when pollutant concentrations show abnormal trends even before exceeding standards, allowing sufficient time for emergency response and effectively preventing pollution from spreading to sensitive areas. Employing adaptive dynamic thresholds and Bayesian decision theory, it can adapt to seasonal changes and natural fluctuations in water quality parameters. Combined with continuous monitoring of instantaneous filtration fluctuations over time windows, it effectively reduces false alarm rates and improves the reliability and user acceptance of the early warning system. Through the isolated forest algorithm and multi-scale spatiotemporal feature extraction, it can automatically discover multi-dimensional weak anomaly combinations and identify collaborative anomaly patterns that traditional single-parameter methods cannot capture, significantly improving anomaly detection accuracy and effectively avoiding the risk of missed detections.
[0018] Based on empirical hydraulic models and machine learning prediction techniques, the system can accurately predict the propagation path and arrival time of pollution plumes in rivers, providing early warnings for sensitive downstream areas and enabling collaborative protection of regional water quality. Employing the TreeSHAP algorithm and historical case matching technology, the system can automatically identify key anomaly parameters, analyze pollution types, infer pollution source locations, and generate targeted treatment suggestions based on similar historical cases, significantly shortening emergency response decision-making time. Through an online learning mechanism, the system can continuously optimize model parameters based on feedback from early warning effects and user evaluations, adapting to the evolving characteristics of water quality data and new pollution patterns, ensuring the long-term stability and accuracy of the early warning system.
[0019] The system automatically determines the warning level and notification scope based on risk assessment, and uses multiple channels such as SMS, voice calls, and mobile applications to push warning information in parallel, ensuring timely and accurate delivery of warning information to relevant personnel and improving the organizational efficiency of emergency response. Compared to traditional methods, the system deployment cost is lower, and the early warning system effectively avoids water pollution losses and saves on emergency response costs, resulting in significant economic and social benefits. It is applicable to various water quality monitoring scenarios, including industrial parks, urban water supply, rivers, and lakes. This invention provides an advanced technical means for ensuring water quality safety and is of great significance for protecting the water environment, ensuring water supply security, and improving environmental governance capabilities. Attached Figure Description
[0020] Figure 1 This is a flowchart of the machine learning-based real-time early warning method for water quality anomalies according to the present invention; Figure 2 This is a block diagram of the machine learning-based real-time early warning system for water quality anomalies according to the present invention. Detailed Implementation
[0021] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and implement the subject matter described herein, and changes may be made to the function and arrangement of the elements discussed without departing from the scope of this specification. Various processes or components may be omitted, substituted, or added as needed in the examples. Furthermore, some features described in the examples may be combined in other examples.
[0022] At least one embodiment of the present invention discloses a real-time early warning method for water quality anomalies based on machine learning, such as... Figure 1 As shown, it includes: Step 1: Obtain high-quality raw water quality time-series data stream, and obtain a standardized water quality time-series dataset after quality control through preprocessing; Seven monitoring points were set up in the target water area, and a gradient layout was adopted for spatial configuration. The river distance between each monitoring point was controlled within an appropriate range to ensure that the spatial variation gradient of water quality and the pollution propagation process could be effectively captured.
[0023] Each monitoring point is equipped with an integrated multi-parameter water quality sensor, employing a composite sensor array that combines optical, electrochemical, and physical measurement principles. The sensor is waterproof, can operate stably underwater for extended periods, has a fast response time, good data stability, and its continuous operating accuracy meets monitoring requirements after periodic calibration.
[0024] The system monitors 20 key water quality parameters, including four categories: basic physicochemical parameters, nutrient parameters, organic pollution parameters, and heavy metal parameters. It covers major indicators such as temperature, pH value, dissolved oxygen, conductivity, turbidity, COD, ammonia nitrogen, and total phosphorus. The monitoring accuracy of each parameter meets the relevant standard requirements.
[0025] A high-frequency acquisition mode is employed to ensure timely capture of rapid changes in water quality. The data acquisition system uses an embedded processor, equipped with a wireless communication module and local storage unit. Data transmission uses standard communication protocols and is uploaded to the cloud data center in real time via the network. When the network is interrupted, historical data can be saved locally and automatically re-transmitted when the network is restored.
[0026] The system synchronously collects sensor operating status parameters for real-time monitoring of equipment health and data quality assessment, including response time parameters, signal strength parameters, calibration status parameters, environmental parameters, etc., to ensure stable operation of the equipment in a suitable environment.
[0027] Based on the physical constraints between sensor operating status parameters and water quality data, a multi-rule fusion method is employed to identify sensor faults. First, it checks whether the water quality parameters meet the physical constraints. If a parameter value violates the physical constraints, it is initially identified as suspected fault data. For suspected fault data, the correlation coefficient between the monitoring point and its spatiotemporal neighboring data is calculated. Z-score standardization is used to preprocess the data to eliminate the influence of dimensional differences, and then the Pearson correlation coefficient of the standardized data is calculated. Fault diagnosis is performed based on a correlation coefficient threshold. If the correlation coefficient is below the set threshold, the sensor is determined to be faulty, and the data is marked as missing; otherwise, the data is retained but marked as low-confidence data.
[0028] Based on the missing value markers in the fault identification results, an adaptive interpolation method is used to process the missing data. A hierarchical interpolation strategy is adopted according to the duration of the missing data: for short-term missing data, cubic spline interpolation is used for temporal interpolation, constructing spline curves using normal data points before and after the missing segment; for medium-term missing data, synchronous data from neighboring monitoring points is used for spatial interpolation, calculating interpolated values based on distance weighting and hydrological connectivity; for long-term missing data, a matrix completion method is used for spatiotemporal joint interpolation, constructing a spatiotemporal matrix of water quality parameters, and recovering missing elements based on a low-rank matrix completion algorithm. Different interpolation methods correspond to different confidence level markers.
[0029] Based on the interpolated complete time-series data, an adaptive normalization method is used to eliminate dimensional differences between different parameters. Historical quantiles for each parameter are calculated using a sliding window, and a linear mapping method is employed to normalize the current data to a standard interval. This processing method allows the normalization results to adapt to seasonal changes in water quality, linearly mapping data within the normal range to the standard interval. Finally, fault identifiers, interpolation flags, confidence levels, and other attribute information are integrated to obtain a standardized water quality time-series dataset after quality control.
[0030] Step 2: Based on the standardized water quality time series dataset after quality control, extract time features, spatial correlation features and parameter interaction features, and form a multi-scale spatiotemporal feature vector through feature concatenation and PCA dimensionality reduction; Based on the standardized water quality time-series dataset after quality control, complete monitoring data were extracted. Simultaneously, based on the geographical location and hydrological information of the monitoring points, a spatial topology matrix was constructed. This matrix describes the upstream and downstream connectivity and river distances between each monitoring point, providing fundamental information for subsequent spatial feature extraction.
[0031] A multi-scale sliding window method was employed to extract statistical features at different time scales. For each water quality parameter at each monitoring point, three sliding windows with different time scales—short-term, medium-term, and long-term—were constructed to capture short-term fluctuations, medium-term trends, and long-term periodic characteristics, respectively. Within each window, core statistical features such as mean, standard deviation, range, trend, and confidence level were calculated. The features from the three time windows were then concatenated sequentially to construct a multi-scale time feature vector.
[0032] Based on the spatial topological relationship matrix, a neighborhood aggregation method is used to extract spatial correlation features. For each target monitoring point, its first-order neighborhood set is identified, and the key water quality parameter values of these neighborhood points at the current time are extracted. Two types of spatial features are calculated: neighborhood mean and parameter difference. The difference feature reflects the water quality difference between the target point and its neighboring points; a larger difference indicates the presence of local anomalies. A spatial correlation feature vector is constructed based on the key parameters.
[0033] Mutual information calculation is employed to identify the interrelationships between parameters. Mutual information values between parameter pairs are calculated using a sliding historical data window, measuring the statistical dependency between two variables. Parameters undergo equal-frequency discretization preprocessing, joint frequencies are statistically analyzed, and mutual information values are calculated based on information theory principles. A ranking selection method is used to identify key parameter pairs, selecting those with the highest mutual information values as key parameter pairs with interactive relationships. Product features and ratio features are calculated based on these key parameter pairs to capture cooperative patterns and proportional relationships, respectively.
[0034] Step 3: Perform isolated forest detection and semi-supervised identification on multi-scale spatiotemporal feature vectors to obtain anomaly diagnosis information.
[0035] Based on multi-scale spatiotemporal feature vectors, an improved isolated forest algorithm is used for unsupervised anomaly detection. An isolated forest model is constructed based on historical normal samples. The model recursively isolates samples by randomly selecting features and split points, and maps the isolation degree of the samples to an anomaly score based on the average path length and standardization factor. To improve sensitivity to local anomalies, a local density correction is introduced. The local density value is obtained by calculating the distance relationship between the target sample and its nearest neighbors, and a correction coefficient is calculated based on the local density to correct the original anomaly score, resulting in the final anomaly score.
[0036] An adaptive threshold is used to determine whether an anomaly is detected based on the final anomaly score and the data confidence level of the current sample. The adaptive threshold is obtained by weighting the anomaly score quantiles and adjusting them according to the data confidence level, and then outputting the binary anomaly detection result.
[0037] Based on the binary anomaly detection results, a semi-supervised classification method is used to identify the pollution type for samples judged as anomalous, thus obtaining the pollution type identification result. Specifically, this includes: expanding the label set using small-scale labeled samples and label propagation: in the standardized feature space, the three nearest labeled samples are retrieved for each unlabeled anomalous sample according to Euclidean distance. If most categories are consistent and the distance is below a threshold (approximately 1.5 times the mean) based on the average distance of labeled samples, then its category label is propagated. A multi-class classification model (XGBoost) is trained on the expanded labeled dataset. The input is a 100-dimensional feature normalized to Min-Max, and the output is the pollution type (heavy metals, organic matter, agricultural non-point source pollution, domestic sewage, unknown). Training uses cross-entropy loss, 100 iterations, a learning rate of 0.1, and a maximum depth of 6. During the inference phase, five probability distributions are output, and the category with the highest probability is taken as the predicted type and its confidence level; if the highest probability is below 0.5, "unknown type" is output, prompting further manual confirmation.
[0038] Online learning is conducted in conjunction with feedback from manual verification after early warnings, and new samples (features, anomaly labels, type labels) are added to the database; retraining is triggered when ≥50 new samples are added each week; Isolation Forest uses normal samples from the last 6 months, and classification models use all labeled events; if the performance on the validation set is better than the current model, a new version is launched.
[0039] Based on the anomaly detection results and type identification results, complete anomaly diagnostic information is integrated to obtain a comprehensive output including anomaly identifier (normal / abnormal), anomaly score (a continuous value between 0 and 1), contamination type (if it is abnormal, the specific type is given), and classification confidence.
[0040] Furthermore, deep learning methods can be used to replace isolated forests for anomaly detection. Based on 100-dimensional feature vectors, a variational autoencoder (VAE) model is constructed for anomaly detection, obtaining an anomaly score based on reconstruction error. The VAE model consists of an encoder and a decoder. The encoder maps the 100-dimensional input features to a 20-dimensional latent representation, and the decoder reconstructs the latent representation back into a 100-dimensional feature space. The model is trained using historical normal samples to learn the latent distribution of normal water quality data. For a sample to be detected, the mean squared error between its input features and the reconstructed features is calculated as the reconstruction error. The larger the reconstruction error, the more the sample deviates from the normal distribution, and the higher the degree of anomaly. The purpose of this alternative embodiment is to utilize the stronger nonlinear expressive power of deep learning models to improve the accuracy of identifying complex anomaly patterns, especially for detecting anomalies with nonlinear correlations between multi-dimensional features.
[0041] Step 4: Based on the abnormal diagnostic information, perform multi-task LSTM prediction and risk assessment to obtain prediction and risk assessment information; Based on the time series data of key parameters from the past two hours, a multi-task LSTM neural network model is used to predict water quality parameter values at multiple future time points, thus obtaining a prediction model.
[0042] Design a multi-task LSTM network architecture to construct the prediction model structure. The model input layer receives 20-dimensional time-series data; the LSTM layer contains two stacked LSTM units, with the first layer containing 128 LSTM neurons and the second layer containing 64 LSTM neurons. A dropout layer (dropout rate of 0.2) is set between each layer to prevent overfitting; the output of the LSTM layer is connected to the attention layer, which automatically learns the weights of different historical moments for future predictions; the output of the attention layer is connected to three parallel fully connected output layers, which predict the values of five parameters at three time points: 30 minutes, 60 minutes, and 90 minutes. Each output layer produces a 5-dimensional output, and the model outputs a total of 15-dimensional (3 time points × 5 parameters) predicted values.
[0043] Based on the designed network architecture and historical water quality data from the past 6 months, a multi-task LSTM model was trained to obtain a well-trained prediction model. A 6-month historical interval was selected to cover seasonal variations while also considering the freshness of recent data. The historical water quality time-series data was preprocessed, and the Min-Max normalization method was used to scale the five key parameters (COD, ammonia nitrogen, total phosphorus, pH, and conductivity) to the [0,1] interval. This normalization method is similar to the adaptive normalization method used in the data preprocessing stage, but uses historical minimum and maximum values as normalization boundaries to ensure the consistency of the training data. The normalized parameters are saved for subsequent data preprocessing and de-normalization in prediction. A sliding window method was used to generate training samples from the normalized historical data, with a sampling interval of 5 minutes and a sliding window step size of 5 minutes. Therefore, two consecutive hours of input correspond to 24 time steps. Each training sample contains input (two consecutive hours of time-series data for the five parameters) and output (the true values of the five parameters at 30, 60, and 90 minutes after the end of the input period). The model was trained using the Adam optimizer with a learning rate of 0.001 to balance convergence stability and speed. The loss function was multi-task weighted mean squared error, calculated as follows: Predicted and actual values were obtained at three time points (30 minutes, 60 minutes, and 90 minutes); for each time point, the squared error between the predicted and actual values for the five parameters was calculated; the squared errors at each time point were weighted and summed, with weights set to 0.5 for the 30-minute time point, 0.3 for the 60-minute time point, and 0.2 for the 90-minute time point, reflecting the higher importance of recent predictions; the weighted squared errors at the three time points were then summed to obtain the total loss value.
[0044] The model is trained for 100 epochs, with each epoch iterating through all training samples using mini-batch gradient descent with a batch size of 64. During training, the prediction error on the validation set is monitored, and training is stopped early if the validation error fails to decrease for 10 consecutive epochs. After training, the model is retrained monthly based on the latest data, employing a transfer learning strategy to retain some weights from the LSTM layers as initialization to accelerate retraining.
[0045] Based on the attention layer of the trained LSTM model, dynamic weights are assigned to different historical moments to obtain the temporal attention distribution. The attention layer receives the output of the second layer of the LSTM, which is a sequence of hidden states for 24 time steps, with each hidden state being a 64-dimensional vector. The attention layer calculates the attention score for each time step to obtain the attention weights. The attention score calculation process is as follows: Obtain the LSTM hidden state vector and context vector for each time step. The context vector is obtained by mean pooling all hidden states; perform a linear transformation on the hidden state vector of each time step, multiplying the hidden state vector by a learnable weight matrix to obtain the transformed hidden state representation; perform a linear transformation on the context vector, multiplying the context vector by another learnable weight matrix to obtain the transformed context representation; add the transformed hidden state representation and the context representation, and perform a nonlinear transformation using the hyperbolic tangent activation function; multiply the nonlinear transformation result by the learnable weight vector to obtain the attention score for that time step.
[0046] Based on the calculated attention scores, the attention weight distribution is obtained using the softmax normalization method. The calculation process is as follows: The attention score at each time step is exponentially calculated; the sum of the exponential calculation results for all time steps is calculated; the exponential calculation result for each time step is divided by the sum to obtain the attention weight for that time step. It is ensured that the sum of the attention weights for all time steps is 1.
[0047] Based on the attention weight distribution, the hidden states of the LSTM are weighted and summed to obtain an attention-weighted context representation. The calculation process is as follows: multiply the hidden state vector at each time step by the corresponding attention weight to obtain a weighted hidden state vector; sum all weighted hidden state vectors to obtain the final attention-weighted context vector. This vector serves as the input to the output layer to generate the final prediction value. The attention mechanism enables the model to automatically learn which historical moments are more important for future predictions; typically, recent data (the past 30 minutes) and periodic moments (the same moment 24 hours ago) receive higher weights.
[0048] Based on a trained LSTM model and water quality time-series data from the current monitoring point over the past two hours, the system predicts parameter values for multiple future time points, yielding the prediction results. Specifically, this involves: taking the raw time-series data of five key parameters (COD, ammonia nitrogen, total phosphorus, pH, and conductivity) from the current monitoring point over the past two hours (24 time steps, 120 minutes prior to the current time) and performing Min-Max normalization preprocessing using normalized parameters saved during training to ensure the input data has the same numerical range as the training data, organizing it into a 24×5 normalized input matrix; based on the input matrix, performing forward propagation calculations using the trained LSTM model to obtain a 15-dimensional prediction output vector, which contains normalized prediction values for the five parameters at three time points: 30 minutes, 60 minutes, and 90 minutes; and based on the normalized prediction values, using an inverse normalization method to recover the actual physical values of the parameters, obtaining the final prediction results.
[0049] The denormalization calculation steps are as follows: obtain the normalized predicted value, which is located in the interval between 0 and 1; obtain the historical 95th and 5th quantiles of the parameter, which define the normal range of parameter variation; calculate the difference between the 95th and 5th quantiles to obtain the magnitude of parameter variation; multiply the normalized predicted value by this magnitude of variation to obtain the scaled predicted value; add the 5th quantile to the scaled predicted value to obtain the denormalized actual physical value of the parameter, which restores the original parameter's dimensions and numerical range.
[0050] Based on a trained LSTM model, the Monte Carlo Dropout method is used to quantify prediction uncertainty and obtain prediction confidence intervals. Specifically, this involves: for the same input time-series data, keeping the Dropout layer active during the model inference phase (unlike the traditional approach of disabling Dropout during inference), performing multiple forward propagation calculations to obtain multiple sets of prediction results, repeating the prediction 20 times. Each time, due to Dropout randomly discarding different neurons, slightly different prediction values are generated. Based on the 20 prediction results, the mean and standard deviation of the prediction values are calculated to obtain a measure of prediction uncertainty. For each parameter at each future time point, the arithmetic mean of the 20 prediction values is calculated as the final prediction value, and the standard deviation is calculated as the prediction uncertainty. The larger the standard deviation, the more uncertain the model is about the prediction. Based on the prediction standard deviation, the prediction reliability level is determined to obtain a confidence assessment. The prediction standard deviation is compared with the standard deviation of historical prediction errors, and divided into three confidence levels: high, medium, and low. Low-confidence predictions indicate that the model has encountered data patterns rarely seen in the training set, and the reliability of the prediction results is low.
[0051] Based on predicted future parameter values and current anomaly diagnostic information, a comprehensive assessment of the risk of water quality anomalies in future periods is conducted to obtain a risk level. Specifically, this includes: comparing predicted future parameter values with dynamic thresholds to assess the risk of parameter exceedances and obtaining exceedance risk indicators; determining the dynamic threshold based on the seasonal quantiles of historical data, calculating the 95th quantile of the same period data over the past year for each parameter as the dynamic threshold; calculating the number of parameters exceeding the dynamic threshold among the five key parameters for each future time point; constructing feature vectors for future moments using the same multi-scale spatiotemporal feature extraction method based on predicted future parameter values to obtain future feature representations; constructing 100-dimensional feature vectors for the predicted parameter values at the next 30, 60, and 90 minutes; calculating future anomaly scores using the isolated forest anomaly detection model trained in step 3 based on future feature vectors to obtain future anomaly risk scores; inputting the feature vectors from the three future time points into the anomaly detection model to obtain corresponding anomaly scores; and comprehensively calculating the risk level based on the current anomaly score, future anomaly score, parameter exceedance risk, and prediction uncertainty to obtain a four-level risk assessment result.
[0052] The calculation steps for the comprehensive risk score are as follows: First, obtain the current anomaly score, reflecting the degree of water quality anomaly at the current moment. Second, obtain the highest anomaly score at a future time point, reflecting the maximum anomaly risk within the prediction period. Third, calculate the exceedance risk ratio, which is the proportion of parameters predicted to exceed the dynamic threshold to the total number of parameters. Fourth, obtain the prediction uncertainty weight, calculated based on the prediction standard deviation obtained using the Monte Carlo Dropout method. Fifth, set weight coefficients for the four risk factors: the current anomaly score is weighted at 0.3, the highest future anomaly score at 0.4, the exceedance risk ratio at 0.2, and the prediction uncertainty at 0.1. Finally, multiply each risk factor by its corresponding weight coefficient, sum the four weighted results, and obtain the comprehensive risk score between 0 and 1.
[0053] The steps for risk level classification are as follows: Three risk level classification thresholds are set: the first threshold is 0.3, the second threshold is 0.6, and the third threshold is 0.8. The comprehensive risk score is compared with these thresholds. If the comprehensive risk score is less than the first threshold (0.3), it is classified as a low-risk level, indicating normal water quality and requiring no special attention. If the comprehensive risk score is greater than or equal to the first threshold but less than the second threshold (between 0.3 and 0.6), it is classified as a medium-risk level, requiring enhanced monitoring. If the comprehensive risk score is greater than or equal to the second threshold but less than the third threshold (between 0.6 and 0.8), it is classified as a high-risk level, requiring emergency measures to be prepared. If the comprehensive risk score is greater than or equal to the third threshold (0.8), it is classified as an emergency risk level, requiring immediate activation of the emergency response.
[0054] Based on the calculation results of the above steps, complete prediction and risk assessment information is integrated to obtain the output results including parameter prediction values, prediction uncertainty, anomaly score, and comprehensive risk level for three time points in the next 30 minutes, 60 minutes, and 90 minutes.
[0055] Furthermore, a Transformer model can be used instead of LSTM for time series prediction. Based on water quality time series data from the past two hours, a Transformer encoder-decoder architecture is constructed for multi-step prediction, yielding prediction results based on a self-attention mechanism. The Transformer model captures the long-range dependencies between any two time steps in the time series data through a self-attention mechanism, unrestricted by the sequential processing of LSTM. The encoder receives the input sequence of 24 time steps and extracts time series features through a multi-head self-attention layer and a feedforward neural network layer; the decoder autoregressively generates prediction values for the next three time steps (30 minutes, 60 minutes, and 90 minutes). The purpose of this alternative embodiment is to leverage the parallel computing power and long-range dependency modeling advantages of the Transformer to improve prediction efficiency and the ability to capture complex time series patterns, especially achieving higher prediction accuracy when water quality exhibits multi-period nested changes.
[0056] Step 5: Based on the prediction and risk assessment information, perform flow velocity estimation and propagation prediction to obtain collaborative early warning information and model update results; Historical hydrological parameter statistics (statistical table of average flow velocity and flow rate under different seasons and water level conditions).
[0057] The current flow velocity estimation relies on the real-time water levels at upstream monitoring stations and the seasonal water level-flow velocity correlation constructed from statistics of the past three years. The current season is determined based on the date, and then, combined with the monitored water level intervals, the average flow velocity under these conditions is retrieved from the correlation table to form the basic flow velocity estimate. This table is grouped into four seasons and three water level intervals, totaling twelve entries. Each entry records the average flow velocity and its standard deviation, reflecting typical values under different hydrological conditions.
[0058] Considering the specific location of the current water level within the interval, a linear interpolation refinement of the base velocity is performed to improve the accuracy of the estimate. Specifically, this involves using the average velocity of the current interval as a base point, selecting adjacent intervals whose water level midpoint is closer to the current water level as references, and assigning weights according to the degree of deviation of the current water level from the interval midpoint: the closer the water level is to the interval midpoint, the smaller the weight; the closer it is to the interval boundary, the larger the weight. This ensures that the final estimated value transitions reasonably between the average values of the two intervals, thus obtaining a final velocity estimate that more closely reflects reality. This final velocity estimate is used for subsequent calculations of the pollution plume propagation time. For locations lacking hydrological monitoring data, to ensure conservatism, the annual average velocity of the river segment over the past five years is used as the default estimate.
[0059] Based on the final estimated flow velocity and the spatial location information of monitoring points, the time it takes for the pollution plume to propagate from the upstream anomaly point to each downstream point is calculated, resulting in a propagation time prediction. Specifically, when an upstream monitoring point (denoted as point A) is determined to be abnormal or high-risk / emergency-risk, the downstream propagation prediction process is triggered. Based on the spatial location information of the monitoring point, all downstream points of the anomaly point are identified, resulting in a set of downstream points. The topological relationship matrix of monitoring points is queried to find all downstream points reachable from point A along the water flow direction, forming a set of downstream points (containing several downstream points).
[0060] For each downstream point (denoted as point B), the theoretical propagation time of the pollution plume is calculated based on the river distance between the two points and the estimated flow velocity, yielding the theoretical arrival time. The specific process for calculating the propagation time is as follows: Calculate the river distance between the two points; convert the estimated flow velocity to the distance to obtain the time required to traverse that distance, thus obtaining the theoretical propagation time; Calculate the ratio of actual arrival time to theoretical time for historical propagation events in this river segment, and take the median as the propagation delay correction factor; Multiply the theoretical propagation time using the correction factor to obtain the predicted arrival time. The steps for calculating the correction factor are as follows: Collect actual arrival time data for historical propagation events in this river segment; Collect theoretical propagation time data for the corresponding events; Calculate the ratio of actual arrival time to theoretical propagation time for each event; Sort all ratios by size, and take the median as the propagation delay correction factor; Multiply the correction factor by the theoretical propagation time of the current event to obtain the corrected predicted arrival time.
[0061] Based on propagation time and anomaly severity information, a simplified dilution attenuation model is used to predict the impact of the pollution plume when it reaches the downstream area, thus obtaining an impact assessment. Specifically, based on the anomaly score and pollution type of the upstream anomaly point, the pollution source intensity is quantified to obtain the initial pollution intensity; the higher the anomaly score, the further the deviation from the normal state, and the greater the pollution intensity. The calculation steps for the initial pollution intensity are as follows: obtain the current anomaly score, which reflects the degree of water quality deviation from the normal state; determine the corresponding weighting coefficient according to the pollution type; multiply the current anomaly score by the corresponding pollution type weighting coefficient to obtain the initial pollution intensity, which reflects the relative severity of the pollution source.
[0062] Based on the initial pollution intensity, propagation distance, and estimated flow rate, the intensity attenuation caused by the dilution effect is calculated to obtain the diluted intensity. The larger the river flow rate, the stronger the dilution effect. The flow rate is estimated based on the combination of flow velocity and river cross-sectional area, where the river cross-sectional area is set according to the river class based on the system's typical value library. The calculation steps for the diluted pollution intensity are as follows: calculate the river flow rate by multiplying the estimated flow velocity by the river cross-sectional area; obtain the dilution constant from the system parameter library, which reflects the river's dilution capacity; calculate the ratio of propagation distance to river flow rate, which reflects the degree of dilution of pollutants during propagation; multiply the dilution constant by this ratio to obtain the dilution index; use the natural constant e as the base and the negative value of the dilution index as the exponent for power operation to obtain the dilution attenuation factor; multiply the initial pollution intensity by the dilution attenuation factor to obtain the diluted pollution intensity.
[0063] For non-conservative pollutants (such as organic matter and ammonia nitrogen), the degradation attenuation effect is further considered to obtain the final impact intensity. A first-order kinetic model is used for degradation attenuation. The calculation steps for degradation attenuation are as follows: determine whether the pollutant type is non-conservative; if it is organic matter or ammonia nitrogen, a degradable pollutant, the degradation effect needs to be considered; obtain the degradation rate constant of the corresponding pollutant from the system parameter library; obtain the expected arrival time and convert the time unit to days; multiply the degradation rate constant by the expected arrival time to obtain the degradation exponent; using the natural constant e as the base, perform a power operation on the negative value of the degradation exponent to obtain the degradation attenuation factor; multiply the diluted pollution intensity by the degradation attenuation factor to obtain the final impact intensity considering the degradation effect.
[0064] Based on the expected impact intensity, the impact severity levels are classified to obtain a qualitative impact assessment. The steps for classifying the impact severity levels are as follows: setting two impact severity thresholds; comparing the final impact intensity with these thresholds; and classifying the impact intensity into three levels—minor, moderate, and severe—based on the threshold comparison, each corresponding to different degrees of downstream water quality impact.
[0065] Based on the propagation time and impact level, collaborative early warning information is generated for downstream monitoring points, resulting in early warning notification content. Specifically, for each downstream monitoring point expected to be affected, structured collaborative early warning information is constructed. The early warning information includes the following fields: early warning source (name and number of upstream abnormal point), early warning time (current moment), estimated arrival time (current moment plus propagation time), early warning time window (remaining time from now until estimated arrival), estimated impact level (slight / moderate / severe), pollution type (from type identification results), and emergency recommendations (given based on the early warning time window and impact level, such as "It is recommended to complete the preparation for closing the intake gate within 30 minutes").
[0066] Based on the importance and impact of downstream monitoring points, the priority of early warning notifications is determined, resulting in a notification strategy. For highly sensitive points such as drinking water source intakes, where the expected impact is moderate or severe, high-priority early warnings are issued and notifications are sent immediately. For general monitoring points or those with minor impacts, medium-priority warnings are issued, with notifications delayed by a preset time to observe trends.
[0067] Based on the generated collaborative early warning information and push strategy, the early warning system pushes the information to downstream site managers, resulting in early warning notifications. Early warning information is simultaneously sent via SMS, mobile application push notifications, and other methods to ensure timely receipt.
[0068] Based on collaborative early warning information and anomaly detection records generated at downstream monitoring points, the accuracy of propagation prediction is verified, model performance is evaluated, and model parameters are updated. Specifically, when a downstream monitoring point (point B) actually detects an anomaly within a certain period after the collaborative early warning is issued, the actual arrival time of the anomaly is recorded. The actual arrival time is compared with the expected arrival time to calculate the prediction error. The actual arrival time of the anomaly identified at the downstream point is recorded and subtracted from the expected arrival time to obtain the time prediction error (positive value indicates later than expected, negative value indicates earlier than expected); recent propagation events in this river section are statistically analyzed, and the average of the actual arrival time and the expected arrival time are calculated respectively; when there is a systematic bias, the propagation delay correction factor is updated by multiplying the ratio of the two averages.
[0069] The steps for updating the correction factor are as follows: collect the actual arrival time data of all recent propagation events in the river segment; collect the corresponding estimated arrival time data; calculate the average of the actual arrival time and the average of the estimated arrival time; calculate the ratio of the two averages, which reflects the degree of systematic prediction bias; multiply the original correction factor by this ratio to obtain the updated correction factor; replace the original parameter with the updated correction factor for subsequent propagation time prediction, realizing online learning and continuous optimization of the model. Based on the statistics of multiple prediction errors, update the propagation delay correction factor to obtain the optimized correction factor. Calculate the prediction error of all recent propagation events in the river segment; if the systematic error is significant, adjust the correction factor.
[0070] The steps for determining systematic bias are as follows: Calculate the average prediction error of all propagation events, where the prediction error equals the actual arrival time minus the estimated arrival time; calculate the absolute value of the average prediction error to eliminate the canceling effect of positive and negative errors; set an error threshold of 30 minutes; compare the absolute value of the average prediction error with the error threshold. If the absolute value is greater than the threshold, a systematic bias is identified, and the correction factor needs to be adjusted. Based on the updated correction factor, the original parameters are replaced for subsequent predictions, enabling online learning and continuous optimization of the model.
[0071] Based on the collaborative early warning information and model update results, the output includes collaborative early warning notifications for each downstream monitoring point (including estimated arrival time, impact level, and early warning time window) and updated propagation model parameters.
[0072] Furthermore, a physics-based hydrodynamic-water quality coupling model can be used to replace empirical statistical models for anomaly propagation prediction. Based on the river's geometric parameters, hydrological parameters, and pollutant characteristics, a one-dimensional hydrodynamic equation and convection-diffusion equation are constructed. Numerical solutions yield the spatiotemporal distribution of pollutant concentrations, predicting the propagation path and arrival time of the pollution plume. This method leverages the mechanistic and accurate nature of physical models to improve the accuracy of propagation prediction, especially in situations with complex and changing river hydrological conditions or the presence of tributaries. Physical models can more accurately simulate the migration and transformation processes of pollutants. However, the computational complexity is high, making it suitable only for scenarios requiring extremely high prediction accuracy.
[0073] Step 6: Based on risk assessment information and collaborative early warning information, calculate dynamic thresholds and Bayesian decision-making to obtain hierarchical early warning results and early warning implementation plans; Based on historical normal water quality data from the past year, a seasonal decomposition method was used to extract the periodicity and trend characteristics of water quality parameters, resulting in a seasonal baseline model. Specifically, historical normal data from the past year was extracted as the training dataset; water quality monitoring data from the past year were extracted from the historical database, and periods of confirmed pollution events were removed, retaining the periods of normal operation to form a normal baseline dataset; and the daily average time series of each key water quality parameter (COD, ammonia nitrogen, total phosphorus, pH, and conductivity) was extracted.
[0074] Before seasonal decomposition, different water quality parameters were standardized to eliminate dimensional differences. The same Z-score standardization method as in the data preprocessing stage was used. Considering the differences in the range and distribution characteristics of COD, ammonia nitrogen, total phosphorus, pH, and conductivity, the Z-score method was used to calculate the mean and standard deviation of the past days. Each daily mean was processed by "subtracting the mean and dividing by the standard deviation" to obtain a standardized sequence with a mean of approximately 0.5% and a standard deviation of approximately 0.5%, which facilitates subsequent unified decomposition.
[0075] Based on the components obtained from the decomposition, a seasonal baseline model is established and a baseline prediction function is obtained. The STL method is used to decompose the time series into a trend term, a seasonal term, and a residual term, where the trend term reflects the long-term trend of parameter changes, the seasonal term reflects periodic fluctuations, and the residual term reflects random fluctuations. The STL decomposition uses Locally Estimated Scatterplot Smoothing (LOESS) to iteratively extract the trend and seasonal components. The seasonal period is set as short period and long period. The short period and long period seasonal terms are extracted separately through two-layer LOESS smoothing. After removing the seasonal term from the original series, the trend term is extracted, and finally the residual term is calculated.
[0076] For the baseline forecast of the current date: the trend term is linearly extrapolated over time to obtain the trend value of the current date; the seasonal term is found and summarized according to the position of the current date in the cycle (e.g., using the average of the seasonal term for the same day of the week in history); the trend term and the seasonal term are combined to obtain the baseline forecast value of the current date.
[0077] Based on the statistical characteristics of the residuals, the normal fluctuation range is calculated, and the dynamic confidence interval is obtained. The calculation steps for the dynamic confidence interval are as follows: calculate the standard deviation of the residuals, which reflects the random fluctuations after removing trends and seasonality; set the confidence coefficient to 2, corresponding to approximately 95% confidence level; calculate the lower bound of the confidence interval by subtracting the confidence coefficient from the baseline predicted value and multiplying it by the standard deviation of the residuals; calculate the upper bound of the confidence interval by adding the confidence coefficient to the baseline predicted value and multiplying it by the standard deviation of the residuals; the dynamic confidence interval is obtained, which represents the reasonable fluctuation range of the parameter value under normal conditions.
[0078] Based on a seasonal baseline model and the current rate of change of water quality parameters, an adaptive anomaly detection threshold is calculated to obtain a dynamic threshold. Specifically, the upper bound of the normal range at the current moment is obtained based on the seasonal baseline model to obtain a basic dynamic threshold. This basic dynamic threshold, compared to a fixed threshold, can adapt to seasonal changes and avoid false alarms during periods of large natural parameter fluctuations. Based on the rate of change of the current parameter value and historical values, a rate of change correction factor is calculated to obtain a rate-sensitive threshold. To eliminate the influence of differences in the dimensions of different water quality parameters on the calculation of the rate of change, the current parameter value and the parameter value from 30 minutes ago are standardized.
[0079] Based on the standardized parameter values, the standardized rate of change is calculated: the standardized current value is subtracted from the standardized historical value and divided by the set time interval (in minutes) to obtain the standardized rate of change; this rate eliminates the dimensional differences of different parameters, making the rates of change of parameters such as COD, ammonia nitrogen, total phosphorus, pH value, and conductivity comparable.
[0080] Based on the calculated rate of change, it is compared with the historical distribution of normal rates of change to determine whether it is an abnormal rate. All minute-level rates of change are statistically analyzed from historical normal data, and quantiles are calculated as the upper limit of the normal rate of change. If the standardized rate of change exceeds this upper limit, it indicates that the current parameter is changing abnormally fast, and even if the parameter value has not yet exceeded the baseline threshold, caution should be exercised.
[0081] Based on the abnormal change rate, the abnormal threshold is dynamically adjusted to obtain the final dynamic threshold: Threshold dynamic adjustment: The upper limit of the normal change rate is statistically analyzed from historical normal data to determine the quantile of the minute change rate; starting from the basic dynamic threshold, when the standardized change rate is higher than the upper limit of the normal change rate, the threshold is adjusted downward by multiplying the excess by the adjustment coefficient (taken from the system parameter library, default) to obtain the final dynamic threshold; when the change rate is abnormal, the threshold is lowered to make the system more sensitive and provide early warning.
[0082] Based on anomaly scores, risk levels, and dynamic thresholds, Bayesian decision theory is used to determine whether to trigger an early warning, resulting in an early warning triggering decision. Specifically, a cost function for early warning decisions is defined, quantifying the costs of false alarms and missed alarms to obtain a cost model. The costs of false alarms (including unnecessary emergency response costs, manpower costs, and decreased trust due to early warning fatigue) and missed alarms (including water supply interruption losses, health risks, and social impacts caused by water pollution incidents) are set. For drinking water source protection scenarios, the cost of missed alarms is much greater than the cost of false alarms; therefore, the cost of missed alarms is set to 10 times the cost of false alarms, reflecting the principle of "better to have a false alarm than a missed alarm." Based on current anomaly scores and historical data statistics, the probability that the current sample is an anomaly is estimated, resulting in an anomaly probability estimate. To ensure the comparability of anomaly scores, the current anomaly scores are normalized, and a range scaling method is used to map the anomaly scores to an interval, using the score normalization interval as the mapping basis. The normalized anomaly scores are compared with the score distribution, and the posterior anomaly probability is calculated according to the Bayesian update rule: the corresponding likelihoods are estimated using the score distributions of "abnormal" and "normal" samples; the prior proportion is used as the prior; and the posterior probability of anomaly is calculated using the Bayesian update rule, with "abnormal likelihood × abnormal prior" as the numerator and the sum of "normal likelihood × normal prior" as the denominator. Based on the anomaly probability and the cost function, the expected benefit of issuing an early warning is calculated, providing the basis for decision-making.
[0083] The expected benefit of issuing an alert is the benefit of avoiding missed reports minus the loss of false alarms. The expected benefit of an alert is calculated as "abnormal posterior probability × missed report cost" minus "normal posterior probability × false alarm cost." An alert is triggered when the expected benefit is positive; otherwise, it is not triggered. Based on the expected benefit, a decision rule is used to determine whether to trigger an alert, resulting in an alert triggering decision. When the expected benefit is positive, it indicates that the expected benefit of issuing an alert is positive, and an alert should be triggered; otherwise, an alert is not triggered. This decision rule determines the optimal alert strategy under the constraint of minimizing the total alert cost.
[0084] Based on the initial early warning trigger decision, a time window continuous monitoring method is used to filter instantaneous fluctuations and obtain a stable early warning decision. Specifically, when it is initially determined that an early warning should be triggered, a formal early warning is not issued immediately; instead, an early warning preparation state is entered, and a continuous monitoring process is initiated. The moment of the first early warning trigger is recorded, with a monitoring time window length set at 15 minutes. Samples are taken every 5 minutes, for a total of 3 additional samples. Within the monitoring time window, an anomaly score is obtained every 5 minutes, and the early warning decision is repeated based on this score to obtain a time-series judgment result. At the initial trigger moment and at four subsequent time points (5 minutes, 10 minutes, and 15 minutes), anomaly scores are calculated, and early warning trigger decision judgments are executed. Based on the time-series judgment results, a multi-condition rule is used to determine whether to formally issue an early warning, resulting in the final early warning decision.
[0085] A formal warning will be issued when any of the following conditions are met: If the warning trigger decision is "warning should be triggered" at at least 3 out of 4 time points, it indicates that the anomaly persists and is confirmed as a genuine anomaly; If the anomaly score shows an upward trend, that is, if a linear fit is performed on the anomaly scores at the 4 time points and the slope of the fitted line is positive and the significance test p-value is less than 0.1, it indicates that the water quality anomaly is deteriorating and an immediate warning should be issued; If the prediction results show that the predicted value of a certain key parameter exceeds the dynamic threshold within the next 30 minutes, it indicates that the anomaly is about to reach the exceedance level and an early warning should be issued; If none of the above three conditions are met at the end of the monitoring time window, it is determined to be an instantaneous fluctuation or a data quality problem, and the warning is cancelled to avoid false alarms.
[0086] Based on the comprehensive risk level and stable early warning decision, the early warning level is determined, resulting in a tiered early warning system. Specifically, based on the comprehensive risk level and early warning decision, a four-level early warning system is mapped to obtain the early warning level. The correspondence between the early warning level and the risk level is as follows: low-level early warning corresponds to low risk (reminding attention and notifying monitoring point administrators), medium-level early warning corresponds to medium risk (strengthening monitoring and notifying monitoring point administrators and regional environmental protection departments), high-level early warning corresponds to high risk (preparing for emergency response and notifying monitoring point administrators, regional environmental protection departments, and the emergency command center), and emergency early warning corresponds to emergency risk (activating emergency response and notifying all relevant departments and activating the emergency plan).
[0087] Based on the warning level, the scope of the warning notification and response requirements are determined, resulting in a warning execution plan. Different warning levels correspond to different notification recipients, notification methods, and response time limits. Low- and medium-level warnings use mobile application push notifications and emails, with a response time limit of 1 hour for confirmation; high- and emergency warnings use multiple channels including SMS, voice calls, and mobile applications, with a response time limit of 30 minutes for confirmation and initiation of the emergency response process.
[0088] Based on the tiered early warning results and early warning execution plan, the output includes the final early warning decision result, which includes whether to issue an early warning, the early warning level (low / medium / high / urgent), the triggering reason (abnormal score exceeding the threshold / abnormal rate of change / prediction exceeding the standard / high overall risk), the notification recipients, and the notification method.
[0089] Furthermore, reinforcement learning methods can be used to dynamically optimize the early warning decision-making strategy. The early warning decision-making process is modeled as a Markov decision process. The state space includes information such as current water quality characteristics, anomaly scores, and historical early warning effects. The action space includes decision options such as whether to issue an early warning and the warning level. The reward function comprehensively considers early warning accuracy (positive reward for correct early warnings), timeliness (higher reward for longer advance warning times), and cost (negative reward for false alarms). A deep Q-network or policy gradient algorithm is used to train the intelligent decision-making agent, continuously optimizing the early warning strategy through interaction with the environment. This alternative embodiment aims to leverage the adaptability and optimization capabilities of reinforcement learning to automatically learn the optimal early warning decision-making strategy over long-term operation, adapting to different scenarios and user preferences. However, it requires a long training time and a large amount of interactive data.
[0090] Step 7: Based on the hierarchical early warning results, perform anomaly attribution analysis and generate structured early warnings to obtain structured early warning information and push results; Based on the isolated forest anomaly detection model and the feature vector of the current anomaly sample, the TreeSHAP algorithm is used to quantify the contribution of each feature to the anomaly judgment and obtain the feature contribution ranking. Specifically, when it is determined to issue an alert, the 100-dimensional feature vector of the current sample is extracted as the input for SHAP analysis; based on the isolated forest model (containing 100 decision trees), the TreeSHAP algorithm is used to calculate the Shapley value of each input feature for the anomaly score.
[0091] The TreeSHAP algorithm works by calculating the marginal contribution of each feature to the model's prediction before and after its inclusion in all possible feature subsets, and then averaging the marginal contributions of all feature subsets. For decision tree ensemble models, TreeSHAP efficiently calculates Shapley values using the tree structure. For a single tree, the contribution of each feature segmentation to the final anomaly score is calculated on each path from the root node to the leaf node; the contributions of all trees are averaged to obtain the SHAP value for each feature. The algorithm then performs contribution ranking and filtering: the input is the contribution values (SHAP) of 100 features; the processing involves taking the absolute value of each contribution and sorting them from largest to smallest, where a positive contribution promotes anomaly detection, a negative contribution inhibits it, and a larger absolute value indicates a greater impact; the output is the set of the top 10 ranked features as key contributing features.
[0092] Based on key contribution features, the original water quality parameters are mapped back to identify the key parameters causing anomalies, resulting in a list of key anomaly parameters. Since the 100-dimensional feature vector consists of multi-scale spatiotemporal features extracted from 20 water quality parameters in step 2, the feature indices need to be mapped back to the corresponding original parameters. For example, if the SHAP value of the 5th dimension feature (corresponding to the short-term window mean feature of the COD parameter) ranks first, then COD is identified as a key anomaly parameter. The original parameters corresponding to all key contribution features are statistically analyzed, and their SHAP values are summed to obtain the total contribution of each original parameter. The top 3 parameters with the highest total contribution are selected as the main anomaly parameters.
[0093] Based on key anomaly parameters and current water quality data, collaborative anomaly patterns among multiple parameters are analyzed to obtain parameter correlation anomaly characteristics. Specifically, the values of key anomaly parameters at the current time are extracted, and the current correlation coefficients between parameters are calculated to obtain the current correlation matrix. Assuming the top three identified key anomaly parameters are COD, ammonia nitrogen, and total phosphorus, time-series data of these three parameters over the past two hours are extracted. Before calculating the correlation coefficients, different water quality parameters are standardized to eliminate the influence of dimensional differences.
[0094] Based on the standardized parameter data, a 3×3 current correlation matrix is constructed using the same Pearson correlation coefficient calculation method as used in fault diagnosis. Based on historical normal data, the correlation coefficients of the same parameter pairs under normal conditions are calculated to obtain the baseline correlation matrix. Data for these three parameters during the past three months of normal operation are extracted from the historical normal database, and the correlation coefficient matrix under normal conditions is calculated.
[0095] Based on the current correlation matrix and the baseline correlation matrix, the correlation change is calculated and collaborative anomaly patterns are identified to obtain a description of the anomalous correlation pattern. Specifically, this involves subtracting the two types of correlation matrices (current and baseline) element by element to form a correlation change matrix, where each element represents the magnitude of change in the correlation between two parameters; the output is the correlation change matrix and a list of its changed elements. If the absolute change of an element exceeds a set threshold, it is determined that the relationship between the corresponding parameter pair has changed, reflecting a collaborative anomaly pattern.
[0096] Based on the identified collaborative anomaly patterns, descriptive text descriptions are generated to obtain collaborative pattern descriptions. For example, if the correlation coefficient between COD and ammonia nitrogen is detected to increase from the normal state of 0.5 to the current 0.9, the description generated is: "COD and ammonia nitrogen show a strong positive correlation and collaborative increase pattern, and the correlation strength is stronger than the normal state, which is consistent with the characteristics of organic pollutants and nitrogen being emitted from the same source."
[0097] Based on pollution type, key anomaly parameters, and collaborative patterns, similar cases are retrieved from a historical pollution event knowledge base to obtain reference cases and disposal suggestions. Specifically, a feature vector for the current event is constructed for similarity matching to obtain a query vector. The feature vector includes the following elements: pollution type, set of key anomaly parameters, degree of parameter anomaly, collaborative pattern characteristics, and time period of occurrence. Before concatenating the feature vector, different types of features undergo standardization preprocessing to ensure a balanced contribution of each feature dimension. The preprocessed features are then concatenated to form a standardized feature vector, ensuring comparability of different feature dimensions in similarity calculations.
[0098] Based on the query vector and historical case feature vectors, cosine similarity is used for matching to retrieve the most similar cases, resulting in a candidate case set. Each case in the historical pollution event knowledge base has a pre-extracted feature vector in the same format. The specific steps are: calculating the dot product of the current event feature vector and the historical case feature vector; calculating the Euclidean modulus of the two vectors; dividing the dot product by the product of the two modulus lengths to obtain the similarity; setting the similarity to 0 when any vector is all zero to avoid division by zero; outputting the similarity score (range 0 to 1) for each historical case, and selecting the top 5 historical cases with the highest similarity as candidate cases.
[0099] Based on the records of disposal measures and effects of candidate cases, effective disposal suggestions are extracted to obtain an emergency response plan. For the case with the highest similarity, the recorded pollution source information (e.g., "abnormal discharge from the No. 2 chemical plant's discharge outlet, with pollutants being high-concentration organic wastewater"), the disposal measures taken (e.g., "closing the downstream water intake gate, activating the activated carbon dosing system, notifying No. 2 plant to immediately stop discharge, and activating the emergency water supply plan"), and the disposal effects (e.g., "the pollution plume did not affect the water quality at the water intake, and the emergency response was timely and effective") are extracted. Based on this information, disposal suggestions for the current event are generated: "It is recommended to immediately investigate the discharge outlets of chemical plants in the industrial park, focusing on checking the operational status of organic wastewater treatment facilities; it is recommended to close the water intake gate 30 minutes before the pollution plume arrives; it is recommended to activate the activated carbon dosing system to enhance water purification capacity; and it is recommended to activate the backup water source emergency water supply plan."
[0100] For cases where no highly similar cases were found (all cases had a similarity score below 0.5), a general disposal procedure suggestion was provided based on the pollution type, resulting in a general disposal guideline. Based on the pollution type identified in step 3, a pre-defined general emergency disposal procedure library was queried. For example, for "industrial pollution - organic type," the general procedure is: "Immediately initiate the pollution source investigation procedure, notify the environmental protection department for on-site investigation, increase the frequency of downstream monitoring, prepare water quality emergency treatment facilities, and activate the water supply emergency plan if necessary."
[0101] Based on the analysis results, the system generates structured early warning messages according to predefined templates. The content unfolds logically and completely: It provides basic early warning information, including a unique early warning number formed by combining a timestamp and monitoring point number, the early warning level (low / medium / high / emergency), the current system time, and the name and number of the early warning point; it provides an anomaly description, clearly defining the anomaly type (e.g., industrial pollution - heavy metal / organic, agricultural non-point source pollution, domestic sewage pollution, or unknown type), listing the top three key anomaly parameters and their current values, and presenting examples of deviations from the baseline (e.g., "Current COD value 85 mg / L (normal baseline 60 mg / L, exceeding by 42%)"), while also providing an anomaly score in the 0-1 range and a textual description of the collaborative anomaly pattern; in the trend prediction section, it centrally displays the key parameters for the next 30 days. The system provides forecasts for 60-minute, 90-minute, and 60-minute intervals, and uses changes in predicted abnormal scores to determine the risk level trend (rising, stable, or falling). In the impact analysis section, it lists the expected impact range and potentially affected downstream locations, providing the estimated arrival time of the pollution plume for each location and indicating the warning time window from the current time to arrival. In the attribution analysis section, it lists the main contributing parameters in order of contribution, indicating the percentage contribution of each parameter, and makes reasonable inferences about potential pollution sources based on parameter characteristics and historical cases. In the response recommendations section, it briefly describes similar historical cases, lists a list of specific emergency measures recommended for the current situation, and clarifies the recommended response time based on the warning level and impact analysis. In the confidence level description section, it summarizes and displays the data confidence level, classification confidence level, and prediction uncertainty level (high / medium / low).
[0102] After completing the above structured content, the system converts the early warning message into easy-to-read text and charts, highlights key information through layered layout, and assists users in quickly understanding the key points of the early warning with visualizations such as key parameter time series trend charts, future prediction curves, and multi-parameter radar comparison charts.
[0103] Based on the warning level and warning information, warnings are pushed out using multi-channel communication methods, resulting in a warning notification delivery list. Specifically, firstly, a list of notification recipients is determined according to the warning level, resulting in a list of recipients. The warning notification configuration database is queried to determine the roles and contact information of the personnel who should receive the warnings, based on the warning level and warning location. This includes administrators of low- and medium-level warning notification monitoring points; administrators of high-level warning notification monitoring points and heads of regional environmental protection departments; administrators of emergency warning notification monitoring points, heads of regional environmental protection departments, emergency command center duty personnel, water supply company dispatch center, and all other relevant personnel.
[0104] Based on the contact information and preferences of the recipients, appropriate communication channels are selected to obtain the push notification plan. Low-level and medium-level alerts use mobile application push (sent to the alert system APP) and email; high-level and emergency alerts use four channels in parallel: SMS (sent to mobile phone numbers), voice calls (automatically dialing to broadcast the alert content), mobile application push, and email, to ensure information delivery.
[0105] Based on the push notification scheme, the communication interface is called to send alert information and obtain the sending status. This includes sending SMS messages via an SMS gateway, sending emails via a mail server, initiating automated voice calls via a voice gateway, and sending app notifications via push notification services. Each channel returns a sending status (success / failure) and a delivery status (delivered / not delivered / read).
[0106] Based on the sending status, the system monitors the receipt and confirmation of alerts, triggers an escalation mechanism, and obtains confirmation tracking results. For advanced and emergency alerts, recipients are required to confirm receipt and respond within a specified time limit (30 minutes). The system tracks the confirmation status; if no confirmation is received within the time limit, the system automatically escalates the notification, sending alert information and unconfirmed notification to higher-level management to ensure that no alert is missed.
[0107] Based on early warning and subsequent water quality monitoring data, the effectiveness of the early warning is tracked, user feedback is collected, and an early warning assessment report is obtained for model optimization.
[0108] Specifically, after an alert is issued, water quality data changes at that location are continuously monitored, and the actual development of any anomalies is recorded to obtain an event tracking record. Water quality data is tracked for 6 hours after the alert, recording the actual trends of key parameters, whether any exceedances occurred, and the duration of the anomaly. Simultaneously, the emergency response measures taken by the user and their timing are recorded.
[0109] Based on the comparison between early warning information and actual conditions, the accuracy of early warning is evaluated, and early warning effectiveness indicators are obtained. The following indicators are calculated: early warning accuracy (whether an abnormal event actually occurs after the early warning; if so, it is a true positive early warning; otherwise, it is a false positive, i.e., a false alarm), early warning lead time (the time difference between the time the early warning is issued and the time when the actual parameter exceeds the standard), prediction accuracy (the error between the future parameter value predicted in step 4 and the actual value), and accuracy of influence range prediction (the degree of consistency between the downstream influence range of the early warning and the actual influence range).
[0110] The early warning system interface collects user feedback on early warning information, generating user satisfaction data. Early warning recipients can evaluate the warnings based on factors such as timeliness, clarity, usefulness of suggested actions, and appropriateness of the warning level, using a 5-point rating system (1-5 points). They can also provide written feedback, explaining the advantages of the warning and offering suggestions for improvement.
[0111] Based on early warning effectiveness indicators and user feedback, an early warning evaluation report is generated and stored in a database to obtain a historical early warning archive. Each early warning record contains complete information such as early warning information, actual development status, effectiveness evaluation indicators, and user feedback, serving as the operational archive of the early warning system. All early warning records are periodically (e.g., monthly) analyzed to calculate system-level performance indicators (overall accuracy, false alarm rate, missed alarm rate, average lead time, etc.), generating a monthly early warning effectiveness analysis report.
[0112] Based on early warning assessment reports and user feedback, valuable information is fed back into the model training process to achieve continuous system optimization. For early warning samples confirmed as real pollution events, their feature vectors and type labels are added to the training set; for cases with large prediction errors, the reasons are analyzed and the weights of similar samples are increased during model retraining; for cases where user feedback provides useful handling suggestions, they are added to the historical pollution event knowledge base.
[0113] Based on the generated structured early warning information and push results, output the complete early warning notification content and sending status.
[0114] Furthermore, natural language generation technology can be used to automatically generate early warning report text. Based on the data of each field in the structured early warning information, a pre-trained language generation model (such as the GPT series models) can be used to automatically generate fluent natural language early warning reports, including paragraphs such as event description, cause analysis, trend prediction, and handling suggestions. The language generation model can adjust the language style and level of detail according to the early warning level and the target audience (such as a detailed report for technical professionals or a concise summary for management decision-makers). The purpose of this alternative embodiment is to improve the readability and user-friendliness of early warning information, enabling managers without technical backgrounds to quickly understand the early warning content. However, it is necessary to ensure the accuracy and professionalism of the generated text and avoid the language model producing misleading content.
[0115] A machine learning-based real-time water quality anomaly early warning system is used to execute the aforementioned machine learning-based real-time water quality anomaly early warning method, such as... Figure 2 As shown, it includes: The quality control and preprocessing module acquires high-quality raw water quality time-series data streams and, through preprocessing, obtains standardized water quality time-series datasets after quality control. The spatiotemporal feature extraction module extracts temporal features, spatial correlation features, and parameter interaction features based on the standardized water quality time series dataset after quality control. Through feature concatenation and PCA dimensionality reduction, a spatiotemporal feature vector is formed. The anomaly detection and type recognition module performs isolated forest detection and semi-supervised recognition on spatiotemporal feature vectors to obtain anomaly diagnosis information. The short-term water quality prediction and risk assessment module performs LSTM prediction and risk assessment based on anomaly diagnosis information to obtain prediction and risk assessment information; The abnormal propagation prediction module, based on prediction and risk assessment information, performs flow velocity estimation and propagation prediction to obtain collaborative early warning information and model update results; The dynamic early warning decision module calculates dynamic thresholds and Bayesian decisions based on risk assessment information and collaborative early warning information to obtain hierarchical early warning results and early warning execution plans. The anomaly attribution and early warning generation module performs anomaly attribution analysis and generates structured early warnings based on the hierarchical early warning results, resulting in structured early warning information and push notifications.
[0116] In one embodiment of the present invention, a specific example is provided: In practical application, the actual effect of the method of the present invention is demonstrated based on water quality monitoring data from 7 monitoring points in an industrial park during the period from 8:00 to 10:00 on October 15, 2024.
[0117] Table 1 shows the key water quality parameters of a certain monitoring point (the main discharge outlet of the industrial park) at certain times during this period: Table 1: Example of monitoring data;
[0118] Table 1 shows that from 8:00 to 9:45, COD continuously increased from 62.3 mg / L to 101.8 mg / L, ammonia nitrogen increased from 1.82 mg / L to 4.76 mg / L, and total phosphorus increased from 0.15 mg / L to 0.46 mg / L, with the three parameters showing a synergistic upward trend. Although no single parameter has exceeded the national standard (COD standard limit 100 mg / L, ammonia nitrogen standard limit 2.0 mg / L), a multi-parameter synergistic abnormal pattern has already emerged.
[0119] The synchronous monitoring data of the adjacent upstream and downstream points at the same location during the same period (at 9:00 AM) are shown in Table 2: Table 2: Example of spatial neighborhood monitoring data (at 9:00 AM);
[0120] Table 2 shows that the water quality parameters at the discharge outlet of upstream company No. 2 are higher than the current monitoring point, indicating that the anomaly may originate from this company; the parameters at downstream section 1 are lower than the current monitoring point, indicating that the pollution plume has not yet reached the downstream area. Spatial correlation information provides important clues for tracing the source of the anomaly.
[0121] The embodiments of the present invention have been described above. However, the embodiments are not limited to the specific implementation methods described above. The specific implementation methods described above are merely illustrative and not restrictive. Those skilled in the art can make more equivalent embodiments under the guidance of the present embodiments, and all of them are within the protection scope of the present embodiments.
Claims
1. A real-time early warning method for water quality anomalies based on machine learning, characterized in that, Includes the following steps: High-quality raw water quality time-series data streams are acquired, and through preprocessing, standardized water quality time-series datasets after quality control are obtained; Based on the standardized water quality time series dataset after quality control, temporal features, spatial correlation features, and parameter interaction features are extracted. Through feature concatenation and PCA dimensionality reduction, a spatiotemporal feature vector is formed. Anomaly diagnostic information is obtained by performing isolated forest detection and semi-supervised identification on spatiotemporal feature vectors. Based on abnormal diagnostic information, LSTM prediction and risk assessment are performed to obtain prediction and risk assessment information. Based on prediction and risk assessment information, flow velocity is estimated and propagation is predicted to obtain collaborative early warning information and model update results. Based on risk assessment information and collaborative early warning information, dynamic thresholds and Bayesian decision-making are calculated to obtain hierarchical early warning results and early warning implementation plans. Based on the tiered early warning results, anomaly attribution analysis and structured early warning generation are performed to obtain structured early warning information and push results.
2. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps for obtaining the standardized water quality time-series dataset after quality control include: Based on the physical constraints of sensor operating status parameters and water quality data, a rule fusion method is used to identify sensor faults, check whether water quality parameters meet physical constraints, calculate the correlation coefficient between monitoring points and spatiotemporal neighboring point data, and determine that the sensor has malfunctioned if the correlation coefficient is lower than the first threshold. An adaptive interpolation method is used to process missing data. For short-term missing data, cubic spline interpolation is used for temporal interpolation. For medium-term missing data, distance-weighted spatial interpolation is performed using spatial neighborhood monitoring point data. For long-term missing data, a matrix completion method is used for spatiotemporal joint interpolation. An adaptive normalization method is used to calculate the historical quantiles of parameters based on a sliding window, and the current data is normalized to a preset interval to obtain a standardized water quality time series dataset after quality control.
3. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps for forming the spatiotemporal feature vector include: Extract statistical features at different time scales, construct short-term, medium-term, and long-term windows, and calculate the mean, standard deviation, range, trend, and confidence features within each window; Based on the spatial topological relationship matrix, a neighborhood aggregation method is used to extract spatial correlation features and calculate the neighborhood mean and parameter difference features. The mutual information calculation method is used to identify the mutual influence relationship between parameters, and the parameters with the highest mutual information values are selected to calculate the product feature and ratio feature. The temporal features, spatial features, and parameter interaction features are concatenated and then dimensionality is reduced using PCA to form a spatiotemporal feature vector.
4. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps of isolated forest detection and semi-supervised identification include: An isolated forest model is constructed based on historical normal samples. By randomly selecting features and split points, isolated samples are recursively isolated. The sample separability is mapped to anomaly score based on the average path length. An adaptive threshold is obtained by using the preset quantile of the anomaly score as the base threshold and adjusting it according to the data confidence level. The adaptive threshold is then used to determine whether an anomaly exists. For samples identified as abnormal, a semi-supervised classification method is used. The nearest labeled samples are retrieved in the standardized feature space according to Euclidean distance for label propagation. The classification model is trained on the augmented labeled dataset to obtain abnormal diagnostic information.
5. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps of the LSTM prediction and risk assessment include: Design an LSTM network architecture. The input layer receives time-series data of water quality parameters. The LSTM layer contains two stacked units. The attention layer automatically learns the weights of different historical moments. The three parallel output layers predict the parameter values at three future time points respectively. The Monte Carlo Dropout method is used to quantify the prediction uncertainty. During the inference phase, the Dropout layer is kept active for forward propagation, and the statistical mean and standard deviation form the prediction confidence interval. The predicted future parameter values are compared with dynamic thresholds to assess the risk of exceeding the standard. Based on the future feature vector, the future anomaly score is calculated through an anomaly detection model. The risk level is then calculated comprehensively and divided into four risk levels.
6. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps for velocity estimation and propagation prediction include: The flow velocity is estimated based on the established seasonal water level-flow velocity correspondence. The average flow velocity is retrieved based on the current season and water level interval and then interpolated. The propagation time of the pollution plume is calculated based on the estimated flow velocity and spatial location information of the monitoring points. The theoretical propagation time is corrected by a propagation delay correction factor to obtain the expected arrival time. A dilution attenuation model is used to predict the impact of the pollution plume when it reaches the downstream area. The initial pollution intensity is quantified based on anomaly scores and pollution types, and the final impact intensity is calculated. The system generates collaborative early warning information for downstream monitoring points, including the source of the warning, the estimated arrival time, the warning time window, the estimated impact, the type of pollution, and emergency recommendations. The system also updates the propagation delay correction factor based on the prediction error statistics.
7. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps of the dynamic threshold and Bayesian decision-making include: Based on historical normal data, the seasonal decomposition method is used to extract the periodic and trend characteristics of water quality parameters, establish a seasonal baseline model, and calculate the dynamic confidence interval of the normal fluctuation range. Calculate the rate of change correction factor based on the current rate of change of parameters, and dynamically adjust the abnormal threshold when the standardized rate of change exceeds the upper limit of the normal rate of change. Bayesian decision theory is used to determine the early warning trigger, the cost functions of false alarm and false alarm are defined, the probability of anomaly is estimated based on anomaly score, and the expected benefit of issuing an early warning is calculated as the basis for decision-making. The time window continuous monitoring method is used to filter instantaneous fluctuations. Samples are taken and judged at set intervals within the preset monitoring window. When the conditions of continuous abnormality, rising score trend or predicted exceedance are met, a formal warning is issued. Based on the comprehensive risk level, a four-level early warning system is mapped to determine the scope of early warning notifications and response requirements.
8. The real-time early warning method for water quality anomalies based on machine learning according to claim 1, characterized in that, The steps for anomaly attribution analysis and structured early warning generation include: Based on the isolated forest model, the TreeSHAP algorithm is used to quantify the contribution of each feature to anomaly detection. The feature index is mapped back to the original water quality parameters to identify key anomaly parameters. The top 10 parameters with the highest total contribution are selected as the main anomaly parameters. Analyze the collaborative anomaly patterns among water quality parameters, calculate the change in the correlation between the current correlation coefficient of key anomaly parameters and the historical normal state baseline correlation matrix, and identify collaborative patterns of altered relationships. Cosine similarity is used to retrieve similar cases from a historical pollution incident knowledge base, and records of disposal measures and effects are extracted to generate emergency response suggestions; The system generates structured early warning messages based on predefined templates, including early warning information, anomaly description, trend prediction, impact analysis, attribution analysis, handling suggestions, and confidence level descriptions, and converts them into text and charts for display. The notification recipients and communication channels are determined according to the warning level, and the warning information is pushed out and the receipt and confirmation status is monitored.
9. The real-time early warning method for water quality anomalies based on machine learning according to claim 5, characterized in that, The implementation of the attention layer includes: The attention layer receives the hidden state sequence of 24 time steps output by the LSTM layer, calculates the attention score for each time step, performs linear transformations on the hidden state vector and the context vector respectively and adds them together, and then performs a nonlinear transformation through the hyperbolic tangent activation function to obtain the attention score. Based on the attention scores, the attention weight distribution is obtained using the softmax normalization method; The attention-weighted context representation is obtained by weighting and summing the hidden states of the LSTM, and the model automatically learns the importance weights of recent data and periodic moments; Monte Carlo Dropout uncertainty quantification calculates the mean and standard deviation of predicted values by keeping the Dropout layer active during the inference phase, and then compares the predicted standard deviation with the historical error standard deviation to divide it into three confidence levels.
10. A real-time early warning system for water quality anomalies based on machine learning, characterized in that, The method for implementing the real-time early warning method for water quality anomalies based on any one of claims 1-9 includes: The quality control and preprocessing module acquires high-quality raw water quality time-series data streams and, through preprocessing, obtains standardized water quality time-series datasets after quality control. The spatiotemporal feature extraction module extracts temporal features, spatial correlation features, and parameter interaction features based on the standardized water quality time series dataset after quality control. Through feature concatenation and PCA dimensionality reduction, a spatiotemporal feature vector is formed. The anomaly detection and type recognition module performs isolated forest detection and semi-supervised recognition on spatiotemporal feature vectors to obtain anomaly diagnosis information. The short-term water quality prediction and risk assessment module performs LSTM prediction and risk assessment based on anomaly diagnosis information to obtain prediction and risk assessment information; The abnormal propagation prediction module, based on prediction and risk assessment information, performs flow velocity estimation and propagation prediction to obtain collaborative early warning information and model update results; The dynamic early warning decision module calculates dynamic thresholds and Bayesian decisions based on risk assessment information and collaborative early warning information to obtain hierarchical early warning results and early warning execution plans. The anomaly attribution and early warning generation module performs anomaly attribution analysis and generates structured early warnings based on the hierarchical early warning results, resulting in structured early warning information and push notifications.
Citation Information
Cited By
Intelligent monitoring system and method for compaction pile shrinkage cavity
CN122024173A
An online water quality monitoring anomaly typing correction and credible data generation method and system
CN122174053A
A marine multi-parameter precision measuring instrument operation fault intelligent early warning method
CN122241651A
