Inlet water quality prediction method based on double-branch multi-head attention mechanism

The Trend Attention LSTM model, with its dual-branch multi-head attention mechanism, addresses the issues of low accuracy, slow response, and poor adaptability in influent water quality prediction, achieving high-precision, fast-response, and low-cost support for wastewater treatment processes.

CN121963941APending Publication Date: 2026-05-01AI WO TE ZHI NENG SHUI WU (AN HUI) YOU XIAN GONG SI
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
AI WO TE ZHI NENG SHUI WU (AN HUI) YOU XIAN GONG SI
Filing Date
2025-11-27
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing influent water quality prediction technologies suffer from low accuracy, slow response, and poor adaptability, especially when faced with multi-source data noise, long-term time-series characteristics, and complex operating conditions.

Method used

We employ a Trend Attention LSTM model based on a dual-branch multi-head attention mechanism, and construct an end-to-end deep learning architecture by combining multi-scale temporal feature fusion and periodic pattern encoding with multi-source data processing to achieve accurate prediction of influent water quality.

Benefits of technology

It significantly improves the accuracy and response speed of influent water quality prediction, reduces operation and maintenance costs, and enhances cross-scenario adaptability, enabling real-time monitoring and adjustment of wastewater treatment processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121963941A_ABST
    Figure CN121963941A_ABST
Patent Text Reader

Abstract

The invention discloses an inflow water quality prediction method based on a double-branch multi-head attention mechanism, and the method comprises the following steps: S1, collecting the operation parameters and water quality indexes of aeration equipment from a sewage plant database according to a time interval, and constructing a time sequence data set; s2, extracting periodic features, trend features and hysteresis features from the time sequence data set; s3, a Trend Attention LSTM model is constructed, the model comprises a numerical feature processing path and a trend feature processing path, and future multi-step water quality index predicted values and descending / invariant / ascending water quality change trend classification results are output; s4, training a Trend Attention LSTM (Long Short Term Memory) model by utilizing the data set, and storing a model file; and S5, collecting data in real time by using an edge calculation unit, obtaining multi-scale features after processing in the step S2, inputting the multi-scale features into the Trend Attention LSTM model loaded with the model file, and outputting future multi-step water quality prediction values and trend judgment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method for predicting the influent water quality of a wastewater treatment plant. Background Technology

[0002] Influent water quality prediction is a key preliminary step in the overall management of wastewater treatment. Its technological evolution can be roughly divided into three stages: experience-driven prediction, model-driven prediction, and data-driven prediction.

[0003] Experience-driven forecasting: Early influent water quality forecasting mainly relies on manual sampling and experience-based judgment. Operators periodically collect influent samples, obtain indicators such as COD, BOD, and ammonia nitrogen through laboratory testing, and predict water quality changes based on historical data patterns. This method is greatly affected by human operation, has a low sampling frequency, cannot capture instantaneous fluctuations in water quality, and has a long forecast cycle and poor timeliness, making it difficult to guide real-time process adjustments.

[0004] Model-driven prediction: With the development of water quality monitoring technology, mechanism-based prediction models are gradually being applied, such as water quality-quantity balance models and pollutant migration and transformation models. These methods predict water quality by establishing the physicochemical relationship between influent water quality indicators and factors such as hydrology and industrial emissions. However, due to the complexity of influent sources (mixture of domestic sewage and industrial wastewater) and the variability of discharge patterns, model parameters (such as pollutant degradation coefficients and flow distribution coefficients) are difficult to calibrate accurately, and the response to disturbances such as sudden industrial discharges and rainfall is insufficient, resulting in large prediction errors, especially low reliability in scenarios of sudden changes in water quality.

[0005] Data-driven forecasting: With the widespread adoption of IoT sensors and the development of big data technology, machine learning methods are widely used in influent water quality forecasting. Predictive models are built by collecting historical water quality, flow rate, and meteorological data from multiple sources to achieve dynamic early warning. However, most current solutions suffer from insufficient feature fusion, inadequate temporal pattern mining, and weak cross-scenario adaptability, particularly performing poorly in dealing with concentrated industrial wastewater discharge, seasonal water quality fluctuations, and collaborative forecasting across multiple plants.

[0006] Current industry technical bottlenecks: The core challenges in influent water quality prediction include incomplete noise processing of multi-source data, insufficient mining of long-term time-series characteristics (such as weekly industrial emission patterns and seasonal water quality fluctuations), and weak robustness of models under complex conditions (such as rainstorm impacts and sudden industrial sewage discharges). Summary of the Invention

[0007] The purpose of this invention is to provide an influent water quality prediction method based on a dual-branch multi-head attention mechanism to solve the problems of low accuracy, slow response, and poor adaptability in traditional influent water quality prediction.

