Water quality prediction method, device and electronic equipment
By integrating physical mechanisms and data-driven methods, multi-source heterogeneous water quality time-series data are generated and subjected to feature screening and normalization. This solves the problems of weak generalization ability and poor physical consistency in water quality prediction under non-stationary environments, and achieves higher prediction accuracy and robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TSINGHUA UNIVERSITY
- Filing Date
- 2026-02-05
- Publication Date
- 2026-06-05
AI Technical Summary
Existing water quality prediction methods have weak generalization ability and poor physical consistency in prediction results when facing non-stationary environments. They are also difficult to adapt to the drift in water quality data distribution caused by seasonal changes, climate change, and human pollution.
By integrating physical mechanisms and data-driven methods, multi-source heterogeneous water quality time-series data are generated. Input features are screened and normalized, multilayer perceptrons are used for prediction, and inverse normalization is performed to restore the original physical scale.
This enhances the model's adaptability to non-stationary environments and improves the accuracy, robustness, and interpretability of water quality predictions.
Smart Images

Figure CN122153292A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of water quality monitoring technology, and in particular to a water quality prediction method, device and electronic equipment. Background Technology
[0002] Water quality is directly related to ecological security and human health. Accurate and timely water quality forecasting is a crucial foundation for achieving refined water environment management and pollution control. Currently, water quality forecasting methods can be mainly divided into two categories: mechanistic models and data-driven models.
[0003] In related technologies, mechanistic models (such as WASP and EFDC) establish differential equations or systems of equations based on theories of hydrodynamics and biogeochemistry to characterize the migration and transformation processes of pollutants. While these models have clear physical meanings, they typically require a large number of parameters and boundary conditions, resulting in complex modeling, high computational costs, and limited adaptability to sudden pollution events and complex nonlinear relationships. Data-driven models achieve predictions by learning statistical patterns from historical monitoring data; however, most of these methods rely on the assumption that training and test data follow the same independent and identically distributed distribution. In reality, influenced by factors such as seasonal changes, climate change, and human-caused pollution, the distribution of water quality data often undergoes statistical characteristic drift over time (i.e., non-stationarity), leading to a sharp decline in the model's generalization performance under non-stationary environments. Summary of the Invention
[0004] The purpose of this application is to provide a water quality prediction method, device, and electronic device that enhances the model's adaptability to non-stationary environments and improves the accuracy, robustness, and interpretability of water quality prediction by deeply integrating physical mechanisms with data-driven methods.
[0005] This application provides a water quality prediction method, including: Hydrological and meteorological data of the target water area are acquired, and multi-source heterogeneous water quality time-series data are generated based on the hydrological and meteorological data. Input feature screening is performed on the multi-source heterogeneous water quality time-series data to extract input features with robust physical correlations, and time-series input data is generated based on the extracted input features. The time-series input data is input into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model for future periods. The water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data and then input it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
[0006] Optionally, generating multi-source heterogeneous water quality time-series data based on the hydrological data and the meteorological data includes: performing time alignment processing on the acquired multi-source data with different sampling frequencies, resampling the multi-source data with different frequencies to the same preset time interval to obtain timestamp-aligned standardized time-series data; performing outlier detection on each variable in the standardized time-series data and deleting the detected outliers; and imputing missing values in the standardized time-series data after deleting outliers according to a preset data imputation method to obtain the multi-source heterogeneous water quality time-series data; wherein, the preset data imputation method includes: using linear interpolation to imput missing data in the middle part of the sequence, and using the nearest valid value method to imput missing data at the beginning and end of the sequence.
[0007] Optionally, the step of performing outlier detection on each variable in the standardized time series data and deleting the detected outliers includes: calculating the upper quartile and lower quartile of any target data sequence within a preset time period, and calculating the interquartile range of the target data sequence based on the difference between the lower quartile and the upper quartile; determining the lower limit of the outlier of the target data sequence based on the interquartile range and the upper quartile, and determining the upper limit of the outlier of the target data sequence based on the interquartile range and the lower quartile; identifying data points in the target data sequence that are outside the numerical range corresponding to the lower limit and the upper limit of the outlier as outliers and deleting them from the target data sequence; wherein, the target data sequence is the time series data corresponding to any variable in the standardized time series data.
[0008] Optionally, the step of filtering input features from the multi-source heterogeneous water quality time series data and extracting input features with robust physical correlations includes: calculating the global correlation index and time stability index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature in the multi-source heterogeneous water quality time series data and the target water quality variable; and determining the candidate features in the multi-source heterogeneous water quality time series data that satisfy the global correlation threshold and the time stability threshold as input features.
[0009] Optionally, the step of calculating the global correlation index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature and the target water quality variable in the multi-source heterogeneous water quality time series data includes: calculating the rank correlation coefficient between the target candidate feature and the target water quality variable based on the rank of any target candidate feature and the target water quality variable in the time series corresponding to the multi-source heterogeneous water quality time series data; and determining the absolute value of the rank correlation coefficient between the target candidate feature and the target water quality variable as the global correlation index corresponding to the target water quality variable.
[0010] Optionally, the step of calculating the time stability index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature and the target water quality variable in the multi-source heterogeneous water quality time series data includes: dividing the multi-source heterogeneous water quality time series data into multiple time periods, and calculating the rank correlation coefficient between the target candidate feature and the target water quality variable in each time period to obtain multiple rank correlation coefficients corresponding to the target candidate feature; calculating the mean and standard deviation of the multiple rank correlation coefficients corresponding to the target candidate feature, and calculating the coefficient of variation based on the ratio of the obtained standard deviation to the mean; transforming the coefficients to obtain the time stability index corresponding to the target candidate feature; wherein the time stability index is negatively correlated with the standard deviation and positively correlated with the mean.
[0011] Optionally, the step of inputting the time-series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable in future time periods output by the water quality prediction model includes: calculating the mean and standard deviation of each variable along the time axis for the time-series input data, and performing normalization processing on the time-series input data based on the mean and standard deviation of each variable; flattening the normalized time-series input data along the feature dimension, and inputting the obtained one-dimensional vector into the multilayer perceptron of the water quality prediction model to obtain the predicted value of the target water quality variable in each time period in the future multiple time periods under the normalization space; and performing inverse normalization processing on the obtained predicted value based on the mean and standard deviation of the target water quality variable to obtain the predicted value sequence of the target water quality variable in the future multiple time periods.
[0012] This application also provides a water quality prediction device, comprising: The data processing module is used to acquire hydrological and meteorological data of the target water area and generate multi-source heterogeneous water quality time series data based on the hydrological and meteorological data; the feature filtering module is used to filter the input features of the multi-source heterogeneous water quality time series data, extract input features with robust physical correlations, and generate time series input data based on the extracted input features; the water quality prediction module is used to input the time series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model in the future period; wherein, the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data and then input it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
[0013] Optionally, the data processing module is specifically used to perform time alignment processing on the acquired multi-source data with different sampling frequencies, resample the multi-source data with different frequencies to the same preset time interval, and obtain timestamp-aligned standardized time series data; the data processing module is also specifically used to perform outlier detection on each variable in the standardized time series data and delete the detected outliers; the data processing module is also specifically used to fill in missing values in the standardized time series data after deleting outliers according to a preset data filling method to obtain the multi-source heterogeneous water quality time series data; wherein, the preset data filling method includes: using linear interpolation to fill in missing data in the middle part of the sequence, and using the nearest valid value method to fill in missing data at the beginning and end of the sequence.
[0014] Optionally, the data processing module is specifically used to calculate the upper quartile and lower quartile of any target data sequence within a preset time period, and to calculate the interquartile range of the target data sequence based on the difference between the lower quartile and the upper quartile; the data processing module is further used to determine the lower limit of the outlier of the target data sequence based on the interquartile range and the upper quartile, and to determine the upper limit of the outlier of the target data sequence based on the interquartile range and the lower quartile; the data processing module is further used to identify data points in the target data sequence that are outside the numerical range corresponding to the lower limit and the upper limit of the outlier as outliers, and to delete them from the target data sequence; wherein, the target data sequence is the time series data corresponding to any variable in the standardized time series data.
[0015] Optionally, the feature filtering module is specifically used to calculate the global correlation index and time stability index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature in the multi-source heterogeneous water quality time series data and the target water quality variable; the feature filtering module is also specifically used to determine the candidate features in the multi-source heterogeneous water quality time series data that meet the global correlation threshold and the time stability threshold as input features.
[0016] Optionally, the feature filtering module is further configured to calculate the rank correlation coefficient between the target candidate feature and the target water quality variable based on the rank of any target candidate feature and the target water quality variable on the time series corresponding to the multi-source heterogeneous water quality time series data; the feature filtering module is further configured to determine the absolute value of the rank correlation coefficient between the target candidate feature and the target water quality variable as the global correlation index corresponding to the target water quality variable.
[0017] Optionally, the feature selection module is further configured to divide the multi-source heterogeneous water quality time series data into multiple time periods, and calculate the rank correlation coefficient between the target candidate feature and the target water quality variable in each time period to obtain multiple rank correlation coefficients corresponding to the target candidate feature; the feature selection module is further configured to calculate the mean and standard deviation of the multiple rank correlation coefficients corresponding to the target candidate feature, and calculate the coefficient of variation based on the ratio of the obtained standard deviation to the mean; the feature selection module is further configured to transform the coefficients to obtain the time stability index corresponding to the target candidate feature; wherein, the time stability index is negatively correlated with the standard deviation and positively correlated with the mean.
[0018] Optionally, the water quality prediction module is specifically used to calculate the mean and standard deviation of each variable along the time axis of the time-series input data, and perform normalization processing on the time-series input data based on the mean and standard deviation of each variable; the water quality prediction module is further used to flatten the normalized time-series input data along the feature dimension, and input the obtained one-dimensional vector into the multilayer perceptron of the water quality prediction model to obtain the predicted value of the target water quality variable in each time period in the future under the normalization space; the water quality prediction module is further used to perform inverse normalization processing on the obtained predicted value based on the mean and standard deviation of the target water quality variable to obtain the predicted value sequence of the target water quality variable in the future.
[0019] This application also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of any of the water quality prediction methods described above.
[0020] This application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the above-described water quality prediction methods.
[0021] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above-described water quality prediction methods.
[0022] The water quality prediction method, apparatus, and electronic equipment provided in this application first acquire hydrological and meteorological data of the target water area, and generate multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data; then, the multi-source heterogeneous water quality time-series data undergoes input feature screening to extract input features with robust physical correlations, and time-series input data is generated based on the extracted input features; finally, the time-series input data is input into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable for future periods output by the water quality prediction model; wherein, the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data before inputting it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. Thus, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, improving the accuracy, robustness, and interpretability of water quality prediction. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 This is a flowchart illustrating the water quality prediction method provided in this application; Figure 2 This is a flowchart illustrating the water quality prediction model provided in this application; Figure 3 This is a schematic diagram of the water quality prediction device provided in this application; Figure 4 This is a schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0026] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, "and / or" in the specification and claims indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship. All actions involving the acquisition of signal information or data in this application are performed in accordance with the relevant data protection laws and policies of the country where the application is located and with authorization from the owner of the relevant device.
[0027] To address the aforementioned technical problems in related technologies, this application provides a water quality prediction method that integrates physical mechanisms to solve the issues of weak generalization ability and poor physical consistency of prediction results in data-driven models when faced with water quality data distribution drift. This method deeply integrates physical mechanisms with data-driven methods, enhancing the model's adaptability to non-stationary environments and improving the accuracy, robustness, and interpretability of water quality predictions.
[0028] The water quality prediction method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0029] like Figure 1 As shown in the embodiment of this application, a water quality prediction method is provided, which may include the following steps 101 to 103: Step 101: Obtain hydrological and meteorological data of the target water area, and generate multi-source heterogeneous water quality time series data based on the hydrological and meteorological data.
[0030] For example, before making water quality predictions for a target water area, it is necessary to obtain hydrological and meteorological data of the target water area, construct a multi-source heterogeneous water quality dataset, and perform time alignment, outlier processing, and missing value imputation on the data.
[0031] For example, in this embodiment of the application, multi-source heterogeneous time-series data can be collected simultaneously from online monitoring systems, hydrological stations, and meteorological stations in the target water area. Hydrological data includes: water temperature, pH value, conductivity, dissolved oxygen, turbidity, permanganate index, ammonia nitrogen, total phosphorus, and total nitrogen; meteorological data includes: atmospheric temperature, dew point temperature, sea level pressure, wind speed, wind direction, and precipitation.
[0032] For example, time alignment processing is performed on the acquired multi-source data with different sampling frequencies, and the data is uniformly resampled to the same preset time interval to form a standardized time series dataset with strictly aligned timestamps.
[0033] Specifically, step 101 above may also include the following steps: 101a, 101b and 101c: Step 101a: Perform time alignment processing on the acquired multi-source data with different sampling frequencies, resample the multi-source data with different frequencies to the same preset time interval, and obtain standardized time-series data with timestamp alignment.
[0034] Step 101b involves detecting outliers for each variable in the standardized time series data and deleting the detected outliers.
[0035] Specifically, step 101b above may also include steps 101b1 to 101b3: Step 101b1: Calculate the upper quartile and lower quartile of any target data sequence within a preset time period, and calculate the interquartile range of the target data sequence based on the difference between the lower quartile and the upper quartile.
[0036] Step 101b2: Determine the lower limit of the anomaly of the target data sequence based on the interquartile range and the upper quartile, and determine the upper limit of the anomaly of the target data sequence based on the interquartile range and the lower quartile.
[0037] Step 101b3: Determine data points in the target data sequence that are outside the numerical range corresponding to the lower and upper limits of the anomaly as outliers, and delete them from the target data sequence.
[0038] The target data sequence is the time series data corresponding to any variable in the standardized time series data.
[0039] For example, in this embodiment of the application, the upper quartile (Q1) and lower quartile (Q3) of each data sequence within a preset time period can be calculated, and the interquartile range IQR = Q3 - Q1 can be obtained. The lower limit of outliers is defined as Q1 - 1.5 × IQR, and the upper limit is Q3 + 1.5 × IQR. Any data point that is less than the lower limit or greater than the upper limit is marked as an outlier and removed.
[0040] Step 101c: Fill in the missing values in the standardized time series data after deleting outliers using a preset data filling method to obtain the multi-source heterogeneous water quality time series data.
[0041] The preset data filling method includes: using linear interpolation to fill missing data in the middle part of the sequence, and using the nearest valid value method to fill missing data at the beginning and end of the sequence.
[0042] For example, missing values generated after processing, as well as missing values existing in the original data, are filled using linear interpolation; for missing values at the beginning or end of the sequence, the most recent valid value is used to fill in the missing values, so as to obtain complete and continuous time series data. This completes the data acquisition and preprocessing, after which the input features can be filtered.
[0043] Step 102: Filter the input features of the multi-source heterogeneous water quality time series data, extract input features with robust physical correlations, and generate time series input data based on the extracted input features.
[0044] For example, in this embodiment of the application, features can be selected by calculating the global relevance index and time stability index of each candidate feature. Each variable can be used as a candidate feature.
[0045] Specifically, step 102 above, the calculation of the global correlation index, may further include the following steps 102a1 and 102a2: Step 102a1: Based on the rank of any target candidate feature and the target water quality variable in the time series corresponding to the multi-source heterogeneous water quality time series data, calculate the rank correlation coefficient between the target candidate feature and the target water quality variable.
[0046] Step 102a2: Determine the absolute value of the rank correlation coefficient between the target candidate feature and the target water quality variable as the global correlation index corresponding to the target water quality variable.
[0047] For example, for each candidate feature With total nitrogen The Spearman correlation coefficient is calculated based on the rank of the two data points in the time series, as shown in Formula 1 below: (Formula 1) in, , Representing candidate features respectively With the target water quality variables At the point of time rank, and It is the mean of the corresponding rank. That is the total number of samples.
[0048] Therefore, the global relevance index can be defined as shown in Formula 2 below: (Formula 2) For example, according to the above formula, The larger the value, the stronger the correlation between the candidate feature and the target water quality variable, and the greater its predictive potential.
[0049] Specifically, in step 102 above, the calculation of the time stability index may further include the following steps 102b1 to 102b3: Step 102b1: Divide the multi-source heterogeneous water quality time series data into multiple time periods, and calculate the rank correlation coefficient between the target candidate feature and the target water quality variable in each time period to obtain multiple rank correlation coefficients corresponding to the target candidate feature.
[0050] Step 102b2: Calculate the mean and standard deviation of multiple rank correlation coefficients corresponding to the target candidate features, and calculate the coefficient of variation based on the ratio of the obtained standard deviation to the mean.
[0051] Step 102b3: Transform the coefficients to obtain the time stability index corresponding to the target candidate feature.
[0052] Among them, the time stability index is negatively correlated with the standard deviation and positively correlated with the mean.
[0053] For example, multi-source heterogeneous water quality time-series data is divided into K consecutive time periods. In each time period... Internal, independent computational features With total nitrogen Spearman correlation coefficient of (i.e., the target water quality variables mentioned above) Then calculate this The mean of the correlation coefficients and standard deviation The specific formula is shown in Formula 3 below: (Formula 3) Therefore, its coefficient of variation can be calculated as shown in Formula 4 below: (Formula 4) For example, by transforming the coefficient of variation, a time stability index can be defined as shown in Formula 5 below: (Formula 5) For example, according to the above formula, The smaller, The larger, the better The larger the value, the smaller the fluctuation in the association pattern between the candidate feature and the target water quality variable over different time periods, and the better its temporal stability.
[0054] For example, after obtaining the two metrics for each candidate feature, a dual threshold can be set based on these metrics for feature selection, namely: a global relevance threshold. and time stability threshold If and only if the feature Simultaneously satisfy and Only when this condition is met is it selected as an input feature for predicting total nitrogen, in order to retain predictors with robust physical correlations.
[0055] It is understood that in the embodiments of this application, the global correlation index of the candidate feature can be calculated by using the rank of the candidate feature and the target water quality variable over the entire time series; while for the time stability index, the entire time series is divided into multiple time periods, and the time stability index of the candidate feature is calculated based on the rank of the candidate feature and the target water quality variable over each time period.
[0056] Step 103: Input the time series input data into the pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model in the future time period.
[0057] The water quality prediction model is configured to: perform normalization processing on the input data to remove non-stationary background, then input the data into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
[0058] For example, the target water quality variable can be any variable that needs to be predicted, such as total nitrogen content.
[0059] Specifically, step 103 above may also include steps 103a1 to 103a3: Step 103a1: Calculate the mean and standard deviation of each variable along the time axis for the time series input data, and perform normalization processing on the time series input data based on the mean and standard deviation of each variable.
[0060] Step 103a2: Flatten the normalized time-series input data along the feature dimension, and input the resulting one-dimensional vector into the multilayer perceptron of the water quality prediction model to obtain the predicted value of the target water quality variable in each time period in the future under the normalized space.
[0061] Step 103a3: Based on the mean and standard deviation of the target water quality variable, perform inverse normalization on the obtained predicted values to obtain a sequence of predicted values for the target water quality variable in multiple future time periods.
[0062] For example, before inputting the time-series input data into the model, each input sample needs to be normalized independently. This normalization process specifically includes: For a multivariable input sequence , Indicates the length of the input time series. This represents the number of variables after feature selection, calculated along the time axis for each variable channel. The mean and standard deviation are shown in Formula 6 below: (Formula 6) Subsequently, the input sequence is standardized using the calculated statistics, which can be achieved through the following formula seven: (Formula 7) in, It should be a very small positive value to prevent division by zero errors. and These are learnable transformation parameters.
[0063] For example, after normalization, the data can be input into a water quality prediction model to predict the target water quality variable. The aforementioned water quality prediction model is a pre-trained model, and its structure is as follows: Figure 2 As shown, the backbone network is a multilayer perceptron, and the design of each part of the multilayer perceptron backbone network is as follows: Input and flattening: Normalized sequence Flatten along the feature dimension to form a one-dimensional vector As input to a multilayer perceptron.
[0064] Network Structure: The network consists of an input layer, a hidden layer, and an output layer connected sequentially. Each layer comprises a linear transformation (fully connected) followed by a ReLU activation function, calculated as follows: in, and These represent the weight matrices and bias terms for each layer. The introduction of the ReLU activation function provides the model with the necessary nonlinear fitting capability.
[0065] Output: The network output That is, in a normalized space, regarding the future Predicted sequences of target water quality variables at each time step.
[0066] For example, after obtaining the prediction results output by the water quality prediction model, in order to restore the predicted values to the original data scale, the mean value calculated for total nitrogen during normalization is used. Standard deviation and transformation parameters Inverse normalization can be achieved using the following formula: (Formula 8) The final result This refers to the predicted value of the target water quality variable that has original physical meaning.
[0067] Optionally, in this embodiment, the training of the aforementioned water quality prediction model can be achieved by establishing a multi-source heterogeneous dataset using acquired historical hydrological and meteorological data, and dividing it into a training set, a validation set, and a test set in a 7:1:2 ratio. Features selected through feature filtering are input into the constructed deep learning model, and a joint time-frequency domain loss function is used to guide model training. All experiments are conducted within the PyTorch deep learning framework.
[0068] For example, the joint time-frequency domain loss function is calculated as shown in Equation Nine below: (Formula Nine) in, These represent the sequences of actual values and predicted values, respectively. This represents the Fast Fourier Transform (FFT), used to map a time-domain signal to the frequency domain. Hyperparameters Used to dynamically weigh the proportion of the two losses in the total loss.
[0069] For example, the above The mean squared error loss in the time domain ensures that the predicted sequence is as close as possible to the true value in numerical terms, which is the basis for prediction accuracy.
[0070] The frequency domain average absolute error loss is achieved by comparing the differences between the real and imaginary parts of the Fourier transform of the real and predicted sequences, thus constraining their consistency in periodicity and variation patterns.
[0071] For example, the model training uses the Adam optimizer, with an input time span of the past 36 hours (i.e., 9 time steps), predicting the total nitrogen concentration for the next 72 hours (i.e., 18 time steps). During training, an early stopping strategy is implemented based on the validation set loss to avoid overfitting. Training stops when the validation set loss does not decrease for 50 consecutive periods, indicating model convergence. The hyperparameters set are shown in Table 1 below: Table 1
[0072] For example, the test set data is input into the trained model, which outputs predicted total nitrogen concentrations for the next 72 hours. To comprehensively evaluate model performance, four widely used regression metrics are used to quantify prediction error and goodness of fit: root mean square error (RMSE, which penalizes large errors), mean absolute error (MAE, which captures the average magnitude), mean percentage error (MAPE, which provides scale-invariant relative error), and coefficient of determination (R²). 2 (Quantitative explanation of variance).
[0073] in, These represent the actual value and the predicted value, respectively.
[0074] In addition, to comprehensively evaluate the model performance, representative models in the field of time series forecasting were selected as baseline models for comparison with the model proposed in this method, including: the efficient linear regression model DLinear; recurrent neural network series models: basic recurrent neural network (RNN) and long short-term memory network (LSTM), which capture the dependencies between sequences through gating mechanisms; and Transformer series models: Informer and PatchTST, which are advanced models based on attention mechanisms, respectively improving long-term forecasting ability through ProbSparse self-attention and sequence patching.
[0075] The performance of the framework proposed in this application embodiment was compared with the baseline model on the test set, and the results are shown in Table 2 below. As shown in Table 2, the water quality prediction method provided in this application embodiment significantly outperforms all baseline models on all evaluation indicators, achieving a root mean square error (RMSE) of 0.0798 and a coefficient of determination (R²) of 0.9801. 2 Compared to traditional time series forecasting models (LSTM), our framework reduces the root mean square error by 69.7%, demonstrating the superior ability of our method to capture robust patterns and adapt to distribution drift.
[0076] Table 2
[0077] The proposed framework was compared with the baseline models mentioned above on the test set, and the results are shown in Table 2. As shown in the table, the proposed method significantly outperforms all baseline models on all evaluation metrics, achieving a root mean square error (RMSE) of 0.0798 and a coefficient of determination (R²) of 0.9801. 2Compared to traditional time series forecasting models (LSTM), our framework reduces the root mean square error by 69.7%, demonstrating the superior ability of our method to capture robust patterns and adapt to distribution drift.
[0078] The water quality prediction method provided in this application first acquires hydrological and meteorological data of the target water area, and generates multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data. Then, it filters input features from the multi-source heterogeneous water quality time-series data, extracts input features with robust physical correlations, and generates time-series input data based on the extracted input features. Finally, it inputs the time-series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable for future periods output by the water quality prediction model. The water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data before inputting it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. Thus, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, improving the accuracy, robustness, and interpretability of water quality prediction.
[0079] It should be noted that the water quality prediction method provided in this application can be executed by a water quality prediction device or a control module within that device. This application uses the example of a water quality prediction device executing the water quality prediction method to illustrate the water quality prediction device provided in this application.
[0080] It should be noted that, in the embodiments of this application, the water quality prediction methods shown in the accompanying drawings are all illustrated by way of example with reference to one of the accompanying drawings in the embodiments of this application. In specific implementation, the water quality prediction methods shown in the accompanying drawings of the above methods can also be implemented in conjunction with any other accompanying drawings shown in the above embodiments, which will not be elaborated here.
[0081] The water quality prediction device provided in this application is described below, and the water quality prediction method described below can be referred to in correspondence with the water quality prediction method described above.
[0082] Figure 3 This is a schematic diagram of the structure of the water quality prediction device provided in the embodiments of this application, as shown below. Figure 3 As shown, it specifically includes: The data processing module 301 is used to acquire hydrological and meteorological data of the target water area, and generate multi-source heterogeneous water quality time series data based on the hydrological and meteorological data; the feature filtering module 302 is used to filter the input features of the multi-source heterogeneous water quality time series data, extract input features with robust physical correlations, and generate time series input data based on the extracted input features; the water quality prediction module 303 is used to input the time series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model in the future period; wherein, the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data and then input it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
[0083] Optionally, the data processing module 301 is specifically used to perform time alignment processing on the acquired multi-source data with different sampling frequencies, resample the multi-source data with different frequencies to the same preset time interval, and obtain timestamp-aligned standardized time series data; the data processing module 301 is also specifically used to perform outlier detection on each variable in the standardized time series data and delete the detected outliers; the data processing module 301 is also specifically used to fill in missing values in the standardized time series data after deleting outliers according to a preset data filling method to obtain the multi-source heterogeneous water quality time series data; wherein, the preset data filling method includes: filling in missing data in the middle part of the sequence using linear interpolation, and filling in missing data at the beginning and end of the sequence using the nearest valid value method.
[0084] Optionally, the data processing module 301 is specifically used to calculate the upper quartile and lower quartile of any target data sequence within a preset time period, and to calculate the interquartile range of the target data sequence based on the difference between the lower quartile and the upper quartile; the data processing module 301 is further used to determine the lower limit of the outlier of the target data sequence based on the interquartile range and the upper quartile, and to determine the upper limit of the outlier of the target data sequence based on the interquartile range and the lower quartile; the data processing module 301 is further used to determine data points in the target data sequence that are outside the numerical range corresponding to the lower limit and the upper limit of the outlier as outliers, and to delete them from the target data sequence; wherein, the target data sequence is the time series data corresponding to any variable in the standardized time series data.
[0085] Optionally, the feature filtering module 302 is specifically used to calculate the global correlation index and time stability index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature in the multi-source heterogeneous water quality time series data and the target water quality variable; the feature filtering module 302 is also specifically used to determine the candidate features in the multi-source heterogeneous water quality time series data that meet the global correlation threshold and the time stability threshold as input features.
[0086] Optionally, the feature filtering module 302 is further configured to calculate the rank correlation coefficient between the target candidate feature and the target water quality variable based on the rank of any target candidate feature and the target water quality variable in the time series corresponding to the multi-source heterogeneous water quality time series data; the feature filtering module 302 is further configured to determine the absolute value of the rank correlation coefficient between the target candidate feature and the target water quality variable as the global correlation index corresponding to the target water quality variable.
[0087] Optionally, the feature filtering module 302 is further configured to divide the multi-source heterogeneous water quality time series data into multiple time periods, and calculate the rank correlation coefficient between the target candidate feature and the target water quality variable in each time period to obtain multiple rank correlation coefficients corresponding to the target candidate feature; the feature filtering module 302 is further configured to calculate the mean and standard deviation of the multiple rank correlation coefficients corresponding to the target candidate feature, and calculate the coefficient of variation based on the ratio of the obtained standard deviation to the mean; the feature filtering module 302 is further configured to transform the coefficients to obtain the time stability index corresponding to the target candidate feature; wherein, the time stability index is negatively correlated with the standard deviation and positively correlated with the mean.
[0088] Optionally, the water quality prediction module 303 is specifically used to calculate the mean and standard deviation of each variable along the time axis of the time-series input data, and perform normalization processing on the time-series input data based on the mean and standard deviation of each variable; the water quality prediction module 303 is further used to flatten the normalized time-series input data along the feature dimension, and input the obtained one-dimensional vector into the multilayer perceptron of the water quality prediction model to obtain the predicted value of the target water quality variable in each time period in the future under the normalization space; the water quality prediction module 303 is further used to perform inverse normalization processing on the obtained predicted value based on the mean and standard deviation of the target water quality variable to obtain the predicted value sequence of the target water quality variable in the future.
[0089] The water quality prediction device provided in this application first acquires hydrological and meteorological data of the target water area, and generates multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data; then, it performs input feature filtering on the multi-source heterogeneous water quality time-series data, extracts input features with robust physical correlations, and generates time-series input data based on the extracted input features; finally, it inputs the time-series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable for future periods output by the water quality prediction model; wherein, the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data before inputting it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. Thus, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, improving the accuracy, robustness, and interpretability of water quality prediction.
[0090] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 410, a communications interface 420, a memory 430, and a communications bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other through the communications bus 440. The processor 410 can call logic instructions in the memory 430 to execute a water quality prediction method. This method includes: first, acquiring hydrological and meteorological data of the target water area, and generating multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data; then, filtering input features of the multi-source heterogeneous water quality time-series data to extract input features with robust physical correlations, and generating time-series input data based on the extracted input features; finally, inputting the time-series input data into a pre-trained water quality prediction model to obtain a sequence of predicted values for the target water quality variable in future periods output by the water quality prediction model. The water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data before inputting it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. Thus, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, improving the accuracy, robustness, and interpretability of water quality prediction.
[0091] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium 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 described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0092] On the other hand, this application also provides a computer program product, which includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer is able to execute the water quality prediction method provided by the above methods. The method includes: first, acquiring hydrological data and meteorological data of a target water area, and generating multi-source heterogeneous water quality time series data based on the hydrological data and the meteorological data; then, performing input feature screening on the multi-source heterogeneous water quality time series data, extracting input features with robust physical correlations, and generating time series input data based on the extracted input features; finally, inputting the time series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model for future periods; wherein, the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data and then input it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. In this way, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, and the accuracy, robustness, and interpretability of water quality prediction are improved.
[0093] Furthermore, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the aforementioned water quality prediction methods. The method includes: first, acquiring hydrological and meteorological data of a target water area, and generating multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data; then, filtering input features of the multi-source heterogeneous water quality time-series data to extract input features with robust physical correlations, and generating time-series input data based on the extracted input features; finally, inputting the time-series input data into a pre-trained water quality prediction model to obtain a sequence of predicted values for the target water quality variable in future periods output by the water quality prediction model; wherein the water quality prediction model is configured to: perform normalization processing to remove non-stationary background from the input data before inputting it into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale. Thus, by deeply integrating physical mechanisms with data-driven methods, the model's adaptability to non-stationary environments is enhanced, improving the accuracy, robustness, and interpretability of water quality prediction.
[0094] The device embodiments described above are merely illustrative. 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 modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0095] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A water quality prediction method, characterized in that, include: Acquire hydrological and meteorological data of the target water area, and generate multi-source heterogeneous water quality time-series data based on the hydrological and meteorological data; Input feature filtering is performed on the multi-source heterogeneous water quality time series data to extract input features with robust physical correlations, and time series input data is generated based on the extracted input features; The time-series input data is input into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable in the future time period output by the water quality prediction model. The water quality prediction model is configured to: perform normalization processing on the input data to remove non-stationary background, then input the data into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
2. The method according to claim 1, characterized in that, The generation of multi-source heterogeneous water quality time-series data based on the hydrological data and the meteorological data includes: Time alignment processing is performed on the acquired multi-source data with different sampling frequencies. The multi-source data with different frequencies are resampled to the same preset time interval to obtain standardized time-series data with timestamp alignment. Outlier detection is performed on each variable in the standardized time series data, and the detected outliers are deleted. The standardized time-series data after removing outliers is filled with missing values according to a preset data filling method to obtain the multi-source heterogeneous water quality time-series data. The preset data filling method includes: using linear interpolation to fill missing data in the middle part of the sequence, and using the nearest valid value method to fill missing data at the beginning and end of the sequence.
3. The method according to claim 2, characterized in that, The step of detecting outliers for each variable in the standardized time-series data and deleting the detected outliers includes: Calculate the upper quartile and lower quartile of any target data sequence within a preset time period, and calculate the interquartile range of the target data sequence based on the difference between the lower quartile and the upper quartile. The lower limit of the anomaly of the target data sequence is determined based on the interquartile range and the upper quartile, and the upper limit of the anomaly of the target data sequence is determined based on the interquartile range and the lower quartile. Data points in the target data sequence that fall outside the numerical range corresponding to the lower and upper limits of the anomaly are identified as anomalies and deleted from the target data sequence. The target data sequence is the time series data corresponding to any variable in the standardized time series data.
4. The method according to claim 1, characterized in that, The step of filtering input features from the multi-source heterogeneous water quality time-series data and extracting input features with robust physical correlations includes: Based on the rank correlation coefficient between each candidate feature and the target water quality variable in the multi-source heterogeneous water quality time series data, calculate the global correlation index and time stability index corresponding to each candidate feature; Candidate features that satisfy the global correlation threshold and time stability threshold in the multi-source heterogeneous water quality time series data are determined as input features.
5. The method according to claim 4, characterized in that, The calculation of the global correlation index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature and the target water quality variable in the multi-source heterogeneous water quality time series data includes: Based on the rank of any target candidate feature and the target water quality variable in the time series corresponding to the multi-source heterogeneous water quality time series data, the rank correlation coefficient between the target candidate feature and the target water quality variable is calculated. The absolute value of the rank correlation coefficient between the target candidate feature and the target water quality variable is determined as the global correlation index corresponding to the target water quality variable.
6. The method according to claim 4 or 5, characterized in that, The step of calculating the time stability index corresponding to each candidate feature based on the rank correlation coefficient between each candidate feature in the multi-source heterogeneous water quality time series data and the target water quality variable includes: The multi-source heterogeneous water quality time series data is divided into multiple time periods, and the rank correlation coefficient between the target candidate feature and the target water quality variable is calculated in each time period to obtain multiple rank correlation coefficients corresponding to the target candidate feature. Calculate the mean and standard deviation of multiple rank correlation coefficients corresponding to the target candidate features, and calculate the coefficient of variation based on the ratio of the obtained standard deviation to the mean; The coefficients are transformed to obtain the time stability index corresponding to the target candidate feature; Among them, the time stability index is negatively correlated with the standard deviation and positively correlated with the mean.
7. The method according to claim 1, characterized in that, The step of inputting the time-series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable for future periods output by the water quality prediction model includes: The mean and standard deviation of each variable are calculated along the time axis for the time series input data, and normalization is performed on the time series input data based on the mean and standard deviation of each variable; The normalized time-series input data is flattened along the feature dimension, and the resulting one-dimensional vector is input into the multilayer perceptron of the water quality prediction model to obtain the predicted value of the target water quality variable in each time period in the future under the normalized space. Based on the mean and standard deviation of the target water quality variable, the predicted values are inversely normalized to obtain a sequence of predicted values for the target water quality variable over multiple future time periods.
8. A water quality prediction device, characterized in that, The device includes: The data processing module is used to acquire hydrological and meteorological data of the target water area, and generate multi-source heterogeneous water quality time series data based on the hydrological and meteorological data. The feature filtering module is used to filter the input features of the multi-source heterogeneous water quality time series data, extract input features with robust physical correlations, and generate time series input data based on the extracted input features. The water quality prediction module is used to input the time-series input data into a pre-trained water quality prediction model to obtain the predicted value sequence of the target water quality variable output by the water quality prediction model in the future time period. The water quality prediction model is configured to: perform normalization processing on the input data to remove non-stationary background, then input the data into a multilayer perceptron for prediction, and perform inverse normalization processing on the prediction results to restore them to the original physical scale.
9. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the steps of the water quality prediction method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the steps of the water quality prediction method as described in any one of claims 1 to 7.