A water quality evaluation method and device, and a storage medium

By preprocessing water body monitoring index data and constructing a multi-scale attention network model, combined with a composite loss function, the problems of computational redundancy and overfitting in water quality assessment are solved. This enables accurate identification and robust assessment of highly polluted water bodies, applicable to various water body types, and supports environmental governance decision-making.

CN122451384APending Publication Date: 2026-07-24GUANGXI ZHUANG AUTONOMOUS REGION ECOLOGICAL ENVIRONMENT MONITORING CENT +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGXI ZHUANG AUTONOMOUS REGION ECOLOGICAL ENVIRONMENT MONITORING CENT
Filing Date
2026-04-03
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing water quality assessment methods suffer from strong subjectivity, inability to capture nonlinear correlations between indicators, poor adaptability to complex pollution scenarios, and computational redundancy and overfitting in low-dimensional water quality data, resulting in poor robustness of assessment results and low accuracy in identifying highly polluted water bodies.

Method used

By preprocessing the raw water body monitoring data, a multi-scale attention network model is constructed and trained using a composite loss function to capture the local correlation and global synergistic effect of the indicators, thereby achieving automated water quality assessment.

Benefits of technology

It improves the accuracy and robustness of water quality assessment, enhances the ability to identify highly polluted water bodies, is applicable to the assessment of different types of water bodies, and provides real-time and reliable environmental governance decision support.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122451384A_ABST
    Figure CN122451384A_ABST
Patent Text Reader

Abstract

The application provides a water quality evaluation method and device and a storage medium, and belongs to the technical field of water quality evaluation.The method comprises the following steps: introducing original water body monitoring index data, preprocessing the original water body monitoring index data to obtain preprocessed water body monitoring index data; constructing a training model, performing model analysis on the training model through the preprocessed water body monitoring index data to obtain a water quality evaluation model; introducing water body monitoring index data to be evaluated, and performing evaluation on the water body monitoring index data to be evaluated through the water quality evaluation model to obtain a water quality evaluation result.The application solves the problems of calculation redundancy and overfitting of a traditional model in low-dimensional water quality data, can be applied to water quality evaluation of different types of water bodies, does not need to manually set complex rules, realizes automatic evaluation based on monitoring index data, improves the evaluation speed, and provides real-time and reliable support for environmental governance decision-making.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of water quality assessment technology, specifically to a water quality assessment method, apparatus, and storage medium. Background Technology

[0002] Water quality assessment is a core component of water resource protection, environmental governance, and drinking water safety assurance. Its core requirement is to quickly and accurately determine the degree of water pollution and the functional level of water bodies through water quality monitoring indicators (such as pH value, dissolved oxygen, chemical oxygen demand (COD), ammonia nitrogen, total phosphorus, heavy metal content, etc.).

[0003] Existing water quality assessment methods are mainly divided into two categories: 1. Traditional methods: Threshold comparison method or weighted scoring method based on national standards (such as GB 3838-2002 "Surface Water Environmental Quality Standard"). However, this method relies on manually set rules and has problems such as strong subjectivity, inability to capture nonlinear correlation between indicators, and poor adaptability to complex pollution scenarios. 2. Machine learning methods, such as Support Vector Machines (SVM), Random Forests (RF), and traditional neural networks (CNN, LSTM), while capable of learning statistical patterns between indicators, have the following drawbacks: (1) Limitations of network structure: CNN has difficulty capturing non-local correlations of indicators (such as the synergistic pollution effect of COD and ammonia nitrogen), LSTM has insufficient ability to model the global dependence of long-sequence monitoring data, and traditional Transformer is prone to overfitting and computational redundancy when processing low-dimensional water quality indicators. (2) Single loss function: Existing methods mostly use cross-entropy loss or mean squared error loss, focusing only on classification accuracy or regression error, ignoring the orderliness of water quality levels (e.g., the difference between Class I and Class II water is smaller than that between Class I and Class V water), sample imbalance (e.g., there are far more clean water samples than heavily polluted samples), and the weight differences of key indicators, resulting in poor robustness of the evaluation results and low accuracy in identifying highly polluted water bodies. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a water quality assessment method, apparatus and storage medium to address the shortcomings of the prior art.

[0005] The technical solution of the present invention to solve the above-mentioned technical problems is as follows: A water quality assessment method, comprising the following steps: S1: Import multiple raw water body monitoring index data, preprocess each of the raw water body monitoring index data respectively, and obtain preprocessed water body monitoring index data corresponding to each of the raw water body monitoring index data. S2: Construct a training model, and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model; S3: Import the monitoring index data of the water body to be evaluated, and evaluate the monitoring index data of the water body to be evaluated through the water quality assessment model to obtain the water quality assessment result.

[0006] Another technical solution of the present invention to solve the above-mentioned technical problems is as follows: A water quality assessment device, comprising: The import module is used to import multiple raw water body monitoring index data; The preprocessing module is used to preprocess each of the original water body monitoring index data to obtain preprocessed water body monitoring index data corresponding to each of the original water body monitoring index data. The model analysis module is used to build a training model and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model. The import module is also used to import monitoring index data of the water body to be evaluated; The assessment result acquisition module is used to evaluate the monitoring index data of the water body to be assessed through the water quality assessment model, and obtain the water quality assessment result.

[0007] Based on the above-mentioned water quality assessment method, the present invention also provides a water quality assessment system.

[0008] Another technical solution of the present invention to solve the above-mentioned technical problems is as follows: a water quality assessment system, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the water quality assessment method as described above.

[0009] Based on the above-mentioned water quality assessment method, the present invention also provides a computer-readable storage medium.