[0008] Therefore, this invention provides an influent water quality prediction method based on a dual-branch multi-head attention mechanism, comprising the following steps: S1, collecting aeration equipment operating parameters and water quality indicators from a wastewater treatment plant database according to time intervals to construct a time series dataset; S2, extracting periodic features, trend features, and lag features from the time series dataset to form multi-scale features, wherein the trend features include rate of change and acceleration; S3, constructing a Trend Attention LSTM model, which includes a numerical feature processing branch and a trend feature processing branch. The numerical feature processing branch receives periodic features, lag features, and raw data, extracts time-series correlations through LSTM, mines feature correlations through multi-head attention, and outputs a numerical feature vector; the trend feature processing branch only receives trend features, extracts trend patterns through LSTM, locates abrupt change nodes through multi-head attention, and outputs a trend feature vector. The two vectors are fused and passed through a fully connected layer to output the predicted values ​​of water quality indicators for future multiple steps and the classification results of water quality change trends of decreasing / unchanged / increasing; S4, training the Trend Attention LSTM using the dataset. Model and save the model file; S5, use edge computing units to collect data in real time, and after processing in step S2, obtain multi-scale features, input them into the Trend Attention LSTM model that has loaded the model file, and output future multi-step water quality prediction values ​​and trend judgments.

[0009] Compared with existing technologies, the present invention has the following technical effects / advantages:

[0010] 1) Significantly improved prediction accuracy: By encoding periodic features through Fourier transform and calculating trend features through difference, combined with the Trend Attention LSTM model, the prediction error of influent water quality (such as COD and ammonia nitrogen) is reduced, effectively avoiding errors in wastewater treatment process adjustment caused by prediction deviation.

[0011] 2) Reduced model maintenance costs: The end-to-end deep learning architecture replaces the complex parameter calibration process of traditional mechanistic models. Combined with the validation set early stopping mechanism, the model is automatically optimized, reducing the manpower required for model maintenance and lowering operation and maintenance costs.

[0012] 3) Enhanced cross-scenario adaptability: Through multi-source data fusion (water quality, equipment operation, meteorological data) and periodic coding, the model exhibits less error increase when migrating between wastewater treatment plants of different scales and processes.

[0013] In addition to the objectives, features, and advantages described above, the present invention has other objectives, features, and advantages. The invention will now be described in further detail with reference to the figures. Attached Figure Description

[0014] The accompanying drawings, which form part of this application, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings:

[0015] Figure 1 This is a flowchart of the influent water quality prediction method based on a dual-branch multi-head attention mechanism of the present invention.

[0016] Figure 2 The entire process from data acquisition to model optimization is illustrated in the form of a block diagram;

[0017] Figure 3 This is a diagram of the Trend Attention LSTM model architecture used in this invention. Detailed Implementation

[0018] The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0019] This invention effectively solves the problems of existing influent water quality prediction schemes in terms of data processing refinement, temporal feature modeling, and cross-scenario adaptability by using multi-scale temporal feature fusion, periodic pattern encoding, and bi-branch attention network.

[0020] Figure 2 The entire process from data acquisition to model optimization is illustrated in a block diagram, clearly showing the data flow and processing logic at each stage. The data acquisition stage obtains raw data, which is then cleaned and fused before entering the feature engineering stage. Periodic, trend, and lag features are extracted through mathematical calculations. Model training then proceeds, using multi-task learning and optimization algorithms to adjust model parameters. After evaluation and meeting standards, the model is saved and deployed to edge nodes. During online prediction, real-time acquired data is processed and input into the model for inference. Prediction results are output and evaluated, and feedback optimization improves model performance, fully covering the core steps of the technical solution of this invention.

[0021] Combined with reference Figure 1 and Figure 2 The influent water quality prediction method of the present invention includes the following steps S1 to S5.

[0022] S1. Multi-source data fusion and preprocessing

[0023] Data on aeration equipment operating parameters and water quality indicators were collected from multiple tables in the wastewater treatment plant database, categorized by time interval, with a uniform time granularity of 30 minutes. For missing data, a forward imputation method was used; if data was missing at a certain moment, it was filled with the nearest non-missing data before that moment, thus constructing a complete time series dataset.

[0024]

[0025] in is a scalar representing the value of influent water quality data (such as influent COD) at time point t, m represents the total number of features, and X is the concatenated expression of all features. .

[0026] S2, Multi-scale Temporal Feature Engineering

[0027] Periodicity characteristic: For a given periodic set T = {T1, T2, ..., T...} P Construct Fourier features for each period (e.g., daily, weekly, monthly) T. p Let ∈T, and let its harmonic order be K. p Then the feature vector is generated:

[0028]

[0029] in:

[0030]

[0031]

[0032] Total periodic eigenvector:

[0033]

