A sewage plant carbon source dosing prediction method, device, medium and product
By dynamically adjusting the model parameters and order, and utilizing the dynamic attention weighting mechanism, the problem of insufficient prediction accuracy of fixed parameter models under multiple operating conditions was solved, and efficient and accurate prediction of carbon source addition in wastewater treatment plants was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI ENVIRONMENT PROTECTION GROUP
- Filing Date
- 2026-05-25
- Publication Date
- 2026-06-23
AI Technical Summary
In existing carbon source dosing prediction technologies for wastewater treatment plants, fixed-parameter models cannot adapt to the statistical distribution differences in carbon source dosage sequences under various operating conditions, resulting in insufficient prediction accuracy and robustness.
A dynamic attention weighting mechanism is adopted to adjust model parameters according to real-time operating conditions, generate weighted target sequences and weighted external covariates, and dynamically adjust the order of the ARIMAX model to adapt to different operating states.
It significantly improves the accuracy and robustness of carbon source addition prediction, and can maintain high prediction performance under various operating conditions.
Smart Images

Figure CN122264231A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of industrial process control, specifically to a method, equipment, medium, and product for predicting carbon source dosing in wastewater treatment plants. Background Technology
[0002] Carbon source addition is a key factor in maintaining the normal operation of denitrification processes in wastewater treatment plants. In actual operation, the amount of carbon source added needs to be adjusted according to the dynamic changes of various operating parameters such as influent flow rate, influent composition, system activated sludge concentration, and dissolved oxygen concentration.
[0003] Existing carbon source dosing prediction technologies for wastewater treatment plants mainly employ time series forecasting methods. The typical approach is as follows: First, based on the overall characteristics of historical operational data, a set of structural parameters for a prediction model is determined through industry experience or statistical criteria. These parameters remain constant throughout the modeling process. Then, this fixed parameter framework is used to fit the model coefficients to the wastewater treatment plant's historical data. Finally, the resulting model is used to predict future carbon source dosing levels.
[0004] However, the core problem with the above technical solutions lies in the fact that once the model structure parameters are fixed, the prediction model uses the exact same modeling strategy and weighting method for all operating conditions. In actual wastewater treatment operations, due to the combined influence of various factors such as influent characteristics, flow rate changes, temperature fluctuations, and changes in microbial activity, wastewater treatment systems exhibit various operating states, including sunny weather conditions, rainy weather conditions, low temperature conditions, high concentration conditions, and abnormal conditions. Under these different operating conditions, the time series characteristics of carbon source dosage data show significant differences in statistical distribution. Summary of the Invention
[0005] To address the aforementioned technical problems, this application provides a method, equipment, medium, and product for predicting carbon source dosing in wastewater treatment plants.
[0006] The first aspect of this application provides a method for predicting carbon source dosing in wastewater treatment plants: Obtain historical operating data of wastewater treatment plants that include historical carbon source injection target sequences and multidimensional external covariates; According to the preset weight adjustment strategy, corresponding dynamic attention weights are generated for each historical time step of the target sequence of historical carbon source addition and each covariate dimension of the multidimensional external covariate. Extract weight distribution features from all the dynamic attention weights; Based on the weight distribution characteristics and the preset order mapping rules, the target autoregression order and the target moving average order are determined. The dynamic attention weights are applied to the historical carbon source injection target sequence and the multidimensional external covariates to generate a weighted target sequence and a weighted external covariate, respectively. The weighted target sequence and the weighted external covariates are input into a preset ARIMAX model, and the order parameters of the ARIMAX model are set to the target autoregressive order and the target moving average order to obtain the predicted value of carbon source addition.
[0007] By adopting the above technical solution, the core problem that fixed-parameter models cannot adapt to the statistical distribution differences of carbon source dosage sequences under multiple operating conditions is effectively solved. Dynamic attention weights enable adaptive weighting of different historical time steps and covariate dimensions, allowing the model to focus on key information based on changes in operating conditions. At the same time, the order parameters of the ARIMAX model are dynamically determined based on the weight distribution characteristics, allowing the model structure to be flexibly adjusted according to operating condition characteristics, thereby significantly improving the accuracy of predictions and robustness to various operating states such as sunny days, rainy days, and abnormal conditions.
[0008] Optionally, the step of generating corresponding dynamic attention weights for each historical time step of the historical carbon source injection target sequence and each covariate dimension of the multidimensional external covariates according to a preset weight adjustment strategy includes: Assign a preset baseline weight value to each of the covariate dimensions and each of the historical time steps; The actual values of the covariate dimension are compared with the triggering conditions of the working conditions defined in the preset working condition event library; When the actual value matches the triggering condition of the operating condition event, the target operating condition event is identified and marked. Based on the target operating condition event, retrieve the weight adjustment strategy corresponding to the target operating condition event from the preset weight adjustment strategy set; According to the weight adjustment strategy, the baseline weight values corresponding to the covariate dimensions associated with the target working condition event are modified; Normalization is performed on all the modified baseline weight values to obtain the corresponding dynamic attention weights.
[0009] By adopting the above technical solution, the problem of weak adaptability of traditional attention mechanisms in professional scenarios is effectively solved. The system can automatically identify specific working conditions (such as rainfall) and adjust the weights of relevant covariates and historical time steps according to preset strategies, thereby ensuring that the model always focuses on the most critical driving factors in complex and ever-changing operating environments. This significantly improves the interpretability, working condition specificity, and predictive reliability of attention weights.
[0010] Optionally, extracting weight distribution features from all the dynamic attention weights includes: Based on the maximum and minimum values of the dynamic attention weights, the numerical range of the dynamic attention weights is calculated, and the numerical range is divided into multiple weight distribution intervals at equal intervals. The distribution of the number of dynamic attention weights within each weight distribution interval is statistically analyzed to obtain the histogram features of the weights; Based on the histogram features, the weight concentration index of the dynamic attention weight is calculated using a preset information entropy calculation formula. The number of weights in the dynamic attention weights whose values are greater than a preset weight threshold is counted to obtain the weight span index; The weight distribution characteristics are constructed based on the weight concentration index and the weight span index.
[0011] By employing the above technical solution, a quantitative analysis and feature extraction of the dynamic attention weight distribution characteristics were achieved. By calculating the weight concentration and span indices, the weight distribution pattern was transformed into a quantitative feature that characterizes the temporal complexity of the current data and the concentration of key information. This feature objectively reflects the focus and dispersion of the input variable's influence under different operating conditions, thus providing a basis for the dynamic selection of the optimal order of the subsequent ARIMAX model. This overcomes the shortcomings of traditional methods, such as fixed orders and the inability to adapt to the data's own characteristics, enabling the model structure to intelligently adjust according to the actual distribution of the input's influence.
[0012] Optionally, determining the target autoregressive order and the target moving average order based on the weight distribution characteristics and a preset order mapping rule includes: The weight concentration index and the weight span index in the weight distribution feature are weighted and fused to generate a fused feature vector; In the order mapping rule, multiple feature intervals are traversed, and the Euclidean distance between the fused feature vector and the center coordinates of each feature interval is calculated. Based on the relationship of the Euclidean distances, the target feature interval with the smallest Euclidean distance is selected, and the initial autoregressive order and the initial moving average order associated with the target feature interval are extracted from the order mapping rule. Based on the length constraint of the historical carbon source injection target sequence and the initial autoregressive order and the initial moving average order, the validity of the order is verified and adjusted to obtain the target autoregressive order and the target moving average order.
[0013] By adopting the above technical solution, the weight distribution characteristics are intelligently matched with preset rules, enabling adaptive and refined determination of the ARIMAX model order. Through feature fusion, interval mapping, and validity verification, the inherent characteristics of the data are directly transformed into the optimal model structure configuration, allowing the model memory and error backtracking depth to be dynamically adjusted according to operating conditions, fundamentally improving model adaptability and prediction accuracy.
[0014] Optionally, the application of the dynamic attention weights to the historical carbon source injection target sequence and the multidimensional external covariates to generate a weighted target sequence and weighted external covariates respectively includes: Based on the mapping relationship between the dynamic attention weights and the historical time steps and the covariate dimensions, the dynamic attention weights are decomposed into a target sequence weight subset and an external covariate weight subset, wherein the target sequence weight subset contains weight values associated with each historical time step, and the external covariate weight subset contains weight values associated with each covariate dimension. The weighted target sequence is obtained by multiplying the value of each historical time step in the target sequence with the weight value corresponding to the historical time step in the target sequence weight subset element by element. The weighted external covariate is obtained by performing element-wise multiplication of the value of each covariate dimension in the multidimensional external covariate with the weight value corresponding to the covariate dimension position in the external covariate weight subset.
[0015] By employing the aforementioned technical solution, a dual differentiated weighting of time-series dependence and external influencing factors is achieved. This translates the model's focusing capability into concrete data transformation, enabling the influence of important historical moments and key covariates to be targeted and enhanced before being input into the model, while secondary information is correspondingly suppressed. This provides subsequent ARIMAX models with purified and focused input sequences, effectively improving the model's ability and efficiency in extracting stable predictive patterns from complex and variable raw data.
[0016] Optionally, the step of inputting the weighted target sequence and the weighted external covariates into a preset ARIMAX model, and setting the order parameters of the ARIMAX model to the target autoregressive order and the target moving average order, to obtain the predicted carbon source injection amount, includes: The target autoregression order, the preset integral difference order, and the target moving average order are configured into the ARIMAX model to obtain the initialized ARIMAX model. The weighted target sequence is used as an endogenous variable and the weighted external covariate is used as an exogenous variable. These are then input into the initial ARIMAX model to obtain the target ARIMAX model. Perform parameter fitting operations on the target ARIMAX model to obtain autoregressive coefficients, moving average coefficients, and exogenous variable coefficients; A prediction expression is constructed based on the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient; The external covariates of the preset prediction period are substituted into the prediction expression to perform calculations and obtain the predicted value of the carbon source addition.
[0017] By adopting the above technical solution, a closed loop from data preprocessing to final prediction is completed. This ensures that the key information (weighted sequence) focused by the attention mechanism and the dynamically optimized model structure (adaptive order) based on data characteristics can work together. Parameter fitting is then performed, and the resulting prediction expression integrates optimized representations of historical trends, external factors, and model noise. This results in the final carbon source dosage prediction calculated based on this expression having higher accuracy, stability, and adaptability to complex operating conditions.
[0018] Optionally, the step of performing parameter fitting operations on the target ARIMAX model to obtain autoregressive coefficients, moving average coefficients, and exogenous variable coefficients includes: Based on the mathematical expression of the target ARIMAX model, a conditional log-likelihood function is established to obtain the objective function with the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient as undetermined parameters. The objective function is iteratively solved using a preset numerical optimization algorithm to obtain the optimal parameters that maximize the value of the objective function. The optimal parameters are used as the final parameters of the ARIMAX model, and the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient are determined from the optimal parameters.
[0019] By adopting the above technical solution, a rigorous maximum likelihood estimation framework is established and efficient numerical optimization is performed, achieving accurate and stable solutions for model parameters. This method can automatically find the parameter combination that best fits the weighted input data in a probabilistic sense, ensuring that the coefficient estimates of the autoregressive, moving average, and exogenous variable components have optimal statistical properties, thus laying a solid mathematical foundation for generating a reliable and accurate final prediction expression.
[0020] A second aspect of this application provides an electronic device including a processor, a memory, a user interface, and a network interface, wherein the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any of the foregoing.
[0021] A third aspect of this application provides a computer-readable storage medium storing instructions that, when executed, perform the method described in any of the preceding descriptions.
[0022] A fourth aspect of this application provides a computer program product that, when run on an electronic device, causes the electronic device to perform the method as described in any of the preceding claims.
[0023] In summary, one or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: By employing a dynamic attention mechanism, the system adaptively focuses on key historical moments and core covariates. Based on weight distribution characteristics, it intelligently adjusts the structural order of the ARIMAX model, constructing a predictive framework that can autonomously adapt to changes in influent characteristics, flow rate, temperature, and other operating conditions. This approach effectively overcomes the core deficiency of traditional fixed-parameter models in adapting to dynamic changes in the statistical distribution of carbon source dosage sequences. It significantly improves the accuracy, robustness, and interpretability of the predictive model under different operating conditions, providing reliable technical support for the precise and intelligent control of carbon source dosage in wastewater treatment plants. Attached Figure Description
[0024] Figure 1 This is a schematic diagram of the system architecture of an embodiment of a carbon source dosing prediction method for wastewater treatment plants, which applies this application; Figure 2 This is a schematic flowchart of a method for predicting carbon source dosing in a wastewater treatment plant, as disclosed in an embodiment of this application. Figure 3 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application.
[0025] Explanation of reference numerals in the attached figures: 100, System architecture; 101, First terminal device; 102, Second terminal device; 103, Third terminal device; 104, Network; 105, Server; 301, Processor; 302, Communication bus; 303, User interface; 304, Network interface; 305, Memory. Detailed Implementation
[0026] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0027] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0028] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0029] like Figure 1 As shown, the system architecture 100 may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired communication links, wireless communication links, or fiber optic cables.
[0030] Users can use the first terminal device 101, the second terminal device 102, or the third terminal device 103 to interact with the server 105 via the network 104 to receive or send wastewater treatment plant operation data, model prediction results, operational event alerts, or carbon source dosing control suggestions, etc. The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be equipped with data monitoring applications, model training applications, web browser applications, or operation management platform clients, etc.
[0031] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be either hardware or software. When they are hardware, they can be various electronic devices with displays or data interaction capabilities, including but not limited to desktop computers, portable computers, tablet computers, smartphones, industrial touch screen terminals, or factory maintenance workstations. When they are software, they can be installed in the aforementioned electronic devices and can be implemented as a single software module or multiple software modules; this application does not limit this.
[0032] This embodiment discloses a method for predicting carbon source dosing in wastewater treatment plants. Figure 2 This is a schematic flowchart of a method for predicting carbon source dosing in a wastewater treatment plant, as disclosed in an embodiment of this application. Figure 2 As shown, the method includes the following steps: S201. Obtain historical operating data of wastewater treatment plants, including historical carbon source addition target sequences and multidimensional external covariates; In a specific embodiment, step S201 is the data foundation construction stage of the entire prediction method. Its core purpose is to acquire and integrate a comprehensive, time-aligned historical operation dataset of the wastewater treatment plant. There are several specific implementation schemes for acquiring this dataset. The first scheme is to interface with the wastewater treatment plant's SCADA (Supervisory Control and Data Acquisition) system and LIMS (Laboratory Information Management System) database to automatically pull structured historical data at a preset time frequency (e.g., hourly or minute-level). The second scheme is to construct the dataset by parsing and importing data report files regularly exported by plant operation and maintenance personnel, such as Excel or CSV (Comma-Separated Values) files. This dataset mainly consists of two parts: first, the historical carbon source dosage target sequence as the prediction target. This is usually a one-dimensional time series, recording the actual cumulative dosage or instantaneous dosage rate of the carbon source dosing pump over a past period (e.g., the past 48 time steps). Secondly, there are multidimensional external covariates closely related to changes in carbon source dosage. These covariates constitute key external factors affecting prediction, and may include, but are not limited to: influent parameters obtained from online sensors, such as COD (Chemical Oxygen Demand), NH3-N (Ammonia Nitrogen), influent flow rate, and pH value; process parameters reflecting the state of the biochemical reactor, such as MLSS (Mixed Liquor Suspended Solids) and DO (Dissolved Oxygen) concentrations; effluent water quality indicators reflecting treatment effectiveness, such as TN (Total Nitrogen) value; and weather data obtained from third-party meteorological service APIs (Application Programming Interfaces), such as local rainfall and weather type. After acquiring the raw data, the system will also perform necessary data preprocessing operations, such as strictly aligning all data sequences by time using a unified timestamp, cleaning the data (e.g., removing outliers using the Laida criterion or interquartile range method), and processing covariates of different dimensions using minimum-maximum normalization or Z-score standardization methods, thereby ultimately forming a clean, well-organized historical running dataset that can be directly used as input for subsequent models.
[0033] S202. According to the preset weight adjustment strategy, generate corresponding dynamic attention weights for each historical time step of the target sequence of historical carbon source addition and each covariate dimension of the multidimensional external covariate. In one embodiment of this application, step S202 aims to generate dynamic attention weights for all input data based on real-time operating conditions to reflect their relative importance to the current prediction task. The generation of these dynamic weights can employ various technical solutions. A preferred solution is weight adjustment based on expert rules. This solution first assigns a unified baseline weight to all historical time steps and covariate dimensions. Then, the system matches the real-time data of the covariates with a preset operating condition event library (e.g., defining triggering conditions for events such as "rainy day" and "high load shock"). Once a specific operating condition event is identified, the system invokes a preset adjustment strategy to selectively gain or lose the baseline weights of variables related to that event (such as "influent flow rate" and "influent COD"). Finally, the final weight distribution is obtained through normalization processing (such as the Softmax function). Another optional solution is to use a continuous function mapping approach. For example, an S-shaped function can be constructed to directly map the effluent TN concentration to a weight value. When the TN value is close to the emission standard limit, the function outputs a high weight, thereby dynamically enhancing the importance of recent historical carbon source addition data. In some other embodiments, the system can also adopt a data-driven approach, such as dynamically calculating the correlation coefficients between each covariate and historical time steps and the recent carbon source injection amount within a sliding time window, and directly using the normalized correlation index as the dynamic attention weight. Through any of the above schemes, this step can achieve adaptive focusing on input features, ensuring that the model can focus on the most critical influencing factors based on real-time changes in operating conditions.
[0034] Optionally, the step of generating corresponding dynamic attention weights for each historical time step of the historical carbon source injection target sequence and each covariate dimension of the multidimensional external covariates according to a preset weight adjustment strategy includes: assigning a preset baseline weight value to each covariate dimension and each historical time step; comparing the actual value of the covariate dimension with the operating condition event triggering conditions defined in a preset operating condition event library; identifying and marking a target operating condition event when the actual value matches the operating condition event triggering conditions; retrieving a weight adjustment strategy corresponding to the target operating condition event from a preset weight adjustment strategy set based on the target operating condition event; modifying the baseline weight value corresponding to the covariate dimension associated with the target operating condition event according to the weight adjustment strategy; and performing normalization processing on all the modified baseline weight values to obtain the corresponding dynamic attention weights.
[0035] Specifically, in the initial stage of the weight adjustment process, the system needs to establish a baseline weight value for each input feature. Specifically, the system iterates through each historical time step in the historical carbon source injection target sequence (e.g., every hour from t-48 to t-1) and each covariate dimension in the multidimensional external covariates (e.g., influent COD, influent flow rate, dissolved oxygen DO, rainfall, etc.), and assigns each a preset baseline weight value. A simple and commonly used implementation is to initialize all these baseline weight values uniformly to a neutral value, such as 1, which means that all input features are given equal initial importance when no specific operating condition occurs. In another alternative implementation, these baseline weights can be non-uniformly initialized based on prior knowledge or offline analysis results. For example, by performing feature importance analysis on a large amount of historical data (such as using random forests or SHAP analysis), a relatively high initial baseline weight (e.g., 1.2) can be assigned to covariates that have proven to have higher long-term predictive value (e.g., inflow rate), while a lower baseline weight (e.g., 0.9) can be assigned to variables with weaker correlation, thus providing a more optimized starting point for weight adjustment. These baseline weights can be stored in a key-value pair structure, where the key is the feature identifier and the value is the corresponding baseline weight.
[0036] Furthermore, the system initiates a real-time operating condition monitoring and matching process. The core of this process is to utilize a pre-defined operating condition event database to interpret the current operating status. This database can be configured as a structured database or configuration file, pre-defined with various typical operating condition events that significantly impact wastewater treatment plant operation. Each operating condition event is associated with a set of explicit, quantifiable triggering conditions. For example, the triggering condition for a rainstorm impact operating condition event can be defined as local hourly rainfall exceeding 5 mm and influent flow exceeding the historical average for the same period by 30%; the triggering condition for a high-load impact operating condition event can be defined as an instantaneous increase in influent COD concentration exceeding 50 mg / L within one hour. The system compares and judges the real-time observed values of covariates against these triggering conditions in the operating condition event database at a preset frequency (e.g., whenever a new data point is entered). When a set of actual values of covariates satisfies all the triggering conditions defined for a certain operating condition event, the system determines that the event has been successfully matched and immediately identifies and marks the current target operating condition event, for example, marking the system status as "rainstorm impact_triggered".
[0037] In one optional implementation, the operating event database can be defined according to a data structure of "event identifier, trigger variable, trigger condition, duration, release condition, associated covariate, weight adjustment direction, and adjustment magnitude". The event identifier is used to distinguish different operating states, such as stable sunny weather, rainy weather shock conditions, high influent load conditions, low-temperature nitrification-limited conditions, low C / N ratio conditions, effluent total nitrogen approaching the limit conditions, and sensor malfunction conditions. Trigger variables may include rainfall, influent flow rate, influent COD, influent TN, influent ammonia nitrogen, water temperature, dissolved oxygen (DO), MLSS, effluent TN, and the operating frequency of the carbon source dosing pump, etc. Trigger conditions can be determined by design operating parameters, emission standards, historical quantile statistics, or plant operating experience. For example, the rain impact condition can be defined as the current hourly rainfall exceeding a first rainfall threshold, and the influent flow rate increasing by more than a first flow fluctuation threshold relative to the average of the same period over the past 7 days; the high influent load condition can be defined as the influent COD or influent TN exceeding the 75th or 90th percentile of the historical average for the same period; the low temperature condition can be defined as the biological treatment tank water temperature being below a first temperature threshold for a preset time; the effluent TN approaching the limit condition can be defined as the effluent TN exceeding a preset proportion of the discharge limit, such as reaching 80% to 95% of the discharge limit. The above thresholds can be configured according to the wastewater treatment plant design scale, local discharge standards, historical operating data statistics, and operation and management requirements, and this application does not impose any limitations on them.
[0038] To avoid frequent jitter-triggered operation events, the operation event library can also set duration and release conditions. For example, a certain trigger condition may need to be met continuously for 2 or 3 sampling periods before the target operation event is confirmed to have been triggered; the target operation event may be released only after the corresponding variable falls below the trigger threshold and remains below it for a preset time. In another implementation, different values can be set for the trigger threshold and the release threshold to form a hysteresis judgment mechanism, thereby avoiding frequent changes in weights caused by sensor noise or short-term fluctuations.
[0039] Furthermore, once a target operating condition event is identified and tagged, the system immediately retrieves the corresponding weight adjustment strategy from a pre-defined set of weight adjustment strategies based on this event identifier. This strategy set can also be a structured database or configuration file, typically a mapping table where the key is the unique identifier of the operating condition event (e.g., rain impact), and the value is the specific set of weight adjustment instructions. This instruction set defines in detail how the weights of which features should be modified under the current operating condition. For example, the weight adjustment strategy associated with a rain impact event might include the following instructions: multiply the baseline weight value of the influent flow covariate by a gain factor of 1.5, multiply the baseline weight value of the influent COD covariate by a decay factor of 0.8, and uniformly multiply the baseline weight values of all historical carbon source dosage time steps over the past 6 hours by a gain factor of 1.2. Through this retrieval mechanism, the system can transform abstract operating condition judgments into precise, quantifiable weight adjustment operations.
[0040] In one specific implementation, the set of weight adjustment strategies can be generated by combining expert rules with historical data calibration. First, the main influencing factors corresponding to different operating conditions are determined based on the wastewater treatment process mechanism. For example, under rainy weather shock conditions, influent flow rate, rainfall, and short-term changes in influent COD dilution have a significant impact on carbon source dosage prediction; therefore, the weights of influent flow rate, rainfall, and recent historical time steps can be increased. Under low C / N ratio conditions, influent COD, influent TN, effluent TN, and recent carbon source dosage have a significant impact on prediction; therefore, the weights of these variables can be increased. Under low temperature conditions, water temperature and denitrification-related operating parameters have a significant impact on changes in carbon source demand; therefore, the weights of water temperature, MLSS, DO, and the lagged terms of historical carbon source dosage can be increased. Secondly, the system uses historical operating data to calibrate the initial adjustment range. It can search within a preset set of candidate gain coefficients, such as selecting a gain coefficient between 1.05 and 2.00, and a decay coefficient between 0.50 and 0.95. The final adjustment range is determined with the goal of minimizing the rolling prediction error or achieving a better validation set AIC / BIC.
[0041] In another implementation, the weight adjustment strategy can also be generated using a data-driven approach. The system can calculate the mutual information, Pearson correlation coefficient, Spearman correlation coefficient, lag correlation coefficient, or tree-based feature importance between each covariate and carbon source dosage in historical sample subsets corresponding to different operating conditions, and convert the normalized importance results into weight adjustment coefficients. For example, for inflow rate and rainfall, which show a significantly enhanced correlation with changes in carbon source dosage in rainy weather impact samples, a larger gain coefficient can be assigned; for variables whose explanatory power decreases under this operating condition, a smaller attenuation coefficient can be assigned. The expert rule approach and the data-driven approach described above can be used individually or in combination; when the results of the two approaches are inconsistent, the final strategy can be determined according to a pre-set reliability level or the results of manual review.
[0042] Furthermore, after obtaining the specific weight adjustment strategy, the system begins to execute the actual weight modification operation. The system parses the retrieved strategy instruction set and modifies the baseline weight values of specific covariate dimensions or historical time steps associated with the current target operating condition event according to the instructions. The modification methods can be varied, including but not limited to: the first is multiplicative adjustment, which multiplies the baseline weight value by a gain coefficient greater than 1 or a decay coefficient less than 1 to enhance or weaken the weight; the second is additive adjustment, which adds or subtracts a fixed adjustment value from the baseline weight value; the third is direct replacement, which directly sets the baseline weight value to a specific value specified in the strategy, regardless of its actual value. For example, according to the aforementioned rain impact strategy, the system updates the baseline weight of influent flow rate from 1 to 1.5 (assuming multiplicative adjustment), and updates the weight of influent COD from 1 to 0.8. For features not mentioned in the current operating condition event, their baseline weight values remain unchanged. Through this step, the system effectively injects expert knowledge (i.e., which variables should be considered under which operating conditions) into the weight matrix.
[0043] Furthermore, after modifying all relevant baseline weight values, to ensure that the final generated dynamic attention weights have a uniform scale and probabilistic meaning, the system needs to perform a normalization process on the weight values of all current features (including modified and unmodified ones). A preferred normalization method is to apply the Softmax function, which maps a set of arbitrary real numbers to a set of real numbers that sum to 1, so that each weight value can be interpreted as the proportion of attention allocation for that feature in the current prediction. Another optional normalization method is simple linear normalization, which scales all weight values to the interval [0, 1]. After performing the normalization process, the resulting set of new, dynamically adjusted and normalized weight values is the final output dynamic attention weight that accurately reflects the relative importance of each input feature under the current conditions, and can be directly used for subsequent weighted prediction calculations.
[0044] S203. Extract weight distribution features from all the dynamic attention weights; In one embodiment of this application, the purpose of step S203 is to refine and elevate the large number of discrete dynamic attention weights generated in the previous step into a set of quantitative features that can globally describe the "attention state" of the model. This process can be implemented in various ways. A preferred approach is to extract the statistical distribution features of the weights. For example, the system can calculate the mean, variance (or standard deviation), skewness, and kurtosis of the set of all dynamic attention weights. In this scenario, the mean reflects the average distribution level of attention, while the variance directly quantifies whether attention is concentrated on a few key variables (high variance) or evenly distributed across multiple variables (low variance). Another feasible approach is feature extraction based on information theory, such as calculating the Shannon entropy of the weight distribution. A lower entropy value indicates that the model's attention is highly concentrated, and the prediction certainty is strong; conversely, a higher entropy value means that the attention distribution is relatively uniform, which may indicate that the current working condition is complex and the model cannot determine the key influencing factors. In some other embodiments, group-based aggregation features can also be extracted. For example, all weights can be grouped according to their corresponding input types (i.e., "historical carbon source input" and "external covariates"), and then the sum, mean, or ratio of the sums of the two groups of weights can be calculated and extracted. This ratio can serve as a key feature to characterize whether the model relies more on historical operational experience or changes in the external environment at the current moment. Finally, one or more weight distribution features extracted through any or a combination of the above methods will be integrated into a feature vector to characterize the overall attention pattern of the model under the current operating conditions.
[0045] Optionally, extracting weight distribution features from all the dynamic attention weights includes: calculating the numerical range of the dynamic attention weights based on the maximum and minimum values, and dividing the numerical range into multiple weight distribution intervals at equal intervals; statistically analyzing the distribution of the number of dynamic attention weights within each weight distribution interval to obtain a histogram feature of the weights; calculating the weight concentration index of the dynamic attention weights based on the histogram feature using a preset information entropy calculation formula; statistically analyzing the number of dynamic attention weights whose values are greater than a preset weight threshold to obtain a weight span index; and constructing the weight distribution features based on the weight concentration index and the weight span index.
[0046] Furthermore, to perform effective statistical analysis on continuous weight values, the system needs to discretize these values, i.e., divide them into intervals. Specifically, the system first iterates through all dynamic attention weights generated at the current moment (assuming a total of N weights) and identifies the maximum value W_max and the minimum value W_min. Based on these two extreme values, the system calculates the numerical range of the entire weight set (Range = W_max - W_min). Subsequently, the system divides this numerical range into equal intervals according to a preset number of divisions K, thus obtaining K continuous and non-overlapping weight distribution intervals. For example, if the preset K = 10, the first interval is [W_min, W_min + Range / 10), the second interval is [W_min + Range / 10, W_min + 2 × Range / 10), and so on. The value of parameter K can be configured according to the application's precision requirements and is not fixed, thus providing flexibility to this method. In some other embodiments, equal-frequency division can also be used, that is, all weights are sorted and divided into K groups equally according to their quantity. This method is more robust to handling scenarios with extremely uneven data distribution.
[0047] Furthermore, after completing the interval division, the system will then count the distribution of weights within each interval to generate a histogram feature of the weights. Specifically, the system initializes a counting vector of length K, with each element initially set to 0, corresponding to the K weight distribution intervals defined in the previous step. Then, the system iterates through all N dynamic attention weights again. For each weight value, it determines its corresponding interval and increments the element in the counting vector corresponding to that interval by 1. After the iteration is complete, this counting vector constitutes the frequency histogram of the weights. To eliminate the impact of changes in the total number of weights N, a preferred implementation is to normalize this frequency histogram, i.e., divide each element by the total number N to obtain a frequency distribution histogram. This normalized vector of length K, with a sum of 1 for each element, can intuitively depict the distribution density and shape of the attention weight values, and is itself an important set of histogram features.
[0048] Furthermore, to extract a single metric from the histogram features that measures the degree of attention concentration, the system calculates the information entropy of the weights based on this feature. Specifically, the system uses a pre-defined information entropy calculation formula (e.g., the Shannon entropy formula: H = -Σ[p_i × log(p_i)]), where p_i is the frequency value of the i-th interval in the frequency distribution histogram obtained in the previous step. The calculated information entropy value is defined as the weight concentration index. This index has a clear physical meaning: when the weights are highly concentrated in a few intervals (i.e., most p_i are close to 0, and a few p_i are close to 1), the calculated information entropy value is small, indicating that the model's attention is highly focused; conversely, when the weights are evenly distributed across all intervals, the information entropy value is large, indicating that the model's attention is scattered. Therefore, this index can efficiently quantify the degree of certainty of the model's attention.
[0049] Meanwhile, to characterize the distribution of attention from another dimension—the number of high-weight features—the system also calculates a weight span metric. This process requires pre-setting a weight threshold, for example, 0.05 (assuming the weights have been softmax normalized). The system iterates through all the original dynamic attention weights and counts the total number of weights with values greater than the preset threshold. This number is defined as the weight span metric. This metric intuitively reflects how many input features the model considers significantly important under the current conditions. A lower span metric means the model relies on a very small number of core variables for decision-making, while a higher span metric means multiple variables collectively have a significant impact on the prediction result. The weight threshold here is a hyperparameter that can be flexibly adjusted according to actual business needs.
[0050] Furthermore, the system combines the two key indicators independently calculated in the preceding steps—the weight concentration indicator (such as information entropy) and the weight span indicator (such as the number of high-weight indicators)—to construct a final weight distribution feature that comprehensively describes the attention distribution state. A simple construction method is to combine these two scalar values into a two-dimensional feature vector, for example, [weight concentration indicator, weight span indicator]. In more complex embodiments, the histogram feature of the weights themselves, along with these two indicators, can be concatenated into a higher-dimensional feature vector. This final constructed weight distribution feature integrates information on the overall shape, concentration, and number of salient features of attention, providing a profound and robust basis for subsequent carbon source addition decisions or model status monitoring.
[0051] Furthermore, the weight concentration index and weight span index described in this application do not directly determine the order of the ARIMAX model in isolation. Instead, they serve as intermediate features characterizing the complexity of the current input information and the range of temporal dependencies, used for matching within a pre-constructed and validated order mapping rule. Specifically, the dynamic attention weights reflect the relative contributions of different historical time steps and different external covariate dimensions to the current carbon source injection prediction task. When the dynamic attention weights are concentrated on a few historical time steps or a few covariate dimensions, it indicates that the carbon source injection under the current operating conditions is mainly driven by a few key factors or recent historical states, and the effective dependency range of the input information is narrow. In this case, using a lower autoregression order and a lower moving average order can usually fully express the main dynamic relationships and reduce the risk of model overfitting. Conversely, when the dynamic attention weights are distributed relatively dispersed across multiple historical time steps and multiple covariate dimensions, it indicates that the carbon source input under the current operating conditions is affected by many external factors, and the contribution of historical states to the current prediction has a large range. In this case, the model needs to introduce longer historical backtracking terms or more error correction terms to enhance its ability to characterize complex dynamic processes. Therefore, it can be mapped to a relatively high autoregressive order and / or moving average order.
[0052] In one specific implementation, the weight concentration index can reflect the dispersion of attention distribution through information entropy. A higher information entropy indicates that the weights are closer to a uniform distribution, meaning the model cannot achieve stable predictions under current conditions relying solely on a few key variables, and the current data state typically exhibits stronger multi-factor coupling characteristics. Conversely, a lower information entropy indicates that attention is concentrated on a few key variables or key historical moments, suggesting that the dominant factors in the current prediction task are relatively clear. The weight span index is used to characterize the number of significant features exceeding a preset weight threshold. A greater number of significant features indicates more effective variables involved in explaining the current changes in carbon source input, and a wider range of input influence that the model needs to consider. Therefore, using both information entropy and weight span as order mapping inputs can, in engineering terms, characterize the historical memory depth and error correction complexity required for current sequence modeling.
[0053] It should be noted that the order mapping rule described in this application is not derived from a single theoretical formula, but rather constructed by combining the principles of ARIMAX model order selection, wastewater treatment process experience, and offline verification using historical operating data. For each weight distribution characteristic interval, the system can traverse multiple candidate order combinations within the historical sample window and select the order combination with superior prediction performance and moderate model complexity based on one or more evaluation indicators among the Akaike Information Criterion (AIC), Bayesian Information Criterion (BIC), Root Mean Square Error of Rolling Prediction (RMSE), and Mean Absolute Error (MAE). This combination serves as the initial autoregressive order and the initial moving average order for that characteristic interval. Thus, a historically validated engineering mapping relationship is formed between weight concentration, weight span, and model order, rather than an arbitrary, unconstrained correspondence.
[0054] S204. Based on the weight distribution characteristics and the preset order mapping rules, determine the target autoregression order and the target moving average order. In a preferred embodiment of this application, step S204 is the core step in achieving adaptive adjustment of the model structure. Essentially, it transforms the abstract features extracted in the previous step into specific model hyperparameters. The "preset order mapping rule" upon which this step relies can be implemented using various techniques. One concrete and easily explained approach is to construct a rule base or multidimensional lookup table based on expert knowledge. This rule base divides the possible value space of the weight distribution features into multiple regions, each region mapping to a set of preset (p, q) order combinations. For example, the rule base can be predefined: when the "weight concentration index" is below a certain threshold (indicating scattered attention) and the "weight span index" is above a certain threshold (indicating numerous influencing factors), the system judges the current operating condition to be complex and unstable, and should use a higher autoregressive order p (e.g., p=12) to capture more historical information, and a lower moving average order q (e.g., q=2) to simplify the fitting to noise; conversely, when the "weight concentration index" is high and the "weight span index" is low, the system judges the current operating condition to be dominated by a few key factors, and should map to a lower combination of p and q orders (e.g., p=3, q=1) to build a simpler and more efficient model. In another alternative implementation, this mapping rule can also be a lightweight, pre-trained regression model (e.g., gradient boosting tree or small neural network), which takes the weight distribution characteristics as input and directly outputs the optimal p and q values as the prediction result. Regardless of the method used, the ultimate goal of this step is to dynamically determine the target autoregressive order p and the target moving average order q that are most suitable for the current working conditions based on the real-time changing attention distribution characteristics.
[0055] Optionally, determining the target autoregressive order and the target moving average order based on the weight distribution characteristics and a preset order mapping rule includes: weighting and fusing the weight concentration index and the weight span index in the weight distribution characteristics to generate a fused feature vector; traversing multiple feature intervals in the order mapping rule and calculating the Euclidean distance between the fused feature vector and the center coordinates of each feature interval; selecting the target feature interval with the smallest Euclidean distance based on the magnitude relationship of the Euclidean distances, and extracting the initial autoregressive order and the initial moving average order associated with the target feature interval from the order mapping rule; and verifying and adjusting the order validity based on the length constraint of the historical carbon source injection target sequence and the initial autoregressive order and the initial moving average order to obtain the target autoregressive order and the target moving average order.
[0056] Specifically, to consolidate multi-dimensional attention distribution information into a unified metric, the system performs weighted fusion of the weight concentration index and weight span index obtained in the preceding steps to generate a fused feature vector. Specifically, the system can use a linear weighting method to assign a preset weight coefficient, such as α and β, to each of these two indicators. These two weight coefficients reflect the relative importance attached to the degree of attention concentration and the breadth of influence during the decision-making process. Their specific values can be preset by domain experts based on process experience or obtained through offline optimization using historical data. Before fusion, a preferred implementation is to normalize the two indicators, for example, using max-min normalization, to eliminate differences in the dimensions and numerical ranges between different indicators, ensuring the fairness and stability of the fusion result. The final generated fused feature vector, such as a two-dimensional vector, can more comprehensively represent the overall attention state of the model under the current operating conditions.
[0057] Furthermore, the system will use the fused feature vector to perform matching within a preset order mapping rule. This order mapping rule can be specifically implemented as a feature space divided into multiple regions. Within this space, multiple feature intervals are predefined, each representing a typical operating condition and possessing a central coordinate and a uniquely associated set of model orders. The system will traverse all feature intervals and use the Euclidean distance formula to calculate the spatial distance between the currently generated fused feature vector and the central coordinates of each feature interval. Euclidean distance, as an intuitive similarity measure, indicates that the smaller the value, the closer the current operating condition represented by the fused feature vector is to the typical operating condition represented by that feature interval. In other feasible embodiments, other distance metrics such as Manhattan distance or Mahalanobis distance can also be used to adapt to different feature space distribution characteristics.
[0058] In a preferred embodiment, multiple feature intervals in the order mapping rule can be constructed offline using historical running samples. Specifically, the system first extracts multiple training sample windows from the historical running data using a fixed sliding window, and performs dynamic attention weight generation and weight distribution feature extraction on each sample window to obtain the corresponding weight concentration index and weight span index. Then, the system normalizes the weight concentration index and weight span index of all sample windows and performs interval division based on the normalized two-dimensional feature space. The interval division method can be equal-interval division, equal-frequency quantile division, or clustering division. For example, the weight concentration index can be divided into three intervals according to low, medium, and high, and the weight span index can be divided into three intervals according to small, medium, and large, thus forming nine feature intervals; alternatively, K-means clustering, Gaussian mixture model clustering, or hierarchical clustering can be used to automatically divide the historical samples into several typical attention distribution patterns, each corresponding to a feature interval. The number of intervals and boundary values can be configured according to the amount of historical samples, the complexity of the operating conditions, and the prediction accuracy requirements.
[0059] Furthermore, for each feature interval, the system can construct a validation sample set from historical sample windows falling within that interval, and search for candidate order combinations of the ARIMAX model within a preset candidate order range. For example, the autoregressive order p can take values between 1 and Pmax, the moving average order q can take values between 0 and Qmax, and Pmax and Qmax can be determined based on the sampling period, control period, historical window length, and computational resources. Under each candidate order combination, the system trains the ARIMAX model separately and calculates the validation error using a rolling prediction method, while simultaneously calculating model complexity evaluation indicators such as AIC or BIC. The system can select the order combination that results in a smaller validation error and better AIC or BIC as the initial autoregressive order and initial moving average order corresponding to that feature interval. The order mapping rule obtained in this way has a historical data validation basis and can adapt to the operating characteristics of different wastewater treatment plants.
[0060] In an exemplary mapping relationship, when the weight concentration index is low and the weight span index is small, it indicates that attention is focused on a few recent features, and the system can map to a lower-order combination, such as p = 2 to 4 and q = 0 to 1. When the weight concentration index and the weight span index are at a medium level, it indicates that the current operating condition is affected by multiple factors, and the system can map to a medium-order combination, such as p = 4 to 8 and q = 1 to 2. When the weight concentration index is high and the weight span index is large, it indicates that attention is scattered and multiple variables jointly affect the prediction result, and the system can map to a higher-order combination, such as p = 8 to 12 and q = 2 to 4. The above values are only examples for ease of understanding, and can be adjusted according to the offline verification results of historical data from wastewater treatment plants during actual deployment.
[0061] Furthermore, after calculating all distances, the system determines the target interval based on the principle of minimizing distances. Specifically, the system compares and sorts all calculated Euclidean distances, selecting the distance value with the smallest value. The feature interval corresponding to this smallest distance value is determined as the target feature interval under the current operating condition. Once the target feature interval is locked, the system extracts and reads a set of initial model parameters pre-bound to the target feature interval from the order mapping rules, namely the initial autoregressive order and the initial moving average order. This process essentially completes a rapid mapping from a continuous feature space to a discrete parameter space, realizing the initial parameter selection based on operating condition identification.
[0062] Furthermore, to ensure the effectiveness of the selected order and the stability of the model, the system performs an order validity verification and adjustment. Since ARIMA-type models have a basic requirement regarding the length of the input time series—that is, the series length must be greater than the sum of the autoregressive order p and the moving average order q—the system obtains the actual length of the target historical carbon source injection sequence currently used for modeling and checks whether this length meets the aforementioned constraints. If not, for example, if the series length is less than the sum of the initial orders, the system will reduce the initial order according to a preset adjustment strategy, such as proportionally reducing it or decreasing it step by step, until the length constraint is met. After this verification and possible adjustment, the final order is determined as the target autoregressive order and target moving average order that can be safely applied to subsequent model construction. This step greatly enhances the robustness of the entire dynamic order selection method and its reliability in practical applications.
[0063] When validating the order of a model, the system can also set upper limits and complexity constraints for candidate orders. For example, the target autoregressive order p should be less than a preset proportion of the historical modeling window length, and the target moving average order q should also be less than a preset proportion of the historical modeling window length. Furthermore, the sum of p and q should be less than the effective degrees of freedom after subtracting the number of exogenous variables from the number of historical samples. When the initial autoregressive order or the initial moving average order exceeds these constraints, the system can adjust it according to preset rules. These adjustment rules may include: prioritizing a reduction in the moving average order q to decrease the complexity of the error term; or reducing it synchronously according to the ratio of p to q; or recalculating the AIC, BIC, or validation error within the neighborhood of the candidate orders and selecting the optimal order combination that satisfies the constraints. This validity verification process avoids excessively high model orders due to insufficient sample length, a large number of external covariates, or sudden changes in operating conditions, thereby improving the model's fitting stability.
[0064] S205. Apply the dynamic attention weights to the historical carbon source injection target sequence and the multidimensional external covariates to generate a weighted target sequence and a weighted external covariates, respectively. In one specific implementation of this application, step S205 is a crucial step for the attention mechanism to function effectively. Its core lies in rescaling the input data using dynamic attention weights. Specifically, the system performs two parallel weighting operations. For a one-dimensional historical carbon source injection target sequence, the system multiplies each historical value element-wise with a corresponding attention weight to obtain a weighted target sequence. For multi-dimensional external covariates, the system multiplies the time series data representing each covariate dimension (e.g., the entire data column representing influent flow) by its corresponding single attention weight scalar, thereby generating a weighted external covariate matrix. In this way, input features identified by the attention mechanism as having a greater influence on the current prediction are significantly amplified before being fed into the subsequent model, while secondary features are correspondingly weakened. This achieves dynamic filtering and focusing of input information, laying a data foundation for subsequent accurate modeling.
[0065] Optionally, applying the dynamic attention weights to the historical carbon source injection target sequence and the multidimensional external covariates to generate a weighted target sequence and weighted external covariates respectively includes: decomposing the dynamic attention weights into a target sequence weight subset and an external covariate weight subset according to the corresponding mapping relationship between the dynamic attention weights and the historical time steps and the covariate dimensions, wherein the target sequence weight subset contains weight values associated with each historical time step, and the external covariate weight subset contains weight values associated with each covariate dimension; performing element-wise multiplication of the value of each historical time step in the historical carbon source injection target sequence with the weight value corresponding to the historical time step position in the target sequence weight subset to obtain the weighted target sequence; and performing element-wise multiplication of the value of each covariate dimension in the multidimensional external covariates with the weight value corresponding to the covariate dimension position in the external covariate weight subset to obtain the weighted external covariates.
[0066] In a more specific embodiment, the process of applying dynamic attention weights to the input data first involves a structured decomposition of the generated overall attention weight vector. Since this weight vector is generated jointly for the concatenated historical target sequence and multidimensional external covariates, its internal weight values have a clear positional correspondence with each part of the input data. Based on this preset mapping rule, the system precisely divides this one-dimensional weight vector into two independent subsets: a target sequence weight subset and an external covariate weight subset. The target sequence weight subset contains weight values corresponding one-to-one with each historical time step in the historical carbon source injection target sequence, and its length is equal to the size of the historical window being traced. The external covariate weight subset contains weight values corresponding to each external covariate dimension, such as different types of external influencing factors like influent flow rate and total nitrogen concentration. This decomposition step is a prerequisite for subsequent targeted weighting operations.
[0067] Furthermore, after obtaining the decomposed weighted subset, the system first performs weighted processing on the historical carbon source injection target sequence. Specifically, this involves performing an element-wise multiplication operation. That is, the value at the first time point in the historical target sequence is multiplied by the first weight value in the target sequence's weighted subset; the value at the second time point is multiplied by the second weight value, and so on, until the last historical value in the sequence is weighted. In this way, the influence of historical moments in the time series that the attention mechanism determines are more valuable for future prediction is amplified, while the influence of less important moments is weakened, thus generating a weighted target sequence that better reflects key historical dynamics.
[0068] Furthermore, the system performs another set of weighting operations on the multidimensional external covariates. This weighting is based on the dimension or type of the covariates. The system multiplies the first covariate dimension (e.g., representing the entire time series data of influent flow) with its corresponding weight value in the subset of external covariate weights; then it multiplies the second covariate dimension (e.g., representing the entire time series data of total nitrogen concentration) with the second weight value in the subset, and so on, until all covariate dimensions have undergone this operation. Essentially, this operation scales the overall importance of different external factors based on their influence on the prediction target, thus obtaining a weighted external covariate matrix that highlights the key influencing factors.
[0069] S206. Input the weighted target sequence and the weighted external covariates into a preset ARIMAX model, and set the order parameters of the ARIMAX model to the target autoregressive order and the target moving average order to obtain the predicted value of carbon source addition.
[0070] After data preparation and model parameter determination, the system executes the core predictive modeling steps. Specifically, the system inputs the weighted target sequence (as an endogenous variable) and weighted external covariates (as exogenous regression terms) generated in the aforementioned steps into a pre-instantiated ARIMAX model. Simultaneously, the system sets the dynamically determined target autoregressive order and target moving average order, along with the differencing order preset based on time series stationarity, as the (p, d, q) order parameters of the ARIMAX model. Once the model is configured, it uses this attention-filtered and enhanced data to perform internal parameter fitting and calculations, ultimately predicting one time step forward. The single output value is the predicted carbon source injection amount for the next control cycle, thus completing an adaptive and accurate prediction process that integrates multiple influencing factors.
[0071] Optionally, the step of inputting the weighted target sequence and the weighted external covariates into a preset ARIMAX model, and setting the order parameters of the ARIMAX model to the target autoregressive order and the target moving average order to obtain the predicted carbon source injection amount, includes: configuring the target autoregressive order, the preset integral difference order, and the target moving average order into the ARIMAX model to obtain an initial ARIMAX model; inputting the weighted target sequence as an endogenous variable and the weighted external covariates as exogenous variables into the initial ARIMAX model to obtain a target ARIMAX model; performing parameter fitting operations on the target ARIMAX model to obtain autoregressive coefficients, moving average coefficients, and exogenous variable coefficients; constructing a prediction expression based on the autoregressive coefficients, the moving average coefficients, and the exogenous variable coefficients; and substituting the external covariates of the preset prediction period into the prediction expression to perform calculations to obtain the predicted carbon source injection amount.
[0072] The external covariates for the prediction period described in this application can be understood as input values of external influencing factors corresponding to the time point of the carbon source addition to be predicted. These can be measured values, estimated values, predicted values, or planned values. For example, when the prediction period is the carbon source addition amount for the next hour, the external covariates for the prediction period can include the predicted influent flow rate for the next hour, the predicted rainfall for the next hour, and the current or short-term predicted influent COD, TN, ammonia nitrogen, water temperature, DO, and MLSS, etc. For variables that can be detected in real time and change slowly, the current value or short-term smoothed value can be used as the input for the prediction period; for variables that will change significantly in the future and cannot be directly detected, they can be obtained using an independent prediction model or an external interface. Before entering the ARIMAX model, the covariates from the above different sources can be processed according to the same feature order and normalization rules as the historical external covariates to ensure the consistency of the model input.
[0073] In a preferred embodiment of this application, the prediction process using the ARIMAX model is further decomposed into a series of precise steps. The first step is model structure initialization. The system configures the target autoregressive order p and the target moving average order q, which are dynamically determined in the previous steps, and the integral differencing order d, which is determined based on the time series stationarity test, into a basic ARIMAX model framework. The differencing order d is used to ensure that the weighted target sequence meets the stationarity requirements of the ARIMAX model. Its determination process may include: firstly, performing a unit root test, such as the ADF test, on the weighted target sequence or the historical carbon source injection sequence within its training window; simultaneously, cross-validation can be performed in conjunction with the KPSS test, where the ADF test is used to determine whether the sequence has a unit root, and the KPSS test is used to determine whether the sequence is stationary. When the ADF test rejects the unit root hypothesis and the KPSS test does not reject the stationarity hypothesis, the current difference order can be determined as d. When the sequence still does not meet the stationarity requirement, the system will gradually increase the difference order from 0 to 1 or 2, and re-perform the stationarity test after each difference until the preset stationarity condition is met or the maximum allowable difference order is reached.
[0074] In one specific implementation, the maximum permissible differencing order can be set to 2 to reduce the risk of sequence information loss due to excessive differencing. When d=0, it indicates that the original weighted target sequence has met the stationarity requirement; when d=1, it indicates that the trend term is eliminated by first-order differencing; when d=2, it indicates that there is still a significant non-stationary trend after first-order differencing, requiring further differencing. The system can also perform a validity check on the differencing order by combining the variance change of the differencing sequence, the autocorrelation function (ACF) decay characteristics, and the prediction validation error. If the validation error does not decrease after increasing the differencing order or the sequence shows obvious excessive differencing characteristics, such as a significant increase in negative autocorrelation, the system can revert to a lower differencing order. In scenarios with significant changes in operating conditions, such as rain impacts or high load impacts, the differencing order d can be re-performed and dynamically updated within each sliding modeling window; in scenarios with stable operating conditions, a fixed differencing order determined offline can also be used. Thus, the selection of the differencing order can simultaneously consider the model stationarity requirement and the prediction effect under different operating conditions.
[0075] Furthermore, the system inputs the attention-weighted data into this initialized model. Specifically, the weighted target sequence is designated as the model's endogenous variable, i.e., the target variable that the model needs to predict, and its historical values are one of the main bases for predicting future values. At the same time, the weighted external covariates are designated as the model's exogenous variables or regression terms; these variables are considered as external driving factors affecting the endogenous variables. When this data carrying key dynamic information is successfully loaded into a model with a predetermined order structure, a specific instance to be solved is formed, namely the target ARIMAX model.
[0076] Furthermore, the system performs core parameter fitting calculations on the target ARIMAX model. This process essentially utilizes known historical data (including the weighted target sequence and weighted external covariates) and optimization algorithms, such as maximum likelihood estimation and iterative least squares, to solve for a series of unknown coefficients within the model. After the calculations are complete, the system obtains three sets of key coefficients: one set is the autoregressive coefficient reflecting how historical values of the target sequence affect the current value; another set is the moving average coefficient reflecting how historical prediction errors affect the current value; and the last set is the exogenous variable coefficient quantifying the influence of each external covariate on the target variable. These coefficients together constitute a mathematical description of the dynamic law of carbon source dosage in this specific water treatment scenario.
[0077] Furthermore, based on the coefficients obtained from the fitting, the system automatically constructs a precise prediction expression or mathematical equation. This expression explicitly defines how the predicted future carbon source input is determined by its own historical values, historical prediction errors, and the values of external covariates at future points in time. This expression is essentially the specific mathematical form of the trained ARIMAX model, solidifying the complex temporal relationships into a formula that can be directly used for calculation.
[0078] Furthermore, to obtain specific predicted values, the system needs to acquire the external covariate values for the prediction period, i.e., the next control cycle or several future control cycles, and substitute them into the prediction expression constructed above. Since the external covariates for the prediction period may not have all actually occurred at the prediction time, this application can obtain these external covariates in several ways. The first method is to utilize real-time or short-term held values from online sensors and the control system. For variables that change slowly or have a high sampling frequency, such as DO, MLSS, pH, water temperature, and current influent flow rate, the detection value at the most recent sampling time, the moving average of the most recent several sampling times, or the exponentially smoothed value can be used as the estimated external covariate value for the next control cycle. The second method is to obtain future covariate values through independent short-term prediction models, such as using ARIMA models, exponentially smoothed models, random forest regression models, long short-term memory network models, or similar day models based on historical time-series curves to predict variables such as influent flow rate, influent COD, influent TN, and influent ammonia nitrogen for future periods. The third method involves directly acquiring data from external systems or plans. For example, future rainfall or weather type can be obtained from a meteorological service interface; planned water intake, pump station operation plans, or process setpoints can be obtained from a plant dispatching system; and setpoints that have been issued or are about to be executed in future control cycles can be obtained from a SCADA system. These methods can be used individually or in combination. When a covariate has multiple sources, the system can weight and fuse them according to preset priorities or confidence levels to obtain the final external covariate for the prediction period.
[0079] In one specific implementation, the system can configure data source priorities for each external covariate. For example, rainfall data is prioritized from meteorological forecast interface data; if the meteorological interface is unavailable, the recent period's held-off rainfall value is used. Influent flow rate is prioritized from pump station scheduling plans or short-term flow prediction model outputs; if the prediction model is unavailable, the moving average of the most recent several periods is used. Water quality indicators such as influent COD and influent TN are prioritized from online instrument short-term prediction results; if online instrument data is missing, interpolated laboratory test data or historical averages for the same period are used. After obtaining the external covariates for the prediction period, the system can also perform time alignment, missing value imputation, outlier limiting, and normalization processing identical to that in the historical modeling stage to ensure that the data scale substituted into the prediction expression remains consistent with that in the model training stage. Through the above processing, the external covariates for the prediction period can be clearly and completely obtained, thereby ensuring that the ARIMAX prediction steps can be implemented.
[0080] Optionally, the step of performing parameter fitting operations on the target ARIMAX model to obtain autoregressive coefficients, moving average coefficients, and exogenous variable coefficients includes: establishing a conditional log-likelihood function based on the mathematical expression of the target ARIMAX model to obtain an objective function with the autoregressive coefficients, the moving average coefficients, and the exogenous variable coefficients as undetermined parameters; performing iterative solutions on the objective function using a preset numerical optimization algorithm to obtain optimal parameters that maximize the value of the objective function; using the optimal parameters as the final parameters of the ARIMAX model, and determining the autoregressive coefficients, the moving average coefficients, and the exogenous variable coefficients from the optimal parameters.
[0081] In a more specific embodiment of this application, a rigorous method based on statistical principles is employed in the parameter fitting process of the target ARIMAX model. The first step of this process is to construct an objective function for evaluating the quality of the parameters. Specifically, the system first establishes a conditional log-likelihood function for the given weighted target sequence and weighted external covariates based on the standard mathematical expression of the ARIMAX model. The core idea of this function is to measure the probability of observing the current set of historical data under a specific set of undetermined parameters. In this function, the autoregressive coefficient, moving average coefficient, and exogenous variable coefficient are set as unknown variables to be solved. Therefore, this conditional log-likelihood function constitutes the objective function of this parameter fitting process, and the purpose of subsequent optimization is to find the set of parameters that maximizes the value of this function.
[0082] Furthermore, after establishing the objective function, the system enters an iterative solution phase to find the optimal parameters. Since the objective function is typically nonlinear and difficult to solve directly analytically, the system employs a pre-defined numerical optimization algorithm to perform this task. Such algorithms may include, but are not limited to, the Broyden-Fletcher-Goldfarb-Shanno algorithm (BFGS), or other similar quasi-Newton methods, gradient descent methods, etc. When the algorithm starts, it assigns a set of initial values to the parameters to be determined, and then determines a search direction that maximizes the function value by calculating the gradient or approximate gradient of the objective function. Next, it iteratively advances along this direction, continuously updating the parameter values in each iteration, and repeating this process until a pre-defined convergence condition is met, such as the increment of the objective function value being less than a very small threshold, or the number of iterations reaching its upper limit. When the algorithm converges, the resulting set of parameter values represents the optimal parameter combination that maximizes the conditional log-likelihood function.
[0083] Furthermore, after the numerical optimization algorithm converges and outputs the optimal parameter combination, the system completes the final parameter determination. This set of optimal parameters best mathematically characterizes the dynamic law of carbon source addition under the current dataset, and the system will formally adopt it as the final parameters of the target ARIMAX model. Since this set of optimal parameters is a collection containing all coefficients to be solved, the system will accurately analyze and separate each part according to a predetermined structure. Specifically, the system will extract the values corresponding to the autoregressive term as the final autoregressive coefficients; extract the values corresponding to the moving average term as the final moving average coefficients; and extract the values corresponding to each external covariate as the final exogenous variable coefficients. At this point, a fully configured and sufficiently trained ARIMAX model is completed and can be used for subsequent prediction calculations.
[0084] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0085] This embodiment also discloses an electronic device, as shown in the reference. Figure 3 The electronic device may include: at least one processor 301, at least one communication bus 302, user interface 303, network interface 304, and at least one memory 305.
[0086] The communication bus 302 is used to enable communication between these components.
[0087] The user interface 303 may include a display screen and a camera. Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.
[0088] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0089] The processor 301 may include one or more processing cores. The processor 301 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 305, and by calling data stored in memory 305. Optionally, the processor 301 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 301 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 301 and may be implemented as a separate chip.
[0090] The memory 305 may include random access memory (RAM) or read-only memory. Optionally, the memory 305 may include a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 305 may also be at least one storage device located remotely from the aforementioned processor 301. Figure 3 As shown, the memory 305, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program relating to a method for predicting carbon source dosing in a wastewater treatment plant.
[0091] exist Figure 3 In the electronic device shown, the user interface 303 is mainly used to provide an input interface for the user and to obtain the user input data; while the processor 301 can be used to call the application program stored in the memory 305 that relates to a method for predicting carbon source dosing in a wastewater treatment plant. When executed by one or more processors 301, the electronic device performs one or more methods as described in the above embodiments.
[0092] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0093] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the shown or discussed mutual couplings or direct couplings or communication connections may be through some service interfaces; indirect couplings or communication connections between apparatuses or units may be electrical or other forms.
[0094] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0095] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory 305 and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned memory 305 includes various media capable of storing program code, such as a USB flash drive, external hard drive, magnetic disk, or optical disk.
[0096] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will be readily apparent to those skilled in the art upon consideration of the disclosure in this specification. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A method for predicting carbon source dosing in wastewater treatment plants, characterized in that, Applied to a server, the method includes: Obtain historical operating data of wastewater treatment plants that include historical carbon source injection target sequences and multidimensional external covariates; According to the preset weight adjustment strategy, corresponding dynamic attention weights are generated for each historical time step of the target sequence of historical carbon source addition and each covariate dimension of the multidimensional external covariate. Extract weight distribution features from all the dynamic attention weights; Based on the weight distribution characteristics and the preset order mapping rules, the target autoregression order and the target moving average order are determined. The dynamic attention weights are applied to the historical carbon source injection target sequence and the multidimensional external covariates to generate a weighted target sequence and a weighted external covariate, respectively. The weighted target sequence and the weighted external covariates are input into a preset ARIMAX model, and the order parameters of the ARIMAX model are set to the target autoregressive order and the target moving average order to obtain the predicted value of carbon source addition.
2. The method according to claim 1, characterized in that, The step of generating corresponding dynamic attention weights for each historical time step of the historical carbon source injection target sequence and each covariate dimension of the multidimensional external covariates according to a preset weight adjustment strategy includes: Assign a preset baseline weight value to each of the covariate dimensions and each of the historical time steps; The actual values of the covariate dimension are compared with the triggering conditions of the working conditions defined in the preset working condition event library; When the actual value matches the triggering condition of the operating condition event, the target operating condition event is identified and marked. Based on the target operating condition event, retrieve the weight adjustment strategy corresponding to the target operating condition event from the preset weight adjustment strategy set; According to the weight adjustment strategy, the baseline weight values corresponding to the covariate dimensions associated with the target working condition event are modified; Normalization is performed on all the modified baseline weight values to obtain the corresponding dynamic attention weights.
3. The method according to claim 1, characterized in that, The step of extracting weight distribution features from all the dynamic attention weights includes: Based on the maximum and minimum values of the dynamic attention weights, the numerical range of the dynamic attention weights is calculated, and the numerical range is divided into multiple weight distribution intervals at equal intervals. The distribution of the number of dynamic attention weights within each weight distribution interval is statistically analyzed to obtain the histogram features of the weights; Based on the histogram features, the weight concentration index of the dynamic attention weight is calculated using a preset information entropy calculation formula. The number of weights in the dynamic attention weights whose values are greater than a preset weight threshold is counted to obtain the weight span index; The weight distribution characteristics are constructed based on the weight concentration index and the weight span index.
4. The method according to claim 3, characterized in that, The step of determining the target autoregressive order and the target moving average order based on the weight distribution characteristics and the preset order mapping rule includes: The weight concentration index and the weight span index in the weight distribution feature are weighted and fused to generate a fused feature vector; In the order mapping rule, multiple feature intervals are traversed, and the Euclidean distance between the fused feature vector and the center coordinates of each feature interval is calculated. Based on the relationship of the Euclidean distances, the target feature interval with the smallest Euclidean distance is selected, and the initial autoregressive order and the initial moving average order associated with the target feature interval are extracted from the order mapping rule. Based on the length constraint of the historical carbon source injection target sequence and the initial autoregressive order and the initial moving average order, the validity of the order is verified and adjusted to obtain the target autoregressive order and the target moving average order.
5. The method according to claim 1, characterized in that, The application of the dynamic attention weights to the historical carbon source injection target sequence and the multidimensional external covariates generates a weighted target sequence and weighted external covariates, respectively, including: Based on the mapping relationship between the dynamic attention weights and the historical time steps and the covariate dimensions, the dynamic attention weights are decomposed into a target sequence weight subset and an external covariate weight subset, wherein the target sequence weight subset contains weight values associated with each historical time step, and the external covariate weight subset contains weight values associated with each covariate dimension. The weighted target sequence is obtained by multiplying the value of each historical time step in the target sequence with the weight value corresponding to the historical time step in the target sequence weight subset element by element. The weighted external covariate is obtained by performing element-wise multiplication of the value of each covariate dimension in the multidimensional external covariate with the weight value corresponding to the covariate dimension position in the external covariate weight subset.
6. The method according to claim 1, characterized in that, The step of inputting the weighted target sequence and the weighted external covariates into a preset ARIMAX model, and setting the order parameters of the ARIMAX model to the target autoregressive order and the target moving average order, to obtain the predicted carbon source injection amount, includes: The target autoregression order, the preset integral difference order, and the target moving average order are configured into the ARIMAX model to obtain the initialized ARIMAX model. The weighted target sequence is used as an endogenous variable and the weighted external covariate is used as an exogenous variable. These are then input into the initial ARIMAX model to obtain the target ARIMAX model. Perform parameter fitting operations on the target ARIMAX model to obtain autoregressive coefficients, moving average coefficients, and exogenous variable coefficients; A prediction expression is constructed based on the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient; The external covariates of the preset prediction period are substituted into the prediction expression to perform calculations and obtain the predicted value of the carbon source addition.
7. The method according to claim 6, characterized in that, The parameter fitting operation performed on the target ARIMAX model yields autoregressive coefficients, moving average coefficients, and exogenous variable coefficients, including: Based on the mathematical expression of the target ARIMAX model, a conditional log-likelihood function is established to obtain the objective function with the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient as undetermined parameters. The objective function is iteratively solved using a preset numerical optimization algorithm to obtain the optimal parameters that maximize the value of the objective function. The optimal parameters are used as the final parameters of the ARIMAX model, and the autoregressive coefficient, the moving average coefficient, and the exogenous variable coefficient are determined from the optimal parameters.
8. An electronic device, characterized in that, The device includes a processor, a memory, a user interface, and a network interface. The memory is used to store instructions. The user interface and the network interface are both used to communicate with other devices. The processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the method as described in any one of claims 1-7.
10. A computer program product, characterized in that, When the computer program product is run on an electronic device, it causes the electronic device to perform the method as described in any one of claims 1-7.