[0010] Another technical solution of the present invention to solve the above-mentioned technical problems is as follows: a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program controls the device where the computer-readable storage medium is located to perform the water quality assessment method as described above when the computer program is running.

[0011] The beneficial effects of this invention are as follows: by preprocessing the original water body monitoring index data, preprocessed water body monitoring index data is obtained; by analyzing the training model using the preprocessed water body monitoring index data, a water quality assessment model is obtained; and by evaluating the monitoring index data of the water body to be assessed using the water quality assessment model, the water quality assessment result is obtained. This solves the problems of computational redundancy and overfitting in traditional models with low-dimensional water quality data, resulting in more accurate feature extraction and improved model identification ability and assessment robustness for highly polluted water bodies. It is applicable to water quality assessment of different types of water bodies, eliminates the need for manually setting complex rules, realizes automatic assessment based on monitoring index data, improves assessment speed, and provides real-time and reliable support for environmental governance decisions. Attached Figure Description

[0012] Figure 1 This is a schematic flowchart of the water quality assessment method provided in an embodiment of the present invention; Figure 2 This is a block diagram of a water quality assessment device provided in an embodiment of the present invention. Detailed Implementation

[0013] The principles and features of the present invention are described below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0014] Figure 1 This is a schematic flowchart of a water quality assessment method provided in an embodiment of the present invention.

[0015] like Figure 1 As shown, a water quality assessment method includes the following steps: S1: Import multiple raw water body monitoring index data, preprocess each of the raw water body monitoring index data respectively, and obtain preprocessed water body monitoring index data corresponding to each of the raw water body monitoring index data. S2: Construct a training model, and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model; S3: Import the monitoring index data of the water body to be evaluated, and evaluate the monitoring index data of the water body to be evaluated through the water quality assessment model to obtain the water quality assessment result.

[0016] It should be understood that the raw water body monitoring data includes mandatory indicators (pH value, dissolved oxygen, COD, ammonia nitrogen, total phosphorus, total nitrogen) and optional indicators (heavy metal content, turbidity, biochemical oxygen demand, etc.).

[0017] In the above embodiments, preprocessed water body monitoring index data is obtained by preprocessing the original water body monitoring index data. A water quality assessment model is obtained by analyzing the training model using the preprocessed water body monitoring index data. The water quality assessment result is obtained by evaluating the monitoring index data of the water body to be assessed using the water quality assessment model. This solves the problems of computational redundancy and overfitting in low-dimensional water quality data of traditional models. Feature extraction is more accurate, and the model's ability to identify highly polluted water bodies and its assessment robustness are improved. It can be applied to water quality assessment of different types of water bodies. There is no need to manually set complex rules. It realizes automatic assessment based on monitoring index data, improves assessment speed, and provides real-time and reliable support for environmental governance decisions.

[0018] Optionally, the preprocessing process in step S1 includes the following steps: S11: Use the K-nearest neighbor interpolation algorithm to fill in the missing values ​​of each of the original water body monitoring index data to obtain the filled water body monitoring index data corresponding to each of the original water body monitoring index data. S12: Perform outlier processing on each of the filled water body monitoring index data to obtain the water body monitoring index data to be processed corresponding to each of the original water body monitoring index data. S13: Standardize the monitoring index data of each water body to be processed to obtain standardized water body monitoring index data corresponding to the original water body monitoring index data. S14: According to the preset water quality level rules, the standardized water body monitoring index data of each of the above are labeled and processed to obtain the preprocessed water body monitoring index data corresponding to the original water body monitoring index data of each of the above.

[0019] It should be understood that K-nearest neighbor (KNN) based interpolation (i.e., K-nearest neighbor interpolation algorithm) is used to fill in the missing data.

[0020] Specifically, outliers are identified using box plots, and domain knowledge is used to determine whether to replace them with a reasonable threshold for the metric or to delete the outlier samples.

[0021] It should be understood that Z-score standardization is used to convert all indicators (i.e., the monitoring data of the water bodies to be treated) into standardized data with a mean of 0 and a variance of 1, thereby eliminating dimensional differences.

[0022] Specifically, based on the corresponding water quality standards (such as GB 3838-2002) (i.e., the preset water quality grade rules), the pre-treated monitoring data (i.e., the standardized water body monitoring index data) are labeled with the corresponding water quality grade labels (such as Class I, Class II, Class III, Class IV, Class V, and worse than Class V).

[0023] In the above embodiments, the original water body monitoring index data are preprocessed to obtain preprocessed water body monitoring index data, which provides accurate data for subsequent processing. This solves the problems of computational redundancy and overfitting in traditional models with low-dimensional water quality data, makes feature extraction more accurate, and improves the model's ability to identify highly polluted water bodies and its assessment robustness.

[0024] Optionally, as an embodiment of the present invention, the process of performing model analysis on the training model using all the pretreated water monitoring index data to obtain a water quality assessment model includes: S21: Train the training model using all the preprocessed water body monitoring index data to obtain the key index feature matrix corresponding to each of the original water body monitoring index data and the prediction probability corresponding to each of the original water body monitoring index data. S22: Import the true probability corresponding to each of the original water body monitoring index data and the true water body monitoring index feature matrix corresponding to each of the original water body monitoring index data; S23: Update and analyze the training model based on all the key indicator feature matrices, all the predicted probabilities, all the true probabilities, and all the true water body monitoring indicator feature matrices to obtain a water quality assessment model.

[0025] In the above embodiments, a water quality assessment model is obtained by performing model analysis on the training model using preprocessed water body monitoring index data. This solves the problems of computational redundancy and overfitting in traditional models with low-dimensional water quality data. Feature extraction is more accurate, and the model's ability to identify highly polluted water bodies and its assessment robustness are improved. It can be applied to water quality assessment of different types of water bodies without the need for manually setting complex rules. It realizes automatic assessment based on monitoring index data, improves assessment speed, and provides real-time and reliable support for environmental governance decisions.