[0034] Trend characteristics: Differential calculations are performed on target water quality indicators to generate characteristics reflecting the trend of data changes. First-order differencing is used to calculate the rate of data change; the formula is as follows:

[0035]

[0036] The second-order difference is used to calculate the rate of change of data, i.e., acceleration. The calculation formula is:

[0037]

[0038] Constructing trend-based eigenvectors:

[0039]

[0040] here This represents the value of the i-th feature at time t. It predicts the quantity of the target water quality (influent COD, influent ammonia nitrogen, etc.).

[0041] Lagged Features: Historical data is introduced as lagged features to reflect historical dependencies in the data. The lagged terms for each feature are constructed as follows:

[0042]

[0043] Constructing the hysteresis eigenvector:

[0044]

[0045] here L represents the lag step size of the target column, and L is the number of lags.

[0046] By forming multi-scale time series features through periodicity, trend, and lag characteristics, we can achieve full-dimensional time series pattern mining of "short-term fluctuations - medium-term trends - long-term cycles".

[0047] S3, Trend Attention LSTM Model Construction

[0048] The Trend Attention LSTM model designed in this invention adopts a dual-branch parallel architecture, with its core consisting of an LSTM network and a multi-head attention mechanism. Figure 3 The diagram shows the Trend Attention LSTM model architecture, illustrating the dual-branch architecture and operational logic of the core model of this invention.

[0049] The model receives preprocessed multi-source data and processes it along two paths: numerical features and trend features. In the numerical feature branch, the data is sequentially processed through LSTM layers for temporal feature extraction, capturing long-term dependencies. Then, a multi-head attention mechanism is used to mine the correlations between data features from different representation subspaces, ultimately outputting a numerical feature vector. The trend feature branch adopts a similar structure, using LSTM and a multi-head attention mechanism to process trend features and output a trend feature vector.

[0050] The output vectors of the two branches are concatenated in the fusion layer, and after calculation by the fully connected layer, the predicted values ​​of water quality indicators for future multiple steps and the classification results of water quality change trends (decreasing, unchanged, increasing) are output. This model architecture significantly improves the ability to predict complex changes in influent water quality through parallel processing and feature fusion.

[0051] Specifically, taking numerical branches as an example to explore data flow, after... Figure 2 Numerical features are obtained after numerical feature processing and used as input. These numerical features include original features, periodic features, and lag features, which can be expressed mathematically as follows:

[0052]

[0053] Let the numerical feature dimension , The output after passing through the LSTM encoder is:

[0054]

[0055] here It is the length of the time window. It is the hidden layer dimension.

[0056] The final hidden state of the LSTM is used as input to the attention network to extract importance features and automatically model higher-order feature combinations:

[0057]

[0058] Here, k refers to the number of bullish heads. It is the dimension of each head, let Similarly, the output of the trend features after passing through the trend LSTM and the trend multi-head attention network is: ,here The dimension is also the product of the time window dimension, the number of multi-head attention heads, and the dimension of the head.

[0059] The dual-branch fusion output is obtained by concatenating the output of the numerical feature branch (processed by LSTM and multi-head attention) with the output of the trend feature branch through a feature fusion layer.

[0060]

[0061] Then, by using an activation function and a fully connected layer, the predicted values ​​and trend classification results (decreasing, unchanged, increasing) of future water quality indicators are output:

[0062]

[0063]

[0064] here , These are the weight parameters of the fully connected layer. , These are the bias parameters of the fully connected layer. It is the regression predicted value of the i-th sample. It is the trend prediction value of the i-th sample.

[0065] S4. Model Training and Optimization

[0066] A multi-task learning strategy is employed, weighting the mean squared error (MSE) of numerical prediction and the cross-entropy loss (CE) of trend classification by a weight coefficient α to fuse them into a total loss function. The formula for calculating the mean squared error is:

[0067]

[0068] The formula for calculating cross-entropy loss is:

[0069] The total loss function is:

[0070] Where n is the number of samples. For the true value, Here, C represents the predicted value, and C represents the number of categories. For the true category labels (0, 1, 2). This represents the predicted class probabilities. The model is trained using the Adam optimizer, with an early stopping mechanism that combines training epochs with validation set loss to avoid overfitting and save the optimal model parameters.

[0071] S5, Online Prediction and Feedback Optimization

[0072] Edge computing units collect data in real time, extract multi-scale time-series features after preprocessing, input them into the deployed model for inference, and output future multi-step water quality predictions and trend judgments.

[0073] The model employs a multi-step rolling prediction matrix, which shortens the system's response time to sudden changes in water quality and significantly improves early warning efficiency compared to the traditional threshold method. The implementation method is as follows:

[0074] 1) Prediction settings: Based on the process response requirements of the wastewater treatment plant, predict the next 12 hours in 24 steps (30 minutes each) - the first 4 steps (0.5-2 hours) focus on the precise values ​​of water quality indicators, and the last 20 steps (2.5-12 hours) take into account both the values ​​and the trend of change (decreasing / unchanged / increasing).

