A method and device for transferable surface water quality prediction based on representation learning
By constructing a prediction network that integrates water quality and meteorological characteristics using a Transformer model framework based on representation learning, the problem of water quality changes being difficult to predict in existing technologies is solved, enabling more accurate water quality prediction and more effective water environment management.
Patent Information
- Application Number
- CN202510050078.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2045-01-13
AI Technical Summary
Existing water quality models are unable to accurately capture the complex mechanisms of river water quality changes, resulting in a lack of foresight in water pollution prevention and control, and an inability to effectively conduct early warning and proactive management.
A representation-based learning approach is adopted, which constructs a prediction network using the Transformer model framework, extracts feature vectors using water quality and meteorological feature extractors, fuses the feature vectors through an attention mechanism, and combines transfer learning for model training and fine-tuning to establish a transferable surface water quality prediction model.
It has improved the accuracy of predicting water quality changes at river monitoring sections, realized the shift from post-event control to pre-event prevention, and enhanced the predictability of water environment management and the effectiveness of management strategies.
Smart Images

Figure CN120105282B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of water quality monitoring, and particularly relates to a transferable surface water quality prediction method and device based on representation learning. Background Technology
[0002] With the continued growth of the global economy and the rapid increase in population, the shortage of freshwater and clean water resources is becoming increasingly serious, making water resource management and protection crucial. In practice, river water quality management often lacks foresight due to a lack of in-depth understanding of the future trends of key water quality indicators. Accurately predicting the future dynamics of these key indicators would allow for early warning of potential pollution events, thereby strengthening proactive management and prevention measures, which is of great significance for protecting and improving water environmental quality.
[0003] However, current water quality models struggle to capture the complex mechanisms of river water quality changes, while data-driven machine learning or deep learning techniques can effectively capture the nonlinear changes in water quality parameters. With the rapid development of IoT technology, the efficiency of water quality monitoring data collection has improved, and the amount of data has increased significantly, making deep learning technology mainstream and widely used in water environment management. To reduce the complexity of water quality data and improve prediction accuracy, data decomposition methods are widely used for water quality prediction preprocessing. Simultaneously, utilizing spatiotemporal information from multiple sites can enhance the predictive capabilities of the model.
[0004] Patent document CN119129863A discloses a method for predicting river water quality, including the following steps: setting up an automatic water quality station at the starting position of the river section to be predicted to obtain the initial water flow data of the river section to be predicted; dividing the river section to be predicted into multiple sub-prediction sections according to the multiple automatic water quality stations set up within the river section to be predicted; using a preset dynamic grouping model, predicting and grouping the multiple sub-prediction sections according to the initial water flow data of the river section to be predicted and the current water flow data of the multiple sub-prediction sections to obtain a prediction group scheme composed of multiple prediction groups; using a preset river water quality prediction model, predicting the water quality data of each prediction group of the prediction group scheme in a cascade manner according to the initial water flow data of the river section to be predicted and the current water flow data of the prediction group.
[0005] Patent document CN119168176A discloses a multi-site water quality prediction method based on spatiotemporal feature fusion. It models multi-site water quality index data from three perspectives: causality, space, and semantics. For complex water scenarios, it considers more relevant factors. Based on the neural ordinary differential equation, it provides a more interpretable modeling scheme for the water quality propagation process. Compared with traditional neural ordinary differential modeling, it uses a multi-hop propagation method to improve the utilization and propagation rate of information. Summary of the Invention
[0006] The purpose of this invention is to provide a transferable surface water quality prediction method and device based on representation learning. This method predicts key water quality indicators of river monitoring sections in the source region by analyzing changes in water quality information at various stations in the source region, providing a more accurate and comprehensive reference for subsequent water quality management.
[0007] To achieve the first objective of this invention, the following technical solution is provided: a transferable surface water quality prediction method based on representation learning, comprising the following steps:
[0008] Step 1: Obtain historical monitoring data, including historical water quality data and historical meteorological data for each station;
[0009] A multi-site sequence grid is constructed using a timeline and site locations, and the historical monitoring data is filled into the multi-site sequence grid to construct the corresponding dataset;
[0010] In the dataset, the historical monitoring data of each station in the selected target source domain is masked to obtain masked data. The historical monitoring data and the masked data are then combined to form a training and testing set.
[0011] Step 2: Select a Transformer model framework with the same number of source domains to construct a prediction network. The prediction network includes a feature extraction module, a feature fusion module, and a prediction module.
[0012] The feature extraction module includes a water quality feature extractor and a meteorological feature extractor. The water quality feature extractor is used to extract data features from the input water quality data to output a water quality feature vector. The meteorological feature extractor is used to extract data features from the input meteorological data to output a meteorological feature vector.
[0013] The feature fusion module performs dot multiplication of the water quality feature vector and the meteorological feature vector through an attention mechanism to obtain a fused feature vector.
[0014] The prediction module makes predictions based on the input fused feature vectors and outputs the prediction results.
[0015] Step 3: Train the prediction network using the training and testing set: Input the mask data corresponding to all historical water quality data of a source domain into the corresponding Transformer model framework in the upstream and downstream order of the stations. Calculate the loss between the prediction results and the historical water quality data, and adjust the parameter weights in the Transformer model framework based on the loss calculation results. Repeat the adjustment operation to adjust the Transformer model framework corresponding to all source domains.
[0016] The Transformer model framework obtained from all adjustments was fitted using a linear fusion method to obtain the temporal and parameter relationships between different sites in the source domain.
[0017] The temporal and parameter relationships between different stations within the source domain are loaded into the prediction network, and the prediction network is fine-tuned using historical water quality data and historical meteorological data to obtain the prediction model.
[0018] Step 4: Input the water quality data collected at the station and the current day's meteorological data into the prediction model to obtain the water quality data of the source area where the station is located.
[0019] The method of this invention extracts historical water quality information of each station in the source domain by introducing representation learning, and then uses transfer learning to fuse and reorganize this effective information for use in the water quality prediction model of the target station, thereby improving the accuracy of the prediction results of key water quality indicators.
[0020] Specifically, the dataset needs to undergo data preprocessing when historical monitoring data is entered. The data preprocessing includes removing outliers from the historical monitoring data using a four-part difference calculation method, and filling in the positions of the removed outliers using linear interpolation.
[0021] Specifically, before the historical monitoring data is masked, position encoding is performed on the linear function of all stations in a single source domain. The position encoding encodes the historical monitoring data in the time dimension and parameter dimension with a preset time step to obtain encoded data with uniform dimension and format.
[0022] Specifically, the masking process includes one or more of random masking, temporal masking, spatial masking, or parametric masking.
[0023] Specifically, random masking: This strategy is similar to the method used in masked autoencoder models, which randomly masks spatiotemporal data. Its purpose is to capture fine-grained spatiotemporal relationships.
[0024] Temporal masking: In this method, data is masked along the time dimension, forcing the model to reconstruct the data based only on partial temporal information. Its purpose is to improve the model's ability to capture temporal dependencies.
[0025] Spatial masking: This strategy simulates a scenario where data from certain spatial cells is completely lost in time across all instances, reflecting the real-world situation where some sensors may fail to function. The aim is to improve spatial extrapolation capabilities.
[0026] Parameter masking: Parameter masking involves the complete absence of an entire parameter cell block across all instances in time. Due to limitations in context information, the reconstruction task becomes more complex, with the aim of improving the transitivity of water quality parameters.
[0027] Specifically, the parameter weights of the Transformer model framework are adjusted based on the mean square error loss between the prediction results and historical water quality data.
[0028] Specifically, the prediction network is fine-tuned based on the objective function constructed using the coefficient of determination and the root mean square error.
[0029] Specifically, the expression for the objective function is as follows:
[0030]
[0031]
[0032] in, This represents the actual value of the water quality data to be predicted. This represents the predicted value of the water quality data to be predicted. This represents the average of the actual values of the water quality data. Indicates the number of data values in a time series. The coefficient of determination is represented by the coefficient of determination. Root mean square error is expressed as follows.
[0033] Specifically, the meteorological data includes 2-meter air temperature (°C), surface air pressure (Pa), specific humidity (kg / kg), 10-meter wind speed (m / s), downwind shortwave radiation (W / m2), downwind longwave radiation (W / m2), and precipitation (mm / d).
[0034] To achieve the second objective of this invention, the following technical solution is provided: a portable surface water quality prediction device, used to implement the steps of the above-mentioned portable surface water quality prediction method based on representation learning.
[0035] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0036] By extracting and fusing information from various stations in the source domain through representation learning, we can help understand the water quality changes at the target stations and predict the water quality changes at river monitoring sections more accurately. This is of great significance for changing water quality management strategies from "post-event control" to "pre-event prevention" and improving the surface water environment. Attached Figure Description
[0037] Figure 1 A flowchart of the transferable surface water quality prediction method based on representation learning provided in this embodiment;
[0038] Figure 2 This embodiment provides water quality data results for different watersheds as source areas; Detailed Implementation
[0039] Furthermore, the terms "upper," "lower," "inner," "outer," "front," and "rear" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Unless otherwise specifically stated, the relative steps, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the invention.
[0040] Of course, the above description is only a specific embodiment of the present invention and is not intended to limit the scope of the present invention. All equivalent changes or modifications made to the structure, features and principles described in the claims of the present invention should be included in the scope of the claims of the present invention.
[0041] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, 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 the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
[0042] like Figure 1 As shown in this embodiment, a transferable surface water quality prediction method based on representation learning is provided, which includes the following steps:
[0043] Step 1: Obtain historical monitoring data, including historical water quality data and historical meteorological data for each station;
[0044] A multi-site sequence grid is constructed using a timeline and site locations, and the historical monitoring data is filled into the multi-site sequence grid to construct the corresponding dataset;
[0045] In the dataset, the historical monitoring data of each station in the selected target source domain is masked to obtain masked data. The historical monitoring data and the masked data are then combined to form a training and testing set.
[0046] Step 2: Select a Transformer model framework with the same number of source domains to construct a prediction network. The prediction network includes a feature extraction module, a feature fusion module, and a prediction module.
[0047] The feature extraction module includes a water quality feature extractor and a meteorological feature extractor. The water quality feature extractor is used to extract data features from the input water quality data to output a water quality feature vector. The meteorological feature extractor is used to extract data features from the input meteorological data to output a meteorological feature vector.
[0048] The feature fusion module uses an attention mechanism to perform dot multiplication between the water quality feature vector and the meteorological feature vector to obtain a fused feature vector.
[0049] The prediction module makes predictions based on the input fused feature vectors and outputs the prediction results.
[0050] Step 3: Train the prediction network using the training and testing set: Input the mask data corresponding to all historical water quality data of a source domain into the corresponding Transformer model framework in the upstream and downstream order of the stations. Calculate the loss between the prediction results and the historical water quality data, and adjust the parameter weights in the Transformer model framework based on the loss calculation results. Repeat the adjustment operation to adjust the Transformer model framework corresponding to all source domains.
[0051] The Transformer model framework obtained from all adjustments was fitted using a linear fusion method to obtain the temporal and parameter relationships between different sites in the source domain.
[0052] The temporal and parametric relationships between different stations within the source domain are loaded into the prediction network, and the prediction network is fine-tuned using historical water quality and meteorological data to obtain the prediction model.
[0053] Step 4: Input the water quality data collected at the station and the current day's meteorological data into the prediction model to obtain the water quality data of the source area where the station is located.
[0054] To better illustrate the technical effects of the method provided in this embodiment, the water quality parameters in this embodiment include COD, DO, NH3-N and pH.
[0055] These monitoring stations are concentrated in East China, covering six major river basins: the Heilongjiang, Songhua, Yellow, Huai, Yangtze, and Pearl Rivers. The length of water quality data varies considerably among different stations, with the longest data spanning from October 29, 2007 to December 24, 2018 (583 data points). While a few stations have fewer than 200 records, 66.4% and 87.9% of the stations have more than 500 and 300 data points, respectively. Furthermore, we obtained meteorological data from corresponding stations using the China Meteorological Forcing Dataset (CMFD), one of the most widely used climate datasets in China. This dataset is a fusion of remote sensing products, reanalysis datasets, and field station data. CMFD provides seven near-surface meteorological elements: 2-meter air temperature (°C), surface pressure (Pa), specific humidity (kg / kg), 10-meter wind speed (m / s), downwave shortwave radiation (W / m²), downwave longwave radiation (W / m²), and precipitation (mm / d). Based on the station location and timestamp, meteorological data were extracted and preprocessed using Python.
[0056] The collected data were organized to extract monitoring data from 149 surface water quality stations, and preprocessed to construct a sequence format dataset.
[0057] Stations from the Heilongjiang, Songhua, Yellow, Huai, Yangtze, and Pearl Rivers were selected as source domains from sequence format datasets to construct and train Transformer models. Hyperparameter combinations were manually tested, and a sequence length of 8, a Transformer layer size of 3, and a mask ratio of 0.5 were used for training for a total of 300 epochs.
[0058] In the fine-tuning phase, the input data was divided into a training set (the first 80% of the data) and a test set (the last 20% of the data). Standardization was applied to all inputs to ensure numerical stability. Using corresponding meteorological and water quality data from the same training period, a prediction model was trained on 149 monitoring points, and the model performance was evaluated based on data from the test period. To ensure the feasibility of parameter transfer, the input sequence length of the prediction model remained at 8, while the prediction sequence length was 1. However, unlike the pre-training phase, the fine-tuning phase only had 50 training cycles, which significantly reduced training time.
[0059] The obtained model was used to predict the water quality of 149 stations, and R2 and RMSE were calculated for quantitative comparison.
[0060] like Figure 2 The image shows the test results of the prediction model trained using the above method. The actual water quality parameters of each source region are basically consistent with the predictions made by the model, and the evaluation R of all stations is [data missing]. 2The accuracy reached 0.80, indicating that the prediction accuracy of this method is high and fully meets the requirements for practical application.
[0061] Table 1 shows the distribution of water quality data at each station predicted by the prediction model provided in the above embodiment. Good performance indicates NSE > 0.7, medium performance indicates 0.7 < NSE > 0.4, and poor performance indicates NSE < 0.4.
[0062] Table 1
[0063]
[0064] From the prediction results of each station in the table, it is clear that the performance of the prediction model is stable and performs well on space stations. In terms of quantity, more than 70% of the 149 stations have an R2 greater than 0.7, and more than 99% have an R2 greater than 0.4.
[0065] In addition, this embodiment also provides a portable surface water quality prediction device for implementing the steps of the representation learning-based portable surface water quality prediction method provided in the above embodiment.
[0066] The embodiments described above are merely one application of the present invention and are not intended to limit the invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the invention. Therefore, all technical solutions obtained through equivalent substitution or transformation are within the protection scope of the present invention.
Claims
1. A transferable surface water quality prediction method based on representation learning, characterized in that, Includes the following steps: Step 1: Obtain historical monitoring data, including historical water quality data and historical meteorological data for each station; A multi-site sequence grid is constructed using a timeline and site locations, and the historical monitoring data is filled into the multi-site sequence grid to construct the corresponding dataset; In the dataset, the historical monitoring data of each station in the selected target source domain is masked to obtain masked data. The historical monitoring data and the masked data are then combined to form a training and testing set. Step 2: Select a Transformer model framework with the same number of source domains to construct a prediction network. The prediction network includes a feature extraction module, a feature fusion module, and a prediction module. The feature extraction module includes a water quality feature extractor and a meteorological feature extractor. The water quality feature extractor is used to extract data features from the input water quality data to output a water quality feature vector. The meteorological feature extractor is used to extract data features from the input meteorological data to output a meteorological feature vector. The feature fusion module performs dot multiplication of the water quality feature vector and the meteorological feature vector through an attention mechanism to obtain a fused feature vector. The prediction module makes predictions based on the input fused feature vectors and outputs the prediction results. Step 3: Train the prediction network using the training and testing set: Input the mask data corresponding to all historical water quality data of a source domain into the corresponding Transformer model framework in the upstream and downstream order of the stations. Calculate the loss between the prediction results and the historical water quality data, and adjust the parameter weights in the Transformer model framework based on the loss calculation results. Repeat the adjustment operation to adjust the Transformer model framework corresponding to all source domains. The Transformer model framework obtained from all adjustments was fitted using a linear fusion method to obtain the temporal and parameter relationships between different sites in the source domain. The temporal and parameter relationships between different stations within the source domain are loaded into the prediction network, and the prediction network is fine-tuned using historical water quality data and historical meteorological data to obtain the prediction model. Step 4: Input the water quality data collected at the station and the current day's meteorological data into the prediction model to obtain the water quality data of the source area where the station is located.
2. The transferable surface water quality prediction method based on representation learning according to claim 1, characterized in that, The dataset needs to undergo data preprocessing when historical monitoring data is entered. The data preprocessing includes removing outliers from the historical monitoring data using the four-part difference calculation method, and filling in the positions of the removed outliers using linear interpolation.
3. The transferable surface water quality prediction method based on representation learning according to claim 1, characterized in that, Before the historical monitoring data is masked, position encoding is performed on the linear function of all stations in a single source domain. The position encoding encodes the historical monitoring data in the time dimension and parameter dimension with a preset time step to obtain encoded data with uniform dimension and format.
4. The transferable surface water quality prediction method based on representation learning according to claim 1, characterized in that, The masking process includes one or more of random masking, temporal masking, spatial masking, or parametric masking.
5. The transferable surface water quality prediction method based on representation learning according to claim 1, characterized in that, The parameter weights of the Transformer model framework are adjusted based on the mean square error loss between the prediction results and historical water quality data.
6. The transferable surface water quality prediction method based on representation learning according to claim 1, characterized in that, The prediction network is fine-tuned based on an objective function constructed using the coefficient of determination and root mean square error.
7. The transferable surface water quality prediction method based on representation learning according to claim 6, characterized in that, The expression for the objective function is as follows: in, This represents the actual value of the water quality data to be predicted. This represents the predicted value of the water quality data to be predicted. This represents the average of the actual values of the water quality data. Indicates the number of data values in a time series. The coefficient of determination is represented by the coefficient of determination. Root mean square error is expressed as follows.
8. A portable surface water quality prediction device, characterized in that, Steps for implementing the transferable surface water quality prediction method based on representation learning as described in any one of claims 1 to 7.
Citation Information
Patent Citations
River water quality prediction method
CN119129863A
Multi-site water quality prediction method based on spatio-temporal feature fusion
CN119168176A