[0026] Optionally, as an embodiment of the present invention, the training model includes a first fully connected layer, a multi-scale attention network, a 1D convolutional layer, multiple second fully connected layers, and a first Softmax activation function layer; The process S21 includes: The first fully connected layer is used to map each of the preprocessed water body monitoring index data to obtain the original water body monitoring index feature matrix corresponding to each of the original water body monitoring index data. The multi-scale attention network is used to perform attention analysis on the feature matrices of each of the original water body monitoring indicators to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The attention feature matrices of each target water body monitoring indicator are reduced in dimension by the 1D convolutional layer to obtain the dimensionality-reduced attention feature matrices of water body monitoring indicators corresponding to the original water body monitoring indicator data. By using multiple second fully connected layers to map the attention feature matrices of each of the dimensionality-reduced water body monitoring indicators, a mapped attention feature matrix of water body monitoring indicators corresponding to each of the original water body monitoring indicator data is obtained. The first Softmax activation function layer is used to normalize the attention feature matrix of each mapped water body monitoring indicator to obtain the predicted probability corresponding to each of the original water body monitoring indicator data.

[0027] It should be understood that the input vector (i.e., the preprocessed water monitoring index data) is mapped from the d dimension to the model dimension d_model (e.g., d_model=128) through the first fully connected layer, resulting in the embedding vector X∈R (N×d_model) (i.e., the original water monitoring index feature matrix), where N is the number of samples.

[0028] It should be understood that using a 1×1 convolutional kernel (i.e., a 1D convolutional layer) reduces the dimension of X_att from d_model to d_model / 2, compressing redundant features.

[0029] Specifically, the second fully connected layer (with a hidden layer dimension of d_model / 4) is used to map the feature vector X_fuse∈R(N×C) (i.e., the attention feature matrix of water body monitoring indicators after mapping), where C is the total number of water quality grade categories (e.g., C=6).

[0030] Specifically, the first Softmax activation function layer is used to transform X_fuse (i.e., the mapped water body monitoring index attention feature matrix) into probability distributions for each category, outputting the predicted probability of water quality level: ,in , These are the output layer parameters.

[0031] In the above embodiments, the training model is trained by preprocessing water monitoring index data to obtain the key index feature matrix and prediction probability. This captures the local correlation of water quality indicators and retains the global synergistic effect of key indicators. It solves the problems of computational redundancy and overfitting in traditional models in low-dimensional water quality data, and the feature extraction is more accurate. At the same time, it also solves the three core problems of water quality level order, sample imbalance and key index sensitivity, and improves the model's ability to identify highly polluted water bodies and its assessment robustness.

[0032] Optionally, as an embodiment of the present invention, the multi-scale attention network includes a local attention layer, a global attention layer, a residual connection layer, and a layer normalization layer; The process of performing attention analysis on the feature matrices of each of the original water body monitoring indicators through the multi-scale attention network to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator attention feature matrix corresponding to each of the original water body monitoring indicator data includes: By performing local attention analysis on the feature matrices of each of the original water body monitoring indicators through the local attention layer, the target water body monitoring indicator local attention feature matrix corresponding to the data of each of the original water body monitoring indicators is obtained. The global attention layer performs global attention analysis on the feature matrices of each of the original water body monitoring indicators to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator global attention feature matrix corresponding to each of the original water body monitoring indicator data. The residual connection layer is used to add the feature matrices of each original water body monitoring index, the local attention feature matrix of the target water body monitoring index corresponding to each original water body monitoring index data, and the global attention feature matrix of the target water body monitoring index corresponding to each original water body monitoring index data, respectively, to obtain the original water body monitoring index attention feature matrix corresponding to each original water body monitoring index data. The attention feature matrices of each of the original water body monitoring indicators are normalized by the layer normalization layer to obtain the attention feature matrices of the target water body monitoring indicators corresponding to the original water body monitoring indicator data.

[0033] It should be understood that the self-attention mechanism of traditional models calculates the correlation between all global indicators. In the case of low-dimensional water quality indicators, there is computational redundancy and it is prone to overfitting. This invention combines local window attention and global sparse attention to take into account both the local correlation of indicators and the global synergistic effect.

[0034] It should be understood that the local attention layer is used to capture local correlations within a subset of indicators, such as the interactions between highly correlated organic pollution indicators like dissolved oxygen, COD, and ammonia nitrogen.

[0035] Specifically, the global attention layer is used to ensure that the model can capture the long-range dependencies between key metrics and all other metrics while controlling the amount of computation.

[0036] Specifically, the local attention feature matrix and global features (i.e., the global attention feature matrix of the target water body monitoring index) are organically combined, and the gradient vanishing problem of deep networks is alleviated through residual connections.

[0037] Specifically, the output X_local of the local attention (i.e., the local attention feature matrix of the target water body monitoring index) and the output X_global of the global attention (i.e., the global attention feature matrix of the target water body monitoring index) are added together; then, they are added to the original input X (i.e., the original water body monitoring index feature matrix) of the residual connection layer (this is the residual connection); adding X (i.e., the original water body monitoring index feature matrix) allows the gradient to propagate directly through this "shortcut path" of X (i.e., the original water body monitoring index feature matrix), ensuring that even in deep networks, the gradient will not become too small and vanish.

[0038] It should be understood that layer normalization is performed on the fused features X_fused (i.e., the original water body monitoring index attention feature matrix) to standardize the feature dimension of each sample, accelerate model training and improve stability.