[0075] 2) Rolling update: New data is collected every 30 minutes, the multi-scale window is updated (the earliest step data is discarded and the current data is added), the feature matrix is ​​regenerated and input into the model, and the prediction results for the next 24 steps are updated.

[0076] The prediction performance is evaluated by calculating metrics such as mean absolute error (MAE), root mean square error (RMSE), and coefficient of determination (R²). If the error exceeds a threshold or the model performance deteriorates, new data is fed back into the training phase to re-optimize the model, thus achieving closed-loop iteration.

[0077] Compared with traditional influent water quality prediction methods and existing machine learning schemes, this invention achieves significant breakthroughs in the following aspects, as shown in Table 1 below:

[0078] Table 1. Comparison of the Multi-Dimensional Technical Effects of the Invention and Comparative Objects

[0079]

[0080] Prediction accuracy: By combining multi-scale feature engineering with deep neural networks, the system accurately captures the patterns of water quality changes, reduces MAE and improves R², effectively supporting the precise control of wastewater treatment processes.

[0081] Real-time responsiveness: Enables minute-level data processing and prediction to meet the real-time monitoring needs of dynamic changes in influent water quality;

[0082] Ease of operation and maintenance: The automatic model optimization and update mechanism reduces manual intervention, significantly shortens the model retraining cycle, and reduces the complexity of operation and maintenance;

[0083] Scenario versatility: By introducing features such as holiday markers and weekly coding, the model's prediction accuracy is improved under special conditions such as rainy seasons and holidays, and it has strong generalization ability.

[0084] This method effectively solves the problems of low accuracy, slow response, and poor adaptability in traditional influent water quality prediction, providing efficient and reliable technical support for the intelligent operation of wastewater treatment plants. It can be widely applied to wastewater treatment scenarios of different scales and processes.

[0085] The above description is merely an embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, substitutions, or improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for predicting influent water quality based on a two-branch multi-head attention mechanism, characterized in that, Includes the following steps: S1. Collect aeration equipment operating parameters and water quality indicators from the wastewater treatment plant database according to time intervals to construct a time series dataset; S2. Extract periodic features, trend features, and lag features from the time series dataset to form multi-scale features, where trend features include rate of change and acceleration. S3. Construct a Trend Attention LSTM model, which includes a numerical feature processing branch and a trend feature processing branch. The numerical feature processing branch receives periodic features, lagged features, and raw data, extracts temporal correlations through LSTM, mines feature correlations through multi-head attention, and outputs a numerical feature vector. The trend feature processing branch only receives trend features, extracts trend patterns through LSTM, locates abrupt change nodes through multi-head attention, and outputs a trend feature vector. The two vectors are fused and passed through a fully connected layer to output the predicted values ​​of water quality indicators for future multiple steps and the trend classification results of decreasing / unchanged / increasing. S4. Train the Trend Attention LSTM model using the dataset and save the model file; S5. Data is collected in real time using edge computing units. After processing in step S2, multi-scale features are obtained and input into the Trend Attention LSTM model with the model file loaded. The model outputs the predicted water quality values ​​and trend judgments for the next multiple steps.

2. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, When running the model, the model performance evaluation index is calculated. If the index exceeds the threshold or the model performance deteriorates, new data is fed back to the training phase to re-optimize the model and achieve closed-loop iteration.

3. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, The model performance evaluation metrics include mean absolute error, root mean square error, and coefficient of determination.

4. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, In the training model, the mean squared error of numerical prediction and the cross-entropy loss of trend classification are weighted and fused into a total loss function.

5. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, The data collection time granularity is 30 minutes. For missing data, the forward imputation method is used to fill in the missing data.

6. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, The methods for extracting periodic features are as follows: For a given periodic set T = {T1, T2, ..., T...} P Construct Fourier features for each period T. p Let ∈T, and let its harmonic order be K. p Then the feature vector is generated: , in: , , Among them, the total periodic eigenvector is: 。 7. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, Methods for extracting trend features include: Differential calculations are performed on the target water quality indicators to generate features reflecting the trend of data changes. The first-order difference is used to calculate the rate of data change, and the calculation formula is as follows: , The second-order difference is used to calculate the rate of change of data, i.e., acceleration. The calculation formula is: , Constructing trend-based eigenvectors: , here This represents the value of the i-th feature at time t. It is the quantity of the target water quality that is predicted.

8. The influent water quality prediction method based on a dual-branch multi-head attention mechanism according to claim 1, characterized in that, Historical data is introduced as lagged features to reflect historical dependencies in the data, and lagged terms are constructed for each feature: , Constructing the hysteresis eigenvector: , here L represents the lag step size of the target column, and L is the number of lags.