[0039] In the above embodiments, attention analysis is performed on the original water body monitoring indicator feature matrix using a multi-scale attention network to obtain the key indicator feature matrix and the target water body monitoring indicator attention feature matrix. This approach can take into account both the local correlation and global synergistic effect of indicators, and also capture the local correlation within the indicator subset. This ensures that the model can capture the long-range dependency between the key indicator and all other indicators, alleviates the gradient vanishing problem of deep networks, accelerates model training, and improves stability.

[0040] Optionally, as an embodiment of the present invention, the local attention layer includes a third fully connected layer, a fourth fully connected layer, a fifth fully connected layer, and a second Softmax function layer; The process of performing local attention analysis on the feature matrices of each of the original water body monitoring indicators through the local attention layer to obtain the local attention feature matrix of the target water body monitoring indicator corresponding to each of the original water body monitoring indicator data includes: The feature matrix of each original water body monitoring indicator is divided according to the preset feature dimension to obtain multiple local features of the original water body monitoring indicators corresponding to the data of each original water body monitoring indicator. The local features of each of the original water body monitoring indicators are mapped through the third fully connected layer to obtain multiple local query features corresponding to the data of each of the original water body monitoring indicators. The fourth fully connected layer maps the local features of each of the original water body monitoring indicators to obtain multiple local key features corresponding to each of the original water body monitoring indicator data and multiple local key feature dimensions corresponding to each of the original water body monitoring indicator data. The fifth fully connected layer is used to map the local features of each of the original water body monitoring indicators to obtain multiple local value features corresponding to the data of each of the original water body monitoring indicators. The first formula is used to calculate multiple local query features, multiple local key features, multiple local key feature dimensions, and multiple local value features corresponding to each of the original water body monitoring index data, thereby obtaining multiple local attention scores corresponding to each of the original water body monitoring index data. , in, For the first The first original water body monitoring index data corresponding to the first Local attention score, For the Softmax function, For the first The first original water body monitoring index data corresponding to the first Local query features, For the first The first original water body monitoring index data corresponding to the first Local bond features, For transpose, For the first The first original water body monitoring index data corresponding to the first Each local key feature dimension For the first The first original water body monitoring index data corresponding to the first Local value features; The local attention scores corresponding to each of the original water body monitoring index data are concatenated to obtain the local attention feature matrix of the target water body monitoring index corresponding to each of the original water body monitoring index data.

[0041] It should be understood that although the third, fourth, and fifth fully connected layers all process the local characteristics of the original water body monitoring indicators, the results obtained are different because the weights in the third, fourth, and fifth fully connected layers are different.

[0042] Understandably, the input feature matrix X (i.e., the original water body monitoring index feature matrix) is divided into k non-overlapping local windows along the feature dimension (Feature_Dim); assuming Feature_Dim=128 and k=4, then the size of each window is 128 / 4=32; after division, k local feature matrices (i.e., local features of the original water body monitoring index) are obtained: X_1, X_2, ..., X_k. The shape of each X_i is [Batch_Size, Window_Size], i.e. [N, 32], where N is the number of samples.

[0043] It should be understood that X_i is mapped to query Q_i (i.e., local query feature), key K_i (i.e., local key feature) and value V_i (i.e., local value feature) through three different linear projection layers (i.e., the third fully connected layer, the fourth fully connected layer, and the fifth fully connected layer), respectively.

[0044] Q_i=X_i W_Q, shape [N, d_k]; K_i=X_i W_K, shape [N, d_k]; V_i=X_i W_V, shape [N, d_v].

[0045] It should be understood that the attention outputs X_local_1, X_local_2, ..., X_local_k (i.e., local attention scores) of the k windows are reassembled along the feature dimension to form a complete local attention feature matrix X_local (i.e., the local attention feature matrix of the target water body monitoring index).

[0046] In the above embodiments, the local attention feature matrix of the target water body monitoring index is obtained by performing local attention analysis on the feature matrices of each original water body monitoring index through the local attention layer. This can take into account both the local correlation of the index and the synergistic effect of the whole, ensuring that the model can capture the long-range dependency relationship between the key index and all other indexes, alleviating the gradient vanishing problem of deep networks, accelerating model training and improving stability.

[0047] Optionally, as an embodiment of the present invention, the global attention layer includes a sixth fully connected layer, a seventh fully connected layer, an eighth fully connected layer, a first linear layer, a ninth fully connected layer, a tenth fully connected layer, an eleventh fully connected layer, and a second linear layer; The process of performing global attention analysis on the feature matrices of each of the original water body monitoring indicators through the global attention layer to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator global attention feature matrix corresponding to each of the original water body monitoring indicator data includes the following steps: According to the preset key indicator screening rules, multiple key indicator features corresponding to each original water body monitoring indicator data are selected from the feature matrices of each original water body monitoring indicator data. Then, the key indicator feature matrix corresponding to each original water body monitoring indicator data is obtained through the multiple key indicator features corresponding to each original water body monitoring indicator data. Finally, the non-key indicator feature matrix corresponding to each original water body monitoring indicator data is obtained through all the remaining original water body monitoring indicator features corresponding to each original water body monitoring indicator data. The sixth fully connected layer is used to map each of the key indicator feature matrices to obtain the key indicator query feature matrix corresponding to each of the original water body monitoring indicator data. The seventh fully connected layer is used to map the feature matrices of each of the original water body monitoring indicators to obtain the key indicator key feature matrix and the key indicator key feature dimension corresponding to each of the original water body monitoring indicator data. The eighth fully connected layer is used to map the feature matrices of each of the original water body monitoring indicators to obtain the key indicator value feature matrix corresponding to each of the original water body monitoring indicator data. The second formula is used to calculate the key indicator attention score corresponding to each of the original water body monitoring indicator data, the key indicator key feature matrix corresponding to each of the key indicator query feature matrices, the key indicator key feature dimension corresponding to each of the original water body monitoring indicator data, and the key indicator value feature matrix corresponding to each of the original water body monitoring indicator data, respectively. , in, For the first Attention scores for key indicators corresponding to each original water body monitoring data point. For the Softmax function, For the first Key indicator query feature matrix corresponding to each original water body monitoring indicator data For the first Key indicator feature matrix corresponding to each original water body monitoring indicator data For transpose, For the first Key indicator feature dimensions corresponding to each original water body monitoring indicator data For the first Feature matrix of key indicator values ​​corresponding to each original water body monitoring indicator data; The attention scores of each key indicator are mapped through the first linear layer to obtain the key indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The ninth fully connected layer is used to map each of the non-critical indicator feature matrices to obtain the non-critical indicator query feature matrices corresponding to each of the original water body monitoring indicator data. The tenth fully connected layer maps at least one original water body monitoring indicator feature adjacent to each of the non-key indicator feature matrices to obtain the non-key indicator key feature matrix corresponding to each of the original water body monitoring indicator data and the non-key indicator key feature dimension corresponding to each of the original water body monitoring indicator data. The eleventh fully connected layer maps at least one original water body monitoring indicator feature adjacent to each of the non-critical indicator feature matrices to obtain a non-critical indicator value feature matrix corresponding to each of the original water body monitoring indicator data. The third formula is used to calculate the non-critical indicator query feature matrix, the non-critical indicator key feature matrix corresponding to each of the original water body monitoring indicator data, the non-critical indicator key feature dimension corresponding to each of the original water body monitoring indicator data, and the non-critical indicator value feature matrix corresponding to each of the original water body monitoring indicator data, respectively, to obtain the non-critical indicator attention score corresponding to each of the original water body monitoring indicator data. The third formula is: , in, For the first Attention scores for non-critical indicators corresponding to the original water body monitoring data For the Softmax function, For the first Query feature matrix of non-key indicators corresponding to each original water body monitoring indicator data For the first Non-critical indicator key feature matrix corresponding to each original water body monitoring indicator data For transpose, For the first Non-critical indicator key feature dimensions corresponding to each original water body monitoring indicator data For the first Feature matrix of non-critical indicator values ​​corresponding to each original water body monitoring indicator data; The second linear layer is used to map the attention scores of each non-critical indicator to obtain the non-critical indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The attention feature matrices of each key indicator are concatenated with the attention feature matrices of non-key indicators corresponding to each original water body monitoring indicator data to obtain the global attention feature matrix of the target water body monitoring indicator corresponding to each original water body monitoring indicator data.

[0048] Specifically, through domain knowledge (e.g., identifying COD, ammonia nitrogen, and total phosphorus as key pollution indicators) or data-driven methods (e.g., analyzing attention heatmaps), m key feature dimensions are pre-determined; these key features are extracted from the original input X (i.e., the original water body monitoring indicator feature matrix) to form a key feature matrix X_key (shape: [N, m]) (i.e., the key indicator feature matrix); the remaining features are treated as non-key features to form X_nonkey (i.e., the non-key indicator feature matrix).

[0049] It should be understood that Q_key = X_key W_Q_key, shape [N, d_k]; K_global=X W_K_global, shape [N, d_k]; V_global=X W_V_global, shape [N, d_v].

[0050] It should be understood that although both the tenth and eleventh fully connected layers process at least one original water body monitoring indicator feature adjacent to the non-critical indicator feature matrix, the results obtained are different because the weights in the tenth and eleventh fully connected layers are different.

[0051] Specifically, the global attention output X_global_key (i.e., the key indicator attention feature matrix) of key features and the sparse attention output X_global_nonkey (i.e., the non-key indicator attention feature matrix) of non-key features are concatenated to form the complete global attention feature matrix X_global (i.e., the target water body monitoring indicator global attention feature matrix).

[0052] In the above embodiments, the key indicator feature matrix and the target water body monitoring indicator global attention feature matrix are obtained by performing global attention analysis on the feature matrices of each original water body monitoring indicator through a global attention layer. This ensures that the model can capture the long-range dependency relationship between the key indicator and all other indicators, alleviates the gradient vanishing problem of deep networks, accelerates model training, and improves stability.

[0053] Optionally, as an embodiment of the present invention, the process of S23 includes: The target loss function is obtained by calculating the feature matrices of all the key indicators, all the predicted probabilities, all the true probabilities, and all the feature matrices of the actual water body monitoring indicators using the fourth equation. The fourth equation is: , in, , , , in, , , , in, Let be the target loss function. , as well as All are weighting coefficients. For the first loss function, For the second loss function, For the third loss function, This represents the total number of original water body monitoring index data. This represents the total number of water quality grade categories. , For the first The first set of original water body monitoring index data The true probability corresponding to each water quality grade category For the first The first set of original water body monitoring index data The predicted probability for each water quality category For the first The category weights of each water quality grade category For the first The first set of original water body monitoring index data The predicted probability for each water quality category For focus coefficient, The total number of key indicator feature matrices. For the first Key indicator feature matrix corresponding to each original water body monitoring indicator data For the first The feature matrix of real water body monitoring indicators corresponding to the original water body monitoring indicator data. For the first The first set of original water body monitoring index data The true probability corresponding to each water quality grade category For the first The total number of original water body monitoring indicator data corresponding to each water quality grade category; Determine whether the target loss function is less than or equal to the preset loss function. If not, update the parameters of the training model according to the target loss function and return to S21 after parameter update. If yes, use the training model as the water quality assessment model.

[0054] It should be understood that satisfying The optimal value is determined through cross-validation. Example values: , , .

[0055] Specifically, water quality grades (Class I → Class II → … → worse than Class V) exhibit an increasing order (pollution levels rise sequentially). Traditional cross-entropy treats grades as independent categories, ignoring sequential relationships (e.g., the difference between Class I and Class II should be smaller than that between Class I and worse than Class V). The first loss function transforms multi-class classification into multiple binary classification tasks (e.g., "whether ≤ Class III" or "whether ≤ Class IV"), capturing the sequential dependencies between grades.

[0056] It should be understood that for a true rating of Class IV ( For the sample, t=1 (whether it is ≤ class I) When t=3 (whether it is ≤Class III) When t=4 (whether it is ≤Class IV) .

[0057] Specifically, in water quality assessment, some indicators (such as COD, ammonia nitrogen, and total phosphorus) are core indicators for judging the degree of pollution (abnormalities in key indicators directly lead to a decline in water quality level). The third loss function strengthens the model's sensitivity to these indicators by penalizing the prediction error of key indicators, thus avoiding overall assessment bias caused by misjudgment of key indicators.

[0058] Specifically, the core advantages of the loss function (i.e., the target loss function) are as follows: (1) Multi-objective approach: Simultaneously address the three core issues of water quality assessment, such as orderliness, sample imbalance, and sensitivity of key indicators, and avoid the limitations of a single loss function; (2) High interpretability: The physical meaning of each sub-loss is clear, and the weighting coefficients can be increased according to the actual application scenario (e.g., when focusing on the identification of highly polluted water bodies). Adjust flexibly; (3) Gradient optimization friendly: All three types of sub-losses are continuously differentiable functions, compatible with the backpropagation of the Transformer model, and will not cause gradient vanishing or exploding.

[0059] In the above embodiments, the water quality assessment model is obtained by updating and analyzing the training model based on all key indicator feature matrices, all predicted probabilities, all true probabilities, and all true water body monitoring indicator feature matrices. This solves the three core problems of water quality assessment, avoids the limitations of a single loss function, and does not lead to gradient vanishing or exploding.

[0060] Alternatively, as another embodiment of the present invention, the present invention enhances the feature extraction capability of water quality indicators by improving the Transformer network structure, and solves the problems of orderliness, sample imbalance and key indicator weights in water quality assessment by designing a composite loss function, thereby achieving a more accurate and reliable water quality grade assessment.

[0061] Alternatively, as another embodiment of the present invention, the present invention has the following beneficial effects compared with the prior art: (i) Network structure optimization: Improved multi-scale local-global attention layer, which captures the local correlation of water quality indicators (such as the coupling of dissolved oxygen and COD) and retains the global synergistic effect of key indicators, solves the problem of computational redundancy and overfitting of traditional Transformer in low-dimensional water quality data, and makes feature extraction more accurate; (II) Innovation of loss function: The composite loss function integrates ordered cross-entropy, weighted focus loss and key index loss, which solves the three core problems of water quality level order, sample imbalance and key index sensitivity at the same time, and improves the model’s ability to identify highly polluted water bodies and its assessment robustness. (III) Excellent evaluation performance: Compared with traditional methods and existing machine learning methods, the evaluation accuracy and macro average F1 value of this invention are improved by more than 5%, the accuracy of high pollution sample identification is improved by more than 10%, and the generalization ability is strong, making it suitable for water quality assessment of different types of water bodies. (iv) Highly practical: It does not require manual setting of complex rules, and can be automatically evaluated directly based on monitoring indicator data. It has a fast processing speed and can be integrated into the online water quality monitoring system to provide real-time and reliable support for environmental governance decisions.

[0062] Figure 2 This is a block diagram of a water quality assessment device provided in an embodiment of the present invention.

[0063] Alternatively, as another embodiment of the present invention, such as Figure 2 As shown, a water quality assessment device includes: The import module is used to import multiple raw water body monitoring index data; The preprocessing module is used to preprocess each of the original water body monitoring index data to obtain preprocessed water body monitoring index data corresponding to each of the original water body monitoring index data. The model analysis module is used to build a training model and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model. The import module is also used to import monitoring index data of the water body to be evaluated; The assessment result acquisition module is used to evaluate the monitoring index data of the water body to be assessed through the water quality assessment model, and obtain the water quality assessment result.

[0064] Optionally, another embodiment of the present invention provides a water quality assessment system, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the water quality assessment method described above. This system can be a computer or similar system.

[0065] Optionally, another embodiment of the present invention provides a computer-readable storage medium storing a computer program that, when the computer program is executed, controls the device where the computer-readable storage medium is located to perform the above-described water quality assessment method.

[0066] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0067] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described apparatus and unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0068] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0069] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0070] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0071] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a 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 of the various embodiments of the present invention. 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.

[0072] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A water quality assessment method, characterized in that, Includes the following steps: S1: Import multiple raw water body monitoring index data, preprocess each of the raw water body monitoring index data respectively, and obtain preprocessed water body monitoring index data corresponding to each of the raw water body monitoring index data. S2: Construct a training model, and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model; S3: Import the monitoring index data of the water body to be evaluated, and evaluate the monitoring index data of the water body to be evaluated through the water quality assessment model to obtain the water quality assessment result.

2. The water quality assessment method according to claim 1, characterized in that, The preprocessing process described in step S1 includes: S11: Use the K-nearest neighbor interpolation algorithm to fill in the missing values ​​of each of the original water body monitoring index data to obtain the filled water body monitoring index data corresponding to each of the original water body monitoring index data. S12: Perform outlier processing on each of the filled water body monitoring index data to obtain the water body monitoring index data to be processed corresponding to each of the original water body monitoring index data. S13: Standardize the monitoring index data of each water body to be processed to obtain standardized water body monitoring index data corresponding to the original water body monitoring index data. S14: According to the preset water quality level rules, the standardized water body monitoring index data of each of the above are labeled and processed to obtain the preprocessed water body monitoring index data corresponding to the original water body monitoring index data of each of the above.

3. The water quality assessment method according to claim 1, characterized in that, Step S2 includes the following steps: S21: Train the training model using all the preprocessed water body monitoring index data to obtain the key index feature matrix corresponding to each of the original water body monitoring index data and the prediction probability corresponding to each of the original water body monitoring index data. S22: Import the true probability corresponding to each of the original water body monitoring index data and the true water body monitoring index feature matrix corresponding to each of the original water body monitoring index data; S23: Update and analyze the training model based on all the key indicator feature matrices, all the predicted probabilities, all the true probabilities, and all the true water body monitoring indicator feature matrices to obtain a water quality assessment model.

4. The water quality assessment method according to claim 3, characterized in that, The training model includes a first fully connected layer, a multi-scale attention network, a 1D convolutional layer, multiple second fully connected layers, and a first Softmax activation function layer; The process S21 includes: The first fully connected layer is used to map each of the preprocessed water body monitoring index data to obtain the original water body monitoring index feature matrix corresponding to each of the original water body monitoring index data. The multi-scale attention network is used to perform attention analysis on the feature matrices of each of the original water body monitoring indicators to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The attention feature matrices of each target water body monitoring indicator are reduced in dimension by the 1D convolutional layer to obtain the dimensionality-reduced attention feature matrices of water body monitoring indicators corresponding to the original water body monitoring indicator data. By using multiple second fully connected layers to map the attention feature matrices of each of the dimensionality-reduced water body monitoring indicators, a mapped attention feature matrix of water body monitoring indicators corresponding to each of the original water body monitoring indicator data is obtained. The first Softmax activation function layer is used to normalize the attention feature matrix of each mapped water body monitoring indicator to obtain the predicted probability corresponding to each of the original water body monitoring indicator data.

5. The water quality assessment method according to claim 4, characterized in that, The multi-scale attention network includes a local attention layer, a global attention layer, a residual connection layer, and a layer normalization layer. The process of performing attention analysis on the feature matrices of each of the original water body monitoring indicators using the multi-scale attention network includes the following steps: By performing local attention analysis on the feature matrices of each of the original water body monitoring indicators through the local attention layer, the target water body monitoring indicator local attention feature matrix corresponding to the data of each of the original water body monitoring indicators is obtained. The global attention layer performs global attention analysis on the feature matrices of each of the original water body monitoring indicators to obtain the key indicator feature matrix corresponding to each of the original water body monitoring indicator data and the target water body monitoring indicator global attention feature matrix corresponding to each of the original water body monitoring indicator data. The residual connection layer is used to add the feature matrices of each original water body monitoring index, the local attention feature matrix of the target water body monitoring index corresponding to each original water body monitoring index data, and the global attention feature matrix of the target water body monitoring index corresponding to each original water body monitoring index data, respectively, to obtain the original water body monitoring index attention feature matrix corresponding to each original water body monitoring index data. The attention feature matrices of each of the original water body monitoring indicators are normalized by the layer normalization layer to obtain the attention feature matrices of the target water body monitoring indicators corresponding to the original water body monitoring indicator data.

6. The water quality assessment method according to claim 5, characterized in that, The local attention layer includes a third fully connected layer, a fourth fully connected layer, a fifth fully connected layer, and a second Softmax function layer; The process of performing local attention analysis on the feature matrices of each of the original water body monitoring indicators through the local attention layer includes the following steps: The feature matrix of each original water body monitoring indicator is divided according to the preset feature dimension to obtain multiple local features of the original water body monitoring indicators corresponding to the data of each original water body monitoring indicator. The local features of each of the original water body monitoring indicators are mapped through the third fully connected layer to obtain multiple local query features corresponding to the data of each of the original water body monitoring indicators. The fourth fully connected layer maps the local features of each of the original water body monitoring indicators to obtain multiple local key features corresponding to each of the original water body monitoring indicator data and multiple local key feature dimensions corresponding to each of the original water body monitoring indicator data. The fifth fully connected layer is used to map the local features of each of the original water body monitoring indicators to obtain multiple local value features corresponding to the data of each of the original water body monitoring indicators. The first formula is used to calculate multiple local query features, multiple local key features, multiple local key feature dimensions, and multiple local value features corresponding to each of the original water body monitoring index data, thereby obtaining multiple local attention scores corresponding to each of the original water body monitoring index data. , in, For the first The first original water body monitoring index data corresponding to the first Local attention score, For the Softmax function, For the first The first original water body monitoring index data corresponding to the first Local query features, For the first The first original water body monitoring index data corresponding to the first Local bond features, For transpose, For the first The first original water body monitoring index data corresponding to the first Each local key feature dimension For the first The first original water body monitoring index data corresponding to the first Local value features; The local attention scores corresponding to each of the original water body monitoring index data are concatenated to obtain the local attention feature matrix of the target water body monitoring index corresponding to each of the original water body monitoring index data.

7. The water quality assessment method according to claim 5, characterized in that, The global attention layer includes a sixth fully connected layer, a seventh fully connected layer, an eighth fully connected layer, a first linear layer, a ninth fully connected layer, a tenth fully connected layer, an eleventh fully connected layer, and a second linear layer; The process of performing global attention analysis on the feature matrices of each of the original water body monitoring indicators through the global attention layer includes the following steps: According to the preset key indicator screening rules, multiple key indicator features corresponding to each original water body monitoring indicator data are selected from the feature matrices of each original water body monitoring indicator data. Then, the key indicator feature matrix corresponding to each original water body monitoring indicator data is obtained through the multiple key indicator features corresponding to each original water body monitoring indicator data. Finally, the non-key indicator feature matrix corresponding to each original water body monitoring indicator data is obtained through all the remaining original water body monitoring indicator features corresponding to each original water body monitoring indicator data. The sixth fully connected layer is used to map each of the key indicator feature matrices to obtain the key indicator query feature matrix corresponding to each of the original water body monitoring indicator data. The seventh fully connected layer is used to map the feature matrices of each of the original water body monitoring indicators to obtain the key indicator key feature matrix and the key indicator key feature dimension corresponding to each of the original water body monitoring indicator data. The eighth fully connected layer is used to map the feature matrices of each of the original water body monitoring indicators to obtain the key indicator value feature matrix corresponding to each of the original water body monitoring indicator data. The second formula is used to calculate the key indicator attention score corresponding to each of the original water body monitoring indicator data, the key indicator key feature matrix corresponding to each of the key indicator query feature matrices, the key indicator key feature dimension corresponding to each of the original water body monitoring indicator data, and the key indicator value feature matrix corresponding to each of the original water body monitoring indicator data, respectively. , in, For the first Attention scores for key indicators corresponding to each original water body monitoring data point. For the Softmax function, For the first Key indicator query feature matrix corresponding to each original water body monitoring indicator data For the first Key indicator feature matrix corresponding to each original water body monitoring indicator data For transpose, For the first Key indicator feature dimensions corresponding to each original water body monitoring indicator data For the first Feature matrix of key indicator values ​​corresponding to each original water body monitoring indicator data; The attention scores of each key indicator are mapped through the first linear layer to obtain the key indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The ninth fully connected layer is used to map each of the non-critical indicator feature matrices to obtain the non-critical indicator query feature matrices corresponding to each of the original water body monitoring indicator data. The tenth fully connected layer maps at least one original water body monitoring indicator feature adjacent to each of the non-key indicator feature matrices to obtain the non-key indicator key feature matrix corresponding to each of the original water body monitoring indicator data and the non-key indicator key feature dimension corresponding to each of the original water body monitoring indicator data. The eleventh fully connected layer maps at least one original water body monitoring indicator feature adjacent to each of the non-critical indicator feature matrices to obtain a non-critical indicator value feature matrix corresponding to each of the original water body monitoring indicator data. The third formula is used to calculate the non-critical indicator query feature matrix, the non-critical indicator key feature matrix corresponding to each of the original water body monitoring indicator data, the non-critical indicator key feature dimension corresponding to each of the original water body monitoring indicator data, and the non-critical indicator value feature matrix corresponding to each of the original water body monitoring indicator data, respectively, to obtain the non-critical indicator attention score corresponding to each of the original water body monitoring indicator data. The third formula is: , in, For the first Attention scores for non-critical indicators corresponding to the original water body monitoring data For the Softmax function, For the first Query feature matrix of non-key indicators corresponding to each original water body monitoring indicator data For the first Non-critical indicator key feature matrix corresponding to each original water body monitoring indicator data For transpose, For the first Non-critical indicator key feature dimensions corresponding to each original water body monitoring indicator data For the first Feature matrix of non-critical indicator values ​​corresponding to each original water body monitoring indicator data; The second linear layer is used to map the attention scores of each non-critical indicator to obtain the non-critical indicator attention feature matrix corresponding to each of the original water body monitoring indicator data. The attention feature matrices of each key indicator are concatenated with the attention feature matrices of non-key indicators corresponding to each original water body monitoring indicator data to obtain the global attention feature matrix of the target water body monitoring indicator corresponding to each original water body monitoring indicator data.

8. The water quality assessment method according to claim 3, characterized in that, The process S23 includes: The target loss function is obtained by calculating the feature matrices of all the key indicators, all the predicted probabilities, all the true probabilities, and all the feature matrices of the actual water body monitoring indicators using the fourth equation. The fourth equation is: , in, , , , in, , , , in, Let be the target loss function. , as well as All are weighting coefficients. For the first loss function, For the second loss function, For the third loss function, This represents the total number of original water body monitoring index data. This represents the total number of water quality grade categories. , For the first The first set of original water body monitoring index data The true probability corresponding to each water quality grade category For the first The first set of original water body monitoring index data The predicted probability for each water quality category For the first The category weights of each water quality grade category For the first The first set of original water body monitoring index data The predicted probability for each water quality category For focus coefficient, The total number of key indicator feature matrices. For the first Key indicator feature matrix corresponding to each original water body monitoring indicator data For the first The feature matrix of real water body monitoring indicators corresponding to the original water body monitoring indicator data. For the first The first set of original water body monitoring index data The true probability corresponding to each water quality grade category For the first The total number of original water body monitoring indicator data corresponding to each water quality grade category; Determine whether the target loss function is less than or equal to the preset loss function. If not, update the parameters of the training model according to the target loss function and return to S21 after parameter update. If yes, use the training model as the water quality assessment model.

9. A water quality assessment device, employing the water quality assessment method as described in any one of claims 1 to 8, characterized in that, include: The import module is used to import multiple raw water body monitoring index data; The preprocessing module is used to preprocess each of the original water body monitoring index data to obtain preprocessed water body monitoring index data corresponding to each of the original water body monitoring index data. The model analysis module is used to build a training model and perform model analysis on the training model using all the pre-processed water body monitoring index data to obtain a water quality assessment model. The import module is also used to import monitoring index data of the water body to be evaluated; The assessment result acquisition module is used to evaluate the monitoring index data of the water body to be assessed through the water quality assessment model, and obtain the water quality assessment result.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when the computer program is executed, controls the device containing the computer-readable storage medium to perform the water quality assessment method as described in any one of claims 1 to 8.